Skip to content

refactor(capture): extract setup orchestration (#168) - #266

Merged
abogartz merged 3 commits into
abogartz:mainfrom
WhollyMindless:refactor/168-capture-runtime
Nov 3, 2026
Merged

abogartz merged 3 commits into
abogartz:mainfrom
WhollyMindless:refactor/168-capture-runtime

Conversation

@WhollyMindless

Copy link
Copy Markdown
Contributor

Partial contribution to #168: extract opt-in capture configuration, subscriptions and dispatch from setup into src/capture/runtime.ts.

Setup calls configureAutoCapture with the host object, workspace and existing gate/guard callbacks, then connects its compaction callback and cleanup. Capture's cooldown map stays at module scope, shared across setup instances. Trigger constants and test reset helpers retain their existing exports from src/index.ts through re-exports. The host object and API receivers are preserved.

The moved orchestration block matches base d286e7a after indentation normalization. Options, trigger vocabulary, context/model calls, gate inputs, evidence, fail-soft handling and abort behavior are retained. This extraction preserves the existing in-flight cleanup limitation tracked separately in #211. Hook registration and the generic hook guard remain in setup for the final smaller extraction; this PR does not close #168.

The governed-write-path assertion now checks src/capture/runtime.ts for capture's runWriteGate call instead of its former home in src/index.ts. No assertion was removed or relaxed. Temporarily replacing that invocation with a bypass name makes the relocated assertion fail with zero gate calls; the actual invocation was restored before validation.

Validation, Bun 1.4.4:

  • Focused capture/compaction/session-race/crop/event-fidelity suites: 59 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.
  • Gate-path mutation check: 0 pass / 1 fail, at the expected missing-call assertion.

Claim posted on #168 after #265's approval; automation labels untouched. This is based directly on main, with no dependency on the other open extraction PRs. Please feel free to defer, narrow or reject it 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: 576ee8dd95cc69aef73e5338bb5a957f5f49c12e (diff key 4069791c14286e0acca53f321a662edfe0cdbb649431d1844f4ca7b596252f3e)

Contract: #168 (WhollyMindless, trusted). This is the auto-capture-scheduling boundary from the issue's "Possible boundaries" list — the third slice after #261 (status assembly) and #265 (session identity). Spec hash 34f8af443344b8b8, unchanged since the #261/#265 reviews; spec frozen. No osi-spec-hash: anchor exists on the issue because this app lacks issues:write (403 on POST issues/168/comments, re-confirmed this run) — triager or maintainer should post osi-spec-hash: 34f8af443344b8b8.

Conformance to "Boundaries and verification" (quoted verbatim from #168):

  1. "Preserve tool schemas and responses, repository visibility, lock ordering, capture defaults, and the exact injected bytes/invalidation behavior, including #162/#165."
    — Evidence: the extracted body is byte-identical to the removed block modulo indentation. Normalized diff (removed lines from src/index.ts vs src/capture/runtime.ts:29-271, leading whitespace stripped) differs only in the wrapper plumbing: export function configureAutoCapture(ctx, deps) { + let onCompactCapture declaration + return { onCompactCapture, cleanup: captureCleanup };. All capture defaults preserved verbatim: autoCapture === true master switch, parseModelRef skip-with-warn, capability guard, captureOnCompact !== false, master-switch warning (runtime.ts:96-101, 108-111, 253, 264-268). No injection, tool-schema, visibility, or lock file touched — diff is exactly 3 files (git diff --numstat: runtime.ts +271/−0, index.ts +9/−245, negative-eval.test.ts +2/−2).

  2. "Keep the current lifetime of process-shared cooldown state; moving it into an instance would change behavior."
    — Evidence: lastCaptureRun is module-level in runtime.ts:41 (process-wide, same shape as before), not per-configureAutoCapture call. resetCaptureCooldowns re-exported from index.ts:41; all 14 test files importing it from ../src/index.ts (capture.test.ts:20, capture-compaction.test.ts:33, capture-sid-race.test.ts:25, security-*, lock-partial-outcomes, lifecycle-evidence, injection-framing) resolve unchanged. TURN_END_EVENTS/CAPTURE_EVENT_TYPES/captureTriggerFor likewise re-exported; event-fidelity.test.ts:19 import intact.

  3. "Preserve the existing hook-level regressions and run the project's checks."
    — Evidence: no capture/security test file modified except the tripwire path update in negative-eval.test.ts:549 (gatesIn("src/index.ts") → gatesIn("src/capture/runtime.ts")). Not a weakening: the regex counts runWriteGate\s*\(; the one real call moved to runtime.ts:183 (count = 1 ≥ 1), and the sole remaining runWriteGate string in index.ts:543 is a comment with no paren, so the old assertion would now read 0 — pointing it at the new home keeps the tripwire naming the actual write path. No .skip, no deleted assertion, no widened tolerance anywhere in the diff.

  4. "Keep that as one independently reviewable PR." — Evidence: single boundary (auto-capture scheduling), 3 files, no other extraction mixed in.

Seam check: onCompactCapture is still a setup-closure variable read at call time by the compaction hook (index.ts:375, 484-485), assigned synchronously during setup from the returned value (index.ts:552) before any event can fire; captureCleanup flows to the same setup cleanup return. CAPTURE_EVENT_TYPES still feeds the plugin_load heartbeat subscribed= field (index.ts:593).

Commands run (measured):

  • bun run typecheck — 0 errors
  • bun run lint — 498 warnings = baseline
  • bun run test — 874 pass / 14 skip / 0 fail (888 tests, 83 files)
  • bun run test:e2e — 30 pass / 0 fail (src/ changed)
  • CI gh pr checks: lint, test, test-windows, smoke — 4/4 pass

Findings:

  • nit — src/capture/runtime.ts has no trailing newline; every sibling in src/capture/ ends with \n. Cosmetic; lint does not flag it.

No P0/P1. Approving; human merges.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Fixed the trailing-newline nit in 8d25530; no code or behavior change. Thank you for the extraction and state-lifetime verification.

@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: 8d25530fb38809a1ba5b1fbd8238caea882e53b5

Contract: #168 (trusted author WhollyMindless) — extract opt-in capture configuration, subscriptions and dispatch from setup into src/capture/runtime.ts; cooldown map stays module-scope shared; trigger constants and test reset helpers retain exports from src/index.ts via re-exports; moved orchestration block matches base d286e7a. Spec hash 34f8af443344b8b8 — unchanged since the #261/#265 reviews; spec frozen.

Delta since prior APPROVE at 576ee8d: exactly one commit style(capture): add trailing newline — adds the missing final newline to src/capture/runtime.ts (git diff 576ee8d..8d25530 shows only the \ No newline at end of file marker removal). This resolves the nit from my prior review. All criteria previously evidenced at 576ee8d carry over unchanged; re-verified at this head:

  • Extracted body byte-identical modulo indent; configureAutoCapture wrapper only (prior normalized removed-vs-added diff).
  • Cooldown lastCaptureRun module-level, process-shared: src/capture/runtime.ts:41.
  • Re-exports keep the 14 test importers working: src/index.ts.
  • Tripwire move test/negative-eval.test.ts:549 legitimate (real runWriteGate call at runtime.ts:183; index.ts:543 is a comment).

Measured at this head:

  • bun run typecheck — 0 errors
  • bun run lint — 498 warnings = baseline
  • bun run test — 874 pass / 14 skip / 0 fail (888 total, matches prior head)
  • bun run test:e2e — 30 pass / 0 fail (src/ changed)
  • CI: lint / test / test-windows / smoke all pass

No P0/P1 findings. Nit (trailing newline) resolved at this head. Human merges.

Resolve import conflicts: keep abogartz#265's session-context extraction and
abogartz#266's capture/runtime.ts extraction together. Symbols whose uses moved
out of src/index.ts on either side are dropped from its imports; the
capture wiring consumes the gateContext dependency from
createSessionContext, matching runtime.ts's CaptureDependencies.
@abogartz
abogartz merged commit d50964a into abogartz:main Nov 3, 2026
7 of 8 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.

Proposal: separate responsibilities in plugin setup (src/index.ts)

2 participants