@xzzpig/pi-subagents 0.8.0 → 0.10.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 (221) hide show
  1. package/CHANGELOG.md +477 -0
  2. package/README.md +2 -2
  3. package/agents/claude-code-writer.md +15 -0
  4. package/agents/claude-code.md +15 -0
  5. package/agents/codex-exec-writer.md +15 -0
  6. package/agents/codex-exec.md +15 -0
  7. package/agents/cursor-agent-writer.md +14 -0
  8. package/agents/cursor-agent.md +14 -0
  9. package/agents/reviewer.md +1 -1
  10. package/agents/scout.md +1 -1
  11. package/docs/agents.md +195 -39
  12. package/docs/configuration.md +81 -22
  13. package/docs/extension-api.md +69 -14
  14. package/docs/missions.md +2 -0
  15. package/docs/models.md +32 -9
  16. package/docs/observability.md +22 -20
  17. package/docs/tool-reference.md +123 -14
  18. package/docs/watchdog.md +92 -114
  19. package/docs/workflows.md +142 -4
  20. package/install.mjs +1 -1
  21. package/package.json +7 -6
  22. package/prompts/review-loop.md +2 -2
  23. package/skills/council-mode/SKILL.md +48 -243
  24. package/skills/council-mode/references/pass-contracts.md +150 -0
  25. package/skills/pi-subagents/SKILL.md +89 -35
  26. package/skills/pi-subagents/references/constraints-and-recipes.md +30 -234
  27. package/skills/pi-subagents/references/execution-controls.md +91 -15
  28. package/skills/pi-subagents/references/management-authoring-rpc.md +5 -5
  29. package/skills/pi-subagents/references/multi-lane-orchestration.md +13 -1
  30. package/skills/pi-subagents/references/prompting-and-roles.md +59 -31
  31. package/skills/pi-subagents/references/review-and-validation.md +73 -0
  32. package/src/agents/agent-management.ts +384 -115
  33. package/src/agents/agent-refinements.ts +4 -4
  34. package/src/agents/agent-serializer.ts +14 -2
  35. package/src/agents/agents.ts +935 -372
  36. package/src/agents/builtin-names.ts +6 -0
  37. package/src/agents/runtime-agent-events.ts +70 -0
  38. package/src/agents/runtime-agent-registry.ts +42 -21
  39. package/src/api/agents.ts +10 -5
  40. package/src/api/background-work.ts +12 -3
  41. package/src/api/capability-ceiling.ts +0 -1
  42. package/src/api/{pi-args.ts → child-tool-plan.ts} +1 -1
  43. package/src/api/delegation.ts +0 -7
  44. package/src/api/external-runs.ts +67 -4
  45. package/src/api/preflight.ts +77 -21
  46. package/src/api/shared-types.ts +6 -0
  47. package/src/extension/config.ts +90 -0
  48. package/src/extension/doctor.ts +5 -13
  49. package/src/extension/fanout-child.ts +14 -14
  50. package/src/extension/index.ts +115 -37
  51. package/src/extension/public-execution.ts +103 -15
  52. package/src/extension/rpc.ts +120 -25
  53. package/src/extension/schemas.ts +65 -29
  54. package/src/extension/tool-description.ts +48 -26
  55. package/src/inspectors/herdr/actions.ts +2 -1
  56. package/src/inspectors/herdr/inspector-runner.ts +21 -23
  57. package/src/inspectors/herdr/session-roots-codec.ts +42 -0
  58. package/src/integrations/herdr-status.ts +51 -3
  59. package/src/intercom/native-supervisor-channel.ts +138 -60
  60. package/src/intercom/result-intercom.ts +7 -0
  61. package/src/intercom/supervisor-ui.ts +243 -0
  62. package/src/profiles/profiles.ts +5 -6
  63. package/src/runs/background/active-async-capacity.ts +103 -18
  64. package/src/runs/background/async-execution.ts +417 -133
  65. package/src/runs/background/async-job-tracker.ts +95 -15
  66. package/src/runs/background/async-resume.ts +60 -28
  67. package/src/runs/background/async-retention.ts +20 -3
  68. package/src/runs/background/async-status-snapshot.ts +23 -261
  69. package/src/runs/background/async-status.ts +204 -14
  70. package/src/runs/background/auto-drain.ts +1 -1
  71. package/src/runs/background/chain-append.ts +8 -3
  72. package/src/runs/background/chain-root-attachment.ts +74 -8
  73. package/src/runs/background/control-channel.ts +4 -205
  74. package/src/runs/background/fleet-view.ts +38 -22
  75. package/src/runs/background/inspect-rpc.ts +8 -8
  76. package/src/runs/background/notify.ts +238 -12
  77. package/src/runs/background/process-terminal.ts +16 -0
  78. package/src/runs/background/result-delivery-ownership.ts +45 -0
  79. package/src/runs/background/result-files.ts +28 -14
  80. package/src/runs/background/result-watcher.ts +39 -16
  81. package/src/runs/background/resume-guidance.ts +2 -2
  82. package/src/runs/background/retained-children.ts +1 -1
  83. package/src/runs/background/run-child-session.ts +613 -0
  84. package/src/runs/background/run-status.ts +84 -17
  85. package/src/runs/background/runner-aliases.ts +125 -0
  86. package/src/runs/background/runner-child-sessions.ts +31 -0
  87. package/src/runs/background/scheduled-runs.ts +174 -18
  88. package/src/runs/background/stale-run-reconciler.ts +10 -4
  89. package/src/runs/background/steering.ts +8 -15
  90. package/src/runs/background/subagent-runner.ts +718 -1161
  91. package/src/runs/background/subagent-wait.ts +86 -31
  92. package/src/runs/background/terminal-run-index.ts +1 -1
  93. package/src/runs/background/wait-completions.ts +43 -2
  94. package/src/runs/background/wait-config.ts +23 -9
  95. package/src/runs/background/wait-tool.ts +26 -19
  96. package/src/runs/foreground/async-steering-action.ts +3 -19
  97. package/src/runs/foreground/execution.ts +489 -499
  98. package/src/runs/foreground/foreground-control.ts +13 -0
  99. package/src/runs/foreground/foreground-history.ts +23 -1
  100. package/src/runs/foreground/subagent-executor.ts +1223 -402
  101. package/src/runs/foreground/workflow-detach-reconcile.ts +140 -115
  102. package/src/runs/foreground/workflow-foreground-steering.ts +24 -98
  103. package/src/runs/shared/abort-recovery.ts +119 -0
  104. package/src/runs/shared/acceptance.ts +138 -36
  105. package/src/runs/shared/async-status-projection.ts +565 -0
  106. package/src/runs/shared/background-process-options.ts +9 -0
  107. package/src/runs/shared/capability-ceiling.ts +2 -2
  108. package/src/runs/shared/child-hooks.ts +25 -0
  109. package/src/runs/shared/child-identity.ts +32 -6
  110. package/src/runs/shared/child-launch-plan.ts +151 -0
  111. package/src/runs/shared/child-launch.ts +364 -0
  112. package/src/runs/shared/child-lifecycle.ts +25 -0
  113. package/src/runs/shared/child-runtime-config.ts +126 -0
  114. package/src/runs/shared/child-session.ts +366 -0
  115. package/src/runs/shared/child-tool-plan.ts +632 -0
  116. package/src/runs/shared/claude-code-adapter.ts +133 -0
  117. package/src/runs/shared/codex-exec-adapter.ts +129 -0
  118. package/src/runs/shared/completion-evidence.ts +89 -0
  119. package/src/runs/shared/completion-guard.ts +6 -5
  120. package/src/runs/shared/cursor-agent-adapter.ts +114 -0
  121. package/src/runs/shared/dynamic-fanout.ts +3 -3
  122. package/src/runs/shared/external-cli-contract.ts +167 -0
  123. package/src/runs/shared/external-cli-preflight.ts +138 -0
  124. package/src/runs/shared/external-cli-runner.ts +348 -55
  125. package/src/runs/shared/fast-mode-extension.ts +5 -5
  126. package/src/runs/shared/host-step-status.ts +231 -0
  127. package/src/runs/shared/lane-metadata.ts +126 -0
  128. package/src/runs/shared/launch-cwd.ts +16 -0
  129. package/src/runs/shared/long-running-guard.ts +2 -1
  130. package/src/runs/shared/mcp-config-sources.ts +422 -0
  131. package/src/runs/shared/mcp-direct-tool-allowlist.ts +222 -158
  132. package/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
  133. package/src/runs/shared/model-exclusions.ts +139 -9
  134. package/src/runs/shared/model-fallback.ts +146 -14
  135. package/src/runs/shared/mutation-evidence.ts +57 -3
  136. package/src/runs/shared/nested-events.ts +99 -77
  137. package/src/runs/shared/nested-path.ts +0 -14
  138. package/src/runs/shared/nested-render.ts +9 -5
  139. package/src/runs/shared/orca-progress-tabs.ts +12 -7
  140. package/src/runs/shared/parallel-handoff.ts +423 -7
  141. package/src/runs/shared/parallel-utils.ts +20 -7
  142. package/src/runs/shared/permissions.ts +1 -14
  143. package/src/runs/shared/pi-spawn.ts +69 -35
  144. package/src/runs/shared/process-signal.ts +16 -0
  145. package/src/runs/shared/run-fanout-budget.ts +0 -13
  146. package/src/runs/shared/run-history.ts +21 -1
  147. package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -27
  148. package/src/runs/shared/sandbox-profile-guard.ts +85 -0
  149. package/src/runs/shared/sandbox-startup-diagnostics.ts +54 -0
  150. package/src/runs/shared/single-output.ts +89 -22
  151. package/src/runs/shared/structured-output.ts +49 -9
  152. package/src/runs/shared/subagent-control.ts +6 -2
  153. package/src/runs/shared/subagent-prompt-runtime.ts +188 -365
  154. package/src/runs/shared/task-intent.ts +21 -7
  155. package/src/runs/shared/tool-availability.ts +18 -62
  156. package/src/runs/shared/tool-budget.ts +0 -14
  157. package/src/runs/shared/tool-timeout.ts +1 -1
  158. package/src/runs/shared/workflow-graph.ts +16 -0
  159. package/src/runs/shared/worktree-cleanup-plan.ts +866 -0
  160. package/src/runs/shared/worktree.ts +571 -62
  161. package/src/shared/atomic-json.ts +3 -1
  162. package/src/shared/child-session-name.ts +46 -0
  163. package/src/shared/extension-context.ts +24 -0
  164. package/src/shared/fork-context.ts +21 -12
  165. package/src/shared/fork-session-cwd.ts +27 -0
  166. package/src/shared/formatters.ts +18 -3
  167. package/src/shared/jsonl-writer.ts +11 -0
  168. package/src/shared/launch-contract.ts +11 -1
  169. package/src/shared/pruned-fork.ts +450 -0
  170. package/src/shared/sandbox-profile.ts +23 -0
  171. package/src/shared/session-file-trust.ts +19 -0
  172. package/src/shared/session-tokens.ts +14 -3
  173. package/src/shared/settings.ts +19 -105
  174. package/src/shared/shortcuts.ts +17 -0
  175. package/src/shared/thinking-ceiling.ts +0 -6
  176. package/src/shared/types.ts +545 -70
  177. package/src/shared/utils.ts +60 -93
  178. package/src/shared/workflow-child-permit.ts +207 -0
  179. package/src/slash/delegation-adapters.ts +1 -9
  180. package/src/slash/delegation-request.ts +0 -4
  181. package/src/slash/prompt-template-bridge.ts +37 -1
  182. package/src/slash/slash-bridge.ts +1 -2
  183. package/src/slash/slash-commands.ts +383 -116
  184. package/src/slash/slash-live-state.ts +22 -11
  185. package/src/slash/subagents-admin.ts +29 -12
  186. package/src/tui/fleet-native-transcript.ts +4 -0
  187. package/src/tui/fleet-status.ts +217 -82
  188. package/src/tui/fleet-transcript.ts +11 -5
  189. package/src/tui/fleet.ts +54 -28
  190. package/src/tui/render-helpers.ts +31 -0
  191. package/src/tui/render.ts +1429 -163
  192. package/src/watchdog/change-signature.ts +40 -1
  193. package/src/watchdog/child-status.ts +54 -34
  194. package/src/watchdog/diff-tool.ts +77 -0
  195. package/src/watchdog/emission-guard.ts +5 -3
  196. package/src/watchdog/guidance.ts +20 -0
  197. package/src/watchdog/register-child.ts +28 -25
  198. package/src/watchdog/register-main.ts +10 -9
  199. package/src/watchdog/render.ts +4 -5
  200. package/src/watchdog/review.ts +15 -4
  201. package/src/watchdog/rules.ts +70 -0
  202. package/src/watchdog/runtime.ts +75 -92
  203. package/src/watchdog/scope.ts +0 -11
  204. package/src/watchdog/settings.ts +48 -104
  205. package/src/watchdog/turn-delta.ts +1 -1
  206. package/src/watchdog/types.ts +18 -32
  207. package/src/watchdog/warning-format.ts +0 -1
  208. package/src/workflows/chat-progress.ts +7 -3
  209. package/src/workflows/host-command.ts +235 -0
  210. package/src/workflows/scripted-workflow.ts +988 -59
  211. package/src/workflows/workflow-checklist.ts +439 -0
  212. package/src/workflows/workflow-child-summary.ts +121 -0
  213. package/src/workflows/workflow-preflight.ts +297 -0
  214. package/src/workflows/workflow-receipt.ts +232 -6
  215. package/src/workflows/workflow-resources.ts +150 -0
  216. package/src/workflows/workflow-settlement.ts +246 -0
  217. package/src/runs/shared/child-protocol.ts +0 -401
  218. package/src/runs/shared/pi-args.ts +0 -935
  219. package/src/runs/shared/subagent-startup-retry.ts +0 -116
  220. package/src/runs/shared/turn-budget.ts +0 -98
  221. package/src/shared/post-exit-stdio-guard.ts +0 -85
