brl-subagent 2.5.2 → 2.7.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 +14 -11
- package/README.md +30 -6
- package/package.json +8 -5
- package/src/concurrency.ts +156 -44
- package/src/dispatch-line.ts +144 -0
- package/src/history.ts +13 -1
- package/src/index.ts +642 -743
- package/src/loader.ts +178 -0
- package/src/mode-prologue.ts +169 -0
- package/src/model-availability.ts +13 -1
- package/src/params.ts +252 -67
- package/src/prelude.ts +279 -3
- package/src/presets.ts +56 -148
- package/src/project-flags.ts +58 -0
- package/src/run-registry.ts +4 -1
- package/src/schema.ts +69 -51
- package/src/session-manager.ts +790 -91
- package/src/state.ts +29 -4
- package/src/store-permissions.ts +98 -0
- package/src/templates.ts +65 -121
- package/src/transcript.ts +5 -2
- package/src/transport-retry.ts +90 -0
- package/src/tui-format.ts +382 -4
- package/src/tui.ts +997 -867
- package/src/types.ts +54 -25
- package/src/validate.ts +41 -0
package/src/tui.ts
CHANGED
|
@@ -21,18 +21,20 @@ import type {
|
|
|
21
21
|
TaskTemplate,
|
|
22
22
|
SubagentResult,
|
|
23
23
|
SubagentRun,
|
|
24
|
-
|
|
24
|
+
SubTaskResult,
|
|
25
25
|
MultiSubagentDetails,
|
|
26
26
|
ChainDetails,
|
|
27
27
|
ParallelDetails,
|
|
28
28
|
GraphDetails,
|
|
29
29
|
DelegateTaskDetails,
|
|
30
|
-
|
|
30
|
+
DelegateTaskParams,
|
|
31
31
|
ThinkingLevel,
|
|
32
32
|
UsageStats,
|
|
33
33
|
FileDiff,
|
|
34
34
|
CompletionNotifyMode,
|
|
35
35
|
RecoveryMode,
|
|
36
|
+
LiveSubagent,
|
|
37
|
+
SLAMetrics,
|
|
36
38
|
} from "./types";
|
|
37
39
|
import {
|
|
38
40
|
THINKING_LEVELS,
|
|
@@ -46,7 +48,6 @@ import {
|
|
|
46
48
|
DEFAULT_OUTPUT_CAP_BYTES,
|
|
47
49
|
formatTokens,
|
|
48
50
|
formatUsageStats,
|
|
49
|
-
formatModel,
|
|
50
51
|
formatMaxParallel,
|
|
51
52
|
getFinalOutput,
|
|
52
53
|
isSubagentError,
|
|
@@ -58,7 +59,7 @@ import {
|
|
|
58
59
|
import { buildFileAccessReport, buildSecretsExposureReport, generateComplianceSummary } from "./reports";
|
|
59
60
|
import { extractParamNames } from "./templates";
|
|
60
61
|
import { parseDiff } from "./diff";
|
|
61
|
-
import { formatPresetSummary, getPreset, loadCustomPresets } from "./presets";
|
|
62
|
+
import { formatPresetSummary, getPreset, loadCustomPresets, sanitizeFileName } from "./presets";
|
|
62
63
|
import { buildOutputHonestyLines, formatRunDuration } from "./history";
|
|
63
64
|
import * as fs from "node:fs";
|
|
64
65
|
import * as path from "node:path";
|
|
@@ -66,7 +67,7 @@ import { collapseRunsForHistory, retryableRuns, sweepStaleLiveSubagents, type Se
|
|
|
66
67
|
import { getAgent } from "./session-manager";
|
|
67
68
|
import { visibleRunEntriesForSession } from "./recovery-surface";
|
|
68
69
|
import { computeSLAMetrics, computeCostTrend, formatSparkline } from "./metrics";
|
|
69
|
-
import { formatElapsed, liveRowName, liveSpinner, formatLiveRowDim, runHistoryStatus, runHistoryStatusLabel, buildRetryOfferMessage, runDisplayName } from "./tui-format";
|
|
70
|
+
import { formatElapsed, formatOutcomeSymbol, liveRowName, liveSpinner, formatLiveRowDim, runHistoryStatus, runHistoryStatusLabel, buildRetryOfferMessage, runDisplayName, formatMenuValue, formatTemplateSummary, menuSection } from "./tui-format";
|
|
70
71
|
import {
|
|
71
72
|
renderTranscriptMessages,
|
|
72
73
|
type TranscriptLineStyle,
|
|
@@ -121,6 +122,103 @@ export async function showSelectList(
|
|
|
121
122
|
});
|
|
122
123
|
}
|
|
123
124
|
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
// Choice-list rows (menu polish U2): one `(current)` marker syntax
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Apply the single canonical current-value marker to a choice label. Every
|
|
131
|
+
* in-scope choice list marks exactly the row whose value equals the current
|
|
132
|
+
* setting, and marks nothing when no current value exists.
|
|
133
|
+
*/
|
|
134
|
+
export function withCurrentMarker(label: string, isCurrent: boolean): string {
|
|
135
|
+
return isCurrent ? `${label} (current)` : label;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Model choice rows; the current `provider/id` carries the `(current)` marker. */
|
|
139
|
+
export function getModelSelectorItems(
|
|
140
|
+
models: ReadonlyArray<Pick<Model<Api>, "provider" | "id" | "name" | "contextWindow">>,
|
|
141
|
+
state: SessionState,
|
|
142
|
+
): SelectItem[] {
|
|
143
|
+
const current = state.config.model
|
|
144
|
+
? `${state.config.model.provider}/${state.config.model.id}`
|
|
145
|
+
: undefined;
|
|
146
|
+
return models.map((m) => {
|
|
147
|
+
const value = `${m.provider}/${m.id}`;
|
|
148
|
+
return {
|
|
149
|
+
value,
|
|
150
|
+
label: withCurrentMarker(value, value === current),
|
|
151
|
+
description: m.name ?? `context: ${(m.contextWindow ?? 0) / 1000}K`,
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Thinking-level choice rows; the configured ceiling carries the marker. */
|
|
157
|
+
export function getThinkingSelectorItems(state: SessionState): SelectItem[] {
|
|
158
|
+
return THINKING_LEVELS.map((level) => ({
|
|
159
|
+
value: level,
|
|
160
|
+
label: withCurrentMarker(level, level === state.config.maxThinkingLevel),
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Change-approval choice rows; the active mode carries the marker. */
|
|
165
|
+
export function getApprovalModeItems(state: SessionState): SelectItem[] {
|
|
166
|
+
const descriptions: Record<string, string> = {
|
|
167
|
+
auto: "Never ask - auto-approve",
|
|
168
|
+
writes: "Ask when files changed - default",
|
|
169
|
+
always: "Ask every time",
|
|
170
|
+
};
|
|
171
|
+
return (["auto", "writes", "always"] as const).map((mode) => ({
|
|
172
|
+
value: mode,
|
|
173
|
+
label: withCurrentMarker(mode, mode === state.config.approvalMode),
|
|
174
|
+
description: descriptions[mode],
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Completion-notify choice rows; the active mode carries the marker. */
|
|
179
|
+
export function getCompletionNotifyItems(state: SessionState): SelectItem[] {
|
|
180
|
+
const modeDescriptions: Record<CompletionNotifyMode, string> = {
|
|
181
|
+
all: "Wake on every terminal state (completed, failed, stopped) - default",
|
|
182
|
+
failed: "Wake only on failed / stopped runs",
|
|
183
|
+
off: "Never wake (still delivered passively at the next user prompt)",
|
|
184
|
+
};
|
|
185
|
+
return COMPLETION_NOTIFY_MODES.map((mode) => ({
|
|
186
|
+
value: mode,
|
|
187
|
+
label: withCurrentMarker(mode, mode === state.config.completionNotify),
|
|
188
|
+
description: modeDescriptions[mode],
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Recovery-posture choice rows; the active posture carries the marker. */
|
|
193
|
+
export function getRecoveryItems(state: SessionState): SelectItem[] {
|
|
194
|
+
const modeDescriptions: Record<RecoveryMode, string> = {
|
|
195
|
+
offer: "Surface interrupted runs (Run History row + one boot notice) - default",
|
|
196
|
+
off: "Do not surface interrupted runs",
|
|
197
|
+
};
|
|
198
|
+
return RECOVERY_MODES.map((mode) => ({
|
|
199
|
+
value: mode,
|
|
200
|
+
label: withCurrentMarker(mode, mode === state.config.recovery),
|
|
201
|
+
description: modeDescriptions[mode],
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** SLA enable→window step 1; exactly one of Enabled/Disabled carries the marker. */
|
|
206
|
+
export function getSLAEnableItems(state: SessionState): SelectItem[] {
|
|
207
|
+
const enabled = state.config.slaTrackingEnabled;
|
|
208
|
+
return [
|
|
209
|
+
{
|
|
210
|
+
value: "disabled",
|
|
211
|
+
label: withCurrentMarker("Disabled", !enabled),
|
|
212
|
+
description: "No SLA tracking",
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
value: "enabled",
|
|
216
|
+
label: withCurrentMarker("Enabled", enabled),
|
|
217
|
+
description: "Track performance metrics and detect degradation",
|
|
218
|
+
},
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
|
|
124
222
|
// ---------------------------------------------------------------------------
|
|
125
223
|
// Model selector
|
|
126
224
|
// ---------------------------------------------------------------------------
|
|
@@ -140,11 +238,7 @@ export async function showModelSelector(
|
|
|
140
238
|
return;
|
|
141
239
|
}
|
|
142
240
|
|
|
143
|
-
const items: SelectItem[] = availableModels
|
|
144
|
-
value: `${m.provider}/${m.id}`,
|
|
145
|
-
label: `${m.provider}/${m.id}`,
|
|
146
|
-
description: m.name ?? `context: ${(m.contextWindow ?? 0) / 1000}K`,
|
|
147
|
-
}));
|
|
241
|
+
const items: SelectItem[] = getModelSelectorItems(availableModels, state);
|
|
148
242
|
|
|
149
243
|
const result = await showSelectList(ctx, "Select Subagent Model", items, 15);
|
|
150
244
|
if (!result) return;
|
|
@@ -163,10 +257,7 @@ export async function showThinkingSelector(
|
|
|
163
257
|
state: SessionState,
|
|
164
258
|
onConfigChanged: (ctx: ExtensionContext, msg: string) => void,
|
|
165
259
|
): Promise<void> {
|
|
166
|
-
const items: SelectItem[] =
|
|
167
|
-
value: level,
|
|
168
|
-
label: level === state.config.maxThinkingLevel ? `${level} (current - ceiling)` : level,
|
|
169
|
-
}));
|
|
260
|
+
const items: SelectItem[] = getThinkingSelectorItems(state);
|
|
170
261
|
|
|
171
262
|
const result = await showSelectList(ctx, "Select Max Thinking Level", items, 10);
|
|
172
263
|
if (!result) return;
|
|
@@ -187,7 +278,9 @@ export async function showConcurrencyInput(
|
|
|
187
278
|
state: SessionState,
|
|
188
279
|
onConfigChanged: (ctx: ExtensionContext, msg: string) => void,
|
|
189
280
|
): Promise<void> {
|
|
190
|
-
const result = await ctx.ui.input(
|
|
281
|
+
const result = await ctx.ui.input(
|
|
282
|
+
`Max parallel subagents (0 = Unlimited \u00b7 current: ${formatMenuValue("parallel", { maxParallel: state.config.maxParallel })}):`,
|
|
283
|
+
);
|
|
191
284
|
if (result == null) return;
|
|
192
285
|
const num = parseInt(result, 10);
|
|
193
286
|
if (isNaN(num) || num < 0) {
|
|
@@ -207,7 +300,9 @@ export async function showDepthInput(
|
|
|
207
300
|
state: SessionState,
|
|
208
301
|
onConfigChanged: (ctx: ExtensionContext, msg: string) => void,
|
|
209
302
|
): Promise<void> {
|
|
210
|
-
const result = await ctx.ui.input(
|
|
303
|
+
const result = await ctx.ui.input(
|
|
304
|
+
`Max subagent recursion depth (0 = cannot delegate, 1 = one level \u00b7 current: ${formatMenuValue("depth", { maxSubagentDepth: state.config.maxSubagentDepth })}):`,
|
|
305
|
+
);
|
|
211
306
|
if (result == null) return;
|
|
212
307
|
const num = parseInt(result, 10);
|
|
213
308
|
if (isNaN(num) || num < 0) {
|
|
@@ -230,11 +325,12 @@ export async function showHistoryEntriesInput(
|
|
|
230
325
|
state: SessionState,
|
|
231
326
|
onConfigChanged: (ctx: ExtensionContext, msg: string) => void,
|
|
232
327
|
): Promise<void> {
|
|
233
|
-
const current =
|
|
234
|
-
state.config.maxHistoryEntries
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
328
|
+
const current = formatMenuValue("historyentries", {
|
|
329
|
+
maxHistoryEntries: state.config.maxHistoryEntries,
|
|
330
|
+
});
|
|
331
|
+
const result = await ctx.ui.input(
|
|
332
|
+
`Max run history entries (0 = Unlimited, default 500 \u00b7 current: ${current}):`,
|
|
333
|
+
);
|
|
238
334
|
if (result == null) return;
|
|
239
335
|
const num = parseInt(result, 10);
|
|
240
336
|
if (isNaN(num) || num < 0) {
|
|
@@ -245,7 +341,7 @@ export async function showHistoryEntriesInput(
|
|
|
245
341
|
onConfigChanged(
|
|
246
342
|
ctx,
|
|
247
343
|
num === 0
|
|
248
|
-
?
|
|
344
|
+
? `Run history set to ${formatMenuValue("historyentries", { maxHistoryEntries: num })}`
|
|
249
345
|
: `Run history entries set to ${num} (oldest entries will be pruned)`,
|
|
250
346
|
);
|
|
251
347
|
}
|
|
@@ -259,11 +355,12 @@ export async function showCostLimitInput(
|
|
|
259
355
|
state: SessionState,
|
|
260
356
|
onConfigChanged: (ctx: ExtensionContext, msg: string) => void,
|
|
261
357
|
): Promise<void> {
|
|
262
|
-
const current =
|
|
263
|
-
state.config.sessionCostLimit
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
358
|
+
const current = formatMenuValue("costlimit", {
|
|
359
|
+
sessionCostLimit: state.config.sessionCostLimit,
|
|
360
|
+
});
|
|
361
|
+
const result = await ctx.ui.input(
|
|
362
|
+
`Session cost limit in USD (0 = Unlimited, e.g. 1.00 for $1 \u00b7 current: ${current}):`,
|
|
363
|
+
);
|
|
267
364
|
if (result == null) return;
|
|
268
365
|
const num = parseFloat(result);
|
|
269
366
|
if (isNaN(num) || num < 0) {
|
|
@@ -274,7 +371,7 @@ export async function showCostLimitInput(
|
|
|
274
371
|
onConfigChanged(
|
|
275
372
|
ctx,
|
|
276
373
|
num === 0
|
|
277
|
-
?
|
|
374
|
+
? `Session cost limit set to ${formatMenuValue("costlimit", { sessionCostLimit: num })}`
|
|
278
375
|
: `Session cost limit set to $${num.toFixed(2)}`,
|
|
279
376
|
);
|
|
280
377
|
}
|
|
@@ -288,23 +385,7 @@ export async function showApprovalModeSelector(
|
|
|
288
385
|
state: SessionState,
|
|
289
386
|
onConfigChanged: (ctx: ExtensionContext, msg: string) => void,
|
|
290
387
|
): Promise<void> {
|
|
291
|
-
const items: SelectItem[] =
|
|
292
|
-
{
|
|
293
|
-
value: "auto",
|
|
294
|
-
label: "auto",
|
|
295
|
-
description: "Never ask - auto-approve",
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
value: "writes",
|
|
299
|
-
label: "writes",
|
|
300
|
-
description: "Ask when files changed - default",
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
value: "always",
|
|
304
|
-
label: "always",
|
|
305
|
-
description: "Ask every time",
|
|
306
|
-
},
|
|
307
|
-
];
|
|
388
|
+
const items: SelectItem[] = getApprovalModeItems(state);
|
|
308
389
|
|
|
309
390
|
const result = await showSelectList(ctx, "Select Change Approval Mode", items, 5);
|
|
310
391
|
if (!result) return;
|
|
@@ -322,18 +403,9 @@ export async function showCompletionNotifySelector(
|
|
|
322
403
|
state: SessionState,
|
|
323
404
|
onConfigChanged: (ctx: ExtensionContext, msg: string) => void,
|
|
324
405
|
): Promise<void> {
|
|
325
|
-
const
|
|
326
|
-
all: "Wake on every terminal state (completed, failed, stopped) - default",
|
|
327
|
-
failed: "Wake only on failed / stopped runs",
|
|
328
|
-
off: "Never wake (still delivered passively at the next user prompt)",
|
|
329
|
-
};
|
|
330
|
-
const items: SelectItem[] = COMPLETION_NOTIFY_MODES.map((mode) => ({
|
|
331
|
-
value: mode,
|
|
332
|
-
label: mode,
|
|
333
|
-
description: modeDescriptions[mode],
|
|
334
|
-
}));
|
|
406
|
+
const items: SelectItem[] = getCompletionNotifyItems(state);
|
|
335
407
|
|
|
336
|
-
const result = await showSelectList(ctx, "Completion Notify Mode", items, 5);
|
|
408
|
+
const result = await showSelectList(ctx, "Select Completion Notify Mode", items, 5);
|
|
337
409
|
if (!result) return;
|
|
338
410
|
|
|
339
411
|
state.config.completionNotify = result as CompletionNotifyMode;
|
|
@@ -349,17 +421,9 @@ export async function showRecoverySelector(
|
|
|
349
421
|
state: SessionState,
|
|
350
422
|
onConfigChanged: (ctx: ExtensionContext, msg: string) => void,
|
|
351
423
|
): Promise<void> {
|
|
352
|
-
const
|
|
353
|
-
offer: "Surface interrupted runs (Run History row + one boot notice) - default",
|
|
354
|
-
off: "Do not surface interrupted runs",
|
|
355
|
-
};
|
|
356
|
-
const items: SelectItem[] = RECOVERY_MODES.map((mode) => ({
|
|
357
|
-
value: mode,
|
|
358
|
-
label: mode,
|
|
359
|
-
description: modeDescriptions[mode],
|
|
360
|
-
}));
|
|
424
|
+
const items: SelectItem[] = getRecoveryItems(state);
|
|
361
425
|
|
|
362
|
-
const result = await showSelectList(ctx, "Recovery Posture", items, 5);
|
|
426
|
+
const result = await showSelectList(ctx, "Select Recovery Posture", items, 5);
|
|
363
427
|
if (!result) return;
|
|
364
428
|
|
|
365
429
|
state.config.recovery = result as RecoveryMode;
|
|
@@ -376,11 +440,8 @@ export async function showSLAConfig(
|
|
|
376
440
|
onConfigChanged: (ctx: ExtensionContext, msg: string) => void,
|
|
377
441
|
): Promise<void> {
|
|
378
442
|
// Step 1: Enable/disable toggle
|
|
379
|
-
const enableItems: SelectItem[] =
|
|
380
|
-
|
|
381
|
-
{ value: "enabled", label: "Enabled", description: "Track performance metrics and detect degradation" },
|
|
382
|
-
];
|
|
383
|
-
const enableResult = await showSelectList(ctx, "SLA Tracking", enableItems, 5);
|
|
443
|
+
const enableItems: SelectItem[] = getSLAEnableItems(state);
|
|
444
|
+
const enableResult = await showSelectList(ctx, "Configure SLA Tracking", enableItems, 5);
|
|
384
445
|
if (!enableResult) return;
|
|
385
446
|
|
|
386
447
|
const enabled = enableResult === "enabled";
|
|
@@ -392,7 +453,9 @@ export async function showSLAConfig(
|
|
|
392
453
|
}
|
|
393
454
|
|
|
394
455
|
// Step 2: Window size input
|
|
395
|
-
const sizeResult = await ctx.ui.input(
|
|
456
|
+
const sizeResult = await ctx.ui.input(
|
|
457
|
+
`Window size (10-500 \u00b7 current: ${state.config.slaWindowSize}):`,
|
|
458
|
+
);
|
|
396
459
|
if (sizeResult == null) return;
|
|
397
460
|
const size = parseInt(sizeResult, 10);
|
|
398
461
|
if (isNaN(size) || size < 10 || size > 500) {
|
|
@@ -403,6 +466,31 @@ export async function showSLAConfig(
|
|
|
403
466
|
onConfigChanged(ctx, `SLA tracking enabled with window size ${size}`);
|
|
404
467
|
}
|
|
405
468
|
|
|
469
|
+
/**
|
|
470
|
+
* D9: the one report "lines modal" — accent border, title, blank row, dim body
|
|
471
|
+
* lines, accent border. Closes on `q` or Escape. Presentation-only; every
|
|
472
|
+
* report screen routes through this so the chrome cannot drift between them.
|
|
473
|
+
*/
|
|
474
|
+
function showLinesModal(ctx: ExtensionContext, title: string, lines: string[]): void {
|
|
475
|
+
ctx.ui.custom((tui, theme, _kb, done) => {
|
|
476
|
+
const container = new Container();
|
|
477
|
+
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
478
|
+
container.addChild(new Text(theme.fg("accent", theme.bold(title)), 1, 0));
|
|
479
|
+
container.addChild(new Text("", 0, 0));
|
|
480
|
+
for (const line of lines) {
|
|
481
|
+
container.addChild(new Text(theme.fg("dim", line), 1, 0));
|
|
482
|
+
}
|
|
483
|
+
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
484
|
+
return {
|
|
485
|
+
render: (w: number) => container.render(w),
|
|
486
|
+
invalidate: () => container.invalidate(),
|
|
487
|
+
handleInput: (data: string) => {
|
|
488
|
+
if (data === "q" || data === "\x1b") done(undefined);
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
|
|
406
494
|
export async function showSLAStats(
|
|
407
495
|
ctx: ExtensionContext,
|
|
408
496
|
state: SessionState,
|
|
@@ -440,23 +528,7 @@ export async function showSLAStats(
|
|
|
440
528
|
}
|
|
441
529
|
}
|
|
442
530
|
|
|
443
|
-
ctx
|
|
444
|
-
const container = new Container();
|
|
445
|
-
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
446
|
-
container.addChild(new Text(theme.fg("accent", theme.bold("SLA Statistics")), 1, 0));
|
|
447
|
-
container.addChild(new Text("", 0, 0));
|
|
448
|
-
for (const line of lines) {
|
|
449
|
-
container.addChild(new Text(theme.fg("dim", line), 1, 0));
|
|
450
|
-
}
|
|
451
|
-
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
452
|
-
return {
|
|
453
|
-
render: (w: number) => container.render(w),
|
|
454
|
-
invalidate: () => container.invalidate(),
|
|
455
|
-
handleInput: (data: string) => {
|
|
456
|
-
if (data === "q" || data === "\x1b") done(undefined);
|
|
457
|
-
},
|
|
458
|
-
};
|
|
459
|
-
});
|
|
531
|
+
showLinesModal(ctx, "SLA Statistics", lines);
|
|
460
532
|
}
|
|
461
533
|
|
|
462
534
|
// Preset management UI
|
|
@@ -498,23 +570,7 @@ export async function showFileAccessReport(
|
|
|
498
570
|
lines.push(` Runs: ${runIds.join(", ")}`);
|
|
499
571
|
}
|
|
500
572
|
|
|
501
|
-
ctx
|
|
502
|
-
const container = new Container();
|
|
503
|
-
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
504
|
-
container.addChild(new Text(theme.fg("accent", theme.bold("File Access Report")), 1, 0));
|
|
505
|
-
container.addChild(new Text("", 0, 0));
|
|
506
|
-
for (const line of lines) {
|
|
507
|
-
container.addChild(new Text(theme.fg("dim", line), 1, 0));
|
|
508
|
-
}
|
|
509
|
-
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
510
|
-
return {
|
|
511
|
-
render: (w: number) => container.render(w),
|
|
512
|
-
invalidate: () => container.invalidate(),
|
|
513
|
-
handleInput: (data: string) => {
|
|
514
|
-
if (data === "q" || data === "\x1b") done(undefined);
|
|
515
|
-
},
|
|
516
|
-
};
|
|
517
|
-
});
|
|
573
|
+
showLinesModal(ctx, "File Access Report", lines);
|
|
518
574
|
}
|
|
519
575
|
|
|
520
576
|
export async function showSecretsExposureReport(
|
|
@@ -571,23 +627,7 @@ export async function showSecretsExposureReport(
|
|
|
571
627
|
}
|
|
572
628
|
}
|
|
573
629
|
|
|
574
|
-
ctx
|
|
575
|
-
const container = new Container();
|
|
576
|
-
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
577
|
-
container.addChild(new Text(theme.fg("accent", theme.bold("Secrets Exposure Report")), 1, 0));
|
|
578
|
-
container.addChild(new Text("", 0, 0));
|
|
579
|
-
for (const line of lines) {
|
|
580
|
-
container.addChild(new Text(theme.fg("dim", line), 1, 0));
|
|
581
|
-
}
|
|
582
|
-
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
583
|
-
return {
|
|
584
|
-
render: (w: number) => container.render(w),
|
|
585
|
-
invalidate: () => container.invalidate(),
|
|
586
|
-
handleInput: (data: string) => {
|
|
587
|
-
if (data === "q" || data === "\x1b") done(undefined);
|
|
588
|
-
},
|
|
589
|
-
};
|
|
590
|
-
});
|
|
630
|
+
showLinesModal(ctx, "Secrets Exposure Report", lines);
|
|
591
631
|
}
|
|
592
632
|
|
|
593
633
|
export async function showFullComplianceSummary(
|
|
@@ -620,23 +660,7 @@ export async function showFullComplianceSummary(
|
|
|
620
660
|
` High Severity: ${summary.highSeverityFindings}`,
|
|
621
661
|
];
|
|
622
662
|
|
|
623
|
-
ctx
|
|
624
|
-
const container = new Container();
|
|
625
|
-
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
626
|
-
container.addChild(new Text(theme.fg("accent", theme.bold("Compliance Summary")), 1, 0));
|
|
627
|
-
container.addChild(new Text("", 0, 0));
|
|
628
|
-
for (const line of lines) {
|
|
629
|
-
container.addChild(new Text(theme.fg("dim", line), 1, 0));
|
|
630
|
-
}
|
|
631
|
-
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
632
|
-
return {
|
|
633
|
-
render: (w: number) => container.render(w),
|
|
634
|
-
invalidate: () => container.invalidate(),
|
|
635
|
-
handleInput: (data: string) => {
|
|
636
|
-
if (data === "q" || data === "\x1b") done(undefined);
|
|
637
|
-
},
|
|
638
|
-
};
|
|
639
|
-
});
|
|
663
|
+
showLinesModal(ctx, "Compliance Summary", lines);
|
|
640
664
|
}
|
|
641
665
|
|
|
642
666
|
export async function showComplianceMenu(
|
|
@@ -686,193 +710,256 @@ export async function showPresetManager(
|
|
|
686
710
|
|
|
687
711
|
const items: SelectItem[] = [
|
|
688
712
|
...builtinItems,
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
value: "__divider__",
|
|
693
|
-
label: "\u2500\u2500\u2500 Custom Presets \u2500\u2500\u2500",
|
|
694
|
-
description: "",
|
|
695
|
-
},
|
|
696
|
-
]
|
|
697
|
-
: []),
|
|
713
|
+
// Shared factory (U1) rather than a literal: same value shape
|
|
714
|
+
// (`__divider__:<slug>`) and label grammar as every other section row.
|
|
715
|
+
...(customItems.length > 0 ? [menuSection("Custom Presets")] : []),
|
|
698
716
|
...customItems,
|
|
699
717
|
];
|
|
700
718
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
719
|
+
// Defensive zero-item case, mirroring the Templates manager: never open an
|
|
720
|
+
// empty SelectList — say so instead.
|
|
721
|
+
if (items.length === 0) {
|
|
722
|
+
ctx.ui.notify(emptyManagerNotice("presets", "presets", "presets"), "info");
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const title = `Presets (${state.builtinPresets.length} built-in, ${state.customPresets.length} custom)`;
|
|
727
|
+
|
|
728
|
+
// Browse loop: selecting the divider is a no-op re-render (the list comes
|
|
729
|
+
// back), never a close — the same semantics as the Templates manager and
|
|
730
|
+
// the config menu's dividers.
|
|
731
|
+
while (true) {
|
|
732
|
+
const result = await showSelectList(ctx, title, items, 15);
|
|
733
|
+
if (!result) return;
|
|
734
|
+
if (isDividerValue(result)) continue;
|
|
708
735
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
const isBuiltin = result.startsWith("__builtin__:");
|
|
712
|
-
const isCustom = result.startsWith("__custom__:");
|
|
713
|
-
const presetName = isBuiltin
|
|
736
|
+
// Row values carry the tier prefix; the detail view takes the bare name.
|
|
737
|
+
const presetName = result.startsWith("__builtin__:")
|
|
714
738
|
? result.slice("__builtin__:".length)
|
|
715
|
-
:
|
|
739
|
+
: result.startsWith("__custom__:")
|
|
716
740
|
? result.slice("__custom__:".length)
|
|
717
741
|
: result;
|
|
742
|
+
await showViewPreset(ctx, state, presetName);
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
718
746
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
747
|
+
/**
|
|
748
|
+
* Preset detail view. Mirrors `showViewTemplate` exactly (U6): same tier suffix
|
|
749
|
+
* vocabulary, same `Label: value` field grammar, and the same unset-field policy
|
|
750
|
+
* — unset optional fields are omitted, `Inherit:` always renders because it is a
|
|
751
|
+
* real default (`yes (default)`), not an absent value.
|
|
752
|
+
*/
|
|
753
|
+
export async function showViewPreset(
|
|
754
|
+
ctx: ExtensionContext,
|
|
755
|
+
state: SessionState,
|
|
756
|
+
name: string,
|
|
757
|
+
): Promise<void> {
|
|
758
|
+
const preset = getPreset(name, state.builtinPresets, state.customPresets);
|
|
759
|
+
if (!preset) return;
|
|
760
|
+
|
|
761
|
+
// A custom preset that shadows a built-in name wins in getPreset, so only a
|
|
762
|
+
// name with no custom entry is `builtin`; the rest split project/global.
|
|
763
|
+
const tier: Tier = state.customPresets.some((p) => p.name === preset.name)
|
|
764
|
+
? findPresetSource(preset.name, ctx)
|
|
765
|
+
: "builtin";
|
|
766
|
+
|
|
767
|
+
await showDetailView(ctx, {
|
|
768
|
+
title: `Preset: ${preset.name}`,
|
|
769
|
+
tier,
|
|
770
|
+
description: preset.description,
|
|
771
|
+
content: (theme) =>
|
|
772
|
+
detailFieldLines(theme, [
|
|
773
|
+
{ label: "Thinking", value: preset.thinkingLevel },
|
|
774
|
+
{
|
|
775
|
+
label: "Inherit",
|
|
776
|
+
value: preset.inheritSystemPrompt === false ? "no" : "yes (default)",
|
|
777
|
+
},
|
|
778
|
+
{ label: "Tools", value: preset.tools?.join(", ") },
|
|
779
|
+
{ label: "Exclude", value: preset.excludeTools?.join(", ") },
|
|
780
|
+
{ label: "System prompt", value: preset.systemPrompt?.slice(0, 100) },
|
|
781
|
+
]),
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// ---------------------------------------------------------------------------
|
|
786
|
+
// Tier classification (menu polish U4, umbrella #345)
|
|
787
|
+
// ---------------------------------------------------------------------------
|
|
788
|
+
|
|
789
|
+
/** Tier vocabulary shared by presets and templates: shipped, project-local, user-global. */
|
|
790
|
+
export type Tier = "builtin" | "project" | "global";
|
|
791
|
+
|
|
792
|
+
/** One candidate directory for classifyTier, tagged with the tier it represents. */
|
|
793
|
+
export interface TierDir {
|
|
794
|
+
tier: "project" | "global";
|
|
795
|
+
dir: string;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/** Injected I/O and terminal fallback for classifyTier (keeps the decision pure). */
|
|
799
|
+
export interface TierClassifierIo {
|
|
800
|
+
/** Terminal fallback for the surface: the tier to return when no canonical file matches. */
|
|
801
|
+
fallback: Tier;
|
|
802
|
+
/** Existence probe for a candidate file path. */
|
|
803
|
+
exists: (filePath: string) => boolean;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Pure tier classifier: decide which tier a preset or template name comes from.
|
|
808
|
+
*
|
|
809
|
+
* Order of decision:
|
|
810
|
+
* 1. `<sanitizeFileName(name)>.md` in each `dirs` entry, in order — the real
|
|
811
|
+
* writers (`writePresetFile` / `writeTemplateFile`) emit exactly that
|
|
812
|
+
* filename via the same `sanitizeFileName`, so a file we wrote by name is
|
|
813
|
+
* always resolved by path (#345 A1: the pre-U4 finders re-derived a
|
|
814
|
+
* different, lowercased/underscored filename convention and missed it).
|
|
815
|
+
* 2. `io.fallback` — the surface's terminal value: `builtin` for templates,
|
|
816
|
+
* `project` for presets (the preset manager only has [P]/[G] labels, so it
|
|
817
|
+
* maps the non-global answer to `project`).
|
|
818
|
+
*
|
|
819
|
+
* Both the filesystem and the fallback are injected, so the result is a pure
|
|
820
|
+
* function of its arguments and testable against temp dirs or stubs.
|
|
821
|
+
*
|
|
822
|
+
* Documented residual (accepted this cycle): a hand-written file that overrides
|
|
823
|
+
* a builtin NAME but is stored under a non-canonical filename matches no path
|
|
824
|
+
* and is therefore classified by the surface fallback (templates → `builtin`,
|
|
825
|
+
* presets → `project`). The additive `source` field (out of scope for U4) is
|
|
826
|
+
* what would fix it.
|
|
827
|
+
*/
|
|
828
|
+
export function classifyTier(
|
|
829
|
+
name: string,
|
|
830
|
+
dirs: readonly TierDir[],
|
|
831
|
+
io: TierClassifierIo,
|
|
832
|
+
): Tier {
|
|
833
|
+
const fileName = sanitizeFileName(name) + ".md";
|
|
834
|
+
for (const { tier, dir } of dirs) {
|
|
835
|
+
if (io.exists(path.join(dir, fileName))) return tier;
|
|
770
836
|
}
|
|
837
|
+
return io.fallback;
|
|
771
838
|
}
|
|
772
839
|
|
|
773
840
|
/**
|
|
774
|
-
*
|
|
775
|
-
*
|
|
841
|
+
* The two on-disk tiers for a preset or template surface, highest priority
|
|
842
|
+
* first. Mirrors the order loadCustomPresets/loadCustomTemplates scan: the
|
|
843
|
+
* project-local dir wins over the user-global dir.
|
|
776
844
|
*/
|
|
777
|
-
function
|
|
845
|
+
function tierDirs(ctx: ExtensionContext, kind: "presets" | "templates"): TierDir[] {
|
|
778
846
|
const homedir = process.env.HOME || process.env.USERPROFILE || "";
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
847
|
+
return [
|
|
848
|
+
{ tier: "project", dir: path.join(ctx.cwd, ".pi", "brl-subagent", kind) },
|
|
849
|
+
{ tier: "global", dir: path.join(homedir, ".pi", "agent", "brl-subagent", kind) },
|
|
850
|
+
];
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* Determine whether a custom preset comes from the project or global directory.
|
|
855
|
+
* Delegates the decision to classifyTier; the preset manager only ever labels
|
|
856
|
+
* custom entries ([P]/[G]), and the preset surface fallback is already
|
|
857
|
+
* `project`, so a builtin-named custom preset stored under a non-canonical
|
|
858
|
+
* filename keeps the pre-U4 project label.
|
|
859
|
+
*/
|
|
860
|
+
export function findPresetSource(name: string, ctx: ExtensionContext): "project" | "global" {
|
|
861
|
+
const tier = classifyTier(name, tierDirs(ctx, "presets"), {
|
|
862
|
+
fallback: "project",
|
|
863
|
+
exists: fs.existsSync,
|
|
864
|
+
});
|
|
865
|
+
return tier === "global" ? "global" : "project";
|
|
786
866
|
}
|
|
787
867
|
|
|
788
868
|
/**
|
|
789
869
|
* Determine which tier a template comes from: project, global, or builtin.
|
|
790
|
-
*
|
|
791
|
-
*
|
|
870
|
+
* Mirrors findPresetSource. The `builtin` terminal value is the template
|
|
871
|
+
* surface fallback: any name with no canonical file on disk is `builtin`.
|
|
792
872
|
*/
|
|
793
|
-
function findTemplateSource(
|
|
794
|
-
name
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
const projectDir = path.join(ctx.cwd, ".pi", "brl-subagent", "templates");
|
|
799
|
-
const globalDir = path.join(homedir, ".pi", "agent", "brl-subagent", "templates");
|
|
800
|
-
// Prefer project over global (project has higher priority in loadCustomTemplates)
|
|
801
|
-
const sanitizedName = name.replace(/[^a-zA-Z0-9_-]/g, "_").toLowerCase();
|
|
802
|
-
if (fs.existsSync(path.join(projectDir, sanitizedName + ".md"))) return "project";
|
|
803
|
-
if (fs.existsSync(path.join(globalDir, sanitizedName + ".md"))) return "global";
|
|
804
|
-
return "builtin";
|
|
873
|
+
export function findTemplateSource(name: string, ctx: ExtensionContext): Tier {
|
|
874
|
+
return classifyTier(name, tierDirs(ctx, "templates"), {
|
|
875
|
+
fallback: "builtin",
|
|
876
|
+
exists: fs.existsSync,
|
|
877
|
+
});
|
|
805
878
|
}
|
|
806
879
|
|
|
807
880
|
// ---------------------------------------------------------------------------
|
|
808
|
-
//
|
|
881
|
+
// Shared manager/detail helpers (menu polish U6, umbrella #345)
|
|
809
882
|
// ---------------------------------------------------------------------------
|
|
810
883
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
884
|
+
/**
|
|
885
|
+
* The empty-state notice every manager surface uses: one shape, one set of
|
|
886
|
+
* places to add files. A manager whose row list is empty notifies with this
|
|
887
|
+
* instead of opening a SelectList with nothing to select.
|
|
888
|
+
*/
|
|
889
|
+
export function emptyManagerNotice(
|
|
890
|
+
loadedNoun: string,
|
|
891
|
+
builtinNoun: string,
|
|
892
|
+
dir: string,
|
|
893
|
+
): string {
|
|
894
|
+
return (
|
|
895
|
+
`No ${loadedNoun} loaded — built-in ${builtinNoun} ship with the extension and ` +
|
|
896
|
+
"should always be present. Add custom .md files in " +
|
|
897
|
+
`~/.pi/agent/brl-subagent/${dir}/ or <project>/.pi/brl-subagent/${dir}/.`
|
|
898
|
+
);
|
|
816
899
|
}
|
|
817
900
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
901
|
+
/**
|
|
902
|
+
* Tier suffix for a detail-view title: `(built-in)`, `(project)`, or `(global)`.
|
|
903
|
+
* One vocabulary for both detail views, so the title always names the same tier
|
|
904
|
+
* the manager row's `[B]`/`[P]`/`[G]` prefix came from.
|
|
905
|
+
*/
|
|
906
|
+
export function tierDetailSuffix(tier: Tier): string {
|
|
907
|
+
return tier === "builtin" ? " (built-in)" : tier === "project" ? " (project)" : " (global)";
|
|
908
|
+
}
|
|
825
909
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
: " (global)";
|
|
910
|
+
/**
|
|
911
|
+
* One `Label: value` row in a detail view. `value === undefined` means "unset"
|
|
912
|
+
* and the row is omitted (the U6 unset-field policy).
|
|
913
|
+
*/
|
|
914
|
+
export interface DetailField {
|
|
915
|
+
label: string;
|
|
916
|
+
value: string | undefined;
|
|
917
|
+
}
|
|
835
918
|
|
|
836
|
-
|
|
919
|
+
/**
|
|
920
|
+
* Render a detail view's field block: dim `Label: value` lines, in the order
|
|
921
|
+
* given, with unset fields omitted. A field that has a real DEFAULT (such as
|
|
922
|
+
* `Inherit: yes (default)`) passes its resolved value and therefore always
|
|
923
|
+
* renders — the policy drops absent data, not defaults.
|
|
924
|
+
*/
|
|
925
|
+
export function detailFieldLines(theme: Theme, fields: readonly DetailField[]): string[] {
|
|
926
|
+
return fields
|
|
927
|
+
.filter((f) => f.value !== undefined && f.value !== "")
|
|
928
|
+
.map((f) => theme.fg("dim", `${f.label}: ${f.value}`));
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/** What a detail view shows: a titled, tier-suffixed header plus body lines. */
|
|
932
|
+
export interface DetailView {
|
|
933
|
+
/** Bold accent title, e.g. `Preset: code-review`. */
|
|
934
|
+
title: string;
|
|
935
|
+
/** Tier vocabulary from `tierDetailSuffix`. */
|
|
936
|
+
tier: Tier;
|
|
937
|
+
/** Optional dim subtitle under the title. */
|
|
938
|
+
description?: string;
|
|
939
|
+
/** Body lines (a lead row first, then the field block). */
|
|
940
|
+
content: (theme: Theme) => string[];
|
|
941
|
+
}
|
|
837
942
|
|
|
943
|
+
/**
|
|
944
|
+
* The one detail-view shell both `showViewPreset` and `showViewTemplate` use:
|
|
945
|
+
* accent border, title + tier suffix, optional description, body, close hint.
|
|
946
|
+
* Sharing it keeps the grammar and suffix vocabulary from drifting apart.
|
|
947
|
+
*/
|
|
948
|
+
async function showDetailView(ctx: ExtensionContext, view: DetailView): Promise<void> {
|
|
838
949
|
await ctx.ui.custom<void>((_tui, theme, _kb, done) => {
|
|
839
950
|
const container = new Container();
|
|
840
951
|
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
841
952
|
container.addChild(
|
|
842
953
|
new Text(
|
|
843
|
-
theme.fg("accent", theme.bold(
|
|
844
|
-
theme.fg("dim", tierSuffix),
|
|
954
|
+
theme.fg("accent", theme.bold(view.title)) + theme.fg("dim", tierDetailSuffix(view.tier)),
|
|
845
955
|
1,
|
|
846
956
|
0,
|
|
847
957
|
),
|
|
848
958
|
);
|
|
849
|
-
if (
|
|
850
|
-
container.addChild(new Text(theme.fg("dim",
|
|
959
|
+
if (view.description)
|
|
960
|
+
container.addChild(new Text(theme.fg("dim", view.description), 1, 0));
|
|
851
961
|
container.addChild(new Text("", 0, 0));
|
|
852
|
-
container.addChild(
|
|
853
|
-
new Text(theme.fg("toolTitle", "Task:") + " " + theme.fg("toolOutput", template.task), 1, 0),
|
|
854
|
-
);
|
|
855
|
-
if (paramNames.length > 0) {
|
|
856
|
-
container.addChild(
|
|
857
|
-
new Text(theme.fg("dim", `Parameters: ${paramNames.join(", ")}`), 1, 0),
|
|
858
|
-
);
|
|
859
|
-
}
|
|
860
|
-
if (template.preset)
|
|
861
|
-
container.addChild(
|
|
862
|
-
new Text(theme.fg("dim", `Preset: ${template.preset}`), 1, 0),
|
|
863
|
-
);
|
|
864
|
-
if (template.thinkingLevel)
|
|
865
|
-
container.addChild(
|
|
866
|
-
new Text(theme.fg("dim", `Thinking: ${template.thinkingLevel}`), 1, 0),
|
|
867
|
-
);
|
|
868
|
-
if (template.outputFile)
|
|
869
|
-
container.addChild(
|
|
870
|
-
new Text(theme.fg("dim", `Output file: ${template.outputFile}`), 1, 0),
|
|
871
|
-
);
|
|
872
|
-
if (template.timeout)
|
|
873
|
-
container.addChild(
|
|
874
|
-
new Text(theme.fg("dim", `Timeout: ${template.timeout}ms`), 1, 0),
|
|
875
|
-
);
|
|
962
|
+
for (const line of view.content(theme)) container.addChild(new Text(line, 1, 0));
|
|
876
963
|
container.addChild(new Text("", 0, 0));
|
|
877
964
|
container.addChild(new Text(theme.fg("dim", "Press any key to close"), 1, 0));
|
|
878
965
|
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
@@ -884,117 +971,217 @@ export async function showViewTemplate(
|
|
|
884
971
|
});
|
|
885
972
|
}
|
|
886
973
|
|
|
974
|
+
// ---------------------------------------------------------------------------
|
|
975
|
+
// Template management UI
|
|
976
|
+
// ---------------------------------------------------------------------------
|
|
977
|
+
|
|
978
|
+
/** True for a select-list divider row (`menuSection` shape), never a template. */
|
|
979
|
+
function isDividerValue(value: string): boolean {
|
|
980
|
+
return value.startsWith("__divider__");
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* Split the merged template stack by membership in the shipped built-ins: a
|
|
985
|
+
* built-in OBJECT is `builtin`, everything else is `custom`. Object identity —
|
|
986
|
+
* not the name, not the filename — is the partition key, so a custom template
|
|
987
|
+
* that overrides a built-in name (the merged stack then holds only the custom
|
|
988
|
+
* object) still counts as custom. Both the manager and the parent config row
|
|
989
|
+
* read this, so their counts can never disagree.
|
|
990
|
+
*/
|
|
991
|
+
export function partitionTemplates(
|
|
992
|
+
templates: readonly TaskTemplate[],
|
|
993
|
+
builtinTemplates: readonly TaskTemplate[],
|
|
994
|
+
): { builtin: TaskTemplate[]; custom: TaskTemplate[] } {
|
|
995
|
+
const shipped = new Set<TaskTemplate>(builtinTemplates);
|
|
996
|
+
const builtin: TaskTemplate[] = [];
|
|
997
|
+
const custom: TaskTemplate[] = [];
|
|
998
|
+
for (const t of templates) (shipped.has(t) ? builtin : custom).push(t);
|
|
999
|
+
return { builtin, custom };
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Build the Templates manager's rows: built-ins first (shipped order), then —
|
|
1004
|
+
* only when customs exist — a `─── Custom Templates ───` divider, then customs
|
|
1005
|
+
* in current order. Pure: the tier lookup for the `[P]`/`[G]` prefix is injected
|
|
1006
|
+
* (`findTemplateSource` in production), so ordering/partition is testable with
|
|
1007
|
+
* no TUI and no filesystem.
|
|
1008
|
+
*
|
|
1009
|
+
* @param templates - the FULL merged stack (`state.config.templates`)
|
|
1010
|
+
* @param sourceOf - tier lookup for a custom row's prefix
|
|
1011
|
+
* @param builtinTemplates - the shipped built-ins (`state.builtinTemplates`)
|
|
1012
|
+
*/
|
|
1013
|
+
export function buildTemplateMenuItems(
|
|
1014
|
+
templates: readonly TaskTemplate[],
|
|
1015
|
+
sourceOf: (name: string) => Tier,
|
|
1016
|
+
builtinTemplates: readonly TaskTemplate[],
|
|
1017
|
+
): SelectItem[] {
|
|
1018
|
+
const { builtin, custom } = partitionTemplates(templates, builtinTemplates);
|
|
1019
|
+
|
|
1020
|
+
const rows = (list: TaskTemplate[], prefix: (t: TaskTemplate) => string): SelectItem[] =>
|
|
1021
|
+
list.map((t) => ({
|
|
1022
|
+
value: t.name,
|
|
1023
|
+
label: `[${prefix(t)}] ${t.name}`,
|
|
1024
|
+
description: t.description || formatTemplateSummary(t),
|
|
1025
|
+
}));
|
|
1026
|
+
|
|
1027
|
+
return [
|
|
1028
|
+
...rows(builtin, () => "B"),
|
|
1029
|
+
...(custom.length > 0 ? [menuSection("Custom Templates")] : []),
|
|
1030
|
+
...rows(custom, (t) => (sourceOf(t.name) === "project" ? "P" : "G")),
|
|
1031
|
+
];
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
export function getTemplate(
|
|
1035
|
+
name: string,
|
|
1036
|
+
templates: TaskTemplate[],
|
|
1037
|
+
): TaskTemplate | undefined {
|
|
1038
|
+
return templates.find((t) => t.name === name);
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
export async function showViewTemplate(
|
|
1042
|
+
ctx: ExtensionContext,
|
|
1043
|
+
state: SessionState,
|
|
1044
|
+
name: string,
|
|
1045
|
+
): Promise<void> {
|
|
1046
|
+
const template = getTemplate(name, state.config.templates);
|
|
1047
|
+
if (!template) return;
|
|
1048
|
+
|
|
1049
|
+
const paramNames = extractParamNames(template.task + (template.outputFile || ""));
|
|
1050
|
+
|
|
1051
|
+
await showDetailView(ctx, {
|
|
1052
|
+
title: `Template: ${template.name}`,
|
|
1053
|
+
tier: findTemplateSource(template.name, ctx),
|
|
1054
|
+
description: template.description,
|
|
1055
|
+
// The task IS the template, so it leads the body; every other concept is
|
|
1056
|
+
// an optional field and follows the shared omit-when-unset policy.
|
|
1057
|
+
content: (theme) => [
|
|
1058
|
+
theme.fg("toolTitle", "Task:") + " " + theme.fg("toolOutput", template.task),
|
|
1059
|
+
...detailFieldLines(theme, [
|
|
1060
|
+
{
|
|
1061
|
+
label: "Parameters",
|
|
1062
|
+
value: paramNames.length > 0 ? paramNames.join(", ") : undefined,
|
|
1063
|
+
},
|
|
1064
|
+
{ label: "Preset", value: template.preset },
|
|
1065
|
+
{ label: "Thinking", value: template.thinkingLevel },
|
|
1066
|
+
{ label: "Output file", value: template.outputFile },
|
|
1067
|
+
{ label: "Timeout", value: template.timeout ? `${template.timeout}ms` : undefined },
|
|
1068
|
+
]),
|
|
1069
|
+
],
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
|
|
887
1073
|
export async function showTemplateManager(
|
|
888
1074
|
ctx: ExtensionContext,
|
|
889
1075
|
state: SessionState,
|
|
890
1076
|
): Promise<void> {
|
|
891
1077
|
if (state.config.templates.length === 0) {
|
|
892
|
-
ctx.ui.notify(
|
|
893
|
-
"No task templates loaded — built-in templates ship with the extension and " +
|
|
894
|
-
"should always be present. Add custom .md files in " +
|
|
895
|
-
"~/.pi/agent/brl-subagent/templates/ or <project>/.pi/brl-subagent/templates/.",
|
|
896
|
-
"info",
|
|
897
|
-
);
|
|
1078
|
+
ctx.ui.notify(emptyManagerNotice("task templates", "templates", "templates"), "info");
|
|
898
1079
|
return;
|
|
899
1080
|
}
|
|
900
1081
|
|
|
901
|
-
//
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
label: `[${tierLabel}] ${t.name}`,
|
|
908
|
-
description: t.description || t.task.slice(0, 60),
|
|
909
|
-
};
|
|
910
|
-
});
|
|
911
|
-
|
|
912
|
-
const result = await showSelectList(
|
|
913
|
-
ctx,
|
|
914
|
-
`Templates (${state.config.templates.length})`,
|
|
915
|
-
templateItems,
|
|
916
|
-
15,
|
|
1082
|
+
// The FULL merged stack plus the shipped built-ins: the builder partitions by
|
|
1083
|
+
// membership, so custom-overrides-builtin still classifies as custom.
|
|
1084
|
+
const items = buildTemplateMenuItems(
|
|
1085
|
+
state.config.templates,
|
|
1086
|
+
(name) => findTemplateSource(name, ctx),
|
|
1087
|
+
state.builtinTemplates,
|
|
917
1088
|
);
|
|
918
|
-
|
|
1089
|
+
const { builtin, custom } = partitionTemplates(state.config.templates, state.builtinTemplates);
|
|
1090
|
+
const title = `Templates (${builtin.length} built-in, ${custom.length} custom)`;
|
|
1091
|
+
|
|
1092
|
+
// Browse loop: selecting the divider is a no-op re-render (the list comes
|
|
1093
|
+
// back), never a close — mirrors the config menu's divider semantics.
|
|
1094
|
+
while (true) {
|
|
1095
|
+
const result = await showSelectList(ctx, title, items, 15);
|
|
1096
|
+
if (!result) return;
|
|
1097
|
+
if (isDividerValue(result)) continue;
|
|
919
1098
|
|
|
920
|
-
|
|
1099
|
+
await showViewTemplate(ctx, state, result);
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
921
1102
|
}
|
|
922
1103
|
|
|
923
1104
|
// ---------------------------------------------------------------------------
|
|
924
1105
|
// Configuration menu
|
|
925
1106
|
// ---------------------------------------------------------------------------
|
|
926
1107
|
|
|
1108
|
+
/** Maximum config rows visible before the list scrolls (U3: 10 → 15). */
|
|
1109
|
+
export const CONFIG_MENU_VIEWPORT = 15;
|
|
1110
|
+
|
|
927
1111
|
export function getConfigMenuItems(state: SessionState): SelectItem[] {
|
|
1112
|
+
// Menu polish U2: every value row renders the canonical token from
|
|
1113
|
+
// `formatMenuValue` (tui-format.ts) instead of hand-rolled prose. Templates
|
|
1114
|
+
// have no `customTemplates` field on state; the merged stack keeps the
|
|
1115
|
+
// BUILTIN objects by reference (getAllTemplates), so an identity partition
|
|
1116
|
+
// is the state-side equivalent of the manager's builtin/custom split.
|
|
1117
|
+
const templateCounts = partitionTemplates(state.config.templates, state.builtinTemplates);
|
|
1118
|
+
|
|
928
1119
|
return [
|
|
929
1120
|
{
|
|
930
1121
|
value: "model",
|
|
931
|
-
label: "
|
|
932
|
-
description: state.config.model
|
|
933
|
-
? `${state.config.model.provider}/${state.config.model.id}`
|
|
934
|
-
: "Not set (will use main agent\u2019s model by default)",
|
|
1122
|
+
label: "Set Model",
|
|
1123
|
+
description: formatMenuValue("model", { model: state.config.model }),
|
|
935
1124
|
},
|
|
936
1125
|
{
|
|
937
1126
|
value: "thinking",
|
|
938
|
-
label: "
|
|
939
|
-
description:
|
|
1127
|
+
label: "Set Max Thinking Level",
|
|
1128
|
+
description: formatMenuValue("thinking", {
|
|
1129
|
+
maxThinkingLevel: state.config.maxThinkingLevel,
|
|
1130
|
+
}),
|
|
940
1131
|
},
|
|
941
1132
|
{
|
|
942
1133
|
value: "concurrency",
|
|
943
1134
|
label: "Set Max Parallel Subagents",
|
|
944
|
-
description:
|
|
1135
|
+
description: formatMenuValue("parallel", { maxParallel: state.config.maxParallel }),
|
|
945
1136
|
},
|
|
946
1137
|
{
|
|
947
1138
|
value: "depth",
|
|
948
1139
|
label: "Set Max Recursion Depth",
|
|
949
|
-
description:
|
|
950
|
-
|
|
951
|
-
|
|
1140
|
+
description: formatMenuValue("depth", {
|
|
1141
|
+
maxSubagentDepth: state.config.maxSubagentDepth,
|
|
1142
|
+
}),
|
|
952
1143
|
},
|
|
953
1144
|
{
|
|
954
1145
|
value: "approval",
|
|
955
1146
|
label: "Set Change Approval Mode",
|
|
956
|
-
description: state.config.approvalMode
|
|
957
|
-
? "Never ask"
|
|
958
|
-
: state.config.approvalMode === "writes"
|
|
959
|
-
? "Ask when files changed"
|
|
960
|
-
: "Ask every time",
|
|
1147
|
+
description: formatMenuValue("approval", { approvalMode: state.config.approvalMode }),
|
|
961
1148
|
},
|
|
962
1149
|
{
|
|
963
1150
|
value: "completionnotify",
|
|
964
1151
|
label: "Set Completion Notify Mode",
|
|
965
|
-
description:
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
? "Wake only on failed/stopped"
|
|
969
|
-
: "Never wake (passive delivery)",
|
|
1152
|
+
description: formatMenuValue("completionnotify", {
|
|
1153
|
+
completionNotify: state.config.completionNotify,
|
|
1154
|
+
}),
|
|
970
1155
|
},
|
|
971
1156
|
{
|
|
972
1157
|
value: "recovery",
|
|
973
1158
|
label: "Set Recovery Posture",
|
|
974
|
-
description: state.config.recovery
|
|
975
|
-
? "Surface interrupted runs (default)"
|
|
976
|
-
: "Do not surface interrupted runs",
|
|
1159
|
+
description: formatMenuValue("recovery", { recovery: state.config.recovery }),
|
|
977
1160
|
},
|
|
978
1161
|
|
|
979
1162
|
{
|
|
980
1163
|
value: "historyentries",
|
|
981
1164
|
label: "Set Max History Entries",
|
|
982
|
-
description:
|
|
983
|
-
|
|
984
|
-
|
|
1165
|
+
description: formatMenuValue("historyentries", {
|
|
1166
|
+
maxHistoryEntries: state.config.maxHistoryEntries,
|
|
1167
|
+
}),
|
|
985
1168
|
},
|
|
986
1169
|
{
|
|
987
1170
|
value: "costlimit",
|
|
988
1171
|
label: "Set Session Cost Limit",
|
|
989
|
-
description:
|
|
990
|
-
|
|
991
|
-
|
|
1172
|
+
description: formatMenuValue("costlimit", {
|
|
1173
|
+
sessionCostLimit: state.config.sessionCostLimit,
|
|
1174
|
+
}),
|
|
992
1175
|
},
|
|
993
1176
|
{
|
|
994
|
-
value: "
|
|
995
|
-
label: "
|
|
996
|
-
description: "
|
|
1177
|
+
value: "sla",
|
|
1178
|
+
label: "Set SLA Tracking",
|
|
1179
|
+
description: formatMenuValue("sla", {
|
|
1180
|
+
slaTrackingEnabled: state.config.slaTrackingEnabled,
|
|
1181
|
+
slaWindowSize: state.config.slaWindowSize,
|
|
1182
|
+
}),
|
|
997
1183
|
},
|
|
1184
|
+
menuSection("Run Activity"),
|
|
998
1185
|
{
|
|
999
1186
|
value: "history",
|
|
1000
1187
|
label: "View Run History",
|
|
@@ -1002,37 +1189,40 @@ export function getConfigMenuItems(state: SessionState): SelectItem[] {
|
|
|
1002
1189
|
},
|
|
1003
1190
|
{
|
|
1004
1191
|
value: "monitor",
|
|
1005
|
-
label: "Live Monitor",
|
|
1192
|
+
label: "View Live Monitor",
|
|
1006
1193
|
description: "Watch running subagents in real-time",
|
|
1007
1194
|
},
|
|
1008
1195
|
{
|
|
1009
1196
|
value: "dashboard",
|
|
1010
|
-
label: "Observability Dashboard",
|
|
1197
|
+
label: "View Observability Dashboard",
|
|
1011
1198
|
description: "Real-time metrics, SLA, errors, and cost trends",
|
|
1012
1199
|
},
|
|
1013
1200
|
{
|
|
1014
|
-
value: "
|
|
1015
|
-
label: "
|
|
1016
|
-
description:
|
|
1201
|
+
value: "retry",
|
|
1202
|
+
label: "Retry Failed Run",
|
|
1203
|
+
description: "Select a failed subagent to retry",
|
|
1017
1204
|
},
|
|
1205
|
+
menuSection("Presets & Templates"),
|
|
1018
1206
|
{
|
|
1019
|
-
value: "
|
|
1020
|
-
label: "
|
|
1021
|
-
description:
|
|
1022
|
-
|
|
1023
|
-
:
|
|
1207
|
+
value: "preset",
|
|
1208
|
+
label: "Browse Presets",
|
|
1209
|
+
description: formatMenuValue("presetCounts", {
|
|
1210
|
+
builtinCount: state.builtinPresets.length,
|
|
1211
|
+
customCount: state.customPresets.length,
|
|
1212
|
+
}),
|
|
1024
1213
|
},
|
|
1025
1214
|
{
|
|
1026
|
-
value: "
|
|
1027
|
-
label: "
|
|
1028
|
-
description: "
|
|
1215
|
+
value: "templates",
|
|
1216
|
+
label: "Browse Templates",
|
|
1217
|
+
description: formatMenuValue("templateCounts", {
|
|
1218
|
+
builtinCount: templateCounts.builtin.length,
|
|
1219
|
+
customCount: templateCounts.custom.length,
|
|
1220
|
+
}),
|
|
1029
1221
|
},
|
|
1030
1222
|
{
|
|
1031
|
-
value: "
|
|
1032
|
-
label: "
|
|
1033
|
-
description:
|
|
1034
|
-
? `Enabled (window: ${state.config.slaWindowSize})`
|
|
1035
|
-
: "Disabled",
|
|
1223
|
+
value: "reset",
|
|
1224
|
+
label: "Reset Configuration",
|
|
1225
|
+
description: "Clear subagent configuration",
|
|
1036
1226
|
},
|
|
1037
1227
|
];
|
|
1038
1228
|
}
|
|
@@ -1052,63 +1242,12 @@ export async function showConfigMenu(
|
|
|
1052
1242
|
},
|
|
1053
1243
|
];
|
|
1054
1244
|
|
|
1055
|
-
const result = await
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
);
|
|
1062
|
-
|
|
1063
|
-
container.addChild(
|
|
1064
|
-
new Text(theme.fg("dim", `Model: ${formatModel(state.config.model)}`), 1, 0),
|
|
1065
|
-
);
|
|
1066
|
-
container.addChild(
|
|
1067
|
-
new Text(
|
|
1068
|
-
theme.fg("dim", `Max Thinking: ${state.config.maxThinkingLevel}`),
|
|
1069
|
-
1,
|
|
1070
|
-
0,
|
|
1071
|
-
),
|
|
1072
|
-
);
|
|
1073
|
-
container.addChild(
|
|
1074
|
-
new Text(
|
|
1075
|
-
theme.fg("dim", `Max parallel: ${formatMaxParallel(state.config.maxParallel)}`),
|
|
1076
|
-
1,
|
|
1077
|
-
0,
|
|
1078
|
-
),
|
|
1079
|
-
);
|
|
1080
|
-
if (state.config.sessionCostLimit > 0) {
|
|
1081
|
-
container.addChild(
|
|
1082
|
-
new Text(
|
|
1083
|
-
theme.fg("dim", `Cost limit: $${state.config.sessionCostLimit.toFixed(2)}`),
|
|
1084
|
-
1,
|
|
1085
|
-
0,
|
|
1086
|
-
),
|
|
1087
|
-
);
|
|
1088
|
-
}
|
|
1089
|
-
container.addChild(new Text("", 0, 0));
|
|
1090
|
-
|
|
1091
|
-
const selectList = new SelectList(
|
|
1092
|
-
items,
|
|
1093
|
-
Math.min(items.length, 10),
|
|
1094
|
-
makeSelectListTheme(theme),
|
|
1095
|
-
);
|
|
1096
|
-
selectList.onSelect = (item) => done(item.value);
|
|
1097
|
-
selectList.onCancel = () => done(null);
|
|
1098
|
-
|
|
1099
|
-
container.addChild(selectList);
|
|
1100
|
-
container.addChild(new Text(theme.fg("dim", NAV_FOOTER), 1, 0));
|
|
1101
|
-
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
1102
|
-
|
|
1103
|
-
return {
|
|
1104
|
-
render: (w: number) => container.render(w),
|
|
1105
|
-
invalidate: () => container.invalidate(),
|
|
1106
|
-
handleInput: (data: string) => {
|
|
1107
|
-
selectList.handleInput(data);
|
|
1108
|
-
tui.requestRender();
|
|
1109
|
-
},
|
|
1110
|
-
};
|
|
1111
|
-
});
|
|
1245
|
+
const result = await showSelectList(
|
|
1246
|
+
ctx,
|
|
1247
|
+
"brl-subagent Configuration",
|
|
1248
|
+
items,
|
|
1249
|
+
CONFIG_MENU_VIEWPORT,
|
|
1250
|
+
);
|
|
1112
1251
|
|
|
1113
1252
|
if (!result || result === "__done__") return;
|
|
1114
1253
|
|
|
@@ -1140,8 +1279,8 @@ export async function showRunHistory(
|
|
|
1140
1279
|
): Promise<void> {
|
|
1141
1280
|
const statusIcon: Record<string, string> = {
|
|
1142
1281
|
running: ctx.ui.theme.fg("accent", "◉"),
|
|
1143
|
-
done:
|
|
1144
|
-
failed: ctx.ui.theme
|
|
1282
|
+
done: formatOutcomeSymbol("success", ctx.ui.theme),
|
|
1283
|
+
failed: formatOutcomeSymbol("failure", ctx.ui.theme),
|
|
1145
1284
|
interrupted: ctx.ui.theme.fg("warning", "◌"),
|
|
1146
1285
|
};
|
|
1147
1286
|
|
|
@@ -1182,8 +1321,8 @@ export async function showRunHistory(
|
|
|
1182
1321
|
// Mark as seen
|
|
1183
1322
|
if (state.markRunSeen(run.id)) {
|
|
1184
1323
|
persistState();
|
|
1185
|
-
import("./concurrency").then(({
|
|
1186
|
-
|
|
1324
|
+
import("./concurrency").then(({ repaintStatus }) => {
|
|
1325
|
+
repaintStatus(state, ctx);
|
|
1187
1326
|
});
|
|
1188
1327
|
}
|
|
1189
1328
|
|
|
@@ -1829,6 +1968,250 @@ function compactDuration(ms: number): string {
|
|
|
1829
1968
|
return `${Math.floor(ms / 60_000)}m${Math.round((ms % 60_000) / 1000)}s`;
|
|
1830
1969
|
}
|
|
1831
1970
|
|
|
1971
|
+
// ---------------------------------------------------------------------------
|
|
1972
|
+
// E1 dashboard panels (issue #356)
|
|
1973
|
+
//
|
|
1974
|
+
// `showDashboard` is a thin composer: it samples the session state once per
|
|
1975
|
+
// render pass, then appends these six panels in order. Each panel renders only
|
|
1976
|
+
// its own data slice and returns its components instead of painting a
|
|
1977
|
+
// container, so its output is pinnable without a terminal (see
|
|
1978
|
+
// `src/__tests__/dashboard-panels.test.ts`) while the composer keeps ownership
|
|
1979
|
+
// of ordering, borders and spacing.
|
|
1980
|
+
// ---------------------------------------------------------------------------
|
|
1981
|
+
|
|
1982
|
+
/** The per-row live-session slice the Active Subagents panel renders. */
|
|
1983
|
+
export type ActiveSubagentSlice = Pick<
|
|
1984
|
+
LiveSubagent,
|
|
1985
|
+
"label" | "task" | "startedAt" | "usage"
|
|
1986
|
+
>;
|
|
1987
|
+
|
|
1988
|
+
/** Panel 1 — header: the dashboard title plus the refresh stamp. */
|
|
1989
|
+
export function renderDashboardHeader(theme: Theme, refreshStr: string): Component[] {
|
|
1990
|
+
return [
|
|
1991
|
+
new Text(
|
|
1992
|
+
theme.fg("accent", theme.bold("brl-subagent Dashboard")) +
|
|
1993
|
+
theme.fg("dim", ` ${refreshStr}`),
|
|
1994
|
+
1,
|
|
1995
|
+
0,
|
|
1996
|
+
),
|
|
1997
|
+
new Text("", 0, 0),
|
|
1998
|
+
];
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
/**
|
|
2002
|
+
* Panel 2 — active subagents: the live count in the title, one row per entry.
|
|
2003
|
+
*
|
|
2004
|
+
* `now` is injected (the composer passes the wall clock) so the spinner frame
|
|
2005
|
+
* and the elapsed suffix stay testable; it is sampled per row, as before.
|
|
2006
|
+
*/
|
|
2007
|
+
export function renderDashboardActivePanel(
|
|
2008
|
+
theme: Theme,
|
|
2009
|
+
sessions: ReadonlyMap<string, ActiveSubagentSlice>,
|
|
2010
|
+
now: () => number = Date.now,
|
|
2011
|
+
): Component[] {
|
|
2012
|
+
const activeCount = sessions.size;
|
|
2013
|
+
const components: Component[] = [
|
|
2014
|
+
new Text(
|
|
2015
|
+
theme.fg("accent", theme.bold(`Active Subagents (${activeCount})`)),
|
|
2016
|
+
1,
|
|
2017
|
+
0,
|
|
2018
|
+
),
|
|
2019
|
+
];
|
|
2020
|
+
if (activeCount === 0) {
|
|
2021
|
+
components.push(new Text(theme.fg("dim", " None running"), 1, 0));
|
|
2022
|
+
} else {
|
|
2023
|
+
let idx = 0;
|
|
2024
|
+
for (const [id, session] of sessions) {
|
|
2025
|
+
const elapsedStr = formatElapsed(now() - session.startedAt);
|
|
2026
|
+
const name = liveRowName(session.label, session.task);
|
|
2027
|
+
const spinner = liveSpinner(now());
|
|
2028
|
+
components.push(
|
|
2029
|
+
new Text(
|
|
2030
|
+
theme.fg("accent", ` ${spinner} ${name}`) +
|
|
2031
|
+
theme.fg(
|
|
2032
|
+
"dim",
|
|
2033
|
+
formatLiveRowDim(id, session.usage, elapsedStr),
|
|
2034
|
+
),
|
|
2035
|
+
1,
|
|
2036
|
+
0,
|
|
2037
|
+
),
|
|
2038
|
+
);
|
|
2039
|
+
idx++;
|
|
2040
|
+
if (idx < activeCount) components.push(new Text("", 0, 0));
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
components.push(new Text("", 0, 0));
|
|
2044
|
+
return components;
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
/**
|
|
2048
|
+
* Panel 3 — SLA summary: success rate (colour-graded), p50/p95/p99 and cost over
|
|
2049
|
+
* the current SLA window. `metrics` is null when there is no run history and
|
|
2050
|
+
* `runCount` is the window size named in the title.
|
|
2051
|
+
*/
|
|
2052
|
+
export function renderDashboardSlaPanel(
|
|
2053
|
+
theme: Theme,
|
|
2054
|
+
metrics: SLAMetrics | null,
|
|
2055
|
+
runCount: number,
|
|
2056
|
+
): Component[] {
|
|
2057
|
+
const components: Component[] = [
|
|
2058
|
+
new Text(
|
|
2059
|
+
theme.fg("accent", theme.bold(`SLA Summary (last ${runCount} runs)`)),
|
|
2060
|
+
1,
|
|
2061
|
+
0,
|
|
2062
|
+
),
|
|
2063
|
+
];
|
|
2064
|
+
if (metrics && metrics.totalRuns > 0) {
|
|
2065
|
+
const successPct = (metrics.successRate * 100).toFixed(1);
|
|
2066
|
+
const successColor = metrics.successRate >= 0.9 ? "success" : metrics.successRate >= 0.7 ? "warning" : "error";
|
|
2067
|
+
components.push(
|
|
2068
|
+
new Text(
|
|
2069
|
+
theme.fg("dim", " Success: ") +
|
|
2070
|
+
theme.fg(successColor, `${successPct}%`) +
|
|
2071
|
+
theme.fg("dim", ` \u00b7 p50: ${compactDuration(metrics.p50DurationMs)} \u00b7 p95: ${compactDuration(metrics.p95DurationMs)} \u00b7 p99: ${compactDuration(metrics.p99DurationMs)}`),
|
|
2072
|
+
1,
|
|
2073
|
+
0,
|
|
2074
|
+
),
|
|
2075
|
+
);
|
|
2076
|
+
components.push(
|
|
2077
|
+
new Text(
|
|
2078
|
+
theme.fg("dim", " Cost: ") +
|
|
2079
|
+
theme.fg("dim", `total $${metrics.totalCost.toFixed(4)} \u00b7 avg $${metrics.averageCost.toFixed(4)}`),
|
|
2080
|
+
1,
|
|
2081
|
+
0,
|
|
2082
|
+
),
|
|
2083
|
+
);
|
|
2084
|
+
} else {
|
|
2085
|
+
components.push(new Text(theme.fg("dim", " No completed runs yet"), 1, 0));
|
|
2086
|
+
}
|
|
2087
|
+
components.push(new Text("", 0, 0));
|
|
2088
|
+
return components;
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
/** Panel 4 — recent runs: outcome symbol, name, duration and cost per row. */
|
|
2092
|
+
export function renderDashboardRecentRunsPanel(
|
|
2093
|
+
theme: Theme,
|
|
2094
|
+
runs: SubagentRun[],
|
|
2095
|
+
): Component[] {
|
|
2096
|
+
const components: Component[] = [
|
|
2097
|
+
new Text(
|
|
2098
|
+
theme.fg("accent", theme.bold("Recent Runs")),
|
|
2099
|
+
1,
|
|
2100
|
+
0,
|
|
2101
|
+
),
|
|
2102
|
+
];
|
|
2103
|
+
if (runs.length === 0) {
|
|
2104
|
+
components.push(new Text(theme.fg("dim", " No runs recorded"), 1, 0));
|
|
2105
|
+
} else {
|
|
2106
|
+
for (const run of runs) {
|
|
2107
|
+
const icon =
|
|
2108
|
+
run.status === "done"
|
|
2109
|
+
? formatOutcomeSymbol("success", theme)
|
|
2110
|
+
: run.status === "failed"
|
|
2111
|
+
? formatOutcomeSymbol("failure", theme)
|
|
2112
|
+
: theme.fg("accent", "\u25CF");
|
|
2113
|
+
const name = run.label || run.task.slice(0, 50);
|
|
2114
|
+
const dur = run.durationMs ? compactDuration(run.durationMs) : "...";
|
|
2115
|
+
const cost = run.cost ? ` $${run.cost.toFixed(4)}` : "";
|
|
2116
|
+
components.push(
|
|
2117
|
+
new Text(
|
|
2118
|
+
` ${icon} ${theme.fg("dim", name.slice(0, 50))}` +
|
|
2119
|
+
theme.fg("dim", ` ${dur}${cost}`),
|
|
2120
|
+
1,
|
|
2121
|
+
0,
|
|
2122
|
+
),
|
|
2123
|
+
);
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
components.push(new Text("", 0, 0));
|
|
2127
|
+
return components;
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
/**
|
|
2131
|
+
* Panel 5 — error breakdown: categories sorted by count, each with a
|
|
2132
|
+
* proportional bar. An empty breakdown renders the "no errors" line.
|
|
2133
|
+
*/
|
|
2134
|
+
export function renderDashboardErrorPanel(
|
|
2135
|
+
theme: Theme,
|
|
2136
|
+
breakdown: Record<string, number> | undefined,
|
|
2137
|
+
): Component[] {
|
|
2138
|
+
const components: Component[] = [
|
|
2139
|
+
new Text(
|
|
2140
|
+
theme.fg("accent", theme.bold("Error Breakdown")),
|
|
2141
|
+
1,
|
|
2142
|
+
0,
|
|
2143
|
+
),
|
|
2144
|
+
];
|
|
2145
|
+
if (breakdown && Object.keys(breakdown).length > 0) {
|
|
2146
|
+
const cats = Object.entries(breakdown).sort(
|
|
2147
|
+
(a, b) => b[1] - a[1],
|
|
2148
|
+
);
|
|
2149
|
+
const maxCount = cats[0][1];
|
|
2150
|
+
for (const [cat, count] of cats) {
|
|
2151
|
+
const bar = buildHorizontalBar(count, maxCount, 20);
|
|
2152
|
+
components.push(
|
|
2153
|
+
new Text(
|
|
2154
|
+
theme.fg("dim", ` ${cat.padEnd(18)} `) +
|
|
2155
|
+
theme.fg("error", bar) +
|
|
2156
|
+
theme.fg("dim", ` ${count}`),
|
|
2157
|
+
1,
|
|
2158
|
+
0,
|
|
2159
|
+
),
|
|
2160
|
+
);
|
|
2161
|
+
}
|
|
2162
|
+
} else {
|
|
2163
|
+
// A sentence, not a status icon: coloured as a whole line, so it is
|
|
2164
|
+
// deliberately not routed through formatOutcomeSymbol.
|
|
2165
|
+
components.push(new Text(theme.fg("success", " No errors \u2713"), 1, 0));
|
|
2166
|
+
}
|
|
2167
|
+
components.push(new Text("", 0, 0));
|
|
2168
|
+
return components;
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
/**
|
|
2172
|
+
* Panel 6 — cost trend: the sparkline for the sampled costs plus the run count
|
|
2173
|
+
* and cost totals.
|
|
2174
|
+
*/
|
|
2175
|
+
export function renderDashboardCostTrendPanel(
|
|
2176
|
+
theme: Theme,
|
|
2177
|
+
costTrend: number[],
|
|
2178
|
+
): Component[] {
|
|
2179
|
+
const components: Component[] = [
|
|
2180
|
+
new Text(
|
|
2181
|
+
theme.fg("accent", theme.bold("Cost Trend (last 20 runs)")),
|
|
2182
|
+
1,
|
|
2183
|
+
0,
|
|
2184
|
+
),
|
|
2185
|
+
];
|
|
2186
|
+
if (costTrend.length > 0) {
|
|
2187
|
+
const sparkline = formatSparkline(costTrend);
|
|
2188
|
+
const totalCost = costTrend.reduce((s, c) => s + c, 0);
|
|
2189
|
+
components.push(
|
|
2190
|
+
new Text(
|
|
2191
|
+
theme.fg("dim", " ") + theme.fg("accent", sparkline),
|
|
2192
|
+
1,
|
|
2193
|
+
0,
|
|
2194
|
+
),
|
|
2195
|
+
);
|
|
2196
|
+
components.push(
|
|
2197
|
+
new Text(
|
|
2198
|
+
theme.fg("dim", ` ${costTrend.length} runs \u00b7 total $${totalCost.toFixed(4)} \u00b7 avg $${(totalCost / costTrend.length).toFixed(4)}`),
|
|
2199
|
+
1,
|
|
2200
|
+
0,
|
|
2201
|
+
),
|
|
2202
|
+
);
|
|
2203
|
+
} else {
|
|
2204
|
+
components.push(new Text(theme.fg("dim", " No cost data"), 1, 0));
|
|
2205
|
+
}
|
|
2206
|
+
components.push(new Text("", 0, 0));
|
|
2207
|
+
return components;
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
/**
|
|
2211
|
+
* E1 dashboard — the composer. Samples the session state once per render pass
|
|
2212
|
+
* and appends the six panels (rendered above) between the two borders; the
|
|
2213
|
+
* panel bodies themselves live in their own render functions.
|
|
2214
|
+
*/
|
|
1832
2215
|
export async function showDashboard(
|
|
1833
2216
|
ctx: ExtensionContext,
|
|
1834
2217
|
state: SessionState,
|
|
@@ -1840,187 +2223,34 @@ export async function showDashboard(
|
|
|
1840
2223
|
sweepStaleLiveSubagents(state, getAgent);
|
|
1841
2224
|
|
|
1842
2225
|
const container = new Container();
|
|
2226
|
+
const append = (components: Component[]) => {
|
|
2227
|
+
for (const component of components) container.addChild(component);
|
|
2228
|
+
};
|
|
1843
2229
|
const now = new Date();
|
|
1844
2230
|
const refreshStr = `refreshing \u00b7 ${now.toLocaleTimeString()}`;
|
|
1845
2231
|
|
|
1846
2232
|
// ---- Panel 1: Header ----
|
|
1847
2233
|
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
1848
|
-
|
|
1849
|
-
new Text(
|
|
1850
|
-
theme.fg("accent", theme.bold("brl-subagent Dashboard")) +
|
|
1851
|
-
theme.fg("dim", ` ${refreshStr}`),
|
|
1852
|
-
1,
|
|
1853
|
-
0,
|
|
1854
|
-
),
|
|
1855
|
-
);
|
|
1856
|
-
container.addChild(new Text("", 0, 0));
|
|
2234
|
+
append(renderDashboardHeader(theme, refreshStr));
|
|
1857
2235
|
|
|
1858
2236
|
// ---- Panel 2: Active subagents ----
|
|
1859
|
-
|
|
1860
|
-
container.addChild(
|
|
1861
|
-
new Text(
|
|
1862
|
-
theme.fg("accent", theme.bold(`Active Subagents (${activeCount})`)),
|
|
1863
|
-
1,
|
|
1864
|
-
0,
|
|
1865
|
-
),
|
|
1866
|
-
);
|
|
1867
|
-
if (activeCount === 0) {
|
|
1868
|
-
container.addChild(new Text(theme.fg("dim", " None running"), 1, 0));
|
|
1869
|
-
} else {
|
|
1870
|
-
let idx = 0;
|
|
1871
|
-
for (const [id, session] of state.subagentSessions) {
|
|
1872
|
-
const elapsedStr = formatElapsed(Date.now() - session.startedAt);
|
|
1873
|
-
const name = liveRowName(session.label, session.task);
|
|
1874
|
-
const spinner = liveSpinner(Date.now());
|
|
1875
|
-
container.addChild(
|
|
1876
|
-
new Text(
|
|
1877
|
-
theme.fg("accent", ` ${spinner} ${name}`) +
|
|
1878
|
-
theme.fg(
|
|
1879
|
-
"dim",
|
|
1880
|
-
formatLiveRowDim(id, session.usage, elapsedStr),
|
|
1881
|
-
),
|
|
1882
|
-
1,
|
|
1883
|
-
0,
|
|
1884
|
-
),
|
|
1885
|
-
);
|
|
1886
|
-
idx++;
|
|
1887
|
-
if (idx < activeCount) container.addChild(new Text("", 0, 0));
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
container.addChild(new Text("", 0, 0));
|
|
2237
|
+
append(renderDashboardActivePanel(theme, state.subagentSessions, Date.now));
|
|
1891
2238
|
|
|
1892
2239
|
// ---- Panel 3: SLA Summary ----
|
|
1893
2240
|
const allRuns = state.getRunEntries(ctx);
|
|
1894
2241
|
const recentRuns = allRuns.slice(0, state.config.slaWindowSize || 50);
|
|
1895
2242
|
const metrics = recentRuns.length > 0 ? computeSLAMetrics(recentRuns) : null;
|
|
1896
|
-
|
|
1897
|
-
container.addChild(
|
|
1898
|
-
new Text(
|
|
1899
|
-
theme.fg("accent", theme.bold(`SLA Summary (last ${recentRuns.length} runs)`)),
|
|
1900
|
-
1,
|
|
1901
|
-
0,
|
|
1902
|
-
),
|
|
1903
|
-
);
|
|
1904
|
-
if (metrics && metrics.totalRuns > 0) {
|
|
1905
|
-
const successPct = (metrics.successRate * 100).toFixed(1);
|
|
1906
|
-
const successColor = metrics.successRate >= 0.9 ? "success" : metrics.successRate >= 0.7 ? "warning" : "error";
|
|
1907
|
-
container.addChild(
|
|
1908
|
-
new Text(
|
|
1909
|
-
theme.fg("dim", " Success: ") +
|
|
1910
|
-
theme.fg(successColor, `${successPct}%`) +
|
|
1911
|
-
theme.fg("dim", ` \u00b7 p50: ${compactDuration(metrics.p50DurationMs)} \u00b7 p95: ${compactDuration(metrics.p95DurationMs)} \u00b7 p99: ${compactDuration(metrics.p99DurationMs)}`),
|
|
1912
|
-
1,
|
|
1913
|
-
0,
|
|
1914
|
-
),
|
|
1915
|
-
);
|
|
1916
|
-
container.addChild(
|
|
1917
|
-
new Text(
|
|
1918
|
-
theme.fg("dim", " Cost: ") +
|
|
1919
|
-
theme.fg("dim", `total $${metrics.totalCost.toFixed(4)} \u00b7 avg $${metrics.averageCost.toFixed(4)}`),
|
|
1920
|
-
1,
|
|
1921
|
-
0,
|
|
1922
|
-
),
|
|
1923
|
-
);
|
|
1924
|
-
} else {
|
|
1925
|
-
container.addChild(new Text(theme.fg("dim", " No completed runs yet"), 1, 0));
|
|
1926
|
-
}
|
|
1927
|
-
container.addChild(new Text("", 0, 0));
|
|
2243
|
+
append(renderDashboardSlaPanel(theme, metrics, recentRuns.length));
|
|
1928
2244
|
|
|
1929
2245
|
// ---- Panel 4: Recent Runs (last 10) ----
|
|
1930
|
-
|
|
1931
|
-
container.addChild(
|
|
1932
|
-
new Text(
|
|
1933
|
-
theme.fg("accent", theme.bold("Recent Runs")),
|
|
1934
|
-
1,
|
|
1935
|
-
0,
|
|
1936
|
-
),
|
|
1937
|
-
);
|
|
1938
|
-
if (recent10.length === 0) {
|
|
1939
|
-
container.addChild(new Text(theme.fg("dim", " No runs recorded"), 1, 0));
|
|
1940
|
-
} else {
|
|
1941
|
-
for (const run of recent10) {
|
|
1942
|
-
const icon =
|
|
1943
|
-
run.status === "done"
|
|
1944
|
-
? theme.fg("success", "\u2713")
|
|
1945
|
-
: run.status === "failed"
|
|
1946
|
-
? theme.fg("error", "\u2717")
|
|
1947
|
-
: theme.fg("accent", "\u25CF");
|
|
1948
|
-
const name = run.label || run.task.slice(0, 50);
|
|
1949
|
-
const dur = run.durationMs ? compactDuration(run.durationMs) : "...";
|
|
1950
|
-
const cost = run.cost ? ` $${run.cost.toFixed(4)}` : "";
|
|
1951
|
-
container.addChild(
|
|
1952
|
-
new Text(
|
|
1953
|
-
` ${icon} ${theme.fg("dim", name.slice(0, 50))}` +
|
|
1954
|
-
theme.fg("dim", ` ${dur}${cost}`),
|
|
1955
|
-
1,
|
|
1956
|
-
0,
|
|
1957
|
-
),
|
|
1958
|
-
);
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
container.addChild(new Text("", 0, 0));
|
|
2246
|
+
append(renderDashboardRecentRunsPanel(theme, allRuns.slice(0, 10)));
|
|
1962
2247
|
|
|
1963
2248
|
// ---- Panel 5: Error Breakdown ----
|
|
1964
|
-
|
|
1965
|
-
new Text(
|
|
1966
|
-
theme.fg("accent", theme.bold("Error Breakdown")),
|
|
1967
|
-
1,
|
|
1968
|
-
0,
|
|
1969
|
-
),
|
|
1970
|
-
);
|
|
1971
|
-
if (metrics && Object.keys(metrics.errorCategoryBreakdown).length > 0) {
|
|
1972
|
-
const cats = Object.entries(metrics.errorCategoryBreakdown).sort(
|
|
1973
|
-
(a, b) => b[1] - a[1],
|
|
1974
|
-
);
|
|
1975
|
-
const maxCount = cats[0][1];
|
|
1976
|
-
for (const [cat, count] of cats) {
|
|
1977
|
-
const bar = buildHorizontalBar(count, maxCount, 20);
|
|
1978
|
-
container.addChild(
|
|
1979
|
-
new Text(
|
|
1980
|
-
theme.fg("dim", ` ${cat.padEnd(18)} `) +
|
|
1981
|
-
theme.fg("error", bar) +
|
|
1982
|
-
theme.fg("dim", ` ${count}`),
|
|
1983
|
-
1,
|
|
1984
|
-
0,
|
|
1985
|
-
),
|
|
1986
|
-
);
|
|
1987
|
-
}
|
|
1988
|
-
} else {
|
|
1989
|
-
container.addChild(new Text(theme.fg("success", " No errors \u2713"), 1, 0));
|
|
1990
|
-
}
|
|
1991
|
-
container.addChild(new Text("", 0, 0));
|
|
2249
|
+
append(renderDashboardErrorPanel(theme, metrics?.errorCategoryBreakdown));
|
|
1992
2250
|
|
|
1993
2251
|
// ---- Panel 6: Cost Trend (sparkline) ----
|
|
1994
|
-
|
|
1995
|
-
new Text(
|
|
1996
|
-
theme.fg("accent", theme.bold("Cost Trend (last 20 runs)")),
|
|
1997
|
-
1,
|
|
1998
|
-
0,
|
|
1999
|
-
),
|
|
2000
|
-
);
|
|
2001
|
-
const costTrend = computeCostTrend(allRuns, 20);
|
|
2002
|
-
if (costTrend.length > 0) {
|
|
2003
|
-
const sparkline = formatSparkline(costTrend);
|
|
2004
|
-
const totalCost = costTrend.reduce((s, c) => s + c, 0);
|
|
2005
|
-
container.addChild(
|
|
2006
|
-
new Text(
|
|
2007
|
-
theme.fg("dim", " ") + theme.fg("accent", sparkline),
|
|
2008
|
-
1,
|
|
2009
|
-
0,
|
|
2010
|
-
),
|
|
2011
|
-
);
|
|
2012
|
-
container.addChild(
|
|
2013
|
-
new Text(
|
|
2014
|
-
theme.fg("dim", ` ${costTrend.length} runs \u00b7 total $${totalCost.toFixed(4)} \u00b7 avg $${(totalCost / costTrend.length).toFixed(4)}`),
|
|
2015
|
-
1,
|
|
2016
|
-
0,
|
|
2017
|
-
),
|
|
2018
|
-
);
|
|
2019
|
-
} else {
|
|
2020
|
-
container.addChild(new Text(theme.fg("dim", " No cost data"), 1, 0));
|
|
2021
|
-
}
|
|
2252
|
+
append(renderDashboardCostTrendPanel(theme, computeCostTrend(allRuns, 20)));
|
|
2022
2253
|
|
|
2023
|
-
container.addChild(new Text("", 0, 0));
|
|
2024
2254
|
container.addChild(new Text(theme.fg("dim", "q / esc to close"), 1, 0));
|
|
2025
2255
|
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
2026
2256
|
|
|
@@ -2069,6 +2299,8 @@ export async function showRetryMenu(
|
|
|
2069
2299
|
const err = r.errorMessage ? r.errorMessage.slice(0, 40) : interrupted ? "interrupted" : "error";
|
|
2070
2300
|
return {
|
|
2071
2301
|
value: r.id,
|
|
2302
|
+
// Uncoloured select-list label pairing ✗ with the interrupted ◌, so the
|
|
2303
|
+
// verdict symbol here is not the themed one — kept as an exception.
|
|
2072
2304
|
label: `${interrupted ? "◌" : "✗"} ${name}`,
|
|
2073
2305
|
description: `${interrupted ? "interrupted · " : ""}${model} · ${err}`,
|
|
2074
2306
|
};
|
|
@@ -2209,35 +2441,45 @@ function renderCollapsedText(
|
|
|
2209
2441
|
// Chain / parallel collapsed rendering
|
|
2210
2442
|
// ---------------------------------------------------------------------------
|
|
2211
2443
|
|
|
2444
|
+
/** One collapsed per-step line — shared by the chain and parallel summaries. */
|
|
2445
|
+
function renderCollapsedSubTask(
|
|
2446
|
+
r: SubTaskResult,
|
|
2447
|
+
theme: Theme,
|
|
2448
|
+
opts: { stepPrefix: boolean; emptyLabelSeparator: string },
|
|
2449
|
+
): string {
|
|
2450
|
+
const isErr = isSubagentError(r);
|
|
2451
|
+
const statusIcon = formatOutcomeSymbol(isErr ? "failure" : "success", theme);
|
|
2452
|
+
const stepNum =
|
|
2453
|
+
opts.stepPrefix && r.step !== undefined
|
|
2454
|
+
? theme.fg("muted", `${r.step}. `)
|
|
2455
|
+
: "";
|
|
2456
|
+
const label = r.label ? theme.fg("accent", r.label) : "";
|
|
2457
|
+
const output = getFinalOutput(r.messages);
|
|
2458
|
+
const preview = output.split("\n").slice(0, 2).join("\n");
|
|
2459
|
+
const sep = label ? ": " : opts.emptyLabelSeparator;
|
|
2460
|
+
let text = `\n${stepNum}${statusIcon} ${label}${sep}${theme.fg("toolOutput", preview)}`;
|
|
2461
|
+
if (r.errorMessage) {
|
|
2462
|
+
text += `\n ${theme.fg("error", r.errorMessage)}`;
|
|
2463
|
+
}
|
|
2464
|
+
const diffSummary = renderCollapsedDiffSummary(r.gitDiff, theme);
|
|
2465
|
+
if (diffSummary) text += `\n ${diffSummary}`;
|
|
2466
|
+
return text;
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2212
2469
|
function renderCollapsedChain(
|
|
2213
2470
|
details: ChainDetails,
|
|
2214
2471
|
theme: Theme,
|
|
2215
2472
|
): string {
|
|
2216
2473
|
const allSucceeded = details.results.every((r) => !isSubagentError(r));
|
|
2217
|
-
const icon = allSucceeded
|
|
2218
|
-
? theme.fg("success", "\u2713")
|
|
2219
|
-
: theme.fg("error", "\u2717");
|
|
2474
|
+
const icon = formatOutcomeSymbol(allSucceeded ? "success" : "failure", theme);
|
|
2220
2475
|
const stoppedEarly = details.stoppedEarly ? " (stopped early)" : "";
|
|
2221
2476
|
let text = `${icon} ${theme.fg("toolTitle", theme.bold("chain"))} ${theme.fg("muted", `${details.completedSteps}/${details.totalSteps} steps${stoppedEarly}`)}`;
|
|
2222
2477
|
|
|
2223
2478
|
for (const r of details.results) {
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
const stepNum =
|
|
2229
|
-
r.step !== undefined ? theme.fg("muted", `${r.step}. `) : "";
|
|
2230
|
-
const label = r.label ? theme.fg("accent", r.label) : "";
|
|
2231
|
-
const output = getFinalOutput(r.messages);
|
|
2232
|
-
const preview = output.split("\n").slice(0, 2).join("\n");
|
|
2233
|
-
const sep = label ? ": " : "";
|
|
2234
|
-
text += `\n${stepNum}${statusIcon} ${label}${sep}${theme.fg("toolOutput", preview)}`;
|
|
2235
|
-
if (r.errorMessage) {
|
|
2236
|
-
text += `\n ${theme.fg("error", r.errorMessage)}`;
|
|
2237
|
-
}
|
|
2238
|
-
// P5: Collapsed diff file summary per step
|
|
2239
|
-
const diffSummary = renderCollapsedDiffSummary(r.gitDiff, theme);
|
|
2240
|
-
if (diffSummary) text += `\n ${diffSummary}`;
|
|
2479
|
+
text += renderCollapsedSubTask(r, theme, {
|
|
2480
|
+
stepPrefix: true,
|
|
2481
|
+
emptyLabelSeparator: "",
|
|
2482
|
+
});
|
|
2241
2483
|
}
|
|
2242
2484
|
|
|
2243
2485
|
text += `\n${theme.fg("muted", "(Ctrl+O to expand)")}`;
|
|
@@ -2248,28 +2490,14 @@ function renderCollapsedParallel(
|
|
|
2248
2490
|
details: ParallelDetails,
|
|
2249
2491
|
theme: Theme,
|
|
2250
2492
|
): string {
|
|
2251
|
-
const icon =
|
|
2252
|
-
details.failed === 0
|
|
2253
|
-
? theme.fg("success", "\u2713")
|
|
2254
|
-
: theme.fg("error", "\u2717");
|
|
2493
|
+
const icon = formatOutcomeSymbol(details.failed === 0 ? "success" : "failure", theme);
|
|
2255
2494
|
let text = `${icon} ${theme.fg("toolTitle", theme.bold("parallel"))} ${theme.fg("muted", `${details.succeeded}/${details.failed}/${details.results.length} total`)}`;
|
|
2256
2495
|
|
|
2257
2496
|
for (const r of details.results) {
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
const label = r.label ? theme.fg("accent", r.label) : "";
|
|
2263
|
-
const output = getFinalOutput(r.messages);
|
|
2264
|
-
const preview = output.split("\n").slice(0, 2).join("\n");
|
|
2265
|
-
const sep = label ? ": " : " ";
|
|
2266
|
-
text += `\n${statusIcon} ${label}${sep}${theme.fg("toolOutput", preview)}`;
|
|
2267
|
-
if (r.errorMessage) {
|
|
2268
|
-
text += `\n ${theme.fg("error", r.errorMessage)}`;
|
|
2269
|
-
}
|
|
2270
|
-
// P5: Collapsed diff file summary per task
|
|
2271
|
-
const diffSummary = renderCollapsedDiffSummary(r.gitDiff, theme);
|
|
2272
|
-
if (diffSummary) text += `\n ${diffSummary}`;
|
|
2497
|
+
text += renderCollapsedSubTask(r, theme, {
|
|
2498
|
+
stepPrefix: false,
|
|
2499
|
+
emptyLabelSeparator: " ",
|
|
2500
|
+
});
|
|
2273
2501
|
}
|
|
2274
2502
|
|
|
2275
2503
|
text += `\n${theme.fg("muted", "(Ctrl+O to expand)")}`;
|
|
@@ -2280,78 +2508,74 @@ function renderCollapsedParallel(
|
|
|
2280
2508
|
// Chain / parallel expanded rendering
|
|
2281
2509
|
// ---------------------------------------------------------------------------
|
|
2282
2510
|
|
|
2283
|
-
|
|
2284
|
-
|
|
2511
|
+
type AggregatedTotals = Pick<
|
|
2512
|
+
MultiSubagentDetails,
|
|
2513
|
+
"totalInput" | "totalOutput" | "totalCost" | "totalTurns"
|
|
2514
|
+
>;
|
|
2515
|
+
|
|
2516
|
+
/** Add one expanded sub-task block (result header, task, output, diff, usage). */
|
|
2517
|
+
function addExpandedSubTask(
|
|
2518
|
+
container: Container,
|
|
2519
|
+
r: SubTaskResult,
|
|
2285
2520
|
theme: Theme,
|
|
2286
2521
|
mdTheme: ReturnType<typeof getMarkdownTheme>,
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
const
|
|
2522
|
+
opts: { stepPrefix: boolean },
|
|
2523
|
+
): void {
|
|
2524
|
+
const isErr = isSubagentError(r);
|
|
2525
|
+
const statusIcon = formatOutcomeSymbol(isErr ? "failure" : "success", theme);
|
|
2526
|
+
const stepNum =
|
|
2527
|
+
opts.stepPrefix && r.step !== undefined ? `${r.step}. ` : "";
|
|
2528
|
+
const label = r.label ? `[${r.label}] ` : "";
|
|
2290
2529
|
container.addChild(
|
|
2291
2530
|
new Text(
|
|
2292
|
-
theme.fg("
|
|
2293
|
-
theme.fg(
|
|
2294
|
-
"muted",
|
|
2295
|
-
` ${details.completedSteps}/${details.totalSteps} steps${stoppedEarly}`,
|
|
2296
|
-
),
|
|
2531
|
+
`${statusIcon} ${stepNum}${theme.fg("toolTitle", theme.bold(label))}` +
|
|
2532
|
+
(r.model ? theme.fg("muted", ` (${r.model})`) : ""),
|
|
2297
2533
|
0,
|
|
2298
2534
|
0,
|
|
2299
2535
|
),
|
|
2300
2536
|
);
|
|
2301
|
-
container.addChild(
|
|
2537
|
+
container.addChild(
|
|
2538
|
+
new Text(theme.fg("dim", `Task: ${r.task.slice(0, 200)}`), 0, 0),
|
|
2539
|
+
);
|
|
2302
2540
|
|
|
2303
|
-
|
|
2304
|
-
const isErr = isSubagentError(r);
|
|
2305
|
-
const statusIcon = isErr
|
|
2306
|
-
? theme.fg("error", "\u2717")
|
|
2307
|
-
: theme.fg("success", "\u2713");
|
|
2308
|
-
const stepNum = r.step !== undefined ? `${r.step}. ` : "";
|
|
2309
|
-
const label = r.label ? `[${r.label}] ` : "";
|
|
2541
|
+
if (isErr && r.errorMessage) {
|
|
2310
2542
|
container.addChild(
|
|
2311
|
-
new Text(
|
|
2312
|
-
`${statusIcon} ${stepNum}${theme.fg("toolTitle", theme.bold(label))}` +
|
|
2313
|
-
(r.model ? theme.fg("muted", ` (${r.model})`) : ""),
|
|
2314
|
-
0,
|
|
2315
|
-
0,
|
|
2316
|
-
),
|
|
2543
|
+
new Text(theme.fg("error", `Error: ${r.errorMessage}`), 0, 0),
|
|
2317
2544
|
);
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
const output = getFinalOutput(r.messages);
|
|
2548
|
+
if (output) {
|
|
2318
2549
|
container.addChild(
|
|
2319
|
-
new Text(theme.fg("
|
|
2550
|
+
new Text(theme.fg("muted", "\u2500\u2500\u2500 Output \u2500\u2500\u2500"), 0, 0),
|
|
2320
2551
|
);
|
|
2552
|
+
container.addChild(new Markdown(output.trim(), 0, 0, mdTheme));
|
|
2553
|
+
}
|
|
2321
2554
|
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
new Text(theme.fg("error", `Error: ${r.errorMessage}`), 0, 0),
|
|
2325
|
-
);
|
|
2326
|
-
}
|
|
2327
|
-
|
|
2328
|
-
const output = getFinalOutput(r.messages);
|
|
2329
|
-
if (output) {
|
|
2330
|
-
container.addChild(
|
|
2331
|
-
new Text(theme.fg("muted", "\u2500\u2500\u2500 Output \u2500\u2500\u2500"), 0, 0),
|
|
2332
|
-
);
|
|
2333
|
-
container.addChild(new Markdown(output.trim(), 0, 0, mdTheme));
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
// P5: Expanded diff section per step
|
|
2337
|
-
addExpandedDiffSection(container, r.gitDiff, theme);
|
|
2555
|
+
// P5: Expanded diff section per step/task
|
|
2556
|
+
addExpandedDiffSection(container, r.gitDiff, theme);
|
|
2338
2557
|
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
}
|
|
2343
|
-
container.addChild(new Spacer(1));
|
|
2558
|
+
const usageStr = formatUsageStats(r.usage, r.model);
|
|
2559
|
+
if (usageStr) {
|
|
2560
|
+
container.addChild(new Text(theme.fg("dim", usageStr), 0, 0));
|
|
2344
2561
|
}
|
|
2562
|
+
container.addChild(new Spacer(1));
|
|
2563
|
+
}
|
|
2345
2564
|
|
|
2346
|
-
|
|
2565
|
+
/** Add the aggregated totals line shared by every multi-task mode. */
|
|
2566
|
+
function addAggregatedTotals(
|
|
2567
|
+
container: Container,
|
|
2568
|
+
totals: AggregatedTotals,
|
|
2569
|
+
theme: Theme,
|
|
2570
|
+
): void {
|
|
2347
2571
|
const aggUsage: UsageStats = {
|
|
2348
|
-
input:
|
|
2349
|
-
output:
|
|
2572
|
+
input: totals.totalInput,
|
|
2573
|
+
output: totals.totalOutput,
|
|
2350
2574
|
cacheRead: 0,
|
|
2351
2575
|
cacheWrite: 0,
|
|
2352
|
-
cost:
|
|
2576
|
+
cost: totals.totalCost,
|
|
2353
2577
|
contextTokens: 0,
|
|
2354
|
-
turns:
|
|
2578
|
+
turns: totals.totalTurns,
|
|
2355
2579
|
};
|
|
2356
2580
|
const aggStr = formatUsageStats(aggUsage);
|
|
2357
2581
|
if (aggStr) {
|
|
@@ -2359,89 +2583,63 @@ function renderExpandedChain(
|
|
|
2359
2583
|
new Text(theme.fg("dim", `Totals: ${aggStr}`), 0, 0),
|
|
2360
2584
|
);
|
|
2361
2585
|
}
|
|
2362
|
-
|
|
2363
|
-
return container;
|
|
2364
2586
|
}
|
|
2365
2587
|
|
|
2366
|
-
|
|
2367
|
-
|
|
2588
|
+
/**
|
|
2589
|
+
* Expanded chain/parallel view. The two modes differ only in their header and
|
|
2590
|
+
* per-step labelling, both supplied by the caller.
|
|
2591
|
+
*/
|
|
2592
|
+
function renderExpandedMulti(
|
|
2593
|
+
details: MultiSubagentDetails,
|
|
2594
|
+
header: string,
|
|
2368
2595
|
theme: Theme,
|
|
2369
2596
|
mdTheme: ReturnType<typeof getMarkdownTheme>,
|
|
2597
|
+
opts: { stepPrefix: boolean },
|
|
2370
2598
|
): Container {
|
|
2371
2599
|
const container = new Container();
|
|
2372
|
-
container.addChild(
|
|
2373
|
-
new Text(
|
|
2374
|
-
theme.fg("accent", theme.bold("Parallel")) +
|
|
2375
|
-
theme.fg(
|
|
2376
|
-
"muted",
|
|
2377
|
-
` ${details.succeeded} succeeded, ${details.failed} failed, ${details.results.length} total`,
|
|
2378
|
-
),
|
|
2379
|
-
0,
|
|
2380
|
-
0,
|
|
2381
|
-
),
|
|
2382
|
-
);
|
|
2600
|
+
container.addChild(new Text(header, 0, 0));
|
|
2383
2601
|
container.addChild(new Spacer(1));
|
|
2384
2602
|
|
|
2385
2603
|
for (const r of details.results) {
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
? theme.fg("error", "\u2717")
|
|
2389
|
-
: theme.fg("success", "\u2713");
|
|
2390
|
-
const label = r.label ? `[${r.label}] ` : "";
|
|
2391
|
-
container.addChild(
|
|
2392
|
-
new Text(
|
|
2393
|
-
`${statusIcon} ${theme.fg("toolTitle", theme.bold(label))}` +
|
|
2394
|
-
(r.model ? theme.fg("muted", ` (${r.model})`) : ""),
|
|
2395
|
-
0,
|
|
2396
|
-
0,
|
|
2397
|
-
),
|
|
2398
|
-
);
|
|
2399
|
-
container.addChild(
|
|
2400
|
-
new Text(theme.fg("dim", `Task: ${r.task.slice(0, 200)}`), 0, 0),
|
|
2401
|
-
);
|
|
2402
|
-
|
|
2403
|
-
if (isErr && r.errorMessage) {
|
|
2404
|
-
container.addChild(
|
|
2405
|
-
new Text(theme.fg("error", `Error: ${r.errorMessage}`), 0, 0),
|
|
2406
|
-
);
|
|
2407
|
-
}
|
|
2408
|
-
|
|
2409
|
-
const output = getFinalOutput(r.messages);
|
|
2410
|
-
if (output) {
|
|
2411
|
-
container.addChild(
|
|
2412
|
-
new Text(theme.fg("muted", "\u2500\u2500\u2500 Output \u2500\u2500\u2500"), 0, 0),
|
|
2413
|
-
);
|
|
2414
|
-
container.addChild(new Markdown(output.trim(), 0, 0, mdTheme));
|
|
2415
|
-
}
|
|
2604
|
+
addExpandedSubTask(container, r, theme, mdTheme, opts);
|
|
2605
|
+
}
|
|
2416
2606
|
|
|
2417
|
-
|
|
2418
|
-
addExpandedDiffSection(container, r.gitDiff, theme);
|
|
2607
|
+
addAggregatedTotals(container, details, theme);
|
|
2419
2608
|
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
container.addChild(new Text(theme.fg("dim", usageStr), 0, 0));
|
|
2423
|
-
}
|
|
2424
|
-
container.addChild(new Spacer(1));
|
|
2425
|
-
}
|
|
2609
|
+
return container;
|
|
2610
|
+
}
|
|
2426
2611
|
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
if (aggStr) {
|
|
2439
|
-
container.addChild(
|
|
2440
|
-
new Text(theme.fg("dim", `Totals: ${aggStr}`), 0, 0),
|
|
2612
|
+
function renderExpandedChain(
|
|
2613
|
+
details: ChainDetails,
|
|
2614
|
+
theme: Theme,
|
|
2615
|
+
mdTheme: ReturnType<typeof getMarkdownTheme>,
|
|
2616
|
+
): Container {
|
|
2617
|
+
const stoppedEarly = details.stoppedEarly ? " (stopped early)" : "";
|
|
2618
|
+
const header =
|
|
2619
|
+
theme.fg("accent", theme.bold("Chain")) +
|
|
2620
|
+
theme.fg(
|
|
2621
|
+
"muted",
|
|
2622
|
+
` ${details.completedSteps}/${details.totalSteps} steps${stoppedEarly}`,
|
|
2441
2623
|
);
|
|
2442
|
-
|
|
2624
|
+
return renderExpandedMulti(details, header, theme, mdTheme, {
|
|
2625
|
+
stepPrefix: true,
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2443
2628
|
|
|
2444
|
-
|
|
2629
|
+
function renderExpandedParallel(
|
|
2630
|
+
details: ParallelDetails,
|
|
2631
|
+
theme: Theme,
|
|
2632
|
+
mdTheme: ReturnType<typeof getMarkdownTheme>,
|
|
2633
|
+
): Container {
|
|
2634
|
+
const header =
|
|
2635
|
+
theme.fg("accent", theme.bold("Parallel")) +
|
|
2636
|
+
theme.fg(
|
|
2637
|
+
"muted",
|
|
2638
|
+
` ${details.succeeded} succeeded, ${details.failed} failed, ${details.results.length} total`,
|
|
2639
|
+
);
|
|
2640
|
+
return renderExpandedMulti(details, header, theme, mdTheme, {
|
|
2641
|
+
stepPrefix: false,
|
|
2642
|
+
});
|
|
2445
2643
|
}
|
|
2446
2644
|
|
|
2447
2645
|
// ---------------------------------------------------------------------------
|
|
@@ -2759,9 +2957,7 @@ function renderCollapsedGraph(
|
|
|
2759
2957
|
const allSucceeded = details.waves.every((w) =>
|
|
2760
2958
|
w.tasks.every((r) => !isSubagentError(r)),
|
|
2761
2959
|
);
|
|
2762
|
-
const icon = allSucceeded
|
|
2763
|
-
? theme.fg("success", "\u2713")
|
|
2764
|
-
: theme.fg("error", "\u2717");
|
|
2960
|
+
const icon = formatOutcomeSymbol(allSucceeded ? "success" : "failure", theme);
|
|
2765
2961
|
let text = `${icon} ${theme.fg("toolTitle", theme.bold("graph"))} ${theme.fg("muted", `${totalTasks} tasks in ${details.waves.length} waves`)}`;
|
|
2766
2962
|
|
|
2767
2963
|
const maxWavesToShow = 3;
|
|
@@ -2769,15 +2965,11 @@ function renderCollapsedGraph(
|
|
|
2769
2965
|
|
|
2770
2966
|
for (const wave of wavesToRender) {
|
|
2771
2967
|
const waveOk = wave.tasks.every((r) => !isSubagentError(r));
|
|
2772
|
-
const waveIcon = waveOk
|
|
2773
|
-
? theme.fg("success", "\u2713")
|
|
2774
|
-
: theme.fg("error", "\u2717");
|
|
2968
|
+
const waveIcon = formatOutcomeSymbol(waveOk ? "success" : "failure", theme);
|
|
2775
2969
|
const modeLabel = wave.parallel ? "parallel" : "serial";
|
|
2776
2970
|
const taskLabels = wave.tasks.map((r) => {
|
|
2777
2971
|
const label = r.label || r.task.slice(0, 30);
|
|
2778
|
-
const taskIcon =
|
|
2779
|
-
? theme.fg("success", "\u2713")
|
|
2780
|
-
: theme.fg("error", "\u2717");
|
|
2972
|
+
const taskIcon = formatOutcomeSymbol(isSubagentError(r) ? "failure" : "success", theme);
|
|
2781
2973
|
return `${taskIcon} ${theme.fg("dim", label)}`;
|
|
2782
2974
|
});
|
|
2783
2975
|
text += `
|
|
@@ -2816,9 +3008,7 @@ function renderExpandedGraph(
|
|
|
2816
3008
|
|
|
2817
3009
|
for (const wave of details.waves) {
|
|
2818
3010
|
const waveOk = wave.tasks.every((r) => !isSubagentError(r));
|
|
2819
|
-
const waveIcon = waveOk
|
|
2820
|
-
? theme.fg("success", "\u2713")
|
|
2821
|
-
: theme.fg("error", "\u2717");
|
|
3011
|
+
const waveIcon = formatOutcomeSymbol(waveOk ? "success" : "failure", theme);
|
|
2822
3012
|
const modeLabel = wave.parallel ? "parallel" : "serial";
|
|
2823
3013
|
container.addChild(
|
|
2824
3014
|
new Text(
|
|
@@ -2829,64 +3019,11 @@ function renderExpandedGraph(
|
|
|
2829
3019
|
);
|
|
2830
3020
|
|
|
2831
3021
|
for (const r of wave.tasks) {
|
|
2832
|
-
|
|
2833
|
-
const statusIcon = isErr
|
|
2834
|
-
? theme.fg("error", "\u2717")
|
|
2835
|
-
: theme.fg("success", "\u2713");
|
|
2836
|
-
const label = r.label ? `[${r.label}] ` : "";
|
|
2837
|
-
|
|
2838
|
-
container.addChild(
|
|
2839
|
-
new Text(
|
|
2840
|
-
`${statusIcon} ${theme.fg("toolTitle", theme.bold(label))}` +
|
|
2841
|
-
(r.model ? theme.fg("muted", ` (${r.model})`) : ""),
|
|
2842
|
-
0,
|
|
2843
|
-
0,
|
|
2844
|
-
),
|
|
2845
|
-
);
|
|
2846
|
-
container.addChild(
|
|
2847
|
-
new Text(theme.fg("dim", `Task: ${r.task.slice(0, 200)}`), 0, 0),
|
|
2848
|
-
);
|
|
2849
|
-
|
|
2850
|
-
if (isErr && r.errorMessage) {
|
|
2851
|
-
container.addChild(
|
|
2852
|
-
new Text(theme.fg("error", `Error: ${r.errorMessage}`), 0, 0),
|
|
2853
|
-
);
|
|
2854
|
-
}
|
|
2855
|
-
|
|
2856
|
-
const output = getFinalOutput(r.messages);
|
|
2857
|
-
if (output) {
|
|
2858
|
-
container.addChild(
|
|
2859
|
-
new Text(theme.fg("muted", "\u2500\u2500\u2500 Output \u2500\u2500\u2500"), 0, 0),
|
|
2860
|
-
);
|
|
2861
|
-
container.addChild(new Markdown(output.trim(), 0, 0, mdTheme));
|
|
2862
|
-
}
|
|
2863
|
-
|
|
2864
|
-
addExpandedDiffSection(container, r.gitDiff, theme);
|
|
2865
|
-
|
|
2866
|
-
const usageStr = formatUsageStats(r.usage, r.model);
|
|
2867
|
-
if (usageStr) {
|
|
2868
|
-
container.addChild(new Text(theme.fg("dim", usageStr), 0, 0));
|
|
2869
|
-
}
|
|
2870
|
-
container.addChild(new Spacer(1));
|
|
3022
|
+
addExpandedSubTask(container, r, theme, mdTheme, { stepPrefix: false });
|
|
2871
3023
|
}
|
|
2872
3024
|
}
|
|
2873
3025
|
|
|
2874
|
-
|
|
2875
|
-
const aggUsage: UsageStats = {
|
|
2876
|
-
input: details.totalInput,
|
|
2877
|
-
output: details.totalOutput,
|
|
2878
|
-
cacheRead: 0,
|
|
2879
|
-
cacheWrite: 0,
|
|
2880
|
-
cost: details.totalCost,
|
|
2881
|
-
contextTokens: 0,
|
|
2882
|
-
turns: details.totalTurns,
|
|
2883
|
-
};
|
|
2884
|
-
const aggStr = formatUsageStats(aggUsage);
|
|
2885
|
-
if (aggStr) {
|
|
2886
|
-
container.addChild(
|
|
2887
|
-
new Text(theme.fg("dim", `Totals: ${aggStr}`), 0, 0),
|
|
2888
|
-
);
|
|
2889
|
-
}
|
|
3026
|
+
addAggregatedTotals(container, details, theme);
|
|
2890
3027
|
|
|
2891
3028
|
return container;
|
|
2892
3029
|
}
|
|
@@ -2895,74 +3032,67 @@ function renderExpandedGraph(
|
|
|
2895
3032
|
// Public rendering entry points (used by delegate_task tool)
|
|
2896
3033
|
// ---------------------------------------------------------------------------
|
|
2897
3034
|
|
|
3035
|
+
/**
|
|
3036
|
+
* Render the delegate_task call preview shared by graph / chain / parallel.
|
|
3037
|
+
* `items` are pre-resolved labels (plus an optional already-formatted suffix).
|
|
3038
|
+
*/
|
|
3039
|
+
function renderDelegatePreview(
|
|
3040
|
+
kind: string,
|
|
3041
|
+
noun: string,
|
|
3042
|
+
items: Array<{ label: string; suffix?: string }>,
|
|
3043
|
+
theme: Theme,
|
|
3044
|
+
): Text {
|
|
3045
|
+
const count = items.length;
|
|
3046
|
+
let text = `${theme.fg("accent", "delegate_task")} ${theme.fg("muted", `${kind} (${count} ${noun}${count > 1 ? "s" : ""})`)}`;
|
|
3047
|
+
const preview = items.slice(0, 3);
|
|
3048
|
+
for (let i = 0; i < preview.length; i++) {
|
|
3049
|
+
const item = preview[i];
|
|
3050
|
+
const suffix = item.suffix ? theme.fg("dim", item.suffix) : "";
|
|
3051
|
+
text += `\n${theme.fg("muted", `${i + 1}.`)} ${theme.fg("dim", item.label)}${suffix}`;
|
|
3052
|
+
}
|
|
3053
|
+
if (count > 3) {
|
|
3054
|
+
text += `\n${theme.fg("dim", `+${count - 3} more`)}`;
|
|
3055
|
+
}
|
|
3056
|
+
return new Text(text, 0, 0);
|
|
3057
|
+
}
|
|
3058
|
+
|
|
2898
3059
|
export function renderDelegateCall(
|
|
2899
|
-
args:
|
|
2900
|
-
task?: string;
|
|
2901
|
-
label?: string;
|
|
2902
|
-
systemPrompt?: string;
|
|
2903
|
-
inheritSystemPrompt?: boolean;
|
|
2904
|
-
thinkingLevel?: string;
|
|
2905
|
-
outputFile?: string;
|
|
2906
|
-
timeout?: number;
|
|
2907
|
-
cwd?: string;
|
|
2908
|
-
tools?: string[];
|
|
2909
|
-
excludeTools?: string[];
|
|
2910
|
-
noBuiltinTools?: boolean;
|
|
2911
|
-
chain?: SubTaskParams[];
|
|
2912
|
-
tasks?: SubTaskParams[];
|
|
2913
|
-
graph?: GraphTask[];
|
|
2914
|
-
},
|
|
3060
|
+
args: DelegateTaskParams,
|
|
2915
3061
|
theme: Theme,
|
|
2916
3062
|
): Text {
|
|
2917
3063
|
// Graph mode
|
|
2918
3064
|
if (args.graph && args.graph.length > 0) {
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
text += `
|
|
2931
|
-
${theme.fg("dim", `+${n - 3} more`)}`;
|
|
2932
|
-
}
|
|
2933
|
-
return new Text(text, 0, 0);
|
|
3065
|
+
return renderDelegatePreview(
|
|
3066
|
+
"graph",
|
|
3067
|
+
"task",
|
|
3068
|
+
args.graph.map((t) => ({
|
|
3069
|
+
label: t.label || t.id,
|
|
3070
|
+
suffix: t.dependsOn?.length
|
|
3071
|
+
? ` [depends on: ${t.dependsOn.join(", ")}]`
|
|
3072
|
+
: undefined,
|
|
3073
|
+
})),
|
|
3074
|
+
theme,
|
|
3075
|
+
);
|
|
2934
3076
|
}
|
|
2935
3077
|
|
|
2936
3078
|
// Chain mode
|
|
2937
3079
|
if (args.chain && args.chain.length > 0) {
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
text += `\n${theme.fg("muted", `${i + 1}.`)} ${theme.fg("dim", label)}`;
|
|
2945
|
-
}
|
|
2946
|
-
if (n > 3) {
|
|
2947
|
-
text += `\n${theme.fg("dim", `+${n - 3} more`)}`;
|
|
2948
|
-
}
|
|
2949
|
-
return new Text(text, 0, 0);
|
|
3080
|
+
return renderDelegatePreview(
|
|
3081
|
+
"chain",
|
|
3082
|
+
"step",
|
|
3083
|
+
args.chain.map((s) => ({ label: s.label || s.task.slice(0, 60) })),
|
|
3084
|
+
theme,
|
|
3085
|
+
);
|
|
2950
3086
|
}
|
|
2951
3087
|
|
|
2952
3088
|
// Parallel mode
|
|
2953
3089
|
if (args.tasks && args.tasks.length > 0) {
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
text += `\n${theme.fg("muted", `${i + 1}.`)} ${theme.fg("dim", label)}`;
|
|
2961
|
-
}
|
|
2962
|
-
if (n > 3) {
|
|
2963
|
-
text += `\n${theme.fg("dim", `+${n - 3} more`)}`;
|
|
2964
|
-
}
|
|
2965
|
-
return new Text(text, 0, 0);
|
|
3090
|
+
return renderDelegatePreview(
|
|
3091
|
+
"parallel",
|
|
3092
|
+
"task",
|
|
3093
|
+
args.tasks.map((t) => ({ label: t.label || t.task.slice(0, 60) })),
|
|
3094
|
+
theme,
|
|
3095
|
+
);
|
|
2966
3096
|
}
|
|
2967
3097
|
|
|
2968
3098
|
// Single mode (original)
|
|
@@ -3029,7 +3159,7 @@ export function renderDelegateResult(
|
|
|
3029
3159
|
}
|
|
3030
3160
|
|
|
3031
3161
|
const isError = isSubagentError(details);
|
|
3032
|
-
const icon = isError ?
|
|
3162
|
+
const icon = formatOutcomeSymbol(isError ? "failure" : "success", theme);
|
|
3033
3163
|
const finalOutput = getFinalOutput(details.messages);
|
|
3034
3164
|
|
|
3035
3165
|
if (options.expanded) {
|