opencode-subagent-tools 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,42 @@ All notable changes to this project are documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.2.1 - 2026-11-18
9
+
10
+ ### Added
11
+
12
+ - Code Mode background jobs (`codemode`) are reported in `backgroundJob.kinds` and count as active work. OpenCode 2.3.1+ reports them through the `experimental.idle` hook; older versions never send this kind.
13
+
14
+ ### Changed
15
+
16
+ - Tested against `@opencode/plugin` 2.3.2.
17
+
18
+ ### Fixed
19
+
20
+ - A Code Mode idle item no longer falls into the unknown-kind path and marks its owner `stateUnknown`.
21
+
22
+ ## 0.2.0 - 2026-11-17
23
+
24
+ ### Added
25
+
26
+ - Background subagent activity tracking: the experimental idle hook, shell events, structured context probes, and a bounded background-job store. The hook is disposed on cleanup; `session.deleted` clears live and background state.
27
+ - `list`: `active`, `subtreeActive`, `activeDescendants`, `backgroundJob`, `activeCount`, `subtreeActiveCount`, and the `active`/`subtreeActive` filters. `status` remains execution-oriented; use `active` and `subtreeActive` for work that is still in progress.
28
+ - `usage`: `active`, optional `subtreeActive` with `includeDescendants`, `backgroundJob`, and background-aware lag flags.
29
+ - `cancel`: `active`, `backgroundJob`, an on-demand probe for idle/terminal targets, and `mayRemain`/`stateUnknown`.
30
+ - `cancel_descendants`: `activeCount`, `subtreeActiveCount`, `backgroundJobCount`, `backgroundJobMayRemain`, and per-target background jobs.
31
+ - `queue`: `queued`; `steer`, `queue`, and `context`: `active` and `backgroundJob`. `queue` waits for the current execution, not background jobs, which continue in parallel.
32
+
33
+ ### Changed
34
+
35
+ - Requires OpenCode 2.3.0+.
36
+ - `usageMayLag` covers active sessions with background work, not only running/unknown executions.
37
+
38
+ ### Fixed
39
+
40
+ - An idle event no longer overrides a known terminal status.
41
+ - `cancel` no longer prints only "no interrupt was needed" when an idle target owns background work.
42
+ - `cancel_descendants` reports idle background jobs instead of returning an unqualified "No running subagents".
43
+
8
44
  ## 0.1.0 - 2026-11-07
9
45
 
10
46
  ### Added
package/README.md CHANGED
@@ -6,7 +6,7 @@ descendants, steer or queue messages, and inject context.
6
6
 
7
7
  > Plugin ID: `subagent-tools`. Default tool namespace: `subagent`.
8
8
 
9
- Requires OpenCode 2.2.5+ with `ctx.session.list`.
9
+ Requires OpenCode 2.3.0+; tested against 2.3.2.
10
10
 
11
11
  ## Quick start
12
12
 
@@ -25,15 +25,15 @@ For manual/local installation, see [installation](docs/installation.md).
25
25
 
26
26
  ## Tools
27
27
 
28
- | Tool | What it does |
29
- | ----------------------------- | ------------------------------------------------------------ |
30
- | `subagent_list` | List child sessions with status, age, cost, and token usage. |
31
- | `subagent_usage` | Read cost, tokens, and current context for a session. |
32
- | `subagent_cancel` | Stop one session. |
33
- | `subagent_cancel_descendants` | Stop running descendants of the calling session. |
34
- | `subagent_steer` | Send an instruction at the child's next model request. |
35
- | `subagent_queue` | Queue a message as the next independent turn. |
36
- | `subagent_context` | Inject a synthetic context message without starting a turn. |
28
+ | Tool | What it does |
29
+ | ----------------------------- | ----------------------------------------------------------------------- |
30
+ | `subagent_list` | List child sessions with status, activity, age, cost, and token usage. |
31
+ | `subagent_usage` | Read cost, tokens, current context, status, and activity for a session. |
32
+ | `subagent_cancel` | Stop one session and report background work it cannot stop. |
33
+ | `subagent_cancel_descendants` | Stop running descendants and report idle background jobs. |
34
+ | `subagent_steer` | Send an instruction at the child's next model request. |
35
+ | `subagent_queue` | Queue a message as the next independent turn. |
36
+ | `subagent_context` | Inject a synthetic context message without starting a turn. |
37
37
 
38
38
  The plugin also registers a `subagent-tools` skill with operational guidance.
