@xzzpig/pi-subagents 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/README.md +2 -0
  3. package/agents/oracle.md +7 -5
  4. package/agents/researcher.md +1 -1
  5. package/agents/reviewer.md +2 -2
  6. package/agents/scout.md +1 -1
  7. package/agents/worker.md +1 -1
  8. package/docs/agents.md +3 -0
  9. package/docs/configuration.md +121 -10
  10. package/docs/extension-api.md +36 -0
  11. package/docs/missions.md +5 -3
  12. package/docs/observability.md +43 -3
  13. package/docs/tool-reference.md +20 -3
  14. package/docs/workflows.md +2 -2
  15. package/package.json +4 -4
  16. package/skills/pi-subagents/references/constraints-and-recipes.md +3 -2
  17. package/skills/pi-subagents/references/execution-controls.md +5 -4
  18. package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
  19. package/skills/pi-subagents/references/prompting-and-roles.md +31 -15
  20. package/src/agents/agent-serializer.ts +2 -0
  21. package/src/agents/agents.ts +46 -15
  22. package/src/api/external-runs.ts +174 -84
  23. package/src/api/preflight.ts +13 -7
  24. package/src/extension/config.ts +59 -0
  25. package/src/extension/doctor.ts +40 -0
  26. package/src/extension/index.ts +83 -9
  27. package/src/extension/public-execution.ts +37 -4
  28. package/src/extension/rpc.ts +8 -10
  29. package/src/extension/schemas.ts +12 -10
  30. package/src/extension/tool-description.ts +13 -9
  31. package/src/inspectors/herdr/actions.ts +13 -8
  32. package/src/inspectors/herdr/inspector-runner.ts +16 -3
  33. package/src/inspectors/herdr/project-panes.ts +2 -6
  34. package/src/inspectors/herdr/shell-command.ts +16 -0
  35. package/src/intercom/intercom-bridge.ts +9 -5
  36. package/src/intercom/native-supervisor-channel.ts +19 -42
  37. package/src/missions/goal-driver.ts +3 -1
  38. package/src/missions/lifecycle.ts +4 -7
  39. package/src/missions/store.ts +12 -7
  40. package/src/missions/workflow-state.ts +6 -2
  41. package/src/runs/background/active-async-capacity.ts +431 -0
  42. package/src/runs/background/active-run-index.ts +77 -3
  43. package/src/runs/background/async-execution.ts +190 -72
  44. package/src/runs/background/async-job-tracker.ts +5 -0
  45. package/src/runs/background/async-resume.ts +21 -7
  46. package/src/runs/background/async-status-snapshot.ts +277 -0
  47. package/src/runs/background/async-status.ts +17 -6
  48. package/src/runs/background/chain-append.ts +33 -15
  49. package/src/runs/background/chain-root-attachment.ts +2 -2
  50. package/src/runs/background/completion-replay.ts +11 -1
  51. package/src/runs/background/fleet-view.ts +21 -6
  52. package/src/runs/background/owned-process-tree.ts +104 -0
  53. package/src/runs/background/process-terminal.ts +17 -3
  54. package/src/runs/background/result-files.ts +437 -0
  55. package/src/runs/background/result-watcher.ts +188 -41
  56. package/src/runs/background/resume-guidance.ts +27 -7
  57. package/src/runs/background/retained-children.ts +75 -18
  58. package/src/runs/background/run-id-resolver.ts +30 -24
  59. package/src/runs/background/run-status.ts +106 -5
  60. package/src/runs/background/scheduled-runs.ts +54 -28
  61. package/src/runs/background/stale-run-reconciler.ts +30 -16
  62. package/src/runs/background/subagent-runner.ts +352 -62
  63. package/src/runs/background/subagent-wait.ts +2 -0
  64. package/src/runs/background/wait-completions.ts +5 -2
  65. package/src/runs/foreground/async-dismiss-action.ts +2 -1
  66. package/src/runs/foreground/chain-execution.ts +53 -2
  67. package/src/runs/foreground/execution.ts +309 -34
  68. package/src/runs/foreground/foreground-control.ts +12 -0
  69. package/src/runs/foreground/prompt-audit.ts +172 -0
  70. package/src/runs/foreground/subagent-executor.ts +936 -224
  71. package/src/runs/shared/acceptance.ts +13 -4
  72. package/src/runs/shared/completion-guard.ts +107 -1
  73. package/src/runs/shared/external-cli-runner.ts +4 -0
  74. package/src/runs/shared/llm-intent-arbiter.ts +302 -0
  75. package/src/runs/shared/model-fallback.ts +16 -2
  76. package/src/runs/shared/nested-events.ts +66 -62
  77. package/src/runs/shared/orca-progress-tabs.ts +375 -0
  78. package/src/runs/shared/parallel-utils.ts +4 -0
  79. package/src/runs/shared/pi-args.ts +44 -1
  80. package/src/runs/shared/run-fanout-budget.ts +280 -0
  81. package/src/runs/shared/single-output.ts +4 -2
  82. package/src/runs/shared/subagent-control.ts +15 -0
  83. package/src/runs/shared/subagent-prompt-runtime.ts +1 -9
  84. package/src/runs/shared/subagent-startup-retry.ts +12 -0
  85. package/src/runs/shared/task-intent.ts +19 -3
  86. package/src/runs/shared/tool-timeout.ts +93 -0
  87. package/src/runs/shared/worktree.ts +17 -5
  88. package/src/shared/agent-stream-options.ts +5 -0
  89. package/src/shared/artifacts.ts +2 -6
  90. package/src/shared/display-text.ts +50 -0
  91. package/src/shared/node-executable.ts +21 -0
  92. package/src/shared/types.ts +143 -5
  93. package/src/shared/utils.ts +3 -1
  94. package/src/slash/slash-commands.ts +34 -25
  95. package/src/slash/slash-live-state.ts +3 -0
  96. package/src/tui/fleet-status.ts +164 -47
  97. package/src/tui/fleet-transcript.ts +1 -48
  98. package/src/tui/fleet.ts +352 -27
  99. package/src/tui/render.ts +122 -44
  100. package/src/watchdog/permission-arbiter.ts +2 -1
  101. package/src/watchdog/review.ts +4 -3
  102. package/src/workflows/chat-progress.ts +10 -2
  103. package/src/workflows/scripted-workflow.ts +292 -79
package/src/tui/fleet.ts CHANGED
@@ -3,6 +3,7 @@ import * as path from "node:path";
3
3
  import type { AgentToolResult } from "@earendil-works/pi-agent-core";
