feat(agent): put tool execution behind a ToolHost interface (brain/hand split, step 1)
Closed
CO
6h ago+433+433+012345678901234567890123456789-5-5-0123456789
Fixes #4360.
Step 1 of separating senpi's brain (the agent loop) from its hands (tool execution), as Q ordered on 2026-10-26: one clean boundary, fusable in one process (the default) and runnable apart later.
ToolHost/ToolHostCall(types.ts) andAgentLoopConfig.toolHost(optional).executePreparedToolCallcallstoolHost.execute(...)instead oftool.execute(...). The sequential batch, the parallel batch andrunToolCall(RunToolCallOptions.toolHost) all pass the host, so no path bypasses it.localToolHost(exported) is the default: it runstool.executein-process, so behaviour is byte-identical for every existing caller.- The loop keeps name resolution, argument preparation, schema validation,
beforeToolCall/afterToolCall, events and abort handling.
Tests: test/tool-host-seam.test.ts, 7 tests. RED: they failed to load, since localToolHost and ToolHost did not exist. GREEN covers:
- the host receiving the prepared, validated call in both sequential and parallel mode, with its result becoming the tool result message and partial updates reaching
tool_execution_update; afterToolCallseeing the host's result;- unknown and schema-invalid calls never reaching the host;
- a throwing host becoming an
isErrorresult; runToolCallgoing through the host;- the default being unchanged.
Local: build-all OK; packages/agent 1285 passed / 1 skipped; tsc, oxlint and oxfmt clean; the pre-commit check (incl. the lint ratchet) passed.
Not here: registry publication, an out-of-process hand, the relay hand (later steps of the design).