pi-crew 0.2.3 → 0.2.4

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 (348) hide show
  1. package/AGENTS.md +57 -32
  2. package/CHANGELOG.md +466 -448
  3. package/LICENSE +21 -21
  4. package/NOTICE.md +16 -16
  5. package/README.md +323 -323
  6. package/docs/FEATURE_INTAKE.md +126 -0
  7. package/docs/HARNESS.md +86 -0
  8. package/docs/HARNESS_BACKLOG.md +41 -0
  9. package/docs/TEST_MATRIX.md +49 -0
  10. package/docs/actions-reference.md +595 -595
  11. package/docs/architecture.md +180 -180
  12. package/docs/code-review-2026-05-11.md +592 -592
  13. package/docs/commands-reference.md +347 -347
  14. package/docs/comparison-pi-subagents-vs-pi-crew.md +303 -0
  15. package/docs/decisions/0001-durable-state.md +41 -0
  16. package/docs/decisions/0002-child-process-for-async.md +42 -0
  17. package/docs/decisions/0003-depth-guard.md +36 -0
  18. package/docs/decisions/0004-execfile-over-exec.md +34 -0
  19. package/docs/decisions/0005-no-parameter-properties.md +49 -0
  20. package/docs/decisions/0006-publish-bundled-esm.md +63 -0
  21. package/docs/decisions/0007-active-run-binary-index.md +54 -0
  22. package/docs/decisions/0008-child-pi-warm-pool.md +61 -0
  23. package/docs/decisions/README.md +23 -0
  24. package/docs/followup-review-round4-2026-05-13.md +107 -0
  25. package/docs/implementation-plan-top3.md +333 -0
  26. package/docs/live-mailbox-runtime.md +36 -36
  27. package/docs/next-upgrade-roadmap.md +808 -808
  28. package/docs/oh-my-pi-research.md +509 -0
  29. package/docs/perf/baseline-2026-05.md +113 -0
  30. package/docs/perf/final-report-2026-05.md +206 -0
  31. package/docs/perf/sprint-1-report.md +71 -0
  32. package/docs/perf/sprint-2-report.md +81 -0
  33. package/docs/perf/sprint-2.5-report.md +53 -0
  34. package/docs/perf/sprint-3-report.md +36 -0
  35. package/docs/perf/sprint-4-report.md +47 -0
  36. package/docs/perf/sprint-5-report.md +51 -0
  37. package/docs/perf/sprint-6-report.md +94 -0
  38. package/docs/perf/sprint-7-report.md +74 -0
  39. package/docs/perf/upgrade-plan-2026-05.md +147 -0
  40. package/docs/pi-subagents3-deep-analysis.md +508 -0
  41. package/docs/product/README.md +31 -0
  42. package/docs/product/platform.md +27 -0
  43. package/docs/product/runtime-safety.md +37 -0
  44. package/docs/product/team-run.md +39 -0
  45. package/docs/product/team-tool.md +37 -0
  46. package/docs/publishing.md +65 -65
  47. package/docs/resource-formats.md +134 -134
  48. package/docs/runtime-analysis-child-vs-live.md +171 -0
  49. package/docs/runtime-flow.md +148 -148
  50. package/docs/runtime-migration-in-process-analysis.md +250 -0
  51. package/docs/stories/README.md +30 -0
  52. package/docs/stories/backlog.md +36 -0
  53. package/docs/templates/decision.md +27 -0
  54. package/docs/templates/story.md +44 -0
  55. package/docs/templates/validation-report.md +32 -0
  56. package/docs/usage.md +238 -238
  57. package/index.ts +7 -6
  58. package/install.mjs +65 -65
  59. package/package.json +107 -100
  60. package/schema.json +222 -222
  61. package/skills/child-pi-spawning/SKILL.md +213 -0
  62. package/skills/context-artifact-hygiene/SKILL.md +32 -0
  63. package/skills/event-log-tracing/SKILL.md +299 -0
  64. package/skills/git-master/SKILL.md +225 -24
  65. package/skills/live-agent-lifecycle/SKILL.md +192 -0
  66. package/skills/mailbox-interactive/SKILL.md +300 -19
  67. package/skills/model-routing-context/SKILL.md +94 -0
  68. package/skills/multi-perspective-review/SKILL.md +88 -0
  69. package/skills/read-only-explorer/SKILL.md +250 -26
  70. package/skills/safe-bash/SKILL.md +307 -21
  71. package/skills/verification-before-done/SKILL.md +11 -2
  72. package/skills/widget-rendering/SKILL.md +258 -0
  73. package/skills/workspace-isolation/SKILL.md +202 -0
  74. package/skills/worktree-isolation/SKILL.md +202 -18
  75. package/src/adapters/claude-adapter.ts +25 -25
  76. package/src/adapters/codex-adapter.ts +21 -21
  77. package/src/adapters/cursor-adapter.ts +17 -17
  78. package/src/adapters/export-util.ts +137 -137
  79. package/src/adapters/index.ts +15 -15
  80. package/src/adapters/registry.ts +18 -18
  81. package/src/adapters/types.ts +23 -23
  82. package/src/agents/agent-config.ts +38 -38
  83. package/src/agents/agent-serializer.ts +38 -38
  84. package/src/agents/discover-agents.ts +121 -118
  85. package/src/config/config.ts +740 -858
  86. package/src/config/defaults.ts +96 -96
  87. package/src/config/drift-detector.ts +211 -211
  88. package/src/config/markers.ts +327 -327
  89. package/src/config/resilient-parser.ts +109 -108
  90. package/src/config/suggestions.ts +74 -74
  91. package/src/config/types.ts +199 -0
  92. package/src/extension/async-notifier.ts +123 -89
  93. package/src/extension/autonomous-policy.ts +169 -169
  94. package/src/extension/cross-extension-rpc.ts +104 -104
  95. package/src/extension/help.ts +47 -47
  96. package/src/extension/import-index.ts +69 -69
  97. package/src/extension/management.ts +395 -382
  98. package/src/extension/notification-router.ts +116 -116
  99. package/src/extension/notification-sink.ts +51 -51
  100. package/src/extension/project-init.ts +168 -168
  101. package/src/extension/register.ts +859 -668
  102. package/src/extension/registration/artifact-cleanup.ts +15 -15
  103. package/src/extension/registration/command-utils.ts +54 -54
  104. package/src/extension/registration/commands.ts +559 -452
  105. package/src/extension/registration/compaction-guard.ts +125 -125
  106. package/src/extension/registration/subagent-helpers.ts +102 -102
  107. package/src/extension/registration/subagent-tools.ts +220 -159
  108. package/src/extension/registration/team-tool.ts +159 -99
  109. package/src/extension/registration/viewers.ts +29 -0
  110. package/src/extension/result-watcher.ts +128 -128
  111. package/src/extension/run-bundle-schema.ts +89 -89
  112. package/src/extension/run-export.ts +73 -73
  113. package/src/extension/run-import.ts +84 -84
  114. package/src/extension/run-index.ts +94 -94
  115. package/src/extension/run-maintenance.ts +142 -142
  116. package/src/extension/session-summary.ts +8 -8
  117. package/src/extension/team-manager-command.ts +96 -96
  118. package/src/extension/team-recommendation.ts +188 -188
  119. package/src/extension/team-tool/api.ts +5 -2
  120. package/src/extension/team-tool/cancel.ts +224 -209
  121. package/src/extension/team-tool/config-patch.ts +36 -36
  122. package/src/extension/team-tool/context.ts +60 -60
  123. package/src/extension/team-tool/doctor.ts +242 -242
  124. package/src/extension/team-tool/handle-settings.ts +421 -195
  125. package/src/extension/team-tool/inspect.ts +41 -41
  126. package/src/extension/team-tool/lifecycle-actions.ts +139 -139
  127. package/src/extension/team-tool/parallel-dispatch.ts +156 -156
  128. package/src/extension/team-tool/plan.ts +19 -19
  129. package/src/extension/team-tool/respond.ts +112 -111
  130. package/src/extension/team-tool/run.ts +246 -229
  131. package/src/extension/team-tool/status.ts +110 -110
  132. package/src/extension/team-tool-types.ts +13 -13
  133. package/src/extension/team-tool.ts +344 -344
  134. package/src/extension/tool-result.ts +16 -16
  135. package/src/extension/validate-resources.ts +77 -77
  136. package/src/hooks/registry.ts +61 -61
  137. package/src/hooks/types.ts +40 -40
  138. package/src/i18n.ts +184 -184
  139. package/src/observability/correlation.ts +35 -35
  140. package/src/observability/event-to-metric.ts +68 -68
  141. package/src/observability/exporters/adapter.ts +30 -30
  142. package/src/observability/exporters/otlp-exporter.ts +106 -92
  143. package/src/observability/exporters/prometheus-exporter.ts +54 -54
  144. package/src/observability/metric-registry.ts +87 -87
  145. package/src/observability/metric-retention.ts +54 -54
  146. package/src/observability/metric-sink.ts +81 -56
  147. package/src/observability/metrics-primitives.ts +167 -167
  148. package/src/prompt/prompt-runtime.ts +72 -72
  149. package/src/runtime/adaptive-plan.ts +338 -0
  150. package/src/runtime/agent-control.ts +169 -169
  151. package/src/runtime/agent-memory.ts +72 -72
  152. package/src/runtime/agent-observability.ts +114 -114
  153. package/src/runtime/async-marker.ts +26 -26
  154. package/src/runtime/async-runner.ts +153 -153
  155. package/src/runtime/attention-events.ts +28 -28
  156. package/src/runtime/auto-resume.ts +100 -100
  157. package/src/runtime/background-runner.ts +122 -89
  158. package/src/runtime/cancellation.ts +61 -61
  159. package/src/runtime/capability-inventory.ts +116 -116
  160. package/src/runtime/child-pi-pool.ts +68 -0
  161. package/src/runtime/child-pi.ts +541 -461
  162. package/src/runtime/code-summary.ts +247 -247
  163. package/src/runtime/compaction-summary.ts +271 -271
  164. package/src/runtime/concurrency.ts +58 -58
  165. package/src/runtime/crash-recovery.ts +317 -301
  166. package/src/runtime/crew-agent-records.ts +379 -281
  167. package/src/runtime/crew-agent-runtime.ts +60 -60
  168. package/src/runtime/cross-extension-rpc.ts +72 -0
  169. package/src/runtime/custom-tools/irc-tool.ts +201 -201
  170. package/src/runtime/custom-tools/submit-result-tool.ts +90 -90
  171. package/src/runtime/deadletter.ts +47 -47
  172. package/src/runtime/delivery-coordinator.ts +176 -176
  173. package/src/runtime/delta-conflict.ts +360 -360
  174. package/src/runtime/diagnostic-export.ts +102 -102
  175. package/src/runtime/direct-run.ts +35 -35
  176. package/src/runtime/effectiveness.ts +82 -81
  177. package/src/runtime/errors/crew-errors.ts +166 -0
  178. package/src/runtime/event-stream-bridge.ts +92 -92
  179. package/src/runtime/foreground-control.ts +82 -82
  180. package/src/runtime/green-contract.ts +46 -46
  181. package/src/runtime/group-join.ts +234 -106
  182. package/src/runtime/heartbeat-watcher.ts +145 -124
  183. package/src/runtime/iteration-hooks.ts +267 -267
  184. package/src/runtime/live-agent-control.ts +88 -88
  185. package/src/runtime/live-agent-manager.ts +377 -179
  186. package/src/runtime/live-control-realtime.ts +36 -36
  187. package/src/runtime/live-session-runtime.ts +676 -600
  188. package/src/runtime/loop-gates.ts +129 -129
  189. package/src/runtime/manifest-cache.ts +263 -263
  190. package/src/runtime/mcp-proxy.ts +113 -113
  191. package/src/runtime/metric-parser.ts +40 -40
  192. package/src/runtime/model-fallback.ts +282 -274
  193. package/src/runtime/model-resolver.ts +118 -0
  194. package/src/runtime/output-validator.ts +187 -187
  195. package/src/runtime/overflow-recovery.ts +175 -175
  196. package/src/runtime/parallel-research.ts +44 -44
  197. package/src/runtime/parallel-utils.ts +156 -156
  198. package/src/runtime/parent-guard.ts +80 -80
  199. package/src/runtime/phase-progress.ts +217 -217
  200. package/src/runtime/pi-args.ts +165 -165
  201. package/src/runtime/pi-json-output.ts +111 -111
  202. package/src/runtime/pi-spawn.ts +167 -167
  203. package/src/runtime/policy-engine.ts +79 -79
  204. package/src/runtime/post-checks.ts +125 -125
  205. package/src/runtime/post-exit-stdio-guard.ts +86 -86
  206. package/src/runtime/process-status.ts +97 -73
  207. package/src/runtime/progress-event-coalescer.ts +43 -43
  208. package/src/runtime/recovery-recipes.ts +74 -74
  209. package/src/runtime/retry-executor.ts +81 -81
  210. package/src/runtime/role-permission.ts +39 -39
  211. package/src/runtime/run-tracker.ts +99 -0
  212. package/src/runtime/runtime-policy.ts +21 -0
  213. package/src/runtime/runtime-resolver.ts +94 -91
  214. package/src/runtime/scheduler.ts +294 -0
  215. package/src/runtime/semaphore.ts +131 -131
  216. package/src/runtime/sensitive-paths.ts +92 -92
  217. package/src/runtime/session-usage.ts +79 -79
  218. package/src/runtime/settings-store.ts +103 -0
  219. package/src/runtime/sidechain-output.ts +29 -29
  220. package/src/runtime/skill-instructions.ts +222 -222
  221. package/src/runtime/stale-reconciler.ts +198 -189
  222. package/src/runtime/streaming-output.ts +47 -0
  223. package/src/runtime/subagent-manager.ts +404 -400
  224. package/src/runtime/subprocess-tool-registry.ts +67 -67
  225. package/src/runtime/task-display.ts +38 -38
  226. package/src/runtime/task-graph-scheduler.ts +122 -122
  227. package/src/runtime/task-graph.ts +207 -207
  228. package/src/runtime/task-output-context.ts +177 -177
  229. package/src/runtime/task-packet.ts +93 -93
  230. package/src/runtime/task-quality.ts +207 -207
  231. package/src/runtime/task-runner/capabilities.ts +78 -78
  232. package/src/runtime/task-runner/live-executor.ts +131 -113
  233. package/src/runtime/task-runner/progress.ts +119 -119
  234. package/src/runtime/task-runner/prompt-builder.ts +139 -139
  235. package/src/runtime/task-runner/prompt-pipeline.ts +64 -64
  236. package/src/runtime/task-runner/result-utils.ts +14 -14
  237. package/src/runtime/task-runner/run-projection.ts +103 -103
  238. package/src/runtime/task-runner/state-helpers.ts +22 -22
  239. package/src/runtime/task-runner.ts +469 -459
  240. package/src/runtime/team-runner.ts +693 -945
  241. package/src/runtime/usage-tracker.ts +71 -0
  242. package/src/runtime/worker-heartbeat.ts +21 -21
  243. package/src/runtime/worker-startup.ts +57 -57
  244. package/src/runtime/workflow-state.ts +187 -187
  245. package/src/runtime/yield-handler.ts +190 -190
  246. package/src/schema/config-schema.ts +172 -168
  247. package/src/schema/team-tool-schema.ts +126 -126
  248. package/src/schema/validation-types.ts +151 -148
  249. package/src/skills/discover-skills.ts +67 -67
  250. package/src/skills/skill-templates.ts +374 -374
  251. package/src/state/active-run-registry.ts +227 -191
  252. package/src/state/artifact-store.ts +130 -129
  253. package/src/state/atomic-write.ts +262 -195
  254. package/src/state/blob-store.ts +116 -116
  255. package/src/state/contracts.ts +111 -111
  256. package/src/state/event-log-rotation.ts +161 -158
  257. package/src/state/event-log.ts +383 -303
  258. package/src/state/event-reconstructor.ts +217 -217
  259. package/src/state/jsonl-writer.ts +82 -82
  260. package/src/state/locks.ts +146 -146
  261. package/src/state/mailbox.ts +446 -405
  262. package/src/state/state-store.ts +364 -351
  263. package/src/state/task-claims.ts +44 -44
  264. package/src/state/types.ts +285 -285
  265. package/src/state/usage.ts +29 -29
  266. package/src/subagents/async-entry.ts +1 -1
  267. package/src/subagents/index.ts +3 -3
  268. package/src/subagents/live/control.ts +1 -1
  269. package/src/subagents/live/manager.ts +1 -1
  270. package/src/subagents/live/realtime.ts +1 -1
  271. package/src/subagents/live/session-runtime.ts +1 -1
  272. package/src/subagents/manager.ts +1 -1
  273. package/src/subagents/spawn.ts +1 -1
  274. package/src/teams/discover-teams.ts +116 -116
  275. package/src/teams/team-config.ts +27 -27
  276. package/src/teams/team-serializer.ts +38 -38
  277. package/src/types/diff.d.ts +18 -18
  278. package/src/ui/agent-management-overlay.ts +144 -144
  279. package/src/ui/crew-widget.ts +487 -370
  280. package/src/ui/dashboard-panes/agents-pane.ts +109 -28
  281. package/src/ui/dashboard-panes/cancellation-pane.ts +42 -42
  282. package/src/ui/dashboard-panes/capability-pane.ts +59 -59
  283. package/src/ui/dashboard-panes/health-pane.ts +30 -30
  284. package/src/ui/dashboard-panes/mailbox-pane.ts +35 -35
  285. package/src/ui/dashboard-panes/progress-pane.ts +30 -30
  286. package/src/ui/dashboard-panes/transcript-pane.ts +10 -10
  287. package/src/ui/heartbeat-aggregator.ts +63 -63
  288. package/src/ui/keybinding-map.ts +97 -94
  289. package/src/ui/live-conversation-overlay.ts +152 -0
  290. package/src/ui/live-run-sidebar.ts +180 -180
  291. package/src/ui/mascot.ts +442 -442
  292. package/src/ui/overlays/agent-picker-overlay.ts +57 -57
  293. package/src/ui/overlays/confirm-overlay.ts +58 -58
  294. package/src/ui/overlays/mailbox-compose-overlay.ts +144 -144
  295. package/src/ui/overlays/mailbox-compose-preview.ts +63 -63
  296. package/src/ui/overlays/mailbox-detail-overlay.ts +122 -122
  297. package/src/ui/pi-ui-compat.ts +57 -57
  298. package/src/ui/powerbar-publisher.ts +221 -197
  299. package/src/ui/render-scheduler.ts +216 -143
  300. package/src/ui/run-action-dispatcher.ts +118 -118
  301. package/src/ui/run-dashboard.ts +526 -464
  302. package/src/ui/run-event-bus.ts +208 -208
  303. package/src/ui/run-snapshot-cache.ts +826 -777
  304. package/src/ui/settings-overlay.ts +721 -0
  305. package/src/ui/snapshot-types.ts +86 -70
  306. package/src/ui/theme-adapter.ts +190 -190
  307. package/src/ui/tool-progress-formatter.ts +89 -0
  308. package/src/ui/transcript-cache.ts +94 -94
  309. package/src/ui/transcript-viewer.ts +335 -335
  310. package/src/utils/conflict-detect.ts +662 -0
  311. package/src/utils/file-coalescer.ts +86 -86
  312. package/src/utils/frontmatter.ts +68 -68
  313. package/src/utils/fs-watch.ts +88 -31
  314. package/src/utils/gh-protocol.ts +479 -0
  315. package/src/utils/ids.ts +17 -17
  316. package/src/utils/incremental-reader.ts +104 -104
  317. package/src/utils/internal-error.ts +6 -6
  318. package/src/utils/names.ts +27 -27
  319. package/src/utils/paths.ts +102 -63
  320. package/src/utils/redaction.ts +44 -44
  321. package/src/utils/safe-paths.ts +47 -47
  322. package/src/utils/scan-cache.ts +136 -136
  323. package/src/utils/sse-parser.ts +134 -134
  324. package/src/utils/task-name-generator.ts +337 -337
  325. package/src/utils/timings.ts +33 -33
  326. package/src/utils/visual.ts +243 -198
  327. package/src/workflows/discover-workflows.ts +139 -139
  328. package/src/workflows/validate-workflow.ts +40 -40
  329. package/src/workflows/workflow-config.ts +26 -26
  330. package/src/workflows/workflow-serializer.ts +32 -32
  331. package/src/worktree/branch-freshness.ts +45 -45
  332. package/src/worktree/cleanup.ts +75 -75
  333. package/src/worktree/worktree-manager.ts +188 -188
  334. package/teams/default.team.md +12 -12
  335. package/teams/fast-fix.team.md +11 -11
  336. package/teams/implementation.team.md +18 -18
  337. package/teams/parallel-research.team.md +14 -14
  338. package/teams/research.team.md +11 -11
  339. package/teams/review.team.md +12 -12
  340. package/tsconfig.json +19 -19
  341. package/workflows/default.workflow.md +30 -30
  342. package/workflows/fast-fix.workflow.md +23 -23
  343. package/workflows/implementation.workflow.md +43 -43
  344. package/workflows/parallel-research.workflow.md +46 -46
  345. package/workflows/research.workflow.md +22 -22
  346. package/workflows/review.workflow.md +30 -30
  347. package/skills/task-packet/SKILL.md +0 -28
  348. package/skills/verify-evidence/SKILL.md +0 -27
