@each1024/pi-mini-mode 2.0.17 → 2.0.19
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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/extensions/footer-status.ts +70 -11
- package/lib/agent-render.ts +352 -14
- package/lib/agent-state.ts +109 -6
- package/lib/agent-view.ts +4 -1
- package/lib/assistant-images.ts +30 -3
- package/lib/file-links.ts +24 -3
- package/lib/input-editor.ts +26 -5
- package/lib/minimal-output.ts +417 -83
- package/lib/minimal-turns.ts +18 -2
- package/lib/print-agent.ts +712 -0
- package/lib/settings.ts +6 -2
- package/lib/token-speed.ts +219 -30
- package/lib/update-banner.ts +161 -0
- package/lib/usage.ts +41 -8
- package/package.json +2 -1
package/lib/minimal-output.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { getMarkdownTheme, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Text, truncateToWidth, visibleWidth, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
3
3
|
import { stripVTControlCharacters } from "node:util";
|
|
4
|
-
import { agentCallDisplay, isAgentTool, liveAgentView, runningGlyph } from "./agent-view.ts";
|
|
5
|
-
import { createAssistantImages, imagePlaceholders } from "./assistant-images.ts";
|
|
6
|
-
import { linkToolFiles } from "./file-links.ts";
|
|
4
|
+
import { agentCallDisplay, agentChildren, childSessionData, isAgentTool, isPrintAgentCall, liveAgentView, printAgentStatuses, runningGlyph, type AgentCall } from "./agent-view.ts";
|
|
5
|
+
import { assistantImageSpans, clearAssistantImageCaches, createAssistantImages, imagePlaceholders } from "./assistant-images.ts";
|
|
6
|
+
import { clearFileLinkCaches, linkToolFiles } from "./file-links.ts";
|
|
7
7
|
import { createLinkHover } from "./link-hover.ts";
|
|
8
8
|
import { diagramMarkdown, isFencedMarkdown, renderMinimalMarkdown } from "./minimal-markdown.ts";
|
|
9
9
|
import { minimalSurface, paintExpandedHeading } from "./minimal-theme.ts";
|
|
10
10
|
import { formatElapsed, formatThinkingElapsed, formatToolElapsed, piLoopSummary, type MinimalTurn } from "./minimal-turns.ts";
|
|
11
|
-
import {
|
|
11
|
+
import { clearPrintAgentCaches } from "./print-agent.ts";
|
|
12
|
+
import { DEFAULT_SETTINGS, type UiLanguage } from "./settings.ts";
|
|
12
13
|
import { thinkingPreview } from "./thinking-preview.ts";
|
|
13
14
|
import type { NoticeRows, TurnNotices } from "./transcript-adapter.ts";
|
|
15
|
+
import { renderUpdateBanner } from "./update-banner.ts";
|
|
14
16
|
import { addUsage, EMPTY_USAGE, formatTokens } from "./usage.ts";
|
|
15
17
|
|
|
16
18
|
/** Shown when a thinking block has no displayable summary. */
|
|
@@ -19,12 +21,148 @@ const THINKING_FALLBACK: Record<UiLanguage, Record<"active" | "aborted" | "error
|
|
|
19
21
|
en: { active: "Waiting for a displayable summary", aborted: "Interrupted, no displayable summary returned", error: "Failed, no displayable summary returned", ended: "Finished, no displayable summary returned" },
|
|
20
22
|
};
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
const MINIMAL_COPY = {
|
|
25
|
+
zh: {
|
|
26
|
+
collapsePrompt: "▴ 收起",
|
|
27
|
+
expandPrompt: "▾ 展开",
|
|
28
|
+
expandPromptLines: (n: number) => `▾ 展开 (${n} 行)`,
|
|
29
|
+
session: "会话 ",
|
|
30
|
+
cache: " · 缓存 ",
|
|
31
|
+
inputLabel: "输入:",
|
|
32
|
+
outputLabel: "输出:",
|
|
33
|
+
waitingToolResult: "等待工具文本结果…",
|
|
34
|
+
emptyToolResult: "无文本结果",
|
|
35
|
+
waitingModel: "等待模型响应",
|
|
36
|
+
waitingNextStep: "等待下一步执行",
|
|
37
|
+
},
|
|
38
|
+
en: {
|
|
39
|
+
collapsePrompt: "▴ Collapse",
|
|
40
|
+
expandPrompt: "▾ Expand",
|
|
41
|
+
expandPromptLines: (n: number) => `▾ Expand (${n} lines)`,
|
|
42
|
+
session: "Session ",
|
|
43
|
+
cache: " · Cache ",
|
|
44
|
+
inputLabel: "Input:",
|
|
45
|
+
outputLabel: "Output:",
|
|
46
|
+
waitingToolResult: "Waiting for tool text result…",
|
|
47
|
+
emptyToolResult: "No text result",
|
|
48
|
+
waitingModel: "Waiting for model response",
|
|
49
|
+
waitingNextStep: "Waiting for next step",
|
|
50
|
+
},
|
|
51
|
+
} as const;
|
|
52
|
+
|
|
53
|
+
const LRU_MAX = 800;
|
|
54
|
+
function lruGet<K, V>(map: Map<K, V>, key: K): V | undefined {
|
|
55
|
+
return map.get(key);
|
|
56
|
+
}
|
|
57
|
+
function lruSet<K, V>(map: Map<K, V>, key: K, val: V, max = LRU_MAX): V {
|
|
58
|
+
if (map.has(key)) map.delete(key);
|
|
59
|
+
else if (map.size >= max) {
|
|
60
|
+
const first = map.keys().next().value;
|
|
61
|
+
if (first !== undefined) map.delete(first);
|
|
62
|
+
}
|
|
63
|
+
map.set(key, val);
|
|
64
|
+
return val;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function keysEqual(a: readonly unknown[], b: readonly unknown[]): boolean {
|
|
68
|
+
if (a.length !== b.length) return false;
|
|
69
|
+
for (let i = 0; i < a.length; i++) {
|
|
70
|
+
if (a[i] !== b[i]) return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isSubAgentChildRunning(child: Record<string, unknown>): boolean {
|
|
76
|
+
const exit = typeof child.exitCode === "number" ? child.exitCode : undefined;
|
|
77
|
+
const raw = String(child.status ?? child.state ?? "");
|
|
78
|
+
const failed = (exit !== undefined && exit > 0) || /^(failed|error|aborted|cancelled|canceled|timed?_?out|killed)$/i.test(raw);
|
|
79
|
+
const done = !failed && /^(done|completed?|succeeded|success|failed|error|aborted|cancelled|canceled|stopped|timed?_?out|killed)$/i.test(raw);
|
|
80
|
+
return !failed && !done;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface TurnRenderResult {
|
|
84
|
+
lines: string[];
|
|
85
|
+
promptControls: Array<{ index: number; question: string; y: number; x: number; width: number; label: string }>;
|
|
86
|
+
toolControls: Array<{ id: string; y: number; width: number; title: string }>;
|
|
87
|
+
processRows: Array<{ key: string; y: number }>;
|
|
88
|
+
agentControls: Array<{ index: number; y: number; width: number }>;
|
|
89
|
+
subagentControls: Array<{ runId: string; y: number; width: number; line: string }>;
|
|
90
|
+
pinnedTool?: { id: string; y: number; line: string };
|
|
91
|
+
pinnedAgent?: { index: number; y: number; line: string };
|
|
92
|
+
pinnedSubagent?: { id: string; y: number; line: string; autoScroll?: boolean };
|
|
93
|
+
claimedPrintFiles: string[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface UpdateBannerState {
|
|
97
|
+
version: string;
|
|
98
|
+
collapsed: boolean;
|
|
99
|
+
toggle: () => void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface MinimalOutputOptions {
|
|
103
|
+
cwd(): string;
|
|
104
|
+
requestRender(): void;
|
|
105
|
+
write?(data: string): void;
|
|
106
|
+
updateBanner?: () => UpdateBannerState | undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], getTurns: () => MinimalTurn[], isExpanded: () => boolean = () => false, showUsage: () => boolean = () => true, subAgentsExpanded: () => boolean = () => false, agentDeadlines = new Map<string, number>(), transformText: (text: string) => string = text => text, imageOptions?: MinimalOutputOptions, getRecordLimit: () => number = () => DEFAULT_SETTINGS["pi-mini-mode-minimal-record-limit"], getLanguage: () => UiLanguage = () => "zh", getUpdateBanner?: () => UpdateBannerState | undefined) {
|
|
110
|
+
const resolveUpdateBanner = getUpdateBanner ?? imageOptions?.updateBanner;
|
|
111
|
+
const markdownCache = new Map<string, string[]>();
|
|
112
|
+
const assistantMdCache = new Map<string, string[]>();
|
|
113
|
+
const callDisplayCache = new Map<string, { tool?: string; name: string; action?: string; state: string; task: string; output?: string; value: { summary: string; detail: string } }>();
|
|
114
|
+
const turnCache = new Map<number, { key: readonly unknown[]; value: TurnRenderResult }>();
|
|
23
115
|
const placeholderText = (text: string) => imageOptions ? imagePlaceholders(text, imageOptions.cwd()) : text;
|
|
24
|
-
const markdown = (text: string, width: number, process = false) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
116
|
+
const markdown = (text: string, width: number, process = false): string[] => {
|
|
117
|
+
const key = `${process ? 1 : 0}|${width}|${text}`;
|
|
118
|
+
const hit = lruGet(markdownCache, key);
|
|
119
|
+
if (hit !== undefined) return [...hit];
|
|
120
|
+
const rows = renderMinimalMarkdown(text, width, getMarkdownTheme(), theme.getBgAnsi?.("userMessageBg") ?? "",
|
|
121
|
+
{ color: (value) => theme.fg(process ? "muted" : "text", value) }, (source, available) => transformText(placeholderText(diagramMarkdown(source, available))));
|
|
122
|
+
lruSet(markdownCache, key, rows);
|
|
123
|
+
return [...rows];
|
|
124
|
+
};
|
|
125
|
+
const thinkingMarkdown = (text: string, width: number, color: "error" | "accent" | "muted", previewRows: number): string[] => {
|
|
126
|
+
const key = `t:${color}|${width}|${previewRows}|${text}`;
|
|
127
|
+
const hit = lruGet(markdownCache, key);
|
|
128
|
+
if (hit !== undefined) return [...hit];
|
|
129
|
+
const rows = renderMinimalMarkdown(text, width, getMarkdownTheme(), theme.getBgAnsi?.("userMessageBg") ?? "",
|
|
130
|
+
{ color: value => theme.fg(color, value) }, (source, avail) => transformText(placeholderText(diagramMarkdown(source, avail))))
|
|
131
|
+
.slice(0, previewRows);
|
|
132
|
+
lruSet(markdownCache, key, rows);
|
|
133
|
+
return [...rows];
|
|
134
|
+
};
|
|
135
|
+
const assistantImages = imageOptions && createAssistantImages(imageOptions.cwd, () => { turnCache.clear(); imageOptions.requestRender(); }, imageOptions.write);
|
|
136
|
+
const assistantMarkdown = (text: string, width: number, owner: string): string[] => {
|
|
137
|
+
if (!assistantImages) return markdown(text, width);
|
|
138
|
+
const key = `${width}|${text}`;
|
|
139
|
+
const hit = lruGet(assistantMdCache, key);
|
|
140
|
+
if (hit !== undefined) return [...hit];
|
|
141
|
+
if (!assistantImageSpans(text, imageOptions!.cwd()).length) {
|
|
142
|
+
const rows = markdown(text, width);
|
|
143
|
+
lruSet(assistantMdCache, key, rows);
|
|
144
|
+
return [...rows];
|
|
145
|
+
}
|
|
146
|
+
return assistantImages.render(text, width, markdown, owner);
|
|
147
|
+
};
|
|
148
|
+
const cachedCallDisplay = (call: AgentCall) => {
|
|
149
|
+
const hit = callDisplayCache.get(call.id);
|
|
150
|
+
if (hit && hit.state === call.state && hit.output === call.output && hit.task === call.task && hit.name === call.name && hit.tool === call.tool && hit.action === call.action) {
|
|
151
|
+
return hit.value;
|
|
152
|
+
}
|
|
153
|
+
const value = agentCallDisplay(call);
|
|
154
|
+
lruSet(callDisplayCache, call.id, { tool: call.tool, name: call.name, action: call.action, state: call.state, task: call.task, output: call.output, value });
|
|
155
|
+
return value;
|
|
156
|
+
};
|
|
157
|
+
const clearAllCaches = () => {
|
|
158
|
+
markdownCache.clear();
|
|
159
|
+
assistantMdCache.clear();
|
|
160
|
+
callDisplayCache.clear();
|
|
161
|
+
turnCache.clear();
|
|
162
|
+
clearAssistantImageCaches();
|
|
163
|
+
clearFileLinkCaches();
|
|
164
|
+
clearPrintAgentCaches();
|
|
165
|
+
};
|
|
28
166
|
const surface = (rows: string[], width: number, user: boolean, selected = -1, expanded = false) => {
|
|
29
167
|
const padding = Math.min(2, Math.floor((width - 1) / 2));
|
|
30
168
|
return ["", ...rows, ""].map((row, index) => {
|
|
@@ -74,7 +212,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
74
212
|
clearHover();
|
|
75
213
|
return;
|
|
76
214
|
}
|
|
77
|
-
if (!getTurns().some(turn => turn.agentCalls?.some(call => call.id === id && !isAgentTool(call.tool ?? call.name)))) return;
|
|
215
|
+
if (!getTurns().some(turn => turn.agentCalls?.some(call => call.id === id && !isAgentTool(call.tool ?? call.name) && !isPrintAgentCall(call)))) return;
|
|
78
216
|
if (expandedTools.has(id)) {
|
|
79
217
|
expandedTools.delete(id);
|
|
80
218
|
if (pinnedToolId === id) pinnedToolId = undefined;
|
|
@@ -99,6 +237,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
99
237
|
let promptControls: Array<{ index: number; question: string; y: number; x: number; width: number; label: string }> = [];
|
|
100
238
|
let subagentControls: Array<{ runId: string; y: number; width: number; line: string }> = [];
|
|
101
239
|
let noticeRegions: Array<{ y: number; rows: NoticeRows }> = [];
|
|
240
|
+
let bannerControl: { headerRows: number; totalRows: number; width: number; toggle: () => void } | undefined;
|
|
102
241
|
const togglePrompt = (index: number, question: string) => {
|
|
103
242
|
if (getTurns()[index]?.question !== question) return;
|
|
104
243
|
if (expandedPrompts.get(index) === question) expandedPrompts.delete(index);
|
|
@@ -106,10 +245,11 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
106
245
|
};
|
|
107
246
|
return {
|
|
108
247
|
dispose() { assistantImages?.dispose(); },
|
|
109
|
-
invalidate() { clearHover(); },
|
|
248
|
+
invalidate() { clearHover(); clearAllCaches(); },
|
|
110
249
|
resetProcessView() {
|
|
111
250
|
agentModes.clear(); expandedThinking.clear(); expandedTools.clear(); expandedSubagents.clear();
|
|
112
251
|
thinkingPreviews.clear();
|
|
252
|
+
clearAllCaches();
|
|
113
253
|
pinnedToolId = undefined; pinnedAgentIndex = undefined; pinnedSubagentId = undefined;
|
|
114
254
|
},
|
|
115
255
|
clearHover,
|
|
@@ -147,6 +287,18 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
147
287
|
}
|
|
148
288
|
}
|
|
149
289
|
if (event.button !== "left" || event.shift || event.ctrl || event.alt) return;
|
|
290
|
+
if (bannerControl && (event.clickCount ?? 1) === 1) {
|
|
291
|
+
const inHeader = event.y >= 0 && event.y < bannerControl.headerRows;
|
|
292
|
+
const inFooter = bannerControl.totalRows > bannerControl.headerRows
|
|
293
|
+
&& event.y >= bannerControl.totalRows - 3 && event.y < bannerControl.totalRows;
|
|
294
|
+
if ((inHeader || inFooter) && event.x >= 0 && event.x < bannerControl.width) {
|
|
295
|
+
if (event.type === "press") return { handled: true };
|
|
296
|
+
if (event.type === "click") {
|
|
297
|
+
bannerControl.toggle();
|
|
298
|
+
return { handled: true, render: true };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
150
302
|
const agent = agentControls.find(control => event.y === control.y && event.x >= 0 && event.x < control.width);
|
|
151
303
|
if (agent && (event.clickCount ?? 1) === 1) {
|
|
152
304
|
if (event.type === "press") return { handled: true };
|
|
@@ -190,24 +342,153 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
190
342
|
pinnedSubagent = undefined;
|
|
191
343
|
subagentControls = [];
|
|
192
344
|
noticeRegions = [];
|
|
345
|
+
bannerControl = undefined;
|
|
193
346
|
agentExpiry = Infinity;
|
|
194
347
|
if (width <= 0) { clearHover(); return linkHover.render([], width); }
|
|
195
348
|
const turns = getTurns();
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
349
|
+
if (turnCache.size > turns.length) {
|
|
350
|
+
for (const k of turnCache.keys()) if (k >= turns.length) turnCache.delete(k);
|
|
351
|
+
}
|
|
352
|
+
const renderCwd = imageOptions?.cwd() ?? process.cwd();
|
|
353
|
+
const claimedPrintSessions = new Set<string>();
|
|
354
|
+
const isCapturedCall = (call: AgentCall) => isAgentTool(call.tool ?? call.name) || isPrintAgentCall(call);
|
|
355
|
+
if (expandedTools.size > 0) {
|
|
356
|
+
const toolIds = new Set(turns.flatMap(turn => (turn.agentCalls ?? []).filter(call => !isCapturedCall(call)).map(call => call.id)));
|
|
357
|
+
for (const id of expandedTools) if (!toolIds.has(id)) expandedTools.delete(id);
|
|
358
|
+
}
|
|
359
|
+
if (expandedThinking.size > 0 || thinkingPreviews.size > 0) {
|
|
360
|
+
const hasThinkingId = (id: string) => {
|
|
361
|
+
const parts = id.split(":");
|
|
362
|
+
return Boolean(turns[Number(parts[1])]?.process[Number(parts[2])]?.startsWith("thinking"));
|
|
363
|
+
};
|
|
364
|
+
for (const id of expandedThinking) if (!hasThinkingId(id)) expandedThinking.delete(id);
|
|
365
|
+
for (const id of thinkingPreviews.keys()) if (!hasThinkingId(id)) thinkingPreviews.delete(id);
|
|
366
|
+
}
|
|
202
367
|
const inner = Math.max(1, width - 2 * Math.min(2, Math.floor((width - 1) / 2)));
|
|
203
368
|
const lines: string[] = [];
|
|
204
369
|
// An open heading wears the same full-width selectedBg band as an expanded SubAgent row.
|
|
205
370
|
const bandHeading = (row: string, open: boolean) => open
|
|
206
371
|
? paintExpandedHeading(theme, row + " ".repeat(Math.max(0, width - visibleWidth(row)))) : row;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
372
|
+
const now = Date.now();
|
|
373
|
+
let hasFutureDeadline = false;
|
|
374
|
+
for (const deadline of agentDeadlines.values()) {
|
|
375
|
+
if (deadline > now) {
|
|
376
|
+
hasFutureDeadline = true;
|
|
377
|
+
agentExpiry = Math.min(agentExpiry, deadline);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const exp = isExpanded();
|
|
381
|
+
const subExp = subAgentsExpanded();
|
|
382
|
+
const usageShown = showUsage();
|
|
383
|
+
const recLimit = getRecordLimit();
|
|
384
|
+
const lang = getLanguage();
|
|
385
|
+
const banner = resolveUpdateBanner?.();
|
|
386
|
+
if (banner) {
|
|
387
|
+
const renderedBanner = renderUpdateBanner(theme, width, {
|
|
388
|
+
version: banner.version,
|
|
389
|
+
language: lang,
|
|
390
|
+
collapsed: banner.collapsed,
|
|
391
|
+
});
|
|
392
|
+
if (renderedBanner.rows.length > 0) {
|
|
393
|
+
bannerControl = {
|
|
394
|
+
headerRows: renderedBanner.headerRows,
|
|
395
|
+
totalRows: renderedBanner.rows.length,
|
|
396
|
+
width,
|
|
397
|
+
toggle: banner.toggle,
|
|
398
|
+
};
|
|
399
|
+
lines.push(...renderedBanner.rows);
|
|
400
|
+
if (turns.length > 0) lines.push("");
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const buildTurnKey = (index: number, turn: MinimalTurn, baseY: number, subChildren: Record<string, unknown>[]): readonly unknown[] => {
|
|
405
|
+
const usage = addUsage({ ...EMPTY_USAGE, ...turn.usage, cost: turn.usage?.cost ?? 0 }, turn.pendingUsage);
|
|
406
|
+
const calls = turn.agentCalls ?? [];
|
|
407
|
+
const turnExpandedTools = expandedTools.size > 0
|
|
408
|
+
? calls.filter(c => expandedTools.has(c.id)).map(c => c.id).join(",")
|
|
409
|
+
: "";
|
|
410
|
+
const thinkingPrefix = `thinking:${index}:`;
|
|
411
|
+
let turnExpandedThinking = "";
|
|
412
|
+
if (expandedThinking.size > 0) {
|
|
413
|
+
for (const id of expandedThinking) {
|
|
414
|
+
if (id.startsWith(thinkingPrefix)) turnExpandedThinking += (turnExpandedThinking ? "," : "") + id;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const turnExpandedSubagents = expandedSubagents.size > 0 && (subChildren.length > 0 || calls.some(isPrintAgentCall))
|
|
418
|
+
? Array.from(expandedSubagents).join(",")
|
|
419
|
+
: "";
|
|
420
|
+
const hoveredId = hoveredTool && (hoveredTool.id.startsWith(thinkingPrefix) || calls.some(c => c.id === hoveredTool!.id))
|
|
421
|
+
? `${hoveredTool.id}@${hoveredTool.y - baseY}@${hoveredTool.width}`
|
|
422
|
+
: "";
|
|
423
|
+
const turnPinnedTool = pinnedToolId && calls.some(c => c.id === pinnedToolId) ? pinnedToolId : "";
|
|
424
|
+
const turnPinnedAgent = pinnedAgentIndex === index ? index : -1;
|
|
425
|
+
const turnPinnedSubagent = pinnedSubagentId && (subChildren.length > 0 || calls.some(isPrintAgentCall)) ? pinnedSubagentId : "";
|
|
426
|
+
const elapsedSec = turn.startedAt != null && turn.endedAt == null
|
|
427
|
+
? Math.floor((now - turn.startedAt) / 1000)
|
|
428
|
+
: (turn.endedAt ?? -1);
|
|
429
|
+
const key: unknown[] = [
|
|
430
|
+
width,
|
|
431
|
+
exp,
|
|
432
|
+
subExp,
|
|
433
|
+
usageShown,
|
|
434
|
+
recLimit,
|
|
435
|
+
lang,
|
|
436
|
+
agentModes.get(index),
|
|
437
|
+
expandedPrompts.get(index),
|
|
438
|
+
turnExpandedTools,
|
|
439
|
+
turnExpandedThinking,
|
|
440
|
+
turnExpandedSubagents,
|
|
441
|
+
hoveredId,
|
|
442
|
+
turnPinnedTool,
|
|
443
|
+
turnPinnedAgent,
|
|
444
|
+
turnPinnedSubagent,
|
|
445
|
+
turn.question,
|
|
446
|
+
turn.final ?? "",
|
|
447
|
+
turn.replies?.length ?? 0,
|
|
448
|
+
turn.replies?.at(-1) ?? "",
|
|
449
|
+
turn.process.length,
|
|
450
|
+
turn.process[0] ?? "",
|
|
451
|
+
turn.process.at(-1) ?? "",
|
|
452
|
+
turn.startedAt ?? -1,
|
|
453
|
+
elapsedSec,
|
|
454
|
+
turn.thinkingClocks?.length ?? 0,
|
|
455
|
+
turn.thinkingClocks?.at(-1)?.endedAt ?? -1,
|
|
456
|
+
turn.thinkingOutcomes?.length ?? 0,
|
|
457
|
+
usage.totalTokens,
|
|
458
|
+
usage.cacheRead,
|
|
459
|
+
calls.length,
|
|
460
|
+
subChildren.length,
|
|
461
|
+
];
|
|
462
|
+
for (const c of calls) {
|
|
463
|
+
key.push(c.id, c.state, c.task, c.output?.length ?? -1, c.output, c.startedAt ?? -1, c.endedAt ?? -1);
|
|
464
|
+
}
|
|
465
|
+
for (const sub of subChildren) {
|
|
466
|
+
key.push(
|
|
467
|
+
sub.runId ?? sub.displayId,
|
|
468
|
+
sub.status ?? sub.state,
|
|
469
|
+
sub.finalOutput,
|
|
470
|
+
sub.error,
|
|
471
|
+
(sub.notice as { summary?: unknown } | undefined)?.summary,
|
|
472
|
+
(sub.noticeMessages as unknown[] | undefined)?.length ?? 0,
|
|
473
|
+
childSessionData(sub.sessionFile)?.stamp ?? "",
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
return key;
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const renderTurn = (index: number, turn: MinimalTurn, baseY: number): TurnRenderResult => {
|
|
480
|
+
const turnLines: string[] = [];
|
|
481
|
+
const turnPromptControls: TurnRenderResult["promptControls"] = [];
|
|
482
|
+
const turnToolControls: TurnRenderResult["toolControls"] = [];
|
|
483
|
+
const turnProcessRows: TurnRenderResult["processRows"] = [];
|
|
484
|
+
const turnAgentControls: TurnRenderResult["agentControls"] = [];
|
|
485
|
+
const turnSubagentControls: TurnRenderResult["subagentControls"] = [];
|
|
486
|
+
let turnPinnedTool: TurnRenderResult["pinnedTool"];
|
|
487
|
+
let turnPinnedAgent: TurnRenderResult["pinnedAgent"];
|
|
488
|
+
let turnPinnedSubagent: TurnRenderResult["pinnedSubagent"];
|
|
489
|
+
const beforeClaimedSize = claimedPrintSessions.size;
|
|
490
|
+
const copy = MINIMAL_COPY[lang] ?? MINIMAL_COPY.zh;
|
|
491
|
+
|
|
211
492
|
const questionRows = markdown(turn.question, inner);
|
|
212
493
|
const loopSummary = piLoopSummary(turn.question);
|
|
213
494
|
const expanded = expandedPrompts.get(index) === turn.question;
|
|
@@ -218,20 +499,20 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
218
499
|
const userRows = expanded || keepFence ? [...questionRows] : loopSummary ? markdown(loopSummary, inner) : questionRows.slice(0, 4);
|
|
219
500
|
let controlIndex = -1;
|
|
220
501
|
if (!keepFence && (loopSummary || questionRows.length > 4)) {
|
|
221
|
-
const label = expanded ?
|
|
502
|
+
const label = expanded ? copy.collapsePrompt : loopSummary ? copy.expandPrompt : copy.expandPromptLines(questionRows.length);
|
|
222
503
|
const control = truncateToWidth(label, inner, "");
|
|
223
|
-
|
|
504
|
+
turnPromptControls.push({ index, question: turn.question, y: turnLines.length + 1 + userRows.length,
|
|
224
505
|
x: 0, width, label });
|
|
225
506
|
userRows.push(theme.fg("accent", control));
|
|
226
507
|
// The expanded control is this message's heading, so it keeps the band in place of the user surface.
|
|
227
508
|
controlIndex = userRows.length;
|
|
228
509
|
}
|
|
229
|
-
|
|
510
|
+
turnLines.push(...surface(userRows, width, true, controlIndex, expanded));
|
|
230
511
|
const entries = turn.process.flatMap((entry, processIndex) => {
|
|
231
512
|
if (entry.startsWith("call ")) {
|
|
232
513
|
const call = turn.agentCalls?.find(call => call.id === entry.slice(5));
|
|
233
|
-
if (call &&
|
|
234
|
-
const display = call &&
|
|
514
|
+
if (call && isCapturedCall(call)) return [];
|
|
515
|
+
const display = call && cachedCallDisplay(call);
|
|
235
516
|
return call && display ? [{ title: `${isAgentTool(call.tool ?? call.name) ? "Control" : call.name} ${display.summary}`.trim(), detail: display.detail, state: call.state, id: call.id, thinking: false, processIndex, activeThinking: false }] : [];
|
|
236
517
|
}
|
|
237
518
|
const part = entry.match(/^(tool|output|thinking|skill)(?:\s+|$)([\s\S]*)/);
|
|
@@ -243,54 +524,49 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
243
524
|
});
|
|
244
525
|
// Older in-memory turns may predate call markers.
|
|
245
526
|
for (const call of turn.agentCalls ?? []) {
|
|
246
|
-
if (
|
|
247
|
-
const display =
|
|
527
|
+
if (isCapturedCall(call)) continue;
|
|
528
|
+
const display = cachedCallDisplay(call);
|
|
248
529
|
if (!entries.some(entry => entry.id === call.id)) entries.push({ title: `${isAgentTool(call.tool ?? call.name) ? "Control" : call.name} ${display.summary}`, detail: display.detail, state: call.state, id: call.id, thinking: false, processIndex: -1, activeThinking: false });
|
|
249
530
|
}
|
|
531
|
+
const printStatuses = (turn.agentCalls ?? []).flatMap(call => printAgentStatuses(call, renderCwd, claimedPrintSessions));
|
|
532
|
+
const claimedPrintFiles = claimedPrintSessions.size > beforeClaimedSize
|
|
533
|
+
? Array.from(claimedPrintSessions).slice(beforeClaimedSize)
|
|
534
|
+
: [];
|
|
535
|
+
const combinedSubAgents = [...(turn.subAgents ?? []), ...printStatuses];
|
|
536
|
+
const hasTableSubAgents = printStatuses.length > 0 || agentChildren(turn.subAgents ?? []).some(child => Boolean(child.usage || childSessionData(child.sessionFile)?.sessionId));
|
|
250
537
|
const agentTurnControls: Array<{ runId: string; y: number; width: number; line: string }> = [];
|
|
251
|
-
const agents = liveAgentView(
|
|
538
|
+
const agents = liveAgentView(combinedSubAgents, theme, width, subExp && hasTableSubAgents, true, agentDeadlines, now, expandedSubagents, agentTurnControls, lang);
|
|
252
539
|
const active = !!turn.running || agents.running > 0 || entries.some(entry => entry.state === "running") || (turn.waitingTools?.length ?? 0) > 0;
|
|
253
|
-
if (active) runningTurns.add(index);
|
|
254
|
-
else if (runningTurns.delete(index)) {
|
|
255
|
-
// Return to the configured preview once; a later click can expand everything again.
|
|
256
|
-
if (agentModes.get(index) === "all") {
|
|
257
|
-
agentModes.set(index, "preview");
|
|
258
|
-
expandedThinking.clear();
|
|
259
|
-
expandedTools.clear();
|
|
260
|
-
expandedSubagents.clear();
|
|
261
|
-
if (pinnedAgentIndex === index) pinnedAgentIndex = undefined;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
540
|
if (entries.length || active || turn.usage || agents.total) {
|
|
265
|
-
const mode = agentModes.get(index) ?? (
|
|
541
|
+
const mode = agentModes.get(index) ?? (exp ? "all" : "preview");
|
|
266
542
|
const expanded = mode === "all";
|
|
267
543
|
const busy = entries.some(entry => entry.state === "running") || (turn.waitingTools?.length ?? 0) > 0;
|
|
268
544
|
const working = turn.running && !busy && !turn.final;
|
|
269
|
-
const showAgentRows = (expanded ||
|
|
545
|
+
const showAgentRows = (Boolean(agents.table) || expanded || subExp) && agents.total > 0;
|
|
270
546
|
// Every child keeps its heading; process records share the remaining preview budget.
|
|
271
|
-
const processLimit = Math.max(0,
|
|
547
|
+
const processLimit = Math.max(0, recLimit - (!agents.table && showAgentRows ? agents.total : 0));
|
|
272
548
|
const shown = expanded ? entries : processLimit ? entries.slice(-processLimit) : [];
|
|
273
549
|
const showWorking = working && (turn.awaitingResponse || expanded || (!shown.length && !agents.total));
|
|
274
|
-
const sparkle = active ? Math.floor(
|
|
550
|
+
const sparkle = active ? Math.floor(now / 360) % 2 ? "✧" : "✦" : "✦";
|
|
275
551
|
const usage = addUsage({ ...EMPTY_USAGE, ...turn.usage, cost: turn.usage?.cost ?? 0 }, turn.pendingUsage);
|
|
276
552
|
const hasUsage = usage.totalTokens > 0 || usage.cacheRead > 0;
|
|
277
553
|
const totals = hasUsage
|
|
278
|
-
? theme.fg("muted",
|
|
279
|
-
+ theme.fg("muted",
|
|
554
|
+
? theme.fg("muted", copy.session) + theme.bold(theme.fg("text", formatTokens(usage.totalTokens)))
|
|
555
|
+
+ theme.fg("muted", copy.cache) + theme.bold(theme.fg("text", formatTokens(usage.cacheRead)))
|
|
280
556
|
: "";
|
|
281
557
|
const recordCount = entries.length + agents.total;
|
|
282
558
|
const progressHeader = theme.fg(active ? "accent" : "muted", sparkle + " ") + theme.bold(theme.fg("text", "Agent")) + theme.fg("muted", recordCount ? ` · ${recordCount}` : "");
|
|
283
559
|
const caret = theme.fg("muted", expanded ? " ▾" : " ▸");
|
|
284
|
-
const elapsedHeader = turn.startedAt == null ? "" : theme.fg("muted", " · ") + theme.fg(active ? "success" : "muted", formatElapsed(turn.startedAt, turn.endedAt ??
|
|
560
|
+
const elapsedHeader = turn.startedAt == null ? "" : theme.fg("muted", " · ") + theme.fg(active ? "success" : "muted", formatElapsed(turn.startedAt, turn.endedAt ?? now));
|
|
285
561
|
const left = progressHeader + elapsedHeader + caret;
|
|
286
|
-
const showTotals = hasUsage &&
|
|
287
|
-
|
|
288
|
-
if (expanded && pinnedAgentIndex === index)
|
|
289
|
-
|
|
562
|
+
const showTotals = hasUsage && usageShown && visibleWidth(left) + 2 + visibleWidth(totals) <= width;
|
|
563
|
+
turnAgentControls.push({ index, y: turnLines.length + 1, width: Math.min(width, visibleWidth(left)) });
|
|
564
|
+
if (expanded && pinnedAgentIndex === index) turnPinnedAgent = { index, y: turnLines.length + 1, line: truncateToWidth(left, width) };
|
|
565
|
+
turnLines.push("", showTotals
|
|
290
566
|
? left + " ".repeat(width - visibleWidth(left) - visibleWidth(totals)) + totals
|
|
291
567
|
: truncateToWidth(left, width));
|
|
292
568
|
shown.forEach((entry, row) => {
|
|
293
|
-
|
|
569
|
+
turnProcessRows.push({ key: entry.id || `${index}:${entry.processIndex}`, y: turnLines.length });
|
|
294
570
|
const title = entry.title;
|
|
295
571
|
const text = title.split(/\r?\n/).find(line => line.trim())?.replace(/\s+/g, " ").trim() ?? "";
|
|
296
572
|
const split = text.indexOf(" ");
|
|
@@ -298,19 +574,19 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
298
574
|
const label = split < 0 ? text : text.slice(0, split);
|
|
299
575
|
const body = split < 0 ? "" : text.slice(split + 1);
|
|
300
576
|
const activeThinking = !!entry.activeThinking;
|
|
301
|
-
const elapsed = entry.thinking ? formatThinkingElapsed(turn, entry.processIndex, activeThinking) : "";
|
|
577
|
+
const elapsed = entry.thinking ? formatThinkingElapsed(turn, entry.processIndex, activeThinking, now) : "";
|
|
302
578
|
const thinkingElapsed = elapsed ? theme.fg(activeThinking ? "success" : "muted", ` ${elapsed}`) : "";
|
|
303
|
-
const call = turn.agentCalls?.find(call => call.id === entry.id && !
|
|
579
|
+
const call = turn.agentCalls?.find(call => call.id === entry.id && !isCapturedCall(call));
|
|
304
580
|
const controlId = call?.id ?? (entry.thinking && !noThinkingBody || entry.id.startsWith("agents:") ? entry.id : "");
|
|
305
581
|
const open = call ? expandedTools.has(call.id) : entry.thinking && !noThinkingBody && expandedThinking.has(entry.id);
|
|
306
582
|
const identity = entry.state === "error" ? "error" : open || activeThinking ? "accent" : "text";
|
|
307
583
|
const duration = call ? formatToolElapsed(call.startedAt,
|
|
308
|
-
call.endedAt ?? (call.state === "running" ?
|
|
584
|
+
call.endedAt ?? (call.state === "running" ? now : undefined)) : "";
|
|
309
585
|
const toolElapsed = duration ? theme.fg(entry.state === "error" ? "error" : call?.state === "running" ? "accent" : "muted", ` ${duration}`) : "";
|
|
310
586
|
const summary = theme.fg(identity, theme.bold(label)) + thinkingElapsed + toolElapsed + " ";
|
|
311
|
-
if (controlId && width >= 4)
|
|
312
|
-
if (hoveredTool?.id === controlId && (hoveredTool.y !==
|
|
313
|
-
const status = entry.state === "error" ? "✕" : entry.state === "running" ? runningGlyph() : "●";
|
|
587
|
+
if (controlId && width >= 4) turnToolControls.push({ id: controlId, y: turnLines.length, width, title: text });
|
|
588
|
+
if (hoveredTool?.id === controlId && (hoveredTool.y !== baseY + turnLines.length || hoveredTool.width !== width)) clearHover();
|
|
589
|
+
const status = entry.state === "error" ? "✕" : entry.state === "running" ? runningGlyph(now) : "●";
|
|
314
590
|
const arrow = !!controlId && (open || hoveredTool?.id === controlId);
|
|
315
591
|
const keepStatus = entry.state === "running" || (open && entry.state === "error");
|
|
316
592
|
const glyph = arrow ? (open ? "▼" : "▶") + (keepStatus ? ` ${status}` : "") : status;
|
|
@@ -323,8 +599,8 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
323
599
|
const indent = visibleWidth(prefix);
|
|
324
600
|
const rail = !last && indent > 0 ? theme.fg("dim", "\u2502") + " ".repeat(indent - 1) : " ".repeat(indent);
|
|
325
601
|
const wrapped = markdown(body, Math.max(1, width - indent), true);
|
|
326
|
-
|
|
327
|
-
for (const extra of wrapped.slice(1))
|
|
602
|
+
turnLines.push(truncateToWidth(prefix + (wrapped[0] ?? ""), width, ""));
|
|
603
|
+
for (const extra of wrapped.slice(1)) turnLines.push(truncateToWidth(rail + extra, width, ""));
|
|
328
604
|
} else {
|
|
329
605
|
const available = Math.max(0, width - visibleWidth(prefix));
|
|
330
606
|
if (entry.thinking) {
|
|
@@ -334,29 +610,27 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
334
610
|
const display = reuse ? cached.text : thinkingPreview(entry.detail, available, previewRows, activeThinking);
|
|
335
611
|
if (!reuse) thinkingPreviews.set(entry.id, { text: display, source: entry.detail, width: available, rows: previewRows, live: activeThinking });
|
|
336
612
|
const outcome = turn.thinkingOutcomes?.[entry.processIndex];
|
|
337
|
-
const fallbackCopy = THINKING_FALLBACK[
|
|
613
|
+
const fallbackCopy = THINKING_FALLBACK[lang];
|
|
338
614
|
const fallback = activeThinking ? fallbackCopy.active
|
|
339
615
|
: outcome === "aborted" ? fallbackCopy.aborted
|
|
340
616
|
: outcome === "error" ? fallbackCopy.error : fallbackCopy.ended;
|
|
341
617
|
const color = entry.state === "error" ? "error" : activeThinking ? "accent" : "muted";
|
|
342
618
|
const rows = available > 0
|
|
343
|
-
?
|
|
344
|
-
{ color: value => theme.fg(color, value) }, (source, avail) => transformText(placeholderText(diagramMarkdown(source, avail))))
|
|
345
|
-
.slice(0, previewRows)
|
|
619
|
+
? thinkingMarkdown(display || fallback, available, color, previewRows)
|
|
346
620
|
: [];
|
|
347
|
-
|
|
621
|
+
turnLines.push(bandHeading(truncateToWidth(prefix + (rows[0] ?? ""), width, ""), open));
|
|
348
622
|
const rail = theme.fg(last ? color : "dim", last ? " " : "│") + " ".repeat(Math.max(0, visibleWidth(prefix) - 1));
|
|
349
|
-
for (const extra of rows.slice(1))
|
|
623
|
+
for (const extra of rows.slice(1)) turnLines.push(truncateToWidth(rail + extra, width, ""));
|
|
350
624
|
} else {
|
|
351
625
|
const displayBody = placeholderText(body);
|
|
352
|
-
const compactBody = linkToolFiles(displayBody,
|
|
626
|
+
const compactBody = linkToolFiles(displayBody, renderCwd, !open);
|
|
353
627
|
const fittedBody = truncateToWidth(compactBody, available, "…");
|
|
354
628
|
// Always close a hyperlink before subsequent rows.
|
|
355
629
|
const styledBody = theme.fg(entry.state === "error" ? "error" : open ? "accent" : "muted", fittedBody + "\x1b]8;;\x07");
|
|
356
|
-
|
|
630
|
+
turnLines.push(bandHeading(truncateToWidth(prefix + styledBody, width, "…"), open));
|
|
357
631
|
}
|
|
358
632
|
}
|
|
359
|
-
if (open && call && call.id === pinnedToolId)
|
|
633
|
+
if (open && call && call.id === pinnedToolId) turnPinnedTool = { id: call.id, y: turnLines.length - 1, line: turnLines.at(-1)! };
|
|
360
634
|
if (open && call) {
|
|
361
635
|
// ponytail: saved text only; native view retains images, args and custom renderers.
|
|
362
636
|
const output = stripVTControlCharacters(call.output ?? "").replace(/\r\n?/g, "\n").replace(/[\x00-\x08\x0b-\x1f\x7f]/g, "");
|
|
@@ -364,36 +638,96 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
364
638
|
const detailWidth = Math.max(1, width - visibleWidth(rail));
|
|
365
639
|
if (call.task && (/\r|\n/.test(call.task) || visibleWidth(call.task) > width - visibleWidth(prefix))) {
|
|
366
640
|
const input = stripVTControlCharacters(call.task).replace(/\r\n?/g, "\n").replace(/[\x00-\x08\x0b-\x1f\x7f]/g, "");
|
|
367
|
-
|
|
368
|
-
|
|
641
|
+
turnLines.push(...new Text(`${copy.inputLabel}\n${input}`, 0, 0).render(detailWidth).map(line => truncateToWidth(rail + theme.fg("muted", line), width, "")));
|
|
642
|
+
turnLines.push(truncateToWidth(rail + theme.fg("muted", copy.outputLabel), width, ""));
|
|
369
643
|
}
|
|
370
|
-
const details = new Text(output || (entry.state === "running" ?
|
|
371
|
-
|
|
644
|
+
const details = new Text(output || (entry.state === "running" ? copy.waitingToolResult : copy.emptyToolResult), 0, 0).render(detailWidth);
|
|
645
|
+
turnLines.push(...details.map(line => truncateToWidth(rail + theme.fg(entry.state === "error" ? "error" : "muted", line), width, "")));
|
|
372
646
|
} else if (open && entry.thinking) {
|
|
373
647
|
const rail = width > 5 ? (last ? " " : theme.fg("accent", "│ ")) : "";
|
|
374
648
|
const detailWidth = Math.max(1, width - visibleWidth(rail));
|
|
375
|
-
|
|
649
|
+
turnLines.push(...markdown(entry.detail, detailWidth, true).map(line => truncateToWidth(rail + line, width, "")));
|
|
376
650
|
}
|
|
377
651
|
});
|
|
378
652
|
if (showAgentRows) {
|
|
379
|
-
const agentStartY =
|
|
653
|
+
const agentStartY = turnLines.length;
|
|
380
654
|
for (const c of agentTurnControls) {
|
|
381
655
|
const control = { ...c, y: agentStartY + c.y };
|
|
382
|
-
|
|
383
|
-
if (c.runId === pinnedSubagentId)
|
|
656
|
+
turnSubagentControls.push(control);
|
|
657
|
+
if (c.runId === pinnedSubagentId) turnPinnedSubagent = { id: c.runId, y: control.y, line: c.line, autoScroll: false };
|
|
384
658
|
}
|
|
385
|
-
|
|
659
|
+
turnLines.push(...agents.rows);
|
|
386
660
|
}
|
|
387
661
|
if (showWorking) {
|
|
388
662
|
const label = turn.awaitingResponse ? "Waiting" : "Working";
|
|
389
|
-
const prefix = theme.fg("dim", "└─ ") + theme.fg("accent", `${runningGlyph()} `) + theme.fg("text", theme.bold(label)) + " ";
|
|
390
|
-
|
|
663
|
+
const prefix = theme.fg("dim", "└─ ") + theme.fg("accent", `${runningGlyph(now)} `) + theme.fg("text", theme.bold(label)) + " ";
|
|
664
|
+
turnLines.push(truncateToWidth(prefix + theme.fg("muted", turn.awaitingResponse ? copy.waitingModel : copy.waitingNextStep), width, ""));
|
|
391
665
|
}
|
|
392
666
|
}
|
|
393
|
-
for (const [replyIndex, reply] of (turn.replies ?? []).entries())
|
|
394
|
-
if (turn.final)
|
|
667
|
+
for (const [replyIndex, reply] of (turn.replies ?? []).entries()) turnLines.push("", ...assistantMarkdown(reply, width, `reply:${index}:${replyIndex}`));
|
|
668
|
+
if (turn.final) turnLines.push("", ...assistantMarkdown(turn.final, width, `final:${index}`));
|
|
669
|
+
return {
|
|
670
|
+
lines: turnLines,
|
|
671
|
+
promptControls: turnPromptControls,
|
|
672
|
+
toolControls: turnToolControls,
|
|
673
|
+
processRows: turnProcessRows,
|
|
674
|
+
agentControls: turnAgentControls,
|
|
675
|
+
subagentControls: turnSubagentControls,
|
|
676
|
+
pinnedTool: turnPinnedTool,
|
|
677
|
+
pinnedAgent: turnPinnedAgent,
|
|
678
|
+
pinnedSubagent: turnPinnedSubagent,
|
|
679
|
+
claimedPrintFiles,
|
|
680
|
+
};
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
for (const [index, turn] of turns.entries()) {
|
|
684
|
+
if (index > 0) lines.push("");
|
|
685
|
+
const baseY = lines.length;
|
|
686
|
+
if (expandedPrompts.has(index) && expandedPrompts.get(index) !== turn.question) expandedPrompts.delete(index);
|
|
687
|
+
const subChildren = turn.subAgents?.length ? agentChildren(turn.subAgents) : [];
|
|
688
|
+
const cheapActive = !!turn.running
|
|
689
|
+
|| (turn.waitingTools?.length ?? 0) > 0
|
|
690
|
+
|| (turn.agentCalls ?? []).some(call => !isAgentTool(call.tool ?? call.name) && call.state === "running")
|
|
691
|
+
|| subChildren.some(isSubAgentChildRunning);
|
|
692
|
+
if (cheapActive) runningTurns.add(index);
|
|
693
|
+
else if (runningTurns.delete(index)) {
|
|
694
|
+
// Return to the configured preview once; a later click can expand everything again.
|
|
695
|
+
if (agentModes.get(index) === "all") {
|
|
696
|
+
agentModes.set(index, "preview");
|
|
697
|
+
expandedThinking.clear();
|
|
698
|
+
expandedTools.clear();
|
|
699
|
+
expandedSubagents.clear();
|
|
700
|
+
if (pinnedAgentIndex === index) pinnedAgentIndex = undefined;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const canCache = !cheapActive && !hasFutureDeadline;
|
|
704
|
+
let rendered: TurnRenderResult | undefined;
|
|
705
|
+
if (canCache) {
|
|
706
|
+
const key = buildTurnKey(index, turn, baseY, subChildren);
|
|
707
|
+
const cached = turnCache.get(index);
|
|
708
|
+
if (cached && keysEqual(cached.key, key)) {
|
|
709
|
+
rendered = cached.value;
|
|
710
|
+
} else {
|
|
711
|
+
rendered = renderTurn(index, turn, baseY);
|
|
712
|
+
turnCache.set(index, { key: buildTurnKey(index, turn, baseY, subChildren), value: rendered });
|
|
713
|
+
}
|
|
714
|
+
} else {
|
|
715
|
+
turnCache.delete(index);
|
|
716
|
+
rendered = renderTurn(index, turn, baseY);
|
|
717
|
+
}
|
|
718
|
+
for (const f of rendered.claimedPrintFiles) claimedPrintSessions.add(f);
|
|
719
|
+
for (const c of rendered.promptControls) promptControls.push({ ...c, y: baseY + c.y });
|
|
720
|
+
for (const c of rendered.toolControls) toolControls.push({ ...c, y: baseY + c.y });
|
|
721
|
+
for (const r of rendered.processRows) processRows.push({ key: r.key, y: baseY + r.y });
|
|
722
|
+
for (const c of rendered.agentControls) agentControls.push({ ...c, y: baseY + c.y });
|
|
723
|
+
for (const c of rendered.subagentControls) subagentControls.push({ ...c, y: baseY + c.y });
|
|
724
|
+
if (rendered.pinnedTool) pinnedTool = { ...rendered.pinnedTool, y: baseY + rendered.pinnedTool.y };
|
|
725
|
+
if (rendered.pinnedAgent) pinnedAgent = { ...rendered.pinnedAgent, y: baseY + rendered.pinnedAgent.y };
|
|
726
|
+
if (rendered.pinnedSubagent) pinnedSubagent = { ...rendered.pinnedSubagent, y: baseY + rendered.pinnedSubagent.y };
|
|
727
|
+
for (const line of rendered.lines) lines.push(line);
|
|
728
|
+
const noticeRows = notices?.get(index) ?? [];
|
|
395
729
|
noticeRegions.push({ y: lines.length, rows: noticeRows });
|
|
396
|
-
lines.push(
|
|
730
|
+
for (const line of noticeRows) lines.push(line);
|
|
397
731
|
}
|
|
398
732
|
if (hoveredTool && !toolControls.some(control => control.id === hoveredTool!.id)) clearHover();
|
|
399
733
|
if (hoveredProcess && !processRows.some(row => row.key === hoveredProcess!.key && row.y === hoveredProcess!.y)) clearHover();
|