Skip to content

refactor(hooks): extract host registration and guard (#168) - #267

Merged
abogartz merged 2 commits into
abogartz:mainfrom
WhollyMindless:refactor/168-hook-registration
Nov 3, 2026
Merged

abogartz merged 2 commits into
abogartz:mainfrom
WhollyMindless:refactor/168-hook-registration

Conversation

@WhollyMindless

Copy link
Copy Markdown
Contributor

Final planned registration slice of #168: move host hook registration and the measured-usage subscription into src/events.ts, the structural host context types into src/core/host.ts, and the fail-soft hook guard into src/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 d286e7a after 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:

  • Focused registration coverage, host/event fidelity, session isolation, serve-host and compaction suites: 65 pass / 0 fail on Windows and WSL Linux.
  • Full Windows merge gate: typecheck/lint pass (498 advisory warnings); unit 862 pass / 26 skip / 0 fail; E2E 30 pass / 0 fail.

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.

@ocsi-triager ocsi-triager Bot added the review:requested Human-admitted for autonomous review by ocsi-reviewer label Nov 3, 2026

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.ts vs src/events.ts:62-222) shows exactly two deltas — const onCompactCapture = getCompactCapture(); at src/events.ts:169 and return measuredController; at src/events.ts:222. Matches the body's declared change.
  • Call-time capture seam equivalent: old compaction hook read the let onCompactCapture closure at hook execution; new code calls getCompactCapture: () => onCompactCapture (src/index.ts call 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).
  • measuredController created inside registerHooks (src/events.ts:186), returned, retained at the same const in setup; subscription stays fire-and-forget void IIFE; cleanup path unchanged.
  • guarded moved verbatim to src/core/hooks.ts:2-8; types moved verbatim to src/core/host.ts with PluginCtx exported.
  • 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 errors
  • bun run lint — 498 warnings = baseline
  • bun run test — 874 pass / 14 skip / 0 fail
  • bun 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.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

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.
@abogartz
abogartz merged commit 6deb697 into abogartz:main Nov 3, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.15.13 🎉

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

released review:requested Human-admitted for autonomous review by ocsi-reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants