Skip to content

Commit f9bfa5d

Browse files
author
HCL
committed
fix(schema): accept tools.codeMode at agent-entry scope (#83388)
docs/reference/code-mode.md describes 'tools.codeMode.enabled: true' as settable on 'the agent or runtime config'. The top-level ToolsSchema already accepts codeMode, but AgentToolsSchema is .strict() and didn't include the key, so gateway startup rejected the documented per-agent shape with 'agents.list.0.tools: Unrecognized key: "codeMode"'. Add 'codeMode: CodeModeSchema' to AgentToolsSchema. The schema is the same one consumed at the top level, so the boolean shorthand and the full object form (enabled/runtime/timeoutMs/languages/...) all behave identically at the per-agent scope. strict() is preserved on the inner schema; unknown nested keys still reject. Adds 1 regression case in zod-schema.agent-defaults.test.ts covering: - per-agent { codeMode: { enabled: true } } shape accepts - boolean codeMode: true shape accepts - full options object accepts - unknown nested key still rejected (strict() preserved)
1 parent 6baa2b3 commit f9bfa5d

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/config/zod-schema.agent-defaults.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,48 @@ describe("agent defaults schema", () => {
342342
expect(config.agents?.list?.[0]?.contextTokens).toBe(1_048_576);
343343
});
344344

345+
it("accepts per-agent tools.codeMode.enabled (#83388)", () => {
346+
// docs/reference/code-mode.md describes `tools.codeMode.enabled: true` as
347+
// settable at the agent level. Pre-fix AgentToolsSchema was .strict() and
348+
// didn't include codeMode, so gateway startup rejected the documented
349+
// shape with `agents.list.0.tools: Unrecognized key: "codeMode"`.
350+
expectSchemaSuccess(
351+
AgentEntrySchema.safeParse({
352+
id: "test-agent",
353+
tools: { codeMode: { enabled: true } },
354+
}),
355+
);
356+
// Boolean form should also work, mirroring the top-level CodeModeSchema union.
357+
expectSchemaSuccess(
358+
AgentEntrySchema.safeParse({
359+
id: "test-agent",
360+
tools: { codeMode: true },
361+
}),
362+
);
363+
// Full object form with documented options.
364+
expectSchemaSuccess(
365+
AgentEntrySchema.safeParse({
366+
id: "test-agent",
367+
tools: {
368+
codeMode: {
369+
enabled: true,
370+
runtime: "quickjs-wasi",
371+
timeoutMs: 5000,
372+
languages: ["javascript"],
373+
},
374+
},
375+
}),
376+
);
377+
// Unknown nested key still rejected (strict() preserved on the inner schema).
378+
expectSchemaFailurePath(
379+
AgentEntrySchema.safeParse({
380+
id: "test-agent",
381+
tools: { codeMode: { unknownKey: 1 } },
382+
}),
383+
"tools.codeMode",
384+
);
385+
});
386+
345387
it("rejects non-positive contextTokens on agent entries and defaults", () => {
346388
expectSchemaFailurePath(
347389
AgentEntrySchema.safeParse({ id: "ops", contextTokens: 0 }),

src/config/zod-schema.agent-runtime.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,12 @@ const MessageToolConfigSchema = z
703703
const AgentToolsSchema = z
704704
.object({
705705
...CommonToolPolicyFields,
706+
// #83388: per-agent code-mode enablement matches the doc surface
707+
// (`docs/reference/code-mode.md` describes `tools.codeMode.enabled` as
708+
// an "agent or runtime" config). The top-level ToolsSchema already
709+
// accepts `codeMode`; mirror it here so a per-agent override can be
710+
// tested without forcing fleet-wide behavior change.
711+
codeMode: CodeModeSchema,
706712
elevated: z
707713
.object({
708714
enabled: z.boolean().optional(),

0 commit comments

Comments
 (0)