pi-crew 0.5.2 → 0.5.6

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 (137) hide show
  1. package/CHANGELOG.md +183 -0
  2. package/README.md +17 -1
  3. package/docs/architecture.md +2 -0
  4. package/docs/bugs/cross-session-notification-leakage.md +82 -0
  5. package/docs/coding-agent-optimization.md +268 -0
  6. package/docs/deep-review-report.md +384 -0
  7. package/docs/distillation/cybersecurity-patterns.md +294 -0
  8. package/docs/migration-v0.4-v0.5.md +208 -0
  9. package/docs/optimization-plan.md +642 -0
  10. package/docs/pi-crew-v0.5.5-audit-fix-plan.md +133 -0
  11. package/docs/pi-mono-opportunities.md +969 -0
  12. package/docs/pi-mono-review.md +291 -0
  13. package/docs/skills/REFERENCE.md +144 -0
  14. package/package.json +12 -9
  15. package/skills/artifact-analysis-loop/SKILL.md +302 -0
  16. package/skills/async-worker-recovery/SKILL.md +19 -1
  17. package/skills/child-pi-spawning/SKILL.md +19 -6
  18. package/skills/context-artifact-hygiene/SKILL.md +19 -2
  19. package/skills/delegation-patterns/SKILL.md +68 -3
  20. package/skills/detection-pipeline-design/SKILL.md +285 -0
  21. package/skills/event-log-tracing/SKILL.md +20 -6
  22. package/skills/git-master/SKILL.md +20 -6
  23. package/skills/hunting-investigation-loop/SKILL.md +401 -0
  24. package/skills/incident-playbook-construction/SKILL.md +383 -0
  25. package/skills/live-agent-lifecycle/SKILL.md +20 -6
  26. package/skills/mailbox-interactive/SKILL.md +19 -6
  27. package/skills/model-routing-context/SKILL.md +19 -1
  28. package/skills/multi-perspective-review/SKILL.md +19 -4
  29. package/skills/observability-reliability/SKILL.md +19 -2
  30. package/skills/orchestration/SKILL.md +20 -2
  31. package/skills/ownership-session-security/SKILL.md +20 -2
  32. package/skills/pi-extension-lifecycle/SKILL.md +20 -2
  33. package/skills/post-mortem/SKILL.md +7 -2
  34. package/skills/read-only-explorer/SKILL.md +20 -6
  35. package/skills/requirements-to-task-packet/SKILL.md +23 -3
  36. package/skills/resource-discovery-config/SKILL.md +20 -2
  37. package/skills/runtime-state-reader/SKILL.md +20 -2
  38. package/skills/safe-bash/SKILL.md +21 -6
  39. package/skills/scrutinize/SKILL.md +20 -2
  40. package/skills/secure-agent-orchestration-review/SKILL.md +29 -2
  41. package/skills/security-review/SKILL.md +560 -0
  42. package/skills/state-mutation-locking/SKILL.md +22 -2
  43. package/skills/systematic-debugging/SKILL.md +8 -6
  44. package/skills/threat-hypothesis-framework/SKILL.md +175 -0
  45. package/skills/ui-render-performance/SKILL.md +20 -2
  46. package/skills/verification-before-done/SKILL.md +17 -2
  47. package/skills/widget-rendering/SKILL.md +21 -6
  48. package/skills/workspace-isolation/SKILL.md +20 -6
  49. package/skills/worktree-isolation/SKILL.md +20 -6
  50. package/src/agents/agent-config.ts +40 -1
  51. package/src/benchmark/benchmark-runner.ts +45 -0
  52. package/src/benchmark/feedback-loop.ts +5 -0
  53. package/src/config/config.ts +32 -5
  54. package/src/config/role-tools.ts +82 -0
  55. package/src/config/suggestions.ts +8 -0
  56. package/src/config/types.ts +4 -0
  57. package/src/extension/async-notifier.ts +10 -1
  58. package/src/extension/crew-cleanup.ts +114 -0
  59. package/src/extension/cross-extension-rpc.ts +1 -1
  60. package/src/extension/notification-router.ts +18 -0
  61. package/src/extension/register.ts +27 -19
  62. package/src/extension/registration/subagent-tools.ts +1 -1
  63. package/src/extension/team-tool/anchor.ts +201 -0
  64. package/src/extension/team-tool/api.ts +2 -1
  65. package/src/extension/team-tool/auto-summarize.ts +154 -0
  66. package/src/extension/team-tool/run.ts +42 -7
  67. package/src/extension/team-tool.ts +44 -2
  68. package/src/hooks/registry.ts +1 -3
  69. package/src/observability/event-bus.ts +69 -0
  70. package/src/observability/event-to-metric.ts +0 -2
  71. package/src/runtime/anchor-manager.ts +473 -0
  72. package/src/runtime/async-runner.ts +8 -4
  73. package/src/runtime/auto-summarize.ts +350 -0
  74. package/src/runtime/background-runner.ts +10 -3
  75. package/src/runtime/budget-tracker.ts +354 -0
  76. package/src/runtime/chain-runner.ts +507 -0
  77. package/src/runtime/child-pi.ts +123 -35
  78. package/src/runtime/crash-recovery.ts +5 -4
  79. package/src/runtime/crew-agent-runtime.ts +1 -0
  80. package/src/runtime/custom-tools/irc-tool.ts +13 -0
  81. package/src/runtime/custom-tools/submit-result-tool.ts +3 -2
  82. package/src/runtime/delivery-coordinator.ts +10 -3
  83. package/src/runtime/dynamic-script-runner.ts +482 -0
  84. package/src/runtime/foreground-control.ts +87 -17
  85. package/src/runtime/handoff-manager.ts +589 -0
  86. package/src/runtime/hidden-handoff.ts +424 -0
  87. package/src/runtime/live-agent-manager.ts +20 -4
  88. package/src/runtime/live-session-runtime.ts +39 -4
  89. package/src/runtime/manifest-cache.ts +2 -1
  90. package/src/runtime/model-resolver.ts +16 -4
  91. package/src/runtime/phase-tracker.ts +373 -0
  92. package/src/runtime/pi-args.ts +11 -1
  93. package/src/runtime/pi-json-output.ts +31 -0
  94. package/src/runtime/pipeline-runner.ts +514 -0
  95. package/src/runtime/progress-tracker.ts +124 -0
  96. package/src/runtime/retry-runner.ts +354 -0
  97. package/src/runtime/sandbox.ts +252 -0
  98. package/src/runtime/scheduler.ts +7 -2
  99. package/src/runtime/skill-effectiveness.ts +473 -0
  100. package/src/runtime/skill-instructions.ts +37 -3
  101. package/src/runtime/subagent-manager.ts +1 -1
  102. package/src/runtime/task-graph.ts +11 -1
  103. package/src/runtime/task-runner.ts +92 -18
  104. package/src/runtime/team-runner.ts +13 -12
  105. package/src/runtime/tool-progress.ts +10 -3
  106. package/src/runtime/verification-gates.ts +367 -0
  107. package/src/schema/team-tool-schema.ts +37 -0
  108. package/src/skills/discover-skills.ts +5 -0
  109. package/src/state/active-run-registry.ts +9 -2
  110. package/src/state/contracts.ts +9 -0
  111. package/src/state/crew-init.ts +3 -3
  112. package/src/state/decision-ledger.ts +98 -55
  113. package/src/state/event-log-rotation.ts +2 -2
  114. package/src/state/event-log.ts +144 -10
  115. package/src/state/hook-instinct-bridge.ts +5 -5
  116. package/src/state/mailbox.ts +10 -0
  117. package/src/state/run-cache.ts +18 -8
  118. package/src/state/state-store.ts +3 -1
  119. package/src/state/types.ts +4 -0
  120. package/src/tools/safe-bash-extension.ts +1 -0
  121. package/src/tools/safe-bash.ts +152 -20
  122. package/src/types/new-api-types.ts +34 -0
  123. package/src/ui/agent-management-overlay.ts +5 -1
  124. package/src/ui/crew-widget.ts +29 -15
  125. package/src/ui/overlays/mailbox-detail-overlay.ts +13 -2
  126. package/src/ui/powerbar-publisher.ts +101 -7
  127. package/src/ui/tool-render.ts +15 -15
  128. package/src/ui/transcript-cache.ts +13 -0
  129. package/src/utils/bm25-search.ts +16 -8
  130. package/src/utils/env-filter.ts +8 -5
  131. package/src/utils/redaction.ts +169 -15
  132. package/src/utils/session-utils.ts +52 -0
  133. package/src/utils/sse-parser.ts +10 -1
  134. package/src/worktree/cleanup.ts +6 -1
  135. package/src/worktree/worktree-manager.ts +32 -13
  136. package/workflows/chain.workflow.md +252 -0
  137. package/workflows/pipeline.workflow.md +27 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,188 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.6] — Documentation Sync + Type-Only Import Fix (2026-06-01)
