pi-crew 0.8.14 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +271 -0
  2. package/README.md +112 -2
  3. package/docs/FEATURE_INTAKE.md +1 -1
  4. package/docs/HARNESS.md +20 -19
  5. package/docs/PROJECT_REVIEW.md +132 -133
  6. package/docs/PROJECT_REVIEW_FIXES.md +130 -131
  7. package/docs/actions-reference.md +127 -121
  8. package/docs/architecture.md +1 -1
  9. package/docs/code-review-2026-05-11.md +134 -134
  10. package/docs/commands-reference.md +108 -106
  11. package/docs/comparison-pi-subagents-vs-pi-crew.md +105 -105
  12. package/docs/deep-review-report.md +1 -1
  13. package/docs/dynamic-workflows.md +90 -0
  14. package/docs/fixes/BATCH_A_H1_H2.md +17 -17
  15. package/docs/fixes/bug-007-async-notifier-stale-ctx.md +23 -23
  16. package/docs/followup-plan-2026-05-12.md +135 -135
  17. package/docs/followup-review-2026-05-12.md +86 -86
  18. package/docs/followup-review-round3-2026-05-12.md +123 -123
  19. package/docs/goals.md +59 -0
  20. package/docs/implementation-plan-top3.md +4 -4
  21. package/docs/issue-29-analysis.md +2 -2
  22. package/docs/oh-my-pi-research.md +154 -154
  23. package/docs/optimization-plan.md +2 -0
  24. package/docs/perf/baseline-2026-05.md +9 -9
  25. package/docs/perf/final-report-2026-05.md +2 -2
  26. package/docs/perf/sprint-1-report.md +2 -2
  27. package/docs/perf/sprint-2-report.md +1 -1
  28. package/docs/perf/upgrade-plan-2026-05.md +72 -72
  29. package/docs/pi-crew-bugs.md +230 -230
  30. package/docs/pi-crew-investigation-report.md +102 -102
  31. package/docs/pi-crew-test-round5.md +4 -4
  32. package/docs/runtime-analysis-child-vs-live.md +57 -57
  33. package/docs/runtime-migration-in-process-analysis.md +97 -97
  34. package/package.json +2 -4
  35. package/skills/orchestration/SKILL.md +11 -11
  36. package/src/agents/agent-config.ts +4 -0
  37. package/src/config/config.ts +39 -0
  38. package/src/config/types.ts +11 -0
  39. package/src/extension/action-suggestions.ts +2 -1
  40. package/src/extension/async-notifier.ts +10 -0
  41. package/src/extension/help.ts +14 -0
  42. package/src/extension/registration/commands.ts +27 -0
  43. package/src/extension/team-tool/destructive-gate.ts +1 -1
  44. package/src/extension/team-tool/goal-wrap.ts +288 -0
  45. package/src/extension/team-tool/goal.ts +405 -0
  46. package/src/extension/team-tool/run.ts +103 -4
  47. package/src/extension/team-tool/workflow-manage.ts +194 -0
  48. package/src/extension/team-tool.ts +20 -0
  49. package/src/hooks/types.ts +3 -1
  50. package/src/runtime/async-runner.ts +24 -2
  51. package/src/runtime/background-runner.ts +68 -19
  52. package/src/runtime/child-pi.ts +6 -1
  53. package/src/runtime/completion-guard.ts +1 -1
  54. package/src/runtime/dynamic-workflow-context.ts +450 -0
  55. package/src/runtime/dynamic-workflow-runner.ts +180 -0
  56. package/src/runtime/global-worker-cap.ts +96 -0
  57. package/src/runtime/goal-evaluator.ts +294 -0
  58. package/src/runtime/goal-loop-runner.ts +612 -0
  59. package/src/runtime/goal-state-store.ts +209 -0
  60. package/src/runtime/pi-args.ts +10 -2
  61. package/src/runtime/result-extractor.ts +32 -0
  62. package/src/runtime/team-runner.ts +11 -1
  63. package/src/runtime/verification-gates.ts +85 -5
  64. package/src/runtime/verification-integrity.ts +110 -0
  65. package/src/runtime/verification-worktree.ts +136 -0
  66. package/src/runtime/workspace-lock.ts +448 -0
  67. package/src/schema/config-schema.ts +26 -0
  68. package/src/schema/team-tool-schema.ts +39 -4
  69. package/src/state/atomic-write.ts +9 -0
  70. package/src/state/contracts.ts +14 -0
  71. package/src/state/crew-init.ts +18 -5
  72. package/src/state/event-log.ts +7 -1
  73. package/src/state/state-store.ts +2 -0
  74. package/src/state/types.ts +82 -0
  75. package/src/state/worker-atomic-writer.ts +176 -0
  76. package/src/utils/redaction.ts +104 -24
  77. package/src/workflows/discover-workflows.ts +25 -1
  78. package/src/workflows/workflow-config.ts +13 -0
  79. package/teams/parallel-research.team.md +1 -1
  80. package/workflows/examples/hello.dwf.ts +24 -0
