brl-subagent 2.5.2 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENT.md +12 -10
- package/README.md +16 -5
- package/package.json +5 -5
- package/src/concurrency.ts +156 -44
- package/src/index.ts +100 -34
- package/src/params.ts +73 -5
- package/src/schema.ts +3 -1
- package/src/state.ts +29 -4
- package/src/tui-format.ts +382 -4
- package/src/tui.ts +793 -522
- package/src/types.ts +12 -2
package/src/tui.ts
CHANGED
|
@@ -33,6 +33,8 @@ import type {
|
|
|
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) {
|
|
@@ -686,193 +749,256 @@ export async function showPresetManager(
|
|
|
686
749
|
|
|
687
750
|
const items: SelectItem[] = [
|
|
688
751
|
...builtinItems,
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
value: "__divider__",
|
|
693
|
-
label: "\u2500\u2500\u2500 Custom Presets \u2500\u2500\u2500",
|
|
694
|
-
description: "",
|
|
695
|
-
},
|
|
696
|
-
]
|
|
697
|
-
: []),
|
|
752
|
+
// Shared factory (U1) rather than a literal: same value shape
|
|
753
|
+
// (`__divider__:<slug>`) and label grammar as every other section row.
|
|
754
|
+
...(customItems.length > 0 ? [menuSection("Custom Presets")] : []),
|
|
698
755
|
...customItems,
|
|
699
756
|
];
|
|
700
757
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
if (!result || result === "__divider__") return;
|
|
758
|
+
// Defensive zero-item case, mirroring the Templates manager: never open an
|
|
759
|
+
// empty SelectList — say so instead.
|
|
760
|
+
if (items.length === 0) {
|
|
761
|
+
ctx.ui.notify(emptyManagerNotice("presets", "presets", "presets"), "info");
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
708
764
|
|
|
709
|
-
{
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
765
|
+
const title = `Presets (${state.builtinPresets.length} built-in, ${state.customPresets.length} custom)`;
|
|
766
|
+
|
|
767
|
+
// Browse loop: selecting the divider is a no-op re-render (the list comes
|
|
768
|
+
// back), never a close — the same semantics as the Templates manager and
|
|
769
|
+
// the config menu's dividers.
|
|
770
|
+
while (true) {
|
|
771
|
+
const result = await showSelectList(ctx, title, items, 15);
|
|
772
|
+
if (!result) return;
|
|
773
|
+
if (isDividerValue(result)) continue;
|
|
774
|
+
|
|
775
|
+
// Row values carry the tier prefix; the detail view takes the bare name.
|
|
776
|
+
const presetName = result.startsWith("__builtin__:")
|
|
714
777
|
? result.slice("__builtin__:".length)
|
|
715
|
-
:
|
|
778
|
+
: result.startsWith("__custom__:")
|
|
716
779
|
? result.slice("__custom__:".length)
|
|
717
780
|
: result;
|
|
781
|
+
await showViewPreset(ctx, state, presetName);
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
718
785
|
|
|
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
|
-
|
|
786
|
+
/**
|
|
787
|
+
* Preset detail view. Mirrors `showViewTemplate` exactly (U6): same tier suffix
|
|
788
|
+
* vocabulary, same `Label: value` field grammar, and the same unset-field policy
|
|
789
|
+
* — unset optional fields are omitted, `Inherit:` always renders because it is a
|
|
790
|
+
* real default (`yes (default)`), not an absent value.
|
|
791
|
+
*/
|
|
792
|
+
export async function showViewPreset(
|
|
793
|
+
ctx: ExtensionContext,
|
|
794
|
+
state: SessionState,
|
|
795
|
+
name: string,
|
|
796
|
+
): Promise<void> {
|
|
797
|
+
const preset = getPreset(name, state.builtinPresets, state.customPresets);
|
|
798
|
+
if (!preset) return;
|
|
799
|
+
|
|
800
|
+
// A custom preset that shadows a built-in name wins in getPreset, so only a
|
|
801
|
+
// name with no custom entry is `builtin`; the rest split project/global.
|
|
802
|
+
const tier: Tier = state.customPresets.some((p) => p.name === preset.name)
|
|
803
|
+
? findPresetSource(preset.name, ctx)
|
|
804
|
+
: "builtin";
|
|
805
|
+
|
|
806
|
+
await showDetailView(ctx, {
|
|
807
|
+
title: `Preset: ${preset.name}`,
|
|
808
|
+
tier,
|
|
809
|
+
description: preset.description,
|
|
810
|
+
content: (theme) =>
|
|
811
|
+
detailFieldLines(theme, [
|
|
812
|
+
{ label: "Thinking", value: preset.thinkingLevel },
|
|
813
|
+
{
|
|
814
|
+
label: "Inherit",
|
|
815
|
+
value: preset.inheritSystemPrompt === false ? "no" : "yes (default)",
|
|
816
|
+
},
|
|
817
|
+
{ label: "Tools", value: preset.tools?.join(", ") },
|
|
818
|
+
{ label: "Exclude", value: preset.excludeTools?.join(", ") },
|
|
819
|
+
{ label: "System prompt", value: preset.systemPrompt?.slice(0, 100) },
|
|
820
|
+
]),
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// ---------------------------------------------------------------------------
|
|
825
|
+
// Tier classification (menu polish U4, umbrella #345)
|
|
826
|
+
// ---------------------------------------------------------------------------
|
|
827
|
+
|
|
828
|
+
/** Tier vocabulary shared by presets and templates: shipped, project-local, user-global. */
|
|
829
|
+
export type Tier = "builtin" | "project" | "global";
|
|
830
|
+
|
|
831
|
+
/** One candidate directory for classifyTier, tagged with the tier it represents. */
|
|
832
|
+
export interface TierDir {
|
|
833
|
+
tier: "project" | "global";
|
|
834
|
+
dir: string;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/** Injected I/O and terminal fallback for classifyTier (keeps the decision pure). */
|
|
838
|
+
export interface TierClassifierIo {
|
|
839
|
+
/** Terminal fallback for the surface: the tier to return when no canonical file matches. */
|
|
840
|
+
fallback: Tier;
|
|
841
|
+
/** Existence probe for a candidate file path. */
|
|
842
|
+
exists: (filePath: string) => boolean;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Pure tier classifier: decide which tier a preset or template name comes from.
|
|
847
|
+
*
|
|
848
|
+
* Order of decision:
|
|
849
|
+
* 1. `<sanitizeFileName(name)>.md` in each `dirs` entry, in order — the real
|
|
850
|
+
* writers (`writePresetFile` / `writeTemplateFile`) emit exactly that
|
|
851
|
+
* filename via the same `sanitizeFileName`, so a file we wrote by name is
|
|
852
|
+
* always resolved by path (#345 A1: the pre-U4 finders re-derived a
|
|
853
|
+
* different, lowercased/underscored filename convention and missed it).
|
|
854
|
+
* 2. `io.fallback` — the surface's terminal value: `builtin` for templates,
|
|
855
|
+
* `project` for presets (the preset manager only has [P]/[G] labels, so it
|
|
856
|
+
* maps the non-global answer to `project`).
|
|
857
|
+
*
|
|
858
|
+
* Both the filesystem and the fallback are injected, so the result is a pure
|
|
859
|
+
* function of its arguments and testable against temp dirs or stubs.
|
|
860
|
+
*
|
|
861
|
+
* Documented residual (accepted this cycle): a hand-written file that overrides
|
|
862
|
+
* a builtin NAME but is stored under a non-canonical filename matches no path
|
|
863
|
+
* and is therefore classified by the surface fallback (templates → `builtin`,
|
|
864
|
+
* presets → `project`). The additive `source` field (out of scope for U4) is
|
|
865
|
+
* what would fix it.
|
|
866
|
+
*/
|
|
867
|
+
export function classifyTier(
|
|
868
|
+
name: string,
|
|
869
|
+
dirs: readonly TierDir[],
|
|
870
|
+
io: TierClassifierIo,
|
|
871
|
+
): Tier {
|
|
872
|
+
const fileName = sanitizeFileName(name) + ".md";
|
|
873
|
+
for (const { tier, dir } of dirs) {
|
|
874
|
+
if (io.exists(path.join(dir, fileName))) return tier;
|
|
770
875
|
}
|
|
876
|
+
return io.fallback;
|
|
771
877
|
}
|
|
772
878
|
|
|
773
879
|
/**
|
|
774
|
-
*
|
|
775
|
-
*
|
|
880
|
+
* The two on-disk tiers for a preset or template surface, highest priority
|
|
881
|
+
* first. Mirrors the order loadCustomPresets/loadCustomTemplates scan: the
|
|
882
|
+
* project-local dir wins over the user-global dir.
|
|
776
883
|
*/
|
|
777
|
-
function
|
|
884
|
+
function tierDirs(ctx: ExtensionContext, kind: "presets" | "templates"): TierDir[] {
|
|
778
885
|
const homedir = process.env.HOME || process.env.USERPROFILE || "";
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
886
|
+
return [
|
|
887
|
+
{ tier: "project", dir: path.join(ctx.cwd, ".pi", "brl-subagent", kind) },
|
|
888
|
+
{ tier: "global", dir: path.join(homedir, ".pi", "agent", "brl-subagent", kind) },
|
|
889
|
+
];
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Determine whether a custom preset comes from the project or global directory.
|
|
894
|
+
* Delegates the decision to classifyTier; the preset manager only ever labels
|
|
895
|
+
* custom entries ([P]/[G]), and the preset surface fallback is already
|
|
896
|
+
* `project`, so a builtin-named custom preset stored under a non-canonical
|
|
897
|
+
* filename keeps the pre-U4 project label.
|
|
898
|
+
*/
|
|
899
|
+
export function findPresetSource(name: string, ctx: ExtensionContext): "project" | "global" {
|
|
900
|
+
const tier = classifyTier(name, tierDirs(ctx, "presets"), {
|
|
901
|
+
fallback: "project",
|
|
902
|
+
exists: fs.existsSync,
|
|
903
|
+
});
|
|
904
|
+
return tier === "global" ? "global" : "project";
|
|
786
905
|
}
|
|
787
906
|
|
|
788
907
|
/**
|
|
789
908
|
* Determine which tier a template comes from: project, global, or builtin.
|
|
790
|
-
*
|
|
791
|
-
*
|
|
909
|
+
* Mirrors findPresetSource. The `builtin` terminal value is the template
|
|
910
|
+
* surface fallback: any name with no canonical file on disk is `builtin`.
|
|
792
911
|
*/
|
|
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";
|
|
912
|
+
export function findTemplateSource(name: string, ctx: ExtensionContext): Tier {
|
|
913
|
+
return classifyTier(name, tierDirs(ctx, "templates"), {
|
|
914
|
+
fallback: "builtin",
|
|
915
|
+
exists: fs.existsSync,
|
|
916
|
+
});
|
|
805
917
|
}
|
|
806
918
|
|
|
807
919
|
// ---------------------------------------------------------------------------
|
|
808
|
-
//
|
|
920
|
+
// Shared manager/detail helpers (menu polish U6, umbrella #345)
|
|
809
921
|
// ---------------------------------------------------------------------------
|
|
810
922
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
923
|
+
/**
|
|
924
|
+
* The empty-state notice every manager surface uses: one shape, one set of
|
|
925
|
+
* places to add files. A manager whose row list is empty notifies with this
|
|
926
|
+
* instead of opening a SelectList with nothing to select.
|
|
927
|
+
*/
|
|
928
|
+
export function emptyManagerNotice(
|
|
929
|
+
loadedNoun: string,
|
|
930
|
+
builtinNoun: string,
|
|
931
|
+
dir: string,
|
|
932
|
+
): string {
|
|
933
|
+
return (
|
|
934
|
+
`No ${loadedNoun} loaded — built-in ${builtinNoun} ship with the extension and ` +
|
|
935
|
+
"should always be present. Add custom .md files in " +
|
|
936
|
+
`~/.pi/agent/brl-subagent/${dir}/ or <project>/.pi/brl-subagent/${dir}/.`
|
|
937
|
+
);
|
|
816
938
|
}
|
|
817
939
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
940
|
+
/**
|
|
941
|
+
* Tier suffix for a detail-view title: `(built-in)`, `(project)`, or `(global)`.
|
|
942
|
+
* One vocabulary for both detail views, so the title always names the same tier
|
|
943
|
+
* the manager row's `[B]`/`[P]`/`[G]` prefix came from.
|
|
944
|
+
*/
|
|
945
|
+
export function tierDetailSuffix(tier: Tier): string {
|
|
946
|
+
return tier === "builtin" ? " (built-in)" : tier === "project" ? " (project)" : " (global)";
|
|
947
|
+
}
|
|
825
948
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
: " (global)";
|
|
949
|
+
/**
|
|
950
|
+
* One `Label: value` row in a detail view. `value === undefined` means "unset"
|
|
951
|
+
* and the row is omitted (the U6 unset-field policy).
|
|
952
|
+
*/
|
|
953
|
+
export interface DetailField {
|
|
954
|
+
label: string;
|
|
955
|
+
value: string | undefined;
|
|
956
|
+
}
|
|
835
957
|
|
|
836
|
-
|
|
958
|
+
/**
|
|
959
|
+
* Render a detail view's field block: dim `Label: value` lines, in the order
|
|
960
|
+
* given, with unset fields omitted. A field that has a real DEFAULT (such as
|
|
961
|
+
* `Inherit: yes (default)`) passes its resolved value and therefore always
|
|
962
|
+
* renders — the policy drops absent data, not defaults.
|
|
963
|
+
*/
|
|
964
|
+
export function detailFieldLines(theme: Theme, fields: readonly DetailField[]): string[] {
|
|
965
|
+
return fields
|
|
966
|
+
.filter((f) => f.value !== undefined && f.value !== "")
|
|
967
|
+
.map((f) => theme.fg("dim", `${f.label}: ${f.value}`));
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/** What a detail view shows: a titled, tier-suffixed header plus body lines. */
|
|
971
|
+
export interface DetailView {
|
|
972
|
+
/** Bold accent title, e.g. `Preset: code-review`. */
|
|
973
|
+
title: string;
|
|
974
|
+
/** Tier vocabulary from `tierDetailSuffix`. */
|
|
975
|
+
tier: Tier;
|
|
976
|
+
/** Optional dim subtitle under the title. */
|
|
977
|
+
description?: string;
|
|
978
|
+
/** Body lines (a lead row first, then the field block). */
|
|
979
|
+
content: (theme: Theme) => string[];
|
|
980
|
+
}
|
|
837
981
|
|
|
982
|
+
/**
|
|
983
|
+
* The one detail-view shell both `showViewPreset` and `showViewTemplate` use:
|
|
984
|
+
* accent border, title + tier suffix, optional description, body, close hint.
|
|
985
|
+
* Sharing it keeps the grammar and suffix vocabulary from drifting apart.
|
|
986
|
+
*/
|
|
987
|
+
async function showDetailView(ctx: ExtensionContext, view: DetailView): Promise<void> {
|
|
838
988
|
await ctx.ui.custom<void>((_tui, theme, _kb, done) => {
|
|
839
989
|
const container = new Container();
|
|
840
990
|
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
841
991
|
container.addChild(
|
|
842
992
|
new Text(
|
|
843
|
-
theme.fg("accent", theme.bold(
|
|
844
|
-
theme.fg("dim", tierSuffix),
|
|
993
|
+
theme.fg("accent", theme.bold(view.title)) + theme.fg("dim", tierDetailSuffix(view.tier)),
|
|
845
994
|
1,
|
|
846
995
|
0,
|
|
847
996
|
),
|
|
848
997
|
);
|
|
849
|
-
if (
|
|
850
|
-
container.addChild(new Text(theme.fg("dim",
|
|
998
|
+
if (view.description)
|
|
999
|
+
container.addChild(new Text(theme.fg("dim", view.description), 1, 0));
|
|
851
1000
|
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
|
-
);
|
|
1001
|
+
for (const line of view.content(theme)) container.addChild(new Text(line, 1, 0));
|
|
876
1002
|
container.addChild(new Text("", 0, 0));
|
|
877
1003
|
container.addChild(new Text(theme.fg("dim", "Press any key to close"), 1, 0));
|
|
878
1004
|
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
@@ -884,117 +1010,217 @@ export async function showViewTemplate(
|
|
|
884
1010
|
});
|
|
885
1011
|
}
|
|
886
1012
|
|
|
1013
|
+
// ---------------------------------------------------------------------------
|
|
1014
|
+
// Template management UI
|
|
1015
|
+
// ---------------------------------------------------------------------------
|
|
1016
|
+
|
|
1017
|
+
/** True for a select-list divider row (`menuSection` shape), never a template. */
|
|
1018
|
+
function isDividerValue(value: string): boolean {
|
|
1019
|
+
return value.startsWith("__divider__");
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* Split the merged template stack by membership in the shipped built-ins: a
|
|
1024
|
+
* built-in OBJECT is `builtin`, everything else is `custom`. Object identity —
|
|
1025
|
+
* not the name, not the filename — is the partition key, so a custom template
|
|
1026
|
+
* that overrides a built-in name (the merged stack then holds only the custom
|
|
1027
|
+
* object) still counts as custom. Both the manager and the parent config row
|
|
1028
|
+
* read this, so their counts can never disagree.
|
|
1029
|
+
*/
|
|
1030
|
+
export function partitionTemplates(
|
|
1031
|
+
templates: readonly TaskTemplate[],
|
|
1032
|
+
builtinTemplates: readonly TaskTemplate[],
|
|
1033
|
+
): { builtin: TaskTemplate[]; custom: TaskTemplate[] } {
|
|
1034
|
+
const shipped = new Set<TaskTemplate>(builtinTemplates);
|
|
1035
|
+
const builtin: TaskTemplate[] = [];
|
|
1036
|
+
const custom: TaskTemplate[] = [];
|
|
1037
|
+
for (const t of templates) (shipped.has(t) ? builtin : custom).push(t);
|
|
1038
|
+
return { builtin, custom };
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* Build the Templates manager's rows: built-ins first (shipped order), then —
|
|
1043
|
+
* only when customs exist — a `─── Custom Templates ───` divider, then customs
|
|
1044
|
+
* in current order. Pure: the tier lookup for the `[P]`/`[G]` prefix is injected
|
|
1045
|
+
* (`findTemplateSource` in production), so ordering/partition is testable with
|
|
1046
|
+
* no TUI and no filesystem.
|
|
1047
|
+
*
|
|
1048
|
+
* @param templates - the FULL merged stack (`state.config.templates`)
|
|
1049
|
+
* @param sourceOf - tier lookup for a custom row's prefix
|
|
1050
|
+
* @param builtinTemplates - the shipped built-ins (`state.builtinTemplates`)
|
|
1051
|
+
*/
|
|
1052
|
+
export function buildTemplateMenuItems(
|
|
1053
|
+
templates: readonly TaskTemplate[],
|
|
1054
|
+
sourceOf: (name: string) => Tier,
|
|
1055
|
+
builtinTemplates: readonly TaskTemplate[],
|
|
1056
|
+
): SelectItem[] {
|
|
1057
|
+
const { builtin, custom } = partitionTemplates(templates, builtinTemplates);
|
|
1058
|
+
|
|
1059
|
+
const rows = (list: TaskTemplate[], prefix: (t: TaskTemplate) => string): SelectItem[] =>
|
|
1060
|
+
list.map((t) => ({
|
|
1061
|
+
value: t.name,
|
|
1062
|
+
label: `[${prefix(t)}] ${t.name}`,
|
|
1063
|
+
description: t.description || formatTemplateSummary(t),
|
|
1064
|
+
}));
|
|
1065
|
+
|
|
1066
|
+
return [
|
|
1067
|
+
...rows(builtin, () => "B"),
|
|
1068
|
+
...(custom.length > 0 ? [menuSection("Custom Templates")] : []),
|
|
1069
|
+
...rows(custom, (t) => (sourceOf(t.name) === "project" ? "P" : "G")),
|
|
1070
|
+
];
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
export function getTemplate(
|
|
1074
|
+
name: string,
|
|
1075
|
+
templates: TaskTemplate[],
|
|
1076
|
+
): TaskTemplate | undefined {
|
|
1077
|
+
return templates.find((t) => t.name === name);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
export async function showViewTemplate(
|
|
1081
|
+
ctx: ExtensionContext,
|
|
1082
|
+
state: SessionState,
|
|
1083
|
+
name: string,
|
|
1084
|
+
): Promise<void> {
|
|
1085
|
+
const template = getTemplate(name, state.config.templates);
|
|
1086
|
+
if (!template) return;
|
|
1087
|
+
|
|
1088
|
+
const paramNames = extractParamNames(template.task + (template.outputFile || ""));
|
|
1089
|
+
|
|
1090
|
+
await showDetailView(ctx, {
|
|
1091
|
+
title: `Template: ${template.name}`,
|
|
1092
|
+
tier: findTemplateSource(template.name, ctx),
|
|
1093
|
+
description: template.description,
|
|
1094
|
+
// The task IS the template, so it leads the body; every other concept is
|
|
1095
|
+
// an optional field and follows the shared omit-when-unset policy.
|
|
1096
|
+
content: (theme) => [
|
|
1097
|
+
theme.fg("toolTitle", "Task:") + " " + theme.fg("toolOutput", template.task),
|
|
1098
|
+
...detailFieldLines(theme, [
|
|
1099
|
+
{
|
|
1100
|
+
label: "Parameters",
|
|
1101
|
+
value: paramNames.length > 0 ? paramNames.join(", ") : undefined,
|
|
1102
|
+
},
|
|
1103
|
+
{ label: "Preset", value: template.preset },
|
|
1104
|
+
{ label: "Thinking", value: template.thinkingLevel },
|
|
1105
|
+
{ label: "Output file", value: template.outputFile },
|
|
1106
|
+
{ label: "Timeout", value: template.timeout ? `${template.timeout}ms` : undefined },
|
|
1107
|
+
]),
|
|
1108
|
+
],
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
|
|
887
1112
|
export async function showTemplateManager(
|
|
888
1113
|
ctx: ExtensionContext,
|
|
889
1114
|
state: SessionState,
|
|
890
1115
|
): Promise<void> {
|
|
891
1116
|
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
|
-
);
|
|
1117
|
+
ctx.ui.notify(emptyManagerNotice("task templates", "templates", "templates"), "info");
|
|
898
1118
|
return;
|
|
899
1119
|
}
|
|
900
1120
|
|
|
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,
|
|
1121
|
+
// The FULL merged stack plus the shipped built-ins: the builder partitions by
|
|
1122
|
+
// membership, so custom-overrides-builtin still classifies as custom.
|
|
1123
|
+
const items = buildTemplateMenuItems(
|
|
1124
|
+
state.config.templates,
|
|
1125
|
+
(name) => findTemplateSource(name, ctx),
|
|
1126
|
+
state.builtinTemplates,
|
|
917
1127
|
);
|
|
918
|
-
|
|
1128
|
+
const { builtin, custom } = partitionTemplates(state.config.templates, state.builtinTemplates);
|
|
1129
|
+
const title = `Templates (${builtin.length} built-in, ${custom.length} custom)`;
|
|
1130
|
+
|
|
1131
|
+
// Browse loop: selecting the divider is a no-op re-render (the list comes
|
|
1132
|
+
// back), never a close — mirrors the config menu's divider semantics.
|
|
1133
|
+
while (true) {
|
|
1134
|
+
const result = await showSelectList(ctx, title, items, 15);
|
|
1135
|
+
if (!result) return;
|
|
1136
|
+
if (isDividerValue(result)) continue;
|
|
919
1137
|
|
|
920
|
-
|
|
1138
|
+
await showViewTemplate(ctx, state, result);
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
921
1141
|
}
|
|
922
1142
|
|
|
923
1143
|
// ---------------------------------------------------------------------------
|
|
924
1144
|
// Configuration menu
|
|
925
1145
|
// ---------------------------------------------------------------------------
|
|
926
1146
|
|
|
1147
|
+
/** Maximum config rows visible before the list scrolls (U3: 10 → 15). */
|
|
1148
|
+
export const CONFIG_MENU_VIEWPORT = 15;
|
|
1149
|
+
|
|
927
1150
|
export function getConfigMenuItems(state: SessionState): SelectItem[] {
|
|
1151
|
+
// Menu polish U2: every value row renders the canonical token from
|
|
1152
|
+
// `formatMenuValue` (tui-format.ts) instead of hand-rolled prose. Templates
|
|
1153
|
+
// have no `customTemplates` field on state; the merged stack keeps the
|
|
1154
|
+
// BUILTIN objects by reference (getAllTemplates), so an identity partition
|
|
1155
|
+
// is the state-side equivalent of the manager's builtin/custom split.
|
|
1156
|
+
const templateCounts = partitionTemplates(state.config.templates, state.builtinTemplates);
|
|
1157
|
+
|
|
928
1158
|
return [
|
|
929
1159
|
{
|
|
930
1160
|
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)",
|
|
1161
|
+
label: "Set Model",
|
|
1162
|
+
description: formatMenuValue("model", { model: state.config.model }),
|
|
935
1163
|
},
|
|
936
1164
|
{
|
|
937
1165
|
value: "thinking",
|
|
938
|
-
label: "
|
|
939
|
-
description:
|
|
1166
|
+
label: "Set Max Thinking Level",
|
|
1167
|
+
description: formatMenuValue("thinking", {
|
|
1168
|
+
maxThinkingLevel: state.config.maxThinkingLevel,
|
|
1169
|
+
}),
|
|
940
1170
|
},
|
|
941
1171
|
{
|
|
942
1172
|
value: "concurrency",
|
|
943
1173
|
label: "Set Max Parallel Subagents",
|
|
944
|
-
description:
|
|
1174
|
+
description: formatMenuValue("parallel", { maxParallel: state.config.maxParallel }),
|
|
945
1175
|
},
|
|
946
1176
|
{
|
|
947
1177
|
value: "depth",
|
|
948
1178
|
label: "Set Max Recursion Depth",
|
|
949
|
-
description:
|
|
950
|
-
|
|
951
|
-
|
|
1179
|
+
description: formatMenuValue("depth", {
|
|
1180
|
+
maxSubagentDepth: state.config.maxSubagentDepth,
|
|
1181
|
+
}),
|
|
952
1182
|
},
|
|
953
1183
|
{
|
|
954
1184
|
value: "approval",
|
|
955
1185
|
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",
|
|
1186
|
+
description: formatMenuValue("approval", { approvalMode: state.config.approvalMode }),
|
|
961
1187
|
},
|
|
962
1188
|
{
|
|
963
1189
|
value: "completionnotify",
|
|
964
1190
|
label: "Set Completion Notify Mode",
|
|
965
|
-
description:
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
? "Wake only on failed/stopped"
|
|
969
|
-
: "Never wake (passive delivery)",
|
|
1191
|
+
description: formatMenuValue("completionnotify", {
|
|
1192
|
+
completionNotify: state.config.completionNotify,
|
|
1193
|
+
}),
|
|
970
1194
|
},
|
|
971
1195
|
{
|
|
972
1196
|
value: "recovery",
|
|
973
1197
|
label: "Set Recovery Posture",
|
|
974
|
-
description: state.config.recovery
|
|
975
|
-
? "Surface interrupted runs (default)"
|
|
976
|
-
: "Do not surface interrupted runs",
|
|
1198
|
+
description: formatMenuValue("recovery", { recovery: state.config.recovery }),
|
|
977
1199
|
},
|
|
978
1200
|
|
|
979
1201
|
{
|
|
980
1202
|
value: "historyentries",
|
|
981
1203
|
label: "Set Max History Entries",
|
|
982
|
-
description:
|
|
983
|
-
|
|
984
|
-
|
|
1204
|
+
description: formatMenuValue("historyentries", {
|
|
1205
|
+
maxHistoryEntries: state.config.maxHistoryEntries,
|
|
1206
|
+
}),
|
|
985
1207
|
},
|
|
986
1208
|
{
|
|
987
1209
|
value: "costlimit",
|
|
988
1210
|
label: "Set Session Cost Limit",
|
|
989
|
-
description:
|
|
990
|
-
|
|
991
|
-
|
|
1211
|
+
description: formatMenuValue("costlimit", {
|
|
1212
|
+
sessionCostLimit: state.config.sessionCostLimit,
|
|
1213
|
+
}),
|
|
992
1214
|
},
|
|
993
1215
|
{
|
|
994
|
-
value: "
|
|
995
|
-
label: "
|
|
996
|
-
description: "
|
|
1216
|
+
value: "sla",
|
|
1217
|
+
label: "Set SLA Tracking",
|
|
1218
|
+
description: formatMenuValue("sla", {
|
|
1219
|
+
slaTrackingEnabled: state.config.slaTrackingEnabled,
|
|
1220
|
+
slaWindowSize: state.config.slaWindowSize,
|
|
1221
|
+
}),
|
|
997
1222
|
},
|
|
1223
|
+
menuSection("Run Activity"),
|
|
998
1224
|
{
|
|
999
1225
|
value: "history",
|
|
1000
1226
|
label: "View Run History",
|
|
@@ -1002,37 +1228,40 @@ export function getConfigMenuItems(state: SessionState): SelectItem[] {
|
|
|
1002
1228
|
},
|
|
1003
1229
|
{
|
|
1004
1230
|
value: "monitor",
|
|
1005
|
-
label: "Live Monitor",
|
|
1231
|
+
label: "View Live Monitor",
|
|
1006
1232
|
description: "Watch running subagents in real-time",
|
|
1007
1233
|
},
|
|
1008
1234
|
{
|
|
1009
1235
|
value: "dashboard",
|
|
1010
|
-
label: "Observability Dashboard",
|
|
1236
|
+
label: "View Observability Dashboard",
|
|
1011
1237
|
description: "Real-time metrics, SLA, errors, and cost trends",
|
|
1012
1238
|
},
|
|
1013
1239
|
{
|
|
1014
|
-
value: "
|
|
1015
|
-
label: "
|
|
1016
|
-
description:
|
|
1240
|
+
value: "retry",
|
|
1241
|
+
label: "Retry Failed Run",
|
|
1242
|
+
description: "Select a failed subagent to retry",
|
|
1017
1243
|
},
|
|
1244
|
+
menuSection("Presets & Templates"),
|
|
1018
1245
|
{
|
|
1019
|
-
value: "
|
|
1020
|
-
label: "
|
|
1021
|
-
description:
|
|
1022
|
-
|
|
1023
|
-
:
|
|
1246
|
+
value: "preset",
|
|
1247
|
+
label: "Browse Presets",
|
|
1248
|
+
description: formatMenuValue("presetCounts", {
|
|
1249
|
+
builtinCount: state.builtinPresets.length,
|
|
1250
|
+
customCount: state.customPresets.length,
|
|
1251
|
+
}),
|
|
1024
1252
|
},
|
|
1025
1253
|
{
|
|
1026
|
-
value: "
|
|
1027
|
-
label: "
|
|
1028
|
-
description: "
|
|
1254
|
+
value: "templates",
|
|
1255
|
+
label: "Browse Templates",
|
|
1256
|
+
description: formatMenuValue("templateCounts", {
|
|
1257
|
+
builtinCount: templateCounts.builtin.length,
|
|
1258
|
+
customCount: templateCounts.custom.length,
|
|
1259
|
+
}),
|
|
1029
1260
|
},
|
|
1030
1261
|
{
|
|
1031
|
-
value: "
|
|
1032
|
-
label: "
|
|
1033
|
-
description:
|
|
1034
|
-
? `Enabled (window: ${state.config.slaWindowSize})`
|
|
1035
|
-
: "Disabled",
|
|
1262
|
+
value: "reset",
|
|
1263
|
+
label: "Reset Configuration",
|
|
1264
|
+
description: "Clear subagent configuration",
|
|
1036
1265
|
},
|
|
1037
1266
|
];
|
|
1038
1267
|
}
|
|
@@ -1060,37 +1289,9 @@ export async function showConfigMenu(
|
|
|
1060
1289
|
new Text(theme.fg("accent", theme.bold("brl-subagent Configuration")), 1, 0),
|
|
1061
1290
|
);
|
|
1062
1291
|
|
|
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
1292
|
const selectList = new SelectList(
|
|
1092
1293
|
items,
|
|
1093
|
-
Math.min(items.length,
|
|
1294
|
+
Math.min(items.length, CONFIG_MENU_VIEWPORT),
|
|
1094
1295
|
makeSelectListTheme(theme),
|
|
1095
1296
|
);
|
|
1096
1297
|
selectList.onSelect = (item) => done(item.value);
|
|
@@ -1140,8 +1341,8 @@ export async function showRunHistory(
|
|
|
1140
1341
|
): Promise<void> {
|
|
1141
1342
|
const statusIcon: Record<string, string> = {
|
|
1142
1343
|
running: ctx.ui.theme.fg("accent", "◉"),
|
|
1143
|
-
done:
|
|
1144
|
-
failed: ctx.ui.theme
|
|
1344
|
+
done: formatOutcomeSymbol("success", ctx.ui.theme),
|
|
1345
|
+
failed: formatOutcomeSymbol("failure", ctx.ui.theme),
|
|
1145
1346
|
interrupted: ctx.ui.theme.fg("warning", "◌"),
|
|
1146
1347
|
};
|
|
1147
1348
|
|
|
@@ -1182,8 +1383,8 @@ export async function showRunHistory(
|
|
|
1182
1383
|
// Mark as seen
|
|
1183
1384
|
if (state.markRunSeen(run.id)) {
|
|
1184
1385
|
persistState();
|
|
1185
|
-
import("./concurrency").then(({
|
|
1186
|
-
|
|
1386
|
+
import("./concurrency").then(({ repaintStatus }) => {
|
|
1387
|
+
repaintStatus(state, ctx);
|
|
1187
1388
|
});
|
|
1188
1389
|
}
|
|
1189
1390
|
|
|
@@ -1829,6 +2030,250 @@ function compactDuration(ms: number): string {
|
|
|
1829
2030
|
return `${Math.floor(ms / 60_000)}m${Math.round((ms % 60_000) / 1000)}s`;
|
|
1830
2031
|
}
|
|
1831
2032
|
|
|
2033
|
+
// ---------------------------------------------------------------------------
|
|
2034
|
+
// E1 dashboard panels (issue #356)
|
|
2035
|
+
//
|
|
2036
|
+
// `showDashboard` is a thin composer: it samples the session state once per
|
|
2037
|
+
// render pass, then appends these six panels in order. Each panel renders only
|
|
2038
|
+
// its own data slice and returns its components instead of painting a
|
|
2039
|
+
// container, so its output is pinnable without a terminal (see
|
|
2040
|
+
// `src/__tests__/dashboard-panels.test.ts`) while the composer keeps ownership
|
|
2041
|
+
// of ordering, borders and spacing.
|
|
2042
|
+
// ---------------------------------------------------------------------------
|
|
2043
|
+
|
|
2044
|
+
/** The per-row live-session slice the Active Subagents panel renders. */
|
|
2045
|
+
export type ActiveSubagentSlice = Pick<
|
|
2046
|
+
LiveSubagent,
|
|
2047
|
+
"label" | "task" | "startedAt" | "usage"
|
|
2048
|
+
>;
|
|
2049
|
+
|
|
2050
|
+
/** Panel 1 — header: the dashboard title plus the refresh stamp. */
|
|
2051
|
+
export function renderDashboardHeader(theme: Theme, refreshStr: string): Component[] {
|
|
2052
|
+
return [
|
|
2053
|
+
new Text(
|
|
2054
|
+
theme.fg("accent", theme.bold("brl-subagent Dashboard")) +
|
|
2055
|
+
theme.fg("dim", ` ${refreshStr}`),
|
|
2056
|
+
1,
|
|
2057
|
+
0,
|
|
2058
|
+
),
|
|
2059
|
+
new Text("", 0, 0),
|
|
2060
|
+
];
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
/**
|
|
2064
|
+
* Panel 2 — active subagents: the live count in the title, one row per entry.
|
|
2065
|
+
*
|
|
2066
|
+
* `now` is injected (the composer passes the wall clock) so the spinner frame
|
|
2067
|
+
* and the elapsed suffix stay testable; it is sampled per row, as before.
|
|
2068
|
+
*/
|
|
2069
|
+
export function renderDashboardActivePanel(
|
|
2070
|
+
theme: Theme,
|
|
2071
|
+
sessions: ReadonlyMap<string, ActiveSubagentSlice>,
|
|
2072
|
+
now: () => number = Date.now,
|
|
2073
|
+
): Component[] {
|
|
2074
|
+
const activeCount = sessions.size;
|
|
2075
|
+
const components: Component[] = [
|
|
2076
|
+
new Text(
|
|
2077
|
+
theme.fg("accent", theme.bold(`Active Subagents (${activeCount})`)),
|
|
2078
|
+
1,
|
|
2079
|
+
0,
|
|
2080
|
+
),
|
|
2081
|
+
];
|
|
2082
|
+
if (activeCount === 0) {
|
|
2083
|
+
components.push(new Text(theme.fg("dim", " None running"), 1, 0));
|
|
2084
|
+
} else {
|
|
2085
|
+
let idx = 0;
|
|
2086
|
+
for (const [id, session] of sessions) {
|
|
2087
|
+
const elapsedStr = formatElapsed(now() - session.startedAt);
|
|
2088
|
+
const name = liveRowName(session.label, session.task);
|
|
2089
|
+
const spinner = liveSpinner(now());
|
|
2090
|
+
components.push(
|
|
2091
|
+
new Text(
|
|
2092
|
+
theme.fg("accent", ` ${spinner} ${name}`) +
|
|
2093
|
+
theme.fg(
|
|
2094
|
+
"dim",
|
|
2095
|
+
formatLiveRowDim(id, session.usage, elapsedStr),
|
|
2096
|
+
),
|
|
2097
|
+
1,
|
|
2098
|
+
0,
|
|
2099
|
+
),
|
|
2100
|
+
);
|
|
2101
|
+
idx++;
|
|
2102
|
+
if (idx < activeCount) components.push(new Text("", 0, 0));
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
components.push(new Text("", 0, 0));
|
|
2106
|
+
return components;
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
/**
|
|
2110
|
+
* Panel 3 — SLA summary: success rate (colour-graded), p50/p95/p99 and cost over
|
|
2111
|
+
* the current SLA window. `metrics` is null when there is no run history and
|
|
2112
|
+
* `runCount` is the window size named in the title.
|
|
2113
|
+
*/
|
|
2114
|
+
export function renderDashboardSlaPanel(
|
|
2115
|
+
theme: Theme,
|
|
2116
|
+
metrics: SLAMetrics | null,
|
|
2117
|
+
runCount: number,
|
|
2118
|
+
): Component[] {
|
|
2119
|
+
const components: Component[] = [
|
|
2120
|
+
new Text(
|
|
2121
|
+
theme.fg("accent", theme.bold(`SLA Summary (last ${runCount} runs)`)),
|
|
2122
|
+
1,
|
|
2123
|
+
0,
|
|
2124
|
+
),
|
|
2125
|
+
];
|
|
2126
|
+
if (metrics && metrics.totalRuns > 0) {
|
|
2127
|
+
const successPct = (metrics.successRate * 100).toFixed(1);
|
|
2128
|
+
const successColor = metrics.successRate >= 0.9 ? "success" : metrics.successRate >= 0.7 ? "warning" : "error";
|
|
2129
|
+
components.push(
|
|
2130
|
+
new Text(
|
|
2131
|
+
theme.fg("dim", " Success: ") +
|
|
2132
|
+
theme.fg(successColor, `${successPct}%`) +
|
|
2133
|
+
theme.fg("dim", ` \u00b7 p50: ${compactDuration(metrics.p50DurationMs)} \u00b7 p95: ${compactDuration(metrics.p95DurationMs)} \u00b7 p99: ${compactDuration(metrics.p99DurationMs)}`),
|
|
2134
|
+
1,
|
|
2135
|
+
0,
|
|
2136
|
+
),
|
|
2137
|
+
);
|
|
2138
|
+
components.push(
|
|
2139
|
+
new Text(
|
|
2140
|
+
theme.fg("dim", " Cost: ") +
|
|
2141
|
+
theme.fg("dim", `total $${metrics.totalCost.toFixed(4)} \u00b7 avg $${metrics.averageCost.toFixed(4)}`),
|
|
2142
|
+
1,
|
|
2143
|
+
0,
|
|
2144
|
+
),
|
|
2145
|
+
);
|
|
2146
|
+
} else {
|
|
2147
|
+
components.push(new Text(theme.fg("dim", " No completed runs yet"), 1, 0));
|
|
2148
|
+
}
|
|
2149
|
+
components.push(new Text("", 0, 0));
|
|
2150
|
+
return components;
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
/** Panel 4 — recent runs: outcome symbol, name, duration and cost per row. */
|
|
2154
|
+
export function renderDashboardRecentRunsPanel(
|
|
2155
|
+
theme: Theme,
|
|
2156
|
+
runs: SubagentRun[],
|
|
2157
|
+
): Component[] {
|
|
2158
|
+
const components: Component[] = [
|
|
2159
|
+
new Text(
|
|
2160
|
+
theme.fg("accent", theme.bold("Recent Runs")),
|
|
2161
|
+
1,
|
|
2162
|
+
0,
|
|
2163
|
+
),
|
|
2164
|
+
];
|
|
2165
|
+
if (runs.length === 0) {
|
|
2166
|
+
components.push(new Text(theme.fg("dim", " No runs recorded"), 1, 0));
|
|
2167
|
+
} else {
|
|
2168
|
+
for (const run of runs) {
|
|
2169
|
+
const icon =
|
|
2170
|
+
run.status === "done"
|
|
2171
|
+
? formatOutcomeSymbol("success", theme)
|
|
2172
|
+
: run.status === "failed"
|
|
2173
|
+
? formatOutcomeSymbol("failure", theme)
|
|
2174
|
+
: theme.fg("accent", "\u25CF");
|
|
2175
|
+
const name = run.label || run.task.slice(0, 50);
|
|
2176
|
+
const dur = run.durationMs ? compactDuration(run.durationMs) : "...";
|
|
2177
|
+
const cost = run.cost ? ` $${run.cost.toFixed(4)}` : "";
|
|
2178
|
+
components.push(
|
|
2179
|
+
new Text(
|
|
2180
|
+
` ${icon} ${theme.fg("dim", name.slice(0, 50))}` +
|
|
2181
|
+
theme.fg("dim", ` ${dur}${cost}`),
|
|
2182
|
+
1,
|
|
2183
|
+
0,
|
|
2184
|
+
),
|
|
2185
|
+
);
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
components.push(new Text("", 0, 0));
|
|
2189
|
+
return components;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
/**
|
|
2193
|
+
* Panel 5 — error breakdown: categories sorted by count, each with a
|
|
2194
|
+
* proportional bar. An empty breakdown renders the "no errors" line.
|
|
2195
|
+
*/
|
|
2196
|
+
export function renderDashboardErrorPanel(
|
|
2197
|
+
theme: Theme,
|
|
2198
|
+
breakdown: Record<string, number> | undefined,
|
|
2199
|
+
): Component[] {
|
|
2200
|
+
const components: Component[] = [
|
|
2201
|
+
new Text(
|
|
2202
|
+
theme.fg("accent", theme.bold("Error Breakdown")),
|
|
2203
|
+
1,
|
|
2204
|
+
0,
|
|
2205
|
+
),
|
|
2206
|
+
];
|
|
2207
|
+
if (breakdown && Object.keys(breakdown).length > 0) {
|
|
2208
|
+
const cats = Object.entries(breakdown).sort(
|
|
2209
|
+
(a, b) => b[1] - a[1],
|
|
2210
|
+
);
|
|
2211
|
+
const maxCount = cats[0][1];
|
|
2212
|
+
for (const [cat, count] of cats) {
|
|
2213
|
+
const bar = buildHorizontalBar(count, maxCount, 20);
|
|
2214
|
+
components.push(
|
|
2215
|
+
new Text(
|
|
2216
|
+
theme.fg("dim", ` ${cat.padEnd(18)} `) +
|
|
2217
|
+
theme.fg("error", bar) +
|
|
2218
|
+
theme.fg("dim", ` ${count}`),
|
|
2219
|
+
1,
|
|
2220
|
+
0,
|
|
2221
|
+
),
|
|
2222
|
+
);
|
|
2223
|
+
}
|
|
2224
|
+
} else {
|
|
2225
|
+
// A sentence, not a status icon: coloured as a whole line, so it is
|
|
2226
|
+
// deliberately not routed through formatOutcomeSymbol.
|
|
2227
|
+
components.push(new Text(theme.fg("success", " No errors \u2713"), 1, 0));
|
|
2228
|
+
}
|
|
2229
|
+
components.push(new Text("", 0, 0));
|
|
2230
|
+
return components;
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
/**
|
|
2234
|
+
* Panel 6 — cost trend: the sparkline for the sampled costs plus the run count
|
|
2235
|
+
* and cost totals.
|
|
2236
|
+
*/
|
|
2237
|
+
export function renderDashboardCostTrendPanel(
|
|
2238
|
+
theme: Theme,
|
|
2239
|
+
costTrend: number[],
|
|
2240
|
+
): Component[] {
|
|
2241
|
+
const components: Component[] = [
|
|
2242
|
+
new Text(
|
|
2243
|
+
theme.fg("accent", theme.bold("Cost Trend (last 20 runs)")),
|
|
2244
|
+
1,
|
|
2245
|
+
0,
|
|
2246
|
+
),
|
|
2247
|
+
];
|
|
2248
|
+
if (costTrend.length > 0) {
|
|
2249
|
+
const sparkline = formatSparkline(costTrend);
|
|
2250
|
+
const totalCost = costTrend.reduce((s, c) => s + c, 0);
|
|
2251
|
+
components.push(
|
|
2252
|
+
new Text(
|
|
2253
|
+
theme.fg("dim", " ") + theme.fg("accent", sparkline),
|
|
2254
|
+
1,
|
|
2255
|
+
0,
|
|
2256
|
+
),
|
|
2257
|
+
);
|
|
2258
|
+
components.push(
|
|
2259
|
+
new Text(
|
|
2260
|
+
theme.fg("dim", ` ${costTrend.length} runs \u00b7 total $${totalCost.toFixed(4)} \u00b7 avg $${(totalCost / costTrend.length).toFixed(4)}`),
|
|
2261
|
+
1,
|
|
2262
|
+
0,
|
|
2263
|
+
),
|
|
2264
|
+
);
|
|
2265
|
+
} else {
|
|
2266
|
+
components.push(new Text(theme.fg("dim", " No cost data"), 1, 0));
|
|
2267
|
+
}
|
|
2268
|
+
components.push(new Text("", 0, 0));
|
|
2269
|
+
return components;
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
/**
|
|
2273
|
+
* E1 dashboard — the composer. Samples the session state once per render pass
|
|
2274
|
+
* and appends the six panels (rendered above) between the two borders; the
|
|
2275
|
+
* panel bodies themselves live in their own render functions.
|
|
2276
|
+
*/
|
|
1832
2277
|
export async function showDashboard(
|
|
1833
2278
|
ctx: ExtensionContext,
|
|
1834
2279
|
state: SessionState,
|
|
@@ -1840,187 +2285,34 @@ export async function showDashboard(
|
|
|
1840
2285
|
sweepStaleLiveSubagents(state, getAgent);
|
|
1841
2286
|
|
|
1842
2287
|
const container = new Container();
|
|
2288
|
+
const append = (components: Component[]) => {
|
|
2289
|
+
for (const component of components) container.addChild(component);
|
|
2290
|
+
};
|
|
1843
2291
|
const now = new Date();
|
|
1844
2292
|
const refreshStr = `refreshing \u00b7 ${now.toLocaleTimeString()}`;
|
|
1845
2293
|
|
|
1846
2294
|
// ---- Panel 1: Header ----
|
|
1847
2295
|
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));
|
|
2296
|
+
append(renderDashboardHeader(theme, refreshStr));
|
|
1857
2297
|
|
|
1858
2298
|
// ---- 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));
|
|
2299
|
+
append(renderDashboardActivePanel(theme, state.subagentSessions, Date.now));
|
|
1891
2300
|
|
|
1892
2301
|
// ---- Panel 3: SLA Summary ----
|
|
1893
2302
|
const allRuns = state.getRunEntries(ctx);
|
|
1894
2303
|
const recentRuns = allRuns.slice(0, state.config.slaWindowSize || 50);
|
|
1895
2304
|
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));
|
|
2305
|
+
append(renderDashboardSlaPanel(theme, metrics, recentRuns.length));
|
|
1928
2306
|
|
|
1929
2307
|
// ---- 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));
|
|
2308
|
+
append(renderDashboardRecentRunsPanel(theme, allRuns.slice(0, 10)));
|
|
1962
2309
|
|
|
1963
2310
|
// ---- 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));
|
|
2311
|
+
append(renderDashboardErrorPanel(theme, metrics?.errorCategoryBreakdown));
|
|
1992
2312
|
|
|
1993
2313
|
// ---- 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
|
-
}
|
|
2314
|
+
append(renderDashboardCostTrendPanel(theme, computeCostTrend(allRuns, 20)));
|
|
2022
2315
|
|
|
2023
|
-
container.addChild(new Text("", 0, 0));
|
|
2024
2316
|
container.addChild(new Text(theme.fg("dim", "q / esc to close"), 1, 0));
|
|
2025
2317
|
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
2026
2318
|
|
|
@@ -2069,6 +2361,8 @@ export async function showRetryMenu(
|
|
|
2069
2361
|
const err = r.errorMessage ? r.errorMessage.slice(0, 40) : interrupted ? "interrupted" : "error";
|
|
2070
2362
|
return {
|
|
2071
2363
|
value: r.id,
|
|
2364
|
+
// Uncoloured select-list label pairing ✗ with the interrupted ◌, so the
|
|
2365
|
+
// verdict symbol here is not the themed one — kept as an exception.
|
|
2072
2366
|
label: `${interrupted ? "◌" : "✗"} ${name}`,
|
|
2073
2367
|
description: `${interrupted ? "interrupted · " : ""}${model} · ${err}`,
|
|
2074
2368
|
};
|
|
@@ -2214,17 +2508,13 @@ function renderCollapsedChain(
|
|
|
2214
2508
|
theme: Theme,
|
|
2215
2509
|
): string {
|
|
2216
2510
|
const allSucceeded = details.results.every((r) => !isSubagentError(r));
|
|
2217
|
-
const icon = allSucceeded
|
|
2218
|
-
? theme.fg("success", "\u2713")
|
|
2219
|
-
: theme.fg("error", "\u2717");
|
|
2511
|
+
const icon = formatOutcomeSymbol(allSucceeded ? "success" : "failure", theme);
|
|
2220
2512
|
const stoppedEarly = details.stoppedEarly ? " (stopped early)" : "";
|
|
2221
2513
|
let text = `${icon} ${theme.fg("toolTitle", theme.bold("chain"))} ${theme.fg("muted", `${details.completedSteps}/${details.totalSteps} steps${stoppedEarly}`)}`;
|
|
2222
2514
|
|
|
2223
2515
|
for (const r of details.results) {
|
|
2224
2516
|
const isErr = isSubagentError(r);
|
|
2225
|
-
const statusIcon = isErr
|
|
2226
|
-
? theme.fg("error", "\u2717")
|
|
2227
|
-
: theme.fg("success", "\u2713");
|
|
2517
|
+
const statusIcon = formatOutcomeSymbol(isErr ? "failure" : "success", theme);
|
|
2228
2518
|
const stepNum =
|
|
2229
2519
|
r.step !== undefined ? theme.fg("muted", `${r.step}. `) : "";
|
|
2230
2520
|
const label = r.label ? theme.fg("accent", r.label) : "";
|
|
@@ -2248,17 +2538,12 @@ function renderCollapsedParallel(
|
|
|
2248
2538
|
details: ParallelDetails,
|
|
2249
2539
|
theme: Theme,
|
|
2250
2540
|
): string {
|
|
2251
|
-
const icon =
|
|
2252
|
-
details.failed === 0
|
|
2253
|
-
? theme.fg("success", "\u2713")
|
|
2254
|
-
: theme.fg("error", "\u2717");
|
|
2541
|
+
const icon = formatOutcomeSymbol(details.failed === 0 ? "success" : "failure", theme);
|
|
2255
2542
|
let text = `${icon} ${theme.fg("toolTitle", theme.bold("parallel"))} ${theme.fg("muted", `${details.succeeded}/${details.failed}/${details.results.length} total`)}`;
|
|
2256
2543
|
|
|
2257
2544
|
for (const r of details.results) {
|
|
2258
2545
|
const isErr = isSubagentError(r);
|
|
2259
|
-
const statusIcon = isErr
|
|
2260
|
-
? theme.fg("error", "\u2717")
|
|
2261
|
-
: theme.fg("success", "\u2713");
|
|
2546
|
+
const statusIcon = formatOutcomeSymbol(isErr ? "failure" : "success", theme);
|
|
2262
2547
|
const label = r.label ? theme.fg("accent", r.label) : "";
|
|
2263
2548
|
const output = getFinalOutput(r.messages);
|
|
2264
2549
|
const preview = output.split("\n").slice(0, 2).join("\n");
|
|
@@ -2302,9 +2587,7 @@ function renderExpandedChain(
|
|
|
2302
2587
|
|
|
2303
2588
|
for (const r of details.results) {
|
|
2304
2589
|
const isErr = isSubagentError(r);
|
|
2305
|
-
const statusIcon = isErr
|
|
2306
|
-
? theme.fg("error", "\u2717")
|
|
2307
|
-
: theme.fg("success", "\u2713");
|
|
2590
|
+
const statusIcon = formatOutcomeSymbol(isErr ? "failure" : "success", theme);
|
|
2308
2591
|
const stepNum = r.step !== undefined ? `${r.step}. ` : "";
|
|
2309
2592
|
const label = r.label ? `[${r.label}] ` : "";
|
|
2310
2593
|
container.addChild(
|
|
@@ -2384,9 +2667,7 @@ function renderExpandedParallel(
|
|
|
2384
2667
|
|
|
2385
2668
|
for (const r of details.results) {
|
|
2386
2669
|
const isErr = isSubagentError(r);
|
|
2387
|
-
const statusIcon = isErr
|
|
2388
|
-
? theme.fg("error", "\u2717")
|
|
2389
|
-
: theme.fg("success", "\u2713");
|
|
2670
|
+
const statusIcon = formatOutcomeSymbol(isErr ? "failure" : "success", theme);
|
|
2390
2671
|
const label = r.label ? `[${r.label}] ` : "";
|
|
2391
2672
|
container.addChild(
|
|
2392
2673
|
new Text(
|
|
@@ -2759,9 +3040,7 @@ function renderCollapsedGraph(
|
|
|
2759
3040
|
const allSucceeded = details.waves.every((w) =>
|
|
2760
3041
|
w.tasks.every((r) => !isSubagentError(r)),
|
|
2761
3042
|
);
|
|
2762
|
-
const icon = allSucceeded
|
|
2763
|
-
? theme.fg("success", "\u2713")
|
|
2764
|
-
: theme.fg("error", "\u2717");
|
|
3043
|
+
const icon = formatOutcomeSymbol(allSucceeded ? "success" : "failure", theme);
|
|
2765
3044
|
let text = `${icon} ${theme.fg("toolTitle", theme.bold("graph"))} ${theme.fg("muted", `${totalTasks} tasks in ${details.waves.length} waves`)}`;
|
|
2766
3045
|
|
|
2767
3046
|
const maxWavesToShow = 3;
|
|
@@ -2769,15 +3048,11 @@ function renderCollapsedGraph(
|
|
|
2769
3048
|
|
|
2770
3049
|
for (const wave of wavesToRender) {
|
|
2771
3050
|
const waveOk = wave.tasks.every((r) => !isSubagentError(r));
|
|
2772
|
-
const waveIcon = waveOk
|
|
2773
|
-
? theme.fg("success", "\u2713")
|
|
2774
|
-
: theme.fg("error", "\u2717");
|
|
3051
|
+
const waveIcon = formatOutcomeSymbol(waveOk ? "success" : "failure", theme);
|
|
2775
3052
|
const modeLabel = wave.parallel ? "parallel" : "serial";
|
|
2776
3053
|
const taskLabels = wave.tasks.map((r) => {
|
|
2777
3054
|
const label = r.label || r.task.slice(0, 30);
|
|
2778
|
-
const taskIcon =
|
|
2779
|
-
? theme.fg("success", "\u2713")
|
|
2780
|
-
: theme.fg("error", "\u2717");
|
|
3055
|
+
const taskIcon = formatOutcomeSymbol(isSubagentError(r) ? "failure" : "success", theme);
|
|
2781
3056
|
return `${taskIcon} ${theme.fg("dim", label)}`;
|
|
2782
3057
|
});
|
|
2783
3058
|
text += `
|
|
@@ -2816,9 +3091,7 @@ function renderExpandedGraph(
|
|
|
2816
3091
|
|
|
2817
3092
|
for (const wave of details.waves) {
|
|
2818
3093
|
const waveOk = wave.tasks.every((r) => !isSubagentError(r));
|
|
2819
|
-
const waveIcon = waveOk
|
|
2820
|
-
? theme.fg("success", "\u2713")
|
|
2821
|
-
: theme.fg("error", "\u2717");
|
|
3094
|
+
const waveIcon = formatOutcomeSymbol(waveOk ? "success" : "failure", theme);
|
|
2822
3095
|
const modeLabel = wave.parallel ? "parallel" : "serial";
|
|
2823
3096
|
container.addChild(
|
|
2824
3097
|
new Text(
|
|
@@ -2830,9 +3103,7 @@ function renderExpandedGraph(
|
|
|
2830
3103
|
|
|
2831
3104
|
for (const r of wave.tasks) {
|
|
2832
3105
|
const isErr = isSubagentError(r);
|
|
2833
|
-
const statusIcon = isErr
|
|
2834
|
-
? theme.fg("error", "\u2717")
|
|
2835
|
-
: theme.fg("success", "\u2713");
|
|
3106
|
+
const statusIcon = formatOutcomeSymbol(isErr ? "failure" : "success", theme);
|
|
2836
3107
|
const label = r.label ? `[${r.label}] ` : "";
|
|
2837
3108
|
|
|
2838
3109
|
container.addChild(
|
|
@@ -3029,7 +3300,7 @@ export function renderDelegateResult(
|
|
|
3029
3300
|
}
|
|
3030
3301
|
|
|
3031
3302
|
const isError = isSubagentError(details);
|
|
3032
|
-
const icon = isError ?
|
|
3303
|
+
const icon = formatOutcomeSymbol(isError ? "failure" : "success", theme);
|
|
3033
3304
|
const finalOutput = getFinalOutput(details.messages);
|
|
3034
3305
|
|
|
3035
3306
|
if (options.expanded) {
|