opencode-subagent-tools 0.0.0-stage → 0.2.0
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 +49 -0
- package/LICENSE +21 -0
- package/README.md +118 -2
- package/SECURITY.md +36 -0
- package/SKILL.md +345 -0
- package/docs/configuration.md +238 -0
- package/docs/development.md +82 -0
- package/docs/installation.md +131 -0
- package/docs/limitations.md +155 -0
- package/docs/reference.md +398 -0
- package/docs/security-model.md +79 -0
- package/package.json +74 -4
- package/src/access.ts +236 -0
- package/src/background.ts +591 -0
- package/src/config.ts +143 -0
- package/src/cursor.ts +114 -0
- package/src/discovery.ts +159 -0
- package/src/errors.ts +18 -0
- package/src/events.ts +236 -0
- package/src/format.ts +34 -0
- package/src/index.ts +129 -0
- package/src/interrupt.ts +20 -0
- package/src/live-state.ts +113 -0
- package/src/messages.ts +246 -0
- package/src/permissions.ts +62 -0
- package/src/session-row.ts +116 -0
- package/src/session.ts +141 -0
- package/src/skill.ts +57 -0
- package/src/status.ts +119 -0
- package/src/text.ts +42 -0
- package/src/tokens.ts +171 -0
- package/src/tools/cancel-descendants.ts +660 -0
- package/src/tools/cancel.ts +271 -0
- package/src/tools/index.ts +41 -0
- package/src/tools/input.ts +75 -0
- package/src/tools/list.ts +608 -0
- package/src/tools/names.ts +11 -0
- package/src/tools/output.ts +169 -0
- package/src/tools/send.ts +369 -0
- package/src/tools/usage.ts +434 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
Pass options with the object form of a `plugins` entry in `opencode.json(c)`. Options belong to the entry that loads the plugin and are read from `ctx.options` during `setup`. If you installed with `opencode plugin add`, replace the string entry with the object form to add options.
|
|
4
|
+
|
|
5
|
+
A plugin auto-discovered from a `plugins/` directory has no entry, so it always uses defaults. To pass options, load it through `opencode.json(c)`.
|
|
6
|
+
|
|
7
|
+
Local paths in `plugins` must be directories. A path to a single `.ts` file is skipped. Point `package` at the directory that contains `package.json` with `name` and `exports`.
|
|
8
|
+
|
|
9
|
+
## Full example
|
|
10
|
+
|
|
11
|
+
The example shows the defaults and uses the npm package name. You can omit any option you do not need. For a local checkout, use the directory path instead; see [Global vs project configuration](#global-vs-project-configuration).
|
|
12
|
+
|
|
13
|
+
```jsonc
|
|
14
|
+
{
|
|
15
|
+
"$schema": "https://opencode.ai/config.json",
|
|
16
|
+
"plugins": [
|
|
17
|
+
{
|
|
18
|
+
"package": "opencode-subagent-tools",
|
|
19
|
+
"options": {
|
|
20
|
+
"namespace": "subagent",
|
|
21
|
+
"enforcePermissions": true,
|
|
22
|
+
"sessionControlPolicy": "descendants",
|
|
23
|
+
"allowedOutputFormats": ["text", "json"],
|
|
24
|
+
"registerSkill": true,
|
|
25
|
+
"limits": {
|
|
26
|
+
"maxDiscoveryNodes": 200,
|
|
27
|
+
"maxDiscoveryDepth": 8,
|
|
28
|
+
"maxDiscoveryPages": 5,
|
|
29
|
+
"maxListRows": 20,
|
|
30
|
+
"maxCancelBatch": 20,
|
|
31
|
+
"maxTextLength": 16000,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Options
|
|
40
|
+
|
|
41
|
+
| Option | Type | Default | Effect |
|
|
42
|
+
| ---------------------- | -------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
43
|
+
| `namespace` | string | `"subagent"` | Tool namespace. Tools become `<namespace>_list`, `<namespace>_usage`, `<namespace>_cancel`, `<namespace>_cancel_descendants`, `<namespace>_steer`, `<namespace>_queue`, and `<namespace>_context`. |
|
|
44
|
+
| `enforcePermissions` | boolean | `true` | Checks every mutation with `ctx.permission.assert` using action `subagent.control`. A denial returns a tool error. Read-only `list` and `usage` do not request `subagent.control`. Set to `false` to skip permission evaluation entirely; ownership still follows `sessionControlPolicy`. |
|
|
45
|
+
| `sessionControlPolicy` | string | `"descendants"` | Who **mutating** tools may target: `"descendants"` (caller subtree), `"all-except-ancestors"` (any except caller/ancestors), or `"all"` (any session, including the caller's ancestors, except the caller itself). Read-only `list`/`usage` are not restricted. `cancel_descendants` always stays in the caller's subtree. |
|
|
46
|
+
| `allowedOutputFormats` | string[] | `["text", "json"]` | Formats the tools may return. `["text"]` returns text only; `["json"]` always returns structured output. When both are allowed, tools also accept a per-call `format`; with one format the input is omitted. Unknown values are ignored; a non-array, an empty list, or a list with no recognized values falls back to the default, while a partially valid list keeps the recognized values. |
|
|
47
|
+
| `registerSkill` | boolean | `true` | Registers the bundled `SKILL.md` as a skill for the model. Set to `false` to skip skill registration; the tools still work. |
|
|
48
|
+
|
|
49
|
+
The permission action is always `subagent.control`, even if you change `namespace`. See [Permissions](security-model.md#permissions).
|
|
50
|
+
|
|
51
|
+
## Session control policy
|
|
52
|
+
|
|
53
|
+
`sessionControlPolicy` applies only to **mutating** tools. Read-only `list` and `usage` may read any session, including the caller and its ancestors.
|
|
54
|
+
|
|
55
|
+
| Tool | Mutating | Uses `subagent.control` | Policy applies |
|
|
56
|
+
| -------------------- | -------- | ----------------------- | ------------------------- |
|
|
57
|
+
| `list` | no | no | no; any `parentID` |
|
|
58
|
+
| `usage` | no | no | no; any session |
|
|
59
|
+
| `cancel` | yes | yes | yes |
|
|
60
|
+
| `cancel_descendants` | yes | yes | no; always caller subtree |
|
|
61
|
+
| `steer` / `queue` | yes | yes | yes |
|
|
62
|
+
| `context` | yes | yes | yes |
|
|
63
|
+
|
|
64
|
+
| Value | Mutations may target |
|
|
65
|
+
| ------------------------- | ------------------------------------------------------------------------ |
|
|
66
|
+
| `"descendants"` (default) | Only the calling session's subtree. |
|
|
67
|
+
| `"all-except-ancestors"` | Any session except the caller and its ancestors. |
|
|
68
|
+
| `"all"` | Any session, including the caller's ancestors, except the caller itself. |
|
|
69
|
+
|
|
70
|
+
Cross-tree control without allowing upward control:
|
|
71
|
+
|
|
72
|
+
```jsonc
|
|
73
|
+
{
|
|
74
|
+
"plugins": [
|
|
75
|
+
{
|
|
76
|
+
"package": "opencode-subagent-tools",
|
|
77
|
+
"options": { "sessionControlPolicy": "all-except-ancestors" },
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Full control, including ancestors:
|
|
84
|
+
|
|
85
|
+
```jsonc
|
|
86
|
+
{
|
|
87
|
+
"plugins": [
|
|
88
|
+
{
|
|
89
|
+
"package": "opencode-subagent-tools",
|
|
90
|
+
"options": { "sessionControlPolicy": "all" },
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`"all"` is security-sensitive: a subagent can target its parent or root if it knows the ID. Read-only tools are unrestricted in every mode and do not request `subagent.control`. `cancel_descendants` never widens beyond the caller's subtree.
|
|
97
|
+
|
|
98
|
+
## Global vs project configuration
|
|
99
|
+
|
|
100
|
+
Options are scoped to the config file that contains the `plugins` entry:
|
|
101
|
+
|
|
102
|
+
- **Global** — `~/.config/opencode/opencode.json(c)`: applies to every project.
|
|
103
|
+
- **Project** — `./opencode.json(c)` or `./.opencode/opencode.json(c)`: applies to that project only.
|
|
104
|
+
- **System** — `/etc/opencode/opencode.json(c)` on Linux, `/Library/Application Support/opencode` on macOS, or `%ProgramData%\opencode` on Windows: managed settings with the highest precedence.
|
|
105
|
+
|
|
106
|
+
### Global example
|
|
107
|
+
|
|
108
|
+
```jsonc
|
|
109
|
+
// ~/.config/opencode/opencode.jsonc
|
|
110
|
+
{
|
|
111
|
+
"$schema": "https://opencode.ai/config.json",
|
|
112
|
+
"plugins": [
|
|
113
|
+
{
|
|
114
|
+
"package": "opencode-subagent-tools",
|
|
115
|
+
"options": {
|
|
116
|
+
"namespace": "subagent",
|
|
117
|
+
"enforcePermissions": true,
|
|
118
|
+
"sessionControlPolicy": "descendants",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
For a local checkout, use the absolute path to the plugin directory instead of the npm name:
|
|
126
|
+
|
|
127
|
+
```jsonc
|
|
128
|
+
{
|
|
129
|
+
"plugins": [
|
|
130
|
+
{
|
|
131
|
+
"package": "C:/Users/<you>/opencode-subagent-tools",
|
|
132
|
+
"options": { "sessionControlPolicy": "all-except-ancestors" },
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Project example
|
|
139
|
+
|
|
140
|
+
From `./opencode.jsonc`:
|
|
141
|
+
|
|
142
|
+
```jsonc
|
|
143
|
+
{
|
|
144
|
+
"$schema": "https://opencode.ai/config.json",
|
|
145
|
+
"plugins": [
|
|
146
|
+
{
|
|
147
|
+
"package": "./opencode-subagent-tools",
|
|
148
|
+
"options": {
|
|
149
|
+
"namespace": "subagent",
|
|
150
|
+
"enforcePermissions": true,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
From `./.opencode/opencode.jsonc`, the path is relative to that file, so use one extra `../`:
|
|
158
|
+
|
|
159
|
+
```jsonc
|
|
160
|
+
{
|
|
161
|
+
"$schema": "https://opencode.ai/config.json",
|
|
162
|
+
"plugins": [
|
|
163
|
+
{
|
|
164
|
+
"package": "../opencode-subagent-tools",
|
|
165
|
+
"options": {
|
|
166
|
+
"namespace": "subagent",
|
|
167
|
+
"enforcePermissions": true,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The package path is a directory containing `package.json` and `exports`, not a `.ts` file.
|
|
175
|
+
|
|
176
|
+
### Choosing a scope
|
|
177
|
+
|
|
178
|
+
Use a global entry when the same options should apply everywhere. Use a project entry when only that project needs the option.
|
|
179
|
+
|
|
180
|
+
Plugin arrays from applicable config files are merged from lowest to highest precedence; they are not replaced. OpenCode rejects duplicate plugin IDs: a second entry is reported as failed with `Duplicate plugin ID` and does not load. Load the plugin in exactly one scope. If you need different options per project, load it only from the project config.
|
|
181
|
+
|
|
182
|
+
### Auto-discovered directory installs
|
|
183
|
+
|
|
184
|
+
Copying the package directory (with `package.json`, `src/`, and `SKILL.md`) into a `plugins/` directory is still supported, but that path is auto-discovered and has no `plugins` entry. It always uses default options. To pass options, use a configured directory package and a `plugins` entry as above.
|
|
185
|
+
|
|
186
|
+
## Limits
|
|
187
|
+
|
|
188
|
+
All limits are integers and are clamped to the allowed range. Invalid values fall back to the default.
|
|
189
|
+
|
|
190
|
+
| Option | Default | Range | Effect |
|
|
191
|
+
| ------------------- | ------- | ------- | -------------------------------------------------------------------- |
|
|
192
|
+
| `maxDiscoveryNodes` | `200` | 1–5000 | Maximum nodes visited in one server discovery pass. |
|
|
193
|
+
| `maxDiscoveryDepth` | `8` | 1–32 | Maximum parent-chain depth walked during discovery and verification. |
|
|
194
|
+
| `maxDiscoveryPages` | `5` | 1–50 | Maximum `session.list` pages requested per parent. |
|
|
195
|
+
| `maxListRows` | `20` | 1–50 | Maximum rows returned by `list` per call. |
|
|
196
|
+
| `maxCancelBatch` | `20` | 1–50 | Maximum children interrupted by `cancel_descendants` per call. |
|
|
197
|
+
| `maxTextLength` | `16000` | 1–32000 | Maximum characters accepted by `steer`, `queue`, and `context`. |
|
|
198
|
+
|
|
199
|
+
`list` and `cancel_descendants` are independent: raising `maxListRows` does not change how many children `cancel_descendants` may stop, and vice versa. The `session.list` page size stays at 100.
|
|
200
|
+
|
|
201
|
+
Discovery follows the server cursor:
|
|
202
|
+
|
|
203
|
+
- A short page with a cursor continues.
|
|
204
|
+
- A page without a cursor ends the walk.
|
|
205
|
+
- A full page without a cursor is treated as potentially truncated.
|
|
206
|
+
- A repeated cursor is treated as incomplete.
|
|
207
|
+
|
|
208
|
+
## Tuning notes
|
|
209
|
+
|
|
210
|
+
- Raising `maxDiscoveryNodes`, `maxDiscoveryDepth`, or `maxDiscoveryPages` increases the number of `session.list` calls and discovery latency.
|
|
211
|
+
- Raising `maxListRows` increases the number of rows in `list` output. Raising `maxCancelBatch` increases the number of interrupts and status checks per `cancel_descendants` call. `cancel_descendants` checks the whole batch in one permission request, so an `ask` policy prompts once per call, not once per child.
|
|
212
|
+
- `list` and `cancel_descendants` use a cursor to page. A cursor keeps its place while statuses change, but it sees the sessions found when the walk started; children launched after the first page may not appear.
|
|
213
|
+
- `list` filters by the last observed status. Include `unknown` in `statuses` if you also want to see sessions whose state is not known yet.
|
|
214
|
+
- Discovery stops at the configured node, depth, and page limits and can miss sessions. An empty or partial result is not proof that no subagents exist; see [limitations](limitations.md).
|
|
215
|
+
- `sessionControlPolicy: "all"` is security-sensitive; see the [security model](security-model.md).
|
|
216
|
+
|
|
217
|
+
## Power-user example
|
|
218
|
+
|
|
219
|
+
```jsonc
|
|
220
|
+
{
|
|
221
|
+
"$schema": "https://opencode.ai/config.json",
|
|
222
|
+
"plugins": [
|
|
223
|
+
{
|
|
224
|
+
"package": "opencode-subagent-tools",
|
|
225
|
+
"options": {
|
|
226
|
+
"limits": {
|
|
227
|
+
"maxDiscoveryNodes": 1000,
|
|
228
|
+
"maxDiscoveryDepth": 16,
|
|
229
|
+
"maxDiscoveryPages": 10,
|
|
230
|
+
"maxListRows": 50,
|
|
231
|
+
"maxCancelBatch": 10,
|
|
232
|
+
"maxTextLength": 24000,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
}
|
|
238
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Development
|
|
2
|
+
|
|
3
|
+
## Dependencies
|
|
4
|
+
|
|
5
|
+
The plugin imports only `@opencode/plugin` plus Node built-ins:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Plugin, Skill } from "@opencode/plugin";
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
```
|
|
12
|
+
|
|
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`.
|
|
14
|
+
- At runtime **OpenCode resolves `@opencode/plugin` itself**, so a user who copies the package into a plugins directory does not need to install anything for the plugin to work.
|
|
15
|
+
- `package.json` declares `@opencode/plugin` as an **optional peer dependency** (and as a dev dependency for local typechecking and tests), not a bundled runtime dependency. OpenCode provides it at runtime, so installing the plugin does not need to pull in a second copy.
|
|
16
|
+
- There are **no third-party runtime dependencies** in the plugin source.
|
|
17
|
+
- `ctx.session.list` is required. `setup` fails with a clear error on a build that does not expose it; there is no event-only fallback.
|
|
18
|
+
- The optional `limits` options are validated and clamped in `config.ts`; see [configuration](configuration.md) for the public defaults and ranges.
|
|
19
|
+
|
|
20
|
+
## Source layout
|
|
21
|
+
|
|
22
|
+
`src/index.ts` is the composition root. It resolves configuration, constructs the runtime services, registers tools and the skill, starts the event stream, and returns the cleanup function. Domain modules own one concept each:
|
|
23
|
+
|
|
24
|
+
| Module | Owns |
|
|
25
|
+
| ---------------- | ----------------------------------------------------------------------- |
|
|
26
|
+
| `config.ts` | Public `Options`/`Limits`, defaults, and clamping |
|
|
27
|
+
| `status.ts` | Run-status vocabulary and session-record status derivation |
|
|
28
|
+
| `session.ts` | Session-shaped types and `session.list` response adapters |
|
|
29
|
+
| `live-state.ts` | Process-local live evidence and freshness rules |
|
|
30
|
+
| `background.ts` | Background job store, idle hook, shell events, probe helper |
|
|
31
|
+
| `session-row.ts` | `SessionRow` projection and recursive subtree activity |
|
|
32
|
+
| `discovery.ts` | Bounded subtree walk and row discovery |
|
|
33
|
+
| `access.ts` | `session.get` read-back and parent-chain ownership verification |
|
|
34
|
+
| `permissions.ts` | `subagent.control` permission gate |
|
|
35
|
+
| `messages.ts` | Shared steer/queue/context admission path |
|
|
36
|
+
| `interrupt.ts` | Shared interrupt outcome mapping |
|
|
37
|
+
| `cursor.ts` | Opaque paging cursor encode/decode/compare |
|
|
38
|
+
| `tokens.ts` | Token normalization, totals, context formula, usage schema |
|
|
39
|
+
| `format.ts` | Human-readable age, cost, and compact-number formatting |
|
|
40
|
+
| `text.ts` | Clipping, Unicode length, control-character, and length-error helpers |
|
|
41
|
+
| `errors.ts` | `Tool.Error` helper and the OpenCode capability message |
|
|
42
|
+
| `events.ts` | Event names, reducer, reconnect loop |
|
|
43
|
+
| `skill.ts` | Bundled `SKILL.md` parsing and registration |
|
|
44
|
+
| `tools/*.ts` | Tool registration grouped by shared behavior, plus input/output helpers |
|
|
45
|
+
|
|
46
|
+
`SKILL.md` sits at the package root, beside `src/`; `skill.ts` resolves it with `new URL("../SKILL.md", import.meta.url)`.
|
|
47
|
+
|
|
48
|
+
## Tests
|
|
49
|
+
|
|
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.
|
|
51
|
+
|
|
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.
|
|
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.
|
|
55
|
+
|
|
56
|
+
## Commands
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
bun install
|
|
60
|
+
bun run lint
|
|
61
|
+
bun run format:check
|
|
62
|
+
bun run typecheck
|
|
63
|
+
bun test
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`bun run check` runs lint, format checking, typecheck, and the test suite. `bun run format` rewrites files with Prettier. The lint configuration is in `.oxlintrc.json`; it enables Oxlint's `correctness` and `suspicious` categories plus the `Reflect` restriction.
|
|
67
|
+
|
|
68
|
+
The tests cover:
|
|
69
|
+
|
|
70
|
+
- Discovery through `ctx.session.list`: pagination, depth/node/page limits, bare arrays, malformed responses, failures, and incomplete-discovery warnings.
|
|
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.
|
|
75
|
+
- Configurable limits, `sessionControlPolicy` modes, and ancestor verification, including depth exhaustion reported as unverified.
|
|
76
|
+
- Cancellation, steering, queueing, and context injection, including background honesty and queue `queued` state.
|
|
77
|
+
- Usage freshness markers (`usageMayLag` and tree), context unavailable/zero handling, and `Tool.Error` refusals.
|
|
78
|
+
- Live status and freshness (`activeAt`), stale live terminal reconciliation, out-of-order event rejection, event-stream reconnect, and event subscription filtering.
|
|
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.
|
|
81
|
+
|
|
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.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
The standard install uses npm or GitHub; see the [README quick start](../README.md#quick-start).
|
|
4
|
+
This page covers manual and local installation, path rules, and the difference
|
|
5
|
+
between server and CLI plugins.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- OpenCode 2.3.0+.
|
|
10
|
+
- The plugin is a TypeScript directory package: `package.json` exports
|
|
11
|
+
`./src/index.ts`, and OpenCode loads the sources directly. There is no build
|
|
12
|
+
step.
|
|
13
|
+
- Keep `SKILL.md` beside `src/` if you want the bundled skill. Without it, the
|
|
14
|
+
tools still load, but the skill is skipped.
|
|
15
|
+
|
|
16
|
+
## Manual installation
|
|
17
|
+
|
|
18
|
+
Use this when you want to run a local checkout or pin the plugin yourself.
|
|
19
|
+
|
|
20
|
+
### Global plugins directory
|
|
21
|
+
|
|
22
|
+
OpenCode discovers immediate plugin package directories under the OpenCode
|
|
23
|
+
config directory:
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
<global-config-dir>/plugins/
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
On Windows the global config directory is `%USERPROFILE%\.config\opencode`. Copy
|
|
30
|
+
the package as a directory named `subagent-tools`:
|
|
31
|
+
|
|
32
|
+
```powershell
|
|
33
|
+
$target = "$env:USERPROFILE\.config\opencode\plugins\subagent-tools"
|
|
34
|
+
New-Item -ItemType Directory -Force $target | Out-Null
|
|
35
|
+
Copy-Item .\package.json, .\SKILL.md $target
|
|
36
|
+
Copy-Item .\src $target -Recurse
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
OpenCode watches this directory and reloads plugins automatically. If the new
|
|
40
|
+
package is not picked up, run `opencode reload`; a full restart is not normally
|
|
41
|
+
needed.
|
|
42
|
+
|
|
43
|
+
This layout loads the plugin with its default options. An auto-discovered
|
|
44
|
+
package has no `plugins` entry, so there is nowhere to attach `options`. Use the
|
|
45
|
+
directory package layout below when you need to pass options.
|
|
46
|
+
|
|
47
|
+
> Project-scoped plugins live in `.opencode/plugins/`. A `plugins/` directory
|
|
48
|
+
> beside a project-root `opencode.json(c)` is **not** auto-discovered.
|
|
49
|
+
|
|
50
|
+
### From a local directory package
|
|
51
|
+
|
|
52
|
+
Global config lives at `~/.config/opencode/opencode.jsonc`; project config lives
|
|
53
|
+
at `./opencode.jsonc` or `./.opencode/opencode.jsonc`. Relative paths resolve
|
|
54
|
+
from the config file that contains the entry, so a path that works in
|
|
55
|
+
`./opencode.jsonc` needs one extra `../` in `./.opencode/opencode.jsonc`.
|
|
56
|
+
|
|
57
|
+
`opencode.json(c)` can load the plugin from a directory that contains a
|
|
58
|
+
`package.json` with `name` and `exports`. Point `package` at the directory.
|
|
59
|
+
|
|
60
|
+
Global config — absolute path:
|
|
61
|
+
|
|
62
|
+
```jsonc
|
|
63
|
+
{
|
|
64
|
+
"$schema": "https://opencode.ai/config.json",
|
|
65
|
+
"plugins": ["C:/Users/<you>/opencode-subagent-tools"],
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Object form — required if you want to pass options:
|
|
70
|
+
|
|
71
|
+
```jsonc
|
|
72
|
+
{
|
|
73
|
+
"$schema": "https://opencode.ai/config.json",
|
|
74
|
+
"plugins": [
|
|
75
|
+
{
|
|
76
|
+
"package": "C:/Users/<you>/opencode-subagent-tools",
|
|
77
|
+
"options": {
|
|
78
|
+
"namespace": "subagent",
|
|
79
|
+
"enforcePermissions": true,
|
|
80
|
+
"sessionControlPolicy": "descendants",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Project config — relative path from `./opencode.jsonc`:
|
|
88
|
+
|
|
89
|
+
```jsonc
|
|
90
|
+
{
|
|
91
|
+
"$schema": "https://opencode.ai/config.json",
|
|
92
|
+
"plugins": [
|
|
93
|
+
{
|
|
94
|
+
"package": "./opencode-subagent-tools",
|
|
95
|
+
"options": {
|
|
96
|
+
"namespace": "subagent",
|
|
97
|
+
"enforcePermissions": true,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
From `./.opencode/opencode.jsonc`, use `"package": "../opencode-subagent-tools"`
|
|
105
|
+
or an absolute path.
|
|
106
|
+
|
|
107
|
+
The `plugins` array also accepts npm package names, GitHub specifications, local
|
|
108
|
+
directories, and `file://` URLs. Local paths must be directories; a path to a
|
|
109
|
+
single file is skipped.
|
|
110
|
+
|
|
111
|
+
> **Do not load the plugin twice.** If the package directory is already
|
|
112
|
+
> auto-discovered from a `plugins/` directory, adding a second `plugins` entry is
|
|
113
|
+
> rejected by OpenCode as a duplicate plugin ID; the duplicate is reported as
|
|
114
|
+
> failed and does not load. Load the plugin either as an auto-discovered package
|
|
115
|
+
> (defaults only) or as a configured directory package (options), not both.
|
|
116
|
+
|
|
117
|
+
> **Windows paths.** Tilde expansion is not guaranteed for plugin paths on
|
|
118
|
+
> Windows; use an absolute forward-slash path such as `C:/Users/<you>/...`.
|
|
119
|
+
> `%USERPROFILE%` is not expanded inside JSON config strings.
|
|
120
|
+
|
|
121
|
+
> **Server plugin vs CLI plugin.** This plugin uses the server plugin API
|
|
122
|
+
> (`ctx.tool`, `ctx.session`, `ctx.event`, `ctx.permission`), so load it as a
|
|
123
|
+
> server plugin — from the global plugins directory or from `plugins` in
|
|
124
|
+
> `opencode.json(c)`. The separate `cli.json` is for CLI-only (TUI) plugins and
|
|
125
|
+
> is not needed here.
|
|
126
|
+
|
|
127
|
+
## Options
|
|
128
|
+
|
|
129
|
+
See [configuration](configuration.md) for all options, defaults, ranges, and
|
|
130
|
+
examples. For manual installs, the object form of the `plugins` entry is required
|
|
131
|
+
to pass options; an auto-discovered package always uses defaults.
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Limitations
|
|
2
|
+
|
|
3
|
+
Read these before you rely on the plugin for anything destructive. The tool
|
|
4
|
+
contracts are in [reference](reference.md); this page covers what can go wrong
|
|
5
|
+
and what to do about it.
|
|
6
|
+
|
|
7
|
+
## Discovery and status
|
|
8
|
+
|
|
9
|
+
- **Discovery can miss sessions.** The plugin refreshes the subtree through
|
|
10
|
+
`ctx.session.list` before `list`, `cancel_descendants`, and `usage` with
|
|
11
|
+
`includeDescendants: true`, so it finds children launched before it loaded,
|
|
12
|
+
from the TUI, or by another process. The defaults
|
|
13
|
+
are 200 nodes, 8 levels, and 5 pages per parent; raise these limits in
|
|
14
|
+
[configuration](configuration.md) for bigger trees; partial results include a
|
|
15
|
+
warning, and empty results are inconclusive.
|
|
16
|
+
- **Ordering can skip a child.** OpenCode orders `session.list` by
|
|
17
|
+
`time.updated`, so a child that updates between pages can move and be missed;
|
|
18
|
+
`discoveryComplete` does not show it, so re-run discovery before a large batch.
|
|
19
|
+
- **Status can be stale.** `running` comes from live events and the session
|
|
20
|
+
record, and an `unknown` row may still be running. A resumed child can look
|
|
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, or subagent job is still running. `finished` means the
|
|
24
|
+
last execution succeeded, not that the delegated task is complete. Use
|
|
25
|
+
`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 and subagent jobs may be
|
|
31
|
+
missed. The hook has no timestamp, so the plugin stamps it locally; large clock
|
|
32
|
+
skew can delay or drop a snapshot.
|
|
33
|
+
- **`subtreeActive` follows discovered rows.** Incomplete discovery can make it
|
|
34
|
+
false when an active descendant is missing. `discoveryComplete` and the warning
|
|
35
|
+
still apply.
|
|
36
|
+
- **Unknown activity is conservative.** `unknown` and `backgroundJob.stateUnknown`
|
|
37
|
+
count as active or possibly active. `active` can be true for a session that is
|
|
38
|
+
not actually running.
|
|
39
|
+
- **Live state is not persisted.** After a restart, the plugin rediscovers
|
|
40
|
+
sessions through `ctx.session.list` and infers status from `session.get`; live
|
|
41
|
+
events fill it again.
|
|
42
|
+
|
|
43
|
+
## Cancellation
|
|
44
|
+
|
|
45
|
+
- **`cancel` is a soft interrupt.** It uses `session.interrupt({ resume: false })`.
|
|
46
|
+
A long tool call may finish first, and there is no hard abort.
|
|
47
|
+
- **Idle jobs keep running.** OpenCode can keep shell, subagent, or image jobs
|
|
48
|
+
alive while a session is idle; `session.interrupt` does nothing there. When the
|
|
49
|
+
session is running, an interrupt cancels its jobs as the session stops; for an
|
|
50
|
+
idle session, use the job's own controls. The plugin context exposes no job
|
|
51
|
+
list or job cancellation API, so the plugin probes the target's structured
|
|
52
|
+
context when no live job is known, but it cannot stop those jobs.
|
|
53
|
+
- **A failed or unverifiable probe is not proof of no job.** If the target
|
|
54
|
+
context cannot be read, or no authoritative idle snapshot exists for the
|
|
55
|
+
target, `cancel` sets `backgroundJob.stateUnknown` instead of claiming there
|
|
56
|
+
is no background work.
|
|
57
|
+
- **`cancel` does not cascade.** Interrupting a child leaves its own children
|
|
58
|
+
running. Use `cancel_descendants` for the caller's subtree, or cancel each
|
|
59
|
+
child.
|
|
60
|
+
- **The status check after `cancel` can lag.** The session record may still say
|
|
61
|
+
`running` after the interrupt. Re-run `list` if `readBackMayLag` is true or
|
|
62
|
+
the status is `running` or `unknown`.
|
|
63
|
+
- **Cancelling a child can wake the parent.** OpenCode may deliver a
|
|
64
|
+
`<subagent state="cancelled">` notice to the parent, which can resume, continue
|
|
65
|
+
its work, and spend more tokens. This is OpenCode behavior, not the plugin's;
|
|
66
|
+
see [issue #36423](https://github.com/anomalyco/opencode/issues/36423).
|
|
67
|
+
- **`cancel_descendants` stops running descendants in batches.** It interrupts
|
|
68
|
+
at most 20 per call (`maxCancelBatch`) and returns `remaining`; use
|
|
69
|
+
the cursor when one is returned to continue, and use `cancel` for `unknown`
|
|
70
|
+
rows. Idle descendants that own background jobs are counted in
|
|
71
|
+
`backgroundJobCount`, not interrupted; idle parents with active descendants are
|
|
72
|
+
reported through `subtreeActiveCount` and may wake. The status check can lag and
|
|
73
|
+
an aborted call can leave part of the batch running, so re-run `list` and
|
|
74
|
+
inspect `targets` and `remaining`.
|
|
75
|
+
|
|
76
|
+
## Usage and context
|
|
77
|
+
|
|
78
|
+
- **Usage can lag.** `usage` and `list` read the session record; cost and tokens
|
|
79
|
+
update per step, so a child can show `0` or stale values until its step
|
|
80
|
+
completes or it is cancelled. A child cancelled before its first step is saved
|
|
81
|
+
can keep `0`, so re-query when `usageMayLag` is true (it is set while the
|
|
82
|
+
session is active or unknown, including a `finished` row with background work).
|
|
83
|
+
- **Context resets after compaction.** `contextTokens` is the last assistant step
|
|
84
|
+
after the last completed compaction and can drop. `tokens` and `tokensUsed` are
|
|
85
|
+
cumulative; use them for total usage, not current context.
|
|
86
|
+
- **Context after revert.** The UI reads the full loaded message list, while
|
|
87
|
+
`usage` counts from the latest completed compaction; if a staged revert
|
|
88
|
+
boundary predates that compaction, the two can differ. This is uncommon.
|
|
89
|
+
- **`contextTokens: 0` is not always missing.** Zero is valid when no assistant
|
|
90
|
+
step exists after the last compaction. If context cannot be read, or the
|
|
91
|
+
staged revert boundary is missing, the field is omitted and `warning` explains
|
|
92
|
+
why.
|
|
93
|
+
- **`usage.tree` includes the target.** `tree.sessions`, `tree.costUSD`, and the
|
|
94
|
+
token totals cover the target as well as its descendants, so do not
|
|
95
|
+
double-count. An active or unknown descendant can make the totals lag, and
|
|
96
|
+
incomplete discovery can leave sessions out; see [reference](reference.md#usage)
|
|
97
|
+
for the fields.
|
|
98
|
+
- **`subtreeActive` depends on discovery.** Without `includeDescendants: true`,
|
|
99
|
+
descendant activity is unknown and `subtreeActive` is omitted. With the tree, a
|
|
100
|
+
missing descendant can make it false; `discoveryComplete` and `warning` still
|
|
101
|
+
apply.
|
|
102
|
+
|
|
103
|
+
## Targeting and permissions
|
|
104
|
+
|
|
105
|
+
- **Reads are unrestricted; mutations follow policy.** `list` and `usage` can
|
|
106
|
+
read any session, including the caller and its ancestors. Mutations follow
|
|
107
|
+
`sessionControlPolicy`, and `cancel_descendants` always stays in the caller's
|
|
108
|
+
subtree; see the [security model](security-model.md).
|
|
109
|
+
- **A mutation cannot target the caller.** `usage` can read it.
|
|
110
|
+
- **Permissions are not prompted by default.** Mutations request
|
|
111
|
+
`subagent.control`; a denial returns a tool error, and
|
|
112
|
+
`enforcePermissions: false` skips the check entirely. Add an `ask` or `deny`
|
|
113
|
+
rule if you rely on approval; see the [security model](security-model.md).
|
|
114
|
+
|
|
115
|
+
## Nested subagents
|
|
116
|
+
|
|
117
|
+
- **Nested subagents need an OpenCode setting.** Set
|
|
118
|
+
`experimental.subagent_depth` to at least `2`; the default is `1`. This is an
|
|
119
|
+
OpenCode setting, not a plugin option.
|
|
120
|
+
- **Grandchild transcripts are not exposed.** The plugin can list, inspect,
|
|
121
|
+
steer, queue, and stop a grandchild, but it cannot read its transcript. Use the
|
|
122
|
+
intermediate parent as a relay, or have the grandchild write a handoff file.
|
|
123
|
+
- **Nested cancellation can cost tokens.** In a nested tree, the cancelled
|
|
124
|
+
session's parent is another subagent; it can resume after the interrupt, spend
|
|
125
|
+
tokens, and continue up the branch. Re-run `list` after `cancel_descendants`
|
|
126
|
+
and cancel that parent again if it resumed.
|
|
127
|
+
|
|
128
|
+
## Pagination and output
|
|
129
|
+
|
|
130
|
+
- **A cursor does not see new sessions.** `list` and `cancel_descendants` return
|
|
131
|
+
a cursor for the next page, and a cursor sees the sessions found when the walk
|
|
132
|
+
started. Children launched later may not appear, so re-run without a cursor to
|
|
133
|
+
include them; retrying `cancel_descendants` with the cursor skips failed,
|
|
134
|
+
unknown, rejected, and not-read targets, so inspect them manually.
|
|
135
|
+
- **`list` is limited by `maxListRows`.** It returns at most 20 rows by default.
|
|
136
|
+
Raise `maxListRows` in [configuration](configuration.md) if you need more rows
|
|
137
|
+
per page; the per-call `limit` must be between 1 and `maxListRows`, and the
|
|
138
|
+
cursor still pages through the rest.
|
|
139
|
+
- **`list` filters on the last observed status.** Include `unknown` if you also
|
|
140
|
+
want sessions whose state is not known yet. An empty `statuses` array is
|
|
141
|
+
rejected; omit it to include all five.
|
|
142
|
+
|
|
143
|
+
## Compatibility
|
|
144
|
+
|
|
145
|
+
- **OpenCode 2.3.0+ is required.** There is no
|
|
146
|
+
event-only fallback. The plugin uses only public V2 plugin APIs: `ctx.tool`,
|
|
147
|
+
`ctx.session`, `ctx.event`, `ctx.permission`, `ctx.model`, `ctx.skill`, and
|
|
148
|
+
`ctx.options`. The `experimental.idle` hook is experimental and may be
|
|
149
|
+
unavailable in a custom build; in that case shell events still provide partial
|
|
150
|
+
coverage, but image and subagent jobs may be missed.
|
|
151
|
+
- **`steer` cannot move a blocking shell.** The UI calls `session.background`
|
|
152
|
+
after admitting a steer; `Plugin.Context` does not expose it. Delivery may wait
|
|
153
|
+
for a blocking shell to finish. This is a UI parity gap, not a plugin bug.
|
|
154
|
+
- **No fork or build step.** The plugin runs from source and uses the plugin API
|
|
155
|
+
that OpenCode provides.
|