@@ -1,7 +1,7 @@
1
- # pi-crew Sprint 1 Report — UI mượt rủi ro thấp
1
+ # pi-crew Sprint 1 Report — Low-risk UI smoothness
2
2
 
3
3
  Date: 2026-05-14
4
- Branch: `perf/sprint-1` (cắt từ `perf/baseline-bench`)
4
+ Branch: `perf/sprint-1` (cut from `perf/baseline-bench`)
5
5
  Status: complete
6
6
 
7
7
  ## Items shipped
@@ -1,4 +1,4 @@
1
- # pi-crew Sprint 2 Report — Cắt I/O sync hot path (partial)
1
+ # pi-crew Sprint 2 Report — Cut I/O sync hot path (partial)
2
2
 
3
3
  Date: 2026-05-14
4
4
  Branch: `perf/sprint-2`
@@ -2,110 +2,110 @@
2
2
 
3
3
  Date: 2026-05-14
4
4
  Owner: pi-crew maintainers
5
- Branch nền: `perf/baseline-bench`
5
+ Base branch: `perf/baseline-bench`
6
6
  Status: in-progress (Sprint 0 starting)
7
7
 
8
- ## Mục đích
8
+ ## Purpose
9
9
 
10
- Nâng cấp hiệu năng và UI mượt hơn vẫn giữ tính ổn định, tuân theo `AGENTS.md` task loop 5 ADR hiện hành (durable state, child-process for async, depth guard, execFileSync, no parameter properties). Plan này tập hợp 30 item nâng cấp đã phân tích, chia thành 5 sprint + 1 đợt tổng kết.
10
+ Improve performance and UI smoothness while maintaining stability, following the `AGENTS.md` task loop and the 5 current ADRs (durable state, child-process for async, depth guard, execFileSync, no parameter properties). This plan consolidates 30 analyzed upgrade items, split into 5 sprints plus 1 wrap-up phase.
11
11
 
12
- Các trục:
12
+ The tracks:
13
13
 
14
- 1. **UI mượt hơn** — cắt sync I/O khỏi render path.
15
- 2. **Runtime/state** — giảm syscall, lazy import, warm pool, refactor file lớn.
16
- 3. **Ổn định** — backpressure, heartbeat, cancel sớm, mailbox archive, kill-tree Win.
17
- 4. **Telemetry chi phí thấp** — stream sink, OTLP gzip, sample progress, histogram bucket.
18
- 5. **Build/test feedback loop** — bench gate, test concurrency, watch mode, bundle.
14
+ 1. **Smoother UI** — cut sync I/O out of the render path.
15
+ 2. **Runtime/state** — reduce syscalls, lazy imports, warm pool, refactor large files.
16
+ 3. **Stability** — backpressure, heartbeat, early cancel, mailbox archive, Windows kill-tree.
17
+ 4. **Low-cost telemetry** — stream sink, OTLP gzip, sampled progress, histogram buckets.
18
+ 5. **Build/test feedback loop** — bench gate, test concurrency, watch mode, bundling.
19
19
 
