chore: generate

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

View file

@ -390,8 +390,7 @@ const makeSearchTool = (searchIndex: ReadonlyArray<SearchEntry>) =>
pathQuery === ""
? undefined
: scoped.find(
(entry) =>
entry.description.path === pathQuery || toolExpression(entry.description.path) === trimmed,
(entry) => entry.description.path === pathQuery || toolExpression(entry.description.path) === trimmed,
)
const terms = tokenize(query).map(termForms)
// 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)
.sort(
(left, right) =>
right.score - left.score ||
left.entry.description.path.localeCompare(right.entry.description.path),
right.score - left.score || left.entry.description.path.localeCompare(right.entry.description.path),
)
.map(({ entry }) => entry)
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
* tool count even at budget 0.
*/
export const prepare = <R>(
tools: HostTools<R>,
catalogBudget = defaultCatalogBudget,
): DiscoveryPlan => {
export const prepare = <R>(tools: HostTools<R>, catalogBudget = defaultCatalogBudget): DiscoveryPlan => {
if (!Number.isSafeInteger(catalogBudget) || catalogBudget < 0) {
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
* discovery idioms, mirroring how calling an unknown tool fails.
*/
const namespaceKeys = <R>(
tools: HostTools<R>,
path: ReadonlyArray<string>,
): ReadonlyArray<string> => {
const namespaceKeys = <R>(tools: HostTools<R>, path: ReadonlyArray<string>): ReadonlyArray<string> => {
let value: HostTool<R> | Definition<R> | HostTools<R> = tools
for (const segment of path) {
if (
@ -656,13 +648,9 @@ const namespaceKeys = <R>(
isDefinition(value) ||
!Object.hasOwn(value, segment)
) {
throw new ToolRuntimeError(
"UnknownTool",
`Unknown tool namespace '${path.join(".")}'.`,
[
"Object.keys(tools) lists the available namespaces; tools.$codemode.search({ query }) finds described tools.",
],
)
throw new ToolRuntimeError("UnknownTool", `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>
}
@ -670,10 +658,7 @@ const namespaceKeys = <R>(
return Object.keys(value)
}
const resolve = <R>(
tools: HostTools<R>,
path: ReadonlyArray<string>,
): HostTool<R> | Definition<R> => {
const resolve = <R>(tools: HostTools<R>, path: ReadonlyArray<string>): HostTool<R> | Definition<R> => {
let value: HostTool<R> | Definition<R> | HostTools<R> = tools
for (const segment of path) {
@ -683,11 +668,9 @@ const resolve = <R>(
isDefinition(value) ||
!Object.hasOwn(value, segment)
) {
throw new ToolRuntimeError(
"UnknownTool",
`Unknown tool '${path.join(".")}'.`,
["Use tools.$codemode.search({ query }) to find available described tools."],
)
throw new ToolRuntimeError("UnknownTool", `Unknown tool '${path.join(".")}'.`, [
"Use tools.$codemode.search({ query }) to find available described tools.",
])
}
value = value[segment] as HostTool<R> | Definition<R> | HostTools<R>
}

View file

@ -533,7 +533,8 @@ 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(input: {\n id: string,\n}): Promise<{\n id: string,\n status: string,\n}>",
},
],
remaining: 0,

View file

@ -146,13 +146,7 @@ describe("for...in", () => {
}
return names
`),
).toEqual([
"github.list_issues",
"github.get_issue",
"memory.search",
"playwright.navigate",
"$codemode.search",
])
).toEqual(["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 () => {

View file

@ -83,9 +83,15 @@ describe("pretty signature rendering", () => {
true,
)
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"],
)
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 () => {