Repository navigation
refactor(capture): extract setup orchestration (#168) - #266
Conversation
There was a problem hiding this comment.
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):
-
"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 fromsrc/index.tsvssrc/capture/runtime.ts:29-271, leading whitespace stripped) differs only in the wrapper plumbing:export function configureAutoCapture(ctx, deps) {+let onCompactCapturedeclaration +return { onCompactCapture, cleanup: captureCleanup };. All capture defaults preserved verbatim:autoCapture === truemaster switch,parseModelRefskip-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). -
"Keep the current lifetime of process-shared cooldown state; moving it into an instance would change behavior."
— Evidence:lastCaptureRunis module-level in runtime.ts:41 (process-wide, same shape as before), not per-configureAutoCapturecall.resetCaptureCooldownsre-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/captureTriggerForlikewise re-exported; event-fidelity.test.ts:19 import intact. -
"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 countsrunWriteGate\s*\(; the one real call moved to runtime.ts:183 (count = 1 ≥ 1), and the sole remainingrunWriteGatestring 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. -
"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 errorsbun run lint— 498 warnings = baselinebun 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.tshas no trailing newline; every sibling insrc/capture/ends with\n. Cosmetic; lint does not flag it.
No P0/P1. Approving; human merges.
|
Fixed the trailing-newline nit in 8d25530; no code or behavior change. Thank you for the extraction and state-lifetime verification. |
There was a problem hiding this comment.
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;
configureAutoCapturewrapper only (prior normalized removed-vs-added diff). - Cooldown
lastCaptureRunmodule-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:549legitimate (realrunWriteGatecall atruntime.ts:183;index.ts:543is a comment).
Measured at this head:
bun run typecheck— 0 errorsbun run lint— 498 warnings = baselinebun 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.
|
🎉 This PR is included in version 0.15.13 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Partial contribution to #168: extract opt-in capture configuration, subscriptions and dispatch from setup into
src/capture/runtime.ts.Setup calls
configureAutoCapturewith 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 fromsrc/index.tsthrough re-exports. The host object and API receivers are preserved.The moved orchestration block matches base
d286e7aafter 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.tsfor capture'srunWriteGatecall instead of its former home insrc/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:
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.