feat(coding-agent): build the tool registry through a session-less runtime bootstrap (RT1)
Stacked on #5030 (S18a), as plan row RT1's Deps require. Base is feat/bh-s18a-toolhost-seam; retarget to main after #5030 merges. Review and merge are parent-owned.
Summary
Moves the tool-registry construction out of AgentSession into packages/coding-agent/src/core/runtime/bootstrap.ts, so a runtime with no agent loop and no session can build the same registry (brain/hand split, RT1; surfaces F01 core registry and RT1's part of F02).
bootstrapRuntime()builds the built-in tool definitions (or the base-tools override), the composed filesystem policy and theExtensionRunnerfrom loaded extensions. The code moved verbatim fromAgentSession._buildRuntime.buildToolRegistry()merges built-in, extension and SDK tools, applies the default/allowed/excluded filters and wraps each tool. The code moved verbatim fromAgentSession._refreshToolRegistry.AgentSessionnow calls both. Everything session-specific (tool_search adoption, runner binding, prompt snippets, activation) stays in the session, in the same order.sdk.tsexports the bootstrap for hosts.
No behavior change (Z1)
This is a move, not a rewrite: the session builds the same definitions, sources, wrappers and order as before. A session-less runtime still needs a session manager for the runner's constructor (today's ExtensionRunner signature); bootstrapRuntime defaults it to an in-memory one that nothing writes during registry construction. Running a wrapped extension tool without a session needs the ExtensionContext split, which is RT2.
Verification
- RED first:
test/runtime/bootstrap-registry.test.tsfailed before the change (module not found), commit 91488956ec. - GREEN: the same test passes at the head. It checks that a bootstrapped runtime and an
AgentSessiongive the same definitions, sources, order and wrapped tools for no filter, excluded tools and allowed tools, plus the absolute expected names and an extension tool replacing a base tool. - Mutation proof (each must fail the test, and did): dropping the excluded-tools filter fails the "excluded tools" case; stopping extension tools from replacing a same-named base tool fails the replacement case.
- Z1 focused run: 38 test files that exercise registry construction (tool filters,
getAllTools,customTools, extension tools, tool_search, reload): 327 tests passed. bun run check: passed.
The plan places this test at test/runtime/ (the row's write manifest), not test/suite/.
Summary by cubic
Extracts tool-registry construction from AgentSession into session-less runtime bootstrap functions so a runtime without an agent loop or session can build the same registry. The session code and behavior are unchanged.
bootstrapRuntime()builds built-in tool definitions (or the base-tools override), the composed filesystem policy, and theExtensionRunnerfrom loaded extensions, moved verbatim fromAgentSession.buildToolRegistry()merges built-in, extension, and SDK tools, applies default/allowed/excluded filters, wraps each tool, and returns the allowed-tool predicate, moved verbatim fromAgentSession.AgentSessioncalls both. Session-specific work (tool_search adoption, runner binding, prompt snippets, activation) stays in the session in the same order. Builtin-path detection moves to the shared module as well.- The runner's constructor still requires a session manager, so
bootstrapRuntime()defaults to an in-memory one that nothing writes during registry construction. Running a wrapped extension tool without a session needs the ExtensionContext split, which is follow-up work. bootstrap.tsis exported fromsdk.ts, and the changelog fragment records the new SDK entry points.
The new test proves a session-less registry matches an AgentSession registry for matching inputs, including excluded and allowed tool filters and extension-tool replacement of a same-named base tool.