20
- ## Quy trình áp dụng cho mọi PR
20
+ ## Process applied to every PR
21
21
 
22
- - Branch: `perf/<sprint>-<id>-<slug>` cắt từ `perf/baseline-bench`.
23
- - Lane (theo `AGENTS.md`): tiny / normal / high-risk.
24
- - Validation bắt buộc trước khi merge:
22
+ - Branch: `perf/<sprint>-<id>-<slug>` cut from `perf/baseline-bench`.
23
+ - Lane (per `AGENTS.md`): tiny / normal / high-risk.
24
+ - Required validation before merge:
25
25
  - `npm run typecheck`
26
26
  - `npm run check:lazy-imports`
27
27
  - `npm test`
28
- - `npm run bench:check` — không regress > 15%
29
- - Tài liệu:
30
- - Update `CHANGELOG.md` (nhóm theo sprint).
31
- - Update `docs/TEST_MATRIX.md` khi thêm test.
32
- - Viết ADR cho mọi thay đổi contract (`docs/decisions/`).
33
- - Không gộp > 2 item vào 1 PR. Không refactor "tiện thể".
34
- - Mỗi item rủi ro cao flag tắt được ở config (`runtime.experimental.<feature>=false`).
28
+ - `npm run bench:check` — no regression > 15%
29
+ - Documentation:
30
+ - Update `CHANGELOG.md` (grouped by sprint).
31
+ - Update `docs/TEST_MATRIX.md` when adding tests.
32
+ - Write an ADR for any contract change (`docs/decisions/`).
33
+ - Do not combine > 2 items into a single PR. No "drive-by" refactors.
34
+ - Each high-risk item must have a kill switch in config (`runtime.experimental.<feature>=false`).
35
35
 
36
- ## Sprint 0 — Baseline & gate (2 ngày)
36
+ ## Sprint 0 — Baseline & gate (2 days)
37
37
 
38
- Mục đích: đo trước khi tối ưu.
38
+ Goal: measure before optimizing.
39
39
 
40
40
  | ID | Task | Files | Lane |
41
41
  |---|---|---|---|
42
42
  | S0-1 | Profile script | `scripts/profile-startup.mjs` | tiny |
43
- | S0-2 | Bench harness 3 file | `test/bench/{register-startup,render-flush,snapshot-cache}.bench.ts`, `test/bench/baseline.json` | normal |
43
+ | S0-2 | Bench harness, 3 files | `test/bench/{register-startup,render-flush,snapshot-cache}.bench.ts`, `test/bench/baseline.json` | normal |
44
44
  | S0-3 | `npm run bench` + `bench:check` | `package.json`, `scripts/bench-check.mjs` | tiny |
45
- | S0-4 | Branch nền `perf/baseline-bench` | — | — |
45
+ | S0-4 | Base branch `perf/baseline-bench` | — | — |
46
46
  | S0-5 | Capture baseline | `docs/perf/baseline-2026-05.md` | tiny |
47
47
 
48
- Exit criteria: `npm run bench` ổn định, baseline đã ghi.
48
+ Exit criteria: `npm run bench` is stable, baseline recorded.
49
49
 
50
- ## Sprint 1 — UI mượt rủi ro thấp (5 ngày)
50
+ ## Sprint 1 — Low-risk UI smoothness (5 days)
51
51
 
52
52
  | ID | Item | Lane | Acceptance |
53
53
  |---|---|---|---|
