pi-subagent-manager 1.10.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +9 -9
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +790 -0
  4. package/dist/orch/checklist-integration.js +176 -0
  5. package/dist/orch/context-entries.js +6 -0
  6. package/dist/orch/cost-ledger.js +38 -0
  7. package/dist/orch/diagnostics.js +86 -0
  8. package/dist/orch/extensions.js +66 -0
  9. package/dist/orch/housekeeping-usage.js +22 -0
  10. package/dist/orch/housekeeping.js +248 -0
  11. package/dist/orch/inherited-tools.js +57 -0
  12. package/dist/orch/mailbox.js +195 -0
  13. package/dist/orch/manager.js +970 -0
  14. package/dist/orch/paths.js +69 -0
  15. package/dist/orch/prompt.js +30 -0
  16. package/dist/orch/registry.js +115 -0
  17. package/dist/orch/runtime.js +835 -0
  18. package/dist/orch/tools.js +112 -0
  19. package/dist/orch/transcript.js +165 -0
  20. package/dist/prefs/agent-import.js +188 -0
  21. package/dist/prefs/config.js +878 -0
  22. package/dist/prefs/import-discovery.js +547 -0
  23. package/{src/prefs/import-instructions.ts → dist/prefs/import-instructions.js} +0 -1
  24. package/dist/prefs/models.js +56 -0
  25. package/dist/prefs/settings.js +491 -0
  26. package/dist/types.js +1 -0
  27. package/dist/ui/agent-loader.js +63 -0
  28. package/dist/ui/agent-navigation-editor.js +168 -0
  29. package/dist/ui/cost-footer.js +209 -0
  30. package/dist/ui/dialog.js +505 -0
  31. package/dist/ui/import-picker.js +191 -0
  32. package/dist/ui/live-agent-view.js +527 -0
  33. package/dist/ui/model-picker.js +529 -0
  34. package/dist/ui/settings-ui.js +671 -0
  35. package/dist/ui/status-ui.js +470 -0
  36. package/dist/ui/thread-tree.js +142 -0
  37. package/dist/ui/tool-picker.js +331 -0
  38. package/dist/ui/transcript-tool.js +91 -0
  39. package/dist/ui/ui.js +1019 -0
  40. package/package.json +17 -5
  41. package/docs/assets/subagent-manager-demo.gif +0 -0
  42. package/docs/async-lifecycle.md +0 -153
  43. package/docs/custom-agents.md +0 -154
  44. package/docs/default-agents.md +0 -95
  45. package/docs/demo.md +0 -63
  46. package/docs/development.md +0 -74
  47. package/docs/importing-agents.md +0 -41
  48. package/docs/pi-footer.md +0 -128
  49. package/docs/research-claude.md +0 -258
  50. package/docs/research-codex.md +0 -143
  51. package/docs/research-default-agent-models.md +0 -121
  52. package/docs/research-model-audit-2026-10.md +0 -154
  53. package/docs/research-model-roles-coding.md +0 -99
  54. package/docs/research-model-roles-writing.md +0 -78
  55. package/docs/research-researcher-workflow.md +0 -97
  56. package/docs/settings.md +0 -293
  57. package/docs/subagent-extension-limitations.md +0 -98
  58. package/docs/threads.md +0 -73
  59. package/docs/tools-and-ui.md +0 -129
  60. package/src/index.ts +0 -920
  61. package/src/orch/checklist-integration.ts +0 -230
  62. package/src/orch/context-entries.ts +0 -15
  63. package/src/orch/cost-ledger.ts +0 -56
  64. package/src/orch/diagnostics.ts +0 -95
  65. package/src/orch/extensions.ts +0 -83
  66. package/src/orch/housekeeping-usage.ts +0 -47
  67. package/src/orch/housekeeping.ts +0 -348
  68. package/src/orch/inherited-tools.ts +0 -84
  69. package/src/orch/mailbox.ts +0 -261
  70. package/src/orch/manager.ts +0 -1084
  71. package/src/orch/paths.ts +0 -73
  72. package/src/orch/prompt.ts +0 -39
  73. package/src/orch/registry.ts +0 -168
  74. package/src/orch/runtime.ts +0 -1041
  75. package/src/orch/tools.ts +0 -190
  76. package/src/orch/transcript.ts +0 -186
  77. package/src/prefs/agent-import.ts +0 -245
  78. package/src/prefs/config.ts +0 -1017
  79. package/src/prefs/import-discovery.ts +0 -643
  80. package/src/prefs/models.ts +0 -74
  81. package/src/prefs/settings.ts +0 -614
  82. package/src/types.ts +0 -271
  83. package/src/ui/agent-loader.ts +0 -98
  84. package/src/ui/agent-navigation-editor.ts +0 -233
  85. package/src/ui/cost-footer.ts +0 -230
  86. package/src/ui/dialog.ts +0 -678
  87. package/src/ui/import-picker.ts +0 -231
  88. package/src/ui/live-agent-view.ts +0 -600
  89. package/src/ui/model-picker.ts +0 -701
  90. package/src/ui/settings-ui.ts +0 -830
  91. package/src/ui/status-ui.ts +0 -628
  92. package/src/ui/thread-tree.ts +0 -173
  93. package/src/ui/tool-picker.ts +0 -398
  94. package/src/ui/transcript-tool.ts +0 -142
  95. package/src/ui/ui.ts +0 -1407
@@ -0,0 +1,527 @@
1
+ import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
2
+ import { Input, Key, Markdown, matchesKey, ScrollView, stripTerminalSequences, truncateToWidth, visibleWidth, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
3
+ import { dialogText } from "./dialog.js";
4
+ import { AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeLabel } from "./ui.js";
5
+ import { renderTranscriptTool } from "./transcript-tool.js";
6
+ const DETAIL_CYCLE = ["full", "preview", "compact"];
7
+ export function fillViewport(lines, width, height) {
8
+ width = Math.max(0, Math.floor(width));
9
+ height = Math.max(1, Math.floor(height));
10
+ const result = lines.slice(0, height).map((line) => {
11
+ const clipped = truncateToWidth(line, width, "", true);
12
+ return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
13
+ });
14
+ while (result.length < height)
15
+ result.push(" ".repeat(width));
16
+ return result;
17
+ }
18
+ function text(value) {
19
+ return stripTerminalSequences(value)
20
+ .replace(/\r\n?/g, "\n")
21
+ .replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "");
22
+ }
23
+ function object(value) {
24
+ return value && typeof value === "object" ? value : undefined;
25
+ }
26
+ function json(value) {
27
+ try {
28
+ return JSON.stringify(value, null, 2) ?? "";
29
+ }
30
+ catch {
31
+ return "[unrenderable data]";
32
+ }
33
+ }
34
+ export class LiveAgentView {
35
+ host;
36
+ theme;
37
+ service;
38
+ path;
39
+ viewport;
40
+ done;
41
+ nerdFontIcons;
42
+ loaderStyle;
43
+ snapshot;
44
+ error;
45
+ disposed = false;
46
+ attachment = 0;
47
+ unsubscribe;
48
+ renderTimer;
49
+ progressTimer;
50
+ cache = new WeakMap();
51
+ scroll;
52
+ content = [];
53
+ restoreViewport = true;
54
+ input = new Input({ prompt: "Steer > " });
55
+ editing = true;
56
+ focusedState = true;
57
+ pasting = false;
58
+ pasteTail = "";
59
+ sending = false;
60
+ steerStatus;
61
+ steerFailed = false;
62
+ results = new Map();
63
+ tools = new Map();
64
+ renderedTools = new Set();
65
+ toolCache = new Map();
66
+ constructor(host, theme, service, path, viewport, done, nerdFontIcons = false, loaderStyle = "circle") {
67
+ this.host = host;
68
+ this.theme = theme;
69
+ this.service = service;
70
+ this.path = path;
71
+ this.viewport = viewport;
72
+ this.done = done;
73
+ this.nerdFontIcons = nerdFontIcons;
74
+ this.loaderStyle = loaderStyle;
75
+ this.scroll = new ScrollView({ render: () => this.content, invalidate() { } }, { follow: "end", overscroll: "contain", scrollbar: "hidden" });
76
+ this.input.focused = true;
77
+ this.input.onSubmit = (value) => void this.steer(value);
78
+ void this.attach();
79
+ }
80
+ get focused() {
81
+ return this.focusedState;
82
+ }
83
+ set focused(value) {
84
+ this.focusedState = value;
85
+ this.input.focused = value && this.editing;
86
+ }
87
+ async steer(value) {
88
+ const message = dialogText(value);
89
+ if (this.disposed || this.sending || !message.trim())
90
+ return;
91
+ this.sending = true;
92
+ this.steerFailed = false;
93
+ this.steerStatus = "Sending steering…";
94
+ this.host.requestRender();
95
+ try {
96
+ await this.service.steer(this.path, message);
97
+ if (this.disposed)
98
+ return;
99
+ if (this.input.getValue() === message)
100
+ this.input.setValue("");
101
+ this.steerStatus = "Steering sent";
102
+ }
103
+ catch (error) {
104
+ if (this.disposed)
105
+ return;
106
+ this.steerFailed = true;
107
+ this.steerStatus = `Steering failed: ${error instanceof Error ? error.message : String(error)}`;
108
+ }
109
+ finally {
110
+ this.sending = false;
111
+ if (!this.disposed)
112
+ this.host.requestRender();
113
+ }
114
+ }
115
+ editInput(data) {
116
+ const pasteData = this.pasteTail + data;
117
+ if (pasteData.includes("\x1b[200~"))
118
+ this.pasting = true;
119
+ if (pasteData.includes("\x1b[201~"))
120
+ this.pasting = false;
121
+ this.pasteTail = this.pasting ? pasteData.slice(-5) : "";
122
+ const before = this.input.getValue();
123
+ this.input.handleInput(data);
124
+ const safe = dialogText(this.input.getValue());
125
+ if (safe !== this.input.getValue())
126
+ this.input.setValue(safe);
127
+ if (safe !== before && !this.sending)
128
+ this.steerStatus = undefined;
129
+ this.host.requestRender();
130
+ }
131
+ async attach() {
132
+ const attachment = ++this.attachment;
133
+ this.unsubscribe?.();
134
+ this.unsubscribe = undefined;
135
+ this.error = undefined;
136
+ this.scheduleRender();
137
+ try {
138
+ if (!this.service.observeTranscript)
139
+ throw new Error("Live observation is unavailable for this service.");
140
+ let latest;
141
+ const observation = await this.service.observeTranscript(this.path, (snapshot) => {
142
+ latest = snapshot;
143
+ if (this.disposed || attachment !== this.attachment)
144
+ return;
145
+ this.accept(snapshot);
146
+ });
147
+ if (this.disposed || attachment !== this.attachment) {
148
+ observation.unsubscribe();
149
+ return;
150
+ }
151
+ this.unsubscribe = observation.unsubscribe;
152
+ this.accept(latest ?? observation.snapshot);
153
+ }
154
+ catch (error) {
155
+ if (this.disposed || attachment !== this.attachment)
156
+ return;
157
+ this.error = error instanceof Error ? error.message : String(error);
158
+ this.syncProgress();
159
+ this.scheduleRender();
160
+ }
161
+ }
162
+ accept(snapshot) {
163
+ if (this.snapshot &&
164
+ (snapshot.generation < this.snapshot.generation ||
165
+ (snapshot.generation === this.snapshot.generation &&
166
+ snapshot.revision < this.snapshot.revision)))
167
+ return;
168
+ if (snapshot.generation !== this.snapshot?.generation)
169
+ this.toolCache.clear();
170
+ this.snapshot = snapshot;
171
+ this.error = snapshot.error;
172
+ this.syncProgress();
173
+ this.scheduleRender();
174
+ }
175
+ syncProgress() {
176
+ const state = this.snapshot?.thread?.state;
177
+ const active = !this.disposed && !this.error && (state === "starting" || state === "running");
178
+ if (!active) {
179
+ if (this.progressTimer !== undefined)
180
+ clearInterval(this.progressTimer);
181
+ this.progressTimer = undefined;
182
+ }
183
+ else if (this.progressTimer === undefined) {
184
+ this.progressTimer = setInterval(() => this.scheduleRender(), AGENT_PROGRESS_INTERVAL);
185
+ this.progressTimer.unref?.();
186
+ }
187
+ }
188
+ scheduleRender() {
189
+ if (this.disposed || this.renderTimer)
190
+ return;
191
+ this.renderTimer = setTimeout(() => {
192
+ this.renderTimer = undefined;
193
+ if (!this.disposed)
194
+ this.host.requestRender();
195
+ }, 16);
196
+ this.renderTimer.unref?.();
197
+ }
198
+ invalidate() {
199
+ this.cache = new WeakMap();
200
+ this.toolCache.clear();
201
+ this.input.invalidate();
202
+ }
203
+ dispose() {
204
+ if (this.disposed)
205
+ return;
206
+ this.disposed = true;
207
+ ++this.attachment;
208
+ this.unsubscribe?.();
209
+ this.unsubscribe = undefined;
210
+ if (this.renderTimer)
211
+ clearTimeout(this.renderTimer);
212
+ this.renderTimer = undefined;
213
+ this.syncProgress();
214
+ }
215
+ handleInput(data) {
216
+ if (this.disposed)
217
+ return;
218
+ if (this.pasting || (this.editing && data.includes("\x1b[200~"))) {
219
+ this.editInput(data);
220
+ return;
221
+ }
222
+ if (matchesKey(data, Key.escape))
223
+ return this.done("back");
224
+ if (matchesKey(data, Key.ctrl("q")) || matchesKey(data, Key.ctrl("c")))
225
+ return this.done("main");
226
+ if (matchesKey(data, Key.ctrl("o"))) {
227
+ this.viewport.detail =
228
+ DETAIL_CYCLE[(DETAIL_CYCLE.indexOf(this.detail) + 1) % DETAIL_CYCLE.length];
229
+ this.invalidate();
230
+ this.host.requestRender();
231
+ return;
232
+ }
233
+ if (matchesKey(data, Key.tab)) {
234
+ this.editing = !this.editing;
235
+ this.input.focused = this.focused && this.editing;
236
+ this.host.requestRender();
237
+ return;
238
+ }
239
+ if (this.error && (matchesKey(data, Key.ctrl("r")) || (!this.editing && data === "r"))) {
240
+ void this.attach();
241
+ return;
242
+ }
243
+ if (matchesKey(data, Key.up))
244
+ this.scroll.scrollBy(-1);
245
+ else if (matchesKey(data, Key.down))
246
+ this.scroll.scrollBy(1);
247
+ else if (matchesKey(data, Key.pageUp))
248
+ this.scroll.scrollBy(-Math.max(1, this.scroll.viewportHeight));
249
+ else if (matchesKey(data, Key.pageDown))
250
+ this.scroll.scrollBy(Math.max(1, this.scroll.viewportHeight));
251
+ else if (this.editing) {
252
+ this.editInput(data);
253
+ return;
254
+ }
255
+ else if (data === "c") {
256
+ this.viewport.showInherited = !this.viewport.showInherited;
257
+ this.invalidate();
258
+ }
259
+ else if (matchesKey(data, Key.home))
260
+ this.scroll.scrollTo(0, { disableFollow: true });
261
+ else if (matchesKey(data, Key.end) || data === "l")
262
+ this.scroll.scrollToEnd();
263
+ else
264
+ return;
265
+ this.saveViewport();
266
+ this.host.requestRender();
267
+ }
268
+ handleMouse(event) {
269
+ if (this.disposed || event.type !== "wheel")
270
+ return undefined;
271
+ const lines = Math.trunc(event.wheelDelta ?? 0);
272
+ if (!Number.isFinite(lines) || lines === 0)
273
+ return undefined;
274
+ this.scroll.scrollBy(lines);
275
+ this.saveViewport();
276
+ return { handled: true, render: true };
277
+ }
278
+ saveViewport() {
279
+ this.viewport.scrollTop = this.scroll.scrollTop;
280
+ this.viewport.follow = this.scroll.isFollowingEnd;
281
+ }
282
+ get detail() {
283
+ return this.viewport.detail ?? "preview";
284
+ }
285
+ pad(lines) {
286
+ return lines.map((line) => ` ${line}`);
287
+ }
288
+ wrap(value, width) {
289
+ return text(value)
290
+ .split("\n")
291
+ .flatMap((line) => wrapTextWithAnsi(line, Math.max(1, width)));
292
+ }
293
+ markdown(value, width, thinking = false) {
294
+ return new Markdown(text(value), 0, 0, getMarkdownTheme(), thinking
295
+ ? { color: (value) => this.theme.fg("thinkingText", value), italic: true }
296
+ : undefined).render(Math.max(1, width));
297
+ }
298
+ preview(content, width, markdown = false) {
299
+ const values = Array.isArray(content) ? content : [content];
300
+ const lines = [];
301
+ const more = this.theme.fg("dim", markdown ? "... (Ctrl+O to expand)" : "...");
302
+ for (const value of values) {
303
+ const block = object(value);
304
+ const valueText = typeof value === "string"
305
+ ? value
306
+ : block?.type === "text"
307
+ ? String(block.text ?? "")
308
+ : block?.type === "image"
309
+ ? "[Image — text-only observer]"
310
+ : json(value);
311
+ const safe = text(valueText);
312
+ const bounded = safe.slice(0, 32768);
313
+ const rendered = markdown ? this.markdown(bounded, width) : bounded.split("\n");
314
+ for (const line of rendered) {
315
+ lines.push(...(markdown ? [line] : wrapTextWithAnsi(line, Math.max(1, width))));
316
+ if (lines.length > 3)
317
+ return [...lines.slice(0, 3), more];
318
+ }
319
+ if (safe.length > bounded.length)
320
+ return [...lines.slice(0, 3), more];
321
+ }
322
+ return lines;
323
+ }
324
+ blocks(content, width) {
325
+ const inner = Math.max(1, width - 2);
326
+ if (!Array.isArray(content))
327
+ return this.pad(this.blockLines(content, inner));
328
+ return content.flatMap((value) => {
329
+ const block = object(value);
330
+ if (block?.type === "toolCall")
331
+ return this.tool(String(block.id), String(block.name), block.arguments, width);
332
+ return this.pad(this.blockLines(value, inner));
333
+ });
334
+ }
335
+ blockLines(value, width) {
336
+ if (typeof value === "string")
337
+ return this.markdown(value, width);
338
+ const block = object(value);
339
+ if (!block)
340
+ return this.wrap(json(value), width);
341
+ if (block.type === "text")
342
+ return this.markdown(String(block.text ?? ""), width);
343
+ if (block.type === "image")
344
+ return ["[Image — text-only observer]"];
345
+ if (block.type === "thinking") {
346
+ if (this.detail === "compact")
347
+ return [this.theme.fg("dim", "[Thinking hidden · Ctrl+O cycles view]")];
348
+ const rendered = this.markdown(String(block.thinking ?? "[redacted thinking]"), width, true);
349
+ if (this.detail === "full" || rendered.length <= 3)
350
+ return rendered;
351
+ return [...rendered.slice(0, 3), this.theme.fg("dim", "...")];
352
+ }
353
+ return this.preview(json(block), width);
354
+ }
355
+ customBlocks(content, width) {
356
+ if (this.detail === "compact")
357
+ return [];
358
+ if (this.detail === "full")
359
+ return this.blocks(content, width);
360
+ return this.pad(this.preview(content, Math.max(1, width - 2), true));
361
+ }
362
+ message(message, width) {
363
+ if (message.role === "toolResult") {
364
+ const result = message;
365
+ return this.tool(String(result.toolCallId), String(result.toolName), {}, width);
366
+ }
367
+ const data = message;
368
+ const hasTools = Array.isArray(data.content) &&
369
+ data.content.some((block) => object(block)?.type === "toolCall");
370
+ const cached = !hasTools && this.cache.get(message);
371
+ if (cached && cached.width === width && cached.detail === this.detail)
372
+ return cached.lines;
373
+ const label = message.role;
374
+ const collapsed = !["user", "assistant", "custom"].includes(message.role);
375
+ const content = data.content ?? data.summary ?? data.output ?? data;
376
+ const inner = Math.max(1, width - 2);
377
+ const heading = this.theme.fg(data.isError ? "error" : "accent", dialogText(label));
378
+ const errors = data.errorMessage
379
+ ? (collapsed
380
+ ? this.preview(String(data.errorMessage), inner)
381
+ : this.wrap(String(data.errorMessage), inner)).map((line) => this.theme.fg("error", line))
382
+ : [];
383
+ const lines = [
384
+ ...this.pad([heading]),
385
+ ...(message.role === "custom"
386
+ ? this.customBlocks(content, width)
387
+ : collapsed
388
+ ? this.pad(this.preview(content, inner))
389
+ : this.blocks(content, width)),
390
+ ...this.pad(errors),
391
+ "",
392
+ ];
393
+ if (!hasTools)
394
+ this.cache.set(message, { width, detail: this.detail, lines });
395
+ return lines;
396
+ }
397
+ tool(id, name, args, width) {
398
+ if (this.renderedTools.has(id))
399
+ return [];
400
+ this.renderedTools.add(id);
401
+ const state = this.tools.get(id);
402
+ const result = this.results.get(id) ?? state?.result;
403
+ const running = !this.results.has(id) && (state ? state.state === "running" : result === undefined);
404
+ const isError = Boolean(object(result)?.isError ?? state?.isError);
405
+ if (state && !Object.keys(object(args) ?? {}).length)
406
+ args = state.args;
407
+ const cached = this.toolCache.get(id);
408
+ let lines;
409
+ if (cached &&
410
+ cached.args === args &&
411
+ cached.result === result &&
412
+ cached.running === running &&
413
+ cached.isError === isError &&
414
+ cached.name === name &&
415
+ cached.width === width &&
416
+ cached.detail === this.detail) {
417
+ lines = cached.lines;
418
+ }
419
+ else {
420
+ lines = renderTranscriptTool(name, id, args, result, isError, running, this.detail, width);
421
+ this.toolCache.set(id, {
422
+ args,
423
+ result,
424
+ running,
425
+ isError,
426
+ name,
427
+ width,
428
+ detail: this.detail,
429
+ lines,
430
+ });
431
+ }
432
+ const nested = [];
433
+ for (const child of this.tools.values()) {
434
+ if (child.parentToolCallId !== id || this.renderedTools.has(child.toolCallId))
435
+ continue;
436
+ nested.push(` ${this.theme.fg("dim", "↳ nested tool")}`, ...this.tool(child.toolCallId, child.toolName, child.args, Math.max(3, width - 2)).map((line) => ` ${line}`));
437
+ }
438
+ return [...lines, ...nested];
439
+ }
440
+ render(width) {
441
+ const height = Math.max(1, this.host.terminal?.rows ?? 24);
442
+ const columns = Math.max(1, width);
443
+ const snapshot = this.snapshot;
444
+ const thread = snapshot?.thread;
445
+ const inner = Math.max(1, columns - 2);
446
+ const header = this.theme.fg("accent", dialogText(`${this.path} · ${agentTypeLabel(thread?.type ?? "agent", thread?.icon, this.nerdFontIcons, thread ? agentProgressIcon(thread, this.nerdFontIcons, Date.now(), true, this.loaderStyle) : undefined)} · ${thread?.state ?? "attaching"} — Watching — main continues`));
447
+ this.results = new Map((snapshot?.messages ?? [])
448
+ .filter((message) => message.role === "toolResult")
449
+ .map((message) => [
450
+ String(message.toolCallId),
451
+ message,
452
+ ]));
453
+ this.tools = new Map((snapshot?.tools ?? []).map((tool) => [tool.toolCallId, tool]));
454
+ this.renderedTools.clear();
455
+ const body = [];
456
+ if (this.error)
457
+ body.push(` ${this.theme.fg("error", dialogText(`Attachment error: ${this.error}`))}`, " Ctrl+R Retry · Esc Back · Ctrl+Q Back to main");
458
+ if (!snapshot) {
459
+ if (!this.error)
460
+ body.push(" Attaching to retained live session…");
461
+ }
462
+ else {
463
+ if (snapshot.inheritedCount)
464
+ body.push(" " +
465
+ this.theme.fg("dim", `${snapshot.inheritedCount} inherited messages ${this.viewport.showInherited ? "shown" : "collapsed"} · c toggle`));
466
+ const start = this.viewport.showInherited ? 0 : snapshot.inheritedCount;
467
+ for (const message of snapshot.messages.slice(start))
468
+ body.push(...this.message(message, columns));
469
+ if (snapshot.assistant)
470
+ body.push(` ${this.theme.fg("warning", "Assistant streaming…")}`, ...this.message(snapshot.assistant, columns));
471
+ for (const tool of snapshot.tools)
472
+ if (!tool.parentToolCallId && !this.results.has(tool.toolCallId))
473
+ body.push(...this.tool(tool.toolCallId, tool.toolName, tool.args, columns));
474
+ for (const tool of snapshot.tools)
475
+ if (!this.renderedTools.has(tool.toolCallId) && !this.results.has(tool.toolCallId))
476
+ body.push(...this.tool(tool.toolCallId, tool.toolName, tool.args, columns));
477
+ for (const id of this.toolCache.keys())
478
+ if (!this.renderedTools.has(id))
479
+ this.toolCache.delete(id);
480
+ if (!body.length)
481
+ body.push(thread?.state === "starting"
482
+ ? " Starting — waiting for transcript attachment…"
483
+ : " No retained messages yet.");
484
+ }
485
+ this.content = body;
486
+ const bodyHeight = Math.max(0, height - 4);
487
+ this.scroll.updateLayout(body.length, bodyHeight, () => this.scheduleRender());
488
+ if (this.restoreViewport) {
489
+ if (this.viewport.follow)
490
+ this.scroll.scrollToEnd();
491
+ else
492
+ this.scroll.scrollTo(this.viewport.scrollTop, { disableFollow: true });
493
+ this.restoreViewport = false;
494
+ }
495
+ const visible = this.scroll
496
+ .render(columns)
497
+ .slice(this.scroll.scrollTop, this.scroll.scrollTop + bodyHeight);
498
+ while (visible.length < bodyHeight)
499
+ visible.push("");
500
+ this.saveViewport();
501
+ const footer = this.error
502
+ ? "Ctrl+R Retry · Tab input/transcript · Esc tree · Ctrl+Q main"
503
+ : `${this.editing ? "Enter steer · Tab browse" : "Tab steer · Home/End scroll · c context"} · Ctrl+O view:${this.detail} · Esc tree · Ctrl+Q main · ↑↓/PgUp/PgDn scroll · ${this.viewport.follow ? "following" : "scrolled"}`;
504
+ const input = ` ${this.input.render(inner)[0]}`;
505
+ const status = this.theme.fg(this.steerStatus ? (this.steerFailed ? "error" : "muted") : this.error ? "error" : "muted", dialogText(this.steerStatus ??
506
+ (this.error
507
+ ? `Attachment error: ${this.error}`
508
+ : thread
509
+ ? `${thread.task} · ${thread.status}`
510
+ : "Live transcript · Enter to steer")));
511
+ const chrome = (line) => ` ${truncateToWidth(line, inner, "")}`;
512
+ const lines = height === 1
513
+ ? [input]
514
+ : height === 2
515
+ ? [chrome(header), input]
516
+ : height === 3
517
+ ? [chrome(header), chrome(this.theme.fg("dim", footer)), input]
518
+ : [
519
+ chrome(header),
520
+ chrome(status),
521
+ ...visible,
522
+ chrome(this.theme.fg("dim", footer)),
523
+ input,
524
+ ];
525
+ return fillViewport(lines, width, height);
526
+ }
527
+ }