pi-subagents 0.58.0 → 0.60.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 (116) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/docs/agents.md +5 -3
  3. package/docs/configuration.md +4 -4
  4. package/docs/extension-api.md +1 -1
  5. package/docs/models.md +24 -1
  6. package/docs/observability.md +1 -1
  7. package/docs/tool-reference.md +93 -5
  8. package/docs/workflows.md +94 -3
  9. package/package.json +3 -1
  10. package/prompts/review-loop.md +2 -2
  11. package/skills/council-mode/SKILL.md +48 -243
  12. package/skills/council-mode/references/pass-contracts.md +150 -0
  13. package/skills/pi-subagents/SKILL.md +87 -37
  14. package/skills/pi-subagents/references/constraints-and-recipes.md +29 -233
  15. package/skills/pi-subagents/references/execution-controls.md +52 -7
  16. package/skills/pi-subagents/references/management-authoring-rpc.md +3 -4
  17. package/skills/pi-subagents/references/multi-lane-orchestration.md +13 -1
  18. package/skills/pi-subagents/references/prompting-and-roles.md +54 -26
  19. package/skills/pi-subagents/references/review-and-validation.md +73 -0
  20. package/src/agents/agent-management.ts +159 -42
  21. package/src/agents/agent-serializer.ts +4 -2
  22. package/src/agents/agents.ts +67 -26
  23. package/src/agents/runtime-agent-registry.ts +9 -16
  24. package/src/api/background-work.ts +5 -1
  25. package/src/api/delegation.ts +0 -7
  26. package/src/api/preflight.ts +6 -9
  27. package/src/api/shared-types.ts +2 -0
  28. package/src/extension/fanout-child.ts +5 -3
  29. package/src/extension/index.ts +51 -23
  30. package/src/extension/public-execution.ts +16 -2
  31. package/src/extension/schemas.ts +36 -10
  32. package/src/extension/tool-description.ts +24 -5
  33. package/src/intercom/result-intercom.ts +2 -0
  34. package/src/profiles/profiles.ts +5 -6
  35. package/src/runs/background/active-async-capacity.ts +2 -2
  36. package/src/runs/background/async-execution.ts +52 -37
  37. package/src/runs/background/async-job-tracker.ts +17 -12
  38. package/src/runs/background/async-resume.ts +23 -25
  39. package/src/runs/background/async-status-snapshot.ts +23 -261
  40. package/src/runs/background/async-status.ts +110 -8
  41. package/src/runs/background/chain-append.ts +6 -3
  42. package/src/runs/background/chain-root-attachment.ts +60 -8
  43. package/src/runs/background/control-channel.ts +3 -2
  44. package/src/runs/background/fleet-view.ts +21 -11
  45. package/src/runs/background/notify.ts +158 -6
  46. package/src/runs/background/result-files.ts +2 -1
  47. package/src/runs/background/result-watcher.ts +2 -0
  48. package/src/runs/background/resume-guidance.ts +1 -1
  49. package/src/runs/background/retained-children.ts +1 -1
  50. package/src/runs/background/run-status.ts +30 -9
  51. package/src/runs/background/scheduled-runs.ts +86 -7
  52. package/src/runs/background/stale-run-reconciler.ts +10 -4
  53. package/src/runs/background/steering.ts +4 -14
  54. package/src/runs/background/subagent-runner.ts +351 -358
  55. package/src/runs/background/subagent-wait.ts +68 -12
  56. package/src/runs/background/terminal-run-index.ts +1 -1
  57. package/src/runs/background/wait-completions.ts +25 -1
  58. package/src/runs/background/wait-config.ts +23 -9
  59. package/src/runs/background/wait-tool.ts +9 -2
  60. package/src/runs/foreground/async-steering-action.ts +2 -2
  61. package/src/runs/foreground/execution.ts +125 -122
  62. package/src/runs/foreground/foreground-control.ts +3 -0
  63. package/src/runs/foreground/foreground-history.ts +1 -0
  64. package/src/runs/foreground/subagent-executor.ts +576 -240
  65. package/src/runs/foreground/workflow-detach-reconcile.ts +99 -200
  66. package/src/runs/shared/abort-recovery.ts +119 -0
  67. package/src/runs/shared/async-status-projection.ts +597 -0
  68. package/src/runs/shared/background-process-options.ts +9 -0
  69. package/src/runs/shared/child-identity.ts +19 -4
  70. package/src/runs/shared/child-launch-plan.ts +151 -0
  71. package/src/runs/shared/completion-evidence.ts +89 -0
  72. package/src/runs/shared/completion-guard.ts +1 -1
  73. package/src/runs/shared/dynamic-fanout.ts +2 -2
  74. package/src/runs/shared/host-step-status.ts +230 -0
  75. package/src/runs/shared/lane-metadata.ts +105 -0
  76. package/src/runs/shared/mcp-config-sources.ts +42 -6
  77. package/src/runs/shared/mcp-direct-tool-allowlist.ts +93 -143
  78. package/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
  79. package/src/runs/shared/model-fallback.ts +9 -2
  80. package/src/runs/shared/mutation-evidence.ts +52 -3
  81. package/src/runs/shared/nested-events.ts +6 -2
  82. package/src/runs/shared/nested-render.ts +7 -3
  83. package/src/runs/shared/parallel-handoff.ts +419 -7
  84. package/src/runs/shared/parallel-utils.ts +7 -0
  85. package/src/runs/shared/pi-args.ts +67 -3
  86. package/src/runs/shared/single-output.ts +72 -22
  87. package/src/runs/shared/subagent-prompt-runtime.ts +33 -6
  88. package/src/runs/shared/workflow-graph.ts +15 -0
  89. package/src/runs/shared/worktree-cleanup-plan.ts +847 -0
  90. package/src/runs/shared/worktree.ts +18 -0
  91. package/src/shared/child-session-name.ts +46 -0
  92. package/src/shared/extension-context.ts +24 -0
  93. package/src/shared/formatters.ts +5 -2
  94. package/src/shared/launch-contract.ts +1 -1
  95. package/src/shared/settings.ts +9 -103
  96. package/src/shared/types.ts +232 -30
  97. package/src/shared/utils.ts +35 -55
  98. package/src/slash/delegation-adapters.ts +1 -8
  99. package/src/slash/delegation-request.ts +0 -4
  100. package/src/slash/slash-bridge.ts +1 -2
  101. package/src/slash/slash-commands.ts +369 -90
  102. package/src/slash/slash-live-state.ts +22 -11
  103. package/src/tui/fleet-status.ts +134 -75
  104. package/src/tui/fleet.ts +11 -5
  105. package/src/tui/render-helpers.ts +31 -0
  106. package/src/tui/render.ts +895 -121
  107. package/src/watchdog/change-signature.ts +40 -1
  108. package/src/watchdog/turn-delta.ts +1 -1
  109. package/src/workflows/chat-progress.ts +6 -3
  110. package/src/workflows/host-command.ts +235 -0
  111. package/src/workflows/scripted-workflow.ts +503 -38
  112. package/src/workflows/workflow-child-summary.ts +9 -5
  113. package/src/workflows/workflow-preflight.ts +270 -0
  114. package/src/workflows/workflow-receipt.ts +43 -4
  115. package/src/workflows/workflow-settlement.ts +246 -0
  116. package/src/runs/shared/turn-budget.ts +0 -98
