pi-subagents 0.24.4 → 0.27.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 (48) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +145 -27
  3. package/package.json +1 -1
  4. package/prompts/parallel-context-build.md +3 -1
  5. package/prompts/parallel-handoff-plan.md +3 -1
  6. package/prompts/review-loop.md +1 -1
  7. package/skills/pi-subagents/SKILL.md +71 -20
  8. package/src/agents/agent-management.ts +57 -15
  9. package/src/agents/agent-serializer.ts +3 -2
  10. package/src/agents/agents.ts +47 -16
  11. package/src/agents/chain-serializer.ts +120 -0
  12. package/src/extension/fanout-child.ts +171 -0
  13. package/src/extension/index.ts +7 -2
  14. package/src/extension/schemas.ts +138 -5
  15. package/src/intercom/result-intercom.ts +108 -0
  16. package/src/runs/background/async-execution.ts +185 -10
  17. package/src/runs/background/async-job-tracker.ts +41 -6
  18. package/src/runs/background/async-resume.ts +28 -15
  19. package/src/runs/background/async-status.ts +71 -31
  20. package/src/runs/background/result-watcher.ts +111 -54
  21. package/src/runs/background/run-id-resolver.ts +83 -0
  22. package/src/runs/background/run-status.ts +89 -4
  23. package/src/runs/background/stale-run-reconciler.ts +46 -1
  24. package/src/runs/background/subagent-runner.ts +648 -42
  25. package/src/runs/foreground/chain-execution.ts +331 -118
  26. package/src/runs/foreground/execution.ts +226 -10
  27. package/src/runs/foreground/subagent-executor.ts +377 -14
  28. package/src/runs/shared/acceptance-contract.ts +291 -0
  29. package/src/runs/shared/acceptance-evaluation.ts +221 -0
  30. package/src/runs/shared/acceptance-finalization.ts +161 -0
  31. package/src/runs/shared/acceptance-reports.ts +127 -0
  32. package/src/runs/shared/acceptance.ts +22 -0
  33. package/src/runs/shared/chain-outputs.ts +101 -0
  34. package/src/runs/shared/completion-guard.ts +26 -3
  35. package/src/runs/shared/dynamic-fanout.ts +293 -0
  36. package/src/runs/shared/nested-events.ts +819 -0
  37. package/src/runs/shared/nested-path.ts +52 -0
  38. package/src/runs/shared/nested-render.ts +115 -0
  39. package/src/runs/shared/parallel-utils.ts +31 -1
  40. package/src/runs/shared/pi-args.ts +73 -5
  41. package/src/runs/shared/structured-output.ts +77 -0
  42. package/src/runs/shared/subagent-prompt-runtime.ts +77 -7
  43. package/src/runs/shared/workflow-graph.ts +206 -0
  44. package/src/shared/formatters.ts +2 -2
  45. package/src/shared/settings.ts +53 -4
  46. package/src/shared/types.ts +345 -0
  47. package/src/slash/slash-commands.ts +41 -3
  48. package/src/tui/render.ts +268 -43
@@ -1,8 +1,9 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { writeAtomicJson } from "../../shared/atomic-json.ts";
4
- import { RESULTS_DIR, type AsyncParallelGroupStatus, type AsyncStatus, type SubagentRunMode } from "../../shared/types.ts";
4
+ import { RESULTS_DIR, type AsyncParallelGroupStatus, type AsyncStatus, type NestedRunSummary, type SubagentRunMode } from "../../shared/types.ts";
5
5
  import { normalizeParallelGroups } from "./parallel-groups.ts";
6
+ import { nestedSummaryFromAsyncStatus, projectNestedEvents, resolveNestedAsyncDir, writeNestedEvent, type NestedRoute } from "../shared/nested-events.ts";
6
7
 
7
8
  export type PidLiveness = "alive" | "dead" | "unknown";
8
9
 
@@ -233,6 +234,50 @@ function writeFailedRepair(asyncDir: string, status: AsyncStatus, resultPath: st
233
234
  return { status: repair.status, repaired: true, resultPath, message: repair.message };
234
235
  }
235
236
 
237
+ function terminal(state: AsyncStatus["state"]): boolean {
238
+ return state === "complete" || state === "failed" || state === "paused";
239
+ }
240
+
241
+ function* nestedRuns(children: NestedRunSummary[] | undefined): Generator<NestedRunSummary> {
242
+ for (const child of children ?? []) {
243
+ yield child;
244
+ yield* nestedRuns(child.children);
245
+ yield* nestedRuns(child.steps?.flatMap((step) => step.children ?? []));
246
+ }
247
+ }
248
+
249
+ export function reconcileNestedAsyncDescendants(route: NestedRoute, options: ReconcileAsyncRunOptions = {}): void {
250
+ const registry = projectNestedEvents(route);
251
+ for (const run of nestedRuns(registry.children)) {
252
+ if (run.state !== "running" && run.state !== "queued") continue;
253
+ const asyncDir = resolveNestedAsyncDir(route.rootRunId, run);
254
+ if (!asyncDir) continue;
255
+ const result = reconcileAsyncRun(asyncDir, {
256
+ ...options,
257
+ resultsDir: path.join(options.resultsDir ?? RESULTS_DIR, "nested", route.rootRunId),
258
+ });
259
+ const status = result.status;
260
+ if (!status) continue;
261
+ if (!result.repaired && !terminal(status.state)) continue;
262
+ const ts = options.now?.() ?? Date.now();
263
+ writeNestedEvent(route, {
264
+ type: terminal(status.state) ? "subagent.nested.completed" : "subagent.nested.updated",
265
+ ts,
266
+ parentRunId: run.parentRunId,
267
+ parentStepIndex: run.parentStepIndex,
268
+ child: nestedSummaryFromAsyncStatus(status, asyncDir, {
269
+ id: run.id,
270
+ parentRunId: run.parentRunId,
271
+ parentStepIndex: run.parentStepIndex,
272
+ depth: run.depth,
273
+ path: run.path,
274
+ mode: run.mode,
275
+ ts,
276
+ }),
277
+ });
278
+ }
279
+ }
280
+
236
281
  export function checkPidLiveness(pid: number, kill: KillFn = process.kill): PidLiveness {
237
282
  try {
238
283
  kill(pid, 0);