@xzzpig/pi-subagents 0.4.2 → 0.6.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 (128) hide show
  1. package/CHANGELOG.md +172 -1
  2. package/README.md +8 -0
  3. package/agents/oracle.md +3 -1
  4. package/agents/reviewer.md +1 -0
  5. package/agents/scout.md +2 -2
  6. package/agents/worker.md +2 -1
  7. package/async-retention-discovery-worker.mjs +180 -0
  8. package/docs/agents.md +79 -2
  9. package/docs/configuration.md +42 -14
  10. package/docs/extension-api.md +45 -2
  11. package/docs/models.md +2 -0
  12. package/docs/observability.md +41 -5
  13. package/docs/tool-reference.md +38 -39
  14. package/docs/workflows.md +173 -3
  15. package/package.json +13 -10
  16. package/prompts/council.md +48 -0
  17. package/skills/council-mode/SKILL.md +230 -0
  18. package/skills/pi-subagents/SKILL.md +8 -4
  19. package/skills/pi-subagents/references/constraints-and-recipes.md +13 -6
  20. package/skills/pi-subagents/references/execution-controls.md +40 -15
  21. package/skills/pi-subagents/references/management-authoring-rpc.md +3 -3
  22. package/skills/pi-subagents/references/multi-lane-orchestration.md +39 -0
  23. package/skills/pi-subagents/references/prompting-and-roles.md +4 -2
  24. package/src/agents/agent-management.ts +158 -357
  25. package/src/agents/agent-serializer.ts +4 -0
  26. package/src/agents/agents.ts +227 -53
  27. package/src/agents/builtin-names.ts +9 -0
  28. package/src/agents/runtime-agent-registry.ts +422 -0
  29. package/src/agents/skills.ts +1 -1
  30. package/src/api/agents.ts +7 -0
  31. package/src/api/external-job-provider.ts +186 -0
  32. package/src/api/preflight.ts +37 -9
  33. package/src/api/shared-types.ts +2 -0
  34. package/src/extension/config.ts +6 -3
  35. package/src/extension/context-injection.ts +118 -0
  36. package/src/extension/doctor.ts +15 -6
  37. package/src/extension/fanout-child.ts +2 -2
  38. package/src/extension/index.ts +224 -90
  39. package/src/extension/public-execution.ts +31 -2
  40. package/src/extension/rpc.ts +41 -1
  41. package/src/extension/schemas.ts +17 -37
  42. package/src/extension/tool-description.ts +35 -24
  43. package/src/inspectors/herdr/actions.ts +2 -2
  44. package/src/inspectors/herdr/inspector-runner.ts +2 -1
  45. package/src/inspectors/herdr/project-panes.ts +2 -2
  46. package/src/intercom/native-supervisor-channel.ts +32 -10
  47. package/src/missions/lifecycle.ts +6 -1
  48. package/src/missions/store.ts +4 -9
  49. package/src/missions/workflow-state.ts +2 -2
  50. package/src/profiles/profiles.ts +3 -1
  51. package/src/runs/background/active-run-index.ts +31 -8
  52. package/src/runs/background/async-execution.ts +70 -41
  53. package/src/runs/background/async-job-tracker.ts +24 -7
  54. package/src/runs/background/async-resume.ts +49 -16
  55. package/src/runs/background/async-retention.ts +886 -0
  56. package/src/runs/background/async-status-snapshot.ts +14 -5
  57. package/src/runs/background/async-status.ts +39 -53
  58. package/src/runs/background/auto-drain.ts +1 -0
  59. package/src/runs/background/chain-append.ts +3 -33
  60. package/src/runs/background/completion-dedupe.ts +5 -1
  61. package/src/runs/background/completion-replay.ts +22 -12
  62. package/src/runs/background/control-channel.ts +14 -68
  63. package/src/runs/background/fleet-view.ts +68 -19
  64. package/src/runs/background/index-segment.ts +59 -0
  65. package/src/runs/background/inspect-rpc.ts +443 -0
  66. package/src/runs/background/notify.ts +31 -5
  67. package/src/runs/background/result-files.ts +158 -90
  68. package/src/runs/background/result-watcher.ts +124 -20
  69. package/src/runs/background/resume-guidance.ts +8 -5
  70. package/src/runs/background/retained-children.ts +13 -3
  71. package/src/runs/background/run-id-query.ts +7 -0
  72. package/src/runs/background/run-id-resolver.ts +11 -9
  73. package/src/runs/background/run-status.ts +27 -18
  74. package/src/runs/background/scheduled-runs.ts +24 -4
  75. package/src/runs/background/stale-run-reconciler.ts +6 -3
  76. package/src/runs/background/steering.ts +11 -1
  77. package/src/runs/background/subagent-runner.ts +260 -144
  78. package/src/runs/background/subagent-wait.ts +17 -13
  79. package/src/runs/background/terminal-run-index.ts +138 -0
  80. package/src/runs/background/wait-completions.ts +21 -4
  81. package/src/runs/background/wait-subscriptions.ts +81 -2
  82. package/src/runs/background/wait-tool.ts +1 -0
  83. package/src/runs/foreground/async-steering-action.ts +21 -14
  84. package/src/runs/foreground/execution.ts +8 -2
  85. package/src/runs/foreground/subagent-executor.ts +816 -1593
  86. package/src/runs/foreground/workflow-detach-reconcile.ts +262 -0
  87. package/src/runs/foreground/workflow-foreground-steering.ts +6 -5
  88. package/src/runs/shared/acceptance.ts +48 -5
  89. package/src/runs/shared/chain-outputs.ts +1 -3
  90. package/src/runs/shared/external-job-bridge.ts +444 -0
  91. package/src/runs/shared/external-job-runner.ts +286 -0
  92. package/src/runs/shared/mcp-direct-tool-allowlist.ts +14 -0
  93. package/src/runs/shared/model-exclusions.ts +242 -0
  94. package/src/runs/shared/model-fallback.ts +153 -40
  95. package/src/runs/shared/orca-progress-tabs.ts +84 -22
  96. package/src/runs/shared/parallel-handoff.ts +46 -4
  97. package/src/runs/shared/parallel-utils.ts +4 -15
  98. package/src/runs/shared/permissions.ts +5 -1
  99. package/src/runs/shared/pi-args.ts +8 -1
  100. package/src/runs/shared/session-lease.ts +0 -6
  101. package/src/runs/shared/subagent-control.ts +51 -7
  102. package/src/runs/shared/subagent-prompt-runtime.ts +12 -6
  103. package/src/runs/shared/workflow-graph.ts +1 -23
  104. package/src/runs/shared/worktree.ts +14 -2
  105. package/src/shared/atomic-json.ts +22 -2
  106. package/src/shared/capacity-resilient-json.ts +102 -0
  107. package/src/shared/completion-owner.ts +14 -0
  108. package/src/shared/file-system-retry.ts +49 -1
  109. package/src/shared/fork-context.ts +59 -1
  110. package/src/shared/model-info.ts +20 -0
  111. package/src/shared/prompt-resources.ts +0 -40
  112. package/src/shared/settings.ts +5 -29
  113. package/src/shared/types.ts +110 -26
  114. package/src/shared/utils.ts +8 -0
  115. package/src/shared/watch-strategy.ts +10 -0
  116. package/src/slash/slash-bridge.ts +2 -1
  117. package/src/slash/slash-commands.ts +47 -7
  118. package/src/slash/slash-live-state.ts +3 -3
  119. package/src/tui/fleet-status.ts +86 -1
  120. package/src/tui/fleet.ts +117 -16
  121. package/src/tui/render.ts +73 -3
  122. package/src/watchdog/change-signature.ts +1 -1
  123. package/src/watchdog/lsp-diagnostics.ts +1 -0
  124. package/src/workflows/chat-progress.ts +2 -2
  125. package/src/workflows/scripted-workflow.ts +320 -79
  126. package/src/workflows/workflow-receipt.ts +140 -0
  127. package/src/runs/foreground/chain-clarify.ts +0 -1354
  128. package/src/runs/foreground/chain-execution.ts +0 -1581
