pi-crew 0.9.55 → 0.9.57

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 (309) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +58 -0
  3. package/README.md +53 -5
  4. package/dist/index.mjs +5666 -4370
  5. package/docs/README.md +54 -0
  6. package/package.json +12 -13
  7. package/skills/real-test-pi-crew/SKILL.md +93 -3
  8. package/src/agents/discover-agents.ts +68 -10
  9. package/src/benchmark/feedback-loop.ts +1 -1
  10. package/src/config/config.ts +2 -1
  11. package/src/config/types.ts +12 -0
  12. package/src/extension/action-suggestions.ts +16 -63
  13. package/src/extension/async-notifier.ts +3 -3
  14. package/src/extension/command-completions.ts +2 -2
  15. package/src/extension/crew-cleanup.ts +3 -3
  16. package/src/extension/crew-vibes/footer.ts +4 -2
  17. package/src/extension/cross-extension-rpc.ts +10 -5
  18. package/src/extension/knowledge-injection.ts +57 -10
  19. package/src/extension/register.ts +2 -2
  20. package/src/extension/registration/artifact-cleanup.ts +41 -3
  21. package/src/extension/registration/commands.ts +4 -4
  22. package/src/extension/registration/context-builder.ts +10 -10
  23. package/src/extension/registration/crash-recovery-cache.ts +3 -3
  24. package/src/extension/registration/foreground-run-controller.ts +1 -1
  25. package/src/extension/registration/lazy-configurers.ts +2 -2
  26. package/src/extension/registration/lifecycle-handlers.ts +12 -12
  27. package/src/extension/registration/lifecycle.ts +2 -2
  28. package/src/extension/registration/observability.ts +2 -2
  29. package/src/extension/registration/registration-types.ts +3 -3
  30. package/src/extension/registration/runtime-cleanup.ts +1 -1
  31. package/src/extension/registration/subagent-helpers.ts +2 -2
  32. package/src/extension/registration/subagent-manager-setup.ts +2 -2
  33. package/src/extension/registration/subagent-tools.ts +21 -16
  34. package/src/extension/registration/team-tool.ts +109 -17
  35. package/src/extension/registration/viewers.ts +3 -4
  36. package/src/extension/registration/wire-cross-extension.ts +7 -7
  37. package/src/extension/rpc-hmac.ts +3 -2
  38. package/src/extension/run-bundle-schema.ts +13 -4
  39. package/src/extension/run-export.ts +2 -2
  40. package/src/extension/run-index.ts +2 -3
  41. package/src/extension/run-maintenance.ts +57 -1
  42. package/src/extension/team-manager-command.ts +3 -1
  43. package/src/extension/team-tool/anchor.ts +8 -2
  44. package/src/extension/team-tool/api.ts +117 -39
  45. package/src/extension/team-tool/cancel.ts +23 -8
  46. package/src/extension/team-tool/chain-executor.ts +1 -1
  47. package/src/extension/team-tool/dispatch/automate.ts +17 -2
  48. package/src/extension/team-tool/dispatch/control.ts +17 -2
  49. package/src/extension/team-tool/dispatch/manage.ts +34 -2
  50. package/src/extension/team-tool/dispatch/run.ts +17 -2
  51. package/src/extension/team-tool/dispatch/status.ts +37 -5
  52. package/src/extension/team-tool/doctor.ts +2 -2
  53. package/src/extension/team-tool/explain.ts +1 -1
  54. package/src/extension/team-tool/goal-wrap.ts +5 -5
  55. package/src/extension/team-tool/goal.ts +30 -9
  56. package/src/extension/team-tool/handle-schedule.ts +37 -19
  57. package/src/extension/team-tool/inspect.ts +21 -5
  58. package/src/extension/team-tool/lifecycle-actions.ts +53 -10
  59. package/src/extension/team-tool/parallel-dispatch.ts +14 -5
  60. package/src/extension/team-tool/param-error.ts +138 -0
  61. package/src/extension/team-tool/respond.ts +20 -6
  62. package/src/extension/team-tool/run.ts +27 -17
  63. package/src/extension/team-tool/status.ts +17 -6
  64. package/src/extension/team-tool.ts +26 -19
  65. package/src/hooks/registry.ts +1 -1
  66. package/src/i18n.ts +22 -0
  67. package/src/observability/event-bus.ts +1 -1
  68. package/src/prompt/prompt-runtime.ts +2 -2
  69. package/src/runtime/README.md +35 -0
  70. package/src/runtime/agent-control.ts +1 -1
  71. package/src/runtime/anchor-manager.ts +0 -2
  72. package/src/runtime/async-runner.ts +1 -1
  73. package/src/runtime/attention-events.ts +3 -2
  74. package/src/runtime/auto-summarize.ts +0 -2
  75. package/src/runtime/background-runner.ts +103 -30
  76. package/src/runtime/{crew-broker-child.ts → broker/crew-broker-child.ts} +2 -2
  77. package/src/runtime/{crew-broker-client.ts → broker/crew-broker-client.ts} +4 -7
  78. package/src/runtime/{crew-broker.ts → broker/crew-broker.ts} +13 -21
  79. package/src/runtime/chain-runner.ts +50 -5
  80. package/src/runtime/{child-pi-constants.ts → child-pi/child-pi-constants.ts} +1 -1
  81. package/src/runtime/{child-pi-kill.ts → child-pi/child-pi-kill.ts} +3 -3
  82. package/src/runtime/{child-pi-spawn.ts → child-pi/child-pi-spawn.ts} +28 -12
  83. package/src/runtime/{child-pi-steering.ts → child-pi/child-pi-steering.ts} +1 -1
  84. package/src/runtime/{child-pi-streams.ts → child-pi/child-pi-streams.ts} +23 -4
  85. package/src/runtime/{child-pi-transcript.ts → child-pi/child-pi-transcript.ts} +6 -6
  86. package/src/runtime/{child-pi.ts → child-pi/child-pi.ts} +47 -78
  87. package/src/runtime/compaction/compact-stages/bounded-tail.ts +84 -0
  88. package/src/runtime/{compact-stages → compaction/compact-stages}/index.ts +2 -2
  89. package/src/runtime/{compaction-summary.ts → compaction/compaction-summary.ts} +3 -3
  90. package/src/runtime/{tool-output-pruner.ts → compaction/tool-output-pruner.ts} +1 -1
  91. package/src/runtime/crew-agent-records.ts +48 -2
  92. package/src/runtime/custom-tools/irc-tool.ts +2 -2
  93. package/src/runtime/delivery-coordinator.ts +0 -3
  94. package/src/runtime/diagnostic-export.ts +5 -4
  95. package/src/runtime/foreground-control.ts +1 -1
  96. package/src/runtime/foreground-watchdog.ts +1 -1
  97. package/src/runtime/{adaptive-plan.ts → goal-workflow/adaptive-plan.ts} +8 -8
  98. package/src/runtime/{dynamic-workflow-context.ts → goal-workflow/dynamic-workflow-context.ts} +16 -16
  99. package/src/runtime/{dynamic-workflow-runner.ts → goal-workflow/dynamic-workflow-runner.ts} +10 -10
  100. package/src/runtime/{goal-achievement.ts → goal-workflow/goal-achievement.ts} +3 -3
  101. package/src/runtime/{goal-evaluator.ts → goal-workflow/goal-evaluator.ts} +8 -8
  102. package/src/runtime/{goal-loop-runner.ts → goal-workflow/goal-loop-runner.ts} +27 -25
  103. package/src/runtime/{goal-state-store.ts → goal-workflow/goal-state-store.ts} +8 -8
  104. package/src/runtime/{plan-templates.ts → goal-workflow/plan-templates.ts} +1 -1
  105. package/src/runtime/group-join.ts +3 -3
  106. package/src/runtime/handoff-manager.ts +0 -2
  107. package/src/runtime/{heartbeat-watcher.ts → heartbeat/heartbeat-watcher.ts} +7 -7
  108. package/src/runtime/iteration-hooks.ts +1 -1
  109. package/src/runtime/{live-agent-control.ts → live-session/live-agent-control.ts} +2 -2
  110. package/src/runtime/{live-agent-manager.ts → live-session/live-agent-manager.ts} +4 -4
  111. package/src/runtime/{live-session-runtime.ts → live-session/live-session-runtime.ts} +39 -41
  112. package/src/runtime/manifest-cache.ts +6 -2
  113. package/src/runtime/{model-fallback.ts → model/model-fallback.ts} +1 -1
  114. package/src/runtime/{pi-args.ts → model/pi-args.ts} +20 -5
  115. package/src/runtime/model/provider-extensions.ts +116 -0
  116. package/src/runtime/{runtime-policy.ts → model/runtime-policy.ts} +2 -2
  117. package/src/runtime/{runtime-resolver.ts → model/runtime-resolver.ts} +3 -3
  118. package/src/runtime/{runtime-warmup.ts → model/runtime-warmup.ts} +8 -8
  119. package/src/runtime/orphan-worker-registry.ts +1 -1
  120. package/src/runtime/{progress-tracker.ts → output/progress-tracker.ts} +1 -1
  121. package/src/runtime/{result-extractor.ts → output/result-extractor.ts} +4 -4
  122. package/src/runtime/{sidechain-output.ts → output/sidechain-output.ts} +2 -2
  123. package/src/runtime/{stream-preview.ts → output/stream-preview.ts} +1 -1
  124. package/src/runtime/{streaming-output.ts → output/streaming-output.ts} +2 -2
  125. package/src/runtime/{tool-progress.ts → output/tool-progress.ts} +1 -1
  126. package/src/runtime/parent-guard.ts +30 -10
  127. package/src/runtime/pipeline-runner.ts +2 -2
  128. package/src/runtime/policy-engine.ts +2 -2
  129. package/src/runtime/{cancellation.ts → process/cancellation.ts} +1 -1
  130. package/src/runtime/{post-exit-stdio-guard.ts → process/post-exit-stdio-guard.ts} +1 -1
  131. package/src/runtime/{process-lifecycle.ts → process/process-lifecycle.ts} +3 -3
  132. package/src/runtime/{checkpoint.ts → recovery/checkpoint.ts} +4 -4
  133. package/src/runtime/{crash-recovery.ts → recovery/crash-recovery.ts} +93 -21
  134. package/src/runtime/{overflow-recovery.ts → recovery/overflow-recovery.ts} +1 -1
  135. package/src/runtime/{recovery-recipes.ts → recovery/recovery-recipes.ts} +1 -1
  136. package/src/runtime/{retry-executor.ts → recovery/retry-executor.ts} +2 -2
  137. package/src/runtime/{retry-runner.ts → recovery/retry-runner.ts} +2 -8
  138. package/src/runtime/run-tracker.ts +1 -1
  139. package/src/runtime/run-worker.ts +3 -3
  140. package/src/runtime/{coalesce-tasks.ts → scheduling/coalesce-tasks.ts} +3 -3
  141. package/src/runtime/{concurrency.ts → scheduling/concurrency.ts} +9 -3
  142. package/src/runtime/{parallel-research.ts → scheduling/parallel-research.ts} +4 -2
  143. package/src/runtime/{run-coalesced-task-group.ts → scheduling/run-coalesced-task-group.ts} +95 -36
  144. package/src/runtime/{semaphore.ts → scheduling/semaphore.ts} +4 -1
  145. package/src/runtime/{task-graph-scheduler.ts → scheduling/task-graph-scheduler.ts} +1 -1
  146. package/src/runtime/session-resources.ts +1 -1
  147. package/src/runtime/settings-store.ts +1 -1
  148. package/src/runtime/single-agent-compose.ts +1 -0
  149. package/src/runtime/stale-reconciler.ts +1 -1
  150. package/src/runtime/subagent-manager.ts +1 -1
  151. package/src/runtime/supervisor-contact.ts +28 -13
  152. package/src/runtime/task-output-context.ts +7 -5
  153. package/src/runtime/task-runner/child-executor.ts +67 -31
  154. package/src/runtime/task-runner/live-executor.ts +8 -8
  155. package/src/runtime/task-runner/post-execution.ts +12 -12
  156. package/src/runtime/task-runner/pre-execution.ts +6 -6
  157. package/src/runtime/task-runner/progress.ts +1 -1
  158. package/src/runtime/task-runner/run-projection.ts +1 -1
  159. package/src/runtime/task-runner/scaffold-executor.ts +1 -1
  160. package/src/runtime/task-runner/state-helpers.ts +2 -2
  161. package/src/runtime/task-runner.ts +4 -4
  162. package/src/runtime/team-runner.ts +441 -175
  163. package/src/runtime/{completion-guard.ts → verification/completion-guard.ts} +1 -1
  164. package/src/runtime/{green-contract.ts → verification/green-contract.ts} +1 -1
  165. package/src/runtime/{post-checks.ts → verification/post-checks.ts} +4 -4
  166. package/src/runtime/{verification-gates.ts → verification/verification-gates.ts} +5 -5
  167. package/src/runtime/{verification-integrity.ts → verification/verification-integrity.ts} +1 -1
  168. package/src/schema/config-schema.ts +1 -0
  169. package/src/schema/team-tool-schema.ts +149 -185
  170. package/src/state/README.md +44 -0
  171. package/src/state/atomic-write.ts +24 -3
  172. package/src/state/{locks.ts → coordination/locks.ts} +118 -38
  173. package/src/state/{mailbox.ts → coordination/mailbox.ts} +14 -8
  174. package/src/state/{schedule.ts → coordination/schedule.ts} +3 -3
  175. package/src/state/{task-claims.ts → coordination/task-claims.ts} +1 -1
  176. package/src/state/decision-ledger.ts +1 -1
  177. package/src/state/{event-log-rotation.ts → event-log/event-log-rotation.ts} +189 -31
  178. package/src/state/{event-log.ts → event-log/event-log.ts} +77 -39
  179. package/src/state/{jsonl-writer.ts → event-log/jsonl-writer.ts} +14 -6
  180. package/src/state/hook-instinct-bridge.ts +2 -2
  181. package/src/state/{active-run-registry.ts → stores/active-run-registry.ts} +7 -7
  182. package/src/state/{artifact-store.ts → stores/artifact-store.ts} +62 -4
  183. package/src/state/{blob-store.ts → stores/blob-store.ts} +3 -3
  184. package/src/state/{health-store.ts → stores/health-store.ts} +3 -3
  185. package/src/state/{instinct-store.ts → stores/instinct-store.ts} +3 -3
  186. package/src/state/{observation-store.ts → stores/observation-store.ts} +2 -2
  187. package/src/state/{run-cache.ts → stores/run-cache.ts} +4 -4
  188. package/src/state/{run-graph.ts → stores/run-graph.ts} +4 -4
  189. package/src/state/{run-metrics.ts → stores/run-metrics.ts} +3 -3
  190. package/src/state/{state-store.ts → stores/state-store.ts} +254 -21
  191. package/src/state/types.ts +27 -3
  192. package/src/ui/component.ts +55 -0
  193. package/src/ui/crew-select-list.ts +3 -1
  194. package/src/ui/dashboard-panes/agents-pane.ts +1 -1
  195. package/src/ui/dwf-phase-display.ts +1 -1
  196. package/src/ui/heartbeat-aggregator.ts +1 -1
  197. package/src/ui/keybinding-map.ts +179 -6
  198. package/src/ui/layout-primitives.ts +9 -5
  199. package/src/ui/live-conversation-overlay.ts +1 -1
  200. package/src/ui/live-run-sidebar.ts +1 -1
  201. package/src/ui/overlay-stack.ts +148 -0
  202. package/src/ui/overlays/agent-picker-overlay.ts +1 -1
  203. package/src/ui/overlays/mailbox-compose-overlay.ts +1 -1
  204. package/src/ui/overlays/mailbox-detail-overlay.ts +2 -2
  205. package/src/ui/powerbar-publisher.ts +1 -1
  206. package/src/ui/render-scheduler.ts +1 -1
  207. package/src/ui/run-action-dispatcher.ts +3 -3
  208. package/src/ui/run-dashboard.ts +5 -33
  209. package/src/ui/run-event-bus.ts +3 -3
  210. package/src/ui/run-snapshot-cache.ts +37 -18
  211. package/src/ui/settings-overlay.ts +13 -21
  212. package/src/ui/snapshot-types.ts +1 -1
  213. package/src/ui/status-colors.ts +0 -2
  214. package/src/ui/terminal-status.ts +1 -1
  215. package/src/ui/theme-adapter.ts +33 -13
  216. package/src/ui/tool-renderers/index.ts +8 -0
  217. package/src/ui/transcript-viewer.ts +37 -13
  218. package/src/ui/widget/index.ts +32 -9
  219. package/src/ui/widget/widget-formatters.ts +62 -4
  220. package/src/ui/widget/widget-model.ts +2 -2
  221. package/src/ui/widget/widget-renderer.ts +1 -1
  222. package/src/utils/conflict-detect.ts +58 -5
  223. package/src/utils/ndjson.ts +2 -2
  224. package/src/utils/redaction.ts +39 -0
  225. package/src/utils/socket-path.ts +1 -1
  226. package/src/workflows/workflow-config.ts +1 -1
  227. package/src/worktree/cleanup.ts +1 -1
  228. package/src/worktree/worktree-manager.ts +111 -47
  229. package/workflows/chain.workflow.md +2 -2
  230. package/dist/build-meta.json +0 -16807
  231. package/index.bundle.ts +0 -25
  232. package/scripts/bench-check.mjs +0 -96
  233. package/scripts/bench-cold-start.mjs +0 -216
  234. package/scripts/build-bundle.mjs +0 -92
  235. package/scripts/check-all-skills.ts +0 -294
  236. package/scripts/check-bundle-size.mjs +0 -38
  237. package/scripts/check-bundle-staleness.mjs +0 -97
  238. package/scripts/check-conflict-markers.mjs +0 -91
  239. package/scripts/check-lazy-imports.mjs +0 -28
  240. package/scripts/dev-runner.mjs +0 -106
  241. package/scripts/profile-startup.mjs +0 -125
  242. package/scripts/release-smoke.mjs +0 -74
  243. package/scripts/run-bench.mjs +0 -47
  244. package/scripts/run-real-chain.ts +0 -41
  245. package/scripts/test-issue-29-crash.ts +0 -111
  246. package/scripts/test-issue-29-e2e.ts +0 -183
  247. package/scripts/test-issue-29-real-runtime.ts +0 -330
  248. package/scripts/test-issue-29-real-tasks.ts +0 -387
  249. package/scripts/test-issue-29-team-tool.ts +0 -105
  250. package/scripts/test-runner.mjs +0 -84
  251. package/scripts/verify-flicker-fix.ts +0 -109
  252. package/scripts/verify-skill.ts +0 -550
  253. package/scripts/watch-bundle.mjs +0 -259
  254. package/scripts/watchdog-harness.ts +0 -119
  255. package/src/adapters/claude-adapter.ts +0 -23
  256. package/src/adapters/codex-adapter.ts +0 -21
  257. package/src/adapters/cursor-adapter.ts +0 -17
  258. package/src/adapters/export-util.ts +0 -143
  259. package/src/adapters/index.ts +0 -15
  260. package/src/adapters/registry.ts +0 -18
  261. package/src/adapters/types.ts +0 -23
  262. package/src/runtime/code-summary.ts +0 -292
  263. package/src/runtime/cross-extension-rpc.ts +0 -143
  264. package/src/runtime/hidden-handoff.ts +0 -407
  265. package/src/runtime/prose-compressor.ts +0 -162
  266. package/src/subagents/async-entry.ts +0 -1
  267. package/src/subagents/index.ts +0 -3
  268. package/src/subagents/live/control.ts +0 -1
  269. package/src/subagents/live/manager.ts +0 -1
  270. package/src/subagents/live/realtime.ts +0 -1
  271. package/src/subagents/live/session-runtime.ts +0 -1
  272. package/src/subagents/manager.ts +0 -1
  273. package/src/subagents/spawn.ts +0 -1
  274. package/test-integration-check.ts +0 -118
  275. /package/src/runtime/{broker-issuer.ts → broker/broker-issuer.ts} +0 -0
  276. /package/src/runtime/{crew-broker-tokens.ts → broker/crew-broker-tokens.ts} +0 -0
  277. /package/src/runtime/{child-pi-pool.ts → child-pi/child-pi-pool.ts} +0 -0
  278. /package/src/runtime/{compact-pipeline.ts → compaction/compact-pipeline.ts} +0 -0
  279. /package/src/runtime/{compact-stages → compaction/compact-stages}/ansi-strip-stage.ts +0 -0
  280. /package/src/runtime/{compact-stages → compaction/compact-stages}/blank-collapse-stage.ts +0 -0
  281. /package/src/runtime/{compact-stages → compaction/compact-stages}/deduplicate-stage.ts +0 -0
  282. /package/src/runtime/{compact-stages → compaction/compact-stages}/head-snap-stage.ts +0 -0
  283. /package/src/runtime/{compact-stages → compaction/compact-stages}/tail-capture-stage.ts +0 -0
  284. /package/src/runtime/{compact-stages → compaction/compact-stages}/truncation-stage.ts +0 -0
  285. /package/src/runtime/{important-line-classifier.ts → compaction/important-line-classifier.ts} +0 -0
  286. /package/src/runtime/{heartbeat-gradient.ts → heartbeat/heartbeat-gradient.ts} +0 -0
  287. /package/src/runtime/{worker-heartbeat.ts → heartbeat/worker-heartbeat.ts} +0 -0
  288. /package/src/runtime/{worker-startup.ts → heartbeat/worker-startup.ts} +0 -0
  289. /package/src/runtime/{intercom-bridge.ts → live-session/intercom-bridge.ts} +0 -0
  290. /package/src/runtime/{live-control-realtime.ts → live-session/live-control-realtime.ts} +0 -0
  291. /package/src/runtime/{live-extension-bridge.ts → live-session/live-extension-bridge.ts} +0 -0
  292. /package/src/runtime/{live-irc.ts → live-session/live-irc.ts} +0 -0
  293. /package/src/runtime/{live-session-health.ts → live-session/live-session-health.ts} +0 -0
  294. /package/src/runtime/{model-resolver.ts → model/model-resolver.ts} +0 -0
  295. /package/src/runtime/{model-scope.ts → model/model-scope.ts} +0 -0
  296. /package/src/runtime/{output-validator.ts → output/output-validator.ts} +0 -0
  297. /package/src/runtime/{pi-json-output.ts → output/pi-json-output.ts} +0 -0
  298. /package/src/runtime/{progress-event-coalescer.ts → output/progress-event-coalescer.ts} +0 -0
  299. /package/src/runtime/{cancellation-token.ts → process/cancellation-token.ts} +0 -0
  300. /package/src/runtime/{zombie-scanner.ts → process/zombie-scanner.ts} +0 -0
  301. /package/src/runtime/{crash-classification.ts → recovery/crash-classification.ts} +0 -0
  302. /package/src/runtime/{batch-barrier.ts → scheduling/batch-barrier.ts} +0 -0
  303. /package/src/runtime/{global-worker-cap.ts → scheduling/global-worker-cap.ts} +0 -0
  304. /package/src/runtime/{parallel-utils.ts → scheduling/parallel-utils.ts} +0 -0
  305. /package/src/runtime/{scheduler.ts → scheduling/scheduler.ts} +0 -0
  306. /package/src/runtime/{task-graph.ts → scheduling/task-graph.ts} +0 -0
  307. /package/src/runtime/{verification-worktree.ts → verification/verification-worktree.ts} +0 -0
  308. /package/src/state/{event-reconstructor.ts → event-log/event-reconstructor.ts} +0 -0
  309. /package/src/state/{worker-atomic-writer.ts → event-log/worker-atomic-writer.ts} +0 -0
