Repository navigation
refactor(tools): split the tool registration block into src/tools modules (#168) - #247
Conversation
…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
left a comment
There was a problem hiding this comment.
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.tsAST 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).
|
The Mechanism (log: Fix: explicit 30s budgets on every test and hook in the three files this family keeps failing — 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). |
|
🎉 This PR is included in version 0.15.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
src/tools/, registered byregistry.tsin the original order. Shared closure access is now an explicitToolDepsinterface (deps.ts) —toolIds,bindSessionIdentity,ownerlessWriter,refuseOwnerlessWrite,gateContext, the epoch controller,noteHits,direct. A tool file can no longer reach into the setup closure.lastCaptureRuncooldown maps, same session LRU, same lock ordering.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:
e2e/coverage.test.ts(the E2E covers 5 of 14 tools on a real host: characterization matrix for the nine untested tools and viewer routes #241 registration gate) now parses registrations fromindex.ts+src/tools/*— the same gate, wider net; it keeps the split from silently losing a tool.test/negative-eval.test.ts: the governed-path tripwire assertedrunWriteGateappears ≥4 times insrc/index.ts. With the split that location claim became wrong while the safety property stayed right, so it now asserts per write-path module (tools/remember.ts,tools/update.ts,tools/import.ts,index.tsfor auto-capture,init.ts) — strictly sharper than a count.What did NOT change
Every
ToolDefreaches the host through the samevalidated()wrapper inschema.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)
runWriteGateverdict-step decomposition) with module boundaries in place.Freeze rule: concurrent PRs touching
src/index.tsshould rebase onto this once it lands.