@@ -27,6 +27,17 @@ type FleetStatusEntry = {
27
27
  state: string;
28
28
  external?: true;
29
29
  nestedChildren?: NestedRunSummary[];
30
+ workflowRows?: FleetWorkflowRow[];
31
+ };
32
+
33
+ type FleetWorkflowRow = {
34
+ name: string;
35
+ state: AsyncJobStep["status"];
36
+ modelThinking?: string;
37
+ activity?: string;
38
+ startedAt?: number;
39
+ tokens?: number;
40
+ overflow?: number;
30
41
  };
31
42
 
32
43
  type FleetNestedRow = {
@@ -42,6 +53,7 @@ type FleetNestedRow = {
42
53
  type FleetTreeRow =
43
54
  | { kind: "owner"; entry: FleetStatusEntry }
44
55
  | { kind: "child"; entry: FleetStatusEntry; last: boolean }
56
+ | { kind: "workflow"; ownerKey: string; row: FleetWorkflowRow; last: boolean }
45
57
  | { kind: "nested"; ownerKey: string; row: FleetNestedRow; last: boolean };
46
58
 
47
59
  export interface FleetStatusOptions {
@@ -92,6 +104,51 @@ function nestedActivity(node: NestedRunSummary | NestedStepSummary): string | un
92
104
  return undefined;
93
105
  }
94
106
 
107
+ function workflowStepActivity(step: AsyncJobStep): string | undefined {
108
+ if (step.currentTool) return `tool ${step.currentTool}`;
109
+ if (step.currentPath) return step.currentPath.split(/[\\/]/).at(-1);
110
+ if (step.activityState === "needs_attention") return "needs attention";
111
+ if (step.activityState === "active_long_running") return "long-running";
112
+ if (step.turnCount !== undefined) return `${step.turnCount} turns`;
113
+ if (step.toolCount !== undefined) return `${step.toolCount} tools`;
114
+ return undefined;
115
+ }
116
+
117
+ function workflowStepName(step: AsyncJobStep, index: number): string {
118
+ const key = step.workflowKey ?? `step ${index + 1}`;
119
+ const label = step.label && step.label !== key ? ` · ${step.label}` : "";
120
+ const phase = step.phase ? `${step.phase}: ` : "";
121
+ return `${phase}${key}${label} (${step.agent})`;
122
+ }
123
+
124
+ function workflowFleetRows(steps: AsyncJobStep[] | undefined): FleetWorkflowRow[] {
125
+ return (steps ?? []).map((step, index) => {
126
+ const modelThinking = formatModelThinking(step.model, step.thinking) || undefined;
127
+ const activity = workflowStepActivity(step);
128
+ return {
129
+ name: workflowStepName(step, index),
130
+ state: step.status,
131
+ ...(modelThinking ? { modelThinking } : {}),
132
+ ...(activity ? { activity } : {}),
133
+ ...(step.startedAt !== undefined ? { startedAt: step.startedAt } : {}),
134
+ ...(step.tokens?.total !== undefined ? { tokens: step.tokens.total } : {}),
135
+ };
136
+ });
137
+ }
138
+
139
+ function visibleWorkflowRows(rows: FleetWorkflowRow[] | undefined, visibleLimit: number): FleetWorkflowRow[] {
140
+ if (!rows?.length) return [];
141
+ if (rows.length <= visibleLimit) return rows;
142
+ const selected = new Set<number>();
143
+ for (const [index, row] of rows.entries()) {
144
+ if (row.state !== "complete" && row.state !== "completed") selected.add(index);
145
+ if (selected.size >= visibleLimit) break;
146
+ }
147
+ for (let index = rows.length - 1; index >= 0 && selected.size < visibleLimit; index--) selected.add(index);
148
+ const visible = [...selected].sort((left, right) => left - right).map((index) => rows[index]!);
149
+ return [{ name: `… +${rows.length - visible.length} hidden workflow steps`, state: "complete", overflow: rows.length - visible.length }, ...visible];
150
+ }
151
+
95
152
  function nestedStatusGlyph(state: FleetNestedRow["state"], theme: Theme): string {
96
153
  if (state === "running") return theme.fg("accent", "●");
97
154
  if (state === "queued" || state === "pending") return theme.fg("muted", "◦");
@@ -194,9 +251,10 @@ function fleetTreeRows(entries: FleetStatusEntry[]): FleetTreeRow[] {
194
251
  if (entry.parentKey && entryKeys.has(entry.parentKey)) continue;
195
252
  rows.push({ kind: "owner", entry });
196
253
  const attached = childrenByParent.get(entry.key) ?? [];
254
+ const workflowRows = visibleWorkflowRows(entry.workflowRows, attached.length > 0 ? 2 : 4);
197
255
  for (const [index, child] of attached.entries()) {
198
256
  const nested = nestedFleetRows(child.nestedChildren, 3);
199
- const laterRows = index < attached.length - 1 || Boolean(entry.nestedChildren?.length);
257
+ const laterRows = index < attached.length - 1 || workflowRows.length > 0 || Boolean(entry.nestedChildren?.length);
200
258
  rows.push({ kind: "child", entry: child, last: !laterRows && nested.length === 0 });
201
259
  for (const [nestedIndex, row] of nested.entries()) rows.push({
202
260
  kind: "nested",
@@ -205,6 +263,7 @@ function fleetTreeRows(entries: FleetStatusEntry[]): FleetTreeRow[] {
205
263
  last: nestedIndex === nested.length - 1 && !laterRows,
206
264
  });
207
265
  }
266
+ for (const [index, row] of workflowRows.entries()) rows.push({ kind: "workflow", ownerKey: entry.key, row, last: index === workflowRows.length - 1 && !entry.nestedChildren?.length });
208
267
  const nested = nestedFleetRows(entry.nestedChildren, attached.length > 0 ? 3 : 4);
209
268
  for (const [index, row] of nested.entries()) rows.push({ kind: "nested", ownerKey: entry.key, row, last: index === nested.length - 1 });
210
269
  }
@@ -282,6 +341,7 @@ export function collectFleetStatusEntries(state: SubagentState): FleetStatusEntr
282
341
  startedAt,
283
342
  tokens: job.totalTokens?.total ?? 0,
284
343
  state: job.status,
344
+ ...(job.steps?.length ? { workflowRows: workflowFleetRows(job.steps) } : {}),
285
345
  ...(job.nestedChildren?.length ? { nestedChildren: job.nestedChildren } : {}),
286
346
  });
287
347
  continue;
@@ -548,6 +608,8 @@ export class SubagentFleetStatus {
548
608
  if (row.kind === "owner" || row.kind === "child") {
549
609
  const ownerIndex = this.entries.findIndex((entry) => entry.key === row.entry.key);
550
610
  lines.push(this.renderEntry(ownerIndex + 1, selectedIndex, row.entry, width, theme, row.kind === "child" ? (row.last ? "└─" : "├─") : undefined));
611
+ } else if (row.kind === "workflow") {
612
+ lines.push(this.renderWorkflowRow(row.row, row.last, width, theme));
551
613
  } else {
552
614
  lines.push(this.renderNestedRow(row.row, row.last, width, theme));
553
615
  }
@@ -576,6 +638,20 @@ export class SubagentFleetStatus {
576
638
  return truncateToWidth(`${left}${theme.fg("dim", elapsed)}`, width);
577
639
  }
578
640
 
641
+ private renderWorkflowRow(row: FleetWorkflowRow, last: boolean, width: number, theme: Theme): string {
642
+ const marker = last ? "└─" : "├─";
643
+ const indent = " ";
644
+ if (row.overflow !== undefined) return truncateToWidth(`${indent}${marker} ${theme.fg("dim", `+${row.overflow} hidden workflow steps`)}`, width);
645
+ const modelThinking = row.modelThinking ? ` (${row.modelThinking})` : "";
646
+ const activity = row.activity ? ` · ${row.activity}` : "";
647
+ const left = `${indent}${marker} ${nestedStatusGlyph(row.state, theme)} ${theme.fg("muted", `${row.name}${modelThinking}`)} · ${row.state}${activity}`;
648
+ const details = [
649
+ row.startedAt !== undefined ? formatFleetElapsed(Date.now() - row.startedAt) : undefined,
650
+ row.tokens !== undefined ? formatFleetTokens(row.tokens) : undefined,
651
+ ].filter(Boolean).join(" · ");
652
+ return truncateToWidth(`${left}${details ? theme.fg("dim", ` · ${details}`) : ""}`, width);
653
+ }
654
+
579
655
  private bullet(rosterIndex: number, selectedIndex: number, theme: Theme): string {
580
656
  return rosterIndex === selectedIndex ? theme.fg("accent", ">") : " ";
581
657
  }
@@ -624,6 +700,15 @@ export class SubagentFleetStatus {
624
700
  entry.external,
625
701
  Math.round((now - entry.startedAt) / 1000),
626
702
  entry.tokens,
703
+ visibleWorkflowRows(entry.workflowRows, entry.parentKey ? 2 : 4).map((row) => [
704
+ row.name,
705
+ row.state,
706
+ row.modelThinking,
707
+ row.activity,
708
+ row.startedAt,
709
+ row.tokens,
710
+ row.overflow,
711
+ ]),
627
712
  nestedFleetRows(entry.nestedChildren, entry.parentKey ? 3 : 4).map((row) => [
628
713
  row.name,
629
714
  row.state,
package/src/tui/fleet.ts CHANGED
@@ -6,7 +6,7 @@ import { matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Compo
6
6
  import { snapshotExternalRuns, type ExternalRun } from "../api/external-runs.ts";
7
7
  import { getArtifactPaths, getArtifactsDir } from "../shared/artifacts.ts";
8
8
  import { formatDuration, formatModelThinking, formatTokens, shortenPath } from "../shared/formatters.ts";
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";
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";
12
12
  import { formatAsyncRunTranscript } from "../runs/background/fleet-view.ts";
@@ -15,10 +15,12 @@ import { listAsyncRuns, type AsyncRunSummary } from "../runs/background/async-st
15
15
  import { steerAsyncRun } from "../runs/foreground/async-steering-action.ts";
16
16
  import type { SteerDeliveryMode } from "../runs/background/control-channel.ts";
17
17
  import { stopAsyncRun } from "../runs/foreground/async-stop-action.ts";
18
+ import { resolveWorkflowForegroundSteeringTarget, steerWorkflowForegroundTarget } from "../runs/foreground/workflow-foreground-steering.ts";
18
19
  import { contextModeBadge, contextModeLabel } from "../runs/shared/context-mode.ts";
19
20
  import { FLEET_STATUS_WIDGET_KEY } from "./fleet-status.ts";
20
21
  import { readFleetTranscript, renderFleetTranscript, type FleetTranscript } from "./fleet-transcript.ts";
21
22
  import { handleHerdrInspectorAction } from "../inspectors/herdr/actions.ts";
23
+ import type { HerdrClient } from "../inspectors/herdr/client.ts";
22
24
  import { getLivePromptAudit, type LivePromptAudit, type PromptAuditView } from "../runs/foreground/prompt-audit.ts";
23
25
 
24
26
  const REFRESH_MS = 750;
@@ -110,6 +112,7 @@ export interface FleetViewOptions {
110
112
  fleetKeybindings?: FleetKeybindingsConfig;
111
113
  actions?: FleetActionHandlers;
112
114
  copyText?: (text: string) => Promise<void> | void;
115
+ herdrClient?: HerdrClient;
113
116
  }
114
117
 
115
118
  function belongsToCurrentSession(sessionId: string | undefined, currentSessionId: string | null): boolean {
@@ -195,9 +198,22 @@ export function collectFleetSnapshot(
195
198
  const workflowParentIds = new Set([...trackedJobs.values()]
196
199
  .filter((job) => job.mode === "workflow" && belongsToCurrentSession(job.sessionId, state.currentSessionId))
197
200
  .map((job) => job.asyncId));
201
+ const workflowForegroundChildCounts = new Map<string, number>();
202
+ const liveWorkflowForegroundControls = new Set<ForegroundRunControl>();
203
+ for (const control of state.foregroundControls.values()) {
204
+ const activeChildCount = control.activeChildren?.size ?? 0;
205
+ if (!control.parentWorkflowRunId
206
+ || !workflowParentIds.has(control.parentWorkflowRunId)
207
+ || !belongsToCurrentSession(control.sessionId, state.currentSessionId)
208
+ || !control.workflowSteeringDir
209
+ || activeChildCount === 0) continue;
210
+ liveWorkflowForegroundControls.add(control);
211
+ workflowForegroundChildCounts.set(control.parentWorkflowRunId, (workflowForegroundChildCounts.get(control.parentWorkflowRunId) ?? 0) + activeChildCount);
212
+ }
198
213
  for (const control of [...state.foregroundControls.values()].sort((left, right) => right.updatedAt - left.updatedAt)) {
199
214
  activeForegroundIds.add(control.runId);
200
- if (control.parentWorkflowRunId && workflowParentIds.has(control.parentWorkflowRunId)) continue;
215
+ if (control.parentWorkflowRunId && workflowParentIds.has(control.parentWorkflowRunId)
216
+ && ((workflowForegroundChildCounts.get(control.parentWorkflowRunId) ?? 0) <= 1 || !liveWorkflowForegroundControls.has(control))) continue;
201
217
  if (control.activeChildren) {
202
218
  for (const child of [...control.activeChildren.values()].sort((left, right) => left.index - right.index)) {
203
219
  items.push({
@@ -480,10 +496,68 @@ function externalElapsedEnd(run: ExternalRun): number {
480
496
  return terminal ? (run.endedAt ?? run.updatedAt ?? Date.now()) : Date.now();
481
497
  }
482
498
 
483
- function asyncDetail(item: Extract<FleetItem, { kind: "async" }>): string[] {
499
+ function workflowStepLabel(step: AsyncJobStep, index: number): string {
500
+ const key = step.workflowKey ?? `step ${index + 1}`;
501
+ const label = step.label && step.label !== key ? ` · ${step.label}` : "";
502
+ const phase = step.phase ? `${step.phase}: ` : "";
503
+ return `${phase}${key}${label} (${step.agent})`;
504
+ }
505
+
506
+ function workflowStepActivity(step: AsyncJobStep): string | undefined {
507
+ if (step.currentTool) return `tool ${step.currentTool}`;
508
+ if (step.currentPath) return shortenPath(step.currentPath);
509
+ if (step.activityState === "needs_attention") return "needs attention";
510
+ if (step.activityState === "active_long_running") return "long-running";
511
+ if (step.turnCount !== undefined) return `${step.turnCount} turns`;
512
+ if (step.toolCount !== undefined) return `${step.toolCount} tools`;
513
+ return undefined;
514
+ }
515
+
516
+ function visibleWorkflowProgressSteps(steps: AsyncJobStep[], visibleLimit: number): Array<{ step: AsyncJobStep; index: number } | { hidden: number }> {
517
+ if (steps.length <= visibleLimit) return steps.map((step, index) => ({ step, index }));
518
+ const selected = new Set<number>();
519
+ for (const [index, step] of steps.entries()) {
520
+ if (step.status !== "complete" && step.status !== "completed") selected.add(index);
521
+ if (selected.size >= visibleLimit) break;
522
+ }
523
+ for (let index = steps.length - 1; index >= 0 && selected.size < visibleLimit; index--) selected.add(index);
524
+ const visible = [...selected].sort((left, right) => left - right).map((index) => ({ step: steps[index]!, index }));
525
+ return [{ hidden: steps.length - visible.length }, ...visible];
526
+ }
527
+
528
+ function workflowProgressLines(steps: AsyncJobStep[] | undefined): string[] {
529
+ if (!steps?.length) return [];
530
+ const lines = ["Workflow progress:"];
531
+ for (const row of visibleWorkflowProgressSteps(steps, 8)) {
532
+ if ("hidden" in row) {
533
+ lines.push(` +${row.hidden} hidden workflow steps`);
534
+ continue;
535
+ }
536
+ const activity = workflowStepActivity(row.step);
537
+ const context = contextModeLabel(row.step.context);
538
+ const details = [row.step.status, activity, context, row.step.tokens?.total !== undefined ? formatTokens(row.step.tokens.total) : undefined].filter(Boolean).join(" · ");
539
+ lines.push(` ${row.index + 1}. ${workflowStepLabel(row.step, row.index)}${details ? ` — ${details}` : ""}`);
540
+ }
541
+ return lines;
542
+ }
543
+
544
+ function asyncDetail(item: Extract<FleetItem, { kind: "async" }>, state: SubagentState): string[] {
484
545
  const status = readStatus(item.run.asyncDir);
485
546
  if (status) {
486
- return formatAsyncRunTranscript(status, item.run.asyncDir, { index: item.index, lines: TRANSCRIPT_LINES }).split("\n");
547
+ const trackedJob = state.fleetJobs?.get(item.runId) ?? state.asyncJobs.get(item.runId);
548
+ const lines = formatAsyncRunTranscript(status, item.run.asyncDir, {
549
+ index: item.index,
550
+ lines: TRANSCRIPT_LINES,
551
+ sessionRoots: uniquePaths([...(state.trustedSessionRoots ?? []), trackedJob?.sessionRoot]),
552
+ }).split("\n");
553
+ if (status.mode === "workflow" && item.index === undefined) {
554
+ const progress = workflowProgressLines((status.steps ?? item.run.steps) as AsyncJobStep[]);
555
+ if (progress.length) {
556
+ const modeIndex = lines.findIndex((line) => line.startsWith("Mode:"));
557
+ lines.splice(modeIndex >= 0 ? modeIndex + 1 : 0, 0, "", ...progress);
558
+ }
559
+ }
560
+ return lines;
487
561
  }
488
562
  const outputPath = item.index !== undefined ? path.join(item.run.asyncDir, `output-${item.index}.log`) : undefined;
489
563
  return [
@@ -529,7 +603,7 @@ function detailLines(item: FleetItem | undefined, error: string | undefined, sta
529
603
  ? foregroundRecentDetail(item, state)
530
604
  : item.kind === "external"
531
605
  ? externalDetail(item)
532
- : asyncDetail(item);
606
+ : asyncDetail(item, state);
533
607
  if (error) lines.unshift(`Fleet scan warning: ${error}`, "");
534
608
  return lines;
535
609
  }
@@ -838,6 +912,18 @@ export class SubagentFleetComponent implements Component {
838
912
  return { item };
839
913
  }
840
914
 
915
+ private selectedSteerAction(): { runId: string; asyncDir: string; index?: number } | { reason: string } {
916
+ const item = this.snapshot.items[this.selected];
917
+ if (item?.kind === "foreground-active" && item.control.parentWorkflowRunId) {
918
+ const parent = this.state.asyncJobs.get(item.control.parentWorkflowRunId) ?? this.state.fleetJobs?.get(item.control.parentWorkflowRunId);
919
+ if (!parent || !isActionableAsyncState(parent.status)) return { reason: "The parent workflow is no longer available for steering." };
920
+ return { runId: item.runId, asyncDir: parent.asyncDir, ...(item.index !== undefined ? { index: item.index } : {}) };
921
+ }
922
+ const target = this.selectedAsyncAction();
923
+ if ("reason" in target) return target;
924
+ return { runId: target.item.runId, asyncDir: target.item.run.asyncDir, ...(target.item.index !== undefined ? { index: target.item.index } : {}) };
925
+ }
926
+
841
927
  private selectedHerdrInspectAction(): { runId: string; asyncDir: string; index?: number } | { reason: string } {
842
928
  const item = this.snapshot.items[this.selected];
843
929
  if (!item) return { reason: "No child is selected." };
@@ -1010,12 +1096,12 @@ export class SubagentFleetComponent implements Component {
1010
1096
  this.setActionNotice({ text: "Steer message cannot be empty.", isError: true });
1011
1097
  return;
1012
1098
  }
1013
- const target = this.selectedAsyncAction();
1099
+ const target = this.selectedSteerAction();
1014
1100
  if ("reason" in target || !this.options.actions) {
1015
1101
  this.setActionNotice({ text: "reason" in target ? target.reason : "Fleet controls are unavailable in this context.", isError: true });
1016
1102
  return;
1017
1103
  }
1018
- this.runAction(() => this.options.actions!.steer({ runId: target.item.runId, asyncDir: target.item.run.asyncDir, ...(target.item.index !== undefined ? { index: target.item.index } : {}), message, mode: this.steerMode }));
1104
+ this.runAction(() => this.options.actions!.steer({ ...target, message, mode: this.steerMode }));
1019
1105
  return;
1020
1106
  }
1021
1107
  if (matchesKey(data, "tab") || data === "\t") {
@@ -1083,7 +1169,7 @@ export class SubagentFleetComponent implements Component {
1083
1169
  return;
1084
1170
  }
1085
1171
  if (matchesFleetAction(data, this.keybindings, "steer")) {
1086
- const target = this.selectedAsyncAction();
1172
+ const target = this.selectedSteerAction();
1087
1173
  if ("reason" in target || !this.options.actions) this.setActionNotice({ text: "reason" in target ? target.reason : "Fleet controls are unavailable in this context.", isError: true });
1088
1174
  else {
1089
1175
  this.actionNotice = undefined;
@@ -1293,23 +1379,38 @@ export async function openSubagentFleet(ctx: ExtensionContext, state: SubagentSt
1293
1379
  await copyToClipboard(text);
1294
1380
  });
1295
1381
  const actions = options.actions ?? {
1296
- steer: async (input: { runId: string; asyncDir: string; index?: number; message: string; mode: SteerDeliveryMode }) => firstToolResultText(await steerAsyncRun({
1297
- state,
1298
- runId: input.runId,
1299
- ...(input.index !== undefined ? { index: input.index } : {}),
1300
- message: input.message,
1301
- mode: input.mode,
1302
- location: { asyncDir: input.asyncDir, resolvedId: input.runId } as Parameters<typeof steerAsyncRun>[0]["location"],
1303
- }), `Failed to steer async run ${input.runId}.`),
1382
+ steer: async (input: { runId: string; asyncDir: string; index?: number; message: string; mode: SteerDeliveryMode }) => {
1383
+ const status = readStatus(input.asyncDir);
1384
+ const liveWorkflowRunId = status?.mode === "workflow" && state.workflowControllers?.has(status.runId || input.runId)
1385
+ ? status.runId || input.runId
1386
+ : undefined;
1387
+ if (liveWorkflowRunId) {
1388
+ const route = state.foregroundControls.get(input.runId)?.parentWorkflowRunId === liveWorkflowRunId
1389
+ ? resolveWorkflowForegroundSteeringTarget({ state, childRunId: input.runId, asyncDirRoot: options.asyncDirRoot ?? DIRS.async })
1390
+ : resolveWorkflowForegroundSteeringTarget({ state, workflowRunId: liveWorkflowRunId, asyncDirRoot: options.asyncDirRoot ?? DIRS.async });
1391
+ if (!route.ok) return { text: route.message, isError: true };
1392
+ return firstToolResultText(await steerWorkflowForegroundTarget({ target: route.target, message: input.message, mode: input.mode, ...(input.index !== undefined ? { index: input.index } : {}) }), `Failed to steer foreground run ${input.runId}.`);
1393
+ }
1394
+ return firstToolResultText(await steerAsyncRun({
1395
+ state,
1396
+ runId: input.runId,
1397
+ ...(input.index !== undefined ? { index: input.index } : {}),
1398
+ message: input.message,
1399
+ mode: input.mode,
1400
+ location: { asyncDir: input.asyncDir, resolvedId: input.runId } as Parameters<typeof steerAsyncRun>[0]["location"],
1401
+ }), `Failed to steer async run ${input.runId}.`);
1402
+ },
1304
1403
  stop: (input: { runId: string; asyncDir: string; index?: number }) => firstToolResultText(stopAsyncRun(state, input.runId, undefined, { asyncDir: input.asyncDir, resolvedId: input.runId }), `Failed to stop async run ${input.runId}.`),
1305
1404
  inspect: async (input: { runId: string; asyncDir: string; index?: number }) => firstToolResultText(await handleHerdrInspectorAction("inspector.open", {
1306
1405
  id: input.runId,
1307
1406
  dir: input.asyncDir,
1407
+ focus: true,
1308
1408
  ...(input.index !== undefined ? { index: input.index } : {}),
1309
1409
  }, {
1310
1410
  state,
1311
1411
  sessionRoots: state.trustedSessionRoots,
1312
1412
  cwd: state.baseCwd,
1413
+ ...(options.herdrClient ? { client: options.herdrClient } : {}),
1313
1414
  ...(state.authorityPolicy ? { authorityPolicy: state.authorityPolicy } : {}),
1314
1415
  ...(state.missionStoreConfig ? { missions: state.missionStoreConfig } : {}),
1315
1416
  }), `Failed to open Herdr inspector for async run ${input.runId}.`),
package/src/tui/render.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import * as path from "node:path";
6
+ import { createHash } from "node:crypto";
6
7
  import type { AgentToolResult } from "@earendil-works/pi-agent-core";
7
8
  import { getMarkdownTheme, keyText, type ExtensionContext } from "@earendil-works/pi-coding-agent";
8
9
  import { Container, Markdown, Spacer, Text, visibleWidth, type Component } from "@earendil-works/pi-tui";
@@ -535,7 +536,76 @@ function compactCurrentActivity(progress: AgentProgress): string {
535
536
  return formatCurrentToolLine(progress, getTermWidth() - 4, false, snapshotNow) ?? buildLiveStatusLine(progress, snapshotNow) ?? "thinking…";
536
537
  }
537
538
 
538
- export function widgetRenderKey(job: AsyncJobState): string {
539
+ function textDigest(text: string): string {
540
+ return createHash("sha256").update(text).digest("hex").slice(0, 16);
541
+ }
542
+
543
+ function displayTextRenderKey(text: string): unknown[] {
544
+ const normalized = sanitizeDisplayText(text);
545
+ return [normalized.length, textDigest(normalized)];
546
+ }
547
+
548
+ function expandedStepActivityRenderKey(step: AsyncJobStep): unknown[] {
549
+ return [
550
+ step.recentTools?.slice(-3).map((tool) => [tool.tool, displayTextRenderKey(tool.args), tool.endMs]),
551
+ compactRecentOutputLines(step.recentOutput).map(displayTextRenderKey),
552
+ ];
553
+ }
554
+
555
+ function widgetStepRenderKey(step: AsyncJobStep, index: number, expanded = false): unknown[] {
556
+ return [
557
+ step.index ?? index,
558
+ step.agent,
559
+ step.workflowKey,
560
+ step.phase,
561
+ step.label,
562
+ step.status,
563
+ step.activityState,
564
+ step.lastActivityAt,
565
+ step.currentTool,
566
+ step.currentToolArgs,
567
+ step.currentToolStartedAt,
568
+ step.currentPath,
569
+ step.turnCount,
570
+ step.toolCount,
571
+ step.startedAt,
572
+ step.endedAt,
573
+ step.durationMs,
574
+ step.tokens?.total,
575
+ step.model,
576
+ step.thinking,
577
+ step.context,
578
+ step.error,
579
+ expanded ? expandedStepActivityRenderKey(step) : undefined,
580
+ nestedRenderKey(step.children, expanded),
581
+ ];
582
+ }
583
+
584
+ function nestedRenderKey(children: NestedRunSummary[] | undefined, expanded = false): unknown[] {
585
+ return (children ?? []).map((child) => [
586
+ child.id,
587
+ child.state,
588
+ child.agent,
589
+ child.model,
590
+ child.thinking,
591
+ child.activityState,
592
+ child.lastActivityAt,
593
+ child.currentTool,
594
+ child.currentToolStartedAt,
595
+ child.currentPath,
596
+ child.turnCount,
597
+ child.toolCount,
598
+ child.startedAt,
599
+ child.endedAt,
600
+ child.lastUpdate,
601
+ child.error,
602
+ child.totalTokens?.total,
603
+ child.steps?.map((step, index) => widgetStepRenderKey({ ...step, agent: step.agent, status: step.status }, index, expanded)),
604
+ nestedRenderKey(child.children, expanded),
605
+ ]);
606
+ }
607
+
608
+ export function widgetRenderKey(job: AsyncJobState, expanded = false): string {
539
609
  return JSON.stringify({
540
610
  asyncDir: job.asyncDir,
541
611
  status: job.status,
@@ -551,8 +621,8 @@ export function widgetRenderKey(job: AsyncJobState): string {
551
621
  currentStep: job.currentStep,
552
622
  chainStepCount: job.chainStepCount,
553
623
  parallelGroups: job.parallelGroups,
554
- steps: job.steps,
555
- nestedChildren: job.nestedChildren,
624
+ steps: job.steps?.map((step, index) => widgetStepRenderKey(step, index, expanded)),
625
+ nestedChildren: nestedRenderKey(job.nestedChildren, expanded),
556
626
  stepsTotal: job.stepsTotal,
557
627
  runningSteps: job.runningSteps,
558
628
  completedSteps: job.completedSteps,
@@ -38,7 +38,7 @@ export interface WatchdogRepoChangeSignature {
38
38
  }
39
39
 
40
40
  function git(cwd: string, args: string[]): string | undefined {
41
- const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf-8", maxBuffer: 10 * 1024 * 1024 });
41
+ const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf-8", maxBuffer: 10 * 1024 * 1024, windowsHide: true });
42
42
  if (result.status !== 0) return undefined;
43
43
  return result.stdout;
44
44
  }
@@ -444,6 +444,7 @@ async function collectWithTypeScriptLanguageServer(input: {
444
444
  }): Promise<WatchdogLspResult> {
445
445
  const started = Date.now();
446
446
  const child = spawn(input.command.command, input.command.args, {
447
+ windowsHide: true,
447
448
  cwd: input.root,
448
449
  stdio: "pipe",
449
450
  env: { ...process.env, NO_COLOR: "1" },
@@ -26,7 +26,7 @@ interface ResolveWorkflowChatProgressInput {
26
26
  }
27
27
 
28
28
  function git(cwd: string, args: string[]): string | undefined {
29
- const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf-8" });
29
+ const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf-8", windowsHide: true });
30
30
  if (result.status !== 0) return undefined;
31
31
  const output = result.stdout.trim();
32
32
  return output || undefined;
@@ -90,7 +90,7 @@ export function resolveWorkflowChatProgress(input: ResolveWorkflowChatProgressIn
90
90
  else mode = requestedMode;
91
91
 
92
92
  if (mode === "live-card" && !sameRepo) return { error: "chatProgress: 'live-card' is only available for workflowScript runs in the same Git repository." };
93
- if (mode === "live-card" && input.background) return { error: "chatProgress: 'live-card' requires a watched foreground workflow; pass async:false." };
93
+ if (mode === "live-card" && input.background) return { error: "chatProgress: 'live-card' is unavailable for async workflowScript. Async workflows have no inline live card; omit chatProgress or use auto/off. Use async:false only when the parent must block." };
94
94
  return { projection: { mode, repoRelation, ...(repoLabel ? { repoLabel } : {}) } };
95
95
  }
96
96