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,385 @@
|
|
|
1
|
+
# Pi-Crew Improvement Plan — 14 Enhancements from oh-my-pi
|
|
2
|
+
|
|
3
|
+
## Tổng quan
|
|
4
|
+
|
|
5
|
+
14 cải tiến được chia thành 4 phases. Mỗi phase có thể thực hiện độc lập,
|
|
6
|
+
không conflict file với nhau (trừ khi ghi chú).
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Phase 1: Quick Wins (3-4 ngày)
|
|
11
|
+
> Chất lượng cuộc sống, ít risk, ảnh hưởng ngay
|
|
12
|
+
|
|
13
|
+
### 1.2 Orchestration Skill
|
|
14
|
+
**Mục tiêu**: Tạo orchestration skill cho planner/executor, ép orchestrator làm việc hiệu quả hơn.
|
|
15
|
+
|
|
16
|
+
**Files tạo/sửa**:
|
|
17
|
+
- `skills/orchestration/SKILL.md` — TẠO MỚI (prompt template)
|
|
18
|
+
- `skills/orchestration/SKILL.md` — TẠO MỚI
|
|
19
|
+
|
|
20
|
+
**Chi tiết**:
|
|
21
|
+
- Nội dung dựa trên oh-my-pi `orchestrate.md` pattern
|
|
22
|
+
- Bao gồm: rules (parallelize, verify, respawn), workflow (ingest → plan → dispatch → verify → commit → advance), anti-patterns
|
|
23
|
+
- Điều chỉnh cho pi-crew context: dùng `task` subagent thay vì trực tiếp edit, dùng mailbox cho coordination
|
|
24
|
+
- Thêm `orchestration` vào default skills cho planner role trong `src/runtime/skill-instructions.ts`
|
|
25
|
+
|
|
26
|
+
**Test**: Manual — chạy team run với orchestration skill, verify planner output quality
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### 1.3 `/retry` Manual Retry Command
|
|
31
|
+
**Mục tiêu**: Thêm slash command cho phép retry failed/aborted tasks thủ công.
|
|
32
|
+
|
|
33
|
+
**Files tạo/sửa**:
|
|
34
|
+
- `src/extension/registration/commands.ts` — thêm `team-retry` command
|
|
35
|
+
- `src/extension/team-tool/cancel.ts` — thêm `handleRetry` function
|
|
36
|
+
|
|
37
|
+
**Chi tiết**:
|
|
38
|
+
- Command: `/team-retry <runId> [taskId]`
|
|
39
|
+
- Logic:
|
|
40
|
+
1. Load manifest, tìm task failed/aborted
|
|
41
|
+
2. Nếu chỉ định taskId → retry task đó, set status về "queued"
|
|
42
|
+
3. Nếu không chỉ định → retry tất cả failed/aborted tasks
|
|
43
|
+
4. Reset task metadata (error, finishedAt, terminalEvidence)
|
|
44
|
+
5. Execute hook `before_retry` (nếu có)
|
|
45
|
+
6. Re-run task qua `runTeamTask()`
|
|
46
|
+
- Pre-check: ownership, run không đang active
|
|
47
|
+
- Result message: "Retried N task(s) in run X"
|
|
48
|
+
|
|
49
|
+
**Test**: Unit test trong `test/unit/` — mock manifest với failed task, verify reset + re-run
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### 1.9 Intent Text trên Team Tool Actions
|
|
54
|
+
**Mục tiêu**: Mỗi team tool action (run, cancel, status, etc.) trả về intent text hiển thị trong powerbar.
|
|
55
|
+
|
|
56
|
+
**Files tạo/sửa**:
|
|
57
|
+
- `src/extension/team-tool/context.ts` — thêm `intentText` vào result metadata
|
|
58
|
+
- `src/extension/team-tool/run.ts` — thêm intent: `"running {team} team for: {goal[:60]}"`
|
|
59
|
+
- `src/extension/team-tool/cancel.ts` — thêm intent: `"cancelling run {runId}"`
|
|
60
|
+
- `src/extension/team-tool/status.ts` — thêm intent: `"checking status of run {runId}"`
|
|
61
|
+
- `src/extension/team-tool/respond.ts` — thêm intent: `"responding to task {taskId}"`
|
|
62
|
+
- `src/ui/powerbar-publisher.ts` — hiển thị intent text khi có
|
|
63
|
+
|
|
64
|
+
**Chi tiết**:
|
|
65
|
+
- Mỗi action function thêm `intent` field vào result metadata
|
|
66
|
+
- Powerbar segment hiển thị intent text (truncate 60 chars)
|
|
67
|
+
- Intent chỉ xuất hiện khi action đang chạy, không persist
|
|
68
|
+
|
|
69
|
+
**Test**: Unit test — verify mỗi action trả về đúng intent text
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Phase 2: Worker Efficiency (3-4 ngày)
|
|
74
|
+
> Tăng hiệu suất worker, giảm context waste
|
|
75
|
+
|
|
76
|
+
### 2.5 Workspace Tree Context Injection
|
|
77
|
+
**Mục tiêu**: Inject compact directory tree vào worker prompt để worker hiểu project structure mà không cần explore.
|
|
78
|
+
|
|
79
|
+
**Files tạo/sửa**:
|
|
80
|
+
- `src/runtime/workspace-tree.ts` — TẠO MỚI
|
|
81
|
+
- `src/runtime/task-runner/prompt-builder.ts` — thêm tree block vào prompt
|
|
82
|
+
- `src/runtime/task-runner.ts` — gọi buildWorkspaceTree trước khi render prompt
|
|
83
|
+
|
|
84
|
+
**Chi tiết**:
|
|
85
|
+
- `buildWorkspaceTree(cwd, options)`:
|
|
86
|
+
- `maxDepth: 3`, `directoryEntryLimit: 12`, `lineCap: 120`
|
|
87
|
+
- Skip: node_modules, .git, dist, build, target, .venv, .cache
|
|
88
|
+
- Sort by mtime (recency)
|
|
89
|
+
- Output format: indented list với size + age
|
|
90
|
+
- Async, trả về string hoặc "" nếu lỗi
|
|
91
|
+
- Trong `renderTaskPrompt()`:
|
|
92
|
+
- Thêm section `# Workspace Structure` sau worker context
|
|
93
|
+
- Cache tree per-cwd (TTL 30s) để không rebuild cho mỗi task
|
|
94
|
+
- Option: chỉ inject khi task có `injectWorkspaceTree: true` hoặc khi role là explorer/executor
|
|
95
|
+
|
|
96
|
+
**Test**: Unit test — tạo temp dir structure, verify output format và truncation
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### 2.8 Cache-Stable Worker Prompts
|
|
101
|
+
**Mục tiêu**: Tách worker prompts thành stable prefix + dynamic suffix để tối ưu KV-cache reuse.
|
|
102
|
+
|
|
103
|
+
**Files tạo/sửa**:
|
|
104
|
+
- `src/runtime/task-runner/prompt-builder.ts` — refactor prompt structure
|
|
105
|
+
- `src/runtime/skill-instructions.ts` — tách skill block ra riêng
|
|
106
|
+
|
|
107
|
+
**Chi tiết**:
|
|
108
|
+
- Prompt structure hiện tại: 1 big system message
|
|
109
|
+
- Refactor thành:
|
|
110
|
+
1. **Stable prefix**: role instructions, coordination contract, workspace tree (ít thay đổi giữa tasks)
|
|
111
|
+
2. **Dynamic suffix**: task-specific goal, dependency context, skill instructions (thay đổi mỗi task)
|
|
112
|
+
- `renderTaskPrompt()` trả về `{ stablePrefix: string, dynamicSuffix: string }`
|
|
113
|
+
- `runChildPi()` ghép 2 phần, hoặc gửi riêng nếu provider hỗ trợ multi-system-messages
|
|
114
|
+
- Đo lường: verify cache hit rate tăng khi chạy cùng team nhiều tasks
|
|
115
|
+
|
|
116
|
+
**Test**: Unit test — verify prompt structure, verify stable prefix giống nhau giữa 2 tasks cùng role
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### 2.9 (tiếp) Intent trên powerbar — hoàn thiện
|
|
121
|
+
Xem 1.9 ở Phase 1.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Phase 3: Token Optimization (4-5 ngày)
|
|
126
|
+
> Giảm token usage, chỉ load những gì cần
|
|
127
|
+
|
|
128
|
+
### 3.1 Tool LoadMode Pattern
|
|
129
|
+
**Mục tiêu**: Phân loại tools thành "essential" (luôn load) vs "discoverable" (chỉ load khi cần), giảm prompt size cho workers.
|
|
130
|
+
|
|
131
|
+
**Files tạo/sửa**:
|
|
132
|
+
- `src/runtime/role-permission.ts` — thêm `loadMode` vào tool definitions
|
|
133
|
+
- `src/runtime/task-runner/prompt-builder.ts` — chỉ inject prompt snippets cho essential tools
|
|
134
|
+
- `src/runtime/capability-inventory.ts` — track discoverable tools
|
|
135
|
+
- `src/runtime/skill-instructions.ts` — thêm `search_tool_bm25` khi có discoverable tools
|
|
136
|
+
|
|
137
|
+
**Chi tiết**:
|
|
138
|
+
- Tool classification:
|
|
139
|
+
- **Essential** (luôn active): `bash`, `read`, `edit`, `write` (cho read-write roles)
|
|
140
|
+
- **Discoverable** (ẩn): `github`, `browser`, `ast-grep`, `ast-edit`, `calculator`, `render-mermaid`, etc.
|
|
141
|
+
- Role-level override: explorer chỉ cần `read` essential, executor cần `bash` + `read` + `edit`
|
|
142
|
+
- Khi có discoverable tools:
|
|
143
|
+
- Inject `search_tool_bm25` tool vào available tools
|
|
144
|
+
- Thêm instruction: "Some tools are hidden. Use search_tool_bm25 to discover them."
|
|
145
|
+
- Worker sees: fewer tool definitions → smaller prompt → more context room
|
|
146
|
+
|
|
147
|
+
**Test**: Unit test — verify role permissions, verify discoverable tools excluded from prompt
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
### 3.7 BM25 Agent Discovery
|
|
152
|
+
**Mục tiêu**: Thêm BM25 search cho agent discovery — tìm agent phù hợp nhất theo task description.
|
|
153
|
+
|
|
154
|
+
**Files tạo/sửa**:
|
|
155
|
+
- `src/agents/agent-search.ts` — TẠO MỚI
|
|
156
|
+
- `src/agents/discover-agents.ts` — thêm search capability
|
|
157
|
+
- `src/runtime/task-runner.ts` — sử dụng agent search khi auto-select agent
|
|
158
|
+
|
|
159
|
+
**Chi tiết**:
|
|
160
|
+
- `buildAgentSearchIndex(agents)`:
|
|
161
|
+
- BM25 trên fields: name (6x), label (4x), description (2x), tags (1x)
|
|
162
|
+
- Reuse BM25 implementation từ `src/skills/discover-skills.ts` (hoặc extract shared)
|
|
163
|
+
- `searchAgents(index, query, limit)` → ranked agent list
|
|
164
|
+
- Khi task không chỉ định agent, hệ thống có thể:
|
|
165
|
+
1. Extract keywords từ task description
|
|
166
|
+
2. Search top 3 agents
|
|
167
|
+
3. Auto-select best match hoặc suggest cho planner
|
|
168
|
+
- Integration: trong `handleRun()` khi `params.agent` không set
|
|
169
|
+
|
|
170
|
+
**Test**: Unit test — tạo test agents, verify search ranking
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### 3.13 Agent-as-Markdown Frontmatter Enhancement
|
|
175
|
+
**Mục tiêu**: Thêm frontmatter fields vào agent config: `loadMode`, `defaultTools`, `contextMode`.
|
|
176
|
+
|
|
177
|
+
**Files tạo/sửa**:
|
|
178
|
+
- `src/agents/agent-config.ts` — thêm fields vào AgentConfig type
|
|
179
|
+
- `src/agents/agent-serializer.ts` — parse/serialize new fields
|
|
180
|
+
- `src/runtime/task-runner.ts` — respect loadMode và defaultTools
|
|
181
|
+
|
|
182
|
+
**Chi tiết**:
|
|
183
|
+
- New frontmatter fields:
|
|
184
|
+
```yaml
|
|
185
|
+
---
|
|
186
|
+
name: explorer
|
|
187
|
+
description: Fast codebase discovery
|
|
188
|
+
loadMode: essential # "essential" | "discoverable"
|
|
189
|
+
defaultTools: [read, bash, find]
|
|
190
|
+
contextMode: fresh # "fresh" | "fork"
|
|
191
|
+
---
|
|
192
|
+
```
|
|
193
|
+
- `AgentConfig` thêm optional fields
|
|
194
|
+
- `renderTaskPrompt()` respects `defaultTools` — chỉ inject specified tools
|
|
195
|
+
- `loadMode` maps sang 3.1's loadMode pattern
|
|
196
|
+
- Default values: `loadMode: "essential"`, `defaultTools: null` (all tools)
|
|
197
|
+
|
|
198
|
+
**Test**: Unit test — parse frontmatter với new fields, verify defaults
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Phase 4: Advanced Features (5-7 ngày)
|
|
203
|
+
> Tính năng nâng cao, cần nhiều effort hơn
|
|
204
|
+
|
|
205
|
+
### 4.4 Streaming Preview cho Worker Output
|
|
206
|
+
**Mục tiêu**: Hiển thị preview worker output (file changes) trong TUI khi worker đang chạy.
|
|
207
|
+
|
|
208
|
+
**Files tạo/sửa**:
|
|
209
|
+
- `src/ui/worker-preview.ts` — TẠO MỚI
|
|
210
|
+
- `src/runtime/task-runner.ts` — capture streaming output events
|
|
211
|
+
- `src/ui/powerbar-publisher.ts` — integrate preview
|
|
212
|
+
|
|
213
|
+
**Chi tiết**:
|
|
214
|
+
- Khi worker emit JSON events (tool calls, edits), capture và render preview
|
|
215
|
+
- Preview formats:
|
|
216
|
+
- Write tool: hiển thị last 12 lines với line numbers + syntax highlight
|
|
217
|
+
- Bash tool: hiển thị last 10 lines output
|
|
218
|
+
- Edit tool: hiển thị diff summary
|
|
219
|
+
- Powerbar segment mở rộng khi có preview content
|
|
220
|
+
- Fallback: nếu TUI không support, chỉ hiển thị spinner như hiện tại
|
|
221
|
+
- Streaming events parse từ child Pi JSONL output (đã có `parsePiJsonOutput`)
|
|
222
|
+
|
|
223
|
+
**Test**: Unit test — mock streaming events, verify preview format
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
### 4.6 Structural Code Summary
|
|
228
|
+
**Mục tiêu**: Tạo code summarization capability cho explorer/reviewer roles — đọc structure thay vì toàn bộ file.
|
|
229
|
+
|
|
230
|
+
**Files tạo/sửa**:
|
|
231
|
+
- `src/runtime/code-summary.ts` — TẠO MỚI (TypeScript fallback)
|
|
232
|
+
- `src/runtime/task-runner/prompt-builder.ts` — inject summary thay vì raw content (optional)
|
|
233
|
+
|
|
234
|
+
**Chi tiết**:
|
|
235
|
+
- **Option A** (JS-only): Regex-based summary cho common patterns (functions, classes, imports)
|
|
236
|
+
- Parse: export/function/class/interface/type declarations
|
|
237
|
+
- Elide: function bodies, long arrays, block comments
|
|
238
|
+
- Output: kept/elided segments
|
|
239
|
+
- **Option B** (Rust native): Gọi `@oh-my-pi/pi-natives` `summarize_code` nếu available
|
|
240
|
+
- Check: `try { await import("@oh-my-pi/pi-natives") } catch {}`
|
|
241
|
+
- Fallback to Option A nếu native không available
|
|
242
|
+
- Integration:
|
|
243
|
+
- Explorer role: default inject summaries thay vì raw files
|
|
244
|
+
- Reviewer role: inject summaries + diff context
|
|
245
|
+
- Executor role: vẫn dùng raw files (cần exact content để edit)
|
|
246
|
+
- Config: `agent.summaryMode: "off" | "structure" | "full"` trong frontmatter
|
|
247
|
+
|
|
248
|
+
**Test**: Unit test — verify summary output cho sample TS/Rust/Python files
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
### 4.10 Task Diff API
|
|
253
|
+
**Mục tiêu**: Expose API để external consumers xem diff của những gì worker đã thay đổi.
|
|
254
|
+
|
|
255
|
+
**Files tạo/sửa**:
|
|
256
|
+
- `src/extension/team-tool/api.ts` — thêm `diff` action
|
|
257
|
+
- `src/extension/team-tool/inspect.ts` — thêm diff display
|
|
258
|
+
|
|
259
|
+
**Chi tiết**:
|
|
260
|
+
- New API action: `team api diff <runId> [taskId]`
|
|
261
|
+
- Logic:
|
|
262
|
+
1. Load manifest, tìm diff artifacts (từ worktree mode hoặc file snapshots)
|
|
263
|
+
2. Nếu worktree: chạy `git diff` trong worktree
|
|
264
|
+
3. Nếu không: đọc stored diff artifact
|
|
265
|
+
4. Format: unified diff + summary stats
|
|
266
|
+
- Team tool inspect: thêm diff section vào inspect output
|
|
267
|
+
- Powerbar: hiển thị diff stats khi task completes
|
|
268
|
+
|
|
269
|
+
**Test**: Unit test — mock diff artifacts, verify formatting
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
### 4.11 Notebook-Aware Path Handling
|
|
274
|
+
**Mục tiêu**: Support `.ipynb` files trong workers — parse cells, edit individual cells.
|
|
275
|
+
|
|
276
|
+
**Files tạo/sửa**:
|
|
277
|
+
- `src/runtime/notebook-helpers.ts` — TẠO MỚI
|
|
278
|
+
- `src/runtime/task-runner/prompt-builder.ts` — inject notebook instructions
|
|
279
|
+
|
|
280
|
+
**Chi tiết**:
|
|
281
|
+
- `parseNotebook(path)` → cells array
|
|
282
|
+
- `readNotebookCell(path, index)` → cell content
|
|
283
|
+
- `editNotebookCell(path, index, content)` → update cell
|
|
284
|
+
- Worker instructions: "For .ipynb files, use notebook helpers instead of raw read/write"
|
|
285
|
+
- Edge case: handle malformed notebooks gracefully
|
|
286
|
+
|
|
287
|
+
**Test**: Unit test — tạo sample .ipynb, verify parse/edit
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
### 4.12 Shared SSE Utility
|
|
292
|
+
**Mục tiêu**: Extract SSE parser cho potential future use (streaming dashboard, external integrations).
|
|
293
|
+
|
|
294
|
+
**Files tạo/sửa**:
|
|
295
|
+
- `src/utils/sse-parser.ts` — TẠO MỚI
|
|
296
|
+
|
|
297
|
+
**Chi tiết**:
|
|
298
|
+
- `readSseEvents(stream, signal)` → async generator of `ServerSentEvent`
|
|
299
|
+
- Handles: `\r\n`, `\n`, multi-line data, event types, `[DONE]` sentinel
|
|
300
|
+
- `readSseJson(stream, signal)` → wrapper parse JSON data
|
|
301
|
+
- Reusable cho:
|
|
302
|
+
- Future: streaming task status endpoint
|
|
303
|
+
- Future: external dashboard integration
|
|
304
|
+
- Current: không dùng ngay, nhưng available
|
|
305
|
+
|
|
306
|
+
**Test**: Unit test — verify SSE parsing cho various input formats
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
### 4.14 Control Notices Enhancement
|
|
311
|
+
**Mục tiêu**: Mở rộng attention tracking: consecutive tool failures, per-task thresholds, notification routing.
|
|
312
|
+
|
|
313
|
+
**Files tạo/sửa**:
|
|
314
|
+
- `src/runtime/agent-control.ts` — thêm control types
|
|
315
|
+
- `src/runtime/crew-agent-records.ts` — track tool failure counts
|
|
316
|
+
- `src/extension/notification-router.ts` — thêm notification channels
|
|
317
|
+
|
|
318
|
+
**Chi tiết**:
|
|
319
|
+
- New control events:
|
|
320
|
+
- `consecutive_tool_failures`: track N consecutive failed tool calls per task
|
|
321
|
+
- `long_running`: alert khi task chạy quá X minutes (configurable)
|
|
322
|
+
- `no_file_mutations`: alert khi implementation role completes without any file changes
|
|
323
|
+
- New config fields:
|
|
324
|
+
```json
|
|
325
|
+
{
|
|
326
|
+
"control": {
|
|
327
|
+
"consecutiveFailureThreshold": 3,
|
|
328
|
+
"longRunningMinutes": 10,
|
|
329
|
+
"mutationGuardRoles": ["executor", "worker"]
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
- Notification routing:
|
|
334
|
+
- `event`: append event (current behavior)
|
|
335
|
+
- `attention`: set activityState = "needs_attention" (current)
|
|
336
|
+
- `notify`: dispatch external notification (future: webhook, Slack)
|
|
337
|
+
- Integration: control check chạy trong `applyAttentionState()` — thêm checks mới
|
|
338
|
+
|
|
339
|
+
**Test**: Unit test — verify consecutive failure detection, long-running detection
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## Dependency Graph
|
|
344
|
+
|
|
345
|
+
```
|
|
346
|
+
Phase 1 (independent):
|
|
347
|
+
1.2 Orchestration ─┐
|
|
348
|
+
1.3 Retry ├─→ không phụ thuộc nhau
|
|
349
|
+
1.9 Intent ─┘
|
|
350
|
+
|
|
351
|
+
Phase 2 (light dependencies):
|
|
352
|
+
2.5 Workspace Tree ──→ 2.8 Cache-Stable Prompts (tree là stable prefix candidate)
|
|
353
|
+
|
|
354
|
+
Phase 3 (sequential):
|
|
355
|
+
3.13 Agent Frontmatter ──→ 3.1 Tool LoadMode ──→ 3.7 BM25 Agent Discovery
|
|
356
|
+
(frontmatter định nghĩa loadMode) (loadMode cần agent search khi auto-select)
|
|
357
|
+
|
|
358
|
+
Phase 4 (independent):
|
|
359
|
+
4.4 Streaming Preview
|
|
360
|
+
4.6 Code Summary
|
|
361
|
+
4.10 Task Diff API
|
|
362
|
+
4.11 Notebook Helpers
|
|
363
|
+
4.12 SSE Parser
|
|
364
|
+
4.14 Control Notices
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Execution Timeline
|
|
368
|
+
|
|
369
|
+
| Week | Phase | Deliverables |
|
|
370
|
+
|------|-------|-------------|
|
|
371
|
+
| 1 | Phase 1 | Orchestration skill + Retry command + Intent text |
|
|
372
|
+
| 1-2 | Phase 2 | Workspace tree + Cache-stable prompts |
|
|
373
|
+
| 2-3 | Phase 3 | Agent frontmatter + LoadMode + BM25 agent search |
|
|
374
|
+
| 3-4 | Phase 4 | Streaming preview + Code summary + Diff API + Control notices |
|
|
375
|
+
| 4 | Phase 4 | Notebook + SSE parser (lower priority) |
|
|
376
|
+
|
|
377
|
+
## Risk & Mitigation
|
|
378
|
+
|
|
379
|
+
| Risk | Mitigation |
|
|
380
|
+
|------|-----------|
|
|
381
|
+
| Tool loadMode breaking existing workflows | Default: tất cả tools essential (backward compatible) |
|
|
382
|
+
| BM25 agent search chọn sai agent | Fallback: giữ hiện tại behavior khi search score thấp |
|
|
383
|
+
| Code summary mất info quan trọng | Configurable: chỉ dùng cho explorer/reviewer, không phải executor |
|
|
384
|
+
| Streaming preview phức tạp | Phase 4, chỉ implement khi Phase 1-3 ổn định |
|
|
385
|
+
| Workspace tree too large cho context | Hard lineCap: 120 lines, only inject khi config bật |
|