@tea-agent/loop-agent 0.13.0-beta.0 → 0.13.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.
Files changed (282) hide show
  1. package/AGENTS.md +157 -155
  2. package/CHANGELOG.md +301 -322
  3. package/README.md +335 -345
  4. package/bin/agent-worker.js +22 -22
  5. package/bin/loop-agent.js +21 -21
  6. package/dist/commands/cursor-prompt.js +6 -6
  7. package/dist/commands/init.js +597 -528
  8. package/dist/commands/loop-benchmark.js +11 -11
  9. package/dist/commands/pi-reuse-benchmark.js +16 -16
  10. package/dist/executors/shell-executor.js +200 -21
  11. package/dist/infrastructure/evaluation/candidate-store.js +5 -1
  12. package/dist/sidecars/cursor-prompt/executor.js +1 -1
  13. package/dist/task/runtime.js +27 -27
  14. package/dist/worker/observe/static/api.js +46 -46
  15. package/dist/worker/observe/static/app.js +150 -150
  16. package/dist/worker/observe/static/constants.js +148 -148
  17. package/dist/worker/observe/static/copy.js +67 -67
  18. package/dist/worker/observe/static/dag-helpers.js +172 -172
  19. package/dist/worker/observe/static/dag-layout.d.ts +31 -31
  20. package/dist/worker/observe/static/dag-layout.js +83 -83
  21. package/dist/worker/observe/static/dag-model.js +72 -72
  22. package/dist/worker/observe/static/dom.js +212 -53
  23. package/dist/worker/observe/static/format-pool.js +67 -67
  24. package/dist/worker/observe/static/format.js +292 -292
  25. package/dist/worker/observe/static/index.html +308 -308
  26. package/dist/worker/observe/static/kpi.js +94 -94
  27. package/dist/worker/observe/static/relations.js +133 -133
  28. package/dist/worker/observe/static/router.js +93 -93
  29. package/dist/worker/observe/static/run-processing.js +148 -148
  30. package/dist/worker/observe/static/shell-chrome.js +68 -68
  31. package/dist/worker/observe/static/state.js +267 -253
  32. package/dist/worker/observe/static/styles.css +1902 -1902
  33. package/dist/worker/observe/static/views/batch.js +227 -227
  34. package/dist/worker/observe/static/views/dag-graph.js +172 -172
  35. package/dist/worker/observe/static/views/dag-inspector.js +627 -607
  36. package/dist/worker/observe/static/views/dag.js +371 -362
  37. package/dist/worker/observe/static/views/dashboard.js +509 -252
  38. package/dist/worker/observe/static/views/failures.js +143 -143
  39. package/dist/worker/observe/static/views/feature.js +492 -492
  40. package/dist/worker/observe/static/views/pool.js +350 -350
  41. package/dist/worker/observe/static/views/run.js +453 -453
  42. package/dist/worker/observe/static/views/session-timeline.js +219 -205
  43. package/dist/worker/observe/static/views/shell.js +7 -7
  44. package/dist/worker/observe/static/views/task.js +314 -314
  45. package/dist/worker/observe/static/views/timeline.js +163 -163
  46. package/dist/workflows/dag/backend-test-case-manifest.js +503 -0
  47. package/dist/workflows/dag/backend-test-execution-contract.js +353 -0
  48. package/dist/workflows/dag/backend-test-result-contract.js +568 -0
  49. package/dist/workflows/dag/canvas-observer.js +275 -275
  50. package/dist/workflows/dag/decision-envelope.js +57 -2
  51. package/dist/workflows/dag/frontend-implementation-contract.js +240 -0
  52. package/dist/workflows/dag/frontend-project-capability.js +309 -0
  53. package/dist/workflows/dag/frontend-repair.js +341 -0
  54. package/dist/workflows/dag/frontend-risk.js +161 -0
  55. package/dist/workflows/dag/frontend-verification-trace.js +190 -0
  56. package/dist/workflows/dag/init-hybrid.js +1020 -125
  57. package/dist/workflows/dag/repair-artifact.js +43 -3
  58. package/dist/workflows/dag/skill-instructions.js +4 -2
  59. package/dist/workflows/dag/types.js +29 -8
  60. package/docs/README.md +105 -104
  61. package/docs/agent-dag-recovery-playbook.md +195 -195
  62. package/docs/agent-dag-runner.md +67 -67
  63. package/docs/architecture/README.md +26 -26
  64. package/docs/architecture/dag-execution.md +140 -140
  65. package/docs/architecture/evolution.md +54 -54
  66. package/docs/architecture/facts-and-state.md +71 -71
  67. package/docs/architecture/runtime-boundaries.md +191 -191
  68. package/docs/architecture/system-overview.md +93 -93
  69. package/docs/architecture/worker-and-feature.md +85 -85
  70. package/docs/cursor-prompt-sidecar.md +36 -36
  71. package/docs/decisions/README.md +18 -18
  72. package/docs/design/README.md +167 -167
  73. package/docs/development-principles.md +73 -73
  74. package/docs/exec-plans/README.md +6 -6
  75. package/docs/exec-plans/active/README.md +1 -4
  76. package/docs/exec-plans/completed/README.md +106 -84
  77. package/docs/feature-workflow.md +414 -389
  78. package/docs/harness-methodology-debugging.md +153 -153
  79. package/docs/harness-methodology-tdd.md +130 -130
  80. package/docs/harness-methodology-verification.md +27 -27
  81. package/docs/init-surface.manifest.json +307 -289
  82. package/docs/loop-agent-harness.md +142 -142
  83. package/docs/production-readiness.md +96 -96
  84. package/docs/progress/README.md +76 -60
  85. package/docs/reports/README.md +150 -108
  86. package/docs/skills/README.md +7 -7
  87. package/docs/skills/vetted-skill-registry.md +29 -29
  88. package/docs/templates/adr.md +60 -60
  89. package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -94
  90. package/docs/templates/agent-dag-decision-envelope.schema.json +213 -213
  91. package/docs/templates/agent-dag-decision-gate-dogfood-report.md +117 -117
  92. package/docs/templates/agent-dag-decision-gate.prompt.md +246 -246
  93. package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -98
  94. package/docs/templates/agent-dag-report.schema.json +473 -473
  95. package/docs/templates/agent-dag-review-verdict.prompt.md +68 -68
  96. package/docs/templates/agent-dag.base.json +190 -190
  97. package/docs/templates/agent-dag.final-verification.json +185 -185
  98. package/docs/templates/agent-dag.schema.json +411 -411
  99. package/docs/templates/agent-dag.supervised-implementation.json +620 -501
  100. package/docs/templates/backend-test-analysis.schema.json +44 -44
  101. package/docs/templates/backend-test-case-manifest.schema.json +190 -0
  102. package/docs/templates/backend-test-dag.classify.prompt.md +75 -0
  103. package/docs/templates/backend-test-dag.generate-pytest.prompt.md +204 -202
  104. package/docs/templates/backend-test-dag.json +559 -311
  105. package/docs/templates/backend-test-dag.retrospect.prompt.md +139 -125
  106. package/docs/templates/backend-test-dag.review-cases.prompt.md +83 -81
  107. package/docs/templates/backend-test-execution.schema.json +133 -0
  108. package/docs/templates/backend-test-result.schema.json +99 -0
  109. package/docs/templates/branch-merge-report.md +93 -0
  110. package/docs/templates/exec-plan.md +64 -64
  111. package/docs/templates/feature-spec.md +53 -53
  112. package/docs/templates/frontend-design-contract.md +42 -42
  113. package/docs/templates/frontend-eval/fixtures/failures/01-type-build-error.md +17 -0
  114. package/docs/templates/frontend-eval/fixtures/failures/02-unit-component-test-fail.md +16 -0
  115. package/docs/templates/frontend-eval/fixtures/failures/03-fixture-schema-drift.md +16 -0
  116. package/docs/templates/frontend-eval/fixtures/failures/04-missing-loading-empty-error-state.md +16 -0
  117. package/docs/templates/frontend-eval/fixtures/failures/05-forbidden-write-writeset-expansion.md +16 -0
  118. package/docs/templates/frontend-eval/fixtures/failures/06-unapproved-dependency-add.md +16 -0
  119. package/docs/templates/frontend-eval/fixtures/failures/07-mock-production-on.md +21 -0
  120. package/docs/templates/frontend-eval/fixtures/functional/01-simple-component-style.md +29 -0
  121. package/docs/templates/frontend-eval/fixtures/functional/02-form-validation.md +28 -0
  122. package/docs/templates/frontend-eval/fixtures/functional/03-list-detail-page.md +28 -0
  123. package/docs/templates/frontend-eval/fixtures/functional/04-api-mock.md +29 -0
  124. package/docs/templates/frontend-eval/fixtures/functional/05-permission-auth-gated-ui.md +27 -0
  125. package/docs/templates/frontend-eval/fixtures/functional/06-ssr-server-client-boundary.md +28 -0
  126. package/docs/templates/frontend-eval/fixtures/functional/07-shared-public-component-api.md +28 -0
  127. package/docs/templates/frontend-eval/fixtures/functional/08-pure-local-no-remote.md +27 -0
  128. package/docs/templates/frontend-eval/metrics.md +138 -0
  129. package/docs/templates/frontend-eval/smoke-targets.md +53 -0
  130. package/docs/templates/frontend-implementation-contract.schema.json +27 -0
  131. package/docs/templates/frontend-task-constraints.md +35 -35
  132. package/docs/templates/frontend-task-requirement.md +70 -70
  133. package/docs/templates/frontend-test-dag.generate-cases.prompt.md +5 -5
  134. package/docs/templates/frontend-test-dag.json +23 -23
  135. package/docs/templates/frontend-test-dag.retrieve-context.prompt.md +3 -3
  136. package/docs/templates/frontend-test-dag.retrospect.prompt.md +3 -3
  137. package/docs/templates/frontend-test-dag.review-cases.prompt.md +3 -3
  138. package/docs/templates/frontend-test-dag.review-execution.prompt.md +3 -3
  139. package/docs/templates/harness.schema.json +221 -221
  140. package/docs/templates/hybrid-dag.json +188 -188
  141. package/docs/templates/init-evolution-review.md +35 -35
  142. package/docs/templates/interactive-ui-round2-experiment.md +66 -66
  143. package/docs/templates/knowledge-graph-bootstrap-dag.json +118 -118
  144. package/docs/templates/knowledge-sync-dag.json +178 -178
  145. package/docs/templates/knowledge-sync-draft.schema.json +71 -71
  146. package/docs/templates/product-line/AGENTS.md +8 -8
  147. package/docs/templates/product-line/README.md +9 -9
  148. package/docs/templates/product-line/acceptance.yaml +14 -14
  149. package/docs/templates/product-line/closeout.yaml +9 -9
  150. package/docs/templates/product-line/design.md +13 -13
  151. package/docs/templates/product-line/links.md +10 -10
  152. package/docs/templates/product-line/requirement.md +17 -17
  153. package/docs/templates/product-line/task-graph.yaml +15 -15
  154. package/docs/templates/product-line/task.yaml +64 -64
  155. package/docs/templates/product-line/test-plan.md +7 -7
  156. package/docs/templates/production-readiness-checklist.md +57 -57
  157. package/docs/templates/progress-log.md +17 -17
  158. package/docs/templates/project-start-checklist.md +9 -9
  159. package/docs/templates/qa-report.md +48 -48
  160. package/docs/templates/sprint-contract.md +29 -29
  161. package/docs/templates/worker-dogfood-evidence.md +80 -80
  162. package/docs/templates/worker-dogfood-setup.md +68 -68
  163. package/docs/verification-matrix.md +70 -70
  164. package/examples/decision-gate-agent-dag.json +177 -177
  165. package/examples/example-dag.json +46 -46
  166. package/examples/hybrid-loop-agent-dag.json +189 -189
  167. package/harness.json +66 -66
  168. package/package.json +52 -88
  169. package/scripts/check-product-line-docs.sh +29 -29
  170. package/scripts/check-task-pool-root.sh +32 -32
  171. package/scripts/kb-bootstrap-init-skeleton.sh +240 -240
  172. package/scripts/kb-graph-incremental-prepare.mjs +386 -386
  173. package/scripts/kb-graph-incremental-prepare.sh +5 -5
  174. package/scripts/kb-graph-materialize.mjs +105 -105
  175. package/scripts/kb-graph-materialize.sh +4 -4
  176. package/scripts/kb-graph-promote.mjs +164 -164
  177. package/scripts/kb-graph-promote.sh +4 -4
  178. package/scripts/kb-query.mjs +554 -554
  179. package/scripts/kb-query.sh +5 -5
  180. package/skills/agent-worker/SKILL.md +39 -39
  181. package/skills/agent-worker/references/agent-worker-operator.md +60 -60
  182. package/skills/ai-engineering-context/SKILL.md +48 -48
  183. package/skills/analyze-product-dependencies/SKILL.md +67 -67
  184. package/skills/analyze-product-dependencies/agents/openai.yaml +4 -4
  185. package/skills/analyze-product-dependencies/references/api-documentation-schema.md +30 -30
  186. package/skills/analyze-product-dependencies/references/dependency-analysis-schema.md +28 -28
  187. package/skills/analyze-product-dependencies/references/example.md +76 -76
  188. package/skills/analyze-product-dependencies/references/forward-test-cases.md +35 -35
  189. package/skills/analyze-product-dependencies/references/input-contract.md +11 -11
  190. package/skills/analyze-product-dependencies/references/scouting-rules.md +61 -61
  191. package/skills/analyze-product-dependencies/scripts/test-validators.mjs +267 -267
  192. package/skills/analyze-product-dependencies/scripts/validate-api-documentation.mjs +101 -101
  193. package/skills/analyze-product-dependencies/scripts/validate-dependency-analysis.mjs +142 -142
  194. package/skills/analyze-product-dependencies/scripts/validate-product-requirement-input.mjs +76 -76
  195. package/skills/analyze-product-dependencies/scripts/validation-helpers.mjs +146 -146
  196. package/skills/analyze-product-requirements/SKILL.md +90 -90
  197. package/skills/analyze-product-requirements/agents/openai.yaml +4 -4
  198. package/skills/analyze-product-requirements/references/acceptance-criteria.md +91 -91
  199. package/skills/analyze-product-requirements/references/clarification-and-knowledge.md +56 -56
  200. package/skills/analyze-product-requirements/references/example.md +86 -86
  201. package/skills/analyze-product-requirements/references/forward-test-cases.md +66 -66
  202. package/skills/analyze-product-requirements/references/product-analysis-schema.md +32 -32
  203. package/skills/analyze-product-requirements/references/product-requirement-schema.md +33 -33
  204. package/skills/analyze-product-requirements/references/requirement-clarification-schema.md +35 -35
  205. package/skills/analyze-product-requirements/scripts/test-validators.mjs +193 -193
  206. package/skills/analyze-product-requirements/scripts/validate-product-analysis.mjs +69 -69
  207. package/skills/analyze-product-requirements/scripts/validate-product-requirement.mjs +97 -97
  208. package/skills/analyze-product-requirements/scripts/validate-requirement-clarification.mjs +98 -98
  209. package/skills/analyze-product-requirements/scripts/validation-helpers.mjs +156 -156
  210. package/skills/browser-tools/SKILL.md +196 -0
  211. package/skills/browser-tools/browser-content.js +103 -0
  212. package/skills/browser-tools/browser-cookies.js +35 -0
  213. package/skills/browser-tools/browser-eval.js +53 -0
  214. package/skills/browser-tools/browser-hn-scraper.js +108 -0
  215. package/skills/browser-tools/browser-nav.js +44 -0
  216. package/skills/browser-tools/browser-pick.js +162 -0
  217. package/skills/browser-tools/browser-screenshot.js +34 -0
  218. package/skills/browser-tools/browser-start.js +86 -0
  219. package/skills/browser-tools/package-lock.json +2556 -0
  220. package/skills/browser-tools/package.json +19 -0
  221. package/skills/code-review-core/SKILL.md +20 -20
  222. package/skills/codebase-scout/SKILL.md +19 -19
  223. package/skills/frontend-design-review/SKILL.md +66 -66
  224. package/skills/frontend-design-review/references/review-checklist.md +58 -58
  225. package/skills/frontend-implementation/SKILL.md +49 -47
  226. package/skills/frontend-implementation/references/code-standards.md +32 -32
  227. package/skills/frontend-implementation/references/design-spec.md +46 -46
  228. package/skills/frontend-implementation/references/node-contracts.md +27 -76
  229. package/skills/frontend-review/SKILL.md +59 -59
  230. package/skills/frontend-review/references/review-findings.md +47 -47
  231. package/skills/frontend-verification/SKILL.md +53 -53
  232. package/skills/frontend-verification/references/verification-checklist.md +68 -68
  233. package/skills/grill-me/SKILL.md +10 -10
  234. package/skills/grill-with-docs/SKILL.md +88 -88
  235. package/skills/grill-with-docs/adr-format.md +47 -47
  236. package/skills/grill-with-docs/context-format.md +60 -60
  237. package/skills/init-capability-evolution/SKILL.md +70 -70
  238. package/skills/loop-agent/SKILL.md +151 -151
  239. package/skills/loop-agent/references/README.md +67 -67
  240. package/skills/loop-agent/references/command-reference.md +527 -505
  241. package/skills/loop-agent/references/docs-converge.md +126 -126
  242. package/skills/loop-agent/references/harness-policy.md +263 -263
  243. package/skills/loop-agent/references/hybrid-dag.md +243 -238
  244. package/skills/loop-agent/references/learned/README.md +21 -21
  245. package/skills/loop-agent/references/long-running-loop.md +57 -57
  246. package/skills/loop-agent/references/model-routing.md +36 -36
  247. package/skills/loop-agent/references/multi-worktree.md +54 -54
  248. package/skills/loop-agent/references/one-shot-runs.md +85 -85
  249. package/skills/loop-agent/references/orchestrator-and-interventions.md +169 -169
  250. package/skills/loop-agent/references/pi-prompt.md +23 -23
  251. package/skills/loop-agent/references/pi-subagent-assisted-mode.md +84 -84
  252. package/skills/loop-agent/references/post-implementation-and-patterns.md +44 -44
  253. package/skills/loop-agent/references/task-workflow.md +89 -89
  254. package/skills/loop-agent/references/verification-and-failure-handling.md +141 -139
  255. package/skills/playwright-cli/SKILL.md +420 -420
  256. package/skills/playwright-cli/references/element-attributes.md +23 -23
  257. package/skills/playwright-cli/references/playwright-tests.md +39 -39
  258. package/skills/playwright-cli/references/request-mocking.md +87 -87
  259. package/skills/playwright-cli/references/running-code.md +241 -241
  260. package/skills/playwright-cli/references/session-management.md +225 -225
  261. package/skills/playwright-cli/references/storage-state.md +275 -275
  262. package/skills/playwright-cli/references/test-generation.md +433 -433
  263. package/skills/playwright-cli/references/tracing.md +139 -139
  264. package/skills/playwright-cli/references/video-recording.md +143 -143
  265. package/skills/playwright-cli-case-generator/SKILL.md +74 -74
  266. package/skills/requesting-code-review/SKILL.md +101 -101
  267. package/skills/requesting-code-review/code-reviewer.md +168 -168
  268. package/skills/systematic-debugging/CREATION-LOG.md +119 -119
  269. package/skills/systematic-debugging/SKILL.md +296 -296
  270. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -158
  271. package/skills/systematic-debugging/condition-based-waiting.md +115 -115
  272. package/skills/systematic-debugging/defense-in-depth.md +122 -122
  273. package/skills/systematic-debugging/find-polluter.sh +63 -63
  274. package/skills/systematic-debugging/root-cause-tracing.md +169 -169
  275. package/skills/systematic-debugging/test-academic.md +14 -14
  276. package/skills/systematic-debugging/test-pressure-1.md +58 -58
  277. package/skills/systematic-debugging/test-pressure-2.md +68 -68
  278. package/skills/systematic-debugging/test-pressure-3.md +69 -69
  279. package/skills/test-driven-development/SKILL.md +20 -20
  280. package/skills/using-git-worktrees/SKILL.md +215 -215
  281. package/skills/verification-before-completion/SKILL.md +154 -154
  282. package/skills/webapp-testing/SKILL.md +19 -19
