fix(codemode): drop the parameter name from rendered signatures (#50435)

This commit is contained in:
Aiden Cline
2026-09-21 16:44:46 -05:00
committed by GitHub
parent 4cc9b90f27
commit 096ac95773
6 changed files with 26 additions and 27 deletions
+2 -2
View File
@@ -176,7 +176,7 @@ const describeTool = <R>(visible: VisibleTool<R>): ToolDescription => {
// Joining the final fragments avoids retaining the rendering's intermediate string ropes in JSC.
return (signature ??= [
toolExpression(visible.path),
isEmptyInput(visible.tool) ? "()" : `(input: ${inputTypeScript(visible.tool, true)})`,
isEmptyInput(visible.tool) ? "()" : `(${inputTypeScript(visible.tool, true)})`,
`: Promise<${outputTypeScript(visible.tool, true)}>`,
].join(""))
},
@@ -279,7 +279,7 @@ const makeSearchTool = (searchIndex: ReadonlyArray<SearchEntry>): Tool => ({
/** Exact callable signature of the built-in `search` function, for host-owned instructions. */
export const searchSignature = (() => {
const tool = makeSearchTool([])
return `search(input: ${inputTypeScript(tool, true)}): ${outputTypeScript(tool, true)}`
return `search(${inputTypeScript(tool, true)}): ${outputTypeScript(tool, true)}`
})()
const toSearchEntry = <R>(visible: VisibleTool<R>): SearchEntry => ({
+10 -11
View File
@@ -581,7 +581,7 @@ describe("CodeMode schema flexibility", () => {
{
path: "adapter.call",
description: "Call an adapter-described tool",
signature: "tools.adapter.call(input: {\n id: string,\n count?: number,\n}): Promise<void>",
signature: "tools.adapter.call({\n id: string,\n count?: number,\n}): Promise<void>",
},
])
@@ -664,7 +664,7 @@ describe("CodeMode schema flexibility", () => {
{
path: "users.lookup",
description: "Look up a user",
signature: "tools.users.lookup(input: {\n login: string,\n}): Promise<{\n login: string,\n id: number,\n}>",
signature: "tools.users.lookup({\n login: string,\n}): Promise<{\n login: string,\n id: number,\n}>",
},
])
@@ -680,7 +680,7 @@ describe("CodeMode schema flexibility", () => {
execute: () => Effect.succeed("pong"),
})
const runtime = CodeMode.make({ tools: { net: { ping } } })
expect(runtime.catalog[0]?.signature).toBe("tools.net.ping(input: {\n host: string,\n}): Promise<void>")
expect(runtime.catalog[0]?.signature).toBe("tools.net.ping({\n host: string,\n}): Promise<void>")
const result = await Effect.runPromise(runtime.execute(`return await tools.net.ping({ host: "example.test" })`))
expect(result.ok).toBe(true)
@@ -737,7 +737,7 @@ describe("CodeMode public contract", () => {
{
path: "orders.lookup",
description: "Look up an order by ID",
signature: "tools.orders.lookup(input: {\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>",
signature: "tools.orders.lookup({\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>",
},
])
@@ -749,8 +749,7 @@ describe("CodeMode public contract", () => {
{
path: "tools.orders.lookup",
description: "Look up an order by ID",
signature:
"tools.orders.lookup(input: {\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>",
signature: "tools.orders.lookup({\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>",
},
],
remaining: 0,
@@ -792,7 +791,7 @@ describe("CodeMode public contract", () => {
{
path: "context7.resolve-library-id",
description: "Resolve a library ID",
signature: 'tools.context7["resolve-library-id"](input: {\n libraryName: string,\n}): Promise<string>',
signature: 'tools.context7["resolve-library-id"]({\n libraryName: string,\n}): Promise<string>',
},
])
@@ -804,7 +803,7 @@ describe("CodeMode public contract", () => {
{
path: 'tools.context7["resolve-library-id"]',
description: "Resolve a library ID",
signature: 'tools.context7["resolve-library-id"](input: {\n libraryName: string,\n}): Promise<string>',
signature: 'tools.context7["resolve-library-id"]({\n libraryName: string,\n}): Promise<string>',
},
],
remaining: 0,
@@ -857,12 +856,12 @@ describe("CodeMode public contract", () => {
{
path: "tools.thread.uploadFile",
description: "Upload one readable local file to the current Discord thread",
signature: "tools.thread.uploadFile(input: {\n path: string,\n}): Promise<{\n sent: boolean,\n}>",
signature: "tools.thread.uploadFile({\n path: string,\n}): Promise<{\n sent: boolean,\n}>",
},
{
path: "tools.thread.generateImage",
description: "Generate an image and upload it to the current Discord thread",
signature: "tools.thread.generateImage(input: {\n prompt: string,\n}): Promise<{\n sent: boolean,\n}>",
signature: "tools.thread.generateImage({\n prompt: string,\n}): Promise<{\n sent: boolean,\n}>",
},
],
remaining: 0,
@@ -950,7 +949,7 @@ describe("CodeMode public contract", () => {
{
path: "tools.many.tool13",
description: "Numbered tool 13",
signature: "tools.many.tool13(input: {\n id: string,\n}): Promise<string>",
signature: "tools.many.tool13({\n id: string,\n}): Promise<string>",
},
],
remaining: 0,
+5 -5
View File
@@ -739,7 +739,7 @@ describe("JSDoc signatures in catalogs and search results", () => {
" },",
"}",
].join("\n")
const signature = `tools.constrained(input: ${type}): Promise<${type}>`
const signature = `tools.constrained(${type}): Promise<${type}>`
expect(runtime.catalog[0]?.signature).toBe(signature)
const result = await Effect.runPromise(runtime.execute('return search({ query: "tools.constrained" })'))
expect(result.ok).toBe(true)
@@ -761,7 +761,7 @@ describe("JSDoc signatures in catalogs and search results", () => {
const item = items.find(({ path }) => path === "tools.github.list_issues")!
expect(item.signature).toBe(
[
"tools.github.list_issues(input: {",
"tools.github.list_issues({",
" /** Repository owner */",
" owner: string,",
" /** Cursor from the previous response's pageInfo */",
@@ -782,7 +782,7 @@ describe("JSDoc signatures in catalogs and search results", () => {
const item = items.find(({ path }) => path === "tools.orders.lookup")!
expect(item.signature).toBe(
[
"tools.orders.lookup(input: {",
"tools.orders.lookup({",
" /** Order identifier */",
" id: string,",
" verbose?: boolean,",
@@ -825,7 +825,7 @@ describe("non-identifier tool paths", () => {
test("catalog signatures use bracket notation for dashed tool names", () => {
expect(runtime.catalog[0]?.signature).toBe(
'tools.context7["resolve-library-id"](input: {\n query: string,\n libraryName: string,\n}): Promise<unknown>',
'tools.context7["resolve-library-id"]({\n query: string,\n libraryName: string,\n}): Promise<unknown>',
)
})
@@ -836,6 +836,6 @@ describe("non-identifier tool paths", () => {
const value = result.value as { items: Array<{ path: string; signature: string }> }
expect(value.items[0]?.path).toBe('tools.context7["resolve-library-id"]')
expect(value.items[0]?.signature).toContain('tools.context7["resolve-library-id"](input: {')
expect(value.items[0]?.signature).toContain('tools.context7["resolve-library-id"]({')
})
})
+1 -1
View File
@@ -30,7 +30,7 @@ describe("CodeMode", () => {
type: "tool",
name: "echo",
description: "Echo text",
signature: "tools.echo(input: {\n text: string,\n}): Promise<string>",
signature: "tools.echo({\n text: string,\n}): Promise<string>",
pinned: true,
},
{
+6 -6
View File
@@ -6,14 +6,14 @@ const entry = (path: string, description: string, signature?: string, pinned = f
type: "tool",
name: path,
description,
signature: signature ?? `tools.${path}(input: {\n q: string,\n}): Promise<string>`,
signature: signature ?? `tools.${path}({\n q: string,\n}): Promise<string>`,
pinned,
})
const lookup = entry(
"orders.lookup",
"Look up an order by ID",
"tools.orders.lookup(input: {\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>",
"tools.orders.lookup({\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>",
)
const render = (tools: CodeModeCatalog.Inventory["tools"], budget?: number) =>
@@ -133,7 +133,7 @@ describe("CodeModeInstructions.render", () => {
expect(partial).toContain(
"The catalog is partial. Inside `execute`, use `search(...)` to find a tool, then call it by the `path` in the result. `search` is synchronous. Call it without `await`; it does not return a Promise.",
)
expect(partial).toContain("- search(input: {")
expect(partial).toContain("- search({")
expect(partial).toContain(" /** @integer @exclusiveMinimum 0 */\n limit?: number,")
expect(partial).toContain(" /** @integer @minimum 0 */\n offset?: number,")
expect(partial).not.toContain("tools.orders.lookup(input:")
@@ -145,7 +145,7 @@ describe("CodeModeInstructions.render", () => {
const expensive = entry(
"alpha.expensive",
"Expensive",
`tools.alpha.expensive(input: {\n aVeryLongParameterName: string,\n anotherEvenLongerParameterName: number,\n yetAnotherExtremelyVerboseParameterName: string,\n}): Promise<string>`,
`tools.alpha.expensive({\n aVeryLongParameterName: string,\n anotherEvenLongerParameterName: number,\n yetAnotherExtremelyVerboseParameterName: string,\n}): Promise<string>`,
)
// Round 1 places alpha.cheap and beta.cheap; in round 2 alpha.expensive does not fit,
// which marks only alpha done - it must NOT prevent other namespaces from inlining.
@@ -166,7 +166,7 @@ describe("CodeModeInstructions.render", () => {
const documented = entry(
"records.lookup",
"Look up a record",
`tools.records.lookup(input: {\n /** ${"A detailed identifier description. ".repeat(20).trim()} */\n id: string,\n}): Promise<string>`,
`tools.records.lookup({\n /** ${"A detailed identifier description. ".repeat(20).trim()} */\n id: string,\n}): Promise<string>`,
)
const instructions = render([documented], 40)
expect(instructions).toContain("- records (1 tool, none shown)")
@@ -184,7 +184,7 @@ describe("CodeModeInstructions.update", () => {
const echo = entry("notes.echo", "Echo text")
test("renders additions, changes, and removals as a compact semantic delta", () => {
const changed = { ...echo, signature: "tools.notes.echo(input: {\n text: string,\n}): Promise<string>" }
const changed = { ...echo, signature: "tools.notes.echo({\n text: string,\n}): Promise<string>" }
const added = entry("notes.list", "List notes")
const unchanged = Array.from({ length: 5 }, (_, index) => entry(`stable.tool${index}`, `Stable ${index}`))
const text = update([echo, lookup, ...unchanged], [changed, added, ...unchanged])
@@ -13,14 +13,14 @@ const echo: CodeModeCatalog.Tool = {
type: "tool",
name: "notes.echo",
description: "Echo text",
signature: "tools.notes.echo(input: {\n text: string,\n}): Promise<string>",
signature: "tools.notes.echo({\n text: string,\n}): Promise<string>",
}
const lookup: CodeModeCatalog.Tool = {
type: "tool",
name: "orders.lookup",
description: "Look up an order",
signature: "tools.orders.lookup(input: {\n id: string,\n}): Promise<unknown>",
signature: "tools.orders.lookup({\n id: string,\n}): Promise<unknown>",
}
describe("CodeModeInstructions", () => {