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
package/index.bundle.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- * Bundle entry point — NO shell logic.
3
- *
4
- * Bundled by `scripts/build-bundle.mjs` into `dist/index.mjs`. Keep this
5
- * file minimal — the bundle should NOT try to recursively load itself
6
- * or do path resolution. The shell (load-with-fallback) lives in
7
- * `index.ts`; this file just re-exports the inner extension API so the
8
- * bundle is a single self-contained module the shell can `import()`.
9
- *
10
- * Why a separate file from `index.ts`:
11
- * - `index.ts` runs at the package root and resolves `dist/index.mjs`
12
- * relative to its own location.
13
- * - If the bundle were built FROM `index.ts`, the bundled code would
14
- * resolve `dist/index.mjs` relative to ITS OWN location (inside
15
- * `dist/`), producing `dist/dist/index.mjs` and a recursion error.
16
- * - Building from `index.bundle.ts` (which has no shell) sidesteps
17
- * this chicken-and-egg entirely.
18
- */
19
- import { registerPiTeams } from "./src/extension/register.ts";
20
- import { waitForRun } from "./src/runtime/run-tracker.ts";
21
-
22
- export { waitForRun, registerPiTeams };
23
- export default function (pi: Parameters<typeof registerPiTeams>[0]): void {
24
- registerPiTeams(pi);
25
- }
@@ -1,96 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Compare test/bench/results.json against test/bench/baseline.json.
4
- *
5
- * Fails if any p95 metric regresses by more than the allowed threshold.
6
- *
7
- * Usage:
8
- * npm run bench:check # default 15% threshold
9
- * THRESHOLD_PCT=10 npm run bench:check # tighter
10
- * BASELINE=test/bench/baseline.json npm run bench:check
11
- */
12
- import * as fs from "node:fs";
13
- import * as path from "node:path";
14
-
15
- const root = path.resolve(import.meta.dirname, "..");
16
- const benchDir = path.join(root, "test", "bench");
17
- const resultsPath = path.join(benchDir, "results.json");
18
- const baselinePath = process.env.BASELINE ? path.resolve(process.env.BASELINE) : path.join(benchDir, "baseline.json");
19
- const threshold = Number(process.env.THRESHOLD_PCT ?? 15) / 100;
20
-
21
- if (!fs.existsSync(resultsPath)) {
22
- console.error(`[bench:check] missing ${resultsPath}; run \`npm run bench\` first.`);
23
- process.exit(2);
24
- }
25
- if (!fs.existsSync(baselinePath)) {
26
- console.error(`[bench:check] missing baseline ${baselinePath}.`);
27
- console.error(" Capture baseline with: npm run bench && cp test/bench/results.json test/bench/baseline.json");
28
- process.exit(2);
29
- }
30
-
31
- const results = JSON.parse(fs.readFileSync(resultsPath, "utf-8"));
32
- const baseline = JSON.parse(fs.readFileSync(baselinePath, "utf-8"));
33
-
34
- /**
35
- * Walk each bench's nested numeric metrics and pair with baseline.
36
- * Reports any p95 metric where current > baseline * (1 + threshold).
37
- */
38
- const regressions = [];
39
- const improvements = [];
40
- for (const [benchName, current] of Object.entries(results.results)) {
41
- const base = baseline.results?.[benchName];
42
- if (!base) {
43
- console.log(`[bench:check] no baseline for ${benchName} — skipping`);
44
- continue;
45
- }
46
- for (const metric of metricKeys(current)) {
47
- const cur = readPath(current, metric);
48
- const ref = readPath(base, metric);
49
- if (typeof cur !== "number" || typeof ref !== "number" || ref === 0) continue;
50
- // Sub-ms metrics are dominated by GC / OS jitter — applying a strict
51
- // percentage gate causes false positives. Use absolute delta cap instead.
52
- if (ref < 1.0) {
53
- const absDelta = cur - ref;
54
- if (absDelta > 0.5) regressions.push({ bench: benchName, metric: metric.join("."), baseline: ref, current: cur, deltaPct: round(((cur - ref) / ref) * 100), reason: "abs > 0.5ms" });
55
- else if (absDelta < -0.05) improvements.push({ bench: benchName, metric: metric.join("."), baseline: ref, current: cur, deltaPct: round(((cur - ref) / ref) * 100) });
56
- continue;
57
- }
58
- const delta = (cur - ref) / ref;
59
- if (delta > threshold) regressions.push({ bench: benchName, metric: metric.join("."), baseline: ref, current: cur, deltaPct: round(delta * 100) });
60
- else if (delta < -0.05) improvements.push({ bench: benchName, metric: metric.join("."), baseline: ref, current: cur, deltaPct: round(delta * 100) });
61
- }
62
- }
63
-
64
- if (improvements.length) {
65
- console.log("[bench:check] improvements:");
66
- for (const item of improvements) console.log(` ${item.bench}.${item.metric}: ${item.baseline} → ${item.current} (${item.deltaPct}%)`);
67
- }
68
- if (regressions.length) {
69
- console.error(`[bench:check] regressions (>${(threshold * 100).toFixed(0)}%):`);
70
- for (const item of regressions) console.error(` ${item.bench}.${item.metric}: ${item.baseline} → ${item.current} (+${item.deltaPct}%)`);
71
- process.exit(1);
72
- }
73
- console.log(`[bench:check] all benches within ${(threshold * 100).toFixed(0)}% of baseline.`);
74
-
75
- function metricKeys(obj, prefix = []) {
76
- const skip = new Set(["name", "unit", "iters", "tasks", "events", "eventsPerIter"]);
77
- const keys = [];
78
- for (const [k, v] of Object.entries(obj)) {
79
- if (skip.has(k)) continue;
80
- if (k === "p50" || k === "p95" || k === "p99" || k === "min" || k === "max") {
81
- // We only gate on p95; min/max printed but not enforced.
82
- if (k === "p95") keys.push([...prefix, k]);
83
- continue;
84
- }
85
- if (v && typeof v === "object" && !Array.isArray(v)) keys.push(...metricKeys(v, [...prefix, k]));
86
- }
87
- return keys;
88
- }
89
-
90
- function readPath(obj, parts) {
91
- let cur = obj;
92
- for (const p of parts) cur = cur?.[p];
93
- return cur;
94
- }
95
-
96
- function round(n) { return Math.round(n * 100) / 100; }
@@ -1,216 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Cold-start benchmark: bundle vs strip-types.
4
- *
5
- * Compares two entry paths from a fresh node process:
6
- * - STRIP-TYPES: node --experimental-strip-types loads src/extension/register.ts
7
- * (or src/extension/index.ts via the package entry)
8
- * - BUNDLE: node loads dist/index.mjs (esbuild-bundled 2.9MB single file)
9
- *
10
- * For each path we spawn N child node processes and measure:
11
- * - totalMs: time from process spawn to its exit
12
- * - importMs: time the child reports for `await import(...)`
13
- * - registerMs: time the child reports for registerPiTeams(mockPi)
14
- *
15
- * We report:
16
- * - per-path median, p95, max for each metric
17
- * - bundle vs strip-types speedup (negative = bundle faster)
18
- *
19
- * Usage:
20
- * node scripts/bench-cold-start.mjs # default 10 iters
21
- * node scripts/bench-cold-start.mjs --iters 20
22
- *
23
- * Output goes to stdout as JSON plus a human-readable summary.
24
- */
25
- import { execFileSync, spawnSync } from "node:child_process";
26
- import * as fs from "node:fs";
27
- import * as path from "node:path";
28
- import { pathToFileURL } from "node:url";
29
-
30
- const root = path.resolve(import.meta.dirname, "..");
31
- const args = process.argv.slice(2);
32
- let iters = 10;
33
- for (let i = 0; i < args.length; i++) {
34
- if (args[i] === "--iters" && args[i + 1]) {
35
- iters = Number(args[i + 1]);
36
- i++;
37
- }
38
- }
39
-
40
- // Driver template. We capture wall-clock per sample using performance.now()
41
- // and emit JSON lines (one per sample). The outer harness parses them.
42
- const driverTemplate = (entrySpec, registerImport) => `
43
- import { performance } from "node:perf_hooks";
44
-
45
- const tSpawn = performance.now();
46
-
47
- function createEvents() {
48
- const handlers = new Map();
49
- return {
50
- on(event, handler) {
51
- const set = handlers.get(event) ?? new Set();
52
- set.add(handler);
53
- handlers.set(event, set);
54
- return () => set.delete(handler);
55
- },
56
- emit(event, payload) {
57
- for (const h of handlers.get(event) ?? []) h(payload);
58
- },
59
- };
60
- }
61
-
62
- const mockPi = {
63
- cwd: process.cwd(),
64
- events: createEvents(),
65
- hasUI: false,
66
- getFlag: () => undefined,
67
- getAllFlags: () => ({}),
68
- settings: {},
69
- storage: undefined,
70
- on() {},
71
- registerTool() {},
72
- registerCommand() {},
73
- appendEntry: async () => undefined,
74
- sendMessage: async () => undefined,
75
- sendUserMessage: async () => undefined,
76
- };
77
-
78
- const tImport0 = performance.now();
79
- const entry = await import(${JSON.stringify(entrySpec)});
80
- const tImportMs = performance.now() - tImport0;
81
-
82
- const register = ${registerImport};
83
-
84
- const tReg0 = performance.now();
85
- register(mockPi);
86
- const tRegMs = performance.now() - tReg0;
87
-
88
- const tTotal = performance.now();
89
- process.stdout.write(JSON.stringify({
90
- total: tTotal - tSpawn,
91
- import: tImportMs,
92
- register: tRegMs,
93
- defaultKind: typeof entry.default,
94
- hasRegister: typeof ${registerImport === "entry.registerPiTeams" ? "entry.registerPiTeams" : "register"},
95
- }) + "\\n");
96
- `;
97
-
98
- async function runPath(label, entrySpec, registerImport, itersCount) {
99
- const driverPath = path.join(root, `.bench-${label}-${process.pid}.mjs`);
100
- const driverSrc = driverTemplate(entrySpec, registerImport);
101
- fs.writeFileSync(driverPath, driverSrc, "utf-8");
102
-
103
- const cmd = label === "strip-types"
104
- ? ["--experimental-strip-types", "--no-warnings", driverPath]
105
- : ["--no-warnings", driverPath];
106
-
107
- const samples = [];
108
- for (let i = 0; i < itersCount; i++) {
109
- const t0 = performance.now();
110
- const r = spawnSync(process.execPath, cmd, { encoding: "utf-8", cwd: root });
111
- const wall = performance.now() - t0;
112
- if (r.status !== 0) {
113
- console.error(`[bench:${label}] iter ${i} failed:`, r.stderr?.slice(0, 200));
114
- continue;
115
- }
116
- const lastLine = r.stdout.trim().split("\n").pop();
117
- try {
118
- const sample = JSON.parse(lastLine);
119
- samples.push({ ...sample, wall });
120
- } catch {
121
- console.error(`[bench:${label}] iter ${i} parse error:`, lastLine);
122
- }
123
- }
124
-
125
- fs.unlinkSync(driverPath);
126
- return samples;
127
- }
128
-
129
- function stats(arr) {
130
- const sorted = [...arr].sort((a, b) => a - b);
131
- const p = (q) => sorted[Math.min(sorted.length - 1, Math.floor((sorted.length - 1) * q))];
132
- return {
133
- n: sorted.length,
134
- min: sorted[0],
135
- p50: p(0.5),
136
- p95: p(0.95),
137
- max: sorted[sorted.length - 1],
138
- mean: sorted.reduce((s, x) => s + x, 0) / sorted.length,
139
- };
140
- }
141
-
142
- function pctDelta(newer, older) {
143
- // positive = newer is slower than older
144
- return (((newer - older) / older) * 100).toFixed(1);
145
- }
146
-
147
- console.log(`[bench] Running ${iters} iters per path...`);
148
- console.log("");
149
-
150
- const stripSpec = pathToFileURL(path.join(root, "src/extension/register.ts")).href;
151
- const stripRegister = "(await import(" + JSON.stringify(stripSpec) + ")).registerPiTeams";
152
- const stripSamples = await runPath("strip-types", stripSpec, stripRegister, iters);
153
-
154
- const bundleSpec = pathToFileURL(path.join(root, "dist/index.mjs")).href;
155
- const bundleRegister = "(await import(" + JSON.stringify(bundleSpec) + ")).registerPiTeams";
156
- const bundleSamples = await runPath("bundle", bundleSpec, bundleRegister, iters);
157
-
158
- if (stripSamples.length === 0 || bundleSamples.length === 0) {
159
- console.error("[bench] insufficient samples; aborting");
160
- process.exit(1);
161
- }
162
-
163
- const summary = {
164
- timestamp: new Date().toISOString(),
165
- iters,
166
- strip: {
167
- total: stats(stripSamples.map((s) => s.total)),
168
- import: stats(stripSamples.map((s) => s.import)),
169
- register: stats(stripSamples.map((s) => s.register)),
170
- wall: stats(stripSamples.map((s) => s.wall)),
171
- },
172
- bundle: {
173
- total: stats(bundleSamples.map((s) => s.total)),
174
- import: stats(bundleSamples.map((s) => s.import)),
175
- register: stats(bundleSamples.map((s) => s.register)),
176
- wall: stats(bundleSamples.map((s) => s.wall)),
177
- },
178
- };
179
-
180
- // Speedup = strip - bundle (positive = bundle faster)
181
- summary.speedup = {
182
- total: summary.strip.total.p50 - summary.bundle.total.p50,
183
- totalPct: pctDelta(summary.bundle.total.p50, summary.strip.total.p50),
184
- import: summary.strip.import.p50 - summary.bundle.import.p50,
185
- importPct: pctDelta(summary.bundle.import.p50, summary.strip.import.p50),
186
- register: summary.strip.register.p50 - summary.bundle.register.p50,
187
- registerPct: pctDelta(summary.bundle.register.p50, summary.strip.register.p50),
188
- wall: summary.strip.wall.p50 - summary.bundle.wall.p50,
189
- wallPct: pctDelta(summary.bundle.wall.p50, summary.strip.wall.p50),
190
- };
191
-
192
- // Print human-readable summary
193
- console.log("=== Cold-start benchmark: strip-types vs bundle ===\n");
194
-
195
- const printPath = (label, data) => {
196
- console.log(` ${label}:`);
197
- console.log(` total (child process wall-clock): p50=${data.total.p50.toFixed(1)}ms p95=${data.total.p95.toFixed(1)}ms min=${data.total.min.toFixed(1)}ms`);
198
- console.log(` import (await import(...)): p50=${data.import.p50.toFixed(1)}ms p95=${data.import.p95.toFixed(1)}ms`);
199
- console.log(` register (registerPiTeams(mockPi)): p50=${data.register.p50.toFixed(1)}ms p95=${data.register.p95.toFixed(1)}ms`);
200
- console.log("");
201
- };
202
-
203
- printPath("STRIP-TYPES (--experimental-strip-types + 1100 .ts files)", summary.strip);
204
- printPath("BUNDLE (dist/index.mjs, 2.9MB single file)", summary.bundle);
205
-
206
- console.log(` Speedup (bundle vs strip-types, p50):`);
207
- console.log(` total: ${summary.speedup.total >= 0 ? "FASTER" : "SLOWER"} by ${Math.abs(summary.speedup.total).toFixed(1)}ms (${summary.speedup.totalPct}%)`);
208
- console.log(` import: ${summary.speedup.import >= 0 ? "FASTER" : "SLOWER"} by ${Math.abs(summary.speedup.import).toFixed(1)}ms (${summary.speedup.importPct}%)`);
209
- console.log(` register: ${summary.speedup.register >= 0 ? "FASTER" : "SLOWER"} by ${Math.abs(summary.speedup.register).toFixed(1)}ms (${summary.speedup.registerPct}%)`);
210
- console.log(` outer wall: ${summary.speedup.wall >= 0 ? "FASTER" : "SLOWER"} by ${Math.abs(summary.speedup.wall).toFixed(1)}ms (${summary.speedup.wallPct}%)`);
211
-
212
- const benchDir = path.join(root, ".bench");
213
- fs.mkdirSync(benchDir, { recursive: true });
214
- const outFile = path.join(benchDir, `cold-start-${Date.now()}.json`);
215
- fs.writeFileSync(outFile, JSON.stringify(summary, null, 2) + "\n", "utf-8");
216
- console.log(`\n[bench] Raw results: ${outFile}`);
@@ -1,92 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * 5.5 — Bundle pi-crew into a single ESM file using esbuild.
4
- *
5
- * Output:
6
- * dist/index.mjs — bundled extension entrypoint
7
- * dist/index.mjs.map — source map
8
- *
9
- * Pi peer dependencies are kept external. Bundling shrinks parse+module-
10
- * resolution cost on cold start: with strip-types Node still has to parse
11
- * each .ts file individually, so a single .mjs cuts the per-file overhead.
12
- *
13
- * This script is invoked by `npm run build:bundle`. The `package.json#exports`
14
- * field is configured so:
15
- * - `dist/index.mjs` is the preferred entrypoint when present (set by Pi
16
- * extension loader via "pi.extensions").
17
- * - `index.ts` remains the fallback when dist/ is missing (e.g. running
18
- * directly out of a clone without prior build).
19
- */
20
- import { build } from "esbuild";
21
- import * as fs from "node:fs";
22
- import * as path from "node:path";
23
- import { fileURLToPath } from "node:url";
24
-
25
- const here = path.dirname(fileURLToPath(import.meta.url));
26
- const root = path.resolve(here, "..");
27
-
28
- const distDir = path.join(root, "dist");
29
- fs.mkdirSync(distDir, { recursive: true });
30
-
31
- const start = Date.now();
32
- const result = await build({
33
- // Bundle entry must be the bare extension (index.bundle.ts) NOT the
34
- // entry shell (index.ts). If we bundled index.ts, the bundled code
35
- // would re-resolve dist/index.mjs relative to ITS OWN location
36
- // (file:///.../dist/index.mjs), producing dist/dist/index.mjs and a
37
- // recursion error. index.bundle.ts has no shell logic so this is
38
- // a clean single-file bundle. See index.bundle.ts header for details.
39
- entryPoints: [path.join(root, "index.bundle.ts")],
40
- bundle: true,
41
- format: "esm",
42
- platform: "node",
43
- target: "node22",
44
- outfile: path.join(distDir, "index.mjs"),
45
- sourcemap: true,
46
- logLevel: "info",
47
- // Keep peer deps external so consumers' Pi versions resolve naturally.
48
- external: [
49
- "@earendil-works/pi-coding-agent",
50
- "@earendil-works/pi-ai",
51
- "@earendil-works/pi-agent-core",
52
- "@earendil-works/pi-tui",
53
- // Direct deps as well — bundling their full graph would inflate the
54
- // output and override consumer-installed versions.
55
- "cli-highlight",
56
- "diff",
57
- "jiti",
58
- "@sinclair/typebox",
59
- "acorn",
60
- // esbuild must stay external: its CJS source references __filename/__dirname
61
- // (CJS globals) for self-location. Bundling it into the ESM .mjs makes those
62
- // undefined at runtime → "__filename is not defined" when the dynamic-workflow
63
- // runner (or strip-types loader) invokes esbuild transformSync. Keeping it
64
- // external lets it resolve from node_modules as proper CJS. (esbuild also
65
- // ships a native binary, which shouldn't be bundled anyway.)
66
- "esbuild",
67
- ],
68
- // All node:* and Node-builtin modules are external by default for
69
- // platform=node, but list explicitly for clarity.
70
- //
71
- // CJS-shim banner: pi-crew's dependency graph includes CommonJS modules
72
- // (notably `yaml`) whose source calls `require("process")` etc. esbuild
73
- // emits these as runtime `__require(...)` calls; in a pure-ESM context
74
- // `require` is undefined, so we inject a `createRequire`-backed shim
75
- // at the top of the bundle. This is the standard pattern for shipping
76
- // CJS-mixed bundles as `.mjs`. See phase-2 H2 investigation (2026-06-30).
77
- banner: {
78
- js:
79
- "// pi-crew bundled by scripts/build-bundle.mjs (5.5)\n" +
80
- "// CJS-shim for legacy deps (yaml, etc.) that call require() in ESM context.\n" +
81
- "import { createRequire as __piCrewCreateRequire } from 'node:module';\n" +
82
- "const require = __piCrewCreateRequire(import.meta.url);\n" +
83
- "const module = { exports: {} };\n" +
84
- "const exports = module.exports;\n",
85
- },
86
- metafile: true,
87
- });
88
-
89
- fs.writeFileSync(path.join(distDir, "build-meta.json"), JSON.stringify(result.metafile, null, 2) + "\n", "utf-8");
90
- const elapsedMs = Date.now() - start;
91
- const stat = fs.statSync(path.join(distDir, "index.mjs"));
92
- console.log(`[build-bundle] dist/index.mjs ${(stat.size / 1024).toFixed(1)} KB in ${elapsedMs} ms`);