From 701bf1854f079fbab4405b7b4334e2318fc0ed07 Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Fri, 3 Jul 2026 16:25:10 -0500 Subject: [PATCH] refactor(codemode): inline trivial runtime helpers --- packages/codemode/src/tool-runtime.ts | 47 +++++++++++++-------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/packages/codemode/src/tool-runtime.ts b/packages/codemode/src/tool-runtime.ts index 0135a2ae8f..b068848586 100644 --- a/packages/codemode/src/tool-runtime.ts +++ b/packages/codemode/src/tool-runtime.ts @@ -299,17 +299,16 @@ const definitions = ( return entries } -const describeDefinition = (path: string, definition: Definition): ToolDescription => ({ - path, - description: definition.description, - signature: `${toolExpression(path)}(input: ${inputTypeScript(definition)}): Promise<${outputTypeScript(definition)}>`, -}) - const visibleDefinitions = (tools: HostTools) => - definitions(tools).flatMap(({ path, definition }) => { - const description = describeDefinition(path, definition) - return [{ path, definition, description }] - }) + definitions(tools).map(({ path, definition }) => ({ + path, + definition, + description: { + path, + description: definition.description, + signature: `${toolExpression(path)}(input: ${inputTypeScript(definition)}): Promise<${outputTypeScript(definition)}>`, + }, + })) export const catalog = (tools: HostTools): ReadonlyArray => visibleDefinitions(tools).map(({ description }) => description) @@ -360,16 +359,10 @@ const termForms = (term: string): Array => { return forms } -const firstLine = (text: string) => text.split("\n", 1)[0]!.trim() - -/** One-line description used on inline catalog lines; the full text stays in search results. */ -const brief = (text: string, max = 120) => { - const line = firstLine(text) - return line.length > max ? line.slice(0, max - 1) + "..." : line -} - const catalogLine = (tool: ToolDescription) => { - const description = brief(tool.description) + // Inline catalog lines use only a compact first line; full text stays in search results. + const line = tool.description.split("\n", 1)[0]!.trim() + const description = line.length > 120 ? line.slice(0, 119) + "..." : line return description === "" ? ` - ${tool.signature}` : ` - ${tool.signature} // ${description}` } @@ -644,9 +637,6 @@ export type ToolRuntime = { readonly keys: (path: ReadonlyArray) => ReadonlyArray } -const failureMessage = (error: unknown): string => - error instanceof ToolError || error instanceof ToolRuntimeError ? error.message : "Tool execution failed" - export const make = ( tools: HostTools, /** Undefined means unlimited tool calls. */ @@ -665,9 +655,16 @@ export const make = ( const startedAt = Date.now() return effect.pipe( Effect.tap(() => onEnd({ ...call, durationMs: Date.now() - startedAt, outcome: "success" })), - Effect.tapError((error) => - onEnd({ ...call, durationMs: Date.now() - startedAt, outcome: "failure", message: failureMessage(error) }), - ), + Effect.tapError((error) => { + const message = + error instanceof ToolError || error instanceof ToolRuntimeError ? error.message : "Tool execution failed" + return onEnd({ + ...call, + durationMs: Date.now() - startedAt, + outcome: "failure", + message, + }) + }), ) }