Skip to content

feat(auto-advisor): add OpenCode Auto Advisor - #61

Closed
capyBearista wants to merge 16 commits into
mainfrom
feat/auto-advisor
Closed

capyBearista wants to merge 16 commits into
mainfrom
feat/auto-advisor

Conversation

@capyBearista

@capyBearista capyBearista commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Draft PR for @capybearista/opencode-auto-advisor (unpublished 2.0.0), rebuilt from current main after the original planning branch diverged substantially. Supersedes #54.

An OpenCode V2-only server plugin providing an independent Advisor through explicit consultation plus experimental automatic routing, with an optional TUI companion. Implementation is approved as of 2026-09-28 and may proceed on this draft PR.

Linked issues

Refs #47 (tracking)

Active execution contracts:

Issues #49, #51, and #52 are consolidated into the active contracts/epic.

Current design baseline

  • OpenCode V2 only; exact @opencode/plugin@2.0.21 and @opencode/ai@2.0.21 (verified against host source).
  • Zero-argument explicit advisor().
  • Fresh/stateless shared Advisor service; canonical normalized Executor state with separate fingerprint / Jev routing / Advisor consultation projections.
  • Root eligibility from OpenCode's permission-filtered tool snapshot plus root-session check.
  • Automatic routing defaults to off; observe records telemetry only; v1 automatic routing uses OpenCode Zen only.
  • Jev routing behind AdvisorRouter; default chain jev-1.13-free -> jev-1.13; every new opportunity restarts at the top; bounded transient retry; whole-chain failure fails open for that opportunity only.
  • Routing combines atomic advisor_would_help probability and 0-4 consequence score through deterministic thresholds; routing.maxConsultationsPerTurn default 1; explicit advisor() does not consume the automatic budget.
  • Current privileged advice via session.context.system; no fabricated tool call, synthetic message, Message.system, or session.synthetic().
  • Plus one bounded latest retained automatic review per session (best-effort async persistence, internal 8192-char cap; hook never awaits storage in either direction — telemetry is fire-and-forget, retained reads hydrate once per session in the background with the hook using only cached state, so a first request after startup may miss historical advice; fresh advice supersedes immediately; oversize delivered but not retained; write failure keeps the new review authoritative in-process; observe never hydrates).
  • Review status RPC + lifecycle events; one shared TUI store; server works without the TUI.
  • Package publishes on npm latest; current release tooling already supports V2 packages on latest.

Configuration surface

Seven v1 knobs:

  1. advisor.model
  2. advisor.timeoutMs (default 300000, soft)
  3. routing.mode (off | observe | active)
  4. routing.models (ordered Zen chain)
  5. routing.advisorWouldHelpThreshold (0.7)
  6. routing.consequenceThreshold (3)
  7. routing.maxConsultationsPerTurn (1)

Internal retry timing, fingerprint mechanics, telemetry retention, and retention bounds are intentionally not additional user knobs in v1.

Implementation authorization

Implementation is approved as of 2026-09-28.

The coding orchestrator may proceed against the governing plan and active issue contracts. It should continue to re-check current repository/OpenCode V2 behavior, refine implementation details and tests from runtime evidence, document the initial routing thresholds/consequence anchors, and keep the durable plan synchronized with material findings.

No additional approval pause is required for work within the approved scope. Material changes to requirements, architecture, public interfaces, privacy/security behavior, configuration semantics, release strategy, or acceptance criteria require plan updates and explicit re-approval.

Quality / readiness

  • implementation plan explicitly approved (2026-09-28)
  • package/config and explicit Advisor path complete
  • context fidelity + media placeholder behavior validated
  • routing/fingerprinting/policy/budget tests complete
  • Jev fallback/retry behavior validated
  • off / observe / active runtime scenarios validated
  • telemetry storage + read-only RPC export validated
  • retention/supersession semantics validated (Gate 2 review, findings remediated)
  • package registered in existing release policy/guard
  • package/root documentation reconciled with implementation
  • Changeset added when releasable
  • bun run typecheck && bun run lint && bun run test && bun run build (package 495/0 + root fresh green)
  • real OpenCode V2 package-root runtime smoke completed
  • USER manual testing (docs/plans/opencode-auto-advisor-manual-test.md, 19 cases) — next phase