@@ -4,14 +4,24 @@ import { buildAgentDashboard, readAgentOutput } from "../../runtime/agent-observ
4
4
  import { buildCapabilityInventory } from "../../runtime/capability-inventory.ts";
5
5
  import { agentOutputPath, readCrewAgentEventsCursor, readCrewAgentStatus, readCrewAgents } from "../../runtime/crew-agent-records.ts";
6
6
  import { readForegroundControlStatus, writeForegroundInterruptRequest } from "../../runtime/foreground-control.ts";
7
- import { terminateLiveAgentsForRun } from "../../runtime/live-agent-manager.ts";
7
+ import { touchWorkerHeartbeat } from "../../runtime/heartbeat/worker-heartbeat.ts";
8
+ import { appendLiveAgentControlRequest } from "../../runtime/live-session/live-agent-control.ts";
9
+ import {
10
+ followUpLiveAgent,
11
+ getLiveAgent,
12
+ listActiveLiveAgents,
13
+ resumeLiveAgent,
14
+ steerLiveAgent,
15
+ stopLiveAgent,
16
+ terminateLiveAgentsForRun,
17
+ } from "../../runtime/live-session/live-agent-manager.ts";
18
+ import { liveControlRealtimeMessage, publishLiveControlRealtime } from "../../runtime/live-session/live-control-realtime.ts";
19
+ import { probeLiveSessionRuntime } from "../../runtime/live-session/live-session-runtime.ts";
20
+ import { resolveCrewRuntime } from "../../runtime/model/runtime-resolver.ts";
8
21
  import { currentCrewRole, permissionForRole } from "../../runtime/role-permission.ts";
