feat(agent,coding-agent): add prepareArguments hook for pre-validation argument preparation

Add AgentTool.prepareArguments and ToolDefinition.prepareArguments hook
that runs before schema validation in the agent loop. This lets tools
silently accept legacy argument shapes from resumed old sessions without
polluting the public schema.

The built-in edit tool uses this to fold legacy top-level oldText/newText
into edits[] when resuming sessions that predate the edits-only schema.

- AgentTool/ToolDefinition: typed prepareArguments returning Static<TParameters>
- agent-loop: prepareToolCallArguments() runs before validateToolArguments()
- edit tool: prepareEditArguments folds legacy fields, validateEditInput is strict
- Documented in extensions.md with edit-tool example
This commit is contained in:
Mario Zechner
2026-03-29 21:06:12 +02:00
parent fa890e3f94
commit b5f425ad15
10 changed files with 287 additions and 8 deletions

View File

@@ -377,6 +377,9 @@ export interface ToolDefinition<TParams extends TSchema = TSchema, TDetails = un
/** Parameter schema (TypeBox) */
parameters: TParams;
/** Optional compatibility shim to prepare raw tool call arguments before schema validation. Must return an object conforming to TParams. */
prepareArguments?: (args: unknown) => Static<TParams>;
/** Execute the tool. */
execute(
toolCallId: string,