Repository navigation
refactor(hooks): extract host registration and guard (#168) - #267
Conversation
There was a problem hiding this comment.
Head reviewed: abbb895acf1bdead5511a2b186a5d1a79df0471d
Contract: #168 (trusted author WhollyMindless, spec hash 34f8af443344b8b8 — unchanged since #261/#265/#266 reviews; spec frozen). Registration slice: move host hook registration + measured-usage subscription to src/events.ts, host context types to src/core/host.ts, fail-soft guard to src/core/hooks.ts.
Behavior preservation, verified against the tree:
- Moved hook/listener block byte-identical modulo indent: normalized removed-vs-added diff (d286e7a..abbb895
src/index.tsvssrc/events.ts:62-222) shows exactly two deltas —const onCompactCapture = getCompactCapture();atsrc/events.ts:169andreturn measuredController;atsrc/events.ts:222. Matches the body's declared change. - Call-time capture seam equivalent: old compaction hook read the
let onCompactCaptureclosure at hook execution; new code callsgetCompactCapture: () => onCompactCapture(src/index.tscall site) at the same point. Later setup assignment site untouched. - Hook order preserved: tool before/after → session context/prompt/compaction → measured listener (
src/events.ts:63,73,102,129,151,187). measuredControllercreated insideregisterHooks(src/events.ts:186), returned, retained at the sameconstin setup; subscription stays fire-and-forgetvoidIIFE; cleanup path unchanged.guardedmoved verbatim tosrc/core/hooks.ts:2-8; types moved verbatim tosrc/core/host.tswithPluginCtxexported.- No test file, schema or response touched:
git diff --numstat=src/core/hooks.ts +9,src/core/host.ts +34,src/events.ts +223,src/index.ts +9/-239.
Measured at this head:
bun run typecheck— 0 errorsbun run lint— 498 warnings = baselinebun run test— 874 pass / 14 skip / 0 failbun run test:e2e— 30 pass / 0 fail (src/ changed)- CI: lint / test / test-windows / smoke all pass
Findings: nit only — no Closes #168 footer in the body (advising a trusted human; not a withhold reason). No P0/P1. Human merges.
|
Thank you for the verification. The missing closing footer is intentional: #261, #265 and #266 are still separate open stages, so merging #267 first should not close #168 prematurely. I will reconcile the combined tree and report completion on #168 after all stages land. No implementation changes are needed for this review. |
Resolve conflicts between abogartz#265's createSessionContext extraction and this PR's hook-registration extraction: setup now calls createSessionContext for identity/gate helpers and registerHooks (src/events.ts) for host hooks, with guarded imported from src/core/hooks.ts. Symbols whose uses moved out of src/index.ts on either side are dropped from its imports.
|
🎉 This PR is included in version 0.15.13 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Final planned registration slice of #168: move host hook registration and the measured-usage subscription into
src/events.ts, the structural host context types intosrc/core/host.ts, and the fail-soft hook guard intosrc/core/hooks.ts.Setup constructs the dependencies, awaits hook registration, and retains the returned subscription controller for its existing cleanup. Hook order is preserved: tool before/after, session context/prompt/compaction, then the measured listener. The compaction handler looks up its capture callback at call time through
getCompactCapture, preserving the existing seam populated later during setup. The host object is passed intact, retaining API receivers.The moved hook/listener block matches base
d286e7aafter indentation normalization and removal of the one explicit callback-lookup line. Identity binding before reads, injected-byte/invalidation decisions, contextual pulls, measured usage and cleanup behavior remain in the same order. No existing test assertion, schema or response is changed.Validation, Bun 1.4.4:
This is standalone from main, alongside #261 (status), #265 (identity) and #266 (capture). #168 should remain open until those stages are merged and reconciled. #211's capture cancellation contract, #213's status visibility decision, and #220's gate decomposition remain separate. Claim posted before work; automation labels untouched. Please feel free to defer, narrow or reject this contribution if you prefer another boundary or sequence.