pi-crew 0.5.2 → 0.5.5

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 +67 -0
  2. package/docs/bugs/cross-session-notification-leakage.md +82 -0
  3. package/docs/coding-agent-optimization.md +268 -0
  4. package/docs/deep-review-report.md +384 -0
  5. package/docs/distillation/cybersecurity-patterns.md +294 -0
  6. package/docs/migration-v0.4-v0.5.md +191 -0
  7. package/docs/optimization-plan.md +642 -0
  8. package/docs/pi-mono-opportunities.md +969 -0
  9. package/docs/pi-mono-review.md +291 -0
  10. package/docs/skills/REFERENCE.md +144 -0
  11. package/package.json +7 -6
  12. package/skills/artifact-analysis-loop/SKILL.md +302 -0
  13. package/skills/async-worker-recovery/SKILL.md +19 -1
  14. package/skills/child-pi-spawning/SKILL.md +19 -6
  15. package/skills/context-artifact-hygiene/SKILL.md +19 -2
  16. package/skills/delegation-patterns/SKILL.md +68 -3
  17. package/skills/detection-pipeline-design/SKILL.md +285 -0
  18. package/skills/event-log-tracing/SKILL.md +20 -6
  19. package/skills/git-master/SKILL.md +20 -6
  20. package/skills/hunting-investigation-loop/SKILL.md +401 -0
  21. package/skills/incident-playbook-construction/SKILL.md +383 -0
  22. package/skills/live-agent-lifecycle/SKILL.md +20 -6
  23. package/skills/mailbox-interactive/SKILL.md +19 -6
  24. package/skills/model-routing-context/SKILL.md +19 -1
  25. package/skills/multi-perspective-review/SKILL.md +19 -4
  26. package/skills/observability-reliability/SKILL.md +19 -2
  27. package/skills/orchestration/SKILL.md +20 -2
  28. package/skills/ownership-session-security/SKILL.md +20 -2
  29. package/skills/pi-extension-lifecycle/SKILL.md +20 -2
  30. package/skills/post-mortem/SKILL.md +7 -2
  31. package/skills/read-only-explorer/SKILL.md +20 -6
  32. package/skills/requirements-to-task-packet/SKILL.md +23 -3
  33. package/skills/resource-discovery-config/SKILL.md +20 -2
  34. package/skills/runtime-state-reader/SKILL.md +20 -2
  35. package/skills/safe-bash/SKILL.md +21 -6
  36. package/skills/scrutinize/SKILL.md +20 -2
  37. package/skills/secure-agent-orchestration-review/SKILL.md +29 -2
  38. package/skills/security-review/SKILL.md +560 -0
  39. package/skills/state-mutation-locking/SKILL.md +22 -2
  40. package/skills/systematic-debugging/SKILL.md +8 -6
  41. package/skills/threat-hypothesis-framework/SKILL.md +175 -0
  42. package/skills/ui-render-performance/SKILL.md +20 -2
  43. package/skills/verification-before-done/SKILL.md +17 -2
  44. package/skills/widget-rendering/SKILL.md +21 -6
  45. package/skills/workspace-isolation/SKILL.md +20 -6
  46. package/skills/worktree-isolation/SKILL.md +20 -6
  47. package/src/agents/agent-config.ts +40 -1
  48. package/src/config/config.ts +22 -5
  49. package/src/config/role-tools.ts +82 -0
  50. package/src/config/types.ts +4 -0
  51. package/src/extension/crew-cleanup.ts +114 -0
  52. package/src/extension/register.ts +15 -3
  53. package/src/extension/team-tool/run.ts +7 -7
  54. package/src/observability/event-bus.ts +60 -0
  55. package/src/runtime/background-runner.ts +8 -2
  56. package/src/runtime/child-pi.ts +122 -34
  57. package/src/runtime/crew-agent-runtime.ts +1 -0
  58. package/src/runtime/foreground-control.ts +87 -17
  59. package/src/runtime/pi-args.ts +11 -1
  60. package/src/runtime/pi-json-output.ts +31 -0
  61. package/src/runtime/progress-tracker.ts +124 -0
  62. package/src/runtime/skill-effectiveness.ts +473 -0
  63. package/src/runtime/skill-instructions.ts +37 -3
  64. package/src/runtime/task-runner.ts +91 -17
  65. package/src/runtime/team-runner.ts +11 -11
  66. package/src/runtime/tool-progress.ts +10 -3
  67. package/src/runtime/verification-gates.ts +367 -0
  68. package/src/schema/team-tool-schema.ts +7 -0
  69. package/src/state/decision-ledger.ts +92 -43
  70. package/src/state/event-log.ts +136 -10
  71. package/src/state/hook-instinct-bridge.ts +5 -5
  72. package/src/state/state-store.ts +3 -1
  73. package/src/state/types.ts +4 -0
  74. package/src/types/new-api-types.ts +34 -0
  75. package/src/ui/agent-management-overlay.ts +5 -1
  76. package/src/ui/crew-widget.ts +29 -15
  77. package/src/ui/powerbar-publisher.ts +100 -7
  78. package/src/ui/tool-render.ts +15 -15
  79. package/src/utils/session-utils.ts +52 -0
  80. package/src/worktree/worktree-manager.ts +32 -13
