@tea-agent/loop-agent 0.5.0 → 0.7.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/AGENTS.md +142 -142
- package/CHANGELOG.md +132 -98
- package/README.md +195 -195
- package/bin/agent-worker.js +22 -22
- package/bin/loop-agent.js +21 -21
- package/dist/application/dag/args.js +9 -1
- package/dist/application/dag/run-dag.js +16 -2
- package/dist/cli/command-definitions.js +22 -4
- package/dist/cli/help.js +3 -2
- package/dist/cli/program.js +7 -5
- package/dist/commands/import-prd.js +76 -0
- package/dist/commands/init.js +467 -457
- package/dist/commands/instructions.js +90 -58
- package/dist/commands/loop-benchmark.js +11 -11
- package/dist/commands/pi-reuse-benchmark.js +16 -16
- package/dist/executors/cursor-executor.js +1 -1
- package/dist/executors/dag-pi-executor.js +1 -0
- package/dist/executors/pi-sdk-executor.js +63 -1
- package/dist/shared/preview.js +39 -0
- package/dist/task/config-types.js +3 -0
- package/dist/task/runtime.js +27 -27
- package/dist/task/source-references.js +221 -0
- package/dist/worker/cli.js +62 -1
- package/dist/worker/loop-agent/loop-agent-client.js +97 -5
- package/dist/worker/materialize/harness-task-materializer.js +166 -5
- package/dist/worker/observability/event-store.js +82 -0
- package/dist/worker/observability/events.js +79 -0
- package/dist/worker/observability/progress-composite.js +33 -0
- package/dist/worker/observability/read-model.js +1013 -0
- package/dist/worker/observability/snapshot-store.js +43 -0
- package/dist/worker/observability/types.js +1 -0
- package/dist/worker/observe/paths.js +64 -0
- package/dist/worker/observe/routes.js +423 -0
- package/dist/worker/observe/server.js +61 -0
- package/dist/worker/observe/static/app.js +1419 -0
- package/dist/worker/observe/static/index.html +63 -0
- package/dist/worker/observe/static/styles.css +613 -0
- package/dist/worker/pool/failure-routing.js +41 -6
- package/dist/worker/pool/run-store.js +50 -0
- package/dist/worker/progress-reporter.js +0 -18
- package/dist/worker/run-task/run-task.js +327 -92
- package/dist/worker/runner/run-ready.js +112 -4
- package/dist/worker/task-spec/schema.js +2 -1
- package/dist/workflows/dag/canvas-observer.js +275 -275
- package/dist/workflows/dag/event-observer.js +132 -0
- package/dist/workflows/dag/init-hybrid.js +182 -21
- package/dist/workflows/dag/observer-compose.js +52 -0
- package/docs/README.md +75 -72
- package/docs/agent-dag-recovery-playbook.md +184 -184
- package/docs/agent-dag-runner.md +42 -42
- package/docs/architecture/runtime-boundaries.md +162 -147
- package/docs/cursor-executor-usage.md +25 -25
- package/docs/decisions/README.md +3 -3
- package/docs/design/README.md +49 -36
- package/docs/development-principles.md +73 -73
- package/docs/dynamic-workflow-dag-engine-roadmap.md +1749 -1749
- package/docs/exec-plans/README.md +6 -6
- package/docs/exec-plans/active/README.md +12 -7
- package/docs/exec-plans/completed/README.md +32 -19
- package/docs/feature-workflow.md +186 -186
- package/docs/harness-methodology-debugging.md +153 -153
- package/docs/harness-methodology-tdd.md +130 -130
- package/docs/harness-methodology-verification.md +27 -27
- package/docs/init-surface.manifest.json +208 -199
- package/docs/loop-agent-harness.md +55 -42
- package/docs/production-readiness.md +96 -96
- package/docs/progress/README.md +3 -3
- package/docs/reports/README.md +9 -5
- package/docs/skills/README.md +6 -6
- package/docs/skills/vetted-skill-registry.md +26 -26
- package/docs/templates/adr.md +60 -60
- package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -94
- package/docs/templates/agent-dag-decision-envelope.schema.json +213 -213
- package/docs/templates/agent-dag-decision-gate-dogfood-report.md +117 -117
- package/docs/templates/agent-dag-decision-gate.prompt.md +246 -246
- package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -98
- package/docs/templates/agent-dag-report.schema.json +454 -454
- package/docs/templates/agent-dag-review-verdict.prompt.md +68 -68
- package/docs/templates/agent-dag.base.json +195 -195
- package/docs/templates/agent-dag.final-verification.json +190 -190
- package/docs/templates/agent-dag.schema.json +316 -316
- package/docs/templates/agent-dag.supervised-implementation.json +500 -500
- package/docs/templates/exec-plan.md +64 -64
- package/docs/templates/feature-spec.md +53 -53
- package/docs/templates/hybrid-dag.json +193 -193
- package/docs/templates/init-evolution-review.md +33 -33
- package/docs/templates/interactive-ui-round2-experiment.md +66 -0
- package/docs/templates/production-readiness-checklist.md +57 -57
- package/docs/templates/progress-log.md +17 -17
- package/docs/templates/project-start-checklist.md +9 -9
- package/docs/templates/qa-report.md +48 -48
- package/docs/templates/sprint-contract.md +29 -29
- package/docs/templates/worker-dogfood-evidence.md +52 -0
- package/docs/templates/worker-dogfood-setup.md +48 -0
- package/docs/verification-matrix.md +41 -41
- package/examples/decision-gate-agent-dag.json +123 -123
- package/examples/example-dag.json +51 -51
- package/examples/hybrid-loop-agent-dag.json +194 -194
- package/harness.json +70 -69
- package/package.json +66 -66
- package/skills/ai-engineering-context/SKILL.md +48 -48
- package/skills/code-review-core/SKILL.md +20 -20
- package/skills/codebase-scout/SKILL.md +19 -19
- package/skills/init-capability-evolution/SKILL.md +69 -69
- package/skills/loop-agent/SKILL.md +149 -147
- package/skills/loop-agent/references/README.md +67 -67
- package/skills/loop-agent/references/command-reference.md +412 -403
- package/skills/loop-agent/references/harness-policy.md +263 -259
- package/skills/loop-agent/references/hybrid-dag.md +216 -216
- package/skills/loop-agent/references/learned/README.md +21 -21
- package/skills/loop-agent/references/long-running-loop.md +59 -59
- package/skills/loop-agent/references/model-routing.md +36 -36
- package/skills/loop-agent/references/multi-worktree.md +54 -54
- package/skills/loop-agent/references/one-shot-runs.md +85 -85
- package/skills/loop-agent/references/orchestrator-and-interventions.md +169 -169
- package/skills/loop-agent/references/pi-prompt.md +23 -23
- package/skills/loop-agent/references/pi-subagent-assisted-mode.md +81 -81
- package/skills/loop-agent/references/post-implementation-and-patterns.md +44 -44
- package/skills/loop-agent/references/task-workflow.md +89 -84
- package/skills/loop-agent/references/verification-and-failure-handling.md +128 -128
- package/skills/requesting-code-review/SKILL.md +101 -101
- package/skills/requesting-code-review/code-reviewer.md +168 -168
- package/skills/systematic-debugging/CREATION-LOG.md +119 -119
- package/skills/systematic-debugging/SKILL.md +296 -296
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -158
- package/skills/systematic-debugging/condition-based-waiting.md +115 -115
- package/skills/systematic-debugging/defense-in-depth.md +122 -122
- package/skills/systematic-debugging/find-polluter.sh +63 -63
- package/skills/systematic-debugging/root-cause-tracing.md +169 -169
- package/skills/systematic-debugging/test-academic.md +14 -14
- package/skills/systematic-debugging/test-pressure-1.md +58 -58
- package/skills/systematic-debugging/test-pressure-2.md +68 -68
- package/skills/systematic-debugging/test-pressure-3.md +69 -69
- package/skills/test-driven-development/SKILL.md +20 -20
- package/skills/verification-before-completion/SKILL.md +154 -154
- package/skills/webapp-testing/SKILL.md +19 -19
|
@@ -1,169 +1,169 @@
|
|
|
1
|
-
# Main Orchestrator、Agent DAG 与受控干预
|
|
2
|
-
|
|
3
|
-
协调长时 loop-agent work、判断 main session 是否可 edit、在 Agent DAG / one-shot Cursor / one-shot Pi 间选择,或在不失 auditability 的情况下恢复 in-flight workflow 时使用本文。
|
|
4
|
-
|
|
5
|
-
## 核心立场
|
|
6
|
-
|
|
7
|
-
**Agent DAG 优先,main session 编排,executor 实现,shell 验证。**
|
|
8
|
-
|
|
9
|
-
`harness.json.workflowPolicy` 的 repo 级 policy 将 Agent DAG 作为 autonomous 与 harness-governed work 的 implementation workflow。历史顺序式 `run ...` workflow 已移除。
|
|
10
|
-
|
|
11
|
-
main session 是 decision-maker 与 scheduler,不是默认 implementer。其稀缺 context 应留给 objective 对齐、DAG review、failure triage、executor 选择、verification review 与 handoff。长时 implementation 应委派给 Agent DAG node、Cursor、Pi、shell 或 worktree delegate。
|
|
12
|
-
|
|
13
|
-
这不是绝对禁止 edit。main-session 手动 edit 仅允许作为有 verification 与 artifact 记录的 bounded surgical patch。
|
|
14
|
-
|
|
15
|
-
## 默认执行模型
|
|
16
|
-
|
|
17
|
-
| Actor | 主角色 | 避免 |
|
|
18
|
-
|---|---|---|
|
|
19
|
-
| Main session | Objective、contract、DAG review、routing、failure triage、approve/reject/resume、handoff | 成为长时 coder |
|
|
20
|
-
| Agent DAG runner | 可恢复 multi-node orchestration、rank-parallel execution、write policy、run artifacts | 不更新 DAG/source 的 ad-hoc replanning |
|
|
21
|
-
| Cursor executor / prompt | Codebase-indexed search、multi-file implementation、bounded refactor/fix | 无 narrow `writeSet` / path scope 的宽写入 |
|
|
22
|
-
| Pi executor / prompt | Fast reasoning、read-only scouting、planning、review、decision-envelope advice | 充当 hidden state source |
|
|
23
|
-
| Shell executor | 确定性事实:tests、lint、typecheck、build、governance checks | 智能 repair |
|
|
24
|
-
| Human gate | Product、architecture、risk、permission 决策 | 常规 implementation debugging |
|
|
25
|
-
|
|
26
|
-
## 入口选择
|
|
27
|
-
|
|
28
|
-
**Agent DAG**(`dag run-task` → review/writeSet → `run-dag`)为默认,用于 autonomous implementation、workflow/harness/docs governance 变更、multi-file work,或任何受益于多 executor、parallel scout、显式 write policy、shell evidence、review gate、Decision Gate 的工作。
|
|
29
|
-
|
|
30
|
-
**supervised Agent DAG** 用于 `governanceProfile=supervised`,或工作触及 loop-agent runtime、scripts/CI、schema/public contract、多个 exclusive writer、repair flow 或 high-cost path。
|
|
31
|
-
|
|
32
|
-
**one-shot Pi / Cursor prompt** 仅作受控 sidecar intervention,不是 workflow state source。
|
|
33
|
-
|
|
34
|
-
**main-session surgical patch** 仅用于 small、obvious、low-risk 的修正,且 delegation 开销会占主导。
|
|
35
|
-
|
|
36
|
-
## Sidecar intervention 协议
|
|
37
|
-
|
|
38
|
-
sidecar intervention 是一次性 Pi 或 Cursor prompt,用于 unblock 主 workflow。
|
|
39
|
-
|
|
40
|
-
调用前说明:
|
|
41
|
-
|
|
42
|
-
1. 观察到什么问题。
|
|
43
|
-
2. 为何当前 DAG/step 不应盲目继续。
|
|
44
|
-
3. sidecar 是 read-only 还是可写文件。
|
|
45
|
-
4. 可写工作的精确 allowed/forbidden paths。
|
|
46
|
-
5. 预期输出及记录位置。
|
|
47
|
-
|
|
48
|
-
典型 routing:
|
|
49
|
-
|
|
50
|
-
| 情况 | 使用 |
|
|
51
|
-
|---|---|
|
|
52
|
-
| 需 quick root-cause analysis、plan critique、log 解读 | one-shot Pi prompt,read-only |
|
|
53
|
-
| 需 codebase-indexed multi-file 诊断或 bounded patch | one-shot Cursor prompt |
|
|
54
|
-
| 需确定性 evidence | shell command / shell DAG node |
|
|
55
|
-
| DAG topology、writeSet 或 source contract 错误 | stop/revise DAG 或 source;不要绕开 patch |
|
|
56
|
-
| requirement、architecture 或 risk 决策不清 | Decision Gate / human approval |
|
|
57
|
-
|
|
58
|
-
规则:
|
|
59
|
-
|
|
60
|
-
- 同一 issue 不应反复 sidecar。若需要,pause 并 replan。
|
|
61
|
-
- 可写 sidecar 须在 edit 后跑 targeted verification。
|
|
62
|
-
- sidecar 发现须写入 task artifacts、DAG node artifacts、`docs/progress` 或 report 后再 resume。
|
|
63
|
-
- sidecar 输出为 advisory,直到 deterministic command 验证或并入 canonical workflow state。
|
|
64
|
-
|
|
65
|
-
### Agent DAG read-only artifact boundary
|
|
66
|
-
|
|
67
|
-
Agent DAG read-only node **不得**写 root `artifacts/`。
|
|
68
|
-
|
|
69
|
-
- root `artifacts/修改记录.md` 与 `artifacts/验证结果.md` 是 legacy / explicit-write 摘要;不是 per-node 不可变历史,也不是新工作流默认交付路径。
|
|
70
|
-
- Agent DAG node 发现属于 node output 与 runner-owned artifacts,位于 `.harness/dag-runs/<state>/<run-id>/<node-id>/`;Cursor 节点的 `修改记录.md` / `验证结果.md` 位于 `.harness/dag-runs/<state>/<run-id>/artifacts/<node-id>/`。
|
|
71
|
-
- 不要把 root `artifacts/` 当作所有 DAG node 的共享 state 交集;`.harness/dag-runs/<run-id>/` 才是 DAG state 交集。
|
|
72
|
-
- `./artifacts/**` 不是 DAG artifact 位置;出现该目录通常表示 Cursor prompt 没有收到 DAG-owned artifact dir。
|
|
73
|
-
- 若必须更新 root `artifacts/`,用显式 write-capable node 或 narrow scope、verification、recorded rationale 与后续迁移计划的 main-session surgical patch。
|
|
74
|
-
|
|
75
|
-
**Linked skill-reference writeSet candidates**:DAG task 变更 workflow 语义(artifact boundary、verdict gate、evidence summary、intervention policy)时,scout node 应提议 `./skill/references/**` 下链接文件为 **writeSet expansion candidates**,而非仅 primary docs。P2 表明 implementer writeSet 遗漏 `hybrid-dag.md` 时,虽 scout 已发现 drift,仍须 post-DAG main-session patch。
|
|
76
|
-
|
|
77
|
-
**Bounded main-session patch 须记录**:DAG run 中或之后任何可接受的 surgical patch(scope、变更文件、verification、rationale)应写入 `docs/reports/`、`docs/progress/` 或 active exec plan — 不可静默应用且无 audit trail。
|
|
78
|
-
|
|
79
|
-
**勿把 root `artifacts/**` 当 read-only DAG handoff**(P3/P5):即使 task 文本、scout 或 supervisor 讨论 `artifacts/修改记录.md` / `artifacts/验证结果.md`,read-only DAG node 只能在 node output 返回发现。root `artifacts/` 是 legacy / explicit-write 摘要区,不是 in-flight DAG node 的共享 scratchpad,也不是新工作流默认 handoff。post-DAG 持久 handoff 用 `docs/reports/`、`docs/progress/`、exec-plan 索引与 `.harness/dag-runs/completed/<run-id>/` node artifacts。
|
|
80
|
-
|
|
81
|
-
### Completed run facts boundary(P3/P5)
|
|
82
|
-
|
|
83
|
-
`.harness/dag-runs/completed/<run-id>/` 是 canonical per-run 历史。视为 **只读 evidence**,不是可写 workflow state。
|
|
84
|
-
|
|
85
|
-
- **允许**:读 node JSON、`result.summary.md`、decision envelope、shell stdout、随 run directory 归档的 `artifacts/<node-id>/修改记录.md` / `验证结果.md`,用于 review、Decision Gate 或 post-DAG closeout。
|
|
86
|
-
- **禁止**:run 归档到 `completed/` 后再追加或改写 side file;mutate 历史 `run.json` / `state.json` / `artifacts/**`;把 completed facts 当作 revision DAG 的 write target。
|
|
87
|
-
- **Recovery**:revision DAG 需要 prior evidence 时,在 node output 或 main-session report 中消费 — 不要 in-place patch completed 目录。
|
|
88
|
-
- **Promotion**:需要把 completed DAG 或 one-shot run evidence 汇总为 task artifacts 时,用 deterministic `promote-run <task-id> --run-id <run-id>`;需要长期 progress 时再用 `closeout task <task-id>`。这两个命令消费历史 facts,但不修改历史 facts。
|
|
89
|
-
|
|
90
|
-
P5 验证:future agent 可从 practice report + completed node artifacts 继续,无需 root `artifacts/**` 摘要。
|
|
91
|
-
|
|
92
|
-
### Agent DAG run 中的 main-session intervention
|
|
93
|
-
|
|
94
|
-
main session 编排;不是默认 implementer。in-flight run 期间:
|
|
95
|
-
|
|
96
|
-
| Action | 何时 | 记录位置 |
|
|
97
|
-
|--------|------|----------|
|
|
98
|
-
| Inspect status / node artifacts | 始终允许 | progress 或 sidecar output 中的 notes |
|
|
99
|
-
| Sidecar read-only Pi/Cursor prompt | 诊断、plan critique、log 解读 | resume 前的 findings |
|
|
100
|
-
| Surgical patch | small、obvious、可 verify;无 active `writeSet` 冲突 | `docs/reports/` 或 exec plan,含 scope + verification |
|
|
101
|
-
| DAG/source repair | topology、writeSet 或 prompt contract 错误 | 编辑平台临时目录中的 DAG 或 plan;re-validate;rerun |
|
|
102
|
-
| Approve/reject/resume | Decision Gate `pause-on-human` | 仅 CLI artifacts |
|
|
103
|
-
| Post-DAG closeout | promotion、report、plan archive、indexes | `promote-run`、`closeout task`、`docs/reports/`、`docs/progress`、exec-plan indexes — 非 root `artifacts/`,除非 explicit narrow writeSet |
|
|
104
|
-
|
|
105
|
-
**Verdict 与 Decision Gate 提醒**(authoring guidance,非 runtime 变更):
|
|
106
|
-
|
|
107
|
-
- `shell.verdictGate` 后的 review/supervisor node:首条非空行须精确为 `VERDICT: pass` 或 `VERDICT: request-revision`(P2/P4)。
|
|
108
|
-
- Decision Gate node:恰好一个 `DECISION_ENVELOPE_JSON` block;`audit.runId` 须为 **当前** run id(P4 misbind 教训;P5 fix)。
|
|
109
|
-
- Pi MED quota 耗尽:提高 Pi node `complexity` 到 `HIGH`,而非改 `executorModels` 或加 auto-retry(P4)。
|
|
110
|
-
|
|
111
|
-
完整 authoring checklist:`docs/agent-dag-runner.md` §「Agent DAG authoring checklist」与 `hybrid-dag.md` § Authoring checklist。
|
|
112
|
-
|
|
113
|
-
## Main-session surgical patch policy
|
|
114
|
-
|
|
115
|
-
仅当以下**全部**成立时允许:
|
|
116
|
-
|
|
117
|
-
1. 变更 small 且 obvious,通常 1–3 个文件。
|
|
118
|
-
2. 原因已知;不需要 broad system understanding。
|
|
119
|
-
3. 不改变 product requirement、architecture、public API、data model 或 cross-platform contract。
|
|
120
|
-
4. 不与 active DAG node 的 `writeSet` 或其他 executor 声明职责冲突。
|
|
121
|
-
5. 可用 targeted command 立即 verify。
|
|
122
|
-
6. patch 摘要与 verification 结果记录在 artifacts/progress/report。
|
|
123
|
-
|
|
124
|
-
好例子:
|
|
125
|
-
|
|
126
|
-
- validation 指出后修正 DAG JSON path 或 schema typo。
|
|
127
|
-
- 修正 doc index link 或 typo。
|
|
128
|
-
- revert 明显 out-of-scope 的生成 scratch file。
|
|
129
|
-
- LSP 或 typecheck 指向确切 issue 时修单个 import/path 错误。
|
|
130
|
-
|
|
131
|
-
坏例子:
|
|
132
|
-
|
|
133
|
-
- 手工按 `artifacts/实现计划.md` implement feature。
|
|
134
|
-
- 不委派就修大量 test failure。
|
|
135
|
-
- 改 API/contract 语义。
|
|
136
|
-
- refactor 子系统。
|
|
137
|
-
- 编辑 in-flight exclusive DAG node 拥有的文件。
|
|
138
|
-
|
|
139
|
-
最小协议:
|
|
140
|
-
|
|
141
|
-
```text
|
|
142
|
-
1. 标记 intervention / 必要时 pause。
|
|
143
|
-
2. 检查 status 与 dirty files。
|
|
144
|
-
3. 声明 reason 与 scope。
|
|
145
|
-
4. 做最小 edit。
|
|
146
|
-
5. 跑 targeted verification。
|
|
147
|
-
6. 记录 patch 摘要与 verification evidence。
|
|
148
|
-
7. Resume DAG / rerun failed node / restart verify。
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## 失败状态机
|
|
152
|
-
|
|
153
|
-
```text
|
|
154
|
-
Run DAG workflow
|
|
155
|
-
-> success: verify -> handoff
|
|
156
|
-
-> node/step failure: diagnose
|
|
157
|
-
-> transient/tool issue: one-shot sidecar 或 retry -> verify -> resume
|
|
158
|
-
-> bounded implementation issue: Cursor/Pi fix -> verify -> resume
|
|
159
|
-
-> DAG design/source issue: stop -> edit DAG/source -> validate/spec -> rerun
|
|
160
|
-
-> requirement/architecture issue: Decision Gate 或 human approval -> resume/reject
|
|
161
|
-
-> verification failure: bounded fix loop 或 replan,永不宣称完成
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## 记录要求
|
|
165
|
-
|
|
166
|
-
每次 intervention 须留可恢复 trail:
|
|
167
|
-
|
|
168
|
-
- Agent DAG:优先 node artifacts 于 `.harness/dag-runs/<state>/<run-id>/<node-id>/`;长期结论写入 `docs/progress`、`docs/reports` 或 `docs/exec-plans`。read-only node 不得写 root `artifacts/`。
|
|
169
|
-
- Repo docs/skill workflow 变更:以 governance checks 结束,practice 变更时更新本 skill。
|
|
1
|
+
# Main Orchestrator、Agent DAG 与受控干预
|
|
2
|
+
|
|
3
|
+
协调长时 loop-agent work、判断 main session 是否可 edit、在 Agent DAG / one-shot Cursor / one-shot Pi 间选择,或在不失 auditability 的情况下恢复 in-flight workflow 时使用本文。
|
|
4
|
+
|
|
5
|
+
## 核心立场
|
|
6
|
+
|
|
7
|
+
**Agent DAG 优先,main session 编排,executor 实现,shell 验证。**
|
|
8
|
+
|
|
9
|
+
`harness.json.workflowPolicy` 的 repo 级 policy 将 Agent DAG 作为 autonomous 与 harness-governed work 的 implementation workflow。历史顺序式 `run ...` workflow 已移除。
|
|
10
|
+
|
|
11
|
+
main session 是 decision-maker 与 scheduler,不是默认 implementer。其稀缺 context 应留给 objective 对齐、DAG review、failure triage、executor 选择、verification review 与 handoff。长时 implementation 应委派给 Agent DAG node、Cursor、Pi、shell 或 worktree delegate。
|
|
12
|
+
|
|
13
|
+
这不是绝对禁止 edit。main-session 手动 edit 仅允许作为有 verification 与 artifact 记录的 bounded surgical patch。
|
|
14
|
+
|
|
15
|
+
## 默认执行模型
|
|
16
|
+
|
|
17
|
+
| Actor | 主角色 | 避免 |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| Main session | Objective、contract、DAG review、routing、failure triage、approve/reject/resume、handoff | 成为长时 coder |
|
|
20
|
+
| Agent DAG runner | 可恢复 multi-node orchestration、rank-parallel execution、write policy、run artifacts | 不更新 DAG/source 的 ad-hoc replanning |
|
|
21
|
+
| Cursor executor / prompt | Codebase-indexed search、multi-file implementation、bounded refactor/fix | 无 narrow `writeSet` / path scope 的宽写入 |
|
|
22
|
+
| Pi executor / prompt | Fast reasoning、read-only scouting、planning、review、decision-envelope advice | 充当 hidden state source |
|
|
23
|
+
| Shell executor | 确定性事实:tests、lint、typecheck、build、governance checks | 智能 repair |
|
|
24
|
+
| Human gate | Product、architecture、risk、permission 决策 | 常规 implementation debugging |
|
|
25
|
+
|
|
26
|
+
## 入口选择
|
|
27
|
+
|
|
28
|
+
**Agent DAG**(`dag run-task` → review/writeSet → `run-dag`)为默认,用于 autonomous implementation、workflow/harness/docs governance 变更、multi-file work,或任何受益于多 executor、parallel scout、显式 write policy、shell evidence、review gate、Decision Gate 的工作。
|
|
29
|
+
|
|
30
|
+
**supervised Agent DAG** 用于 `governanceProfile=supervised`,或工作触及 loop-agent runtime、scripts/CI、schema/public contract、多个 exclusive writer、repair flow 或 high-cost path。
|
|
31
|
+
|
|
32
|
+
**one-shot Pi / Cursor prompt** 仅作受控 sidecar intervention,不是 workflow state source。
|
|
33
|
+
|
|
34
|
+
**main-session surgical patch** 仅用于 small、obvious、low-risk 的修正,且 delegation 开销会占主导。
|
|
35
|
+
|
|
36
|
+
## Sidecar intervention 协议
|
|
37
|
+
|
|
38
|
+
sidecar intervention 是一次性 Pi 或 Cursor prompt,用于 unblock 主 workflow。
|
|
39
|
+
|
|
40
|
+
调用前说明:
|
|
41
|
+
|
|
42
|
+
1. 观察到什么问题。
|
|
43
|
+
2. 为何当前 DAG/step 不应盲目继续。
|
|
44
|
+
3. sidecar 是 read-only 还是可写文件。
|
|
45
|
+
4. 可写工作的精确 allowed/forbidden paths。
|
|
46
|
+
5. 预期输出及记录位置。
|
|
47
|
+
|
|
48
|
+
典型 routing:
|
|
49
|
+
|
|
50
|
+
| 情况 | 使用 |
|
|
51
|
+
|---|---|
|
|
52
|
+
| 需 quick root-cause analysis、plan critique、log 解读 | one-shot Pi prompt,read-only |
|
|
53
|
+
| 需 codebase-indexed multi-file 诊断或 bounded patch | one-shot Cursor prompt |
|
|
54
|
+
| 需确定性 evidence | shell command / shell DAG node |
|
|
55
|
+
| DAG topology、writeSet 或 source contract 错误 | stop/revise DAG 或 source;不要绕开 patch |
|
|
56
|
+
| requirement、architecture 或 risk 决策不清 | Decision Gate / human approval |
|
|
57
|
+
|
|
58
|
+
规则:
|
|
59
|
+
|
|
60
|
+
- 同一 issue 不应反复 sidecar。若需要,pause 并 replan。
|
|
61
|
+
- 可写 sidecar 须在 edit 后跑 targeted verification。
|
|
62
|
+
- sidecar 发现须写入 task artifacts、DAG node artifacts、`docs/progress` 或 report 后再 resume。
|
|
63
|
+
- sidecar 输出为 advisory,直到 deterministic command 验证或并入 canonical workflow state。
|
|
64
|
+
|
|
65
|
+
### Agent DAG read-only artifact boundary
|
|
66
|
+
|
|
67
|
+
Agent DAG read-only node **不得**写 root `artifacts/`。
|
|
68
|
+
|
|
69
|
+
- root `artifacts/修改记录.md` 与 `artifacts/验证结果.md` 是 legacy / explicit-write 摘要;不是 per-node 不可变历史,也不是新工作流默认交付路径。
|
|
70
|
+
- Agent DAG node 发现属于 node output 与 runner-owned artifacts,位于 `.harness/dag-runs/<state>/<run-id>/<node-id>/`;Cursor 节点的 `修改记录.md` / `验证结果.md` 位于 `.harness/dag-runs/<state>/<run-id>/artifacts/<node-id>/`。
|
|
71
|
+
- 不要把 root `artifacts/` 当作所有 DAG node 的共享 state 交集;`.harness/dag-runs/<run-id>/` 才是 DAG state 交集。
|
|
72
|
+
- `./artifacts/**` 不是 DAG artifact 位置;出现该目录通常表示 Cursor prompt 没有收到 DAG-owned artifact dir。
|
|
73
|
+
- 若必须更新 root `artifacts/`,用显式 write-capable node 或 narrow scope、verification、recorded rationale 与后续迁移计划的 main-session surgical patch。
|
|
74
|
+
|
|
75
|
+
**Linked skill-reference writeSet candidates**:DAG task 变更 workflow 语义(artifact boundary、verdict gate、evidence summary、intervention policy)时,scout node 应提议 `./skill/references/**` 下链接文件为 **writeSet expansion candidates**,而非仅 primary docs。P2 表明 implementer writeSet 遗漏 `hybrid-dag.md` 时,虽 scout 已发现 drift,仍须 post-DAG main-session patch。
|
|
76
|
+
|
|
77
|
+
**Bounded main-session patch 须记录**:DAG run 中或之后任何可接受的 surgical patch(scope、变更文件、verification、rationale)应写入 `docs/reports/`、`docs/progress/` 或 active exec plan — 不可静默应用且无 audit trail。
|
|
78
|
+
|
|
79
|
+
**勿把 root `artifacts/**` 当 read-only DAG handoff**(P3/P5):即使 task 文本、scout 或 supervisor 讨论 `artifacts/修改记录.md` / `artifacts/验证结果.md`,read-only DAG node 只能在 node output 返回发现。root `artifacts/` 是 legacy / explicit-write 摘要区,不是 in-flight DAG node 的共享 scratchpad,也不是新工作流默认 handoff。post-DAG 持久 handoff 用 `docs/reports/`、`docs/progress/`、exec-plan 索引与 `.harness/dag-runs/completed/<run-id>/` node artifacts。
|
|
80
|
+
|
|
81
|
+
### Completed run facts boundary(P3/P5)
|
|
82
|
+
|
|
83
|
+
`.harness/dag-runs/completed/<run-id>/` 是 canonical per-run 历史。视为 **只读 evidence**,不是可写 workflow state。
|
|
84
|
+
|
|
85
|
+
- **允许**:读 node JSON、`result.summary.md`、decision envelope、shell stdout、随 run directory 归档的 `artifacts/<node-id>/修改记录.md` / `验证结果.md`,用于 review、Decision Gate 或 post-DAG closeout。
|
|
86
|
+
- **禁止**:run 归档到 `completed/` 后再追加或改写 side file;mutate 历史 `run.json` / `state.json` / `artifacts/**`;把 completed facts 当作 revision DAG 的 write target。
|
|
87
|
+
- **Recovery**:revision DAG 需要 prior evidence 时,在 node output 或 main-session report 中消费 — 不要 in-place patch completed 目录。
|
|
88
|
+
- **Promotion**:需要把 completed DAG 或 one-shot run evidence 汇总为 task artifacts 时,用 deterministic `promote-run <task-id> --run-id <run-id>`;需要长期 progress 时再用 `closeout task <task-id>`。这两个命令消费历史 facts,但不修改历史 facts。
|
|
89
|
+
|
|
90
|
+
P5 验证:future agent 可从 practice report + completed node artifacts 继续,无需 root `artifacts/**` 摘要。
|
|
91
|
+
|
|
92
|
+
### Agent DAG run 中的 main-session intervention
|
|
93
|
+
|
|
94
|
+
main session 编排;不是默认 implementer。in-flight run 期间:
|
|
95
|
+
|
|
96
|
+
| Action | 何时 | 记录位置 |
|
|
97
|
+
|--------|------|----------|
|
|
98
|
+
| Inspect status / node artifacts | 始终允许 | progress 或 sidecar output 中的 notes |
|
|
99
|
+
| Sidecar read-only Pi/Cursor prompt | 诊断、plan critique、log 解读 | resume 前的 findings |
|
|
100
|
+
| Surgical patch | small、obvious、可 verify;无 active `writeSet` 冲突 | `docs/reports/` 或 exec plan,含 scope + verification |
|
|
101
|
+
| DAG/source repair | topology、writeSet 或 prompt contract 错误 | 编辑平台临时目录中的 DAG 或 plan;re-validate;rerun |
|
|
102
|
+
| Approve/reject/resume | Decision Gate `pause-on-human` | 仅 CLI artifacts |
|
|
103
|
+
| Post-DAG closeout | promotion、report、plan archive、indexes | `promote-run`、`closeout task`、`docs/reports/`、`docs/progress`、exec-plan indexes — 非 root `artifacts/`,除非 explicit narrow writeSet |
|
|
104
|
+
|
|
105
|
+
**Verdict 与 Decision Gate 提醒**(authoring guidance,非 runtime 变更):
|
|
106
|
+
|
|
107
|
+
- `shell.verdictGate` 后的 review/supervisor node:首条非空行须精确为 `VERDICT: pass` 或 `VERDICT: request-revision`(P2/P4)。
|
|
108
|
+
- Decision Gate node:恰好一个 `DECISION_ENVELOPE_JSON` block;`audit.runId` 须为 **当前** run id(P4 misbind 教训;P5 fix)。
|
|
109
|
+
- Pi MED quota 耗尽:提高 Pi node `complexity` 到 `HIGH`,而非改 `executorModels` 或加 auto-retry(P4)。
|
|
110
|
+
|
|
111
|
+
完整 authoring checklist:`docs/agent-dag-runner.md` §「Agent DAG authoring checklist」与 `hybrid-dag.md` § Authoring checklist。
|
|
112
|
+
|
|
113
|
+
## Main-session surgical patch policy
|
|
114
|
+
|
|
115
|
+
仅当以下**全部**成立时允许:
|
|
116
|
+
|
|
117
|
+
1. 变更 small 且 obvious,通常 1–3 个文件。
|
|
118
|
+
2. 原因已知;不需要 broad system understanding。
|
|
119
|
+
3. 不改变 product requirement、architecture、public API、data model 或 cross-platform contract。
|
|
120
|
+
4. 不与 active DAG node 的 `writeSet` 或其他 executor 声明职责冲突。
|
|
121
|
+
5. 可用 targeted command 立即 verify。
|
|
122
|
+
6. patch 摘要与 verification 结果记录在 artifacts/progress/report。
|
|
123
|
+
|
|
124
|
+
好例子:
|
|
125
|
+
|
|
126
|
+
- validation 指出后修正 DAG JSON path 或 schema typo。
|
|
127
|
+
- 修正 doc index link 或 typo。
|
|
128
|
+
- revert 明显 out-of-scope 的生成 scratch file。
|
|
129
|
+
- LSP 或 typecheck 指向确切 issue 时修单个 import/path 错误。
|
|
130
|
+
|
|
131
|
+
坏例子:
|
|
132
|
+
|
|
133
|
+
- 手工按 `artifacts/实现计划.md` implement feature。
|
|
134
|
+
- 不委派就修大量 test failure。
|
|
135
|
+
- 改 API/contract 语义。
|
|
136
|
+
- refactor 子系统。
|
|
137
|
+
- 编辑 in-flight exclusive DAG node 拥有的文件。
|
|
138
|
+
|
|
139
|
+
最小协议:
|
|
140
|
+
|
|
141
|
+
```text
|
|
142
|
+
1. 标记 intervention / 必要时 pause。
|
|
143
|
+
2. 检查 status 与 dirty files。
|
|
144
|
+
3. 声明 reason 与 scope。
|
|
145
|
+
4. 做最小 edit。
|
|
146
|
+
5. 跑 targeted verification。
|
|
147
|
+
6. 记录 patch 摘要与 verification evidence。
|
|
148
|
+
7. Resume DAG / rerun failed node / restart verify。
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 失败状态机
|
|
152
|
+
|
|
153
|
+
```text
|
|
154
|
+
Run DAG workflow
|
|
155
|
+
-> success: verify -> handoff
|
|
156
|
+
-> node/step failure: diagnose
|
|
157
|
+
-> transient/tool issue: one-shot sidecar 或 retry -> verify -> resume
|
|
158
|
+
-> bounded implementation issue: Cursor/Pi fix -> verify -> resume
|
|
159
|
+
-> DAG design/source issue: stop -> edit DAG/source -> validate/spec -> rerun
|
|
160
|
+
-> requirement/architecture issue: Decision Gate 或 human approval -> resume/reject
|
|
161
|
+
-> verification failure: bounded fix loop 或 replan,永不宣称完成
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 记录要求
|
|
165
|
+
|
|
166
|
+
每次 intervention 须留可恢复 trail:
|
|
167
|
+
|
|
168
|
+
- Agent DAG:优先 node artifacts 于 `.harness/dag-runs/<state>/<run-id>/<node-id>/`;长期结论写入 `docs/progress`、`docs/reports` 或 `docs/exec-plans`。read-only node 不得写 root `artifacts/`。
|
|
169
|
+
- Repo docs/skill workflow 变更:以 governance checks 结束,practice 变更时更新本 skill。
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
# One-shot Pi SDK Prompt Helper(`pi-prompt`)
|
|
2
|
-
|
|
3
|
-
短时 Pi SDK task、不需要完整 `.harness/tasks/<id>` workflow 时使用本文。替代 ad-hoc 临时代码脚本导入 `executeSingleSdkAttempt` 的做法。
|
|
4
|
-
|
|
5
|
-
### One-shot Pi SDK prompt helper
|
|
6
|
-
|
|
7
|
-
短时 Pi SDK task、不需要完整 `.harness/tasks/<id>` workflow 时,用 `loop-agent pi-prompt`,勿创建 ad-hoc 临时代码脚本导入 `executeSingleSdkAttempt`。`pi-prompt` 是一次性 full-capability helper;是否只读由本次调用的 prompt 与 `--tools` 决定。
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
loop-agent pi-prompt "Reply with exactly OK."
|
|
11
|
-
loop-agent pi-prompt --stdin < <temp-dir>/task.md
|
|
12
|
-
loop-agent pi-prompt --file <temp-dir>/task.md
|
|
13
|
-
loop-agent pi-prompt --cwd ~/go/src/loop-agent --tools read,grep,find,ls "Review the current diff. Do not edit files."
|
|
14
|
-
loop-agent pi-prompt --cwd ~/go/src/loop-agent --tools subagent,read --timeout 2400000 "Use subagent exactly once ..."
|
|
15
|
-
loop-agent pi-prompt --model gpt-5.5 --cwd ~/go/src/loop-agent "Deeply diagnose this failure."
|
|
16
|
-
loop-agent pi-prompt "Reply with exactly OK."
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
`<temp-dir>` 表示平台原生临时目录;实际命令中使用本机路径。
|
|
20
|
-
|
|
21
|
-
默认:`--provider wizard-local --model glm-5.2`;高复杂度 one-shot 可显式 `--model gpt-5.5`。按需用 `--provider`、`--model`、`--thinking`、`--tools`、`--timeout` 覆盖。
|
|
22
|
-
|
|
23
|
-
`pi-prompt` 仅用于 quick one-shot SDK call。**不**创建 `.harness/tasks/`、不跑 verification、不写 handoff artifact、不保留 workflow state。须可恢复、可验证的 implementation work 用 DAG 路径;需要隔离写入时使用 bounded Cursor 或 `delegate`。
|
|
1
|
+
# One-shot Pi SDK Prompt Helper(`pi-prompt`)
|
|
2
|
+
|
|
3
|
+
短时 Pi SDK task、不需要完整 `.harness/tasks/<id>` workflow 时使用本文。替代 ad-hoc 临时代码脚本导入 `executeSingleSdkAttempt` 的做法。
|
|
4
|
+
|
|
5
|
+
### One-shot Pi SDK prompt helper
|
|
6
|
+
|
|
7
|
+
短时 Pi SDK task、不需要完整 `.harness/tasks/<id>` workflow 时,用 `loop-agent pi-prompt`,勿创建 ad-hoc 临时代码脚本导入 `executeSingleSdkAttempt`。`pi-prompt` 是一次性 full-capability helper;是否只读由本次调用的 prompt 与 `--tools` 决定。
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
loop-agent pi-prompt "Reply with exactly OK."
|
|
11
|
+
loop-agent pi-prompt --stdin < <temp-dir>/task.md
|
|
12
|
+
loop-agent pi-prompt --file <temp-dir>/task.md
|
|
13
|
+
loop-agent pi-prompt --cwd ~/go/src/loop-agent --tools read,grep,find,ls "Review the current diff. Do not edit files."
|
|
14
|
+
loop-agent pi-prompt --cwd ~/go/src/loop-agent --tools subagent,read --timeout 2400000 "Use subagent exactly once ..."
|
|
15
|
+
loop-agent pi-prompt --model gpt-5.5 --cwd ~/go/src/loop-agent "Deeply diagnose this failure."
|
|
16
|
+
loop-agent pi-prompt "Reply with exactly OK."
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`<temp-dir>` 表示平台原生临时目录;实际命令中使用本机路径。
|
|
20
|
+
|
|
21
|
+
默认:`--provider wizard-local --model glm-5.2`;高复杂度 one-shot 可显式 `--model gpt-5.5`。按需用 `--provider`、`--model`、`--thinking`、`--tools`、`--timeout` 覆盖。
|
|
22
|
+
|
|
23
|
+
`pi-prompt` 仅用于 quick one-shot SDK call。**不**创建 `.harness/tasks/`、不跑 verification、不写 handoff artifact、不保留 workflow state。须可恢复、可验证的 implementation work 用 DAG 路径;需要隔离写入时使用 bounded Cursor 或 `delegate`。
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
# Pi Subagent Assisted Mode
|
|
2
|
-
|
|
3
|
-
loop-agent task 启用 `piSubagentMode`、在 analyze/plan/spec/retrospective 内需要 read-only scout/planner/reviewer subagents,或配置 project-local agents/prompts 时使用本文。
|
|
4
|
-
|
|
5
|
-
`task.json` 支持可选字段 `piSubagentMode`,用于 step 级 `subagent` tool delegation:
|
|
6
|
-
|
|
7
|
-
| Mode | analyze | plan | spec | implement | retrospective | verify |
|
|
8
|
-
|------|---------|------|------|-----------|----------------|--------|
|
|
9
|
-
| `off`(默认) | read only | read only | read only | +write/edit/bash | read only | read only |
|
|
10
|
-
| `analyze-plan` | **+subagent** | **+subagent** | **+subagent** | 同 off | 同 off | 同 off |
|
|
11
|
-
| `full` | **+subagent** | **+subagent** | **+subagent** | 同 off | **+subagent** | 同 off |
|
|
12
|
-
|
|
13
|
-
### 何时启用
|
|
14
|
-
|
|
15
|
-
在 `task.json` 设 `piSubagentMode: "analyze-plan"` 或 `piSubagentMode: "full"` 当:
|
|
16
|
-
- task 涉及大规模 codebase 阅读,适合 parallel scout agents
|
|
17
|
-
- analysis 或 planning 需多角度调查(如跨模块比较实现)
|
|
18
|
-
- retrospective review 适合独立 reviewer subagent(`full` mode)
|
|
19
|
-
|
|
20
|
-
### step 内使用 `subagent` 的指引
|
|
21
|
-
|
|
22
|
-
subagent 可用时,**仅用于 read-only task**:
|
|
23
|
-
- **Parallel scout**:dispatch 多个 subagent 同时搜索/阅读不同区域
|
|
24
|
-
- **Chain**:一个 subagent scout,另一个基于发现 planning
|
|
25
|
-
- **Reviewer**:用 subagent 在定稿前 review analysis/plan
|
|
26
|
-
|
|
27
|
-
**不要**用 subagent 做 writing、editing 或执行命令。subagent 输出仅 advisory;务必 verify 并将发现并入自己的输出。**不要**把 subagent 结果当作权威 state 或 artifact source。
|
|
28
|
-
|
|
29
|
-
### 前置条件
|
|
30
|
-
|
|
31
|
-
- Pi runtime 环境须有 `subagent` tool(经 Pi subagent extension 加载)
|
|
32
|
-
- 推荐用 Pi 自带 example 文件安装:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
mkdir -p ~/.pi/agent/extensions/subagent ~/.pi/agent/agents ~/.pi/agent/prompts
|
|
36
|
-
|
|
37
|
-
ln -sf /usr/local/lib/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/index.ts ~/.pi/agent/extensions/subagent/index.ts
|
|
38
|
-
ln -sf /usr/local/lib/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/agents.ts ~/.pi/agent/extensions/subagent/agents.ts
|
|
39
|
-
|
|
40
|
-
for f in /usr/local/lib/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/agents/*.md; do
|
|
41
|
-
ln -sf "$f" ~/.pi/agent/agents/$(basename "$f")
|
|
42
|
-
done
|
|
43
|
-
|
|
44
|
-
for f in /usr/local/lib/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/prompts/*.md; do
|
|
45
|
-
ln -sf "$f" ~/.pi/agent/prompts/$(basename "$f")
|
|
46
|
-
done
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
- 最小 smoke check:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
pi -p --no-session --no-context-files --no-skills --tools subagent "Reply with exactly OK."
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
预期输出:`OK`
|
|
56
|
-
- mode 按 task opt-in;默认 `off` 保持向后兼容
|
|
57
|
-
- 任何 mode 下 `implement` 都不给 `subagent`(防止 nested multi-writer)
|
|
58
|
-
|
|
59
|
-
### 内置 Project-Local Agents 与 Prompts
|
|
60
|
-
|
|
61
|
-
本 repo 提供 `.pi/agents/` 与 `.pi/prompts/` 模板,供 `piSubagentMode` 使用:
|
|
62
|
-
|
|
63
|
-
**Agents**(`.pi/agents/`)
|
|
64
|
-
|
|
65
|
-
| Agent | Role | Model |
|
|
66
|
-
|-------|------|-------|
|
|
67
|
-
| `loop-agent-scout` | Read-only recon:code、tests、docs、governance | `cursor/composer-2.5` |
|
|
68
|
-
| `loop-agent-planner` | Implementation planning:最小可执行 plan | `cursor/composer-2.5` |
|
|
69
|
-
| `loop-agent-reviewer` | Strict review:scope drift、verification gap、contract break | `cursor/composer-2.5` |
|
|
70
|
-
| `loop-agent-worker` | General execution:bounded implementation 与 fix | `cursor/composer-2.5` |
|
|
71
|
-
|
|
72
|
-
**Prompt Templates**(`.pi/prompts/`):输入 `/loop-agent-*` 调用
|
|
73
|
-
|
|
74
|
-
| Template | Flow |
|
|
75
|
-
|----------|------|
|
|
76
|
-
| `loop-agent-scout-and-plan` | scout → planner chain |
|
|
77
|
-
| `loop-agent-analyze-wide` | 3 parallel scouts → analysis |
|
|
78
|
-
| `loop-agent-review-only` | 独立 review plan/implementation/verification |
|
|
79
|
-
| `loop-agent-implement-and-review` | worker → reviewer → worker loop |
|
|
80
|
-
|
|
81
|
-
传 `agentScope: "both"` + `confirmProjectAgents: false` 以访问 repo-local agents。
|
|
1
|
+
# Pi Subagent Assisted Mode
|
|
2
|
+
|
|
3
|
+
loop-agent task 启用 `piSubagentMode`、在 analyze/plan/spec/retrospective 内需要 read-only scout/planner/reviewer subagents,或配置 project-local agents/prompts 时使用本文。
|
|
4
|
+
|
|
5
|
+
`task.json` 支持可选字段 `piSubagentMode`,用于 step 级 `subagent` tool delegation:
|
|
6
|
+
|
|
7
|
+
| Mode | analyze | plan | spec | implement | retrospective | verify |
|
|
8
|
+
|------|---------|------|------|-----------|----------------|--------|
|
|
9
|
+
| `off`(默认) | read only | read only | read only | +write/edit/bash | read only | read only |
|
|
10
|
+
| `analyze-plan` | **+subagent** | **+subagent** | **+subagent** | 同 off | 同 off | 同 off |
|
|
11
|
+
| `full` | **+subagent** | **+subagent** | **+subagent** | 同 off | **+subagent** | 同 off |
|
|
12
|
+
|
|
13
|
+
### 何时启用
|
|
14
|
+
|
|
15
|
+
在 `task.json` 设 `piSubagentMode: "analyze-plan"` 或 `piSubagentMode: "full"` 当:
|
|
16
|
+
- task 涉及大规模 codebase 阅读,适合 parallel scout agents
|
|
17
|
+
- analysis 或 planning 需多角度调查(如跨模块比较实现)
|
|
18
|
+
- retrospective review 适合独立 reviewer subagent(`full` mode)
|
|
19
|
+
|
|
20
|
+
### step 内使用 `subagent` 的指引
|
|
21
|
+
|
|
22
|
+
subagent 可用时,**仅用于 read-only task**:
|
|
23
|
+
- **Parallel scout**:dispatch 多个 subagent 同时搜索/阅读不同区域
|
|
24
|
+
- **Chain**:一个 subagent scout,另一个基于发现 planning
|
|
25
|
+
- **Reviewer**:用 subagent 在定稿前 review analysis/plan
|
|
26
|
+
|
|
27
|
+
**不要**用 subagent 做 writing、editing 或执行命令。subagent 输出仅 advisory;务必 verify 并将发现并入自己的输出。**不要**把 subagent 结果当作权威 state 或 artifact source。
|
|
28
|
+
|
|
29
|
+
### 前置条件
|
|
30
|
+
|
|
31
|
+
- Pi runtime 环境须有 `subagent` tool(经 Pi subagent extension 加载)
|
|
32
|
+
- 推荐用 Pi 自带 example 文件安装:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
mkdir -p ~/.pi/agent/extensions/subagent ~/.pi/agent/agents ~/.pi/agent/prompts
|
|
36
|
+
|
|
37
|
+
ln -sf /usr/local/lib/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/index.ts ~/.pi/agent/extensions/subagent/index.ts
|
|
38
|
+
ln -sf /usr/local/lib/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/agents.ts ~/.pi/agent/extensions/subagent/agents.ts
|
|
39
|
+
|
|
40
|
+
for f in /usr/local/lib/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/agents/*.md; do
|
|
41
|
+
ln -sf "$f" ~/.pi/agent/agents/$(basename "$f")
|
|
42
|
+
done
|
|
43
|
+
|
|
44
|
+
for f in /usr/local/lib/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/prompts/*.md; do
|
|
45
|
+
ln -sf "$f" ~/.pi/agent/prompts/$(basename "$f")
|
|
46
|
+
done
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- 最小 smoke check:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pi -p --no-session --no-context-files --no-skills --tools subagent "Reply with exactly OK."
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
预期输出:`OK`
|
|
56
|
+
- mode 按 task opt-in;默认 `off` 保持向后兼容
|
|
57
|
+
- 任何 mode 下 `implement` 都不给 `subagent`(防止 nested multi-writer)
|
|
58
|
+
|
|
59
|
+
### 内置 Project-Local Agents 与 Prompts
|
|
60
|
+
|
|
61
|
+
本 repo 提供 `.pi/agents/` 与 `.pi/prompts/` 模板,供 `piSubagentMode` 使用:
|
|
62
|
+
|
|
63
|
+
**Agents**(`.pi/agents/`)
|
|
64
|
+
|
|
65
|
+
| Agent | Role | Model |
|
|
66
|
+
|-------|------|-------|
|
|
67
|
+
| `loop-agent-scout` | Read-only recon:code、tests、docs、governance | `cursor/composer-2.5` |
|
|
68
|
+
| `loop-agent-planner` | Implementation planning:最小可执行 plan | `cursor/composer-2.5` |
|
|
69
|
+
| `loop-agent-reviewer` | Strict review:scope drift、verification gap、contract break | `cursor/composer-2.5` |
|
|
70
|
+
| `loop-agent-worker` | General execution:bounded implementation 与 fix | `cursor/composer-2.5` |
|
|
71
|
+
|
|
72
|
+
**Prompt Templates**(`.pi/prompts/`):输入 `/loop-agent-*` 调用
|
|
73
|
+
|
|
74
|
+
| Template | Flow |
|
|
75
|
+
|----------|------|
|
|
76
|
+
| `loop-agent-scout-and-plan` | scout → planner chain |
|
|
77
|
+
| `loop-agent-analyze-wide` | 3 parallel scouts → analysis |
|
|
78
|
+
| `loop-agent-review-only` | 独立 review plan/implementation/verification |
|
|
79
|
+
| `loop-agent-implement-and-review` | worker → reviewer → worker loop |
|
|
80
|
+
|
|
81
|
+
传 `agentScope: "both"` + `confirmProjectAgents: false` 以访问 repo-local agents。
|