39
39
  See the [tool reference](docs/reference.md#text-vs-json) for output formats and
@@ -83,18 +83,23 @@ to be asked or blocked. See [security model](docs/security-model.md).
83
83
 
84
84
  ## Pitfalls
85
85
 
86
- - **Foreground children block the parent.** If you want to control a child while
87
- it runs, launch it as a background subagent.
86
+ - **`finished` is not task completion.** It means the last execution succeeded.
87
+ The child may still own a shell, image, subagent, or Code Mode job. Use `active` and
88
+ `subtreeActive` to find work that is still in progress.
88
89
  - **`cancel` is a soft interrupt.** It does not cascade. A long tool call may
89
- finish first, and jobs owned by an idle session keep running.
90
+ finish first, and jobs owned by an idle session keep running. The result
91
+ reports observed background work, but this tool cannot stop it.
92
+ - **`cancel_descendants` only targets running executions.** Idle descendants
93
+ that own background jobs are counted in `backgroundJobCount`, not interrupted.
94
+ It stops up to `maxCancelBatch` running descendants per call and only touches
95
+ the caller's subtree; use `cursor` to continue. Nested cancellation can wake an
96
+ intermediate parent.
90
97
  - **Discovery stops at 200 nodes, 8 levels, or 5 pages by default.** Raise them
91
98
  for large trees. An empty or partial list is not proof that no subagents
92
- exist. See [limitations](docs/limitations.md).
93
- - **Usage can lag while a child is running.** Values are persisted at step
99
+ exist, and incomplete discovery can make `subtreeActive` false. See
100
+ [limitations](docs/limitations.md).
101
+ - **Usage can lag while a child is active.** Values are persisted at step
94
102
  boundaries; `usageMayLag` means re-query after the step or after cancellation.
95
- - **`cancel_descendants` stops up to `maxCancelBatch` running descendants per
96
- call.** It only touches the caller's subtree; use `cursor` to continue. Nested
97
- cancellation can wake an intermediate parent.
98
103
  - **Permissions are not prompted by default.** Add an `ask` or `deny` rule for
99
104
  `subagent.control` if you rely on approval.
100
105
 
package/SECURITY.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Supported versions
4
4
 
5
- Security fixes are applied to the latest published `0.1.x` release.
5
+ Security fixes are applied to the latest published minor release.
6
6
 
7
7
  ## Reporting a vulnerability
8
8
 
package/SKILL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: subagent-tools
3
- description: Use the subagent tools to list, inspect usage, cancel, steer, queue, and inject context into OpenCode subagent sessions. Covers tool contracts, delivery modes, soft interrupts, status-check lag, parent wake, nested depth, permissions, and budget handoffs.
3
+ description: Use the subagent tools to list, inspect usage, cancel, steer, queue, and inject context into OpenCode subagent sessions. Covers tool contracts, background work, delivery modes, soft interrupts, status-check lag, parent wake, nested depth, permissions, and budget handoffs.
4
4
  ---
5
5
 
6
6
  # Subagent Tools
@@ -9,7 +9,7 @@ Use these tools when you need to inspect or control OpenCode subagent sessions.
9
9
 
10
10
  ## Names and namespace
11
11
 
12
- Tool names below omit the default `subagent_` prefix. With the default namespace, call `subagent_list`, `subagent_usage`, `subagent_cancel`, `subagent_cancel_descendants`, `subagent_steer`, `subagent_queue`, and `subagent_context`. The prefix follows the plugin's `namespace` option and may be different in the user's config.
12
+ Tool names below omit the default `subagent_` prefix. With the default namespace, call `subagent_list`, `subagent_usage`, `subagent_cancel`, `subagent_cancel_descendants`, `subagent_steer`, `subagent_queue`, and `subagent_context`. The prefix follows the plugin's `namespace` option and may be different in the user's config. In Code Mode, call the same tools as `tools.subagent.list`, `tools.subagent.usage`, and so on; the namespace separator is `.` instead of `_`.
13
13
 
14
14
  ## Choose the tool
15
15
 
@@ -30,6 +30,23 @@ Tool names below omit the default `subagent_` prefix. With the default namespace
30
30
  - `contextTokens` — current context footprint: the last assistant step after the last completed compaction, `input + output + reasoning + cache.read + cache.write`. Only `usage` returns it.
31
31
  - `costUSD` — the session's own cost. For a family total, use `usage` with `includeDescendants: true` and read `tree.costUSD`.
32
32
 
33
+ ## Status and activity
34
+
35
+ - `status` — the last or current execution: `running`, `finished`, `failed`,
36
+ `stopped`, or `unknown`. `finished` does not mean the delegated task is done.
37
+ - `active` — the session itself is running, unknown, or owns a background job.
38
+ Descendants are not included.
39
+ - `subtreeActive` — the session or any discovered descendant is active.
40
+ - `activeDescendants` — at least one discovered child is active in its subtree.
41
+ An idle parent with active descendants may wake.
42
+ - `backgroundJob` — the session's own observed background work. `kinds` can
43
+ contain `shell`, `image`, `subagent`, and `codemode`. `stateUnknown` means work may remain
44
+ but could not be verified.
45
+ - `usageMayLag` — usage may still grow because the session is active or unknown.
46
+
47
+ Use `active: true` for one session's own work and `subtreeActive: true` for the
48
+ whole delegated task. Do not use `statuses: ["running"]` for "still working".
49
+
33
50
  ## Text vs JSON
34
51
 
35
52
  When both formats are allowed (the default), every tool accepts `format`. If the user configured only one format, the `format` input is absent: `["text"]` returns text only, and `["json"]` always returns structured output.
@@ -44,7 +61,9 @@ List child sessions discovered through the server's session tree, newest launch
44
61
  ### Inputs
45
62
 
46
63
  - `parentID?` — parent session ID. Defaults to the calling session. Any parent is accepted because reads are unrestricted.
47
- - `statuses?` — array of `running`, `stopped`, `failed`, `finished`, or `unknown`. Omit it to include all five. An empty array is an error; unknown values are rejected.
64
+ - `statuses?` — execution statuses: `running`, `stopped`, `failed`, `finished`, or `unknown`. Omit it to include all five. An empty array is an error; unknown values are rejected.
65
+ - `active?` — filter on the session's own activity. Omit to include both.
66
+ - `subtreeActive?` — filter on the session or any discovered descendant. Omit to include both.
48
67
  - `limit?` — maximum rows. Defaults to `maxListRows` (20); values outside 1 to `maxListRows` are rejected.
49
68
  - `cursor?` — cursor from a previous `list` call. Pass it back unchanged.
50
69
  - `format?` — default `json`.
@@ -54,18 +73,20 @@ List child sessions discovered through the server's session tree, newest launch
54
73
  Text is a table-like summary. With `format: "json"`, the output contains:
55
74
 
56
75
  - `root`, `statuses`, `discoveryComplete`, `warning?`
57
- - `known` — all discovered sessions before the status filter and cursor.
76
+ - `known` — all discovered sessions before the status and activity filters and cursor.
77
+ - `activeCount`, `subtreeActiveCount` — all discovered sessions with own activity or subtree activity, before filters.
58
78
  - `matching` — all matches in the current discovery pass, before the cursor.
59
79
  - `window` — matches after the cursor; `remaining` is the part not returned; `remainingPages` is pages left.
60
- - `counts` — counts for all five statuses across all discovered sessions, before filter and cursor.
61
- - `rows[]` — `id`, `parentID?`, `agent?`, `title?`, `titleTruncated?`, `status`, `ageSeconds?`, `launchedAt`, `usageMayLag?`, and optional `usage` with `costUSD?`, `tokens?`, and `tokensUsed?`.
80
+ - `counts` — counts for all five execution statuses across all discovered sessions, before filter and cursor. It still sums to `known`.
81
+ - `rows[]` — `id`, `parentID?`, `agent?`, `title?`, `titleTruncated?`, `status`, `active`, `subtreeActive`, `activeDescendants?`, `backgroundJob?`, `ageSeconds?`, `launchedAt`, `usageMayLag?`, and optional `usage` with `costUSD?`, `tokens?`, and `tokensUsed?`.
62
82
 
63
83
  ### Notes
64
84
 
65
- - A cursor walk sees the sessions found when it started. New children can increase `known`/`matching` without appearing in `window`; re-run without a cursor to include them.
66
- - Discovery can miss sessions. `discoveryComplete: false` and `warning` mean the result may be incomplete; an empty list is not proof that no subagents exist.
67
- - `usageMayLag: true` means the row is running or unknown and its usage is as of the last persisted step.
85
+ - A cursor is bound to the status and activity filters. A cursor walk sees the sessions found when it started. New children can increase `known`/`matching` without appearing in `window`; re-run without a cursor to include them.
86
+ - Discovery can miss sessions. `discoveryComplete: false` and `warning` mean the result may be incomplete; an empty list is not proof that no subagents exist. Incomplete discovery can make `subtreeActive` false.
87
+ - `usageMayLag: true` means the row is active or unknown and its usage is as of the last persisted step. A `finished` row with a background job still sets it.
68
88
  - `usage.tokens` and `usage.tokensUsed` are cumulative; neither is the current context. `list` does not return `contextTokens`; use `usage` for that.
89
+ - Text markers distinguish own activity (`active`), subtree-only activity (`subtree`), background kind (`background=shell`), and active descendants (`descendants=active`).
69
90
  - Use `cursor` until `remaining` is 0.
70
91
 
71
92
  ## usage
@@ -82,13 +103,15 @@ Read cost, tokens, and current context for a session. Read-only: any session ID
82
103
 
83
104
  With `format: "json"`:
84
105
 
85
- - `sessionID`, `parentID?`, `status`, `usageMayLag?`
106
+ - `sessionID`, `parentID?`, `status`, `active`, `usageMayLag?`
107
+ - `subtreeActive?` — present only with `includeDescendants: true`; true when the target or any discovered descendant is active.
108
+ - `backgroundJob?` — the target's own observed background work.
86
109
  - `costUSD?` — own cost, not a family total.
87
110
  - `tokens?`, `tokensUsed?` — cumulative counts; `tokensUsed` is `input + output + reasoning`.
88
111
  - `contextTokens?` — last assistant step after the last completed compaction: `input + output + reasoning + cache.read + cache.write`.
89
112
  - `lastRequest?` — input/output/reasoning/cache read/cache write/total for that step.
90
113
  - `contextLimit?`, `contextPercent?`, `model?`, `warning?`.
91
- - `tree?` — with `includeDescendants: true`: `sessions` includes the target, `descendants` excludes it, and `costUSD`/`tokensUsed` include the target's own values when available. `tokensUsed` is omitted when no session in the tree reports token data. `discoveryComplete` covers the descendant walk; `descendantsMayLag?` flags running/unknown descendants; `warning?` marks incomplete discovery.
114
+ - `tree?` — with `includeDescendants: true`: `sessions` includes the target, `descendants` excludes it, and `costUSD`/`tokensUsed` include the target's own values when available. `tokensUsed` is omitted when no session in the tree reports token data. `discoveryComplete` covers the descendant walk; `descendantsMayLag?` flags active/unknown descendants; `warning?` marks incomplete discovery.
92
115
 
93
116
  ### Notes
94
117
 
@@ -96,6 +119,7 @@ With `format: "json"`:
96
119
  - `contextTokens` is the current context; `tokens` and `tokensUsed` are cumulative.
97
120
  - `costUSD` is the session's own cost. For a family total, use `includeDescendants: true` and read `tree.costUSD`.
98
121
  - The caller's own status is reported as `running` while the tool executes.
122
+ - `subtreeActive` is omitted without the tree: descendant activity is unknown, not false.
99
123
  - Re-query after the step completes or after cancellation when `usageMayLag` is true.
100
124
 
101
125
  ## cancel
@@ -112,7 +136,8 @@ Stop one session with a soft interrupt.
112
136
 
113
137
  With `format: "json"`:
114
138
 
115
- - `sessionID`, `accepted`, `interrupt`, `status`
139
+ - `sessionID`, `accepted`, `interrupt`, `status`, `active`
140
+ - `backgroundJob?` — observed own work, with `mayRemain` and `stateUnknown` when relevant.
116
141
  - `reason?`, `readBackMayLag`, `cancellationDoesNotCascade`
117
142
  - `costUSD?`, `tokens?`, `tokensUsed?`
118
143
 
@@ -127,6 +152,9 @@ With `format: "json"`:
127
152
  ### Notes
128
153
 
129
154
  - This is a soft interrupt: it does not cascade to the child's children, a long tool call may finish first, and jobs owned by an idle session keep running.
155
+ - If the target is idle or terminal and no live background job is known, the tool probes the target's structured context for running work. A failed probe, or a probe without an authoritative idle snapshot for the target, sets `backgroundJob.stateUnknown`; it does not claim there is no job.
156
+ - If `interrupt` is `rejected` and a background job exists, the execution was idle; the tool cannot stop that job. If `interrupt` is accepted and a background job exists, the job may continue. `backgroundJob.mayRemain` marks this.
157
+ - `active` is the target's own state after the call. It is true for running, unknown, or observed background work.
130
158
  - OpenCode may wake the parent with a cancellation notice.
131
159
  - The status check after cancellation can lag. If `status` is `running` or `unknown`, or `readBackMayLag` is true, re-run `list`.
132
160
  - The target may settle as `stopped`, `failed`, or `finished`; `stopped` is not guaranteed.
@@ -148,14 +176,19 @@ There is no `sessionID`, `parentID`, `statuses`, or `limit` argument. The tool a
148
176
  With `format: "json"`:
149
177
 
150
178
  - `known` — all discovered descendants in the current pass, before the cursor is applied; `considered` — after the cursor; `running` — running among `considered`.
179
+ - `activeCount`, `subtreeActiveCount` — considered rows with own or subtree activity.
180
+ - `backgroundJobCount` — considered rows with `status !== "running"` that own a background job.
181
+ - `backgroundJobMayRemain?` — true when observed background work may still run.
151
182
  - `beforeCursorRunning?` — running descendants before the cursor window.
152
- - `targets[]` — `sessionID`, `interrupt` (`accepted`/`rejected`/`failed`/`unknown`), `readBack` (`ok`/`failed`/`not-read`), optional `status`, optional `error`.
183
+ - `targets[]` — `sessionID`, `interrupt` (`accepted`/`rejected`/`failed`/`unknown`), `readBack` (`ok`/`failed`/`not-read`), optional `status`, optional `backgroundJob`, optional `error`.
153
184
  - `remaining` — running targets not attempted; `aborted` — the call stopped before the batch completed.
154
185
  - `reason?`, `cursor?`, `warning?`.
155
186
 
156
187
  ### Notes
157
188
 
158
189
  - Only `running` rows are targeted. `unknown` rows need an individual `cancel`.
190
+ - Idle rows that own background jobs are reported in `backgroundJobCount`; this tool cannot stop those jobs. If no execution is running but background jobs exist, the result is normal, not an unqualified "no running subagents".
191
+ - Idle parents with active descendants are counted in `subtreeActiveCount` and reported in the summary; they may wake. The running descendant is the target, not the parent.
159
192
  - The whole batch is checked in one permission request.
160
193
  - `maxCancelBatch` limits targets per call. Use `cursor` to continue; `remaining` counts what is left.
161
194
  - Failed, unknown, rejected, and not-read targets are reported in `targets` and are not retried by the cursor. Inspect them manually.
@@ -183,17 +216,19 @@ With `format: "json"`:
183
216
 
184
217
  - `sessionID`, `messageID?`, `delivery`, `chars`, `resume`
185
218
  - `status?` — status observed before the message was accepted
219
+ - `active`, `backgroundJob?` — observed target activity and own background work
186
220
  - `pending?` — true when the message was accepted without waking an idle child
187
221
 
188
222
  ### Notes
189
223
 
190
224
  - Delivered before the child's next model request. It does not interrupt the current tool call.
191
- - Waking an idle child may not produce a completion notice in the parent. Resume that child by `sessionID` with the built-in `subagent` tool to read its result.
225
+ - The plugin cannot move a blocking shell to the background, so delivery may wait for that shell. This is a UI parity gap, not a hard failure.
226
+ - OpenCode sends a `<subagent>` report each time the child goes idle. A report can say `state="running"` and `Background work still running` when the execution is idle but background work remains. Read the report; do not resume the child just to read its result.
192
227
  - `delivery` is the server-reported delivery, normally `steer`.
193
228
 
194
229
  ## queue
195
230
 
196
- Queue a message as the next independent turn after the current task settles.
231
+ Queue a message as the next independent turn after the current execution settles.
197
232
 
198
233
  ### Inputs
199
234
 
@@ -208,11 +243,15 @@ With `format: "json"`:
208
243
 
209
244
  - `sessionID`, `messageID?`, `delivery`, `chars`, `resume`
210
245
  - `status?` — status observed before the message was accepted
246
+ - `active`, `backgroundJob?` — observed target activity and own background work
247
+ - `queued?` — true when the message was accepted but has not started yet
211
248
  - `pending?` — true when the message was accepted without waking an idle child
212
249
 
213
250
  ### Notes
214
251
 
215
- - The message does not join the current run. It waits until the current task settles, then starts a separate turn.
252
+ - The message does not join the current run. It waits for the current execution to settle, then starts a separate turn.
253
+ - Background jobs are not waited for and continue in parallel. The queue is promoted at the idle boundary even when background work remains.
254
+ - `queued` is inferred from the observed status and `resume`; it does not inspect the server's existing queue. Other queued prompts may be ahead.
216
255
  - `delivery` is the server-reported delivery, normally `queue`.
217
256
 
218
257
  ## context
@@ -233,6 +272,7 @@ With `format: "json"`:
233
272
  - `sessionID`, `messageID?`, `delivery: "next-step"`, `chars`
234
273
  - `description?`
235
274
  - `status?` — status observed before the message was accepted
275
+ - `active`, `backgroundJob?` — observed target activity and own background work
236
276
  - `pending?` — true when the message was accepted without waking an idle child
237
277
 
238
278
  ### Notes
@@ -260,13 +300,13 @@ Abort behavior:
260
300
  - `cancel` returns `Tool.Error` if the abort happens before or during the interrupt; an abort after the interrupt may still return a normal result.
261
301
  - `cancel_descendants` returns `Tool.Error` before discovery; otherwise it reports `aborted: true` with the targets it attempted and a warning when discovery was incomplete.
262
302
 
263
- The error message is actionable. Correct the arguments and continue.
303
+ In OpenCode 2.3.0+, these `Tool.Error` results are normal call results from a cooperative stop, not interrupted tool calls. The error message is actionable. Correct the arguments and continue.
264
304
 
265
305
  No-op outcomes are not errors: `cancel` on an already stopped, failed, or finished session, and `cancel_descendants` with no running children, return a normal result.
266
306
 
267
- ## Foreground and background
307
+ ## Background reports
268
308
 
269
- These tools are most useful with background children. A foreground `subagent` call blocks the parent until the child finishes, so the parent cannot call these tools while it waits. If you plan to control a child while it runs, launch it as a background subagent.
309
+ In OpenCode 2.3.0+, all subagents run in the background. A `<subagent>` report arrives each time a child goes idle, and again after each later round. A report can say `state="running"` and include `Background work still running` when the child's execution is idle but its own background work remains. Read the report; do not resume the child just to read its result.
270
310
 
271
311
  ## Nested subagents
272
312
 
@@ -287,7 +327,7 @@ If cost matters for your workflow, one way to use the tools together is: check `
287
327
 
288
328
  ## Workflow
289
329
 
290
- 1. Call `list`; it includes all statuses by default. Pass `statuses: ["running"]` when you only need active children.
330
+ 1. Call `list`; it includes all statuses by default. Pass `active: true` for one session's own work or `subtreeActive: true` for the whole delegated task. Use `statuses` only when you need a specific execution outcome.
291
331
  2. Pick the session ID from the result. Do not invent or guess IDs.
292
332
  3. To change what a running child is doing, use `steer`; to add a follow-up turn, use `queue`; to add a fact without waking it, use `context`. These adjust the existing session and keep its current run and context. `cancel` stops the session; restarting it with the built-in `subagent` tool is a different workflow.
293
333
  4. To stop one child, use `cancel`. To stop all your running descendants, use `cancel_descendants`; it cannot select one branch.
@@ -5,9 +5,9 @@
5
5
  The plugin imports only `@opencode/plugin` plus Node built-ins:
6
6
 
7
7
  ```ts
8
- import { Plugin, Skill } from "@opencode/plugin"
9
- import { readFile } from "node:fs/promises"
10
- import { fileURLToPath } from "node:url"
8
+ import { Plugin, Skill } from "@opencode/plugin";
9
+ import { readFile } from "node:fs/promises";
10
+ import { fileURLToPath } from "node:url";
11
11
  ```
12
12
 
13
13
  - `@opencode/plugin` is the plugin API package; see the README for the supported OpenCode V2 version. It ships the Promise plugin API used here (`Plugin.define`, `ctx.tool.transform`, `ctx.event`, `ctx.session`, `ctx.permission`, `ctx.model`, `ctx.skill`, `ctx.options`), including the typed `ctx.session.list`.
@@ -24,10 +24,11 @@ import { fileURLToPath } from "node:url"
24
24
  | Module | Owns |
25
25
  | ---------------- | ----------------------------------------------------------------------- |
26
26
  | `config.ts` | Public `Options`/`Limits`, defaults, and clamping |
27
- | `status.ts` | Status vocabulary and session-record status derivation |
27
+ | `status.ts` | Run-status vocabulary and session-record status derivation |
28
28
  | `session.ts` | Session-shaped types and `session.list` response adapters |
29
29
  | `live-state.ts` | Process-local live evidence and freshness rules |
30
- | `session-row.ts` | `SessionRow` projection used by discovery and tools |
30
+ | `background.ts` | Background job store, idle hook, shell events, probe helper |
31
+ | `session-row.ts` | `SessionRow` projection and recursive subtree activity |
31
32
  | `discovery.ts` | Bounded subtree walk and row discovery |
32
33
  | `access.ts` | `session.get` read-back and parent-chain ownership verification |
33
34
  | `permissions.ts` | `subagent.control` permission gate |
@@ -46,9 +47,9 @@ import { fileURLToPath } from "node:url"
46
47
 
47
48
  ## Tests
48
49
 
49
- The suite lives in `tests/` and mirrors the feature areas: `list`, `usage`, `actions`, `status`, `mutations`, `permissions`, `policy`, `cancel-descendants`, `discovery`, and `options`, plus focused unit tests for config, cursor, events, messages, output, schema validation, and tokens. `tests/harness.ts` builds the mocked plugin context and registers the per-test cleanup hook. Tests exercise the plugin through its public `setup`/tool surface.
50
+ The suite lives in `tests/` and mirrors the feature areas: `list`, `usage`, `activity`, `background`, `actions`, `status`, `mutations`, `permissions`, `policy`, `cancel-descendants`, `discovery`, and `options`, plus focused unit tests for config, cursor, events, messages, output, schema validation, and tokens. `tests/harness.ts` builds the mocked plugin context, the idle-hook and synthetic-message helpers, and the per-test cleanup hook. Tests exercise the plugin through its public `setup`/tool surface.
50
51
 
51
- CI runs the unit suite only. Loading the packed package into a real OpenCode server is a manual release check, not a CI job.
52
+ CI runs the unit suite against `@opencode/plugin` 2.3.0. Loading the packed package into a real OpenCode server is a manual release check, not a CI job.
52
53
 
53
54
  `tests/`, `.oxlintrc.json`, and `bun.lock` are repository-only; the npm package ships the source tree, `SKILL.md`, `SECURITY.md`, and the user-facing docs.
54
55
 
@@ -67,12 +68,15 @@ bun test
67
68
  The tests cover:
68
69
 
69
70
  - Discovery through `ctx.session.list`: pagination, depth/node/page limits, bare arrays, malformed responses, failures, and incomplete-discovery warnings.
70
- - Status filtering and cursor pagination for `list`: `known`/`matching`/`window`/`remaining`, empty-status rejection, new children between pages, and cursor scoping.
71
- - `cancel_descendants`: `targets`, `remaining`, cursor, before-cursor running children, abort, and failed/unknown/read-back outcomes.
71
+ - Status filtering, activity filtering, and cursor pagination for `list`: `known`/`activeCount`/`subtreeActiveCount`/`matching`/`window`/`remaining`, empty-status rejection, new children between pages, and cursor scoping.
72
+ - Background job tracking: idle-hook snapshots, shell events, structured probes, descendant owner attribution, stale-event rejection, deletion tombstones, and the cancel probe.
73
+ - Activity projection: own `active`, recursive `subtreeActive`, `activeDescendants`, missing parents, cycles, and order-independent row projection.
74
+ - `cancel_descendants`: `targets`, `remaining`, activity/background counts, cursor, before-cursor running children, abort, and failed/unknown/read-back outcomes.
72
75
  - Configurable limits, `sessionControlPolicy` modes, and ancestor verification, including depth exhaustion reported as unverified.
73
- - Cancellation, steering, queueing, and context injection.
76
+ - Cancellation, steering, queueing, and context injection, including background honesty and queue `queued` state.
74
77
  - Usage freshness markers (`usageMayLag` and tree), context unavailable/zero handling, and `Tool.Error` refusals.
75
78
  - Live status and freshness (`activeAt`), stale live terminal reconciliation, out-of-order event rejection, event-stream reconnect, and event subscription filtering.
76
79
  - Permission routing and denial identity, cleanup, and the `ctx.session.list` capability guard.
80
+ - Cooperative-stop abort behavior across discovery, context reads, interrupts, and batches.
77
81
 
78
82
  Discovery, ownership checks, interrupts, prompt/synthetic admission, and read-backs accept the tool's `context.signal`; stopping a tool call stops the underlying work where the client supports it.
@@ -6,7 +6,7 @@ between server and CLI plugins.
6
6
 
7
7
  ## Requirements
8
8
 
9
- - An OpenCode V2 build with `ctx.session.list`; see the [README](../README.md) for the supported version.
9
+ - OpenCode 2.3.0+.
10
10
  - The plugin is a TypeScript directory package: `package.json` exports
11
11
  `./src/index.ts`, and OpenCode loads the sources directly. There is no build
12
12
  step.
@@ -124,12 +124,6 @@ single file is skipped.
124
124
  > `opencode.json(c)`. The separate `cli.json` is for CLI-only (TUI) plugins and
125
125
  > is not needed here.
126
126
 
127
- ## After installation
128
-
129
- Run `opencode reload`, then ask the agent to call `subagent_list`. If the tool is
130
- missing, check that `ctx.session.list` is available in your OpenCode build and
131
- that the plugin loaded without errors.
132
-
133
127
  ## Options
134
128
 
135
129
  See [configuration](configuration.md) for all options, defaults, ranges, and
@@ -19,6 +19,24 @@ and what to do about it.
19
19
  - **Status can be stale.** `running` comes from live events and the session
20
20
  record, and an `unknown` row may still be running. A resumed child can look
21
21
  finished if the server omits its busy/idle timestamps.
22
+ - **`finished` is execution-only.** In OpenCode 2.3.0+ a child can be
23
+ idle while its own shell, image, subagent, or Code Mode job is still running.
24
+ `finished` means the last execution succeeded, not that the delegated task is
25
+ complete. Use `active` and `subtreeActive` for work that is still in progress.
26
+ - **Background detection is live.** The plugin learns about background work from
27
+ the `experimental.idle` hook, shell events, and structured context probes. A job
28
+ that started before the plugin loaded may not be visible until a later event or
29
+ a `cancel` probe. The idle hook is experimental; if it is unavailable, shell
30
+ events still provide partial coverage, but image, subagent, and Code Mode jobs
31
+ may be missed. Code Mode jobs are visible only through the idle hook; a
32
+ `cancel` probe cannot see them. The hook has no timestamp, so the plugin stamps
33
+ it locally; large clock skew can delay or drop a snapshot.
34
+ - **`subtreeActive` follows discovered rows.** Incomplete discovery can make it
35
+ false when an active descendant is missing. `discoveryComplete` and the warning
36
+ still apply.
37
+ - **Unknown activity is conservative.** `unknown` and `backgroundJob.stateUnknown`
38
+ count as active or possibly active. `active` can be true for a session that is
39
+ not actually running.
22
40
  - **Live state is not persisted.** After a restart, the plugin rediscovers
23
41
  sessions through `ctx.session.list` and infers status from `session.get`; live
24
42
  events fill it again.
@@ -27,10 +45,16 @@ and what to do about it.
27
45
 
28
46
  - **`cancel` is a soft interrupt.** It uses `session.interrupt({ resume: false })`.
29
47
  A long tool call may finish first, and there is no hard abort.
30
- - **Idle jobs keep running.** OpenCode can keep shell, subagent, or image jobs
31
- alive while a session is idle; `session.interrupt` does nothing there. When the
48
+ - **Idle jobs keep running.** OpenCode can keep shell, subagent, image, or Code
49
+ Mode jobs alive while a session is idle; `session.interrupt` does nothing there. When the
32
50
  session is running, an interrupt cancels its jobs as the session stops; for an
33
- idle session, use the job's own controls.
51
+ idle session, use the job's own controls. The plugin context exposes no job
52
+ list or job cancellation API, so the plugin probes the target's structured
53
+ context when no live job is known, but it cannot stop those jobs.
54
+ - **A failed or unverifiable probe is not proof of no job.** If the target
55
+ context cannot be read, or no authoritative idle snapshot exists for the
56
+ target, `cancel` sets `backgroundJob.stateUnknown` instead of claiming there
57
+ is no background work.
34
58
  - **`cancel` does not cascade.** Interrupting a child leaves its own children
35
59
  running. Use `cancel_descendants` for the caller's subtree, or cancel each
36
60
  child.
@@ -44,8 +68,11 @@ and what to do about it.
44
68
  - **`cancel_descendants` stops running descendants in batches.** It interrupts
45
69
  at most 20 per call (`maxCancelBatch`) and returns `remaining`; use
46
70
  the cursor when one is returned to continue, and use `cancel` for `unknown`
47
- rows. The status check can lag and an aborted call can leave part of the batch
48
- running, so re-run `list` and inspect `targets` and `remaining`.
71
+ rows. Idle descendants that own background jobs are counted in
72
+ `backgroundJobCount`, not interrupted; idle parents with active descendants are
73
+ reported through `subtreeActiveCount` and may wake. The status check can lag and
74
+ an aborted call can leave part of the batch running, so re-run `list` and
75
+ inspect `targets` and `remaining`.
49
76
 
50
77
  ## Usage and context
51
78
 
@@ -53,7 +80,7 @@ and what to do about it.
53
80
  update per step, so a child can show `0` or stale values until its step
54
81
  completes or it is cancelled. A child cancelled before its first step is saved
55
82
  can keep `0`, so re-query when `usageMayLag` is true (it is set while the
56
- session is running or unknown).
83
+ session is active or unknown, including a `finished` row with background work).
57
84
  - **Context resets after compaction.** `contextTokens` is the last assistant step
58
85
  after the last completed compaction and can drop. `tokens` and `tokensUsed` are
59
86
  cumulative; use them for total usage, not current context.
@@ -66,9 +93,13 @@ and what to do about it.
66
93
  why.
67
94
  - **`usage.tree` includes the target.** `tree.sessions`, `tree.costUSD`, and the
68
95
  token totals cover the target as well as its descendants, so do not
69
- double-count. A running or unknown descendant can make the totals lag, and
96
+ double-count. An active or unknown descendant can make the totals lag, and
70
97
  incomplete discovery can leave sessions out; see [reference](reference.md#usage)
71
98
  for the fields.
99
+ - **`subtreeActive` depends on discovery.** Without `includeDescendants: true`,
100
+ descendant activity is unknown and `subtreeActive` is omitted. With the tree, a
101
+ missing descendant can make it false; `discoveryComplete` and `warning` still
102
+ apply.
72
103
 
73
104
  ## Targeting and permissions
74
105
 
@@ -112,9 +143,14 @@ and what to do about it.
112
143
 
113
144
  ## Compatibility
114
145
 
115
- - **An OpenCode V2 build with `ctx.session.list` is required.** There is no
146
+ - **OpenCode 2.3.0+ is required.** There is no
116
147
  event-only fallback. The plugin uses only public V2 plugin APIs: `ctx.tool`,
117
148
  `ctx.session`, `ctx.event`, `ctx.permission`, `ctx.model`, `ctx.skill`, and
118
- `ctx.options`. See the README for the supported version.
149
+ `ctx.options`. The `experimental.idle` hook is experimental and may be
150
+ unavailable in a custom build; in that case shell events still provide partial
151
+ coverage, but image, subagent, and Code Mode jobs may be missed.
152
+ - **`steer` cannot move a blocking shell.** The UI calls `session.background`
153
+ after admitting a steer; `Plugin.Context` does not expose it. Delivery may wait
154
+ for a blocking shell to finish. This is a UI parity gap, not a plugin bug.
119
155
  - **No fork or build step.** The plugin runs from source and uses the plugin API
120
156
  that OpenCode provides.