4
4
  import { getMarkdownTheme, type ExtensionContext } from "@earendil-works/pi-coding-agent";
5
5
  import { matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component, type MarkdownTheme } from "@earendil-works/pi-tui";
6
+ import { snapshotExternalRuns, type ExternalRun } from "../api/external-runs.ts";
6
7
  import { getArtifactPaths, getArtifactsDir } from "../shared/artifacts.ts";
7
8
  import { formatDuration, formatModelThinking, formatTokens, shortenPath } from "../shared/formatters.ts";
8
9
  import { DIRS, type AsyncJobState, type Details, type FleetKeybindingAction, type FleetKeybindingsConfig, type ForegroundChildControl, type ForegroundResumeChild, type ForegroundResumeRun, type ForegroundRunControl, type SubagentState } from "../shared/types.ts";
@@ -17,12 +18,15 @@ import { contextModeBadge, contextModeLabel } from "../runs/shared/context-mode.
17
18
  import { FLEET_STATUS_WIDGET_KEY } from "./fleet-status.ts";
18
19
  import { readFleetTranscript, renderFleetTranscript, type FleetTranscript } from "./fleet-transcript.ts";
19
20
  import { handleHerdrInspectorAction } from "../inspectors/herdr/actions.ts";
21
+ import { getLivePromptAudit, type LivePromptAudit, type PromptAuditView } from "../runs/foreground/prompt-audit.ts";
20
22
 
21
23
  const REFRESH_MS = 750;
24
+ const MIN_REFRESH_MS = 250;
22
25
  const MAX_RECENT_ASYNC_RUNS = 20;
23
26
  const MAX_FLEET_HISTORY_CANDIDATES = 100;
24
27
  const TRANSCRIPT_LINES = 200;
25
28
  const OUTPUT_TAIL_BYTES = 64 * 1024;
29
+ const PROMPT_AUDIT_SUMMARY_WIDTH = 160;
26
30
 