@@ -1,238 +1,243 @@
1
- # Agent DAG Hybrid Workflow(`run-dag` / `dag init-hybrid`)
2
-
3
- 创建或执行 loop-agent 工作的首选 Agent DAG path 时使用本文:Level 2 Agent DAG orchestration、Pi read-only + Pi `toolProfile: "write"` bounded execution、Pi-only writers、write policy、DAG template、task-to-DAG 生成,或基于 governance-profile 的 template 选择。
4
-
5
- ### DAG workflow 优先级
6
-
7
- `harness.json.workflowPolicy` 现声明 Agent DAG 为首选 implementation workflow:
8
-
9
- - `defaultImplementationWorkflow=agent-dag`
10
- - `dag.defaultEntry=dag run-task`
11
- - `dag.outputLanguage=zh-CN`;未配置时也默认中文,显式设为 `en` 可切换英文
12
- - `dag.profileRouting`:通用候选映射为 `minimal|standard -> standard-dag`、`reviewed -> review-gated-dag`、`supervised -> supervised-implementation`
13
- - `humanGatePolicy.defaultMode=record-only`;需求不清、架构/公共契约风险、凭据/费用/部署风险、重复 gate failure 或高风险决策时升级人工介入
14
-
15
- 此 policy 驱动 `dag run-task --profile auto`:CLI 仍要求显式 `dag run-task`、`dag validate`、`run-dag`,但 `--profile auto` 在确定性 candidate `governanceProfile` 推断后应用 `workflowPolicy.dag.profileRouting`。生成器还会把 `outputLanguage` 写入 DagSpec,runner 在每个 Pi/Cursor 节点 prompt 中注入语言规则;代码、命令、路径、JSON 字段与 gate token 保持原样。`humanGatePolicy` 是默认人机边界声明;真实暂停仍由 DAG 节点的 `decisionGate.mode: "pause-on-human"` 与 decision envelope 触发。无 profile 的 `dag run-task <task-id>` 仍为 standard-compatible,供 legacy/review workflow。
16
-
17
- 对于默认 `standard` 任务,生成器根据标题、`source/需求.md` 和结构化 `allowedPaths` 做保守、确定性的需求分类。只有高置信的前端实现需求自动选择 `frontend-implementation` DAG;后端、前后端混合、明确排除前端或证据不足的需求继续使用 governance profile 选出的模板。分类不会把普通后端实现路由到 `backend-test`,也不会替换由显式 profile、`workflowPolicy` 或 supervised quality gate 选中的 supervised 模板。
18
-
19
- 前端专用链在 `frontend-scout-pi` 后加入只读 `frontend-mock-assess-pi` 和确定性 contract gate,根据接口契约、后端就绪度、生成期能力 seed 与固化验证入口选择 `native|browser-intercept|request-adapter|not-needed|blocked`。策略直接传给 plan、两阶段 design review、唯一 writer、实现 review 和 closeout;真实请求保持默认,缺少契约、生产隔离或可执行验证时 gate 阻塞。可选 `frontendMock` 配置声明 `auto|required|disabled`、既有服务目录与专项命令;不安全或不完整的显式 required 合同只生成无 writer 的评估链,有可信命令时才增加 `frontend-mock-verify-shell`。Mock-backed 证据只证明前端状态;`not-needed` 需要真实或无远程接口行为证据。未调用后端时 closeout 报告 `Frontend status: mock-validated` 与 `Real integration: pending`。
20
-
21
- 显式专用 `taskKind` 保持兼容并优先于任务源分类,也不扩充 governance profile:`frontend-implementation` 显式选择前端实现 DAG,`backend-test` 显式选择后端测试 DAG。后端测试链为 `analyze-inputs-pi → backend-test-analysis-contract-shell → generate-backend-functional-cases-pi → review-backend-cases-pi → review-backend-cases-gate-shell → generate-backend-pytest-pi → execute-backend-pytest-shell → test-retrospect-pi`。analysis gate 校验 Backend Test Analysis v1、任务源绑定与敏感值,并把规范化 JSON 保存到当前 run `contracts/backend-test-analysis.json`;失败时后续 writer 不启动。治理等级仍由既有 `minimal|standard|reviewed|supervised` 规则推断。
22
-
23
- ### DAG workflow 层级
24
-
25
- | 优先级 | 入口 | 使用场景 |
26
- |-------|-------|----------|
27
- | **Primary / Level 3** | `dag run-task --profile auto` / `dag init-hybrid`(已实现) | 从 task `source/` 自动生成 hybrid DAG;`--profile auto` 路由 standard / review-gated / supervised template;无 profile `run-task` 默认为 standard-compatible generate+validate only |
28
- | **Primary / Level 2** | `run-dag --dag <path>` | 跨 Pi + shell + static executor 执行 Agent DAG orchestration |
29
- 历史顺序式 `run analyze|plan|implement|verify|auto|loop|continue` 已移除。trivial one-line 修正时,记录的 main-session surgical patch 仍可能比建 DAG 更省,但它不是第二套 workflow runtime。
30
-
31
- **心智模型**:`run-dag` 是 loop-agent 内自编的 Agent DAG orchestration;受治理 Agent leaf executor 只有 Pi。`cursor-prompt` 是独立 sidecar,不是 DAG node executor。不要把 Cursor 重新引入 hybrid schema / `executorModels` / writer 选择。
32
-
33
- ### Level 2 Agent DAG hybrid(`run-dag`)
34
-
35
- ```bash
36
- cp examples/hybrid-loop-agent-dag.json <temp-dir>/hybrid-dag.json
37
- loop-agent dag validate --dag <temp-dir>/hybrid-dag.json # 常规 validation + ranks;无 dag-runs 副作用
38
- loop-agent dag validate --dag <temp-dir>/hybrid-dag.json --strict-models # 非 canonical executorModels 时也失败
39
- loop-agent dag validate --dag <temp-dir>/hybrid-dag.json --strict-governance # governance warning(如 read-only artifact drift)时失败
40
- loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --cwd <repo-root> # 执行 Pi/shell/static DAG
41
- loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --init-only --canvas-path <temp-dir>/hybrid-dag.canvas.tsx # 可选 derived Canvas
42
- ```
43
-
44
- `<temp-dir>` 表示平台原生临时目录;实际命令中 macOS 与 Windows 都使用本机路径。`/` 只作为 repo refs、JSON/Markdown evidence refs 和 glob 约定的稳定分隔符。
45
-
46
- 完整 schema 与语义:`docs/agent-dag-runner.md`。Workflow 概览:`docs/loop-agent-harness.md`。
47
-
48
- **v2 字段**(均可选;缺失时行为同 v1):
49
-
50
- - 顶层:`objective`、`successCriteria`、`globalConstraints`、`defaults`、`skillsByRole`、`executorModels`
51
- - 每 node:`role`、`skills`、`writePolicy`、`writeSet`、`piStep`、`shell`、`outputContract`、`executor`(`pi` | `shell` | `static`);Pi 写入节点额外声明 `toolProfile: "write"`;安全只读 Pi 节点可选声明 `retryPolicy`(生成器自动注入默认值)
52
-
53
- **Model 生成 DAG 的 template 卫生**:
54
-
55
- - 执行前将所有 `REPLACE/WITH/...` placeholder 换为具体 repo path。
56
- - 每个 task 应显式声明 `executor`;`defaults.executor` 仅 schema,非 runtime fallback。
57
- - 每个 task 应声明 `outputContract`;read-only node 应含 `forbiddenPaths`(至少 `[".harness/**", "artifacts/**"]`);exclusive write node 也应 forbid `artifacts/**`,除非 legacy root artifacts 显式在 `writeSet` 中并记录迁移计划。
58
- - 输出独立时优先 same-rank parallel read-only scout(`scout-src`、`scout-tests` 等),而非 serial scout chain。
59
- - 仅当 child 真正需要 upstream output 时加 `depends_on`;review 时质疑 single-chain topology。
60
- - `exclusive` implementer node 需 narrow、disjoint 的 `writeSet` path;勿用 `**` 或 repo root。
61
- - 固定 Pi-only DAG:`pi` read-only scouts/reviewers 与 `toolProfile: "write"` exclusive implementer(`implement-pi` / `repair-pi`)。
62
- - model routing 用 `executorModels`;勿用 `defaults.model` 或 legacy 顶层 `models`。
63
-
64
- **运维 warning**:
65
-
66
- - **常规 validation**:`dag validate --dag <path>` 做 schema/topology/ranks。JSON 输出含 `governanceProfile`(确定性 `minimal|standard|reviewed|supervised` 推断,含 `process` / `delivery` / `codeChange` signal 与 `reasons`),及 model-matrix drift、governance lint(如 read-only artifact-boundary drift 或 DAG 内 `check-repo.sh` shell env drift)的 warnings。手写临时 DAG spec 执行前用 `dag validate --dag <path> --strict-models`;governance warning 应 fail fast 时加 `--strict-governance`。含 `executor: "cursor"` 的旧 DAG 会在 schema 校验失败;默认生成 DAG 使用 `pi` read-only / Pi write profile / shell。仅当有意在 `.harness/dag-runs/active/` 要 active run snapshot 时用 `run-dag --dry-run`。
67
- - **Governance profile 推断与 routing(code vs skill 分工)**:`./src/workflows/dag/governance-profile.ts` 从 DAG 结构与 write scope 做 **硬确定性推断**。JSON 输出 **报告** `process` / `delivery` / `codeChange` signal 与人类可读 `reasons`;`profile` tier(`minimal|standard|reviewed|supervised`)仅由该模块 code rule 选择(如多个 exclusive writer、repair node、review-gate topology、`loop-agent-runtime-paths`、`scripts-ci-harness-paths`、weak post-implementation shell verification、supervised topology)。baseline `forbiddenPaths`(`.harness/**`、`.harness/dag-runs/**`、`artifacts/**`)是默认 governance,**本身不是** process-risk signal。skill prompt 与本 reference **解释** tier 并摘要 profile 选择原因;不替代 code 推断。`dag run-task` 转发 embedded validate step 的同一 candidate `governanceProfile`。`dag run-task --profile auto` 先将 candidate profile 经 `harness.json.workflowPolicy.dag.profileRouting` 映射,再在 candidate delivery signal 含 `loop-agent-runtime-paths`、`scripts-ci-harness-paths` 或 `public-contract-paths` 时应用 M4 `supervised-quality-gate` promotion;`profileRouting.routingReasons` 记录确定性 reason。无 profile `dag run-task <task-id>` 仍为 standard-compatible;显式 `--profile minimal|standard|reviewed|supervised` 选择治理路由的通用候选模板,默认 `standard` 前端任务可在非 supervised 候选上选择前端专用模板,但自动分类不得替换 supervised 候选。高风险 task 应用 `--profile auto` 或显式 `--profile supervised`,而非显式 `--profile reviewed`。
68
- - **Executor model routing**:DAG spec 选 `executor` 与 `complexity`,可通过 `executorModels.pi` 覆盖 model 名;不选 provider。默认 routing:Pi LOW=`gpt-5.3-codex-spark`、MED=`glm-5.2`、HIGH=`gpt-5.5`。`shell` 不用 model,忽略 `executorModels`。
69
- - **Active visibility**:真实 `run-dag` execution 在 run/node 转换时写 active `state.json`,归档前 core runner 暴露 isolated `DagRunObserver` hook 供 derived view。`.harness/dag-runs/completed/<run-id>/` / `paused/<run-id>/` 仍是 source of truth;observer 输出非 canonical。
70
- - **可选 Canvas**:传 `--canvas-path <abs-path>` 或 `--canvas <name>` 输出 derived `.canvas.tsx` live view。省略 flag 行为不变。`--init-only` + Canvas 无需 `CURSOR_API_KEY`。
71
-
72
- - **Shell node**:`executor: "shell"` 串行跑确定性 `shell.commands`,每 command 有 `timeoutMs`;非零 exit / timeout 标 node `ERROR` 并将 command output 归档到 node result 目录。用于 verification fact,非 code repair。
73
- - **Pi node**:`executor: "pi"` 默认仅用 read-only tool(当前 DAG Pi executor 中 `read`、`grep`、`find`、`ls`),返回 Markdown 结论供 downstream node。声明 `toolProfile: "write"` 后同一个 Pi executor 使用 writer tools 并在执行后跑 write guard;必须配合 `writePolicy=exclusive`、`allowedPaths`、`forbiddenPaths`、`writeSet`。
74
- - **Root `artifacts/` boundary**:root `artifacts/修改记录.md` 与 `artifacts/验证结果.md` 是 legacy / explicit-write 摘要,不是 Agent DAG read-only scratchpad,也不是新工作流默认 handoff。read-only DAG node 须在 node output 返回发现;runner-owned node artifacts 于 `.harness/dag-runs/<run-id>/` 是 per-run source of truth。
75
- - **Upstream output artifacts**:直接 `depends_on` 上游 stdout 超过 2000 字符时,runner 写 `<runDir>/<node-id>/stdout.md` 并在下游 `<upstream_context>` 提供 preview + artifact pointer map(绝对路径、`chars`、`sha256`)。下游 agent 可读 runner evidence,但 read-only node 仍不得编辑 `.harness/dag-runs/**`。
76
- - **`writePolicy=exclusive`** 要求非空 `writeSet`;same-rank exclusive node 的 `writeSet` 条目须 **disjoint**,否则 validation fail fast。v1 DAG 中声明 `writePolicy` 或 `writeSet` 任一即 opt-in write validation。
77
- - **`forbiddenPaths` 优先于 `allowedPaths`**(writeSet validation)。
78
- - **Pi rollback**:SDK path 损坏时在 `run-dag` 前 `export CODE_AGENT_PI_BACKEND=cli-only`。
79
- - **Defaults caveat**:`defaults.skills` / `defaults.writePolicy` 生效。对 `cursor` / `pi` node,resolved skill 名亦由 DAG runner 映射为有界 inline `SKILL.md` instruction,审计于 `<node>/skills.json`;Pi 仍以 `noSkills` / `--no-skills` 运行,故非 Pi ResourceLoader loading。`defaults.executor`、`defaults.model`、`defaults.piBackend`、`defaults.contextProfile` 接受/保留但尚非 runtime default。runtime execution 用 node `executor` + node `complexity`;各 executor 内部自选 model。live contract 已移除 `models`;executor-specific routing 用 `executorModels`。
80
- - **默认无**跨 node Pi runtime reuse;各 Pi node 是独立 `executePiStep()` call。
81
- - **Prompt source**:每个 task 仅用一种 prompt source。v1-compatible DAG 用 inline `subtask_prompt`;markdown-backed prompt 用 canonical `subtask_prompt_markdown`。同时提供两字段、皆不提供、或用连字符 alias `subtask_prompt-markdown` 均 fail fast。
82
- - **Source binding / recovery**:新生成 DAG 在顶层冻结 `sourceBinding`(任务源相对路径、SHA-256、显式 `REQ/BR/AC`)。前端计划在存在显式编号时经过 `frontend-requirement-coverage-shell`;缺号会在 final design review/writer 前 fail closed。中断后重新生成完整 DAG,不要从二手摘要拼接 impl-only DAG;v3 孤立 exclusive writer 若无 `sourceBinding` 且没有只读 planner 上游,会被 strict governance 拒绝。
83
- - **勿宣称 live smoke 已通过**,除非真实 `run-dag` execution 中 Pi read-only、Pi writer、显式 Cursor 或 shell node 均按 DAG 完成。
84
-
85
- 可复用 template:`docs/templates/agent-dag.base.json`(model 生成 DAG 的首选 base template)、`docs/templates/agent-dag.schema.json`(JSON Schema)、`docs/templates/agent-dag.supervised-implementation.json`(supervised implementation:writeSet audit、soft/hard verify、process supervisor、repair、review verdict gate)、`docs/templates/backend-test-dag.json`(后端测试专用模板)、`docs/templates/frontend-test-dag.json`(FE-test RAG:Markdown case manifest、串行 Playwright CLI case 子节点与逐 case 证据)、`docs/templates/agent-dag-process-supervisor.prompt.md`、`docs/templates/agent-dag-review-verdict.prompt.md`、`docs/templates/agent-dag-authority-surface-audit.prompt.md`(可选 authority surface verifier;authority signal 或显式 enablement 匹配时由 `dag init-hybrid` 插入)、`examples/hybrid-loop-agent-dag.json`、`docs/templates/hybrid-dag.json`。
86
-
87
- ### Supervised implementation flow(减少 main-session intervention)
88
-
89
- 长时 implementation 曾迫使 main session 中途 re-verify、re-review 或 surgical-patch 时,用 `docs/templates/agent-dag.supervised-implementation.json`。
90
-
91
- **此前 main session 介入原因**:linear hybrid DAG 缺少 in-run writeSet coverage auditsupervision 前归档的 soft verification、read-only process supervisor(`executor: pi`,`role: supervisor` — 非新 executor)、bounded repair exclusive writer、确定性 hard-verify shell fact,以及 fail-closed review verdict gate(除非 whitelist `VERDICT:` 行存在)。
92
-
93
- **Supervised topology**(执行前替换所有 `REPLACE/WITH/...` placeholder):
94
-
95
- ```text
96
- contract-pi → scout-src ∥ scout-tests → plan-pi → write-set-audit-pi
97
- → write-set-gate-shell → implement-pi → soft-verify-shell → process-supervisor-pi → process-gate-shell
98
- repair-pi → hard-verify-shell
99
- [authority-surface-audit-pi → authority-surface-gate-shell] # 可选
100
- review-pi → review-gate-shell → decision-pi → closeout-pi
101
- ```
102
-
103
- | Stage | 减少 main-session 工作的方式 |
104
- |-------|------------------------------|
105
- | `write-set-audit-pi` | implement 前捕获 missing/overlapping writeSet owner |
106
- | `write-set-gate-shell` | 除非 extracted audit verdict 行为 `VERDICT: pass`,否则 fail-closed block implement |
107
- | `soft-verify-shell` | supervision 前归档 focused test exit code |
108
- | `process-supervisor-pi` | read-only audit coverage、boundary drift、verify gap、repair scope;应 prominently 输出 `VERDICT: pass` `VERDICT: request-revision` |
109
- | `process-gate-shell` | supervisor node JSON 上 runtime `shell.verdictGate`(仅 `pass` 或 `request-revision`) |
110
- | `repair-pi` | supervisor 请求 revision 时在 repair `writeSet` 内 bounded exclusive fix |
111
- | `hard-verify-shell` | lint/typecheck + `HARNESS_ALLOW_ACTIVE_DAG_RUNS=1 check-repo.sh` fact |
112
- | `authority-surface-audit-pi` + `authority-surface-gate-shell` | 可选 permission/state/tool-exposure audit;仅 authority signal 或显式 `authority-surface-audit` marker 时插入;gate 仅接受 `VERDICT: pass` |
113
- | `review-pi` + `review-gate-shell` | Critical/Important `request-revision`;node JSON `shell.verdictGate` block,除非 extracted verdict 行为 `VERDICT: pass` |
114
-
115
- **Verdict gate contract(`shell.verdictGate`)**:声明 `fromNodeId`、`accept[]`、可选 `label`、可选 `lineMode`。runner 展开为一条 shell command,从 injected current run directory 读 `$HARNESS_DAG_RUN_DIR/<fromNodeId>.json`,对 extracted `assistantText ?? stdout` verdict line 与 `accept[]` exact-match。默认 `lineMode` `first-non-empty` 以兼容;supervised gate `first-verdict-line` 选 Pi 在 preamble 或常见整行 Markdown emphasis(如 `**VERDICT: pass**`)后第一条 normalized `VERDICT:` line。勿用 `result.summary.md`、grep VERDICT、latest-active-run discovery multi-command stateful gate。`--strict-governance` 对 anti-pattern fail。supervisor 仍为 `executor: pi` 上的 `role: supervisor`。
116
-
117
- **Repair artifact gate contract(`shell.repairArtifactGate`)**:声明 `fromNodeId`(supervisor artifact 节点)与 `repairNodeId`(承接修订的 Pi 修复节点)。runner **不再**按节点名(历史 `repair-cursor` / `repair-pi`)猜测 repair 节点:显式 `repairNodeId` 必须存在、直接 `depends_on` gate、且是受治理 Pi writer(`executor: pi`、`toolProfile: write`、`writePolicy: exclusive`、`allowedPaths`+`writeSet` 非空且 `writeSet` 不与 `forbiddenPaths` 冲突)。新生成的 supervised DAG 总是写入 `repairNodeId`;旧 DAG 缺失时只在能唯一、安全地推导出下游 Pi writer 时兼容,零个或多个候选、或候选不满足契约都在执行前 fail closed。validation 覆盖存在性、直接下游、writer 属性与路径边界。
118
-
119
- **Runtime contract 与 controller identity**:新生成的 DagSpec 使用 `version: 3`,并必须携带 `runtimeContract`(`schemaVersion` / `agentRuntime: "pi-only"` / `repairWriterProtocol: "explicit-node-v1"` / 可选 `minimumControllerVersion`)。v3 是旧 controller 无法忽略的解析边界;capability 与最低版本是新 controller 的执行前兼容门。`init-hybrid` 不硬编码 `minimumControllerVersion`,手写 spec 可按需 pin。每个新 run 必须解析并冻结 controller identity(package version、binary SHA-256、portable fingerprint)到 `controller-identity.json`;解析失败不创建 run。`dag report` 展示 identity 与 runtime-contract compatibility,resume 对漂移、篡改或 legacy-unpinned run 全部 fail closed;legacy run 仍可只读报告或显式 reconcile。
120
-
121
- Prompt invariant:`docs/templates/agent-dag-process-supervisor.prompt.md`、`docs/templates/agent-dag-review-verdict.prompt.md`、`docs/templates/agent-dag-authority-surface-audit.prompt.md`(启用时)。测试:`npx vitest run test/dag-supervised-template.test.ts test/authority-surface.test.ts`。完整叙述:`docs/agent-dag-runner.md` §「Why main-session interventions happened」。
122
-
123
- **未实现**:`executor: supervisor`、whole-run automatic retry/resume、`executor: human`/`decision`、browser executor,或 read-only node 对 root `artifacts/**` 的 exemption。注:有界只读 Pi 节点重试已实现(见下「只读 Pi 节点安全重试」)。
124
-
125
- ### Level 3 task-to-DAG(`dag init-hybrid` / `dag run-task`)
126
-
127
- ```bash
128
- loop-agent dag init-hybrid <task-id> [--output <temp-dir>/<task-id>-hybrid-dag.json]
129
- loop-agent dag run-task <task-id> [--output <temp-dir>/<task-id>-hybrid-dag.json] # 安全默认:仅 generate + validate,standard-compatible
130
- loop-agent dag run-task <task-id> --profile auto # 推断 candidate governanceProfile,再经 workflowPolicy 路由
131
- loop-agent dag run-task <task-id> --profile minimal # 选择 minimal 通用路由;standard 前端任务可自动使用前端 DAG
132
- loop-agent dag run-task <task-id> --profile standard # 选择 standard 通用路由;standard 前端任务可自动使用前端 DAG
133
- loop-agent dag run-task <task-id> --profile reviewed # 选择 reviewed 通用路由;standard 前端任务可自动使用前端 DAG
134
- loop-agent dag run-task <task-id> --profile supervised # 选择 supervised DAG;自动前端分类不会降级它
135
- loop-agent dag run-task <task-id> --strict-models # canonical executorModels 时失败
136
- loop-agent dag run-task <task-id> --execute --cwd <repo-root> # 要求 narrowed implement writeSet
137
- loop-agent dag run-task <task-id> --dry-run --cwd <repo-root> # active snapshot .harness/dag-runs/active/
138
- loop-agent dag run-task <task-id> --init-only --cwd <repo-root> # pending active snapshot,不执行 node
139
- ```
140
-
141
- 默认 `dag run-task` **不**创建 `.harness/dag-runs/**`。placeholder / `**` implement writeSet 会 block `--execute`、`--init-only`、`--dry-run`,直到人工 review narrow path。
142
-
143
- `dag run-task` JSON 输出含确定性 `reviewPacket` 供执行前 review。derived 自 generated DAG JSON、embedded validate summary、`profileRouting`;不调用 LLM,不写 completed run facts。`run-dag` 前用它 inspect `profileRouting`、`governanceProfile`、exclusive writer `writeSet`、`broadWriteSetRisk`、`forbiddenOverlapRisk`、`shellGates`(含 `lineMode`)、`shellVerification` / `expectedVerification`、`decisionGates` mode。
144
-
145
- ### DAG 与 artifacts source-of-truth 规则
146
-
147
- - 临时 DAG input spec 放平台原生临时目录(例如 `<temp-dir>/<topic>-dag.json`);可复用 template 放 `examples/` 或 `docs/templates/`。
148
- - **不要**在 `.harness/dag-runs/active/` root 保留手写 DAG input 副本。
149
- - **不要**把 `.harness/dag-runs/` 内容 commit 到 git。
150
- - canonical per-run DAG 历史是 `.harness/dag-runs/completed/<run-id>/run.json` 及该 run 目录的 `state.json`、`executor.jsonl`、node artifacts;新建 run directory 使用 `YYYYMMDD-<slug>`。
151
- - root `artifacts/修改记录.md` 与 `artifacts/验证结果.md` 是 legacy current-work / explicit-write 摘要。不是 per-run 不可变历史,也不是新工作流默认交付路径。
152
- - Agent DAG read-only node 不得写 root `artifacts/`;若须更新 root artifacts,用显式 `exclusive` write node 或记录了理由、验证与迁移计划的 main-session surgical patch。
153
- - DAG Cursor 节点交付物必须写入 `.harness/dag-runs/<state>/<run-id>/artifacts/<node-id>/`;`./artifacts/**` 是错误落点。
154
- - 长期结论须迁入 `docs/exec-plans/`、`docs/reports/` `docs/progress/`。从 completed run evidence 汇总 task artifacts 时用 `promote-run <task-id> --run-id <run-id>`;再用 `closeout task <task-id>` 生成 progress。二者 deterministic,且不 mutate completed run facts
155
-
156
- **DAG author 的 artifact-boundary 提醒**:大量 *讨论* root `artifacts/**` 的 task 仍遵守同一 write guard — read-only node 仅在 node output 返回发现;exclusive node 保持 `artifacts/**` 在 `forbiddenPaths`,除非 concrete path 在 `writeSet`。不要在 declared writeSet 外 instruct implementer 写 `artifacts/修改记录.md` `artifacts/验证结果.md`(P3 boundary-risk practice)。scout 在链接 skill reference 中发现 stale wording 时,把那些 path 纳入 implementer writeSet,或接受记录的 main-session patch(P2 教训:`hybrid-dag.md` 被 scout 发现但 initial writeSet 遗漏)。
157
-
158
- ### Decision Gate(M3–M5 runtime)
159
-
160
- Pi reviewer node 设 `decisionGate.enabled: true` 时,runner 从 persisted `assistantText`(优先)或 `result.summary.md`(fallback)解析 **恰好一个** info string 为 `DECISION_ENVELOPE_JSON` 的 fenced block。Schema:`docs/templates/agent-dag-decision-envelope.schema.json`。Prompt:`docs/templates/agent-dag-decision-gate.prompt.md`(含 §Recovery Recommendation Consumption 与 schema-adherence 硬规则:勿发明 envelope schema、勿用 `decision: accept`、勿加 extra root key、`audit.runId` 须绑定当前 run id,并填 `audit.nodeId` / `audit.model`)。Playbook:`docs/agent-dag-recovery-playbook.md`。示例 DAG:`examples/decision-gate-agent-dag.json`。
161
-
162
- | Milestone | `decisionGate.mode` | 行为 |
163
- |-----------|---------------------|----------|
164
- | **M3 record-only** | `record-only`(默认) | 写 `<node-id>/decision.envelope.json` + node record summary;**不 pause**,**不** branch 于 `decision`/`nextAction` |
165
- | **M4 pause-on-human** | `pause-on-human` | parse OK `requiresHuman=true`:run `status=paused`,移入 `.harness/dag-runs/paused/<run-id>/`,写 `human-escalation.json` / `.md`;downstream node 保持 `PENDING` |
166
- | **M5 CLI** | (M4 pause 后) | 确定性 human decision — **无 LLM**,**无** `executor: human` / `executor: decision` |
167
-
168
- ```bash
169
- loop-agent dag doctor
170
- loop-agent dag status --run-id <run-id>
171
- loop-agent dag report --paused-latest [--json|--markdown] # 最新 paused run;勿与 --lifecycle 并用
172
- loop-agent dag report [--run-id <run-id>] [--lifecycle active|paused|completed|all] [--json|--markdown] [--failed-only] [--latest] [--action <recovery-action>] # derived per-node report(只读);JSON schema: docs/templates/agent-dag-report.schema.json;仅 advisory — 见 docs/agent-dag-recovery-playbook.md
173
- loop-agent dag closeout-draft [--run-id <run-id>] [--output <path>] # M5:从 completed run facts 生成确定性 closeout draft;默认平台临时目录;仅 advisory;不 mutate completed facts
174
- loop-agent promote-run <task-id> --run-id <run-id> # 从 completed DAG/one-shot evidence 汇总 task artifacts;不 mutate completed facts
175
- loop-agent closeout task <task-id> # 从 task artifacts 生成 docs/progress closeout
176
- loop-agent dag reconcile-tasks --glob '<pattern>' [--json|--markdown] # 仅报告的 task/run/artifact/verify drift audit
177
- loop-agent dag final-verification <task-id> [--output <path>] # 生成 closeout DAG;final verify 依赖 closeout artifact
178
- loop-agent dag decision inspect --run-id <run-id> [--node-id <node-id>]
179
- loop-agent dag decision validate --run-id <run-id> [--node-id <node-id>]
180
- loop-agent dag approve --run-id <run-id> --option <id> [--notes "..."]
181
- loop-agent dag reject --run-id <run-id> --reason "..."
182
- loop-agent dag resume --run-id <run-id> # approve 后继续
183
- ```
184
-
185
- **Paused operator flow**:`run-dag` → `paused/` →(`dag status` / 可选 `dag decision validate`)→ `dag approve` `active/` `dag resume` → `completed/`;或 `dag reject` → `completed/`(`failed`,`failureCategory=human-rejected`)。
186
-
187
- **Stale active detection**:`dag doctor` 标 health code 如 `terminal-in-active`(`active/` 保留 terminal run);仅 advisory — 按 playbook 手动 archive/remove,尚无 auto cleanup CLI。
188
-
189
- **Deferred**:`browser` executor;`dag recover apply`;勿在 DAG JSON 加 `executor: human` 或 `executor: decision`。
190
-
191
- **In-flight DAG run 期间的 governance**:live run 内 shell verify node 须用 `HARNESS_ALLOW_ACTIVE_DAG_RUNS=1 bash scripts/check-repo.sh`。run 归档到 `completed/` 后,在 DAG 外跑裸 `bash scripts/check-repo.sh`。
192
-
193
- ### 只读 Pi 节点安全重试(read-only retry)
194
-
195
- planner/scout/reviewer/verifier/closeout 角色的安全只读 Pi 节点可声明 `retryPolicy`,在同一 run 内有界重试模型连接中断、provider 限流、临时不可用或请求 timeout。生成模板自动注入默认策略(总尝试 3 次,手工配置最多 5 次,指数退避,单次等待上限 30s)。supervisor 与 implementer 明确不重试。
196
-
197
- - 仅重试原始分类:`timeout`、`network`、`rate-limit`、`unavailable`。`quota` **不**是 rate limit,不重试;`auth`、`invalid-output`、`write-guard`、`decision-envelope` 与未知失败同样不重试。
198
- - 资格由确定性 helper 判断,executor 内不硬编码循环;仅 `writePolicy=read-only|none`(或 Pi 默认只读)的上述角色可用。supervisor / implementer / writer / docs-only / dynamic / shell / static / decision-gate 节点声明 `retryPolicy` 会在 DAG validation 阶段失败。
199
- - 每次 attempt 写入独立不可变证据 `<node-id>/attempt-<n>.json`(run-relative path),最终 node record `attempts` 字段引用完整历史;后一次成功不覆盖前一次失败证据。
200
- - 重试复用同一 run、controller identity、skill snapshot、prompt、model 与上游输入;退避等待刷新 `lastActivityAt` 避免误判 node-quiet。
201
- - 节点终态聚合全部 attempts 的耗时、Token 与事件数;当前 backoff 等待会占用该节点的并发槽。
202
- - 未声明 `retryPolicy` 的历史 DAG 行为不变(单次执行,不新增 attempt artifact)。
203
-
204
- 实现:`src/workflows/dag/retry-policy.ts`、`node-execution.ts`、`validate.ts`。测试:`npx vitest run test/dag-node-retry.test.ts test/dag-validate.test.ts test/dag-init-hybrid.test.ts`。
205
-
206
- ### Evidence summary guidance(practice convention 非 runtime)
207
-
208
- review-heavy DAG 中长 shell stdout 可能掩盖 proof 时,用 **evidence-summary-shell** 作为 authoring pattern。**不是** runtime executor、schema field 或 parser。
209
-
210
- - soft/hard verify shell node 之后,prompt downstream **read-only** Pi reviewer(`reviewer`、`supervisor`、`closeout`)在 node output 开头用紧凑 `EVIDENCE:` 行(`EVIDENCE: <check> exit=<code> (<one-line fact>)`),再写 prose findings。
211
- - 与现有 **`shell.verdictGate`** 配对做 fail-closed gate:`VERDICT: pass` 或 `VERDICT: request-revision` 仍是 machine-readable decision;supervised gate 用 `lineMode: "first-verdict-line"`,`EVIDENCE:` 行供扫描事实,不能替代 verdict line。
212
- - shell node exit code 与 archived command output 为 authoritative;`EVIDENCE:` 摘要供 human/decision-gate 扫描速度,不替代 deterministic shell verification。
213
- - **不要**期望 runner enforce、parse validate `EVIDENCE:` 格式;**不要**在 `shell.verdictGate` shell exit code 已够用时手写 shell grep `EVIDENCE:`。
214
- - read-only node 不得写 root `artifacts/**`;compact evidence 属于 `.harness/dag-runs/<run-id>/` 下归档的 node output。
215
-
216
- 完整叙述:`docs/agent-dag-runner.md` §「Evidence Summary as a Practice Convention」。P1 calibration report:`docs/reports/2026-06-08-agent-dag-practice-p1-evidence-summary-docs.md`。
217
-
218
- ### Authoring checklist(P1–P5 practice guidance runtime 行为)
219
-
220
- > 与 `docs/agent-dag-runner.md` §「Agent DAG authoring checklist」相同。Calibration reports:`docs/reports/2026-06-08-agent-dag-practice-p1-evidence-summary-docs.md` … `p5-handoff-closeout-20260608.md`。
221
-
222
- | # | Check | Expect |
223
- |---|-------|--------|
224
- | 1 | Topology | 优先 same-rank parallel read-only scout/review;仅 output 真正需要时加 `depends_on` |
225
- | 2 | Executor | 每个 task 显式声明 `executor`;`defaults.executor` schema metadata,非 runtime fallback |
226
- | 3 | Model routing | 用 node `complexity` + `executorModels`;Pi MED(`glm-5.2`)quota 耗尽时提高 Pi node 到 `complexity: HIGH`(`gpt-5.5`)— 勿 mutate canonical model matrix |
227
- | 4 | Read-only output | read-only / Pi node 在 **node output** 返回发现;runner 归档于 `.harness/dag-runs/<run-id>/<node-id>/` |
228
- | 5 | Root `artifacts/**` | 非 read-only handoff target;持久记录去 `docs/reports/`、`docs/progress/`,或 narrow exclusive `writeSet` 写 legacy 摘要并记录迁移计划 |
229
- | 6 | DAG Cursor artifacts | 写入 `.harness/dag-runs/<state>/<run-id>/artifacts/<node-id>/`;不得写入 `./artifacts/**` |
230
- | 7 | Completed facts | `.harness/dag-runs/completed/**` 仅可读 evidence 归档后永不 mutate 历史 run 目录、`run.json`、`state.json` 或 `artifacts/**` |
231
- | 8 | Verdict gate | review/supervisor 应以 `VERDICT: pass` `VERDICT: request-revision` 开头以利阅读;用 current-run `<fromNodeId>.json`(`$HARNESS_DAG_RUN_DIR`)上 `shell.verdictGate` block,exact-match `accept[]`;默认 `lineMode=first-non-empty`,supervised template `first-verdict-line` 容忍 preamble 或第一条 normalized `VERDICT:` 前的常见整行 Markdown emphasis |
232
- | 9 | Decision Gate | 恰好 emit 一个 `DECISION_ENVELOPE_JSON` block;`audit.runId` 须绑定 **当前** run id;禁止 `decision: accept`、发明 schema、extra root key;填 `audit.nodeId` / `audit.model` |
233
- | 10 | writeSet planning | scout 应列出链接的 `./skill/references/**` **writeSet expansion candidates**(P2:遗漏链接 skill ref 迫使 main-session patch) |
234
- | 11 | Evidence summary | `evidence-summary-shell` / leading `EVIDENCE:` 行是 **practice convention**,非 runtime executor、schema field 或 parser |
235
- | 12 | Featureization | 除非 repeated real-run failure 证明 checklist guidance 不够,勿加 runtime/schema/validator/CLI/executor feature |
236
- | 13 | writeSet / writer backend | `exclusive` nodenarrow、disjoint path;无 `**`;固定用 Pi write profile |
237
- | 14 | Placeholders | 执行前将 `REPLACE/WITH/...` 换为具体 path |
238
- | 15 | Governance | in-flight shell:`HARNESS_ALLOW_ACTIVE_DAG_RUNS=1 bash scripts/check-repo.sh`;archive 后:裸 `bash scripts/check-repo.sh` |
1
+ # Agent DAG Hybrid Workflow(`run-dag` / `dag init-hybrid`)
2
+
3
+ 创建或执行 loop-agent 工作的首选 Agent DAG path 时使用本文:Level 2 Agent DAG orchestration、Pi read-only + Pi `toolProfile: "write"` bounded execution、Pi-only writers、write policy、DAG template、task-to-DAG 生成,或基于 governance-profile 的 template 选择。
4
+
5
+ ### DAG workflow 优先级
6
+
7
+ `harness.json.workflowPolicy` 现声明 Agent DAG 为首选 implementation workflow:
8
+
9
+ - `defaultImplementationWorkflow=agent-dag`
10
+ - `dag.defaultEntry=dag run-task`
11
+ - `dag.outputLanguage=zh-CN`;未配置时也默认中文,显式设为 `en` 可切换英文
12
+ - `dag.profileRouting`:通用候选映射为 `minimal|standard -> standard-dag`、`reviewed -> review-gated-dag`、`supervised -> supervised-implementation`
13
+ - `humanGatePolicy.defaultMode=record-only`;需求不清、架构/公共契约风险、凭据/费用/部署风险、重复 gate failure 或高风险决策时升级人工介入
14
+
15
+ 此 policy 驱动 `dag run-task --profile auto`:CLI 仍要求显式 `dag run-task`、`dag validate`、`run-dag`,但 `--profile auto` 在确定性 candidate `governanceProfile` 推断后应用 `workflowPolicy.dag.profileRouting`。生成器还会把 `outputLanguage` 写入 DagSpec,runner 在每个 Pi/Cursor 节点 prompt 中注入语言规则;代码、命令、路径、JSON 字段与 gate token 保持原样。`humanGatePolicy` 是默认人机边界声明;真实暂停仍由 DAG 节点的 `decisionGate.mode: "pause-on-human"` 与 decision envelope 触发。无 profile 的 `dag run-task <task-id>` 仍为 standard-compatible,供 legacy/review workflow。
16
+
17
+ 对于默认 `standard` 任务,生成器根据标题、`source/需求.md` 和结构化 `allowedPaths` 做保守、确定性的需求分类。只有高置信的前端实现需求自动选择 `frontend-implementation` DAG;后端、前后端混合、明确排除前端或证据不足的需求继续使用 governance profile 选出的模板。分类不会把普通后端实现路由到 `backend-test`,也不会替换由显式 profile、`workflowPolicy` 或 supervised quality gate 选中的 supervised 模板。
18
+
19
+ 前端专用链在 `frontend-scout-pi` 后加入只读 `frontend-mock-assess-pi` 和确定性 contract gate,根据接口契约、后端就绪度、生成期能力 seed 与固化验证入口选择 `native|browser-intercept|request-adapter|not-needed|blocked`。策略直接传给 plan、两阶段 design review、唯一 writer、实现 review 和 closeout;真实请求保持默认,缺少契约、生产隔离或可执行验证时 gate 阻塞。可选 `frontendMock` 配置声明 `auto|required|disabled`、既有服务目录与专项命令;不安全或不完整的显式 required 合同只生成无 writer 的评估链,有可信命令时才增加 `frontend-mock-verify-shell`。Mock-backed 证据只证明前端状态;`not-needed` 需要真实或无远程接口行为证据。未调用后端时 closeout 报告 `Frontend status: mock-validated` 与 `Real integration: pending`。
20
+
21
+ 显式专用 `taskKind` 保持兼容并优先于任务源分类,也不扩充 governance profile:`frontend-implementation` 显式选择前端实现 DAG,`frontend-test` 选择 FE-test RAG DAG,`backend-test` 选择后端测试 DAG,`knowledge-sync` 选择 Feature 测试知识回写 DAG,`knowledge-graph-bootstrap` 选择业务知识图谱开荒/增量 DAG。后端测试链为 `analyze-inputs-pi → backend-test-analysis-contract-shell → backend-test-environment-scout-pi → backend-test-execution-contract-shell → generate-backend-functional-cases-pi → emit-backend-case-manifest-pi → backend-test-case-manifest-shell → review-backend-cases-pi → review-backend-cases-gate-shell → generate-backend-pytest-pi → backend-test-traceability-gate-shell → execute-backend-pytest-shell → parse-backend-test-result-shell → classify-backend-test-result-pi → test-retrospect-pi → backend-test-outcome-gate-shell`。analysis/execution/case-manifest gate 写入 run-owned contracts;parse materialize Backend Test Result v1(`contracts/backend-test-result.json`)。Case Manifest 确定性校验 AC→case 覆盖;traceability gate 校验 generated file/symbol。execute 在非空 JUnit 下将 pytest exit 0/1 视为节点成功以便 always-run retrospect;`backend-test-outcome-gate-shell` 以 result.outcome 收口;retrospect 使用 manifest coverageSummary + Result v1,不得自造 coverage%。`evidenceGaps`、未知 framework、secret 值、路径穿越或 preflight 失败时后续 writer/execute 不启动。`knowledge-sync` 链必须绑定 `featureId`;图谱运维公共入口是 `loop-agent knowledge query|graph-init|graph-materialize|graph-promote|graph-incremental-prepare`。治理等级仍由既有 `minimal|standard|reviewed|supervised` 规则推断。
22
+
23
+ ### DAG workflow 层级
24
+
25
+ | 优先级 | 入口 | 使用场景 |
26
+ |-------|-------|----------|
27
+ | **Primary / Level 3** | `dag run-task --profile auto` / `dag init-hybrid`(已实现) | 从 task `source/` 自动生成 hybrid DAG;`--profile auto` 路由 standard / review-gated / supervised template;无 profile `run-task` 默认为 standard-compatible generate+validate only |
28
+ | **Primary / Level 2** | `run-dag --dag <path>` | 跨 Pi + shell + static executor 执行 Agent DAG orchestration |
29
+ 历史顺序式 `run analyze|plan|implement|verify|auto|loop|continue` 已移除。trivial one-line 修正时,记录的 main-session surgical patch 仍可能比建 DAG 更省,但它不是第二套 workflow runtime。
30
+
31
+ **心智模型**:`run-dag` 是 loop-agent 内自编的 Agent DAG orchestration;受治理 Agent leaf executor 只有 Pi。`cursor-prompt` 是独立 sidecar,不是 DAG node executor。不要把 Cursor 重新引入 hybrid schema / `executorModels` / writer 选择。
32
+
33
+ ### Level 2 Agent DAG hybrid(`run-dag`)
34
+
35
+ ```bash
36
+ cp examples/hybrid-loop-agent-dag.json <temp-dir>/hybrid-dag.json
37
+ loop-agent dag validate --dag <temp-dir>/hybrid-dag.json # 常规 validation + ranks;无 dag-runs 副作用
38
+ loop-agent dag validate --dag <temp-dir>/hybrid-dag.json --strict-models # 非 canonical executorModels 时也失败
39
+ loop-agent dag validate --dag <temp-dir>/hybrid-dag.json --strict-governance # governance warning(如 read-only artifact drift)时失败
40
+ loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --cwd <repo-root> # 执行 Pi/shell/static DAG
41
+ loop-agent run-dag --dag <temp-dir>/hybrid-dag.json --init-only --canvas-path <temp-dir>/hybrid-dag.canvas.tsx # 可选 derived Canvas
42
+ ```
43
+
44
+ `<temp-dir>` 表示平台原生临时目录;实际命令中 macOS 与 Windows 都使用本机路径。`/` 只作为 repo refs、JSON/Markdown evidence refs 和 glob 约定的稳定分隔符。
45
+
46
+ 完整 schema 与语义:`ai_workspace/loop-agent/agent-dag-runner.md`。Workflow 概览:`ai_workspace/loop-agent/loop-agent-harness.md`。
47
+
48
+ **v2 字段**(均可选;缺失时行为同 v1):
49
+
50
+ - 顶层:`objective`、`successCriteria`、`globalConstraints`、`defaults`、`skillsByRole`、`executorModels`
51
+ - 每 node:`role`、`skills`、`writePolicy`、`writeSet`、`piStep`、`shell`、`outputContract`、`executor`(`pi` | `shell` | `static`);Pi 写入节点额外声明 `toolProfile: "write"`;安全只读 Pi 节点可选声明 `retryPolicy`(生成器自动注入默认值)
52
+
53
+ **Model 生成 DAG 的 template 卫生**:
54
+
55
+ - 执行前将所有 `REPLACE/WITH/...` placeholder 换为具体 repo path。
56
+ - 每个 task 应显式声明 `executor`;`defaults.executor` 仅 schema,非 runtime fallback。
57
+ - 每个 task 应声明 `outputContract`;read-only node 应含 `forbiddenPaths`(至少 `[".harness/**", "artifacts/**"]`);exclusive write node 也应 forbid `artifacts/**`,除非 legacy root artifacts 显式在 `writeSet` 中并记录迁移计划。
58
+ - 输出独立时优先 same-rank parallel read-only scout(`scout-src`、`scout-tests` 等),而非 serial scout chain。
59
+ - 仅当 child 真正需要 upstream output 时加 `depends_on`;review 时质疑 single-chain topology。
60
+ - `exclusive` implementer node 需 narrow、disjoint 的 `writeSet` path;勿用 `**` 或 repo root。
61
+ - 固定 Pi-only DAG:`pi` read-only scouts/reviewers 与 `toolProfile: "write"` exclusive implementer(`implement-pi` / `repair-pi`)。
62
+ - model routing 用 `executorModels`;勿用 `defaults.model` 或 legacy 顶层 `models`。
63
+
64
+ **运维 warning**:
65
+
66
+ - **常规 validation**:`dag validate --dag <path>` 做 schema/topology/ranks。JSON 输出含 `governanceProfile`(确定性 `minimal|standard|reviewed|supervised` 推断,含 `process` / `delivery` / `codeChange` signal 与 `reasons`),及 model-matrix drift、governance lint(如 read-only artifact-boundary drift 或 DAG 内 `check-repo.sh` shell env drift)的 warnings。手写临时 DAG spec 执行前用 `dag validate --dag <path> --strict-models`;governance warning 应 fail fast 时加 `--strict-governance`。含 `executor: "cursor"` 的旧 DAG 会在 schema 校验失败;默认生成 DAG 使用 `pi` read-only / Pi write profile / shell。仅当有意在 `.harness/dag-runs/active/` 要 active run snapshot 时用 `run-dag --dry-run`。
67
+ - **Governance profile 推断与 routing(code vs skill 分工)**:`./src/workflows/dag/governance-profile.ts` 从 DAG 结构与 write scope 做 **硬确定性推断**。JSON 输出 **报告** `process` / `delivery` / `codeChange` signal 与人类可读 `reasons`;`profile` tier(`minimal|standard|reviewed|supervised`)仅由该模块 code rule 选择(如多个 exclusive writer、repair node、review-gate topology、`loop-agent-runtime-paths`、`scripts-ci-harness-paths`、weak post-implementation shell verification、supervised topology)。baseline `forbiddenPaths`(`.harness/**`、`.harness/dag-runs/**`、`artifacts/**`)是默认 governance,**本身不是** process-risk signal。skill prompt 与本 reference **解释** tier 并摘要 profile 选择原因;不替代 code 推断。`dag run-task` 转发 embedded validate step 的同一 candidate `governanceProfile`。`dag run-task --profile auto` 先将 candidate profile 经 `harness.json.workflowPolicy.dag.profileRouting` 映射,再在 candidate delivery signal 含 `loop-agent-runtime-paths`、`scripts-ci-harness-paths` 或 `public-contract-paths` 时应用 M4 `supervised-quality-gate` promotion;`profileRouting.routingReasons` 记录确定性 reason。无 profile `dag run-task <task-id>` 仍为 standard-compatible;显式 `--profile minimal|standard|reviewed|supervised` 选择治理路由的通用候选模板,默认 `standard` 前端任务可在非 supervised 候选上选择前端专用模板,但自动分类不得替换 supervised 候选。高风险 task 应用 `--profile auto` 或显式 `--profile supervised`,而非显式 `--profile reviewed`。
68
+ - **Executor model routing**:DAG spec 选 `executor` 与 `complexity`,可通过 `executorModels.pi` 覆盖 model 名;不选 provider。默认 routing:Pi LOW=`gpt-5.3-codex-spark`、MED=`glm-5.2`、HIGH=`gpt-5.5`。`shell` 不用 model,忽略 `executorModels`。
69
+ - **Active visibility**:真实 `run-dag` execution 在 run/node 转换时写 active `state.json`,归档前 core runner 暴露 isolated `DagRunObserver` hook 供 derived view。`.harness/dag-runs/completed/<run-id>/` / `paused/<run-id>/` 仍是 source of truth;observer 输出非 canonical。
70
+ - **可选 Canvas**:传 `--canvas-path <abs-path>` 或 `--canvas <name>` 输出 derived `.canvas.tsx` live view。省略 flag 行为不变。`--init-only` + Canvas 无需 `CURSOR_API_KEY`。
71
+
72
+ - **Shell node**:`executor: "shell"` 串行跑确定性 `shell.commands`,每 command 有 `timeoutMs`;非零 exit / timeout 标 node `ERROR` 并将 command output 归档到 node result 目录。用于 verification fact,非 code repair。
73
+ - **Pi node**:`executor: "pi"` 默认仅用 read-only tool(当前 DAG Pi executor 中 `read`、`grep`、`find`、`ls`),返回 Markdown 结论供 downstream node。声明 `toolProfile: "write"` 后同一个 Pi executor 使用 writer tools 并在执行后跑 write guard;必须配合 `writePolicy=exclusive`、`allowedPaths`、`forbiddenPaths`、`writeSet`。
74
+ - **Root `artifacts/` boundary**:root `artifacts/修改记录.md` 与 `artifacts/验证结果.md` 是 legacy / explicit-write 摘要,不是 Agent DAG read-only scratchpad,也不是新工作流默认 handoff。read-only DAG node 须在 node output 返回发现;runner-owned node artifacts 于 `.harness/dag-runs/<run-id>/` 是 per-run source of truth。
75
+ - **Upstream output artifacts**:直接 `depends_on` 上游 stdout 超过 2000 字符时,runner 写 `<runDir>/<node-id>/stdout.md` 并在下游 `<upstream_context>` 提供 preview + artifact pointer map(绝对路径、`chars`、`sha256`)。下游 agent 可读 runner evidence,但 read-only node 仍不得编辑 `.harness/dag-runs/**`。
76
+ - **`writePolicy=exclusive`** 要求非空 `writeSet`;same-rank exclusive node 的 `writeSet` 条目须 **disjoint**,否则 validation fail fast。v1 DAG 中声明 `writePolicy` 或 `writeSet` 任一即 opt-in write validation。
77
+ - **`forbiddenPaths` 优先于 `allowedPaths`**(writeSet validation)。
78
+ - **Pi rollback**:SDK path 损坏时在 `run-dag` 前 `export CODE_AGENT_PI_BACKEND=cli-only`。
79
+ - **Defaults caveat**:`defaults.skills` / `defaults.writePolicy` 生效。对 `cursor` / `pi` node,resolved skill 名亦由 DAG runner 映射为有界 inline `SKILL.md` instruction,审计于 `<node>/skills.json`;Pi 仍以 `noSkills` / `--no-skills` 运行,故非 Pi ResourceLoader loading。`defaults.executor`、`defaults.model`、`defaults.piBackend`、`defaults.contextProfile` 接受/保留但尚非 runtime default。runtime execution 用 node `executor` + node `complexity`;各 executor 内部自选 model。live contract 已移除 `models`;executor-specific routing 用 `executorModels`。
80
+ - **默认无**跨 node Pi runtime reuse;各 Pi node 是独立 `executePiStep()` call。
81
+ - **Prompt source**:每个 task 仅用一种 prompt source。v1-compatible DAG 用 inline `subtask_prompt`;markdown-backed prompt 用 canonical `subtask_prompt_markdown`。同时提供两字段、皆不提供、或用连字符 alias `subtask_prompt-markdown` 均 fail fast。
82
+ - **Source binding / recovery**:新生成 DAG 在顶层冻结 `sourceBinding`(任务源相对路径、SHA-256、显式 `REQ/BR/AC`)。前端计划在存在显式编号时经过 `frontend-requirement-coverage-shell`;缺号会在 final design review/writer 前 fail closed。中断后重新生成完整 DAG,不要从二手摘要拼接 impl-only DAG;v3 孤立 exclusive writer 若无 `sourceBinding` 且没有只读 planner 上游,会被 strict governance 拒绝。
83
+ - **勿宣称 live smoke 已通过**,除非真实 `run-dag` execution 中 Pi read-only、Pi writer、显式 Cursor 或 shell node 均按 DAG 完成。
84
+
85
+ 可复用 template:`docs/templates/agent-dag.base.json`(model 生成 DAG 的首选 base template)、`docs/templates/agent-dag.schema.json`(JSON Schema)、`docs/templates/agent-dag.supervised-implementation.json`(supervised implementation:writeSet audit、soft/hard verify、process supervisor、repair、review verdict gate)、`docs/templates/backend-test-dag.json`(后端测试专用模板)、`docs/templates/frontend-test-dag.json`(FE-test RAG:Markdown case manifest、串行 Playwright CLI case 子节点与逐 case 证据)、`docs/templates/agent-dag-process-supervisor.prompt.md`、`docs/templates/agent-dag-review-verdict.prompt.md`、`docs/templates/agent-dag-authority-surface-audit.prompt.md`(可选 authority surface verifier;authority signal 或显式 enablement 匹配时由 `dag init-hybrid` 插入)、`examples/hybrid-loop-agent-dag.json`、`docs/templates/hybrid-dag.json`。
86
+
87
+ ### Supervised implementation flow(减少 main-session intervention)
88
+
89
+ 长时 implementation 曾迫使 main session 中途 re-verify、re-review 或 surgical-patch 时,用 `ai_workspace/loop-agent/templates/agent-dag.supervised-implementation.json`。
90
+
91
+ **此前 main session 介入原因**:linear hybrid DAG 缺少 in-run writeSet coverage audit;旧 supervised write-set gate 在初审返回 `request-revision` 或遗漏 `VERDICT:` 时也会直接 `partial_failed`,需要人工新建下一轮 run。此外还缺少 supervision 前归档的 soft verification、read-only process supervisor(`executor: pi`,`role: supervisor` — 非新 executor)、bounded repair exclusive writer、确定性 hard-verify shell fact,以及 fail-closed review verdict gate(除非 whitelist `VERDICT:` 行存在)。
92
+
93
+ **Supervised topology**(执行前替换所有 `REPLACE/WITH/...` placeholder):
94
+
95
+ ```text
96
+ contract-pi → scout-src ∥ scout-tests → plan-pi → write-set-audit-pi
97
+ → write-set-audit-format-repair-pi → write-set-format-gate-shell
98
+ plan-revision-pi → final-write-set-audit-pi → final-write-set-audit-format-repair-pi
99
+ write-set-gate-shell → implement-pi → soft-verify-shell → process-supervisor-pi → process-gate-shell
100
+ repair-pi → hard-verify-shell
101
+ → [authority-surface-audit-pi → authority-surface-gate-shell] # 可选
102
+ → review-pi → review-gate-shell → decision-pi → closeout-pi
103
+ ```
104
+
105
+ | Stage | 减少 main-session 工作的方式 |
106
+ |-------|------------------------------|
107
+ | `write-set-audit-pi` | implement 前捕获 missing/overlapping writeSet owner;第一条非空行必须是 canonical verdict |
108
+ | `write-set-audit-format-repair-pi` / `final-write-set-audit-format-repair-pi` | 初审和终审各有一次只读格式恢复;只补 canonical verdict/结构并保留 findings,结论不明确时返回 `request-revision`,不得从一般正文猜 pass |
109
+ | `write-set-format-gate-shell` | 接受格式有效的 pass/request-revision,让有界计划修订继续;本 gate 不授权写入 |
110
+ | `plan-revision-pi` | 最多一轮只读计划修订;初审 pass 时输出 `PASS_NO_REVISION_NEEDED`,request-revision 时解决全部 findings;不得扩大 task `allowedPaths` |
111
+ | `final-write-set-audit-pi` + `write-set-gate-shell` | 终审复核有效计划;只有规范化后的最终 `VERDICT: pass` 授权 implement,终审 request-revision 或格式仍无效时 fail-closed |
112
+ | `soft-verify-shell` | supervision 前归档 focused test exit code |
113
+ | `process-supervisor-pi` | read-only audit coverage、boundary drift、verify gap、repair scope;应 prominently 输出 `VERDICT: pass` `VERDICT: request-revision` |
114
+ | `process-gate-shell` | supervisor node JSON 上 runtime `shell.verdictGate`(仅 `pass` 或 `request-revision`) |
115
+ | `repair-pi` | supervisor 请求 revision 时在 repair `writeSet` bounded exclusive fix |
116
+ | `hard-verify-shell` | lint/typecheck + `HARNESS_ALLOW_ACTIVE_DAG_RUNS=1 check-repo.sh` fact |
117
+ | `authority-surface-audit-pi` + `authority-surface-gate-shell` | 可选 permission/state/tool-exposure audit;仅 authority signal 或显式 `authority-surface-audit` marker 时插入;gate 仅接受 `VERDICT: pass` |
118
+ | `review-pi` + `review-gate-shell` | Critical/Important → `request-revision`;node JSON 上 `shell.verdictGate` block,除非 extracted verdict 行为 `VERDICT: pass` |
119
+
120
+ **Verdict gate contract(`shell.verdictGate`)**:声明 `fromNodeId`、`accept[]`、可选 `label`、可选 `lineMode`。runner 展开为一条 shell command,从 injected current run directory 读 `$HARNESS_DAG_RUN_DIR/<fromNodeId>.json`,对 extracted `assistantText ?? stdout` verdict line 与 `accept[]` exact-match。默认 `lineMode` 为 `first-non-empty` 以兼容;supervised gate 用 `first-verdict-line` 选 Pi 在 preamble 或常见整行 Markdown emphasis(如 `**VERDICT: pass**`)后第一条 normalized `VERDICT:` line。勿用 `result.summary.md`、grep VERDICT、latest-active-run discovery 或 multi-command stateful gate。`--strict-governance` 对 anti-pattern fail。supervisor 仍为 `executor: pi` 上的 `role: supervisor`。
121
+
122
+ **Repair artifact gate contract(`shell.repairArtifactGate`)**:声明 `fromNodeId`(supervisor artifact 节点)与 `repairNodeId`(承接修订的 Pi 修复节点)。runner **不再**按节点名(历史 `repair-cursor` / `repair-pi`)猜测 repair 节点:显式 `repairNodeId` 必须存在、直接 `depends_on` gate、且是受治理 Pi writer(`executor: pi`、`toolProfile: write`、`writePolicy: exclusive`、`allowedPaths`+`writeSet` 非空且 `writeSet` 不与 `forbiddenPaths` 冲突)。新生成的 supervised DAG 总是写入 `repairNodeId`;旧 DAG 缺失时只在能唯一、安全地推导出下游 Pi writer 时兼容,零个或多个候选、或候选不满足契约都在执行前 fail closed。validation 覆盖存在性、直接下游、writer 属性与路径边界。
123
+
124
+ **Runtime contract 与 controller identity**:新生成的 DagSpec 使用 `version: 3`,并必须携带 `runtimeContract`(`schemaVersion` / `agentRuntime: "pi-only"` / `repairWriterProtocol: "explicit-node-v1"` / 可选 `minimumControllerVersion`)。v3 是旧 controller 无法忽略的解析边界;capability 与最低版本是新 controller 的执行前兼容门。`init-hybrid` 不硬编码 `minimumControllerVersion`,手写 spec 可按需 pin。每个新 run 必须解析并冻结 controller identity(package version、binary SHA-256、portable fingerprint)到 `controller-identity.json`;解析失败不创建 run。`dag report` 展示 identity 与 runtime-contract compatibility,resume 对漂移、篡改或 legacy-unpinned run 全部 fail closed;legacy run 仍可只读报告或显式 reconcile。
125
+
126
+ Prompt invariant:`ai_workspace/loop-agent/templates/agent-dag-process-supervisor.prompt.md`、`ai_workspace/loop-agent/templates/agent-dag-review-verdict.prompt.md`、`ai_workspace/loop-agent/templates/agent-dag-authority-surface-audit.prompt.md`(启用时)。测试:`npx vitest run test/dag-supervised-template.test.ts test/authority-surface.test.ts`。完整叙述:`ai_workspace/loop-agent/agent-dag-runner.md` §「Why main-session interventions happened」。
127
+
128
+ **未实现**:`executor: supervisor`、whole-run automatic retry/resume、`executor: human`/`decision`、browser executor,或 read-only node 对 root `artifacts/**` 的 exemption。注:有界只读 Pi 节点重试已实现(见下「只读 Pi 节点安全重试」)。
129
+
130
+ ### Level 3 task-to-DAG(`dag init-hybrid` / `dag run-task`)
131
+
132
+ ```bash
133
+ loop-agent dag init-hybrid <task-id> [--output <temp-dir>/<task-id>-hybrid-dag.json]
134
+ loop-agent dag run-task <task-id> [--output <temp-dir>/<task-id>-hybrid-dag.json] # 安全默认:仅 generate + validate,standard-compatible
135
+ loop-agent dag run-task <task-id> --profile auto # 推断 candidate governanceProfile,再经 workflowPolicy 路由
136
+ loop-agent dag run-task <task-id> --profile minimal # 选择 minimal 通用路由;standard 前端任务可自动使用前端 DAG
137
+ loop-agent dag run-task <task-id> --profile standard # 选择 standard 通用路由;standard 前端任务可自动使用前端 DAG
138
+ loop-agent dag run-task <task-id> --profile reviewed # 选择 reviewed 通用路由;standard 前端任务可自动使用前端 DAG
139
+ loop-agent dag run-task <task-id> --profile supervised # 选择 supervised DAG;自动前端分类不会降级它
140
+ loop-agent dag run-task <task-id> --strict-models # 非 canonical executorModels 时失败
141
+ loop-agent dag run-task <task-id> --execute --cwd <repo-root> # 要求 narrowed implement writeSet
142
+ loop-agent dag run-task <task-id> --dry-run --cwd <repo-root> # active snapshot 于 .harness/dag-runs/active/
143
+ loop-agent dag run-task <task-id> --init-only --cwd <repo-root> # pending active snapshot,不执行 node
144
+ ```
145
+
146
+ 默认 `dag run-task` **不**创建 `.harness/dag-runs/**`。placeholder / `**` implement writeSet 会 block `--execute`、`--init-only`、`--dry-run`,直到人工 review narrow path。
147
+
148
+ `dag run-task` JSON 输出含确定性 `reviewPacket` 供执行前 review。derived 自 generated DAG JSON、embedded validate summary、`profileRouting`;不调用 LLM,不写 completed run facts。`run-dag` 前用它 inspect `profileRouting`、`governanceProfile`、exclusive writer `writeSet`、`broadWriteSetRisk`、`forbiddenOverlapRisk`、`shellGates`(含 `lineMode`)、`shellVerification` / `expectedVerification`、`decisionGates` mode。
149
+
150
+ ### DAG artifacts source-of-truth 规则
151
+
152
+ - 临时 DAG input spec 放平台原生临时目录(例如 `<temp-dir>/<topic>-dag.json`);可复用 template `examples/` `ai_workspace/loop-agent/templates/`。
153
+ - **不要**在 `.harness/dag-runs/active/` root 保留手写 DAG input 副本。
154
+ - **不要**把 `.harness/dag-runs/` 内容 commit git
155
+ - canonical per-run DAG 历史是 `.harness/dag-runs/completed/<run-id>/run.json` 及该 run 目录的 `state.json`、`executor.jsonl`、node artifacts;新建 run directory 使用 `YYYYMMDD-<slug>`。
156
+ - root `artifacts/修改记录.md` `artifacts/验证结果.md` legacy current-work / explicit-write 摘要。不是 per-run 不可变历史,也不是新工作流默认交付路径。
157
+ - Agent DAG read-only node 不得写 root `artifacts/`;若须更新 root artifacts,用显式 `exclusive` write node 或记录了理由、验证与迁移计划的 main-session surgical patch。
158
+ - DAG Cursor 节点交付物必须写入 `.harness/dag-runs/<state>/<run-id>/artifacts/<node-id>/`;`./artifacts/**` 是错误落点。
159
+ - 长期结论须迁入 `ai_workspace/loop-agent/exec-plans/`、`ai_workspace/loop-agent/reports/` 或 `ai_workspace/loop-agent/progress/`。从 completed run evidence 汇总 task artifacts 时用 `promote-run <task-id> --run-id <run-id>`;再用 `closeout task <task-id>` 生成 progress。二者 deterministic,且不 mutate completed run facts。
160
+
161
+ **DAG author 的 artifact-boundary 提醒**:大量 *讨论* root `artifacts/**` 的 task 仍遵守同一 write guard — read-only node 仅在 node output 返回发现;exclusive node 保持 `artifacts/**` 在 `forbiddenPaths`,除非 concrete path 在 `writeSet`。不要在 declared writeSet 外 instruct implementer 写 `artifacts/修改记录.md` 或 `artifacts/验证结果.md`(P3 boundary-risk practice)。scout 在链接 skill reference 中发现 stale wording 时,把那些 path 纳入 implementer writeSet,或接受记录的 main-session patch(P2 教训:`hybrid-dag.md` 被 scout 发现但 initial writeSet 遗漏)。
162
+
163
+ ### Decision Gate(M3–M5 runtime)
164
+
165
+ Pi reviewer node `decisionGate.enabled: true` 时,runner persisted `assistantText`(优先)或 `result.summary.md`(fallback)解析 **恰好一个** info string 为 `DECISION_ENVELOPE_JSON` 的 fenced block。Schema:`ai_workspace/loop-agent/templates/agent-dag-decision-envelope.schema.json`。Prompt:`ai_workspace/loop-agent/templates/agent-dag-decision-gate.prompt.md`(含 §Recovery Recommendation Consumption 与 schema-adherence 硬规则:勿发明 envelope schema、勿用 `decision: accept`、勿加 extra root key、`audit.runId` 须绑定当前 run id,并填 `audit.nodeId` / `audit.model`)。Playbook:`ai_workspace/loop-agent/agent-dag-recovery-playbook.md`。示例 DAG:`examples/decision-gate-agent-dag.json`。
166
+
167
+ | Milestone | `decisionGate.mode` | 行为 |
168
+ |-----------|---------------------|----------|
169
+ | **M3 record-only** | `record-only`(默认) | 写 `<node-id>/decision.envelope.json` + node record summary;**不 pause**,**不** branch 于 `decision`/`nextAction` |
170
+ | **M4 pause-on-human** | `pause-on-human` | parse OK 且 `requiresHuman=true`:run `status=paused`,移入 `.harness/dag-runs/paused/<run-id>/`,写 `human-escalation.json` / `.md`;downstream node 保持 `PENDING` |
171
+ | **M5 CLI** | (M4 pause 后) | 确定性 human decision — **无 LLM**,**无** `executor: human` / `executor: decision` |
172
+
173
+ ```bash
174
+ loop-agent dag doctor
175
+ loop-agent dag status --run-id <run-id>
176
+ loop-agent dag report --paused-latest [--json|--markdown] # 最新 paused run;勿与 --lifecycle 并用
177
+ loop-agent dag report [--run-id <run-id>] [--lifecycle active|paused|completed|all] [--json|--markdown] [--failed-only] [--latest] [--action <recovery-action>] # derived per-node report(只读);JSON schema: ai_workspace/loop-agent/templates/agent-dag-report.schema.json;仅 advisory — 见 ai_workspace/loop-agent/agent-dag-recovery-playbook.md
178
+ loop-agent dag closeout-draft [--run-id <run-id>] [--output <path>] # M5:从 completed run facts 生成确定性 closeout draft;默认平台临时目录;仅 advisory;不 mutate completed facts
179
+ loop-agent promote-run <task-id> --run-id <run-id> # 从 completed DAG/one-shot evidence 汇总 task artifacts;不 mutate completed facts
180
+ loop-agent closeout task <task-id> # task artifacts 生成 ai_workspace/loop-agent/progress closeout
181
+ loop-agent dag reconcile-tasks --glob '<pattern>' [--json|--markdown] # 仅报告的 task/run/artifact/verify drift audit
182
+ loop-agent dag final-verification <task-id> [--output <path>] # 生成 closeout DAG;final verify 依赖 closeout artifact
183
+ loop-agent dag decision inspect --run-id <run-id> [--node-id <node-id>]
184
+ loop-agent dag decision validate --run-id <run-id> [--node-id <node-id>]
185
+ loop-agent dag approve --run-id <run-id> --option <id> [--notes "..."]
186
+ loop-agent dag reject --run-id <run-id> --reason "..."
187
+ loop-agent dag resume --run-id <run-id> # approve 后继续
188
+ ```
189
+
190
+ **Paused operator flow**:`run-dag` → `paused/` →(`dag status` / 可选 `dag decision validate`)→ `dag approve` → `active/` → `dag resume` → `completed/`;或 `dag reject` → `completed/`(`failed`,`failureCategory=human-rejected`)。
191
+
192
+ **Stale active detection**:`dag doctor` 标 health code 如 `terminal-in-active`(`active/` 保留 terminal run);仅 advisory — 按 playbook 手动 archive/remove,尚无 auto cleanup CLI。
193
+
194
+ **Deferred**:`browser` executor;`dag recover apply`;勿在 DAG JSON 加 `executor: human` 或 `executor: decision`。
195
+
196
+ **In-flight DAG run 期间的 governance**:live run 内 shell verify node 须用 `HARNESS_ALLOW_ACTIVE_DAG_RUNS=1 bash scripts/check-repo.sh`。run 归档到 `completed/` 后,在 DAG 外跑裸 `bash scripts/check-repo.sh`。
197
+
198
+ ### 只读 Pi 节点安全重试(read-only retry)
199
+
200
+ planner/scout/reviewer/verifier/closeout 角色的安全只读 Pi 节点可声明 `retryPolicy`,在同一 run 内有界重试模型连接中断、provider 限流、临时不可用或请求 timeout。生成模板自动注入默认策略(总尝试 3 次,手工配置最多 5 次,指数退避,单次等待上限 30s)。supervisor 与 implementer 明确不重试。
201
+
202
+ - 仅重试原始分类:`timeout`、`network`、`rate-limit`、`unavailable`。`quota` **不**是 rate limit,不重试;`auth`、`invalid-output`、`write-guard`、`decision-envelope` 与未知失败同样不重试。
203
+ - 资格由确定性 helper 判断,executor 内不硬编码循环;仅 `writePolicy=read-only|none`(或 Pi 默认只读)的上述角色可用。supervisor / implementer / writer / docs-only / dynamic / shell / static / decision-gate 节点声明 `retryPolicy` 会在 DAG validation 阶段失败。
204
+ - 每次 attempt 写入独立不可变证据 `<node-id>/attempt-<n>.json`(run-relative path),最终 node record `attempts` 字段引用完整历史;后一次成功不覆盖前一次失败证据。
205
+ - 重试复用同一 run、controller identity、skill snapshot、prompt、model 与上游输入;退避等待刷新 `lastActivityAt` 避免误判 node-quiet。
206
+ - 节点终态聚合全部 attempts 的耗时、Token 与事件数;当前 backoff 等待会占用该节点的并发槽。
207
+ - 未声明 `retryPolicy` 的历史 DAG 行为不变(单次执行,不新增 attempt artifact)。
208
+
209
+ 实现:`src/workflows/dag/retry-policy.ts`、`node-execution.ts`、`validate.ts`。测试:`npx vitest run test/dag-node-retry.test.ts test/dag-validate.test.ts test/dag-init-hybrid.test.ts`。
210
+
211
+ ### Evidence summary guidance(practice convention runtime)
212
+
213
+ review-heavy DAG 中长 shell stdout 可能掩盖 proof 时,用 **evidence-summary-shell** 作为 authoring pattern。**不是** runtime executor、schema field parser。
214
+
215
+ - soft/hard verify shell node 之后,prompt downstream **read-only** Pi reviewer(`reviewer`、`supervisor`、`closeout`)在 node output 开头用紧凑 `EVIDENCE:` 行(`EVIDENCE: <check> exit=<code> (<one-line fact>)`),再写 prose findings。
216
+ - 与现有 **`shell.verdictGate`** 配对做 fail-closed gate:`VERDICT: pass` `VERDICT: request-revision` 仍是 machine-readable decision;supervised gate 用 `lineMode: "first-verdict-line"`,`EVIDENCE:` 行供扫描事实,不能替代 verdict line。
217
+ - shell node exit code 与 archived command output 为 authoritative;`EVIDENCE:` 摘要供 human/decision-gate 扫描速度,不替代 deterministic shell verification。
218
+ - **不要**期望 runner enforce、parse validate `EVIDENCE:` 格式;**不要**在 `shell.verdictGate` 或 shell exit code 已够用时手写 shell grep `EVIDENCE:`。
219
+ - read-only node 不得写 root `artifacts/**`;compact evidence 属于 `.harness/dag-runs/<run-id>/` 下归档的 node output。
220
+
221
+ 完整叙述:`ai_workspace/loop-agent/agent-dag-runner.md` §「Evidence Summary as a Practice Convention」。P1 calibration report:`ai_workspace/loop-agent/reports/2026-06-08-agent-dag-practice-p1-evidence-summary-docs.md`。
222
+
223
+ ### Authoring checklist(P1–P5 practice guidance — 非 runtime 行为)
224
+
225
+ > `ai_workspace/loop-agent/agent-dag-runner.md` §「Agent DAG authoring checklist」相同。Calibration reports:`ai_workspace/loop-agent/reports/2026-06-08-agent-dag-practice-p1-evidence-summary-docs.md` `p5-handoff-closeout-20260608.md`。
226
+
227
+ | # | Check | Expect |
228
+ |---|-------|--------|
229
+ | 1 | Topology | 优先 same-rank parallel read-only scout/review;仅 output 真正需要时加 `depends_on` |
230
+ | 2 | Executor | 每个 task 显式声明 `executor`;`defaults.executor` schema metadata,非 runtime fallback |
231
+ | 3 | Model routing | node `complexity` + `executorModels`;Pi MED(`glm-5.2`)quota 耗尽时提高 Pi node `complexity: HIGH`(`gpt-5.5`)— mutate canonical model matrix |
232
+ | 4 | Read-only output | read-only / Pi node **node output** 返回发现;runner 归档于 `.harness/dag-runs/<run-id>/<node-id>/` |
233
+ | 5 | Root `artifacts/**` | read-only handoff target;持久记录去 `ai_workspace/loop-agent/reports/`、`ai_workspace/loop-agent/progress/`,或 narrow exclusive `writeSet` legacy 摘要并记录迁移计划 |
234
+ | 6 | DAG Cursor artifacts | 写入 `.harness/dag-runs/<state>/<run-id>/artifacts/<node-id>/`;不得写入 `./artifacts/**` |
235
+ | 7 | Completed facts | `.harness/dag-runs/completed/**` 仅可读 evidence 归档后永不 mutate 历史 run 目录、`run.json`、`state.json` `artifacts/**` |
236
+ | 8 | Verdict gate | review/supervisor 应以 `VERDICT: pass` `VERDICT: request-revision` 开头以利阅读;用 current-run `<fromNodeId>.json`(`$HARNESS_DAG_RUN_DIR`)上 `shell.verdictGate` block,exact-match `accept[]`;默认 `lineMode=first-non-empty`,supervised template `first-verdict-line` 容忍 preamble 或第一条 normalized `VERDICT:` 前的常见整行 Markdown emphasis |
237
+ | 9 | Decision Gate | 恰好 emit 一个 `DECISION_ENVELOPE_JSON` block;`audit.runId` 须绑定 **当前** run id;禁止 `decision: accept`、发明 schema、extra root key;填 `audit.nodeId` / `audit.model` |
238
+ | 10 | writeSet planning | scout 应列出链接的 `./skill/references/**` **writeSet expansion candidates**(P2:遗漏链接 skill ref 迫使 main-session patch) |
239
+ | 11 | Evidence summary | `evidence-summary-shell` / leading `EVIDENCE:` 行是 **practice convention**,非 runtime executor、schema field 或 parser |
240
+ | 12 | Featureization | 除非 repeated real-run failure 证明 checklist guidance 不够,勿加 runtime/schema/validator/CLI/executor feature |
241
+ | 13 | writeSet / writer backend | `exclusive` node 用 narrow、disjoint path;无 `**`;固定用 Pi write profile |
242
+ | 14 | Placeholders | 执行前将 `REPLACE/WITH/...` 换为具体 path |
243
+ | 15 | Governance | in-flight shell:`HARNESS_ALLOW_ACTIVE_DAG_RUNS=1 bash scripts/check-repo.sh`;archive 后:裸 `bash scripts/check-repo.sh` |