Skip to content

refactor(identity): extract session binding and call context (#168) - #265

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

abogartz merged 2 commits into
abogartz:mainfrom
WhollyMindless:refactor/168-session-context

Conversation

@WhollyMindless

Copy link
Copy Markdown
Contributor

Partial contribution to #168: extract per-setup session binding and caller-context construction from src/index.ts into createSessionContext in src/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 d286e7a after 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:

  • Focused session-isolation, unbound-identity, unresolved-write, serve-host and session-scope suites: 31 pass / 0 fail on Windows and WSL Linux.
  • Full Windows merge gate: typecheck and lint pass (498 advisory warnings); unit 862 pass / 26 skip / 0 fail; E2E 30 pass / 0 fail.
  • Final typecheck/lint pass after removing an unused import and using import type for 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.

@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.

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):

  1. 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 }.
  2. Moved code is byte-identical: git show d286e7a:src/index.ts lines 275–399, dedented 2 spaces, diff against src/identity/session-context.ts:24-148 → IDENTICAL. All comments (#116/#127/#152 notes) carried verbatim.
  3. Closure-capture equivalence — the only setup-scope variables the moved code reads are ctx, instanceDir, liveRoot: liveRoot (index.ts:229) and instanceDir (index.ts:234) are const, never reassigned, so pass-by-value equals capture; ctx is never reassigned (no ctx = in index.ts) and the host object is passed intact so optional methods keep their receiver and are read at call time.
  4. Per-setup state lifetime unchanged — bindingSids, apiBindTried, apiBindOrder are created inside createSessionContext, invoked once per setup, exactly where the closures lived. Cooldown/gate state (writeEvidence, hasGateCheck, hasEngagement) remains process-shared, imported as before.
  5. 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).

@abogartz
abogartz merged commit 1b226e3 into abogartz:main Nov 3, 2026
4 checks passed
abogartz added a commit to WhollyMindless/opencode-self-improvement that referenced this pull request Nov 3, 2026
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 added a commit to WhollyMindless/opencode-self-improvement that referenced this pull request Nov 3, 2026
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-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