package/CHANGELOG.md CHANGED
@@ -1,5 +1,72 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.4] — pi v0.77.0 Integration (2026-05-29)
4
+
5
+ ### New Features
6
+
7
+ **subscribe() API Integration**
8
+ - Created `ProgressTracker` class for real-time agent session monitoring
9
+ - Created `EventBus` singleton for cross-component event communication
10
+ - Replaced file-based progress tracking with event-based tracking
11
+ - 4 new tests for progress tracking functionality
12
+
13
+ **session_shutdown Handler**
14
+ - Created `crew-cleanup.ts` extension for graceful shutdown
15
+ - Added `ChildProcessRegistry` to track and cleanup child processes
16
+ - Registered handlers for SIGTERM/SIGHUP signals
17
+ - Cleanup now properly kills all child-pi processes on shutdown
18
+
19
+ **excludeTools for Role-Based Restrictions**
20
+ - Created `role-tools.ts` with configurations for 8 agent roles
21
+ - Explorer: read-only (excludes bash, edit, write)
22
+ - Security Reviewer: strictest restrictions (excludes all write/exec)
23
+ - Applied via `--tools` and `--exclude-tools` CLI flags to child processes
24
+
25
+ ### Dependencies
26
+ - Updated `@earendil-works/pi-*` packages from `^0.75.5` to `^0.77.0`
27
+
28
+ ### Files Added
29
+ - `src/types/new-api-types.ts` - Type imports and guards
30
+ - `src/observability/event-bus.ts` - EventBus singleton
31
+ - `src/runtime/progress-tracker.ts` - ProgressTracker class
32
+ - `src/extension/crew-cleanup.ts` - Cleanup handlers
33
+ - `src/config/role-tools.ts` - Role tool configurations
34
+ - 4 new test files
35
+
36
+ ## [0.5.3] — Deep Review Fixes + Security Hardening (2026-05-29)
37
+
38
+ ### Security Fixes
39
+ - **C1**: Fixed credential exposure - removed dangerous wildcards `*_API_KEY`, `*_TOKEN`, `*_SECRET` from env allowlist
40
+ - **C2**: Fixed mock mode bypass - now requires `PI_CREW_ALLOW_MOCK=1` alongside `PI_TEAMS_MOCK_CHILD_PI`
41
+ - **C3**: Worktree hooks Windows hardening - safer execution for Git hooks on Windows
42
+
43
+ ### Data Integrity Fixes
44
+ - **C4**: Fixed duplicate `error` key + Promise type mismatch in task-runner.ts
45
+ - **C5**: Fixed decision ledger truncation - `overrideLastEntry()` preserves all entries during promote/decay
46
+
47
+ ### Reliability Fixes
48
+ - **H2**: Race condition in foreground interrupt - added file locking mechanism
49
+ - **H3**: Terminal events now bypass buffer - crash events logged immediately
50
+ - **H5**: File descriptor leak - background runner properly closes log file descriptors
51
+ - **H9**: Stale cache TTL reduced from 5min to 30s
52
+
53
+ ### TypeScript Fixes
54
+ - Fixed 7+ source errors (duplicate error keys, missing properties)
55
+ - Fixed 20+ test errors (type mismatches, missing imports)
56
+ - All files now compile without errors
57
+
58
+ ### Skill System Improvements
59
+ - All 35 skills now have `triggers:` frontmatter field
60
+ - Added Enforcement sections to skills for better gate validation
61
+ - Improved consistency in section naming
62
+
63
+ ### Documentation
64
+ - Added `docs/migration-v0.4-v0.5.md` - comprehensive migration guide
65
+ - Updated `docs/deep-review-report.md` - complete issue tracking
66
+
67
+ ### Dependencies
68
+ - Added `ajv` dependency for JSON schema validation
69
+
3
70
  ## [0.5.2] — ECC Implementation + Critical Bug Fixes (2026-05-27)
4
71
 
5
72
  ### ECC-Inspired Features
@@ -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`.