54
- | 1.1 | renderTick no-sync | tiny | Render skeleton khi preload chưa sẵn; test fs.statSync throw không crash. |
55
- | 1.2 | Async snapshot stamps | normal | Sync version chỉ CLI handler; bench p95 -30%. |
56
- | 1.4 | Stamp version counter | tiny | Dùng `events.jsonl.seq` thay `combineStamps(size)`. |
57
- | 1.5 | Stamp agents O(1) | tiny | 1 stat/run thay N. |
58
- | 1.8 | Powerbar dedup hash | tiny | 100 emit cùng payload → 1 event. |
59
- | 1.9 | subagent.completed coalescer | tiny | 10 events trong 30 ms → 1 invalidate. |
54
+ | 1.1 | renderTick no-sync | tiny | Render skeleton when preload is not ready; test that a thrown fs.statSync does not crash. |
55
+ | 1.2 | Async snapshot stamps | normal | Sync version only in the CLI handler; bench p95 -30%. |
56
+ | 1.4 | Stamp version counter | tiny | Use `events.jsonl.seq` instead of `combineStamps(size)`. |
57
+ | 1.5 | Stamp agents O(1) | tiny | 1 stat/run instead of N. |
58
+ | 1.8 | Powerbar dedup hash | tiny | 100 emits with the same payload → 1 event. |
59
+ | 1.9 | subagent.completed coalescer | tiny | 10 events within 30 ms → 1 invalidate. |
60
60
  | 1.10 | Mascot pause idle | tiny | Config `ui.mascotPauseIdleMs`. |
61
61
 
62
62
  Exit: `render-flush.bench.ts` -30%, `snapshot-cache.bench.ts` -20%.
63
63
 
64
- ## Sprint 2 — Cắt I/O sync hot path (5 ngày)
64
+ ## Sprint 2 — Cut sync I/O from the hot path (5 days)
65
65
 
66
66
  | ID | Item | Lane | Acceptance |
67
67
  |---|---|---|---|
68
68
  | 2.7 | Lazy import phase 2 | tiny | `register` end-to-end -200 ms. |
69
- | 2.10 | projectCrewRoot cache | tiny | 1000 lần gọi → 1 stat. |
70
- | 4.1 | Metric-sink stream | tiny | 10k metric → 0 sync IO hot path. |
71
- | 4.4 | Progress sample 1/10 + first/last | tiny | 100 progress → 12 trong jsonl. |
72
- | 2.1 | Atomic-write coalescer | normal | Crash trong window không corrupt; test recovery. |
73
- | 2.2 | Events.jsonl buffer 20 ms | normal | flushSync trên cleanupRuntime + session_before_switch. |
69
+ | 2.10 | projectCrewRoot cache | tiny | 1000 calls → 1 stat. |
70
+ | 4.1 | Metric-sink stream | tiny | 10k metrics → 0 sync IO on hot path. |
71
+ | 4.4 | Progress sample 1/10 + first/last | tiny | 100 progress events → 12 in jsonl. |
72
+ | 2.1 | Atomic-write coalescer | normal | A crash in the window does not corrupt; recovery test. |
73
+ | 2.2 | Events.jsonl buffer 20 ms | normal | flushSync on cleanupRuntime + session_before_switch. |
74
74
  | 2.3 | Rotation threshold 4 MB | tiny | Append 4 MB → rotate. |
75
- | 1.3 | FS watcher native | normal | Render < 100 ms từ FS event; fallback poll khi ENOSYS. |
75
+ | 1.3 | FS watcher native | normal | Render < 100 ms from FS event; poll fallback on ENOSYS. |
76
76
 
77
- Exit: 0 sync IO trong `RenderScheduler.flush`, register start ≤ 400 ms.
77
+ Exit: 0 sync IO in `RenderScheduler.flush`, register start ≤ 400 ms.
78
78
 
79
- ## Sprint 3 — Refactor & UI selectors (5 ngày)
79
+ ## Sprint 3 — Refactor & UI selectors (5 days)
80
80
 
81
81
  | ID | Item | Lane | Acceptance |
82
82
  |---|---|---|---|
