pi-crew 0.9.41 → 0.9.42

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 (147) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/dist/build-meta.json +7087 -6726
  3. package/dist/index.mjs +43043 -42426
  4. package/dist/index.mjs.map +4 -4
  5. package/docs/migration/atomic-write-v2-migration.md +2 -0
  6. package/docs/superpowers/plans/2026-06-09-fallow-patterns-adoption.md +2 -0
  7. package/package.json +4 -2
  8. package/scripts/README.md +6 -0
  9. package/scripts/check-all-skills.ts +3 -3
  10. package/scripts/dev-runner.mjs +106 -0
  11. package/scripts/postinstall.mjs +6 -2
  12. package/scripts/verify-skill.ts +2 -2
  13. package/src/config/config.ts +19 -0
  14. package/src/config/drift-detector.ts +97 -15
  15. package/src/config/resilient-parser.ts +4 -4
  16. package/src/extension/crew-cleanup.ts +17 -3
  17. package/src/extension/crew-vibes/index.ts +1 -1
  18. package/src/extension/cross-extension-rpc.ts +18 -5
  19. package/src/extension/management.ts +6 -5
  20. package/src/extension/register.ts +58 -1573
  21. package/src/extension/registration/command-registration.ts +57 -0
  22. package/src/extension/registration/commands.ts +2 -1
  23. package/src/extension/registration/context-builder.ts +131 -0
  24. package/src/extension/registration/crash-recovery-cache.ts +54 -0
  25. package/src/extension/registration/foreground-run-controller.ts +210 -0
  26. package/src/extension/registration/hook-registration.ts +119 -0
  27. package/src/extension/registration/lazy-configurers.ts +124 -0
  28. package/src/extension/registration/lifecycle-handlers.ts +731 -0
  29. package/src/extension/registration/observability.ts +33 -4
  30. package/src/extension/registration/registration-types.ts +149 -0
  31. package/src/extension/registration/runtime-cleanup.ts +230 -0
  32. package/src/extension/registration/subagent-manager-setup.ts +211 -0
  33. package/src/extension/registration/tool-registration.ts +50 -0
  34. package/src/extension/registration/wire-cross-extension.ts +37 -0
  35. package/src/extension/rpc-hmac.ts +21 -1
  36. package/src/extension/run-import.ts +3 -3
  37. package/src/extension/team-tool/auto-summarize.ts +4 -4
  38. package/src/extension/team-tool/cancel.ts +5 -5
  39. package/src/extension/team-tool/chain-executor.ts +5 -4
  40. package/src/extension/team-tool/context.ts +11 -1
  41. package/src/extension/team-tool/doctor.ts +2 -1
  42. package/src/extension/team-tool/goal-wrap.ts +2 -2
  43. package/src/extension/team-tool/goal.ts +1 -1
  44. package/src/extension/team-tool/handle-schedule.ts +25 -36
  45. package/src/extension/team-tool/orchestrate.ts +0 -1
  46. package/src/extension/team-tool/parallel-dispatch.ts +5 -0
  47. package/src/extension/team-tool/run.ts +220 -214
  48. package/src/extension/team-tool/workflow-manage.ts +1 -1
  49. package/src/extension/team-tool.ts +64 -16
  50. package/src/hooks/registry.ts +7 -2
  51. package/src/observability/correlation.ts +4 -3
  52. package/src/observability/event-bus.ts +10 -1
  53. package/src/observability/event-to-metric.ts +8 -7
  54. package/src/observability/exporters/adapter.ts +6 -9
  55. package/src/observability/exporters/otlp-exporter.ts +81 -0
  56. package/src/observability/metric-retention.ts +4 -0
  57. package/src/observability/metric-sink.ts +14 -4
  58. package/src/runtime/adaptive-plan.ts +1 -1
  59. package/src/runtime/async-runner.ts +13 -4
  60. package/src/runtime/background-runner.ts +32 -23
  61. package/src/runtime/capability-inventory.ts +1 -1
  62. package/src/runtime/chain-runner.ts +5 -5
  63. package/src/runtime/checkpoint.ts +6 -16
  64. package/src/runtime/child-pi.ts +22 -2
  65. package/src/runtime/coalesce-tasks.ts +1 -1
  66. package/src/runtime/crash-recovery.ts +63 -47
  67. package/src/runtime/delivery-coordinator.ts +1 -1
  68. package/src/runtime/deterministic-ast.ts +2 -2
  69. package/src/runtime/diagnostic-export.ts +2 -1
  70. package/src/runtime/foreground-control.ts +3 -2
  71. package/src/runtime/goal-loop-runner.ts +6 -2
  72. package/src/runtime/goal-state-store.ts +1 -1
  73. package/src/runtime/handoff-manager.ts +0 -2
  74. package/src/runtime/intercom-bridge.ts +0 -2
  75. package/src/runtime/live-agent-manager.ts +12 -5
  76. package/src/runtime/live-extension-bridge.ts +0 -2
  77. package/src/runtime/live-session-runtime.ts +65 -57
  78. package/src/runtime/manifest-cache.ts +59 -0
  79. package/src/runtime/mcp-proxy.ts +1 -1
  80. package/src/runtime/orphan-worker-registry.ts +3 -3
  81. package/src/runtime/output-validator.ts +1 -1
  82. package/src/runtime/path-overlap.ts +1 -1
  83. package/src/runtime/pi-args.ts +3 -3
  84. package/src/runtime/pi-json-output.ts +2 -2
  85. package/src/runtime/pipeline-runner.ts +1 -4
  86. package/src/runtime/post-checks.ts +0 -1
  87. package/src/runtime/retry-runner.ts +1 -1
  88. package/src/runtime/run-coalesced-task-group.ts +0 -13
  89. package/src/runtime/scheduler.ts +2 -0
  90. package/src/runtime/session-resources.ts +1 -1
  91. package/src/runtime/settings-store.ts +31 -1
  92. package/src/runtime/skill-effectiveness.ts +2 -2
  93. package/src/runtime/stale-reconciler.ts +23 -53
  94. package/src/runtime/subagent-manager.ts +19 -3
  95. package/src/runtime/task-output-context.ts +2 -1
  96. package/src/runtime/task-runner/prompt-builder.ts +1 -1
  97. package/src/runtime/task-runner/run-projection.ts +3 -1
  98. package/src/runtime/task-runner/state-helpers.ts +13 -1
  99. package/src/runtime/task-runner.ts +31 -6
  100. package/src/runtime/team-runner.ts +3 -2
  101. package/src/runtime/verification-gates.ts +54 -5
  102. package/src/schema/config-schema.ts +19 -1
  103. package/src/schema/team-tool-schema.ts +2 -0
  104. package/src/skills/discover-skills.ts +25 -15
  105. package/src/state/active-run-registry.ts +0 -1
  106. package/src/state/atomic-write.ts +37 -11
  107. package/src/state/blob-store.ts +3 -9
  108. package/src/state/contracts.ts +5 -1
  109. package/src/state/crew-init.ts +3 -2
  110. package/src/state/decision-ledger.ts +2 -2
  111. package/src/state/event-log-rotation.ts +1 -1
  112. package/src/state/event-log.ts +3 -3
  113. package/src/state/gitignore-manager.ts +2 -1
  114. package/src/state/health-store.ts +5 -2
  115. package/src/state/instinct-store.ts +11 -2
  116. package/src/state/mailbox.ts +3 -4
  117. package/src/state/observation-store.ts +1 -13
  118. package/src/state/run-cache.ts +12 -12
  119. package/src/state/run-graph.ts +2 -1
  120. package/src/state/run-metrics.ts +1 -1
  121. package/src/state/schedule.ts +7 -1
  122. package/src/state/state-store.ts +9 -3
  123. package/src/state/tiered-eval.ts +1 -1
  124. package/src/ui/dynamic-border.ts +13 -3
  125. package/src/ui/live-conversation-overlay.ts +7 -27
  126. package/src/ui/live-duration.ts +2 -2
  127. package/src/ui/live-run-sidebar.ts +56 -32
  128. package/src/ui/mascot.ts +19 -13
  129. package/src/ui/powerbar-publisher.ts +244 -178
  130. package/src/ui/render-coalescer.ts +44 -3
  131. package/src/ui/render-diff.ts +2 -2
  132. package/src/ui/run-dashboard.ts +122 -21
  133. package/src/ui/run-event-bus.ts +66 -0
  134. package/src/ui/run-snapshot-cache.ts +84 -81
  135. package/src/ui/settings-overlay.ts +3 -3
  136. package/src/ui/status-colors.ts +24 -0
  137. package/src/ui/tool-progress-formatter.ts +1 -1
  138. package/src/ui/tool-render.ts +3 -3
  139. package/src/ui/transcript-cache.ts +5 -10
  140. package/src/ui/transcript-entries.ts +68 -72
  141. package/src/ui/transcript-viewer.ts +54 -14
  142. package/src/ui/widget/index.ts +26 -15
  143. package/src/ui/widget/widget-model.ts +18 -9
  144. package/src/ui/widget/widget-renderer.ts +2 -5
  145. package/src/utils/fingerprint.ts +1 -1
  146. package/src/utils/project-detector.ts +1 -1
  147. package/src/state/atomic-write-v2.ts +0 -108
