pi-subagents 0.65.1 → 0.67.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 (148) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/README.md +5 -4
  3. package/agents/evidence-auditor.md +34 -0
  4. package/agents/researcher.md +23 -13
  5. package/agents/reviewer.md +3 -2
  6. package/docs/agents.md +20 -3
  7. package/docs/configuration.md +25 -5
  8. package/docs/extension-api.md +124 -18
  9. package/docs/missions.md +8 -0
  10. package/docs/models.md +59 -2
  11. package/docs/observability.md +46 -6
  12. package/docs/standalone-background.md +49 -0
  13. package/docs/tool-reference.md +20 -10
  14. package/docs/watchdog.md +35 -4
  15. package/docs/workflows.md +40 -19
  16. package/inspector-runner.mjs +2 -2
  17. package/package.json +2 -1
  18. package/prompts/parallel-review.md +1 -1
  19. package/{runner-server-preload.mjs → runner-peer-preload.mjs} +8 -3
  20. package/skills/pi-subagents/SKILL.md +14 -0
  21. package/skills/pi-subagents/references/execution-controls.md +20 -5
  22. package/skills/pi-subagents/references/management-authoring-rpc.md +2 -1
  23. package/skills/pi-subagents/references/prompting-and-roles.md +2 -2
  24. package/src/agents/advertised-agent-prompt.ts +94 -0
  25. package/src/agents/agent-management.ts +14 -1
  26. package/src/agents/agent-serializer.ts +2 -0
  27. package/src/agents/agents.ts +14 -0
  28. package/src/agents/builtin-names.ts +1 -0
  29. package/src/api/delegation.ts +4 -0
  30. package/src/api/preflight.ts +76 -45
  31. package/src/api/shared-types.ts +3 -1
  32. package/src/api/workflow-resources.ts +6 -0
  33. package/src/extension/fanout-child.ts +63 -4
  34. package/src/extension/index.ts +58 -8
  35. package/src/extension/public-execution.ts +4 -3
  36. package/src/extension/rpc.ts +8 -21
  37. package/src/extension/schemas.ts +71 -80
  38. package/src/extension/tool-description.ts +29 -81
  39. package/src/inspectors/actions.ts +148 -0
  40. package/src/inspectors/ghostty/actions.ts +74 -0
  41. package/src/inspectors/ghostty/plugin.ts +17 -0
  42. package/src/inspectors/herdr/actions.ts +99 -179
  43. package/src/inspectors/herdr/plugin.ts +20 -0
  44. package/src/inspectors/herdr/project-panes.ts +1 -1
  45. package/src/inspectors/{herdr/inspector-runner.ts → inspector-runner.ts} +12 -12
  46. package/src/inspectors/plugins.ts +8 -0
  47. package/src/inspectors/{herdr/session-roots-codec.ts → session-roots-codec.ts} +3 -14
  48. package/src/inspectors/types.ts +51 -0
  49. package/src/intercom/intercom-bridge.ts +50 -8
  50. package/src/intercom/native-supervisor-channel.ts +104 -67
  51. package/src/runs/background/active-async-capacity.ts +22 -18
  52. package/src/runs/background/async-execution.ts +45 -56
  53. package/src/runs/background/async-job-tracker.ts +35 -3
  54. package/src/runs/background/async-resume.ts +5 -9
  55. package/src/runs/background/async-status-snapshot.ts +10 -12
  56. package/src/runs/background/async-status.ts +17 -9
  57. package/src/runs/background/auto-drain.ts +44 -30
  58. package/src/runs/background/binary-bootstrap.ts +33 -0
  59. package/src/runs/background/chain-root-attachment.ts +8 -0
  60. package/src/runs/background/control-channel.ts +78 -44
  61. package/src/runs/background/fleet-view.ts +30 -2
  62. package/src/runs/background/notify.ts +117 -13
  63. package/src/runs/background/owned-process-tree.ts +35 -8
  64. package/src/runs/background/process-terminal.ts +23 -23
  65. package/src/runs/background/run-child-session.ts +121 -36
  66. package/src/runs/background/run-status.ts +78 -5
  67. package/src/runs/background/runner-aliases.ts +28 -9
  68. package/src/runs/background/runner-child-launch.ts +88 -0
  69. package/src/runs/background/runner-child-sessions.ts +5 -4
  70. package/src/runs/background/scheduled-runs.ts +40 -13
  71. package/src/runs/background/stale-run-reconciler.ts +3 -1
  72. package/src/runs/background/steering.ts +20 -2
  73. package/src/runs/background/subagent-runner.ts +458 -239
  74. package/src/runs/background/subagent-wait.ts +54 -8
  75. package/src/runs/background/wait-completions.ts +4 -0
  76. package/src/runs/background/wait-tool.ts +1 -1
  77. package/src/runs/foreground/async-steering-action.ts +37 -7
  78. package/src/runs/foreground/execution.ts +145 -56
  79. package/src/runs/foreground/prompt-audit.ts +3 -1
  80. package/src/runs/foreground/subagent-executor.ts +584 -297
  81. package/src/runs/foreground/workflow-detach-reconcile.ts +10 -5
  82. package/src/runs/foreground/workflow-foreground-steering.ts +57 -2
  83. package/src/runs/shared/acceptance.ts +7 -4
  84. package/src/runs/shared/agent-contract.ts +1 -1
  85. package/src/runs/shared/async-status-projection.ts +51 -47
  86. package/src/runs/shared/capability-ceiling.ts +2 -0
  87. package/src/runs/shared/child-hooks.ts +167 -3
  88. package/src/runs/shared/child-launch.ts +28 -13
  89. package/src/runs/shared/child-lifecycle.ts +6 -3
  90. package/src/runs/shared/child-runtime-config.ts +3 -1
  91. package/src/runs/shared/child-session.ts +75 -8
  92. package/src/runs/shared/child-tool-plan.ts +124 -5
  93. package/src/runs/shared/completion-evidence.ts +2 -2
  94. package/src/runs/shared/completion-guard.ts +6 -3
  95. package/src/runs/shared/effective-system-prompt.ts +33 -0
  96. package/src/runs/shared/external-cli-runner.ts +9 -7
  97. package/src/runs/shared/host-step-status.ts +11 -11
  98. package/src/runs/shared/llm-intent-arbiter.ts +21 -11
  99. package/src/runs/shared/model-fallback.ts +12 -6
  100. package/src/runs/shared/nested-events.ts +5 -5
  101. package/src/runs/shared/orca-progress-tabs.ts +7 -1
  102. package/src/runs/shared/parallel-handoff.ts +57 -12
  103. package/src/runs/shared/parallel-utils.ts +2 -2
  104. package/src/runs/shared/pi-spawn.ts +10 -0
  105. package/src/runs/shared/readonly-drain-observation.ts +42 -0
  106. package/src/runs/shared/readonly-model-continuation.ts +69 -0
  107. package/src/runs/shared/readonly-session-evidence.ts +307 -0
  108. package/src/runs/shared/run-fanout-budget.ts +8 -8
  109. package/src/runs/shared/runtime-acknowledged-extensions.ts +3 -3
  110. package/src/runs/shared/subagent-prompt-runtime.ts +20 -4
  111. package/src/runs/shared/task-intent.ts +46 -13
  112. package/src/runs/shared/workflow-async-child-guidance.ts +18 -0
  113. package/src/runs/shared/worktree-setup-command.ts +190 -0
  114. package/src/runs/shared/worktree.ts +366 -208
  115. package/src/shared/fork-context.ts +15 -72
  116. package/src/shared/launch-contract.ts +65 -2
  117. package/src/shared/opencode-session-headers.ts +30 -0
  118. package/src/shared/types.ts +85 -61
  119. package/src/shared/utils.ts +7 -2
  120. package/src/shared/workflow-child-permit.ts +18 -13
  121. package/src/slash/delegation-adapters.ts +3 -1
  122. package/src/slash/delegation-request.ts +14 -0
  123. package/src/slash/slash-commands.ts +2 -1
  124. package/src/slash/subagents-admin.ts +11 -4
  125. package/src/tui/fleet-status.ts +164 -19
  126. package/src/tui/fleet.ts +27 -19
  127. package/src/tui/render.ts +172 -33
  128. package/src/watchdog/child-status.ts +8 -0
  129. package/src/watchdog/model-selection.ts +20 -0
  130. package/src/watchdog/permission-arbiter.ts +3 -1
  131. package/src/watchdog/register-child.ts +1 -0
  132. package/src/watchdog/register-main.ts +31 -27
  133. package/src/watchdog/review.ts +132 -67
  134. package/src/watchdog/runtime.ts +82 -20
  135. package/src/watchdog/scope.ts +1 -1
  136. package/src/watchdog/settings.ts +9 -3
  137. package/src/watchdog/tool-actions.ts +13 -12
  138. package/src/watchdog/turn-delta.ts +23 -0
  139. package/src/watchdog/types.ts +4 -0
  140. package/src/workflows/chat-progress.ts +3 -3
  141. package/src/workflows/scripted-workflow.ts +275 -17
  142. package/src/workflows/workflow-checklist.ts +13 -17
  143. package/src/workflows/workflow-child-summary.ts +57 -8
  144. package/src/workflows/workflow-preflight.ts +19 -19
  145. package/src/workflows/workflow-receipt.ts +3 -3
  146. package/src/workflows/workflow-resources.ts +96 -21
  147. package/src/workflows/workflow-settlement.ts +3 -0
  148. /package/src/inspectors/{herdr/shell-command.ts → shell-command.ts} +0 -0
