feat(core): tell models about Bun's file APIs in Code Mode with full_codemode (#64589)

This commit is contained in:
Aiden Cline
2026-11-17 22:48:33 -06:00
committed by GitHub
Unverified
parent db8730ebcd
commit 7667ec4020
2 changed files with 23 additions and 11 deletions
+15 -11
View File
@@ -89,16 +89,20 @@ export type Inventory = {
readonly namespaces?: ReadonlyMap<string, ToolNamespace>
}
// 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.<namespace>["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.<namespace>["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,
+8
View File
@@ -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",