@@ -0,0 +1,303 @@
1
+ # So sánh kiến trúc: pi-subagents3 vs pi-crew
2
+
3
+ > Ngày: 2026-05-12
4
+ > Source: `@tintinweb/pi-subagents` v0.7.1 (6.082 LOC, 28 files) vs `pi-crew` v0.2.3 (35.809 LOC, ~200+ files)
5
+
6
+ ---
7
+
8
+ ## 1. Tổng quan
9
+
10
+ | Tiêu chí | pi-subagents3 | pi-crew |
11
+ |---|---|---|
12
+ | **Tác giả** | tintinweb | baphuongna |
13
+ | **Phiên bản** | 0.7.1 | 0.2.3 |
14
+ | **Mục tiêu** | Subagent đơn lẻ (Agent tool) — spawn, resume, steer | Team orchestration — multi-agent workflows, phases, parallel dispatch |
15
+ | **LOC** | ~6.000 | ~36.000 |
16
+ | **Entry point** | `src/index.ts` (1.885 dòng — monolith) | `index.ts` → `register.ts` (668 dòng) → modular registration |
17
+ | **Kiến trúc** | Đơn giản, trực tiếp, single-agent focus | Layered, event-driven, state-machine based |
18
+ | **Peer deps** | pi-ai ≥0.70.5, pi-coding-agent ≥0.70.5, pi-tui ≥0.70.5 | pi-coding-agent (runtime) |
19
+ | **Npm deps** | `@sinclair/typebox`, `croner`, `nanoid` | 0 (zero runtime dependencies) |
20
+ | **Test runner** | vitest | Node built-in `--experimental-strip-types` |
21
+ | **Subprocess model** | **In-process** (tái sử dụng Pi SDK `createAgentSession`) | **Out-of-process** (spawn child Pi instance via `child-pi.ts`) |
22
+
23
+ ---
24
+
25
+ ## 2. Kiến trúc cốt lõi
26
+
27
+ ### 2.1 pi-subagents3 — In-process Agent Sessions
28
+
29
+ ```
30
+ ┌─────────────────────────────────────────────┐
31
+ │ index.ts (1885 LOC) │
32
+ │ Extension entry: tools, commands, menus, │
33
+ │ lifecycle hooks, settings, scheduling │
34
+ ├─────────┬──────────┬──────────┬──────────────┤
35
+ │agent- │agent- │agent- │schedule.ts │
36
+ │runner │manager │types │ScheduleStore │
37
+ │(310 LOC)│(310 LOC) │(140 LOC) │(365 LOC) │
38
+ ├─────────┴──────────┴──────────┴──────────────┤
39
+ │ memory.ts │ prompts.ts │ context.ts │ env.ts │
40
+ │ worktree │ model- │ settings │ usage │
41
+ │ │ resolver │ │ │
42
+ ├──────────────────────────────────────────────┤
43
+ │ Pi SDK (createAgentSession) │
44
+ │ In-process, shared event loop │
45
+ └──────────────────────────────────────────────┘
46
+ ```
47
+
48
+ **Đặc điểm chính:**
49
+ - Agent chạy **trong cùng process** với parent Pi session
50
+ - Dùng `createAgentSession()` + `session.prompt()` — Pi SDK API trực tiếp
51
+ - Tool filtering, extension binding, skill preloading trong process
52
+ - Event subscription (`session.subscribe()`) để track turns, tool uses, streaming text
53
+ - 1 file `index.ts` khổng lồ chứa gần như toàn bộ logic
54
+
55
+ ### 2.2 pi-crew — Out-of-process Child Workers
56
+
57
+ ```
58
+ ┌─────────────────────────────────────────────────────────┐
59
+ │ register.ts (668 LOC) │
60
+ │ Extension entry: lifecycle, commands, tool registration │
61
+ ├────────────────┬─────────────────┬───────────────────────┤
62
+ │ team-tool.ts │ team-runner.ts │ subagent-manager.ts │
63
+ │ (344 LOC) │ (945 LOC) │ (400 LOC) │
64
+ │ Tool handler │ Workflow engine │ Agent tracking │
65
+ ├────────────────┴─────────────────┴───────────────────────┤
66
+ │ child-pi.ts (461 LOC) │ task-runner.ts (459 LOC) │
67
+ │ Subprocess spawn │ Per-worker execution │
68
+ ├─────────────────────────┬───────────────────────────────┤
69
+ │ State Layer │ UI Layer │
70
+ │ state-store.ts │ crew-widget.ts │
71
+ │ event-log.ts │ run-dashboard.ts │
72
+ │ locks.ts │ transcript-viewer.ts │
73
+ │ atomic-write.ts │ powerbar-publisher.ts │
74
+ ├─────────────────────────┴───────────────────────────────┤
75
+ │ Pi CLI (child process via spawn) │
76
+ │ Isolated process, independent event loop │
77
+ └─────────────────────────────────────────────────────────┘
78
+ ```
79
+
80
+ **Đặc điểm chính:**
81
+ - Worker chạy **riêng process** — spawn `pi` CLI child process
82
+ - Giao tiếp qua JSON events trên stdout (`--json-output` mode)
83
+ - State persistence: JSONL event log, manifest files, atomic writes
84
+ - Kiến trúc phân tán: team → workflow → phases → tasks → workers
85
+ - Tách biệt hoàn toàn: crash recovery, stuck detection, deadletter
86
+
87
+ ---
88
+
89
+ ## 3. So sánh chi tiết theo module
90
+
91
+ ### 3.1 Agent Execution
92
+
93
+ | Khía cạnh | pi-subagents3 | pi-crew |
94
+ |---|---|---|
95
+ | **Runtime** | `createAgentSession()` in-process | `spawn("pi", [...])` child process |
96
+ | **Tool access** | Direct — `session.setActiveToolsByName()` | Giới hạn bởi child Pi args |
97
+ | **Context sharing** | `buildParentContext()` — copy conversation | Không share (isolated by design) |
98
+ | **Steering** | `session.steer(message)` — immediate in-process | `child.stdin.write()` — JSON event |
99
+ | **Resume** | `resumeAgent(session, prompt)` — reuse session | Re-spawn child process |
100
+ | **Turn limits** | Soft limit → steer "wrap up" → hard abort | `--max-turns` CLI arg → child exit |
101
+ | **Grace turns** | Configurable (default 5) | N/A |
102
+ | **Streaming** | `session.subscribe()` — real-time deltas | JSON event polling on stdout |
103
+ | **Compaction** | Tracked via `compaction_end` events | Child handles independently |
104
+ | **Memory overhead** | Low (shared process) | High (separate Node.js process) |
105
+ | **Isolation** | Process-shared (same memory space) | Process-isolated (crash-safe) |
106
+ | **Max concurrent** | Queue with configurable limit (default 4) | Queue with configurable limit (default 4) |
107
+
108
+ ### 3.2 Agent Configuration
109
+
110
+ | Khía cạnh | pi-subagents3 | pi-crew |
111
+ |---|---|---|
112
+ | **Built-in agents** | 3: general-purpose, Explore, Plan | 10: explorer, planner, executor, reviewer, verifier, analyst, critic, writer, security-reviewer, test-engineer |
113
+ | **Custom agents** | `.md` files in `.pi/agents/` or `~/.pi/agents/` | `.md` files in `agents/` (project) |
114
+ | **Agent config** | 22 fields: systemPrompt, promptMode, extensions, skills, model, thinking, maxTurns, memory, isolation, disallowedTools... | agent-config.ts: name, systemPrompt (frontmatter), maxTurns |
115
+ | **Prompt mode** | `replace` (standalone) or `append` (parent twin) | Always replace (isolated subprocess) |
116
+ | **Tool filtering** | Allowlist (builtinToolNames) + denylist (disallowedTools) + extension filter | CLI arg `--allowed-tools` |
117
+ | **Model lock** | Per-agent model in config | Per-agent model in frontmatter |
118
+ | **Thinking level** | Per-agent `thinking` field | Per-agent `thinkingLevel` in frontmatter |
119
+ | **Agent discovery** | `custom-agents.ts` → `.md` frontmatter parse | `discover-agents.ts` → `.md` frontmatter parse |
120
+
121
+ ### 3.3 Memory / Persistence
122
+
123
+ | Khía cạnh | pi-subagents3 | pi-crew |
124
+ |---|---|---|
125
+ | **Agent memory** | ✅ Persistent MEMORY.md per agent (user/project/local scope) | ❌ Không có built-in agent memory |
126
+ | **Memory tools** | Injected dynamically based on write capability | N/A |
127
+ | **State persistence** | In-memory AgentRecord + JSON schedule store | Full state machine: manifest.json + events.jsonl + tasks.json |
128
+ | **Crash recovery** | Worktree prune on dispose | Detect interrupted runs, deadletter, stuck-blocked notifications |
129
+ | **Locking** | PID-based file lock for schedule store | `mkdirSync` atomic lock + PID stale detection for event log |
130
+ | **Atomic writes** | temp+rename (POSIX) | Full atomic-write.ts with O_NOFOLLOW, symlink checks, sync/async parity |
131
+
132
+ ### 3.4 Scheduling
133
+
134
+ | Khía cạnh | pi-subagents3 | pi-crew |
135
+ |---|---|---|
136
+ | **Scheduling** | ✅ Full scheduler: cron (6-field), interval, one-shot | ❌ Không có scheduling |
137
+ | **Cron engine** | `croner` library | N/A |
138
+ | **Persistence** | Session-scoped JSON with PID-locked store | N/A |
139
+ | **Queue bypass** | `bypassQueue: true` for scheduled fires | N/A |
140
+ | **Events** | `subagents:scheduled` (added/removed/fired/error) | N/A |
141
+ | **Master switch** | `schedulingEnabled` setting (strips tool param) | N/A |
142
+
143
+ ### 3.5 Worktree Isolation
144
+
145
+ | Khía cạnh | pi-subagents3 | pi-crew |
146
+ |---|---|---|
147
+ | **Worktree support** | ✅ `createWorktree()` / `cleanupWorktree()` | ✅ Full `worktree-manager.ts` (8.8 KB) |
148
+ | **Branch management** | Auto-branch, auto-commit changes | Branch freshness, reuse, file node_modules skip |
149
+ | **Error handling** | Strict — throws if worktree creation fails | Retry + fallback |
150
+ | **Cleanup** | On completion (success or error) + prune on dispose | On completion + cleanup.ts + branch-freshness |
151
+
152
+ ### 3.6 Cross-extension Communication
153
+
154
+ | Khía cạnh | pi-subagents3 | pi-crew |
155
+ |---|---|---|
156
+ | **RPC protocol** | ✅ Event bus RPC: ping/spawn/stop | ✅ Event bus RPC: ping/spawn/status/cancel |
157
+ | **Protocol version** | v2 | Versioned |
158
+ | **Reply envelope** | `{ success: true, data? }` / `{ success: false, error }` | Similar |
159
+ | **Singleton access** | `Symbol.for("pi-subagents:manager")` on globalThis | `globalThis.__piCrewRuntimeCleanup` |
160
+
161
+ ### 3.7 UI / TUI
162
+
163
+ | Khía cạnh | pi-subagents3 | pi-crew |
164
+ |---|---|---|
165
+ | **Agent widget** | `agent-widget.ts` (518 LOC) — overlay | `crew-widget.ts` (16 KB) — sidebar + dashboard |
166
+ | **Conversation viewer** | `conversation-viewer.ts` (243 LOC) | `transcript-viewer.ts` (13.9 KB) — JSONL-based |
167
+ | **Schedule menu** | `schedule-menu.ts` (104 LOC) | N/A |
168
+ | **Dashboard** | N/A (overlay-based) | `run-dashboard.ts` (22.7 KB) — multi-pane |
169
+ | **Status bar** | Inline status in overlay | `powerbar-publisher.ts` (8.9 KB) |
170
+ | **Live sidebar** | N/A | `live-run-sidebar.ts` (8.6 KB) |
171
+ | **Notification render** | Custom `renderCall` / `renderResult` | `notification-router.ts` + `notification-sink.ts` |
172
+ | **Context % indicator** | ✅ Token count + context % (colored) + compaction count | ❌ Không có context indicator |
173
+
174
+ ### 3.8 Settings / Configuration
175
+
176
+ | Khía cạnh | pi-subagents3 | pi-crew |
177
+ |---|---|---|
178
+ | **Settings file** | `.pi/subagents.json` (project) + `~/.pi/agent/subagents.json` (global) | `config.ts` → `.pi/crew-config.json` + `defaults.ts` |
179
+ | **Runtime settings** | maxConcurrent, defaultMaxTurns, graceTurns, defaultJoinMode, schedulingEnabled | maxConcurrent, telemetry, notifications |
180
+ | **Validation** | `sanitize()` with ceiling values | `config.ts` schema validation |
181
+ | **Hot reload** | Apply on change + emit event | Load on register |
182
+
183
+ ---
184
+
185
+ ## 4. Tính năng độc đáo
186
+
187
+ ### pi-subagents3 có nhưng pi-crew không:
188
+
189
+ 1. **In-process agent sessions** — Zero subprocess overhead, direct Pi SDK access, shared event loop
190
+ 2. **Persistent agent memory** — MEMORY.md per agent với 3 scope (user/project/local), auto-injected tools
191
+ 3. **Soft turn limit + grace period** — Steer "wrap up" trước khi hard-abort, configurable grace turns
192
+ 4. **Scheduling** — Full cron/interval/one-shot scheduler với croner, session-scoped persistence
193
+ 5. **Parent context inheritance** — `inheritContext` fork conversation cho subagent
194
+ 6. **Append mode** — Agent chạy như "twin" của parent (kế thừa system prompt + tools)
195
+ 7. **Context % indicator** — Live context window utilization (%), compaction count (↻N)
196
+ 8. **Agent memory tools** — Dynamic tool injection based on write capability (read-only vs read-write)
197
+ 9. **Skill preloading** — Load skill content directly into system prompt (string[])
198
+ 10. **Batch grouping** — 100ms debounce gom nhiều background completions thành 1 notification
199
+ 11. **Cancelable nudges** — 200ms hold trước khi gửi notification, get_subagent_result hủy nudge
200
+ 12. **Agent creation wizard** — `/agents` → spawn agent để tạo agent config .md file
201
+
202
+ ### pi-crew có nhưng pi-subagents3 không:
203
+
204
+ 1. **Team orchestration** — Multi-agent teams với workflows, phases, parallel dispatch
205
+ 2. **Workflow engine** — Declarative workflow definitions (step → agent → gate → next)
206
+ 3. **Out-of-process isolation** — Child Pi process, crash-safe, independent event loop
207
+ 4. **Full state machine** — manifest.json + tasks.json + events.jsonl, durable persistence
208
+ 5. **Crash recovery** — Detect interrupted runs, deadletter queue, stuck-blocked detection
209
+ 6. **Mailbox system** — Interactive respond/nudge/ack workflow cho waiting tasks
210
+ 7. **Heartbeat monitoring** — `heartbeat-watcher.ts` + gradient-based health tracking
211
+ 8. **Observability** — Metrics registry, OTLP exporter, Prometheus exporter
212
+ 9. **Run export/import** — Bundle/unbundle runs cho cross-machine sharing
213
+ 10. **Live session management** — Live IRC, live agent control, live extension bridge
214
+ 11. **UI dashboard** — Multi-pane dashboard với agents/capabilities/health/mailbox/progress
215
+ 12. **Run snapshot cache** — Efficient state snapshots cho UI rendering
216
+ 13. **Delivery coordination** — Overflow recovery, delivery coordinator cho message routing
217
+ 14. **i18n** — Internationalization support
218
+ 15. **Post-checks** — Configurable post-execution verification hooks
219
+ 16. **Iteration hooks** — Pre/post iteration hooks cho external integrations
220
+ 17. **Model fallback chain** — Multi-model fallback với cost tracking
221
+ 18. **Compaction summary** — Context compaction cho long-running agents
222
+ 19. **Task quality scoring** — Automatic quality assessment of task outputs
223
+ 20. **Agent capability inventory** — Dynamic tool/skill capability detection
224
+
225
+ ---
226
+
227
+ ## 5. Phân tích ưu/nhược điểm
228
+
229
+ ### pi-subagents3
230
+
231
+ **Ưu điểm:**
232
+ - **Đơn giản**: ~6K LOC, dễ hiểu, dễ maintain
233
+ - **Performance**: In-process, zero subprocess overhead, shared memory
234
+ - **Tính năng sâu**: Memory, scheduling, context inheritance, turn management rất chi tiết
235
+ - **SDK-first**: Sử dụng Pi SDK trực tiếp, tận dụng tối đa API
236
+ - **Interactive**: Resume, steer, conversation viewer rất mượt
237
+ - **Settings**: Hot-reload, master switch cho features
238
+
239
+ **Nhược điểm:**
240
+ - **Monolith**: `index.ts` 1.885 dòng — khó maintain, khó test
241
+ - **No team support**: Không có workflow, phases, parallel dispatch
242
+ - **Crash propagation**: Agent crash ảnh hưởng parent process
243
+ - **Limited observability**: Không có metrics, export, monitoring
244
+ - **No run persistence**: Agent record chỉ in-memory (trừ schedule store)
245
+
246
+ ### pi-crew
247
+
248
+ **Ưu điểm:**
249
+ - **Kiến trúc mạnh**: Layered, event-driven, state-machine based
250
+ - **Team orchestration**: Workflow engine với phases, parallel, gates
251
+ - **Crash isolation**: Out-of-process workers, child crash không ảnh hưởng parent
252
+ - **Full persistence**: JSONL event log, manifest, atomic writes
253
+ - **Observability**: Metrics, OTLP, Prometheus, heartbeat monitoring
254
+ - **Modular**: 200+ files, mỗi file một trách nhiệm
255
+ - **Enterprise features**: Export/import, i18n, compaction, quality scoring
256
+
257
+ **Nhược điểm:**
258
+ - **Phức tạp**: 36K LOC, learning curve cao
259
+ - **Subprocess overhead**: Mỗi worker spawn riêng process (RAM, startup time)
260
+ - **Không có memory**: Agents không có persistent memory giữa sessions
261
+ - **Không có scheduling**: Không có cron/interval/one-shot
262
+ - **Không có context inheritance**: Workers chạy isolated, không thấy parent context
263
+ - **Không có soft turn limit**: Hard cutoff, không có grace period
264
+ - **Không có interactive steer**: Không thể steer worker sau khi spawn
265
+
266
+ ---
267
+
268
+ ## 6. Khuyến nghị
269
+
270
+ ### pi-crew nên học từ pi-subagents3:
271
+
272
+ 1. **Persistent agent memory** — MEMORY.md pattern rất giá trị cho long-running projects
273
+ 2. **Soft turn limit + grace period** — Elegant hơn hard abort
274
+ 3. **Scheduling** — Cron/interval scheduling cho automated tasks
275
+ 4. **Context % indicator** — Giúp LLM parent biết subagent còn bao nhiêu room
276
+ 5. **Batch notification grouping** — Giảm noise khi nhiều workers complete đồng thời
277
+ 6. **In-process mode** (optional) — Cho lightweight tasks không cần process isolation
278
+ 7. **Cancelable nudges** — Tránh notification spam
279
+ 8. **Agent settings hot-reload** — Thay đổi settings mà không cần restart
280
+
281
+ ### pi-subagents3 nên học từ pi-crew:
282
+
283
+ 1. **Modular architecture** — Tách `index.ts` thành nhiều files
284
+ 2. **State persistence** — Durable state thay vì chỉ in-memory
285
+ 3. **Crash recovery** — Detect interrupted runs, deadletter
286
+ 4. **Observability** — Metrics, monitoring, health checks
287
+ 5. **Team support** — Multi-agent workflows
288
+ 6. **Out-of-process option** — Cho heavy tasks cần isolation
289
+ 7. **Run export/import** — Cross-machine sharing
290
+
291
+ ---
292
+
293
+ ## 7. Kết luận
294
+
295
+ **pi-subagents3** là một extension **tập trung** — làm rất tốt một việc: spawn và quản lý individual subagents. Nó tận dụng Pi SDK tối đa, in-process, interactive, với những tính năng sâu như memory và scheduling.
296
+
297
+ **pi-crew** là một **orchestration platform** — broader scope, mạnh về team workflows, state management, crash recovery, và enterprise features. Nhưng phức tạp hơn nhiều và thiếu một số tính năng "nice-to-have" mà pi-subagents3 có.
298
+
299
+ Hai extension **complement** nhau hơn là compete:
300
+ - pi-subagents3 cho **quick, interactive subagent tasks** (code review, exploration, one-off analysis)
301
+ - pi-crew cho **complex, multi-phase team workflows** (full feature implementation, multi-perspective review, parallel research)
302
+
303
+ Một kiến trúc lý tưởng có thể kết hợp: dùng pi-subagents3's in-process execution cho lightweight tasks, và pi-crew's orchestration layer cho complex workflows.
@@ -0,0 +1,41 @@
1
+ # 0001 Durable State as Source of Truth
2
+
3
+ Date: 2026-05-11
4
+
5
+ ## Status
6
+
7
+ Accepted
8
+
9
+ ## Context
10
+
11
+ pi-crew runs can last minutes to hours. Runs may be started from foreground
12
+ sessions, background processes, or async workers. Multiple observers (TUI
13
+ dashboard, status commands, event hooks) need to see the same run state.
14
+
15
+ ## Decision
16
+
17
+ All run state is stored on disk as JSON files:
18
+ - `manifest.json` — run metadata, status, config
19
+ - `tasks.json` — task graph with statuses
20
+ - `events.jsonl` — append-only event log
21
+ - `agents/{taskId}/status.json` — per-agent state
22
+
23
+ All reads go through state store. All writes use atomic write helpers and
24
+ run-level locks (`withRunLockSync`).
25
+
26
+ ## Alternatives Considered
27
+
28
+ 1. In-memory state with periodic flush. Rejected: lost on crash, inconsistent across processes.
29
+ 2. Database (SQLite). Rejected: adds native dependency, overkill for append-mostly data.
30
+
31
+ ## Consequences
32
+
33
+ Positive:
34
+ - Crash recovery is possible by reading state from disk
35
+ - Multiple processes can observe the same run
36
+ - Event log provides audit trail
37
+
38
+ Tradeoffs:
39
+ - File I/O on every state mutation (mitigated by atomic writes)
40
+ - Windows EBUSY/EPERM requires retry logic
41
+ - Lock contention under heavy concurrent access
@@ -0,0 +1,42 @@
1
+ # 0002 Child-Process for Async Runners
2
+
3
+ Date: 2026-05-12
4
+
5
+ ## Status
6
+
7
+ Accepted
8
+
9
+ ## Context
10
+
11
+ pi-crew supports two runtime modes for task execution:
12
+ - `live-session`: in-process, reuses current Pi agent session
13
+ - `child-process`: spawns a new Node process via `child-pi.ts`
14
+
15
+ Async runs (background runner, async runner) start from the current session but
16
+ continue after the session ends. Live-session mode requires the parent Pi agent
17
+ to be alive — it uses the same in-process tools and session context.
18
+
19
+ ## Decision
20
+
21
+ Async runners MUST use `child-process` mode. The `live-session` mode is only
22
+ available for foreground runs within the current Pi agent session.
23
+
24
+ Runtime policy enforces: `runtimeResolver` overrides any `live-session` request
25
+ to `child-process` when the run is async.
26
+
27
+ ## Alternatives Considered
28
+
29
+ 1. Allow live-session for async. Rejected: crashes when parent session ends, resource leaks.
30
+ 2. Persist and restore live-session. Rejected: in-process state (timers, handles) cannot be serialized.
31
+
32
+ ## Consequences
33
+
34
+ Positive:
35
+ - Async runs survive session shutdown
36
+ - No zombie timers or leaked handles from dead sessions
37
+ - Clean process isolation
38
+
39
+ Tradeoffs:
40
+ - Child process startup overhead (~2-5s)
41
+ - No shared in-process state between parent and child
42
+ - Requires all runtime config to be serializable
@@ -0,0 +1,36 @@
1
+ # 0003 Depth Guard for Nested Live-Session
2
+
3
+ Date: 2026-05-12
4
+
5
+ ## Status
6
+
7
+ Accepted
8
+
9
+ ## Context
10
+
11
+ Live-session agents run inside the current Pi agent process. If a team
12
+ workflow schedules a task that itself tries to create a team run with
13
+ live-session agents, the nested Pi agent instance attempts to spawn inside
14
+ the already-running agent. This causes stack overflow or resource exhaustion.
15
+
16
+ ## Decision
17
+
18
+ Add a depth guard: track nesting depth via environment variable
19
+ `PI_CREW_SESSION_DEPTH`. If depth >= 2, force `child-process` mode instead of
20
+ `live-session`.
21
+
22
+ ## Alternatives Considered
23
+
24
+ 1. Allow unlimited nesting. Rejected: guaranteed crash.
25
+ 2. Block nested runs entirely. Rejected: loses useful recursive team capability.
26
+ 3. Use child-process for all nested runs. Accepted — this is the depth guard.
27
+
28
+ ## Consequences
29
+
30
+ Positive:
31
+ - Nested team runs work safely via child-process
32
+ - No crash from stack overflow or resource exhaustion
33
+
34
+ Tradeoffs:
35
+ - Nested runs lose in-process speed advantage
36
+ - Environment variable tracking requires propagation
@@ -0,0 +1,34 @@
1
+ # 0004 execFileSync Over execSync
2
+
3
+ Date: 2026-05-13
4
+
5
+ ## Status
6
+
7
+ Accepted
8
+
9
+ ## Context
10
+
11
+ `gh-protocol.ts` used `execSync` with string interpolation to construct `gh`
12
+ CLI commands. This creates a command injection surface when any parameter
13
+ (user input, repo name, PR number) contains shell metacharacters.
14
+
15
+ ## Decision
16
+
17
+ Always use `execFileSync` for external commands. Pass arguments as an array,
18
+ not interpolated strings. This prevents shell injection entirely.
19
+
20
+ ## Alternatives Considered
21
+
22
+ 1. Sanitize inputs before interpolation. Rejected: fragile, easy to bypass.
23
+ 2. Shell escape functions. Rejected: another dependency, edge cases.
24
+ 3. `execFileSync` with argument array. Accepted — eliminates injection by design.
25
+
26
+ ## Consequences
27
+
28
+ Positive:
29
+ - No command injection surface
30
+ - No need for input sanitization of shell metacharacters
31
+
32
+ Tradeoffs:
33
+ - Slightly more verbose code
34
+ - Cannot use shell features (pipes, redirects) in command
@@ -0,0 +1,49 @@
1
+ # 0005 No TypeScript Parameter Properties
2
+
3
+ Date: 2026-05-13
4
+
5
+ ## Status
6
+
7
+ Accepted
8
+
9
+ ## Context
10
+
11
+ Pi uses Node.js `--experimental-strip-types` mode to run TypeScript directly
12
+ without transpilation. This mode strips `type` annotations but does NOT
13
+ transform TypeScript-only syntax like parameter properties
14
+ (`constructor(private foo: string)`).
15
+
16
+ ## Decision
17
+
18
+ Never use TypeScript parameter properties. Always declare fields explicitly
19
+ and assign them in the constructor body:
20
+
21
+ ```typescript
22
+ // DO NOT:
23
+ class Foo {
24
+ constructor(private bar: string) {}
25
+ }
26
+
27
+ // DO:
28
+ class Foo {
29
+ private bar: string;
30
+ constructor(bar: string) {
31
+ this.bar = bar;
32
+ }
33
+ }
34
+ ```
35
+
36
+ ## Alternatives Considered
37
+
38
+ 1. Use tsx/ts-node for transpilation. Rejected: Pi doesn't bundle these.
39
+ 2. Use parameter properties + hope Node adds support. Rejected: runtime crash.
40
+
41
+ ## Consequences
42
+
43
+ Positive:
44
+ - Code runs correctly under Node strip-types mode
45
+ - No transpilation dependency
46
+
47
+ Tradeoffs:
48
+ - More verbose class definitions
49
+ - Easy to accidentally use parameter properties (caught by typecheck + test)
@@ -0,0 +1,63 @@
1
+ # 0006 Publish a Bundled ESM Build
2
+
3
+ Date: 2026-05-14
4
+
5
+ ## Status
6
+
7
+ Proposed — not yet implemented.
8
+
9
+ ## Context
10
+
11
+ Cold-start `register-startup.import.p95` is dominated by Node's
12
+ `--experimental-strip-types` parsing of ~150 .ts files in src/. Sprint
13
+ 2 lazy-loading reduced top-level import cost from 655 ms to 531 ms but
14
+ the parse cost still dominates because Pi loads pi-crew via jiti. A
15
+ single bundled `dist/index.mjs` (esbuild target node22, ESM, source-map
16
+ preserved, peer deps externalized) would skip per-file parse + module
17
+ resolution and is the next big lever.
18
+
19
+ ## Decision (proposed)
20
+
21
+ Adopt a dual-ship layout for one release cycle:
22
+
23
+ - `index.ts` → keeps current behaviour (Pi via jiti).
24
+ - `dist/index.mjs` → published under `package.json#exports["."]` with
25
+ appropriate `default` / `import` keys; tree-shaken; peers external.
26
+ - `pi.extensions[]` updated to `[ "./dist/index.mjs" ]` only after a
27
+ smoke test pass on Linux + macOS + Windows.
28
+
29
+ If smoke fails on any OS, dual-ship is kept indefinitely and the
30
+ extension key falls back to `./index.ts`.
31
+
32
+ ## Alternatives considered
33
+
34
+ 1. Pre-compile to .js (tsc) — same run-time hit because Pi still loads
35
+ many files; only saves the strip-types step.
36
+ 2. SWC bundle — faster than esbuild but adds another tool. esbuild is
37
+ already in the npm ecosystem and well-tested for Node ESM.
38
+ 3. Status quo — keeps p95 ≈ 530 ms which is fine for non-interactive
39
+ use but visible on first widget paint.
40
+
41
+ ## Consequences
42
+
43
+ Positive:
44
+ - Cold-start `register-startup.import.p95` projected to drop to ~150–
45
+ 250 ms on the same hardware.
46
+ - Source-map preserved so error stacks still point at .ts lines.
47
+
48
+ Tradeoffs / risks:
49
+ - Pi extension loader behaviour with bundled ESM is unverified across
50
+ versions. Dual-ship lets us roll back if any OS breaks.
51
+ - Bundle invalidates lazy-import boundaries at file granularity; we'll
52
+ rely on `import()` calls at code-level boundaries instead.
53
+ - `npm pack --dry-run` size grows by one extra file; offset by deleting
54
+ unused .ts in publish step. Net wire size lower because fewer files.
55
+
56
+ ## Next steps
57
+
58
+ 1. Prototype on `perf/bundle-prototype` branch; measure delta with
59
+ `npm run profile:startup`.
60
+ 2. Add `scripts/build-bundle.mjs`.
61
+ 3. Run `npm run smoke:release` on all 3 OS images.
62
+ 4. Update `package.json#exports`, `pi.extensions[]`, `files[]`.
63
+ 5. Land ADR as "Accepted" only after dual-ship soak.
@@ -0,0 +1,54 @@
1
+ # 0007 Active-Run Registry Binary Index
2
+
3
+ Date: 2026-05-14
4
+
5
+ ## Status
6
+
7
+ Proposed — not yet implemented.
8
+
9
+ ## Context
10
+
11
+ `active-run-registry.ts` performs ~10 syscalls per registry lookup
12
+ (JSONL append, readdirSync of state/runs, statSync per directory).
13
+ On `session_start` this dominates extension wake-up time when the user
14
+ has many historical runs.
15
+
16
+ ## Decision (proposed)
17
+
18
+ Replace the JSONL-backed registry with a small binary index file
19
+ (`<crewRoot>/state/active-runs.bin`) using a length-prefixed
20
+ msgpack-style record. A single read populates an in-memory map.
21
+
22
+ For backwards compatibility, the loader continues to parse the legacy
23
+ JSONL when the binary file is absent, and writes both formats during a
24
+ 2-release transition. Readers prefer binary when both exist.
25
+
26
+ ## Alternatives considered
27
+
28
+ 1. SQLite — adds a native dependency that breaks Node's strip-types
29
+ loader; rejected.
30
+ 2. Just cache the JSONL parse — only saves on subsequent session_start
31
+ within the same process; doesn't help cold start across processes.
32
+ 3. Memory-mapped file — more complex; similar throughput.
33
+
34
+ ## Consequences
35
+
36
+ Positive:
37
+ - One read replaces O(N) syscalls.
38
+ - Index can carry derived metadata (run.status snapshot) so the
39
+ widget can render without touching individual run dirs.
40
+
41
+ Tradeoffs / risks:
42
+ - Custom format requires test coverage for partial writes / corruption.
43
+ - Migration window needs operational care: any tool reading the legacy
44
+ JSONL must continue to work for 2 releases.
45
+ - Binary corruption recovery: fall back to JSONL truth source and
46
+ rewrite binary from scratch.
47
+
48
+ ## Next steps
49
+
50
+ 1. Define schema (run id, status, started-at, sessionId, pid).
51
+ 2. Implement reader/writer with checksum per record.
52
+ 3. Backwards compat: read binary if present, else JSONL; write both.
53
+ 4. After 2 release cycles, drop JSONL writer.
54
+ 5. Land ADR as "Accepted" once migration complete.