package/src/tui/render.ts CHANGED
@@ -45,6 +45,10 @@ import { formatWorkflowChecklistBottleneck, formatWorkflowChecklistPhase, format
45
45
  type Theme = ExtensionContext["ui"]["theme"];
46
46
 
47
47
  interface WorkflowWidgetProjection {
48
+ now: number;
49
+ inlineFleetCovered?: boolean;
50
+ children?: AsyncJobState[];
51
+ materializedKeys?: Set<string>;
48
52
  stages: WorkflowGraphNode[];
49
53
  steps: AsyncJobStep[];
50
54
  stageProgress?: { total: number; current?: number };
@@ -443,11 +447,14 @@ function workflowStageProgress(job: AsyncJobState, stages = job.mode === "workfl
443
447
  return { total: stages.length };
444
448
  }
445
449
 
446
- function buildWorkflowWidgetProjection(job: AsyncJobState): WorkflowWidgetProjection {
450
+ function buildWorkflowWidgetProjection(job: AsyncJobState, now = Date.now()): WorkflowWidgetProjection {
447
451
  const stages = job.mode === "workflow" ? workflowGraphStageNodes(job.workflowGraph) : [];
448
452
  const stageProgress = workflowStageProgress(job, stages);
449
- const steps = workflowWidgetSteps(job, stages);
450
- const projection: WorkflowWidgetProjection = { stages, steps };
453
+ const clock = job.status === "running" ? now : job.updatedAt;
454
+ const loadedSteps = workflowWidgetSteps(job, stages);
455
+ const steps = job.mode === "workflow" ? loadedSteps.map((step) => step.status === "running" && step.startedAt !== undefined && clock !== undefined
456
+ ? { ...step, durationMs: Math.max(0, clock - step.startedAt) } : step) : loadedSteps;
457
+ const projection: WorkflowWidgetProjection = { stages, steps, now };
451
458
  if (stageProgress) projection.stageProgress = stageProgress;
452
459
  if (stages.length) projection.plannedKeys = new Set(stages.map((node) => node.id));
453
460
  if (job.mode === "workflow") {
@@ -457,19 +464,27 @@ function buildWorkflowWidgetProjection(job: AsyncJobState): WorkflowWidgetProjec
457
464
  hostSteps: job.hostSteps,
458
465
  preflight: job.preflight,
459
466
  trace: job.workflow?.trace,
460
- now: job.updatedAt ?? Date.now(),
467
+ now: clock,
461
468
  });
462
469
  if (checklist.total > 0) projection.checklist = checklist;
463
470
  }
464
471
  return projection;
465
472
  }
466
473
 
467
- function workflowWidgetProjectionLookup(): WorkflowWidgetProjectionLookup {
474
+ function workflowWidgetProjectionLookup(now = Date.now(), childrenByParent = new Map<string, AsyncJobState[]>()): WorkflowWidgetProjectionLookup {
468
475
  const projections = new WeakMap<AsyncJobState, WorkflowWidgetProjection>();
469
476
  return (job: AsyncJobState) => {
470
477
  const cached = projections.get(job);
471
478
  if (cached) return cached;
472
- const projection = buildWorkflowWidgetProjection(job);
479
+ const projection = buildWorkflowWidgetProjection(job, now);
480
+ const children = childrenByParent.get(job.asyncId);
481
+ if (children?.length) {
482
+ projection.children = children;
483
+ projection.materializedKeys = new Set(children.flatMap((child) => [child.asyncId, ...(child.workflowKey ? [child.workflowKey] : [])]));
484
+ for (const step of projection.steps) {
485
+ if (step.runId && projection.materializedKeys.has(step.runId) && step.workflowKey) projection.materializedKeys.add(step.workflowKey);
486
+ }
487
+ }
473
488
  projections.set(job, projection);
474
489
  return projection;
475
490
  };
@@ -1051,9 +1066,11 @@ function hostStepRenderKey(row: AsyncStatusWorkflowRow): unknown[] {
1051
1066
  }
1052
1067
 
1053
1068
  export function widgetRenderKey(job: AsyncJobState, expanded = false): string {
1054
- const projection = buildWorkflowWidgetProjection(job);
1069
+ const projection = buildWorkflowWidgetProjection(job, job.updatedAt ?? 0);
1055
1070
  return JSON.stringify({
1056
1071
  asyncDir: job.asyncDir,
1072
+ parentWorkflowRunId: job.parentWorkflowRunId,
1073
+ workflowKey: job.workflowKey,
1057
1074
  status: job.status,
1058
1075
  description: job.mode === "workflow" ? job.description : undefined,
1059
1076
  activityState: job.activityState,
@@ -1501,9 +1518,10 @@ function compactWorkflowStats(job: AsyncJobState, rows: readonly CompactWorkflow
1501
1518
  const rowToolUses = rows.map((row) => row.toolUses).filter((value): value is number => value !== undefined);
1502
1519
  const toolUses = job.toolCount ?? (rowToolUses.length ? rowToolUses.reduce((sum, value) => sum + value, 0) : undefined);
1503
1520
  const rowDuration = rows.map((row) => row.durationMs).filter((value): value is number => value !== undefined);
1504
- const durationMs = job.startedAt !== undefined && job.updatedAt !== undefined
1505
- ? Math.max(0, job.updatedAt - job.startedAt)
1506
- : rowDuration.length ? Math.max(...rowDuration) : undefined;
1521
+ const end = job.status === "running" ? projection.now : job.updatedAt;
1522
+ const durationMs = job.status !== "queued" && job.startedAt !== undefined && end !== undefined
1523
+ ? Math.max(0, end - job.startedAt)
1524
+ : job.status !== "queued" && rowDuration.length ? Math.max(...rowDuration) : undefined;
1507
1525
  return statJoin(theme, [
1508
1526
  `id: ${compactWorkflowShortId(job)}`,
1509
1527
  ...progress,
@@ -1540,8 +1558,11 @@ function compactWorkflowHeaderLine(job: AsyncJobState, theme: Theme, width?: num
1540
1558
  function compactWorkflowWidgetBodyLines(job: AsyncJobState, theme: Theme, frame: number | undefined, projection: WorkflowWidgetProjection): string[] {
1541
1559
  const rows = compactWorkflowLaneRows(job, projection.checklist);
1542
1560
  const lines = [` ${compactWorkflowStats(job, rows, theme, projection)}`];
1561
+ if (projection.inlineFleetCovered) return [...lines, ` ${theme.fg("dim", "Workflow children shown in Fleet roster")}`];
1543
1562
  if (rows.length) {
1544
- for (const row of rows) lines.push(compactWorkflowLaneLine(row, theme, " ", frame));
1563
+ for (const row of rows) {
1564
+ if (!projection.materializedKeys?.has(row.key)) lines.push(compactWorkflowLaneLine(row, theme, " ", frame));
1565
+ }
1545
1566
  } else {
1546
1567
  lines.push(` ${theme.fg("dim", "◦ waiting for workflow lanes")}`);
1547
1568
  }
@@ -2085,7 +2106,8 @@ function widgetStats(job: AsyncJobState, theme: Theme, projection = buildWorkflo
2085
2106
  if (projection.checklist && !checklistPrimary) parts.push(formatWorkflowChecklistSummary(projection.checklist));
2086
2107
  if (job.toolCount !== undefined) parts.push(formatToolUseStat(job.toolCount));
2087
2108
  if (job.totalTokens?.total) parts.push(formatTokenUsage(job.totalTokens, "token"));
2088
- if (job.startedAt !== undefined && job.updatedAt !== undefined) parts.push(formatDuration(Math.max(0, job.updatedAt - job.startedAt)));
2109
+ const end = job.status === "running" && (job.mode === "workflow" || job.parentWorkflowRunId) ? projection.now : job.updatedAt;
2110
+ if (job.status !== "queued" && job.startedAt !== undefined && end !== undefined) parts.push(formatDuration(Math.max(0, end - job.startedAt)));
2089
2111
  return statJoin(theme, parts);
2090
2112
  }
2091
2113
 
@@ -2364,7 +2386,8 @@ function hostStepWidgetLines(job: AsyncJobState, theme: Theme, indent: string):
2364
2386
  }
2365
2387
 
2366
2388
  function foregroundStyleWidgetDetails(job: AsyncJobState, theme: Theme, expanded: boolean, width: number, frame?: number, projection = buildWorkflowWidgetProjection(job)): string[] {
2367
- const { steps } = projection;
2389
+ const steps = projection.steps.filter((step) => !projection.materializedKeys?.has(step.workflowKey ?? "") && !projection.materializedKeys?.has(step.runId ?? ""));
2390
+ const checklist = widgetChecklistWithoutMaterializedChildren(projection);
2368
2391
  if (!expanded && job.mode === "workflow") {
2369
2392
  return compactWorkflowWidgetBodyLines(job, theme, frame, projection);
2370
2393
  }
@@ -2372,7 +2395,7 @@ function foregroundStyleWidgetDetails(job: AsyncJobState, theme: Theme, expanded
2372
2395
  const lane = projectAsyncLane(job, laneStepForJob(job, steps));
2373
2396
  return [
2374
2397
  ...(expanded ? workflowPreflightLines(job) : []),
2375
- ...workflowChecklistWidgetLines(projection.checklist, theme, " ", expanded, frame),
2398
+ ...workflowChecklistWidgetLines(checklist, theme, " ", expanded, frame),
2376
2399
  ...(lane ? formatLaneProjectionLines(lane, theme, " ") : []),
2377
2400
  ...hostStepWidgetLines(job, theme, " "),
2378
2401
  ` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
@@ -2382,7 +2405,7 @@ function foregroundStyleWidgetDetails(job: AsyncJobState, theme: Theme, expanded
2382
2405
  if (job.mode === "chain" && !job.activeParallelGroup && job.parallelGroups?.length) return widgetChainDetails(job, theme, expanded, width, frame);
2383
2406
  const lines: string[] = [
2384
2407
  ...(expanded ? workflowPreflightLines(job) : []),
2385
- ...workflowChecklistWidgetLines(projection.checklist, theme, " ", expanded, frame, { includeItemErrors: !expanded }),
2408
+ ...workflowChecklistWidgetLines(checklist, theme, " ", expanded, frame, { includeItemErrors: !expanded }),
2386
2409
  ];
2387
2410
  const group = activeParallelWidgetGroup(job);
2388
2411
  if (group) {
@@ -2415,7 +2438,7 @@ function foregroundStyleWidgetDetails(job: AsyncJobState, theme: Theme, expanded
2415
2438
  }
2416
2439
 
2417
2440
  function buildSingleWidgetLines(job: AsyncJobState, theme: Theme, width: number, expanded: boolean, frame?: number, projection = buildWorkflowWidgetProjection(job)): string[] {
2418
- if (!expanded && job.mode === "workflow") return [compactWorkflowHeaderLine(job, theme, width), ...compactWorkflowWidgetBodyLines(job, theme, frame, projection)].map((line) => truncLine(line, width));
2441
+ if ((!expanded || projection.inlineFleetCovered) && job.mode === "workflow") return [compactWorkflowHeaderLine(job, theme, width), ...compactWorkflowWidgetBodyLines(job, theme, frame, projection)].map((line) => truncLine(line, width));
2419
2442
  const stats = widgetStats(job, theme, projection, !expanded);
2420
2443
  const count = job.mode === "workflow"
2421
2444
  ? projection.checklist?.total ?? projection.stageProgress?.total ?? job.stepsTotal ?? job.agents?.length ?? job.steps?.length
@@ -2722,37 +2745,146 @@ function fitAdaptiveWidgetLines(jobs: AsyncJobState[], buildLines: () => string[
2722
2745
  return rendered.lines;
2723
2746
  }
2724
2747
 
2725
- function buildWidgetComponent(jobs: AsyncJobState[], isExpanded: () => boolean): (_tui: unknown, theme: Theme) => Component {
2726
- return (_tui, theme) => {
2748
+ const asyncWidgetUpdates = new WeakMap<ExtensionContext["ui"], (jobs: AsyncJobState[]) => void>();
2749
+ const inlineWorkflowCoverage = new WeakMap<ExtensionContext["ui"], ReadonlyMap<string, string>>();
2750
+ const asyncWidgetInvalidations = new WeakMap<ExtensionContext["ui"], () => void>();
2751
+
2752
+ /** Include child identity and freshness in the roster's existing snapshot. */
2753
+ export function inlineWorkflowRenderKey(job: AsyncJobState, children: AsyncJobState[]): string {
2754
+ if (!children.length) return widgetRenderKey(job);
2755
+ return JSON.stringify([widgetRenderKey(job), children.map((child) => [
2756
+ child.asyncId, widgetRenderKey(child, true), child.context,
2757
+ child.steps?.map((step) => [Boolean(step.runner), step.tokens?.window]), Boolean(child.workflowGraph),
2758
+ ])]);
2759
+ }
2760
+
2761
+ /** Presentation-only coverage from the mounted inline Fleet roster, never configuration. */
2762
+ export function setInlineWorkflowCoverage(ui: ExtensionContext["ui"], coverage: ReadonlyMap<string, string>): void {
2763
+ const previous = inlineWorkflowCoverage.get(ui);
2764
+ if ((previous?.size ?? 0) === coverage.size && [...coverage].every(([id, key]) => previous?.get(id) === key)) return;
2765
+ if (coverage.size) inlineWorkflowCoverage.set(ui, coverage);
2766
+ else inlineWorkflowCoverage.delete(ui);
2767
+ asyncWidgetInvalidations.get(ui)?.();
2768
+ }
2769
+
2770
+ /** Attach only to loaded workflow parents; orphan jobs remain top-level. */
2771
+ function widgetJobTree(jobs: AsyncJobState[], now: number): { roots: AsyncJobState[]; projectionFor: WorkflowWidgetProjectionLookup } {
2772
+ const parents = new Map(jobs.filter((job) => job.mode === "workflow").map((job) => [job.asyncId, job]));
2773
+ const childrenByParent = new Map<string, AsyncJobState[]>();
2774
+ const roots: AsyncJobState[] = [];
2775
+ for (const job of jobs) {
2776
+ const parent = job.parentWorkflowRunId ? parents.get(job.parentWorkflowRunId) : undefined;
2777
+ // Root-only adaptive summaries cannot advertise live work under a non-running parent.
2778
+ const keepLiveRoot = isProgressiveActiveJob(job) && parent?.status !== "running";
2779
+ if (parent && parent.asyncId !== job.asyncId && !keepLiveRoot) {
2780
+ const children = childrenByParent.get(parent.asyncId) ?? [];
2781
+ children.push(job);
2782
+ childrenByParent.set(parent.asyncId, children);
2783
+ } else roots.push(job);
2784
+ }
2785
+ return { roots, projectionFor: workflowWidgetProjectionLookup(now, childrenByParent) };
2786
+ }
2787
+
2788
+ function widgetChecklistWithoutMaterializedChildren(projection: WorkflowWidgetProjection): WorkflowChecklistProjection | undefined {
2789
+ const { checklist, materializedKeys } = projection;
2790
+ if (!checklist || !materializedKeys) return checklist;
2791
+ return { ...checklist, phases: checklist.phases.map((phase) => ({ ...phase, items: phase.items.filter((item) => !materializedKeys.has(item.key)) })) };
2792
+ }
2793
+
2794
+ function materializedWidgetChildLines(job: AsyncJobState, theme: Theme, width: number, expanded: boolean, frame: number | undefined, projectionFor: WorkflowWidgetProjectionLookup): string[] {
2795
+ const { children, inlineFleetCovered } = projectionFor(job);
2796
+ if (inlineFleetCovered || !children?.length) return [];
2797
+ const lines: string[] = [];
2798
+ const shown = orderedWidgetJobs(children).slice(0, MAX_WIDGET_JOBS);
2799
+ for (const [index, child] of shown.entries()) {
2800
+ const projection = projectionFor(child);
2801
+ const last = index === children.length - 1;
2802
+ const identity = child.workflowKey ?? child.asyncId;
2803
+ const stats = widgetStats(child, theme, projection, !expanded);
2804
+ lines.push(` ${last ? "└─" : "├─"} ${theme.bold(identity)} ${widgetStatusGlyph(child, theme, frame)} ${themeBold(theme, widgetJobName(child))}${contextModeBadge(theme, child.context)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`);
2805
+ for (const detail of foregroundStyleWidgetDetails(child, theme, expanded, Math.max(0, width - 6), frame, projection)) lines.push(` ${last ? " " : "│ "}${detail}`);
2806
+ for (const detail of materializedWidgetChildLines(child, theme, Math.max(0, width - 4), expanded, frame, projectionFor)) lines.push(` ${detail}`);
2807
+ }
2808
+ if (shown.length < children.length) lines.push(` +${children.length - shown.length} more workflow children`);
2809
+ return lines;
2810
+ }
2811
+
2812
+ function buildWidgetComponent(jobs: AsyncJobState[], ui: ExtensionContext["ui"]): (tui: { requestRender(): void }, theme: Theme) => Component {
2813
+ return (tui, theme) => {
2727
2814
  const container = new Container();
2728
2815
  let cachedRenderWidth: number | undefined;
2729
2816
  let cachedFrame: number | undefined;
2730
2817
  let cachedExpanded: boolean | undefined;
2731
2818
  let cachedLines: string[] | undefined;
2819
+ let cachedCoverage = "[]";
2820
+ const invalidate = (): void => {
2821
+ cachedLines = undefined;
2822
+ resetWidgetLayoutSession();
2823
+ tui.requestRender();
2824
+ };
2825
+ asyncWidgetInvalidations.set(ui, invalidate);
2826
+ const update = (nextJobs: AsyncJobState[]): void => {
2827
+ jobs = nextJobs;
2828
+ cachedLines = undefined;
2829
+ tui.requestRender();
2830
+ };
2831
+ asyncWidgetUpdates.set(ui, update);
2832
+ const component = Object.assign(container, {
2833
+ dispose(): void {
2834
+ if (asyncWidgetUpdates.get(ui) === update) asyncWidgetUpdates.delete(ui);
2835
+ if (asyncWidgetInvalidations.get(ui) === invalidate) asyncWidgetInvalidations.delete(ui);
2836
+ },
2837
+ });
2732
2838
  container.render = (renderWidth: number): string[] => {
2733
- const frame = Math.floor(Date.now() / WIDGET_ANIMATION_INTERVAL_MS);
2734
- const expanded = isExpanded();
2735
- if (cachedLines && cachedRenderWidth === renderWidth && cachedFrame === frame && cachedExpanded === expanded) return cachedLines;
2839
+ const now = Date.now();
2840
+ const frame = Math.floor(now / WIDGET_ANIMATION_INTERVAL_MS);
2841
+ const expanded = ui.getToolsExpanded?.() ?? false;
2842
+ const coverage = inlineWorkflowCoverage.get(ui);
2843
+ const covered = new Set<string>();
2844
+ if (coverage?.size) {
2845
+ const childrenByParent = new Map<string, AsyncJobState[]>();
2846
+ for (const child of jobs) {
2847
+ if (!child.parentWorkflowRunId) continue;
2848
+ const children = childrenByParent.get(child.parentWorkflowRunId) ?? [];
2849
+ children.push(child);
2850
+ childrenByParent.set(child.parentWorkflowRunId, children);
2851
+ }
2852
+ for (const job of jobs) {
2853
+ const snapshot = coverage.get(job.asyncId);
2854
+ if (snapshot === undefined) continue;
2855
+ const children = childrenByParent.get(job.asyncId) ?? [];
2856
+ if (!children.some((child) => childrenByParent.has(child.asyncId))
2857
+ && snapshot === inlineWorkflowRenderKey(job, children)) covered.add(job.asyncId);
2858
+ }
2859
+ }
2860
+ const coverageKey = JSON.stringify([...covered]);
2861
+ if (cachedLines && cachedRenderWidth === renderWidth && cachedFrame === frame && cachedExpanded === expanded && cachedCoverage === coverageKey) return cachedLines;
2862
+ if (cachedCoverage !== coverageKey) resetWidgetLayoutSession();
2863
+ cachedCoverage = coverageKey;
2736
2864
  const width = Math.max(0, renderWidth - 2);
2737
- const projectionFor = workflowWidgetProjectionLookup();
2865
+ const { roots, projectionFor } = widgetJobTree(jobs, now);
2866
+ for (const job of roots) projectionFor(job).inlineFleetCovered = covered.has(job.asyncId);
2738
2867
  const buildLines = (): string[] => expanded
2739
- ? buildWidgetLinesWithProjection(jobs, theme, width, true, frame, projectionFor)
2740
- : jobs.length === 1
2741
- ? compactSingleWidgetLines(jobs[0]!, theme, width, frame, projectionFor(jobs[0]!))
2742
- : buildWidgetLinesWithProjection(jobs, theme, width, false, frame, projectionFor);
2868
+ ? buildWidgetLinesWithProjection(roots, theme, width, true, frame, projectionFor)
2869
+ : roots.length === 1 && !projectionFor(roots[0]!).children?.length
2870
+ ? compactSingleWidgetLines(roots[0]!, theme, width, frame, projectionFor(roots[0]!))
2871
+ : buildWidgetLinesWithProjection(roots, theme, width, false, frame, projectionFor);
2743
2872
  cachedRenderWidth = renderWidth;
2744
2873
  cachedFrame = frame;
2745
2874
  cachedExpanded = expanded;
2746
- cachedLines = fitAdaptiveWidgetLines(jobs, buildLines, theme, width, expanded, frame, projectionFor).map((line) => paddedWidgetLine(line, renderWidth));
2875
+ cachedLines = fitAdaptiveWidgetLines(roots, buildLines, theme, width, expanded, frame, projectionFor).map((line) => paddedWidgetLine(line, renderWidth));
2747
2876
  return cachedLines;
2748
2877
  };
2749
- return container;
2878
+ return component;
2750
2879
  };
2751
2880
  }
2752
2881
 
2753
2882
  function buildWidgetLinesWithProjection(jobs: AsyncJobState[], theme: Theme, width = getTermWidth(), expanded = false, frame?: number, projectionFor: WorkflowWidgetProjectionLookup = workflowWidgetProjectionLookup()): string[] {
2754
2883
  if (jobs.length === 0) return [];
2755
- if (jobs.length === 1) return buildSingleWidgetLines(jobs[0]!, theme, width, expanded, frame, projectionFor(jobs[0]!));
2884
+ if (jobs.length === 1) return [
2885
+ ...buildSingleWidgetLines(jobs[0]!, theme, width, expanded, frame, projectionFor(jobs[0]!)),
2886
+ ...materializedWidgetChildLines(jobs[0]!, theme, width, expanded, frame, projectionFor).map((line) => truncLine(line, width)),
2887
+ ];
2756
2888
  const running = jobs.filter((job) => job.status === "running");
2757
2889
  const queued = jobs.filter((job) => job.status === "queued");
2758
2890
  const finished = jobs.filter((job) => job.status !== "running" && job.status !== "queued");
@@ -2769,7 +2901,7 @@ function buildWidgetLinesWithProjection(jobs: AsyncJobState[], theme: Theme, wid
2769
2901
  let slots = MAX_WIDGET_JOBS;
2770
2902
  const appendJob = (job: AsyncJobState): void => {
2771
2903
  const projection = projectionFor(job);
2772
- const compactWorkflow = !expanded && job.mode === "workflow";
2904
+ const compactWorkflow = (!expanded || projection.inlineFleetCovered) && job.mode === "workflow";
2773
2905
  const stats = compactWorkflow ? "" : widgetStats(job, theme, projection, !expanded);
2774
2906
  const details = compactWorkflow
2775
2907
  ? [
@@ -2778,7 +2910,7 @@ function buildWidgetLinesWithProjection(jobs: AsyncJobState[], theme: Theme, wid
2778
2910
  : [
2779
2911
  ` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
2780
2912
  ...widgetLaneDetailLines(job, theme, projection),
2781
- ...workflowChecklistWidgetLines(projection.checklist, theme, " ", expanded, frame, { includeItemErrors: !expanded || !job.steps?.length }),
2913
+ ...workflowChecklistWidgetLines(widgetChecklistWithoutMaterializedChildren(projection), theme, " ", expanded, frame, { includeItemErrors: !expanded || !job.steps?.length }),
2782
2914
  ...widgetParallelAgentDetails(job, theme, expanded, width, frame),
2783
2915
  ];
2784
2916
  items.push([
@@ -2786,6 +2918,7 @@ function buildWidgetLinesWithProjection(jobs: AsyncJobState[], theme: Theme, wid
2786
2918
  ? compactWorkflowHeaderLine(job, theme, width)
2787
2919
  : `${widgetStatusGlyph(job, theme, frame)} ${themeBold(theme, widgetJobName(job))}${contextModeBadge(theme, job.context)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
2788
2920
  ...details,
2921
+ ...materializedWidgetChildLines(job, theme, width, expanded, frame, projectionFor),
2789
2922
  ]);
2790
2923
  };
2791
2924
 
@@ -2832,7 +2965,8 @@ function buildWidgetLinesWithProjection(jobs: AsyncJobState[], theme: Theme, wid
2832
2965
  }
2833
2966
 
2834
2967
  export function buildWidgetLines(jobs: AsyncJobState[], theme: Theme, width = getTermWidth(), expanded = false, frame?: number): string[] {
2835
- return buildWidgetLinesWithProjection(jobs, theme, width, expanded, frame);
2968
+ const { roots, projectionFor } = widgetJobTree(jobs, Date.now());
2969
+ return buildWidgetLinesWithProjection(roots, theme, width, expanded, frame, projectionFor);
2836
2970
  }
2837
2971
 
2838
2972
  /**
@@ -2841,6 +2975,7 @@ export function buildWidgetLines(jobs: AsyncJobState[], theme: Theme, width = ge
2841
2975
  export function renderWidget(ctx: ExtensionContext, jobs: AsyncJobState[]): void {
2842
2976
  if (jobs.length === 0) {
2843
2977
  resetWidgetLayoutSession();
2978
+ asyncWidgetUpdates.delete(ctx.ui);
2844
2979
  if (ctx.hasUI) ctx.ui.setWidget(WIDGET_KEY, undefined);
2845
2980
  return;
2846
2981
  }
@@ -2849,7 +2984,11 @@ export function renderWidget(ctx: ExtensionContext, jobs: AsyncJobState[]): void
2849
2984
  ctx.ui.setWidget(WIDGET_KEY, encodeAsyncStatusSnapshotWidget(jobs));
2850
2985
  return;
2851
2986
  }
2852
- ctx.ui.setWidget(WIDGET_KEY, buildWidgetComponent(jobs, () => ctx.ui.getToolsExpanded?.() ?? false));
2987
+ // Pi replaces a widget by deleting and reinserting its key. Update the mounted
2988
+ // component instead so progress cannot move it past other extensions' widgets.
2989
+ const update = asyncWidgetUpdates.get(ctx.ui);
2990
+ if (update) update(jobs);
2991
+ else ctx.ui.setWidget(WIDGET_KEY, buildWidgetComponent(jobs, ctx.ui));
2853
2992
  }
2854
2993
 
2855
2994
  function renderSingleCompact(
@@ -16,6 +16,7 @@ export interface ChildWatchdogConfig {
16
16
  agentEndTimeoutMs: number;
17
17
  maxWarnings: number | null;
18
18
  model?: string;
19
+ fallbackModels?: string[];
19
20
  thinking?: string | false;
20
21
  lsp: WatchdogLspConfig;
21
22
  stalemateRepeats: number;
@@ -47,6 +48,7 @@ export function resolveChildWatchdogConfig(input: {
47
48
  const enabled = input.config.enabled && (override?.enabled ?? input.config.children.enabled);
48
49
  if (!enabled) return undefined;
49
50
  const model = override?.model ?? input.config.children.model;
51
+ const fallbackModels = override?.fallbackModels ?? input.config.children.fallbackModels;
50
52
  const thinking = override?.thinking ?? input.config.children.thinking;
51
53
  const cadence = override?.cadence ?? input.config.children.cadence ?? input.config.cadence;
52
54
  return {
@@ -57,6 +59,7 @@ export function resolveChildWatchdogConfig(input: {
57
59
  agentEndTimeoutMs: input.config.agentEndTimeoutMs,
58
60
  maxWarnings: input.config.maxWarnings,
59
61
  ...(model ? { model } : {}),
62
+ ...(fallbackModels !== undefined ? { fallbackModels: [...fallbackModels] } : {}),
60
63
  ...(thinking !== undefined ? { thinking } : {}),
61
64
  lsp: { ...input.config.lsp },
62
65
  stalemateRepeats: input.config.stalemateRepeats,
@@ -137,6 +140,10 @@ export function decodeChildWatchdogConfig(raw: string | undefined): ChildWatchdo
137
140
  const agent = childConfigOptionalString(parsed, "agent");
138
141
  const childIndex = childConfigOptionalIndex(parsed, "childIndex");
139
142
  const model = childConfigOptionalString(parsed, "model");
143
+ const fallbackModels = parsed.fallbackModels;
144
+ if (fallbackModels !== undefined && (!Array.isArray(fallbackModels) || fallbackModels.some((value) => typeof value !== "string" || !value.trim()))) {
145
+ throw new Error("Invalid child watchdog config: fallbackModels must be an array of non-empty strings.");
146
+ }
140
147
  return {
141
148
  ...(runId ? { runId } : {}),
142
149
  ...(agent ? { agent } : {}),
@@ -145,6 +152,7 @@ export function decodeChildWatchdogConfig(raw: string | undefined): ChildWatchdo
145
152
  agentEndTimeoutMs: childConfigPositiveInteger(parsed, "agentEndTimeoutMs"),
146
153
  maxWarnings: childConfigNullableNonNegativeInteger(parsed, "maxWarnings"),
147
154
  ...(model ? { model } : {}),
155
+ ...(fallbackModels !== undefined ? { fallbackModels: (fallbackModels as string[]).map((value) => value.trim()) } : {}),
148
156
  ...(thinking !== undefined ? { thinking: thinking as string | false } : {}),
149
157
  lsp: childConfigLsp(parsed.lsp),
150
158
  stalemateRepeats: childConfigPositiveInteger(parsed, "stalemateRepeats"),
@@ -1,5 +1,6 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { normalizeModelSegment, resolveModelCandidate } from "../runs/shared/model-fallback.ts";
3
+ import type { WatchdogEndpointConfig } from "./types.ts";
3
4
  import {
4
5
  getSupportedThinkingLevels,
5
6
  splitKnownThinkingSuffix,
@@ -43,6 +44,7 @@ export interface ResolvedWatchdogModelInput {
43
44
  }
44
45
 
45
46
  export interface WatchdogModelRecommendation {
47
+ source: "configured" | "suggested";
46
48
  model: string;
47
49
  thinking: ThinkingLevel;
48
50
  label: string;
@@ -147,6 +149,7 @@ function resolveStrongCandidate(ctx: ExtensionContext, family: StrongWatchdogFam
147
149
  if (!getSupportedThinkingLevels(modelInfo).includes(STRONG_WATCHDOG_THINKING)) continue;
148
150
  const current = ctx.model ? fullModelId(toModelInfo(ctx.model)) : "no current session model";
149
151
  return {
152
+ source: "suggested",
150
153
  model: resolved.model,
151
154
  thinking: STRONG_WATCHDOG_THINKING,
152
155
  label: preference.label,
@@ -165,3 +168,20 @@ export function recommendStrongWatchdogModel(ctx: ExtensionContext): WatchdogMod
165
168
  const current = ctx.model ? fullModelId(toModelInfo(ctx.model)) : "the current session";
166
169
  throw new Error(`No authenticated strong complementary watchdog model was found for ${current}. Configure access to Opus 4.8 or GPT 5.5, then run the recommendation again.`);
167
170
  }
171
+
172
+ export function recommendWatchdogModel(ctx: ExtensionContext, configured: WatchdogEndpointConfig): WatchdogModelRecommendation {
173
+ if (!configured.model) return recommendStrongWatchdogModel(ctx);
174
+ const resolved = resolveWatchdogModelInput(ctx, configured.model);
175
+ const thinking = resolved.thinking ?? parseWatchdogThinkingInput(configured.thinking) ?? "off";
176
+ return {
177
+ ...resolved,
178
+ source: "configured",
179
+ thinking: thinking === false ? "off" : thinking,
180
+ label: "configured watchdog",
181
+ reason: "Keep the configured watchdog model and thinking; no replacement recommendation is needed. This is not a strength or independence assessment.",
182
+ };
183
+ }
184
+
185
+ export function formatWatchdogRecommendation(recommendation: WatchdogModelRecommendation): string {
186
+ return `${recommendation.source === "configured" ? "Keep configured watchdog" : "Recommended strong watchdog"}: ${recommendation.model}:${recommendation.thinking}`;
187
+ }
@@ -4,6 +4,7 @@ import { streamSimple } from "@earendil-works/pi-ai/compat";
4
4
  import { Type, type Static } from "typebox";
5
5
  import { appendPermissionAudit, permissionArgsPreview } from "../runs/shared/permissions.ts";
6
6
  import { agentStreamOptions } from "../shared/agent-stream-options.ts";
7
+ import { opencodeSessionHeaders } from "../shared/opencode-session-headers.ts";
7
8
  import { decodeChildWatchdogConfig } from "./child-status.ts";
8
9
  import { childResolvedConfig } from "./register-child.ts";
9
10
  import { resolveWatchdogReviewModel } from "./review.ts";
@@ -94,6 +95,7 @@ export function createWatchdogPermissionArbiter(options: WatchdogPermissionArbit
94
95
  const config = childResolvedConfig(childConfig);
95
96
  const selection = await resolveWatchdogReviewModel(request.ctx, config);
96
97
  const auth = selection.auth;
98
+ const sessionId = request.ctx.sessionManager.getSessionId();
97
99
  const registeredProvider = (request.ctx.modelRegistry as {
98
100
  getRegisteredProviderConfig?: (provider: string) => { api?: string; streamSimple?: StreamFn } | undefined;
99
101
  }).getRegisteredProviderConfig?.(selection.model.provider);
@@ -104,7 +106,7 @@ export function createWatchdogPermissionArbiter(options: WatchdogPermissionArbit
104
106
  ...streamOptions,
105
107
  ...(auth.apiKey ? { apiKey: auth.apiKey } : {}),
106
108
  env: auth.env || streamOptions?.env ? { ...(auth.env ?? {}), ...(streamOptions?.env ?? {}) } : undefined,
107
- headers: { ...(streamOptions?.headers ?? {}), ...(auth.headers ?? {}) },
109
+ headers: { ...opencodeSessionHeaders(model, sessionId), ...(streamOptions?.headers ?? {}), ...(auth.headers ?? {}) },
108
110
  });
109
111
  agent = new Agent({
110
112
  initialState: {
@@ -21,6 +21,7 @@ export function childResolvedConfig(config: ChildWatchdogConfig): ResolvedWatchd
21
21
  main: {
22
22
  enabled: true,
23
23
  ...(config.model ? { model: config.model } : {}),
24
+ ...(config.fallbackModels !== undefined ? { fallbackModels: [...config.fallbackModels] } : {}),
24
25
  ...(config.thinking !== undefined ? { thinking: config.thinking } : {}),
25
26
  },
26
27
  stalemateRepeats: config.stalemateRepeats,