brl-subagent 2.5.2 → 2.6.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/AGENT.md +12 -10
- package/README.md +16 -5
- package/package.json +5 -5
- package/src/concurrency.ts +156 -44
- package/src/index.ts +100 -34
- package/src/params.ts +73 -5
- package/src/schema.ts +3 -1
- package/src/state.ts +29 -4
- package/src/tui-format.ts +382 -4
- package/src/tui.ts +793 -522
- package/src/types.ts +12 -2
package/AGENT.md
CHANGED
|
@@ -16,16 +16,17 @@ delegation-heavy work.
|
|
|
16
16
|
|
|
17
17
|
| Mode | What blocks | What wakes you | Batchable? |
|
|
18
18
|
| --- | --- | --- | --- |
|
|
19
|
-
| single,
|
|
20
|
-
| single,
|
|
19
|
+
| single, background (**default** at effective `auto`) | returns immediately with an agent id | yes — a `subagent-completion` message on terminal state | no |
|
|
20
|
+
| single, foreground (default at `writes`/`always`, or `background: false`) | blocks until it returns | — (result comes back inline) | no |
|
|
21
21
|
| chain | blocks until the chain finishes or fails | — | yes (foreground) |
|
|
22
|
-
| parallel (`tasks`),
|
|
23
|
-
| parallel
|
|
22
|
+
| parallel (`tasks`), background fan-out (**default** at effective `auto`) | returns immediately with one agent id per task | yes — a `subagent-completion` message per agent, on each agent's terminal state | yes |
|
|
23
|
+
| parallel (`tasks`), foreground (default at `writes`/`always`, or `background: false`) | blocks until every task finishes | — | yes (foreground) |
|
|
24
24
|
| graph | blocks; runs in waves via `dependsOn` | — | yes (foreground) |
|
|
25
25
|
|
|
26
|
+
- **`background` is a conditional default (issue #361).** With `background` omitted, a single task or a `tasks` fan-out runs in the **background** when the *effective* approval mode is `auto` (per-call param, else the configured default), and stays **foreground** when it is `writes` or `always`. Chain and graph always stay foreground. Explicit `true`/`false` is honoured exactly.
|
|
26
27
|
- Foreground single blocks: you wait for the result inline.
|
|
27
28
|
- Background single returns immediately with an agent id; a completion message wakes you (see below).
|
|
28
|
-
- Chain, parallel, and graph are batch — one call, many subtasks. Chain and graph are foreground; `tasks`
|
|
29
|
+
- Chain, parallel, and graph are batch — one call, many subtasks. Chain and graph are foreground; `tasks` fans out by default under `auto` (and always with `background: true`): every task starts as its own background agent, the call returns with one id per task in task order, and you are woken once per agent as each finishes.
|
|
29
30
|
- Fan-out validates the whole batch before spawning anything: any invalid task (cwd, `outputFile`, or a pre-task check) rejects the entire batch before a single spawn starts, and the error names the task (`Task N ("label")`).
|
|
30
31
|
- Fan-out rejects `gitMode: "branch"` for the batch — the git lock is awaited inside the first spawn and held until that agent settles, so branch-mode spawns targeting the same repository would serialize and block the call (the rule is blanket because the lock is keyed by the resolved repository root, so any two units of the same repo contend). It also rejects `approvalMode: "always"` up front, and the session cost limit is checked as per-task estimate × N.
|
|
31
32
|
- Spawn failure mid-loop stops further spawns and reports the failed task plus the ids already started; abort mid-loop stops further spawns and reports the ids already started. Either way those agents are detached and still wake you.
|
|
@@ -45,11 +46,11 @@ delegation-heavy work.
|
|
|
45
46
|
|
|
46
47
|
## Delegation judgment
|
|
47
48
|
|
|
48
|
-
- Foreground vs background:
|
|
49
|
+
- Foreground vs background: the default is background under effective `auto`, foreground otherwise. Pass `background: false` for a quick probe whose answer the next step needs inline (it keeps the call blocking, so no wake round-trip). Pass `background: true` to force a background run where the default blocks. If the user can keep working or is AFK, act on the wake. Pre-declared independent work while the user is away → `tasks` (fan-out is the default) and act on each wake.
|
|
49
50
|
- Batch vs sequential: if the work is pre-declared, use chain/parallel/graph. If you're steering incrementally with the user, issue sequential calls.
|
|
50
51
|
- Retry taxonomy: `retryRunId` is a retry — it re-runs with the recorded task and params. A re-dispatch (a fresh call with the same task text) is not a retry. Never re-issue an identical spec after a termination without confirming the cause with the user.
|
|
51
52
|
- When to delegate: when the task needs an isolated context, a deep investigation, parallel research, or a long-running analysis.
|
|
52
|
-
- Approval: `approvalMode: "always"` is rejected in background — there is no dialog. Use `auto` (default) or `writes`; `writes` auto-approves in background.
|
|
53
|
+
- Approval: `approvalMode: "always"` is rejected in background — there is no dialog. Use `auto` (default) or `writes`; `writes` auto-approves in background. This is why the background default is approval-aware: an omitted `background` stays foreground under `writes`/`always`, so the gate is never silently bypassed by a default.
|
|
53
54
|
|
|
54
55
|
### Claim verification
|
|
55
56
|
|
|
@@ -62,8 +63,9 @@ delegation-heavy work.
|
|
|
62
63
|
|
|
63
64
|
- Batch chain with `{previous}`: `chain: [{ task: "…" }, { task: "Use {previous} …" }]` — each step gets the prior step's output.
|
|
64
65
|
- Graph with `dependsOn`: subtasks declare edges; the scheduler runs them in waves.
|
|
65
|
-
- Background + act on wake: spawn a background run, then act when the completion message arrives. Never poll between spawn and wake.
|
|
66
|
-
- Background fan-out: `tasks: [...]
|
|
66
|
+
- Background + act on wake: spawn a background run (the default under `auto`), then act when the completion message arrives. Never poll between spawn and wake.
|
|
67
|
+
- Background fan-out: `tasks: [...]` — one background agent per task, one id per task in task order, one wake per agent.
|
|
68
|
+
- Inline probe: `background: false` — blocks and returns the result in the same turn when the next step needs it immediately.
|
|
67
69
|
- retryRunId: pass a failed or **interrupted** run's id to re-run it with its recorded task and params; explicit parameters override the originals. A run interrupted before durable task capture (a pre-enrichment registry entry) has no recorded task — pass `task` explicitly for those.
|
|
68
70
|
|
|
69
71
|
## Interrupted runs and recovery
|
|
@@ -75,7 +77,7 @@ delegation-heavy work.
|
|
|
75
77
|
|
|
76
78
|
## Deadlines and retries
|
|
77
79
|
|
|
78
|
-
- `timeout` (ms) is a **deadline, not a ceiling** — an explicit value is honored as given; 30 minutes is only the default for a background run that passes none. Background expiry aborts the session (the run ends `stopped`); foreground expiry kills the process.
|
|
80
|
+
- `timeout` (ms) is a **deadline, not a ceiling** — an explicit value is honored as given; 30 minutes is only the default for a background run that passes none (a foreground run is not capped). Background expiry aborts the session (the run ends `stopped`); foreground expiry kills the process. Because background is now the default under `auto`, remember the 30-minute deadline: pass an explicit `timeout` for anything expected to run longer.
|
|
79
81
|
- `retryOnTimeout` applies to **foreground runs only**. A timed-out background run is not auto-retried: re-dispatch it with `retryRunId` if that is the right call. The same applies to an interrupted run — recovery is always an explicit `retryRunId` call, never automatic (auto mode is not yet accepted).
|
|
80
82
|
|
|
81
83
|
## Mechanics pointer
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Multi-agent orchestration for [pi](https://github.com/earendil-works/pi) — chain, parallel, and dependency-graph delegation to isolated subagents with per-step model routing, preset-driven tool scoping, thinking-level control, and background execution with live monitoring, real abort, and per-agent timeouts.
|
|
4
4
|
|
|
5
|
-
**Version:** 2.
|
|
5
|
+
**Version:** 2.6.0 · **Author:** Azmeen Afandi / [Beeroo Labs](https://beeroolabs.com) · **License:** MIT
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
- **True background execution** — live monitor, real abort (`stop_subagent`), per-agent timeouts, and a 30-minute default deadline for runs that don't set one. Nothing orphans; nothing leaks.
|
|
15
15
|
- **Preset-driven tool scoping** — every subagent runs with exactly the tools its job needs, restricted by preset or per-call `tools`/`excludeTools`, with auto-route that picks the right preset when you don't.
|
|
16
16
|
- **Templates with slots** — saved, file-backed task templates with `${param}` placeholders for workflows you run again and again.
|
|
17
|
-
- **Safety by default** — task-fence injection protection, sanitized error paths, owner-only persistence, and a
|
|
17
|
+
- **Safety by default** — task-fence injection protection, sanitized error paths, owner-only persistence, and a 1700+ test suite pinning every contract against the real pi SDK.
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -92,7 +92,7 @@ All settings persist across sessions.
|
|
|
92
92
|
| `outputFile` | string | — | Path for the subagent to write full findings. Returns only a summary. |
|
|
93
93
|
| `timeout` | number | — | Max milliseconds. Foreground: exceeded → SIGTERM (5s grace) → SIGKILL. Background: the session is aborted and the run ends `stopped` with the timeout reason. A background run with no explicit `timeout` gets the 30-minute default deadline — an explicit timeout is honored as given (a default, not a ceiling). A raw value `≥ 2^31-1` normalizes to no timeout (for a background run, the 30-minute default then applies). |
|
|
94
94
|
| `cwd` | string | — | Working directory. Defaults to conductor's cwd. |
|
|
95
|
-
| `background` | boolean |
|
|
95
|
+
| `background` | boolean | conditional | Spawn as an independent background session; returns an ID immediately. **Omitted**, a single task or a `tasks` fan-out runs in the background when the *effective* `approvalMode` is `auto` (call param, else config), and stays foreground under `writes`/`always` or for `chain`/`graph` — see [Background execution](#background-execution). With `tasks` it fans out (one background agent per task, one ID per task), and the conductor is woken once per agent as each finishes. Pass `false` for a quick probe whose answer the next step needs inline. |
|
|
96
96
|
| `priority` | string | — | Concurrency priority: `critical` / `high` / `normal` / `low`. Defaults to `normal`; higher-priority delegations queue ahead. `tasks[]` / `graph[]` steps can set `priority` per unit (see below). |
|
|
97
97
|
| `tools` | array | — | Explicit tool allowlist for the subagent. |
|
|
98
98
|
| `excludeTools` | array | — | Tool names to disable for the subagent. |
|
|
@@ -126,7 +126,7 @@ All settings persist across sessions.
|
|
|
126
126
|
|
|
127
127
|
Beyond a single `task`, `delegate_task` accepts three multi-step shapes: `chain` (sequential steps, `{previous}` references the prior step's output), `tasks` (parallel, independent), and `graph` (dependency-ordered, `{<nodeId>}` references another node's output — the referenced node's own `id`, which must be a word-character id: letters, digits, and underscore. `{step-1}` and `{node.a}` are not matched and are left as literal text).
|
|
128
128
|
|
|
129
|
-
`background: true` fans out the `tasks` shape into one background agent per task (one ID per task, one completion wake per agent); `chain` and `graph` reject it.
|
|
129
|
+
`background: true` fans out the `tasks` shape into one background agent per task (one ID per task, one completion wake per agent); `chain` and `graph` reject it. Under an effective `approvalMode` of `auto` that fan-out is the **default** (see [Background execution](#background-execution)); pass `background: false` to run the batch foreground.
|
|
130
130
|
|
|
131
131
|
Every execution knob can be set per step: `model`, `thinkingLevel`, `tools`, `excludeTools`, `noBuiltinTools`, `systemPrompt`, `inheritSystemPrompt`, `outputFile`, `timeout`, `cwd`. Unset fields inherit from the global parameters (and their preset defaults).
|
|
132
132
|
|
|
@@ -283,7 +283,18 @@ The built-in `code-review` template's slot is `${target}` (its companion `securi
|
|
|
283
283
|
|
|
284
284
|
## Background execution
|
|
285
285
|
|
|
286
|
-
|
|
286
|
+
The tool can spawn the subagent as an independent session that returns an ID immediately and keeps running (`background: true`). Its progress is tracked via `getAgent` and the live monitor while the main session continues. Steering via `steerAgent` delivers the message into the agent's live session — it is queued while the agent runs and delivered after the current tool call finishes, before the next model call. Repeat steers work, and a delivery failure surfaces as a real tool error rather than a recorded-but-undelivered steer.
|
|
287
|
+
|
|
288
|
+
**Background is the conditional default (issue #361).** When `background` is omitted, dispatch resolves it once from the *effective* approval mode (per-call param, else the configured default — the mode the child will actually run with):
|
|
289
|
+
|
|
290
|
+
| Call shape | Default |
|
|
291
|
+
| --- | --- |
|
|
292
|
+
| single task or `tasks` fan-out, effective `approvalMode: 'auto'` | **background** |
|
|
293
|
+
| `chain` / `graph` | foreground (an explicit `background: true` is still rejected) |
|
|
294
|
+
| effective `approvalMode` `'writes'` or `'always'` | foreground |
|
|
295
|
+
| explicit `true` / `false` | honoured exactly |
|
|
296
|
+
|
|
297
|
+
The approval-aware fallback is the safety property: background runs have no approval dialog, so a mode that gates on the user cannot be reached by a default. Pass `background: false` for a quick probe whose answer the next step needs inline, and `background: true` to force a background run where the default blocks. The effective value is recorded on the run, so a retry restores what the run actually was.
|
|
287
298
|
|
|
288
299
|
**System prompt semantics:** background sessions are spawned with the same built prompt as foreground subagents (base prompt when `inheritSystemPrompt: true`, custom prompt, preset guidance, and subagent instructions). Like pi's own `--append-system-prompt`, supplying this prompt **replaces** any discovered `.pi/APPEND_SYSTEM.md` / global `APPEND_SYSTEM.md` content — this matches foreground subagent behavior exactly. With `inheritSystemPrompt: true` (the default) your conductor session's instructions — including its own appended content — are inherited through the base prompt.
|
|
289
300
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brl-subagent",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Subagent delegation for pi — blocking or background runs, chain/parallel/graph modes, presets and task templates, live monitor, and dispatch capability guards.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"typebox": "*"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@earendil-works/pi-agent-core": "^1.
|
|
41
|
-
"@earendil-works/pi-ai": "^1.
|
|
42
|
-
"@earendil-works/pi-coding-agent": "^1.
|
|
43
|
-
"@earendil-works/pi-tui": "^1.
|
|
40
|
+
"@earendil-works/pi-agent-core": "^1.4.0",
|
|
41
|
+
"@earendil-works/pi-ai": "^1.4.0",
|
|
42
|
+
"@earendil-works/pi-coding-agent": "^1.4.0",
|
|
43
|
+
"@earendil-works/pi-tui": "^1.4.0",
|
|
44
44
|
"jiti": "^2.7.0",
|
|
45
45
|
"typebox": "1.3.27",
|
|
46
46
|
"typescript": "7.0.2",
|
package/src/concurrency.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
13
13
|
import type { Priority } from "./types";
|
|
14
14
|
import { PRIORITY_ORDER } from "./types";
|
|
15
15
|
import type { SessionState } from "./state";
|
|
16
|
+
import { LIVE_SPINNER_FRAME_MS, formatProgressStatus } from "./tui-format";
|
|
16
17
|
|
|
17
18
|
// ---------------------------------------------------------------------------
|
|
18
19
|
// Slot management
|
|
@@ -52,7 +53,7 @@ export async function acquireSlot(
|
|
|
52
53
|
|
|
53
54
|
if (maxParallel === 0 || state.activeSubagents < maxParallel) {
|
|
54
55
|
state.activeSubagents++;
|
|
55
|
-
|
|
56
|
+
repaintStatus(state, ctx);
|
|
56
57
|
return true;
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -60,7 +61,7 @@ export async function acquireSlot(
|
|
|
60
61
|
const entry = {
|
|
61
62
|
run: () => {
|
|
62
63
|
state.activeSubagents++;
|
|
63
|
-
|
|
64
|
+
repaintStatus(state, ctx);
|
|
64
65
|
resolve(true);
|
|
65
66
|
},
|
|
66
67
|
signal,
|
|
@@ -103,7 +104,7 @@ export function releaseSlot(state: SessionState, success: boolean, ctx: Extensio
|
|
|
103
104
|
state.failedSubagents++;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
repaintStatus(state, ctx);
|
|
107
108
|
|
|
108
109
|
// Dequeue next waiting task
|
|
109
110
|
const next = state.pendingQueue.shift();
|
|
@@ -118,7 +119,148 @@ export function releaseSlot(state: SessionState, success: boolean, ctx: Extensio
|
|
|
118
119
|
|
|
119
120
|
const STATUS_RESET_DELAY_MS = 3000;
|
|
120
121
|
|
|
122
|
+
/** Repaint the footer from the current counters (issue #354). */
|
|
123
|
+
function renderProgressStatus(state: SessionState, ctx: ExtensionContext): void {
|
|
124
|
+
ctx.ui.setStatus(
|
|
125
|
+
"brl-subagent",
|
|
126
|
+
formatProgressStatus(state, Date.now(), ctx.ui.theme),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Keep the elapsed anchor in step with the active count: it is the start of
|
|
132
|
+
* the run that opened the current burst of activity, so it survives the settle
|
|
133
|
+
* of a later sibling and clears when the last run stops.
|
|
134
|
+
*/
|
|
135
|
+
function syncActiveSince(state: SessionState, now: number): void {
|
|
136
|
+
if (state.activeSubagents > 0) {
|
|
137
|
+
if (state.activeSinceMs === undefined) state.activeSinceMs = now;
|
|
138
|
+
} else {
|
|
139
|
+
state.activeSinceMs = undefined;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* One ticker per session (issue #354): started by the first active run,
|
|
145
|
+
* stopped when the last one settles. Idempotent, so every counter update can
|
|
146
|
+
* call it — and it never coexists with the 2 s background poller, which ticks
|
|
147
|
+
* on its own interval in src/index.ts.
|
|
148
|
+
*/
|
|
149
|
+
function syncProgressTicker(state: SessionState, ctx: ExtensionContext): void {
|
|
150
|
+
if (state.activeSubagents === 0) {
|
|
151
|
+
stopProgressTicker(state);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (state.statusTicker === undefined) {
|
|
155
|
+
state.statusTicker = setInterval(
|
|
156
|
+
() => repaintStatus(state, ctx),
|
|
157
|
+
LIVE_SPINNER_FRAME_MS,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Stop the footer ticker (idempotent) and drop the elapsed anchor. Exported so
|
|
164
|
+
* session shutdown/dispose can guarantee no timer outlives the session.
|
|
165
|
+
*/
|
|
166
|
+
export function stopProgressTicker(state: SessionState): void {
|
|
167
|
+
if (state.statusTicker !== undefined) {
|
|
168
|
+
clearInterval(state.statusTicker);
|
|
169
|
+
state.statusTicker = undefined;
|
|
170
|
+
}
|
|
171
|
+
state.activeSinceMs = undefined;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Drop the linger timer (idempotent). Exported so session shutdown can
|
|
176
|
+
* guarantee no timer outlives the session.
|
|
177
|
+
*/
|
|
178
|
+
export function clearProgressLinger(state: SessionState): void {
|
|
179
|
+
if (state.statusResetTimer !== undefined) {
|
|
180
|
+
clearTimeout(state.statusResetTimer);
|
|
181
|
+
state.statusResetTimer = undefined;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* One linger timer per burst of settled runs (issue #354, F2).
|
|
187
|
+
*
|
|
188
|
+
* When every run has settled the footer lingers on the static summary line for
|
|
189
|
+
* {@link STATUS_RESET_DELAY_MS} before the counters reset and the idle config
|
|
190
|
+
* line returns. The timer is EDGE-triggered: it arms once, on the transition
|
|
191
|
+
* into `active === 0` with something settled, and repeated renders of the same
|
|
192
|
+
* linger line leave it alone — so N renders can never stack N timers, and no
|
|
193
|
+
* render allocates a closure. Cleared when a new run becomes active (the
|
|
194
|
+
* linger window is over), when it fires, and on session shutdown.
|
|
195
|
+
*
|
|
196
|
+
* The window is measured from the end of the burst, not from the last render:
|
|
197
|
+
* a sibling settling inside it updates the line but does not extend it.
|
|
198
|
+
*/
|
|
199
|
+
export function syncProgressLinger(state: SessionState, ctx: ExtensionContext): void {
|
|
200
|
+
const settled = state.completedSubagents + state.failedSubagents;
|
|
201
|
+
|
|
202
|
+
// A live run, or nothing settled to linger over: no armed timer may survive.
|
|
203
|
+
if (state.activeSubagents > 0 || settled === 0) {
|
|
204
|
+
clearProgressLinger(state);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (state.statusResetTimer !== undefined) return; // already armed — edge held
|
|
209
|
+
|
|
210
|
+
state.statusResetTimer = setTimeout(() => {
|
|
211
|
+
state.statusResetTimer = undefined;
|
|
212
|
+
state.completedSubagents = 0;
|
|
213
|
+
state.failedSubagents = 0;
|
|
214
|
+
state.unseenSubagents = 0;
|
|
215
|
+
repaintStatus(state, ctx);
|
|
216
|
+
}, STATUS_RESET_DELAY_MS);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The ONE production entry point for painting the footer status (issue #356).
|
|
221
|
+
*
|
|
222
|
+
* Every lifecycle edge calls this and nothing else:
|
|
223
|
+
* - dispatch — `acquireSlot` (slot taken or queued run started) and the
|
|
224
|
+
* background spawn's counter bump in `src/index.ts`;
|
|
225
|
+
* - settle — `releaseSlot`, the background poller's terminal branches, the
|
|
226
|
+
* deadline/crash paths;
|
|
227
|
+
* - dequeue — `releaseSlot` hands the slot to the next queued run, which
|
|
228
|
+
* repaints through `acquireSlot`;
|
|
229
|
+
* - config change — `applyConfig`, `resetState`, and the boot paint;
|
|
230
|
+
* - poller tick — the 2 s background poll and the live spinner interval,
|
|
231
|
+
* which both fire this function;
|
|
232
|
+
* - linger fire — the 3 s reset in `syncProgressLinger`.
|
|
233
|
+
*
|
|
234
|
+
* Contract: synchronous, reads the CURRENT counters/config from `state`, and
|
|
235
|
+
* picks the active line or the idle config line itself. There is no queued
|
|
236
|
+
* microtask or coalescing — a repaint is visible by the time the call returns,
|
|
237
|
+
* so callers may paint before a notification or an `onUpdate` and keep the
|
|
238
|
+
* established ordering.
|
|
239
|
+
*
|
|
240
|
+
* Idempotent: calling it twice with no state change repaints the same line (at
|
|
241
|
+
* the same clock instant) and cannot stack timers — the spinner ticker and
|
|
242
|
+
* linger timer are edge-triggered in their sync helpers. There is no explicit
|
|
243
|
+
* reentrancy guard; a nested paint terminates because the production render is
|
|
244
|
+
* non-reentrant and the timers are edge-triggered.
|
|
245
|
+
*
|
|
246
|
+
* `updateProgressStatus` below is the implementation. It is exported only for
|
|
247
|
+
* its unit tests; production sources (including `src/index.ts` and `src/tui.ts`)
|
|
248
|
+
* must call THIS function, while tests opt in to the implementation directly.
|
|
249
|
+
* `status-chokepoint.test.ts` asserts the production-source boundary.
|
|
250
|
+
*/
|
|
251
|
+
export function repaintStatus(state: SessionState, ctx: ExtensionContext): void {
|
|
252
|
+
updateProgressStatus(state, ctx);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @internal Paint implementation — call {@link repaintStatus}, never this.
|
|
257
|
+
* The tag is convention-only; `status-chokepoint.test.ts`'s source scan is the
|
|
258
|
+
* enforcement.
|
|
259
|
+
*/
|
|
121
260
|
export function updateProgressStatus(state: SessionState, ctx: ExtensionContext): void {
|
|
261
|
+
syncActiveSince(state, Date.now());
|
|
262
|
+
syncProgressLinger(state, ctx);
|
|
263
|
+
|
|
122
264
|
const total = state.activeSubagents + state.completedSubagents + state.failedSubagents;
|
|
123
265
|
|
|
124
266
|
if (total === 0) {
|
|
@@ -126,50 +268,20 @@ export function updateProgressStatus(state: SessionState, ctx: ExtensionContext)
|
|
|
126
268
|
return;
|
|
127
269
|
}
|
|
128
270
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// dispatch is in flight — e.g. "brl: graph wave 1/2 · node 2/3, 2 running".
|
|
132
|
-
// The mode's finally clears modeContext, so the plain shape returns once
|
|
133
|
-
// no mode is active.
|
|
134
|
-
if (state.modeContext) {
|
|
135
|
-
const mc = state.modeContext;
|
|
136
|
-
parts.push(
|
|
137
|
-
mc.kind === "graph"
|
|
138
|
-
? `graph wave ${mc.wave}/${mc.totalWaves} · node ${mc.node}/${mc.totalNodes}`
|
|
139
|
-
: `chain step ${mc.step}/${mc.totalSteps}`,
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
if (state.activeSubagents > 0) parts.push(`${state.activeSubagents} running`);
|
|
143
|
-
if (state.completedSubagents > 0) {
|
|
144
|
-
if (state.unseenSubagents > 0) {
|
|
145
|
-
parts.push(`${state.completedSubagents} done (${state.unseenSubagents} unseen)`);
|
|
146
|
-
} else {
|
|
147
|
-
parts.push(`${state.completedSubagents} done`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (state.failedSubagents > 0) parts.push(`${state.failedSubagents} failed`);
|
|
151
|
-
|
|
152
|
-
const statusText = `brl: ${parts.join(", ")}`;
|
|
153
|
-
ctx.ui.setStatus("brl-subagent", ctx.ui.theme.fg("accent", statusText));
|
|
154
|
-
|
|
155
|
-
// When all subagents finish, reset counters after a brief delay
|
|
156
|
-
if (state.activeSubagents === 0 && total > 0) {
|
|
157
|
-
const snapshotTotal = total;
|
|
158
|
-
setTimeout(() => {
|
|
159
|
-
if (
|
|
160
|
-
state.activeSubagents === 0 &&
|
|
161
|
-
state.completedSubagents + state.failedSubagents === snapshotTotal
|
|
162
|
-
) {
|
|
163
|
-
state.completedSubagents = 0;
|
|
164
|
-
state.failedSubagents = 0;
|
|
165
|
-
state.unseenSubagents = 0;
|
|
166
|
-
updateStatus(state, ctx);
|
|
167
|
-
}
|
|
168
|
-
}, STATUS_RESET_DELAY_MS);
|
|
169
|
-
}
|
|
271
|
+
renderProgressStatus(state, ctx);
|
|
272
|
+
syncProgressTicker(state, ctx);
|
|
170
273
|
}
|
|
171
274
|
|
|
275
|
+
/**
|
|
276
|
+
* @internal The idle config line — also part of the one-entry paint contract.
|
|
277
|
+
* Produced by {@link updateProgressStatus} when no run is active; production
|
|
278
|
+
* callers must reach it through {@link repaintStatus}. The tag is
|
|
279
|
+
* convention-only; `status-chokepoint.test.ts`'s source scan is the enforcement.
|
|
280
|
+
*/
|
|
172
281
|
export function updateStatus(state: SessionState, ctx: ExtensionContext): void {
|
|
282
|
+
// The idle config line: no run is active, so the spinner has no job.
|
|
283
|
+
stopProgressTicker(state);
|
|
284
|
+
|
|
173
285
|
if (state.config.model) {
|
|
174
286
|
ctx.ui.setStatus(
|
|
175
287
|
"brl-subagent",
|