Skip to content

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

Closed

Description

@WhollyMindless

Would you find a staged, behavior-preserving separation of responsibilities in src/index.ts useful?

Maintenance benefit

The reviewed v0.14.17 entry point is about 1,770 lines. Length alone is not the concern: one setup closure combines host compatibility, session identity, tool workflows, injection-cache policy, status assembly, and capture scheduling. Understanding a change to one policy requires following shared closure state and callbacks across those other responsibilities.

There are already useful foundations to preserve, including schema.ts, SessionLru, the shared resolver tree, and the existing regression suites.

Possible boundaries

These are options for discussion, not a prescribed directory layout or a request to extract everything:

  • Injection epochs: own the epoch/prompt state, eviction, rendering, refresh decisions, and compaction invalidation.
  • Host adaptation and session identity: normalize supported event shapes and expose explicit per-call identity.
  • Tool registration and workflows: keep schemas and descriptions near their handlers, with explicit dependencies instead of access to the entire setup closure.
  • Auto-capture scheduling: own trigger eligibility, cooldowns, subscription cleanup, and dispatch to the existing capture/gate helpers.
  • Status assembly: share store-summary calculations between the chat report and status payload.

Suggested first step

If the direction fits, the epoch section looks like a coherent first extraction. Its interface could handle prompt updates, context delivery, compaction, and status inspection, leaving setup to wire it to the host. The important benefit would be making the cache policy readable in one place with its dependencies explicit.

Keep that as one independently reviewable PR. Other extractions could be accepted, deferred, or dropped separately. Coordinate with active work touching index.ts, especially #158; no existing fix should wait on this reorganization.

Boundaries and verification

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. This proposal makes no performance claim and needs no new framework or dependency.

Which, if any, of these boundaries would make the project easier for you to maintain? A smaller extraction or keeping the current arrangement are both reasonable choices. No implementation is attached; this issue is for your direction on scope and timing.

The separate, smaller gate-outcome typing proposal is #167; neither proposal depends on accepting the other.

