@piagent/platform 1.0.0
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/.gitattributes +7 -0
- package/AGENTS.md +31 -0
- package/CHANGELOG.md +296 -0
- package/CODE_OF_CONDUCT.md +36 -0
- package/CONTRIBUTING.md +66 -0
- package/LICENSE +21 -0
- package/README.md +588 -0
- package/SECURITY.md +38 -0
- package/adapters/backend-api/profile.json +88 -0
- package/adapters/be-readonly-fe/profile.json +120 -0
- package/adapters/data/profile.json +88 -0
- package/adapters/devops/profile.json +92 -0
- package/adapters/docs/profile.json +74 -0
- package/adapters/fullstack/profile.json +94 -0
- package/adapters/generic/profile.json +95 -0
- package/adapters/mobile/profile.json +87 -0
- package/adapters/node-typescript/profile.json +76 -0
- package/adapters/python/profile.json +75 -0
- package/adapters/web-frontend/profile.json +101 -0
- package/catalog/capabilities.json +206 -0
- package/docs/architecture.md +64 -0
- package/docs/auto-delegation-policy.md +192 -0
- package/docs/capability-packs.md +234 -0
- package/docs/command-reference-vietnamese.md +484 -0
- package/docs/context-window-policy.md +85 -0
- package/docs/distribution-standard.md +229 -0
- package/docs/herdr-workflow.md +58 -0
- package/docs/mcp-and-tools.md +316 -0
- package/docs/memory-policy.md +164 -0
- package/docs/model-options.md +165 -0
- package/docs/oauth-providers.md +53 -0
- package/docs/operator-manual-vietnamese.md +1080 -0
- package/docs/package-architecture-notes.md +101 -0
- package/docs/project-adapters.md +174 -0
- package/docs/project-onboarding.md +135 -0
- package/docs/publishing-for-teams.md +64 -0
- package/docs/quality-benchmark.md +74 -0
- package/docs/quickstart-vietnamese.md +350 -0
- package/docs/release-install-policy.md +223 -0
- package/docs/runtime-harness-standard.md +118 -0
- package/docs/runtime-policy-design.md +132 -0
- package/docs/runtime-quality-baseline.md +257 -0
- package/docs/security-redaction-benchmark.md +56 -0
- package/docs/security-threat-model.md +66 -0
- package/docs/subagent-orchestration-capabilities.md +104 -0
- package/docs/subagents-and-multiagent.md +346 -0
- package/docs/task-implementation-contract.md +200 -0
- package/docs/team-onboarding.md +333 -0
- package/docs/usage-observability.md +130 -0
- package/docs/vercel-docs-site.md +115 -0
- package/docs/workflow-recipes.md +125 -0
- package/docs-site/assets/piagent-logo.svg +35 -0
- package/docs-site/favicon.svg +18 -0
- package/docs-site/index.html +1613 -0
- package/docs-site/vercel.json +24 -0
- package/evals/fixtures/action-proposal.invalid.json +34 -0
- package/evals/fixtures/action-proposal.valid.json +34 -0
- package/evals/fixtures/capability-pack.invalid.json +123 -0
- package/evals/fixtures/capability-pack.valid.json +123 -0
- package/evals/fixtures/capability-recipe.invalid.json +81 -0
- package/evals/fixtures/capability-recipe.valid.json +82 -0
- package/evals/fixtures/context-index.invalid.json +25 -0
- package/evals/fixtures/context-index.valid.json +25 -0
- package/evals/fixtures/eval-scenario.invalid.json +40 -0
- package/evals/fixtures/eval-scenario.valid.json +45 -0
- package/evals/fixtures/project-profile.invalid.json +88 -0
- package/evals/fixtures/project-profile.valid.json +95 -0
- package/evals/fixtures/task-contract.invalid.json +73 -0
- package/evals/fixtures/task-contract.valid.json +74 -0
- package/evals/golden/enforcement-decisions.json +329 -0
- package/evals/scenarios/capability-resolution.json +45 -0
- package/package.json +132 -0
- package/packages/piagent-core/README.md +147 -0
- package/packages/piagent-core/capabilities/capability-core.js +1023 -0
- package/packages/piagent-core/capabilities/capability-sources.js +265 -0
- package/packages/piagent-core/extensions/guard-io.js +45 -0
- package/packages/piagent-core/extensions/guard-shell-analysis.ts +558 -0
- package/packages/piagent-core/extensions/guard-types.ts +406 -0
- package/packages/piagent-core/extensions/piagent-guard.ts +5760 -0
- package/packages/piagent-core/extensions/policy-core.js +1070 -0
- package/packages/piagent-core/extensions/redaction-core.js +4 -0
- package/packages/piagent-core/extensions/runtime-evidence.js +215 -0
- package/packages/piagent-core/package.json +46 -0
- package/packages/piagent-core/policies/base-policy.json +249 -0
- package/packages/piagent-core/prompts/be-to-fe.md +82 -0
- package/packages/piagent-core/prompts/commit.md +27 -0
- package/packages/piagent-core/prompts/discuss.md +35 -0
- package/packages/piagent-core/prompts/memory-policy.md +52 -0
- package/packages/piagent-core/prompts/model-options.md +68 -0
- package/packages/piagent-core/prompts/onboard-project.md +147 -0
- package/packages/piagent-core/prompts/piagent-commands.md +68 -0
- package/packages/piagent-core/prompts/plan.md +35 -0
- package/packages/piagent-core/prompts/platform-improve.md +69 -0
- package/packages/piagent-core/prompts/pr.md +26 -0
- package/packages/piagent-core/prompts/review.md +38 -0
- package/packages/piagent-core/prompts/scout.md +50 -0
- package/packages/piagent-core/prompts/task.md +69 -0
- package/packages/piagent-core/security/sensitive-data.js +187 -0
- package/packages/piagent-core/skills/piagent-ops/SKILL.md +44 -0
- package/packages/piagent-core/skills/piagent-source-cache/SKILL.md +59 -0
- package/packages/piagent-core/skills/piagent-source-cache/checkout-source-repo.sh +144 -0
- package/packages/piagent-core/subagents/piagent-oracle.md +29 -0
- package/packages/piagent-core/subagents/piagent-planner.md +46 -0
- package/packages/piagent-core/subagents/piagent-reviewer.md +48 -0
- package/packages/piagent-core/subagents/piagent-scout.md +37 -0
- package/packages/piagent-core/subagents/piagent-worker.md +44 -0
- package/packs/engineering-base/pack.json +123 -0
- package/packs/engineering-base/recipes/bounded-change.json +82 -0
- package/packs/web-delivery/pack.json +72 -0
- package/packs/web-delivery/recipes/verified-web-change.json +57 -0
- package/schemas/action-proposal.schema.json +90 -0
- package/schemas/capability-pack.schema.json +190 -0
- package/schemas/capability-recipe.schema.json +72 -0
- package/schemas/context-index.schema.json +258 -0
- package/schemas/eval-scenario.schema.json +67 -0
- package/schemas/project-profile.schema.json +555 -0
- package/schemas/task-contract.schema.json +314 -0
- package/scripts/audit-runtime-host.sh +78 -0
- package/scripts/bootstrap-local.sh +25 -0
- package/scripts/capability-catalog.mjs +290 -0
- package/scripts/check-runtime-advisories.mjs +114 -0
- package/scripts/configure-mcp.sh +301 -0
- package/scripts/configure-model-scope.sh +143 -0
- package/scripts/configure-subagents.sh +241 -0
- package/scripts/import-agent-instructions.mjs +199 -0
- package/scripts/init-project.sh +369 -0
- package/scripts/install-global.sh +532 -0
- package/scripts/link-project.sh +25 -0
- package/scripts/migrate-project-state.mjs +176 -0
- package/scripts/pi-auto.sh +79 -0
- package/scripts/pi-model-catalog.sh +154 -0
- package/scripts/pi-session-stats.sh +135 -0
- package/scripts/piagent-cli.mjs +53 -0
- package/scripts/profile-doctor.sh +238 -0
- package/scripts/quality-benchmark.sh +185 -0
- package/scripts/redaction-benchmark.mjs +227 -0
- package/scripts/runtime-policy-smoke.sh +48 -0
- package/scripts/setup.sh +425 -0
- package/scripts/team-doctor.sh +461 -0
- package/scripts/verify-local.sh +540 -0
- package/scripts/verify-release-identity.mjs +85 -0
- package/scripts/verify-vercel-link.mjs +64 -0
- package/templates/global/mcp.json +9 -0
- package/templates/global/settings.json +37 -0
- package/templates/project/.mcp.json +9 -0
- package/templates/project/.pi/context-index.json +25 -0
- package/templates/project/.pi/gitignore.template +22 -0
- package/templates/project/.pi/mcp.json +9 -0
- package/templates/project/.pi/memory/MEMORY.md +11 -0
- package/templates/project/.pi/memory/memory_summary.md +9 -0
- package/templates/project/.pi/piagent-profile.json +107 -0
- package/templates/project/.pi/project-context.md +30 -0
- package/templates/project/.pi/settings.json +17 -0
- package/templates/project/.pi/task-contract.template.json +74 -0
- package/templates/project/.pi/tech-context/README.md +7 -0
- package/templates/project/.pi/tech-stack.json +10 -0
- package/templates/project/AGENTS.md +34 -0
- package/templates/project/REVIEW_GUIDELINES.md +23 -0
- package/types/pi-runtime-shims.d.ts +13 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# Subagents và multi-agent workflow
|
|
2
|
+
|
|
3
|
+
## Kết luận
|
|
4
|
+
|
|
5
|
+
Pi core không có subagents built-in. Theo design của Pi, subagents là extension/package. Platform này dùng `pi-subagents` làm subagent runtime vì nó hỗ trợ:
|
|
6
|
+
|
|
7
|
+
- child Pi sessions riêng context;
|
|
8
|
+
- foreground/background runs;
|
|
9
|
+
- `/run`, `/parallel`, `/chain`;
|
|
10
|
+
- builtin agents `scout`, `planner`, `worker`, `reviewer`, `oracle`, `researcher`, `context-builder`, `delegate`;
|
|
11
|
+
- custom package agents từ `packages/piagent-core/subagents`;
|
|
12
|
+
- status/fleet/cost/doctor commands;
|
|
13
|
+
- bounded recursion/concurrency;
|
|
14
|
+
- optional worktree isolation cho parallel writers.
|
|
15
|
+
- prompt shortcuts như `/parallel-review`, `/review-loop`, `/parallel-research`, `/parallel-context-build`;
|
|
16
|
+
- native supervisor channel (`contact_supervisor` / `subagent_supervisor`);
|
|
17
|
+
- acceptance gates, output files, forked context, watchdog, model profiles, and lifecycle artifacts.
|
|
18
|
+
|
|
19
|
+
Từ `v0.3.7`, `scripts/setup.sh` mặc định cài `pi-subagents` và chạy config preset `safe`.
|
|
20
|
+
|
|
21
|
+
Workflow prompts của platform dùng **solo-first orchestration policy**: khi anh chạy `/task`, `/be-to-fe`, `/platform-improve`, `/plan`, hoặc `/review`, parent agent đọc `piagent_orchestration_policy`, lập task tree/review lenses, rồi mới cân nhắc subagent cho phần việc độc lập. Anh không bắt buộc phải gọi `/run` nếu chỉ muốn task hoàn chỉnh, và platform cũng không spawn swarm khi task nhỏ.
|
|
22
|
+
|
|
23
|
+
Kiểm tra nhanh policy trong Pi:
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
/piagent-orchestration
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Guard extension vẫn load trong subagent process. Bash verify results do not stay in process-local memory only; they are appended to `.pi/piagent-state/observed-bash.jsonl`. Because parent and child share the same project cwd, parent can validate an exact verify command that a guarded worker subagent ran.
|
|
30
|
+
|
|
31
|
+
Xem chi tiết: `docs/auto-delegation-policy.md`.
|
|
32
|
+
|
|
33
|
+
Capability notes chi tiết: `docs/subagent-orchestration-capabilities.md`.
|
|
34
|
+
|
|
35
|
+
## Install/setup
|
|
36
|
+
|
|
37
|
+
Một lệnh setup đầy đủ:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
bash /path/to/piagent/scripts/setup.sh . \
|
|
41
|
+
--profile auto \
|
|
42
|
+
--package-source git:github.com/Vt-mmm/piagent@vX.Y.Z \
|
|
43
|
+
--mcp-preset core \
|
|
44
|
+
--subagents-preset safe
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Nếu chỉ cài global:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pi install git:github.com/Vt-mmm/piagent
|
|
51
|
+
pi install npm:pi-subagents@0.35.1
|
|
52
|
+
bash /path/to/piagent/scripts/configure-subagents.sh --preset safe
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Nếu package đã cài nhưng muốn re-apply config:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
piagent-subagents --preset safe
|
|
59
|
+
# hoặc nếu chưa link npm bin:
|
|
60
|
+
bash /path/to/piagent/scripts/configure-subagents.sh --preset safe
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Safe preset
|
|
64
|
+
|
|
65
|
+
`safe` ghi vào:
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
~/.pi/agent/extensions/subagent/config.json
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Nội dung chính:
|
|
72
|
+
|
|
73
|
+
- `toolDescriptionMode: compact` để giảm prompt/token;
|
|
74
|
+
- `asyncByDefault: false` để không tự chạy background nếu không yêu cầu;
|
|
75
|
+
- `waitTool.enabled: true` để parent có thể đợi async runs khi workflow cần kết quả;
|
|
76
|
+
- `intercomBridge.mode: always` để child có thể hỏi parent qua `contact_supervisor`;
|
|
77
|
+
- `singleRunOutputBaseDir` và `defaultSessionDir` stable trong `~/.pi/agent`;
|
|
78
|
+
- `worktreeBaseDir` stable cho parallel writer khi được explicit bật;
|
|
79
|
+
- `scheduledRuns.enabled: false` để không lộ surface schedule nếu user không yêu cầu;
|
|
80
|
+
- `parallel.concurrency: 3`;
|
|
81
|
+
- `parallel.maxTasks: 6`;
|
|
82
|
+
- `maxSubagentDepth: 1`;
|
|
83
|
+
- `maxSubagentSpawnsPerSession: 32`;
|
|
84
|
+
- async completion batching bật.
|
|
85
|
+
|
|
86
|
+
Không ép `subagents.modelScope` mặc định. Anh chọn model parent bằng `/model`; builtin subagents sẽ inherit model nếu không override. Nếu muốn ép chỉ provider:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
bash /path/to/piagent/scripts/configure-subagents.sh --preset safe --model-scope piagent
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Kiểm tra trong Pi
|
|
93
|
+
|
|
94
|
+
Sau khi mở session mới hoặc `/reload`:
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
/subagents-doctor
|
|
98
|
+
/subagents-models
|
|
99
|
+
/subagents
|
|
100
|
+
/subagents-fleet
|
|
101
|
+
/subagent-cost
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`/subagents-doctor` là lệnh đầu tiên nên chạy nếu không thấy tool/agent.
|
|
105
|
+
|
|
106
|
+
Optional research support:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pi install npm:pi-web-access@0.13.0
|
|
110
|
+
# hoặc
|
|
111
|
+
bash /path/to/piagent/scripts/setup.sh . --with-web-access
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`researcher` builtin cần web/search/fetch tools từ package này. Không bật mặc định để tránh tăng tool surface cho team không cần web research.
|
|
115
|
+
|
|
116
|
+
Giải nghĩa nhanh:
|
|
117
|
+
|
|
118
|
+
| Command | Nghĩa đơn giản | Khi dùng |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `/subagents-doctor` | Health check subagent | Kiểm package/config/agent files/runtime readiness. |
|
|
121
|
+
| `/subagents-models` | Bản đồ model/thinking của subagents | Xem agent nào inherit model parent, agent nào override. |
|
|
122
|
+
| `/subagents` | Catalog/admin agents | Xem builtin agents và `piagent-*` agents. |
|
|
123
|
+
| `/subagents-fleet` | Dashboard đội child sessions | Follow background/parallel runs, xem active/done/result. |
|
|
124
|
+
| `/subagent-cost` | Token/cost subagents | Xem usage của child runs nếu package/provider expose stats. |
|
|
125
|
+
| `/run` | Chạy một agent | Dùng cho scout/planner/worker/reviewer riêng context. |
|
|
126
|
+
| `/parallel` | Chạy nhiều agent độc lập | Tốt cho read-only scout/review/test-gap analysis. |
|
|
127
|
+
| `/chain` | Chạy tuần tự | Output agent trước làm input agent sau qua `{previous}`. |
|
|
128
|
+
|
|
129
|
+
Nếu cần bản tổng hợp cho team mới:
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
/piagent-commands subagents
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Gọi subagent tự nhiên
|
|
136
|
+
|
|
137
|
+
Không bắt buộc nhớ exact tool call. Có thể prompt tự nhiên:
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
Use scout to map the auth flow, then summarize likely change targets.
|
|
141
|
+
Ask oracle to challenge this plan before we edit code.
|
|
142
|
+
Use reviewer to review the current diff for correctness and tests.
|
|
143
|
+
Run parallel reviewers: correctness, tests, and unnecessary complexity.
|
|
144
|
+
Have worker implement this approved plan, then run reviewer.
|
|
145
|
+
Run a review loop on this change until reviewers stop finding fixes worth doing, max 3 rounds.
|
|
146
|
+
Run parallel research: external docs, local code context, and practical tradeoffs.
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Với workflow platform, còn có thể chỉ gọi:
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
/task Implement <task lớn>.
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Parent agent sẽ tự quyết định:
|
|
156
|
+
|
|
157
|
+
- không spawn nếu task nhỏ;
|
|
158
|
+
- spawn bounded `piagent-scout` nếu cần map source/spec;
|
|
159
|
+
- spawn bounded `piagent-planner` nếu cần plan medium/high-risk;
|
|
160
|
+
- spawn bounded `piagent-reviewer` trước final nếu diff không nhỏ;
|
|
161
|
+
- dùng builtin `researcher` nếu task cần external evidence và web tools available;
|
|
162
|
+
- dùng builtin `context-builder` nếu task lớn cần handoff context;
|
|
163
|
+
- dùng review lenses (`correctness`, `tests`, `scope`, optional `security/docs/release/package`) thay vì gọi review swarm chung chung;
|
|
164
|
+
- ghi trong final `Subagents: used/not used and why`.
|
|
165
|
+
|
|
166
|
+
## Package prompt shortcuts nên biết
|
|
167
|
+
|
|
168
|
+
| Prompt | Dùng khi nào |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `/parallel-review` | Review nhiều góc nhìn độc lập; thêm `autofix` nếu muốn áp fix đáng làm. |
|
|
171
|
+
| `/review-loop` | Worker/reviewer/fix loop đến khi sạch hoặc hết max rounds. |
|
|
172
|
+
| `/parallel-research` | External research + local scout + tradeoff. Cần `pi-web-access` cho web researcher. |
|
|
173
|
+
| `/parallel-context-build` | Tạo `context.md`/meta-prompt handoff cho task lớn. |
|
|
174
|
+
| `/parallel-handoff-plan` | Research + context-builder + implementation handoff plan. |
|
|
175
|
+
| `/gather-context-and-clarify` | Đọc/scout trước rồi chỉ hỏi câu clarification thật sự cần. |
|
|
176
|
+
| `/parallel-cleanup` | Cleanup review sau implementation; có thể thêm `autofix`. |
|
|
177
|
+
|
|
178
|
+
## Gọi bằng slash command
|
|
179
|
+
|
|
180
|
+
Single agent:
|
|
181
|
+
|
|
182
|
+
```text
|
|
183
|
+
/run scout "Map the auth flow and identify entry points."
|
|
184
|
+
/run piagent-scout "Map FE routes related to listing search. Read-only."
|
|
185
|
+
/run piagent-planner "Create implementation plan from context.md."
|
|
186
|
+
/run piagent-worker "Implement the approved plan. Do not touch backend."
|
|
187
|
+
/run piagent-reviewer "Review current diff against the task and verify evidence."
|
|
188
|
+
/run piagent-oracle "Challenge this architecture choice before implementation."
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Parallel:
|
|
192
|
+
|
|
193
|
+
```text
|
|
194
|
+
/parallel piagent-reviewer "Review correctness" -> piagent-reviewer "Review tests" -> piagent-reviewer "Review scope drift"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Chain:
|
|
198
|
+
|
|
199
|
+
```text
|
|
200
|
+
/chain piagent-scout "Scout the target area" -> piagent-planner "Plan from {previous}" -> piagent-worker "Implement from {previous}" -> piagent-reviewer "Review the implementation"
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Background:
|
|
204
|
+
|
|
205
|
+
```text
|
|
206
|
+
/run piagent-scout "Map this module" --bg
|
|
207
|
+
/subagents-fleet
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Gọi bằng tool syntax
|
|
211
|
+
|
|
212
|
+
Khi muốn chính xác:
|
|
213
|
+
|
|
214
|
+
```text
|
|
215
|
+
subagent({ agent: "piagent-scout", task: "Map the auth flow. Read-only.", context: "fresh" })
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Background:
|
|
219
|
+
|
|
220
|
+
```text
|
|
221
|
+
subagent({ agent: "piagent-reviewer", task: "Review current diff", async: true })
|
|
222
|
+
subagent({ action: "status" })
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Status/control:
|
|
226
|
+
|
|
227
|
+
```text
|
|
228
|
+
subagent({ action: "status" })
|
|
229
|
+
subagent({ action: "status", view: "fleet" })
|
|
230
|
+
subagent({ action: "status", id: "<run-id>", view: "transcript" })
|
|
231
|
+
subagent({ action: "steer", id: "<run-id>", message: "Focus only on tests." })
|
|
232
|
+
subagent({ action: "stop", id: "<run-id>" })
|
|
233
|
+
subagent({ action: "resume", id: "<run-id>", message: "Continue after this clarification." })
|
|
234
|
+
subagent_supervisor({ action: "pending" })
|
|
235
|
+
subagent_supervisor({ action: "reply", replyTo: "<request-id>", message: "Approved path A." })
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Output/file controls:
|
|
239
|
+
|
|
240
|
+
```text
|
|
241
|
+
/run scout[output=context.md,outputMode=file-only] "Map target area"
|
|
242
|
+
/chain scout[output=context.md,as=context] "Scan" -> planner[reads=context.md] "Plan from {outputs.context}"
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Use `outputMode=file-only` khi report dài để parent không bị nhồi full output vào context.
|
|
246
|
+
|
|
247
|
+
## Piagent subagents
|
|
248
|
+
|
|
249
|
+
Platform package exposes these package-level agents:
|
|
250
|
+
|
|
251
|
+
| Agent | Role | Write? |
|
|
252
|
+
|---|---|---|
|
|
253
|
+
| `piagent-scout` | bounded repo mapping | no |
|
|
254
|
+
| `piagent-planner` | implementation plan + verify gates | no |
|
|
255
|
+
| `piagent-worker` | single-writer implementation | yes |
|
|
256
|
+
| `piagent-reviewer` | review diff/policy/tests/scope | review-first, edit only if asked |
|
|
257
|
+
| `piagent-oracle` | second opinion/risk challenge | no |
|
|
258
|
+
|
|
259
|
+
Default rule:
|
|
260
|
+
|
|
261
|
+
- Use `piagent-scout` before touching unfamiliar code.
|
|
262
|
+
- Use `piagent-planner` before medium/high-risk changes.
|
|
263
|
+
- Use `piagent-worker` only for approved, bounded write tasks.
|
|
264
|
+
- Use `piagent-reviewer` before final handoff.
|
|
265
|
+
- Use `piagent-oracle` when architecture/product/risk is uncertain.
|
|
266
|
+
|
|
267
|
+
## Worktree isolation
|
|
268
|
+
|
|
269
|
+
Parallel implementation writers can clobber each other in one checkout. Only use `worktree: true` when:
|
|
270
|
+
|
|
271
|
+
- current repo is a Git repo;
|
|
272
|
+
- working tree is clean;
|
|
273
|
+
- write sets do not overlap;
|
|
274
|
+
- parent will review/merge outputs.
|
|
275
|
+
|
|
276
|
+
Example:
|
|
277
|
+
|
|
278
|
+
```text
|
|
279
|
+
subagent({
|
|
280
|
+
tasks: [
|
|
281
|
+
{ agent: "piagent-worker", task: "Implement feature A" },
|
|
282
|
+
{ agent: "piagent-worker", task: "Implement feature B" }
|
|
283
|
+
],
|
|
284
|
+
worktree: true
|
|
285
|
+
})
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
For normal solo/internal workflow, prefer one `piagent-worker` plus parallel read-only reviewers.
|
|
289
|
+
|
|
290
|
+
## Watchdog opt-in
|
|
291
|
+
|
|
292
|
+
Watchdog không phải `reviewer`. Nó là adversarial review ở boundary `agent_end`, chỉ chạy khi có repo edits. Không bật mặc định vì tốn thêm model pass.
|
|
293
|
+
|
|
294
|
+
Session-only high-risk run:
|
|
295
|
+
|
|
296
|
+
```text
|
|
297
|
+
/subagents-watchdog recommend-model
|
|
298
|
+
/subagents-watchdog session model recommended
|
|
299
|
+
/subagents-watchdog on
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Persistent project/user config chỉ dùng khi team đã đồng ý cost/latency.
|
|
303
|
+
|
|
304
|
+
## Model profiles
|
|
305
|
+
|
|
306
|
+
Khi team có nhiều provider/quota:
|
|
307
|
+
|
|
308
|
+
```text
|
|
309
|
+
/subagents-refresh-provider-models openai-codex
|
|
310
|
+
/subagents-generate-profiles openai-codex
|
|
311
|
+
/subagents-load-profile openai-codex.quota
|
|
312
|
+
/subagents-check-profile openai-codex.quota
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Model scope platform vẫn có thể enforce bằng:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
piagent-subagents --preset safe --model-scope piagent
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Cost/token controls
|
|
322
|
+
|
|
323
|
+
Use:
|
|
324
|
+
|
|
325
|
+
```text
|
|
326
|
+
/subagent-cost
|
|
327
|
+
/piagent-usage
|
|
328
|
+
/session
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Recommended token policy:
|
|
332
|
+
|
|
333
|
+
- default `safe` preset;
|
|
334
|
+
- do not set `asyncByDefault` unless anh intentionally wants background-heavy workflow;
|
|
335
|
+
- keep `/piagent-orchestration` at `solo-first` unless team has a measured reason to change it;
|
|
336
|
+
- one writer at a time;
|
|
337
|
+
- parallel reviewers/scouts are OK;
|
|
338
|
+
- use `piagent-scout`/`piagent-planner` to compress context before handing off to `piagent-worker`;
|
|
339
|
+
- run `/subagents-fleet` to inspect background runs instead of asking parent model to recall everything.
|
|
340
|
+
|
|
341
|
+
## Nguồn
|
|
342
|
+
|
|
343
|
+
- Pi usage docs: https://pi.dev/docs/latest/usage
|
|
344
|
+
- Pi SDK docs: https://pi.dev/docs/latest/sdk
|
|
345
|
+
- pi-subagents package: https://pi.dev/packages/pi-subagents
|
|
346
|
+
- pi-subagents GitHub: https://github.com/nicobailon/pi-subagents
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Task Implementation Contract
|
|
2
|
+
|
|
3
|
+
## Mục tiêu
|
|
4
|
+
|
|
5
|
+
Đây là contract tối thiểu để Pi implement task không khác gì một CLI agent nghiêm túc: có scope, context, guard, verify, trace.
|
|
6
|
+
|
|
7
|
+
## Contract fields
|
|
8
|
+
|
|
9
|
+
| Field | Required | Ý nghĩa |
|
|
10
|
+
|---|---:|---|
|
|
11
|
+
| `taskId` | yes | ID ổn định cho task. |
|
|
12
|
+
| `summary` | yes | Một câu mô tả outcome. |
|
|
13
|
+
| `riskLane` | yes | `tiny`, `normal`, hoặc `high-risk`. |
|
|
14
|
+
| `expectedOutput` | yes | Artifact/behavior cụ thể. |
|
|
15
|
+
| `acceptanceCriteria` | yes | Điều kiện pass/fail. |
|
|
16
|
+
| `scope` | yes | File/module được phép đụng. |
|
|
17
|
+
| `outOfScope` | yes | Cái không làm. |
|
|
18
|
+
| `protectedPaths` | yes | Vùng cấm từ profile/policy. |
|
|
19
|
+
| `requiredContext` | yes | Context bắt buộc đọc. |
|
|
20
|
+
| `contextManifest` | yes | Bằng chứng context đã dùng. |
|
|
21
|
+
| `memoryCitations` | no | Memory file dùng làm advisory context, nếu có. |
|
|
22
|
+
| `mcpCapabilities` | no | Tool/MCP được phép. |
|
|
23
|
+
| `verifyCommands` | yes | Command phải chạy trước DONE. |
|
|
24
|
+
| `workPlan` | no | Task tree compact: step, role, mode, trạng thái, dependency. |
|
|
25
|
+
| `reviewLenses` | no | Góc review rõ ràng, mặc định `correctness`, `tests`, `scope`. |
|
|
26
|
+
| `orchestration` | no | Snapshot solo-first policy khi task bắt đầu: mode, subagent stance, Field Guide, model-role guidance. |
|
|
27
|
+
| `verifyEvidence` | yes before done | Observed command result. Passing gate requires exact match with `verifyCommands`. |
|
|
28
|
+
| `changedFiles` | yes before done | File đã sửa. |
|
|
29
|
+
| `trace` | yes before done | Handoff/audit record. |
|
|
30
|
+
|
|
31
|
+
## JSON example
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"taskId": "TASK-0001",
|
|
36
|
+
"summary": "Fix listing filter reset behavior",
|
|
37
|
+
"riskLane": "normal",
|
|
38
|
+
"expectedOutput": "Filter reset returns listing page to default query and preserves route owner.",
|
|
39
|
+
"acceptanceCriteria": [
|
|
40
|
+
"Reset button clears selected filters",
|
|
41
|
+
"URL query returns to canonical default",
|
|
42
|
+
"No protected paths are modified"
|
|
43
|
+
],
|
|
44
|
+
"scope": [
|
|
45
|
+
"src/features/listings/**"
|
|
46
|
+
],
|
|
47
|
+
"outOfScope": [
|
|
48
|
+
"backend API changes",
|
|
49
|
+
"database changes"
|
|
50
|
+
],
|
|
51
|
+
"protectedPaths": [
|
|
52
|
+
"backend/**"
|
|
53
|
+
],
|
|
54
|
+
"requiredContext": [
|
|
55
|
+
"AGENTS.md",
|
|
56
|
+
".pi/project-context.md",
|
|
57
|
+
"docs/frontend/structure-guide.md"
|
|
58
|
+
],
|
|
59
|
+
"contextManifest": [
|
|
60
|
+
{
|
|
61
|
+
"path": "AGENTS.md",
|
|
62
|
+
"reason": "root rules"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"memoryCitations": [],
|
|
66
|
+
"mcpCapabilities": [
|
|
67
|
+
"filesystem-readonly",
|
|
68
|
+
"browser"
|
|
69
|
+
],
|
|
70
|
+
"verifyCommands": [
|
|
71
|
+
"npm run test"
|
|
72
|
+
],
|
|
73
|
+
"workPlan": [
|
|
74
|
+
{
|
|
75
|
+
"id": "plan",
|
|
76
|
+
"title": "Confirm scope and verify gate before editing.",
|
|
77
|
+
"role": "parent",
|
|
78
|
+
"mode": "read-only",
|
|
79
|
+
"status": "done"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"id": "implement",
|
|
83
|
+
"title": "Apply the bounded source change.",
|
|
84
|
+
"role": "piagent-worker",
|
|
85
|
+
"mode": "single-writer",
|
|
86
|
+
"status": "pending",
|
|
87
|
+
"dependsOn": [
|
|
88
|
+
"plan"
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"reviewLenses": [
|
|
93
|
+
"correctness",
|
|
94
|
+
"tests",
|
|
95
|
+
"scope"
|
|
96
|
+
],
|
|
97
|
+
"orchestration": {
|
|
98
|
+
"mode": "solo-first",
|
|
99
|
+
"subagents": "not-used",
|
|
100
|
+
"reason": "Task starts in solo-first mode; use bounded subagents only for independent scout, planning, or review work.",
|
|
101
|
+
"fieldGuidePath": ".pi/memory/MEMORY.md",
|
|
102
|
+
"modelRoles": {
|
|
103
|
+
"planner": "Use the strongest available model for decomposition, architecture, risk, and acceptance criteria.",
|
|
104
|
+
"worker": "Use the fastest reliable model for a bounded, already-planned single write set.",
|
|
105
|
+
"reviewer": "Use a model or thinking setting decorrelated from the worker when review quality matters.",
|
|
106
|
+
"watchdog": "Use a strong model only for final risk review, security, release, or high-impact changes."
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"verifyEvidence": [
|
|
110
|
+
{
|
|
111
|
+
"command": "npm run test",
|
|
112
|
+
"exitCode": 0,
|
|
113
|
+
"summary": "Unit test suite passed.",
|
|
114
|
+
"observed": true,
|
|
115
|
+
"matchedProfileCommand": true
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
"changedFiles": [],
|
|
119
|
+
"trace": {
|
|
120
|
+
"outcome": "pending"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Prompt contract
|
|
126
|
+
|
|
127
|
+
Pi task prompt phải bắt buộc:
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
Use piagent_context first.
|
|
131
|
+
Use piagent_orchestration_policy; default to solo-first, create a compact task tree, and choose review lenses before spawning subagents.
|
|
132
|
+
Use piagent_context_index_status/search as advisory navigation when available; verify cited files before editing.
|
|
133
|
+
Use piagent_memory_status and search memory when relevant; memory is advisory only.
|
|
134
|
+
Read .pi/project-context.md; if it is pending, stop and request /onboard-project.
|
|
135
|
+
Create a Task Implementation Contract with piagent_task_start.
|
|
136
|
+
Check large context with piagent_context_budget.
|
|
137
|
+
Check complex/high-impact shell with piagent_exec_policy_check.
|
|
138
|
+
Check non-piagent tools with piagent_tool_policy_check.
|
|
139
|
+
Do not edit before scope + verify command are known.
|
|
140
|
+
Before final, run the exact verify command from task.verifyCommands through Pi bash, record observed verify evidence, and trace.
|
|
141
|
+
Call piagent_task_gate_check before DONE.
|
|
142
|
+
If verify cannot run, final outcome is blocked/partial, not done.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Enforcement levels
|
|
146
|
+
|
|
147
|
+
| Level | Cách enforce | Độ tin cậy |
|
|
148
|
+
|---|---|---:|
|
|
149
|
+
| Prompt only | prompt nhắc model | Thấp |
|
|
150
|
+
| Profile + prompt | profile có rule, prompt đọc profile | Trung bình |
|
|
151
|
+
| Extension guard | tool_call block protected/destructive | Khá |
|
|
152
|
+
| Runtime task tools | task_start/context_record/verify_record/trace | Cao |
|
|
153
|
+
| Runtime quality tools | exec_policy/context_budget/tool_policy/task_gate | Cao |
|
|
154
|
+
| Final gate | trace completion block khi `finalGate=enforce`; hard assistant stop-hook khi Pi API hỗ trợ | Cao nhất |
|
|
155
|
+
|
|
156
|
+
Hiện platform đang ở mức “P3-baseline runtime policy”:
|
|
157
|
+
|
|
158
|
+
- `piagent_task_start`
|
|
159
|
+
- `piagent_exec_policy_check`
|
|
160
|
+
- `piagent_context_budget`
|
|
161
|
+
- `piagent_context_index_status`
|
|
162
|
+
- `piagent_context_index_search`
|
|
163
|
+
- `piagent_context_index_record`
|
|
164
|
+
- `piagent_tool_policy_check`
|
|
165
|
+
- `piagent_context_record`
|
|
166
|
+
- `piagent_verify_record`
|
|
167
|
+
- `piagent_trace_record`
|
|
168
|
+
- `piagent_task_gate_check`
|
|
169
|
+
- local task/trace/observed-bash state trong `.pi/piagent-state/`
|
|
170
|
+
- session trace qua Pi custom entry `piagent-task-trace`
|
|
171
|
+
|
|
172
|
+
`piagent_trace_record` có thể block completion nếu profile bật `finalGate=enforce`. Nếu Pi runtime chưa expose hard final assistant stop hook, agent vẫn phải gọi `piagent_task_gate_check` và final phải nêu gate result.
|
|
173
|
+
|
|
174
|
+
## Verify evidence rules
|
|
175
|
+
|
|
176
|
+
`piagent_verify_record` is not a free-form self-report. It accepts evidence only when the same normalized command was observed through a Pi `bash` `tool_result` after `task.createdAt`.
|
|
177
|
+
|
|
178
|
+
Observed bash results are persisted to:
|
|
179
|
+
|
|
180
|
+
```text
|
|
181
|
+
.pi/piagent-state/observed-bash.jsonl
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
This lets parent agents validate verify commands executed by guarded subagent processes in the same cwd.
|
|
185
|
+
|
|
186
|
+
Final-gate pass requires:
|
|
187
|
+
|
|
188
|
+
- `observed=true`;
|
|
189
|
+
- `matchedProfileCommand=true`;
|
|
190
|
+
- `exitCode=0`.
|
|
191
|
+
|
|
192
|
+
Exact command identity matters. If the task profile says `npm test`, record `npm test`. `npm test`, `npm test 2>&1`, `npm test || true`, `true`, and `echo ok` are different commands and will not satisfy the passing gate unless explicitly present in `task.verifyCommands`.
|
|
193
|
+
|
|
194
|
+
## Named implementation recipes
|
|
195
|
+
|
|
196
|
+
- `/platform-improve`: dùng cho task cải tiến setup, docs, prompt, MCP, model, memory, runtime policy, hoặc subagent workflow của platform.
|
|
197
|
+
- `/be-to-fe`: dùng cho task scout BE contract read-only rồi implement FE.
|
|
198
|
+
- `/memory-policy`: dùng cho task kiểm tra/ghi nhớ explicit project memory.
|
|
199
|
+
|
|
200
|
+
Hai recipe này vẫn phải tạo/giữ Task Implementation Contract khi có source writes.
|