History (labeled, preserved for context)

  • Remediation (2026-09-30): 23-item pass; canonical projections; suite 286/0; live 2.0.19 probes 6/6.
  • Simplification (2026-10-02): removed multi-record history/compaction protocol/custom permission engine; one bounded retained review; 7 knobs; Oracle Gate 1 APPROVE-WITH-CHANGES; suite 478/0; live 2.0.21 active runs accepted/delivered with retained real advice.
  • Final remediation (2026-10-02): retention off the hook critical path (in-memory overlay + best-effort per-session durable queues); fresh-supersedes-old in the same dispatch; oversize tombstones; write failure keeps new in memory; parser hardening; TUI listener isolation; code-reviewer Gate 2 WITH FIXES, all remediated; suite 488/0.
  • Storage critical path (2026-10-02): telemetry fire-and-forget with failures consumed; retained hydration exactly-once background (sync cached peek on hook, absence cached, late hydration loses to replace/forget, clear() tombstones unknown sessions); 7 new tests incl. guard-removal probes; code-reviewer gate 0 critical/important (1 minor remediated); suite 495/0; narrow live 2.0.21 probes 4/4 PASS (fresh delivery, in-process + restart reinjection with documented first-request miss, status RPC, headless).

No merge/publish/dogfood in this pass — branch is manual-test-ready, awaiting USER manual testing.

Implements #48: V2 server-only package, sparse global config, zero-arg advisor(), canonical context serialization with media placeholders, routing domain with fingerprinting, AdvisorRouter seam, AND policy and per-turn budget. Gate review passed with fixes applied.
Non-obvious discoveries from the Phase 1 build: four-file release registration coupling, first-publish 404 behavior, package-list sync, git-restore safety-net forms, turbo --force evidence rule, reviewer routing, plus auto-advisor router strictness and Phase 2 limits.

Context:
- Updated AGENTS.md with release, git, testing, and review-routing conventions
- Updated packages/opencode-auto-advisor/AGENTS.md with router strictness and known limits
V2 table row, five-port counts, structure/context lists, V2-correct JIT patterns, and three repaired doc links from the bootstrap audit drift report.

Context:
- Updated AGENTS.md managed sections (structure, JIT index) and V2 boundary counts
- Updated three package AGENTS.md files with corrected relative doc links
… context

Automatic routing consumes the assembled session.context request instead of reconstructing persisted history; explicit advisor() merges a turn-matched hook snapshot with the current assistant delta. Fingerprints are SHA-256 digests, media names/URIs are sanitized, and snapshot/turn state is bounded.

Context:
- Updated packages/opencode-auto-advisor/AGENTS.md with the three-domain architecture, digest fingerprints, sanitization rules, and known limits
Route automatic consultations through OpenCode Zen behind the AdvisorRouter seam (free-first chain with bounded retry and per-class fallback), record digest-only observe telemetry with read-only RPC, and deliver accepted advice as system-role context with same-turn lifetime. Baseline moves to OpenCode 2.0.19 (upstream stateless-generation session-attribution fix); live off/observe/active validation passes on 2.0.19.

Context:
- Updated AGENTS.md with the gh-api PR-body workaround and self-contained delegation-briefs rule
- Updated packages/opencode-auto-advisor/AGENTS.md with Zen adapter, delivery, telemetry, and host-contract notes
@capyBearista capyBearista added enhancement New feature or request new-plugin type:milestone Milestone or workstream issue and removed type:milestone Milestone or workstream issue labels Sep 30, 2026
Replace the shared unbounded transcript with a canonical normalized
state plus separate fingerprint, Jev routing, and Advisor consultation
projections; make automatic consultation model-aware with a 25% reserve
budget, priority retention, and lazy construction; tighten the Zen
deadline to 5s with distinct retry/fallback/fail-open outcomes; skip
paid models the public bearer rejects via a session ineligibility cache;
fail the context hook open end to end; and reconcile the durable docs
with the resulting behavior.

