@xzzpig/pi-subagents 0.2.0 → 0.4.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 (103) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/README.md +2 -0
  3. package/agents/oracle.md +7 -5
  4. package/agents/researcher.md +1 -1
  5. package/agents/reviewer.md +2 -2
  6. package/agents/scout.md +1 -1
  7. package/agents/worker.md +1 -1
  8. package/docs/agents.md +3 -0
  9. package/docs/configuration.md +121 -10
  10. package/docs/extension-api.md +36 -0
  11. package/docs/missions.md +5 -3
  12. package/docs/observability.md +43 -3
  13. package/docs/tool-reference.md +20 -3
  14. package/docs/workflows.md +2 -2
  15. package/package.json +4 -4
  16. package/skills/pi-subagents/references/constraints-and-recipes.md +3 -2
  17. package/skills/pi-subagents/references/execution-controls.md +5 -4
  18. package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
  19. package/skills/pi-subagents/references/prompting-and-roles.md +31 -15
  20. package/src/agents/agent-serializer.ts +2 -0
  21. package/src/agents/agents.ts +46 -15
  22. package/src/api/external-runs.ts +174 -84
  23. package/src/api/preflight.ts +13 -7
  24. package/src/extension/config.ts +59 -0
  25. package/src/extension/doctor.ts +40 -0
  26. package/src/extension/index.ts +83 -9
  27. package/src/extension/public-execution.ts +37 -4
  28. package/src/extension/rpc.ts +8 -10
  29. package/src/extension/schemas.ts +12 -10
  30. package/src/extension/tool-description.ts +13 -9
  31. package/src/inspectors/herdr/actions.ts +13 -8
  32. package/src/inspectors/herdr/inspector-runner.ts +16 -3
  33. package/src/inspectors/herdr/project-panes.ts +2 -6
  34. package/src/inspectors/herdr/shell-command.ts +16 -0
  35. package/src/intercom/intercom-bridge.ts +9 -5
  36. package/src/intercom/native-supervisor-channel.ts +19 -42
  37. package/src/missions/goal-driver.ts +3 -1
  38. package/src/missions/lifecycle.ts +4 -7
  39. package/src/missions/store.ts +12 -7
  40. package/src/missions/workflow-state.ts +6 -2
  41. package/src/runs/background/active-async-capacity.ts +431 -0
  42. package/src/runs/background/active-run-index.ts +77 -3
  43. package/src/runs/background/async-execution.ts +190 -72
  44. package/src/runs/background/async-job-tracker.ts +5 -0
  45. package/src/runs/background/async-resume.ts +21 -7
  46. package/src/runs/background/async-status-snapshot.ts +277 -0
  47. package/src/runs/background/async-status.ts +17 -6
  48. package/src/runs/background/chain-append.ts +33 -15
  49. package/src/runs/background/chain-root-attachment.ts +2 -2
  50. package/src/runs/background/completion-replay.ts +11 -1
  51. package/src/runs/background/fleet-view.ts +21 -6
  52. package/src/runs/background/owned-process-tree.ts +104 -0
  53. package/src/runs/background/process-terminal.ts +17 -3
  54. package/src/runs/background/result-files.ts +437 -0
  55. package/src/runs/background/result-watcher.ts +188 -41
  56. package/src/runs/background/resume-guidance.ts +27 -7
  57. package/src/runs/background/retained-children.ts +75 -18
  58. package/src/runs/background/run-id-resolver.ts +30 -24
  59. package/src/runs/background/run-status.ts +106 -5
  60. package/src/runs/background/scheduled-runs.ts +54 -28
  61. package/src/runs/background/stale-run-reconciler.ts +30 -16
  62. package/src/runs/background/subagent-runner.ts +352 -62
  63. package/src/runs/background/subagent-wait.ts +2 -0
  64. package/src/runs/background/wait-completions.ts +5 -2
  65. package/src/runs/foreground/async-dismiss-action.ts +2 -1
  66. package/src/runs/foreground/chain-execution.ts +53 -2
  67. package/src/runs/foreground/execution.ts +309 -34
  68. package/src/runs/foreground/foreground-control.ts +12 -0
  69. package/src/runs/foreground/prompt-audit.ts +172 -0
  70. package/src/runs/foreground/subagent-executor.ts +936 -224
  71. package/src/runs/shared/acceptance.ts +13 -4
  72. package/src/runs/shared/completion-guard.ts +107 -1
  73. package/src/runs/shared/external-cli-runner.ts +4 -0
  74. package/src/runs/shared/llm-intent-arbiter.ts +302 -0
  75. package/src/runs/shared/model-fallback.ts +16 -2
  76. package/src/runs/shared/nested-events.ts +66 -62
  77. package/src/runs/shared/orca-progress-tabs.ts +375 -0
  78. package/src/runs/shared/parallel-utils.ts +4 -0
  79. package/src/runs/shared/pi-args.ts +44 -1
  80. package/src/runs/shared/run-fanout-budget.ts +280 -0
  81. package/src/runs/shared/single-output.ts +4 -2
  82. package/src/runs/shared/subagent-control.ts +15 -0
  83. package/src/runs/shared/subagent-prompt-runtime.ts +1 -9
  84. package/src/runs/shared/subagent-startup-retry.ts +12 -0
  85. package/src/runs/shared/task-intent.ts +19 -3
  86. package/src/runs/shared/tool-timeout.ts +93 -0
  87. package/src/runs/shared/worktree.ts +17 -5
  88. package/src/shared/agent-stream-options.ts +5 -0
  89. package/src/shared/artifacts.ts +2 -6
  90. package/src/shared/display-text.ts +50 -0
  91. package/src/shared/node-executable.ts +21 -0
  92. package/src/shared/types.ts +143 -5
  93. package/src/shared/utils.ts +3 -1
  94. package/src/slash/slash-commands.ts +34 -25
  95. package/src/slash/slash-live-state.ts +3 -0
  96. package/src/tui/fleet-status.ts +164 -47
  97. package/src/tui/fleet-transcript.ts +1 -48
  98. package/src/tui/fleet.ts +352 -27
  99. package/src/tui/render.ts +122 -44
  100. package/src/watchdog/permission-arbiter.ts +2 -1
  101. package/src/watchdog/review.ts +4 -3
  102. package/src/workflows/chat-progress.ts +10 -2
  103. package/src/workflows/scripted-workflow.ts +292 -79