9
- import { resolveCrewRuntime } from "../../runtime/runtime-resolver.ts";
10
- import { touchWorkerHeartbeat } from "../../runtime/worker-heartbeat.ts";
11
22
  import type { TeamToolParamsValue } from "../../schema/team-tool-schema.ts";
12
23
  import { canTransitionTaskStatus, isTeamTaskStatus } from "../../state/contracts.ts";
13
- import { appendEvent, readEvents, readEventsCursor } from "../../state/event-log.ts";
14
- import { withRunLock, withRunLockSync } from "../../state/locks.ts";
24
+ import { withRunLock, withRunLockSync } from "../../state/coordination/locks.ts";
15
25
  import {
16
26
  acknowledgeMailboxMessage,
17
27
  appendFollowUpMessage,
@@ -25,25 +35,16 @@ import {
25
35
  readMailbox,
26
36
  readMailboxMessage,
27
37
  validateMailbox,
28
- } from "../../state/mailbox.ts";
29
- import { loadRunManifestById, saveRunManifestAsync, saveRunTasks, updateRunStatus } from "../../state/state-store.ts";
30
- import { claimTask, releaseTaskClaim, transitionClaimedTaskStatus } from "../../state/task-claims.ts";
31
- import { appendLiveAgentControlRequest } from "../../subagents/live/control.ts";
32
- import {
33
- followUpLiveAgent,
34
- getLiveAgent,
35
- listActiveLiveAgents,
36
- resumeLiveAgent,
37
- steerLiveAgent,
38
- stopLiveAgent,
39
- } from "../../subagents/live/manager.ts";
40
- import { liveControlRealtimeMessage, publishLiveControlRealtime } from "../../subagents/live/realtime.ts";
41
- import { probeLiveSessionRuntime } from "../../subagents/live/session-runtime.ts";
38
+ } from "../../state/coordination/mailbox.ts";
39
+ import { claimTask, releaseTaskClaim, transitionClaimedTaskStatus } from "../../state/coordination/task-claims.ts";
40
+ import { appendEvent, readEvents, readEventsCursor } from "../../state/event-log/event-log.ts";
41
+ import { loadRunManifestById, saveRunManifestAsync, saveRunTasks, updateRunStatus } from "../../state/stores/state-store.ts";
42
42
  import { logInternalError } from "../../utils/internal-error.ts";
