@draht/coding-agent 2026.10.4-3 → 2026.10.8-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +32 -6
- package/dist/bundle/chunks/anthropic.js +1 -1
- package/dist/bundle/chunks/{chunk-JTLUBTZT.js → chunk-6QIFWMDF.js} +1 -1
- package/dist/bundle/chunks/{chunk-AFL4IDSI.js → chunk-AHGUOQPH.js} +2 -2
- package/dist/bundle/chunks/{chunk-VPYAVQLP.js → chunk-BOGY4QVF.js} +4 -4
- package/dist/bundle/chunks/chunk-GD2WVXWT.js +65 -0
- package/dist/bundle/chunks/{chunk-3HF756LN.js → chunk-KJJJSTND.js} +292 -153
- package/dist/bundle/chunks/chunk-PGJAHC3R.js +107 -0
- package/dist/bundle/chunks/chunk-QVFELZW2.js +312 -0
- package/dist/bundle/chunks/{chunk-V5HG6S2T.js → chunk-QVTLBSTH.js} +1 -1
- package/dist/bundle/chunks/{chunk-A4OX5CPR.js → chunk-U6LDZZGM.js} +1 -1
- package/dist/bundle/chunks/{chunk-XO3IECI5.js → chunk-VQOV5VFH.js} +1 -1
- package/dist/bundle/chunks/{cli-L74YA5GF.js → cli-O6OWCY7N.js} +1 -1
- package/dist/bundle/chunks/execute-4JU5WQXP.js +18 -0
- package/dist/bundle/chunks/google-antigravity.js +1 -1
- package/dist/bundle/chunks/google-gemini-cli.js +1 -1
- package/dist/bundle/chunks/openai-chatgpt.js +1 -1
- package/dist/bundle/chunks/openai-codex.js +1 -1
- package/dist/bundle/chunks/openrouter.js +1 -1
- package/dist/bundle/chunks/radius.js +1 -1
- package/dist/bundle/chunks/{runtime-RYUR6LRB.js → runtime-FIGQHW75.js} +1 -1
- package/dist/bundle/chunks/runtime-TJ3EAMJK.js +3 -0
- package/dist/bundle/chunks/{settings-manager-CHEMMAGQ.js → settings-manager-HC5RR36T.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-UIGTRGHQ.js +2 -0
- package/dist/bundle/chunks/xai.js +1 -1
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.js +3 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/core/builtins/duet.d.ts +5 -2
- package/dist/core/builtins/duet.d.ts.map +1 -1
- package/dist/core/builtins/duet.js +65 -27
- package/dist/core/builtins/duet.js.map +1 -1
- package/dist/core/builtins/index.d.ts.map +1 -1
- package/dist/core/builtins/index.js +2 -0
- package/dist/core/builtins/index.js.map +1 -1
- package/dist/core/builtins/polyphase.d.ts +15 -0
- package/dist/core/builtins/polyphase.d.ts.map +1 -0
- package/dist/core/builtins/polyphase.js +196 -0
- package/dist/core/builtins/polyphase.js.map +1 -0
- package/dist/core/builtins/subagent.d.ts +44 -34
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +827 -560
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/extensions/types.d.ts +17 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +30 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-resolver.js +4 -4
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +4 -1
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/polyphase/approval.d.ts +35 -0
- package/dist/core/polyphase/approval.d.ts.map +1 -0
- package/dist/core/polyphase/approval.js +184 -0
- package/dist/core/polyphase/approval.js.map +1 -0
- package/dist/core/polyphase/child-events.d.ts +107 -0
- package/dist/core/polyphase/child-events.d.ts.map +1 -0
- package/dist/core/polyphase/child-events.js +862 -0
- package/dist/core/polyphase/child-events.js.map +1 -0
- package/dist/core/polyphase/child-process.d.ts +65 -0
- package/dist/core/polyphase/child-process.d.ts.map +1 -0
- package/dist/core/polyphase/child-process.js +361 -0
- package/dist/core/polyphase/child-process.js.map +1 -0
- package/dist/core/polyphase/commands.d.ts +44 -0
- package/dist/core/polyphase/commands.d.ts.map +1 -0
- package/dist/core/polyphase/commands.js +244 -0
- package/dist/core/polyphase/commands.js.map +1 -0
- package/dist/core/polyphase/details.d.ts +40 -0
- package/dist/core/polyphase/details.d.ts.map +1 -0
- package/dist/core/polyphase/details.js +538 -0
- package/dist/core/polyphase/details.js.map +1 -0
- package/dist/core/polyphase/emitter.d.ts +20 -0
- package/dist/core/polyphase/emitter.d.ts.map +1 -0
- package/dist/core/polyphase/emitter.js +90 -0
- package/dist/core/polyphase/emitter.js.map +1 -0
- package/dist/core/polyphase/jsonl-reader.d.ts +31 -0
- package/dist/core/polyphase/jsonl-reader.d.ts.map +1 -0
- package/dist/core/polyphase/jsonl-reader.js +161 -0
- package/dist/core/polyphase/jsonl-reader.js.map +1 -0
- package/dist/core/polyphase/keyword.d.ts +27 -0
- package/dist/core/polyphase/keyword.d.ts.map +1 -0
- package/dist/core/polyphase/keyword.js +97 -0
- package/dist/core/polyphase/keyword.js.map +1 -0
- package/dist/core/polyphase/limiter.d.ts +38 -0
- package/dist/core/polyphase/limiter.d.ts.map +1 -0
- package/dist/core/polyphase/limiter.js +129 -0
- package/dist/core/polyphase/limiter.js.map +1 -0
- package/dist/core/polyphase/model-selection.d.ts +35 -0
- package/dist/core/polyphase/model-selection.d.ts.map +1 -0
- package/dist/core/polyphase/model-selection.js +72 -0
- package/dist/core/polyphase/model-selection.js.map +1 -0
- package/dist/core/polyphase/render/format.d.ts +52 -0
- package/dist/core/polyphase/render/format.d.ts.map +1 -0
- package/dist/core/polyphase/render/format.js +169 -0
- package/dist/core/polyphase/render/format.js.map +1 -0
- package/dist/core/polyphase/render/renderers.d.ts +63 -0
- package/dist/core/polyphase/render/renderers.d.ts.map +1 -0
- package/dist/core/polyphase/render/renderers.js +277 -0
- package/dist/core/polyphase/render/renderers.js.map +1 -0
- package/dist/core/polyphase/render/run-block.d.ts +45 -0
- package/dist/core/polyphase/render/run-block.d.ts.map +1 -0
- package/dist/core/polyphase/render/run-block.js +843 -0
- package/dist/core/polyphase/render/run-block.js.map +1 -0
- package/dist/core/polyphase/render/snapshot.d.ts +106 -0
- package/dist/core/polyphase/render/snapshot.d.ts.map +1 -0
- package/dist/core/polyphase/render/snapshot.js +292 -0
- package/dist/core/polyphase/render/snapshot.js.map +1 -0
- package/dist/core/polyphase/result-text.d.ts +41 -0
- package/dist/core/polyphase/result-text.d.ts.map +1 -0
- package/dist/core/polyphase/result-text.js +326 -0
- package/dist/core/polyphase/result-text.js.map +1 -0
- package/dist/core/polyphase/session.d.ts +33 -0
- package/dist/core/polyphase/session.d.ts.map +1 -0
- package/dist/core/polyphase/session.js +106 -0
- package/dist/core/polyphase/session.js.map +1 -0
- package/dist/core/polyphase/settings.d.ts +18 -0
- package/dist/core/polyphase/settings.d.ts.map +1 -0
- package/dist/core/polyphase/settings.js +93 -0
- package/dist/core/polyphase/settings.js.map +1 -0
- package/dist/core/polyphase/store.d.ts +197 -0
- package/dist/core/polyphase/store.d.ts.map +1 -0
- package/dist/core/polyphase/store.js +558 -0
- package/dist/core/polyphase/store.js.map +1 -0
- package/dist/core/polyphase/types.d.ts +371 -0
- package/dist/core/polyphase/types.d.ts.map +1 -0
- package/dist/core/polyphase/types.js +36 -0
- package/dist/core/polyphase/types.js.map +1 -0
- package/dist/core/polyphase/ui/controller.d.ts +28 -0
- package/dist/core/polyphase/ui/controller.d.ts.map +1 -0
- package/dist/core/polyphase/ui/controller.js +150 -0
- package/dist/core/polyphase/ui/controller.js.map +1 -0
- package/dist/core/polyphase/ui/dock.d.ts +27 -0
- package/dist/core/polyphase/ui/dock.d.ts.map +1 -0
- package/dist/core/polyphase/ui/dock.js +121 -0
- package/dist/core/polyphase/ui/dock.js.map +1 -0
- package/dist/core/polyphase/ui/inspector.d.ts +117 -0
- package/dist/core/polyphase/ui/inspector.d.ts.map +1 -0
- package/dist/core/polyphase/ui/inspector.js +1016 -0
- package/dist/core/polyphase/ui/inspector.js.map +1 -0
- package/dist/core/polyphase/ui/transcript-layout.d.ts +55 -0
- package/dist/core/polyphase/ui/transcript-layout.d.ts.map +1 -0
- package/dist/core/polyphase/ui/transcript-layout.js +210 -0
- package/dist/core/polyphase/ui/transcript-layout.js.map +1 -0
- package/dist/core/polyphase/update-pump.d.ts +18 -0
- package/dist/core/polyphase/update-pump.d.ts.map +1 -0
- package/dist/core/polyphase/update-pump.js +132 -0
- package/dist/core/polyphase/update-pump.js.map +1 -0
- package/dist/core/polyphase/workflow/agent-host.d.ts +26 -0
- package/dist/core/polyphase/workflow/agent-host.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/agent-host.js +187 -0
- package/dist/core/polyphase/workflow/agent-host.js.map +1 -0
- package/dist/core/polyphase/workflow/guidance.d.ts +19 -0
- package/dist/core/polyphase/workflow/guidance.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/guidance.js +119 -0
- package/dist/core/polyphase/workflow/guidance.js.map +1 -0
- package/dist/core/polyphase/workflow/launch.d.ts +41 -0
- package/dist/core/polyphase/workflow/launch.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/launch.js +173 -0
- package/dist/core/polyphase/workflow/launch.js.map +1 -0
- package/dist/core/polyphase/workflow/meta.d.ts +43 -0
- package/dist/core/polyphase/workflow/meta.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/meta.js +529 -0
- package/dist/core/polyphase/workflow/meta.js.map +1 -0
- package/dist/core/polyphase/workflow/prelude.d.ts +24 -0
- package/dist/core/polyphase/workflow/prelude.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/prelude.js +93 -0
- package/dist/core/polyphase/workflow/prelude.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.d.ts +79 -0
- package/dist/core/polyphase/workflow/runtime.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/runtime.js +217 -0
- package/dist/core/polyphase/workflow/runtime.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.lazy.d.ts +3 -0
- package/dist/core/polyphase/workflow/runtime.lazy.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/runtime.lazy.js +3 -0
- package/dist/core/polyphase/workflow/runtime.lazy.js.map +1 -0
- package/dist/core/polyphase/workflow/saved.d.ts +55 -0
- package/dist/core/polyphase/workflow/saved.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/saved.js +299 -0
- package/dist/core/polyphase/workflow/saved.js.map +1 -0
- package/dist/core/polyphase/workflow/structured-output.d.ts +22 -0
- package/dist/core/polyphase/workflow/structured-output.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/structured-output.js +66 -0
- package/dist/core/polyphase/workflow/structured-output.js.map +1 -0
- package/dist/core/polyphase/workflow/tool.d.ts +24 -0
- package/dist/core/polyphase/workflow/tool.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/tool.js +139 -0
- package/dist/core/polyphase/workflow/tool.js.map +1 -0
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +27 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/socket-server/permission-relay.js +4 -0
- package/dist/core/socket-server/permission-relay.js.map +1 -1
- package/dist/core/trust-manager.d.ts +3 -2
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +5 -2
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/experimental/micro/runtime.js +1 -1
- package/dist/experimental/micro/runtime.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +18 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +11 -2
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +9 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/prompts/commands/orchestrate.md +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +7 -1
- package/dist/utils/shell.js.map +1 -1
- package/docs/docs.json +4 -0
- package/docs/duet.md +3 -3
- package/docs/environment-variables.md +11 -0
- package/docs/json.md +7 -0
- package/docs/keybindings.md +20 -0
- package/docs/polyphase.md +391 -0
- package/docs/rpc-commands.md +9 -9
- package/docs/settings.md +12 -0
- package/docs/virtual-models.md +3 -3
- package/examples/extensions/preset.ts +3 -3
- package/examples/extensions/subagent/README.md +1 -1
- package/examples/extensions/subagent/agents/planner.md +1 -1
- package/examples/extensions/subagent/agents/reviewer.md +1 -1
- package/examples/extensions/subagent/agents/scout.md +1 -1
- package/examples/extensions/subagent/agents/worker.md +1 -1
- package/examples/extensions/summarize.ts +3 -3
- package/examples/sdk/02-custom-model.ts +1 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/package.json +10 -10
- package/prompts/commands/orchestrate.md +1 -1
- package/dist/bundle/chunks/chunk-SPZUYYP5.js +0 -170
- package/dist/bundle/chunks/execute-EMOVNTD6.js +0 -328
- package/dist/bundle/chunks/virtual-modules-OC56AAJ7.js +0 -2
|
@@ -0,0 +1,1016 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `PolyphaseInspector`: the `alt+a` popup overlay listing runs and following an agent's live
|
|
3
|
+
* transcript. See DESIGN.md §12.1-12.6, §12.8.
|
|
4
|
+
*/
|
|
5
|
+
import { visibleWidth, wrapTextWithAnsi } from "@draht/tui";
|
|
6
|
+
import { combinedKeyHint, keyHint } from "../../../modes/interactive/components/keybinding-hints.js";
|
|
7
|
+
import { columns, fitLine, formatCost, formatDuration, formatModelLabel, formatTokens, oneLine, padToWidth, statusGlyph, } from "../render/format.js";
|
|
8
|
+
import { sanitizeChildText, sanitizeSnapshot } from "../render/run-block.js";
|
|
9
|
+
import { snapshotFromDetails, snapshotFromRun } from "../render/snapshot.js";
|
|
10
|
+
import { sanitizeForDisplay, TranscriptLineCache, tailWindowOf, } from "./transcript-layout.js";
|
|
11
|
+
const PAGE_SIZE = 10;
|
|
12
|
+
const SPLIT_MIN_WIDTH = 120;
|
|
13
|
+
const SPLIT_LEFT_WIDTH = 40;
|
|
14
|
+
function clamp(n, min, max) {
|
|
15
|
+
return Math.min(max, Math.max(min, n));
|
|
16
|
+
}
|
|
17
|
+
/** Slices `lines` to `height` rows centred on `pivot`, replacing the first/last visible row with
|
|
18
|
+
* a muted "N more" marker when the window hides rows above/below. The window is always centred on
|
|
19
|
+
* `pivot` (clamped only at the list's edges), so `pivot` lands on an edge row of the window only
|
|
20
|
+
* when that edge has nothing hidden past it — the marker never overwrites the selected row. */
|
|
21
|
+
function windowAround(lines, height, pivot, theme) {
|
|
22
|
+
if (lines.length <= height)
|
|
23
|
+
return lines;
|
|
24
|
+
const start = Math.max(0, Math.min(pivot - Math.floor(height / 2), lines.length - height));
|
|
25
|
+
const end = start + height;
|
|
26
|
+
const windowed = lines.slice(start, end);
|
|
27
|
+
if (height < 2)
|
|
28
|
+
return windowed;
|
|
29
|
+
const pivotOffset = pivot - start;
|
|
30
|
+
const marked = windowed.slice();
|
|
31
|
+
if (start > 0 && pivotOffset !== 0) {
|
|
32
|
+
marked[0] = theme.fg("muted", `↑ ${start} more`);
|
|
33
|
+
}
|
|
34
|
+
if (end < lines.length && pivotOffset !== marked.length - 1) {
|
|
35
|
+
marked[marked.length - 1] = theme.fg("muted", `↓ ${lines.length - end} more`);
|
|
36
|
+
}
|
|
37
|
+
return marked;
|
|
38
|
+
}
|
|
39
|
+
function padLines(lines, height) {
|
|
40
|
+
if (lines.length >= height)
|
|
41
|
+
return lines.slice(0, height);
|
|
42
|
+
return [...lines, ...Array.from({ length: height - lines.length }, () => "")];
|
|
43
|
+
}
|
|
44
|
+
/** Resolves a pause anchor back to an absolute window-end line (exclusive), against the item line
|
|
45
|
+
* ranges from the most recent render. If the anchored item was evicted, clamps to just past the
|
|
46
|
+
* first still-kept item instead of drifting the view forward by the wrong amount. */
|
|
47
|
+
function resolvePauseEndLine(anchor, ranges, totalLines) {
|
|
48
|
+
const range = ranges.find((r) => r.seq === anchor.seq);
|
|
49
|
+
if (range)
|
|
50
|
+
return clamp(range.start + anchor.lineInItem + 1, 0, totalLines);
|
|
51
|
+
const first = ranges[0];
|
|
52
|
+
return first ? clamp(first.start + 1, 0, totalLines) : 0;
|
|
53
|
+
}
|
|
54
|
+
/** Converts an absolute window-end line (exclusive) into a pause anchor on whichever item renders
|
|
55
|
+
* that line, so the anchor survives evictions that shift line numbers. */
|
|
56
|
+
function anchorAtEndLine(endLine, ranges) {
|
|
57
|
+
const lastVisibleLine = endLine - 1;
|
|
58
|
+
for (const range of ranges) {
|
|
59
|
+
if (lastVisibleLine >= range.start && lastVisibleLine < range.end) {
|
|
60
|
+
return { seq: range.seq, lineInItem: lastVisibleLine - range.start };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const last = ranges[ranges.length - 1];
|
|
64
|
+
return last ? { seq: last.seq, lineInItem: Math.max(0, last.end - last.start - 1) } : undefined;
|
|
65
|
+
}
|
|
66
|
+
/** Truncates the title (never the right segment or the closing corner) so the border always stays
|
|
67
|
+
* closed, instead of handing the whole assembled string to `fitLine` and letting it cut off
|
|
68
|
+
* whichever happens to sit at the end. */
|
|
69
|
+
function borderTop(title, right, width) {
|
|
70
|
+
const inner = Math.max(0, width - 2);
|
|
71
|
+
let rightSeg = right ? ` ${right} ` : "";
|
|
72
|
+
let rightWidth = visibleWidth(rightSeg);
|
|
73
|
+
if (rightWidth > inner) {
|
|
74
|
+
rightSeg = "";
|
|
75
|
+
rightWidth = 0;
|
|
76
|
+
}
|
|
77
|
+
const minDashes = 1;
|
|
78
|
+
const titleBudget = Math.max(0, inner - rightWidth - minDashes);
|
|
79
|
+
const titleSeg = fitLine(` ${title} `, titleBudget);
|
|
80
|
+
const dashes = Math.max(0, inner - visibleWidth(titleSeg) - rightWidth);
|
|
81
|
+
return `┌${titleSeg}${"─".repeat(dashes)}${rightSeg}┐`;
|
|
82
|
+
}
|
|
83
|
+
function borderBottom(width) {
|
|
84
|
+
return fitLine(`└${"─".repeat(Math.max(0, width - 2))}┘`, width);
|
|
85
|
+
}
|
|
86
|
+
function sideLine(content, width) {
|
|
87
|
+
const inner = Math.max(0, width - 4);
|
|
88
|
+
return fitLine(`│ ${padToWidth(content, inner)} │`, width);
|
|
89
|
+
}
|
|
90
|
+
function runsRowKey(row) {
|
|
91
|
+
if (row.kind === "saved")
|
|
92
|
+
return `saved:${row.saved?.name ?? ""}`;
|
|
93
|
+
return `run:${row.runId ?? ""}`;
|
|
94
|
+
}
|
|
95
|
+
function groupLabel(kind) {
|
|
96
|
+
switch (kind) {
|
|
97
|
+
case "live":
|
|
98
|
+
return "Live";
|
|
99
|
+
case "earlier":
|
|
100
|
+
return "Earlier in this session";
|
|
101
|
+
case "saved":
|
|
102
|
+
return "Saved workflows";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Drops a trailing agent-count suffix (e.g. "subagent parallel · 2 agents"): `runSubtitleText`
|
|
106
|
+
* is the single place that shows the count, so the title must not repeat it. */
|
|
107
|
+
const TRAILING_AGENT_COUNT = / · \d+ agents?$/;
|
|
108
|
+
/** The phase marker is only meaningful while the run is still progressing through phases; a
|
|
109
|
+
* finished or cancelled run has no "current" phase left, so showing one would misread as still
|
|
110
|
+
* running. */
|
|
111
|
+
function isCurrentlyPhased(status) {
|
|
112
|
+
return status === "running";
|
|
113
|
+
}
|
|
114
|
+
function runTitleText(snapshot) {
|
|
115
|
+
if (snapshot.kind === "workflow")
|
|
116
|
+
return `workflow ${snapshot.workflow?.name ?? snapshot.title}`;
|
|
117
|
+
if (snapshot.kind === "duet")
|
|
118
|
+
return `duet · ${snapshot.title}`;
|
|
119
|
+
return snapshot.title.replace(TRAILING_AGENT_COUNT, "");
|
|
120
|
+
}
|
|
121
|
+
function runSubtitleText(snapshot) {
|
|
122
|
+
if (snapshot.kind === "workflow") {
|
|
123
|
+
const phase = isCurrentlyPhased(snapshot.status) && snapshot.currentPhase !== undefined
|
|
124
|
+
? snapshot.phases[snapshot.currentPhase]
|
|
125
|
+
: undefined;
|
|
126
|
+
if (phase)
|
|
127
|
+
return `▸ ${phase.title}`;
|
|
128
|
+
const n = snapshot.phases.length;
|
|
129
|
+
return n > 0 ? `${n} phase${n === 1 ? "" : "s"}` : "";
|
|
130
|
+
}
|
|
131
|
+
const n = snapshot.agents.length;
|
|
132
|
+
return `${n} agent${n === 1 ? "" : "s"}`;
|
|
133
|
+
}
|
|
134
|
+
/** `› ` (or ` `) + glyph, always a fixed-width cell outside the title's flex cell: the cursor and
|
|
135
|
+
* status glyph must stay visible even when nothing else does. `columns()`'s own 1-column gap
|
|
136
|
+
* supplies the separator space before the title, matching `› ● label` elsewhere in this file. */
|
|
137
|
+
const RUNS_ROW_CURSOR_WIDTH = 3;
|
|
138
|
+
function savedWorkflowSourceLabel(source) {
|
|
139
|
+
return source === "project" ? "proj" : "user";
|
|
140
|
+
}
|
|
141
|
+
/** Drops or shrinks the runs-view row's optional columns as `width` decreases, in order of least
|
|
142
|
+
* useful first (tokens, then cost, then the subtitle, then counts and duration), so the title (the
|
|
143
|
+
* flex cell) keeps a usable share of the row instead of being squeezed to nothing by fixed columns
|
|
144
|
+
* that no longer fit. */
|
|
145
|
+
function runsRowOptionalWidths(width) {
|
|
146
|
+
return {
|
|
147
|
+
subtitle: width >= 80 ? 16 : width >= 60 ? 10 : 0,
|
|
148
|
+
counts: width >= 56 ? 10 : 0,
|
|
149
|
+
duration: width >= 50 ? 7 : 0,
|
|
150
|
+
tokens: width >= 70 ? 6 : 0,
|
|
151
|
+
cost: width >= 60 ? 7 : 0,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/** The agent detail header's right side (§12.2: `◐ thinking 0:41`) shows only the current activity
|
|
155
|
+
* keyword, not `row.now`'s full content: `row.now` for a thinking/writing agent is `"thinking · <the
|
|
156
|
+
* actual text>"`, and showing that verbatim in the border would leak hidden-thinking content past the
|
|
157
|
+
* `app.thinking.toggle` gate that otherwise hides it in the transcript below. */
|
|
158
|
+
function headerActivityText(row) {
|
|
159
|
+
const now = row.now ? oneLine(sanitizeForDisplay(row.now)) : undefined;
|
|
160
|
+
if (!now)
|
|
161
|
+
return row.status;
|
|
162
|
+
const separator = now.indexOf(" · ");
|
|
163
|
+
return separator === -1 ? now : now.slice(0, separator);
|
|
164
|
+
}
|
|
165
|
+
/** Mirrors `headerActivityText`'s thinking-keyword cut: the run view's agent list and the split
|
|
166
|
+
* view's left pane must not leak hidden thinking content into the "now" column either (§12.2 shows
|
|
167
|
+
* just `thinking` there), even though the same column shows the activity in full once thinking is
|
|
168
|
+
* visible. */
|
|
169
|
+
function agentRowRightText(row, showThinking) {
|
|
170
|
+
if (row.now) {
|
|
171
|
+
const now = oneLine(sanitizeForDisplay(row.now));
|
|
172
|
+
// "thinking" is the only `computeNowLine()` activity word that can be followed by child-written
|
|
173
|
+
// text; checking the prefix (not the full `"thinking · "` separator) also catches the edge case
|
|
174
|
+
// where the thinking block is still empty and `oneLine()` has trimmed the trailing separator.
|
|
175
|
+
if (!showThinking && now.startsWith("thinking"))
|
|
176
|
+
return "thinking";
|
|
177
|
+
return now;
|
|
178
|
+
}
|
|
179
|
+
if (row.statusLine)
|
|
180
|
+
return oneLine(sanitizeForDisplay(row.statusLine));
|
|
181
|
+
if (row.error)
|
|
182
|
+
return oneLine(sanitizeForDisplay(row.error));
|
|
183
|
+
switch (row.status) {
|
|
184
|
+
case "queued":
|
|
185
|
+
return "queued";
|
|
186
|
+
case "pending":
|
|
187
|
+
return row.step !== undefined && row.step > 1 ? `waits for step ${row.step - 1}` : "not run";
|
|
188
|
+
case "skipped":
|
|
189
|
+
return "not run";
|
|
190
|
+
case "cancelled":
|
|
191
|
+
return "cancelled";
|
|
192
|
+
case "done":
|
|
193
|
+
// A finished agent with no `now` and no `STATUS:` line still has output worth showing
|
|
194
|
+
// (§11.3's tool-row fallback does the same): the first line beats a blank column.
|
|
195
|
+
return row.output ? oneLine(sanitizeForDisplay(row.output)) : "";
|
|
196
|
+
default:
|
|
197
|
+
return "";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const COUNT_ORDER = ["running", "done", "failed", "cancelled", "queued", "pending", "skipped"];
|
|
201
|
+
function formatCounts(theme, now, counts) {
|
|
202
|
+
const parts = [];
|
|
203
|
+
for (const status of COUNT_ORDER) {
|
|
204
|
+
const n = counts[status];
|
|
205
|
+
if (n > 0)
|
|
206
|
+
parts.push(`${statusGlyph(status, theme, { now, animate: false })}${n}`);
|
|
207
|
+
}
|
|
208
|
+
return parts.join(" ");
|
|
209
|
+
}
|
|
210
|
+
function isFinishedAgentStatus(status) {
|
|
211
|
+
return status === "done" || status === "failed" || status === "cancelled" || status === "skipped";
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The `alt+a` popup. `render()` recomputes the live runs-view list, the current run's agent list
|
|
215
|
+
* and the selected agent's transcript window on every call, since those come straight from the
|
|
216
|
+
* live store; nothing here owns a timer. Dirtiness (when to re-render at all) is the caller's job,
|
|
217
|
+
* driven by `session.store`'s flush notifications.
|
|
218
|
+
*/
|
|
219
|
+
export class PolyphaseInspector {
|
|
220
|
+
focused = false;
|
|
221
|
+
deps;
|
|
222
|
+
transcriptCache;
|
|
223
|
+
unsubscribe;
|
|
224
|
+
mode = "runs";
|
|
225
|
+
currentRunId;
|
|
226
|
+
currentAgentIndex;
|
|
227
|
+
runsRows = [];
|
|
228
|
+
runsSelection = 0;
|
|
229
|
+
runsSelectionKey;
|
|
230
|
+
runSelection = 0;
|
|
231
|
+
following = true;
|
|
232
|
+
/** Anchors the paused window to an item (`seq`) and a line within it, not an absolute line index:
|
|
233
|
+
* the transcript keeps at most `maxItems`, so a paused run that keeps producing output evicts
|
|
234
|
+
* older items and shifts every absolute line index after them. Resolved back to an absolute line
|
|
235
|
+
* on each render via `resolvePauseEndLine`. See `renderAgentDetailBody`. */
|
|
236
|
+
pauseAnchor;
|
|
237
|
+
lastTranscriptTotalLines;
|
|
238
|
+
lastTranscriptRanges = [];
|
|
239
|
+
lastDetailBodyHeight;
|
|
240
|
+
lastRenderWidth = 0;
|
|
241
|
+
showThinking;
|
|
242
|
+
showToolPreviews = false;
|
|
243
|
+
armed;
|
|
244
|
+
footerNotice;
|
|
245
|
+
constructor(deps) {
|
|
246
|
+
this.deps = deps;
|
|
247
|
+
this.showThinking = deps.showThinking;
|
|
248
|
+
this.transcriptCache = new TranscriptLineCache(deps.theme);
|
|
249
|
+
this.resolveInitialView();
|
|
250
|
+
this.unsubscribe = deps.session.store.subscribe((change) => {
|
|
251
|
+
if (change.type === "disposed") {
|
|
252
|
+
this.deps.close();
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
this.deps.tui.requestRender();
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
handleInput(data) {
|
|
259
|
+
if (this.mode === "runs") {
|
|
260
|
+
this.runsRows = this.buildRunsRows();
|
|
261
|
+
this.runsSelection = this.resolveRunsSelectionIndex(this.runsRows);
|
|
262
|
+
}
|
|
263
|
+
const kb = this.deps.keybindings;
|
|
264
|
+
if (kb.matches(data, "app.polyphase.inspector")) {
|
|
265
|
+
this.deps.close();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (kb.matches(data, "app.polyphase.cancelAgent")) {
|
|
269
|
+
this.handleCancelKey("cancelAgent");
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (kb.matches(data, "app.polyphase.cancelRun")) {
|
|
273
|
+
this.handleCancelKey("cancelRun");
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
this.armed = undefined;
|
|
277
|
+
this.footerNotice = undefined;
|
|
278
|
+
if (kb.matches(data, "tui.select.cancel")) {
|
|
279
|
+
this.goBack();
|
|
280
|
+
}
|
|
281
|
+
else if (kb.matches(data, "app.thinking.toggle")) {
|
|
282
|
+
this.showThinking = !this.showThinking;
|
|
283
|
+
}
|
|
284
|
+
else if (kb.matches(data, "app.tools.expand")) {
|
|
285
|
+
this.showToolPreviews = !this.showToolPreviews;
|
|
286
|
+
}
|
|
287
|
+
else if (kb.matches(data, "app.polyphase.follow")) {
|
|
288
|
+
this.toggleFollow();
|
|
289
|
+
}
|
|
290
|
+
else if (kb.matches(data, "app.polyphase.nextAgent")) {
|
|
291
|
+
this.cycleAgent(1);
|
|
292
|
+
}
|
|
293
|
+
else if (kb.matches(data, "app.polyphase.previousAgent")) {
|
|
294
|
+
this.cycleAgent(-1);
|
|
295
|
+
}
|
|
296
|
+
else if (kb.matches(data, "tui.select.up")) {
|
|
297
|
+
this.moveSelection(-1);
|
|
298
|
+
}
|
|
299
|
+
else if (kb.matches(data, "tui.select.down")) {
|
|
300
|
+
this.moveSelection(1);
|
|
301
|
+
}
|
|
302
|
+
else if (kb.matches(data, "tui.select.pageUp")) {
|
|
303
|
+
this.handlePage(-1);
|
|
304
|
+
}
|
|
305
|
+
else if (kb.matches(data, "tui.select.pageDown")) {
|
|
306
|
+
this.handlePage(1);
|
|
307
|
+
}
|
|
308
|
+
else if (kb.matches(data, "tui.select.confirm")) {
|
|
309
|
+
this.confirmSelection();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
render(width) {
|
|
313
|
+
this.lastRenderWidth = width;
|
|
314
|
+
const terminal = this.deps.tui.terminal;
|
|
315
|
+
if (width < 40 || terminal.rows < 10) {
|
|
316
|
+
return [fitLine("terminal too small for the agent inspector", width)];
|
|
317
|
+
}
|
|
318
|
+
const height = Math.max(8, terminal.rows - 2);
|
|
319
|
+
const bodyHeight = Math.max(1, height - 2);
|
|
320
|
+
const innerWidth = Math.max(1, width - 4);
|
|
321
|
+
let topTitle;
|
|
322
|
+
let topRight;
|
|
323
|
+
let bodyLines;
|
|
324
|
+
if (this.mode === "runs") {
|
|
325
|
+
this.runsRows = this.buildRunsRows();
|
|
326
|
+
this.runsSelection = this.resolveRunsSelectionIndex(this.runsRows);
|
|
327
|
+
// Tracks the selection by identity from the very first render, not only once the user has
|
|
328
|
+
// pressed an arrow key, so a live run inserted above the selection between renders cannot
|
|
329
|
+
// change what a subsequent `enter` opens.
|
|
330
|
+
if (this.runsSelectionKey === undefined) {
|
|
331
|
+
const row = this.runsRows[this.runsSelection];
|
|
332
|
+
this.runsSelectionKey = row ? runsRowKey(row) : undefined;
|
|
333
|
+
}
|
|
334
|
+
const liveCount = this.runsRows.filter((row) => row.kind === "live").length;
|
|
335
|
+
const earlierCount = this.runsRows.filter((row) => row.kind === "earlier").length;
|
|
336
|
+
const limiter = this.deps.session.limiter.stats();
|
|
337
|
+
topTitle = `polyphase · ${liveCount} live · ${earlierCount} earlier · slots ${limiter.active}/${limiter.capacity}`;
|
|
338
|
+
topRight = keyHint("app.polyphase.inspector", "close");
|
|
339
|
+
bodyLines = this.renderRunsBody(innerWidth, bodyHeight);
|
|
340
|
+
}
|
|
341
|
+
else if (this.mode === "run") {
|
|
342
|
+
// Built once here and threaded through, instead of each of the header and the body methods
|
|
343
|
+
// calling `currentRunSnapshot()`/`currentRunAgents()` again: `snapshotFromRun` runs a regex
|
|
344
|
+
// over every agent's output and hashes the whole details object, so repeating it several
|
|
345
|
+
// times per render on every pump flush is wasted work.
|
|
346
|
+
const snapshot = this.currentRunSnapshot();
|
|
347
|
+
const rows = this.sortedAgentsOf(snapshot);
|
|
348
|
+
topTitle = snapshot ? this.runTitleForHeader(snapshot) : "run";
|
|
349
|
+
topRight = snapshot ? this.runHeaderRight(snapshot) : "";
|
|
350
|
+
bodyLines =
|
|
351
|
+
width >= SPLIT_MIN_WIDTH
|
|
352
|
+
? this.renderSplitBody(innerWidth, bodyHeight, rows)
|
|
353
|
+
: this.renderRunBody(innerWidth, bodyHeight, snapshot, rows);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
const snapshot = this.currentRunSnapshot();
|
|
357
|
+
const rows = this.sortedAgentsOf(snapshot);
|
|
358
|
+
const row = rows.find((r) => r.i === this.currentAgentIndex);
|
|
359
|
+
const phaseTitle = row?.phase !== undefined ? snapshot?.phases[row.phase]?.title : undefined;
|
|
360
|
+
topTitle = row ? `${row.label} · ${row.agentType}${phaseTitle ? ` · ${phaseTitle}` : ""}` : "agent";
|
|
361
|
+
topRight = row
|
|
362
|
+
? `${statusGlyph(row.status, this.deps.theme, { now: this.now(), animate: false })} ${headerActivityText(row)}${row.elapsedMs === undefined ? "" : ` ${formatDuration(row.elapsedMs)}`}`
|
|
363
|
+
: "";
|
|
364
|
+
bodyLines = this.renderAgentDetailBody(this.currentAgentIndex, innerWidth, bodyHeight, rows);
|
|
365
|
+
}
|
|
366
|
+
const padded = padLines(bodyLines, bodyHeight);
|
|
367
|
+
return [
|
|
368
|
+
borderTop(topTitle, topRight, width),
|
|
369
|
+
...padded.map((line) => sideLine(line, width)),
|
|
370
|
+
borderBottom(width),
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
invalidate() { }
|
|
374
|
+
dispose() {
|
|
375
|
+
this.unsubscribe();
|
|
376
|
+
}
|
|
377
|
+
now() {
|
|
378
|
+
return Date.now();
|
|
379
|
+
}
|
|
380
|
+
// ── Navigation ──────────────────────────────────────────────────────────
|
|
381
|
+
resolveInitialView() {
|
|
382
|
+
const initial = this.deps.initial;
|
|
383
|
+
if (initial.view === "runs") {
|
|
384
|
+
this.mode = "runs";
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (initial.view === "run") {
|
|
388
|
+
this.mode = "run";
|
|
389
|
+
this.currentRunId = initial.runId;
|
|
390
|
+
this.selectFirstActiveAgentForCurrentRun();
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (initial.view === "agent") {
|
|
394
|
+
this.mode = "agent";
|
|
395
|
+
this.currentRunId = initial.runId;
|
|
396
|
+
this.currentAgentIndex = initial.agentIndex;
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const liveRuns = this.deps.session.store.runs().filter((run) => run.status === "running");
|
|
400
|
+
if (liveRuns.length === 1) {
|
|
401
|
+
this.mode = "run";
|
|
402
|
+
this.currentRunId = liveRuns[0]?.id;
|
|
403
|
+
this.selectFirstActiveAgentForCurrentRun();
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
this.mode = "runs";
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
selectFirstActiveAgentForCurrentRun() {
|
|
410
|
+
const rows = this.currentRunAgents();
|
|
411
|
+
const idx = rows.findIndex((row) => row.status === "running" || row.status === "starting");
|
|
412
|
+
this.runSelection = idx === -1 ? 0 : idx;
|
|
413
|
+
}
|
|
414
|
+
/** Resolves the runs-view selection by the identity of the previously selected row (its runId or
|
|
415
|
+
* saved-workflow name), not its index, so a live update that reorders rows between a render and the
|
|
416
|
+
* next key press does not silently select a different run. Falls back to a clamped index when the
|
|
417
|
+
* previous row is gone (e.g. an archived run was pruned). */
|
|
418
|
+
resolveRunsSelectionIndex(rows) {
|
|
419
|
+
if (this.runsSelectionKey !== undefined) {
|
|
420
|
+
const idx = rows.findIndex((row) => runsRowKey(row) === this.runsSelectionKey);
|
|
421
|
+
if (idx !== -1)
|
|
422
|
+
return idx;
|
|
423
|
+
}
|
|
424
|
+
return clamp(this.runsSelection, 0, Math.max(0, rows.length - 1));
|
|
425
|
+
}
|
|
426
|
+
resetFollowing() {
|
|
427
|
+
this.following = true;
|
|
428
|
+
this.pauseAnchor = undefined;
|
|
429
|
+
}
|
|
430
|
+
isSplitActive() {
|
|
431
|
+
return this.lastRenderWidth >= SPLIT_MIN_WIDTH;
|
|
432
|
+
}
|
|
433
|
+
goBack() {
|
|
434
|
+
if (this.mode === "agent") {
|
|
435
|
+
const rows = this.currentRunAgents();
|
|
436
|
+
const idx = rows.findIndex((row) => row.i === this.currentAgentIndex);
|
|
437
|
+
if (idx !== -1)
|
|
438
|
+
this.runSelection = idx;
|
|
439
|
+
this.mode = "run";
|
|
440
|
+
this.resetFollowing();
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (this.mode === "run") {
|
|
444
|
+
// Reselects the run the user came from, so the runs view does not fall back to the index it
|
|
445
|
+
// had before drilling in (which may now point at a different row).
|
|
446
|
+
if (this.currentRunId)
|
|
447
|
+
this.runsSelectionKey = `run:${this.currentRunId}`;
|
|
448
|
+
this.mode = "runs";
|
|
449
|
+
this.currentRunId = undefined;
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
this.deps.close();
|
|
453
|
+
}
|
|
454
|
+
confirmSelection() {
|
|
455
|
+
if (this.mode === "runs") {
|
|
456
|
+
const row = this.runsRows[this.runsSelection];
|
|
457
|
+
if (!row)
|
|
458
|
+
return;
|
|
459
|
+
if (row.kind === "saved") {
|
|
460
|
+
const saved = row.saved;
|
|
461
|
+
if (!saved)
|
|
462
|
+
return;
|
|
463
|
+
if (!saved.valid) {
|
|
464
|
+
this.footerNotice = `/${saved.name} is invalid`;
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const command = saved.command ? `/${saved.command.replace(/^\//, "")} ` : `/workflow ${saved.name} `;
|
|
468
|
+
this.deps.insertCommand(command);
|
|
469
|
+
this.deps.close();
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (row.runId) {
|
|
473
|
+
this.currentRunId = row.runId;
|
|
474
|
+
this.mode = "run";
|
|
475
|
+
this.selectFirstActiveAgentForCurrentRun();
|
|
476
|
+
}
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (this.mode === "run") {
|
|
480
|
+
const rows = this.currentRunAgents();
|
|
481
|
+
const row = rows[this.runSelection];
|
|
482
|
+
if (!row)
|
|
483
|
+
return;
|
|
484
|
+
this.currentAgentIndex = row.i;
|
|
485
|
+
this.mode = "agent";
|
|
486
|
+
this.resetFollowing();
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
moveSelection(delta) {
|
|
490
|
+
if (this.mode === "runs") {
|
|
491
|
+
if (this.runsRows.length === 0)
|
|
492
|
+
return;
|
|
493
|
+
this.runsSelection = clamp(this.runsSelection + delta, 0, this.runsRows.length - 1);
|
|
494
|
+
const row = this.runsRows[this.runsSelection];
|
|
495
|
+
this.runsSelectionKey = row ? runsRowKey(row) : undefined;
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
if (this.mode === "run") {
|
|
499
|
+
const rows = this.currentRunAgents();
|
|
500
|
+
if (rows.length === 0)
|
|
501
|
+
return;
|
|
502
|
+
const next = clamp(this.runSelection + delta, 0, rows.length - 1);
|
|
503
|
+
if (next !== this.runSelection) {
|
|
504
|
+
this.runSelection = next;
|
|
505
|
+
this.resetFollowing();
|
|
506
|
+
}
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
this.scrollTranscript(delta);
|
|
510
|
+
}
|
|
511
|
+
/** Shared by the agent detail view and, in split view, by page keys on the run view: both drive
|
|
512
|
+
* the same `following`/`pauseAnchor` pair against whichever agent is currently shown on the
|
|
513
|
+
* right. */
|
|
514
|
+
scrollTranscript(delta) {
|
|
515
|
+
const total = this.lastTranscriptTotalLines ?? 0;
|
|
516
|
+
const ranges = this.lastTranscriptRanges;
|
|
517
|
+
const visible = Math.max(1, this.lastDetailBodyHeight ?? 1);
|
|
518
|
+
const currentEnd = this.pauseAnchor ? resolvePauseEndLine(this.pauseAnchor, ranges, total) : total;
|
|
519
|
+
if (delta < 0) {
|
|
520
|
+
if (total <= visible)
|
|
521
|
+
return;
|
|
522
|
+
const minEnd = Math.min(total, visible);
|
|
523
|
+
this.pauseAnchor = anchorAtEndLine(Math.max(minEnd, currentEnd + delta), ranges);
|
|
524
|
+
this.following = false;
|
|
525
|
+
}
|
|
526
|
+
else if (delta > 0 && this.pauseAnchor !== undefined) {
|
|
527
|
+
const next = Math.min(total, currentEnd + delta);
|
|
528
|
+
if (next >= total) {
|
|
529
|
+
this.pauseAnchor = undefined;
|
|
530
|
+
this.following = true;
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
this.pauseAnchor = anchorAtEndLine(next, ranges);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
/** Page keys scroll the right pane in split view (§12.2) instead of moving the left selection by
|
|
538
|
+
* a page. Up/down always move the left selection; only page keys are redirected. */
|
|
539
|
+
handlePage(direction) {
|
|
540
|
+
if (this.mode === "run" && this.isSplitActive()) {
|
|
541
|
+
this.scrollTranscript(direction * PAGE_SIZE);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
this.moveSelection(direction * PAGE_SIZE);
|
|
545
|
+
}
|
|
546
|
+
cycleAgent(direction) {
|
|
547
|
+
if (this.mode === "run") {
|
|
548
|
+
const rows = this.currentRunAgents();
|
|
549
|
+
if (rows.length === 0)
|
|
550
|
+
return;
|
|
551
|
+
this.runSelection = (this.runSelection + direction + rows.length) % rows.length;
|
|
552
|
+
this.resetFollowing();
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (this.mode === "agent") {
|
|
556
|
+
const rows = this.currentRunAgents();
|
|
557
|
+
if (rows.length === 0)
|
|
558
|
+
return;
|
|
559
|
+
const curIdx = rows.findIndex((row) => row.i === this.currentAgentIndex);
|
|
560
|
+
const nextIdx = ((curIdx === -1 ? 0 : curIdx) + direction + rows.length) % rows.length;
|
|
561
|
+
this.currentAgentIndex = rows[nextIdx]?.i;
|
|
562
|
+
this.resetFollowing();
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
toggleFollow() {
|
|
566
|
+
if (this.mode !== "agent" && !(this.mode === "run" && this.isSplitActive()))
|
|
567
|
+
return;
|
|
568
|
+
if (this.following) {
|
|
569
|
+
const anchor = anchorAtEndLine(this.lastTranscriptTotalLines ?? 0, this.lastTranscriptRanges);
|
|
570
|
+
// An empty transcript (no ranges yet, or the archived/retention-dropped summary body, which
|
|
571
|
+
// never sets any ranges) has nothing to anchor a pause to. Pressing `f` must stay a no-op
|
|
572
|
+
// then, not flip into a paused state the view can never escape: `scrollTranscript` only
|
|
573
|
+
// resumes following once `pauseAnchor` advances to the end, which it can never do without an
|
|
574
|
+
// anchor.
|
|
575
|
+
if (anchor === undefined)
|
|
576
|
+
return;
|
|
577
|
+
this.pauseAnchor = anchor;
|
|
578
|
+
this.following = false;
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
this.resetFollowing();
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
// ── Two-press cancel (§12.4) ────────────────────────────────────────────
|
|
585
|
+
handleCancelKey(action) {
|
|
586
|
+
const target = this.cancelTarget(action);
|
|
587
|
+
if (!target) {
|
|
588
|
+
this.armed = undefined;
|
|
589
|
+
this.footerNotice = undefined;
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
const sameTarget = this.armed?.action === action &&
|
|
593
|
+
this.armed.runId === target.runId &&
|
|
594
|
+
this.armed.agentIndex === target.agentIndex;
|
|
595
|
+
if (sameTarget) {
|
|
596
|
+
this.armed = undefined;
|
|
597
|
+
this.footerNotice = undefined;
|
|
598
|
+
if (action === "cancelAgent" && target.agentIndex !== undefined) {
|
|
599
|
+
this.deps.session.store.cancelAgent(target.runId, target.agentIndex);
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
this.deps.session.store.cancelRun(target.runId);
|
|
603
|
+
}
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (target.finished) {
|
|
607
|
+
this.armed = undefined;
|
|
608
|
+
this.footerNotice = "already finished";
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
this.armed = { action, runId: target.runId, agentIndex: target.agentIndex };
|
|
612
|
+
this.footerNotice =
|
|
613
|
+
action === "cancelAgent" ? `press x again to cancel ${target.label}` : "press X again to cancel the run";
|
|
614
|
+
}
|
|
615
|
+
cancelTarget(action) {
|
|
616
|
+
if (action === "cancelAgent") {
|
|
617
|
+
if (this.mode === "run") {
|
|
618
|
+
const row = this.currentRunAgents()[this.runSelection];
|
|
619
|
+
if (!row || !this.currentRunId)
|
|
620
|
+
return undefined;
|
|
621
|
+
return {
|
|
622
|
+
runId: this.currentRunId,
|
|
623
|
+
agentIndex: row.i,
|
|
624
|
+
label: row.label,
|
|
625
|
+
finished: isFinishedAgentStatus(row.status),
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
if (this.mode === "agent") {
|
|
629
|
+
const row = this.currentAgentRow();
|
|
630
|
+
if (!row || !this.currentRunId)
|
|
631
|
+
return undefined;
|
|
632
|
+
return {
|
|
633
|
+
runId: this.currentRunId,
|
|
634
|
+
agentIndex: row.i,
|
|
635
|
+
label: row.label,
|
|
636
|
+
finished: isFinishedAgentStatus(row.status),
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
return undefined;
|
|
640
|
+
}
|
|
641
|
+
if (this.mode === "runs") {
|
|
642
|
+
const row = this.runsRows[this.runsSelection];
|
|
643
|
+
if (!row || row.kind === "saved" || !row.runId || !row.snapshot)
|
|
644
|
+
return undefined;
|
|
645
|
+
return { runId: row.runId, label: row.snapshot.title, finished: row.snapshot.status !== "running" };
|
|
646
|
+
}
|
|
647
|
+
const snapshot = this.currentRunSnapshot();
|
|
648
|
+
if (!snapshot || !this.currentRunId)
|
|
649
|
+
return undefined;
|
|
650
|
+
return { runId: this.currentRunId, label: snapshot.title, finished: snapshot.status !== "running" };
|
|
651
|
+
}
|
|
652
|
+
// ── Data access ─────────────────────────────────────────────────────────
|
|
653
|
+
buildRunsRows() {
|
|
654
|
+
const store = this.deps.session.store;
|
|
655
|
+
const allRuns = store.runs();
|
|
656
|
+
const liveRuns = allRuns.filter((run) => run.status === "running");
|
|
657
|
+
const finishedLive = allRuns.filter((run) => run.status !== "running");
|
|
658
|
+
const knownIds = new Set([...liveRuns, ...finishedLive].map((run) => run.id));
|
|
659
|
+
const archived = this.deps.getArchivedRuns().filter((entry) => !knownIds.has(entry.runId));
|
|
660
|
+
const rows = [];
|
|
661
|
+
for (const run of liveRuns) {
|
|
662
|
+
rows.push({
|
|
663
|
+
kind: "live",
|
|
664
|
+
runId: run.id,
|
|
665
|
+
snapshot: sanitizeSnapshot(snapshotFromRun(run, { now: this.now(), tailItems: 0, limiter: this.deps.session.limiter.stats() })),
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
for (const run of finishedLive) {
|
|
669
|
+
rows.push({
|
|
670
|
+
kind: "earlier",
|
|
671
|
+
runId: run.id,
|
|
672
|
+
snapshot: sanitizeSnapshot(snapshotFromRun(run, { now: this.now(), tailItems: 0 })),
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
for (const entry of archived) {
|
|
676
|
+
rows.push({
|
|
677
|
+
kind: "earlier",
|
|
678
|
+
runId: entry.runId,
|
|
679
|
+
snapshot: sanitizeSnapshot(snapshotFromDetails(entry.details, { now: this.now() })),
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
for (const saved of this.deps.getSavedWorkflows()) {
|
|
683
|
+
rows.push({ kind: "saved", saved });
|
|
684
|
+
}
|
|
685
|
+
return rows;
|
|
686
|
+
}
|
|
687
|
+
currentRunSnapshot() {
|
|
688
|
+
if (!this.currentRunId)
|
|
689
|
+
return undefined;
|
|
690
|
+
const liveRun = this.deps.session.store.getRun(this.currentRunId);
|
|
691
|
+
if (liveRun) {
|
|
692
|
+
return sanitizeSnapshot(snapshotFromRun(liveRun, { now: this.now(), tailItems: 0, limiter: this.deps.session.limiter.stats() }));
|
|
693
|
+
}
|
|
694
|
+
const archived = this.deps.getArchivedRuns().find((entry) => entry.runId === this.currentRunId);
|
|
695
|
+
return archived ? sanitizeSnapshot(snapshotFromDetails(archived.details, { now: this.now() })) : undefined;
|
|
696
|
+
}
|
|
697
|
+
sortedAgentsOf(snapshot) {
|
|
698
|
+
if (!snapshot)
|
|
699
|
+
return [];
|
|
700
|
+
return [...snapshot.agents].sort((a, b) => a.i - b.i);
|
|
701
|
+
}
|
|
702
|
+
currentRunAgents() {
|
|
703
|
+
return this.sortedAgentsOf(this.currentRunSnapshot());
|
|
704
|
+
}
|
|
705
|
+
currentAgentRow() {
|
|
706
|
+
if (this.currentAgentIndex === undefined)
|
|
707
|
+
return undefined;
|
|
708
|
+
return this.currentRunAgents().find((row) => row.i === this.currentAgentIndex);
|
|
709
|
+
}
|
|
710
|
+
currentAgentTranscriptFor(agentIndex) {
|
|
711
|
+
if (!this.currentRunId)
|
|
712
|
+
return undefined;
|
|
713
|
+
const run = this.deps.session.store.getRun(this.currentRunId);
|
|
714
|
+
const agent = run?.agents[agentIndex];
|
|
715
|
+
// Retention drops every agent's transcript on a finished run once it falls past
|
|
716
|
+
// `keepTranscriptRuns`; `undefined` here sends the caller to the archived-style summary body
|
|
717
|
+
// (status, output, error, the "only kept while in memory" note) instead of an empty transcript.
|
|
718
|
+
if (!run || !agent || run.transcriptsDropped)
|
|
719
|
+
return undefined;
|
|
720
|
+
return { items: agent.state.transcript, dropped: agent.state.droppedItems };
|
|
721
|
+
}
|
|
722
|
+
// ── Rendering ───────────────────────────────────────────────────────────
|
|
723
|
+
formatRunsRow(row, width, selected) {
|
|
724
|
+
const cursor = selected ? "› " : " ";
|
|
725
|
+
if (row.kind === "saved" && row.saved) {
|
|
726
|
+
const saved = row.saved;
|
|
727
|
+
// `name`/`description` come from the saved script's own meta block (`workflow/meta.ts`), the
|
|
728
|
+
// same kind of script-supplied text `sanitizeSnapshot` cleans for live/archived runs.
|
|
729
|
+
const nameText = `${cursor}/${sanitizeChildText(saved.name)}`;
|
|
730
|
+
return columns([
|
|
731
|
+
{ text: saved.valid ? nameText : this.deps.theme.fg("error", `${nameText} invalid`), width: 18 },
|
|
732
|
+
{ text: sanitizeChildText(saved.description), width: "flex" },
|
|
733
|
+
{ text: savedWorkflowSourceLabel(saved.source), width: 4, align: "right" },
|
|
734
|
+
], width);
|
|
735
|
+
}
|
|
736
|
+
const snapshot = row.snapshot;
|
|
737
|
+
if (!snapshot)
|
|
738
|
+
return fitLine(`${cursor}?`, width);
|
|
739
|
+
const glyph = statusGlyph(snapshot.status, this.deps.theme, { now: this.now(), animate: false });
|
|
740
|
+
const optional = runsRowOptionalWidths(width);
|
|
741
|
+
// The cursor, glyph and title are fixed/flex cells ahead of every optional column, so they
|
|
742
|
+
// always render, even at widths where every optional column below has been dropped.
|
|
743
|
+
const cells = [
|
|
744
|
+
{ text: `${cursor}${glyph}`, width: RUNS_ROW_CURSOR_WIDTH },
|
|
745
|
+
{ text: runTitleText(snapshot), width: "flex" },
|
|
746
|
+
];
|
|
747
|
+
if (optional.subtitle > 0)
|
|
748
|
+
cells.push({ text: runSubtitleText(snapshot), width: optional.subtitle });
|
|
749
|
+
if (optional.counts > 0) {
|
|
750
|
+
cells.push({ text: formatCounts(this.deps.theme, this.now(), snapshot.counts), width: optional.counts });
|
|
751
|
+
}
|
|
752
|
+
if (optional.duration > 0) {
|
|
753
|
+
cells.push({ text: formatDuration(snapshot.elapsedMs), width: optional.duration, align: "right" });
|
|
754
|
+
}
|
|
755
|
+
if (optional.tokens > 0) {
|
|
756
|
+
cells.push({
|
|
757
|
+
text: snapshot.tokens > 0 ? formatTokens(snapshot.tokens) : "",
|
|
758
|
+
width: optional.tokens,
|
|
759
|
+
align: "right",
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
if (optional.cost > 0)
|
|
763
|
+
cells.push({ text: formatCost(snapshot.cost), width: optional.cost, align: "right" });
|
|
764
|
+
return columns(cells, width);
|
|
765
|
+
}
|
|
766
|
+
renderRunsBody(width, height) {
|
|
767
|
+
const rows = this.runsRows;
|
|
768
|
+
const lines = [];
|
|
769
|
+
const lineForRow = [];
|
|
770
|
+
let lastKind;
|
|
771
|
+
rows.forEach((row, idx) => {
|
|
772
|
+
if (row.kind !== lastKind) {
|
|
773
|
+
lines.push(this.deps.theme.bold(groupLabel(row.kind)));
|
|
774
|
+
lastKind = row.kind;
|
|
775
|
+
}
|
|
776
|
+
lineForRow[idx] = lines.length;
|
|
777
|
+
lines.push(this.formatRunsRow(row, width, idx === this.runsSelection));
|
|
778
|
+
});
|
|
779
|
+
if (rows.length === 0) {
|
|
780
|
+
lines.push('No agents yet. Put "polyphase" in a prompt or run /workflow <name>.');
|
|
781
|
+
}
|
|
782
|
+
const pivot = lineForRow[this.runsSelection] ?? 0;
|
|
783
|
+
const contentHeight = Math.max(1, height - 1);
|
|
784
|
+
const windowed = padLines(windowAround(lines, contentHeight, pivot, this.deps.theme), contentHeight);
|
|
785
|
+
return [...windowed, this.footerLine(this.runsHintLine(), width)];
|
|
786
|
+
}
|
|
787
|
+
formatAgentRow(row, width, selected) {
|
|
788
|
+
const cursor = selected ? "› " : " ";
|
|
789
|
+
const glyph = statusGlyph(row.status, this.deps.theme, { now: this.now(), animate: false });
|
|
790
|
+
const model = formatModelLabel(row, { withProvider: false });
|
|
791
|
+
const cells = [
|
|
792
|
+
{ text: `${cursor}${glyph} ${row.label}`, width: 18 },
|
|
793
|
+
{ text: model, width: 20 },
|
|
794
|
+
];
|
|
795
|
+
// Dropped below 60 columns, the same threshold `layoutRun` uses for its elapsed column: at
|
|
796
|
+
// the 40-column split-pane width there is no room for a 5th fixed cell ahead of the flex one.
|
|
797
|
+
if (width >= 60) {
|
|
798
|
+
cells.push({
|
|
799
|
+
text: row.elapsedMs === undefined ? "" : formatDuration(row.elapsedMs),
|
|
800
|
+
width: 5,
|
|
801
|
+
align: "right",
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
cells.push({ text: agentRowRightText(row, this.showThinking), width: "flex" });
|
|
805
|
+
return columns(cells, width);
|
|
806
|
+
}
|
|
807
|
+
runTitleForHeader(snapshot) {
|
|
808
|
+
const base = runTitleText(snapshot);
|
|
809
|
+
if (snapshot.kind === "workflow" && isCurrentlyPhased(snapshot.status) && snapshot.currentPhase !== undefined) {
|
|
810
|
+
const phase = snapshot.phases[snapshot.currentPhase];
|
|
811
|
+
if (phase)
|
|
812
|
+
return `${base} ▸ ${phase.title}`;
|
|
813
|
+
}
|
|
814
|
+
return base;
|
|
815
|
+
}
|
|
816
|
+
runHeaderRight(snapshot) {
|
|
817
|
+
const parts = [formatCounts(this.deps.theme, this.now(), snapshot.counts), formatDuration(snapshot.elapsedMs)];
|
|
818
|
+
if (snapshot.tokens > 0)
|
|
819
|
+
parts.push(formatTokens(snapshot.tokens));
|
|
820
|
+
const cost = formatCost(snapshot.cost);
|
|
821
|
+
if (cost)
|
|
822
|
+
parts.push(cost);
|
|
823
|
+
return parts.filter((part) => part.length > 0).join(" ");
|
|
824
|
+
}
|
|
825
|
+
renderRunBody(width, height, snapshot, rows) {
|
|
826
|
+
if (!snapshot)
|
|
827
|
+
return [this.deps.theme.fg("muted", "run not found")];
|
|
828
|
+
this.runSelection = clamp(this.runSelection, 0, Math.max(0, rows.length - 1));
|
|
829
|
+
const lines = [];
|
|
830
|
+
const lineForAgent = [];
|
|
831
|
+
if (snapshot.phases.length > 0) {
|
|
832
|
+
// Agents spawned before any phase()/agent({phase}) call (§13.3) carry no phase index; they
|
|
833
|
+
// are still selectable, so they get an ungrouped block ahead of the phase list instead of
|
|
834
|
+
// being silently dropped from the view.
|
|
835
|
+
rows.forEach((row, idx) => {
|
|
836
|
+
if (row.phase !== undefined)
|
|
837
|
+
return;
|
|
838
|
+
lineForAgent[idx] = lines.length;
|
|
839
|
+
lines.push(this.formatAgentRow(row, width, idx === this.runSelection));
|
|
840
|
+
});
|
|
841
|
+
for (const phase of snapshot.phases) {
|
|
842
|
+
lines.push(columns([
|
|
843
|
+
{
|
|
844
|
+
text: `${statusGlyph(phase.status, this.deps.theme, { now: this.now(), animate: false })} ${phase.index + 1} ${phase.title}`,
|
|
845
|
+
width: "flex",
|
|
846
|
+
},
|
|
847
|
+
{ text: `${phase.done}/${phase.total}`, width: 7, align: "right" },
|
|
848
|
+
{
|
|
849
|
+
text: phase.elapsedMs === undefined ? "" : formatDuration(phase.elapsedMs),
|
|
850
|
+
width: 7,
|
|
851
|
+
align: "right",
|
|
852
|
+
},
|
|
853
|
+
], width));
|
|
854
|
+
rows.forEach((row, idx) => {
|
|
855
|
+
if (row.phase !== phase.index)
|
|
856
|
+
return;
|
|
857
|
+
lineForAgent[idx] = lines.length;
|
|
858
|
+
lines.push(` ${this.formatAgentRow(row, Math.max(1, width - 4), idx === this.runSelection)}`);
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
else {
|
|
863
|
+
rows.forEach((row, idx) => {
|
|
864
|
+
lineForAgent[idx] = lines.length;
|
|
865
|
+
const prefix = row.step !== undefined ? `${row.step} ` : "";
|
|
866
|
+
lines.push(`${prefix}${this.formatAgentRow(row, Math.max(1, width - prefix.length), idx === this.runSelection)}`);
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
if (snapshot.log.length > 0) {
|
|
870
|
+
lines.push(`» ${oneLine(sanitizeForDisplay(snapshot.log[snapshot.log.length - 1] ?? ""))}`);
|
|
871
|
+
}
|
|
872
|
+
else if (snapshot.resultPreview && snapshot.status !== "running") {
|
|
873
|
+
lines.push(`→ ${oneLine(sanitizeForDisplay(snapshot.resultPreview))}`);
|
|
874
|
+
}
|
|
875
|
+
const pivot = lineForAgent[this.runSelection] ?? 0;
|
|
876
|
+
const contentHeight = Math.max(1, height - 1);
|
|
877
|
+
const windowed = padLines(windowAround(lines, contentHeight, pivot, this.deps.theme), contentHeight);
|
|
878
|
+
return [...windowed, this.footerLine(this.runHintLine(), width)];
|
|
879
|
+
}
|
|
880
|
+
renderSplitBody(width, height, rows) {
|
|
881
|
+
const rightWidth = Math.max(1, width - SPLIT_LEFT_WIDTH - 1);
|
|
882
|
+
this.runSelection = clamp(this.runSelection, 0, Math.max(0, rows.length - 1));
|
|
883
|
+
const leftLines = rows.map((row, idx) => fitLine(this.formatAgentRow(row, SPLIT_LEFT_WIDTH, idx === this.runSelection), SPLIT_LEFT_WIDTH));
|
|
884
|
+
const selectedAgentIndex = rows[this.runSelection]?.i;
|
|
885
|
+
const rightLines = this.renderAgentDetailBody(selectedAgentIndex, rightWidth, height, rows);
|
|
886
|
+
// Windowed the same way `renderRunBody` windows the flat agent list, so a run with more agents
|
|
887
|
+
// than the pane has rows keeps the `›` cursor on screen instead of scrolling it off the top.
|
|
888
|
+
const paddedLeft = padLines(windowAround(leftLines, height, this.runSelection, this.deps.theme), height);
|
|
889
|
+
const paddedRight = padLines(rightLines, height);
|
|
890
|
+
return paddedLeft.map((line, idx) => `${padToWidth(line, SPLIT_LEFT_WIDTH)}│${paddedRight[idx] ?? ""}`);
|
|
891
|
+
}
|
|
892
|
+
renderAgentDetailBody(agentIndex, width, height, rows) {
|
|
893
|
+
const footerFallback = this.agentHintLine();
|
|
894
|
+
const contentHeight = Math.max(1, height - 1);
|
|
895
|
+
if (agentIndex === undefined) {
|
|
896
|
+
return [
|
|
897
|
+
...padLines([this.deps.theme.fg("muted", "no agent selected")], contentHeight),
|
|
898
|
+
this.footerLine(footerFallback, width),
|
|
899
|
+
];
|
|
900
|
+
}
|
|
901
|
+
const row = rows.find((r) => r.i === agentIndex);
|
|
902
|
+
if (!row) {
|
|
903
|
+
return [
|
|
904
|
+
...padLines([this.deps.theme.fg("muted", "agent not found")], contentHeight),
|
|
905
|
+
this.footerLine(footerFallback, width),
|
|
906
|
+
];
|
|
907
|
+
}
|
|
908
|
+
const header = [];
|
|
909
|
+
const modelLabel = formatModelLabel(row, { withProvider: true, withSource: true });
|
|
910
|
+
const confirmText = row.modelConfirmed ? "confirmed" : "unconfirmed";
|
|
911
|
+
const tokensText = row.tokens > 0 ? ` · ${formatTokens(row.tokens)} tok` : "";
|
|
912
|
+
const costText = row.cost > 0 ? ` · ${formatCost(row.cost)}` : "";
|
|
913
|
+
const turnsText = `${row.turns} turn${row.turns === 1 ? "" : "s"}`;
|
|
914
|
+
const toolsText = `${row.toolCalls} tool${row.toolCalls === 1 ? "" : "s"}`;
|
|
915
|
+
header.push(oneLine(`${modelLabel} · ${confirmText} · ${turnsText} · ${toolsText}${tokensText}${costText}`));
|
|
916
|
+
header.push(`task ${oneLine(row.task)}`);
|
|
917
|
+
header.push("─".repeat(Math.max(0, width)));
|
|
918
|
+
const footer = this.footerLine(this.agentHintLine(row.status), width);
|
|
919
|
+
const transcript = this.currentAgentTranscriptFor(agentIndex);
|
|
920
|
+
if (!transcript) {
|
|
921
|
+
const OUTPUT_PREVIEW_MAX_LINES = 8;
|
|
922
|
+
let statusLines = row.statusLine ? 1 : 0;
|
|
923
|
+
let errorLines = row.error ? 1 : 0;
|
|
924
|
+
const noteLines = 1;
|
|
925
|
+
// The note explains why the transcript is gone, so it must survive trimming even at the
|
|
926
|
+
// smallest supported height: reserve header + note first, then drop error, then status,
|
|
927
|
+
// before giving any remaining budget to the output preview. `padLines` below only pads or
|
|
928
|
+
// truncates from the end, so whatever we build here must already fit `contentHeight`.
|
|
929
|
+
if (header.length + statusLines + errorLines + noteLines > contentHeight && errorLines > 0) {
|
|
930
|
+
errorLines = 0;
|
|
931
|
+
}
|
|
932
|
+
if (header.length + statusLines + errorLines + noteLines > contentHeight && statusLines > 0) {
|
|
933
|
+
statusLines = 0;
|
|
934
|
+
}
|
|
935
|
+
const outputBudget = row.output
|
|
936
|
+
? Math.max(0, contentHeight - header.length - statusLines - errorLines - noteLines - 1)
|
|
937
|
+
: 0;
|
|
938
|
+
const body = [...header];
|
|
939
|
+
if (statusLines > 0 && row.statusLine) {
|
|
940
|
+
body.push(fitLine(`status ${oneLine(sanitizeForDisplay(row.statusLine))}`, width));
|
|
941
|
+
}
|
|
942
|
+
if (row.output && outputBudget > 0) {
|
|
943
|
+
body.push("output");
|
|
944
|
+
body.push(...wrapTextWithAnsi(sanitizeForDisplay(row.output), Math.max(1, width - 2))
|
|
945
|
+
.slice(0, Math.min(OUTPUT_PREVIEW_MAX_LINES, outputBudget))
|
|
946
|
+
.map((line) => fitLine(` ${line}`, width)));
|
|
947
|
+
}
|
|
948
|
+
if (errorLines > 0 && row.error)
|
|
949
|
+
body.push(fitLine(`error ${oneLine(sanitizeForDisplay(row.error))}`, width));
|
|
950
|
+
body.push(this.deps.theme.fg("muted", "Live transcript is only kept while the run is in memory."));
|
|
951
|
+
this.lastTranscriptTotalLines = undefined;
|
|
952
|
+
this.lastTranscriptRanges = [];
|
|
953
|
+
this.lastDetailBodyHeight = undefined;
|
|
954
|
+
return [...padLines(body, contentHeight), footer];
|
|
955
|
+
}
|
|
956
|
+
const owner = `${this.currentRunId}:${agentIndex}`;
|
|
957
|
+
const transcriptLines = this.transcriptCache.linesFor(owner, transcript.items, transcript.dropped, {
|
|
958
|
+
width,
|
|
959
|
+
showThinking: this.showThinking,
|
|
960
|
+
showToolPreviews: this.showToolPreviews,
|
|
961
|
+
now: this.now(),
|
|
962
|
+
});
|
|
963
|
+
const tail = tailWindowOf(transcriptLines);
|
|
964
|
+
this.lastTranscriptTotalLines = tail.totalLines;
|
|
965
|
+
this.lastTranscriptRanges = this.transcriptCache.lineRanges();
|
|
966
|
+
// A finished or cancelled agent has nothing left to follow or pause: the indicator row only
|
|
967
|
+
// makes sense while the agent could still produce more output.
|
|
968
|
+
const showFollowLine = !isFinishedAgentStatus(row.status);
|
|
969
|
+
const transcriptRows = Math.max(1, contentHeight - header.length - (showFollowLine ? 1 : 0));
|
|
970
|
+
this.lastDetailBodyHeight = transcriptRows;
|
|
971
|
+
const pinnedEndLine = this.pauseAnchor
|
|
972
|
+
? resolvePauseEndLine(this.pauseAnchor, this.lastTranscriptRanges, tail.totalLines)
|
|
973
|
+
: undefined;
|
|
974
|
+
const offsetFromEnd = this.following ? 0 : Math.max(0, tail.totalLines - (pinnedEndLine ?? tail.totalLines));
|
|
975
|
+
const windowLines = padLines(tail.window(transcriptRows, offsetFromEnd), transcriptRows);
|
|
976
|
+
const followLine = showFollowLine
|
|
977
|
+
? [fitLine(this.following ? "◆ following" : "‖ paused · f to follow", width)]
|
|
978
|
+
: [];
|
|
979
|
+
const body = [...header, ...windowLines, ...followLine];
|
|
980
|
+
return [...padLines(body, contentHeight), footer];
|
|
981
|
+
}
|
|
982
|
+
/** `width` is the same inner width the caller laid its body out to, so a hint line that does not
|
|
983
|
+
* fit is ellipsised like every other row instead of being hard-cut by `sideLine`'s padding,
|
|
984
|
+
* which carries no ellipsis of its own. */
|
|
985
|
+
footerLine(hint, width) {
|
|
986
|
+
return fitLine(this.footerNotice ? this.deps.theme.fg("warning", this.footerNotice) : hint, width);
|
|
987
|
+
}
|
|
988
|
+
runsHintLine() {
|
|
989
|
+
return [
|
|
990
|
+
combinedKeyHint(["tui.select.up", "tui.select.down"], "select"),
|
|
991
|
+
keyHint("tui.select.confirm", "open"),
|
|
992
|
+
keyHint("app.polyphase.cancelRun", "cancel run"),
|
|
993
|
+
keyHint("tui.select.cancel", "close"),
|
|
994
|
+
].join(" ");
|
|
995
|
+
}
|
|
996
|
+
runHintLine() {
|
|
997
|
+
return [
|
|
998
|
+
combinedKeyHint(["tui.select.up", "tui.select.down"], "select"),
|
|
999
|
+
keyHint("tui.select.confirm", "follow"),
|
|
1000
|
+
keyHint("app.polyphase.cancelAgent", "cancel agent"),
|
|
1001
|
+
keyHint("app.polyphase.cancelRun", "cancel run"),
|
|
1002
|
+
keyHint("tui.select.cancel", "back"),
|
|
1003
|
+
].join(" ");
|
|
1004
|
+
}
|
|
1005
|
+
agentHintLine(status) {
|
|
1006
|
+
const finished = status !== undefined && isFinishedAgentStatus(status);
|
|
1007
|
+
return [
|
|
1008
|
+
keyHint("app.polyphase.nextAgent", "next agent"),
|
|
1009
|
+
...(finished ? [] : [keyHint("app.polyphase.follow", "follow")]),
|
|
1010
|
+
keyHint("app.thinking.toggle", "thinking"),
|
|
1011
|
+
...(finished ? [] : [keyHint("app.polyphase.cancelAgent", "cancel")]),
|
|
1012
|
+
keyHint("tui.select.cancel", "back"),
|
|
1013
|
+
].join(" ");
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
//# sourceMappingURL=inspector.js.map
|