pi-crew 0.5.1 → 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.
- package/CHANGELOG.md +95 -0
- package/README.md +1 -1
- package/docs/actions-reference.md +87 -0
- package/docs/bugs/cross-session-notification-leakage.md +82 -0
- package/docs/coding-agent-optimization.md +268 -0
- package/docs/commands-reference.md +5 -0
- package/docs/deep-review-report.md +384 -0
- package/docs/distillation/cybersecurity-patterns.md +294 -0
- package/docs/migration-v0.4-v0.5.md +191 -0
- package/docs/optimization-plan.md +642 -0
- package/docs/pi-crew-bugs.md +6 -0
- package/docs/pi-mono-opportunities.md +969 -0
- package/docs/pi-mono-review.md +291 -0
- package/{skills → docs/skills}/REFERENCE.md +13 -5
- package/index.ts +1 -1
- package/package.json +19 -16
- package/skills/artifact-analysis-loop/SKILL.md +302 -0
- package/skills/async-worker-recovery/SKILL.md +19 -1
- package/skills/child-pi-spawning/SKILL.md +19 -6
- package/skills/context-artifact-hygiene/SKILL.md +19 -2
- package/skills/delegation-patterns/SKILL.md +68 -3
- package/skills/detection-pipeline-design/SKILL.md +285 -0
- package/skills/event-log-tracing/SKILL.md +20 -6
- package/skills/git-master/SKILL.md +20 -6
- package/skills/hunting-investigation-loop/SKILL.md +401 -0
- package/skills/incident-playbook-construction/SKILL.md +383 -0
- package/skills/live-agent-lifecycle/SKILL.md +20 -6
- package/skills/mailbox-interactive/SKILL.md +19 -6
- package/skills/model-routing-context/SKILL.md +19 -1
- package/skills/multi-perspective-review/SKILL.md +19 -4
- package/skills/observability-reliability/SKILL.md +19 -2
- package/skills/orchestration/SKILL.md +20 -2
- package/skills/ownership-session-security/SKILL.md +20 -2
- package/skills/pi-extension-lifecycle/SKILL.md +20 -2
- package/skills/post-mortem/SKILL.md +7 -2
- package/skills/read-only-explorer/SKILL.md +20 -6
- package/skills/requirements-to-task-packet/SKILL.md +23 -3
- package/skills/resource-discovery-config/SKILL.md +20 -2
- package/skills/runtime-state-reader/SKILL.md +20 -2
- package/skills/safe-bash/SKILL.md +21 -6
- package/skills/scrutinize/SKILL.md +20 -2
- package/skills/secure-agent-orchestration-review/SKILL.md +29 -2
- package/skills/security-review/SKILL.md +560 -0
- package/skills/state-mutation-locking/SKILL.md +22 -2
- package/skills/systematic-debugging/SKILL.md +8 -6
- package/skills/threat-hypothesis-framework/SKILL.md +175 -0
- package/skills/ui-render-performance/SKILL.md +20 -2
- package/skills/verification-before-done/SKILL.md +17 -2
- package/skills/widget-rendering/SKILL.md +21 -6
- package/skills/workspace-isolation/SKILL.md +20 -6
- package/skills/worktree-isolation/SKILL.md +20 -6
- package/src/agents/agent-config.ts +40 -1
- package/src/benchmark/benchmark-runner.ts +245 -0
- package/src/benchmark/feedback-loop.ts +66 -0
- package/src/config/config.ts +22 -5
- package/src/config/role-tools.ts +82 -0
- package/src/config/types.ts +4 -0
- package/src/extension/async-notifier.ts +1 -1
- package/src/extension/autonomous-policy.ts +1 -1
- package/src/extension/crew-cleanup.ts +114 -0
- package/src/extension/cross-extension-rpc.ts +1 -1
- package/src/extension/plan-orchestrate.ts +322 -0
- package/src/extension/register.ts +46 -44
- package/src/extension/registration/command-utils.ts +1 -1
- package/src/extension/registration/commands.ts +1 -1
- package/src/extension/registration/compaction-guard.ts +1 -1
- package/src/extension/registration/subagent-helpers.ts +1 -1
- package/src/extension/registration/subagent-tools.ts +1 -1
- package/src/extension/registration/team-tool.ts +1 -1
- package/src/extension/registration/viewers.ts +1 -1
- package/src/extension/session-summary.ts +1 -1
- package/src/extension/team-manager-command.ts +1 -1
- package/src/extension/team-tool/context.ts +1 -1
- package/src/extension/team-tool/handle-schedule.ts +183 -0
- package/src/extension/team-tool/orchestrate.ts +102 -0
- package/src/extension/team-tool/run.ts +222 -35
- package/src/extension/team-tool.ts +10 -0
- package/src/extension/tool-result.ts +1 -1
- package/src/i18n.ts +1 -1
- package/src/observability/event-bus.ts +60 -0
- package/src/observability/event-to-metric.ts +1 -1
- package/src/prompt/prompt-runtime.ts +1 -1
- package/src/runtime/background-runner.ts +35 -7
- package/src/runtime/child-pi.ts +122 -34
- package/src/runtime/crash-recovery.ts +1 -1
- package/src/runtime/crew-agent-runtime.ts +1 -0
- package/src/runtime/crew-hooks.ts +240 -0
- package/src/runtime/custom-tools/irc-tool.ts +1 -1
- package/src/runtime/custom-tools/submit-result-tool.ts +1 -1
- package/src/runtime/diagnostic-export.ts +38 -2
- package/src/runtime/foreground-control.ts +87 -17
- package/src/runtime/foreground-watchdog.ts +1 -1
- package/src/runtime/live-session-runtime.ts +1 -1
- package/src/runtime/mcp-proxy.ts +1 -1
- package/src/runtime/pi-args.ts +11 -1
- package/src/runtime/pi-json-output.ts +31 -0
- package/src/runtime/pi-spawn.ts +20 -4
- package/src/runtime/process-status.ts +15 -2
- package/src/runtime/progress-tracker.ts +124 -0
- package/src/runtime/runtime-resolver.ts +1 -1
- package/src/runtime/session-resources.ts +1 -1
- package/src/runtime/skill-effectiveness.ts +473 -0
- package/src/runtime/skill-instructions.ts +37 -3
- package/src/runtime/task-runner.ts +122 -18
- package/src/runtime/team-runner.ts +17 -11
- package/src/runtime/tool-progress.ts +10 -3
- package/src/runtime/verification-gates.ts +367 -0
- package/src/schema/team-tool-schema.ts +31 -1
- package/src/state/crew-init.ts +56 -38
- package/src/state/decision-ledger.ts +344 -0
- package/src/state/event-log.ts +136 -10
- package/src/state/hook-instinct-bridge.ts +90 -0
- package/src/state/hook-integrations.ts +51 -0
- package/src/state/instinct-store.ts +249 -0
- package/src/state/run-metrics.ts +135 -0
- package/src/state/state-store.ts +3 -1
- package/src/state/tiered-eval.ts +471 -0
- package/src/state/types-eval.ts +58 -0
- package/src/state/types.ts +7 -0
- package/src/tools/safe-bash-extension.ts +5 -5
- package/src/types/new-api-types.ts +34 -0
- package/src/ui/agent-management-overlay.ts +5 -1
- package/src/ui/crew-widget.ts +30 -16
- package/src/ui/pi-ui-compat.ts +1 -1
- package/src/ui/powerbar-publisher.ts +100 -7
- package/src/ui/run-action-dispatcher.ts +1 -1
- package/src/ui/tool-render.ts +17 -17
- package/src/utils/project-detector.ts +160 -0
- package/src/utils/session-utils.ts +52 -0
- package/src/worktree/worktree-manager.ts +32 -13
- package/test-bugs-all.mjs +1 -1
- package/skills/.gitkeep +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,100 @@
|
|
|
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
|
+
|
|
70
|
+
## [0.5.2] — ECC Implementation + Critical Bug Fixes (2026-05-27)
|
|
71
|
+
|
|
72
|
+
### ECC-Inspired Features
|
|
73
|
+
- **12-Layer Diagnostic**: Extended diagnostic export from 7 to 12 layers including taskDiagnostics, terminalEvidence, modelAttempts, pendingMailbox, recoveryLedger
|
|
74
|
+
- **Recursive Decision Ledger**: Full rollout tracking with coherence marks (matchesPrior, matchesRecursive, promotionAllowed) in JSONL format with 10 unit tests
|
|
75
|
+
- **Verify-skill Script**: `scripts/verify-skill.ts` and `scripts/check-all-skills.ts` to validate skill RED/GREEN gates and anti-patterns (15 unit tests)
|
|
76
|
+
- **Schedule Wiring**: `team action='schedule'` with cron/interval/once support; `team action='scheduled'` to list jobs; scheduler wired into handlers via global symbol
|
|
77
|
+
- **Plan Orchestrate**: `team action='orchestrate'` with tag-based plan parsing (`<!-- tag: design -->`, etc.) and TAG→chain mapping
|
|
78
|
+
- **Hook System**: `src/state/hook-integrations.ts` and `src/state/hook-instinct-bridge.ts` for extensibility
|
|
79
|
+
- **Feedback Loop**: `src/benchmark/feedback-loop.ts` for agent evaluation
|
|
80
|
+
- **Agent Eval Framework**: Extended `benchmark-runner.ts` with BenchmarkMetrics, aggregateBenchmarkMetrics(), pass rates, and cost tracking
|
|
81
|
+
- **Project Detector**: `src/utils/project-detector.ts` for project-aware decisions
|
|
82
|
+
|
|
83
|
+
### Critical Bug Fixes
|
|
84
|
+
- **crew-init.ts**: Rewrote to be completely self-contained (no paths.ts imports) to fix child-process crash `TypeError: Cannot read properties of undefined (reading 'projectCrewRoot')`
|
|
85
|
+
- **task-runner.ts**: Fixed needs_attention output by ensuring live-session stdout is captured as resultArtifact
|
|
86
|
+
- **team-runner.ts**: Fixed zombie agent detection to trust running agents and require activity evidence for queued agents
|
|
87
|
+
- **register.ts**: Fixed schedule wiring (sessionId resolution order, global symbol registration)
|
|
88
|
+
- **decision-ledger.ts**: Fixed promoteCandidate/decayCandidate to return correctly overridden coherence marks
|
|
89
|
+
- **verify-skill.ts**: Fixed decision matrix parsing, warning detection regex, duplicate indexOf bug, removed unused readline import
|
|
90
|
+
- **plan-orchestrate.ts**: Fixed heading extraction (global regex to find last heading), word-boundary matching for implicit tags
|
|
91
|
+
- **team-tool-schema.ts**: Added missing cron/interval/once fields and scheduled action case
|
|
92
|
+
|
|
93
|
+
### Tests
|
|
94
|
+
- All 1894 tests passing (0 failures)
|
|
95
|
+
- Test fixes: crew-widget (shows running agents), foreground-nonblocking (mock), lazy-agent-materialization (skipped design limitation)
|
|
96
|
+
- Test:new and test:changed scripts added
|
|
97
|
+
|
|
3
98
|
## [0.5.1] — Integration + End-to-End Tests (2026-05-26)
|
|
4
99
|
|
|
5
100
|
### Integration
|
package/README.md
CHANGED
|
@@ -9,15 +9,20 @@ Tool `team` là công cụ chính mà pi-crew đăng ký vào Pi. Mọi thao tá
|
|
|
9
9
|
| `recommend` | Gợi ý team/workflow phù hợp | Bắt đầu khi chưa chắc chọn gì |
|
|
10
10
|
| `run` | Tạo run và thực thi workflow | Thao tác chính |
|
|
11
11
|
| `plan` | Preview workflow không chạy tasks | Dry-run planning |
|
|
12
|
+
| `orchestrate` | Execute từ plan document | Tự động hóa plan |
|
|
13
|
+
| `schedule` | Lên lịch recurring runs | Tự động định kỳ |
|
|
14
|
+
| `scheduled` | List scheduled jobs | Xem lịch trình |
|
|
12
15
|
| `status` | Đọc trạng thái run | Theo dõi tiến độ |
|
|
13
16
|
| `summary` | Đọc/ghi run summary artifact | Tổng kết |
|
|
14
17
|
| `cancel` | Hủy queued/running work | Dừng run |
|
|
15
18
|
| `resume` | Re-queue failed/cancelled tasks | Tiếp tục run |
|
|
16
19
|
| `list` | List teams, agents, workflows, runs | Khám phá tài nguyên |
|
|
17
20
|
| `get` | Inspect agent/team/workflow | Xem chi tiết |
|
|
21
|
+
| `search` | BM25 ranked agent/team discovery | Tìm kiếm thông minh |
|
|
18
22
|
| `events` | Đọc event log | Debug/audit |
|
|
19
23
|
| `artifacts` | List run artifacts | Xem outputs |
|
|
20
24
|
| `worktrees` | List run worktree metadata | Kiểm tra worktrees |
|
|
25
|
+
| `graph` | Load/save/list run graphs | Trực quan hóa |
|
|
21
26
|
| `cleanup` | Xóa run worktrees | Dọn dẹp |
|
|
22
27
|
| `forget` | Xóa run state/artifacts | Xóa hẳn (cần `confirm`) |
|
|
23
28
|
| `prune` | Xóa nhiều old finished runs | Dọn dẹp hàng loạt |
|
|
@@ -184,6 +189,88 @@ Giống `run` nhưng **không spawn workers**. Xem trước task graph sẽ tạ
|
|
|
184
189
|
|
|
185
190
|
---
|
|
186
191
|
|
|
192
|
+
### `orchestrate` — Execute từ plan document
|
|
193
|
+
|
|
194
|
+
Thực thi workflow từ plan document có tag sections:
|
|
195
|
+
|
|
196
|
+
```markdown
|
|
197
|
+
# Design Phase
|
|
198
|
+
<!-- tag: design -->
|
|
199
|
+
Design the authentication system...
|
|
200
|
+
|
|
201
|
+
# Implementation
|
|
202
|
+
<!-- tag: impl -->
|
|
203
|
+
Implement the JWT auth...
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"action": "orchestrate",
|
|
209
|
+
"planPath": "./plan.md"
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
TAG→chain mapping:
|
|
214
|
+
- `design` → planner, architect
|
|
215
|
+
- `impl` → tdd-guide, lang-reviewer
|
|
216
|
+
- `security` → security-reviewer, lang-reviewer
|
|
217
|
+
- `build` → build-error-resolver
|
|
218
|
+
- `test` → test-engineer, verifier
|
|
219
|
+
- `review` → reviewer
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### `schedule` — Lên lịch recurring runs
|
|
224
|
+
|
|
225
|
+
Tạo scheduled job với cron, interval, hoặc once:
|
|
226
|
+
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"action": "schedule",
|
|
230
|
+
"team": "review",
|
|
231
|
+
"goal": "Weekly security review",
|
|
232
|
+
"cron": "0 9 * * MON"
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Params: `cron`, `interval` (ms), `once` (ISO timestamp)
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
### `scheduled` — List scheduled jobs
|
|
241
|
+
|
|
242
|
+
```json
|
|
243
|
+
{
|
|
244
|
+
"action": "scheduled"
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
### `graph` — Load/save/list run graphs
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"action": "graph",
|
|
255
|
+
"runId": "team_..."
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
### `search` — BM25 ranked discovery
|
|
262
|
+
|
|
263
|
+
Tìm kiếm agents/teams/workflows với BM25 ranking:
|
|
264
|
+
|
|
265
|
+
```json
|
|
266
|
+
{
|
|
267
|
+
"action": "search",
|
|
268
|
+
"goal": "security audit"
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
187
274
|
### `status` — Trạng thái run
|
|
188
275
|
|
|
189
276
|
```json
|
|
@@ -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`.
|
|
@@ -8,10 +8,15 @@ Slash commands là thao tác thủ công từ Pi chat. Autonomous tool use qua `
|
|
|
8
8
|
|---------|-------|
|
|
9
9
|
| `/teams` | Liệt kê teams, agents, workflows, recent runs |
|
|
10
10
|
| `/team-run [options] <goal>` | Chạy team workflow |
|
|
11
|
+
| `/team-orchestrate <planPath>` | Execute từ plan document |
|
|
12
|
+
| `/team-schedule [options]` | Lên lịch recurring run |
|
|
13
|
+
| `/team-scheduled` | List scheduled jobs |
|
|
11
14
|
| `/team-cancel <runId>` | Hủy run |
|
|
12
15
|
| `/team-status <runId>` | Xem trạng thái |
|
|
13
16
|
| `/team-summary <runId>` | Xem/ghi summary |
|
|
14
17
|
| `/team-resume <runId>` | Tiếp tục run đã dừng |
|
|
18
|
+
| `/team-search <query>` | BM25 ranked discovery |
|
|
19
|
+
| `/team-graph <runId>` | Load/save/list run graphs |
|
|
15
20
|
| `/team-events <runId>` | Xem event log |
|
|
16
21
|
| `/team-artifacts <runId>` | Xem artifacts |
|
|
17
22
|
| `/team-worktrees <runId>` | Xem worktree metadata |
|