@xzzpig/pi-subagents 0.7.0 → 0.9.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 (234) hide show
  1. package/CHANGELOG.md +456 -4
  2. package/README.md +3 -3
  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 +13 -3
  10. package/agents/scout.md +1 -1
  11. package/docs/agents.md +154 -42
  12. package/docs/configuration.md +85 -26
  13. package/docs/extension-api.md +81 -16
  14. package/docs/missions.md +2 -0
  15. package/docs/models.md +75 -11
  16. package/docs/observability.md +34 -21
  17. package/docs/tool-reference.md +142 -18
  18. package/docs/watchdog.md +92 -114
  19. package/docs/workflows.md +148 -4
  20. package/index.ts +10 -1
  21. package/install.mjs +1 -1
  22. package/package.json +7 -6
  23. package/prompts/council.md +19 -7
  24. package/prompts/parallel-review.md +5 -1
  25. package/prompts/review-loop.md +11 -7
  26. package/skills/council-mode/SKILL.md +44 -215
  27. package/skills/council-mode/references/pass-contracts.md +150 -0
  28. package/skills/pi-subagents/SKILL.md +90 -32
  29. package/skills/pi-subagents/references/constraints-and-recipes.md +34 -223
  30. package/skills/pi-subagents/references/execution-controls.md +104 -19
  31. package/skills/pi-subagents/references/management-authoring-rpc.md +5 -5
  32. package/skills/pi-subagents/references/multi-lane-orchestration.md +16 -4
  33. package/skills/pi-subagents/references/prompting-and-roles.md +71 -36
  34. package/skills/pi-subagents/references/review-and-validation.md +73 -0
  35. package/src/agents/agent-management.ts +471 -114
  36. package/src/agents/agent-refinements.ts +4 -4
  37. package/src/agents/agent-serializer.ts +16 -4
  38. package/src/agents/agents.ts +1076 -351
  39. package/src/agents/builtin-names.ts +6 -0
  40. package/src/agents/runtime-agent-events.ts +70 -0
  41. package/src/agents/runtime-agent-registry.ts +31 -20
  42. package/src/api/agents.ts +10 -5
  43. package/src/api/background-work.ts +12 -3
  44. package/src/api/capability-ceiling.ts +0 -1
  45. package/src/api/{pi-args.ts → child-tool-plan.ts} +1 -1
  46. package/src/api/delegation.ts +0 -7
  47. package/src/api/external-job-provider.ts +10 -1
  48. package/src/api/external-runs.ts +67 -4
  49. package/src/api/preflight.ts +97 -34
  50. package/src/api/project-panes.ts +2 -0
  51. package/src/api/shared-types.ts +6 -0
  52. package/src/extension/config.ts +90 -0
  53. package/src/extension/doctor.ts +15 -13
  54. package/src/extension/fanout-child.ts +17 -16
  55. package/src/extension/index.ts +139 -41
  56. package/src/extension/public-execution.ts +113 -22
  57. package/src/extension/rpc.ts +182 -13
  58. package/src/extension/schemas.ts +63 -21
  59. package/src/extension/tool-description.ts +48 -23
  60. package/src/extension/tool-result.ts +19 -0
  61. package/src/inspectors/herdr/actions.ts +2 -1
  62. package/src/inspectors/herdr/client.ts +3 -3
  63. package/src/inspectors/herdr/focus.ts +55 -0
  64. package/src/inspectors/herdr/inspector-runner.ts +21 -23
  65. package/src/inspectors/herdr/project-panes.ts +228 -44
  66. package/src/inspectors/herdr/session-roots-codec.ts +42 -0
  67. package/src/integrations/herdr-status.ts +75 -5
  68. package/src/intercom/native-supervisor-channel.ts +138 -60
  69. package/src/intercom/result-intercom.ts +2 -0
  70. package/src/intercom/supervisor-ui.ts +243 -0
  71. package/src/profiles/profiles.ts +5 -6
  72. package/src/runs/background/active-async-capacity.ts +103 -18
  73. package/src/runs/background/async-execution.ts +492 -125
  74. package/src/runs/background/async-job-tracker.ts +127 -28
  75. package/src/runs/background/async-resume.ts +67 -29
  76. package/src/runs/background/async-retention.ts +21 -4
  77. package/src/runs/background/async-status-snapshot.ts +23 -261
  78. package/src/runs/background/async-status.ts +199 -14
  79. package/src/runs/background/auto-drain.ts +1 -1
  80. package/src/runs/background/chain-append.ts +8 -3
  81. package/src/runs/background/chain-root-attachment.ts +79 -8
  82. package/src/runs/background/control-channel.ts +101 -214
  83. package/src/runs/background/fleet-view.ts +38 -22
  84. package/src/runs/background/inspect-rpc.ts +8 -8
  85. package/src/runs/background/notify.ts +295 -8
  86. package/src/runs/background/process-terminal.ts +16 -0
  87. package/src/runs/background/result-delivery-ownership.ts +45 -0
  88. package/src/runs/background/result-files.ts +28 -14
  89. package/src/runs/background/result-watcher.ts +43 -19
  90. package/src/runs/background/resume-guidance.ts +2 -2
  91. package/src/runs/background/retained-children.ts +1 -1
  92. package/src/runs/background/run-child-session.ts +613 -0
  93. package/src/runs/background/run-status.ts +99 -18
  94. package/src/runs/background/runner-aliases.ts +125 -0
  95. package/src/runs/background/runner-child-sessions.ts +31 -0
  96. package/src/runs/background/scheduled-runs.ts +174 -18
  97. package/src/runs/background/stale-run-reconciler.ts +13 -4
  98. package/src/runs/background/steering.ts +8 -15
  99. package/src/runs/background/subagent-runner.ts +959 -1159
  100. package/src/runs/background/subagent-wait.ts +86 -31
  101. package/src/runs/background/terminal-run-index.ts +1 -1
  102. package/src/runs/background/wait-completions.ts +45 -2
  103. package/src/runs/background/wait-config.ts +23 -9
  104. package/src/runs/background/wait-tool.ts +27 -19
  105. package/src/runs/foreground/async-steering-action.ts +3 -19
  106. package/src/runs/foreground/async-stop-action.ts +23 -2
  107. package/src/runs/foreground/execution.ts +585 -481
  108. package/src/runs/foreground/foreground-control.ts +13 -0
  109. package/src/runs/foreground/foreground-history.ts +26 -3
  110. package/src/runs/foreground/subagent-executor.ts +1549 -410
  111. package/src/runs/foreground/workflow-detach-reconcile.ts +141 -104
  112. package/src/runs/foreground/workflow-foreground-steering.ts +24 -98
  113. package/src/runs/shared/abort-recovery.ts +119 -0
  114. package/src/runs/shared/acceptance.ts +147 -39
  115. package/src/runs/shared/agent-contract.ts +1 -1
  116. package/src/runs/shared/async-status-projection.ts +565 -0
  117. package/src/runs/shared/background-process-options.ts +9 -0
  118. package/src/runs/shared/capability-ceiling.ts +2 -2
  119. package/src/runs/shared/child-hooks.ts +25 -0
  120. package/src/runs/shared/child-identity.ts +62 -0
  121. package/src/runs/shared/child-launch-plan.ts +151 -0
  122. package/src/runs/shared/child-launch.ts +314 -0
  123. package/src/runs/shared/child-lifecycle.ts +25 -0
  124. package/src/runs/shared/child-runtime-config.ts +126 -0
  125. package/src/runs/shared/child-session.ts +342 -0
  126. package/src/runs/shared/child-tool-plan.ts +540 -0
  127. package/src/runs/shared/claude-code-adapter.ts +133 -0
  128. package/src/runs/shared/codex-exec-adapter.ts +129 -0
  129. package/src/runs/shared/completion-evidence.ts +89 -0
  130. package/src/runs/shared/completion-guard.ts +57 -6
  131. package/src/runs/shared/cursor-agent-adapter.ts +114 -0
  132. package/src/runs/shared/dynamic-fanout.ts +4 -4
  133. package/src/runs/shared/extension-bindings.ts +78 -0
  134. package/src/runs/shared/external-cli-contract.ts +167 -0
  135. package/src/runs/shared/external-cli-preflight.ts +138 -0
  136. package/src/runs/shared/external-cli-runner.ts +349 -54
  137. package/src/runs/shared/external-job-bridge.ts +53 -37
  138. package/src/runs/shared/external-job-runner.ts +126 -23
  139. package/src/runs/shared/fast-mode-extension.ts +10 -0
  140. package/src/runs/shared/host-step-status.ts +231 -0
  141. package/src/runs/shared/lane-metadata.ts +126 -0
  142. package/src/runs/shared/launch-cwd.ts +16 -0
  143. package/src/runs/shared/long-running-guard.ts +2 -1
  144. package/src/runs/shared/mcp-config-sources.ts +422 -0
  145. package/src/runs/shared/mcp-direct-tool-allowlist.ts +222 -158
  146. package/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
  147. package/src/runs/shared/model-exclusions.ts +141 -10
  148. package/src/runs/shared/model-fallback.ts +187 -33
  149. package/src/runs/shared/model-scope.ts +106 -39
  150. package/src/runs/shared/mutation-evidence.ts +199 -0
  151. package/src/runs/shared/nested-events.ts +38 -48
  152. package/src/runs/shared/nested-path.ts +0 -14
  153. package/src/runs/shared/nested-render.ts +9 -5
  154. package/src/runs/shared/orca-progress-tabs.ts +83 -16
  155. package/src/runs/shared/parallel-handoff.ts +423 -7
  156. package/src/runs/shared/parallel-utils.ts +28 -5
  157. package/src/runs/shared/permissions.ts +1 -14
  158. package/src/runs/shared/pi-spawn.ts +69 -35
  159. package/src/runs/shared/process-signal.ts +16 -0
  160. package/src/runs/shared/run-fanout-budget.ts +0 -13
  161. package/src/runs/shared/run-history.ts +21 -1
  162. package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -27
  163. package/src/runs/shared/single-output.ts +89 -22
  164. package/src/runs/shared/structured-output.ts +61 -7
  165. package/src/runs/shared/subagent-control.ts +6 -2
  166. package/src/runs/shared/subagent-prompt-runtime.ts +216 -360
  167. package/src/runs/shared/task-intent.ts +21 -7
  168. package/src/runs/shared/tool-availability.ts +18 -64
  169. package/src/runs/shared/tool-budget.ts +0 -14
  170. package/src/runs/shared/tool-timeout.ts +1 -1
  171. package/src/runs/shared/workflow-graph.ts +16 -0
  172. package/src/runs/shared/worktree-cleanup-plan.ts +866 -0
  173. package/src/runs/shared/worktree.ts +571 -62
  174. package/src/shared/atomic-json.ts +3 -1
  175. package/src/shared/child-session-name.ts +46 -0
  176. package/src/shared/extension-context.ts +24 -0
  177. package/src/shared/fork-context.ts +21 -12
  178. package/src/shared/fork-session-cwd.ts +27 -0
  179. package/src/shared/formatters.ts +18 -3
  180. package/src/shared/jsonl-writer.ts +11 -0
  181. package/src/shared/launch-contract.ts +20 -6
  182. package/src/shared/pruned-fork.ts +450 -0
  183. package/src/shared/session-file-trust.ts +19 -0
  184. package/src/shared/session-tokens.ts +14 -3
  185. package/src/shared/settings.ts +21 -102
  186. package/src/shared/shortcuts.ts +17 -0
  187. package/src/shared/thinking-ceiling.ts +46 -0
  188. package/src/shared/types.ts +644 -75
  189. package/src/shared/utils.ts +60 -93
  190. package/src/shared/workflow-child-permit.ts +207 -0
  191. package/src/slash/delegation-adapters.ts +1 -9
  192. package/src/slash/delegation-request.ts +0 -4
  193. package/src/slash/prompt-template-bridge.ts +37 -1
  194. package/src/slash/slash-bridge.ts +1 -2
  195. package/src/slash/slash-commands.ts +383 -116
  196. package/src/slash/slash-live-state.ts +22 -11
  197. package/src/slash/subagents-admin.ts +29 -12
  198. package/src/tui/fleet-native-transcript.ts +4 -0
  199. package/src/tui/fleet-status.ts +278 -90
  200. package/src/tui/fleet-transcript.ts +11 -5
  201. package/src/tui/fleet.ts +54 -28
  202. package/src/tui/render-helpers.ts +31 -0
  203. package/src/tui/render.ts +1433 -166
  204. package/src/watchdog/change-signature.ts +40 -1
  205. package/src/watchdog/child-status.ts +54 -34
  206. package/src/watchdog/diff-tool.ts +77 -0
  207. package/src/watchdog/emission-guard.ts +5 -3
  208. package/src/watchdog/guidance.ts +20 -0
  209. package/src/watchdog/permission-arbiter.ts +59 -52
  210. package/src/watchdog/register-child.ts +28 -25
  211. package/src/watchdog/register-main.ts +10 -9
  212. package/src/watchdog/render.ts +4 -5
  213. package/src/watchdog/review.ts +15 -4
  214. package/src/watchdog/rules.ts +70 -0
  215. package/src/watchdog/runtime.ts +75 -92
  216. package/src/watchdog/scope.ts +0 -11
  217. package/src/watchdog/settings.ts +48 -104
  218. package/src/watchdog/turn-delta.ts +1 -1
  219. package/src/watchdog/types.ts +18 -32
  220. package/src/watchdog/warning-format.ts +0 -1
  221. package/src/workflows/chat-progress.ts +7 -3
  222. package/src/workflows/host-command.ts +235 -0
  223. package/src/workflows/scripted-workflow.ts +1142 -69
  224. package/src/workflows/workflow-checklist.ts +439 -0
  225. package/src/workflows/workflow-child-summary.ts +121 -0
  226. package/src/workflows/workflow-preflight.ts +297 -0
  227. package/src/workflows/workflow-receipt.ts +232 -6
  228. package/src/workflows/workflow-resources.ts +150 -0
  229. package/src/workflows/workflow-settlement.ts +246 -0
  230. package/src/runs/shared/child-protocol.ts +0 -401
  231. package/src/runs/shared/pi-args.ts +0 -858
  232. package/src/runs/shared/subagent-startup-retry.ts +0 -116
  233. package/src/runs/shared/turn-budget.ts +0 -98
  234. package/src/shared/post-exit-stdio-guard.ts +0 -85
@@ -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
  }
package/src/tui/fleet.ts CHANGED
@@ -5,7 +5,7 @@ import { getMarkdownTheme, type ExtensionContext } from "@earendil-works/pi-codi
5
5
  import { matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component, type MarkdownTheme } from "@earendil-works/pi-tui";
6
6
  import { snapshotExternalRuns, type ExternalRun } from "../api/external-runs.ts";
7
7
  import { getArtifactPaths, getArtifactsDir } from "../shared/artifacts.ts";
8
- import { formatDuration, formatModelThinking, formatTokens, shortenPath } from "../shared/formatters.ts";
8
+ import { formatDuration, formatModelThinking, formatTokens, formatTokenUsage, shortenPath } from "../shared/formatters.ts";
9
9
  import { DIRS, type AsyncJobState, type AsyncJobStep, type Details, type FleetKeybindingAction, type FleetKeybindingsConfig, type ForegroundChildControl, type ForegroundResumeChild, type ForegroundResumeRun, type ForegroundRunControl, type SubagentState } from "../shared/types.ts";
10
10
  import { decodeUtf8Tail } from "../shared/utf8.ts";
11
11
  import { readStatus } from "../shared/utils.ts";
@@ -45,7 +45,7 @@ export const DEFAULT_FLEET_KEYBINDINGS: Record<FleetKeybindingAction, string[]>
45
45
  pageDown: ["pageDown"],
46
46
  refresh: ["r", "R"],
47
47
  steer: ["s"],
48
- inspect: ["H"],
48
+ inspect: ["return", "H"],
49
49
  stop: ["D"],
50
50
  toggleTools: ["x", "X", "ctrl+o"],
51
51
  toggleRenderer: ["v", "V"],
@@ -151,6 +151,7 @@ function trackedJobSummary(job: AsyncJobState): AsyncRunSummary {
151
151
  ...(job.currentStep !== undefined ? { currentStep: job.currentStep } : {}),
152
152
  ...(job.chainStepCount !== undefined ? { chainStepCount: job.chainStepCount } : {}),
153
153
  ...(job.parallelGroups?.length ? { parallelGroups: job.parallelGroups } : {}),
154
+ ...(job.preflight ? { preflight: job.preflight } : {}),
154
155
  steps: (job.steps ?? job.agents?.map((agent, index) => ({ agent, index, status: job.status === "queued" ? "pending" as const : job.status })) ?? []).map((step, index) => ({
155
156
  ...step,
156
157
  index: step.index ?? index,
@@ -207,7 +208,6 @@ export function collectFleetSnapshot(
207
208
  if (!control.parentWorkflowRunId
208
209
  || !workflowParentIds.has(control.parentWorkflowRunId)
209
210
  || !belongsToCurrentSession(control.sessionId, state.currentSessionId)
210
- || !control.workflowSteeringDir
211
211
  || activeChildCount === 0) continue;
212
212
  liveWorkflowForegroundControls.add(control);
213
213
  workflowForegroundChildCounts.set(control.parentWorkflowRunId, (workflowForegroundChildCounts.get(control.parentWorkflowRunId) ?? 0) + activeChildCount);
@@ -359,7 +359,12 @@ function foregroundPromptAuditCount(item: Extract<FleetItem, { kind: "foreground
359
359
  return [...item.control.activeChildren.keys()].filter((index) => getLivePromptAudit(item.control, index)).length;
360
360
  }
361
361
 
362
- function authoredPromptSummary(text: string): string | undefined {
362
+ function promptAuditString(value: unknown): string | undefined {
363
+ return typeof value === "string" ? value : undefined;
364
+ }
365
+
366
+ function authoredPromptSummary(text: unknown): string | undefined {
367
+ if (typeof text !== "string") return undefined;
363
368
  const summary = text.replace(/\s+/g, " ").trim();
364
369
  return summary ? truncateToWidth(summary, PROMPT_AUDIT_SUMMARY_WIDTH, "…") : undefined;
365
370
  }
@@ -370,11 +375,11 @@ function foregroundAuthoredPromptSummary(item: Extract<FleetItem, { kind: "foreg
370
375
  return prompt ? authoredPromptSummary(prompt.authoredTask) : undefined;
371
376
  }
372
377
 
373
- function promptAuditText(prompt: LivePromptAudit, view: PromptAuditView): string {
378
+ function promptAuditText(prompt: LivePromptAudit, view: PromptAuditView): string | undefined {
374
379
  switch (view) {
375
- case "authored": return prompt.authoredTask;
376
- case "runtime": return prompt.runtimeAdditions;
377
- case "effective": return prompt.finalEffectivePrompt;
380
+ case "authored": return promptAuditString(prompt.authoredTask);
381
+ case "runtime": return promptAuditString(prompt.runtimeAdditions);
382
+ case "effective": return promptAuditString(prompt.finalEffectivePrompt);
378
383
  }
379
384
  }
380
385
 
@@ -407,7 +412,9 @@ function foregroundActiveDetail(item: Extract<FleetItem, { kind: "foreground-act
407
412
  live.currentTool ? `Current tool: ${live.currentTool}${live.currentPath ? ` · ${shortenPath(live.currentPath)}` : ""}` : undefined,
408
413
  live.turnCount !== undefined ? `Turns: ${live.turnCount}` : undefined,
409
414
  live.toolCount !== undefined ? `Tools: ${live.toolCount}` : undefined,
410
- live.tokens !== undefined ? `Tokens: ${formatTokens(live.tokens)}` : undefined,
415
+ live.tokens !== undefined
416
+ ? `Tokens: ${formatTokenUsage({ input: live.inputTokens ?? 0, output: live.outputTokens ?? 0, total: live.tokens, ...(live.window !== undefined ? { window: live.window } : {}), ...(live.windowPeak !== undefined ? { windowPeak: live.windowPeak } : {}) }, "tokens")}`
417
+ : undefined,
411
418
  promptAuditCount > 0 ? `Prompt audit: ${promptAuditCount} live · 3 views · p opens` : undefined,
412
419
  "",
413
420
  "Transcript",
@@ -537,7 +544,7 @@ function workflowProgressLines(steps: AsyncJobStep[] | undefined): string[] {
537
544
  }
538
545
  const activity = workflowStepActivity(row.step);
539
546
  const context = contextModeLabel(row.step.context);
540
- const details = [row.step.status, activity, context, row.step.tokens?.total !== undefined ? formatTokens(row.step.tokens.total) : undefined].filter(Boolean).join(" · ");
547
+ const details = [row.step.status, activity, context, row.step.tokens ? formatTokenUsage(row.step.tokens) : undefined].filter(Boolean).join(" · ");
541
548
  lines.push(` ${row.index + 1}. ${workflowStepLabel(row.step, row.index)}${details ? ` — ${details}` : ""}`);
542
549
  }
543
550
  return lines;
@@ -551,6 +558,8 @@ function asyncDetail(item: Extract<FleetItem, { kind: "async" }>, state: Subagen
551
558
  index: item.index,
552
559
  lines: TRANSCRIPT_LINES,
553
560
  sessionRoots: uniquePaths([...(state.trustedSessionRoots ?? []), trackedJob?.sessionRoot]),
561
+ trustedSessionFiles: [item.step?.sessionFile ?? item.run.sessionFile].filter((value): value is string => Boolean(value)),
562
+ trustedSessionFileRoot: state.trustedSessionFileRoot,
554
563
  }).split("\n");
555
564
  if (status.mode === "workflow" && item.index === undefined) {
556
565
  const progress = workflowProgressLines((status.steps ?? item.run.steps) as AsyncJobStep[]);
@@ -632,7 +641,7 @@ function fleetArtifactsRoot(state: SubagentState, cwd: string): string {
632
641
  );
633
642
  }
634
643
 
635
- function transcriptTarget(item: FleetItem, state: SubagentState): { path: string; trustedRoots: string[] } | undefined {
644
+ function transcriptTarget(item: FleetItem, state: SubagentState): { path: string; trustedRoots: string[]; trustedFiles?: string[]; trustedFileRoot?: string } | undefined {
636
645
  if (item.kind === "external") return undefined;
637
646
  if (item.kind === "foreground-active") {
638
647
  const artifactsRoot = fleetArtifactsRoot(state, item.control.cwd ?? state.baseCwd);
@@ -655,10 +664,12 @@ function transcriptTarget(item: FleetItem, state: SubagentState): { path: string
655
664
  };
656
665
  }
657
666
  const step = item.step ?? (item.run.steps.length === 1 ? item.run.steps[0] : undefined);
658
- if (!step?.transcriptPath) return undefined;
659
- const transcriptPath = path.isAbsolute(step.transcriptPath)
660
- ? step.transcriptPath
661
- : path.resolve(item.run.asyncDir, step.transcriptPath);
667
+ const recordedSessionFile = step?.sessionFile ?? item.run.sessionFile;
668
+ const recordedPath = step?.transcriptPath ?? recordedSessionFile;
669
+ if (!recordedPath) return undefined;
670
+ const transcriptPath = path.isAbsolute(recordedPath)
671
+ ? recordedPath
672
+ : path.resolve(item.run.asyncDir, recordedPath);
662
673
  const trackedJob = state.fleetJobs?.get(item.runId) ?? state.asyncJobs.get(item.runId);
663
674
  return {
664
675
  path: transcriptPath,
@@ -668,6 +679,7 @@ function transcriptTarget(item: FleetItem, state: SubagentState): { path: string
668
679
  trackedJob?.cwd ? fleetArtifactsRoot(state, trackedJob.cwd) : undefined,
669
680
  item.run.sessionFile ? getArtifactsDir(item.run.sessionFile, item.run.cwd ?? state.baseCwd, state.artifactDirPreference) : undefined,
670
681
  ]),
682
+ ...(!step?.transcriptPath && recordedSessionFile ? { trustedFiles: [recordedSessionFile], trustedFileRoot: state.trustedSessionFileRoot } : {}),
671
683
  };
672
684
  }
673
685
 
@@ -691,23 +703,27 @@ function itemSource(item: FleetItem): string {
691
703
  function itemStats(item: FleetItem): string[] {
692
704
  let model: string | undefined;
693
705
  let tokens: number | undefined;
706
+ let tokenUsage: AsyncJobStep["tokens"];
694
707
  let tools: number | undefined;
695
708
  let durationMs: number | undefined;
696
709
  if (item.kind === "foreground-active") {
697
710
  const live = item.activeChild ?? item.control;
698
711
  model = formatModelThinking(live.model, live.thinking) || undefined;
699
712
  tokens = live.tokens;
713
+ if (tokens !== undefined) tokenUsage = { input: live.inputTokens ?? 0, output: live.outputTokens ?? 0, total: tokens, ...(live.window !== undefined ? { window: live.window } : {}), ...(live.windowPeak !== undefined ? { windowPeak: live.windowPeak } : {}) };
700
714
  tools = live.toolCount;
701
715
  durationMs = Math.max(0, Date.now() - live.startedAt);
702
716
  } else if (item.kind === "foreground-recent") {
703
717
  model = formatModelThinking(item.child.model, item.child.thinking) || undefined;
704
718
  tokens = item.child.tokens;
719
+ if (tokens !== undefined) tokenUsage = { input: 0, output: 0, total: tokens, ...(item.child.window !== undefined ? { window: item.child.window } : {}), ...(item.child.windowPeak !== undefined ? { windowPeak: item.child.windowPeak } : {}) };
705
720
  tools = item.child.toolCount;
706
721
  } else if (item.kind === "external") {
707
722
  durationMs = Math.max(0, externalElapsedEnd(item.run) - item.run.startedAt);
708
723
  } else {
709
724
  model = formatModelThinking(item.step?.model, item.step?.thinking) || undefined;
710
- tokens = item.step?.tokens?.total ?? (item.index === undefined ? item.run.totalTokens?.total : undefined);
725
+ tokenUsage = item.step?.tokens ?? (item.index === undefined ? item.run.totalTokens : undefined);
726
+ tokens = tokenUsage?.total;
711
727
  tools = item.step?.toolCount ?? (item.index === undefined ? item.run.toolCount : undefined);
712
728
  const terminalRun = item.state !== "queued" && item.state !== "running" && item.state !== "pending";
713
729
  const endTime = item.run.endedAt ?? (terminalRun ? item.run.lastUpdate : undefined) ?? Date.now();
@@ -715,7 +731,7 @@ function itemStats(item: FleetItem): string[] {
715
731
  }
716
732
  return [
717
733
  model,
718
- tokens !== undefined ? `${formatTokens(tokens)} tok` : undefined,
734
+ tokenUsage ? formatTokenUsage(tokenUsage) : tokens !== undefined ? `${formatTokens(tokens)} tok` : undefined,
719
735
  tools !== undefined ? `${tools} tool${tools === 1 ? "" : "s"}` : undefined,
720
736
  durationMs !== undefined ? formatDuration(durationMs) : undefined,
721
737
  ].filter((value): value is string => Boolean(value));
@@ -833,11 +849,13 @@ export class SubagentFleetComponent implements Component {
833
849
  });
834
850
  }
835
851
 
836
- private nativeRenderedOutcome(mod: NativeTranscriptModule, target: { path: string; trustedRoots: string[] }, width: number): { body: string[]; conversationState: string; hasContent: boolean; warning?: string } {
852
+ private nativeRenderedOutcome(mod: NativeTranscriptModule, target: { path: string; trustedRoots: string[]; trustedFiles?: string[]; trustedFileRoot?: string }, width: number): { body: string[]; conversationState: string; hasContent: boolean; warning?: string } {
837
853
  try {
838
854
  const built = buildNativeFleetTranscript(mod, {
839
855
  filePath: target.path,
840
856
  trustedRoots: target.trustedRoots,
857
+ ...(target.trustedFiles ? { trustedFiles: target.trustedFiles } : {}),
858
+ ...(target.trustedFileRoot ? { trustedFileRoot: target.trustedFileRoot } : {}),
841
859
  width,
842
860
  expandedTools: this.expandedTools,
843
861
  cwd: this.state.baseCwd,
@@ -852,8 +870,12 @@ export class SubagentFleetComponent implements Component {
852
870
  }
853
871
  }
854
872
 
855
- private legacyRenderedOutcome(target: { path: string; trustedRoots: string[] }, width: number): { body: string[]; conversationState: string; hasContent: boolean; warning?: string } {
856
- const transcript = readFleetTranscript(target.path, { trustedRoots: target.trustedRoots });
873
+ private legacyRenderedOutcome(target: { path: string; trustedRoots: string[]; trustedFiles?: string[]; trustedFileRoot?: string }, width: number): { body: string[]; conversationState: string; hasContent: boolean; warning?: string } {
874
+ const transcript = readFleetTranscript(target.path, {
875
+ trustedRoots: target.trustedRoots,
876
+ ...(target.trustedFiles ? { trustedFiles: target.trustedFiles } : {}),
877
+ ...(target.trustedFileRoot ? { trustedFileRoot: target.trustedFileRoot } : {}),
878
+ });
857
879
  const body = transcript.events.length > 0
858
880
  ? renderFleetTranscript(transcript, width, this.theme, this.markdownTheme, { expandedTools: this.expandedTools })
859
881
  : [];
@@ -993,6 +1015,12 @@ export class SubagentFleetComponent implements Component {
993
1015
  return { runId: parent.asyncId, asyncDir: parent.asyncDir };
994
1016
  }
995
1017
 
1018
+ private inspectSelectedHerdr(): void {
1019
+ const target = this.selectedHerdrInspectAction();
1020
+ if ("reason" in target || !this.options.actions?.inspect) this.setActionNotice({ text: "reason" in target ? target.reason : "Herdr inspector controls are unavailable in this context.", isError: true });
1021
+ else this.runAction(() => this.options.actions!.inspect!(target));
1022
+ }
1023
+
996
1024
  private actionLines(): string[] {
997
1025
  const lines: string[] = [];
998
1026
  if (this.actionBusy) lines.push(this.theme.fg("accent", "Action pending..."));
@@ -1235,12 +1263,6 @@ export class SubagentFleetComponent implements Component {
1235
1263
  }
1236
1264
  return;
1237
1265
  }
1238
- if (matchesFleetAction(data, this.keybindings, "inspect")) {
1239
- const target = this.selectedHerdrInspectAction();
1240
- if ("reason" in target || !this.options.actions?.inspect) this.setActionNotice({ text: "reason" in target ? target.reason : "Herdr inspector controls are unavailable in this context.", isError: true });
1241
- else this.runAction(() => this.options.actions!.inspect!(target));
1242
- return;
1243
- }
1244
1266
  if (matchesFleetAction(data, this.keybindings, "stop")) {
1245
1267
  const target = this.selectedAsyncAction();
1246
1268
  if ("reason" in target || !this.options.actions) this.setActionNotice({ text: "reason" in target ? target.reason : "Fleet controls are unavailable in this context.", isError: true });
@@ -1259,6 +1281,10 @@ export class SubagentFleetComponent implements Component {
1259
1281
  this.tui.requestRender();
1260
1282
  return;
1261
1283
  }
1284
+ if (matchesFleetAction(data, this.keybindings, "inspect")) {
1285
+ this.inspectSelectedHerdr();
1286
+ return;
1287
+ }
1262
1288
  if (matchesFleetAction(data, this.keybindings, "toggleRenderer")) {
1263
1289
  if (this.rendererMode === "native" && this.nativeModule === null) {
1264
1290
  this.setActionNotice({ text: "Native transcript renderer unavailable in this host; staying on the text view.", isError: true });
@@ -1290,8 +1316,8 @@ export class SubagentFleetComponent implements Component {
1290
1316
  });
1291
1317
  }
1292
1318
 
1293
- private renderedTranscript(target: { path: string; trustedRoots: string[] }, width: number): { body: string[]; conversationState: string; hasContent: boolean; warning?: string } {
1294
- const fingerprint = `${this.rendererMode}|${target.trustedRoots.join("\0")}|${transcriptFingerprint(target.path)}`;
1319
+ private renderedTranscript(target: { path: string; trustedRoots: string[]; trustedFiles?: string[]; trustedFileRoot?: string }, width: number): { body: string[]; conversationState: string; hasContent: boolean; warning?: string } {
1320
+ const fingerprint = `${this.rendererMode}|${target.trustedRoots.join("\0")}|${target.trustedFiles?.join("\0") ?? ""}|${target.trustedFileRoot ?? ""}|${transcriptFingerprint(target.path)}`;
1295
1321
  if (this.transcriptCache
1296
1322
  && this.transcriptCache.mode === this.rendererMode
1297
1323
  && this.transcriptCache.path === target.path
@@ -30,6 +30,37 @@ export function fuzzyFilter<T extends { name: string; description: string; model
30
30
  .map((x) => x.item);
31
31
  }
32
32
 
33
+ /** Remove a repeated job name from a child label when a safe separator follows it. */
34
+ export function stripRepeatedAgentPrefix(label: string, jobName: string | undefined): string {
35
+ const value = label.trim();
36
+ const prefix = jobName?.trim();
37
+ if (!prefix || !value.startsWith(prefix)) return value;
38
+
39
+ const suffix = value.slice(prefix.length);
40
+ if (!suffix || !/^(?::|·|\s)/u.test(suffix)) return value;
41
+ return suffix.replace(/^\s*(?::|·)?\s*/u, "").trim();
42
+ }
43
+
44
+ /** Whether a status label may omit the one logical step marker. */
45
+ export function shouldSuppressSingleStep(chainStepCount?: number, stepsTotal?: number): boolean {
46
+ return (chainStepCount ?? stepsTotal) === 1;
47
+ }
48
+
49
+ /** Add an Agent fraction only when visible candidates collide. */
50
+ export function withDuplicateLabelDiscriminators<T extends { index: number; displayName: string }>(
51
+ rows: readonly T[],
52
+ total: number,
53
+ ): Array<T & { rowLabel: string }> {
54
+ const counts = new Map<string, number>();
55
+ for (const row of rows) counts.set(row.displayName, (counts.get(row.displayName) ?? 0) + 1);
56
+ return rows.map((row) => ({
57
+ ...row,
58
+ rowLabel: (counts.get(row.displayName) ?? 0) > 1
59
+ ? `Agent ${row.index + 1}/${total}: ${row.displayName}`
60
+ : row.displayName,
61
+ }));
62
+ }
63
+
33
64
  export function pad(s: string, len: number): string {
34
65
  const vis = visibleWidth(s);
35
66
  return s + " ".repeat(Math.max(0, len - vis));