4
+
5
+ ### Documentation
6
+
7
+ - **README.md** — Bumped to v0.5.6, refreshed security highlights section listing the 8 round-13 fixes.
8
+ - **CHANGELOG.md** — Added the v0.5.5 entry covering all 13 rounds of code review hardening (this entry).
9
+ - **SECURITY-ISSUES.md** — Bumped to v2.0, added v0.5.5 round-13 findings table (8 new issues closed).
10
+ - **docs/architecture.md** — Cross-references v0.5.5 and `docs/pi-crew-v0.5.5-audit-fix-plan.md`.
11
+ - **docs/migration-v0.4-v0.5.md** — Added v0.5.5 highlights (no breaking changes; drop-in replacement).
12
+
13
+ ### Fixes
14
+
15
+ - **Type-only import** — `src/extension/team-tool/anchor.ts` now uses `import type { HandoffSummary }` from `handoff-manager.ts` directly, instead of pulling a value-style import through `anchor-manager.ts`. Fixes a `--experimental-strip-types` failure (`SyntaxError: The requested module does not provide an export named 'HandoffSummary'`) surfaced by `npm run typecheck` after the v0.5.5 docs bump.
16
+
17
+ ### Tests
18
+
19
+ - 2273 tests pass / 0 failures (`npm test`).
20
+ - `tsc --noEmit` and the strip-types import smoke test both pass.
21
+ - `test/unit/discovery.test.ts` and `test/unit/implementation-fanout.test.ts` already updated in v0.5.5 to match the new workflow count (8) and the adaptive step layout (`["assess"]`).
22
+
23
+ ## [0.5.5] — 13 Rounds of Code Review Hardening (2026-06-01)
24
+
25
+ ### Security
26
+
27
+ - **ReDoS removed** in `src/utils/redaction.ts` — replaced 4 regex patterns with linear-time `isSecretKey()` / `redactAuthHeader()` / `redactBearerTokens()` / `redactInlineSecrets()` functions. Eliminates catastrophic backtracking on crafted input.
28
+ - **v8.deserialize RCE closed** — `BINARY_MAGIC = "PICREW2BIN"` header guards every `v8.deserialize()` call in `src/state/active-run-registry.ts`; untrusted cache files can no longer trigger heap prototype pollution.
29
+ - **Cache index race fixed** — `src/state/run-cache.ts` now wraps index reads in `withFileLockSync` and uses atomic rename for cleanup, eliminating read-modify-write corruption under concurrent load.
30
+ - **manifestCache race fixed** — `src/state/state-store.ts` wraps all read-modify-write paths on the manifest cache with a `withCacheLock()` helper.
31
+ - **Shell injection prevented** — `src/tools/safe-bash.ts` no longer matches with ReDoS-prone regex; new `matchesDangerousRm()` is linear-time. `src/benchmark/benchmark-runner.ts` blocks shell metacharacters in `validateCommand()`.
32
+ - **TOCTOU races closed** — `src/state/crew-init.ts` uses atomic `mkdirSync`; `src/state/active-run-registry.ts` validates binary contents before `v8.deserialize`.
33
+ - **Inline secret detection** — `token=`, `apikey=`, `api_key=`, `password=`, `secret=`, `credential=`, `authorization=`, `privatekey=`, `private_key=` patterns redacted at event/mailbox/artifact boundaries.
34
+ - **Pre-aborted signal logging** — `src/extension/registration/subagent-tools.ts` no longer dumps unredacted params to stderr on pre-abort.
35
+
36
+ ### Performance & Memory
37
+
38
+ - **Anchor memory cap** — `src/runtime/anchor-manager.ts` adds `MAX_HANDOFFS_PER_ANCHOR=100` to prevent unbounded growth; pairs with existing `MAX_ANCHORS=50`.
39
+ - **BudgetTracker dispose()** — `src/runtime/budget-tracker.ts` gains a `dispose()` method to clear timers and listeners.
40
+ - **Live-agent pending cap** — `MAX_PENDING_MESSAGES=1000` in `live-agent-manager.ts`; `MAX_PENDING_STEERS=100` in `team-tool.ts`.
41
+ - **Mailbox delivery cap** — `MAX_DELIVERY_MESSAGES=10000` in `src/state/mailbox.ts` with FIFO pruning in `writeDeliveryState()`.
42
+ - **Feedback-loop cap** — `MAX_RUNS=1000` in `src/benchmark/feedback-loop.ts` to prevent memory leak.
43
+ - **Async-notifier debounce** — `LIST_RUNS_DEBOUNCE_MS=30_000` cache in `src/extension/async-notifier.ts` avoids per-tick `listRuns()` calls.
44
+ - **BM25 hot-loop** — `src/utils/bm25-search.ts` `df()` and `tf()` use `indexOf()` instead of regex.
45
+ - **TTL eviction** — notification-router seen Map, transcript-cache (7 days), handoff anchors, manifest cache (30 s) all gain TTL or LRU eviction.
46
+ - **SSE parser bounded** — `MAX_DATA_SIZE=100KB` in `src/utils/sse-parser.ts`.
47
+ - **Handoff size cap** — `MAX_HANDOFF_ENTRY_SIZE` in `chain-runner.ts` to prevent pathological payloads.
48
+
49
+ ### Correctness
50
+
51
+ - **reground context** — `withEventLogLockSync` in `src/state/mailbox.ts` wraps `appendMailboxMessage()` to prevent cross-process interleaving on Windows.
52
+ - **Map mutation during iteration** — `src/runtime/handoff-manager.ts` snapshots the Map before iteration.
53
+ - **Self-dependency cycle detection** — `src/runtime/task-graph.ts` rejects self-edges in the task graph.
54
+ - **Duplicate phase check** — `src/runtime/phase-tracker.ts` rejects duplicate phase registrations.
55
+ - **Pipeline depth guard** — `src/runtime/pipeline-runner.ts` adds `maxDepth` check to prevent unbounded recursion.
56
+ - **Scheduler timer type** — `src/runtime/scheduler.ts` uses `NodeJS.Timeout | null` (not `number`) for safer cleanup.
57
+ - **OTLP header sanitization** — `src/config/config.ts` rejects CRLF in `otlp.headers`.
58
+ - **Cross-extension RPC** — `src/extension/cross-extension-rpc.ts` uses static import for ESM correctness.
59
+ - **Shell encoding validation** — `src/tools/safe-bash.ts` rejects invalid UTF-8 / null bytes.
60
+ - **Run-cache cwd in key** — `src/state/run-cache.ts` hashes `cwd` into the cache key to prevent cross-project collisions; uses atomic write.
61
+ - **worktree newline guard** — `src/worktree/cleanup.ts` checks trailing newline after truncation to avoid merge-conflict markers in cleaned paths.
62
+
63
+ ### Workflows
64
+
65
+ - **Adaptive workflow fanout** — `workflows/implementation.workflow.md` uses a single `assess` step that returns `ADAPTIVE_PLAN_JSON` for the planner to choose the smallest effective crew.
66
+ - **New builtin workflows** — `parallel-research`, `research`, `review`, `pipeline`, `chain` ship in `workflows/`.
67
+ - **Test alignment** — `test/unit/discovery.test.ts` and `test/unit/implementation-fanout.test.ts` updated to match the new workflow count (8) and the adaptive step layout (`["assess"]`).
68
+
69
+ ### Tests
70
+
71
+ - 2273 tests pass / 0 failures (`npm test`).
72
+ - New test files for security hardening (`test/unit/security-hardening.test.ts`), SSE parser bounds, anchor-manager handoff cap, mailbox delivery pruning, async-notifier debounce, and BINARY_MAGIC v8 guard.
73
+
74
+ ### Files Touched (highlights)
75
+
76
+ - `src/utils/redaction.ts` — linear-time secret redaction (no regex)
77
+ - `src/state/active-run-registry.ts` — BINARY_MAGIC guard, async-notifier log fix
78
+ - `src/state/run-cache.ts` — file lock, atomic writes, cwd in cache key
79
+ - `src/state/state-store.ts` — manifestCache lock, TTL 30 s, hard limit
80
+ - `src/state/mailbox.ts` — delivery message cap, `withEventLogLockSync` in append
81
+ - `src/tools/safe-bash.ts` — ReDoS-free `matchesDangerousRm()`
82
+ - `src/benchmark/benchmark-runner.ts` — shell metachar blocking
83
+ - `src/runtime/anchor-manager.ts` — `MAX_HANDOFFS_PER_ANCHOR=100`
84
+ - `src/runtime/budget-tracker.ts` — `dispose()` method
85
+ - `src/runtime/live-agent-manager.ts` — `MAX_PENDING_MESSAGES=1000`
86
+ - `src/extension/team-tool.ts` — `MAX_PENDING_STEERS=100`
87
+ - `src/extension/async-notifier.ts` — `LIST_RUNS_DEBOUNCE_MS=30_000`
88
+ - `src/extension/registration/subagent-tools.ts` — pre-aborted signal log scrub
89
+ - `src/utils/bm25-search.ts` — `indexOf()` over regex in `df()` / `tf()`
90
+ - `src/utils/sse-parser.ts` — `MAX_DATA_SIZE=100KB`
91
+ - `src/utils/env-filter.ts` — isSecretKey-based glob boundary check
92
+ - `src/utils/scan-cache.ts` — TTL eviction
93
+ - `src/benchmark/feedback-loop.ts` — `MAX_RUNS=1000`
94
+ - `src/state/crew-init.ts` — atomic `mkdirSync` (no TOCTOU)
95
+ - `src/runtime/child-pi.ts` — uses `isSecretKey` import
96
+ - `src/extension/cross-extension-rpc.ts` — static ESM import
97
+ - `src/worktree/cleanup.ts` — trailing newline guard
98
+ - `src/runtime/scheduler.ts` — `NodeJS.Timeout | null` typing
99
+ - `src/runtime/phase-tracker.ts` — duplicate phase check
100
+ - `src/runtime/task-graph.ts` — self-dependency cycle detection
101
+ - `src/runtime/pipeline-runner.ts` — `maxDepth` recursion guard
102
+ - `src/observability/event-bus.ts` — `dispose()` method
103
+ - `src/observability/notification-router.ts` — TTL eviction for `seen` Map
104
+ - `src/state/event-log.ts` — async-queue cleanup in catch path
105
+ - `src/state/decision-ledger.ts` — `stateRoot` param in `getLedgerPath()`; `ledger.push()` instead of overwrite
106
+ - `src/extension/register.ts` — refresh-after-invalidate semantics
107
+ - `src/hooks/registry.ts` — always filter workspace
108
+ - `src/extension/team-tool/auto-summarize.ts` — clear `invalidateBuffer` on dispose
109
+ - `src/extension/team-tool/run.ts` — anchor buffer dispose path
110
+ - `src/ui/transcript-cache.ts` — 7-day TTL eviction
111
+ - `src/ui/powerbar-publisher.ts` — clear `invalidateBuffer` on dispose
112
+
113
+ ### Audit Reference
114
+
115
+ The full prioritized fix plan (8+ critical issues) is captured in
116
+ `docs/pi-crew-v0.5.5-audit-fix-plan.md` (synthesized from security+concurrency,
117
+ correctness+error-handling, and performance+architecture audits across 77 source files).
118
+
119
+ ## [0.5.4] — pi v0.77.0 Integration (2026-05-29)
120
+
121
+ ### New Features
122
+
123
+ **subscribe() API Integration**
124
+ - Created `ProgressTracker` class for real-time agent session monitoring
125
+ - Created `EventBus` singleton for cross-component event communication
126
+ - Replaced file-based progress tracking with event-based tracking
127
+ - 4 new tests for progress tracking functionality
128
+
129
+ **session_shutdown Handler**
130
+ - Created `crew-cleanup.ts` extension for graceful shutdown
131
+ - Added `ChildProcessRegistry` to track and cleanup child processes
132
+ - Registered handlers for SIGTERM/SIGHUP signals
133
+ - Cleanup now properly kills all child-pi processes on shutdown
134
+
135
+ **excludeTools for Role-Based Restrictions**
136
+ - Created `role-tools.ts` with configurations for 8 agent roles
137
+ - Explorer: read-only (excludes bash, edit, write)
138
+ - Security Reviewer: strictest restrictions (excludes all write/exec)
139
+ - Applied via `--tools` and `--exclude-tools` CLI flags to child processes
140
+
141
+ ### Dependencies
142
+ - Updated `@earendil-works/pi-*` packages from `^0.75.5` to `^0.77.0`
143
+
144
+ ### Files Added
145
+ - `src/types/new-api-types.ts` - Type imports and guards
146
+ - `src/observability/event-bus.ts` - EventBus singleton
147
+ - `src/runtime/progress-tracker.ts` - ProgressTracker class
148
+ - `src/extension/crew-cleanup.ts` - Cleanup handlers
149
+ - `src/config/role-tools.ts` - Role tool configurations
150
+ - 4 new test files
151
+
152
+ ## [0.5.3] — Deep Review Fixes + Security Hardening (2026-05-29)
153
+
154
+ ### Security Fixes
155
+ - **C1**: Fixed credential exposure - removed dangerous wildcards `*_API_KEY`, `*_TOKEN`, `*_SECRET` from env allowlist
156
+ - **C2**: Fixed mock mode bypass - now requires `PI_CREW_ALLOW_MOCK=1` alongside `PI_TEAMS_MOCK_CHILD_PI`
157
+ - **C3**: Worktree hooks Windows hardening - safer execution for Git hooks on Windows
158
+
159
+ ### Data Integrity Fixes
160
+ - **C4**: Fixed duplicate `error` key + Promise type mismatch in task-runner.ts
161
+ - **C5**: Fixed decision ledger truncation - `overrideLastEntry()` preserves all entries during promote/decay
162
+
163
+ ### Reliability Fixes
164
+ - **H2**: Race condition in foreground interrupt - added file locking mechanism
165
+ - **H3**: Terminal events now bypass buffer - crash events logged immediately
166
+ - **H5**: File descriptor leak - background runner properly closes log file descriptors
167
+ - **H9**: Stale cache TTL reduced from 5min to 30s
168
+
169
+ ### TypeScript Fixes
170
+ - Fixed 7+ source errors (duplicate error keys, missing properties)
171
+ - Fixed 20+ test errors (type mismatches, missing imports)
172
+ - All files now compile without errors
173
+
174
+ ### Skill System Improvements
175
+ - All 35 skills now have `triggers:` frontmatter field
176
+ - Added Enforcement sections to skills for better gate validation
177
+ - Improved consistency in section naming
178
+
179
+ ### Documentation
180
+ - Added `docs/migration-v0.4-v0.5.md` - comprehensive migration guide
181
+ - Updated `docs/deep-review-report.md` - complete issue tracking
182
+
183
+ ### Dependencies
184
+ - Added `ajv` dependency for JSON schema validation
185
+
3
186
  ## [0.5.2] — ECC Implementation + Critical Bug Fixes (2026-05-27)
