feat(tools): the P2 toggle bridge — toolToggles first-class, definitive vocabulary
Reconciliation of the diverged tool-toggles seam (2026-09-19, master's P2): Platform injected the resolved delta as an ad-hoc intersection on AgentBuildOptions while the factories' enabled? param sat unread — the seam was inert on both sides. - teacher-agent: AgentBuildOptions gains toolToggles?: EnabledTools; both constructors thread it to the factories (createTeacherTools / createProberTools). An explicitly injected opts.tools registry is never filtered — the caller owns it. - Vocabulary ADJUDICATED with the user (2026-09-19): TOGGLEABLE_TOOLS is the definitive list — the job tools only (research/demo/visual/pdf). quiz/ask_user_question stay always-on forever (the prober's flow is graded-quiz brackets -> probe_done; quiz-off collapses assessment and teaching doctrine is built on graded verification — the wedge danger); the learner-fs set, plan tools, and probe_done also always-on. - settings-body (write side): unknown tool keys reject with 400 + the supported list, mirroring the prompt-switch validation; the read-side sanitizer stays lenient for forward-compat. - chat-handler: the intersection is gone (field now first-class) and the seam comment states the adjudicated vocabulary. Gates: typecheck, 28 new/updated tests green (tool-toggles-bridge, question-tools, settings-body), chat-flow + settings suites green.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* The P2 tool-toggle bridge (2026-09-19): AgentBuildOptions.toolToggles is
|
||||
* first-class — the agent constructors thread it to the factories' enabled?
|
||||
* param (an explicit opts.tools registry is never filtered), and the
|
||||
* settings write side rejects unknown tool keys against TOGGLEABLE_TOOLS
|
||||
* (the definitive adjudicated list — a persisted `quiz: false` would
|
||||
* genuinely drop the quiz once the bridge honors the delta).
|
||||
*
|
||||
* Parser tests are PURE (no fs — parallel-test discipline); the agent
|
||||
* construction tests use an in-memory chat fixture like
|
||||
* question-tools.test.ts.
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import { z } from "zod";
|
||||
import { describe, it } from "node:test";
|
||||
import { createProberAgent, createTeacherAgent } from "../src/agent/teacher-agent.ts";
|
||||
import type { ProbeDoneContext } from "../src/agent/tools.ts";
|
||||
import { parseAgentSettingsBody } from "../src/server/settings-body.ts";
|
||||
import { chatStore } from "../src/store/chats.ts";
|
||||
import type { AgentSettings } from "../src/core/settings.ts";
|
||||
|
||||
describe("AgentBuildOptions.toolToggles (the P2 bridge)", () => {
|
||||
const toolNames = (agent: { state: { tools: Array<{ name: string }> } }) =>
|
||||
agent.state.tools.map((t) => t.name).sort();
|
||||
|
||||
it("flows into the teacher's registry: a job-tool delta is a no-op on the bare set", () => {
|
||||
// No ctx → bare agent: quiz/ask only. A job-tool delta names tools
|
||||
// that don't exist there — the bridge must not crash on it.
|
||||
const bare = createTeacherAgent(undefined, { toolToggles: { research: false } });
|
||||
assert.deepEqual(toolNames(bare), ["ask_user_question", "quiz"]);
|
||||
});
|
||||
|
||||
it("flows into the prober's registry; probe_done survives everything", () => {
|
||||
const chatId = chatStore.createChat("Toggle bridge test").id;
|
||||
const ctx: ProbeDoneContext = { chatId, chatStore, deliver: () => {} };
|
||||
const prober = createProberAgent(ctx, { toolToggles: { ask_user_question: false } });
|
||||
const names = toolNames(prober);
|
||||
assert.ok(!names.includes("ask_user_question"), "the delta dropped the tool");
|
||||
assert.ok(names.includes("probe_done"), "probe_done always-on");
|
||||
});
|
||||
|
||||
it("an explicitly injected opts.tools registry is NEVER toggle-filtered", () => {
|
||||
const teacher = createTeacherAgent(undefined, {
|
||||
tools: {
|
||||
quiz: { name: "quiz", description: "test", clientQuestion: true, schema: z.object({}) },
|
||||
},
|
||||
toolToggles: { quiz: false },
|
||||
});
|
||||
assert.deepEqual(toolNames(teacher), ["quiz"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseAgentSettingsBody: tool keys validate at write time", () => {
|
||||
const parse = (tools: Record<string, boolean>) =>
|
||||
parseAgentSettingsBody({ tools }) as
|
||||
| { ok: true; settings: AgentSettings }
|
||||
| { ok: false; error: string };
|
||||
|
||||
it("a valid job-tool delta parses", () => {
|
||||
const r = parse({ research: false, pdf: false });
|
||||
assert.equal(r.ok, true);
|
||||
assert.deepEqual(r.ok && r.settings.tools, { research: false, pdf: false });
|
||||
});
|
||||
|
||||
it("unknown keys are rejected with the supported list (the quiz wedge never persists)", () => {
|
||||
const r = parse({ quiz: false });
|
||||
assert.equal(r.ok, false);
|
||||
assert.match(!r.ok && r.error, /unknown tool "quiz" \(supported: research, demo, visual, pdf\)/);
|
||||
const typo = parse({ reasearch: false });
|
||||
assert.equal(typo.ok, false);
|
||||
assert.match(!typo.ok && typo.error, /unknown tool "reasearch"/);
|
||||
});
|
||||
|
||||
it("absent tools field is fine (absent = enabled everywhere)", () => {
|
||||
const r = parseAgentSettingsBody({}) as { ok: boolean };
|
||||
assert.equal(r.ok, true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user