83
- | 2.8 | Tách adaptive-plan | normal | `team-runner.ts` < 45 KB; lazy import khi workflow ≠ implementation. |
84
- | 2.9 | Tách config.ts | normal | `config.ts` < 20 KB; hot path không import drift/suggestions. |
85
- | 1.6 | Dashboard pane independent | normal | 1 task đổichỉ agents-pane render. |
86
- | 1.7 | Memoized snapshot slice | normal | 2 lần get cùng cache → cùng reference. |
87
- | 5.1 | Test concurrency 4 | tiny | mỗi test mkdtemp riêng PI_TEAMS_HOME. |
83
+ | 2.8 | Split out adaptive-plan | normal | `team-runner.ts` < 45 KB; lazy import when workflow ≠ implementation. |
84
+ | 2.9 | Split out config.ts | normal | `config.ts` < 20 KB; hot path does not import drift/suggestions. |
85
+ | 1.6 | Dashboard pane independent | normal | 1 task changesonly the agents-pane re-renders. |
86
+ | 1.7 | Memoized snapshot slice | normal | 2 identical get calls on the same cache → same reference. |
87
+ | 5.1 | Test concurrency 4 | tiny | each test does its own mkdtemp for a private PI_TEAMS_HOME. |
88
88
 
89
- Exit: dashboard FPS +50% khi run đang chạy.
89
+ Exit: dashboard FPS +50% while a run is active.
90
90
 
91
- ## Sprint 4 — Ổn định & telemetry (4 ngày)
91
+ ## Sprint 4 — Stability & telemetry (4 days)
92
92
 
93
93
  | ID | Item | Lane | Acceptance |
94
94
  |---|---|---|---|
95
- | 3.1 | Backpressure stdout | normal | Stress 50 MB output → memory không vượt cap. |
96
- | 3.2 | Heartbeat backoff | tiny | Stale → poll 1 s; khoẻ → 5 s. |
95
+ | 3.1 | Backpressure stdout | normal | Stress 50 MB output → memory does not exceed cap. |
96
+ | 3.2 | Heartbeat backoff | tiny | Stale → poll every 1 s; healthyevery 5 s. |
97
97
  | 3.5 | Cancel propagate < 200 ms | normal | Stream-parse JSONL + signal check. |
98
98
  | 3.6 | Deadletter cooldown | tiny | Config `reliability.deadletterCooldownMs`. |
99
- | 3.7 | Idempotent resume theo attemptId | tiny | Resume 3 lần → artifact không nhân đôi. |
100
- | 3.8 | Kill-tree Win | normal | SIGKILL fail → `taskkill /F /T`. |
99
+ | 3.7 | Idempotent resume by attemptId | tiny | Resume 3 times → artifact is not duplicated. |
100
+ | 3.8 | Kill-tree on Windows | normal | SIGKILL fail → `taskkill /F /T`. |
101
101
  | 3.4 | Atomic-write jitter | tiny | Jitter ±20%, max 8 attempts. |
102
- | 3.3 | Mailbox auto-archive | normal | 11 MB → rotate vào blob-store. |
102
+ | 3.3 | Mailbox auto-archive | normal | 11 MB → rotate into blob-store. |
103
103
  | 4.2 | OTLP gzip + delta | tiny | Content-Encoding: gzip; counter delta. |
104
104
  | 4.3 | Histogram buckets pre-tuned | tiny | `crew.task.duration_ms` buckets `[50,200,500,1k,5k,30k,120k]`. |
105
105
 
106
- Exit: cancel < 200 ms, no OOM trên stress, deadletter không lặp.
106
+ Exit: cancel < 200 ms, no OOM under stress, no deadletter repetition.
107
107
 
108
- ## Sprint 5 — Backlog rủi ro cao + ADR (1 tuần)
108
+ ## Sprint 5 — High-risk backlog + ADR (1 week)
109
109
 