package/CHANGELOG.md CHANGED
@@ -1,5 +1,111 @@
1
1
  # Changelog
2
2
 
3
+ > **Note:** `atomic-write-v2.ts` / `AtomicWriter` mentioned in historical entries below was consolidated into `atomic-write.ts` as of v0.9.42. This changelog is preserved as historical record — the migration was completed (the v2 class was never adopted; v1 won on simplicity + symlink-safety + link+unlink atomicity). See `docs/migration/atomic-write-v2-migration.md` for the decision rationale.
4
+
5
+ ## [0.9.42] — 107-finding deep review + arch cleanup (2026-07-17)
6
+
7
+ ### Deep Review Resolution
8
+
9
+ A full-codebase audit (8 parallel agents, 107 findings across P0/P1/P2/P3 + UI) was completed and **all 107 findings were addressed**. The audit covered runtime, state durability, subagents, observability+config, UI/TUI, extension/team-tool, security STRIDE, and tests/build.
10
+
11
+ ### Reliability / Runtime (4 fixes)
12
+
13
+ - **RT-F7** — `src/runtime/goal-loop-runner.ts`. Replaced bare `require()` in ESM context with `createRequire(import.meta.url)`. Resolves the `ReferenceError: require is not defined` failure that would silently break goal-wrap builtin resolution under Node 22.6+ strip-types loader.
14
+ - **RT-F2** — `src/extension/registration/observability.ts`. Added `before_agent_start` hook to opportunistically tick `reconcileAllStaleRuns` on every user turn. Auto-repair interval default raised 60s → 5min since `.unref()`-d timers don't fire when event loop is idle.
15
+ - **RT-F3** — `src/runtime/manifest-cache.ts`. Added `listActive(limit)` method that filters `status === 'running'` BEFORE applying the cap, so orphaned runs past top-N are no longer hidden.
16
+ - **RT-F5** — `src/runtime/crash-recovery.ts`. Wrapped the orphan-cancellation block in `purgeStaleActiveRunIndex` (conditions 5 + 6) with `withRunLockSync`, with a fresh read under the lock to defeat TOCTOU.
17
+
18
+ ### Subagents (3 fixes)
19
+
20
+ - **SUB-H2/H3** — `src/runtime/async-runner.ts`. Added `child.on('exit')` handler that calls `unregisterWorker(child.pid)` — previously the orphan-worker registry never got cleaned up until next session_start.
21
+ - **SUB-M4** — `src/runtime/subagent-manager.ts`. Added 30-minute max lifetime guard (1800 polls at 1s) to `pollRunToTerminal` so a missing manifest file cannot cause an infinite poll loop.
22
+ - **SUB-M1/M2/M3** — guarded session subscribe callback exceptions; added liveness check before evicting slow-but-alive running agents; capped `ChildPiLineObserver` buffer at 1MB.
23
+
24
+ ### State durability (8 fixes)
25
+
26
+ - **ST-2/3/4** — `src/state/{health-store,instinct-store,run-cache}.ts`. Replaced raw `writeFileSync` / non-atomic writes with `atomicWriteFile` / `atomicWriteJson`.
27
+ - **ST-5** — `src/runtime/checkpoint.ts`. Replaced hand-rolled atomic write (which skipped data fsync) with `atomicWriteFile`.
28
+ - **ST-7** — `src/state/atomic-write.ts`. Added `skipCoalesce` option to `atomicWriteJsonCoalesced` so terminal transitions bypass the 50ms coalescer (avoids stale-task-status on resume after SIGKILL).
29
+ - **ST-8** — `src/state/atomic-write.ts` + deleted `src/state/atomic-write-v2.ts`. Consolidated the v2 `AtomicWriter` class into the primary impl; v2 was 0-importers in production.
30
+ - **ST-12** — deleted stray `src/state/test_write.txt` test artifact.
31
+
32
+ ### Config / schema (4 fixes)
33
+
34
+ - **CFG-1** — `src/config/config.ts` + `src/schema/config-schema.ts`. Wired 10 previously-phantom config fields (`reliability.autoRepairIntervalMs`, `scopeModels`, `forcePreflight`, etc.) into both parser and TypeBox schema with `additionalProperties: false` enforced.
35
+ - **CFG-2** — `test/unit/config-schema-sync.test.ts` (new). Compile-time sync test verifying every `PiTeamsConfig` key exists in `PiTeamsConfigSchema` (prevents future drift).
36
+ - **CFG-3** — `src/config/drift-detector.ts`. Recursive depth-3 nested key checker emits unknown nested keys as dotted paths (was top-level only).
37
+ - **CFG-5** — `src/config/resilient-parser.ts`. Collect ALL errors per field instead of returning on first.
38
+
39
+ ### Security / hardening (6 fixes)
40
+
41
+ - **SEC-03 / AUDIT-03** — `src/extension/cross-extension-rpc.ts` + `src/extension/rpc-hmac.ts`. Moved the noisy HMAC startup warning from `registerPiCrewRpc` (fires every pi load) to `withHmacVerification` (fires only on actual RPC traffic). Soft tone; opt-out via `PI_CREW_SUPPRESS_RPC_WARNING=1`.
42
+ - **SEC-04** — `src/runtime/task-runner/run-projection.ts`. Mailbox message bodies are now wrapped in `<untrusted_data source="mailbox">` delimiters before injection into worker prompts.
43
+ - **SEC-08** — `src/runtime/task-runner.ts`. Replaced string-concatenated steering file paths with `resolveContainedPath()` for path-containment validation.
44
+ - **CFG-6** — `src/observability/exporters/otlp-exporter.ts`. Added async DNS-resolution + private IP check (blocks DNS rebinding to metadata IPs 169.254.x, 10.x, 172.16-31.x, 192.168.x, 127.x).
45
+ - **AUDIT-06** — `src/hooks/registry.ts` + `src/extension/team-tool.ts`. Pre-step execution now emits `hook.pre_step_started`, `hook.pre_step_completed`, `hook.pre_step_failed` events for audit trail. `resolveRealContainedPath()` placed outside `preStepOptional` catch so path traversal is always fatal.
46
+ - **AUDIT-05** — explicit dispatch-time warning that `.dwf.ts` runs as trusted Node.js with full `process` / `require` / `import` access.
47
+
48
+ ### Extension / team-tool (8 fixes)
49
+
50
+ - **EXT-2** — `src/extension/team-tool/run.ts`. Extracted `formatRunResult(manifest, options)` helper unifying 3 triplicated result-formatting blocks (eliminated ~210 lines of divergence).
51
+ - **EXT-3** — `src/extension/team-tool/handle-schedule.ts`. `Number.isFinite()` guards on `interval`/`once` to prevent `new Date(NaN).toISOString()` `RangeError`.
52
+ - **EXT-4** — `src/schema/team-tool-schema.ts`. Added `subAction` / `jobId` to the TypeBox schema (was in TS interface but stripped by strict validators).
53
+ - **EXT-5** — signal handlers (`SIGTERM`/`SIGHUP`) idempotent via `signalHandlersRegistered` module flag; tools/commands still re-register per Pi platform constraint (test pins both behaviors).
54
+ - **EXT-6** — `src/extension/team-tool/cancel.ts`. Standardized `confirm` / `force` checks to `=== true` (literal) instead of truthy.
55
+ - **EXT-7** — `src/extension/team-tool.ts` + `src/extension/register.ts`. Refactored `installCrewGlobalRegistry()` to take optional `{ manifestCache, cwdProvider }` deps and build the entire registry in one atomic step (no stubs mid-flight).
56
+ - **EXT-10** — `src/extension/team-tool/run.ts`. `runKind` on non-dynamic workflows now logs `team-tool.run.runKindIgnored` warning and is silently dropped.
57
+ - **EXT-13** — `src/hooks/registry.ts`. Hook `modify` outcome uses existing `sanitizeMergeData(result.data)` deep-clone before assignment to `ctx` and `capturedModifications`.
58
+
59
+ ### Observability (3 fixes)
60
+
61
+ - **OBS-2** — `src/observability/metric-sink.ts`. Replaced `fs.writeSync(fd, data)` on main thread with async `fs.write` (callback-fired fire-and-forget).
62
+ - **OBS-6** — `src/observability/event-bus.ts`. Added `MAX_LISTENERS_PER_EVENT = 100` cap with `logInternalError` warning when exceeded.
63
+ - **OBS-5** — `src/observability/metric-retention.ts`. Documented O(N) `TimeWindowedCounter.count()` limitation in-place (deferred fix).
64
+
65
+ ### UI / TUI (9 fixes)
66
+
67
+ - **FIND-04/05/UI-P1-1/2/3** — `src/ui/{run-dashboard,live-run-sidebar,widget,run-snapshot-cache,run-event-bus}.ts`. Routed 3 overlay subscriptions through `RenderScheduler` (debounced), added 100ms signature TTL cache, replaced O(N) per-task `mailboxStamp` with single tasks-dir stat, added `runEventBusAsRenderScheduler(channels)` adapter.
68
+ - **FIND-06** — `src/ui/transcript-viewer.ts`. 500ms short-TTL `readRunTranscript` cache keyed by `(runId, taskId, full, maxTailBytes)`.
69
+ - **FIND-08** — `src/ui/run-snapshot-cache.ts`. Shared `computeSliceSignatures(input)` hoists slice hashing; both `signatureFor` and `sliceSignaturesFor` reuse it.
70
+ - **FIND-10/12/13/15/16/18/23** — `.unref()` on render coalescer timer; Map insertion-order LRU eviction; microtask-batched emit; instance-level powerbar state; O(n²)→O(n) tool_call→tool_result Map lookup; dropped-event callback in coalescer.
71
+ - **FIND-14** — `src/ui/settings-overlay.ts`. Broadened ASCII-only text input to all non-control Unicode (CJK / IME input now works).
72
+ - **FIND-17** — `src/ui/live-duration.ts`. Lowered ms range threshold `100B` → `10B` to close `[10B, 100B)` detection gap.
73
+ - **FIND-19/20/21/22** — cached `char.repeat()` in dynamic-border; fast-path regex in status-colors; single `Date.now()` per render frame; in-place grid mutation in mascot glitch (eliminates GC pressure).
74
+
75
+ ### Architectural cleanup (4 fixes)
76
+
77
+ - **ST-8** (re-listed) + `register.ts` decomposition — `src/extension/register.ts` shrunk from **1578 → 108 lines**. The monolith was split into 14+ focused modules under `src/extension/registration/` (tool-registration, command-registration, hook-registration, lifecycle-handlers, subagent-manager-setup, etc.).
78
+ - **TB-2** — `test/unit/register-registration.test.ts` (6 tests) pins the public API contract of `registerPiTeams` (including the EXT-5 signal-listener idempotency invariant).
79
+ - **P0-6 partial** — `src/ui/{live-run-sidebar,run-dashboard,widget}.ts`. Snapshot-only render path; removed sync `readFileSync` fallbacks (uses `snapshotCache.get(runId)` exclusively; returns `["(loading…")` on first frame).
80
+
81
+ ### Tests / CI (8 additions)
82
+
83
+ - `test/unit/bundle-load.test.ts` — exercises shipped `dist/index.mjs` (catches stale-bundle class of regression). **Now integrated into `.github/workflows/ci.yml`** via `npm run build:bundle && npm run test:bundle` step.
84
+ - `test/unit/cross-extension-rpc.test.ts` — 4 regression tests for swapped-args cwd bypass.
85
+ - `test/unit/config-phantom-fields.test.ts` — verifies all 10 previously-phantom fields round-trip.
86
+ - `test/unit/config-schema-sync.test.ts` — compile-time schema/type sync.
87
+ - `test/unit/prestep-audit-events.test.ts` — pre-step audit event types + path-validation ordering.
88
+ - `test/unit/event-to-metric.test.ts` — high-cardinality label drop regression.
89
+ - `test/unit/stale-reconciler.test.ts` — ESRCH immediate-repair regression.
90
+ - `test/unit/{build-knowledge-fragment,compact-stages,cancel-ownership,drift-detector,round25-injection-guards,team-tool-run,atomic-write-coalesced,manifest-cache-list-active,crash-recovery-purge-lock}.test.ts` — coverage additions.
91
+
92
+ ### Infrastructure
93
+
94
+ - **`.github/workflows/weekly-smoke.yml`** — Monday 9am UTC scheduled smoke run (cheap canary).
95
+ - **`scripts/dev-runner.mjs`** + `npm run dev` — combined bundle-watch + test-watch.
96
+ - **`scripts/postinstall.mjs`** — bundle-build failures now log to stderr with red ANSI color (was silent `console.warn`).
97
+ - **`scripts/check-lazy-imports.mjs`** — moved `// LAZY (mild):` → exact `// LAZY:` form for consistency.
98
+ - **`biome.json`** — re-enabled `noUnusedImports`; cleaned 38 files across the codebase.
99
+
100
+ ### Stats
101
+
102
+ - **Files modified:** 70+
103
+ - **Files created:** 30+ (tests, modules, fixtures, docs)
104
+ - **Files deleted:** 2 (`atomic-write-v2.ts`, `test/unit/atomic-write-v2.test.ts`)
105
+ - **`register.ts`:** 1578 → 108 lines (93% reduction)
106
+ - **New tests:** 20+ files, 150+ test cases
107
+ - **Verified end-to-end:** `team action='run'` with fast-fix workflow → 3 real child-process workers spawned (explore → execute → verify) → file `/tmp/pi-crew-smoke-test.txt` created with exact expected content (36 bytes, SHA-256 verified).
108
+
3
109
  ## [0.9.41] — communication-layer optimization (2026-07-16)
4
110
 
5
111
  ### Performance