@@ -1,12 +1,13 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { type EditorComponent, isKeyRelease, Key, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
3
+ import { snapshotExternalRuns } from "../api/external-runs.ts";
3
4
  import { formatModelThinking } from "../shared/formatters.ts";
4
5
  import type { AsyncJobStep, FleetViewPlacement, NestedRunSummary, NestedStepSummary, SubagentState } from "../shared/types.ts";
5
6
  import { formatWorkflowJsonPreview } from "../workflows/scripted-workflow.ts";
6
7
 
7
8
  export const FLEET_STATUS_WIDGET_KEY = "subagent-fleet-status";
8
9
 
9
- // Six rows fit the accepted collapsed hierarchy: one owner, four direct leaves, and overflow.
10
+ // Six rows fit the accepted collapsed hierarchy: one owner, four visible descendants, and overflow.
10
11
  const MAX_AGENT_ROWS = 6;
11
12
  const REFRESH_MS = 500;
12
13
 
@@ -16,12 +17,15 @@ type FleetStatusTui = {
16
17
  };
17
18
  type FleetStatusEntry = {
18
19
  key: string;
20
+ parentKey?: string;
21
+ workflowWrapper?: boolean;
19
22
  agent: string;
20
23
  modelThinking?: string;
21
24
  description?: string;
22
25
  startedAt: number;
23
26
  tokens: number;
24
27
  state: string;
28
+ external?: true;
25
29
  nestedChildren?: NestedRunSummary[];
26
30
  };
27
31
 
@@ -31,11 +35,13 @@ type FleetNestedRow = {
31
35
  modelThinking?: string;
32
36
  activity?: string;
33
37
  startedAt?: number;
38
+ depth: number;
34
39
  overflow?: number;
35
40
  };
36
41
 
37
42
  type FleetTreeRow =
38
43
  | { kind: "owner"; entry: FleetStatusEntry }
44
+ | { kind: "child"; entry: FleetStatusEntry; last: boolean }
39
45
  | { kind: "nested"; ownerKey: string; row: FleetNestedRow; last: boolean };
40
46
 
41
47
  export interface FleetStatusOptions {
@@ -94,44 +100,112 @@ function nestedStatusGlyph(state: FleetNestedRow["state"], theme: Theme): string
94
100
  return theme.fg("warning", "■");
95
101
  }
96
102
 
97
- function nestedFleetRows(children: NestedRunSummary[] | undefined): FleetNestedRow[] {
98
- const rows: FleetNestedRow[] = [];
99
- for (const child of children ?? []) {
103
+ function nestedStepDisplayCount(steps: NestedStepSummary[] | undefined, start = 0): number {
104
+ let count = 0;
105
+ for (let index = start; index < (steps?.length ?? 0); index++) {
106
+ count += 1 + nestedDisplayCount(steps![index]!.children);
107
+ }
108
+ return count;
109
+ }
110
+
111
+ function nestedDisplayCount(children: NestedRunSummary[] | undefined, start = 0): number {
112
+ let count = 0;
113
+ for (let index = start; index < (children?.length ?? 0); index++) {
114
+ const child = children![index]!;
100
115
  const steps = (child.mode === "parallel" || child.mode === "chain") ? child.steps ?? [] : [];
101
- if (steps.length > 0) {
102
- for (const step of steps) {
103
- const modelThinking = formatModelThinking(step.model, step.thinking) || undefined;
104
- const activity = nestedActivity(step);
116
+ count += steps.length > 0 ? nestedStepDisplayCount(steps) : 1;
117
+ count += nestedDisplayCount(child.children);
118
+ }
119
+ return count;
120
+ }
121
+
122
+ function nestedFleetRows(children: NestedRunSummary[] | undefined, visibleLimit: number): FleetNestedRow[] {
123
+ const rows: FleetNestedRow[] = [];
124
+ let omitted = 0;
125
+ const appendRuns = (runs: NestedRunSummary[] | undefined, depth: number): boolean => {
126
+ for (let runIndex = 0; runIndex < (runs?.length ?? 0); runIndex++) {
127
+ const child = runs![runIndex]!;
128
+ const steps = (child.mode === "parallel" || child.mode === "chain") ? child.steps ?? [] : [];
129
+ if (steps.length > 0) {
130
+ for (let stepIndex = 0; stepIndex < steps.length; stepIndex++) {
131
+ if (rows.length >= visibleLimit) {
132
+ omitted += nestedStepDisplayCount(steps, stepIndex);
133
+ omitted += nestedDisplayCount(child.children);
134
+ omitted += nestedDisplayCount(runs, runIndex + 1);
135
+ return false;
136
+ }
137
+ const step = steps[stepIndex]!;
138
+ const modelThinking = formatModelThinking(step.model, step.thinking) || undefined;
139
+ const activity = nestedActivity(step);
140
+ rows.push({
141
+ name: step.agent,
142
+ state: step.status,
143
+ depth,
144
+ ...(modelThinking ? { modelThinking } : {}),
145
+ ...(activity ? { activity } : {}),
146
+ ...(step.startedAt !== undefined ? { startedAt: step.startedAt } : {}),
147
+ });
148
+ if (!appendRuns(step.children, depth + 1)) {
149
+ omitted += nestedStepDisplayCount(steps, stepIndex + 1);
150
+ omitted += nestedDisplayCount(child.children);
151
+ omitted += nestedDisplayCount(runs, runIndex + 1);
152
+ return false;
153
+ }
154
+ }
155
+ } else {
156
+ if (rows.length >= visibleLimit) {
157
+ omitted += nestedDisplayCount(runs, runIndex);
158
+ return false;
159
+ }
160
+ const modelThinking = formatModelThinking(child.model, child.thinking) || undefined;
161
+ const activity = nestedActivity(child);
105
162
  rows.push({
106
- name: step.agent,
107
- state: step.status,
163
+ name: nestedRunLabel(child),
164
+ state: child.state,
165
+ depth,
108
166
  ...(modelThinking ? { modelThinking } : {}),
109
167
  ...(activity ? { activity } : {}),
110
- ...(step.startedAt !== undefined ? { startedAt: step.startedAt } : {}),
168
+ ...(child.startedAt !== undefined ? { startedAt: child.startedAt } : {}),
111
169
  });
112
170
  }
113
- continue;
171
+ if (!appendRuns(child.children, depth + 1)) {
172
+ omitted += nestedDisplayCount(runs, runIndex + 1);
173
+ return false;
174
+ }
114
175
  }
115
- const modelThinking = formatModelThinking(child.model, child.thinking) || undefined;
116
- const activity = nestedActivity(child);
117
- rows.push({
118
- name: nestedRunLabel(child),
119
- state: child.state,
120
- ...(modelThinking ? { modelThinking } : {}),
121
- ...(activity ? { activity } : {}),
122
- ...(child.startedAt !== undefined ? { startedAt: child.startedAt } : {}),
123
- });
124
- }
125
- const visible = rows.slice(0, 4);
126
- if (rows.length > visible.length) visible.push({ name: `… +${rows.length - visible.length} more nested leaves`, state: "complete", overflow: rows.length - visible.length });
127
- return visible;
176
+ return true;
177
+ };
178
+ appendRuns(children, 0);
179
+ if (omitted > 0) rows.push({ name: `… +${omitted} more nested leaves`, state: "complete", depth: 0, overflow: omitted });
180
+ return rows;
128
181
  }
129
182
 
130
183
  function fleetTreeRows(entries: FleetStatusEntry[]): FleetTreeRow[] {
131
184
  const rows: FleetTreeRow[] = [];
185
+ const entryKeys = new Set(entries.map((entry) => entry.key));
186
+ const childrenByParent = new Map<string, FleetStatusEntry[]>();
187
+ for (const entry of entries) {
188
+ if (!entry.parentKey || !entryKeys.has(entry.parentKey)) continue;
189
+ const children = childrenByParent.get(entry.parentKey) ?? [];
190
+ children.push(entry);
191
+ childrenByParent.set(entry.parentKey, children);
192
+ }
132
193
  for (const entry of entries) {
194
+ if (entry.parentKey && entryKeys.has(entry.parentKey)) continue;
133
195
  rows.push({ kind: "owner", entry });
134
- const nested = nestedFleetRows(entry.nestedChildren);
196
+ const attached = childrenByParent.get(entry.key) ?? [];
197
+ for (const [index, child] of attached.entries()) {
198
+ const nested = nestedFleetRows(child.nestedChildren, 3);
199
+ const laterRows = index < attached.length - 1 || Boolean(entry.nestedChildren?.length);
200
+ rows.push({ kind: "child", entry: child, last: !laterRows && nested.length === 0 });
201
+ for (const [nestedIndex, row] of nested.entries()) rows.push({
202
+ kind: "nested",
203
+ ownerKey: child.key,
204
+ row: { ...row, depth: row.depth + 1 },
205
+ last: nestedIndex === nested.length - 1 && !laterRows,
206
+ });
207
+ }
208
+ const nested = nestedFleetRows(entry.nestedChildren, attached.length > 0 ? 3 : 4);
135
209
  for (const [index, row] of nested.entries()) rows.push({ kind: "nested", ownerKey: entry.key, row, last: index === nested.length - 1 });
136
210
  }
137
211
  return rows;
@@ -150,14 +224,24 @@ function foregroundDescription(control: { parentWorkflowRunId?: string; workflow
150
224
  return description ? `${workflow} · ${description}` : workflow;
151
225
  }
152
226
 
227
+ function activeLeafAgentCount(entries: FleetStatusEntry[]): number {
228
+ return entries.filter((entry) => !entry.workflowWrapper).length;
229
+ }
230
+
153
231
  export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntry[] {
154
232
  const entries: FleetStatusEntry[] = [];
233
+ const activeWorkflowKeys = new Set([...state.asyncJobs.values()]
234
+ .filter((job) => job.mode === "workflow" && isActiveState(job.status))
235
+ .map((job) => `async:${job.asyncId}`));
155
236
  for (const control of state.foregroundControls.values()) {
237
+ const parentKey = control.parentWorkflowRunId ? `async:${control.parentWorkflowRunId}` : undefined;
238
+ const linkedParentKey = parentKey && activeWorkflowKeys.has(parentKey) ? parentKey : undefined;
156
239
  if (control.activeChildren) {
157
240
  for (const child of [...control.activeChildren.values()].sort((left, right) => left.index - right.index)) {
158
241
  const modelThinking = formatModelThinking(child.model, child.thinking) || undefined;
159
242
  entries.push({
160
243
  key: `foreground-active:${control.runId}:${child.index}`,
244
+ ...(linkedParentKey ? { parentKey: linkedParentKey } : {}),
161
245
  agent: child.agent,
162
246
  ...(modelThinking ? { modelThinking } : {}),
163
247
  description: foregroundDescription(control, child.description),
@@ -174,6 +258,7 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
174
258
  const modelThinking = formatModelThinking(control.model, control.thinking) || undefined;
175
259
  entries.push({
176
260
  key: `foreground-active:${control.runId}:${control.currentIndex ?? 0}`,
261
+ ...(linkedParentKey ? { parentKey: linkedParentKey } : {}),
177
262
  agent: control.currentAgent ?? control.mode,
178
263
  ...(modelThinking ? { modelThinking } : {}),
179
264
  description: foregroundDescription(control, control.description),
@@ -191,6 +276,7 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
191
276
  const latestEmit = job.workflow?.emits?.length ? formatWorkflowJsonPreview(job.workflow.emits.at(-1), 120) : undefined;
192
277
  entries.push({
193
278
  key: `async:${job.asyncId}`,
279
+ workflowWrapper: true,
194
280
  agent: "workflow",
195
281
  description: latestEmit !== undefined ? `latest emit: ${latestEmit}` : job.description,
196
282
  startedAt,
@@ -241,6 +327,25 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
241
327
  }
242
328
  }
243
329
 
330
+ if (state.currentSessionId) {
331
+ try {
332
+ for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => console.warn(`[pi-subagents] Removed ${message}`) })) {
333
+ if (!isActiveState(run.state)) continue;
334
+ entries.push({
335
+ key: `external:${run.id}`,
336
+ agent: `external · ${run.label}`,
337
+ description: run.currentAction ?? `source: ${run.source}`,
338
+ startedAt: run.startedAt,
339
+ tokens: 0,
340
+ state: run.state,
341
+ external: true,
342
+ });
343
+ }
344
+ } catch (cause) {
345
+ console.warn(`[pi-subagents] Failed to inspect external jobs: ${cause instanceof Error ? cause.message : String(cause)}`);
346
+ }
347
+ }
348
+
244
349
  return entries.sort((left, right) => left.startedAt - right.startedAt || left.key.localeCompare(right.key));
245
350
  }
246
351
 
@@ -318,7 +423,7 @@ export class SubagentFleetStatus {
318
423
  this.clearWidget();
319
424
  return;
320
425
  }
321
- if (this.entries.length === 0) {
426
+ if (this.entries.length === 0 && !(this.state.activeAsyncCapacity?.used)) {
322
427
  this.active = false;
323
428
  this.selectedKey = "main";
324
429
  this.lastRenderKey = "";
@@ -413,11 +518,19 @@ export class SubagentFleetStatus {
413
518
  }
414
519
 
415
520
  render(width: number, theme: Theme): string[] {
416
- if (this.entries.length === 0) return [];
521
+ if (this.entries.length === 0 && !(this.state.activeAsyncCapacity?.used)) return [];
417
522
  if (!this.active) {
418
523
  const tokens = this.entries.reduce((total, entry) => total + entry.tokens, 0);
419
- const label = `${this.entries.length} active ${this.entries.length === 1 ? "agent" : "agents"}`;
420
- return [truncateToWidth(` ${theme.fg("muted", label)} · ${theme.fg("dim", `${formatFleetTokens(tokens)} · ↓/← to inspect`)}`, width)];
524
+ const capacity = this.state.activeAsyncCapacity;
525
+ const hasNativeRows = this.entries.some((entry) => !entry.external);
526
+ const showNativeSummary = hasNativeRows || Boolean(capacity?.used);
527
+ const asyncRuns = capacity && showNativeSummary ? `Async runs ${capacity.used}/${capacity.limit || "∞"}` : "";
528
+ const activeEntries = activeLeafAgentCount(this.entries);
529
+ const noun = this.entries.some((entry) => entry.external) ? "job" : "agent";
530
+ const agents = activeEntries > 0 ? `${activeEntries} active ${noun}${activeEntries === 1 ? "" : "s"}` : "";
531
+ const label = [agents, asyncRuns].filter(Boolean).join(" · ");
532
+ const detail = [showNativeSummary ? formatFleetTokens(tokens) : undefined, "↓/← to inspect"].filter(Boolean).join(" · ");
533
+ return [truncateToWidth(` ${theme.fg("muted", label)} · ${theme.fg("dim", detail)}`, width)];
421
534
  }
422
535
  const roster = this.rosterKeys();
423
536
  const selectedIndex = Math.max(0, roster.indexOf(this.selectedKey));
@@ -425,16 +538,16 @@ export class SubagentFleetStatus {
425
538
  lines.push(truncateToWidth(` ${this.bullet(0, selectedIndex, theme)} main`, width));
426
539
 
427
540
  const tree = fleetTreeRows(this.entries);
428
- const selectedTreeIndex = Math.max(0, tree.findIndex((row) => row.kind === "owner" && row.entry.key === this.selectedKey));
541
+ const selectedTreeIndex = Math.max(0, tree.findIndex((row) => (row.kind === "owner" || row.kind === "child") && row.entry.key === this.selectedKey));
429
542
  const visibleCount = Math.min(this.maxAgentRows, tree.length);
430
543
  const start = selectedTreeIndex < visibleCount ? 0 : selectedTreeIndex - visibleCount + 1;
431
544
  const hiddenBelow = tree.length - (start + visibleCount);
432
545
  if (start > 0) lines.push(rightAlign("", theme.fg("dim", `↑ ${start} more`), width));
433
546
  for (let index = start; index < start + visibleCount; index++) {
434
547
  const row = tree[index]!;
435
- if (row.kind === "owner") {
548
+ if (row.kind === "owner" || row.kind === "child") {
436
549
  const ownerIndex = this.entries.findIndex((entry) => entry.key === row.entry.key);
437
- lines.push(this.renderEntry(ownerIndex + 1, selectedIndex, row.entry, width, theme));
550
+ lines.push(this.renderEntry(ownerIndex + 1, selectedIndex, row.entry, width, theme, row.kind === "child" ? (row.last ? "└─" : "├─") : undefined));
438
551
  } else {
439
552
  lines.push(this.renderNestedRow(row.row, row.last, width, theme));
440
553
  }
@@ -443,21 +556,22 @@ export class SubagentFleetStatus {
443
556
  return lines;
444
557
  }
445
558
 
446
- private renderEntry(rosterIndex: number, selectedIndex: number, entry: FleetStatusEntry, width: number, theme: Theme): string {
447
- const description = entry.description?.replace(/\s+/g, " ").trim();
559
+ private renderEntry(rosterIndex: number, selectedIndex: number, entry: FleetStatusEntry, width: number, theme: Theme, branch?: string): string {
448
560
  const agent = entry.modelThinking ? `${entry.agent} (${entry.modelThinking})` : entry.agent;
449
- const left = ` ${this.bullet(rosterIndex, selectedIndex, theme)} ${theme.fg("muted", agent)} · ${entry.state}${description ? ` ${description}` : ""}`;
561
+ const prefix = branch ? ` ${branch}` : " ";
562
+ const left = `${prefix} ${this.bullet(rosterIndex, selectedIndex, theme)} ${theme.fg("muted", agent)} · ${entry.state}`;
450
563
  const elapsed = Date.now() - entry.startedAt;
451
- const right = theme.fg("dim", `${formatFleetElapsed(elapsed)} · ${formatFleetTokens(entry.tokens)}`);
564
+ const right = theme.fg("dim", entry.external ? formatFleetElapsed(elapsed) : `${formatFleetElapsed(elapsed)} · ${formatFleetTokens(entry.tokens)}`);
452
565
  return rightAlign(left, right, width);
453
566
  }
454
567
 
455
568
  private renderNestedRow(row: FleetNestedRow, last: boolean, width: number, theme: Theme): string {
456
569
  const marker = last ? "└─" : "├─";
457
- if (row.overflow !== undefined) return truncateToWidth(` ${marker} ${theme.fg("dim", `+${row.overflow} nested leaves`)}`, width);
570
+ const indent = " ".repeat(row.depth + 1);
571
+ if (row.overflow !== undefined) return truncateToWidth(`${indent}${marker} ${theme.fg("dim", `+${row.overflow} nested leaves`)}`, width);
458
572
  const modelThinking = row.modelThinking ? ` (${row.modelThinking})` : "";
459
573
  const activity = row.activity ? ` · ${row.activity}` : "";
460
- const left = ` ${marker} ${nestedStatusGlyph(row.state, theme)} ${theme.fg("muted", `${row.name}${modelThinking}`)} · ${row.state}${activity}`;
574
+ const left = `${indent}${marker} ${nestedStatusGlyph(row.state, theme)} ${theme.fg("muted", `${row.name}${modelThinking}`)} · ${row.state}${activity}`;
461
575
  const elapsed = row.startedAt !== undefined ? ` · ${formatFleetElapsed(Date.now() - row.startedAt)}` : "";
462
576
  return truncateToWidth(`${left}${theme.fg("dim", elapsed)}`, width);
463
577
  }
@@ -502,22 +616,25 @@ export class SubagentFleetStatus {
502
616
  entries: this.entries.map((entry) => this.active
503
617
  ? [
504
618
  entry.key,
619
+ entry.parentKey,
505
620
  entry.agent,
506
621
  entry.state,
507
622
  entry.modelThinking,
508
623
  entry.description,
624
+ entry.external,
509
625
  Math.round((now - entry.startedAt) / 1000),
510
626
  entry.tokens,
511
- entry.nestedChildren?.map((child) => [
512
- child.id,
513
- child.state,
514
- child.model,
515
- child.thinking,
516
- child.lastUpdate,
517
- child.steps?.map((step) => [step.agent, step.status, step.model, step.thinking, step.lastActivityAt]),
627
+ nestedFleetRows(entry.nestedChildren, entry.parentKey ? 3 : 4).map((row) => [
628
+ row.name,
629
+ row.state,
630
+ row.modelThinking,
631
+ row.activity,
632
+ row.startedAt,
633
+ row.depth,
634
+ row.overflow,
518
635
  ]),
519
636
  ]
520
- : [entry.key, entry.state, entry.tokens]),
637
+ : [entry.key, entry.state, entry.external, entry.tokens]),
521
638
  });
522
639
  }
523
640
 
@@ -2,59 +2,12 @@ import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { getLanguageFromPath, highlightCode, type ExtensionContext } from "@earendil-works/pi-coding-agent";
4
4
  import { Markdown, truncateToWidth, visibleWidth, wrapTextWithAnsi, type MarkdownTheme } from "@earendil-works/pi-tui";
5
+ import { safeTerminalText as safeDisplayText } from "../shared/display-text.ts";
5
6
 
6
7
  const DEFAULT_MAX_RECORDS = 240;
7
8
  const DEFAULT_MAX_BYTES = 2 * 1024 * 1024;
8
9
  const MAX_MESSAGE_CHARS = 64 * 1024;
9
10
  const TOOL_PREVIEW_LINES = 7;
10
- const BINARY_CONTENT_PLACEHOLDER = "[binary content omitted for safe display]";
11
-
12
- function isUnsafeDisplayCodePoint(codePoint: number): boolean {
13
- const terminalControl = (codePoint <= 0x1f && codePoint !== 0x09 && codePoint !== 0x0a)
14
- || (codePoint >= 0x7f && codePoint <= 0x9f);
15
- const bidiControl = codePoint === 0x061c
16
- || codePoint === 0x200e
17
- || codePoint === 0x200f
18
- || (codePoint >= 0x202a && codePoint <= 0x202e)
19
- || (codePoint >= 0x2066 && codePoint <= 0x2069);
20
- const privateUse = (codePoint >= 0xe000 && codePoint <= 0xf8ff)
21
- || (codePoint >= 0xf0000 && codePoint <= 0xffffd)
22
- || (codePoint >= 0x100000 && codePoint <= 0x10fffd);
23
- const invalidScalar = codePoint >= 0xd800 && codePoint <= 0xdfff;
24
- const nonCharacter = (codePoint >= 0xfdd0 && codePoint <= 0xfdef)
25
- || (codePoint & 0xffff) === 0xfffe
26
- || (codePoint & 0xffff) === 0xffff;
27
- return terminalControl || bidiControl || privateUse || invalidScalar || nonCharacter;
28
- }
29
-
30
- function looksLikeBinaryContent(text: string): boolean {
31
- if (text.includes("\0")) return true;
32
- let suspiciousControls = 0;
33
- let replacementCharacters = 0;
34
- let codePoints = 0;
35
- for (const character of text) {
36
- codePoints++;
37
- const codePoint = character.codePointAt(0) ?? 0;
38
- if ((codePoint <= 0x08) || (codePoint >= 0x0e && codePoint <= 0x1f)) suspiciousControls++;
39
- if (codePoint === 0xfffd) replacementCharacters++;
40
- }
41
- if (codePoints === 0) return false;
42
- return (suspiciousControls >= 4 && suspiciousControls / codePoints >= 0.1)
43
- || (replacementCharacters >= 3 && replacementCharacters / codePoints >= 0.1);
44
- }
45
-
46
- function safeDisplayText(text: string): string {
47
- const normalized = text.replace(/\r\n/g, "\n");
48
- if (looksLikeBinaryContent(normalized)) return BINARY_CONTENT_PLACEHOLDER;
49
- let safe = "";
50
- for (const character of normalized) {
51
- const codePoint = character.codePointAt(0) ?? 0;
52
- safe += isUnsafeDisplayCodePoint(codePoint)
53
- ? `[U+${codePoint.toString(16).toUpperCase().padStart(4, "0")}]`
54
- : character;
55
- }
56
- return safe;
57
- }
58
11
 
59
12
  function sanitizeJsonDisplayValue(value: unknown): { value: unknown; changed: boolean } {
60
13
  if (typeof value === "string") {