110
110
  | ID | Item | Lane | ADR |
111
111
  |---|---|---|---|
@@ -115,33 +115,33 @@ Exit: cancel < 200 ms, no OOM trên stress, deadletter không lặp.
115
115
  | 2.5 | Lazy materialize agent records | normal | — |
116
116
  | 5.2 | Watch mode test | tiny | — |
117
117
 
118
- Mỗi item: ADR + flag tắt được + dual-ship migration nếu cần.
118
+ Each item: ADR + kill switch + dual-ship migration if needed.
119
119
 
120
- ## Tổng kết
120
+ ## Wrap-up
121
121
 
122
- - `docs/perf/sprint-<n>-report.md` cuối mỗi sprint.
123
- - `docs/perf/final-report-2026-05.md` so sánh baseline vs final.
124
- - Update `docs/next-upgrade-roadmap.md` đánh dấu các item đã xong.
122
+ - `docs/perf/sprint-<n>-report.md` at the end of each sprint.
123
+ - `docs/perf/final-report-2026-05.md` comparing baseline vs final.
124
+ - Update `docs/next-upgrade-roadmap.md` to mark completed items.
125
125
 
126
126
  ## Risk register
127
127
 
128
128
  | Risk | Sprint | Mitigation |
129
129
  |---|---|---|
130
- | Coalescer mất event lúc crash | 2 | flushSync exit hook; integration test crash recovery. |
131
- | FS watcher fail trên FS mạng | 2 | Detect ENOSYS/EPERM → fallback poll. |
132
- | Bundle phá Pi extension load | 5 | Prototype + smoke trước; dual-ship 1 release. |
133
- | Warm pool leak state | 5 | Pool process khởi động fresh, nonce; reuse fail → discard. |
134
- | Binary index migration | 5 | Read both binary + JSONL trong 2 release. |
135
- | Concurrency=4 unit test flaky | 3 | Audit test dùng shared HOME; mỗi test mkdtemp riêng. |
130
+ | Coalescer loses events on crash | 2 | flushSync in exit hook; crash-recovery integration test. |
131
+ | FS watcher fails on network filesystems | 2 | Detect ENOSYS/EPERM → poll fallback. |
132
+ | Bundling breaks Pi extension load | 5 | Prototype + smoke first; dual-ship for 1 release. |
133
+ | Warm pool leaks state | 5 | Pool process starts fresh, has a nonce; reuse failure → discard. |
134
+ | Binary index migration | 5 | Read both binary + JSONL for 2 releases. |
135
+ | Concurrency=4 unit tests flaky | 3 | Audit tests using a shared HOME; each test does its own mkdtemp. |
136
136
 
137
- ## Mục tiêu đo lường
137
+ ## Measurement goals
138
138
 
139
- | Metric | Baseline (Sprint 0) | Target | Sprint kỳ vọng cải thiện |
139
+ | Metric | Baseline (Sprint 0) | Target | Expected sprint for improvement |
140
140
  |---|---|---|---|
141
141
  | `register.ts` end-to-end | TBD | < 400 ms | 2 |
142
- | Widget first frame sau session_start | TBD | < 150 ms | 1 |
143
- | `runTeamTask` cold | TBD | -2 đến -4 s (warm pool) | 5 |
144
- | Dashboard FPS khi run đang chạy | TBD | +50% | 3 |
142
+ | Widget first frame after session_start | TBD | < 150 ms | 1 |
143
+ | `runTeamTask` cold | TBD | -2 to -4 s (warm pool) | 5 |
144
+ | Dashboard FPS while a run is active | TBD | +50% | 3 |
145
145
  | events.jsonl tail 32 KB parse | TBD | < 5 ms | 2 |
146
- | CPU idle khi run completed | TBD | < 1% | 1 |
146
+ | CPU idle when run completed | TBD | < 1% | 1 |
147
147
  | Cancel round-trip | TBD | < 200 ms | 4 |