diff --git a/packages/core/src/codemode/tool.ts b/packages/core/src/codemode/tool.ts index 5fcbea149a3..4534660baa1 100644 --- a/packages/core/src/codemode/tool.ts +++ b/packages/core/src/codemode/tool.ts @@ -89,16 +89,20 @@ export type Inventory = { readonly namespaces?: ReadonlyMap } -// Invariant model-facing guidance; the changing tool catalog is delivered through Instructions. -const description = [ - "Run JavaScript in a confined Code Mode runtime to script tool calls and HTTP requests and compose their results.", - "Write plain JavaScript and send it exactly as written: no code fence, and no JSON or other wrapper around it.", - "`fetch` is available for HTTP requests. Imports, direct filesystem access, and timers are unavailable: there is no `setTimeout` or sleep. All other external access goes through `tools`.", - "Inside `execute`, the only callable tools are those explicitly listed in the Code Mode catalog instructions or returned by the `search` function. Ignore tools shown outside the Code Mode catalog. They are not available in the Code Mode runtime.", - 'Call tools through `tools` using only exact paths and signatures from the catalog. Do not infer or normalize tool names; preserve bracket notation such as `tools.["tool-name"](input)`.', - "Prefer an explicit `return`; if omitted, the final top-level expression becomes the result.", - "Await every call whose completion matters; pending calls are interrupted when execution ends. Run independent calls concurrently with `Promise.allSettled`.", -].join("\n") +// Invariant model-facing guidance; the changing tool catalog is delivered through Instructions. With `full_codemode`, +// the runtime also has Bun's file APIs. +const description = (full: boolean) => + [ + "Run JavaScript in a confined Code Mode runtime to script tool calls and HTTP requests and compose their results.", + "Write plain JavaScript and send it exactly as written: no code fence, and no JSON or other wrapper around it.", + full + ? "`fetch` is available for HTTP requests, and Bun's file APIs (`Bun.file`, `Bun.write`, `Bun.Glob`) for files, in place of Node's `fs`. Imports and timers are unavailable: there is no `setTimeout` or sleep. All other external access goes through `tools`." + : "`fetch` is available for HTTP requests. Imports, direct filesystem access, and timers are unavailable: there is no `setTimeout` or sleep. All other external access goes through `tools`.", + "Inside `execute`, the only callable tools are those explicitly listed in the Code Mode catalog instructions or returned by the `search` function. Ignore tools shown outside the Code Mode catalog. They are not available in the Code Mode runtime.", + 'Call tools through `tools` using only exact paths and signatures from the catalog. Do not infer or normalize tool names; preserve bracket notation such as `tools.["tool-name"](input)`.', + "Prefer an explicit `return`; if omitted, the final top-level expression becomes the result.", + "Await every call whose completion matters; pending calls are interrupted when execution ends. Run independent calls concurrently with `Promise.allSettled`.", + ].join("\n") export const create = ( inventory: Inventory, @@ -109,7 +113,7 @@ export const create = ( ) => { return { name: "execute", - description, + description: description(services !== undefined), input: CodeMode.Input, freeform: { type: "text" }, output: ExecuteOutput, diff --git a/packages/core/test/tool-execute.test.ts b/packages/core/test/tool-execute.test.ts index bc81f9c6bb8..01fd787736e 100644 --- a/packages/core/test/tool-execute.test.ts +++ b/packages/core/test/tool-execute.test.ts @@ -72,6 +72,14 @@ test("execute describes invariant Code Mode behavior", () => { ) }) +test("with full_codemode, execute names Bun's file APIs instead of ruling out filesystem access", () => { + const description = createCodeMode(new Map(), allowAll, codeModeServices(process.cwd())).description + expect(description).toContain( + "`fetch` is available for HTTP requests, and Bun's file APIs (`Bun.file`, `Bun.write`, `Bun.Glob`) for files, in place of Node's `fs`. Imports and timers are unavailable: there is no `setTimeout` or sleep. All other external access goes through `tools`.", + ) + expect(description).not.toContain("direct filesystem access") +}) + test("canonical execution distinguishes declared, model-only, and raw schema outputs", async () => { const declared: Info = { name: "declared",