Context:
- Root AGENTS.md: gh issue-body endpoint, gh issue comment --jq gap,
  pipe-tail masking, delegated-lane validation protocol rule
- Package AGENTS.md: state representations, model-aware budget, Zen
  chain semantics, RPC silent-strip note, telemetry label nuances
The host-path round-trip test imported effect directly, which resolves
in local node_modules but not in a clean install, failing CI. Replace
it with a dependency-free assertion that every emittable event field
is declared in the schema.
share one stateless tool-free advisor service across explicit and automatic paths with model-aware projection, root-only eligibility and native permission checks.

use privileged system delivery for new and retained advice, bounded history with exact compaction proof, soft timeout and operation lifetime guards.

add optional TUI companion with lifecycle RPC plus reconnect and ordering fixes, alongside docs and coverage for the 18-case manual procedure.

Context:
- Updated packages/opencode-auto-advisor/AGENTS.md with live-verification findings (child-session identity, loopback host isolation, bundled Zen instrumentation, synthetic provenance)
…ke suite

Replace multi-record advice history and the compaction-absorption protocol
with one bounded latest retained review per session; persistence is
best-effort and never suppresses same-dispatch delivery. Drop the custom
permission engine (host 2.0.21 filtering suffices: root check plus
advertised tool), collapse the TUI to one shared store, and shrink the
built-artifact smoke to a seam check. All settled behavior preserved.

Context:
- Updated packages/opencode-auto-advisor/AGENTS.md (retained-review model, seam-check smoke, live-probe learnings)
- Reconciled package README, governing plan, and manual-test checklist
try {
clearTimeoutFn(pulseTimer);
} catch {
undefined;
try {
unsubscribe();
} catch {
undefined;
try {
queryAbort?.abort();
} catch {
undefined;
try {
queryAbort?.abort();
} catch {
undefined;
try {
offConnected?.();
} catch {
undefined;
try {
next.dispose();
} catch {
undefined;
try {
off?.();
} catch {
undefined;
try {
free?.();
} catch {
undefined;
try {
unregisterFooter();
} catch {
undefined;
try {
unregisterComposer();
} catch {
undefined;
…edes-old

Retention leaves the Executor critical path: in-memory overlay is
authoritative, durable writes are per-session best-effort, fresh advice
ships alone, oversize tombstones, write failure keeps the new review.
Parser hardened, TUI listeners isolated, smoke + docs reconciled.
…uidance

Cold-start TUI discovery, smoke-scenario upkeep, free-Zen Advisor gate,
and the 2.0.21 RPC path-param shape bit live verification; capture them
where future probes will look.

Context:
- Updated packages/opencode-auto-advisor/AGENTS.md testing/TUI guidance
  with four non-obvious findings from real-host 2.0.21 probes
…cal path

Telemetry is fire-and-forget (failures consumed); retained hydration is
exactly-once background with sync cached peek, absence cached, late
hydration loses to replace/forget, observe never hydrates. clear() now
tombstones unknown sessions. 7 new tests (495/0); code-reviewer gate
clean; root gates fresh green; 2.0.21 probes 4/4 PASS.

Context: storage-critical-path remediation pass; branch manual-test-ready.
Reviewer-surfaced invariants from the hook-critical-path pass: telemetry
queue backpressure, retained test-file coupling with reads() pins, the
synchronous hydration-assignment mechanism, fail-open negative caching,
and the clear-vs-forget cleanup contract.

Context:
- Updated packages/opencode-auto-advisor/AGENTS.md with 3 entries
  (telemetry backpressure, hook-contract pins, cleanup contract)

Copy link
Copy Markdown
Owner Author

Superseded by #94. OpenCode 2.2.0 removed the experimental Evaluation/System One API this PR is built on, so it can't run on current OpenCode. #94 rebuilds the plugin on 2.2.0's Decision API and instruction entries (see #47 and #50 for the updated scope). This branch stays for reference.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request new-plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants