pi-crew 0.1.45 → 0.1.49
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 +97 -0
- package/README.md +5 -5
- package/agents/analyst.md +11 -11
- package/agents/critic.md +11 -11
- package/agents/executor.md +11 -11
- package/agents/explorer.md +11 -11
- package/agents/planner.md +11 -11
- package/agents/reviewer.md +11 -11
- package/agents/security-reviewer.md +11 -11
- package/agents/test-engineer.md +11 -11
- package/agents/verifier.md +11 -11
- package/agents/writer.md +11 -11
- package/docs/next-upgrade-roadmap.md +808 -0
- package/docs/research/AGENT-EXECUTION-ARCHITECTURE.md +261 -0
- package/docs/research/AGENT-LIFECYCLE-COMPARISON.md +111 -0
- package/docs/research/AUDIT_OH_MY_PI.md +261 -0
- package/docs/research/AUDIT_PI_CREW.md +457 -0
- package/docs/research/CAVEMAN-DEEP-RESEARCH.md +281 -0
- package/docs/research/COMPARISON_OH_MY_PI_VS_PI_CREW.md +264 -0
- package/docs/research/DEEP-RESEARCH-PI-POWERBAR.md +343 -0
- package/docs/research/DEEP_RESEARCH_SUBAGENT_ARCHITECTURE.md +480 -0
- package/docs/research/GAP_CLOSURE_IMPLEMENTATION_PLAN.md +354 -0
- package/docs/research/IMPLEMENTATION_PLAN.md +385 -0
- package/docs/research/LIVE-SESSION-PRODUCTION-READY-PLAN.md +502 -0
- package/docs/research/OH-MY-PI-DEEP-RESEARCH-v14.7.6.md +266 -0
- package/docs/research/REMAINING-GAPS-PLAN.md +363 -0
- package/docs/research/SESSION-SUMMARY-2026-05-08.md +146 -0
- package/docs/research/UI-RESPONSIVENESS-AUDIT.md +173 -0
- package/docs/research-awesome-agent-skills-distillation.md +100 -0
- package/docs/research-oh-my-pi-distillation.md +369 -0
- package/docs/source-runtime-refactor-map.md +24 -0
- package/docs/usage.md +3 -3
- package/install.mjs +52 -8
- package/package.json +99 -98
- package/schema.json +10 -1
- package/skills/async-worker-recovery/SKILL.md +42 -0
- package/skills/context-artifact-hygiene/SKILL.md +52 -0
- package/skills/delegation-patterns/SKILL.md +54 -0
- package/skills/mailbox-interactive/SKILL.md +40 -0
- package/skills/model-routing-context/SKILL.md +39 -0
- package/skills/multi-perspective-review/SKILL.md +58 -0
- package/skills/observability-reliability/SKILL.md +41 -0
- package/skills/orchestration/SKILL.md +157 -0
- package/skills/ownership-session-security/SKILL.md +41 -0
- package/skills/pi-extension-lifecycle/SKILL.md +39 -0
- package/skills/requirements-to-task-packet/SKILL.md +63 -0
- package/skills/resource-discovery-config/SKILL.md +41 -0
- package/skills/runtime-state-reader/SKILL.md +44 -0
- package/skills/secure-agent-orchestration-review/SKILL.md +45 -0
- package/skills/state-mutation-locking/SKILL.md +42 -0
- package/skills/systematic-debugging/SKILL.md +67 -0
- package/skills/ui-render-performance/SKILL.md +39 -0
- package/skills/verification-before-done/SKILL.md +57 -0
- package/skills/worktree-isolation/SKILL.md +39 -0
- package/src/agents/agent-config.ts +6 -0
- package/src/agents/agent-search.ts +98 -0
- package/src/agents/agent-serializer.ts +38 -34
- package/src/agents/discover-agents.ts +29 -15
- package/src/config/config.ts +72 -24
- package/src/config/defaults.ts +25 -0
- package/src/extension/autonomous-policy.ts +26 -33
- package/src/extension/help.ts +1 -0
- package/src/extension/management.ts +5 -0
- package/src/extension/project-init.ts +62 -2
- package/src/extension/register.ts +69 -22
- package/src/extension/registration/commands.ts +64 -25
- package/src/extension/registration/compaction-guard.ts +1 -1
- package/src/extension/registration/subagent-helpers.ts +8 -0
- package/src/extension/registration/subagent-tools.ts +149 -148
- package/src/extension/registration/team-tool.ts +14 -10
- package/src/extension/run-index.ts +35 -21
- package/src/extension/run-maintenance.ts +30 -5
- package/src/extension/team-tool/api.ts +47 -9
- package/src/extension/team-tool/cancel.ts +109 -5
- package/src/extension/team-tool/context.ts +8 -0
- package/src/extension/team-tool/intent-policy.ts +42 -0
- package/src/extension/team-tool/lifecycle-actions.ts +120 -79
- package/src/extension/team-tool/parallel-dispatch.ts +156 -0
- package/src/extension/team-tool/respond.ts +46 -18
- package/src/extension/team-tool/run.ts +55 -12
- package/src/extension/team-tool/status.ts +13 -2
- package/src/extension/team-tool-types.ts +3 -0
- package/src/extension/team-tool.ts +45 -14
- package/src/hooks/registry.ts +61 -0
- package/src/hooks/types.ts +41 -0
- package/src/observability/event-to-metric.ts +8 -1
- package/src/runtime/agent-control.ts +169 -63
- package/src/runtime/async-runner.ts +3 -1
- package/src/runtime/background-runner.ts +78 -53
- package/src/runtime/cancellation-token.ts +89 -0
- package/src/runtime/cancellation.ts +61 -0
- package/src/runtime/capability-inventory.ts +116 -0
- package/src/runtime/child-pi.ts +458 -444
- package/src/runtime/code-summary.ts +247 -0
- package/src/runtime/crash-recovery.ts +182 -0
- package/src/runtime/crew-agent-records.ts +70 -10
- package/src/runtime/crew-agent-runtime.ts +1 -0
- package/src/runtime/custom-tools/irc-tool.ts +201 -0
- package/src/runtime/custom-tools/submit-result-tool.ts +90 -0
- package/src/runtime/deadletter.ts +1 -0
- package/src/runtime/delivery-coordinator.ts +48 -25
- package/src/runtime/effectiveness.ts +81 -0
- package/src/runtime/event-stream-bridge.ts +90 -0
- package/src/runtime/live-agent-control.ts +2 -1
- package/src/runtime/live-agent-manager.ts +179 -85
- package/src/runtime/live-control-realtime.ts +1 -1
- package/src/runtime/live-extension-bridge.ts +150 -0
- package/src/runtime/live-irc.ts +92 -0
- package/src/runtime/live-session-health.ts +100 -0
- package/src/runtime/live-session-runtime.ts +599 -305
- package/src/runtime/manifest-cache.ts +17 -2
- package/src/runtime/mcp-proxy.ts +113 -0
- package/src/runtime/model-fallback.ts +6 -4
- package/src/runtime/notebook-helpers.ts +90 -0
- package/src/runtime/orphan-sentinel.ts +7 -0
- package/src/runtime/output-validator.ts +187 -0
- package/src/runtime/parallel-utils.ts +57 -0
- package/src/runtime/parent-guard.ts +80 -0
- package/src/runtime/pi-args.ts +18 -3
- package/src/runtime/process-status.ts +5 -1
- package/src/runtime/prose-compressor.ts +164 -0
- package/src/runtime/result-extractor.ts +121 -0
- package/src/runtime/retry-executor.ts +81 -64
- package/src/runtime/runtime-resolver.ts +23 -10
- package/src/runtime/semaphore.ts +131 -0
- package/src/runtime/sensitive-paths.ts +92 -0
- package/src/runtime/skill-instructions.ts +222 -0
- package/src/runtime/stale-reconciler.ts +4 -14
- package/src/runtime/stream-preview.ts +177 -0
- package/src/runtime/subagent-manager.ts +6 -2
- package/src/runtime/subprocess-tool-registry.ts +67 -0
- package/src/runtime/task-output-context.ts +177 -127
- package/src/runtime/task-runner/capabilities.ts +78 -0
- package/src/runtime/task-runner/live-executor.ts +107 -101
- package/src/runtime/task-runner/prompt-builder.ts +72 -8
- package/src/runtime/task-runner/prompt-pipeline.ts +64 -0
- package/src/runtime/task-runner/run-projection.ts +104 -0
- package/src/runtime/task-runner.ts +115 -5
- package/src/runtime/team-runner.ts +134 -19
- package/src/runtime/workspace-tree.ts +298 -0
- package/src/runtime/yield-handler.ts +189 -0
- package/src/schema/config-schema.ts +7 -0
- package/src/schema/team-tool-schema.ts +14 -4
- package/src/skills/discover-skills.ts +67 -0
- package/src/state/active-run-registry.ts +167 -0
- package/src/state/artifact-store.ts +4 -1
- package/src/state/atomic-write.ts +50 -1
- package/src/state/blob-store.ts +117 -0
- package/src/state/contracts.ts +2 -1
- package/src/state/event-log-rotation.ts +158 -0
- package/src/state/event-log.ts +52 -2
- package/src/state/mailbox.ts +129 -9
- package/src/state/state-store.ts +32 -5
- package/src/state/types.ts +64 -2
- package/src/teams/team-config.ts +1 -0
- package/src/ui/agent-management-overlay.ts +144 -0
- package/src/ui/crew-widget.ts +15 -5
- package/src/ui/dashboard-panes/cancellation-pane.ts +43 -0
- package/src/ui/dashboard-panes/capability-pane.ts +60 -0
- package/src/ui/dashboard-panes/mailbox-pane.ts +35 -11
- package/src/ui/dashboard-panes/progress-pane.ts +2 -0
- package/src/ui/live-run-sidebar.ts +4 -0
- package/src/ui/powerbar-publisher.ts +77 -15
- package/src/ui/render-coalescer.ts +51 -0
- package/src/ui/run-dashboard.ts +4 -0
- package/src/ui/run-event-bus.ts +209 -0
- package/src/ui/run-snapshot-cache.ts +78 -18
- package/src/ui/snapshot-types.ts +10 -0
- package/src/ui/transcript-entries.ts +258 -0
- package/src/utils/ids.ts +5 -0
- package/src/utils/incremental-reader.ts +104 -0
- package/src/utils/paths.ts +4 -2
- package/src/utils/scan-cache.ts +137 -0
- package/src/utils/sse-parser.ts +134 -0
- package/src/utils/task-name-generator.ts +337 -0
- package/src/utils/visual.ts +33 -2
- package/src/workflows/workflow-config.ts +1 -0
- package/src/worktree/cleanup.ts +2 -1
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
# 🔍 pi-crew Codebase Deep Audit
|
|
2
|
+
|
|
3
|
+
> **Ngày**: 2026-05-07
|
|
4
|
+
> **Commit**: `682194c`
|
|
5
|
+
> **Codebase**: `pi-crew/` — `src/` + `test/`
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Tổng quan Architecture
|
|
10
|
+
|
|
11
|
+
### End-to-End Flow
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
User → Pi CLI → team tool → team-tool.ts (dispatcher)
|
|
15
|
+
↓
|
|
16
|
+
team-tool/run.ts → validate resources → create manifest + tasks
|
|
17
|
+
↓
|
|
18
|
+
team-runner.ts → build task graph → resolve ready tasks → batch by concurrency
|
|
19
|
+
↓
|
|
20
|
+
task-runner.ts → spawn child Pi process → capture stdout/stderr JSONL
|
|
21
|
+
↓
|
|
22
|
+
child-pi.ts → process management (spawn, timeout, kill, drain)
|
|
23
|
+
↓
|
|
24
|
+
State layer (manifest.json, tasks.json, events.jsonl, mailbox.jsonl)
|
|
25
|
+
↓
|
|
26
|
+
UI layer (crew-widget, run-dashboard, powerbar-publisher, snapshot-cache)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Design Patterns chính
|
|
30
|
+
|
|
31
|
+
- **Artifact-per-operation**: Mỗi task produces 8-15+ artifacts (prompt, result, log, transcript, verification, startup-evidence, capabilities, prompt-pipeline, diff, diff-stat, task-packet, skills, coordination-bridge, inputs, shared-output, summary)
|
|
32
|
+
- **Event sourcing**: All mutations logged as JSONL events với sequence numbers và fingerprints
|
|
33
|
+
- **Caching với mtime stamps**: Manifest cache và snapshot cache dùng file stat mtime/size comparisons
|
|
34
|
+
- **Safety-by-default**: Scaffold mode disables workers; path containment checks; depth guards; plan approval gates
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 2. Key Files & Responsibilities
|
|
39
|
+
|
|
40
|
+
### Core Runtime
|
|
41
|
+
|
|
42
|
+
| File | ~Lines | Responsibility |
|
|
43
|
+
|------|--------|----------------|
|
|
44
|
+
| `src/runtime/team-runner.ts` | ~520 | Core workflow scheduler, adaptive plan injection, task graph execution, policy application |
|
|
45
|
+
| `src/runtime/task-runner.ts` | ~430 | Per-task execution, model fallback, artifact persistence, worktree management |
|
|
46
|
+
| `src/runtime/child-pi.ts` | ~380 | Child Pi process spawning, stdout/stderr capture, timeout handling, process tree kills |
|
|
47
|
+
| `src/runtime/task-graph-scheduler.ts` | ~130 | Dependency graph resolution, ready/blocked/failed task classification |
|
|
48
|
+
| `src/runtime/retry-executor.ts` | ~90 | Generic retry với exponential backoff và jitter |
|
|
49
|
+
| `src/runtime/agent-control.ts` | ~200 | Attention detection, consecutive failure tracking, long-running task alerts |
|
|
50
|
+
| `src/runtime/crash-recovery.ts` | ~150 | Crash state detection và recovery |
|
|
51
|
+
| `src/runtime/overflow-recovery.ts` | ~130 | Overflow/compaction state machine tracking |
|
|
52
|
+
| `src/runtime/stale-reconciler.ts` | ~100 | Stale run detection và reconciliation |
|
|
53
|
+
| `src/runtime/deadletter.ts` | ~80 | Permanently failed task tracking |
|
|
54
|
+
|
|
55
|
+
### Extension Layer
|
|
56
|
+
|
|
57
|
+
| File | ~Lines | Responsibility |
|
|
58
|
+
|------|--------|----------------|
|
|
59
|
+
| `src/extension/register.ts` | ~550 | Extension registration, session lifecycle, observability, UI wiring |
|
|
60
|
+
| `src/extension/team-tool.ts` | ~400 | Tool action dispatcher (~25 actions), resume logic, checkpoint recovery |
|
|
61
|
+
| `src/extension/team-tool/run.ts` | ~300 | Run action handler, manifest creation, async/foreground routing |
|
|
62
|
+
| `src/extension/team-tool/api.ts` | ~200 | Public API operations (list, get, status, diff, etc.) |
|
|
63
|
+
| `src/extension/team-tool/cancel.ts` | ~100 | Cancel action handler |
|
|
64
|
+
| `src/extension/team-tool/respond.ts` | ~80 | Mailbox respond action |
|
|
65
|
+
| `src/extension/team-tool/status.ts` | ~100 | Status display action |
|
|
66
|
+
|
|
67
|
+
### State Layer
|
|
68
|
+
|
|
69
|
+
| File | ~Lines | Responsibility |
|
|
70
|
+
|------|--------|----------------|
|
|
71
|
+
| `src/state/state-store.ts` | ~250 | Run manifest CRUD, path resolution, manifest caching |
|
|
72
|
+
| `src/state/mailbox.ts` | ~380 | Inter-task message passing, inbox/outbox, delivery state, reply support |
|
|
73
|
+
| `src/state/event-log.ts` | ~180 | JSONL event append, sequence numbering, cursor reads |
|
|
74
|
+
| `src/state/types.ts` | ~220 | Core types: manifest, tasks, artifacts, policies, output schema |
|
|
75
|
+
| `src/state/contracts.ts` | ~110 | Status enums, transition tables, event types |
|
|
76
|
+
| `src/state/blob-store.ts` | ~120 | Large binary/text blob storage |
|
|
77
|
+
| `src/state/active-run-registry.ts` | ~60 | In-memory tracking of active runs |
|
|
78
|
+
|
|
79
|
+
### UI Layer
|
|
80
|
+
|
|
81
|
+
| File | ~Lines | Responsibility |
|
|
82
|
+
|------|--------|----------------|
|
|
83
|
+
| `src/ui/run-dashboard.ts` | ~460 | Interactive TUI dashboard với panes và keybindings |
|
|
84
|
+
| `src/ui/run-snapshot-cache.ts` | ~550 | Aggressive caching cho dashboard render, async preloading, stamp-based staleness |
|
|
85
|
+
| `src/ui/crew-widget.ts` | ~360 | Status bar widget rendering, frame-based animation |
|
|
86
|
+
| `src/ui/powerbar-publisher.ts` | ~130 | Powerbar segment updates (coalesced) |
|
|
87
|
+
| `src/ui/transcript-viewer.ts` | ~335 | Syntax-highlighted transcript display, diff rendering |
|
|
88
|
+
| `src/ui/transcript-entries.ts` | ~200 | Entry-based transcript navigation (expand/collapse) |
|
|
89
|
+
| `src/ui/agent-management-overlay.ts` | ~130 | Agent config viewer |
|
|
90
|
+
| `src/ui/render-coalescer.ts` | ~60 | Render request batching (debounce) |
|
|
91
|
+
| `src/ui/render-scheduler.ts` | ~143 | Scheduled render coordination |
|
|
92
|
+
| `src/ui/run-event-bus.ts` | ~98 | In-process event bus cho UI updates |
|
|
93
|
+
|
|
94
|
+
### Config
|
|
95
|
+
|
|
96
|
+
| File | ~Lines | Responsibility |
|
|
97
|
+
|------|--------|----------------|
|
|
98
|
+
| `src/config/config.ts` | ~840 | Config loading, merging, validation, autonomous settings |
|
|
99
|
+
| `src/config/defaults.ts` | ~200 | Default values cho all config options |
|
|
100
|
+
|
|
101
|
+
### Agents & Discovery
|
|
102
|
+
|
|
103
|
+
| File | ~Lines | Responsibility |
|
|
104
|
+
|------|--------|----------------|
|
|
105
|
+
| `src/agents/agent-config.ts` | ~80 | AgentConfig type definition |
|
|
106
|
+
| `src/agents/discover-agents.ts` | ~120 | Agent discovery từ agents/ dir + .md files |
|
|
107
|
+
| `src/agents/agent-search.ts` | ~140 | BM25 agent search (weighted fields) |
|
|
108
|
+
| `src/agents/agent-serializer.ts` | ~60 | Agent config serialization/deserialization |
|
|
109
|
+
|
|
110
|
+
### Utilities
|
|
111
|
+
|
|
112
|
+
| File | ~Lines | Responsibility |
|
|
113
|
+
|------|--------|----------------|
|
|
114
|
+
| `src/utils/visual.ts` | ~200 | visibleWidth (emoji/CJK aware), truncate, pad, wrapHard |
|
|
115
|
+
| `src/utils/safe-paths.ts` | ~50 | Path traversal prevention, containment validation |
|
|
116
|
+
| `src/utils/redaction.ts` | ~40 | Secret redaction cho logs/artifacts |
|
|
117
|
+
| `src/utils/frontmatter.ts` | ~80 | YAML frontmatter parsing |
|
|
118
|
+
| `src/utils/paths.ts` | ~60 | Project/user path resolution |
|
|
119
|
+
| `src/utils/file-coalescer.ts` | ~40 | File read coalescing (debounce) |
|
|
120
|
+
| `src/utils/sse-parser.ts` | ~120 | SSE event stream parser |
|
|
121
|
+
| `src/utils/scan-cache.ts` | ~80 | Directory scan caching |
|
|
122
|
+
|
|
123
|
+
### New Runtime Utilities (Phase 1-4 additions)
|
|
124
|
+
|
|
125
|
+
| File | ~Lines | Responsibility |
|
|
126
|
+
|------|--------|----------------|
|
|
127
|
+
| `src/runtime/event-stream-bridge.ts` | ~80 | Bridge child Pi JSON events → RunEventBus |
|
|
128
|
+
| `src/runtime/result-extractor.ts` | ~130 | Structured JSON extraction từ worker output |
|
|
129
|
+
| `src/runtime/stream-preview.ts` | ~140 | Live output capture và preview |
|
|
130
|
+
| `src/runtime/code-summary.ts` | ~240 | Regex-based code summarizer (TS/JS/Python/Rust) |
|
|
131
|
+
| `src/runtime/notebook-helpers.ts` | ~90 | .ipynb parser/editor |
|
|
132
|
+
| `src/runtime/workspace-tree.ts` | ~100 | Workspace tree builder |
|
|
133
|
+
| `src/runtime/task-output-context.ts` | ~180 | Dependency context collection (structured + artifacts + usage) |
|
|
134
|
+
| `src/runtime/task-runner/prompt-builder.ts` | ~200 | Worker prompt construction |
|
|
135
|
+
| `src/runtime/task-runner/run-projection.ts` | ~80 | Task run result projection |
|
|
136
|
+
|
|
137
|
+
### Worktree
|
|
138
|
+
|
|
139
|
+
| File | ~Lines | Responsibility |
|
|
140
|
+
|------|--------|----------------|
|
|
141
|
+
| `src/worktree/worktree-manager.ts` | ~150 | Git worktree creation, branch management |
|
|
142
|
+
| `src/worktree/setup-hooks.ts` | ~60 | Post-worktree-creation setup scripts |
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 3. Bugs & Code Quality Issues
|
|
147
|
+
|
|
148
|
+
### 🐛 Bug #1: Redundant Ternary trong blob-store.ts (HIGH)
|
|
149
|
+
|
|
150
|
+
**File**: `src/state/blob-store.ts`
|
|
151
|
+
**Line**: ~60
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const content = typeof input.content === "string" ? input.content : input.content;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Vấn đề**: Ternary luôn return `input.content` — condition meaningless. Có thể là copy-paste error, ban đầu intended để handle Buffer/Uint8Array fallback.
|
|
158
|
+
|
|
159
|
+
**Fix**:
|
|
160
|
+
```typescript
|
|
161
|
+
const content = input.content;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Hoặc nếu intended để validate type:
|
|
165
|
+
```typescript
|
|
166
|
+
if (typeof input.content !== "string") throw new TypeError("content must be string");
|
|
167
|
+
const content = input.content;
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### 🐛 Bug #2: Non-null Assertion trên Potentially Empty Array (MEDIUM)
|
|
173
|
+
|
|
174
|
+
**File**: `src/runtime/team-runner.ts`
|
|
175
|
+
**Line**: ~385
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
manifest = { ...results.at(-1)!.manifest, ... };
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Vấn đề**: `results.at(-1)!` assert non-null nhưng nếu `batchTasks` empty (race condition hoặc edge case), sẽ throw TypeError.
|
|
182
|
+
|
|
183
|
+
**Fix**:
|
|
184
|
+
```typescript
|
|
185
|
+
const lastResult = results.at(-1);
|
|
186
|
+
if (!lastResult) break;
|
|
187
|
+
manifest = { ...lastResult.manifest, ... };
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### 🐛 Bug #3: Indentation Sai trong Switch Case (LOW)
|
|
193
|
+
|
|
194
|
+
**File**: `src/extension/team-tool.ts`
|
|
195
|
+
**Line**: ~267
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
case "prune": return handlePrune(params, ctx); // extra tab
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**Vấn đề**: Copy-paste artifact — case `"prune"` có 1 tab thừa so với các cases khác.
|
|
202
|
+
|
|
203
|
+
**Fix**: Xóa 1 tab.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### 🐛 Bug #4: observeStdoutChunk Creates New Observer Per Call (LOW)
|
|
208
|
+
|
|
209
|
+
**File**: `src/runtime/child-pi.ts`
|
|
210
|
+
**Line**: ~246
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
function observeStdoutChunk(input: ChildPiRunInput, text: string): void {
|
|
214
|
+
const observer = new ChildPiLineObserver(input);
|
|
215
|
+
observer.observe(text);
|
|
216
|
+
observer.flush();
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
**Vấn đề**: Tạo `new ChildPiLineObserver` mỗi call. Trong real code path, observer được tạo 1 lần và reuse. Mock path nên làm tương tự.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
### 🐛 Bug #5: Silent Event Bus Error Swallowing (LOW)
|
|
225
|
+
|
|
226
|
+
**File**: `src/state/event-log.ts`
|
|
227
|
+
**Line**: ~151
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
try { emitFromTeamEvent(fullEvent); } catch { /* event bus errors are non-fatal */ }
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**Vấn đề**: Nếu event bus throws repeatedly (e.g., bug in subscriber), mỗi `appendEvent` call silently continues. Mask real issues.
|
|
234
|
+
|
|
235
|
+
**Fix**: Thêm debug-level logging:
|
|
236
|
+
```typescript
|
|
237
|
+
try { emitFromTeamEvent(fullEvent); } catch (error) { logInternalError("event-log.emit", error); }
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## 4. Test Coverage Analysis
|
|
243
|
+
|
|
244
|
+
### Test Coverage Matrix
|
|
245
|
+
|
|
246
|
+
| Module | ~Lines | Has Tests? | Test File | Test Count | Coverage |
|
|
247
|
+
|--------|--------|-----------|-----------|------------|----------|
|
|
248
|
+
| `event-stream-bridge.ts` | 80 | ✅ | `event-stream-bridge.test.ts` | 11 | Good |
|
|
249
|
+
| `render-coalescer.ts` | 60 | ✅ | `render-coalescer.test.ts` | 7 | Good |
|
|
250
|
+
| `result-extractor.ts` | 130 | ✅ | `result-extractor.test.ts` | 17 | Good |
|
|
251
|
+
| `mailbox.ts` | 380 | ✅ | `mailbox-reply.test.ts` | 6 | Partial |
|
|
252
|
+
| `task-output-context.ts` | 180 | ✅ | `dependency-context-enhanced.test.ts` | 6 | Partial |
|
|
253
|
+
| `transcript-entries.ts` | 200 | ✅ | `transcript-entries.test.ts` | 10 | Good |
|
|
254
|
+
| `agent-management-overlay.ts` | 130 | ✅ | `agent-management-overlay.test.ts` | 10 | Good |
|
|
255
|
+
| `agent-search.ts` | 140 | ✅ | `agent-search.test.ts` | 8 | Good |
|
|
256
|
+
| `code-summary.ts` | 240 | ✅ | `code-summary.test.ts` | 22 | Good |
|
|
257
|
+
| `sse-parser.ts` | 120 | ✅ | `sse-parser.test.ts` | 13 | Good |
|
|
258
|
+
| `stream-preview.ts` | 140 | ✅ | `stream-preview.test.ts` | 14 | Good |
|
|
259
|
+
| `notebook-helpers.ts` | 90 | ✅ | `notebook-helpers.test.ts` | 12 | Good |
|
|
260
|
+
| `visual.ts` | 200 | ✅ | `visual.test.ts` | 5 | Good |
|
|
261
|
+
| `frontmatter.ts` | 80 | ✅ | `frontmatter.test.ts` | ~8 | Good |
|
|
262
|
+
| `config.ts` | 840 | ✅ | `config.test.ts` + others | ~20 | Partial |
|
|
263
|
+
| **`child-pi.ts`** | **380** | ❌ | — | 0 | **NONE** |
|
|
264
|
+
| **`team-runner.ts`** | **520** | ❌ | — | 0 | **NONE** |
|
|
265
|
+
| **`team-tool.ts`** | **400** | ❌ | — | 0 | **NONE** |
|
|
266
|
+
| **`state-store.ts`** | **250** | ❌ | — | 0 | **NONE** |
|
|
267
|
+
| **`run-dashboard.ts`** | **460** | ❌ | — | 0 | **NONE** |
|
|
268
|
+
| **`worktree-manager.ts`** | **150** | ❌ | — | 0 | **NONE** |
|
|
269
|
+
| **`event-log.ts`** | **180** | ✅ | `run-event-bus.test.ts` | 4 | Minimal |
|
|
270
|
+
| **`run-snapshot-cache.ts`** | **550** | ❌ | — | 0 | **NONE** |
|
|
271
|
+
| **`task-runner.ts`** | **430** | ✅ | Integration | 3 | Minimal |
|
|
272
|
+
| `blob-store.ts` | 120 | ✅ | `blob-store.test.ts` | ~6 | Good |
|
|
273
|
+
| `powerbar-publisher.ts` | 130 | ✅ | `powerbar-publisher.test.ts` | 6 | Good |
|
|
274
|
+
| `discover-agents.ts` | 120 | ✅ | `discovery.test.ts` | ~8 | Good |
|
|
275
|
+
| `hooks/registry.ts` | — | ✅ | `hooks.test.ts` | ~5 | Good |
|
|
276
|
+
|
|
277
|
+
### Coverage Summary
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
Total src/ modules: ~50
|
|
281
|
+
Tested: ~32 (64%)
|
|
282
|
+
Untested: ~18 (36%)
|
|
283
|
+
|
|
284
|
+
Critical untested (HIGH risk):
|
|
285
|
+
- child-pi.ts (380 lines) — process lifecycle, kill logic
|
|
286
|
+
- team-runner.ts (520 lines) — scheduler, adaptive planning
|
|
287
|
+
- team-tool.ts (400 lines) — 25+ action dispatch
|
|
288
|
+
- state-store.ts (250 lines) — manifest CRUD
|
|
289
|
+
|
|
290
|
+
Important untested (MEDIUM risk):
|
|
291
|
+
- run-dashboard.ts (460 lines) — UI rendering
|
|
292
|
+
- run-snapshot-cache.ts (550 lines) — caching logic
|
|
293
|
+
- worktree-manager.ts (150 lines) — git operations
|
|
294
|
+
- event-log.ts (180 lines) — event persistence
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Test Count Breakdown
|
|
298
|
+
|
|
299
|
+
```
|
|
300
|
+
Unit tests: ~74 new (Phase 1-4) + ~30 existing = ~104
|
|
301
|
+
Integration tests: 46 (test/integration/)
|
|
302
|
+
Total: ~150 tests
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## 5. Performance Concerns
|
|
308
|
+
|
|
309
|
+
### 5.1 File-Polling Overhead
|
|
310
|
+
|
|
311
|
+
**Files**: `run-snapshot-cache.ts`, `powerbar-publisher.ts`, `crew-widget.ts`
|
|
312
|
+
|
|
313
|
+
UI components poll files mỗi 200-500ms cho active runs. Mỗi poll:
|
|
314
|
+
1. `stat()` manifest, tasks, agents, events, mailbox, output files
|
|
315
|
+
2. If stale → re-read và parse JSON
|
|
316
|
+
3. Build snapshot → render
|
|
317
|
+
|
|
318
|
+
**Impact**: Với 2+ active runs, mỗi tick reads 12+ files. Đã cải thiện bằng `RenderCoalescer` (Phase 1), nhưng polling vẫn là bottleneck.
|
|
319
|
+
|
|
320
|
+
**Mitigation**: Event Stream Bridge (Phase 1) bypass polling cho real-time events. Nhưng snapshot cache vẫn poll cho full state.
|
|
321
|
+
|
|
322
|
+
### 5.2 Event Log Append-Only Growth
|
|
323
|
+
|
|
324
|
+
**File**: `src/state/event-log.ts`
|
|
325
|
+
|
|
326
|
+
Events JSONL file grows unbounded. Large runs (100+ tasks) có thể produce 10,000+ events → file becomes slow to tail.
|
|
327
|
+
|
|
328
|
+
**Mitigation**: `MAX_TAIL_LINES = 500` trong snapshot cache. Nhưng file I/O vẫn O(file_size) cho append.
|
|
329
|
+
|
|
330
|
+
### 5.3 Manifest JSON Rewrite on Every Status Change
|
|
331
|
+
|
|
332
|
+
**Files**: `state-store.ts`, `team-runner.ts`
|
|
333
|
+
|
|
334
|
+
Mỗi task status change → rewrite toàn bộ `manifest.json` và `tasks.json`. Với 10 concurrent tasks updating every second → 20 full JSON serializations/sec.
|
|
335
|
+
|
|
336
|
+
**Mitigation**: Có thể dùng append-only format (JSONL) cho tasks, chỉ rewrite manifest khi structure changes.
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## 6. Security Analysis
|
|
341
|
+
|
|
342
|
+
### ✅ Good Practices
|
|
343
|
+
|
|
344
|
+
| Area | File | Detail |
|
|
345
|
+
|------|------|--------|
|
|
346
|
+
| Path traversal | `safe-paths.ts` | Containment validation cho all file paths |
|
|
347
|
+
| Secret redaction | `redaction.ts` | Redacts JSON lines containing secrets |
|
|
348
|
+
| Depth guards | `pi-args.ts` | `checkCrewDepth()` prevents recursive spawning |
|
|
349
|
+
| Plan approval | `team-runner.ts` | Plan approval gate cho implementation workflow |
|
|
350
|
+
| Symlink containment | `safe-paths.ts` | `resolveRealContainedPath()` resolves symlinks |
|
|
351
|
+
|
|
352
|
+
### ⚠️ Concerns
|
|
353
|
+
|
|
354
|
+
| # | Severity | File | Issue |
|
|
355
|
+
|---|----------|------|-------|
|
|
356
|
+
| 1 | MEDIUM | `worktree-manager.ts:107` | `JSON.parse(trimmed) as { syntheticPaths?: unknown }` — unchecked cast, could throw on malformed JSON |
|
|
357
|
+
| 2 | MEDIUM | `config.ts:303-405` | ~20 `as Record<string, unknown>` casts bypass type safety trong config merge |
|
|
358
|
+
| 3 | LOW | `task-runner.ts` | Worker stdout parsing assumes valid JSON lines — malformed lines could cause silent data loss |
|
|
359
|
+
| 4 | LOW | `child-pi.ts` | `killProcessTree` uses `taskkill /t /f` on Windows — potential for killing wrong processes if PID reused |
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## 7. Code Hygiene
|
|
364
|
+
|
|
365
|
+
### 7.1 `__test__` Export Pattern
|
|
366
|
+
|
|
367
|
+
Files exporting test-only helpers (pollute public API):
|
|
368
|
+
|
|
369
|
+
| File | Exports |
|
|
370
|
+
|------|---------|
|
|
371
|
+
| `team-runner.ts` | `__test__parseAdaptivePlan`, `__test__repairAdaptivePlan`, `__test__mergeTaskUpdates` |
|
|
372
|
+
| `state-store.ts` | `__test__manifestCacheSize`, `__test__clearManifestCache` |
|
|
373
|
+
| `config/i18n.ts` | `__test__resetI18n` |
|
|
374
|
+
| `runtime/pi-spawn.ts` | `__test__subagentSpawnParams` |
|
|
375
|
+
| `utils/visual.ts` | `__test__clearVisibleWidthCache`, `__test__visibleWidthCacheSize` |
|
|
376
|
+
|
|
377
|
+
**Count**: 7+ files, 9+ exports
|
|
378
|
+
|
|
379
|
+
**Recommendation**: Move test helpers vào separate `internal` export hoặc dùng `export type` conditional pattern.
|
|
380
|
+
|
|
381
|
+
### 7.2 Config Merge Type Safety
|
|
382
|
+
|
|
383
|
+
**File**: `src/config/config.ts` (lines 303-405)
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
const overrideRecord = override as Record<string, unknown>;
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
~20 unsafe casts trong config merge function. Bypass type safety cho nested config field merging.
|
|
390
|
+
|
|
391
|
+
**Recommendation**: Dùng validated schema approach (similar to oh-my-pi's `settings-schema.ts`).
|
|
392
|
+
|
|
393
|
+
### 7.3 Unused / Dead Code
|
|
394
|
+
|
|
395
|
+
| Item | File | Detail |
|
|
396
|
+
|------|------|--------|
|
|
397
|
+
| `observeStdoutChunk` | `child-pi.ts:246` | Defined but only used in mock path — creates new observer each call |
|
|
398
|
+
| Redundant ternary | `blob-store.ts:60` | `typeof x === "string" ? x : x` — always returns same value |
|
|
399
|
+
| `formatTranscriptEvent` export | `transcript-viewer.ts` | Exported but may not be imported externally |
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
## 8. Dependency Graph — Module Coupling
|
|
404
|
+
|
|
405
|
+
```
|
|
406
|
+
extension/register.ts (550 lines) — GOD FILE
|
|
407
|
+
├── depends on: team-tool.ts, run-dashboard.ts, crew-widget.ts,
|
|
408
|
+
│ powerbar-publisher.ts, config.ts, run-event-bus.ts,
|
|
409
|
+
│ state-store.ts, manifest-cache.ts, active-run-registry.ts,
|
|
410
|
+
│ skill-instructions.ts, capability-inventory.ts,
|
|
411
|
+
│ team-runner.ts, pi-spawn.ts, run-index.ts
|
|
412
|
+
└── 20+ imports — highest coupling in codebase
|
|
413
|
+
|
|
414
|
+
team-tool.ts (400 lines)
|
|
415
|
+
├── depends on: run.ts, cancel.ts, status.ts, respond.ts, api.ts,
|
|
416
|
+
│ state-store.ts, team-runner.ts, manifest-cache.ts
|
|
417
|
+
└── 15+ imports
|
|
418
|
+
|
|
419
|
+
team-runner.ts (520 lines)
|
|
420
|
+
├── depends on: task-runner.ts, task-graph-scheduler.ts, state-store.ts,
|
|
421
|
+
│ event-log.ts, mailbox.ts, agent-control.ts, policy.ts
|
|
422
|
+
└── 12+ imports
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
`register.ts` là coupling hotspot — 20+ imports. Nên tách thành smaller registration modules.
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## 9. Recommendations (Priority Order)
|
|
430
|
+
|
|
431
|
+
### P0 — Fix Bugs
|
|
432
|
+
1. Fix blob-store redundant ternary
|
|
433
|
+
2. Fix team-runner non-null assertion
|
|
434
|
+
3. Add error logging cho silent event bus catch
|
|
435
|
+
|
|
436
|
+
### P1 — Test Coverage
|
|
437
|
+
4. Add unit tests cho `child-pi.ts` (mock ChildProcess)
|
|
438
|
+
5. Add unit tests cho `team-runner.ts` (mock task execution)
|
|
439
|
+
6. Add unit tests cho `team-tool.ts` (action dispatch)
|
|
440
|
+
7. Add unit tests cho `state-store.ts` (manifest CRUD)
|
|
441
|
+
|
|
442
|
+
### P2 — Performance
|
|
443
|
+
8. Implement append-only tasks format (JSONL thay vì full JSON rewrite)
|
|
444
|
+
9. Add event log rotation/compaction cho long runs
|
|
445
|
+
10. Implement incremental event reading (seek to offset thay vì tail toàn bộ)
|
|
446
|
+
|
|
447
|
+
### P3 — Code Quality
|
|
448
|
+
11. Extract test helpers vào `internal/` exports
|
|
449
|
+
12. Reduce register.ts coupling — tách thành smaller registration modules
|
|
450
|
+
13. Validate config merge với schema thay vì unsafe casts
|
|
451
|
+
14. Fix worktree-manager.ts JSON parse error handling
|
|
452
|
+
|
|
453
|
+
### P4 — Architecture
|
|
454
|
+
15. Typed event channels (worker:progress, worker:lifecycle, worker:stream)
|
|
455
|
+
16. Yield tool enforcement (schema validation + retry reminders)
|
|
456
|
+
17. SubprocessToolRegistry pattern cho worker result extraction
|
|
457
|
+
18. MCP proxy tools cho child processes
|