Skip to content

refactor(tools): split the tool registration block into src/tools modules (#168) - #247

Merged
abogartz merged 3 commits into
mainfrom
refactor/tool-registry
Nov 1, 2026
Merged

abogartz merged 3 commits into
mainfrom
refactor/tool-registry

Conversation

@abogartz

@abogartz abogartz commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Step 1 of the staged #168 split. src/index.ts: 1739 → 866 lines; the entry point keeps host wiring, hooks, capture scheduling and status plumbing.

What changed

  • Each of the 14 memory tools moved to its own module under src/tools/, registered by registry.ts in the original order. Shared closure access is now an explicit ToolDeps interface (deps.ts) — toolIds, bindSessionIdentity, ownerlessWriter, refuseOwnerlessWrite, gateContext, the epoch controller, noteHits, direct. A tool file can no longer reach into the setup closure.
  • The epochs-controller wiring moved above the tool transform because registration now references it eagerly. Runtime lifetimes unchanged: same process-shared lastCaptureRun cooldown maps, same session LRU, same lock ordering.
  • The recall scorer (scoreMemory) moved with the recall tool.

Behavior preservation

Schemas, descriptions and handler bodies are byte-moved, not rewritten. The acceptance proof is the net itself:

What did NOT change

Every ToolDef reaches the host through the same validated() wrapper in schema.ts; the load-smoke (MEMORY_TOOLS × real host) passes. No rename of any tool, arg, description, or result string.

Next steps on #168 (separate PRs)

  1. auto-capture scheduling out of the setup closure
  2. host adaptation / session identity helpers
  3. status assembly sharing
  4. then Decompose runWriteGate (583 lines) into ordered verdict steps #220 (runWriteGate verdict-step decomposition) with module boundaries in place.

Freeze rule: concurrent PRs touching src/index.ts should rebase onto this once it lands.

…ules (#168)

Each memory tool now lives in its own module under src/tools/, registered
through a small ToolDeps interface instead of reaching into the plugin setup
closure. src/index.ts drops from 1739 to 866 lines; the entry point keeps
host wiring, hooks, capture scheduling and status plumbing.

- Behavior-preserving move: schemas, descriptions and handler bodies are
  unchanged; the e2e characterization suite (#241) passed identically on the
  split tree, which is its purpose.
- The epochs-controller wiring moved above the tool transform because tool
  registration now references it eagerly; runtime lifetimes are unchanged.
- The recall scorer moved with the recall tool.
- e2e/coverage.test.ts now parses registrations from index.ts plus
  src/tools/* (the same gate, wider net); test/negative-eval.test.ts asserts
  the runWriteGate tripwire per write-path module instead of counting four
  calls inside index.ts.
- Next extractions from #168 (capture scheduling, host/session identity,
  status assembly) land as separate PRs on this foundation.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: APPROVE — scoped to e85a589

I found no blocking regression in this extraction against base 054815a. This review is for #247 only; #248 is queued separately, and our permissions fix #244 will remain a separate PR when adapted to the new layout.

Independent checks:

  • Parsed both trees and compared normalized ASTs: all 14 validated(schema, definition) calls match, including descriptions and execute bodies; the recall scorer and registration order also match.
  • After excluding imports, the extracted scorer, and the replaced transform registration, the remaining index.ts AST matches the base. I checked the dependency wiring and epoch-controller initialization move: the controller is initialized before registration, remains per setup, and retains the same dependency functions.
  • Windows / Bun 1.4.4: typecheck and lint pass; unit suite 843 pass, 11 skip, 0 fail. All four hosted checks are green at this head.

One inherited test issue, not a blocker introduced by this PR: the local full gate ends with 29 E2E passes and 1 failure in e2e/coverage.test.ts (every registered event hook has a tagged scenario). On a CRLF checkout, source.split("\n") leaves a trailing carriage return, so /@covers\s+(.+)$/ misses the tag lines. The same coverage test fails on base 054815a (3 pass / 1 fail). A temporary local change to source.split(/\r?\n/) makes all four coverage tests pass on this head; I restored the file afterward. The actual host scenarios passed. This warrants a small follow-up so the local Windows gate agrees with Linux; it is not evidence of changed tool behavior.

No branch changes pushed, and no need to fold #244 into this refactor. Happy for you to handle the CRLF follow-up in whichever PR fits your sequence.

In JavaScript, . never matches a carriage return and $ without /m
requires the end of the string, so "/@Covers\s+(.+)$/" never matched a
tag line on a Windows checkout with core.autocrlf: the coverage gate
reported every registered hook as untagged. Split the source on
\r?\n; verified green under both line conventions.
…245)

The Windows job turned red on #247 without touching these tests: a
starved --parallel=4 worker spends real time past Bun's default 5s
budget, the test dies, bun kills the dangling racer children, and
finish() rejects after teardown as "racer-d1 exited null". The margins
are measured, not theorized: on the GREEN windows run the prune-sweep
scenario took 5272ms and the viewer-mutation scenario 4990ms against
the 5s default. Bun also applies the default 5s to beforeEach/afterEach
even when the test carries a longer override, so lifecycle-evidence
failed at 8.3s in its hook with a 30s test timeout next door.

Give every test and hook in the three files this family keeps failing
(scenarios-consistency, concurrency, lifecycle-evidence) an explicit
30s budget. No assertion moves; only time is granted. Follows the
precedent set for the reader scenario (#174).
@abogartz

abogartz commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

The test-windows red is a real, recurring flake — rerunning would have just been a coin flip, so it is fixed instead, in d38e6a7 on this branch.

Mechanism (log: racer-d1 exited null, empty stderr, killed 2 dangling processes): a starved --parallel=4 worker spends real time past Bun's default 5s test budget → Bun kills the spawned racer children → finish() rejects after the test ended and surfaces as an unhandled error. The margins are measured, not theorized — on the green Windows run the prune-sweep scenario took 5272ms and the viewer-mutation scenario 4990ms against that 5s default. Same root cause as the earlier #248 red: Bun applies the 5s default to beforeEach/afterEach even when the test itself carries a longer override, which is why lifecycle-evidence died at 8.3s inside its hook next to a 30s-budget test.

Fix: explicit 30s budgets on every test and hook in the three files this family keeps failing — scenarios-consistency.test.ts, concurrency.test.ts, lifecycle-evidence.test.ts. No assertion moves; only time is granted (the precedent is the reader scenario's 30s, #174). #248 rebases onto it cleanly.

Also recorded on #245, which I am treating as the tracking issue for the Windows/parallel-runner contention family (base rate since Oct 25: Windows 17/137, Linux 10/175).

@abogartz
abogartz merged commit f459681 into main Nov 1, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.15.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants