pi-subagent-manager 0.11.2 → 0.13.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.
@@ -34,6 +34,7 @@ export interface ManagerSettings {
34
34
  toolFiltering: ToolFilteringMode;
35
35
  widgetMode: WidgetMode;
36
36
  nerdFontIcons: boolean;
37
+ finalRecap: boolean;
37
38
  maxLevels: number;
38
39
  maxConcurrent: number;
39
40
  maxThreads: number;
@@ -49,10 +50,11 @@ export const DEFAULT_MANAGER_SETTINGS: ManagerSettings = {
49
50
  toolFiltering: "allowed",
50
51
  widgetMode: "full",
51
52
  nerdFontIcons: false,
53
+ finalRecap: false,
52
54
  };
53
55
 
54
56
  const KEYS = [
55
- "maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "nerdFontIcons",
57
+ "maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "nerdFontIcons", "finalRecap",
56
58
  ] as const;
57
59
  const MAX_LEVELS = 32;
58
60
 
@@ -90,7 +92,7 @@ function positiveSafeInteger(value: unknown): value is number {
90
92
  }
91
93
 
92
94
  function requirement(key: (typeof KEYS)[number]): string {
93
- if (key === "nerdFontIcons") return "nerdFontIcons must be a boolean";
95
+ if (key === "nerdFontIcons" || key === "finalRecap") return `${key} must be a boolean`;
94
96
  if (key === "subagentMode") return "subagentMode must be off, opportunistic or orchestration";
95
97
  if (key === "widgetMode") return "widgetMode must be full or minimal";
96
98
  if (key === "toolFiltering") return "toolFiltering must be allowed, all-except-blocked or all";
@@ -125,9 +127,9 @@ function parseSettings(content: string): Partial<ManagerSettings> {
125
127
  for (const key of KEYS) {
126
128
  if (!Object.hasOwn(record, key)) continue;
127
129
  const value = record[key];
128
- if (key === "nerdFontIcons") {
130
+ if (key === "nerdFontIcons" || key === "finalRecap") {
129
131
  if (typeof value !== "boolean") throw new Error(requirement(key));
130
- layer.nerdFontIcons = value;
132
+ layer[key] = value;
131
133
  continue;
132
134
  }
133
135
  if (key === "subagentMode") {
package/src/types.ts CHANGED
@@ -20,6 +20,22 @@ export interface AgentType {
20
20
  systemPrompt: string;
21
21
  filePath?: string;
22
22
  source?: "bundled" | "user" | "project";
23
+ /**
24
+ * How this definition is customized relative to its base.
25
+ * - fork: a full `<name>.md` copy (owns the system prompt).
26
+ * - override: a settings-only `<name>.yml` merged on top of the base
27
+ * (no Markdown body; unset fields follow the base).
28
+ * Absent for pure bundled definitions and brand-new drafts.
29
+ */
30
+ customization?: {
31
+ kind: "fork" | "override";
32
+ scope: "user" | "project";
33
+ filePath: string;
34
+ };
35
+ /** Source of the base definition under the customization, if any. */
36
+ baseSource?: "bundled" | "user" | "project";
37
+ /** File path of the base definition under the customization, if any. */
38
+ baseFilePath?: string;
23
39
  }
24
40
  export type ThreadState = "starting" | "running" | "paused" | "completed" | "failed" | "stopped";
25
41
  export interface ThreadView {
@@ -16,6 +16,9 @@ export interface AgentNavigationEditorOptions {
16
16
  /** Must return the whole navigation interaction, so repeated Left cannot reopen it. */
17
17
  openTree(): void | Promise<void>;
18
18
  canOpen(): boolean;
19
+ /** Session-local widget collapse; never saves the configured display mode. */
20
+ collapseWidget?(): void | Promise<void>;
21
+ canCollapse?(): boolean;
19
22
  /** Root ownership token; changing it invalidates queued transitions. */
20
23
  generation(): unknown;
21
24
  onError?(error: unknown): void;
@@ -27,12 +30,12 @@ export interface AgentNavigationEditorOptions {
27
30
  }
28
31
 
29
32
  /**
30
- * Physical Left boundary adapter. It owns no session/history internals and never
33
+ * Physical arrow boundary adapter. It owns no session/history internals and never
31
34
  * changes the draft. Install once per root UI lifecycle, not for tree navigation.
32
35
  * Another custom editor occupies the same host slot; skip installation rather than stack.
33
36
  */
34
37
  export class AgentNavigationEditor extends CustomEditor {
35
- private pending = false;
38
+ private pending: "left" | "right" | undefined;
36
39
  private disposed = false;
37
40
  private dispatchDepth = 0;
38
41
  private inputEpoch = 0;
@@ -59,20 +62,21 @@ export class AgentNavigationEditor extends CustomEditor {
59
62
  this.inputEpoch++;
60
63
  }
61
64
 
62
- private ordinaryLeft(data: string): boolean {
63
- if (!matchesKey(data, Key.left)) return false;
65
+ private ordinaryArrow(data: string, direction: "left" | "right"): boolean {
66
+ if (!matchesKey(data, direction === "left" ? Key.left : Key.right)) return false;
67
+ const action = direction === "left" ? "tui.editor.cursorLeft" : "tui.editor.cursorRight";
64
68
  // Editor uses the global TUI bindings; CustomEditor uses the injected app
65
69
  // manager. Both must agree, and a conflicting remap wins conservatively.
66
70
  for (const keys of [this.navigationKeys, getKeybindings()]) {
67
- if (!keys.matches(data, "tui.editor.cursorLeft")) return false;
68
- for (const action of Object.keys(keys.getResolvedBindings())) {
71
+ if (!keys.matches(data, action)) return false;
72
+ for (const other of Object.keys(keys.getResolvedBindings())) {
69
73
  if (
70
- action !== "tui.editor.cursorLeft" &&
71
- (action.startsWith("tui.editor.") ||
72
- action.startsWith("tui.input.") ||
73
- action.startsWith("tui.altScreen.") ||
74
- action.startsWith("app.")) &&
75
- keys.matches(data, action as Keybinding)
74
+ other !== action &&
75
+ (other.startsWith("tui.editor.") ||
76
+ other.startsWith("tui.input.") ||
77
+ other.startsWith("tui.altScreen.") ||
78
+ other.startsWith("app.")) &&
79
+ keys.matches(data, other as Keybinding)
76
80
  )
77
81
  return false;
78
82
  }
@@ -82,8 +86,9 @@ export class AgentNavigationEditor extends CustomEditor {
82
86
 
83
87
  override handleInput(data: string): void {
84
88
  const outer = this.dispatchDepth === 0;
85
- const left = this.ordinaryLeft(data);
86
- if (outer && !left) this.inputEpoch++;
89
+ const direction = this.ordinaryArrow(data, "left") ? "left"
90
+ : this.ordinaryArrow(data, "right") ? "right" : undefined;
91
+ if (outer && (!direction || (this.pending && this.pending !== direction))) this.inputEpoch++;
87
92
  const previousPaste = this.pastePending;
88
93
  const wasPaste = previousPaste || data.includes("\x1b[200~");
89
94
  // Update before dispatch: Pi recursively sends a suffix after the end
@@ -93,16 +98,20 @@ export class AgentNavigationEditor extends CustomEditor {
93
98
  const wasJump = this.jumpPending;
94
99
  const cursor = this.getCursor();
95
100
  const text = this.getText();
101
+ const lines = text.split("\n");
102
+ const atBoundary = direction === "left"
103
+ ? cursor.line === 0 && cursor.col === 0
104
+ : direction === "right" && cursor.line === lines.length - 1 &&
105
+ cursor.col === lines.at(-1)!.length;
96
106
  const eligible =
97
107
  outer &&
98
- left &&
108
+ direction !== undefined &&
99
109
  this.focused &&
100
110
  !this.disposed &&
101
111
  !wasPaste &&
102
112
  !wasJump &&
103
113
  !this.isShowingAutocomplete() &&
104
- cursor.line === 0 &&
105
- cursor.col === 0;
114
+ atBoundary;
106
115
  const generation = eligible ? this.navigation.generation() : undefined;
107
116
  let changed = false;
108
117
  let consumed = false;
@@ -150,17 +159,21 @@ export class AgentNavigationEditor extends CustomEditor {
150
159
  after.line === cursor.line &&
151
160
  after.col === cursor.col
152
161
  ) {
153
- this.queueOpen(text, cursor, generation);
162
+ this.queueNavigation(text, cursor, generation, direction!);
154
163
  }
155
164
  }
156
165
 
157
- private queueOpen(
166
+ private queueNavigation(
158
167
  text: string,
159
168
  cursor: { line: number; col: number },
160
169
  generation: unknown,
170
+ direction: "left" | "right",
161
171
  ): void {
162
- if (this.pending || !this.navigation.canOpen()) return;
163
- this.pending = true;
172
+ const allowed = () => direction === "left"
173
+ ? this.navigation.canOpen()
174
+ : !!this.navigation.collapseWidget && (this.navigation.canCollapse?.() ?? false);
175
+ if (this.pending || !allowed()) return;
176
+ this.pending = direction;
164
177
  const epoch = this.inputEpoch;
165
178
  queueMicrotask(() => {
166
179
  const after = this.getCursor();
@@ -169,25 +182,26 @@ export class AgentNavigationEditor extends CustomEditor {
169
182
  !this.focused ||
170
183
  this.inputEpoch !== epoch ||
171
184
  this.navigation.generation() !== generation ||
172
- !this.navigation.canOpen() ||
185
+ !allowed() ||
173
186
  this.isShowingAutocomplete() ||
174
187
  this.getText() !== text ||
175
188
  after.line !== cursor.line ||
176
189
  after.col !== cursor.col
177
190
  ) {
178
- this.pending = false;
191
+ this.pending = undefined;
179
192
  return;
180
193
  }
181
194
  try {
182
195
  // Call within the checked microtask: an extra Promise.then would leave
183
196
  // a gap in which root ownership could change after validation.
184
- void Promise.resolve(this.navigation.openTree())
197
+ void Promise.resolve(direction === "left"
198
+ ? this.navigation.openTree() : this.navigation.collapseWidget!())
185
199
  .catch((error: unknown) => this.navigation.onError?.(error))
186
200
  .finally(() => {
187
- this.pending = false;
201
+ this.pending = undefined;
188
202
  });
189
203
  } catch (error) {
190
- this.pending = false;
204
+ this.pending = undefined;
191
205
  this.navigation.onError?.(error);
192
206
  }
193
207
  });
@@ -13,13 +13,17 @@ import {
13
13
  } from "@earendil-works/pi-tui";
14
14
  import type { ThreadService, TranscriptSnapshot } from "../types.ts";
15
15
  import { dialogText, type DialogHost } from "./dialog.ts";
16
- import { agentTypeLabel } from "./ui.ts";
16
+ import { AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeLabel } from "./ui.ts";
17
+
18
+ /** Transcript detail level cycled by the t key: full → preview → compact. */
19
+ export type TranscriptDetail = "full" | "preview" | "compact";
20
+ const DETAIL_CYCLE: TranscriptDetail[] = ["full", "preview", "compact"];
17
21
 
18
22
  export interface AgentViewportState {
19
23
  scrollTop: number;
20
24
  follow: boolean;
21
25
  showInherited?: boolean;
22
- showThinking?: boolean;
26
+ detail?: TranscriptDetail;
23
27
  }
24
28
 
25
29
  /** Fully cover main, including at very small sizes; only trusted renderers emit terminal sequences. */
@@ -60,7 +64,8 @@ export class LiveAgentView {
60
64
  private attachment = 0;
61
65
  private unsubscribe: (() => void) | undefined;
62
66
  private renderTimer: ReturnType<typeof setTimeout> | undefined;
63
- private cache = new WeakMap<object, { width: number; thinking: boolean; lines: string[] }>();
67
+ private progressTimer: ReturnType<typeof setInterval> | undefined;
68
+ private cache = new WeakMap<object, { width: number; detail: TranscriptDetail; lines: string[] }>();
64
69
  private scroll: ScrollView;
65
70
  private content: string[] = [];
66
71
  private restoreViewport = true;
@@ -161,6 +166,7 @@ export class LiveAgentView {
161
166
  } catch (error) {
162
167
  if (this.disposed || attachment !== this.attachment) return;
163
168
  this.error = error instanceof Error ? error.message : String(error);
169
+ this.syncProgress();
164
170
  this.scheduleRender();
165
171
  }
166
172
  }
@@ -175,9 +181,23 @@ export class LiveAgentView {
175
181
  return;
176
182
  this.snapshot = snapshot;
177
183
  this.error = snapshot.error;
184
+ this.syncProgress();
178
185
  this.scheduleRender();
179
186
  }
180
187
 
188
+ private syncProgress(): void {
189
+ const state = this.snapshot?.thread?.state;
190
+ const active = this.nerdFontIcons && !this.disposed && !this.error &&
191
+ (state === "starting" || state === "running");
192
+ if (!active) {
193
+ if (this.progressTimer !== undefined) clearInterval(this.progressTimer);
194
+ this.progressTimer = undefined;
195
+ } else if (this.progressTimer === undefined) {
196
+ this.progressTimer = setInterval(() => this.scheduleRender(), AGENT_PROGRESS_INTERVAL);
197
+ this.progressTimer.unref?.();
198
+ }
199
+ }
200
+
181
201
  private scheduleRender(): void {
182
202
  if (this.disposed || this.renderTimer) return;
183
203
  this.renderTimer = setTimeout(() => {
@@ -200,6 +220,7 @@ export class LiveAgentView {
200
220
  this.unsubscribe = undefined;
201
221
  if (this.renderTimer) clearTimeout(this.renderTimer);
202
222
  this.renderTimer = undefined;
223
+ this.syncProgress();
203
224
  }
204
225
 
205
226
  handleInput(data: string): void {
@@ -235,7 +256,8 @@ export class LiveAgentView {
235
256
  this.viewport.showInherited = !this.viewport.showInherited;
236
257
  this.invalidate();
237
258
  } else if (data === "t") {
238
- this.viewport.showThinking = !this.viewport.showThinking;
259
+ this.viewport.detail =
260
+ DETAIL_CYCLE[(DETAIL_CYCLE.indexOf(this.detail) + 1) % DETAIL_CYCLE.length];
239
261
  this.invalidate();
240
262
  } else if (matchesKey(data, Key.home)) this.scroll.scrollTo(0, { disableFollow: true });
241
263
  else if (matchesKey(data, Key.end) || data === "l") this.scroll.scrollToEnd();
@@ -249,6 +271,10 @@ export class LiveAgentView {
249
271
  this.viewport.follow = this.scroll.isFollowingEnd;
250
272
  }
251
273
 
274
+ private get detail(): TranscriptDetail {
275
+ return this.viewport.detail ?? "preview";
276
+ }
277
+
252
278
  private wrap(value: string, width: number): string[] {
253
279
  return text(value)
254
280
  .split("\n")
@@ -302,26 +328,23 @@ export class LiveAgentView {
302
328
  if (!block) return this.wrap(json(value), width);
303
329
  if (block.type === "text") return this.markdown(String(block.text ?? ""), width);
304
330
  if (block.type === "image") return ["[Image — text-only observer]"];
305
- if (block.type === "thinking")
306
- return this.viewport.showThinking
307
- ? this.markdown(String(block.thinking ?? "[redacted thinking]"), width, true)
308
- : [this.theme.fg("dim", "[Thinking hidden · t show]")];
331
+ if (block.type === "thinking") {
332
+ if (this.detail === "compact")
333
+ return [this.theme.fg("dim", "[Thinking hidden · t cycles view]")];
334
+ // Thinking is model-authored Markdown; preview truncates the rendered lines, not the source.
335
+ const rendered = this.markdown(String(block.thinking ?? "[redacted thinking]"), width, true);
336
+ if (this.detail === "full" || rendered.length <= 3) return rendered;
337
+ return [...rendered.slice(0, 3), this.theme.fg("dim", "...")];
338
+ }
309
339
  if (block.type === "toolCall")
310
- return [
311
- this.theme.fg(
312
- "accent",
313
- dialogText(`Tool call: ${String(block.name)} (${String(block.id)})`),
314
- ),
315
- ...this.preview(json(block.arguments), width),
316
- ];
340
+ return this.toolCall(String(block.name), block.arguments, width);
317
341
  return this.preview(json(block), width);
318
342
  });
319
343
  }
320
344
 
321
345
  private message(message: AgentMessage, width: number): string[] {
322
346
  const cached = this.cache.get(message);
323
- if (cached && cached.width === width && cached.thinking === !!this.viewport.showThinking)
324
- return cached.lines;
347
+ if (cached && cached.width === width && cached.detail === this.detail) return cached.lines;
325
348
  const data = message as unknown as Record<string, unknown>;
326
349
  const label =
327
350
  message.role === "toolResult"
@@ -340,10 +363,112 @@ export class LiveAgentView {
340
363
  : []),
341
364
  "",
342
365
  ];
343
- this.cache.set(message, { width, thinking: !!this.viewport.showThinking, lines });
366
+ this.cache.set(message, { width, detail: this.detail, lines });
344
367
  return lines;
345
368
  }
346
369
 
370
+ /**
371
+ * Pi-style tool call lines, mirroring the main session's built-in renderers (`$ command`,
372
+ * `read path:range`, `grep /pattern/ in path`, …) instead of bare JSON. All interpolated values
373
+ * are sanitized; unknown tools fall back to pretty-printed JSON. Shaped by the detail mode:
374
+ * compact keeps one truncated line, preview keeps three wrapped rows, full keeps everything
375
+ * (bounded by the preview byte cap for pathological payloads).
376
+ */
377
+ private toolCall(name: string, args: unknown, width: number): string[] {
378
+ const data = object(args);
379
+ const str = (key: string): string | undefined => {
380
+ const value = data?.[key];
381
+ return typeof value === "string" ? text(value) : undefined;
382
+ };
383
+ const num = (key: string): number | undefined => {
384
+ const value = data?.[key];
385
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
386
+ };
387
+ const title = (value: string) => this.theme.fg("accent", value);
388
+ const detail = (value: string) => this.theme.fg("muted", value);
389
+ const path = str("file_path") ?? str("path");
390
+ let lines: string[];
391
+ switch (name) {
392
+ case "bash":
393
+ case "powershell": {
394
+ const prompt = name === "bash" ? "$" : ">";
395
+ const command = (str("command") ?? "...").split("\n");
396
+ const timeout = num("timeout");
397
+ lines = [
398
+ `${title(`${prompt} ${command[0]}`)}${timeout ? detail(` (timeout ${timeout}s)`) : ""}`,
399
+ ...command.slice(1),
400
+ ];
401
+ break;
402
+ }
403
+ case "read": {
404
+ const offset = num("offset");
405
+ const limit = num("limit");
406
+ const range =
407
+ offset == null && limit == null
408
+ ? ""
409
+ : this.theme.fg(
410
+ "warning",
411
+ `:${offset ?? 1}${limit != null ? `-${(offset ?? 1) + limit - 1}` : ""}`,
412
+ );
413
+ lines = [`${title("read")} ${path ?? "?"}${range}`];
414
+ break;
415
+ }
416
+ case "edit":
417
+ lines = [`${title("edit")} ${path ?? "?"}`];
418
+ break;
419
+ case "write": {
420
+ lines = [`${title("write")} ${path ?? "?"}`];
421
+ const content = str("content");
422
+ if (content) {
423
+ const contentLines = content.split("\n");
424
+ while (contentLines.length && contentLines.at(-1) === "") contentLines.pop();
425
+ lines.push(...contentLines);
426
+ }
427
+ break;
428
+ }
429
+ case "grep": {
430
+ const pattern = str("pattern");
431
+ const glob = str("glob");
432
+ const limit = num("limit");
433
+ lines = [
434
+ `${title("grep")} ${this.theme.fg("accent", `/${pattern ?? ""}/`)}` +
435
+ `${path ? detail(` in ${path}`) : ""}${glob ? detail(` (${glob})`) : ""}` +
436
+ `${limit != null ? detail(` limit ${limit}`) : ""}`,
437
+ ];
438
+ break;
439
+ }
440
+ case "find": {
441
+ const pattern = str("pattern");
442
+ const limit = num("limit");
443
+ lines = [
444
+ `${title("find")} ${this.theme.fg("accent", pattern ?? "")}` +
445
+ `${path ? detail(` in ${path}`) : ""}${limit != null ? detail(` (limit ${limit})`) : ""}`,
446
+ ];
447
+ break;
448
+ }
449
+ case "ls": {
450
+ const limit = num("limit");
451
+ lines = [`${title("ls")} ${path ?? "."}${limit != null ? detail(` (limit ${limit})`) : ""}`];
452
+ break;
453
+ }
454
+ default:
455
+ lines = [title(dialogText(name)), ...json(args).split("\n")];
456
+ }
457
+ if (this.detail === "compact")
458
+ return [truncateToWidth(lines[0] ?? "", Math.max(1, width), "…", true)];
459
+ const wrapped = lines.flatMap((line) => wrapTextWithAnsi(line, Math.max(1, width)));
460
+ if (this.detail === "preview" && wrapped.length > 3)
461
+ return [...wrapped.slice(0, 3), this.theme.fg("dim", "...")];
462
+ const bounded: string[] = [];
463
+ let chars = 0;
464
+ for (const line of wrapped) {
465
+ if (chars > 32768) return [...bounded, this.theme.fg("dim", "...")];
466
+ bounded.push(line);
467
+ chars += line.length;
468
+ }
469
+ return bounded;
470
+ }
471
+
347
472
  render(width: number): string[] {
348
473
  const height = Math.max(1, this.host.terminal?.rows ?? 24);
349
474
  const columns = Math.max(1, width);
@@ -352,7 +477,7 @@ export class LiveAgentView {
352
477
  const header = this.theme.fg(
353
478
  "accent",
354
479
  dialogText(
355
- `${this.path} · ${agentTypeLabel(thread?.type ?? "agent", thread?.icon, this.nerdFontIcons)} · ${thread?.state ?? "attaching"} — Watching — main continues`,
480
+ `${this.path} · ${agentTypeLabel(thread?.type ?? "agent", thread ? agentProgressIcon(thread, this.nerdFontIcons) : undefined, this.nerdFontIcons)} · ${thread?.state ?? "attaching"} — Watching — main continues`,
356
481
  ),
357
482
  );
358
483
  const body: string[] = [];
@@ -386,16 +511,15 @@ export class LiveAgentView {
386
511
  );
387
512
  for (const tool of snapshot.tools) {
388
513
  if (committedResults.has(tool.toolCallId)) continue;
389
- body.push(
390
- this.theme.fg(
391
- tool.isError ? "error" : "warning",
392
- dialogText(
393
- `Tool ${tool.toolName} — ${tool.state}${tool.isError ? " (error)" : ""}${tool.parentToolCallId ? " (nested)" : ""}`,
394
- ),
514
+ const call = this.toolCall(tool.toolName, tool.args, columns);
515
+ call[0] = `${call[0]} ${this.theme.fg(
516
+ tool.isError ? "error" : "warning",
517
+ dialogText(
518
+ `— ${tool.state}${tool.isError ? " (error)" : ""}${tool.parentToolCallId ? " (nested)" : ""}`,
395
519
  ),
396
- ...this.preview(json(tool.args), columns),
397
- );
398
- if (tool.result !== undefined)
520
+ )}`;
521
+ body.push(...call);
522
+ if (tool.result !== undefined && this.detail !== "compact")
399
523
  body.push(...this.preview(object(tool.result)?.content ?? tool.result, columns));
400
524
  body.push("");
401
525
  }
@@ -421,7 +545,7 @@ export class LiveAgentView {
421
545
  this.saveViewport();
422
546
  const footer = this.error
423
547
  ? "Ctrl+R Retry · Tab input/transcript · Esc tree · Ctrl+Q main"
424
- : `${this.editing ? "Enter steer · Tab browse" : "Tab steer · Home/End scroll · c context · t thinking"} · Esc tree · Ctrl+Q main · ↑↓/PgUp/PgDn scroll · ${this.viewport.follow ? "following" : "scrolled"}`;
548
+ : `${this.editing ? "Enter steer · Tab browse" : `Tab steer · Home/End scroll · c context · t view:${this.detail}`} · Esc tree · Ctrl+Q main · ↑↓/PgUp/PgDn scroll · ${this.viewport.follow ? "following" : "scrolled"}`;
425
549
  const input = this.input.render(columns)[0]!;
426
550
  const status = this.theme.fg(
427
551
  this.steerStatus ? (this.steerFailed ? "error" : "muted") : this.error ? "error" : "muted",
@@ -197,6 +197,12 @@ async function configureAgentsDialog(
197
197
  value: draft.nerdFontIcons ? "On" : "Off",
198
198
  help: "Experimental: display each agent type’s optional icon.\nRequires a Nerd Font configured in your terminal; otherwise glyphs may appear as boxes.\nOff by default. Save and apply to update the widget immediately.",
199
199
  },
200
+ {
201
+ id: "finalRecap",
202
+ label: "[labs] Final Recap",
203
+ value: draft.finalRecap ? "On" : "Off",
204
+ help: "Experimental: when detached agents finish or fail and the main agent is idle, automatically ask the main agent to summarize their results.\nEnabling this may cause extra model turns and uses more tokens and context.\nOff by default. Subagent Mode Off suppresses automatic summaries.",
205
+ },
200
206
  {
201
207
  id: "scope",
202
208
  label: "Save scope",
@@ -280,6 +286,8 @@ async function configureAgentsDialog(
280
286
  draft.widgetMode = mode as WidgetMode;
281
287
  } else if (action === "nerdFontIcons") {
282
288
  draft.nerdFontIcons = !draft.nerdFontIcons;
289
+ } else if (action === "finalRecap") {
290
+ draft.finalRecap = !draft.finalRecap;
283
291
  } else if (action === "scope") {
284
292
  if (!ctx.isProjectTrusted())
285
293
  ctx.ui.notify(
@@ -25,7 +25,9 @@ import {
25
25
  } from "./dialog.ts";
26
26
  import type { ThreadService } from "../types.ts";
27
27
  import { buildStatusTree, type StatusRow } from "./thread-tree.ts";
28
- import { agentTypeBadge, agentTypeLabel, showThreads, threadMetrics } from "./ui.ts";
28
+ import {
29
+ AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeBadge, agentTypeLabel, showThreads, threadMetrics,
30
+ } from "./ui.ts";
29
31
  import { LiveAgentView, fillViewport, type AgentViewportState } from "./live-agent-view.ts";
30
32
 
31
33
  export { buildStatusTree, type StatusRow };
@@ -91,6 +93,8 @@ export class StatusDialog {
91
93
  }
92
94
  private viewport = 1;
93
95
  private timer: ReturnType<typeof setInterval> | undefined;
96
+ private refreshDelay = 0;
97
+ private refreshing = false;
94
98
 
95
99
  constructor(
96
100
  private host: DialogHost,
@@ -111,22 +115,39 @@ export class StatusDialog {
111
115
 
112
116
  invalidate(): void {}
113
117
 
114
- /** Arm the 1s refresh. Host disposal can leave the dialog promise pending. */
118
+ /** Poll retained status, accelerating the existing timer only for animated live agents. */
115
119
  startRefresh(): void {
116
120
  this.stopRefresh();
117
- this.timer = setInterval(() => this.host.requestRender(), 1000);
118
- if (typeof this.timer.unref === "function") this.timer.unref();
121
+ this.refreshing = true;
122
+ this.syncRefresh();
119
123
  }
120
124
 
121
125
  /** Stop the refresh. Safe to call more than once, including from dispose(). */
122
126
  dispose(): void {
127
+ this.refreshing = false;
123
128
  this.stopRefresh();
124
129
  }
125
130
 
131
+ private syncRefresh(): void {
132
+ if (!this.refreshing) return;
133
+ const delay = this.nerdFontIcons && this.service.list().some((thread) =>
134
+ thread.path !== ROOT && (thread.state === "starting" || thread.state === "running"))
135
+ ? AGENT_PROGRESS_INTERVAL : 1000;
136
+ if (this.timer !== undefined && this.refreshDelay === delay) return;
137
+ this.stopRefresh();
138
+ this.refreshDelay = delay;
139
+ this.timer = setInterval(() => {
140
+ this.syncRefresh();
141
+ this.host.requestRender();
142
+ }, delay);
143
+ if (typeof this.timer.unref === "function") this.timer.unref();
144
+ }
145
+
126
146
  private stopRefresh(): void {
127
147
  if (this.timer === undefined) return;
128
148
  clearInterval(this.timer);
129
149
  this.timer = undefined;
150
+ this.refreshDelay = 0;
130
151
  }
131
152
 
132
153
  /** Stop every live agent. Stopping a subtree covers its descendants, so only top-most live paths are sent. */
@@ -247,9 +268,11 @@ export class StatusDialog {
247
268
  const rest = [thread.path, thread.state, thread.status]
248
269
  .map((part) => dialogText(part))
249
270
  .join(" ");
271
+ const badge = agentTypeBadge(thread.type, thread.color, this.theme,
272
+ agentProgressIcon(thread, this.nerdFontIcons), this.nerdFontIcons);
250
273
  if (selected)
251
- return `${this.theme.fg("accent", head)}${agentTypeBadge(thread.type, thread.color, this.theme, thread.icon, this.nerdFontIcons)} ${this.theme.fg("accent", rest)}`;
252
- return `${head}${agentTypeBadge(thread.type, thread.color, this.theme, thread.icon, this.nerdFontIcons)} ${rest}`;
274
+ return `${this.theme.fg("accent", head)}${badge} ${this.theme.fg("accent", rest)}`;
275
+ return `${head}${badge} ${rest}`;
253
276
  }
254
277
 
255
278
  private detail(row: StatusRow | undefined): string[] {
@@ -263,6 +286,7 @@ export class StatusDialog {
263
286
  }
264
287
 
265
288
  render(width: number): string[] {
289
+ this.syncRefresh();
266
290
  const rows = this.rows();
267
291
  const height = this.navigation?.fullscreen
268
292
  ? Math.max(1, this.host.terminal?.rows ?? 24)