@hunter-harness/workflow-harness 0.2.72 → 0.2.74

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 (206) hide show
  1. package/harness/bundles/general/claude-code/.harness-build.json +1 -1
  2. package/harness/bundles/general/claude-code/harness-archive/SKILL.md +3 -3
  3. package/harness/bundles/general/claude-code/harness-codebase-map/SKILL.md +1 -1
  4. package/harness/bundles/general/claude-code/harness-knowledge-ingest/SKILL.md +1 -1
  5. package/harness/bundles/general/claude-code/harness-knowledge-query/SKILL.md +1 -1
  6. package/harness/bundles/general/claude-code/harness-plan/SKILL.md +14 -10
  7. package/harness/bundles/general/claude-code/harness-plan/checklist.md +49 -9
  8. package/harness/bundles/general/claude-code/harness-plan/reference.md +83 -33
  9. package/harness/bundles/general/claude-code/harness-pull/SKILL.md +1 -1
  10. package/harness/bundles/general/claude-code/harness-push/SKILL.md +1 -1
  11. package/harness/bundles/general/claude-code/harness-review/SKILL.md +3 -3
  12. package/harness/bundles/general/claude-code/harness-run/SKILL.md +6 -6
  13. package/harness/bundles/general/claude-code/harness-run/checklist.md +4 -1
  14. package/harness/bundles/general/claude-code/harness-run/reference.md +3 -3
  15. package/harness/bundles/general/claude-code/harness-submit/SKILL.md +5 -4
  16. package/harness/bundles/general/claude-code/harness-sync/SKILL.md +1 -1
  17. package/harness/bundles/general/claude-code/harness-test/SKILL.md +4 -4
  18. package/harness/bundles/general/claude-code/harness-test/checklist.md +2 -0
  19. package/harness/bundles/general/claude-code/scripts/harness_archive.py +82 -1
  20. package/harness/bundles/general/claude-code/scripts/harness_context.py +270 -0
  21. package/harness/bundles/general/claude-code/scripts/harness_gate.py +71 -2
  22. package/harness/bundles/general/claude-code/scripts/harness_ledger.py +25 -4
  23. package/harness/bundles/general/claude-code/scripts/harness_profile.py +45 -0
  24. package/harness/bundles/general/claude-code/scripts/harness_test_guard.py +8 -5
  25. package/harness/bundles/general/codebuddy/.harness-build.json +1 -1
  26. package/harness/bundles/general/codebuddy/harness-archive/SKILL.md +3 -3
  27. package/harness/bundles/general/codebuddy/harness-codebase-map/SKILL.md +1 -1
  28. package/harness/bundles/general/codebuddy/harness-knowledge-ingest/SKILL.md +1 -1
  29. package/harness/bundles/general/codebuddy/harness-knowledge-query/SKILL.md +1 -1
  30. package/harness/bundles/general/codebuddy/harness-plan/SKILL.md +14 -10
  31. package/harness/bundles/general/codebuddy/harness-plan/checklist.md +49 -9
  32. package/harness/bundles/general/codebuddy/harness-plan/reference.md +83 -33
  33. package/harness/bundles/general/codebuddy/harness-pull/SKILL.md +1 -1
  34. package/harness/bundles/general/codebuddy/harness-push/SKILL.md +1 -1
  35. package/harness/bundles/general/codebuddy/harness-review/SKILL.md +3 -3
  36. package/harness/bundles/general/codebuddy/harness-run/SKILL.md +6 -6
  37. package/harness/bundles/general/codebuddy/harness-run/checklist.md +4 -1
  38. package/harness/bundles/general/codebuddy/harness-run/reference.md +3 -3
  39. package/harness/bundles/general/codebuddy/harness-submit/SKILL.md +5 -4
  40. package/harness/bundles/general/codebuddy/harness-sync/SKILL.md +1 -1
  41. package/harness/bundles/general/codebuddy/harness-test/SKILL.md +4 -4
  42. package/harness/bundles/general/codebuddy/harness-test/checklist.md +2 -0
  43. package/harness/bundles/general/codebuddy/scripts/harness_archive.py +82 -1
  44. package/harness/bundles/general/codebuddy/scripts/harness_context.py +270 -0
  45. package/harness/bundles/general/codebuddy/scripts/harness_gate.py +71 -2
  46. package/harness/bundles/general/codebuddy/scripts/harness_ledger.py +25 -4
  47. package/harness/bundles/general/codebuddy/scripts/harness_profile.py +45 -0
  48. package/harness/bundles/general/codebuddy/scripts/harness_test_guard.py +8 -5
  49. package/harness/bundles/general/codex/.harness-build.json +1 -1
  50. package/harness/bundles/general/codex/harness-archive/SKILL.md +3 -3
  51. package/harness/bundles/general/codex/harness-codebase-map/SKILL.md +1 -1
  52. package/harness/bundles/general/codex/harness-knowledge-ingest/SKILL.md +1 -1
  53. package/harness/bundles/general/codex/harness-knowledge-query/SKILL.md +1 -1
  54. package/harness/bundles/general/codex/harness-plan/SKILL.md +14 -10
  55. package/harness/bundles/general/codex/harness-plan/checklist.md +49 -9
  56. package/harness/bundles/general/codex/harness-plan/reference.md +83 -33
  57. package/harness/bundles/general/codex/harness-pull/SKILL.md +1 -1
  58. package/harness/bundles/general/codex/harness-push/SKILL.md +1 -1
  59. package/harness/bundles/general/codex/harness-review/SKILL.md +3 -3
  60. package/harness/bundles/general/codex/harness-run/SKILL.md +6 -6
  61. package/harness/bundles/general/codex/harness-run/checklist.md +4 -1
  62. package/harness/bundles/general/codex/harness-run/reference.md +3 -3
  63. package/harness/bundles/general/codex/harness-submit/SKILL.md +5 -4
  64. package/harness/bundles/general/codex/harness-sync/SKILL.md +1 -1
  65. package/harness/bundles/general/codex/harness-test/SKILL.md +4 -4
  66. package/harness/bundles/general/codex/harness-test/checklist.md +2 -0
  67. package/harness/bundles/general/codex/scripts/harness_archive.py +82 -1
  68. package/harness/bundles/general/codex/scripts/harness_context.py +270 -0
  69. package/harness/bundles/general/codex/scripts/harness_gate.py +71 -2
  70. package/harness/bundles/general/codex/scripts/harness_ledger.py +25 -4
  71. package/harness/bundles/general/codex/scripts/harness_profile.py +45 -0
  72. package/harness/bundles/general/codex/scripts/harness_test_guard.py +8 -5
  73. package/harness/bundles/general/cursor/.harness-build.json +1 -1
  74. package/harness/bundles/general/cursor/harness-archive/SKILL.md +3 -3
  75. package/harness/bundles/general/cursor/harness-codebase-map/SKILL.md +1 -1
  76. package/harness/bundles/general/cursor/harness-knowledge-ingest/SKILL.md +1 -1
  77. package/harness/bundles/general/cursor/harness-knowledge-query/SKILL.md +1 -1
  78. package/harness/bundles/general/cursor/harness-plan/SKILL.md +14 -10
  79. package/harness/bundles/general/cursor/harness-plan/checklist.md +49 -9
  80. package/harness/bundles/general/cursor/harness-plan/reference.md +83 -33
  81. package/harness/bundles/general/cursor/harness-pull/SKILL.md +1 -1
  82. package/harness/bundles/general/cursor/harness-push/SKILL.md +1 -1
  83. package/harness/bundles/general/cursor/harness-review/SKILL.md +3 -3
  84. package/harness/bundles/general/cursor/harness-run/SKILL.md +6 -6
  85. package/harness/bundles/general/cursor/harness-run/checklist.md +4 -1
  86. package/harness/bundles/general/cursor/harness-run/reference.md +3 -3
  87. package/harness/bundles/general/cursor/harness-submit/SKILL.md +5 -4
  88. package/harness/bundles/general/cursor/harness-sync/SKILL.md +1 -1
  89. package/harness/bundles/general/cursor/harness-test/SKILL.md +4 -4
  90. package/harness/bundles/general/cursor/harness-test/checklist.md +2 -0
  91. package/harness/bundles/general/cursor/scripts/harness_archive.py +82 -1
  92. package/harness/bundles/general/cursor/scripts/harness_context.py +270 -0
  93. package/harness/bundles/general/cursor/scripts/harness_gate.py +71 -2
  94. package/harness/bundles/general/cursor/scripts/harness_ledger.py +25 -4
  95. package/harness/bundles/general/cursor/scripts/harness_profile.py +45 -0
  96. package/harness/bundles/general/cursor/scripts/harness_test_guard.py +8 -5
  97. package/harness/bundles/java/claude-code/.harness-build.json +1 -1
  98. package/harness/bundles/java/claude-code/harness-apidoc/SKILL.md +3 -3
  99. package/harness/bundles/java/claude-code/harness-archive/SKILL.md +3 -3
  100. package/harness/bundles/java/claude-code/harness-codebase-map/SKILL.md +1 -1
  101. package/harness/bundles/java/claude-code/harness-knowledge-ingest/SKILL.md +1 -1
  102. package/harness/bundles/java/claude-code/harness-knowledge-query/SKILL.md +1 -1
  103. package/harness/bundles/java/claude-code/harness-package/SKILL.md +3 -3
  104. package/harness/bundles/java/claude-code/harness-plan/SKILL.md +14 -10
  105. package/harness/bundles/java/claude-code/harness-plan/checklist.md +49 -9
  106. package/harness/bundles/java/claude-code/harness-plan/reference.md +83 -33
  107. package/harness/bundles/java/claude-code/harness-pull/SKILL.md +1 -1
  108. package/harness/bundles/java/claude-code/harness-push/SKILL.md +1 -1
  109. package/harness/bundles/java/claude-code/harness-review/SKILL.md +3 -3
  110. package/harness/bundles/java/claude-code/harness-run/SKILL.md +6 -6
  111. package/harness/bundles/java/claude-code/harness-run/checklist.md +1 -1
  112. package/harness/bundles/java/claude-code/harness-run/reference.md +348 -348
  113. package/harness/bundles/java/claude-code/harness-submit/SKILL.md +5 -4
  114. package/harness/bundles/java/claude-code/harness-sync/SKILL.md +1 -1
  115. package/harness/bundles/java/claude-code/harness-test/SKILL.md +4 -4
  116. package/harness/bundles/java/claude-code/scripts/harness_archive.py +82 -1
  117. package/harness/bundles/java/claude-code/scripts/harness_context.py +270 -0
  118. package/harness/bundles/java/claude-code/scripts/harness_gate.py +71 -2
  119. package/harness/bundles/java/claude-code/scripts/harness_ledger.py +25 -4
  120. package/harness/bundles/java/claude-code/scripts/harness_profile.py +45 -0
  121. package/harness/bundles/java/claude-code/scripts/harness_test_guard.py +8 -5
  122. package/harness/bundles/java/codebuddy/.harness-build.json +1 -1
  123. package/harness/bundles/java/codebuddy/harness-apidoc/SKILL.md +3 -3
  124. package/harness/bundles/java/codebuddy/harness-archive/SKILL.md +3 -3
  125. package/harness/bundles/java/codebuddy/harness-codebase-map/SKILL.md +1 -1
  126. package/harness/bundles/java/codebuddy/harness-knowledge-ingest/SKILL.md +1 -1
  127. package/harness/bundles/java/codebuddy/harness-knowledge-query/SKILL.md +1 -1
  128. package/harness/bundles/java/codebuddy/harness-package/SKILL.md +3 -3
  129. package/harness/bundles/java/codebuddy/harness-plan/SKILL.md +14 -10
  130. package/harness/bundles/java/codebuddy/harness-plan/checklist.md +49 -9
  131. package/harness/bundles/java/codebuddy/harness-plan/reference.md +83 -33
  132. package/harness/bundles/java/codebuddy/harness-pull/SKILL.md +1 -1
  133. package/harness/bundles/java/codebuddy/harness-push/SKILL.md +1 -1
  134. package/harness/bundles/java/codebuddy/harness-review/SKILL.md +3 -3
  135. package/harness/bundles/java/codebuddy/harness-run/SKILL.md +6 -6
  136. package/harness/bundles/java/codebuddy/harness-run/checklist.md +1 -1
  137. package/harness/bundles/java/codebuddy/harness-run/reference.md +348 -348
  138. package/harness/bundles/java/codebuddy/harness-submit/SKILL.md +5 -4
  139. package/harness/bundles/java/codebuddy/harness-sync/SKILL.md +1 -1
  140. package/harness/bundles/java/codebuddy/harness-test/SKILL.md +4 -4
  141. package/harness/bundles/java/codebuddy/scripts/harness_archive.py +82 -1
  142. package/harness/bundles/java/codebuddy/scripts/harness_context.py +270 -0
  143. package/harness/bundles/java/codebuddy/scripts/harness_gate.py +71 -2
  144. package/harness/bundles/java/codebuddy/scripts/harness_ledger.py +25 -4
  145. package/harness/bundles/java/codebuddy/scripts/harness_profile.py +45 -0
  146. package/harness/bundles/java/codebuddy/scripts/harness_test_guard.py +8 -5
  147. package/harness/bundles/java/codex/.harness-build.json +1 -1
  148. package/harness/bundles/java/codex/harness-apidoc/SKILL.md +3 -3
  149. package/harness/bundles/java/codex/harness-archive/SKILL.md +3 -3
  150. package/harness/bundles/java/codex/harness-codebase-map/SKILL.md +1 -1
  151. package/harness/bundles/java/codex/harness-knowledge-ingest/SKILL.md +1 -1
  152. package/harness/bundles/java/codex/harness-knowledge-query/SKILL.md +1 -1
  153. package/harness/bundles/java/codex/harness-package/SKILL.md +3 -3
  154. package/harness/bundles/java/codex/harness-plan/SKILL.md +14 -10
  155. package/harness/bundles/java/codex/harness-plan/checklist.md +49 -9
  156. package/harness/bundles/java/codex/harness-plan/reference.md +83 -33
  157. package/harness/bundles/java/codex/harness-pull/SKILL.md +1 -1
  158. package/harness/bundles/java/codex/harness-push/SKILL.md +1 -1
  159. package/harness/bundles/java/codex/harness-review/SKILL.md +3 -3
  160. package/harness/bundles/java/codex/harness-run/SKILL.md +6 -6
  161. package/harness/bundles/java/codex/harness-run/checklist.md +1 -1
  162. package/harness/bundles/java/codex/harness-run/reference.md +348 -348
  163. package/harness/bundles/java/codex/harness-submit/SKILL.md +5 -4
  164. package/harness/bundles/java/codex/harness-sync/SKILL.md +1 -1
  165. package/harness/bundles/java/codex/harness-test/SKILL.md +4 -4
  166. package/harness/bundles/java/codex/scripts/harness_archive.py +82 -1
  167. package/harness/bundles/java/codex/scripts/harness_context.py +270 -0
  168. package/harness/bundles/java/codex/scripts/harness_gate.py +71 -2
  169. package/harness/bundles/java/codex/scripts/harness_ledger.py +25 -4
  170. package/harness/bundles/java/codex/scripts/harness_profile.py +45 -0
  171. package/harness/bundles/java/codex/scripts/harness_test_guard.py +8 -5
  172. package/harness/bundles/java/cursor/.harness-build.json +1 -1
  173. package/harness/bundles/java/cursor/harness-apidoc/SKILL.md +3 -3
  174. package/harness/bundles/java/cursor/harness-archive/SKILL.md +3 -3
  175. package/harness/bundles/java/cursor/harness-codebase-map/SKILL.md +1 -1
  176. package/harness/bundles/java/cursor/harness-knowledge-ingest/SKILL.md +1 -1
  177. package/harness/bundles/java/cursor/harness-knowledge-query/SKILL.md +1 -1
  178. package/harness/bundles/java/cursor/harness-package/SKILL.md +3 -3
  179. package/harness/bundles/java/cursor/harness-plan/SKILL.md +14 -10
  180. package/harness/bundles/java/cursor/harness-plan/checklist.md +49 -9
  181. package/harness/bundles/java/cursor/harness-plan/reference.md +83 -33
  182. package/harness/bundles/java/cursor/harness-pull/SKILL.md +1 -1
  183. package/harness/bundles/java/cursor/harness-push/SKILL.md +1 -1
  184. package/harness/bundles/java/cursor/harness-review/SKILL.md +3 -3
  185. package/harness/bundles/java/cursor/harness-run/SKILL.md +6 -6
  186. package/harness/bundles/java/cursor/harness-run/checklist.md +1 -1
  187. package/harness/bundles/java/cursor/harness-run/reference.md +348 -348
  188. package/harness/bundles/java/cursor/harness-submit/SKILL.md +5 -4
  189. package/harness/bundles/java/cursor/harness-sync/SKILL.md +1 -1
  190. package/harness/bundles/java/cursor/harness-test/SKILL.md +4 -4
  191. package/harness/bundles/java/cursor/scripts/harness_archive.py +82 -1
  192. package/harness/bundles/java/cursor/scripts/harness_context.py +270 -0
  193. package/harness/bundles/java/cursor/scripts/harness_gate.py +71 -2
  194. package/harness/bundles/java/cursor/scripts/harness_ledger.py +25 -4
  195. package/harness/bundles/java/cursor/scripts/harness_profile.py +45 -0
  196. package/harness/bundles/java/cursor/scripts/harness_test_guard.py +8 -5
  197. package/harness/manifests/general/claude-code.json +26 -26
  198. package/harness/manifests/general/codebuddy.json +26 -26
  199. package/harness/manifests/general/codex.json +26 -26
  200. package/harness/manifests/general/cursor.json +26 -26
  201. package/harness/manifests/java/claude-code.json +27 -27
  202. package/harness/manifests/java/codebuddy.json +27 -27
  203. package/harness/manifests/java/codex.json +27 -27
  204. package/harness/manifests/java/cursor.json +27 -27
  205. package/hunter-workflow-family.json +5 -5
  206. package/package.json +1 -1