@@ -2,8 +2,13 @@ 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
3
  import { snapshotExternalRuns } from "../api/external-runs.ts";
4
4
  import { formatModelThinking } from "../shared/formatters.ts";
5
- import type { AsyncJobState, AsyncJobStep, FleetViewPlacement, HerdrProjectPaneSnapshot, NestedRunSummary, NestedStepSummary, SubagentState } from "../shared/types.ts";
5
+ import type { AsyncJobState, AsyncJobStep, FleetViewPlacement, HerdrProjectPaneSnapshot, HostStepState, HostStepVerdict, NestedRunSummary, NestedStepSummary, SubagentState } from "../shared/types.ts";
6
+ import { projectAsyncWorkflowRows, type AsyncStatusWorkflowRow } from "../runs/shared/async-status-projection.ts";
7
+ import { contextModeLabel } from "../runs/shared/context-mode.ts";
6
8
  import { formatWorkflowJsonPreview } from "../workflows/scripted-workflow.ts";
9
+ import { hostStepReportName, hostStepVerdictLabel } from "../runs/shared/host-step-status.ts";
10
+ import { isStaleExtensionContextError } from "../shared/extension-context.ts";
11
+ import { formatWorkflowChecklistBottleneck, formatWorkflowChecklistPhase, formatWorkflowChecklistSummary, projectWorkflowChecklist, type WorkflowChecklistPhase, type WorkflowChecklistProjection } from "../workflows/workflow-checklist.ts";
7
12
 