27
31
  export const DEFAULT_FLEET_KEYBINDINGS: Record<FleetKeybindingAction, string[]> = {
28
32
  close: ["escape", "ctrl+c", "q"],
@@ -75,6 +79,7 @@ export type FleetItem = (
75
79
  | { key: string; kind: "foreground-active"; runId: string; index?: number; agent: string; state: "running"; updatedAt: number; control: ForegroundRunControl; activeChild?: ForegroundChildControl }
76
80
  | { key: string; kind: "foreground-recent"; runId: string; index: number; agent: string; state: ForegroundResumeChild["status"]; updatedAt: number; run: ForegroundResumeRun; child: ForegroundResumeChild }
77
81
  | { key: string; kind: "async"; runId: string; index?: number; agent: string; state: string; updatedAt: number; run: AsyncRunSummary; step?: AsyncStep }
82
+ | { key: string; kind: "external"; runId: string; agent: string; state: ExternalRun["state"]; updatedAt: number; run: ExternalRun }
78
83
  ) & { description?: string };
79
84
 
80
85
  export interface FleetSnapshot {
@@ -91,6 +96,7 @@ export interface FleetActionHandlers {
91
96
  steer(input: { runId: string; asyncDir: string; index?: number; message: string; mode: SteerDeliveryMode }): Promise<FleetActionResult>;
92
97
  stop(input: { runId: string; asyncDir: string; index?: number }): Promise<FleetActionResult> | FleetActionResult;
93
98
  inspect?(input: { runId: string; asyncDir: string; index?: number }): Promise<FleetActionResult>;
99
+ redoPrompt?(input: { runId: string; index: number; guidance: string; control?: ForegroundRunControl }): Promise<FleetActionResult>;
94
100
  }
95
101
 
96
102
  export interface FleetViewOptions {
@@ -101,6 +107,7 @@ export interface FleetViewOptions {
101
107
  markdownTheme?: MarkdownTheme;
102
108
  fleetKeybindings?: FleetKeybindingsConfig;
103
109
  actions?: FleetActionHandlers;
110
+ copyText?: (text: string) => Promise<void> | void;
104
111
  }
105
112
 
106
113
  function belongsToCurrentSession(sessionId: string | undefined, currentSessionId: string | null): boolean {
@@ -182,8 +189,13 @@ export function collectFleetSnapshot(
182
189
  ): FleetSnapshot {
183
190
  const items: FleetItem[] = [];
184
191
  const activeForegroundIds = new Set<string>();
192
+ const trackedJobs = state.fleetJobs ?? state.asyncJobs;
193
+ const workflowParentIds = new Set([...trackedJobs.values()]
194
+ .filter((job) => job.mode === "workflow" && belongsToCurrentSession(job.sessionId, state.currentSessionId))
195
+ .map((job) => job.asyncId));
185
196
  for (const control of [...state.foregroundControls.values()].sort((left, right) => right.updatedAt - left.updatedAt)) {
186
197
  activeForegroundIds.add(control.runId);
198
+ if (control.parentWorkflowRunId && workflowParentIds.has(control.parentWorkflowRunId)) continue;
187
199
  if (control.activeChildren) {
188
200
  for (const child of [...control.activeChildren.values()].sort((left, right) => left.index - right.index)) {
189
201
  items.push({
@@ -218,7 +230,7 @@ export function collectFleetSnapshot(
218
230
  try {
219
231
  let runs: AsyncRunSummary[];
220
232
  const descriptions = new Map<string, string>();
221
- const tracked = [...(state.fleetJobs ?? state.asyncJobs).values()]
233
+ const tracked = [...trackedJobs.values()]
222
234
  .filter((job) => belongsToCurrentSession(job.sessionId, state.currentSessionId));
223
235
  const byUpdate = (left: AsyncJobState, right: AsyncJobState) => (right.updatedAt ?? right.startedAt ?? 0) - (left.updatedAt ?? left.startedAt ?? 0);
224
236
  const active = tracked.filter((job) => job.status === "queued" || job.status === "running").sort(byUpdate);
@@ -251,6 +263,26 @@ export function collectFleetSnapshot(
251
263
  error = cause instanceof Error ? cause.message : String(cause);
252
264
  }
253
265
 
266
+ if (state.currentSessionId) {
267
+ try {
268
+ for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => console.warn(`[pi-subagents] Removed ${message}`) })) {
269
+ items.push({
270
+ key: `external:${run.id}`,
271
+ kind: "external",
272
+ runId: run.id,
273
+ agent: run.label,
274
+ state: run.state,
275
+ updatedAt: run.updatedAt ?? run.endedAt ?? run.startedAt,
276
+ run,
277
+ ...(run.currentAction ? { description: run.currentAction } : {}),
278
+ });
279
+ }
280
+ } catch (cause) {
281
+ const message = `Failed to inspect external jobs: ${cause instanceof Error ? cause.message : String(cause)}`;
282
+ error = error ? `${error}; ${message}` : message;
283
+ }
284
+ }
285
+
254
286
  const recentForeground = [...(state.foregroundRuns?.values() ?? [])]
255
287
  .filter((run) => belongsToCurrentSession(run.sessionId, state.currentSessionId) && !activeForegroundIds.has(run.runId))
256
288
  .sort((left, right) => right.updatedAt - left.updatedAt);
@@ -272,6 +304,27 @@ export function collectFleetSnapshot(
272
304
  return { items, ...(error ? { error } : {}) };
273
305
  }
274
306
 
307
+ function visibleWorkflowParentKeyForForegroundKey(state: SubagentState, key: string, items: FleetItem[]): string | undefined {
308
+ for (const control of state.foregroundControls.values()) {
309
+ if (!control.parentWorkflowRunId) continue;
310
+ let matches = false;
311
+ if (control.activeChildren) {
312
+ for (const child of control.activeChildren.values()) {
313
+ if (`foreground-active:${control.runId}:${child.index}` === key) {
314
+ matches = true;
315
+ break;
316
+ }
317
+ }
318
+ } else {
319
+ matches = `foreground-active:${control.runId}:${control.currentIndex ?? 0}` === key;
320
+ }
321
+ if (!matches) continue;
322
+ const parentKey = `async:${control.parentWorkflowRunId}`;
323
+ return items.some((item) => item.key === parentKey) ? parentKey : undefined;
324
+ }
325
+ return undefined;
326
+ }
327
+
275
328
  function statusGlyph(item: FleetItem, theme: Theme): string {
276
329
  if (item.state === "running") return theme.fg("accent", "●");
277
330
  if (item.state === "queued" || item.state === "pending") return theme.fg("muted", "◦");
@@ -280,23 +333,62 @@ function statusGlyph(item: FleetItem, theme: Theme): string {
280
333
  return theme.fg("error", "✗");
281
334
  }
282
335
 
283
- function foregroundActiveDetail(item: Extract<FleetItem, { kind: "foreground-active" }>): string[] {
336
+ function foregroundPromptAuditCount(item: Extract<FleetItem, { kind: "foreground-active" }>, state: SubagentState): number {
337
+ if (!state.currentSessionId || item.control.sessionId !== state.currentSessionId) return 0;
338
+ if (!item.control.activeChildren) return getLivePromptAudit(item.control, item.index ?? 0) ? 1 : 0;
339
+ return [...item.control.activeChildren.keys()].filter((index) => getLivePromptAudit(item.control, index)).length;
340
+ }
341
+
342
+ function authoredPromptSummary(text: string): string | undefined {
343
+ const summary = text.replace(/\s+/g, " ").trim();
344
+ return summary ? truncateToWidth(summary, PROMPT_AUDIT_SUMMARY_WIDTH, "…") : undefined;
345
+ }
346
+
347
+ function foregroundAuthoredPromptSummary(item: Extract<FleetItem, { kind: "foreground-active" }>, state: SubagentState): string | undefined {
348
+ if (!state.currentSessionId || item.control.sessionId !== state.currentSessionId) return undefined;
349
+ const prompt = getLivePromptAudit(item.control, item.index ?? 0);
350
+ return prompt ? authoredPromptSummary(prompt.authoredTask) : undefined;
351
+ }
352
+
353
+ function promptAuditText(prompt: LivePromptAudit, view: PromptAuditView): string {
354
+ switch (view) {
355
+ case "authored": return prompt.authoredTask;
356
+ case "runtime": return prompt.runtimeAdditions;
357
+ case "effective": return prompt.finalEffectivePrompt;
358
+ }
359
+ }
360
+
361
+ function promptAuditViewLabel(view: PromptAuditView): string {
362
+ switch (view) {
363
+ case "authored": return "[1] Authored task";
364
+ case "runtime": return "[2] Runtime additions";
365
+ case "effective": return "[3] Final effective prompt";
366
+ }
367
+ }
368
+
369
+ function foregroundActiveDetail(item: Extract<FleetItem, { kind: "foreground-active" }>, state: SubagentState): string[] {
284
370
  const { control } = item;
285
371
  const live = item.activeChild ?? control;
286
372
  const modelThinking = formatModelThinking(live.model, live.thinking);
373
+ const promptAuditCount = foregroundPromptAuditCount(item, state);
374
+ const promptSummary = foregroundAuthoredPromptSummary(item, state);
287
375
  const lines = [
288
376
  `Run: ${item.runId}`,
289
377
  "Source: foreground",
290
378
  `State: running`,
291
379
  `Mode: ${control.mode}`,
292
380
  control.parentWorkflowRunId ? `Workflow child of: ${control.parentWorkflowRunId}${control.workflowKey ? ` (${control.workflowKey})` : ""}` : undefined,
381
+ control.sourceRunId ? `Redo source: ${control.sourceRunId}` : undefined,
382
+ control.supersededByRunId ? `Superseded by: ${control.supersededByRunId}` : undefined,
293
383
  item.index !== undefined ? `Child: ${item.index} (${item.agent})` : `Agent: ${item.agent}`,
294
384
  modelThinking ? `Model: ${modelThinking}` : undefined,
385
+ promptSummary ? `Task: ${promptSummary}` : undefined,
295
386
  `Started: ${new Date(live.startedAt).toISOString()}`,
296
387
  live.currentTool ? `Current tool: ${live.currentTool}${live.currentPath ? ` · ${shortenPath(live.currentPath)}` : ""}` : undefined,
297
388
  live.turnCount !== undefined ? `Turns: ${live.turnCount}` : undefined,
298
389
  live.toolCount !== undefined ? `Tools: ${live.toolCount}` : undefined,
299
390
  live.tokens !== undefined ? `Tokens: ${formatTokens(live.tokens)}` : undefined,
391
+ promptAuditCount > 0 ? `Prompt audit: ${promptAuditCount} live · 3 views · p opens` : undefined,
300
392
  "",
301
393
  "Transcript",
302
394
  "Live foreground output remains in the expanded subagent tool result. Persisted output and session paths appear here after the child settles.",
@@ -381,6 +473,11 @@ function foregroundRecentDetail(item: Extract<FleetItem, { kind: "foreground-rec
381
473
  return lines.filter((line): line is string => line !== undefined);
382
474
  }
383
475
 
476
+ function externalElapsedEnd(run: ExternalRun): number {
477
+ const terminal = run.state !== "queued" && run.state !== "running";
478
+ return terminal ? (run.endedAt ?? run.updatedAt ?? Date.now()) : Date.now();
479
+ }
480
+
384
481
  function asyncDetail(item: Extract<FleetItem, { kind: "async" }>): string[] {
385
482
  const status = readStatus(item.run.asyncDir);
386
483
  if (status) {
@@ -401,13 +498,36 @@ function asyncDetail(item: Extract<FleetItem, { kind: "async" }>): string[] {
401
498
  ].filter((line): line is string => line !== undefined);
402
499
  }
403
500
 
501
+ function externalDetail(item: Extract<FleetItem, { kind: "external" }>): string[] {
502
+ return [
503
+ `Run: ${item.runId}`,
504
+ "Source: external · display-only",
505
+ `Owner: ${item.run.source}`,
506
+ `State: ${item.state}`,
507
+ `Started: ${new Date(item.run.startedAt).toISOString()}`,
508
+ item.run.updatedAt !== undefined ? `Updated: ${new Date(item.run.updatedAt).toISOString()}` : undefined,
509
+ item.run.endedAt !== undefined ? `Ended: ${new Date(item.run.endedAt).toISOString()}` : undefined,
510
+ `Elapsed: ${formatDuration(Math.max(0, externalElapsedEnd(item.run) - item.run.startedAt))}`,
511
+ item.run.currentAction ? `Current action: ${item.run.currentAction}` : undefined,
512
+ item.run.reportPath ? `Report path: ${item.run.reportPath}` : undefined,
513
+ item.run.transcriptPath ? `Transcript path: ${item.run.transcriptPath}` : undefined,
514
+ "",
515
+ "Preview",
516
+ item.run.preview ?? "(no preview supplied)",
517
+ "",
518
+ "The owning extension controls execution, persistence, cancellation, and results.",
519
+ ].filter((line): line is string => line !== undefined);
520
+ }
521
+
404
522
  function detailLines(item: FleetItem | undefined, error: string | undefined, state: SubagentState): string[] {
405
- if (!item) return [error ? `Fleet scan failed: ${error}` : "No current-session foreground or recent async children.", "", "New runs appear here automatically while this inspector remains open."];
523
+ if (!item) return [error ? `Fleet scan failed: ${error}` : "No current-session Fleet jobs.", "", "New jobs appear here automatically while this inspector remains open."];
406
524
  const lines = item.kind === "foreground-active"
407
- ? foregroundActiveDetail(item)
525
+ ? foregroundActiveDetail(item, state)
408
526
  : item.kind === "foreground-recent"
409
527
  ? foregroundRecentDetail(item, state)
410
- : asyncDetail(item);
528
+ : item.kind === "external"
529
+ ? externalDetail(item)
530
+ : asyncDetail(item);
411
531
  if (error) lines.unshift(`Fleet scan warning: ${error}`, "");
412
532
  return lines;
413
533
  }
@@ -430,11 +550,12 @@ function fleetArtifactsRoot(state: SubagentState, cwd: string): string {
430
550
  return getArtifactsDir(
431
551
  state.parentSessionFile ?? null,
432
552
  cwd,
433
- state.artifactDirPreference ?? "project",
553
+ state.artifactDirPreference,
434
554
  );
435
555
  }
436
556
 
437
557
  function transcriptTarget(item: FleetItem, state: SubagentState): { path: string; trustedRoots: string[] } | undefined {
558
+ if (item.kind === "external") return undefined;
438
559
  if (item.kind === "foreground-active") {
439
560
  const artifactsRoot = fleetArtifactsRoot(state, item.control.cwd ?? state.baseCwd);
440
561
  return {
@@ -467,6 +588,7 @@ function transcriptTarget(item: FleetItem, state: SubagentState): { path: string
467
588
  item.run.asyncDir,
468
589
  fleetArtifactsRoot(state, state.baseCwd),
469
590
  trackedJob?.cwd ? fleetArtifactsRoot(state, trackedJob.cwd) : undefined,
591
+ item.run.sessionFile ? getArtifactsDir(item.run.sessionFile, item.run.cwd ?? state.baseCwd, state.artifactDirPreference) : undefined,
470
592
  ]),
471
593
  };
472
594
  }
@@ -478,10 +600,12 @@ function itemContext(item: FleetItem): string | undefined {
478
600
  }
479
601
 
480
602
  function itemMode(item: FleetItem): string {
603
+ if (item.kind === "external") return "display-only";
481
604
  return item.kind === "foreground-active" ? item.control.mode : item.run.mode;
482
605
  }
483
606
 
484
607
  function itemSource(item: FleetItem): string {
608
+ if (item.kind === "external") return `external · ${item.run.source}`;
485
609
  if (item.kind === "async") return "background";
486
610
  return item.kind === "foreground-active" ? "foreground · live" : "foreground · recent";
487
611
  }
@@ -501,6 +625,8 @@ function itemStats(item: FleetItem): string[] {
501
625
  model = formatModelThinking(item.child.model, item.child.thinking) || undefined;
502
626
  tokens = item.child.tokens;
503
627
  tools = item.child.toolCount;
628
+ } else if (item.kind === "external") {
629
+ durationMs = Math.max(0, externalElapsedEnd(item.run) - item.run.startedAt);
504
630
  } else {
505
631
  model = formatModelThinking(item.step?.model, item.step?.thinking) || undefined;
506
632
  tokens = item.step?.tokens?.total ?? (item.index === undefined ? item.run.totalTokens?.total : undefined);
@@ -517,19 +643,16 @@ function itemStats(item: FleetItem): string[] {
517
643
  ].filter((value): value is string => Boolean(value));
518
644
  }
519
645
 
520
- function structuredHeader(item: FleetItem, width: number, theme: Theme, conversationState: string): string[] {
646
+ function structuredHeader(item: FleetItem, width: number, theme: Theme, conversationState: string, promptSummary?: string): string[] {
521
647
  const lines: string[] = [];
522
648
  lines.push(rightAligned(` ${statusGlyph(item, theme)} ${theme.bold(item.agent)}`, theme.fg("dim", item.state), width));
523
- const child = item.index !== undefined ? ` · child ${item.index + 1}` : "";
649
+ const child = "index" in item && item.index !== undefined ? ` · child ${item.index + 1}` : "";
524
650
  const context = itemContext(item);
525
651
  const identity = `${itemSource(item)} · ${item.runId.slice(0, 8)}${child} · ${itemMode(item)}${context ? ` ${context}` : ""}`;
526
652
  lines.push(` ${theme.fg("dim", identity)}`);
527
653
  const stats = itemStats(item);
528
654
  if (stats.length) lines.push(` ${theme.fg("muted", stats.join(" · "))}`);
529
- if (item.description) {
530
- const task = item.description.replace(/\s+/g, " ").trim();
531
- lines.push(` ${theme.fg("dim", "Task")} ${task}`);
532
- }
655
+ if (promptSummary) lines.push(` ${theme.fg("muted", `Task: ${promptSummary}`)}`);
533
656
  lines.push(`${theme.fg("accent", "Conversation")} ${theme.fg("dim", `· ${conversationState}`)}`);
534
657
  return lines.map((line) => truncateToWidth(line, width));
535
658
  }
@@ -578,14 +701,18 @@ export class SubagentFleetComponent implements Component {
578
701
  private detailViewportHeight = 8;
579
702
  private bodyHeight = 8;
580
703
  private expandedTools = false;
704
+ private promptAuditOpen = false;
705
+ private promptAuditView: PromptAuditView = "authored";
581
706
  private actionNotice: FleetActionResult | undefined;
582
707
  private steerDraft: string | undefined;
708
+ private redoGuidanceDraft: string | undefined;
583
709
  private steerMode: SteerDeliveryMode = "steer";
584
710
  private stopConfirming = false;
585
711
  private actionBusy = false;
586
712
  private transcriptCache: FleetTranscriptCache | undefined;
587
713
  private disposed = false;
588
- private readonly timer: ReturnType<typeof setInterval>;
714
+ private refreshTimer: ReturnType<typeof setTimeout> | undefined;
715
+ private readonly refreshMs: number;
589
716
  private readonly tui: FleetTui;
590
717
  private readonly theme: Theme;
591
718
  private readonly markdownTheme: MarkdownTheme;
@@ -608,20 +735,41 @@ export class SubagentFleetComponent implements Component {
608
735
  this.done = done;
609
736
  this.options = options;
610
737
  this.keybindings = resolveFleetKeybindings(options.fleetKeybindings);
738
+ this.refreshMs = Math.max(MIN_REFRESH_MS, options.refreshMs ?? REFRESH_MS);
611
739
  this.selectedKey = options.initialKey;
612
740
  this.refresh();
613
- this.timer = setInterval(() => {
741
+ this.scheduleRefresh();
742
+ }
743
+
744
+ private scheduleRefresh(): void {
745
+ if (this.disposed || this.refreshTimer) return;
746
+ this.refreshTimer = setTimeout(() => {
747
+ this.refreshTimer = undefined;
614
748
  if (this.disposed) return;
615
- this.invalidate();
616
- this.tui.requestRender();
617
- }, options.refreshMs ?? REFRESH_MS);
618
- this.timer.unref?.();
749
+ try {
750
+ this.invalidate();
751
+ this.tui.requestRender();
752
+ } finally {
753
+ this.scheduleRefresh();
754
+ }
755
+ }, this.refreshMs);
756
+ this.refreshTimer.unref?.();
757
+ }
758
+
759
+ private stopRefresh(): void {
760
+ this.disposed = true;
761
+ if (this.refreshTimer) clearTimeout(this.refreshTimer);
762
+ this.refreshTimer = undefined;
619
763
  }
620
764
 
621
765
  private refresh(): void {
622
766
  const previousKey = this.snapshot.items[this.selected]?.key ?? this.selectedKey;
623
767
  this.snapshot = collectFleetSnapshot(this.state, this.options);
624
- const preserved = previousKey ? this.snapshot.items.findIndex((item) => item.key === previousKey) : -1;
768
+ let preserved = previousKey ? this.snapshot.items.findIndex((item) => item.key === previousKey) : -1;
769
+ if (preserved < 0 && previousKey) {
770
+ const parentKey = visibleWorkflowParentKeyForForegroundKey(this.state, previousKey, this.snapshot.items);
771
+ if (parentKey) preserved = this.snapshot.items.findIndex((item) => item.key === parentKey);
772
+ }
625
773
  this.selected = preserved >= 0 ? preserved : Math.min(this.selected, Math.max(0, this.snapshot.items.length - 1));
626
774
  this.selectedKey = this.snapshot.items[this.selected]?.key;
627
775
  }
@@ -635,8 +783,45 @@ export class SubagentFleetComponent implements Component {
635
783
  this.tui.requestRender();
636
784
  }
637
785
 
786
+ private selectedPromptAudit(): LivePromptAudit | undefined {
787
+ const item = this.snapshot.items[this.selected];
788
+ if (item?.kind !== "foreground-active") return undefined;
789
+ if (!this.state.currentSessionId || item.control.sessionId !== this.state.currentSessionId) return undefined;
790
+ return getLivePromptAudit(item.control, item.index ?? 0);
791
+ }
792
+
793
+ private promptAuditItems(): Array<{ item: Extract<FleetItem, { kind: "foreground-active" }>; prompt: LivePromptAudit }> {
794
+ const selected = this.snapshot.items[this.selected];
795
+ if (selected?.kind !== "foreground-active" || !this.state.currentSessionId || selected.control.sessionId !== this.state.currentSessionId) return [];
796
+ return this.snapshot.items.flatMap((item) => {
797
+ if (item.kind !== "foreground-active" || item.control !== selected.control) return [];
798
+ const prompt = getLivePromptAudit(item.control, item.index ?? 0);
799
+ return prompt ? [{ item, prompt }] : [];
800
+ });
801
+ }
802
+
803
+ private selectedPromptText(): string | undefined {
804
+ const prompt = this.selectedPromptAudit();
805
+ return prompt ? promptAuditText(prompt, this.promptAuditView) : undefined;
806
+ }
807
+
808
+ private movePromptSelection(delta: number): void {
809
+ const items = this.promptAuditItems();
810
+ if (items.length === 0) return;
811
+ const currentKey = this.snapshot.items[this.selected]?.key;
812
+ const current = Math.max(0, items.findIndex(({ item }) => item.key === currentKey));
813
+ const target = items[Math.max(0, Math.min(items.length - 1, current + delta))]?.item;
814
+ if (!target) return;
815
+ this.selected = this.snapshot.items.findIndex((item) => item.key === target.key);
816
+ this.selectedKey = target.key;
817
+ this.detailScroll = 0;
818
+ this.detailAutoFollow = false;
819
+ this.tui.requestRender();
820
+ }
821
+
638
822
  private resetActionInput(): void {
639
823
  this.steerDraft = undefined;
824
+ this.redoGuidanceDraft = undefined;
640
825
  this.steerMode = "steer";
641
826
  this.stopConfirming = false;
642
827
  }
@@ -644,6 +829,7 @@ export class SubagentFleetComponent implements Component {
644
829
  private selectedAsyncAction(): { item: Extract<FleetItem, { kind: "async" }> } | { reason: string } {
645
830
  const item = this.snapshot.items[this.selected];
646
831
  if (!item) return { reason: "No child is selected." };
832
+ if (item.kind === "external") return { reason: "External jobs are display-only and remain controlled by their owning extension." };
647
833
  if (item.kind !== "async") return { reason: "Fleet controls are available for current-session top-level async runs only." };
648
834
  if (!isActionableAsyncState(item.run.state) || !isActionableAsyncState(item.state)) return { reason: `Selected child is ${item.state}; controls require a running or queued async child.` };
649
835
  return { item };
@@ -652,6 +838,7 @@ export class SubagentFleetComponent implements Component {
652
838
  private selectedHerdrInspectAction(): { runId: string; asyncDir: string; index?: number } | { reason: string } {
653
839
  const item = this.snapshot.items[this.selected];
654
840
  if (!item) return { reason: "No child is selected." };
841
+ if (item.kind === "external") return { reason: "External jobs are display-only and have no Herdr controls." };
655
842
  if (item.kind === "async") {
656
843
  if (!isActionableAsyncState(item.run.state) || !isActionableAsyncState(item.state)) return { reason: `Selected child is ${item.state}; controls require a running or queued async child.` };
657
844
  return { runId: item.runId, asyncDir: item.run.asyncDir, ...(item.index !== undefined ? { index: item.index } : {}) };
@@ -668,6 +855,9 @@ export class SubagentFleetComponent implements Component {
668
855
  if (this.steerDraft !== undefined) {
669
856
  lines.push(this.theme.fg("accent", `Steer message (${this.steerMode}): ${this.steerDraft}${this.theme.fg("dim", "▌")}`));
670
857
  lines.push(this.theme.fg("dim", "Enter sends · Tab changes mode · Esc cancels · Backspace edits"));
858
+ } else if (this.redoGuidanceDraft !== undefined) {
859
+ lines.push(this.theme.fg("accent", `Redo guidance: ${this.redoGuidanceDraft}${this.theme.fg("dim", "▌")}`));
860
+ lines.push(this.theme.fg("dim", "Enter rewrites and reruns · Esc cancels · Backspace edits"));
671
861
  } else if (this.stopConfirming) {
672
862
  const selected = this.snapshot.items[this.selected];
673
863
  lines.push(this.theme.fg("warning", `Confirm stop for async run ${selected?.runId ?? "selected run"}?`));
@@ -714,6 +904,82 @@ export class SubagentFleetComponent implements Component {
714
904
  }
715
905
 
716
906
  handleInput(data: string): void {
907
+ if (this.promptAuditOpen && this.redoGuidanceDraft !== undefined) {
908
+ if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
909
+ this.resetActionInput();
910
+ this.tui.requestRender();
911
+ return;
912
+ }
913
+ if (matchesKey(data, "return") || data === "\r" || data === "\n") {
914
+ const guidance = this.redoGuidanceDraft.trim();
915
+ if (!guidance) {
916
+ this.setActionNotice({ text: "Redo guidance cannot be empty.", isError: true });
917
+ return;
918
+ }
919
+ const selected = this.snapshot.items[this.selected];
920
+ if (selected?.kind !== "foreground-active" || !this.options.actions?.redoPrompt) {
921
+ this.setActionNotice({ text: "Redo is unavailable for this prompt.", isError: true });
922
+ return;
923
+ }
924
+ this.runAction(() => this.options.actions!.redoPrompt!({ runId: selected.runId, index: selected.index ?? 0, guidance, control: selected.control }));
925
+ return;
926
+ }
927
+ if (matchesKey(data, "backspace") || data === "\x7f") {
928
+ this.redoGuidanceDraft = this.redoGuidanceDraft.slice(0, -1);
929
+ this.tui.requestRender();
930
+ return;
931
+ }
932
+ if (data.length === 1 && data >= " " && data !== "\x7f") {
933
+ this.redoGuidanceDraft += data;
934
+ this.tui.requestRender();
935
+ }
936
+ return;
937
+ }
938
+ if (this.promptAuditOpen) {
939
+ if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
940
+ this.promptAuditOpen = false;
941
+ this.detailAutoFollow = true;
942
+ this.tui.requestRender();
943
+ return;
944
+ }
945
+ if (data === "j") return this.movePromptSelection(1);
946
+ if (data === "k") return this.movePromptSelection(-1);
947
+ if (data === "1" || data === "2" || data === "3") {
948
+ this.promptAuditView = data === "1" ? "authored" : data === "2" ? "runtime" : "effective";
949
+ this.detailScroll = 0;
950
+ this.tui.requestRender();
951
+ return;
952
+ }
953
+ if (data === "g") {
954
+ const prompt = this.selectedPromptAudit();
955
+ if (!prompt) this.setActionNotice({ text: "Prompt Audit is available only for a live child owned by this session.", isError: true });
956
+ else if (!prompt.rerun) this.setActionNotice({ text: "Redo is not safe for this prompt in this slice.", isError: true });
957
+ else if (!this.options.actions?.redoPrompt) this.setActionNotice({ text: "Redo controls are unavailable in this context.", isError: true });
958
+ else {
959
+ this.actionNotice = undefined;
960
+ this.redoGuidanceDraft = "";
961
+ this.detailAutoFollow = false;
962
+ this.detailScroll = 0;
963
+ this.tui.requestRender();
964
+ }
965
+ return;
966
+ }
967
+ if (data === "c") {
968
+ const text = this.selectedPromptText();
969
+ if (!text) this.setActionNotice({ text: "No prompt view is available to copy.", isError: true });
970
+ else if (!this.options.copyText) this.setActionNotice({ text: "Clipboard is unavailable in this context.", isError: true });
971
+ else this.runAction(async () => {
972
+ await this.options.copyText!(text);
973
+ return { text: "Copied visible prompt view." };
974
+ });
975
+ return;
976
+ }
977
+ if (matchesFleetAction(data, this.keybindings, "scrollUp")) return this.scrollDetail(-1);
978
+ if (matchesFleetAction(data, this.keybindings, "scrollDown")) return this.scrollDetail(1);
979
+ if (matchesFleetAction(data, this.keybindings, "pageUp")) return this.scrollDetail(-this.detailViewportHeight);
980
+ if (matchesFleetAction(data, this.keybindings, "pageDown")) return this.scrollDetail(this.detailViewportHeight);
981
+ return;
982
+ }
717
983
  if (this.steerDraft !== undefined) {
718
984
  if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
719
985
  this.resetActionInput();
@@ -768,6 +1034,7 @@ export class SubagentFleetComponent implements Component {
768
1034
  return;
769
1035
  }
770
1036
  if (matchesFleetAction(data, this.keybindings, "close")) {
1037
+ this.stopRefresh();
771
1038
  this.done(undefined);
772
1039
  return;
773
1040
  }
@@ -785,6 +1052,18 @@ export class SubagentFleetComponent implements Component {
785
1052
  this.tui.requestRender();
786
1053
  return;
787
1054
  }
1055
+ if (data === "p") {
1056
+ if (!this.selectedPromptAudit()) this.setActionNotice({ text: "Prompt Audit is available only for a live child owned by this session.", isError: true });
1057
+ else {
1058
+ this.promptAuditOpen = true;
1059
+ this.promptAuditView = "authored";
1060
+ this.detailScroll = 0;
1061
+ this.detailAutoFollow = false;
1062
+ this.actionNotice = undefined;
1063
+ this.tui.requestRender();
1064
+ }
1065
+ return;
1066
+ }
788
1067
  if (matchesFleetAction(data, this.keybindings, "steer")) {
789
1068
  const target = this.selectedAsyncAction();
790
1069
  if ("reason" in target || !this.options.actions) this.setActionNotice({ text: "reason" in target ? target.reason : "Fleet controls are unavailable in this context.", isError: true });
@@ -830,7 +1109,7 @@ export class SubagentFleetComponent implements Component {
830
1109
  const marker = index === this.selected ? this.theme.fg("accent", "›") : " ";
831
1110
  const context = item.kind === "async" ? contextModeBadge(this.theme, item.step?.context ?? item.run.context) : item.kind === "foreground-recent" ? contextModeBadge(this.theme, item.child.context) : "";
832
1111
  const agent = index === this.selected ? this.theme.bold(item.agent) : item.agent;
833
- const identity = item.description?.replace(/\s+/g, " ").trim() || item.runId.slice(0, 8);
1112
+ const identity = item.runId.slice(0, 8);
834
1113
  const left = `${marker} ${statusGlyph(item, this.theme)} ${agent}${context} ${this.theme.fg("dim", `· ${identity}`)}`;
835
1114
  return rightAligned(left, this.theme.fg("dim", item.state), width);
836
1115
  });
@@ -853,7 +1132,35 @@ export class SubagentFleetComponent implements Component {
853
1132
  return { transcript, body: [...body] };
854
1133
  }
855
1134
 
1135
+ private promptAuditDetail(width: number): FleetDetailSections {
1136
+ const selected = this.snapshot.items[this.selected];
1137
+ const prompt = this.selectedPromptAudit();
1138
+ const items = this.promptAuditItems();
1139
+ const selectedPosition = selected ? items.findIndex(({ item }) => item.key === selected.key) : -1;
1140
+ const live = selected?.kind === "foreground-active" ? selected.activeChild ?? selected.control : undefined;
1141
+ const viewLabel = promptAuditViewLabel(this.promptAuditView);
1142
+ const promptText = this.selectedPromptText()
1143
+ ?? this.theme.fg("muted", "Selected prompt unavailable.");
1144
+ const raw = [
1145
+ this.theme.bold("Prompt Audit"),
1146
+ this.theme.fg("dim", "Retention: live memory only · no storage"),
1147
+ selected?.kind === "foreground-active" ? `Run: ${selected.runId}${selected.index !== undefined ? ` · Child: ${selected.index}` : ""} · Agent: ${selected.agent}` : "Selected prompt unavailable",
1148
+ live ? `Started: ${new Date(live.startedAt).toISOString()}` : undefined,
1149
+ live ? `Model: ${formatModelThinking(live.model, live.thinking) || "default"}` : undefined,
1150
+ prompt?.cwd ? `Cwd: ${prompt.cwd}` : undefined,
1151
+ prompt?.outputPath ? `Output: ${prompt.outputPath}` : undefined,
1152
+ this.theme.fg("dim", `Live children: ${items.map(({ item }) => item.agent).join(", ") || "none"}`),
1153
+ this.theme.fg("dim", selectedPosition >= 0 ? `Selected: ${selectedPosition + 1}/${items.length}` : "Selected prompt unavailable"),
1154
+ "",
1155
+ this.theme.fg("accent", viewLabel),
1156
+ promptText,
1157
+ ];
1158
+ const body = raw.filter((line): line is string => line !== undefined).flatMap((line) => wrapTextWithAnsi(line, Math.max(1, width)));
1159
+ return { header: [], body: this.withActionLines(body) };
1160
+ }
1161
+
856
1162
  private wrappedDetail(width: number): FleetDetailSections {
1163
+ if (this.promptAuditOpen) return this.promptAuditDetail(width);
857
1164
  const selected = this.snapshot.items[this.selected];
858
1165
  let transcriptWarning: string | undefined;
859
1166
  if (selected) {
@@ -871,7 +1178,8 @@ export class SubagentFleetComponent implements Component {
871
1178
  : latest?.kind === "tool"
872
1179
  ? `${latest.name} · ${latest.status}`
873
1180
  : "activity";
874
- return { header: structuredHeader(selected, width, this.theme, conversationState), body: this.withActionLines(body) };
1181
+ const promptSummary = selected.kind === "foreground-active" ? foregroundAuthoredPromptSummary(selected, this.state) : undefined;
1182
+ return { header: structuredHeader(selected, width, this.theme, conversationState, promptSummary), body: this.withActionLines(body) };
875
1183
  }
876
1184
  }
877
1185
  }
@@ -880,7 +1188,7 @@ export class SubagentFleetComponent implements Component {
880
1188
  if (transcriptWarning) raw.unshift(`Transcript preview warning: ${transcriptWarning}`, "");
881
1189
  const lines: string[] = [];
882
1190
  for (const line of raw) {
883
- const styled = /^(Run|State|Mode|Source|Child|Agent|Model):/.test(line)
1191
+ const styled = /^(Run|State|Mode|Source|Child|Agent|Model|Task):/.test(line)
884
1192
  ? this.theme.bold(line)
885
1193
  : /^(Transcript|Result transcript tail)/.test(line)
886
1194
  ? this.theme.fg("accent", line)
@@ -916,7 +1224,9 @@ export class SubagentFleetComponent implements Component {
916
1224
  ];
917
1225
  const lines = [this.theme.fg("border", `╭${"─".repeat(innerWidth)}╮`)];
918
1226
  const selected = this.snapshot.items[this.selected];
919
- const title = ` ${this.theme.bold("Subagent fleet inspector")} ${this.theme.fg("dim", "· live controls")}`;
1227
+ const title = selected?.kind === "external"
1228
+ ? ` ${this.theme.bold("Fleet inspector")} ${this.theme.fg("dim", "· external display-only")}`
1229
+ : ` ${this.theme.bold("Subagent fleet inspector")} ${this.theme.fg("dim", "· live controls")}`;
920
1230
  const selectedStatus = selected
921
1231
  ? `${statusGlyph(selected, this.theme)} ${selected.agent} · ${selected.state} `
922
1232
  : this.theme.fg("dim", "no children ");
@@ -933,7 +1243,11 @@ export class SubagentFleetComponent implements Component {
933
1243
  }
934
1244
  lines.push(this.theme.fg("border", `├${"─".repeat(rosterWidth)}┴${"─".repeat(detailWidth)}┤`));
935
1245
  const position = this.snapshot.items.length ? `${this.selected + 1}/${this.snapshot.items.length}` : "0/0";
936
- const footer = ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} agent · ${bindingLabel(this.keybindings, "inspect")} Herdr · ${bindingLabel(this.keybindings, "steer")} steer · ${bindingLabel(this.keybindings, "stop")} stop · ${bindingLabel(this.keybindings, "toggleTools")} tools · ${bindingLabel(this.keybindings, "refresh")} refresh · ${bindingLabel(this.keybindings, "close")} close · ${position}`;
1246
+ const footer = this.promptAuditOpen
1247
+ ? ` j/k child · 1/2/3 view · g redo with guidance · c copy · Esc close Prompt Audit · ${position}`
1248
+ : selected?.kind === "external"
1249
+ ? ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} job · display-only · ${bindingLabel(this.keybindings, "refresh")} refresh · ${bindingLabel(this.keybindings, "close")} close · ${position}`
1250
+ : ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} agent · p Prompt Audit · ${bindingLabel(this.keybindings, "inspect")} Herdr · ${bindingLabel(this.keybindings, "steer")} steer · ${bindingLabel(this.keybindings, "stop")} stop · ${bindingLabel(this.keybindings, "toggleTools")} tools · ${bindingLabel(this.keybindings, "refresh")} refresh · ${bindingLabel(this.keybindings, "close")} close · ${position}`;
937
1251
  lines.push(this.theme.fg("border", "│") + fit(this.theme.fg("dim", footer), innerWidth) + this.theme.fg("border", "│"));
938
1252
  lines.push(this.theme.fg("border", `╰${"─".repeat(innerWidth)}╯`));
939
1253
  return lines.map((line) => truncateToWidth(line, width));
@@ -945,8 +1259,7 @@ export class SubagentFleetComponent implements Component {
945
1259
  }
946
1260
 
947
1261
  dispose(): void {
948
- this.disposed = true;
949
- clearInterval(this.timer);
1262
+ this.stopRefresh();
950
1263
  }
951
1264
  }
952
1265
 
@@ -954,6 +1267,12 @@ export async function openSubagentFleet(ctx: ExtensionContext, state: SubagentSt
954
1267
  const wasOpen = state.fleetInspectorOpen === true;
955
1268
  state.fleetInspectorOpen = true;
956
1269
  if (typeof ctx.ui.setWidget === "function") ctx.ui.setWidget(FLEET_STATUS_WIDGET_KEY, undefined);
1270
+ const copyText = options.copyText ?? (async (text: string) => {
1271
+ const module = await import("@earendil-works/pi-coding-agent");
1272
+ const copyToClipboard = (module as { copyToClipboard?: (value: string) => Promise<void> | void }).copyToClipboard;
1273
+ if (!copyToClipboard) throw new Error("Clipboard is unavailable in this Pi version.");
1274
+ await copyToClipboard(text);
1275
+ });
957
1276
  const actions = options.actions ?? {
958
1277
  steer: async (input: { runId: string; asyncDir: string; index?: number; message: string; mode: SteerDeliveryMode }) => firstToolResultText(await steerAsyncRun({
959
1278
  state,
@@ -970,14 +1289,20 @@ export async function openSubagentFleet(ctx: ExtensionContext, state: SubagentSt
970
1289
  ...(input.index !== undefined ? { index: input.index } : {}),
971
1290
  }, {
972
1291
  state,
1292
+ sessionRoots: state.trustedSessionRoots,
973
1293
  cwd: state.baseCwd,
974
1294
  ...(state.authorityPolicy ? { authorityPolicy: state.authorityPolicy } : {}),
975
1295
  ...(state.missionStoreConfig ? { missions: state.missionStoreConfig } : {}),
976
1296
  }), `Failed to open Herdr inspector for async run ${input.runId}.`),
1297
+ redoPrompt: async (input: { runId: string; index: number; guidance: string; control?: ForegroundRunControl }) => {
1298
+ const control = input.control ?? state.foregroundControls.get(input.runId);
1299
+ if (!control?.promptAuditRedo) return { text: "Redo is not available for this live child.", isError: true };
1300
+ return control.promptAuditRedo(input.index, input.guidance);
1301
+ },
977
1302
  } satisfies FleetActionHandlers;
978
1303
  try {
979
1304
  await ctx.ui.custom<undefined>(
980
- (tui, theme, _keybindings, done) => new SubagentFleetComponent(tui, theme, state, done, { ...options, actions }),
1305
+ (tui, theme, _keybindings, done) => new SubagentFleetComponent(tui, theme, state, done, { ...options, actions, copyText }),
981
1306
  {
982
1307
  overlay: true,
983
1308
  overlayOptions: { anchor: "center", width: "95%", minWidth: 60, maxHeight: "85%", margin: 1 },