@@ -3,7 +3,7 @@ name: harness-run
3
3
  description: 按变更簇执行 TDD 编码循环(RED→GREEN→REFACTOR→编译验证),逐变更簇实现计划中的任务。仅当用户显式调用
4
4
  /harness-run 时使用;不得因用户提到编码/实现就自动触发,也不得被其他阶段 skill 自动接续。
5
5
  ---
6
- <!-- generated by harness_deploy.py; core=a4f07759d60ce2c9; overlay=none; agent=codebuddy; do not edit -->
6
+ <!-- generated by harness_deploy.py; core=d0ad43fe132b6817; overlay=none; agent=codebuddy; do not edit -->
7
7
  # harness-run — 需求编码
8
8
 
9
9
  ## Purpose
@@ -18,7 +18,7 @@ description: 按变更簇执行 TDD 编码循环(RED→GREEN→REFACTOR→编
18
18
 
19
19
  ## 前置条件
20
20
 
21
- - `spec/*-design.md`、`plans/*-plan.md`(含 frontmatter)存在且已审批
21
+ - 设计文档(`plans/*-design.md` 优先,回退 `spec/*-design.md`)与 `plans/*-plan.md`(含 frontmatter)存在且已审批
22
22
  - 读 `meta/worktree.json`:`requested=true` 时 worktree 须存在或 run 负责创建
23
23
 
24
24
  ## Worktree 门禁
@@ -41,9 +41,9 @@ description: 按变更簇执行 TDD 编码循环(RED→GREEN→REFACTOR→编
41
41
  ## 统一读取协议
42
42
 
43
43
  1. **`.harness/changes/<change-name>/` 是唯一真相源** — 所有输入从该目录读取,产物写入对应子目录
44
- 2. **change-name 优先从 frontmatter 读取** — `spec/*-design.md`、`plans/*-plan.md` 的 YAML `change-name`
44
+ 2. **change-name 优先从 frontmatter 读取** — `plans/*-design.md`、`spec/*-design.md`、`plans/*-plan.md` 的 YAML `change-name`
45
45
  3. **frontmatter 缺失时兼容旧格式** — 从路径推断,标记 `🟡 legacy-plan`,不失败
46
- 4. **spec** — 设计真相源:`spec/<change>-design.md`
46
+ 4. **design** — 设计真相源按序取第一个存在的:`plans/<change>-design.md`(v2 发布产物,哈希绑定)→ `spec/<change>-design.md`(legacy 手写)。两份**同时存在**时以 `plans/` 为准,并记 `🟡 WARN 设计文档双份`——v2 发布的那份才受完整性门禁保护,读手写的那份等于绕过校验
47
47
  5. **plan** — 任务真相源:`plans/<change>-plan.md`
48
48
  6. **implementation-detail** — 自适应执行参考;legacy 缺失 🟡WARN,不阻断
49
49
  7. **test-scenarios** — 测试真相源:`plans/<change>-test-scenarios.md`
@@ -59,10 +59,10 @@ description: 按变更簇执行 TDD 编码循环(RED→GREEN→REFACTOR→编
59
59
 
60
60
  ## Workflow 概要
61
61
 
62
- 0. 加载上下文:普通 Run 先 `harness_context.py prepare --phase run --executor <tool> [--change <id>] --json`,再 **`harness_context.py begin --phase run --change <id> --executor <tool> --json`** 校验交接,最后运行 **`harness_gate.py begin --phase run --change <id>`**。`harness_gate.py` 会从当前已安装适配器自动识别 skills root;只有执行复制到别处的脚本时才显式传 `--skills-root`。`--fixback` 不得拼装这些底层步骤,必须只调用一次 `harness_fixback.py launch-review --project . --change <id> --change-dir <change-dir> --executor <tool> --skills-root <skills-root> --product-identity <当前产品身份> --json`:该命令会先筛选结构化评审项,再原子选择 Fixback 分支、确认上下文、取得 Run 门禁并创建已填充批次。返回 `FIXBACK_NOTHING_TO_APPLY` 时直接报告“本轮评审没有需要执行的代码修复”并停止;返回阻塞码时按 `recoveryAction` 停止,不搜索实现、不试探其他参数、不创建空批次。禁止手写 `events.ndjson` / `phase.end`。已连接平台时 begin 会 best-effort 补传事件,失败只告警。
62
+ 0. 加载上下文:普通 Run 先 `harness_context.py prepare --project . --change <id> --phase run --executor <tool> --json`(`--project` 必填,漏了直接 argparse 报错),再 **`harness_context.py begin --project . --change <id> --phase run --executor <tool> --json`** 校验交接,最后运行 **`harness_gate.py begin --phase run --change <id>`**。<br>**交接凭证不必手工补**:v2 计划的 `plan finalize` 不写 context 事务,`prepare` 会在检测到 committed 的 `meta/publication-journals/*.json` 时自动补录 `plan → run` 凭证(凭证带 `bootstrapSource=plan_publication_journal` 留痕)。仍报 `HANDOFF_REQUIRED`/`LEGACY_BOOTSTRAP_REQUIRED` 说明**没有**这份发布证据——回到 plan 阶段确认发布是否真的完成,**不得**自己拼 `classify + configure-plan + close` 造凭证。`harness_gate.py` 会从当前已安装适配器自动识别 skills root;只有执行复制到别处的脚本时才显式传 `--skills-root`。`--fixback` 不得拼装这些底层步骤,必须只调用一次 `harness_fixback.py launch-review --project . --change <id> --change-dir <change-dir> --executor <tool> --skills-root <skills-root> --product-identity <当前产品身份> --json`:该命令会先筛选结构化评审项,再原子选择 Fixback 分支、确认上下文、取得 Run 门禁并创建已填充批次。返回 `FIXBACK_NOTHING_TO_APPLY` 时直接报告“本轮评审没有需要执行的代码修复”并停止;返回阻塞码时按 `recoveryAction` 停止,不搜索实现、不试探其他参数、不创建空批次。禁止手写 `events.ndjson` / `phase.end`。已连接平台时 begin 会 best-effort 补传事件,失败只告警。
63
63
  0.5. **测试基础设施探测**(先写 `CHECKING`,四项证据齐备后再结论)→ `reference.md` Step 0.5;测试基线已由上一步 gate begin 内部建立,不得再次执行 guard begin
64
64
  1. **变更簇 TDD** — `protocols.md` `run-tdd-protocol`;批量 RED/GREEN;按需 `change-cluster-review-protocol`(高风险 + reviewer 预检可用)
65
- 2. 构建验证 + **仅**通过 `harness_ledger.py record` 写 ledger(禁止 Write/Edit `verification-ledger.json`);若本阶段创建/删除了清单、锁文件、源码根或改变技术栈,最后一次产品编辑后、写账本与关门前必须执行 `harness_preflight.py detect --project . --json` 刷新 build profile。`record --project . --profile-input <key>` 会对缺失/陈旧 profile 自动检测并从同一 target 推导 scope、coverage、规范命令和输入闭包;不得再手填另一套身份。`diff-hash --change-dir` 纳入 ignored tests → `reference.md` Step 2c
65
+ 2. 构建验证 + **仅**通过 `harness_ledger.py record` 写 ledger(禁止 Write/Edit `verification-ledger.json`);若本阶段创建/删除了清单、锁文件、源码根或改变技术栈,最后一次产品编辑后、写账本与关门前必须执行 `harness_preflight.py detect --project . --json` 刷新 build profile。`record --project . --profile-input <key>` 会对缺失/陈旧 profile 自动检测并从同一 target 推导 scope、coverage、规范命令和输入闭包;不得再手填另一套身份。detect 在嵌套/多组件仓库返回 `DETECTION_AMBIGUOUS` 时,响应里的 `profileTemplate` 就是可填骨架(已含 defaultsFingerprint、excludedRoots 默认集与 commands 条目形状),按 `hint` 填好写入 `.harness/config/build-profile.json` 即可,**不要去反读 `harness_profile.py` 源码凑结构**。`diff-hash --change-dir` 纳入 ignored tests → `reference.md` Step 2c
66
66
  3. **场景覆盖检查**(场景表映射,禁止用用例数冒充场景数)
67
67
  4. **关门检查**(10 项)→ 只执行一次 `harness_gate.py close`;`--to-phase` 必须取返回的 `nextPhases` 或 `plannedPhases` 中 run 的真实后继,禁止写死 test。该命令内部关闭 test guard、写 `phase.end`、释放租约、写 handoff 并补传事件;不得再单独调用 test-guard/context close。失败时按结构化 `recoveryAction` 原样重试,已完成步骤幂等复用。
68
68
 
@@ -29,7 +29,7 @@ description: harness-run 的执行检查清单。仅在编码执行时读取。
29
29
  - [ ] 读取并执行 `meta/worktree.json`:如果 `requested=true` 必须创建/切换 worktree,创建失败则停止或询问用户改为主目录;禁止静默降级
30
30
  - [ ] **读取计划文件(主任务源)**:`.harness/changes/<change>/plans/<change>-plan.md` — 获取任务列表和依赖关系
31
31
  - [ ] **读取详细计划(补充参考)**:`.harness/changes/<change>/plans/<change>-implementation-detail.md`(新版必需;legacy 缺失时 🟡WARN)
32
- - [ ] **读取设计文档**:`.harness/changes/<change>/spec/<change>-design.md` 获取核心设计决策和不变项
32
+ - [ ] **读取设计文档**:`.harness/changes/<change>/plans/<change>-design.md`(v2);不存在时回退 `spec/<change>-design.md`(legacy)— 获取核心设计决策和不变项
33
33
  - [ ] **读取测试场景表**:`.harness/changes/<change>/plans/<change>-test-scenarios.md` — 获取与当前任务相关的测试场景
34
34
  - [ ] **读取验证账本**:通过 context 返回的 `executionRoot` 读取 `evidence/verification-ledger.json`(如存在)— 复用已有 compile/unitTest 结果
35
35
  - [ ] **读取任务状态**:`.harness/changes/<change>/evidence/run-task-status.md`(如存在)— 恢复上次运行状态
@@ -39,7 +39,10 @@ description: harness-run 的执行检查清单。仅在编码执行时读取。
39
39
  - [ ] 检查构建配置完整性(worktree 中确认构建配置文件存在,如 Java 的 `.mvn/maven.config`、`settings.xml`,前端的 `package.json`/lockfile 等)
40
40
  - [ ] 依赖模块预安装(worktree 中检查上游依赖是否已安装,如 Java 的 `mvn install`、前端的 `npm install`/lockfile 等)
41
41
  - [ ] 代码探索优先用 `codegraph_explore`,仅在返回不完整时补充 Read
42
+ - [ ] `harness_context.py prepare/begin` 均带 `--project .` 与 `--change <id>`(缺 `--project` 会被 argparse 直接拒)
43
+ - [ ] 交接凭证缺失时**不自行拼造**:v2 计划由 `prepare` 依据 committed 发布 journal 自动补录;仍报 `HANDOFF_REQUIRED`/`LEGACY_BOOTSTRAP_REQUIRED` 即代表发布证据不存在,回 plan 阶段查,不得用 `classify + configure-plan + close` 现编凭证
42
44
  - [ ] `harness_gate.py begin --phase run` 已返回 Plan handoff 校验通过并自动 append `phase.start`;不得手工写事件绕过
45
+ - [ ] 门禁报 `SCENARIO_MANIFEST_V2_UNSUPPORTED` 时按 `missingFields` 回规划阶段补齐场景字段后重新发布;**不得**手改 `meta/scenario-manifest.json`(派生产物,手改必致哈希漂移)
43
46
 
44
47
  ### 步骤 0.1:执行模式(无询问)
45
48
 
@@ -19,7 +19,7 @@ description: harness-run 的编译失败策略表、TDD循环详细步骤和编
19
19
 
20
20
  ## 前置条件
21
21
 
22
- - `.harness/changes/<change-name>/spec/<change-name>-design.md` 存在(含完整 frontmatter)
22
+ - 设计文档存在:`plans/<change-name>-design.md`(v2)或 `spec/<change-name>-design.md`(legacy,含完整 frontmatter),按 `shared/read-protocol.md` 的顺序取第一个
23
23
  - `.harness/changes/<change-name>/plans/<change-name>-plan.md` 存在(含完整 frontmatter)
24
24
  - `.harness/changes/<change-name>/plans/<change-name>-test-scenarios.md` 存在
25
25
  - `.harness/changes/<change-name>/plans/<change-name>-implementation-detail.md`(新版必需,legacy 缺失时 🟡WARN)
@@ -90,7 +90,7 @@ requested=true + path missing
90
90
  2. **读取并执行 worktree 决策**:读取 `.harness/changes/<change-name>/meta/worktree.json`。如果 `requested=false`,在主目录执行;如果 `requested=true` 且 worktree 存在,必须 cd 到该 worktree;如果 `requested=true` 且 worktree 不存在,必须创建 worktree,创建失败则停止或询问用户是否改为主目录执行。禁止静默降级。
91
91
  3. **读取计划文件(主任务源)**:`.harness/changes/<change-name>/plans/<change-name>-plan.md` → 获取任务列表和依赖关系
92
92
  4. **读取详细计划(补充参考)**:`.harness/changes/<change-name>/plans/<change-name>-implementation-detail.md`(新版必需,legacy 缺失时 🟡WARN)→ 获取自适应执行参考
93
- 5. **读取设计文档**:`.harness/changes/<change-name>/spec/<change-name>-design.md` 获取核心设计决策和不变项
93
+ 5. **读取设计文档**:`.harness/changes/<change-name>/plans/<change-name>-design.md`(v2 发布产物)→ 不存在时回退 `spec/<change-name>-design.md`(legacy)→ 获取核心设计决策和不变项
94
94
  6. **读取测试场景表**:`.harness/changes/<change-name>/plans/<change-name>-test-scenarios.md` → 获取测试真相源
95
95
  7. **读取验证账本**:通过 state layout resolver 定位 `evidence/verification-ledger.json`(如存在)→ 复用已有 compile/unitTest 结果
96
96
  8. **读取任务状态**:`.harness/changes/<change-name>/evidence/run-task-status.md`(如存在)→ 恢复上次运行状态
@@ -113,7 +113,7 @@ requested=true + path missing
113
113
 
114
114
  ```
115
115
  检查逻辑:
116
- 1. 读取 .harness/changes/<change-name>/spec/<change-name>-design.md
116
+ 1. 读取 .harness/changes/<change-name>/plans/<change-name>-design.md(不存在则回退 spec/<change-name>-design.md
117
117
  2. 读取 .harness/changes/<change-name>/plans/<change-name>-plan.md
118
118
  3. 读取 .harness/changes/<change-name>/plans/<change-name>-implementation-detail.md(legacy 缺失时 🟡WARN)
119
119
  4. 读取 .harness/changes/<change-name>/plans/<change-name>-test-scenarios.md
@@ -3,7 +3,7 @@ name: harness-submit
3
3
  description: 最终提交封装:验证→中文 commit→提交/推送;worktree 模式含 --no-ff 合并回主分支。仅当用户显式调用
4
4
  /harness-submit(或 /harness-merge 重入合并段)时使用;用户口头说'提交/commit/push'时必须先确认,不得自动触发。
5
5
  ---
6
- <!-- generated by harness_deploy.py; core=a4f07759d60ce2c9; overlay=none; agent=codebuddy; do not edit -->
6
+ <!-- generated by harness_deploy.py; core=d0ad43fe132b6817; overlay=none; agent=codebuddy; do not edit -->
7
7
  # harness-submit — 最终提交(含 worktree 合并)
8
8
 
9
9
  ## Purpose
@@ -30,9 +30,9 @@ description: 最终提交封装:验证→中文 commit→提交/推送;workt
30
30
  ## 统一读取协议
31
31
 
32
32
  1. **`.harness/changes/<change-name>/` 是唯一真相源** — 所有输入从该目录读取,产物写入对应子目录
33
- 2. **change-name 优先从 frontmatter 读取** — `spec/*-design.md`、`plans/*-plan.md` 的 YAML `change-name`
33
+ 2. **change-name 优先从 frontmatter 读取** — `plans/*-design.md`、`spec/*-design.md`、`plans/*-plan.md` 的 YAML `change-name`
34
34
  3. **frontmatter 缺失时兼容旧格式** — 从路径推断,标记 `🟡 legacy-plan`,不失败
35
- 4. **spec** — 设计真相源:`spec/<change>-design.md`
35
+ 4. **design** — 设计真相源按序取第一个存在的:`plans/<change>-design.md`(v2 发布产物,哈希绑定)→ `spec/<change>-design.md`(legacy 手写)。两份**同时存在**时以 `plans/` 为准,并记 `🟡 WARN 设计文档双份`——v2 发布的那份才受完整性门禁保护,读手写的那份等于绕过校验
36
36
  5. **plan** — 任务真相源:`plans/<change>-plan.md`
37
37
  6. **implementation-detail** — 自适应执行参考;legacy 缺失 🟡WARN,不阻断
38
38
  7. **test-scenarios** — 测试真相源:`plans/<change>-test-scenarios.md`
@@ -54,10 +54,11 @@ worktree 合并前必须运行 `harness_change.py integration-lock acquire --run
54
54
 
55
55
  ### 提交流程(步骤 0–7)
56
56
 
57
- 0. **启动准备** — `harness_context.py prepare --phase submit --executor <tool> [--change <id>] --json` 确定唯一变更与 executionRoot;`harness_context.py begin --phase submit --change <id> --executor <tool> --json` 校验 review→submit receipt;**`harness_gate.py begin --phase submit --change <id>`**;读 ledger,以 `harness_ledger.py diff-hash --repo <executionRoot> --base <baseCommit> --change-dir ".harness/changes/<change-name>" --json` 计算 diffHash + post-test 7 类分类(`executionRoot` 必须直接取准备回执;禁止手写 ledger / 手工 phase.end)
57
+ 0. **启动准备** — `harness_context.py prepare --project . --change <id> --phase submit --executor <tool> --json`(`--project` 必填)确定唯一变更与 executionRoot;`harness_context.py begin --project . --change <id> --phase submit --executor <tool> --json` 校验 review→submit receipt;**`harness_gate.py begin --phase submit --change <id>`**;读 ledger,以 `harness_ledger.py diff-hash --repo <executionRoot> --base <baseCommit> --change-dir ".harness/changes/<change-name>" --json` 计算 diffHash + post-test 7 类分类(`executionRoot` 必须直接取准备回执;禁止手写 ledger / 手工 phase.end)
58
58
  1. **合并最新代码** — 主目录与 worktree 均**不在业务工作区 stash/pull**;远端同步由合并段 integration transaction 在隔离 integration worktree 内完成(见「worktree 合并流程」);**正常路径禁止 `git stash` / `stash pop`**
59
59
  2. **最终验证** — ledger 复用优先;提交前只调用 `can-reuse --project . --profile-input unitTestFull --command <profile 规范命令>`。不得传入另一套 `--files`,不得把 runner 包装说明写进 `command`。`reuse=true` 时禁止重跑;只有真实输入、依赖、工具链或环境身份变化时才执行一次同一 profile 验证,并只登记一条结果。不要读取 ledger/archive 实现源码或临时编写散列脚本排查参数。
60
60
  - 无远端 CI 且 gate-policy 未强制 remote provider 时,验证通过/复用后运行 `harness_archive.py certify-local --change-dir ... --project . --json`,从同一 ledger 生成 `local-reproducible` 产品候选收据;该命令不执行测试。
61
+ - **被与本变更无关的预存失败卡住时的正规出路**:用 `harness_preflight.py record-quirk --project . --action skip-not-block --pattern "<具体错误签名,≥8 字符>" --reason "<为什么与本变更无关>"` 把它声明进 build-profile 的 `knownPreexistingErrors`,certify-local 会在**该失败的 ledger 证据里确实出现该签名**时放行,并把 `{validation, pattern, reason}` 写进收据的 `verification.preexistingExemptions` 留痕。**不得**改 gate-policy 的 `candidateVerification.requiredValidations` 来绕过——那是把门禁本身拆掉。声明了但证据对不上、或签名短到能匹配一切,仍然阻断。
61
62
  - gate-policy 要求 `remote-attested` 时不得降级成本地收据,等待远端 attestation。
62
63
  3. **.gitignore + 精确暂存** ⚠️ — 检查 `.harness/` 在 `.gitignore`;**禁止 `git add -A`**。若存在 `evidence/test-tracking.json`,先执行 `python <skills-root>/scripts/harness_test_guard.py stage --project . --change-dir ".harness/changes/<change-name>" --json`;失败即硬停止。无 manifest 时不使用 `-f`。manifest 之外的文件按精确业务路径正常暂存,**禁止全局 force-add**。
63
64
  4. **提交方式** — 主目录:blocking user confirmation 三选项(commit+push / 仅本地 / 取消);**worktree:固定仅本地 commit**
@@ -4,7 +4,7 @@ description: Use when the user asks to synchronize, refresh, or validate Harness
4
4
  metadata, adapters, remote knowledge ownership, instruction entrypoints,
5
5
  config origins, or CodeGraph status.
6
6
  ---
7
- <!-- generated by harness_deploy.py; core=a4f07759d60ce2c9; overlay=none; agent=codebuddy; do not edit -->
7
+ <!-- generated by harness_deploy.py; core=d0ad43fe132b6817; overlay=none; agent=codebuddy; do not edit -->
8
8
  # harness-sync
9
9
 
10
10
  ## Purpose
@@ -3,7 +3,7 @@ name: harness-test
3
3
  description: 测试执行:读取场景表,执行单元测试+API接口测试+数据兼容验证,输出测试报告。仅当用户显式调用 /harness-test
4
4
  时使用;不得在 run 结束后自动接续执行。
5
5
  ---
6
- <!-- generated by harness_deploy.py; core=a4f07759d60ce2c9; overlay=none; agent=codebuddy; do not edit -->
6
+ <!-- generated by harness_deploy.py; core=d0ad43fe132b6817; overlay=none; agent=codebuddy; do not edit -->
7
7
  # harness-test — 测试执行
8
8
 
9
9
  ## Purpose
@@ -32,9 +32,9 @@ description: 测试执行:读取场景表,执行单元测试+API接口测试
32
32
  ## 统一读取协议
33
33
 
34
34
  1. **`.harness/changes/<change-name>/` 是唯一真相源** — 所有输入从该目录读取,产物写入对应子目录
35
- 2. **change-name 优先从 frontmatter 读取** — `spec/*-design.md`、`plans/*-plan.md` 的 YAML `change-name`
35
+ 2. **change-name 优先从 frontmatter 读取** — `plans/*-design.md`、`spec/*-design.md`、`plans/*-plan.md` 的 YAML `change-name`
36
36
  3. **frontmatter 缺失时兼容旧格式** — 从路径推断,标记 `🟡 legacy-plan`,不失败
37
- 4. **spec** — 设计真相源:`spec/<change>-design.md`
37
+ 4. **design** — 设计真相源按序取第一个存在的:`plans/<change>-design.md`(v2 发布产物,哈希绑定)→ `spec/<change>-design.md`(legacy 手写)。两份**同时存在**时以 `plans/` 为准,并记 `🟡 WARN 设计文档双份`——v2 发布的那份才受完整性门禁保护,读手写的那份等于绕过校验
38
38
  5. **plan** — 任务真相源:`plans/<change>-plan.md`
39
39
  6. **implementation-detail** — 自适应执行参考;legacy 缺失 🟡WARN,不阻断
40
40
  7. **test-scenarios** — 测试真相源:`plans/<change>-test-scenarios.md`
@@ -85,7 +85,7 @@ Runner 强制同项目单实例、低调度优先级、逐命令超时、正常
85
85
 
86
86
  ### Phase 0:环境准备(主会话执行,需要交互确认)
87
87
 
88
- 先 `harness_context.py prepare --phase test --executor <tool> [--change <id>] --json`,再 `harness_context.py begin --phase test --change <id> --executor <tool> --json` 校验最新 run→test receipt 的 artifact/hash/HEAD;然后 **`harness_gate.py begin --phase test --change <id>`**(禁止手工 phase.start / 手写 ledger)。执行各项强制环境检查 + **命令执行模式 preflight (0.1)**;只有首选执行器不可用时,才执行 fallback 执行器探测。
88
+ 先 `harness_context.py prepare --project . --change <id> --phase test --executor <tool> --json`(`--project` 必填,漏了直接 argparse 报错),再 `harness_context.py begin --project . --change <id> --phase test --executor <tool> --json` 校验最新 run→test receipt 的 artifact/hash/HEAD;然后 **`harness_gate.py begin --phase test --change <id>`**(禁止手工 phase.start / 手写 ledger)。执行各项强制环境检查 + **命令执行模式 preflight (0.1)**;只有首选执行器不可用时,才执行 fallback 执行器探测。
89
89
 
90
90
  验证写入**仅**允许 `harness_ledger.py record` / `can-reuse`;禁止 Write/Edit `verification-ledger.json`。测试跟踪:gate begin → 执行(可选 `harness_test_guard.py mark stale-test-repair`)→ 单次 `harness_gate.py close`。`--to-phase` 取实际阶段计划的后继;Fixback 返回 run,普通流程可直接进入 Review、Submit 或 Archive。Fixback 只失效与改动文件相交的验证目标。
91
91
 
@@ -273,6 +273,8 @@ powershell.exe -NoProfile -Command "try { (Invoke-WebRequest -Uri 'http://127.0.
273
273
  - [ ] 复用 → 跳过重跑,标记"✅ 复用 harness-run 单元测试结果"
274
274
  - [ ] 不复用 → 按 profile key resolve 重跑测试命令(`harness_profile.py resolve --key unitTest`,不复制示例 `-pl` 命令),结果写回 ledger 的 `unitTest` 项
275
275
  - [ ] HTTP/API 契约结果写入 `apiTest`;真实浏览器/真实栈 Playwright 结果写入 `browserTest`,两者不得互相覆盖
276
+ - [ ] **本变更没有该维度场景时**(如全部为单元场景 → 无 API 场景):用 `harness_ledger.py record --verification apiTest --status NOT_RUN --applicability NOT_APPLICABLE --applicability-reason "<为什么不适用>"` 登记,**不传 `--files`**。门禁 close 要求 requiredValidations 每项都有 entry,但**绝不能拿无关文件(比如单元测试文件)凑 `--files`**——那会让 ledger 声称该维度的输入是那些文件,是假证据
277
+ - [ ] `can-reuse` 返回 `reuse:false` 时直接读默认输出里的 `reason`/`executionNeed`/`detail` 定位原因,不必再补跑 `--verbose`
276
278
  - [ ] 复用判断前以 `harness_ledger.py diff-hash --repo . --base <baseCommit> --change-dir ".harness/changes/<change-name>" --json` 重算指纹;test-tracking manifest 无效或 hash 漂移即停止
277
279
  - [ ] 测试失败若明确为陈旧测试,仅在当前代码/批准计划/可验证历史唯一确定新契约且只改测试时自动修复;否则记录 `BLOCKED_PREEXISTING`
278
280
  - [ ] 自动修复后立即重跑该测试与目标测试,并以 `harness_test_guard.py record ... --reason stale-test-repair` 记录精确路径
@@ -991,6 +991,62 @@ def migrate_legacy_candidate_evidence(
991
991
  return receipt
992
992
 
993
993
 
994
+ # 声明必须是具体的错误签名,不能是能匹配一切的短串。这个下限不是"安全边界"
995
+ # ——审计线索才是——但它挡住最省事的滥用写法。
996
+ _PREEXISTING_MIN_PATTERN = 8
997
+
998
+
999
+ def _known_preexisting_patterns(
1000
+ project_root: Path,
1001
+ ) -> tuple[list[dict[str, str]], list[dict[str, str]]]:
1002
+ """build-profile 里声明的预存失败签名,按"是否足够具体"分成两组。
1003
+
1004
+ `knownPreexistingErrors` 由 `harness_preflight.py record-quirk --action
1005
+ skip-not-block` 写入,此前没有任何消费方——于是预存失败在 certify-local 处
1006
+ 成为死结:要么去 gate-policy 降门禁,要么顺手改范围外的产品 bug。
1007
+ """
1008
+ path = project_root / ".harness" / "config" / "build-profile.json"
1009
+ if not path.is_file():
1010
+ return [], []
1011
+ try:
1012
+ profile = json.loads(path.read_text(encoding="utf-8-sig"))
1013
+ except (OSError, ValueError):
1014
+ return [], []
1015
+ declared = profile.get("knownPreexistingErrors") if isinstance(profile, dict) else None
1016
+ if not isinstance(declared, list):
1017
+ return [], []
1018
+ usable: list[dict[str, str]] = []
1019
+ vague: list[dict[str, str]] = []
1020
+ for item in declared:
1021
+ if not isinstance(item, dict) or item.get("action") != "skip-not-block":
1022
+ continue
1023
+ pattern = str(item.get("pattern") or "").strip()
1024
+ reason = str(item.get("reason") or "").strip()
1025
+ if not pattern or not reason:
1026
+ continue
1027
+ record = {"pattern": pattern, "reason": reason}
1028
+ (usable if len(pattern) >= _PREEXISTING_MIN_PATTERN else vague).append(record)
1029
+ return usable, vague
1030
+
1031
+
1032
+ def _match_preexisting(
1033
+ entry: dict[str, Any], patterns: list[dict[str, str]]
1034
+ ) -> dict[str, str] | None:
1035
+ """失败证据里是否确实出现了某个已声明签名。
1036
+
1037
+ 只看"声明过"是不够的——那等于声明一次豁免一切。必须是这一条失败的证据里
1038
+ 真的带着该签名,声明与现场才对得上。
1039
+ """
1040
+ evidence = entry.get("evidence")
1041
+ haystack = evidence if isinstance(evidence, str) else json.dumps(
1042
+ evidence, ensure_ascii=False, sort_keys=True
1043
+ )
1044
+ for record in patterns:
1045
+ if record["pattern"] in haystack:
1046
+ return record
1047
+ return None
1048
+
1049
+
994
1050
  def certify_local_candidate(
995
1051
  change_dir: Path,
996
1052
  *,
@@ -1029,14 +1085,28 @@ def certify_local_candidate(
1029
1085
  required = ["unitTestFull"]
1030
1086
  required = [str(item).strip() for item in required if str(item).strip()]
1031
1087
 
1088
+ usable_patterns, vague_patterns = _known_preexisting_patterns(project_root)
1089
+
1032
1090
  selected: list[dict[str, Any]] = []
1091
+ exemptions: list[dict[str, Any]] = []
1033
1092
  for name in required:
1034
1093
  entry = validations.get(name)
1035
1094
  if not isinstance(entry, dict):
1036
1095
  raise ValueError(f"required validation missing: {name}")
1037
1096
  missing: list[str] = []
1097
+ exempted = None
1038
1098
  if str(entry.get("status") or "").upper() != "OK":
1039
- missing.append("status=OK")
1099
+ exempted = _match_preexisting(entry, usable_patterns)
1100
+ if exempted is None:
1101
+ vague = _match_preexisting(entry, vague_patterns)
1102
+ if vague is not None:
1103
+ raise ValueError(
1104
+ f"required validation {name} failed and the declared "
1105
+ f"knownPreexistingErrors pattern {vague['pattern']!r} is too "
1106
+ "generic to identify it; declare the specific error signature "
1107
+ f"(at least {_PREEXISTING_MIN_PATTERN} characters)"
1108
+ )
1109
+ missing.append("status=OK")
1040
1110
  for field in (
1041
1111
  "command",
1042
1112
  "evidence",
@@ -1048,6 +1118,15 @@ def certify_local_candidate(
1048
1118
  raise ValueError(
1049
1119
  f"required validation {name} is incomplete: {', '.join(missing)}"
1050
1120
  )
1121
+ if exempted is not None:
1122
+ exemptions.append(
1123
+ {
1124
+ "validation": name,
1125
+ "status": str(entry.get("status") or "").upper(),
1126
+ "pattern": exempted["pattern"],
1127
+ "reason": exempted["reason"],
1128
+ }
1129
+ )
1051
1130
  selected.append(
1052
1131
  {
1053
1132
  "name": name,
@@ -1160,6 +1239,8 @@ def certify_local_candidate(
1160
1239
  {str(item["inputsHash"]) for item in selected}
1161
1240
  ),
1162
1241
  "logHashes": sorted({str(item["logHash"]) for item in selected}),
1242
+ # 豁免必须随收据一起留痕,否则事后无法把它与干净通过区分开
1243
+ "preexistingExemptions": exemptions,
1163
1244
  },
1164
1245
  }
1165
1246
  if rebound_from_commit is not None:
@@ -732,6 +732,16 @@ def prepare_context(
732
732
  )
733
733
  if not reselection.get("ok"):
734
734
  return reselection
735
+ # v2 计划的交接凭证由此补录:finalize 不写 context 事务,缺它 run 阶段进不去
736
+ if phase != "plan":
737
+ _bootstrap_v2_plan_transition(
738
+ project,
739
+ change,
740
+ contract_root=contract_root,
741
+ state_root=state_root,
742
+ to_phase=phase,
743
+ executor=executor,
744
+ )
735
745
  claim = _claim_prepared_context(
736
746
  project,
737
747
  change,
@@ -779,6 +789,150 @@ def prepare_context(
779
789
  }
780
790
 
781
791
 
792
+ def _plan_run_identity(change_dir: Path) -> tuple[str, int] | None:
793
+ """已存在的 plan `phase.start` 身份(run-id, attempt)。
794
+
795
+ finalize 按生命周期身份 fail-closed:重跑引导时换一个 run-id,整条链路就对不上。
796
+ 因此引导必须复用已有身份,而不是每次新生成。
797
+ """
798
+ for item in reversed(_read_ndjson(change_dir / "events.ndjson")):
799
+ if item.get("phase") != "plan" or item.get("type") != "phase.start":
800
+ continue
801
+ run_id = item.get("run_id")
802
+ if isinstance(run_id, str) and run_id:
803
+ attempt = item.get("attempt")
804
+ return run_id, attempt if isinstance(attempt, int) and attempt > 0 else 1
805
+ return None
806
+
807
+
808
+ def bootstrap_plan(
809
+ project: Path,
810
+ *,
811
+ change: str,
812
+ executor: str,
813
+ display_title: str | None = None,
814
+ stage: str = "plan",
815
+ ttl_seconds: int = 3600,
816
+ ) -> dict[str, Any]:
817
+ """阶段 0 一次性引导:doctor + prepare + capture + classify + phase.start。
818
+
819
+ 拆成五条子进程调用时,每条的完整 argv 都要调用方记住(少 `--project` 或
820
+ `--change-dir` 就白跑一轮),run-id 还要调用方自己保证小写字母开头。这些都是
821
+ 确定性工作,交给脚本做;调用方只需要一次调用和一份紧凑摘要。
822
+
823
+ 重跑安全:已有 plan `phase.start` 时复用同一 run-id / attempt,不追加第二条。
824
+ """
825
+ import uuid
826
+
827
+ import harness_change as hchg
828
+ import harness_events as he
829
+ import harness_gate as hg
830
+ import harness_runtime as hr
831
+ import harness_state as hs
832
+
833
+ project = Path(project).resolve()
834
+ changes_root = project / ".harness" / "changes"
835
+ if not changes_root.is_dir():
836
+ return {
837
+ "ok": False,
838
+ "code": "PROJECT_ROOT_INVALID",
839
+ "error": f"{changes_root} 不存在——先在该项目运行 hunter-harness init",
840
+ }
841
+
842
+ # 新 change 的目录此前没有任何脚本负责创建,靠的是后续 Write 的副作用;
843
+ # 引导阶段显式建立骨架,prepare 才有 contract 可读
844
+ change_dir = changes_root / change
845
+ created_change = not change_dir.is_dir()
846
+ if created_change:
847
+ (change_dir / "meta").mkdir(parents=True, exist_ok=True)
848
+ hchg.migrate_change(project, change)
849
+
850
+ prepared = prepare_context(
851
+ project,
852
+ phase="plan",
853
+ executor=executor,
854
+ change=change,
855
+ display_title=display_title,
856
+ ttl_seconds=ttl_seconds,
857
+ )
858
+ if not prepared.get("ok"):
859
+ return prepared
860
+
861
+ change_name = str(prepared["changeName"])
862
+ # executionRoot 是代码执行根(无 worktree 时等于项目根),change_dir 才是状态目录。
863
+ # 计划产物一律落 change_dir,混用会把 gate-policy/events 写到项目根去。
864
+ change_dir = (changes_root / change_name).resolve()
865
+ execution_root = Path(prepared["executionRoot"])
866
+
867
+ # doctor 失败不阻断引导:它是环境体检,结论随摘要返回给调用方判断
868
+ try:
869
+ health = hr.doctor(project, change_dir, agent=executor)
870
+ except Exception as exc: # noqa: BLE001 - 体检失败要报告而不是中断引导
871
+ health = {"ok": False, "code": "DOCTOR_FAILED", "error": str(exc)}
872
+
873
+ # 首次 capture 把当时的 HEAD 固定为不可变 changeBase(design §3.6)
874
+ snapshot, changed_segments = hs.capture_current_state(
875
+ project=project,
876
+ change_dir=change_dir,
877
+ change_name=change_name,
878
+ worktree_root=project,
879
+ )
880
+ git_state = snapshot.get("git") or {}
881
+
882
+ workflow = hg._load_workflow_policy(project=project)
883
+ classification = hg.classify_risk(change_dir, stage, workflow=workflow)
884
+ classification.setdefault("tierOverride", None)
885
+ classification["classifiedAt"] = _now().isoformat().replace("+00:00", "Z")
886
+ policy_path = change_dir / "meta" / "gate-policy.json"
887
+ hg._write_json(policy_path, hg.gate_policy_document(classification))
888
+
889
+ identity = _plan_run_identity(change_dir)
890
+ reused = identity is not None
891
+ if identity is None:
892
+ # v2 identity:必须小写字母开头,裸 UUID 有 10/16 概率数字开头被拒
893
+ run_id = f"plan_{uuid.uuid4()}"
894
+ attempt = 1
895
+ appended = he.append_event(
896
+ change_dir,
897
+ phase="plan",
898
+ type_="phase.start",
899
+ run_id=run_id,
900
+ attempt=attempt,
901
+ executor_tool=executor,
902
+ note=f"/harness-plan 引导:{change_name}",
903
+ )
904
+ if not appended.get("ok", True):
905
+ return appended
906
+ else:
907
+ run_id, attempt = identity
908
+
909
+ return {
910
+ "ok": True,
911
+ "code": "PLAN_BOOTSTRAPPED",
912
+ "changeName": change_name,
913
+ "displayTitle": prepared.get("displayTitle"),
914
+ "changeCreated": created_change,
915
+ "changeDir": str(change_dir),
916
+ "executionRoot": str(execution_root),
917
+ "runId": run_id,
918
+ "attempt": attempt,
919
+ "reused": reused,
920
+ "tier": classification.get("tier"),
921
+ "tierSource": classification.get("source"),
922
+ "defaultPhases": list(classification.get("defaultPhases") or []),
923
+ "conditionalPhases": list(classification.get("conditionalPhases") or []),
924
+ "requiredValidations": list(classification.get("requiredValidations") or []),
925
+ "gatePolicyPath": str(policy_path),
926
+ "plannedPhases": prepared.get("plannedPhases"),
927
+ "changeBase": git_state.get("base"),
928
+ "head": git_state.get("head"),
929
+ "changedSegments": sorted(changed_segments),
930
+ "legacyBootstrap": prepared.get("legacyBootstrap"),
931
+ "doctorOk": bool(health.get("ok", True)),
932
+ "doctor": health,
933
+ }
934
+
935
+
782
936
  def _invalidate_for_fixback(
783
937
  state_root: Path,
784
938
  *,
@@ -808,6 +962,90 @@ def _invalidate_for_fixback(
808
962
  return record
809
963
 
810
964
 
965
+ def _committed_publication_journal(contract_root: Path) -> Path | None:
966
+ """已 committed 的 v2 发布 journal —— plan 确实完成的机器证据。"""
967
+ journal_dir = contract_root / "meta" / "publication-journals"
968
+ if not journal_dir.is_dir():
969
+ return None
970
+ for path in sorted(journal_dir.glob("*.json")):
971
+ try:
972
+ payload = _read_json(path)
973
+ except (OSError, ValueError, json.JSONDecodeError):
974
+ continue
975
+ if isinstance(payload, dict) and payload.get("state") == "committed":
976
+ return path
977
+ return None
978
+
979
+
980
+ def _published_plan_artifacts(project: Path, contract_root: Path, change: str) -> list[dict[str, Any]]:
981
+ """交接携带的 v2 发布产物(存在者入账,缺失者跳过)。"""
982
+ entries: list[dict[str, Any]] = []
983
+ for rel in (
984
+ f"plans/{change}-design.md",
985
+ f"plans/{change}-plan.md",
986
+ f"plans/{change}-implementation-detail.md",
987
+ f"plans/{change}-test-scenarios.md",
988
+ "meta/scenario-manifest.json",
989
+ ):
990
+ candidate = contract_root / rel
991
+ if candidate.is_file():
992
+ entries.append(
993
+ {
994
+ "path": candidate.resolve().relative_to(project).as_posix(),
995
+ "sha256": _sha256(candidate),
996
+ }
997
+ )
998
+ return entries
999
+
1000
+
1001
+ def _bootstrap_v2_plan_transition(
1002
+ project: Path,
1003
+ change: str,
1004
+ *,
1005
+ contract_root: Path,
1006
+ state_root: Path,
1007
+ to_phase: str,
1008
+ executor: str,
1009
+ ) -> dict[str, Any] | None:
1010
+ """v2 发布已 committed 却没有交接凭证时,补录 plan → to_phase 凭证。
1011
+
1012
+ v2 plan finalize 只写 plan-events.ndjson 与发布 journal,不碰 context 事务
1013
+ 存储,于是 run 阶段 prepare 必报 HANDOFF_REQUIRED、begin 必报
1014
+ LEGACY_BOOTSTRAP_REQUIRED——两个错误都不给恢复路径,调用方只能读脚本源码
1015
+ 自己拼出 classify + configure-plan + close,参数全靠现编,可审计性更差。
1016
+
1017
+ committed 的发布 journal 是比人工 close 更强的完成证据:据此补录,并在凭证上
1018
+ 留 bootstrapSource/bootstrapEvidence,事后能与人工 close 区分。没有该证据时
1019
+ 返回 None,交接继续 fail-closed。
1020
+ """
1021
+ paths = _paths(state_root)
1022
+ if _read_ndjson(paths["transitions"]):
1023
+ return None
1024
+ if to_phase not in _allowed_next_phases(contract_root, "plan"):
1025
+ return None
1026
+ journal = _committed_publication_journal(contract_root)
1027
+ if journal is None:
1028
+ return None
1029
+ receipt: dict[str, Any] = {
1030
+ "schemaVersion": 1,
1031
+ "changeName": change,
1032
+ "fromPhase": "plan",
1033
+ "toPhase": to_phase,
1034
+ "status": "OK",
1035
+ "executor": executor,
1036
+ "productCommit": _head(project),
1037
+ "artifacts": _published_plan_artifacts(project, contract_root, change),
1038
+ "attempt": 1,
1039
+ "closedAt": _now().isoformat(),
1040
+ "previousReceiptHash": None,
1041
+ "bootstrapSource": "plan_publication_journal",
1042
+ "bootstrapEvidence": journal.resolve().relative_to(project).as_posix(),
1043
+ }
1044
+ receipt["receiptHash"] = _payload_hash(receipt)
1045
+ _append_ndjson(paths["transitions"], receipt)
1046
+ return receipt
1047
+
1048
+
811
1049
  def close_transition(
812
1050
  project: Path,
813
1051
  change: str,
@@ -1007,11 +1245,26 @@ def _begin_transition_unlocked(
1007
1245
  "message": "本次修复准备凭证与当前上下文不一致,未启动新阶段。",
1008
1246
  }
1009
1247
  transitions = _read_ndjson(paths["transitions"])
1248
+ if not transitions and phase != "plan":
1249
+ # prepare 之外的入口(或跳过了 prepare)同样要能从发布证据恢复
1250
+ _bootstrap_v2_plan_transition(
1251
+ project,
1252
+ change,
1253
+ contract_root=contract_root,
1254
+ state_root=state_root,
1255
+ to_phase=phase,
1256
+ executor=executor,
1257
+ )
1258
+ transitions = _read_ndjson(paths["transitions"])
1010
1259
  if not transitions:
1011
1260
  return {
1012
1261
  "ok": False,
1013
1262
  "code": "LEGACY_BOOTSTRAP_REQUIRED",
1014
1263
  "legacyBootstrap": True,
1264
+ "message": (
1265
+ "没有交接凭证。v2 计划应有 committed 的 meta/publication-journals/*.json "
1266
+ "作为补录证据;legacy 计划需先完成 plan 阶段的 close"
1267
+ ),
1015
1268
  }
1016
1269
  receipt = transitions[-1]
1017
1270
  if receipt.get("toPhase") != phase:
@@ -1256,6 +1509,14 @@ def build_parser() -> argparse.ArgumentParser:
1256
1509
  prepare.add_argument("--title")
1257
1510
  prepare.add_argument("--ttl-seconds", type=int, default=3600)
1258
1511
  prepare.add_argument("--trigger", choices=["review-fixback"])
1512
+ bootstrap = sub.add_parser("bootstrap-plan")
1513
+ bootstrap.add_argument("--json", action="store_true")
1514
+ bootstrap.add_argument("--project", required=True, type=Path)
1515
+ bootstrap.add_argument("--change", required=True)
1516
+ bootstrap.add_argument("--executor", required=True)
1517
+ bootstrap.add_argument("--title")
1518
+ bootstrap.add_argument("--stage", default="plan", choices=["plan", "post-run"])
1519
+ bootstrap.add_argument("--ttl-seconds", type=int, default=3600)
1259
1520
  close = sub.add_parser("close")
1260
1521
  close.add_argument("--json", action="store_true")
1261
1522
  close.add_argument("--project", required=True, type=Path)
@@ -1297,6 +1558,15 @@ def main(argv: list[str] | None = None) -> int:
1297
1558
  ttl_seconds=args.ttl_seconds,
1298
1559
  trigger=args.trigger,
1299
1560
  )
1561
+ elif args.command == "bootstrap-plan":
1562
+ result = bootstrap_plan(
1563
+ args.project,
1564
+ change=args.change,
1565
+ executor=args.executor,
1566
+ display_title=args.title,
1567
+ stage=args.stage,
1568
+ ttl_seconds=args.ttl_seconds,
1569
+ )
1300
1570
  elif args.command == "close":
1301
1571
  result = close_transition(
1302
1572
  args.project,