43
43
  import { resolveRealContainedPath } from "../../utils/safe-paths.ts";
44
44
  import { locateRunCwd } from "../team-tool.ts";
45
45
  import type { PiTeamsToolResult } from "../tool-result.ts";
46
46
  import { configRecord, result, type TeamContext } from "./context.ts";
47
+ import { paramRequired } from "./param-error.ts";
47
48
  import { RUN_NOT_FOUND_HINT } from "./run-not-found.ts";
48
49
 
49
50
  export function globMatch(value: string, pattern: string): boolean {
@@ -121,7 +122,8 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
121
122
  status: "ok",
122
123
  });
123
124
  }
124
- if (!params.runId) return result("API requires runId.", { action: "api", status: "error" }, true);
125
+ if (!params.runId)
126
+ return result(paramRequired("api", "runId", "{ action: 'api', runId: 'team_...' }"), { action: "api", status: "error" }, true);
125
127
  const runCwd = locateRunCwd(params.runId, ctx.cwd);
126
128
  if (!runCwd) return result(`Run '${params.runId}' not found.${RUN_NOT_FOUND_HINT}`, { action: "api", status: "error" }, true);
127
129
  const loaded = loadRunManifestById(runCwd, params.runId); // NOTE: no withRunLock - best-effort only; concurrent writes may cause inconsistency
@@ -302,7 +304,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
302
304
  const task = loaded.tasks.find((item) => item.id === taskId || item.stepId === taskId);
303
305
  if (!task)
