From aaa0d7c8f6775a211185951a3f16fec840e648a4 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Wed, 28 Oct 2026 20:51:18 -0500 Subject: [PATCH] fix(core): tell Code Mode models built-in tools stay top-level (#57627) --- packages/core/src/codemode/instructions.ts | 6 ++--- packages/core/test/codemode/catalog.test.ts | 22 +++++++++++-------- .../core/test/codemode/instructions.test.ts | 8 ++++--- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/core/src/codemode/instructions.ts b/packages/core/src/codemode/instructions.ts index a87a677d7c6..2f93d261325 100644 --- a/packages/core/src/codemode/instructions.ts +++ b/packages/core/src/codemode/instructions.ts @@ -8,13 +8,13 @@ import { CodeModeCatalog } from "./catalog.js" // prettier-ignore const prompt = (hasMoreTools: boolean) => `# Code Mode -Use the \`execute\` tool to call the tools listed below. They cannot be called directly${hasMoreTools ? ", and neither can \`search\`. Both" : ". They"} only work inside code you pass to \`execute\`. +The tools listed below${hasMoreTools ? ", and \`search\`," : ""} cannot be called directly: they only work as JavaScript inside the \`execute\` tool. Every other tool you have is a normal tool call: call it directly, never inside \`execute\`. -${hasMoreTools ? `The catalog is partial. Inside \`execute\`, use \`search(...)\` to find a tool, then call it by the \`path\` in the result. Do not guess tool names. +${hasMoreTools ? `The catalog is partial. Before calling a tool that is not listed below, find it with the global \`search(...)\` function. Do not guess tool names. Each result's \`path\` is the complete call expression: write it out as code, for example \`await tools.ns.tool_name({ ... })\`. Do not use it as a key such as \`tools[path]\`. - ${searchSignature}` : "The catalog is complete. Do not guess tool names."} -## Available tools` +## Code Mode tools (call only inside \`execute\`)` export function render(catalog: CodeModeCatalog.Summary) { if (catalog.total === 0) diff --git a/packages/core/test/codemode/catalog.test.ts b/packages/core/test/codemode/catalog.test.ts index 17b8026d859..fe483102a60 100644 --- a/packages/core/test/codemode/catalog.test.ts +++ b/packages/core/test/codemode/catalog.test.ts @@ -117,21 +117,25 @@ describe("CodeModeCatalog.summarize", () => { describe("CodeModeInstructions.render", () => { test("inlines complete catalogs without search guidance", () => { const instructions = render([lookup]) - expect(instructions).toContain("## Available tools") + expect(instructions).toContain("## Code Mode tools (call only inside `execute`)") expect(instructions).toContain("- orders (1 tool)") expect(instructions).toContain(` - ${lookup.signature} // Look up an order by ID`) expect(instructions).not.toContain("search") - expect(instructions).toContain("They cannot be called directly. They only work inside code you pass to `execute`.") + expect(instructions).toContain( + "The tools listed below cannot be called directly: they only work as JavaScript inside the `execute` tool. Every other tool you have is a normal tool call: call it directly, never inside `execute`.", + ) expect(instructions).toContain("The catalog is complete. Do not guess tool names.") }) test("adds search guidance when the catalog exceeds the budget", () => { const partial = render([lookup], 0) - expect(partial).toContain("## Available tools") + expect(partial).toContain("## Code Mode tools (call only inside `execute`)") expect(partial).toContain("- orders (1 tool, none shown)") - expect(partial).toContain("They cannot be called directly, and neither can `search`.") expect(partial).toContain( - "The catalog is partial. Inside `execute`, use `search(...)` to find a tool, then call it by the `path` in the result.", + "The tools listed below, and `search`, cannot be called directly: they only work as JavaScript inside the `execute` tool.", + ) + expect(partial).toContain( + "The catalog is partial. Before calling a tool that is not listed below, find it with the global `search(...)` function. Do not guess tool names.", ) expect(partial).toContain("- search({") expect(partial).toContain(" /** @integer @exclusiveMinimum 0 */\n limit?: number,") @@ -194,7 +198,7 @@ describe("CodeModeInstructions.update", () => { `Changed tool listings supersede the previously listed ones:\n - ${changed.signature} // Echo text`, ) expect(text).toContain("The following tools are no longer available and must not be called: tools.orders.lookup.") - expect(text).not.toContain("## Available tools") + expect(text).not.toContain("## Code Mode tools (call only inside `execute`)") }) test("names removed tools with exact callable expressions including bracket notation", () => { @@ -225,14 +229,14 @@ describe("CodeModeInstructions.update", () => { "The Code Mode tool catalog has changed. This catalog supersedes the previous Code Mode tool catalog.", ) expect(text).toContain("The catalog is partial.") - expect(text).toContain("## Available tools") + expect(text).toContain("## Code Mode tools (call only inside `execute`)") }) test("falls back to full replacement when the delta is larger than the catalog", () => { const previous = Array.from({ length: 200 }, (_, index) => entry(`bulk.tool${index}`, `Tool ${index}`)) const text = update([...previous, echo], [echo]) expect(text).toContain("This catalog supersedes the previous Code Mode tool catalog.") - expect(text).toContain("## Available tools") + expect(text).toContain("## Code Mode tools (call only inside `execute`)") expect(text).toContain("The catalog is complete.") expect(text).not.toContain("The following tools are no longer available") }) @@ -243,6 +247,6 @@ describe("CodeModeInstructions.update", () => { expect(text).toContain("`alpha` now has 11 tools") expect(text).toContain("search them again before relying on previous results") expect(text).not.toContain("tools.alpha.tool10(input:") - expect(text).not.toContain("## Available tools") + expect(text).not.toContain("## Code Mode tools (call only inside `execute`)") }) }) diff --git a/packages/core/test/codemode/instructions.test.ts b/packages/core/test/codemode/instructions.test.ts index 5c6f760f403..f128b8ac0d9 100644 --- a/packages/core/test/codemode/instructions.test.ts +++ b/packages/core/test/codemode/instructions.test.ts @@ -46,16 +46,18 @@ describe("CodeModeInstructions", () => { it.effect("renders the initial catalog, semantic deltas, and removal", () => Effect.gen(function* () { const initialized = yield* readInitial(CodeModeInstructions.make({ tools: [echo] })) - expect(initialized.text).toContain("Use the `execute` tool to call the tools listed below.") + expect(initialized.text).toContain( + "The tools listed below cannot be called directly: they only work as JavaScript inside the `execute` tool.", + ) expect(initialized.text).toContain("The catalog is complete.") - expect(initialized.text).toContain("## Available tools") + expect(initialized.text).toContain("## Code Mode tools (call only inside `execute`)") expect(initialized.text).toContain(` - ${echo.signature} // Echo text`) const added = yield* readUpdate(CodeModeInstructions.make({ tools: [echo, lookup] }), initialized) expect(added.text).toContain("The Code Mode tool catalog has changed.") expect(added.text).toContain("New tools are available in addition to those previously listed:") expect(added.text).toContain(` - ${lookup.signature} // Look up an order`) - expect(added.text).not.toContain("## Available tools") + expect(added.text).not.toContain("## Code Mode tools (call only inside `execute`)") const removed = yield* readUpdate(CodeModeInstructions.make({ tools: [echo] }), { values: added.values }) expect(removed.text).toBe(