feat(coding-agent): build the tool registry through a session-less runtime bootstrap (RT1)

Merged
CO
23d ago
+418-129

Closes #5219. Part of #4360.

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 the ExtensionRunner from loaded extensions. The code moved verbatim from AgentSession._buildRuntime.
  • buildToolRegistry() merges built-in, extension and SDK tools, applies the default/allowed/excluded filters and wraps each tool. The code moved verbatim from AgentSession._refreshToolRegistry.
  • AgentSession now calls both. Everything session-specific (tool_search adoption, runner binding, prompt snippets, activation) stays in the session, in the same order.
  • sdk.ts exports 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.ts failed before the change (module not found), commit 91488956ec.
  • GREEN: the same test passes at the head. It checks that a bootstrapped runtime and an AgentSession give 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 the ExtensionRunner from loaded extensions, moved verbatim from AgentSession.
  • buildToolRegistry() merges built-in, extension, and SDK tools, applies default/allowed/excluded filters, wraps each tool, and returns the allowed-tool predicate, moved verbatim from AgentSession.
  • AgentSession calls 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.ts is exported from sdk.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.