Activity

  1. WhollyMindless commented on Oct 29, 2026

    @WhollyMindless
    ContributorAuthor

    I am taking the suggested injection-epoch boundary as a separate, optional PR. #170 already covers host compatibility parsing, so this extraction will preserve that event-listener wiring and leave session identity, tool workflows, and capture scheduling in setup. I will check a combined tree with #158, #169, #170, and #171 before posting. This is one stage of the proposal, not an attempt to close the broader design discussion.

  2. added
    severity:low
    on Oct 30, 2026
  3. WhollyMindless commented on Oct 31, 2026

    @WhollyMindless
    ContributorAuthor

    Additional evidence for the existing Status assembly part of this proposal, from the review of main bf9f4d233064c0594834c44d72648ac532ff13e8 (ARCH-2):

    memory_status in src/index.ts (around 1258–1283) recomputes store summaries after buildPayload in src/injection-epochs.ts (around 103–131) already performs corresponding work. The reviewed path has two loadAll/readLedger passes and duplicated summary logic. This supports sharing a summary calculation if that extraction is still useful; it does not justify another issue for the same refactor.

    Please keep the visibility-policy decision separate: #213 asks whether blocked-write details and aggregate store counts should be repository-scoped. A behavior-preserving extraction should preserve today's semantics until that decision is made, or explicitly implement the accepted policy with regression coverage.

    This is evidence for your consideration, not a claim or implementation reservation. Happy to leave the arrangement as-is or take a narrower approved step.

  4. abogartz commented on Nov 1, 2026

    @abogartz
    Owner

    The architecture review synthesis (2026-11-01) promotes this proposal to consensus High: both independent reviewers reached the same conclusion without consulting each other (2026-10-31 finding O1; 2026-11-01 finding S1). Verified at 2a2cb92: 1,739 lines, 14 inline tool registrations, and the memory_update handler alone spans roughly lines 551-872.

    The layout both reviews converged on: one module per tool under src/tools/ exporting name + schema + handler; src/events.ts for the six event hooks; src/index.ts reduced to the composition root that lists them; the shared guarded/gateContext closures (src/index.ts:286, :294) moved into an exported helper so handlers stay independent of plugin wiring.

    Execution notes: incremental, one tool per commit - the 15.7-second unit suite makes this refactor cheap. Start after #241 (characterization e2e matrix) lands: this split moves exactly the registration and wiring paths that today only five of fourteen tools exercise on a real host.

    Severity label updated from low to high.

  5. added
    severity:high
    and removed
    severity:low
    on Nov 1, 2026
  6. self-assigned this
    on Nov 1, 2026
  7. abogartz commented on Nov 1, 2026

    @abogartz
    Owner

    Taking the staged split, starting with the epoch section as the first independently reviewable PR. #243 (merged) is the acceptance net; the #162/#165 byte-stability tests are the oracle. Freeze rule applies: PRs touching src/index.ts rebase onto each landed extraction, not vice versa. Steps: epochs -> capture scheduling -> per-tool registration -> host/session identity -> status assembly.

  8. abogartz commented on Nov 1, 2026

    @abogartz
    Owner

    The agreed architecture landed as a staged pair:

    Behavior-preserving: declaration bodies verbatim; unit 842/0 and e2e 30/0 identically on the restructured tree. The PR body encodes the folder rules in machine-processable form for reconcile tooling. #220 (runWriteGate verdict decomposition) now has its home — gate/gate.ts — and follows as its own PR.

    Reconcile rule: while #247/#248 are open, PRs touching src/ rebase onto #248, not the reverse.

  9. 7 remaining items

  10. WhollyMindless commented on Nov 3, 2026

    @WhollyMindless
    ContributorAuthor

    Second remaining slice is ready in #265: per-setup session binding and call-context helpers extracted into src/identity/session-context.ts. The moved block matches base after indentation normalization. Existing identity regressions pass 31/31 on Windows and Linux; full Windows gate passes (862 unit tests, 26 skips; 30/30 E2E). This is standalone from main and does not depend on #261. Capture/hook orchestration remains the later stage; automation labels unchanged. Please feel free to defer, narrow or reject.

  11. WhollyMindless commented on Nov 3, 2026

    @WhollyMindless
    ContributorAuthor

    The identity slice (#265) is approved with no requested changes. Claiming the capture-orchestration part of the final stage as a separate PR: move capture configuration, subscriptions and dispatch behind explicit dependencies while preserving process-wide cooldowns and existing cleanup behavior (#211 remains separate). Hook registration will remain a subsequent smaller extraction so each diff stays reviewable. No competing automation claim or overlapping open capture PR is present; labels will remain untouched.

  12. WhollyMindless commented on Nov 3, 2026

    @WhollyMindless
    ContributorAuthor

    Capture orchestration is ready in #266. Cooldowns stay process-wide, existing capture exports remain available, and cleanup behavior is preserved (#211 stays separate). Focused capture suites pass 59/59 on Windows and Linux; full Windows gate passes (862 unit tests, 26 skips; 30/30 E2E). The governed-path assertion follows the moved gate call and was verified to fail when that call is removed. Hook registration and the generic guard remain the final smaller slice after guidance or merge. No automation labels changed; feel free to defer, narrow or reject.

  13. WhollyMindless commented on Nov 3, 2026

    @WhollyMindless
    ContributorAuthor

    Capture orchestration (#266) is approved; its cosmetic trailing-newline nit is fixed. Claiming the final smaller slice: hook registration, the measured-usage subscription, shared runtime context types and the generic fail-soft hook guard. I will preserve registration order, synchronous caller binding, the live compaction-capture seam, and cleanup ownership. No competing claim or overlapping hook PR is present; automation labels remain untouched.

  14. WhollyMindless commented on Nov 3, 2026

    @WhollyMindless
    ContributorAuthor

    Final planned hook-registration slice is ready in #267: src/events.ts owns hook registration and measured usage; core modules hold the structural host types and fail-soft guard. Setup retains cleanup ownership and supplies a live compaction-capture callback lookup. Existing assertions are unchanged. Focused suites pass 65/65 on Windows/Linux; full Windows gate passes (862 unit tests, 26 skips; 30/30 E2E). Together #261, #265, #266 and #267 cover the remaining checklist; keep #168 open until they are merged/reconciled. I will maintain compatibility as main advances. Automation labels unchanged; feel free to defer or reject.

  15. added a commit that references this issue on Nov 3, 2026
  16. abogartz-opencode-self-improvement commented on Nov 3, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.15.12 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  17. added 3 commits that reference this issue on Nov 3, 2026
  18. abogartz-opencode-self-improvement commented on Nov 3, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved 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

Metadata

Metadata

Assignees

Labels

releasedseverity:high

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions