@xzzpig/pi-subagents 0.8.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 (218) hide show
  1. package/CHANGELOG.md +443 -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 +151 -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 +5 -4
  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 +370 -114
  33. package/src/agents/agent-refinements.ts +4 -4
  34. package/src/agents/agent-serializer.ts +12 -2
  35. package/src/agents/agents.ts +919 -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 +31 -20
  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 +48 -18
  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 +57 -21
  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 +2 -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 +366 -128
  65. package/src/runs/background/async-job-tracker.ts +95 -15
  66. package/src/runs/background/async-resume.ts +45 -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 +189 -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 +676 -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 +468 -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 +1172 -400
  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 +314 -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 +342 -0
  115. package/src/runs/shared/child-tool-plan.ts +540 -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 +142 -14
  135. package/src/runs/shared/mutation-evidence.ts +57 -3
  136. package/src/runs/shared/nested-events.ts +38 -48
  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 +15 -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/single-output.ts +89 -22
  149. package/src/runs/shared/structured-output.ts +49 -9
  150. package/src/runs/shared/subagent-control.ts +6 -2
  151. package/src/runs/shared/subagent-prompt-runtime.ts +188 -365
  152. package/src/runs/shared/task-intent.ts +21 -7
  153. package/src/runs/shared/tool-availability.ts +18 -62
  154. package/src/runs/shared/tool-budget.ts +0 -14
  155. package/src/runs/shared/tool-timeout.ts +1 -1
  156. package/src/runs/shared/workflow-graph.ts +16 -0
  157. package/src/runs/shared/worktree-cleanup-plan.ts +866 -0
  158. package/src/runs/shared/worktree.ts +571 -62
  159. package/src/shared/atomic-json.ts +3 -1
  160. package/src/shared/child-session-name.ts +46 -0
  161. package/src/shared/extension-context.ts +24 -0
  162. package/src/shared/fork-context.ts +21 -12
  163. package/src/shared/fork-session-cwd.ts +27 -0
  164. package/src/shared/formatters.ts +18 -3
  165. package/src/shared/jsonl-writer.ts +11 -0
  166. package/src/shared/launch-contract.ts +8 -1
  167. package/src/shared/pruned-fork.ts +450 -0
  168. package/src/shared/session-file-trust.ts +19 -0
  169. package/src/shared/session-tokens.ts +14 -3
  170. package/src/shared/settings.ts +19 -105
  171. package/src/shared/shortcuts.ts +17 -0
  172. package/src/shared/thinking-ceiling.ts +0 -6
  173. package/src/shared/types.ts +524 -70
  174. package/src/shared/utils.ts +60 -93
  175. package/src/shared/workflow-child-permit.ts +207 -0
  176. package/src/slash/delegation-adapters.ts +1 -9
  177. package/src/slash/delegation-request.ts +0 -4
  178. package/src/slash/prompt-template-bridge.ts +37 -1
  179. package/src/slash/slash-bridge.ts +1 -2
  180. package/src/slash/slash-commands.ts +383 -116
  181. package/src/slash/slash-live-state.ts +22 -11
  182. package/src/slash/subagents-admin.ts +29 -12
  183. package/src/tui/fleet-native-transcript.ts +4 -0
  184. package/src/tui/fleet-status.ts +217 -82
  185. package/src/tui/fleet-transcript.ts +11 -5
  186. package/src/tui/fleet.ts +54 -28
  187. package/src/tui/render-helpers.ts +31 -0
  188. package/src/tui/render.ts +1429 -163
  189. package/src/watchdog/change-signature.ts +40 -1
  190. package/src/watchdog/child-status.ts +54 -34
  191. package/src/watchdog/diff-tool.ts +77 -0
  192. package/src/watchdog/emission-guard.ts +5 -3
  193. package/src/watchdog/guidance.ts +20 -0
  194. package/src/watchdog/register-child.ts +28 -25
  195. package/src/watchdog/register-main.ts +10 -9
  196. package/src/watchdog/render.ts +4 -5
  197. package/src/watchdog/review.ts +15 -4
  198. package/src/watchdog/rules.ts +70 -0
  199. package/src/watchdog/runtime.ts +75 -92
  200. package/src/watchdog/scope.ts +0 -11
  201. package/src/watchdog/settings.ts +48 -104
  202. package/src/watchdog/turn-delta.ts +1 -1
  203. package/src/watchdog/types.ts +18 -32
  204. package/src/watchdog/warning-format.ts +0 -1
  205. package/src/workflows/chat-progress.ts +7 -3
  206. package/src/workflows/host-command.ts +235 -0
  207. package/src/workflows/scripted-workflow.ts +988 -59
  208. package/src/workflows/workflow-checklist.ts +439 -0
  209. package/src/workflows/workflow-child-summary.ts +121 -0
  210. package/src/workflows/workflow-preflight.ts +297 -0
  211. package/src/workflows/workflow-receipt.ts +232 -6
  212. package/src/workflows/workflow-resources.ts +150 -0
  213. package/src/workflows/workflow-settlement.ts +246 -0
  214. package/src/runs/shared/child-protocol.ts +0 -401
  215. package/src/runs/shared/pi-args.ts +0 -935
  216. package/src/runs/shared/subagent-startup-retry.ts +0 -116
  217. package/src/runs/shared/turn-budget.ts +0 -98
  218. package/src/shared/post-exit-stdio-guard.ts +0 -85
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));