/** * Adapts BooCoder write tools (which take ToolContext) into BooChat's ToolDef * interface (which takes `projectRoot, extraRoots?`). * * The adapter reads the module-level inference context at execute time, so the * wrapping happens at boot (static) — no per-inference re-wrap needed. */ import type { ToolDef as ServerToolDef } from '@boocode/server/tools'; import type { ToolDef, ToolContext } from './types.js'; import { getInferenceContext } from './inference_context.js'; /** * Wrap a BooCoder write tool (execute takes ToolContext) into a BooChat * ToolDef (execute takes projectRoot + optional extraRoots). The adapter * builds the ToolContext from the module-level inference context at call time. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function adaptWriteTool(tool: ToolDef): ServerToolDef { return { name: tool.name, description: tool.description, inputSchema: tool.inputSchema, jsonSchema: tool.jsonSchema, async execute(input: unknown, projectRoot: string, _extraRoots?: readonly string[]): Promise { const ctx: ToolContext = getInferenceContext(); return tool.execute(input, projectRoot, ctx); }, }; }