chore: generate

This commit is contained in:
opencode-agent[bot] 2026-07-06 05:53:41 +00:00
commit e12cb7fb6b
5 changed files with 26 additions and 40 deletions

View file

@ -390,8 +390,7 @@ const makeSearchTool = (searchIndex: ReadonlyArray<SearchEntry>) =>
pathQuery === "" pathQuery === ""
? undefined ? undefined
: scoped.find( : scoped.find(
(entry) => (entry) => entry.description.path === pathQuery || toolExpression(entry.description.path) === trimmed,
entry.description.path === pathQuery || toolExpression(entry.description.path) === trimmed,
) )
const terms = tokenize(query).map(termForms) const terms = tokenize(query).map(termForms)
// Additive field-weighted scoring, summed across terms: exact path or path segment // Additive field-weighted scoring, summed across terms: exact path or path segment
@ -418,8 +417,7 @@ const makeSearchTool = (searchIndex: ReadonlyArray<SearchEntry>) =>
.filter(({ score }) => terms.length === 0 || score > 0) .filter(({ score }) => terms.length === 0 || score > 0)
.sort( .sort(
(left, right) => (left, right) =>
right.score - left.score || right.score - left.score || left.entry.description.path.localeCompare(right.entry.description.path),
left.entry.description.path.localeCompare(right.entry.description.path),
) )
.map(({ entry }) => entry) .map(({ entry }) => entry)
const items = ranked.slice(offset, offset + (request.limit ?? defaultSearchLimit)).map(({ description }) => ({ const items = ranked.slice(offset, offset + (request.limit ?? defaultSearchLimit)).map(({ description }) => ({
@ -479,10 +477,7 @@ export const assertValidTools = <R>(tools: HostTools<R>): void => {
* namespace. Namespace stub lines are never budgeted: every namespace appears with its * namespace. Namespace stub lines are never budgeted: every namespace appears with its
* tool count even at budget 0. * tool count even at budget 0.
*/ */
export const prepare = <R>( export const prepare = <R>(tools: HostTools<R>, catalogBudget = defaultCatalogBudget): DiscoveryPlan => {
tools: HostTools<R>,
catalogBudget = defaultCatalogBudget,
): DiscoveryPlan => {
if (!Number.isSafeInteger(catalogBudget) || catalogBudget < 0) { if (!Number.isSafeInteger(catalogBudget) || catalogBudget < 0) {
throw new RangeError("discovery.catalogBudget must be a non-negative safe integer") throw new RangeError("discovery.catalogBudget must be a non-negative safe integer")
} }
@ -644,10 +639,7 @@ export const prepare = <R>(
* function in JS). An unknown path is an `UnknownTool` error pointing at the working * function in JS). An unknown path is an `UnknownTool` error pointing at the working
* discovery idioms, mirroring how calling an unknown tool fails. * discovery idioms, mirroring how calling an unknown tool fails.
*/ */
const namespaceKeys = <R>( const namespaceKeys = <R>(tools: HostTools<R>, path: ReadonlyArray<string>): ReadonlyArray<string> => {
tools: HostTools<R>,
path: ReadonlyArray<string>,
): ReadonlyArray<string> => {
let value: HostTool<R> | Definition<R> | HostTools<R> = tools let value: HostTool<R> | Definition<R> | HostTools<R> = tools
for (const segment of path) { for (const segment of path) {
if ( if (
@ -656,13 +648,9 @@ const namespaceKeys = <R>(
isDefinition(value) || isDefinition(value) ||
!Object.hasOwn(value, segment) !Object.hasOwn(value, segment)
) { ) {
throw new ToolRuntimeError( throw new ToolRuntimeError("UnknownTool", `Unknown tool namespace '${path.join(".")}'.`, [
"UnknownTool", "Object.keys(tools) lists the available namespaces; tools.$codemode.search({ query }) finds described tools.",
`Unknown tool namespace '${path.join(".")}'.`, ])
[
"Object.keys(tools) lists the available namespaces; tools.$codemode.search({ query }) finds described tools.",
],
)
} }
value = value[segment] as HostTool<R> | Definition<R> | HostTools<R> value = value[segment] as HostTool<R> | Definition<R> | HostTools<R>
} }
@ -670,10 +658,7 @@ const namespaceKeys = <R>(
return Object.keys(value) return Object.keys(value)
} }
const resolve = <R>( const resolve = <R>(tools: HostTools<R>, path: ReadonlyArray<string>): HostTool<R> | Definition<R> => {
tools: HostTools<R>,
path: ReadonlyArray<string>,
): HostTool<R> | Definition<R> => {
let value: HostTool<R> | Definition<R> | HostTools<R> = tools let value: HostTool<R> | Definition<R> | HostTools<R> = tools
for (const segment of path) { for (const segment of path) {
@ -683,11 +668,9 @@ const resolve = <R>(
isDefinition(value) || isDefinition(value) ||
!Object.hasOwn(value, segment) !Object.hasOwn(value, segment)
) { ) {
throw new ToolRuntimeError( throw new ToolRuntimeError("UnknownTool", `Unknown tool '${path.join(".")}'.`, [
"UnknownTool", "Use tools.$codemode.search({ query }) to find available described tools.",
`Unknown tool '${path.join(".")}'.`, ])
["Use tools.$codemode.search({ query }) to find available described tools."],
)
} }
value = value[segment] as HostTool<R> | Definition<R> | HostTools<R> value = value[segment] as HostTool<R> | Definition<R> | HostTools<R>
} }

View file

@ -533,7 +533,8 @@ describe("CodeMode public contract", () => {
{ {
path: "tools.orders.lookup", path: "tools.orders.lookup",
description: "Look up an order by ID", 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(input: {\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>",
}, },
], ],
remaining: 0, remaining: 0,

View file

@ -146,13 +146,7 @@ describe("for...in", () => {
} }
return names return names
`), `),
).toEqual([ ).toEqual(["github.list_issues", "github.get_issue", "memory.search", "playwright.navigate", "$codemode.search"])
"github.list_issues",
"github.get_issue",
"memory.search",
"playwright.navigate",
"$codemode.search",
])
}) })
test("unsupported values fail with a hint at for...of and Object.keys", async () => { test("unsupported values fail with a hint at for...of and Object.keys", async () => {

View file

@ -83,9 +83,15 @@ describe("pretty signature rendering", () => {
true, true,
) )
expect(pretty).toBe( expect(pretty).toBe(
["{", " /** Search filter */", " filter?: {", " /** Issue state */", " state?: string,", " },", "}"].join( [
"\n", "{",
), " /** Search filter */",
" filter?: {",
" /** Issue state */",
" state?: string,",
" },",
"}",
].join("\n"),
) )
}) })

View file

@ -131,7 +131,9 @@ describe("code mode execute", () => {
}, },
["weather"], ["weather"],
) )
expect(description).toContain("tools.weather.current(input: {\n city: string,\n}): Promise<{\n tempC: number,\n}>") expect(description).toContain(
"tools.weather.current(input: {\n city: string,\n}): Promise<{\n tempC: number,\n}>",
)
}) })
test("the static base description carries no catalog; the registry appends it", async () => { test("the static base description carries no catalog; the registry appends it", async () => {