GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge idle-hook steering and schema nudges (X22, X23) and the 2.3.0 f… · rphang/opencode-workflows@3b0b612

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README.md
  • docs
    • OPENCODE-API-NOTES.md
    • PARITY.md
    • design
      • steering-and-live-tree.md
  • src
    • mailbox.ts
    • opencode
      • children.ts
      • idle.ts
      • permissions.ts
      • runner.ts
      • submit.ts
    • plugin
      • setup.ts
  • tests
    • helpers
      • fake-opencode-ctx.ts
      • plugin-harness.ts
    • parity
      • extensions.test.ts
      • script-api.test.ts
    • unit
      • idle-hook.test.ts
      • mailbox.test.ts
      • opencode-runner.test.ts
      • runner-steer.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ Set them in the environment of the opencode server. They work with every install
508508
| `MAX_STRUCTURED_OUTPUT_RETRIES` (or `OPENCODE_WORKFLOW_MAX_STRUCTURED_OUTPUT_RETRIES`) | `5` | Attempts a schema agent gets before `agent()` throws. |
509509
| `OPENCODE_WORKFLOW_FREEFORM` | unset (on) | `0`, `false`, `no` or `off` registers no `workflow_script` tool, like the `freeformTool: false` option. |
510510
| `OPENCODE_WORKFLOW_RPC_CONTROL` | unset (on) | `0`, `false`, `no` or `off` makes the live tree's RPC read-only, like the `rpcControl: false` option. |
511+
| `OPENCODE_WORKFLOW_IDLE_HOOK` | unset (on) | `0`, `false`, `no` or `off` registers no `experimental.idle` hook (opencode 2.3+). Without it, a steering message that lands as an agent finishes still reaches it through an extra turn, and a schema agent that forgot `workflow_submit` is re-prompted in a new turn instead of nudged in the same one. |
511512
| `OPENCODE_WORKFLOW_DATA_DIR` | `$XDG_DATA_HOME/opencode/workflows`, else `%LOCALAPPDATA%\opencode\workflows` (Windows) or `~/.local/share/opencode/workflows` | Run transcripts, stored as `<dir>/<sessionID>/<runId>/`. The `dataDir` plugin option wins over it. |
512513

513514
## How it compares to Claude Code
Collapse file

‎docs/OPENCODE-API-NOTES.md‎

