opencode-subagent-tools 0.2.1 → 0.2.2
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 +14 -0
- package/README.md +2 -2
- package/SKILL.md +1 -1
- package/docs/development.md +13 -1
- package/docs/limitations.md +5 -5
- package/docs/reference.md +5 -5
- package/package.json +7 -8
- package/src/background.ts +60 -50
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ 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.2 - 2026-11-25
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Background video jobs (`video`) are reported in `backgroundJob.kinds` and count as active work. OpenCode 2.4.0+ reports them through the `experimental.idle` hook; older versions never send this kind.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Tested against `@opencode/plugin` 2.4.1.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Background probes recognize the current `generate_image` tool name and the older `experimental_image_generate` name.
|
|
21
|
+
|
|
8
22
|
## 0.2.1 - 2026-11-18
|
|
9
23
|
|
|
10
24
|
### 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.3.0+; tested against 2.
|
|
9
|
+
Requires OpenCode 2.3.0+; tested against 2.4.1.
|
|
10
10
|
|
|
11
11
|
## Quick start
|
|
12
12
|
|
|
@@ -84,7 +84,7 @@ to be asked or blocked. See [security model](docs/security-model.md).
|
|
|
84
84
|
## Pitfalls
|
|
85
85
|
|
|
86
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
|
|
87
|
+
The child may still own a shell, image, video, subagent, or Code Mode job. Use `active` and
|
|
88
88
|
`subtreeActive` to find work that is still in progress.
|
|
89
89
|
- **`cancel` is a soft interrupt.** It does not cascade. A long tool call may
|
|
90
90
|
finish first, and jobs owned by an idle session keep running. The result
|
package/SKILL.md
CHANGED
|
@@ -40,7 +40,7 @@ Tool names below omit the default `subagent_` prefix. With the default namespace
|
|
|
40
40
|
- `activeDescendants` — at least one discovered child is active in its subtree.
|
|
41
41
|
An idle parent with active descendants may wake.
|
|
42
42
|
- `backgroundJob` — the session's own observed background work. `kinds` can
|
|
43
|
-
contain `shell`, `image`, `subagent`, and `codemode`. `stateUnknown` means work may remain
|
|
43
|
+
contain `shell`, `image`, `video`, `subagent`, and `codemode`. `stateUnknown` means work may remain
|
|
44
44
|
but could not be verified.
|
|
45
45
|
- `usageMayLag` — usage may still grow because the session is active or unknown.
|
|
46
46
|
|
package/docs/development.md
CHANGED
|
@@ -49,7 +49,7 @@ import { fileURLToPath } from "node:url";
|
|
|
49
49
|
|
|
50
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
51
|
|
|
52
|
-
CI runs the unit suite against `@opencode/plugin`
|
|
52
|
+
CI runs the unit suite against the `@opencode/plugin` version from `package.json`. Loading the packed package into a real OpenCode server is a manual release check, not a CI job.
|
|
53
53
|
|
|
54
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
55
|
|
|
@@ -80,3 +80,15 @@ The tests cover:
|
|
|
80
80
|
- Cooperative-stop abort behavior across discovery, context reads, interrupts, and batches.
|
|
81
81
|
|
|
82
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.
|
|
83
|
+
|
|
84
|
+
## CI
|
|
85
|
+
|
|
86
|
+
`.github/workflows/ci.yml` runs on push and pull requests on `ubuntu-latest`:
|
|
87
|
+
|
|
88
|
+
- install with `bun install --frozen-lockfile`;
|
|
89
|
+
- `bun run check`;
|
|
90
|
+
- `npm pack --dry-run`.
|
|
91
|
+
|
|
92
|
+
The workflow uses read-only contents permission, a 15-minute timeout, and cancels superseded runs on the same ref.
|
|
93
|
+
|
|
94
|
+
CI is Ubuntu-only. Windows-specific tests run locally on Windows and are not part of CI.
|
package/docs/limitations.md
CHANGED
|
@@ -20,14 +20,14 @@ and what to do about it.
|
|
|
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
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.
|
|
23
|
+
idle while its own shell, image, video, subagent, or Code Mode job is still running.
|
|
24
24
|
`finished` means the last execution succeeded, not that the delegated task is
|
|
25
25
|
complete. Use `active` and `subtreeActive` for work that is still in progress.
|
|
26
26
|
- **Background detection is live.** The plugin learns about background work from
|
|
27
27
|
the `experimental.idle` hook, shell events, and structured context probes. A job
|
|
28
28
|
that started before the plugin loaded may not be visible until a later event or
|
|
29
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
|
|
30
|
+
events still provide partial coverage, but image, video, subagent, and Code Mode jobs
|
|
31
31
|
may be missed. Code Mode jobs are visible only through the idle hook; a
|
|
32
32
|
`cancel` probe cannot see them. The hook has no timestamp, so the plugin stamps
|
|
33
33
|
it locally; large clock skew can delay or drop a snapshot.
|
|
@@ -45,8 +45,8 @@ and what to do about it.
|
|
|
45
45
|
|
|
46
46
|
- **`cancel` is a soft interrupt.** It uses `session.interrupt({ resume: false })`.
|
|
47
47
|
A long tool call may finish first, and there is no hard abort.
|
|
48
|
-
- **Idle jobs keep running.** OpenCode can keep shell, subagent, image, or
|
|
49
|
-
Mode jobs alive while a session is idle; `session.interrupt` does nothing there. When the
|
|
48
|
+
- **Idle jobs keep running.** OpenCode can keep shell, subagent, image, video, or
|
|
49
|
+
Code Mode jobs alive while a session is idle; `session.interrupt` does nothing there. When the
|
|
50
50
|
session is running, an interrupt cancels its jobs as the session stops; for an
|
|
51
51
|
idle session, use the job's own controls. The plugin context exposes no job
|
|
52
52
|
list or job cancellation API, so the plugin probes the target's structured
|
|
@@ -148,7 +148,7 @@ and what to do about it.
|
|
|
148
148
|
`ctx.session`, `ctx.event`, `ctx.permission`, `ctx.model`, `ctx.skill`, and
|
|
149
149
|
`ctx.options`. The `experimental.idle` hook is experimental and may be
|
|
150
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.
|
|
151
|
+
coverage, but image, video, subagent, and Code Mode jobs may be missed.
|
|
152
152
|
- **`steer` cannot move a blocking shell.** The UI calls `session.background`
|
|
153
153
|
after admitting a steer; `Plugin.Context` does not expose it. Delivery may wait
|
|
154
154
|
for a blocking shell to finish. This is a UI parity gap, not a plugin bug.
|
package/docs/reference.md
CHANGED
|
@@ -48,7 +48,7 @@ Text output is one row per session plus summary and warning lines. JSON output c
|
|
|
48
48
|
- `active` — true when the session itself is running, unknown, or owns a background job. Descendants are excluded.
|
|
49
49
|
- `subtreeActive` — true when the session or any discovered descendant is active.
|
|
50
50
|
- `activeDescendants?` — true only when at least one discovered child is active in its subtree.
|
|
51
|
-
- `backgroundJob?` — the session's own observed work: `kinds` (`shell`, `image`, `subagent`, `codemode`), and optional `stateUnknown` when work may remain but could not be verified.
|
|
51
|
+
- `backgroundJob?` — the session's own observed work: `kinds` (`shell`, `image`, `video`, `subagent`, `codemode`), and optional `stateUnknown` when work may remain but could not be verified.
|
|
52
52
|
- `ageSeconds?` (omitted when the launch time is unknown), `launchedAt`.
|
|
53
53
|
- `usageMayLag?` — true when the row is active or unknown.
|
|
54
54
|
- `usage?` — `costUSD?`, `tokens?`, and `tokensUsed?` when the server provides them.
|
|
@@ -134,7 +134,7 @@ Text output reports the interrupt result, the current state, and a lag note. JSO
|
|
|
134
134
|
- `accepted` — alias for `interrupt === "accepted"`.
|
|
135
135
|
- `status` — execution status after the interrupt and status check.
|
|
136
136
|
- `active` — true when the target is running, unknown, or owns observed background work after the call.
|
|
137
|
-
- `backgroundJob?` — the target's own observed work: `kinds` (`shell`, `image`, `subagent`, `codemode`), `mayRemain?` when work may still run after the call, and `stateUnknown?` when a probe failed.
|
|
137
|
+
- `backgroundJob?` — the target's own observed work: `kinds` (`shell`, `image`, `video`, `subagent`, `codemode`), `mayRemain?` when work may still run after the call, and `stateUnknown?` when a probe failed.
|
|
138
138
|
- `reason?` — the recorded reason.
|
|
139
139
|
- `readBackMayLag` — true when the interrupt was accepted and the status check after cancellation still reports `running` or `unknown`.
|
|
140
140
|
- `cancellationDoesNotCascade` — always `true`; cancellation is non-cascading, not a claim that the target has no children.
|
|
@@ -147,7 +147,7 @@ Text distinguishes an accepted interrupt with a remaining job ("may continue"),
|
|
|
147
147
|
- An unknown target, a self-target, a malformed ID, or a target outside `sessionControlPolicy` returns `Tool.Error`.
|
|
148
148
|
- Aborting before or during the interrupt returns `Tool.Error`. An abort after the interrupt may return a normal result.
|
|
149
149
|
- Cancelling a stopped, failed, or finished session is not an error.
|
|
150
|
-
- If the target is idle or terminal and no live background job is known, the tool probes `session.context(target)` for running shell messages and shell/image/subagent tool parts. It cannot see a Code Mode job; that requires an idle snapshot. 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.
|
|
150
|
+
- If the target is idle or terminal and no live background job is known, the tool probes `session.context(target)` for running shell messages and shell/image/video/subagent tool parts. Video jobs are normally visible through the idle hook because `generate_video` returns before the probe runs. It cannot see a Code Mode job; that requires an idle snapshot. 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.
|
|
151
151
|
- This is a soft interrupt: it does not cascade, a long tool call may finish first, and jobs owned by an idle session keep running. The tool reports those jobs but cannot stop them.
|
|
152
152
|
- OpenCode may wake the parent with a cancellation notice.
|
|
153
153
|
- If `interrupt` is `unknown`, `readBackMayLag` is true, or `status` is `running` or `unknown`, re-run `list`.
|
|
@@ -298,12 +298,12 @@ Text output reports the target and size. JSON output contains:
|
|
|
298
298
|
- `finished` — the last run succeeded. This does not mean the delegated task is complete.
|
|
299
299
|
- `unknown` — no reliable status is available; the session may still be running.
|
|
300
300
|
|
|
301
|
-
`status` is execution-oriented. In OpenCode 2.3.0+, shell, image, subagent, or Code Mode work can stay alive while a session is idle, so use the activity fields for "still working":
|
|
301
|
+
`status` is execution-oriented. In OpenCode 2.3.0+, shell, image, video, subagent, or Code Mode work can stay alive while a session is idle, so use the activity fields for "still working":
|
|
302
302
|
|
|
303
303
|
- `active` — the session itself is running, unknown, or owns a background job. Descendants are not included.
|
|
304
304
|
- `subtreeActive` — the session or any discovered descendant is active.
|
|
305
305
|
- `activeDescendants` — at least one discovered child is active. An idle parent with active descendants may wake.
|
|
306
|
-
- `backgroundJob` — the session's own observed work: `kinds` can contain `shell`, `image`, `subagent`, and `codemode`. `stateUnknown` means work may remain but could not be verified.
|
|
306
|
+
- `backgroundJob` — the session's own observed work: `kinds` can contain `shell`, `image`, `video`, `subagent`, and `codemode`. `stateUnknown` means work may remain but could not be verified.
|
|
307
307
|
- `usageMayLag` — the session is active or unknown, so usage may still grow.
|
|
308
308
|
|
|
309
309
|
Status and activity are observed from live events, the idle hook, shell events, structured context probes, and the session record. Code Mode jobs are visible only through the idle hook. They can lag, and an `unknown` row may still be running. See [limitations](limitations.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-subagent-tools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "OpenCode V2 plugin that gives the agent tools to list, inspect, cancel, steer, queue, and inject context into its subagent sessions.",
|
|
5
5
|
"author": "Maxim Matsiushonak",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,15 +26,14 @@
|
|
|
26
26
|
"keywords": [
|
|
27
27
|
"opencode",
|
|
28
28
|
"opencode-plugin",
|
|
29
|
+
"opencode-v2",
|
|
30
|
+
"opencode-v2-plugin",
|
|
31
|
+
"agent-tools",
|
|
29
32
|
"subagent",
|
|
33
|
+
"subagents",
|
|
30
34
|
"subagent-tools",
|
|
31
35
|
"subagent-control",
|
|
32
|
-
"
|
|
33
|
-
"cancel",
|
|
34
|
-
"steer",
|
|
35
|
-
"queue",
|
|
36
|
-
"opencode-v2",
|
|
37
|
-
"plugin"
|
|
36
|
+
"subagent-orchestration"
|
|
38
37
|
],
|
|
39
38
|
"repository": {
|
|
40
39
|
"type": "git",
|
|
@@ -62,7 +61,7 @@
|
|
|
62
61
|
}
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"@opencode/plugin": "^2.
|
|
64
|
+
"@opencode/plugin": "^2.4.1",
|
|
66
65
|
"@types/bun": "^1.4.3",
|
|
67
66
|
"@types/node": "^26.6.5",
|
|
68
67
|
"oxlint": "1.60.0",
|
package/src/background.ts
CHANGED
|
@@ -2,18 +2,46 @@ import { normalizeSessionID } from "./session";
|
|
|
2
2
|
import { RUN_STATUS, type RunStatus } from "./status";
|
|
3
3
|
import { isUnsafeControlCode } from "./text";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
5
|
+
interface BackgroundJobSpec {
|
|
6
|
+
/** Extract a normalized job key from an idle item. */
|
|
7
|
+
key: (item: Record<string, unknown>) => string | undefined;
|
|
8
|
+
/** Tool names whose running call proves this background kind. */
|
|
9
|
+
tools: readonly string[];
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const BACKGROUND_JOB_SPECS = {
|
|
13
|
+
shell: {
|
|
14
|
+
key: (item) => normalizeBackgroundKey(item.shellID),
|
|
15
|
+
tools: ["shell"],
|
|
16
|
+
},
|
|
17
|
+
image: {
|
|
18
|
+
key: (item) =>
|
|
19
|
+
normalizeBackgroundKey(item.path) ?? normalizeBackgroundKey(item.model),
|
|
20
|
+
tools: ["generate_image", "experimental_image_generate"],
|
|
21
|
+
},
|
|
22
|
+
video: {
|
|
23
|
+
key: (item) => normalizeBackgroundKey(item.path),
|
|
24
|
+
tools: ["generate_video"],
|
|
25
|
+
},
|
|
26
|
+
subagent: {
|
|
27
|
+
key: (item) => normalizeSessionID(item.childSessionID),
|
|
28
|
+
tools: ["subagent"],
|
|
29
|
+
},
|
|
30
|
+
codemode: {
|
|
31
|
+
key: (item) => normalizeBackgroundKey(item.jobID),
|
|
32
|
+
tools: [],
|
|
33
|
+
},
|
|
34
|
+
} as const satisfies Record<string, BackgroundJobSpec>;
|
|
14
35
|
|
|
15
|
-
export
|
|
16
|
-
|
|
36
|
+
export type BackgroundJobKind = keyof typeof BACKGROUND_JOB_SPECS;
|
|
37
|
+
|
|
38
|
+
export const BACKGROUND_JOB_KINDS: readonly BackgroundJobKind[] = Object.keys(
|
|
39
|
+
BACKGROUND_JOB_SPECS,
|
|
40
|
+
) as BackgroundJobKind[];
|
|
41
|
+
|
|
42
|
+
export const BACKGROUND_JOB_KIND = Object.fromEntries(
|
|
43
|
+
BACKGROUND_JOB_KINDS.map((kind) => [kind, kind]),
|
|
44
|
+
) as { readonly [K in BackgroundJobKind]: K };
|
|
17
45
|
|
|
18
46
|
const BACKGROUND_JOB_KIND_SET: ReadonlySet<string> = new Set(BACKGROUND_JOB_KINDS);
|
|
19
47
|
|
|
@@ -60,7 +88,7 @@ export const MAX_BACKGROUND_SESSIONS = 500;
|
|
|
60
88
|
export const MAX_BACKGROUND_JOBS_PER_KIND = 100;
|
|
61
89
|
export const MAX_BACKGROUND_KEY_LENGTH = 500;
|
|
62
90
|
|
|
63
|
-
/** Validate a shell/image key without rejecting spaces in
|
|
91
|
+
/** Validate a shell/image/video key without rejecting spaces in paths. */
|
|
64
92
|
export const normalizeBackgroundKey = (value: unknown): string | undefined => {
|
|
65
93
|
if (typeof value !== "string") return undefined;
|
|
66
94
|
const key = value.trim();
|
|
@@ -73,10 +101,8 @@ export const normalizeBackgroundKey = (value: unknown): string | undefined => {
|
|
|
73
101
|
};
|
|
74
102
|
|
|
75
103
|
interface BackgroundState {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
subagent: Map<string, number>;
|
|
79
|
-
codemode: Map<string, number>;
|
|
104
|
+
/** Jobs grouped by kind, then keyed by their normalized ID or path. */
|
|
105
|
+
jobs: Map<BackgroundJobKind, Map<string, number>>;
|
|
80
106
|
/** Last idle snapshot applied for this session, trusted or not. */
|
|
81
107
|
snapshotAt: number;
|
|
82
108
|
/** Whether an idle snapshot has ever been authoritative for this session. */
|
|
@@ -88,10 +114,7 @@ interface BackgroundState {
|
|
|
88
114
|
}
|
|
89
115
|
|
|
90
116
|
const createState = (): BackgroundState => ({
|
|
91
|
-
|
|
92
|
-
image: new Map(),
|
|
93
|
-
subagent: new Map(),
|
|
94
|
-
codemode: new Map(),
|
|
117
|
+
jobs: new Map(),
|
|
95
118
|
snapshotAt: 0,
|
|
96
119
|
hasAuthoritativeSnapshot: false,
|
|
97
120
|
snapshotOwners: new Set(),
|
|
@@ -101,7 +124,13 @@ const createState = (): BackgroundState => ({
|
|
|
101
124
|
const stateJobMap = (
|
|
102
125
|
state: BackgroundState,
|
|
103
126
|
kind: BackgroundJobKind,
|
|
104
|
-
): Map<string, number> =>
|
|
127
|
+
): Map<string, number> => {
|
|
128
|
+
const existing = state.jobs.get(kind);
|
|
129
|
+
if (existing) return existing;
|
|
130
|
+
const map = new Map<string, number>();
|
|
131
|
+
state.jobs.set(kind, map);
|
|
132
|
+
return map;
|
|
133
|
+
};
|
|
105
134
|
|
|
106
135
|
const trimMap = (map: Map<string, number>, limit: number) => {
|
|
107
136
|
while (map.size > limit) {
|
|
@@ -120,8 +149,7 @@ const trimSet = (set: Set<string>, limit: number) => {
|
|
|
120
149
|
};
|
|
121
150
|
|
|
122
151
|
const clearAtOrBefore = (state: BackgroundState, at: number) => {
|
|
123
|
-
for (const
|
|
124
|
-
const map = stateJobMap(state, kind);
|
|
152
|
+
for (const map of state.jobs.values()) {
|
|
125
153
|
for (const [key, startedAt] of map) {
|
|
126
154
|
if (startedAt <= at) map.delete(key);
|
|
127
155
|
}
|
|
@@ -178,25 +206,7 @@ const parseIdleItem = (value: unknown): IdleItemParse => {
|
|
|
178
206
|
}
|
|
179
207
|
if (!owner) return { ok: false };
|
|
180
208
|
|
|
181
|
-
|
|
182
|
-
const key = normalizeBackgroundKey(item.shellID);
|
|
183
|
-
return key
|
|
184
|
-
? { ok: true, item: { kind: item.kind, key, owner } }
|
|
185
|
-
: { ok: false, owner };
|
|
186
|
-
}
|
|
187
|
-
if (item.kind === BACKGROUND_JOB_KIND.image) {
|
|
188
|
-
const key = normalizeBackgroundKey(item.path) ?? normalizeBackgroundKey(item.model);
|
|
189
|
-
return key
|
|
190
|
-
? { ok: true, item: { kind: item.kind, key, owner } }
|
|
191
|
-
: { ok: false, owner };
|
|
192
|
-
}
|
|
193
|
-
if (item.kind === BACKGROUND_JOB_KIND.codemode) {
|
|
194
|
-
const key = normalizeBackgroundKey(item.jobID);
|
|
195
|
-
return key
|
|
196
|
-
? { ok: true, item: { kind: item.kind, key, owner } }
|
|
197
|
-
: { ok: false, owner };
|
|
198
|
-
}
|
|
199
|
-
const key = normalizeSessionID(item.childSessionID);
|
|
209
|
+
const key = BACKGROUND_JOB_SPECS[item.kind].key(item);
|
|
200
210
|
return key ? { ok: true, item: { kind: item.kind, key, owner } } : { ok: false, owner };
|
|
201
211
|
};
|
|
202
212
|
|
|
@@ -260,11 +270,11 @@ const readContext = async (
|
|
|
260
270
|
};
|
|
261
271
|
|
|
262
272
|
/** Tool names whose running call proves the session owns that background kind. */
|
|
263
|
-
const RUNNING_TOOL_KIND: ReadonlyMap<string, BackgroundJobKind> = new Map(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
273
|
+
const RUNNING_TOOL_KIND: ReadonlyMap<string, BackgroundJobKind> = new Map(
|
|
274
|
+
BACKGROUND_JOB_KINDS.flatMap((kind) =>
|
|
275
|
+
BACKGROUND_JOB_SPECS[kind].tools.map((name) => [name, kind] as const),
|
|
276
|
+
),
|
|
277
|
+
);
|
|
268
278
|
|
|
269
279
|
const scanTargetMessages = (
|
|
270
280
|
messages: readonly ProbeMessage[],
|
|
@@ -469,7 +479,7 @@ export const createBackgroundJobStore = () => {
|
|
|
469
479
|
rememberDeleted(id, at);
|
|
470
480
|
states.delete(id);
|
|
471
481
|
for (const state of states.values()) {
|
|
472
|
-
state.subagent
|
|
482
|
+
state.jobs.get(BACKGROUND_JOB_KIND.subagent)?.delete(id);
|
|
473
483
|
state.snapshotOwners.delete(id);
|
|
474
484
|
}
|
|
475
485
|
};
|
|
@@ -478,7 +488,7 @@ export const createBackgroundJobStore = () => {
|
|
|
478
488
|
const state = states.get(sessionID);
|
|
479
489
|
if (!state) return undefined;
|
|
480
490
|
const kinds = BACKGROUND_JOB_KINDS.filter(
|
|
481
|
-
(kind) =>
|
|
491
|
+
(kind) => (state.jobs.get(kind)?.size ?? 0) > 0,
|
|
482
492
|
);
|
|
483
493
|
const stateUnknown = state.unknownAt > 0;
|
|
484
494
|
if (kinds.length === 0 && !stateUnknown) return undefined;
|
|
@@ -498,8 +508,8 @@ export const createBackgroundJobStore = () => {
|
|
|
498
508
|
/**
|
|
499
509
|
* Structured fallback when the store has no authoritative snapshot for the
|
|
500
510
|
* target, such as after a restart. Running shell messages and running
|
|
501
|
-
* shell/image/subagent tool parts are proof of work. Code Mode scripts
|
|
502
|
-
* not visible here, so they rely on the idle hook. A missing snapshot, or a
|
|
511
|
+
* shell/image/video/subagent tool parts are proof of work. Code Mode scripts
|
|
512
|
+
* are not visible here, so they rely on the idle hook. A missing snapshot, or a
|
|
503
513
|
* failed or malformed read, is unknown, never idle.
|
|
504
514
|
*/
|
|
505
515
|
const probe = async ({
|