Repository navigation
feat(opencode)!: implement coord_comment/coord_watch natively in TypeScript - #302
Conversation
…Script R1 RCA fix (closes #301): `.opencode/plugins/coord.ts` and `pr-watch.ts` were thin harness bindings that DELEGATED to shell scripts in the `marketplace` submodule (`coord.sh`, `gh_watch.sh`). A plugin's own code must load with the plugin, from the SAME ref — but `marketplace` is a generated corpus pinned by gitlink that LAGS, so `coord_comment` failed with "coord.sh not found — sync the marketplace pin". Operator directive (2026-09-29): harness-INDEPENDENT tooling is SHELL; OpenCode plugins are PURE TypeScript; DO NOT MIX. So the plugins are now native TS and spawn NO `.sh` — no dependency on any script file, hence NO `marketplace` pin. - NEW `.opencode/lib/watch.ts` — the ONE native TypeScript GitHub watcher engine (REST v3 + poll loop: item parsing, snapshot, event decision, wake-line format, rate-limit backoff; async + `context.signal`-aware) shared by both plugins. - `coord.ts` — builds the verb body + the canonical two-line footer (`Agent:` FIRST, `Assisted-by:` LAST) and POSTs via the GitHub REST API in-process; `coord_watch` polls natively and returns the wake line. - `pr-watch.ts` — native poll loop via the shared engine (no `gh_watch.sh`); delivery unchanged (`ctx.session.synthetic` V2 / `noReply` V1). - `scripts/check-opencode-coord.mjs` — static (NO `.sh` / NO `spawnSync` / NO `Bun.spawn`), unit (the SHARED CONTRACT), and live (the REAL binary vs a LOCAL capture server via `GITHUB_API_URL`). - `.opencode/instructions.md`, `pr-watch.items` — document the native architecture. The shell family (`coord.sh`, the watcher family) stays UNCHANGED in `marketplace` for bash / Claude Code / Codex / CI. The two are deliberately TWO harness-native implementations (not a forked copy); they share ONE contract — verb set, footer order, event vocabulary + wake-line format, item grammar — asserted by the gate so they cannot drift. Agent: native-coord-plugin Assisted-by: OpenCode DeepSeek V4.1 Flash (analysed on a live system)
Review — BLOCKHead SHA: Change class: opencode harness config — code/config ( Security screen: PASS — no secrets/egress, no weakened gate, no scope mismatch (the Blocks
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
R3 sign-off — the operator directs the two-implementation splitThe operator directs the clean architecture for the OpenCode coordination surface:
This deliberately yields two harness-native implementations of ONE shared contract — the closed verb set, the canonical two-line footer, the event vocabulary, the item grammar, and the wake-line format. That is an authorized R3 divergence, not a forked copy: each implementation is native to its harness. This sign-off is posted at the operator's explicit direction; under the account-gated sign-off model the posting ACCOUNT is the control. Conditions (binding):
Agent: |
…l-hard rate limits Fixes ALL round-1 blocks AND the operator's API-efficiency requirements in ONE commit. Review round 2: - R5/B14(d): the removed exports (resolveScript, spawnCapture, watchArgv, SpawnResult, COORD_SH, GH_WATCH_SH) are proven gone by an EXECUTED tree-wide word-boundaried grep (zero live hits; historical CHANGELOG mentions only, permitted by R5). - R4: named constants RATE_FLOOR/BACKOFF_FACTOR/MAX_BACKOFF_S + POLL_FLOOR (60); coord_watch is BOUNDED by default (DEFAULT_WATCH_TIMEOUT_S = 3600). - R3: the gate now ACTUALLY compares the shell family vs the TypeScript output where the shell is present (Layer B3 runs coord.sh and diffs), SKIPPING visibly where it is absent (never depends on the pin). The "cannot drift" claim is removed from every surface (coord.ts, lib/watch.ts, instructions.md) and replaced with a specification statement; the operator-directed R3 divergence is recorded in the maintainer-account sign-off on the PR thread. API efficiency (operator requirement): - ONE GraphQL request per poll for N items (one alias each) — calls-per-poll = 1, independent of item count. - Fingerprint (state|merged|updatedAt|comments|verdict|commit) skips unchanged items; an idle watch costs one batched call per interval. Delta events only on change; state events always evaluated. - Rate limits FAIL HARD: REST 403/429 or GraphQL RATE_LIMITED throws RateLimitedError; the tool returns a distinct RATE-LIMITED message and the watch STOPS (no spin, never "no event"). The remaining quota is read FREE from the response's rate header, so a near-exhausted quota backs off visibly. - POLL_FLOOR = 60; sub-floor intervals are refused. Tests prove (against a REAL local HTTP server): calls-per-poll = 1 for 3 items, a 403 rate-limit yields the distinct failure with exactly one request (no spin), and a sub-60s interval is refused. Agent: native-coord-plugin Assisted-by: OpenCode DeepSeek V4.1 Flash (analysed on a live system)
Review — BLOCKHead SHA: Change class: opencode harness config — code/config ( Blocks
Comment dispositions
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — PASSHead SHA: Security screen: PASS — no added secrets, no egress beyond the plugin's own GitHub API calls ( Checklist: All applicable rules PASS or NA (R0–R10 answered with HOW; ADE/SDD/B16 placement N/A — no Comment dispositions:
Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
…rogress plugin (supersedes #313) (#320) * feat(opencode)!: agent_control — full subagent control on the agent-progress plugin (#302 architecture) Add a second native tool, agent_control, to .opencode/plugins/agent-progress.ts: list / interrupt / delete / wait / confirm_stopped. interrupt stops a RUNNING session without deleting it (ctx.session.interrupt); delete drives `opencode session delete` (session + child sessions); wait is a BOUNDED ctx.session.wait; confirm_stopped re-reads the transcript and ASSERTS no new turns (the CONFIRM-it-stopped rule). interrupt/delete/wait REQUIRE an explicit session id (never `all`) and report what was stopped, so a session another slug owns is never silently killed. Pure TypeScript: the control half's ONE execFile drives the opencode CLI (a tool, like `gh` in coord.ts), never a .sh — no marketplace pin. Also: the gate gains static + unit control coverage (closed action set, the explicit-session rail, a real read-only SQLite fixture, refusals) and the live layer now calls BOTH agent_progress and agent_control list (read-only — the test never interrupts/deletes a real session); charly.yml runs the gate in verify; instructions.md documents both tools; AGENTS.md gains the dispatcher row. * test(opencode): live layer unwraps the Code Mode return (content string) The live snippet now normalizes the tool return (a plain content string in Code Mode, or { content }) so the model-call assertions read the real report. * fix(opencode): remove dead control constants + wire KNOWN_TOOLS (review round 1) - Delete CONFIRM_WINDOW_S (zero references; its comment described a window the confirmStopped implementation does not have — an R1 comment/code divergence). - KNOWN_TOOLS was zero-reference: wire it via unknownTools(), which the report now uses to surface any tool outside the known set ('tools+' line); the gate asserts it. - Move the delete children query into CONTROL_SQL (named SQL, R4). * fix(opencode): one shared collector + counts query, honour `all`, delete dead code (review round 2) R3 — extract ONE shared helper `collectAnalyses(db, {now, windowMin, sinceMin, limit, signal})` plus `VERDICT_RANK`/`sortByVerdict`/`resolveLimit`/`resolveSinceMin` and route BOTH `agent_progress` (all) and `agent_control` (list) through them; drop the duplicated `CONTROL_SQL.turns` and reuse `SQL.counts` in `turnStats` (ONE counts query). R1 — honour the schema-advertised `all` input via `resolveTarget` (`all:true` forces the whole set; `all:false` REQUIRES an explicit `session`). B14(a)/R5 — delete the zero-caller `SQL.lastEvent` and the unused `stale` local in `classify()`. R10 check-coverage — the gate now asserts resolveTarget honours `all`, the limit/sinceMin clamps, collectAnalyses enumerates the real store and stops on abort, and sortByVerdict orders loudest-first. * fix(opencode): reconcile the artifact display/verdict, correct two diverging comments, gate `wait`+`confirm_stopped` (review round 4) R1 — the report printed `artifact merged · gh pr merge …` while the verdict said `no artifact` (the display used `a.artifacts`, the verdict `a.recentArtifacts`). A RECENT artifact in a stale session is now COMPLETION evidence → DONE ("landed an artifact … then quiet"), and when only OLDER artifacts exist the display labels them "(none recent — transcript history)" — display and verdict can no longer contradict. R1 — the `reportStatus` doc-comment claimed BOTH classifier and report call it; only `classify` does. Comment corrected to match the code. R1 — the analyzeSession artifacts fallback comment claimed a short-session rationale; the fallback is unconditional (and it is LONG/truncated tails that hit it). Comment corrected. B12 — Layer B now drives `runControl({action:"wait"})` through a stubbed ctx.session.wait for BOTH the idle and the bounded-timeout result (and the missing-primitive refusal), plus the `confirm_stopped` ACTION (STOPPED and STILL RUNNING vs the baseline) — a path with no test fails to exist. Gate: 113 unit / 121 live, 0 FAIL. * fix(opencode): pin the artifact-completion DONE arm + document it; prove the verify step runs (review round 5) B12 — the round-4 `recentArtifact → DONE` arm shipped untested (every artifact fixture also had finish=stop, so DONE came from reportStatus regardless). Added the discriminating fixture: stale + RECENT artifact + NO finish=stop ⇒ DONE, using the REAL store tool-input shape so the artifact is truly extracted. Verified it FAILS without the arm (2 assertions). R1 — the DONE definition in .opencode/instructions.md and the agent_progress tool description now documents the artifact-completion case (a landed artifact with the session then quiet), matching classify. R10/B6 — the added verify step is proven through the charly task verify path it is wired into: `[pass] check — the agent-progress monitor+control plugin … exit=0`. Gate: 116 unit / 124 live, 0 FAIL.
Summary
R1/R3 architecture fix (closes #301), review round 2 + API-efficiency optimization —
all fixed in ONE commit. The OpenCode coordination plugins are implemented NATIVELY in
TypeScript: no
.shdelegation, nomarketplace-pin dependency.Operator directive: harness-INDEPENDENT tooling is SHELL; OpenCode plugins are PURE
TypeScript; DO NOT MIX. The maintainer-account R3 sign-off for this split is on this
thread.
Round-2 fixes (first-round BLOCKs)
R5/B14(d) — the removed exports are proven gone by an EXECUTED tree-wide
word-boundaried grep, pasted directly here (zero live hits; the only hits are
historical
CHANGELOG/entries, which R5 permits):R4 — named constants
RATE_FLOOR/BACKOFF_FACTOR/MAX_BACKOFF_S/POLL_FLOOR;coord_watchis bounded by default (DEFAULT_WATCH_TIMEOUT_S = 3600).R3 — the gate now ACTUALLY compares the shell family vs the TypeScript output
(Layer B3 runs
coord.sh --dry-runand diffs), SKIPPING visibly where the shell isabsent (never depends on the pin). The "cannot drift" claim is removed from every
surface (
coord.ts,lib/watch.ts,instructions.md) and replaced with aspecification statement the TS implements and the gate pins.
API-efficiency optimization (operator requirement)
per item; calls-per-poll = 1 regardless of item count.
(
state|merged|updatedAt|comments|verdict|commit) means an idle watch costs exactly onebatched call per interval; delta events (comment/verdict) are only evaluated on a
change (state events are arm-baseline-driven and always evaluated).
RATE_LIMITEDthrowsRateLimitedError; the tool returns a distinctRATE-LIMITED …message and the watchSTOPS (no spin, never misreported as "no event"). The remaining quota is read FREE
from the batched response's
x-ratelimit-remainingheader, so a near-exhausted quotabacks off VISIBLY without an extra call.
POLL_FLOOR = 60— a sub-60s interval is refused;clampIntervalenforces it.How tested
Verbatim gate output (72 PASS, 2 SKIP, 0 FAIL; exit 0).
SHELL_COORD_SCRIPTpointsLayer B3 at the REAL
coord.shso the shell-vs-TS comparison RUNS instead of skipping.This is the COMPLETE output — no elision:
Without the shell present, those 3 PASS lines are replaced by the one visible
SKIP shell-family comparison: no marketplace/scripts/coord.sh present (never depends on the pin).R5/B14(d) — EXECUTED tree-wide sweep (real commands + output):
API-efficiency proof (from the gate above, against a REAL local HTTP server):
calls-per-poll = 1 for 3 items (seed + 1 poll = 2 requests for 3 aliased items)—one batched GraphQL request per poll, aliases
i0..i2in the SAME body.a 403 rate-limit surfaces a distinct RATE-LIMITED message (fail hard)+the rate limit does NOT spin — exactly 1 request+NOT misreported as a wake line or a timeout.coord_watch refuses a sub-60s interval (POLL_FLOOR).LIVE_OPENCODE=1— the REAL v2.0.18 binary, end to end (exit 0):A REAL invocation, captured manually (same plugin + binary + hermetic server): the
native POST produced the canonical body, and the native batched poll returned
MERGED acme/widget#1 (unblocked).Rulebook compliance
/charly-internals:git-workflow,agents,plugin,marketplace,root-cause-analyzer,strict-policy.the fix removes the dependency. Zero gate failures/warnings.
marketplaceis genuinely untouched.thread). The gate now RUNS the shell family and diffs it (Layer B3) where present;
the "cannot drift" claim is removed from all three surfaces.
RATE_FLOOR/BACKOFF_FACTOR/MAX_BACKOFF_S/POLL_FLOORnamed;coord_watchbounded byDEFAULT_WATCH_TIMEOUT_S;rate limits fail hard (no unbounded retry/spin). The
gh auth tokenfallback is a TOOL,not a
.sh.TO the new behaviour.
marketplace/scripts/…prose is gone.layer drives the REAL binary and SKIPS visibly when unset.
drive a REAL local HTTP server (not a
fetchmock). SKIPs are visible.marketplacestays at its recorded gitlink.Change classification
.opencode/plugins/*,.opencode/lib/*,.opencode/instructions.md,scripts/check-opencode-coord.mjs,scripts/check-pr-watch.mjs) — code/config, not docs-only.node scripts/check-opencode-coord.mjs(static + unit + B3shell-vs-TS + real-HTTP efficiency/rate-limit/floor),
node scripts/check-pr-watch.mjs,node scripts/check-opencode-plugin.mjs.to end; the full
charly task verifypin audit needs all 408 submodules initialised,which the session worktree does not carry).
Relates to #296; closes #301.
Agent:
native-coord-plugin· sessionses_f15cfc994ffeTpji7qe5u3aWDfAssisted-by: OpenCode DeepSeek V4.1 Flash (analysed on a live system)