You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Section order is deliberate: workflow first (the top is the least likely part of a long
460
460
// description to be truncated or skimmed away), then rules, then syntax, with the budgeted
461
-
// catalog at the bottom. Example call forms use explicit `<namespace>.<tool>` placeholders -
462
-
// never a real or fabricated tool name.
461
+
// catalog at the bottom. Example call forms use placeholders - never a real or fabricated
462
+
// tool name - and show both dot and bracket notation so non-identifier names are not normalized.
463
463
constintro=[
464
464
"Write a CodeMode program to answer the request. Return code only.",
465
465
empty
466
466
? "Execute JavaScript in a confined runtime."
467
467
: complete
468
468
? "Execute JavaScript in a confined runtime. Inside this program, `tools` contains only the host-provided tools listed below; surrounding agent tools are not available unless listed here."
469
469
: "Execute JavaScript in a confined runtime. Inside this program, `tools` contains only the host-provided tools listed or searchable below; surrounding agent tools are not available unless listed here.",
470
+
...(empty ? [] : ["Do not infer or normalize tool names; use only exact signatures shown below or returned by search."]),
470
471
]
471
472
472
473
// The search step exists only when search is advertised (PARTIAL catalog); a COMPLETE
"1. Pick a tool from the list under `## Available tools` - each line is the exact call signature; use it as-is rather than guessing segments.",
483
-
"2. Call it using the exact signature shown: `const res = await tools.<namespace>.<tool>(input)` - bracket notation may appear for names that are not JavaScript identifiers.",
484
+
'2. Call it using the exact signature shown; bracket notation and quotes are part of the path.',
484
485
'3. Parse text results: `const data = typeof res === "string" ? JSON.parse(res) : res` - most tools return JSON as a string.',
485
486
"4. Return only the fields you need: `return { <field>: data.<field> }` - raw payloads get truncated and waste context.",
486
487
]
487
488
: [
488
-
'1. Find a tool (skip when it is already listed below): `const { items } = await tools.$codemode.search({ query: "<intent + key nouns>" })` - short phrases like "list issues" work best.',
489
+
'1. If the exact signature is not listed below, first search: `const { items } = await tools.$codemode.search({ query: "<intent + key nouns>" })`.',
489
490
"2. Read the matches: each item is `{ path, description, signature }` - read the description before using an unfamiliar tool.",
490
-
"3. Call it with the result's `path` as-is (never guess segments): `const res = await tools.<namespace>.<tool>(input)` - bracket notation may appear for names that are not JavaScript identifiers.",
491
+
"3. Call the result's `path` as-is; bracket notation and quotes are part of the path.",
491
492
'4. Parse text results: `const data = typeof res === "string" ? JSON.parse(res) : res` - most tools return JSON as a string.',
492
493
"5. Return only the fields you need: `return { <field>: data.<field> }` - raw payloads get truncated and waste context.",
: "- Only tools listed here or returned by `tools.$codemode.search` are available inside `tools`; tools from the surrounding agent/runtime are not implicitly exposed.",
505
506
"- Filter, aggregate, and transform collections in code - never return them raw or call a tool per item across messages.",
506
507
"- A result typed `Promise<unknown>` has no guaranteed shape - verify what actually came back before relying on its fields.",
507
-
"- Run independent calls in parallel: `await Promise.all(items.map((item) => tools.<namespace>.<tool>(item)))`.",
508
+
'- Run independent calls in parallel: `await Promise.all(items.map((item) => tools.<namespace>.<tool>(item)))`, or use `tools.<namespace>["tool-name"](item)` when the listed signature uses bracket notation.',
508
509
"- `Object.keys(tools)` lists namespaces; `Object.keys(tools.<namespace>)` lists its tools; `for...in` works on both.",
@@ -640,7 +640,7 @@ describe("CodeMode public contract", () => {
640
640
// PARTIAL: the workflow starts with search (with query-style guidance that is clearly
641
641
// a query string, never a tool name) and the browse-namespace rule appears.
642
642
expect(partial).toContain(
643
-
'1. Find a tool (skip when it is already listed below): `const { items } = await tools.$codemode.search({ query: "<intent + key nouns>" })` - short phrases like "list issues" work best.',
643
+
'1. If the exact signature is not listed below, first search: `const { items } = await tools.$codemode.search({ query: "<intent + key nouns>" })`.',
644
644
)
645
645
expect(partial).toContain(
646
646
"Only tools listed here or returned by `tools.$codemode.search` are available inside `tools`",
0 commit comments