8
13
  export const FLEET_STATUS_WIDGET_KEY = "subagent-fleet-status";
9
14
 
@@ -25,21 +30,13 @@ type FleetStatusEntry = {
25
30
  description?: string;
26
31
  startedAt: number;
27
32
  tokens: number;
33
+ window?: number;
28
34
  state: string;
29
35
  external?: true;
30
36
  projectPane?: HerdrProjectPaneSnapshot;
31
37
  nestedChildren?: NestedRunSummary[];
32
- workflowRows?: FleetWorkflowRow[];
33
- };
34
-
35
- type FleetWorkflowRow = {
36
- name: string;
37
- state: AsyncJobStep["status"];
38
- modelThinking?: string;
39
- activity?: string;
40
- startedAt?: number;
41
- tokens?: number;
42
- overflow?: number;
38
+ workflowRows?: AsyncStatusWorkflowRow[];
39
+ workflowChecklist?: WorkflowChecklistProjection;
43
40
  };
44
41
 
45
42
  type FleetNestedRow = {
@@ -55,7 +52,8 @@ type FleetNestedRow = {
55
52
  type FleetTreeRow =
56
53
  | { kind: "owner"; entry: FleetStatusEntry }
57
54
  | { kind: "child"; entry: FleetStatusEntry; last: boolean }
58
- | { kind: "workflow"; ownerKey: string; row: FleetWorkflowRow; last: boolean }
55
+ | { kind: "workflow-phase"; ownerKey: string; phase: WorkflowChecklistPhase; last: boolean }
56
+ | { kind: "workflow"; ownerKey: string; row: AsyncStatusWorkflowRow; last: boolean }
59
57
  | { kind: "nested"; ownerKey: string; row: FleetNestedRow; last: boolean };
60
58
 
61
59
  export interface FleetStatusOptions {
@@ -72,12 +70,15 @@ export function formatFleetElapsed(ms: number): string {
72
70
  return `${Math.max(0, Math.round(ms / 1000))}s`;
73
71
  }
74
72
 
75
- export function formatFleetTokens(count: number): string {
76
- let compact: string;
77
- if (count >= 1_000_000) compact = `${(count / 1_000_000).toFixed(1)}M`;
78
- else if (count >= 1_000) compact = `${(count / 1_000).toFixed(1)}k`;
79
- else compact = `${Math.max(0, Math.round(count))}`;
80
- return `↓ ${compact} tokens`;
73
+ export function formatFleetTokens(count: number, window?: number): string {
74
+ const compact = (value: number): string => value >= 1_000_000
75
+ ? `${(value / 1_000_000).toFixed(1)}M`
76
+ : value >= 1_000
77
+ ? `${(value / 1_000).toFixed(1)}k`
78
+ : `${Math.max(0, Math.round(value))}`;
79
+ return window !== undefined
80
+ ? `↓ ${compact(window)} window · ${compact(count)} spent`
81
+ : `↓ ${compact(count)} tokens`;
81
82
  }
82
83
 
83
84
  function rightAlign(left: string, right: string, width: number): string {
@@ -106,44 +107,12 @@ function nestedActivity(node: NestedRunSummary | NestedStepSummary): string | un
106
107
  return undefined;
107
108
  }
108
109
 
109
- function workflowStepActivity(step: AsyncJobStep): string | undefined {
110
- if (step.currentTool) return `tool ${step.currentTool}`;
111
- if (step.currentPath) return step.currentPath.split(/[\\/]/).at(-1);
112
- if (step.activityState === "needs_attention") return "needs attention";
113
- if (step.activityState === "active_long_running") return "long-running";
114
- if (step.turnCount !== undefined) return `${step.turnCount} turns`;
115
- if (step.toolCount !== undefined) return `${step.toolCount} tools`;
116
- return undefined;
117
- }
118
-
119
- function workflowStepName(step: AsyncJobStep, index: number): string {
120
- const key = step.workflowKey ?? `step ${index + 1}`;
121
- const label = step.label && step.label !== key ? ` · ${step.label}` : "";
122
- const phase = step.phase ? `${step.phase}: ` : "";
123
- return `${phase}${key}${label} (${step.agent})`;
124
- }
125
-
126
- function workflowFleetRows(steps: AsyncJobStep[] | undefined): FleetWorkflowRow[] {
127
- return (steps ?? []).map((step, index) => {
128
- const modelThinking = formatModelThinking(step.model, step.thinking) || undefined;
129
- const activity = workflowStepActivity(step);
130
- return {
131
- name: workflowStepName(step, index),
132
- state: step.status,
133
- ...(modelThinking ? { modelThinking } : {}),
134
- ...(activity ? { activity } : {}),
135
- ...(step.startedAt !== undefined ? { startedAt: step.startedAt } : {}),
136
- ...(step.tokens?.total !== undefined ? { tokens: step.tokens.total } : {}),
137
- };
138
- });
139
- }
140
-
141
- function visibleWorkflowRows(rows: FleetWorkflowRow[] | undefined, visibleLimit: number): FleetWorkflowRow[] {
110
+ function visibleWorkflowRows(rows: AsyncStatusWorkflowRow[] | undefined, visibleLimit: number): AsyncStatusWorkflowRow[] {
142
111
  if (!rows?.length) return [];
143
112
  if (rows.length <= visibleLimit) return rows;
144
113
  const selected = new Set<number>();
145
114
  for (const [index, row] of rows.entries()) {
146
- if (row.state !== "complete" && row.state !== "completed") selected.add(index);
115
+ if (!isWorkflowRowTerminal(row)) selected.add(index);
147
116
  if (selected.size >= visibleLimit) break;
148
117
  }
149
118
  for (let index = rows.length - 1; index >= 0 && selected.size < visibleLimit; index--) selected.add(index);
@@ -151,9 +120,26 @@ function visibleWorkflowRows(rows: FleetWorkflowRow[] | undefined, visibleLimit:
151
120
  return [{ name: `… +${rows.length - visible.length} hidden workflow steps`, state: "complete", overflow: rows.length - visible.length }, ...visible];
152
121
  }
153
122
 
154
- function nestedStatusGlyph(state: FleetNestedRow["state"], theme: Theme): string {
123
+ function visibleWorkflowPhases(checklist: WorkflowChecklistProjection | undefined, visibleLimit: number): WorkflowChecklistPhase[] {
124
+ const phases = checklist?.phases ?? [];
125
+ if (phases.length <= visibleLimit) return phases;
126
+ const selected = new Set<number>();
127
+ for (const [index, phase] of phases.entries()) {
128
+ if (phase.state !== "complete") selected.add(index);
129
+ if (selected.size >= visibleLimit) break;
130
+ }
131
+ for (let index = phases.length - 1; index >= 0 && selected.size < visibleLimit; index--) selected.add(index);
132
+ return [...selected].sort((left, right) => left - right).map((index) => phases[index]!);
133
+ }
134
+
135
+ function isWorkflowRowTerminal(row: AsyncStatusWorkflowRow): boolean {
136
+ if (row.kind) return row.state === "done" || row.state === "cancelled" || row.state === "error";
137
+ return row.state === "complete" || row.state === "completed";
138
+ }
139
+
140
+ function nestedStatusGlyph(state: FleetNestedRow["state"] | "planned", theme: Theme): string {
155
141
  if (state === "running") return theme.fg("accent", "●");
156
- if (state === "queued" || state === "pending") return theme.fg("muted", "◦");
142
+ if (state === "queued" || state === "pending" || state === "planned") return theme.fg("muted", "◦");
157
143
  if (state === "complete" || state === "completed") return theme.fg("success", "✓");
158
144
  if (state === "failed" || state === "rejected") return theme.fg("error", "✗");
159
145
  return theme.fg("warning", "■");
@@ -253,10 +239,11 @@ function fleetTreeRows(entries: FleetStatusEntry[]): FleetTreeRow[] {
253
239
  if (entry.parentKey && entryKeys.has(entry.parentKey)) continue;
254
240
  rows.push({ kind: "owner", entry });
255
241
  const attached = childrenByParent.get(entry.key) ?? [];
242
+ const workflowPhases = visibleWorkflowPhases(entry.workflowChecklist, attached.length > 0 ? 2 : 4);
256
243
  const workflowRows = visibleWorkflowRows(entry.workflowRows, attached.length > 0 ? 2 : 4);
257
244
  for (const [index, child] of attached.entries()) {
258
245
  const nested = nestedFleetRows(child.nestedChildren, 3);
259
- const laterRows = index < attached.length - 1 || workflowRows.length > 0 || Boolean(entry.nestedChildren?.length);
246
+ const laterRows = index < attached.length - 1 || workflowPhases.length > 0 || workflowRows.length > 0 || Boolean(entry.nestedChildren?.length);
260
247
  rows.push({ kind: "child", entry: child, last: !laterRows && nested.length === 0 });
261
248
  for (const [nestedIndex, row] of nested.entries()) rows.push({
262
249
  kind: "nested",
@@ -265,6 +252,12 @@ function fleetTreeRows(entries: FleetStatusEntry[]): FleetTreeRow[] {
265
252
  last: nestedIndex === nested.length - 1 && !laterRows,
266
253
  });
267
254
  }
255
+ for (const [index, phase] of workflowPhases.entries()) rows.push({
256
+ kind: "workflow-phase",
257
+ ownerKey: entry.key,
258
+ phase,
259
+ last: index === workflowPhases.length - 1 && workflowRows.length === 0 && !entry.nestedChildren?.length,
260
+ });
268
261
  for (const [index, row] of workflowRows.entries()) rows.push({ kind: "workflow", ownerKey: entry.key, row, last: index === workflowRows.length - 1 && !entry.nestedChildren?.length });
269
262
  const nested = nestedFleetRows(entry.nestedChildren, attached.length > 0 ? 3 : 4);
270
263
  for (const [index, row] of nested.entries()) rows.push({ kind: "nested", ownerKey: entry.key, row, last: index === nested.length - 1 });
@@ -272,19 +265,31 @@ function fleetTreeRows(entries: FleetStatusEntry[]): FleetTreeRow[] {
272
265
  return rows;
273
266
  }
274
267
 
275
- function isStaleExtensionContextError(error: unknown): boolean {
276
- // Pi currently exposes stale contexts as plain Errors without a stable code or subtype.
277
- return error instanceof Error
278
- && (error.message.includes("This extension ctx is stale")
279
- || error.message.includes("Extension context no longer active"));
280
- }
281
-
282
268
  function foregroundDescription(control: { parentWorkflowRunId?: string; workflowKey?: string }, description: string | undefined): string | undefined {
283
269
  if (!control.parentWorkflowRunId) return description;
284
270
  const workflow = `workflow child: ${control.parentWorkflowRunId}${control.workflowKey ? ` (${control.workflowKey})` : ""}`;
285
271
  return description ? `${workflow} · ${description}` : workflow;
286
272
  }
287
273
 
274
+ function workflowIdentityCandidates(step: Pick<AsyncJobStep, "workflowKey" | "runId">): string[] {
275
+ return [...new Set([step.workflowKey, step.runId].filter((value): value is string => typeof value === "string" && value.length > 0))];
276
+ }
277
+
278
+ function asyncJobIdentityCandidates(job: AsyncJobState): string[] {
279
+ return [...new Set([job.workflowKey, job.asyncId].filter((value): value is string => typeof value === "string" && value.length > 0))];
280
+ }
281
+
282
+ function linkedWorkflowParentKey(parentWorkflowRunId: string | undefined, activeWorkflowKeys: ReadonlySet<string>): string | undefined {
283
+ if (!parentWorkflowRunId) return undefined;
284
+ const parentKey = `async:${parentWorkflowRunId}`;
285
+ return activeWorkflowKeys.has(parentKey) ? parentKey : undefined;
286
+ }
287
+
288
+ function workflowStepsWithoutMaterializedChildren(steps: AsyncJobStep[] | undefined, materializedChildIds: ReadonlySet<string> | undefined): AsyncJobStep[] | undefined {
289
+ if (!steps?.length || !materializedChildIds?.size) return steps;
290
+ return steps.filter((step) => !workflowIdentityCandidates(step).some((identity) => materializedChildIds.has(identity)));
291
+ }
292
+
288
293
  function activeLeafAgentCount(entries: FleetStatusEntry[]): number {
289
294
  return entries.filter((entry) => !entry.workflowWrapper && !entry.surface).length;
290
295
  }
@@ -319,12 +324,30 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
319
324
  const activeWorkflowKeys = new Set([...state.asyncJobs.values()]
320
325
  .filter((job) => job.mode === "workflow" && isActiveState(job.status))
321
326
  .map((job) => `async:${job.asyncId}`));
327
+ const materializedChildrenByWorkflow = new Map<string, Set<string>>();
328
+ for (const job of state.asyncJobs.values()) {
329
+ if (!isActiveState(job.status) || !job.parentWorkflowRunId) continue;
330
+ const parentKey = linkedWorkflowParentKey(job.parentWorkflowRunId, activeWorkflowKeys);
331
+ if (!parentKey) continue;
332
+ const childIds = materializedChildrenByWorkflow.get(parentKey) ?? new Set<string>();
333
+ for (const identity of asyncJobIdentityCandidates(job)) childIds.add(identity);
334
+ materializedChildrenByWorkflow.set(parentKey, childIds);
335
+ }
322
336
  for (const control of state.foregroundControls.values()) {
323
- const parentKey = control.parentWorkflowRunId ? `async:${control.parentWorkflowRunId}` : undefined;
324
- const linkedParentKey = parentKey && activeWorkflowKeys.has(parentKey) ? parentKey : undefined;
337
+ const linkedParentKey = linkedWorkflowParentKey(control.parentWorkflowRunId, activeWorkflowKeys);
325
338
  if (control.activeChildren) {
339
+ const nestedChildren = control.nestedChildren ?? [];
340
+ const nestedChildrenByParentStep = new Map<number, NestedRunSummary[]>();
341
+ for (const nested of nestedChildren) {
342
+ if (nested.parentStepIndex === undefined) continue;
343
+ const children = nestedChildrenByParentStep.get(nested.parentStepIndex) ?? [];
344
+ children.push(nested);
345
+ nestedChildrenByParentStep.set(nested.parentStepIndex, children);
346
+ }
326
347
  for (const child of [...control.activeChildren.values()].sort((left, right) => left.index - right.index)) {
327
348
  const modelThinking = formatModelThinking(child.model, child.thinking) || undefined;
349
+ const childNestedChildren = nestedChildrenByParentStep.get(child.index)
350
+ ?? (control.activeChildren.size === 1 && nestedChildren.length ? nestedChildren : undefined);
328
351
  entries.push({
329
352
  key: `foreground-active:${control.runId}:${child.index}`,
330
353
  ...(linkedParentKey ? { parentKey: linkedParentKey } : {}),
@@ -333,10 +356,9 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
333
356
  description: foregroundDescription(control, child.description),
334
357
  startedAt: child.startedAt,
335
358
  tokens: child.tokens ?? 0,
359
+ ...(child.window !== undefined ? { window: child.window } : {}),
336
360
  state: "running",
337
- ...((control.nestedChildren?.filter((nested) => nested.parentStepIndex === child.index).length ?? 0) > 0
338
- ? { nestedChildren: control.nestedChildren!.filter((nested) => nested.parentStepIndex === child.index) }
339
- : control.activeChildren.size === 1 && control.nestedChildren?.length ? { nestedChildren: control.nestedChildren } : {}),
361
+ ...(childNestedChildren?.length ? { nestedChildren: childNestedChildren } : {}),
340
362
  });
341
363
  }
342
364
  continue;
@@ -350,6 +372,7 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
350
372
  description: foregroundDescription(control, control.description),
351
373
  startedAt: control.startedAt,
352
374
  tokens: control.tokens ?? 0,
375
+ ...(control.window !== undefined ? { window: control.window } : {}),
353
376
  state: "running",
354
377
  ...(control.nestedChildren?.length ? { nestedChildren: control.nestedChildren } : {}),
355
378
  });
@@ -358,17 +381,31 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
358
381
  for (const job of state.asyncJobs.values()) {
359
382
  if (!isActiveState(job.status)) continue;
360
383
  const startedAt = job.startedAt ?? job.updatedAt ?? Date.now();
384
+ const linkedParentKey = linkedWorkflowParentKey(job.parentWorkflowRunId, activeWorkflowKeys);
361
385
  if (job.mode === "workflow") {
362
386
  const latestEmit = job.workflow?.emits?.length ? formatWorkflowJsonPreview(job.workflow.emits.at(-1), 120) : undefined;
387
+ const workflowSteps = workflowStepsWithoutMaterializedChildren(job.steps, materializedChildrenByWorkflow.get(`async:${job.asyncId}`));
388
+ const workflowRows = projectAsyncWorkflowRows(workflowSteps, job.workflowGraph ?? job.hostSteps, job.preflight);
389
+ const workflowChecklist = projectWorkflowChecklist({
390
+ graph: job.workflowGraph,
391
+ steps: job.steps,
392
+ hostSteps: job.hostSteps,
393
+ preflight: job.preflight,
394
+ trace: job.workflow?.trace,
395
+ now: job.updatedAt ?? Date.now(),
396
+ });
363
397
  entries.push({
364
398
  key: `async:${job.asyncId}`,
399
+ ...(linkedParentKey ? { parentKey: linkedParentKey } : {}),
365
400
  workflowWrapper: true,
366
401
  agent: "workflow",
367
402
  description: latestEmit !== undefined ? `latest emit: ${latestEmit}` : job.description,
368
403
  startedAt,
369
404
  tokens: job.totalTokens?.total ?? 0,
405
+ ...(job.totalTokens?.window !== undefined ? { window: job.totalTokens.window } : {}),
370
406
  state: job.status,
371
- ...(job.steps?.length ? { workflowRows: workflowFleetRows(job.steps) } : {}),
407
+ ...(workflowRows.length ? { workflowRows } : {}),
408
+ ...(workflowChecklist.total ? { workflowChecklist } : {}),
372
409
  ...(job.nestedChildren?.length ? { nestedChildren: job.nestedChildren } : {}),
373
410
  });
374
411
  continue;
@@ -383,10 +420,12 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
383
420
  if (!steps?.length) {
384
421
  entries.push({
385
422
  key: `async:${job.asyncId}`,
423
+ ...(linkedParentKey ? { parentKey: linkedParentKey } : {}),
386
424
  agent: job.mode ?? "subagent",
387
425
  description: job.description,
388
426
  startedAt,
389
427
  tokens: job.totalTokens?.total ?? 0,
428
+ ...(job.totalTokens?.window !== undefined ? { window: job.totalTokens.window } : {}),
390
429
  state: job.status,
391
430
  ...(job.nestedChildren?.length ? { nestedChildren: job.nestedChildren } : {}),
392
431
  });
@@ -399,11 +438,15 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
399
438
  const modelThinking = formatModelThinking(step.model, step.thinking) || undefined;
400
439
  entries.push({
401
440
  key: `async:${job.asyncId}:${index}`,
441
+ ...(linkedParentKey ? { parentKey: linkedParentKey } : {}),
402
442
  agent: step.label ? `${step.label} (${step.agent})` : step.agent,
403
443
  ...(modelThinking ? { modelThinking } : {}),
404
444
  description: step.description ?? job.description,
405
445
  startedAt: step.startedAt ?? startedAt,
406
446
  tokens: step.tokens?.total ?? (steps.length === 1 ? job.totalTokens?.total ?? 0 : 0),
447
+ ...((step.tokens?.window ?? (steps.length === 1 ? job.totalTokens?.window : undefined)) !== undefined
448
+ ? { window: step.tokens?.window ?? job.totalTokens?.window }
449
+ : {}),
407
450
  state: step.status,
408
451
  ...((step.children?.length ?? 0) > 0
409
452
  ? { nestedChildren: step.children }
@@ -539,7 +582,12 @@ export class SubagentFleetStatus {
539
582
  this.lastRenderKey = renderKey;
540
583
  return;
541
584
  }
542
- if (renderKey === this.lastRenderKey) return;
585
+ if (renderKey === this.lastRenderKey) {
586
+ // Repaint anyway while anything is running so the wall-clock
587
+ // spinner animates between state changes (500ms tick).
588
+ if (this.entries.some((entry) => entry.state === "running")) this.tui?.requestRender();
589
+ return;
590
+ }
543
591
  this.lastRenderKey = renderKey;
544
592
  this.tui?.requestRender();
545
593
  }
@@ -611,6 +659,10 @@ export class SubagentFleetStatus {
611
659
  const workEntries = this.entries.filter((entry) => !entry.surface);
612
660
  const projectEntries = this.entries.filter((entry) => entry.surface === "project-pane");
613
661
  const tokens = workEntries.reduce((total, entry) => total + entry.tokens, 0);
662
+ const nativeEntries = workEntries.filter((entry) => !entry.external);
663
+ const window = nativeEntries.length > 0 && nativeEntries.every((entry) => entry.window !== undefined)
664
+ ? nativeEntries.reduce((total, entry) => total + entry.window!, 0)
665
+ : undefined;
614
666
  const capacity = this.state.activeAsyncCapacity;
615
667
  const hasNativeRows = workEntries.some((entry) => !entry.external);
616
668
  const showNativeSummary = hasNativeRows || Boolean(capacity?.used);
@@ -621,11 +673,15 @@ export class SubagentFleetStatus {
621
673
  const paneAttention = projectEntries.filter((entry) => entry.projectPane && projectPaneNeedsAttention(entry.projectPane)).length;
622
674
  const panes = projectEntries.length > 0 ? `${projectEntries.length} pane${projectEntries.length === 1 ? "" : "s"}${paneAttention ? ` (${paneAttention} ⚠)` : ""}` : "";
623
675
  const label = [agents, asyncRuns, panes].filter(Boolean).join(" · ");
624
- const detail = [showNativeSummary ? formatFleetTokens(tokens) : undefined, "↓/← to inspect"].filter(Boolean).join(" · ");
676
+ const detail = [showNativeSummary ? formatFleetTokens(tokens, window) : undefined, "↓/← to inspect"].filter(Boolean).join(" · ");
625
677
  return [truncateToWidth(` ${theme.fg("muted", label)}${label && detail ? " · " : ""}${theme.fg("dim", detail)}`, width)];
626
678
  }
627
679
  const roster = this.rosterKeys();
628
680
  const selectedIndex = Math.max(0, roster.indexOf(this.selectedKey));
681
+ const rosterIndexByKey = new Map<string, number>();
682
+ for (const [index, entry] of this.entries.entries()) {
683
+ if (!rosterIndexByKey.has(entry.key)) rosterIndexByKey.set(entry.key, index + 1);
684
+ }
629
685
  const lines = [truncateToWidth(` ${theme.fg("dim", "↑↓/jk select · enter inspect · esc back")}`, width), ""];
630
686
  lines.push(truncateToWidth(` ${this.bullet(0, selectedIndex, theme)} main`, width));
631
687
 
@@ -639,25 +695,27 @@ export class SubagentFleetStatus {
639
695
  for (let index = start; index < start + visibleCount; index++) {
640
696
  const row = tree[index]!;
641
697
  if (row.kind === "owner" || row.kind === "child") {
642
- const ownerIndex = this.entries.findIndex((entry) => entry.key === row.entry.key);
643
- lines.push(this.renderEntry(ownerIndex + 1, selectedIndex, row.entry, width, theme, row.kind === "child" ? (row.last ? "└─" : "├─") : undefined));
698
+ const rosterIndex = rosterIndexByKey.get(row.entry.key) ?? 0;
699
+ lines.push(this.renderEntry(rosterIndex, selectedIndex, row.entry, width, theme, row.kind === "child" ? (row.last ? "└─" : "├─") : undefined));
644
700
  } else if (row.kind === "workflow") {
645
701
  lines.push(this.renderWorkflowRow(row.row, row.last, width, theme));
702
+ } else if (row.kind === "workflow-phase") {
703
+ lines.push(this.renderWorkflowPhaseRow(row.phase, row.last, width, theme));
646
704
  } else {
647
705
  lines.push(this.renderNestedRow(row.row, row.last, width, theme));
648
706
  }
649
707
  }
650
708
  if (hiddenBelow > 0) lines.push(rightAlign("", theme.fg("dim", `↓ ${hiddenBelow} more`), width));
651
- this.renderProjectPaneSection(lines, selectedIndex, width, theme);
709
+ this.renderProjectPaneSection(lines, selectedIndex, width, theme, rosterIndexByKey);
652
710
  return lines;
653
711
  }
654
712
 
655
- private renderProjectPaneSection(lines: string[], selectedIndex: number, width: number, theme: Theme): void {
713
+ private renderProjectPaneSection(lines: string[], selectedIndex: number, width: number, theme: Theme, rosterIndexByKey: ReadonlyMap<string, number>): void {
656
714
  const entries = this.entries.filter((entry) => entry.surface === "project-pane");
657
715
  if (!entries.length) return;
658
716
  lines.push("", truncateToWidth(` ${theme.fg("dim", "project panes")}`, width));
659
717
  for (const entry of entries) {
660
- const rosterIndex = this.entries.findIndex((candidate) => candidate.key === entry.key) + 1;
718
+ const rosterIndex = rosterIndexByKey.get(entry.key) ?? 0;
661
719
  lines.push(this.renderEntry(rosterIndex, selectedIndex, entry, width, theme));
662
720
  }
663
721
  }
@@ -666,11 +724,14 @@ export class SubagentFleetStatus {
666
724
  private renderEntry(rosterIndex: number, selectedIndex: number, entry: FleetStatusEntry, width: number, theme: Theme, branch?: string): string {
667
725
  const agent = entry.modelThinking ? `${entry.agent} (${entry.modelThinking})` : entry.agent;
668
726
  const prefix = branch ? ` ${branch}` : " ";
669
- const left = `${prefix} ${this.bullet(rosterIndex, selectedIndex, theme)} ${theme.fg("muted", agent)} · ${entry.state}`;
727
+ const checklist = entry.workflowWrapper && entry.workflowChecklist
728
+ ? ` · checklist ${formatWorkflowChecklistSummary(entry.workflowChecklist)}${entry.workflowChecklist.bottleneck ? ` · bottleneck ${formatWorkflowChecklistBottleneck(entry.workflowChecklist.bottleneck)}` : ""}`
729
+ : "";
730
+ const left = `${prefix} ${this.bullet(rosterIndex, selectedIndex, theme)} ${theme.fg("muted", agent)} · ${entry.state}${checklist}`;
670
731
  const elapsed = Date.now() - entry.startedAt;
671
732
  const rightText = entry.projectPane
672
733
  ? `${entry.projectPane.summary ?? "—"} · ${formatFleetElapsed(Date.now() - entry.projectPane.refreshedAt)} ago`
673
- : entry.external ? formatFleetElapsed(elapsed) : `${formatFleetElapsed(elapsed)} · ${formatFleetTokens(entry.tokens)}`;
734
+ : entry.external ? formatFleetElapsed(elapsed) : `${formatFleetElapsed(elapsed)} · ${formatFleetTokens(entry.tokens, entry.window)}`;
674
735
  const right = theme.fg("dim", rightText);
675
736
  return rightAlign(left, right, width);
676
737
  }
@@ -686,16 +747,65 @@ export class SubagentFleetStatus {
686
747
  return truncateToWidth(`${left}${theme.fg("dim", elapsed)}`, width);
687
748
  }
688
749
 
689
- private renderWorkflowRow(row: FleetWorkflowRow, last: boolean, width: number, theme: Theme): string {
750
+ private workflowRowGlyph(row: AsyncStatusWorkflowRow, theme: Theme): string {
751
+ if (!row.kind) return nestedStatusGlyph(row.state as FleetNestedRow["state"], theme);
752
+ const state = row.state as HostStepState;
753
+ if (state === "pending") return theme.fg("muted", "◦");
754
+ if (state === "running") return theme.fg("accent", "●");
755
+ if (state === "done") return row.verdict === "pass" ? theme.fg("success", "✓") : row.verdict === "fail" ? theme.fg("error", "✗") : theme.fg("warning", "■");
756
+ if (state === "error") return theme.fg("error", "✗");
757
+ return theme.fg("warning", "■");
758
+ }
759
+
760
+ private workflowRowStateLabel(row: AsyncStatusWorkflowRow, theme: Theme): string {
761
+ const state = row.kind ? hostStepVerdictLabel(row.state as HostStepState, row.verdict as HostStepVerdict | undefined) : row.state;
762
+ if (state === "running") return theme.fg("accent", state);
763
+ if (state === "pending" || state === "queued") return theme.fg("muted", state);
764
+ if (state === "pass" || state === "complete" || state === "completed") return theme.fg("success", state === "pass" ? "pass" : "complete");
765
+ if (state === "fail" || state === "failed" || state === "error") return theme.fg("error", state === "fail" ? "fail" : state);
766
+ return theme.fg("warning", state);
767
+ }
768
+
769
+ private renderWorkflowPhaseRow(phase: WorkflowChecklistPhase, last: boolean, width: number, theme: Theme): string {
770
+ const marker = last ? "└─" : "├─";
771
+ const glyph = phase.state === "complete"
772
+ ? theme.fg("success", "✓")
773
+ : phase.state === "running"
774
+ ? theme.fg("accent", "●")
775
+ : phase.state === "blocked" || phase.state === "failed"
776
+ ? theme.fg("error", phase.state === "blocked" ? "!" : "✗")
777
+ : phase.state === "queued"
778
+ ? theme.fg("muted", "◦")
779
+ : theme.fg("warning", "■");
780
+ return truncateToWidth(` ${marker} ${glyph} ${theme.fg("muted", formatWorkflowChecklistPhase(phase))}`, width);
781
+ }
782
+
783
+ private renderWorkflowRow(row: AsyncStatusWorkflowRow, last: boolean, width: number, theme: Theme): string {
690
784
  const marker = last ? "└─" : "├─";
691
785
  const indent = " ";
692
786
  if (row.overflow !== undefined) return truncateToWidth(`${indent}${marker} ${theme.fg("dim", `+${row.overflow} hidden workflow steps`)}`, width);
787
+ const context = contextModeLabel(row.context);
693
788
  const modelThinking = row.modelThinking ? ` (${row.modelThinking})` : "";
694
789
  const activity = row.activity ? ` · ${row.activity}` : "";
695
- const left = `${indent}${marker} ${nestedStatusGlyph(row.state, theme)} ${theme.fg("muted", `${row.name}${modelThinking}`)} · ${row.state}${activity}`;
790
+ const kind = row.kind ? `${row.kind}: ` : "";
791
+ const hints = row.preflight ? [
792
+ row.preflight.mode ? `mode:${row.preflight.mode}` : undefined,
793
+ row.preflight.decision ? `decision:${row.preflight.decision}` : undefined,
794
+ row.preflight.claims?.length ? `claims:${row.preflight.claims.join(",")}` : undefined,
795
+ row.preflight.expectedOutput ? `expected:${row.preflight.expectedOutput}` : undefined,
796
+ row.preflight.independence ? `independence:${row.preflight.independence}` : undefined,
797
+ ].filter((value): value is string => Boolean(value)).join(" · ") : "";
798
+ const left = `${indent}${marker} ${this.workflowRowGlyph(row, theme)} ${theme.fg("muted", `${kind}${row.name}${context ? ` ${context}` : ""}${modelThinking}`)} · ${this.workflowRowStateLabel(row, theme)}${activity}${hints ? ` · ${hints}` : ""}`;
696
799
  const details = [
697
800
  row.startedAt !== undefined ? formatFleetElapsed(Date.now() - row.startedAt) : undefined,
698
- row.tokens !== undefined ? formatFleetTokens(row.tokens) : undefined,
801
+ row.tokens !== undefined ? formatFleetTokens(row.tokens, row.window) : undefined,
802
+ row.provider ? `provider:${row.provider}` : undefined,
803
+ row.role ? `role:${row.role}` : undefined,
804
+ row.target,
805
+ row.detail,
806
+ row.reasonCode ? `reason:${row.reasonCode}` : undefined,
807
+ row.freshness?.stale ? "stale" : row.freshness?.observedRef ? `ref:${row.freshness.observedRef}` : undefined,
808
+ row.reportPath ? `out:${hostStepReportName(row.reportPath)}` : undefined,
699
809
  ].filter(Boolean).join(" · ");
700
810
  return truncateToWidth(`${left}${details ? theme.fg("dim", ` · ${details}`) : ""}`, width);
701
811
  }
@@ -749,13 +859,32 @@ export class SubagentFleetStatus {
749
859
  entry.external,
750
860
  Math.round((now - entry.startedAt) / 1000),
751
861
  entry.tokens,
862
+ entry.workflowChecklist ? [
863
+ entry.workflowChecklist.total,
864
+ entry.workflowChecklist.done,
865
+ entry.workflowChecklist.running,
866
+ entry.workflowChecklist.queued,
867
+ entry.workflowChecklist.blocked,
868
+ entry.workflowChecklist.failed,
869
+ entry.workflowChecklist.phases.map((phase) => [phase.key, phase.state, phase.done, phase.total, phase.running, phase.queued, phase.blocked, phase.failed, phase.items.map((item) => [item.key, item.state, item.currentTool, item.currentPath, item.durationMs, item.toolCount, item.error])]),
870
+ ] : undefined,
752
871
  visibleWorkflowRows(entry.workflowRows, entry.parentKey ? 2 : 4).map((row) => [
872
+ row.kind,
753
873
  row.name,
754
874
  row.state,
875
+ row.context,
755
876
  row.modelThinking,
756
877
  row.activity,
757
878
  row.startedAt,
758
879
  row.tokens,
880
+ row.provider,
881
+ row.role,
882
+ row.verdict,
883
+ row.reasonCode,
884
+ row.detail,
885
+ row.target,
886
+ row.freshness,
887
+ row.reportPath,
759
888
  row.overflow,
760
889
  ]),
761
890
  nestedFleetRows(entry.nestedChildren, entry.parentKey ? 3 : 4).map((row) => [
@@ -790,7 +919,13 @@ export class SubagentFleetStatus {
790
919
 
791
920
  private clearWidget(): void {
792
921
  if (!this.widgetRegistered) return;
793
- this.ui?.setWidget(FLEET_STATUS_WIDGET_KEY, undefined);
922
+ try {
923
+ this.ui?.setWidget(FLEET_STATUS_WIDGET_KEY, undefined);
924
+ } catch (error) {
925
+ if (!isStaleExtensionContextError(error)) throw error;
926
+ this.clearUiRegistration();
927
+ return;
928
+ }
794
929
  this.widgetRegistered = false;
795
930
  this.tui = undefined;
796
931
  }
@@ -3,6 +3,7 @@ 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
5
  import { safeTerminalText as safeDisplayText } from "../shared/display-text.ts";
6
+ import { isTrustedRecordedSessionFile } from "../shared/session-file-trust.ts";
6
7
 
7
8
  const DEFAULT_MAX_RECORDS = 240;
8
9
  const DEFAULT_MAX_BYTES = 2 * 1024 * 1024;
@@ -61,6 +62,8 @@ export interface FleetTranscript {
61
62
 
62
63
  export interface FleetTranscriptReadOptions {
63
64
  trustedRoots: string[];
65
+ trustedFiles?: string[];
66
+ trustedFileRoot?: string;
64
67
  maxRecords?: number;
65
68
  maxBytes?: number;
66
69
  }
@@ -109,10 +112,13 @@ function isNotFoundError(error: unknown): boolean {
109
112
  return Boolean(objectValue(error)?.code === "ENOENT");
110
113
  }
111
114
 
112
- function validateTranscriptPath(filePath: string, trustedRoots: string[]): { resolvedPath?: string; warning?: string } {
113
- if (trustedRoots.length === 0) return { warning: `Transcript preview has no trusted root: ${filePath}` };
115
+ function validateTranscriptPath(filePath: string, trustedRoots: string[], trustedFiles: string[] = [], trustedFileRoot?: string): { resolvedPath?: string; warning?: string } {
116
+ if (trustedRoots.length === 0 && (!trustedFileRoot || trustedFiles.length === 0)) return { warning: `Transcript preview has no trusted root: ${filePath}` };
114
117
  const resolvedPath = path.resolve(filePath);
115
- if (!trustedRoots.some((root) => pathWithin(root, resolvedPath))) {
118
+ const recordedCandidate = trustedFileRoot
119
+ && pathWithin(trustedFileRoot, resolvedPath)
120
+ && trustedFiles.some((file) => path.resolve(file) === resolvedPath);
121
+ if (!trustedRoots.some((root) => pathWithin(root, resolvedPath)) && !recordedCandidate) {
116
122
  return { warning: `Transcript is outside trusted roots: ${filePath}` };
117
123
  }
118
124
  let stat: fs.Stats;
@@ -129,7 +135,7 @@ function validateTranscriptPath(filePath: string, trustedRoots: string[]): { res
129
135
  const realRoots = trustedRoots
130
136
  .filter((root) => fs.existsSync(root))
131
137
  .map((root) => fs.realpathSync(root));
132
- if (!realRoots.some((root) => pathWithin(root, realPath))) {
138
+ if (!realRoots.some((root) => pathWithin(root, realPath)) && !isTrustedRecordedSessionFile(realPath, trustedFiles, trustedFileRoot)) {
133
139
  return { warning: `Transcript resolves outside trusted roots: ${filePath}` };
134
140
  }
135
141
  return { resolvedPath: realPath };
@@ -335,7 +341,7 @@ function parseTranscriptLines(lines: string[], conversationStarted = false): { e
335
341
  }
336
342
 
337
343
  export function readFleetTranscript(filePath: string, options: FleetTranscriptReadOptions): FleetTranscript {
338
- const validated = validateTranscriptPath(filePath, options.trustedRoots);
344
+ const validated = validateTranscriptPath(filePath, options.trustedRoots, options.trustedFiles, options.trustedFileRoot);
339
345
  if (!validated.resolvedPath) {
340
346
  return { path: filePath, events: [], truncated: false, ...(validated.warning ? { warning: safeDisplayText(validated.warning) } : {}) };
341
347
  }