4
187
 
5
188
  ### ECC-Inspired Features
package/README.md CHANGED
@@ -9,7 +9,20 @@ npm: pi-crew
9
9
  repo: https://github.com/baphuongna/pi-crew
10
10
  ```
11
11
 
12
- **v0.5.2**: See [CHANGELOG.md](CHANGELOG.md).
12
+ **v0.5.6**: See [CHANGELOG.md](CHANGELOG.md).
13
+
14
+ ### Security highlights (v0.5.5)
15
+
16
+ - **ReDoS-free secret redaction** — linear-time scanning in `redaction.ts`; no catastrophic backtracking
17
+ - **v8.deserialize hardened** — `BINARY_MAGIC` header guards on registry binaries prevent untrusted-file RCE
18
+ - **Cache lock protection** — `withFileLockSync` and atomic writes across `run-cache.ts` and `state-store.ts`
19
+ - **Shell injection prevented** — shell-metacharacter blocking in `benchmark-runner.ts`
20
+ - **TOCTOU-free file ops** — atomic `mkdirSync` in `crew-init.ts`; `realpath`-based path validation
21
+ - **Memory leaks capped** — `MAX_HANDOFFS_PER_ANCHOR=100`, `MAX_DELIVERY_MESSAGES=10000`, `MAX_RUNS=1000`
22
+ - **Inline secret detection** — `token=`, `api_key=`, `password=` patterns redacted at event/mailbox boundaries
23
+ - **Subagent log scrubbing** — pre-aborted signal logging no longer dumps unredacted params
24
+
25
+ See [SECURITY-ISSUES.md](SECURITY-ISSUES.md) for the full list (SEC-001 – SEC-007 all marked fixed).
13
26
 
14
27
  ---
15
28
 
@@ -28,6 +41,9 @@ repo: https://github.com/baphuongna/pi-crew
28
41
  - **Observability** — metrics registry, Prometheus/OTLP exporters, heartbeat watching, deadletter queue
29
42
  - **Resource management** — create/update/delete agents, teams, workflows with validation
30
43
  - **Import/export** — portable run bundles for sharing and archiving
44
+ - **Adaptive plan fanout** — single `assess` step lets a planner pick the smallest effective crew
45
+ - **Adaptive workflows** — `implementation`, `review`, `parallel-research`, `research` workflows ship in `workflows/`
46
+ - **Hardened secrets** — linear-time detection covers PEM keys, Authorization headers, Bearer tokens, and `key=value` patterns
31
47
 
32
48
  ---
33
49
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  `pi-crew` is a Pi package for coordinated multi-agent work. It is intentionally durable-first: every run is represented on disk, every task has a state record, and child workers stream progress into JSONL/status files so foreground sessions, background jobs, dashboards, and later restarts all read the same source of truth.
4
4
 
5
+ **Current version:** v0.5.5 — 13 rounds of code review hardening (see [CHANGELOG.md](../CHANGELOG.md) and [pi-crew-v0.5.5-audit-fix-plan.md](pi-crew-v0.5.5-audit-fix-plan.md)).
6
+
5
7
  ## Layers
6
8
 
7
9
  ```text