Copy file name to clipboardExpand all lines: docs/OPENCODE-API-NOTES.md
+24-2Lines changed: 24 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ the 2.3.0 packages and `tsc` is clean against their types.
3434
- **Failure text:** the `{type:"idle", outcome:"failed"}` context message carries
3535
`error: {type, message, status?}` (#53826). An interrupted step keeps its closed text and its
3636
assistant message gets `error: {type:"aborted", message:"Step interrupted"}` (#60674). Tokens of an
37-
interrupted step are still not counted.
37+
interrupted step are still not counted. The runner reports the idle marker's error and skips
38+
aborted messages when it reads a result or an error (P23).
3839
- **`experimental.idle` session hook:** runs when a session finishes model work with nothing pending,
3940
before it goes idle; input admitted from it (e.g. `synthetic`) continues the same execution
4041
(`core/session/runner/llm.ts`; `/goal` uses it). On 2.0.15 registering the name succeeds and never fires.
42+
Details: hooks are per Location (the instance of the session's directory runs them), run in
43+
sequence and are awaited; a rejected callback is a defect that fails the execution. After the
44+
hooks, `SessionInbox.has(…, "input")` counts any pending steer or queued item, `resume:false`
45+
included, so a steer admitted up to that check continues the execution. The event's
46+
`background` lists running shells/subagents/images with the owning `sessionID`. It does not run
47+
after an interrupted or failed execution. The plugin uses it for X22/X23 ("Inbox and steering").
4148
- **Location eviction:** `LocationActivity` no longer evicts a location with an active execution or
4249
background job (#57416); `experimental.location_idle_timeout` overrides the 60-minute timeout.
4350
- **`ctx.permission.assert({sessionID, agent?, action, resources, save?, metadata?, source?})`** asks
@@ -113,7 +120,8 @@ the 2.3.0 packages and `tsc` is clean against their types.
113120
within milliseconds and `get().outcome` is `"failed"`. `context()` contains **only**
114121
`[user, {type:"idle", outcome:"failed"}]`, with no assistant message and no error text. When an
115122
assistant message does exist, `error: {type, message, status?}` is set on it *(types)*. The
116-
runner reports that message, or a generic "agent session failed (terminal error)".
123+
runner reports that message, or a generic "agent session failed (terminal error)". (2.3.0: the
124+
failed idle marker carries the error itself, and the runner reports it first.)
117125

118126
## Inbox and steering (X01–X08)
119127

@@ -168,6 +176,20 @@ Messages for an agent that has no session yet are appended to its first prompt i
168176
0.2, messages went out with `resume:true`, which could start a successor turn after the runner
169177
had given up verifying: that turn ran unread and its tokens were never counted.)
170178

179+
**opencode 2.3+: the `experimental.idle` hook** *(source; not yet live-verified)* closes most of
180+
that race inside the execution (`src/opencode/idle.ts`, X22/X23). The plugin instance registers it
181+
at setup (unless `OPENCODE_WORKFLOW_IDLE_HOOK=0`) and keeps a map of its live children (session id
182+
→ mailbox, schema, stopping). When a child is about to go idle the hook stops its mailbox
183+
(`finishing`), awaits sends in flight, and returns with the window reopened when a sent message is
184+
not in `context()` yet: it waits in the inbox, so opencode continues the same execution with it.
185+
A later message is refused `finishing` rather than parked. For a schema agent without an accepted
186+
submission it then sends the re-prompt text as a `resume:false` steer (a nudge, counted in the P21
187+
budget through the submit registry). The verification and wake above stay as the fallback for
188+
2.0.15, worktree children (their hook runs in the worktree instance, which has no mailbox; it can
189+
still nudge through the shared storage), a hook that hit its 3 s cap, and interrupted or failed
190+
turns. The plugin does not subscribe to `session.inbox.delivered` instead of checking
191+
`context()`: the check is still needed for the fallback paths, and one mechanism is simpler.
192+
171193
## RPC, events and TUI plugins (X11–X16)
172194

173195
Verified live on 2.0.15: a throwaway spike (local `.tsx` TUI plugin) and the packaged plugin
Collapse file

‎docs/PARITY.md‎

Copy file name to clipboardExpand all lines: docs/PARITY.md
+3-1Lines changed: 3 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,16 @@ Design: [`docs/design/steering-and-live-tree.md`](design/steering-and-live-tree.
141141
| X19 | The agent's model is shown in `/workflows <runId>` and `workflow_control status` (a `model:` line per agent), in the RPC `list`/`status`/`delta` agent views (`model`) and on the TUI agent rows. A running agent whose live step (`session.step.started`) runs on another model than the recorded one shows the live one. A phase without a `meta.phases[].model` label shows the model its agents share (`PhaseSummary.agentModel` in run.json; the RPC phase view keeps listing up to two distinct models). TUI rows show the model in short form when narrow: the provider goes first, then the variant (`gpt-5.4-mini`), then the name is shortened and dropped after the activity; status, counts, tokens, cost and elapsed time always show. A phase label that is a `provider/model` ref is shortened the same way | EXT | `live-tree.test.ts` "X19 …" ×2<br>`tui.test.ts` "X19 …" ×2 |
142142
| X20 | The task notification of a run that failed, or that has agents whose `agent()` call gave the script nothing, carries `<agent-failures>` (after `<warnings>`/`<steering>`, before `<script-path>`): `N of M agents returned no result (a failed, b stopped, c null[, d running]):`, then at most 10 lines `#<i> "<label>" <status>[ (agent() threw)][ in workflow "<name>"]: <first line of the error>` (labels and errors whitespace-folded, label ≤ 60, workflow name ≤ 40, error ≤ 160 characters; `returned null` for a completed/cached agent whose value was null; `stop_agent` shows as `failed: stopped by user`, P51; `(agent() threw)` for a schema agent whose output never validated, P21, `AgentRecord.threw`; `in workflow` for an agent a nested `workflow()` started, `AgentRecord.workflow`), then `… and K more: workflow_control {action:"result", runId:"<id>"} lists failed agents first.` The whole block is capped at 2,800 bytes of UTF-8 (`FAILURE_BLOCK_BYTES`): the per-line caps count characters, so lines that would overflow (3-digit index, `(agent() threw)`, nested workflow, multi-byte text) are folded into the `… and K more` count instead, and it stays under 3 KB with 1000 failing agents. A failed run with no such agent says "No agent failed: the error above was raised by the script itself (this includes agent() calls refused before an agent started: budget, agent cap, invalid options/schema)." Limit: a refused `agent()` call (budget, 1000-agent cap, schema preflight) leaves no agent record, so only that wording acknowledges it; inside `pipeline`/`parallel` it becomes a silent `null` that neither block names (an engine-side refusal counter is a follow-up) | EXT | `delivery.test.ts` "X20 …" ×7<br>unit `plugin.test.ts` "X20 …" ×1<br>e2e `results.test.ts` (live) |
143143
| X21 | `workflow_control {action:"result", runId, agent?, offset?}` shows the parent model what each agent of a FINISHED run (completed, failed or stopped; also a resumed run, and a run read from disk after a plugin reload) returned, right away, before or after its notification arrives. Without `agent` (or with `""`): a header `Run <id> <status>: M agents: a completed, b cached, c failed, d stopped, e null`, then one row per agent, failed, stopped and null ones first, then the rest by index: `#i "label" status [phase] (workflow <name>) <tokens> tokens → <first line ≤ 100>` or `error: <first line ≤ 120>`; 50 rows per page with the footer `Rows X–Y of M. Next: {action:"result", runId:"<id>", offset:Y}`. `agent` is a string: `"9"` or `"#9"` is an index (when that index exists; a different agent labeled `"9"` is then named in a note), anything else an exact label; an ambiguous label lists up to 20 candidates, an unknown one is an error with the agent count. One agent: status, phase, nested workflow, `cached: replayed from run <id>; did not run again`, model, child session id, usage, duration, the first 500 characters of the prompt, the full error, warnings, its last 5 steering messages (each ≤ 500 characters), the kept worktree, then its return value (a string as is, anything else as indented JSON), 50 000 characters per page with `chars X–Y of Z; next offset Y`; a null agent says `agent() returned null to the script (<reason>)` (`agent() threw in the script (…)` for P21). While the run is running or paused it returns the P77 status note byte for byte, never an output. No other parameters: the fields models filled out of habit in the eval (`agentIndex`, `label`, `status`, `limit`, `maxChars`) are ignored, so a filled-in `status:"completed"` cannot hide failed agents. Scoped like every run action (P75); workflow agents cannot call it (P60) | EXT | `results.test.ts` "X21 …" ×15<br>e2e `results.test.ts` (live) |
144+
| X22 | opencode 2.3+ `experimental.idle` hook, steering side: when a workflow child of this plugin instance finishes its model work, the hook moves its message window to `finishing` and waits for the sends in flight; a sent message not yet in the child's context waits in its inbox, so opencode continues the SAME execution with it (no wake, no extra turn) and the window reopens. A message posted after that point is refused `finishing` (X02) instead of being parked. Other sessions are ignored (the `metadata.workflowRunId` tag is looked up once per session and cached). The hook never rejects (a rejected hook would fail the child) and stops after 3 s. Nothing depends on it: on 2.0.15 it registers and never fires, and a worktree child (hook in the worktree instance, which has no mailbox), a timed-out hook or an interrupted turn take the X03 wake. `OPENCODE_WORKFLOW_IDLE_HOOK=0` (also `false`, `no`, `off`) registers no hook; nothing is registered when `ctx.session.hook` is missing | EXT (source-verified, not live-verified on 2.3.0: `core/session/runner/llm.ts`, `plugin/goal.ts`) | `extensions.test.ts` "X22 …" ×2<br>unit `idle-hook.test.ts` "X22 …" ×9 |
145+
| X23 | opencode 2.3+ `experimental.idle` hook, structured-output side: a schema agent (P21) that stops without an accepted `workflow_submit` is nudged in the same execution with the runner's re-prompt text (the last validation error when its attempt submitted invalid output), as `synthetic({delivery:"steer", resume:false, metadata:{workflowRunId, workflowNudge:n}})`. Not when the agent is being stopped, its own subagent or image job is still running (that job's notice wakes it and the hook runs again), its runner has finished, or the attempt budget is spent. Nudges share the `MAX_STRUCTURED_OUTPUT_RETRIES` budget with invalid submissions and runner re-prompts: the submit registry counts each attempt once (an invalid submission followed by a stop is one attempt), then the JSON fallback or `schema_failed` follow as before. A worktree child is nudged by the worktree instance through the shared storage, whose copies are ordered by a revision number. Messages sent during the nudged continuation are delivered (X01). With the hook off or absent the runner re-prompts in new turns (P21 unchanged) | EXT (source-verified, not live-verified on 2.3.0) | `extensions.test.ts` "X23 …" ×2<br>unit `idle-hook.test.ts` "X23 …" ×9, `opencode-runner.test.ts` "P21 X23 …" ×4 |
144146
| X24 | Freeform `workflow_script` tool (opencode 2.3.0 freeform tool input): a NEW inline script sent as raw text instead of JSON-escaped `{script}`. Input schema `{script: string}` (exactly one required string property, as opencode requires) with `freeform: {type: "text"}`; execute always receives `{script}` and takes the same launch path as `workflow {script}` (same output, P02; persisted script and `scriptPath`, P04; P03 errors). A single code fence wrapping the whole input is stripped. Any other key with a value (a JSON call from a model without freeform input) returns `status:"async_launched"` with the error `workflow_script takes only the script; use the workflow tool for args, name, scriptPath, resumeFromRunId or budget`, and nothing runs. `options.permission: "workflow"`: opencode hides a tool whose permission key (`options.permission ?? name`) is wholly denied, so every deny of `workflow` (workflow children P60, Plan mode, user and agent rules) hides it too; there is no separate rule. The session `context` hook drops it from requests whose model's `capabilities.freeform` (from `ctx.model.list()`, cached 5 min) does not list `text`; an unknown model keeps it (it still works as a JSON tool). The `workflow` tool's schema, options and description are unchanged (Claude Code parity, prompt caching). Opt out with the plugin option `freeformTool: false` or env `OPENCODE_WORKFLOW_FREEFORM=0` (`false`, `no`, `off`). The authoring reference tells the model to use it for new inline scripts when it is offered | EXT (the model-side raw-text encoding is opencode's and is not live-verified here) | `tool-surface.test.ts` "X24 …" ×11, "P01 …" (workflow tool unchanged) |
145147
| X25 | TUI agent dialog (`<leader>j`, palette "Workflows: agents (steer, stop, open)"): one searchable `ui.dialog.select` of the running and queued agents of the runs the tree shows (newest active run first, then by index), titled `#i label`, described `status · phase · model`, grouped by workflow name, starting on the agent selected in the panel. Search: `#3` or `3` lists that index first, then labels starting with the query, then labels, phases, workflow names and run ids containing it. Enter steers the agent (the `m` prompt); footer actions `ctrl+u` urgent steer (`M`), `ctrl+d` stop after a confirm (`x`) and `ctrl+o` open its session (a tab when tabs are on); `ctrl+n`/`ctrl+p` stay the list's own keys. Every action re-reads the agent's current row, so an agent that finished meanwhile gets the panel's toast instead, and one no longer listed a toast. The prompt or confirm an action opens replaces the dialog | EXT (not live-verified on 2.3.0) | `tui-client.test.ts` "X25 …" ×5 |
146148
| X26 | TUI sidebar (`sidebar.content` slot, after opencode's own sections): hidden when the session has no runs; a `Workflows` header with a collapse toggle only when there are more than two runs (the state is kept in the plugin's durable `storage.store`; collapsed, the header says `(1 running · $0.42)`: running and paused counts, or `n runs`, and the session's total cost); then up to 3 runs, active newest first, then the newest finished, then `+n more`. Each run: a dot colored by status, the name (≤ 24 cells), `<done>/<total>`, and a muted line: `[paused · ]<phase> · <n> running · <tokens> · $<cost>` while active (the last phase with running agents, else the first unfinished one), `<status> · <tokens> · $<cost>` once finished. Clicking a run opens the panel with that run selected and unfolded. A workflow child session's sidebar shows its parent's runs (the same mapping as the footer) | EXT (not live-verified on 2.3.0) | `tui-client.test.ts` "X26 …" ×3 |
147149
| X27 | TUI cold start: on opencode 2.3 `rpc.call` no longer waits for plugins to load, so the tree's first `list` can fail with `rpc.unavailable`. A `list` that throws is retried after 250, 500, 1000, 2000 and 4000 ms, then the tree gives up and says `workflows RPC unavailable (…); use /workflows` (`workflows list failed (…)` for another error). While it retries an unavailable RPC the panel only says `loading…`; another error is shown with `(retrying)`. The attempts reset on a successful list, on a target change (viewed session, scope) and when the host reports `plugin.updated`; a `delta` from the target Location while the tree is not ready lists again at once. A `list` answered `{ok:false}` is shown, not retried. The driver is host-agnostic (`src/client/sync.ts`) | EXT (not live-verified on 2.3.0) | `tui-client.test.ts` "X27 …" ×7<br>unit `client.test.ts` |
148150

149151
## Test evidence
150152

151-
`npm run test:parity` (`bun test tests/parity`) runs 355 tests in 15 files, and all pass. They
153+
`npm run test:parity` (`bun test tests/parity`) runs 359 tests in 15 files, and all pass. They
152154
enter at the highest level possible: the plugin's `setup()` over a fake opencode v2 Context
153155
(`tests/helpers/plugin-harness.ts`), then the `workflow` and `workflow_control` tools
154156
(`execute`), the slash commands, and the `<task-notification>` delivered through
Collapse file

‎docs/design/steering-and-live-tree.md‎

Copy file name to clipboardExpand all lines: docs/design/steering-and-live-tree.md
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@ const turn = async (text) => {
241241
`AgentRecord.messages` tracks each message's status: `held`, then `sent`, then `delivered`
242242
(when the id shows up in `context()` at `close()`), or `undelivered` (warning).
243243

244+
**opencode 2.3+ (X22, X23).** The `experimental.idle` session hook runs right before a child's
245+
execution ends, and input admitted by then continues that execution. The hook (`src/opencode/idle.ts`)
246+
finds the child in its instance's live map and calls `mailbox.quiesce()`: `open` → `finishing` and
247+
in-flight sends awaited, without consuming the window's sent list (so `close()` still verifies).
248+
If a sent message is not in `context()` yet, it is in the inbox and the execution continues with
249+
it: the window reopens. Otherwise later messages are refused `finishing`. For a schema agent with
250+
no accepted submission the hook then nudges it in the same execution (the re-prompt text as a
251+
`resume:false` steer, counted in the P21 budget) and reopens the window. The protocol above stays
252+
unchanged as the fallback: the hook never fires on 2.0.15, a worktree child's hook runs in another
253+
instance without the mailbox, and a hook that exceeds its 3 s cap or a turn that was interrupted
254+
does nothing.
255+
244256
## A.5 Engine and host changes
245257

246258
- `LiveAgent` gets `mailbox: AgentMailbox`, created at `callAgent` time in state `pending`, and it
Collapse file

‎src/mailbox.ts‎

Copy file name to clipboardExpand all lines: src/mailbox.ts
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// change cannot interleave): pending → held; between → sent at open(); open → sent now; finishing →
1414
// refused `finishing`; closed → refused `finished`. close() awaits every send that started while the
1515
// window was open, so a message accepted just before the turn ended is always verified by the runner.
16+
// quiesce() (the opencode 2.3+ idle hook, X22) moves open → finishing ahead of close() and awaits the
17+
// sends in flight; the hook reopens the window when the execution goes on (open()).
1618

1719
export const MAX_MESSAGE_CHARS = 4000
1820
export const MAX_MESSAGES_PER_AGENT = 20
@@ -174,6 +176,18 @@ export class AgentMailbox {
174176
return sent
175177
}
176178

179+
/**
180+
* Idle-hook side (X22): the agent's execution is about to end. An open window moves to `finishing`
181+
* (new messages are refused until the next open()), and every send in flight is awaited. Unlike
182+
* close(), the window's sent list is kept, so close() still returns it for verification. Resolves
183+
* with the messages sent in this window so far.
184+
*/
185+
async quiesce(): Promise<SentMessage[]> {
186+
if (this._state === "open") this._state = "finishing"
187+
while (this.inflight.size) await Promise.all([...this.inflight])
188+
return this.windowSent.map((s) => ({ ...s }))
189+
}
190+
177191
/** Runner side: confirms (or not) that a held or sent message reached the agent. */
178192
report(id: string, status: "delivered" | "undelivered"): void {
179193
const e = this.entries.find((x) => x.id === id)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.