|
|
@@ -458,8 +458,8 @@ export const discoveryPlan = <R>(
|
|
|
|
|
|
// Section order is deliberate: workflow first (the top is the least likely part of a long
|
|
|
// description to be truncated or skimmed away), then rules, then syntax, with the budgeted
|
|
|
- // catalog at the bottom. Example call forms use explicit `<namespace>.<tool>` placeholders -
|
|
|
- // never a real or fabricated tool name.
|
|
|
+ // catalog at the bottom. Example call forms use placeholders - never a real or fabricated
|
|
|
+ // tool name - and show both dot and bracket notation so non-identifier names are not normalized.
|
|
|
const intro = [
|
|
|
"Write a CodeMode program to answer the request. Return code only.",
|
|
|
empty
|
|
|
@@ -467,6 +467,7 @@ export const discoveryPlan = <R>(
|
|
|
: complete
|
|
|
? "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."
|
|
|
: "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.",
|
|
|
+ ...(empty ? [] : ["Do not infer or normalize tool names; use only exact signatures shown below or returned by search."]),
|
|
|
]
|
|
|
|
|
|
// The search step exists only when search is advertised (PARTIAL catalog); a COMPLETE
|
|
|
@@ -480,14 +481,14 @@ export const discoveryPlan = <R>(
|
|
|
...(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.",
|
|
|
- "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.",
|
|
|
+ '2. Call it using the exact signature shown; bracket notation and quotes are part of the path.',
|
|
|
'3. Parse text results: `const data = typeof res === "string" ? JSON.parse(res) : res` - most tools return JSON as a string.',
|
|
|
"4. Return only the fields you need: `return { <field>: data.<field> }` - raw payloads get truncated and waste context.",
|
|
|
]
|
|
|
: [
|
|
|
- '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.',
|
|
|
+ '1. If the exact signature is not listed below, first search: `const { items } = await tools.$codemode.search({ query: "<intent + key nouns>" })`.',
|
|
|
"2. Read the matches: each item is `{ path, description, signature }` - read the description before using an unfamiliar tool.",
|
|
|
- "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.",
|
|
|
+ "3. Call the result's `path` as-is; bracket notation and quotes are part of the path.",
|
|
|
'4. Parse text results: `const data = typeof res === "string" ? JSON.parse(res) : res` - most tools return JSON as a string.',
|
|
|
"5. Return only the fields you need: `return { <field>: data.<field> }` - raw payloads get truncated and waste context.",
|
|
|
]),
|
|
|
@@ -504,7 +505,7 @@ export const discoveryPlan = <R>(
|
|
|
: "- Only tools listed here or returned by `tools.$codemode.search` are available inside `tools`; tools from the surrounding agent/runtime are not implicitly exposed.",
|
|
|
"- Filter, aggregate, and transform collections in code - never return them raw or call a tool per item across messages.",
|
|
|
"- A result typed `Promise<unknown>` has no guaranteed shape - verify what actually came back before relying on its fields.",
|
|
|
- "- Run independent calls in parallel: `await Promise.all(items.map((item) => tools.<namespace>.<tool>(item)))`.",
|
|
|
+ '- 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.',
|
|
|
"- `Object.keys(tools)` lists namespaces; `Object.keys(tools.<namespace>)` lists its tools; `for...in` works on both.",
|
|
|
...(complete
|
|
|
? []
|