@@ -3,7 +3,7 @@ import { createHash } from "node:crypto";
3
3
  import * as fs from "node:fs";
4
4
  import * as os from "node:os";
5
5
  import * as path from "node:path";
6
- import type { ArtifactPaths, TimeoutRecoverySummary, TrackedMutationEvidence, TrackedMutationFingerprint, TrackedMutationSnapshot } from "../../shared/types.ts";
6
+ import type { ArtifactPaths, TimeoutRecoveryProjection, TimeoutRecoverySummary, TrackedMutationEvidence, TrackedMutationFingerprint, TrackedMutationSnapshot } from "../../shared/types.ts";
7
7
 
8
8
  const MAX_TRACKED_PATHS = 500;
9
9
  const MAX_HASH_BYTES = 1024 * 1024;
@@ -15,7 +15,7 @@ function gitArguments(args: string[]): string[] {
15
15
  }
16
16
 
17
17
  function gitOutput(cwd: string, args: string[], maxBuffer = MAX_HASH_BYTES): string {
18
- return execFileSync("git", gitArguments(args), { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer });
18
+ return execFileSync("git", gitArguments(args), { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer, windowsHide: true });
19
19
  }
20
20
 
21
21
  function splitNul(output: string): string[] {
@@ -26,7 +26,7 @@ function hashLargeDiff(cwd: string, relativePath: string): string {
26
26
  const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagents-tracked-diff-"));
27
27
  const diffPath = path.join(tempDir, "diff.patch");
28
28
  try {
29
- execFileSync("git", gitArguments(["diff", "--no-ext-diff", "--binary", `--output=${diffPath}`, "HEAD", "--", relativePath]), { cwd, stdio: "ignore" });
29
+ execFileSync("git", gitArguments(["diff", "--no-ext-diff", "--binary", `--output=${diffPath}`, "HEAD", "--", relativePath]), { cwd, stdio: "ignore", windowsHide: true });
30
30
  const hash = createHash("sha256");
31
31
  const buffer = Buffer.allocUnsafe(64 * 1024);
32
32
  const fd = fs.openSync(diffPath, "r");
@@ -110,9 +110,48 @@ function formatPathList(paths: string[]): string {
110
110
  return paths.length > MAX_TIMEOUT_FILES ? `${shown}, ... (${paths.length - MAX_TIMEOUT_FILES} more)` : shown;
111
111
  }
112
112
 
113
+ /** Keep status and completion details to bounded routing evidence, not raw output or effects. */
114
+ export function projectTimeoutRecovery(value: unknown): TimeoutRecoveryProjection | undefined {
115
+ if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
116
+ const source = value as Record<string, unknown>;
117
+ const termination = source.termination === "timed-out" || source.termination === "stopped" ? source.termination : undefined;
118
+ if (!termination || !Array.isArray(source.changedFiles)) return undefined;
119
+ const allChangedFiles = source.changedFiles.filter((file): file is string => typeof file === "string");
120
+ const changedFiles = allChangedFiles.slice(0, MAX_TIMEOUT_FILES);
121
+ const reportStatus = source.reportStatus === "missing"
122
+ || source.reportStatus === "written"
123
+ || source.reportStatus === "not-requested"
124
+ || source.reportStatus === "unknown"
125
+ ? source.reportStatus
126
+ : undefined;
127
+ return {
128
+ termination,
129
+ changedFiles,
130
+ ...(source.truncated === true || allChangedFiles.length > changedFiles.length ? { truncated: true } : {}),
131
+ ...(source.recoveryNeeded === true ? { recoveryNeeded: true } : {}),
132
+ ...(source.reason === "timed-out-with-dirty-worktree" ? { reason: source.reason } : {}),
133
+ ...(reportStatus ? { reportStatus } : {}),
134
+ };
135
+ }
136
+
137
+ /** Render only the bounded recovery route needed by a parent/operator. */
138
+ export function formatTimeoutRecoveryLines(value: unknown, indent = ""): string[] {
139
+ const recovery = projectTimeoutRecovery(value);
140
+ if (!recovery?.recoveryNeeded) return [];
141
+ const changedFiles = recovery.changedFiles.length > 0
142
+ ? `${recovery.changedFiles.join(", ")}${recovery.truncated ? ", …" : ""}`
143
+ : "none";
144
+ const changedFileCount = recovery.changedFiles.length > 0 ? `${recovery.changedFiles.length}${recovery.truncated ? "+" : ""}` : "0";
145
+ return [
146
+ `${indent}Recovery needed: review the diff and artifacts before resuming or launching dependent stages.`,
147
+ `${indent}Recovery evidence: requested report: ${recovery.reportStatus ?? "unknown"}; changed tracked files: ${changedFiles} (${changedFileCount}); classification: ${recovery.reason ?? recovery.termination}`,
148
+ ];
149
+ }
150
+
113
151
  export function buildTimeoutRecoverySummary(input: {
114
152
  termination: "timed-out" | "stopped";
115
153
  evidence: TrackedMutationEvidence;
154
+ requiredOutputMissing?: boolean;
116
155
  currentTool?: string;
117
156
  currentToolArgs?: string;
118
157
  currentPath?: string;
@@ -122,11 +161,19 @@ export function buildTimeoutRecoverySummary(input: {
122
161
  }): TimeoutRecoverySummary {
123
162
  const warning = "Inspect partial changes before retrying or resuming the child.";
124
163
  const changedFiles = input.evidence.changedFiles.slice(0, MAX_TIMEOUT_FILES);
164
+ let reportStatus: "missing" | "written" | "not-requested" = "not-requested";
165
+ if (input.requiredOutputMissing === true) reportStatus = "missing";
166
+ else if (input.requiredOutputMissing === false) reportStatus = "written";
167
+ const recoveryNeeded = input.termination === "timed-out"
168
+ && reportStatus === "missing"
169
+ && input.evidence.changedFiles.length > 0;
125
170
  const lines = [
126
171
  "Recovery summary:",
127
172
  `- termination: ${input.termination}`,
128
173
  `- changed tracked files: ${input.evidence.unavailable ? `unavailable (${input.evidence.unavailable})` : formatPathList(input.evidence.changedFiles)}`,
129
174
  ];
175
+ if (input.requiredOutputMissing !== undefined) lines.push(`- requested report: ${reportStatus}`);
176
+ if (recoveryNeeded) lines.push("- Recovery needed: review the diff and artifacts before resuming or launching dependent stages.");
130
177
  if (input.currentTool) lines.push(`- active tool: ${input.currentTool}${input.currentToolArgs ? ` — ${input.currentToolArgs}` : ""}`);
131
178
  if (input.currentPath) lines.push(`- active path: ${input.currentPath}`);
132
179
  if (input.sessionFile) lines.push(`- session file: ${input.sessionFile}`);
@@ -138,6 +185,8 @@ export function buildTimeoutRecoverySummary(input: {
138
185
  termination: input.termination,
139
186
  changedFiles,
140
187
  truncated: input.evidence.changedFiles.length > changedFiles.length || input.evidence.truncated || undefined,
188
+ ...(recoveryNeeded ? { recoveryNeeded: true, reason: "timed-out-with-dirty-worktree" as const } : {}),
189
+ reportStatus,
141
190
  currentTool: input.currentTool,
142
191
  currentToolArgs: input.currentToolArgs,
143
192
  currentPath: input.currentPath,
@@ -286,7 +286,7 @@ function sanitizeTurnBudget(value: unknown): TurnBudgetState | undefined {
286
286
  }
287
287
 
288
288
  function sanitizeState(value: unknown, fallback: NestedRunState): NestedRunState {
289
- return value === "queued" || value === "running" || value === "complete" || value === "failed" || value === "paused" || value === "stopped"
289
+ return value === "queued" || value === "running" || value === "complete" || value === "failed" || value === "partial" || value === "paused" || value === "stopped"
290
290
  ? value
291
291
  : fallback;
292
292
  }
@@ -306,6 +306,7 @@ function sanitizeStep(input: unknown, depth: number): NestedStepSummary | undefi
306
306
  status,
307
307
  ...(model ? { model } : {}),
308
308
  ...(thinking ? { thinking } : {}),
309
+ ...(stringValue(raw.sessionName, 256) ? { sessionName: stringValue(raw.sessionName, 256) } : {}),
309
310
  ...(stringValue(raw.sessionFile, 2048) ? { sessionFile: stringValue(raw.sessionFile, 2048) } : {}),
310
311
  ...(raw.activityState === "active_long_running" || raw.activityState === "needs_attention" ? { activityState: raw.activityState } : {}),
311
312
  ...(clampNumber(raw.lastActivityAt) !== undefined ? { lastActivityAt: clampNumber(raw.lastActivityAt) } : {}),
@@ -346,6 +347,7 @@ export function sanitizeSummary(input: unknown, depth = 0): NestedRunSummary | u
346
347
  depth: Math.min(Math.max(0, clampNumber(raw.depth) ?? 0), MAX_DEPTH),
347
348
  path: pathParts,
348
349
  state: sanitizeState(raw.state, "running"),
350
+ ...(stringValue(raw.sessionName, 256) ? { sessionName: stringValue(raw.sessionName, 256) } : {}),
349
351
  ...(stringValue(raw.model) ? { model: stringValue(raw.model) } : {}),
350
352
  ...(THINKING_LEVELS.find((level) => level === raw.thinking) ? { thinking: THINKING_LEVELS.find((level) => level === raw.thinking) } : {}),
351
353
  ...(stringValue(raw.asyncDir, 2048) ? { asyncDir: stringValue(raw.asyncDir, 2048) } : {}),
@@ -436,7 +438,7 @@ export function parseNestedEventRecords(content: string, route: NestedRoute): Ne
436
438
  }
437
439
 
438
440
  function terminal(state: NestedRunState): boolean {
439
- return state === "complete" || state === "failed" || state === "paused" || state === "stopped";
441
+ return state === "complete" || state === "failed" || state === "partial" || state === "paused" || state === "stopped";
440
442
  }
441
443
 
442
444
  function mergeBoundedChildren(existing: NestedRunSummary[] | undefined, incoming: NestedRunSummary[] | undefined): NestedRunSummary[] | undefined {
@@ -1005,6 +1007,7 @@ export function nestedSummaryFromAsyncStatus(status: AsyncStatus, asyncDir: stri
1005
1007
  mode: status.mode ?? fallback.mode,
1006
1008
  ...(status.steps?.length === 1 && status.steps[0]?.model ? { model: status.steps[0].model } : {}),
1007
1009
  ...(status.steps?.length === 1 && status.steps[0]?.thinking ? { thinking: status.steps[0].thinking } : {}),
1010
+ ...(status.steps?.length === 1 && status.steps[0]?.sessionName ? { sessionName: status.steps[0].sessionName } : {}),
1008
1011
  ...(status.processTerminal ? { processTerminal: sanitizeProcessTerminal(status.processTerminal, { runId: status.runId || fallback.id, runnerProcessInstanceId: status.processTerminal.runnerProcessInstanceId }, `${asyncDir}/status.json`) } : {}),
1009
1012
  ...(status.launchResolvedExtensions ? { launchResolvedExtensions: status.launchResolvedExtensions } : {}),
1010
1013
  ...runtimeAcknowledgedEntry(status.runtimeAcknowledgedExtensions),
@@ -1035,6 +1038,7 @@ export function nestedSummaryFromAsyncStatus(status: AsyncStatus, asyncDir: stri
1035
1038
  ...(status.sessionFile ? { sessionFile: status.sessionFile } : {}),
1036
1039
  ...(status.steps?.length ? { steps: status.steps.map((step, index) => ({
1037
1040
  agent: step.agent,
1041
+ ...(step.sessionName ? { sessionName: step.sessionName } : {}),
1038
1042
  status: step.status,
1039
1043
  ...(step.model ? { model: step.model } : {}),
1040
1044
  ...(step.thinking ? { thinking: step.thinking } : {}),
@@ -1,6 +1,6 @@
1
1
  import { formatDuration, formatModelThinking, formatTokenUsage, shortenPath } from "../../shared/formatters.ts";
2
2
  import { formatActivityLabel } from "../../shared/status-format.ts";
3
- import type { ActivityState, NestedRunSummary, NestedStepSummary } from "../../shared/types.ts";
3
+ import type { ActivityState, NestedRunSummary } from "../../shared/types.ts";
4
4
 
5
5
  export interface NestedRunCounts {
6
6
  total: number;
@@ -8,13 +8,14 @@ export interface NestedRunCounts {
8
8
  paused: number;
9
9
  complete: number;
10
10
  failed: number;
11
+ partial: number;
11
12
  rejected: number;
12
13
  stopped: number;
13
14
  queued: number;
14
15
  }
15
16
 
16
17
  export function countNestedRuns(children: NestedRunSummary[] | undefined): NestedRunCounts {
17
- const counts: NestedRunCounts = { total: 0, running: 0, paused: 0, complete: 0, failed: 0, rejected: 0, stopped: 0, queued: 0 };
18
+ const counts: NestedRunCounts = { total: 0, running: 0, paused: 0, complete: 0, failed: 0, partial: 0, rejected: 0, stopped: 0, queued: 0 };
18
19
  for (const child of children ?? []) {
19
20
  counts.total++;
20
21
  counts[child.state]++;
@@ -24,6 +25,7 @@ export function countNestedRuns(children: NestedRunSummary[] | undefined): Neste
24
25
  counts.paused += nested.paused;
25
26
  counts.complete += nested.complete;
26
27
  counts.failed += nested.failed;
28
+ counts.partial += nested.partial;
27
29
  counts.rejected += nested.rejected;
28
30
  counts.stopped += nested.stopped;
29
31
  counts.queued += nested.queued;
@@ -38,6 +40,7 @@ export function formatNestedAggregate(children: NestedRunSummary[] | undefined):
38
40
  counts.running > 0 ? `${counts.running} running` : "",
39
41
  counts.paused > 0 ? `${counts.paused} paused` : "",
40
42
  counts.failed > 0 ? `${counts.failed} failed` : "",
43
+ counts.partial > 0 ? `${counts.partial} partial` : "",
41
44
  counts.rejected > 0 ? `${counts.rejected} rejected` : "",
42
45
  counts.stopped > 0 ? `${counts.stopped} stopped` : "",
43
46
  counts.complete > 0 ? `${counts.complete} complete` : "",
@@ -47,6 +50,7 @@ export function formatNestedAggregate(children: NestedRunSummary[] | undefined):
47
50
  }
48
51
 
49
52
  function nestedRunLabel(run: NestedRunSummary): string {
53
+ if (run.sessionName?.trim()) return run.sessionName.trim();
50
54
  if (run.agent) return run.agent;
51
55
  if (run.agents?.length) return run.agents.length === 1 ? run.agents[0]! : `${run.agents.slice(0, 2).join(", ")}${run.agents.length > 2 ? ` +${run.agents.length - 2}` : ""}`;
52
56
  return run.id;
@@ -103,7 +107,7 @@ function formatNestedRunLines(children: NestedRunSummary[] | undefined, options:
103
107
  if (lines.length >= options.maxLines) return;
104
108
  const stepActivity = step.status === "running" ? formatNestedActivity(step) : undefined;
105
109
  const stepModelThinking = formatModelThinking(step.model, step.thinking);
106
- lines.push(`${indent} ${stepIndex + 1}. ${step.agent} ${step.status}${stepModelThinking ? ` | ${stepModelThinking}` : ""}${stepActivity ? ` | ${stepActivity}` : ""}${step.error ? ` | error: ${step.error}` : ""}`);
110
+ lines.push(`${indent} ${stepIndex + 1}. ${step.sessionName?.trim() || step.agent} ${step.status}${stepModelThinking ? ` | ${stepModelThinking}` : ""}${stepActivity ? ` | ${stepActivity}` : ""}${step.error ? ` | error: ${step.error}` : ""}`);
107
111
  append(step.children, depth + 1, `${indent} `);
108
112
  }
109
113
  append(child.children, depth + 1, `${indent} `);