304
306
  return result(
305
- "API read-task requires config.taskId matching a task id or step id.",
307
+ paramRequired(
308
+ "API read-task",
309
+ "config.taskId matching a task id or step id",
310
+ "{ action: 'api', runId: 'team_...', config: { operation: 'read-task', taskId: '01_01-agent' } }",
311
+ ),
306
312
  {
307
313
  action: "api",
308
314
  status: "error",
@@ -368,7 +374,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
368
374
  const agent = readCrewAgents(loaded.manifest).find((item) => item.id === agentId || item.taskId === agentId);
369
375
  if (!agent)
370
376
  return result(
371
- "API get-agent-result requires config.agentId matching an agent id or task id.",
377
+ paramRequired(
378
+ "API get-agent-result",
379
+ "config.agentId matching an agent id or task id",
380
+ "{ action: 'api', runId: 'team_...', config: { operation: 'get-agent-result', agentId: 'agent-1' } }",
381
+ ),
372
382
  {
373
383
  action: "api",
374
384
  status: "error",
@@ -391,7 +401,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
391
401
  const status = agent ? (readCrewAgentStatus(loaded.manifest, agent.taskId) ?? agent) : undefined;
392
402
  if (!status)
393
403
  return result(
394
- "API read-agent-status requires config.agentId matching an agent id or task id.",
404
+ paramRequired(
405
+ "API read-agent-status",
406
+ "config.agentId matching an agent id or task id",
407
+ "{ action: 'api', runId: 'team_...', config: { operation: 'read-agent-status', agentId: 'agent-1' } }",
408
+ ),
395
409
  {
396
410
  action: "api",
397
411
  status: "error",
@@ -412,7 +426,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
412
426
  const agent = agentId ? agents.find((item) => item.id === agentId || item.taskId === agentId) : agents[0];
413
427
  if (!agent)
414
428
  return result(
415
- "API read-agent-events requires config.agentId matching an agent id or task id, or at least one agent in the run.",
429
+ paramRequired(
430
+ "API read-agent-events",
431
+ "config.agentId matching an agent id or task id, or at least one agent in the run",
432
+ "{ action: 'api', runId: 'team_...', config: { operation: 'read-agent-events', agentId: 'agent-1' } }",
433
+ ),
416
434
  {
417
435
  action: "api",
418
436
  status: "error",
@@ -438,7 +456,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
438
456
  const agent = agentId ? agents.find((item) => item.id === agentId || item.taskId === agentId) : agents[0];
439
457
  if (!agent)
440
458
  return result(
441
- "API read-agent-transcript requires config.agentId matching an agent id or task id, or at least one agent in the run.",
459
+ paramRequired(
460
+ "API read-agent-transcript",
461
+ "config.agentId matching an agent id or task id, or at least one agent in the run",
462
+ "{ action: 'api', runId: 'team_...', config: { operation: 'read-agent-transcript', agentId: 'agent-1' } }",
463
+ ),
442
464
  {
443
465
  action: "api",
444
466
  status: "error",
@@ -467,7 +489,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
467
489
  const agent = agentId ? agents.find((item) => item.id === agentId || item.taskId === agentId) : agents[0];
468
490
  if (!agent)
469
491
  return result(
470
- "API read-agent-output requires config.agentId matching an agent id or task id, or at least one agent in the run.",
492
+ paramRequired(
493
+ "API read-agent-output",
494
+ "config.agentId matching an agent id or task id, or at least one agent in the run",
495
+ "{ action: 'api', runId: 'team_...', config: { operation: 'read-agent-output', agentId: 'agent-1' } }",
496
+ ),
471
497
  {
472
498
  action: "api",
473
499
  status: "error",
@@ -513,7 +539,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
513
539
  const agent = readCrewAgents(loaded.manifest).find((item) => item.id === agentId || item.taskId === agentId);
514
540
  if (!agent)
515
541
  return result(
516
- "API nudge-agent requires config.agentId matching an agent id or task id.",
542
+ paramRequired(
543
+ "API nudge-agent",
544
+ "config.agentId matching an agent id or task id",
545
+ "{ action: 'api', runId: 'team_...', config: { operation: 'nudge-agent', agentId: 'agent-1' } }",
546
+ ),
517
547
  {
518
548
  action: "api",
519
549
  status: "error",
@@ -580,7 +610,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
580
610
  const agentId = typeof cfg.agentId === "string" ? cfg.agentId : undefined;
581
611
  if (!agentId)
582
612
  return result(
583
- `API ${operation} requires config.agentId.`,
613
+ paramRequired(
614
+ `API ${operation}`,
615
+ "config.agentId",
616
+ `{ action: 'api', runId: 'team_...', config: { operation: '${operation}', agentId: 'agent-1' } }`,
617
+ ),
584
618
  {
585
619
  action: "api",
586
620
  status: "error",
@@ -637,7 +671,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
637
671
  if (operation === "follow-up-agent") {
638
672
  if (!prompt)
639
673
  return result(
640
- "API follow-up-agent requires config.prompt or config.message.",
674
+ paramRequired(
675
+ "API follow-up-agent",
676
+ "config.prompt or config.message",
677
+ "{ action: 'api', runId: 'team_...', config: { operation: 'follow-up-agent', agentId: 'agent-1', prompt: '<next step>' } }",
678
+ ),
641
679
  {
642
680
  action: "api",
643
681
  status: "error",
@@ -662,7 +700,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
662
700
  if (operation === "resume-agent") {
663
701
  if (!prompt)
664
702
  return result(
665
- "API resume-agent requires config.prompt or config.message.",
703
+ paramRequired(
704
+ "API resume-agent",
705
+ "config.prompt or config.message",
706
+ "{ action: 'api', runId: 'team_...', config: { operation: 'resume-agent', agentId: 'agent-1', prompt: '<resume instruction>' } }",
707
+ ),
666
708
  {
667
709
  action: "api",
668
710
  status: "error",
@@ -710,7 +752,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
710
752
  );
711
753
  if (operation === "resume-agent" && !prompt)
712
754
  return result(
713
- "API resume-agent requires config.prompt or config.message.",
755
+ paramRequired(
756
+ "API resume-agent",
757
+ "config.prompt or config.message",
758
+ "{ action: 'api', runId: 'team_...', config: { operation: 'resume-agent', agentId: 'agent-1', prompt: '<resume instruction>' } }",
759
+ ),
714
760
  {
715
761
  action: "api",
716
762
  status: "error",
@@ -720,7 +766,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
720
766
  );
721
767
  if (operation === "follow-up-agent" && !prompt)
722
768
  return result(
723
- "API follow-up-agent requires config.prompt or config.message.",
769
+ paramRequired(
770
+ "API follow-up-agent",
771
+ "config.prompt or config.message",
772
+ "{ action: 'api', runId: 'team_...', config: { operation: 'follow-up-agent', agentId: 'agent-1', prompt: '<next step>' } }",
773
+ ),
724
774
  {
725
775
  action: "api",
726
776
  status: "error",
@@ -867,7 +917,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
867
917
  const taskId = typeof cfg.taskId === "string" && cfg.taskId.trim() ? cfg.taskId.trim() : undefined;
868
918
  if (!body)
869
919
  return result(
870
- "API send-message requires config.body.",
920
+ paramRequired(
921
+ "API send-message",
922
+ "config.body",
923
+ "{ action: 'api', runId: 'team_...', config: { operation: 'send-message', body: '<message>' } }",
924
+ ),
871
925
  {
872
926
  action: "api",
873
927
  status: "error",
@@ -932,7 +986,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
932
986
  const messageId = typeof cfg.messageId === "string" ? cfg.messageId : undefined;
933
987
  if (!messageId)
934
988
  return result(
935
- "API ack-message requires config.messageId.",
989
+ paramRequired(
990
+ "API ack-message",
991
+ "config.messageId",
992
+ "{ action: 'api', runId: 'team_...', config: { operation: 'ack-message', messageId: 'msg-1' } }",
993
+ ),
936
994
  {
937
995
  action: "api",
938
996
  status: "error",
@@ -995,7 +1053,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
995
1053
  const task = loaded.tasks.find((item) => item.id === taskId || item.stepId === taskId);
996
1054
  if (!task)
997
1055
  return result(
998
- "API read-heartbeat requires config.taskId matching a task id or step id.",
1056
+ paramRequired(
1057
+ "API read-heartbeat",
1058
+ "config.taskId matching a task id or step id",
1059
+ "{ action: 'api', runId: 'team_...', config: { operation: 'read-heartbeat', taskId: '01_01-agent' } }",
1060
+ ),
999
1061
  {
1000
1062
  action: "api",
1001
1063
  status: "error",
@@ -1016,7 +1078,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
1016
1078
  const task = loaded.tasks.find((item) => item.id === taskId || item.stepId === taskId);
1017
1079
  if (!task)
1018
1080
  return result(
1019
- "API claim-task requires config.taskId matching a task id or step id.",
1081
+ paramRequired(
1082
+ "API claim-task",
1083
+ "config.taskId matching a task id or step id",
1084
+ "{ action: 'api', runId: 'team_...', config: { operation: 'claim-task', taskId: '01_01-agent' } }",
1085
+ ),
1020
1086
  {
1021
1087
  action: "api",
1022
1088
  status: "error",
@@ -1066,7 +1132,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
1066
1132
  const task = loaded.tasks.find((item) => item.id === taskId || item.stepId === taskId);
1067
1133
  if (!task || !owner || !token)
1068
1134
  return result(
1069
- "API release-task-claim requires config.taskId, config.owner, and config.token.",
1135
+ paramRequired(
1136
+ "API release-task-claim",
1137
+ "config.taskId, config.owner, and config.token",
1138
+ "{ action: 'api', runId: 'team_...', config: { operation: 'release-task-claim', taskId: '01_01-agent', owner: 'worker-1', token: 'tok-1' } }",
1139
+ ),
1070
1140
  {
1071
1141
  action: "api",
1072
1142
  status: "error",
@@ -1113,7 +1183,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
1113
1183
  const task = loaded.tasks.find((item) => item.id === taskId || item.stepId === taskId);
1114
1184
  if (!task || !owner || !token || !isTeamTaskStatus(to))
1115
1185
  return result(
1116
- "API transition-task-status requires config.taskId, config.owner, config.token, and valid config.status.",
1186
+ paramRequired(
1187
+ "API transition-task-status",
1188
+ "config.taskId, config.owner, config.token, and valid config.status",
1189
+ "{ action: 'api', runId: 'team_...', config: { operation: 'transition-task-status', taskId: '01_01-agent', owner: 'worker-1', token: 'tok-1', status: 'done' } }",
1190
+ ),
1117
1191
  {
1118
1192
  action: "api",
1119
1193
  status: "error",
@@ -1167,7 +1241,11 @@ export async function handleApi(params: TeamToolParamsValue, ctx: TeamContext):
1167
1241
  const task = loaded.tasks.find((item) => item.id === taskId || item.stepId === taskId);
1168
1242
  if (!task)
1169
1243
  return result(
1170
- "API write-heartbeat requires config.taskId matching a task id or step id.",
1244
+ paramRequired(
1245
+ "API write-heartbeat",
1246
+ "config.taskId matching a task id or step id",
1247
+ "{ action: 'api', runId: 'team_...', config: { operation: 'write-heartbeat', taskId: '01_01-agent' } }",
1248
+ ),
1171
1249
  {
1172
1250
  action: "api",
1173
1251
  status: "error",
@@ -1,19 +1,24 @@
1
1
  import { appendHookEvent, executeHook } from "../../hooks/registry.ts";
2
- import { buildSyntheticTerminalEvidence, type CancellationReason, cancellationReasonFromUnknown } from "../../runtime/cancellation.ts";
3
- import { killProcessPid } from "../../runtime/child-pi.ts";
2
+ import { killProcessPid } from "../../runtime/child-pi/child-pi.ts";
4
3
  import { recordFromTask, saveCrewAgents } from "../../runtime/crew-agent-records.ts";
5
4
  import { writeForegroundInterruptRequest } from "../../runtime/foreground-control.ts";
6
- import { terminateLiveAgentsForRun } from "../../runtime/live-agent-manager.ts";
5
+ import { terminateLiveAgentsForRun } from "../../runtime/live-session/live-agent-manager.ts";
6
+ import {
7
+ buildSyntheticTerminalEvidence,
8
+ type CancellationReason,
9
+ cancellationReasonFromUnknown,
10
+ } from "../../runtime/process/cancellation.ts";
7
11
  import type { TeamToolParamsValue } from "../../schema/team-tool-schema.ts";
8
- import { appendEvent } from "../../state/event-log.ts";
9
- import { withRunLockSync } from "../../state/locks.ts";
10
- import { loadRunManifestById, saveRunTasks, updateRunStatus } from "../../state/state-store.ts";
12
+ import { withRunLockSync } from "../../state/coordination/locks.ts";
13
+ import { appendEvent } from "../../state/event-log/event-log.ts";
14
+ import { loadRunManifestById, saveRunTasks, updateRunStatus } from "../../state/stores/state-store.ts";
11
15
  import { logInternalError } from "../../utils/internal-error.ts";
12
16
  import { locateRunCwd } from "../team-tool.ts";
13
17
  import type { PiTeamsToolResult } from "../tool-result.ts";
14
18
  import { type CacheControlDeps, invalidateSnapshot } from "./cache-control.ts";
15
19
  import { result, type TeamContext } from "./context.ts";
16
20
  import { enforceDestructiveIntent, intentFromConfig } from "./intent-policy.ts";
21
+ import { paramRequired } from "./param-error.ts";
17
22
  import { RUN_NOT_FOUND_HINT } from "./run-not-found.ts";
18
23
 
19
24
  export interface AbortOwnedResult {
@@ -84,7 +89,12 @@ function cancelReasonFromParams(params: TeamToolParamsValue): CancellationReason
84
89
  }
85
90
 
86
91
  export async function handleRetry(params: TeamToolParamsValue, ctx: TeamContext, deps?: CacheControlDeps): Promise<PiTeamsToolResult> {
87
- if (!params.runId) return result("Retry requires runId.", { action: "retry", status: "error" }, true);
92
+ if (!params.runId)
93
+ return result(
94
+ paramRequired("retry", "runId", "{ action: 'retry', runId: 'team_...' }"),
95
+ { action: "retry", status: "error" },
96
+ true,
97
+ );
88
98
  const runCwd = locateRunCwd(params.runId, ctx.cwd);
89
99
  if (!runCwd) return result(`Run '${params.runId}' not found.${RUN_NOT_FOUND_HINT}`, { action: "retry", status: "error" }, true);
90
100
  const loaded = loadRunManifestById(runCwd, params.runId); // NOTE: no withRunLock - best-effort only; concurrent writes may cause inconsistency
@@ -176,7 +186,12 @@ export async function handleRetry(params: TeamToolParamsValue, ctx: TeamContext,
176
186
  export async function handleCancel(params: TeamToolParamsValue, ctx: TeamContext, deps?: CacheControlDeps): Promise<PiTeamsToolResult> {
177
187
  const intentError = enforceDestructiveIntent("cancel", params, ctx.config);
178
188
  if (intentError) return intentError;
179
- if (!params.runId) return result("Cancel requires runId.", { action: "cancel", status: "error" }, true);
189
+ if (!params.runId)
190
+ return result(
191
+ paramRequired("cancel", "runId", "{ action: 'cancel', runId: 'team_...' }"),
192
+ { action: "cancel", status: "error" },
193
+ true,
194
+ );
180
195
  const runCwd = locateRunCwd(params.runId, ctx.cwd);
181
196
  if (!runCwd) return result(`Run '${params.runId}' not found.${RUN_NOT_FOUND_HINT}`, { action: "cancel", status: "error" }, true);
182
197
  const loaded = loadRunManifestById(runCwd, params.runId); // NOTE: no withRunLock - best-effort only; concurrent writes may cause inconsistency
@@ -31,7 +31,7 @@ import type { Decision, TaskPacket, TaskResult } from "../../runtime/handoff-man
31
31
  import { readIfSmallWithTee } from "../../runtime/task-output-context.ts";
32
32
  import type { TeamToolParamsValue } from "../../schema/team-tool-schema.ts";
33
33
  import { atomicWriteFile } from "../../state/atomic-write.ts";
34
- import { createRunPaths, loadRunManifestById } from "../../state/state-store.ts";
34
+ import { createRunPaths, loadRunManifestById } from "../../state/stores/state-store.ts";
35
35
  import type { TeamRunManifest, TeamTaskState } from "../../state/types.ts";
36
36
  import type { PiTeamsToolResult } from "../tool-result.ts";
37
37
  import { textFromToolResult } from "../tool-result.ts";
@@ -22,8 +22,20 @@ import {
22
22
  import { result, type TeamContext } from "../context.ts";
23
23
  import { handleListScheduled, handleSchedule } from "../handle-schedule.ts";
24
24
 
25
+ /**
26
+ * Actions owned by the Automate domain. Single source of truth for the switch
27
+ * below AND for the runtime exhaustiveness test
28
+ * (test/unit/dispatch-exhaustive.test.ts). The compile-time `never` sentinel in
29
+ * the `default` branch errors if an AutomateDomainAction is added here without
30
+ * a matching `case`.
31
+ */
32
+ export const AUTOMATE_DOMAIN_ACTIONS = ["schedule", "scheduled", "anchor", "auto-summarize", "auto_boomerang", "api"] as const;
33
+ type AutomateDomainAction = (typeof AUTOMATE_DOMAIN_ACTIONS)[number];
34
+
25
35
  export async function handleAutomateDomain(params: TeamToolParamsValue, ctx: TeamContext): Promise<PiTeamsToolResult> {
26
- switch (params.action) {
36
+ // `domainForAction` routes only Automate-domain actions here, so narrowing is sound.
37
+ const action = params.action as AutomateDomainAction;
38
+ switch (action) {
27
39
  case "api":
28
40
  return handleApi(params, ctx);
29
41
  case "schedule":
@@ -70,11 +82,14 @@ export async function handleAutomateDomain(params: TeamToolParamsValue, ctx: Tea
70
82
  return handleAutoSummarizeStatus(params, ctx);
71
83
  }
72
84
  }
73
- default:
85
+ default: {
86
+ // Compile-time exhaustiveness: errors if an AutomateDomainAction lacks a case above.
87
+ const _exhaustive: never = action;
74
88
  return result(
75
89
  `Unhandled automate-domain action: ${params.action}${formatActionSuggestion(String(params.action ?? ""))}`,
76
90
  { action: "unknown", status: "error" },
77
91
  true,
78
92
  );
93
+ }
79
94
  }
80
95
  }
@@ -13,8 +13,20 @@ import { handleDoctor } from "../doctor.ts";
13
13
  import { handleCleanup, handleForget, handlePrune } from "../lifecycle-actions.ts";
14
14
  import { handleRespond } from "../respond.ts";
15
15
 
16
+ /**
17
+ * Actions owned by the Control domain. Single source of truth for the switch
18
+ * below AND for the runtime exhaustiveness test
19
+ * (test/unit/dispatch-exhaustive.test.ts). The compile-time `never` sentinel in
20
+ * the `default` branch errors if a ControlDomainAction is added here without a
21
+ * matching `case`.
22
+ */
23
+ export const CONTROL_DOMAIN_ACTIONS = ["cancel", "invalidate", "respond", "cleanup", "prune", "forget", "doctor"] as const;
24
+ type ControlDomainAction = (typeof CONTROL_DOMAIN_ACTIONS)[number];
25
+
16
26
  export async function handleControlDomain(params: TeamToolParamsValue, ctx: TeamContext): Promise<PiTeamsToolResult> {
17
- switch (params.action) {
27
+ // `domainForAction` routes only Control-domain actions here, so narrowing is sound.
28
+ const action = params.action as ControlDomainAction;
29
+ switch (action) {
18
30
  case "doctor":
19
31
  return handleDoctor(ctx, params);
20
32
  case "cleanup":
@@ -29,7 +41,9 @@ export async function handleControlDomain(params: TeamToolParamsValue, ctx: Team
29
41
  return handleInvalidate(params, ctx);
30
42
  case "respond":
31
43
  return handleRespond(params, ctx);
32
- default:
44
+ default: {
45
+ // Compile-time exhaustiveness: errors if a ControlDomainAction lacks a case above.
46
+ const _exhaustive: never = action;
33
47
  return result(
34
48
  `Unhandled control-domain action: ${params.action}`,
35
49
  {
@@ -38,5 +52,6 @@ export async function handleControlDomain(params: TeamToolParamsValue, ctx: Team
38
52
  },
39
53
  true,
40
54
  );
55
+ }
41
56
  }
42
57
  }
@@ -27,8 +27,37 @@ import {
27
27
  handleWorkflowSave,
28
28
  } from "../workflow-manage.ts";
29
29
 
30
+ /**
31
+ * Actions owned by the Manage domain. Single source of truth for the switch
32
+ * below AND for the runtime exhaustiveness test
33
+ * (test/unit/dispatch-exhaustive.test.ts). The compile-time `never` sentinel in
34
+ * the `default` branch errors if a ManageDomainAction is added here without a
35
+ * matching `case`.
36
+ */
37
+ export const MANAGE_DOMAIN_ACTIONS = [
38
+ "create",
39
+ "update",
40
+ "delete",
41
+ "init",
42
+ "config",
43
+ "validate",
44
+ "autonomy",
45
+ "settings",
46
+ "workflow-create",
47
+ "workflow-get",
48
+ "workflow-list",
49
+ "workflow-save",
50
+ "workflow-delete",
51
+ "import",
52
+ "imports",
53
+ "export",
54
+ ] as const;
55
+ type ManageDomainAction = (typeof MANAGE_DOMAIN_ACTIONS)[number];
56
+
30
57
  export async function handleManageDomain(params: TeamToolParamsValue, ctx: TeamContext): Promise<PiTeamsToolResult> {
31
- switch (params.action) {
58
+ // `domainForAction` routes only Manage-domain actions here, so narrowing is sound.
59
+ const action = params.action as ManageDomainAction;
60
+ switch (action) {
32
61
  case "init": {
33
62
  const cfg = configRecord(params.config);
34
63
  const ignoreMethod =
@@ -151,11 +180,14 @@ export async function handleManageDomain(params: TeamToolParamsValue, ctx: TeamC
151
180
  return handleWorkflowSave(params, ctx);
152
181
  case "workflow-delete":
153
182
  return handleWorkflowDelete(params, ctx);
154
- default:
183
+ default: {
184
+ // Compile-time exhaustiveness: errors if a ManageDomainAction lacks a case above.
185
+ const _exhaustive: never = action;
155
186
  return result(
156
187
  `Unhandled manage-domain action: ${params.action}${formatActionSuggestion(String(params.action ?? ""))}`,
157
188
  { action: "unknown", status: "error" },
158
189
  true,
159
190
  );
191
+ }
160
192
  }
161
193
  }
@@ -20,8 +20,20 @@ import { handleOrchestrate } from "../orchestrate.ts";
20
20
  import { handleParallel } from "../parallel-dispatch.ts";
21
21
  import { handlePlan } from "../plan.ts";
22
22
 
23
+ /**
24
+ * Actions owned by the Run domain. Single source of truth for the switch
25
+ * below AND for the runtime exhaustiveness test
26
+ * (test/unit/dispatch-exhaustive.test.ts). The compile-time `never` sentinel in
27
+ * the `default` branch errors if a RunDomainAction is added here without a
28
+ * matching `case`.
29
+ */
30
+ export const RUN_DOMAIN_ACTIONS = ["run", "parallel", "plan", "orchestrate", "resume", "retry", "wait", "steer", "goal"] as const;
31
+ type RunDomainAction = (typeof RUN_DOMAIN_ACTIONS)[number];
32
+
23
33
  export async function handleRunDomain(params: TeamToolParamsValue, ctx: TeamContext): Promise<PiTeamsToolResult> {
24
- switch (params.action) {
34
+ // `domainForAction` routes only Run-domain actions here, so narrowing is sound.
35
+ const action = params.action as RunDomainAction;
36
+ switch (action) {
25
37
  case "run":
26
38
  return handleRun(params, ctx);
27
39
  case "parallel":
@@ -40,7 +52,9 @@ export async function handleRunDomain(params: TeamToolParamsValue, ctx: TeamCont
40
52
  return handleSteer(params, ctx);
41
53
  case "goal":
42
54
  return handleGoal(params, ctx);
43
- default:
55
+ default: {
56
+ // Compile-time exhaustiveness: errors if a RunDomainAction lacks a case above.
57
+ const _exhaustive: never = action;
44
58
  return result(
45
59
  `Unhandled run-domain action: ${params.action}`,
46
60
  {
@@ -49,5 +63,6 @@ export async function handleRunDomain(params: TeamToolParamsValue, ctx: TeamCont
49
63
  },
50
64
  true,
51
65
  );
66
+ }
52
67
  }
53
68
  }
@@ -10,11 +10,11 @@
10
10
  import * as path from "node:path";
11
11
  import { allAgents, discoverAgents } from "../../../agents/discover-agents.ts";
12
12
  import { loadConfig } from "../../../config/config.ts";
13
- import { FileCheckpointStore } from "../../../runtime/checkpoint.ts";
13
+ import { FileCheckpointStore } from "../../../runtime/recovery/checkpoint.ts";
14
14
  import { getSkillCacheStats } from "../../../runtime/skill-instructions.ts";
15
15
  import type { TeamToolParamsValue } from "../../../schema/team-tool-schema.ts";
16
- import { computeRunCacheKey, getCachedRun, getCacheStats } from "../../../state/run-cache.ts";
17
- import { listRunGraphs, loadRunGraph } from "../../../state/run-graph.ts";
16
+ import { computeRunCacheKey, getCachedRun, getCacheStats } from "../../../state/stores/run-cache.ts";
17
+ import { listRunGraphs, loadRunGraph } from "../../../state/stores/run-graph.ts";
18
18
  import { allTeams, discoverTeams } from "../../../teams/discover-teams.ts";
19
19
  import { searchAgents, searchTeams } from "../../../utils/bm25-search.ts";
20
20
  import { projectCrewRoot } from "../../../utils/paths.ts";
@@ -32,8 +32,37 @@ import { handleArtifacts, handleEvents, handleSummary } from "../inspect.ts";
32
32
  import { handleWorktrees } from "../lifecycle-actions.ts";
33
33
  import { handleStatus } from "../status.ts";
34
34
 
35
+ /**
36
+ * Actions owned by the Status domain. Single source of truth for the switch
37
+ * below AND for the runtime exhaustiveness test
38
+ * (test/unit/dispatch-exhaustive.test.ts). The compile-time `never` sentinel in
39
+ * the `default` branch errors if a StatusDomainAction is added here without a
40
+ * matching `case`.
41
+ */
42
+ export const STATUS_DOMAIN_ACTIONS = [
43
+ "status",
44
+ "list",
45
+ "get",
46
+ "events",
47
+ "artifacts",
48
+ "summary",
49
+ "graph",
50
+ "search",
51
+ "health",
52
+ "worktrees",
53
+ "checkpoint",
54
+ "cache",
55
+ "explain",
56
+ "onboard",
57
+ "recommend",
58
+ "help",
59
+ ] as const;
60
+ type StatusDomainAction = (typeof STATUS_DOMAIN_ACTIONS)[number];
61
+
35
62
  export async function handleStatusDomain(params: TeamToolParamsValue, ctx: TeamContext): Promise<PiTeamsToolResult> {
36
- switch (params.action) {
63
+ // `domainForAction` routes only Status-domain actions here, so narrowing is sound.
64
+ const action = params.action as StatusDomainAction;
65
+ switch (action) {
37
66
  case "list":
38
67
  return handleList(params, ctx);
39
68
  case "get":
@@ -177,11 +206,14 @@ export async function handleStatusDomain(params: TeamToolParamsValue, ctx: TeamC
177
206
  { action: "checkpoint", status: "ok", data: { checkpoint } },
178
207
  );
179
208
  }
180
- default:
209
+ default: {
210
+ // Compile-time exhaustiveness: errors if a StatusDomainAction lacks a case above.
211
+ const _exhaustive: never = action;
181
212
  return result(
182
213
  `Unhandled status-domain action: ${params.action}${formatActionSuggestion(String(params.action ?? ""))}`,
183
214
  { action: "unknown", status: "error" },
184
215
  true,
185
216
  );
217
+ }
186
218
  }
187
219
  }
@@ -5,9 +5,9 @@ import { allAgents, discoverAgents } from "../../agents/discover-agents.ts";
5
5
  import { loadConfig } from "../../config/config.ts";
6
6
  import { DEFAULT_PATHS } from "../../config/defaults.ts";
7
7
  import { type DriftReport, detectDrift, formatDriftReport } from "../../config/drift-detector.ts";
8
+ import { getRuntimeWarmupStatus } from "../../runtime/model/runtime-warmup.ts";
8
9
  import { getPiSpawnCommand } from "../../runtime/pi-spawn.ts";
9
- import { getRuntimeWarmupStatus } from "../../runtime/runtime-warmup.ts";
10
- import { formatZombieReport, scanZombieSubagents } from "../../runtime/zombie-scanner.ts";
10
+ import { formatZombieReport, scanZombieSubagents } from "../../runtime/process/zombie-scanner.ts";
11
11
  import type { TeamToolParamsValue } from "../../schema/team-tool-schema.ts";
12
12
  import { TeamToolParams } from "../../schema/team-tool-schema.ts";
13
13
  import { atomicWriteFile } from "../../state/atomic-write.ts";
@@ -1,6 +1,6 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
- import { loadRunManifestById } from "../../state/state-store.ts";
3
+ import { loadRunManifestById } from "../../state/stores/state-store.ts";
4
4
  import type { TeamRunManifest, TeamTaskState } from "../../state/types.ts";
5
5
  import { RUN_NOT_FOUND_HINT } from "./run-not-found.ts";
6
6