Repository navigation
refactor(identity): extract session binding and call context (#168) - #265
Conversation
There was a problem hiding this comment.
Reviewed head 71d4b834e81c89a19f0b494df584188501d2c494 (diff key b604e7e9fe85e6733f0a568066d98baecc4bd334c0b0b50516418db6c7243bcf).
Contract — #168 (authored by WhollyMindless, trusted human). Governing boundary, verbatim:
Host adaptation and session identity: normalize supported event shapes and expose explicit per-call identity.
Verification clauses, verbatim:
Preserve tool schemas and responses, repository visibility, lock ordering, capture defaults, and the exact injected bytes/invalidation behavior, including #162/#165. Keep the current lifetime of process-shared cooldown state; moving it into an instance would change behavior. Preserve the existing hook-level regressions and run the project's checks.
Conformance (behavior-preserving extraction, one independently reviewable PR):
- Boundary matches — session binding + per-call identity extracted from the setup closure into
src/identity/session-context.ts(createSessionContext);src/index.ts−137/+8 wires it with explicit deps{ instanceDir, liveRoot }. - Moved code is byte-identical:
git show d286e7a:src/index.tslines 275–399, dedented 2 spaces, diff againstsrc/identity/session-context.ts:24-148→ IDENTICAL. All comments (#116/#127/#152 notes) carried verbatim. - Closure-capture equivalence — the only setup-scope variables the moved code reads are
ctx,instanceDir,liveRoot:liveRoot(index.ts:229) andinstanceDir(index.ts:234) areconst, never reassigned, so pass-by-value equals capture;ctxis never reassigned (noctx =inindex.ts) and the host object is passed intact so optional methods keep their receiver and are read at call time. - Per-setup state lifetime unchanged —
bindingSids,apiBindTried,apiBindOrderare created insidecreateSessionContext, invoked once per setup, exactly where the closures lived. Cooldown/gate state (writeEvidence,hasGateCheck,hasEngagement) remains process-shared, imported as before. - Regressions preserved and run — no test file touched; full suite green at head.
Commands run at head: bun run typecheck clean · 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 4/4 green (lint, test, test-windows, smoke).
Findings: no P0/P1.
Spec anchor: #168 body hash 34f8af443344b8b8 — equals the hash recorded when #261 was approved; spec unchanged since. No osi-spec-hash: comment exists on the issue (reviewer app lacks issues:write; prior anchor posts 403'd).
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.
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 📦🚀 |
Partial contribution to #168: extract per-setup session binding and caller-context construction from
src/index.tsintocreateSessionContextinsrc/identity/session-context.ts.Setup now constructs the helper once and passes its functions to the existing tool and capture wiring. The factory owns message/API lookup state, synchronous tool identity capture, gate-context construction, and ownerless-write responses. Its explicit inputs are the host's session lookup surface and this setup's workspace/verification roots. The original host object is retained so optional API methods keep their receiver and are read at call time.
The moved helper block matches base
d286e7aafter indentation normalization. Per-instance sets/LRU, provisional-versus-firm binding, API fallback order, gate reader/write/evidence context, and tool response text are preserved. Existing test assertions and hook wiring are untouched. Capture orchestration and the generic hook guard remain for the later stage; this does not close #168.Validation, Bun 1.4.4:
import typefor the new type-only dependency.This is independent of the status-summary slice #261 and based directly on main. Claimed on #168 after #261's approval and a competing-work check; automation labels left untouched. Please feel free to defer, narrow or reject it if you prefer another boundary or sequence.