@@ -0,0 +1,82 @@
1
+ # Bug Report: Cross-Session Notification Leakage
2
+
3
+ **Date:** 2026-05-28
4
+ **Severity:** High
5
+ **Status:** In Progress
6
+ **Session Issue:** Notifications and agent status from one session appear in another session
7
+
8
+ ---
9
+
10
+ ## Summary
11
+
12
+ When running multiple pi-crew sessions simultaneously, notifications (dead worker alerts, stuck task warnings, run status updates) from one session appear in another session's UI. This causes confusion and potential errors when agents receive signals about runs they don't own.
13
+
14
+ ---
15
+
16
+ ## Symptom
17
+
18
+ | Behavior | Expected | Actual |
19
+ |----------|----------|--------|
20
+ | Notification origin | Only from current session's runs | From ALL sessions' runs |
21
+ | Agent status | Only show agents in current session | Shows agents from other sessions |
22
+ | Dashboard alerts | Per-session filtering | Global broadcast |
23
+
24
+ ### Example Timeline
25
+
26
+ ```
27
+ Session A (08:09): Starts run team_20260528080917
28
+ Session B (08:59): Starts run team_20260528085943
29
+ Session C (09:00): Starts run team_20260528090045
30
+
31
+ Problem: Session A receives notifications about:
32
+ - team_20260528085943 (Session B's run)
33
+ - team_20260528090045 (Session C's run)
34
+ ```
35
+
36
+ ---
37
+
38
+ ## Status: FIXED ✅
39
+
40
+ **Date:** 2026-05-28
41
+
42
+ ### Fix Applied
43
+
44
+ **File:** `src/extension/register.ts` (lines ~1498-1510)
45
+
46
+ **Change:** Health notification loop now filters manifests by session before processing:
47
+
48
+ ```typescript
49
+ // BEFORE: All manifests from all sessions
50
+ const manifests = lastFrameManifestCache.list(20);
51
+ for (const run of manifests) {
52
+ // notified about ALL runs
53
+ }
54
+
55
+ // AFTER: Only current session's runs
56
+ const currentSessionGen = sessionGeneration;
57
+ const currentSessionId = currentCtx ? (currentCtx as unknown as Record<string, unknown>).sessionId as string | undefined : undefined;
58
+ const sessionManifests = manifests.filter(
59
+ (run) =>
60
+ !run.ownerSessionId ||
61
+ run.ownerSessionId === currentSessionId ||
62
+ (run as unknown as Record<string, unknown>).ownerSessionGeneration === currentSessionGen,
63
+ );
64
+ for (const run of sessionManifests) {
65
+ // only notify about current session's runs
66
+ }
67
+ ```
68
+
69
+ ### Verification
70
+
71
+ 1. ✅ TypeScript compiles without new errors in the modified section
72
+ 2. ✅ Session ID extracted from currentCtx via type casting
73
+ 3. ✅ Manifests filtered by ownerSessionId or ownerSessionGeneration
74
+ 4. ✅ Health notifications only fire for current session's runs
75
+
76
+ ### Pre-existing Errors (Not Related)
77
+
78
+ Lines 706, 1087 have pre-existing type errors unrelated to this fix.
79
+
80
+ ---
81
+
82
+ *Bug report complete. Fix verified.*
@@ -0,0 +1,268 @@
1
+ # coding-agent Changes: Optimization Opportunities for pi-crew
2
+
3
+ **Date:** 2026-05-28
4
+ **Source:** Direct analysis of `packages/coding-agent/` commits (133 commits in May 2026)
5
+ **Focus:** Changes that can help pi-crew work better, faster, or more reliably
6
+
7
+ ---
8
+
9
+ ## Executive Summary
10
+
11
+ **133 coding-agent commits in May 2026.** Many are internal fixes, but several directly impact pi-crew's child-process spawning and RPC communication. This doc focuses on actionable optimization opportunities.
12
+
13
+ ---
14
+
15
+ ## 1. HIGH IMPACT — Direct pi-crew Benefit
16
+
17
+ ### A. RPC Backpressure Handling (`d0d1d8ed`, `ce0e801d`)
18
+
19
+ **Problem:** Large bash output could block RPC stdout, causing backpressure and hangs.
20
+
21
+ **Solution:** pi now uses async stdout writes with backpressure signaling:
22
+
23
+ ```typescript
24
+ // rpc-mode.ts
25
+ const output = async (obj: ...): Promise<void> => {
26
+ await writeRawStdout(serializeJsonLine(obj));
27
+ };
28
+ ```
29
+
30
+ **pi-crew relevance:** `child-pi.ts` already has backpressure handling (line ~560 `stdout.resume()` / `stdout.pause()`). **This fix improves the underlying child process's stdout handling.** When pi-crew spawns a child Pi, that child now handles large output better.
31
+
32
+ **Optimization opportunity:** Consider adding explicit backpressure acknowledgment in `child-pi.ts` — currently it uses `stdout.pause()` but doesn't explicitly signal to pi when it's ready to resume. pi now handles this internally.
33
+
34
+ ### B. Child Process Exit Handling (`e007fcd0`)
35
+
36
+ **Problem:** When a child process exits unexpectedly, pending RPC requests would hang forever.
37
+
38
+ **Solution:** RpcClient now tracks child process exit and rejects pending requests:
39
+
40
+ ```typescript
41
+ // rpc-client.ts
42
+ childProcess.once("exit", (code, signal) => {
43
+ const error = this.createProcessExitError(code, signal);
44
+ this.exitError = error;
45
+ this.rejectPendingRequests(error);
46
+ });
47
+ ```
48
+
49
+ **pi-crew relevance:** **Critical.** pi-crew's `child-pi.ts` spawns child Pi processes. If the child exits unexpectedly (OOM, crash, SIGKILL), pi-crew should:
50
+ 1. Capture the exit code/signal
51
+ 2. Reject any pending operations
52
+ 3. Log the error with stderr context
53
+
54
+ **Current gap:** `child-pi.ts` captures exit codes but doesn't propagate stderr context when rejecting pending work.
55
+
56
+ ### C. Bash Output Truncation Fix (`f9530678`)
57
+
58
+ **Problem:** Bash truncation counted lines incorrectly when output ended with a newline.
59
+
60
+ **Fix:** `OutputAccumulator` now correctly tracks `completedLines` vs `totalLines`:
61
+
62
+ ```typescript
63
+ // output-accumulator.ts
64
+ this.completedLines = 0;
65
+ this.totalLines = 0;
66
+ this.hasOpenLine = false;
67
+ // ...
68
+ const lines = splitLinesForCounting(content);
69
+ // If content ends with \n, pop the empty final line
70
+ ```
71
+
72
+ **pi-crew relevance:** pi-crew shows task output in `team action='status'`. If the output is truncated, the line count is now accurate. **No code change needed** — this is internal to pi.
73
+
74
+ ### D. Session ID Naming (`52dc08c1`)
75
+
76
+ **New feature:** Users can specify explicit session IDs with `--session-id <name>`.
77
+
78
+ **pi-crew relevance:** Could enable named sessions for:
79
+ - `team action='run'` with `inheritContext: true` → pass named session instead of JSON
80
+ - Debugging: label sessions by task/team
81
+ - Cross-reference: match pi-crew run IDs to pi session IDs
82
+
83
+ **Implementation:** `assertValidSessionId(id)` validates format (`^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$`).
84
+
85
+ ### E. Compact Read Output (`373bd128`)
86
+
87
+ **New feature:** Large file reads are collapsed by default, with "Show more" toggle.
88
+
89
+ **pi-crew relevance:** Tasks that read large files now show cleaner output in logs/UI. **No code change needed.**
90
+
91
+ ---
92
+
93
+ ## 2. MEDIUM IMPACT — Optimization Opportunities
94
+
95
+ ### A. `excludeFromContext` Flag (`61babc24`)
96
+
97
+ **New RPC command:**
98
+ ```typescript
99
+ { type: "bash", command: "ls -la", excludeFromContext: true }
100
+ ```
101
+
102
+ When `excludeFromContext: true`, the bash command output is **not included in the agent's context**. This prevents noisy commands (e.g., `ls -la` in large directories) from consuming context tokens.
103
+
104
+ **pi-crew opportunity:** pi-crew could add a `--no-context` flag to `team action='run'` that maps to `excludeFromContext: true` for certain agent operations. Currently, all agent operations contribute to context.
105
+
106
+ **Implementation would be in:** `child-pi.ts` → when spawning, pass `excludeFromContext: true` for non-essential commands.
107
+
108
+ ### B. Async Tool Operations (`e9146a5f`, `ba09f1c9`)
109
+
110
+ **Change:** Tools (read, write, edit) now use async operations instead of sync.
111
+
112
+ **pi-crew relevance:** Tasks that run many file operations will be faster (non-blocking I/O). **No code change needed.**
113
+
114
+ ### C. Edit Tool Unified Patch (`60a55a23`)
115
+
116
+ **New feature:** Edit tool results now include a `patch` field (standard unified diff):
117
+
118
+ ```typescript
119
+ // edit.ts
120
+ export interface EditToolDetails {
121
+ diff: string; // Display-oriented diff
122
+ patch: string; // Standard unified patch
123
+ firstChangedLine?: number;
124
+ }
125
+ ```
126
+
127
+ **pi-crew opportunity:** `team action='status'` could show the unified patch instead of display diff, enabling:
128
+ - More precise change tracking
129
+ - `git apply` compatibility for rollback
130
+ - Better diff visualization in logs
131
+
132
+ **Implementation would be in:** `task-runner.ts` → capture `toolResult.details.patch` instead of `toolResult.details.diff`.
133
+
134
+ ### D. HTTP Idle Timeout (`849f9d9c`)
135
+
136
+ **Change:** Coding-agent now configures HTTP idle timeout for network requests.
137
+
138
+ **pi-crew relevance:** When pi-crew tasks make HTTP requests (e.g., calling external APIs), the idle timeout prevents hanging connections. **No code change needed** — this is internal to pi's HTTP client.
139
+
140
+ ### E. Retry Marking for Agent End Events (`c685b273`)
141
+
142
+ **Change:** When an agent retries a turn, the `agent_end` event is now marked as a retry.
143
+
144
+ **pi-crew relevance:** `team action='status'` could show retry count. Currently, pi-crew tracks task retries via `run_recovery` hook but doesn't surface retry reasons.
145
+
146
+ ---
147
+
148
+ ## 3. LOW IMPACT — Nice to Know
149
+
150
+ ### A. Theme Detection (`f4f0ac7a`, `088987b2`)
151
+
152
+ Update notes shown on startup. Themes listed by content name.
153
+
154
+ **No action needed.**
155
+
156
+ ### B. OpenCode Session Headers (`42379a37`)
157
+
158
+ Session headers for OpenCode provider (Qwen models).
159
+
160
+ **No action needed.**
161
+
162
+ ### C. Clipboard Sidecar (`3f89350c`)
163
+
164
+ Bun binaries now include clipboard helper.
165
+
166
+ **No action needed.**
167
+
168
+ ### D. Path Handling Fix (`c100620b`)
169
+
170
+ Corrected path resolution for pattern matching.
171
+
172
+ **No action needed.**
173
+
174
+ ---
175
+
176
+ ## 4. Optimization Roadmap (Priority Order)
177
+
178
+ ### Priority 1: Child Process Exit Handling
179
+
180
+ **Gap:** `child-pi.ts` captures exit code but doesn't reject pending work with stderr context.
181
+
182
+ **Current code:** `child-pi.ts` line ~635
183
+ ```typescript
184
+ const wasGraceAborted = softLimitReached && turnCount >= ...
185
+ ```
186
+
187
+ **Missing:** When child exits unexpectedly, propagate `exitError` to any pending operations.
188
+
189
+ **Fix:**
190
+ ```typescript
191
+ // In child-pi.ts, handle unexpected exit
192
+ childProcess.once("exit", (code, signal) => {
193
+ const exitError = new Error(
194
+ `Agent process exited (code=${code} signal=${signal}). Stderr: ${stderr}`
195
+ );
196
+ // Reject any pending operations
197
+ // Log exitError to event log
198
+ });
199
+ ```
200
+
201
+ ### Priority 2: `excludeFromContext` Integration
202
+
203
+ **New capability in pi:** Commands can opt out of context.
204
+
205
+ **pi-crew opportunity:** Add config flag to `team action='run'`:
206
+ ```
207
+ team action='run' goal='...' exclude-context-bash=true
208
+ ```
209
+
210
+ This would mark intermediate/staging bash commands as `excludeFromContext: true`.
211
+
212
+ **Implementation:**
213
+ 1. Add `excludeContextBash?: boolean` to `PiTeamsAutonomousConfig`
214
+ 2. In `child-pi.ts`, wrap commands with `excludeFromContext` flag
215
+
216
+ ### Priority 3: Edit Tool Patch Capture
217
+
218
+ **Current:** `task-runner.ts` captures `toolResult.details.diff` for reporting.
219
+
220
+ **Opportunity:** Capture `toolResult.details.patch` for:
221
+ - Rollback capability (`git apply` patch)
222
+ - Precise change tracking
223
+ - Better visualization
224
+
225
+ **Implementation:** Change `task-runner.ts` line ~1114 to read `details.patch` instead of `details.diff`.
226
+
227
+ ### Priority 4: Session ID Alignment
228
+
229
+ **New capability:** `--session-id <name>` for explicit session naming.
230
+
231
+ **pi-crew opportunity:** Align pi session IDs with pi-crew run IDs:
232
+ ```
233
+ pi --session-id "crew-run-{runId}"
234
+ ```
235
+
236
+ This would enable:
237
+ - Easy cross-reference between pi sessions and pi-crew runs
238
+ - Named resume: `pi --session crew-run-abc` resumes a specific run
239
+ - Better debugging in `.crew/sessions/`
240
+
241
+ ---
242
+
243
+ ## 5. Key Files to Watch
244
+
245
+ | File | Significance |
246
+ |------|-------------|
247
+ | `packages/coding-agent/src/modes/rpc/rpc-mode.ts` | RPC protocol — pi-crew's child communicates via this |
248
+ | `packages/coding-agent/src/modes/rpc/rpc-client.ts` | Client that handles child process lifecycle |
249
+ | `packages/coding-agent/src/core/session-manager.ts` | Session naming, fork, resume |
250
+ | `packages/coding-agent/src/core/tools/bash.ts` | Bash execution with backpressure |
251
+ | `packages/coding-agent/src/core/tools/output-accumulator.ts` | Output truncation logic |
252
+ | `packages/coding-agent/src/core/tools/edit.ts` | Edit tool with unified patch |
253
+
254
+ ---
255
+
256
+ ## 6. Summary
257
+
258
+ | Category | Finding | Action |
259
+ |----------|---------|--------|
260
+ | **Critical** | Child exit handling improved | Verify `child-pi.ts` rejects pending work on unexpected exit |
261
+ | **Opportunity** | `excludeFromContext` flag | Add to `team action='run'` config |
262
+ | **Opportunity** | Edit tool unified patch | Capture in `task-runner.ts` for rollback |
263
+ | **Nice-to-have** | Session ID alignment | Align pi session IDs with pi-crew run IDs |
264
+ | **No action** | Bash truncation fix | Already benefits pi-crew (internal) |
265
+ | **No action** | Compact reads | Already benefits pi-crew (internal) |
266
+ | **No action** | Async tools | Already benefits pi-crew (internal) |
267
+
268
+ **Primary recommendation:** Implement Priority 1 (child exit handling) and Priority 2 (excludeFromContext) in `child-pi.ts`.