agentic-flow-kit 1.8.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (936) hide show
  1. package/README.md +113 -148
  2. package/bin/flow-kit.mjs +5 -2
  3. package/locales/en/installer.json +25 -0
  4. package/locales/en/overrides/.agents/commands/deploy.md +52 -0
  5. package/locales/en/overrides/.agents/commands/maintain.md +76 -0
  6. package/locales/en/overrides/.agents/commands/new-task.md +89 -0
  7. package/locales/en/overrides/.agents/commands/pipeline-run.md +56 -0
  8. package/locales/en/overrides/.agents/commands/pr-review.md +30 -0
  9. package/locales/en/overrides/.agents/commands/review.md +93 -0
  10. package/locales/en/overrides/.agents/commands/stages.md +256 -0
  11. package/locales/en/overrides/.agents/notes/pr-review-cost-discipline.md +48 -0
  12. package/locales/en/overrides/.agents/notes/process-order-rule.md +21 -0
  13. package/locales/en/overrides/.agents/notes/runtime-env.local.example.md +21 -0
  14. package/locales/en/overrides/.agents/pipelines/_TEMPLATE.md +75 -0
  15. package/locales/en/overrides/.agents/pipelines/pipeline-closing.md +28 -0
  16. package/locales/en/overrides/.agents/roles/implementer.md +28 -0
  17. package/locales/en/overrides/.agents/roles/independent-reviewer.md +39 -0
  18. package/locales/en/overrides/.agents/roles/pr-adjudicator.md +27 -0
  19. package/locales/en/overrides/.agents/roles/pr-finder.md +51 -0
  20. package/locales/en/overrides/.agents/roles/pr-verifier.md +44 -0
  21. package/locales/en/overrides/.agents/roles/ui-verifier.md +22 -0
  22. package/locales/en/overrides/.agents/roles/wiki-compiler.md +47 -0
  23. package/locales/en/overrides/.agents/skills/arena/SKILL.md +50 -0
  24. package/locales/en/overrides/.agents/skills/autonomous-run/SKILL.md +45 -0
  25. package/locales/en/overrides/.agents/skills/blast-radius/SKILL.md +53 -0
  26. package/locales/en/overrides/.agents/skills/csharp-quality-gates/SKILL.md +109 -0
  27. package/locales/en/overrides/.agents/skills/dev-tour/SKILL.md +98 -0
  28. package/locales/en/overrides/.agents/skills/dream/SKILL.md +63 -0
  29. package/locales/en/overrides/.agents/skills/eval/SKILL.md +42 -0
  30. package/locales/en/overrides/.agents/skills/interrogate/SKILL.md +49 -0
  31. package/locales/en/overrides/.agents/skills/number-vetting/SKILL.md +35 -0
  32. package/locales/en/overrides/.agents/skills/page-refactor/SKILL.md +192 -0
  33. package/locales/en/overrides/.agents/skills/papercut-fix/SKILL.md +92 -0
  34. package/locales/en/overrides/.agents/skills/pause-safely/SKILL.md +31 -0
  35. package/locales/en/overrides/.agents/skills/perf/SKILL.md +42 -0
  36. package/locales/en/overrides/.agents/skills/review-method/SKILL.md +92 -0
  37. package/locales/en/overrides/.agents/skills/session-resume/SKILL.md +69 -0
  38. package/locales/en/overrides/.agents/skills/shipyard-workflow-closeout/SKILL.md +109 -0
  39. package/locales/en/overrides/.agents/skills/show-me-your-work/SKILL.md +57 -0
  40. package/locales/en/overrides/.agents/skills/tfs-pr/SKILL.md +95 -0
  41. package/locales/en/overrides/.agents/skills/verify-ui/SKILL.md +116 -0
  42. package/locales/en/overrides/.agents/skills/visual-parity/SKILL.md +35 -0
  43. package/locales/en/overrides/.agents/skills/why/SKILL.md +56 -0
  44. package/locales/en/overrides/.agents/skills/wiki/SKILL.md +53 -0
  45. package/locales/en/overrides/.claude/agents/implementer.md +9 -0
  46. package/locales/en/overrides/.claude/agents/independent-reviewer.md +10 -0
  47. package/locales/en/overrides/.claude/agents/pr-adjudicator.md +10 -0
  48. package/locales/en/overrides/.claude/agents/pr-finder.md +10 -0
  49. package/locales/en/overrides/.claude/agents/pr-verifier.md +10 -0
  50. package/locales/en/overrides/.claude/agents/ui-verifier.md +10 -0
  51. package/locales/en/overrides/.claude/agents/wiki-compiler.md +10 -0
  52. package/locales/en/overrides/.claude/commands/wf-deploy.md +8 -0
  53. package/locales/en/overrides/.claude/commands/wf-maintain.md +8 -0
  54. package/locales/en/overrides/.claude/commands/wf-new-task.md +8 -0
  55. package/locales/en/overrides/.claude/commands/wf-pipeline-run.md +8 -0
  56. package/locales/en/overrides/.claude/commands/wf-pr-review.md +8 -0
  57. package/locales/en/overrides/.claude/commands/wf-review.md +8 -0
  58. package/locales/en/overrides/.claude/commands/wf-stages.md +8 -0
  59. package/locales/en/overrides/.cline/agents/implementer.yml +13 -0
  60. package/locales/en/overrides/.cline/agents/independent-reviewer.yml +11 -0
  61. package/locales/en/overrides/.cline/agents/pr-adjudicator.yml +11 -0
  62. package/locales/en/overrides/.cline/agents/pr-finder.yml +11 -0
  63. package/locales/en/overrides/.cline/agents/pr-verifier.yml +11 -0
  64. package/locales/en/overrides/.cline/agents/ui-verifier.yml +8 -0
  65. package/locales/en/overrides/.cline/agents/wiki-compiler.yml +14 -0
  66. package/locales/en/overrides/.cline/workflows/wf-deploy.md +8 -0
  67. package/locales/en/overrides/.cline/workflows/wf-maintain.md +8 -0
  68. package/locales/en/overrides/.cline/workflows/wf-new-task.md +8 -0
  69. package/locales/en/overrides/.cline/workflows/wf-pipeline-run.md +8 -0
  70. package/locales/en/overrides/.cline/workflows/wf-pr-review.md +8 -0
  71. package/locales/en/overrides/.cline/workflows/wf-review.md +8 -0
  72. package/locales/en/overrides/.cline/workflows/wf-stages.md +8 -0
  73. package/locales/en/overrides/.codebuddy/CODEBUDDY.md +7 -0
  74. package/locales/en/overrides/.codebuddy/agents/implementer.md +9 -0
  75. package/locales/en/overrides/.codebuddy/agents/independent-reviewer.md +10 -0
  76. package/locales/en/overrides/.codebuddy/agents/pr-adjudicator.md +10 -0
  77. package/locales/en/overrides/.codebuddy/agents/pr-finder.md +10 -0
  78. package/locales/en/overrides/.codebuddy/agents/pr-verifier.md +10 -0
  79. package/locales/en/overrides/.codebuddy/agents/ui-verifier.md +11 -0
  80. package/locales/en/overrides/.codebuddy/agents/wiki-compiler.md +10 -0
  81. package/locales/en/overrides/.codebuddy/commands/wf-deploy.md +8 -0
  82. package/locales/en/overrides/.codebuddy/commands/wf-maintain.md +8 -0
  83. package/locales/en/overrides/.codebuddy/commands/wf-new-task.md +8 -0
  84. package/locales/en/overrides/.codebuddy/commands/wf-pipeline-run.md +8 -0
  85. package/locales/en/overrides/.codebuddy/commands/wf-pr-review.md +8 -0
  86. package/locales/en/overrides/.codebuddy/commands/wf-review.md +8 -0
  87. package/locales/en/overrides/.codebuddy/commands/wf-stages.md +8 -0
  88. package/locales/en/overrides/.codebuddy/rules/backend-scope.md +5 -0
  89. package/locales/en/overrides/.codebuddy/rules/frontend-scope.md +5 -0
  90. package/locales/en/overrides/.codebuddy/skills/tfs-pr/SKILL.md +6 -0
  91. package/locales/en/overrides/.commandcode/agents/implementer.md +10 -0
  92. package/locales/en/overrides/.commandcode/agents/independent-reviewer.md +9 -0
  93. package/locales/en/overrides/.commandcode/agents/pr-adjudicator.md +9 -0
  94. package/locales/en/overrides/.commandcode/agents/pr-finder.md +9 -0
  95. package/locales/en/overrides/.commandcode/agents/pr-verifier.md +9 -0
  96. package/locales/en/overrides/.commandcode/agents/ui-verifier.md +10 -0
  97. package/locales/en/overrides/.commandcode/agents/wiki-compiler.md +10 -0
  98. package/locales/en/overrides/.commandcode/commands/wf-deploy.md +7 -0
  99. package/locales/en/overrides/.commandcode/commands/wf-maintain.md +7 -0
  100. package/locales/en/overrides/.commandcode/commands/wf-new-task.md +7 -0
  101. package/locales/en/overrides/.commandcode/commands/wf-pipeline-run.md +7 -0
  102. package/locales/en/overrides/.commandcode/commands/wf-pr-review.md +7 -0
  103. package/locales/en/overrides/.commandcode/commands/wf-review.md +7 -0
  104. package/locales/en/overrides/.commandcode/commands/wf-stages.md +7 -0
  105. package/locales/en/overrides/.opencode/agents/implementer.md +51 -0
  106. package/locales/en/overrides/.opencode/agents/independent-reviewer.md +18 -0
  107. package/locales/en/overrides/.opencode/agents/pr-adjudicator.md +18 -0
  108. package/locales/en/overrides/.opencode/agents/pr-finder.md +18 -0
  109. package/locales/en/overrides/.opencode/agents/pr-verifier.md +18 -0
  110. package/locales/en/overrides/.opencode/agents/ui-verifier.md +45 -0
  111. package/locales/en/overrides/.opencode/agents/wiki-compiler.md +51 -0
  112. package/locales/en/overrides/.opencode/commands/wf-deploy.md +7 -0
  113. package/locales/en/overrides/.opencode/commands/wf-maintain.md +7 -0
  114. package/locales/en/overrides/.opencode/commands/wf-new-task.md +7 -0
  115. package/locales/en/overrides/.opencode/commands/wf-pipeline-run.md +7 -0
  116. package/locales/en/overrides/.opencode/commands/wf-pr-review.md +7 -0
  117. package/locales/en/overrides/.opencode/commands/wf-review.md +7 -0
  118. package/locales/en/overrides/.opencode/commands/wf-stages.md +7 -0
  119. package/locales/en/overrides/.pi/agents/implementer.md +11 -0
  120. package/locales/en/overrides/.pi/agents/independent-reviewer.md +12 -0
  121. package/locales/en/overrides/.pi/agents/pr-adjudicator.md +12 -0
  122. package/locales/en/overrides/.pi/agents/pr-finder.md +11 -0
  123. package/locales/en/overrides/.pi/agents/pr-verifier.md +11 -0
  124. package/locales/en/overrides/.pi/agents/ui-verifier.md +11 -0
  125. package/locales/en/overrides/.pi/agents/wiki-compiler.md +11 -0
  126. package/locales/en/overrides/.qoder/agents/implementer.md +9 -0
  127. package/locales/en/overrides/.qoder/agents/independent-reviewer.md +10 -0
  128. package/locales/en/overrides/.qoder/agents/pr-adjudicator.md +10 -0
  129. package/locales/en/overrides/.qoder/agents/pr-finder.md +10 -0
  130. package/locales/en/overrides/.qoder/agents/pr-verifier.md +10 -0
  131. package/locales/en/overrides/.qoder/agents/ui-verifier.md +10 -0
  132. package/locales/en/overrides/.qoder/agents/wiki-compiler.md +10 -0
  133. package/locales/en/overrides/.qoder/commands/wf-deploy.md +8 -0
  134. package/locales/en/overrides/.qoder/commands/wf-maintain.md +8 -0
  135. package/locales/en/overrides/.qoder/commands/wf-new-task.md +8 -0
  136. package/locales/en/overrides/.qoder/commands/wf-pipeline-run.md +8 -0
  137. package/locales/en/overrides/.qoder/commands/wf-pr-review.md +8 -0
  138. package/locales/en/overrides/.qoder/commands/wf-review.md +8 -0
  139. package/locales/en/overrides/.qoder/commands/wf-stages.md +8 -0
  140. package/locales/en/overrides/.qwen/agents/implementer.md +10 -0
  141. package/locales/en/overrides/.qwen/agents/independent-reviewer.md +10 -0
  142. package/locales/en/overrides/.qwen/agents/pr-adjudicator.md +10 -0
  143. package/locales/en/overrides/.qwen/agents/pr-finder.md +10 -0
  144. package/locales/en/overrides/.qwen/agents/pr-verifier.md +10 -0
  145. package/locales/en/overrides/.qwen/agents/ui-verifier.md +10 -0
  146. package/locales/en/overrides/.qwen/agents/wiki-compiler.md +13 -0
  147. package/locales/en/overrides/.qwen/commands/wf-deploy.md +7 -0
  148. package/locales/en/overrides/.qwen/commands/wf-maintain.md +7 -0
  149. package/locales/en/overrides/.qwen/commands/wf-new-task.md +7 -0
  150. package/locales/en/overrides/.qwen/commands/wf-pipeline-run.md +7 -0
  151. package/locales/en/overrides/.qwen/commands/wf-pr-review.md +7 -0
  152. package/locales/en/overrides/.qwen/commands/wf-review.md +7 -0
  153. package/locales/en/overrides/.qwen/commands/wf-stages.md +7 -0
  154. package/locales/en/overrides/.trae/agents/implementer.md +9 -0
  155. package/locales/en/overrides/.trae/agents/independent-reviewer.md +10 -0
  156. package/locales/en/overrides/.trae/agents/pr-adjudicator.md +10 -0
  157. package/locales/en/overrides/.trae/agents/pr-finder.md +10 -0
  158. package/locales/en/overrides/.trae/agents/pr-verifier.md +10 -0
  159. package/locales/en/overrides/.trae/agents/ui-verifier.md +10 -0
  160. package/locales/en/overrides/.trae/agents/wiki-compiler.md +10 -0
  161. package/locales/en/overrides/.trae/commands/wf-deploy.md +8 -0
  162. package/locales/en/overrides/.trae/commands/wf-maintain.md +8 -0
  163. package/locales/en/overrides/.trae/commands/wf-new-task.md +8 -0
  164. package/locales/en/overrides/.trae/commands/wf-pipeline-run.md +8 -0
  165. package/locales/en/overrides/.trae/commands/wf-pr-review.md +8 -0
  166. package/locales/en/overrides/.trae/commands/wf-review.md +8 -0
  167. package/locales/en/overrides/.trae/commands/wf-stages.md +8 -0
  168. package/locales/en/overrides/.trae/rules/backend-scope.md +5 -0
  169. package/locales/en/overrides/.trae/rules/frontend-scope.md +5 -0
  170. package/locales/en/overrides/.zcode/agents/implementer.md +8 -0
  171. package/locales/en/overrides/.zcode/agents/independent-reviewer.md +8 -0
  172. package/locales/en/overrides/.zcode/agents/ui-verifier.md +8 -0
  173. package/locales/en/overrides/.zcode/agents/wiki-compiler.md +8 -0
  174. package/locales/en/overrides/AGENTS.md +52 -0
  175. package/locales/en/overrides/CLAUDE.md +20 -0
  176. package/locales/en/overrides/wiki/INDEX.md +33 -0
  177. package/locales/en/overrides/wiki/drafts-archive/README.md +6 -0
  178. package/locales/en/overrides/wiki//346/225/260/346/215/256/347/273/264/346/212/244/README.md +22 -0
  179. package/locales/en/overrides/wiki//347/237/245/350/257/206/346/262/211/346/267/200/346/200/273/350/247/210.html +230 -0
  180. package/locales/en/overrides/workflow/INDEX.md +13 -0
  181. package/locales/en/overrides/workflow/README.md +67 -0
  182. package/locales/en/overrides/workflow/archive/README.md +3 -0
  183. package/locales/en/overrides/workflow/delegations.md +4 -0
  184. package/locales/en/overrides/workflow/effective-policy.md +4 -0
  185. package/locales/en/overrides/workflow/gate-cost.md +4 -0
  186. package/locales/en/overrides/workflow/incidents/_TEMPLATE.md +49 -0
  187. package/locales/en/overrides/workflow/intents/_TEMPLATE.md +43 -0
  188. package/locales/en/overrides/workflow/metrics.md +4 -0
  189. package/locales/en/overrides/workflow/papercuts.md +3 -0
  190. package/locales/en/overrides/workflow/plans/_TEMPLATE.md +47 -0
  191. package/locales/en/overrides/workflow/regression-checklist.md +3 -0
  192. package/locales/en/overrides/workflow/specs/_TEMPLATE.md +86 -0
  193. package/locales/en/overrides/workflow/verify-evidence.md +4 -0
  194. package/locales/zh-CN/installer.json +25 -0
  195. package/package.json +23 -36
  196. package/schemas/install-manifest.schema.json +24 -0
  197. package/schemas/project-profile.schema.json +28 -0
  198. package/src/cli/args.mjs +41 -0
  199. package/src/cli/main.mjs +72 -0
  200. package/src/commands/add-host.mjs +29 -0
  201. package/src/commands/doctor.mjs +80 -0
  202. package/src/commands/install.mjs +149 -0
  203. package/src/commands/upgrade.mjs +30 -0
  204. package/src/git/config.mjs +61 -0
  205. package/src/hosts/registry.mjs +26 -0
  206. package/src/i18n.mjs +32 -0
  207. package/src/install/apply.mjs +124 -0
  208. package/src/install/manifest.mjs +40 -0
  209. package/src/install/plan.mjs +83 -0
  210. package/src/render/tokens.mjs +58 -0
  211. package/templates/engine/.agents/board/dev-tour.html +1940 -0
  212. package/templates/engine/.agents/board/index.html +835 -0
  213. package/templates/engine/.agents/commands/deploy.md +52 -0
  214. package/templates/engine/.agents/commands/maintain.md +76 -0
  215. package/templates/engine/.agents/commands/new-task.md +89 -0
  216. package/templates/engine/.agents/commands/pipeline-run.md +56 -0
  217. package/templates/engine/.agents/commands/pr-review.md +30 -0
  218. package/templates/engine/.agents/commands/review.md +93 -0
  219. package/templates/engine/.agents/commands/stages.md +256 -0
  220. package/templates/engine/.agents/config/commit-msg-rules.json +7 -0
  221. package/templates/engine/.agents/config/engine.json +11 -0
  222. package/templates/engine/.agents/config/gate-budgets.json +5 -0
  223. package/templates/engine/.agents/config/mechanism-registry.md +62 -0
  224. package/templates/engine/.agents/config/model-roles.json +26 -0
  225. package/templates/engine/.agents/config/model-roles.local.example.json +7 -0
  226. package/templates/engine/.agents/config/pr-review.json +67 -0
  227. package/templates/engine/.agents/config/principles.md +32 -0
  228. package/templates/engine/.agents/config/workflow-enums.txt +25 -0
  229. package/templates/engine/.agents/hooks/check-architecture.mjs +168 -0
  230. package/templates/engine/.agents/hooks/check-audit-fields.mjs +56 -0
  231. package/templates/engine/.agents/hooks/check-commit-plan-ref.mjs +84 -0
  232. package/templates/engine/.agents/hooks/check-confirm-order.mjs +281 -0
  233. package/templates/engine/.agents/hooks/check-delete-guard.mjs +63 -0
  234. package/templates/engine/.agents/hooks/check-notify-guard.mjs +55 -0
  235. package/templates/engine/.agents/hooks/commit-check.cjs +208 -0
  236. package/templates/engine/.agents/hooks/gates.json +33 -0
  237. package/templates/engine/.agents/hooks/local-pre-commit.mjs +27 -0
  238. package/templates/engine/.agents/hooks/pre-shell-check.cjs +361 -0
  239. package/templates/engine/.agents/hooks/pre-write-check.cjs +220 -0
  240. package/templates/engine/.agents/notes/gate-diet.md +75 -0
  241. package/templates/engine/.agents/notes/pr-review-cost-discipline.md +48 -0
  242. package/templates/engine/.agents/notes/process-order-rule.md +21 -0
  243. package/templates/engine/.agents/notes/runtime-env.local.example.md +21 -0
  244. package/templates/engine/.agents/pipelines/_TEMPLATE.md +75 -0
  245. package/templates/engine/.agents/pipelines/pipeline-closing.md +28 -0
  246. package/templates/engine/.agents/pipelines//347/244/272/344/276/213-/345/271/266/350/241/214/345/256/236/347/216/260/350/257/204/345/256/241.md +16 -0
  247. package/templates/engine/.agents/roles/implementer.md +28 -0
  248. package/templates/engine/.agents/roles/independent-reviewer.md +39 -0
  249. package/templates/engine/.agents/roles/pr-adjudicator.md +27 -0
  250. package/templates/engine/.agents/roles/pr-finder.md +51 -0
  251. package/templates/engine/.agents/roles/pr-verifier.md +44 -0
  252. package/templates/engine/.agents/roles/ui-verifier.md +22 -0
  253. package/templates/engine/.agents/roles/wiki-compiler.md +47 -0
  254. package/templates/engine/.agents/scripts/agg-delegations.mjs +439 -0
  255. package/templates/engine/.agents/scripts/agg-judgments.mjs +301 -0
  256. package/templates/engine/.agents/scripts/agg-kb-usage.mjs +196 -0
  257. package/templates/engine/.agents/scripts/append-compensation.mjs +109 -0
  258. package/templates/engine/.agents/scripts/archive-sweep.mjs +229 -0
  259. package/templates/engine/.agents/scripts/auto-tour.mjs +77 -0
  260. package/templates/engine/.agents/scripts/board-port.mjs +17 -0
  261. package/templates/engine/.agents/scripts/check-doc-body-drift.mjs +102 -0
  262. package/templates/engine/.agents/scripts/check-engine-artifacts.mjs +54 -0
  263. package/templates/engine/.agents/scripts/check-hook-wiring.mjs +75 -0
  264. package/templates/engine/.agents/scripts/check-lane-surface.mjs +393 -0
  265. package/templates/engine/.agents/scripts/check-ledger-doc-presence.mjs +71 -0
  266. package/templates/engine/.agents/scripts/check-ledger-invariant.mjs +873 -0
  267. package/templates/engine/.agents/scripts/check-local-gate-config.mjs +95 -0
  268. package/templates/engine/.agents/scripts/check-local-gates.mjs +248 -0
  269. package/templates/engine/.agents/scripts/check-loop-kit.mjs +550 -0
  270. package/templates/engine/.agents/scripts/check-loop-rev-semantics.mjs +59 -0
  271. package/templates/engine/.agents/scripts/check-loop-sections/s01-pairing.mjs +116 -0
  272. package/templates/engine/.agents/scripts/check-loop-sections/s03x-regr-evidence.mjs +38 -0
  273. package/templates/engine/.agents/scripts/check-loop-sections/s08-acceptance.mjs +130 -0
  274. package/templates/engine/.agents/scripts/check-loop-sections/s15-fingerprint.mjs +152 -0
  275. package/templates/engine/.agents/scripts/check-loop-sections/s23-convergence-audit.mjs +182 -0
  276. package/templates/engine/.agents/scripts/check-loop-sections/s29-regr-enforcer.mjs +69 -0
  277. package/templates/engine/.agents/scripts/check-loop.mjs +131 -0
  278. package/templates/engine/.agents/scripts/check-regression-consistency.mjs +252 -0
  279. package/templates/engine/.agents/scripts/check-schema-residue.mjs +144 -0
  280. package/templates/engine/.agents/scripts/check-scope-range.mjs +156 -0
  281. package/templates/engine/.agents/scripts/check-scope.mjs +121 -0
  282. package/templates/engine/.agents/scripts/check-scripts-syntax.mjs +138 -0
  283. package/templates/engine/.agents/scripts/check-secrets-lite.mjs +239 -0
  284. package/templates/engine/.agents/scripts/check-secrets.mjs +104 -0
  285. package/templates/engine/.agents/scripts/check-test-impact-map.mjs +107 -0
  286. package/templates/engine/.agents/scripts/ci-assert-frontend-deps.mjs +42 -0
  287. package/templates/engine/.agents/scripts/ci-commit-hygiene.mjs +86 -0
  288. package/templates/engine/.agents/scripts/ci-install-gitleaks.mjs +75 -0
  289. package/templates/engine/.agents/scripts/ci-push-before.mjs +49 -0
  290. package/templates/engine/.agents/scripts/closeout.mjs +127 -0
  291. package/templates/engine/.agents/scripts/compact-ledgers.mjs +70 -0
  292. package/templates/engine/.agents/scripts/confirm-doc.mjs +737 -0
  293. package/templates/engine/.agents/scripts/delegation-presence.mjs +38 -0
  294. package/templates/engine/.agents/scripts/dev-tour-model.mjs +1398 -0
  295. package/templates/engine/.agents/scripts/dream-run.mjs +283 -0
  296. package/templates/engine/.agents/scripts/ensure-board.mjs +187 -0
  297. package/templates/engine/.agents/scripts/failure-attribution.mjs +11 -0
  298. package/templates/engine/.agents/scripts/fill-intent.mjs +60 -0
  299. package/templates/engine/.agents/scripts/fill-plan.mjs +105 -0
  300. package/templates/engine/.agents/scripts/fill-spec.mjs +72 -0
  301. package/templates/engine/.agents/scripts/gen-dev-tour.mjs +191 -0
  302. package/templates/engine/.agents/scripts/gen-effective-policy.mjs +113 -0
  303. package/templates/engine/.agents/scripts/gen-engine-map.mjs +292 -0
  304. package/templates/engine/.agents/scripts/gen-narrative-claims.mjs +275 -0
  305. package/templates/engine/.agents/scripts/gen-verify-evidence.mjs +115 -0
  306. package/templates/engine/.agents/scripts/gen-wiki-board.mjs +221 -0
  307. package/templates/engine/.agents/scripts/gen-workflow-index.mjs +201 -0
  308. package/templates/engine/.agents/scripts/gen-workflow-metrics.mjs +692 -0
  309. package/templates/engine/.agents/scripts/git-merge-jsonl.mjs +62 -0
  310. package/templates/engine/.agents/scripts/judgment-ledger.mjs +68 -0
  311. package/templates/engine/.agents/scripts/kb-cache-evict.mjs +50 -0
  312. package/templates/engine/.agents/scripts/kb-search.mjs +423 -0
  313. package/templates/engine/.agents/scripts/lane-surface-audit.mjs +145 -0
  314. package/templates/engine/.agents/scripts/ledger-loader.mjs +77 -0
  315. package/templates/engine/.agents/scripts/ledger-shards.mjs +346 -0
  316. package/templates/engine/.agents/scripts/metrics-core.mjs +131 -0
  317. package/templates/engine/.agents/scripts/pipeline-run.mjs +964 -0
  318. package/templates/engine/.agents/scripts/policy.mjs +250 -0
  319. package/templates/engine/.agents/scripts/pr-create.mjs +54 -0
  320. package/templates/engine/.agents/scripts/pr-review.mjs +1551 -0
  321. package/templates/engine/.agents/scripts/quote-grounding.mjs +233 -0
  322. package/templates/engine/.agents/scripts/regen-ledgers.mjs +59 -0
  323. package/templates/engine/.agents/scripts/rewrite-file.mjs +135 -0
  324. package/templates/engine/.agents/scripts/rule-budget.mjs +246 -0
  325. package/templates/engine/.agents/scripts/stage-gates.mjs +812 -0
  326. package/templates/engine/.agents/scripts/test-impact-lib.mjs +451 -0
  327. package/templates/engine/.agents/scripts/test-impact.mjs +105 -0
  328. package/templates/engine/.agents/scripts/trust-mode.mjs +130 -0
  329. package/templates/engine/.agents/scripts/verify-scope.mjs +163 -0
  330. package/templates/engine/.agents/scripts/verify-wiki-consistency.mjs +264 -0
  331. package/templates/engine/.agents/scripts/verify.mjs +847 -0
  332. package/templates/engine/.agents/scripts/warn-format.mjs +57 -0
  333. package/templates/engine/.agents/scripts/wf-journal.mjs +230 -0
  334. package/templates/engine/.agents/scripts/workflow-board-server.mjs +696 -0
  335. package/templates/engine/.agents/scripts/workflow-enums.mjs +70 -0
  336. package/templates/engine/.agents/scripts/workflows-check.mjs +260 -0
  337. package/templates/engine/.agents/settings.json +33 -0
  338. package/templates/engine/.agents/skills/arena/SKILL.md +50 -0
  339. package/templates/engine/.agents/skills/autonomous-run/SKILL.md +45 -0
  340. package/templates/engine/.agents/skills/blast-radius/SKILL.md +53 -0
  341. package/templates/engine/.agents/skills/csharp-quality-gates/SKILL.md +109 -0
  342. package/templates/engine/.agents/skills/csharp-quality-gates/scripts/quality-gates.mjs +430 -0
  343. package/templates/engine/.agents/skills/dev-tour/SKILL.md +98 -0
  344. package/templates/engine/.agents/skills/dream/SKILL.md +63 -0
  345. package/templates/engine/.agents/skills/eval/SKILL.md +42 -0
  346. package/templates/engine/.agents/skills/eval/scripts/eval-score.mjs +59 -0
  347. package/templates/engine/.agents/skills/interrogate/SKILL.md +49 -0
  348. package/templates/engine/.agents/skills/interrogate/scripts/interrogate-plan.mjs +72 -0
  349. package/templates/engine/.agents/skills/number-vetting/SKILL.md +35 -0
  350. package/templates/engine/.agents/skills/page-refactor/SKILL.md +192 -0
  351. package/templates/engine/.agents/skills/page-refactor/references/templates.md +989 -0
  352. package/templates/engine/.agents/skills/papercut-fix/SKILL.md +92 -0
  353. package/templates/engine/.agents/skills/papercut-fix/references/response-template.md +81 -0
  354. package/templates/engine/.agents/skills/pause-safely/SKILL.md +31 -0
  355. package/templates/engine/.agents/skills/perf/SKILL.md +42 -0
  356. package/templates/engine/.agents/skills/review-method/SKILL.md +92 -0
  357. package/templates/engine/.agents/skills/review-method/golden-set.md +61 -0
  358. package/templates/engine/.agents/skills/session-resume/SKILL.md +69 -0
  359. package/templates/engine/.agents/skills/session-resume/scripts/worktree-audit.mjs +110 -0
  360. package/templates/engine/.agents/skills/shipyard-workflow-closeout/SKILL.md +109 -0
  361. package/templates/engine/.agents/skills/show-me-your-work/SKILL.md +57 -0
  362. package/templates/engine/.agents/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
  363. package/templates/engine/.agents/skills/show-me-your-work/scripts/decision-log.mjs +24 -0
  364. package/templates/engine/.agents/skills/tfs-pr/SKILL.md +95 -0
  365. package/templates/engine/.agents/skills/tfs-pr/scripts/tfs-pr.mjs +947 -0
  366. package/templates/engine/.agents/skills/verify-ui/SKILL.md +116 -0
  367. package/templates/engine/.agents/skills/verify-ui/features/.gitkeep +0 -0
  368. package/templates/engine/.agents/skills/verify-ui/scripts/gen-verify-feature.mjs +114 -0
  369. package/templates/engine/.agents/skills/visual-parity/SKILL.md +35 -0
  370. package/templates/engine/.agents/skills/why/SKILL.md +56 -0
  371. package/templates/engine/.agents/skills/why/scripts/why-evidence.mjs +74 -0
  372. package/templates/engine/.agents/skills/wiki/SKILL.md +53 -0
  373. package/templates/engine/.agents/tests/auto-tour.test.mjs +82 -0
  374. package/templates/engine/.agents/tests/dev-tour-model.test.mjs +452 -0
  375. package/templates/engine/.agents/tests/fill-plan-lite.test.mjs +46 -0
  376. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-bare-mid-path.md +14 -0
  377. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-bare-mid-path.model.json +179 -0
  378. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-fake-path-guard.md +21 -0
  379. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-fake-path-guard.model.json +194 -0
  380. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-h3-batches.md +20 -0
  381. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-h3-batches.model.json +207 -0
  382. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-issues.md +24 -0
  383. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-issues.model.json +225 -0
  384. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-l1-single-file.md +15 -0
  385. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-l1-single-file.model.json +160 -0
  386. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-layer-word-unique.md +29 -0
  387. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-layer-word-unique.model.json +266 -0
  388. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-layers-fallback.md +17 -0
  389. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-layers-fallback.model.json +207 -0
  390. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-numbered-steps.md +39 -0
  391. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-numbered-steps.model.json +359 -0
  392. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-path-guess.md +16 -0
  393. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-path-guess.model.json +131 -0
  394. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-table-rows.md +29 -0
  395. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-table-rows.model.json +190 -0
  396. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-task-checkboxes.md +39 -0
  397. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-task-checkboxes.model.json +362 -0
  398. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-union-label.md +24 -0
  399. package/templates/engine/.agents/tests/fixtures/dev-tour/plan-union-label.model.json +224 -0
  400. package/templates/engine/.agents/tests/tools/gen-synthetic-plan.mjs +108 -0
  401. package/templates/git/.gitattributes +22 -0
  402. package/templates/git/.githooks/commit-msg +72 -0
  403. package/templates/git/.githooks/post-commit +62 -0
  404. package/templates/git/.githooks/pre-commit +197 -0
  405. package/templates/git/.githooks/pre-merge-commit +28 -0
  406. package/templates/git/.githooks/pre-push +201 -0
  407. package/templates/git/.gitignore.engine +11 -0
  408. package/templates/hosts/claude/CLAUDE.md +55 -0
  409. package/templates/hosts/claude/agents/implementer.md +7 -0
  410. package/templates/hosts/claude/agents/independent-reviewer.md +8 -0
  411. package/templates/hosts/claude/agents/pr-adjudicator.md +8 -0
  412. package/templates/hosts/claude/agents/pr-finder.md +8 -0
  413. package/templates/hosts/claude/agents/pr-verifier.md +8 -0
  414. package/templates/hosts/claude/agents/ui-verifier.md +8 -0
  415. package/templates/hosts/claude/agents/wiki-compiler.md +8 -0
  416. package/templates/hosts/claude/commands/wf-deploy.md +10 -0
  417. package/templates/hosts/claude/commands/wf-maintain.md +10 -0
  418. package/templates/hosts/claude/commands/wf-new-task.md +10 -0
  419. package/templates/hosts/claude/commands/wf-pipeline-run.md +10 -0
  420. package/templates/hosts/claude/commands/wf-pr-review.md +10 -0
  421. package/templates/hosts/claude/commands/wf-review.md +10 -0
  422. package/templates/hosts/claude/commands/wf-stages.md +10 -0
  423. package/templates/hosts/claude/settings.json +57 -0
  424. package/templates/hosts/cline/agents/implementer.yml +15 -0
  425. package/templates/hosts/cline/agents/independent-reviewer.yml +20 -0
  426. package/templates/hosts/cline/agents/pr-adjudicator.yml +18 -0
  427. package/templates/hosts/cline/agents/pr-finder.yml +19 -0
  428. package/templates/hosts/cline/agents/pr-verifier.yml +18 -0
  429. package/templates/hosts/cline/agents/ui-verifier.yml +17 -0
  430. package/templates/hosts/cline/agents/wiki-compiler.yml +20 -0
  431. package/templates/hosts/cline/hooks/PreToolUse.cjs +260 -0
  432. package/templates/hosts/cline/workflows/wf-deploy.md +8 -0
  433. package/templates/hosts/cline/workflows/wf-maintain.md +8 -0
  434. package/templates/hosts/cline/workflows/wf-new-task.md +8 -0
  435. package/templates/hosts/cline/workflows/wf-pipeline-run.md +8 -0
  436. package/templates/hosts/cline/workflows/wf-pr-review.md +8 -0
  437. package/templates/hosts/cline/workflows/wf-review.md +8 -0
  438. package/templates/hosts/cline/workflows/wf-stages.md +8 -0
  439. package/templates/hosts/codebuddy/CODEBUDDY.md +7 -0
  440. package/templates/hosts/codebuddy/agents/implementer.md +9 -0
  441. package/templates/hosts/codebuddy/agents/independent-reviewer.md +10 -0
  442. package/templates/hosts/codebuddy/agents/pr-adjudicator.md +10 -0
  443. package/templates/hosts/codebuddy/agents/pr-finder.md +10 -0
  444. package/templates/hosts/codebuddy/agents/pr-verifier.md +10 -0
  445. package/templates/hosts/codebuddy/agents/ui-verifier.md +11 -0
  446. package/templates/hosts/codebuddy/agents/wiki-compiler.md +10 -0
  447. package/templates/hosts/codebuddy/commands/wf-deploy.md +10 -0
  448. package/templates/hosts/codebuddy/commands/wf-maintain.md +10 -0
  449. package/templates/hosts/codebuddy/commands/wf-new-task.md +10 -0
  450. package/templates/hosts/codebuddy/commands/wf-pipeline-run.md +10 -0
  451. package/templates/hosts/codebuddy/commands/wf-pr-review.md +10 -0
  452. package/templates/hosts/codebuddy/commands/wf-review.md +10 -0
  453. package/templates/hosts/codebuddy/commands/wf-stages.md +10 -0
  454. package/templates/hosts/codebuddy/rules/backend-scope.md +5 -0
  455. package/templates/hosts/codebuddy/rules/frontend-scope.md +5 -0
  456. package/templates/hosts/codebuddy/settings.json +31 -0
  457. package/templates/hosts/codebuddy/skills/tfs-pr/SKILL.md +6 -0
  458. package/templates/hosts/commandcode/agents/implementer.md +10 -0
  459. package/templates/hosts/commandcode/agents/independent-reviewer.md +9 -0
  460. package/templates/hosts/commandcode/agents/pr-adjudicator.md +9 -0
  461. package/templates/hosts/commandcode/agents/pr-finder.md +9 -0
  462. package/templates/hosts/commandcode/agents/pr-verifier.md +9 -0
  463. package/templates/hosts/commandcode/agents/ui-verifier.md +11 -0
  464. package/templates/hosts/commandcode/agents/wiki-compiler.md +10 -0
  465. package/templates/hosts/commandcode/commands/wf-deploy.md +9 -0
  466. package/templates/hosts/commandcode/commands/wf-maintain.md +9 -0
  467. package/templates/hosts/commandcode/commands/wf-new-task.md +9 -0
  468. package/templates/hosts/commandcode/commands/wf-pipeline-run.md +9 -0
  469. package/templates/hosts/commandcode/commands/wf-pr-review.md +9 -0
  470. package/templates/hosts/commandcode/commands/wf-review.md +9 -0
  471. package/templates/hosts/commandcode/commands/wf-stages.md +9 -0
  472. package/templates/hosts/commandcode/settings.json +59 -0
  473. package/templates/hosts/opencode/agents/implementer.md +51 -0
  474. package/templates/hosts/opencode/agents/independent-reviewer.md +18 -0
  475. package/templates/hosts/opencode/agents/pr-adjudicator.md +18 -0
  476. package/templates/hosts/opencode/agents/pr-finder.md +18 -0
  477. package/templates/hosts/opencode/agents/pr-verifier.md +18 -0
  478. package/templates/hosts/opencode/agents/ui-verifier.md +45 -0
  479. package/templates/hosts/opencode/agents/wiki-compiler.md +51 -0
  480. package/templates/hosts/opencode/commands/wf-deploy.md +7 -0
  481. package/templates/hosts/opencode/commands/wf-maintain.md +7 -0
  482. package/templates/hosts/opencode/commands/wf-new-task.md +7 -0
  483. package/templates/hosts/opencode/commands/wf-pipeline-run.md +7 -0
  484. package/templates/hosts/opencode/commands/wf-pr-review.md +7 -0
  485. package/templates/hosts/opencode/commands/wf-review.md +7 -0
  486. package/templates/hosts/opencode/commands/wf-stages.md +7 -0
  487. package/templates/hosts/pi/agents/implementer.md +10 -0
  488. package/templates/hosts/pi/agents/independent-reviewer.md +11 -0
  489. package/templates/hosts/pi/agents/pr-adjudicator.md +11 -0
  490. package/templates/hosts/pi/agents/pr-finder.md +10 -0
  491. package/templates/hosts/pi/agents/pr-verifier.md +10 -0
  492. package/templates/hosts/pi/agents/ui-verifier.md +10 -0
  493. package/templates/hosts/pi/agents/wiki-compiler.md +10 -0
  494. package/templates/hosts/pi/extensions/lib/gates-core.cjs +196 -0
  495. package/templates/hosts/pi/extensions/shipyard-gates.ts +95 -0
  496. package/templates/hosts/pi/settings.json +5 -0
  497. package/templates/hosts/qoder/agents/implementer.md +9 -0
  498. package/templates/hosts/qoder/agents/independent-reviewer.md +10 -0
  499. package/templates/hosts/qoder/agents/pr-adjudicator.md +10 -0
  500. package/templates/hosts/qoder/agents/pr-finder.md +10 -0
  501. package/templates/hosts/qoder/agents/pr-verifier.md +10 -0
  502. package/templates/hosts/qoder/agents/ui-verifier.md +10 -0
  503. package/templates/hosts/qoder/agents/wiki-compiler.md +10 -0
  504. package/templates/hosts/qoder/commands/wf-deploy.md +8 -0
  505. package/templates/hosts/qoder/commands/wf-maintain.md +8 -0
  506. package/templates/hosts/qoder/commands/wf-new-task.md +8 -0
  507. package/templates/hosts/qoder/commands/wf-pipeline-run.md +8 -0
  508. package/templates/hosts/qoder/commands/wf-pr-review.md +8 -0
  509. package/templates/hosts/qoder/commands/wf-review.md +8 -0
  510. package/templates/hosts/qoder/commands/wf-stages.md +8 -0
  511. package/templates/hosts/qoder/settings.json +63 -0
  512. package/templates/hosts/qwen/agents/implementer.md +8 -0
  513. package/templates/hosts/qwen/agents/independent-reviewer.md +8 -0
  514. package/templates/hosts/qwen/agents/pr-adjudicator.md +8 -0
  515. package/templates/hosts/qwen/agents/pr-finder.md +8 -0
  516. package/templates/hosts/qwen/agents/pr-verifier.md +8 -0
  517. package/templates/hosts/qwen/agents/ui-verifier.md +8 -0
  518. package/templates/hosts/qwen/agents/wiki-compiler.md +11 -0
  519. package/templates/hosts/qwen/commands/wf-deploy.md +9 -0
  520. package/templates/hosts/qwen/commands/wf-maintain.md +9 -0
  521. package/templates/hosts/qwen/commands/wf-new-task.md +9 -0
  522. package/templates/hosts/qwen/commands/wf-pipeline-run.md +9 -0
  523. package/templates/hosts/qwen/commands/wf-pr-review.md +9 -0
  524. package/templates/hosts/qwen/commands/wf-review.md +9 -0
  525. package/templates/hosts/qwen/commands/wf-stages.md +9 -0
  526. package/templates/hosts/qwen/settings.json +59 -0
  527. package/templates/hosts/trae/agents/implementer.md +9 -0
  528. package/templates/hosts/trae/agents/independent-reviewer.md +10 -0
  529. package/templates/hosts/trae/agents/pr-adjudicator.md +10 -0
  530. package/templates/hosts/trae/agents/pr-finder.md +10 -0
  531. package/templates/hosts/trae/agents/pr-verifier.md +10 -0
  532. package/templates/hosts/trae/agents/ui-verifier.md +10 -0
  533. package/templates/hosts/trae/agents/wiki-compiler.md +10 -0
  534. package/templates/hosts/trae/commands/wf-deploy.md +8 -0
  535. package/templates/hosts/trae/commands/wf-maintain.md +8 -0
  536. package/templates/hosts/trae/commands/wf-new-task.md +8 -0
  537. package/templates/hosts/trae/commands/wf-pipeline-run.md +8 -0
  538. package/templates/hosts/trae/commands/wf-pr-review.md +8 -0
  539. package/templates/hosts/trae/commands/wf-review.md +8 -0
  540. package/templates/hosts/trae/commands/wf-stages.md +8 -0
  541. package/templates/hosts/trae/hooks.json +17 -0
  542. package/templates/hosts/trae/rules/backend-scope.md +5 -0
  543. package/templates/hosts/trae/rules/frontend-scope.md +5 -0
  544. package/templates/hosts/zcode/agents/implementer.md +8 -0
  545. package/templates/hosts/zcode/agents/independent-reviewer.md +8 -0
  546. package/templates/hosts/zcode/agents/ui-verifier.md +8 -0
  547. package/templates/hosts/zcode/agents/wiki-compiler.md +8 -0
  548. package/templates/hosts/zcode/config.json +31 -0
  549. package/templates/hosts/zcode/workflows/code-review.dwf.ts +428 -0
  550. package/templates/hosts/zcode/workflows/fullchain-flow-test.dwf.ts +898 -0
  551. package/templates/profiles/dotnet/.agents/config/lane-surfaces.txt +33 -0
  552. package/templates/profiles/dotnet/.agents/config/rule-budgets.txt +84 -0
  553. package/templates/profiles/dotnet/.agents/config/test-impact-map.json +590 -0
  554. package/templates/profiles/dotnet/.agents/config/workflow-modules.txt +18 -0
  555. package/templates/profiles/dotnet/.agents/hooks/commit-check.config.json +18 -0
  556. package/templates/profiles/dotnet/.agents/hooks/delete-guard-allowlist.txt +28 -0
  557. package/templates/profiles/dotnet/.agents/notes/runtime-env.md +178 -0
  558. package/templates/profiles/dotnet/AGENTS.md +52 -0
  559. package/templates/profiles/empty/.agents/config/lane-surfaces.txt +12 -0
  560. package/templates/profiles/empty/.agents/config/rule-budgets.txt +3 -0
  561. package/templates/profiles/empty/.agents/config/test-impact-map.json +8 -0
  562. package/templates/profiles/empty/.agents/config/workflow-modules.txt +2 -0
  563. package/templates/profiles/empty/.agents/hooks/commit-check.config.json +5 -0
  564. package/templates/profiles/empty/.agents/hooks/delete-guard-allowlist.txt +2 -0
  565. package/templates/profiles/empty/.agents/notes/runtime-env.md +44 -0
  566. package/templates/profiles/empty/AGENTS.md +52 -0
  567. package/templates/profiles/node/.agents/config/lane-surfaces.txt +12 -0
  568. package/templates/profiles/node/.agents/config/rule-budgets.txt +3 -0
  569. package/templates/profiles/node/.agents/config/test-impact-map.json +8 -0
  570. package/templates/profiles/node/.agents/config/workflow-modules.txt +2 -0
  571. package/templates/profiles/node/.agents/hooks/commit-check.config.json +5 -0
  572. package/templates/profiles/node/.agents/hooks/delete-guard-allowlist.txt +2 -0
  573. package/templates/profiles/node/.agents/notes/runtime-env.md +44 -0
  574. package/templates/profiles/node/AGENTS.md +52 -0
  575. package/templates/scaffold/wiki/INDEX.md +33 -0
  576. package/templates/scaffold/wiki/drafts-archive/README.md +7 -0
  577. package/templates/scaffold/wiki//344/272/247/345/223/201/351/234/200/346/261/202/.gitkeep +0 -0
  578. package/templates/scaffold/wiki//345/274/200/345/217/221/346/226/271/346/241/210/.gitkeep +0 -0
  579. package/templates/scaffold/wiki//346/225/260/346/215/256/347/273/264/346/212/244/README.md +22 -0
  580. package/templates/scaffold/wiki//346/265/213/350/257/225/346/212/245/345/221/212/.gitkeep +0 -0
  581. package/templates/scaffold/wiki//347/224/250/346/210/267/345/212/237/350/203/275/.gitkeep +0 -0
  582. package/templates/scaffold/wiki//347/237/245/350/257/206/346/262/211/346/267/200/346/200/273/350/247/210.html +230 -0
  583. package/templates/scaffold/wiki//351/241/271/347/233/256/350/247/204/350/214/203/.gitkeep +0 -0
  584. package/templates/scaffold/workflow/INDEX.md +13 -0
  585. package/templates/scaffold/workflow/README.md +67 -0
  586. package/templates/scaffold/workflow/archive/README.md +3 -0
  587. package/templates/scaffold/workflow/delegations.d/.gitkeep +0 -0
  588. package/templates/scaffold/workflow/delegations.md +4 -0
  589. package/templates/scaffold/workflow/effective-policy.md +4 -0
  590. package/templates/scaffold/workflow/evidence/.gitkeep +0 -0
  591. package/templates/scaffold/workflow/gate-cost.md +4 -0
  592. package/templates/scaffold/workflow/gate-metrics.d/.gitkeep +0 -0
  593. package/templates/scaffold/workflow/incidents/_TEMPLATE.md +49 -0
  594. package/templates/scaffold/workflow/intents/_TEMPLATE.md +43 -0
  595. package/templates/scaffold/workflow/metrics.md +4 -0
  596. package/templates/scaffold/workflow/papercuts.d/.gitkeep +0 -0
  597. package/templates/scaffold/workflow/papercuts.md +3 -0
  598. package/templates/scaffold/workflow/plans/_TEMPLATE.md +47 -0
  599. package/templates/scaffold/workflow/regression-checklist.d/.gitkeep +0 -0
  600. package/templates/scaffold/workflow/regression-checklist.md +3 -0
  601. package/templates/scaffold/workflow/research/.gitkeep +0 -0
  602. package/templates/scaffold/workflow/reviews.d/.gitkeep +0 -0
  603. package/templates/scaffold/workflow/specs/_TEMPLATE.md +87 -0
  604. package/templates/scaffold/workflow/verify-evidence/.gitkeep +0 -0
  605. package/templates/scaffold/workflow/verify-evidence.md +4 -0
  606. package/LICENSE +0 -21
  607. package/modules/gates/README.md +0 -25
  608. package/modules/gates/dotnet-ca/README.md +0 -24
  609. package/modules/gates/dotnet-ca/check-architecture.sh +0 -150
  610. package/modules/gates/dotnet-ca/local-pre-commit.line +0 -1
  611. package/modules/gates/generated-readonly/README.md +0 -13
  612. package/modules/gates/generated-readonly/check-generated.mjs +0 -61
  613. package/modules/gates/generated-readonly/local-pre-commit.line +0 -1
  614. package/modules/gates/node-layer/README.md +0 -9
  615. package/modules/gates/node-layer/check-node-layer.mjs +0 -29
  616. package/modules/gates/node-layer/local-pre-commit.line +0 -1
  617. package/modules/gates/py-import/README.md +0 -9
  618. package/modules/gates/py-import/check-py-import.mjs +0 -30
  619. package/modules/gates/py-import/local-pre-commit.line +0 -1
  620. package/modules/gates/test-protect/README.md +0 -23
  621. package/modules/gates/test-protect/check-test-protect.mjs +0 -64
  622. package/modules/gates/test-protect/local-pre-commit.line +0 -1
  623. package/modules/hosts/README.md +0 -57
  624. package/modules/hosts/claude/agents/implementer.md +0 -51
  625. package/modules/hosts/claude/agents/independent-reviewer.md +0 -49
  626. package/modules/hosts/claude/agents/ui-verifier.md +0 -48
  627. package/modules/hosts/claude/commands/wf-build.md +0 -69
  628. package/modules/hosts/claude/commands/wf-deploy.md +0 -58
  629. package/modules/hosts/claude/commands/wf-design.md +0 -49
  630. package/modules/hosts/claude/commands/wf-gate-checklist.md +0 -77
  631. package/modules/hosts/claude/commands/wf-maintain.md +0 -76
  632. package/modules/hosts/claude/commands/wf-new-task.md +0 -102
  633. package/modules/hosts/claude/commands/wf-pipeline-run.md +0 -35
  634. package/modules/hosts/claude/commands/wf-plan.md +0 -40
  635. package/modules/hosts/claude/commands/wf-review.md +0 -49
  636. package/modules/hosts/claude/commands/wf-sync-hosts.md +0 -64
  637. package/modules/hosts/claude/commands/wf-test.md +0 -68
  638. package/modules/hosts/codex/agents/implementer.md +0 -51
  639. package/modules/hosts/codex/agents/independent-reviewer.md +0 -49
  640. package/modules/hosts/codex/agents/ui-verifier.md +0 -48
  641. package/modules/hosts/codex/commands/wf-build.md +0 -69
  642. package/modules/hosts/codex/commands/wf-deploy.md +0 -58
  643. package/modules/hosts/codex/commands/wf-design.md +0 -49
  644. package/modules/hosts/codex/commands/wf-gate-checklist.md +0 -77
  645. package/modules/hosts/codex/commands/wf-maintain.md +0 -76
  646. package/modules/hosts/codex/commands/wf-new-task.md +0 -102
  647. package/modules/hosts/codex/commands/wf-pipeline-run.md +0 -35
  648. package/modules/hosts/codex/commands/wf-plan.md +0 -40
  649. package/modules/hosts/codex/commands/wf-review.md +0 -49
  650. package/modules/hosts/codex/commands/wf-sync-hosts.md +0 -64
  651. package/modules/hosts/codex/commands/wf-test.md +0 -68
  652. package/modules/hosts/codex/skills/flow-kit/SKILL.md +0 -14
  653. package/modules/hosts/cursor/agents/implementer.md +0 -51
  654. package/modules/hosts/cursor/agents/independent-reviewer.md +0 -49
  655. package/modules/hosts/cursor/agents/ui-verifier.md +0 -48
  656. package/modules/hosts/cursor/commands/wf-build.md +0 -69
  657. package/modules/hosts/cursor/commands/wf-deploy.md +0 -58
  658. package/modules/hosts/cursor/commands/wf-design.md +0 -49
  659. package/modules/hosts/cursor/commands/wf-gate-checklist.md +0 -77
  660. package/modules/hosts/cursor/commands/wf-maintain.md +0 -76
  661. package/modules/hosts/cursor/commands/wf-new-task.md +0 -102
  662. package/modules/hosts/cursor/commands/wf-pipeline-run.md +0 -35
  663. package/modules/hosts/cursor/commands/wf-plan.md +0 -40
  664. package/modules/hosts/cursor/commands/wf-review.md +0 -49
  665. package/modules/hosts/cursor/commands/wf-sync-hosts.md +0 -64
  666. package/modules/hosts/cursor/commands/wf-test.md +0 -68
  667. package/modules/hosts/omp/agents/implementer.md +0 -52
  668. package/modules/hosts/omp/agents/independent-reviewer.md +0 -50
  669. package/modules/hosts/omp/agents/ui-verifier.md +0 -49
  670. package/modules/hosts/opencode/agents/implementer.md +0 -59
  671. package/modules/hosts/opencode/agents/independent-reviewer.md +0 -53
  672. package/modules/hosts/opencode/agents/ui-verifier.md +0 -52
  673. package/modules/hosts/opencode/commands/wf-build.md +0 -69
  674. package/modules/hosts/opencode/commands/wf-deploy.md +0 -58
  675. package/modules/hosts/opencode/commands/wf-design.md +0 -49
  676. package/modules/hosts/opencode/commands/wf-gate-checklist.md +0 -77
  677. package/modules/hosts/opencode/commands/wf-maintain.md +0 -76
  678. package/modules/hosts/opencode/commands/wf-new-task.md +0 -102
  679. package/modules/hosts/opencode/commands/wf-pipeline-run.md +0 -35
  680. package/modules/hosts/opencode/commands/wf-plan.md +0 -40
  681. package/modules/hosts/opencode/commands/wf-review.md +0 -49
  682. package/modules/hosts/opencode/commands/wf-sync-hosts.md +0 -64
  683. package/modules/hosts/opencode/commands/wf-test.md +0 -68
  684. package/modules/hosts/trae/agents/implementer.md +0 -52
  685. package/modules/hosts/trae/agents/independent-reviewer.md +0 -51
  686. package/modules/hosts/trae/agents/ui-verifier.md +0 -50
  687. package/modules/hosts/trae/commands/wf-build.md +0 -70
  688. package/modules/hosts/trae/commands/wf-deploy.md +0 -59
  689. package/modules/hosts/trae/commands/wf-design.md +0 -50
  690. package/modules/hosts/trae/commands/wf-gate-checklist.md +0 -78
  691. package/modules/hosts/trae/commands/wf-maintain.md +0 -77
  692. package/modules/hosts/trae/commands/wf-new-task.md +0 -103
  693. package/modules/hosts/trae/commands/wf-pipeline-run.md +0 -36
  694. package/modules/hosts/trae/commands/wf-plan.md +0 -41
  695. package/modules/hosts/trae/commands/wf-review.md +0 -50
  696. package/modules/hosts/trae/commands/wf-sync-hosts.md +0 -65
  697. package/modules/hosts/trae/commands/wf-test.md +0 -69
  698. package/modules/hosts/trae/hooks/post-edit-check.cjs +0 -98
  699. package/modules/hosts/trae/hooks/pre-shell-check.cjs +0 -192
  700. package/modules/hosts/trae/hooks/resolve-shell.cjs +0 -30
  701. package/modules/hosts/trae/hooks.json +0 -29
  702. package/modules/hosts/trae/rules/beautify-input-chinese.md +0 -6
  703. package/modules/hosts/trae/rules/git-commit-message.md +0 -10
  704. package/modules/hosts/trae/rules/project-workflow.md +0 -14
  705. package/modules/hosts/zcode/agents/implementer.md +0 -51
  706. package/modules/hosts/zcode/agents/independent-reviewer.md +0 -49
  707. package/modules/hosts/zcode/agents/ui-verifier.md +0 -48
  708. package/src/add-gate.mjs +0 -116
  709. package/src/add-gate.test.mjs +0 -103
  710. package/src/add-host.mjs +0 -68
  711. package/src/cli.mjs +0 -169
  712. package/src/doctor.mjs +0 -629
  713. package/src/executor.mjs +0 -262
  714. package/src/executor.test.mjs +0 -295
  715. package/src/fresh-init.test.mjs +0 -64
  716. package/src/gate-dotnet-ca.test.mjs +0 -124
  717. package/src/gates.test.mjs +0 -143
  718. package/src/init.mjs +0 -382
  719. package/src/init.test.mjs +0 -163
  720. package/src/instance-ref.test.mjs +0 -62
  721. package/src/jscpd-drift.test.mjs +0 -144
  722. package/src/pack.test.mjs +0 -24
  723. package/src/profiles.mjs +0 -183
  724. package/src/render.mjs +0 -132
  725. package/src/rule-budget.test.mjs +0 -103
  726. package/src/run-tests.mjs +0 -56
  727. package/src/stack-profile.test.mjs +0 -95
  728. package/src/sync-hosts.mjs +0 -257
  729. package/src/sync-hosts.test.mjs +0 -291
  730. package/src/sync.mjs +0 -228
  731. package/src/sync.test.mjs +0 -452
  732. package/src/trae-hooks.test.mjs +0 -127
  733. package/src/validate.mjs +0 -77
  734. package/src/validate.test.mjs +0 -95
  735. package/templates/.gitattributes +0 -17
  736. package/templates/AGENTS.md +0 -57
  737. package/templates/_agents/board/index.html +0 -676
  738. package/templates/_agents/commands/build.md +0 -84
  739. package/templates/_agents/commands/deploy.md +0 -66
  740. package/templates/_agents/commands/design.md +0 -63
  741. package/templates/_agents/commands/gate-checklist.md +0 -91
  742. package/templates/_agents/commands/maintain.md +0 -90
  743. package/templates/_agents/commands/new-task.md +0 -110
  744. package/templates/_agents/commands/pipeline-run.md +0 -43
  745. package/templates/_agents/commands/plan.md +0 -48
  746. package/templates/_agents/commands/review.md +0 -62
  747. package/templates/_agents/commands/sync-hosts.md +0 -77
  748. package/templates/_agents/commands/test.md +0 -87
  749. package/templates/_agents/control-surfaces.txt +0 -53
  750. package/templates/_agents/engine-lock.json +0 -342
  751. package/templates/_agents/hooks/check-index-incremental.mjs +0 -48
  752. package/templates/_agents/hooks/check-pairing-incremental.mjs +0 -66
  753. package/templates/_agents/hooks/check-wiki-ledger.mjs +0 -30
  754. package/templates/_agents/hooks/commit-check.cjs +0 -193
  755. package/templates/_agents/hooks/local-pre-commit +0 -6
  756. package/templates/_agents/lane-surfaces.txt +0 -17
  757. package/templates/_agents/level-hints.txt +0 -30
  758. package/templates/_agents/loop/papercut-debt/DESIGN.md +0 -112
  759. package/templates/_agents/mechanism-registry.md +0 -27
  760. package/templates/_agents/metric-claims.txt +0 -81
  761. package/templates/_agents/notes/engine-internals.md +0 -17
  762. package/templates/_agents/notes/runtime-env.md +0 -18
  763. package/templates/_agents/roles/implementer.md +0 -47
  764. package/templates/_agents/roles/independent-reviewer.md +0 -45
  765. package/templates/_agents/roles/ui-verifier.md +0 -44
  766. package/templates/_agents/rule-budgets.txt +0 -18
  767. package/templates/_agents/scripts/agg-delegations.cjs +0 -302
  768. package/templates/_agents/scripts/agg-delegations.test.mjs +0 -282
  769. package/templates/_agents/scripts/agg-gate-stats.mjs +0 -113
  770. package/templates/_agents/scripts/agg-gate-stats.test.mjs +0 -95
  771. package/templates/_agents/scripts/agg-judgments.mjs +0 -156
  772. package/templates/_agents/scripts/agg-judgments.test.mjs +0 -93
  773. package/templates/_agents/scripts/archive-sweep.mjs +0 -235
  774. package/templates/_agents/scripts/archive-sweep.test.mjs +0 -129
  775. package/templates/_agents/scripts/check-attribution.mjs +0 -37
  776. package/templates/_agents/scripts/check-convergence.mjs +0 -124
  777. package/templates/_agents/scripts/check-engine-integrity.mjs +0 -220
  778. package/templates/_agents/scripts/check-engine-integrity.test.mjs +0 -215
  779. package/templates/_agents/scripts/check-funnel.mjs +0 -56
  780. package/templates/_agents/scripts/check-hygiene.mjs +0 -167
  781. package/templates/_agents/scripts/check-hygiene.test.mjs +0 -182
  782. package/templates/_agents/scripts/check-index-incremental.test.mjs +0 -73
  783. package/templates/_agents/scripts/check-lane-surface.mjs +0 -238
  784. package/templates/_agents/scripts/check-lane-surface.test.mjs +0 -302
  785. package/templates/_agents/scripts/check-ledger-invariant.mjs +0 -527
  786. package/templates/_agents/scripts/check-ledger-invariant.test.mjs +0 -639
  787. package/templates/_agents/scripts/check-loop-rev.test.mjs +0 -336
  788. package/templates/_agents/scripts/check-loop-unit.test.mjs +0 -103
  789. package/templates/_agents/scripts/check-loop.mjs +0 -1958
  790. package/templates/_agents/scripts/check-loop.sh +0 -6
  791. package/templates/_agents/scripts/check-loop.test.mjs +0 -3875
  792. package/templates/_agents/scripts/check-metric-claims.mjs +0 -277
  793. package/templates/_agents/scripts/check-prejudgment.mjs +0 -64
  794. package/templates/_agents/scripts/check-registry.mjs +0 -45
  795. package/templates/_agents/scripts/check-scope.mjs +0 -96
  796. package/templates/_agents/scripts/check-scope.test.mjs +0 -96
  797. package/templates/_agents/scripts/check-scripts-syntax.mjs +0 -61
  798. package/templates/_agents/scripts/check-scripts-syntax.test.mjs +0 -72
  799. package/templates/_agents/scripts/check-spec-verif.mjs +0 -47
  800. package/templates/_agents/scripts/check-stage-index.mjs +0 -40
  801. package/templates/_agents/scripts/check-stage-index.test.mjs +0 -77
  802. package/templates/_agents/scripts/closeout-l1.mjs +0 -217
  803. package/templates/_agents/scripts/closeout-l1.test.mjs +0 -105
  804. package/templates/_agents/scripts/commit-check-trigger.test.mjs +0 -205
  805. package/templates/_agents/scripts/compact-ledgers.mjs +0 -97
  806. package/templates/_agents/scripts/compact-ledgers.test.mjs +0 -162
  807. package/templates/_agents/scripts/confirm-doc.mjs +0 -603
  808. package/templates/_agents/scripts/confirm-doc.test.mjs +0 -1103
  809. package/templates/_agents/scripts/doctor.test.mjs +0 -770
  810. package/templates/_agents/scripts/draft-sediment.mjs +0 -178
  811. package/templates/_agents/scripts/draft-sediment.test.mjs +0 -272
  812. package/templates/_agents/scripts/edit-face-check.mjs +0 -109
  813. package/templates/_agents/scripts/edit-face-check.test.mjs +0 -99
  814. package/templates/_agents/scripts/ensure-board.mjs +0 -185
  815. package/templates/_agents/scripts/fill-intent.mjs +0 -91
  816. package/templates/_agents/scripts/fill-intent.test.mjs +0 -113
  817. package/templates/_agents/scripts/fill-plan.mjs +0 -79
  818. package/templates/_agents/scripts/fill-plan.test.mjs +0 -224
  819. package/templates/_agents/scripts/fill-spec.mjs +0 -70
  820. package/templates/_agents/scripts/fill-spec.test.mjs +0 -266
  821. package/templates/_agents/scripts/fixture-scripts.mjs +0 -153
  822. package/templates/_agents/scripts/fixture-scripts.test.mjs +0 -112
  823. package/templates/_agents/scripts/gate-checklist.mjs +0 -209
  824. package/templates/_agents/scripts/gate-checklist.test.mjs +0 -201
  825. package/templates/_agents/scripts/gate-seg.mjs +0 -54
  826. package/templates/_agents/scripts/gate-seg.test.mjs +0 -112
  827. package/templates/_agents/scripts/gen-effective-policy.mjs +0 -107
  828. package/templates/_agents/scripts/gen-effective-policy.test.mjs +0 -100
  829. package/templates/_agents/scripts/gen-verify-evidence.mjs +0 -107
  830. package/templates/_agents/scripts/gen-verify-evidence.test.mjs +0 -84
  831. package/templates/_agents/scripts/gen-wiki-board.mjs +0 -276
  832. package/templates/_agents/scripts/gen-wiki-board.test.mjs +0 -249
  833. package/templates/_agents/scripts/gen-workflow-dashboard.mjs +0 -251
  834. package/templates/_agents/scripts/gen-workflow-dashboard.test.mjs +0 -188
  835. package/templates/_agents/scripts/gen-workflow-index.mjs +0 -201
  836. package/templates/_agents/scripts/gen-workflow-index.test.mjs +0 -152
  837. package/templates/_agents/scripts/gen-workflow-metrics.mjs +0 -334
  838. package/templates/_agents/scripts/gen-workflow-metrics.test.mjs +0 -224
  839. package/templates/_agents/scripts/git-merge-jsonl.mjs +0 -63
  840. package/templates/_agents/scripts/git-merge-jsonl.test.mjs +0 -125
  841. package/templates/_agents/scripts/judgment-ledger.mjs +0 -65
  842. package/templates/_agents/scripts/judgment-ledger.test.mjs +0 -129
  843. package/templates/_agents/scripts/kb-cache-evict.mjs +0 -50
  844. package/templates/_agents/scripts/kb-cache-evict.test.mjs +0 -104
  845. package/templates/_agents/scripts/kb-search.mjs +0 -413
  846. package/templates/_agents/scripts/kb-search.test.mjs +0 -299
  847. package/templates/_agents/scripts/lane-surface-audit.mjs +0 -143
  848. package/templates/_agents/scripts/lane-surface-audit.test.mjs +0 -93
  849. package/templates/_agents/scripts/ledger-doc-chain.test.mjs +0 -166
  850. package/templates/_agents/scripts/ledger-loader.mjs +0 -108
  851. package/templates/_agents/scripts/ledger-loader.test.mjs +0 -131
  852. package/templates/_agents/scripts/ledger-prune.mjs +0 -96
  853. package/templates/_agents/scripts/ledger-prune.test.mjs +0 -120
  854. package/templates/_agents/scripts/ledger-shards.mjs +0 -344
  855. package/templates/_agents/scripts/ledger-shards.test.mjs +0 -356
  856. package/templates/_agents/scripts/ledger-ts-monotonic.test.mjs +0 -135
  857. package/templates/_agents/scripts/level-criteria.mjs +0 -231
  858. package/templates/_agents/scripts/level-criteria.test.mjs +0 -281
  859. package/templates/_agents/scripts/mechanism-retire-watch.mjs +0 -183
  860. package/templates/_agents/scripts/mechanism-retire-watch.test.mjs +0 -114
  861. package/templates/_agents/scripts/papercut-debt-controller.mjs +0 -141
  862. package/templates/_agents/scripts/papercut-debt-controller.test.mjs +0 -127
  863. package/templates/_agents/scripts/papercut-debt-sensor.mjs +0 -170
  864. package/templates/_agents/scripts/papercut-debt-sensor.test.mjs +0 -146
  865. package/templates/_agents/scripts/pipeline-run-docs.mjs +0 -76
  866. package/templates/_agents/scripts/pipeline-run-run.mjs +0 -63
  867. package/templates/_agents/scripts/pipeline-run.mjs +0 -867
  868. package/templates/_agents/scripts/pipeline-run.test.mjs +0 -517
  869. package/templates/_agents/scripts/policy.mjs +0 -281
  870. package/templates/_agents/scripts/pre-push.test.mjs +0 -105
  871. package/templates/_agents/scripts/resolve-merge-conflicts.mjs +0 -110
  872. package/templates/_agents/scripts/resolve-merge-conflicts.test.mjs +0 -87
  873. package/templates/_agents/scripts/rewrite-file.mjs +0 -133
  874. package/templates/_agents/scripts/rewrite-file.test.mjs +0 -148
  875. package/templates/_agents/scripts/rule-budget.mjs +0 -96
  876. package/templates/_agents/scripts/rule-budget.test.mjs +0 -118
  877. package/templates/_agents/scripts/run-tests.mjs +0 -99
  878. package/templates/_agents/scripts/run-tests.test.mjs +0 -105
  879. package/templates/_agents/scripts/solidify-task.mjs +0 -107
  880. package/templates/_agents/scripts/solidify-task.test.mjs +0 -129
  881. package/templates/_agents/scripts/stage-gates.mjs +0 -343
  882. package/templates/_agents/scripts/stage-gates.test.mjs +0 -105
  883. package/templates/_agents/scripts/trust-mode.mjs +0 -67
  884. package/templates/_agents/scripts/trust-mode.test.mjs +0 -110
  885. package/templates/_agents/scripts/verify-wiki-consistency.mjs +0 -253
  886. package/templates/_agents/scripts/verify-wiki-consistency.test.mjs +0 -123
  887. package/templates/_agents/scripts/verify.mjs +0 -210
  888. package/templates/_agents/scripts/verify.test.mjs +0 -358
  889. package/templates/_agents/scripts/wf-journal.mjs +0 -231
  890. package/templates/_agents/scripts/wf-journal.test.mjs +0 -216
  891. package/templates/_agents/scripts/wiki-search.mjs +0 -19
  892. package/templates/_agents/scripts/wiki-search.test.mjs +0 -57
  893. package/templates/_agents/scripts/workflow-board-server.mjs +0 -393
  894. package/templates/_agents/scripts/workflow-board-server.test.mjs +0 -201
  895. package/templates/_agents/scripts/workflow-enums.mjs +0 -70
  896. package/templates/_agents/scripts/workflow-enums.test.mjs +0 -118
  897. package/templates/_agents/scripts/workflows-check.mjs +0 -260
  898. package/templates/_agents/scripts/workflows-check.test.mjs +0 -278
  899. package/templates/_agents/scripts-test-exempt.txt +0 -16
  900. package/templates/_agents/skills/papercut-fix/SKILL.md +0 -60
  901. package/templates/_agents/skills/papercut-fix/references/response-template.md +0 -81
  902. package/templates/_agents/skills/review-method/SKILL.md +0 -55
  903. package/templates/_agents/skills/verify-ui/SKILL.md +0 -61
  904. package/templates/_agents/skills/wiki/SKILL.md +0 -106
  905. package/templates/_agents/workflow-enums.txt +0 -26
  906. package/templates/_agents/workflow-modules.txt +0 -11
  907. package/templates/_agents/workflows/_TEMPLATE.md +0 -75
  908. package/templates/_agents/workflows/pipeline-closing.md +0 -28
  909. package/templates/_agents/workflows//347/244/272/344/276/213-/345/271/266/350/241/214/345/256/236/347/216/260/350/257/204/345/256/241.md +0 -16
  910. package/templates/_githooks/commit-msg +0 -17
  911. package/templates/_githooks/post-commit +0 -10
  912. package/templates/_githooks/pre-commit +0 -126
  913. package/templates/_githooks/pre-merge-commit +0 -29
  914. package/templates/_githooks/pre-push +0 -136
  915. package/templates/_github/workflows/kit-ci.yml +0 -49
  916. package/templates/wiki/INDEX.md +0 -73
  917. package/templates/wiki/drafts-archive/README.md +0 -3
  918. package/templates/wiki//344/272/247/345/223/201/351/234/200/346/261/202/README.md +0 -3
  919. package/templates/wiki//345/274/200/345/217/221/346/226/271/346/241/210/README.md +0 -3
  920. package/templates/wiki//346/225/260/346/215/256/347/273/264/346/212/244/README.md +0 -3
  921. package/templates/wiki//346/265/213/350/257/225/346/212/245/345/221/212/README.md +0 -3
  922. package/templates/wiki//347/224/250/346/210/267/345/212/237/350/203/275/README.md +0 -3
  923. package/templates/wiki//347/237/245/350/257/206/346/262/211/346/267/200/346/200/273/350/247/210.html +0 -77
  924. package/templates/wiki//351/241/271/347/233/256/350/247/204/350/214/203/README.md +0 -3
  925. package/templates/wiki//351/241/271/347/233/256/350/256/241/345/210/222/README.md +0 -3
  926. package/templates/workflow/README.md +0 -90
  927. package/templates/workflow/delegations.md +0 -29
  928. package/templates/workflow/incidents/_TEMPLATE.md +0 -51
  929. package/templates/workflow/intents/_TEMPLATE.md +0 -46
  930. package/templates/workflow/papercuts.md +0 -9
  931. package/templates/workflow/plans/_TEMPLATE.md +0 -47
  932. package/templates/workflow/regression-checklist.md +0 -23
  933. package/templates/workflow/specs/_TEMPLATE.md +0 -80
  934. /package/templates/{_agents → engine/.agents}/board/marked.min.js +0 -0
  935. /package/templates/{_agents/workflows → engine/.agents/pipelines}/steps//347/244/272/344/276/213-/351/203/250/347/275/262/351/252/214/350/257/201.md" +0 -0
  936. /package/templates/{_agents → engine/.agents}/scripts/git-core.mjs +0 -0
@@ -0,0 +1,873 @@
1
+ #!/usr/bin/env node
2
+ // check-ledger-invariant — confirmations 台账提交不变量(2026-10-02 ledger-ci-invariant;
3
+ // 2026-10-12 ledger-shard-invariant:校验面自单一主台账扩展到「主台账 + confirmations.d 分片」)
4
+ // 目的:把「台账本地可写」的伪造面从事后对质级升为机器可检出级(能力评审审计维度扣分项)。
5
+ // 台账不可变原则:confirmations 历史行禁删改——修正只能走追加补偿行(README 硬规则 6)。
6
+ //
7
+ // 分片形态(2026-10-10 中期方案;2026-10-12 起为 confirm-doc 默认写入口径):
8
+ // .agents/confirmations.d/<doc 基名>.jsonl —— 按 doc 分片,跨机/跨 worktree 确认不同 doc 时
9
+ // 写不同文件,从根上消除「每合并必冲突 + 手工重建」;同一 doc 被两端并发确认时由
10
+ // .gitattributes 的 merge=jsonl-union 驱动取并集(本地须配 merge.jsonl-union.driver,
11
+ // 见 check-local-gates.mjs --fix)。本脚本给分片补上主台账同级的 append-only 前缀不变量——
12
+ // 否则分片是「无人校验的写入面」,被改写/删除无人知。
13
+ //
14
+ // 特许修剪(2026-10-09 user-directed-prune):仓库所有者明令删除某批 workflow 文档并清理其台账行时,
15
+ // 允许**一次性、逐行对账**的修剪——暂存集须同时携带 .agents/config/ledger-prune-manifest.json
16
+ // ({ts, authority, reason, removes:[被删行 sha256...], docs:[家族名...]}),门禁逐行核验
17
+ // 「新内容 = 旧内容 − manifest 所列各行」且每个哈希恰对应一行。未带 manifest 的删/改/重排仍全拦——
18
+ // append-only 红线对其他一切场景不变;修剪凭据(被删行哈希)随 manifest 入库,事后可对质。
19
+ //
20
+ // 分片删除的唯一合法形态 = compact-ledgers 归并(2026-10-12):分片被删时,该分片**全部非空行必须
21
+ // 已逐字存在于同一提交的主台账**(compact-ledgers 正是把这些行原样追加进主台账后才删片)——
22
+ // 认不出归并凭据的删片一律 hard fail,堵住「删片抹账」这条路。主台账自身永不因归并被删。
23
+ // 合并感知(2026-10-13 merge-aware-shard-delete):分片内容从**各父**取并集后对账——合并解析收口
24
+ // 删片时,分片可能只在第二父侧(首父早已归并删片,实证 56c45b07:4 分片生于他端、首父无此路径,
25
+ // 单看 `${sha}^` 会把合法收口误判成「增删同提交」)。
26
+ // 终树补登追认(2026-10-13 merge-shard-restore-aware):合并删片时缺行若已全部在终树主台账补登
27
+ // (后续提交原样回append),视为丢失已追认——历史事实不可改写,终态无丢失即审计实质
28
+ // (实证 56c45b07 丢失第二父分片行 1 行,同日补登)。
29
+ //
30
+ // 合并并集语义(2026-10-13 merge-union-aware):多父提交不按线性前缀判,改验「并集无丢失」——
31
+ // 合并结果的行集合须 ⊇ 两父各自行集之并(一行不丢)且 ⊆ 该并集(一行不造)。jsonl-union 策略
32
+ // (多 worktree 并行确认的根基)与线性前缀模型天生矛盾,本判据对齐审计实质:确认行不被丢、
33
+ // 不被造。合并通过后以合并 blob 续扫。
34
+ //
35
+ // 历史基线(2026-10-13 ledger-history-baseline,仓库所有者声明):HISTORY_BASELINE 之前的提交不进
36
+ // 前缀扫描——该时代(manifest 特许修剪机制 2026-10-09 之前 + 合并感知 2026-10-13 之前)的删改
37
+ // 无对账凭据,原理上不可追溯验证(回填 manifest 须改写历史且属事后伪造授权);基线由 owner
38
+ // 一次性 loud 声明,同「流程: legacy / 存量不回填」哲学。基线 blob 为可信起点,基线后提交照常
39
+ // 全扫。LEDGER_HISTORY_BASELINE 环境变量可覆盖(测试用)。2026-10-13 盘点:基线前存量标记 71 处
40
+ // (union 合并改写 + 前 manifest 时代清理),详见当日修剪 #3 提交(f16504f)。
41
+ // 2026-10-14 基线前移(owner 声明):PR 647 服务端合并(8c2e1b1d)对主台账取 develop 侧整块,
42
+ // 丢 main 侧 283 行——这 283 行所属 181 个 doc 中 174 个已随特许修剪离开工作树,实质解析正确;
43
+ // 但 TFS 服务端 PR 合并既不运行 jsonl-union 驱动、也无法附带修剪 manifest(该合并提交 manifest
44
+ // 仅声明 8 个早已落地的陈旧哈希,父母并集命中 0),丢行在「历史全扫」下原理上不可追溯补证。
45
+ // 基线自 7a69bc83 前移至 8c2e1b1d(合并后全树一致态为可信起点),基线后提交照常全扫,
46
+ // 终树行级校验不受基线影响、照常全量。
47
+ // 事件登记 workflow/papercuts.d/2026-10.md 2026-10-14 行;丢失行原件 git show c0269da8:.agents/confirmations.jsonl。
48
+ // 2026-10-15 再前移(owner 声明):8c2e1b1d → b6cfd0db。远端提交 b8ce1247(远端机未挂 hooks,门禁
49
+ // 静默失效)单亲改写主台账中段(首异偏移 62995)——带入 18 行整块重复 + 尾部 ts 降序块 + 8 行孤儿
50
+ // 指针(合并时 --staged 并集对账已验零丢失,但该提交自身的前缀破坏无对账凭据、原理上不可追溯补证,
51
+ // 与 PR647 同病理)。b6cfd0db 是 b8ce1247 之后的最新一致态(本仓与 origin/develop 的合并基点),取为
52
+ // 可信起点——窗口同时覆盖两侧并行修复的各自提交:本仓「特许修剪 #6 + 等义回 append」(凭据
53
+ // ledger-prune-manifest,50 行)与远端「特许重建 c22bc2b8」(凭据 ledger-rebuild-manifest,finalRows
54
+ // 289 行)。两条凭据路俱在(matchPrune / matchRebuild),审计面比只认单侧宽;基线后提交照常全扫,
55
+ // 终树行级校验照常全量。
56
+ // 事件登记 workflow/papercuts.d/2026-10.md 2026-10-15 行(两侧各一条 + 合并口径一条)。
57
+ // 2026-10-27 第六次前移(owner 声明):9a0370e8 → e3ceb6c9(PR730 服务端合并后一致态)。
58
+ // 830027060b(2026-10-26 16:57,feature/phase2-MTO-PML 合 develop)与 e3ceb6c9(TFS 服务端合并
59
+ // PR730)对 8 个分片整取单侧,父母并集分别丢 8/6/2/1/1/1/1/1 行;与 PR647/8c2e1b1d 同病理。
60
+ // 丢行已由本支 16670c10 保留、并经 6bd69a2d 本地合并按 jsonl-union 并集恢复(终树行集 = 父母并集,
61
+ // 实测 8 个分片在 HEAD 均无缺行),历史侧不可追溯部分按先例豁免。前移取最小豁免:仅覆盖这两个
62
+ // 合并提交,6bd69a2d 及之后仍全扫。事件登记 workflow/papercuts.d/2026-10.md 2026-10-27 行。
63
+ // 2026-11-05 定点豁免(owner 声明「这是测试密钥,忽略」同轮裁定的发布合入门,非基线前移):main 线
64
+ // 两次回滚提交进 PR 合并检出(refs/pull/N/merge)的祖先链后,历史全扫把 2026-10 的回滚事故判红,
65
+ // 发布 PR 永久不可绿。取定点豁免而非第七次前移:前移会把 develop 10-16~10-27 段重新纳入扫描
66
+ // (该段历史上曾有基线豁免项),风险不可控;定点只覆盖两笔、develop 历史照常全扫。
67
+ // · 4f70a882(还原“已合并 PR 657”):整块回滚 PR 657,主台账被删 57335B——回滚对价,非篡改;
68
+ // · e25127d5(PR 659 合并提交):同一还原的服务端合并收口,父母并集丢 131 行(TFS 不跑 union 驱动,
69
+ // 与 PR647/8c2e1b1d 同病理)。
70
+ // 两笔的终态在 main 与 develop 的合并树中均已归零(main 树 == 8c2e1b1d,develop 全量新增),
71
+ // 无行级丢失。事件登记 workflow/papercuts.d/2026-11.md。
72
+ //
73
+ // 模式:
74
+ // 历史全扫(缺省,CI 机器门):对主台账与每个分片各自遍历其提交历史(时间正序),每次变更必须以
75
+ // 旧 blob 为**逐字节前缀**(允许纯追加;禁止删行/改行/重排)——或前缀破坏但该提交树上有 manifest
76
+ // 恰好对账被删行(特许修剪认领,loud 记录后以新 blob 为基线继续)。分片另判「删除须已归并」。
77
+ // 再对终树(主台账 + 各分片)做行级校验(五项,见下)。
78
+ // blob 读取走 git 对象库(入库 LF 归一口径),不受工作树 autocrlf 影响。
79
+ // --staged(pre-commit 前置):暂存的各台账文件必须以对应 HEAD blob 为逐字节前缀——或携带 manifest
80
+ // 的特许修剪;或携带 rebuild manifest(finalRows 指纹清单)的特许重建——去重/重排在保序语义下无
81
+ // 通道,owner 明令的一次性重建走此路(2026-10-15 ledger-rebuild-manifest,动机见 matchRebuild 头注);
82
+ // 合并进行中(MERGE_HEAD 在场)先认「暂存行集恰为父母行集之并」的纯并集形态
83
+ // (2026-10-15 staged-merge-union,与历史全扫 mergeUnionProblem 同口径——ours==base 时三方合并
84
+ // 整体取 theirs,行序重排必破坏前缀属假阳性),再认「父母并集 − manifest 所列行」的集合对账
85
+ // (2026-10-14 staged-merge-prune,与历史全扫 mergePruneProblem 同口径)。
86
+ // 并集只判**行集合**(多父提交不判前缀),故合并提交可自行排序——两侧并行修复同一台账时(一侧
87
+ // 修剪、一侧重建,被删行在并集中复活),合并提交须把并集按 ts 归位,否则终树行级校验①当场红
88
+ // (2026-10-15 拉取 origin/develop 实证:337 行并集尾部带回旧 ts 行)。
89
+ //
90
+ // 行级校验(终树,逐文件五项):
91
+ // ① ts 为 ISO 字符串且**该文件内**非降序(追加时序单调;跨文件不要求全局单调——分片并发追加下
92
+ // 全局单调不可满足也不必要,单文件单调才是 append-only 的真实不变量)
93
+ // ② fingerprint 为 64 位 hex
94
+ // ③ source=chat-delegated 行必有非空 quote(原话对质面)
95
+ // ④ doc 匹配 workflow/(intents|specs|plans|incidents)/[^/]+.md 且当前树存在(**归档感知**,
96
+ // 2026-10-13 archive-aware-doc:四目录原路径未命中再探 workflow/archive/*/)——关单即归档移动
97
+ // 文件后行仍指向真实文档,移动轨迹由 git 历史承载;与 check-loop「配对门只扫四目录、归档件
98
+ // 不触发」的归档语义对齐
99
+ // ⑤ stage ∈ 合法跳转终态集(approved/done/fixed/closed/superseded/cancelled)
100
+ //
101
+ // 静默条件:台账不存在 / 零提交历史(装户、新仓)/ --staged 且暂存未触任何台账或无 HEAD 版本。
102
+ // 已知边界:git log --follow 未用——各台账路径自创建无重命名(单一路径取史);克隆深度不足时仅扫可得
103
+ // 历史(CI 侧 fetch-depth:0 兜全史,深度不足会告警声明边界,fail-open 于深度、fail-closed 于内容)。
104
+ // 用法:node check-ledger-invariant.mjs [--root <仓库根>] [--staged]
105
+ import { execFileSync, spawnSync } from 'node:child_process';
106
+ import fs from 'node:fs';
107
+ import path from 'node:path';
108
+ import { createHash } from 'node:crypto';
109
+
110
+ const argv = process.argv.slice(2);
111
+ const argOf = (k) => {
112
+ const i = argv.indexOf(k);
113
+ return i >= 0 && i + 1 < argv.length ? argv[i + 1] : '';
114
+ };
115
+ const staged = argv.includes('--staged');
116
+ const ROOT = argOf('--root') || (staged ? process.cwd() : execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).trim());
117
+ const REL = '.agents/confirmations.jsonl';
118
+ const SHARD_DIR = '.agents/confirmations.d';
119
+ const MANIFEST_REL = '.agents/config/ledger-prune-manifest.json';
120
+ const REBUILD_MANIFEST_REL = '.agents/config/ledger-rebuild-manifest.json';
121
+ // 历史基线(owner 声明 2026-10-13,取当日台账 ts 全序恢复提交;2026-10-14 前移至 8c2e1b1d、
122
+ // 2026-10-15 再前移至 b6cfd0db、2026-10-16 四前移至 46beeb7152、2026-10-26 五前移至 9a0370e8、
123
+ // 2026-10-27 六前移至 e3ceb6c9(豁免 830027060b/e3ceb6c9 整取单侧丢行,同 PR647/b8ce1247 先例)——
124
+ // 六次皆 owner 声明,缘由详见头注;env 覆盖供测试)
125
+ const BUILTIN_BASELINE = (() => {
126
+ const raw = 'e3ceb6c901918db828774ddae9370788df0cda68';
127
+ // 装户新仓没有本仓基线提交:解析不出即视为无内置基线,避免新仓每条门禁都报警。
128
+ try { execFileSync('git', ['cat-file', '-e', `${raw}^{commit}`], { cwd: ROOT, stdio: 'ignore' }); return raw; }
129
+ catch { return ''; }
130
+ })();
131
+ // 2026-11-05 定点豁免(owner 声明,缘由见头注「2026-11-05 定点豁免」):main 线两次回滚提交。
132
+ // 只跳过这两笔自身的前缀/并集比对,其后提交仍以其 blob 为基线续扫——不缩小 develop 侧扫描面。
133
+ const LEGACY_EXEMPT = new Map([
134
+ ['4f70a882c2826c413f46ab08f11ac52d1799d85e', '还原“已合并 PR 657”:整块回滚,主台账删 57335B(回滚对价)'],
135
+ ['e25127d5a9e84f2b39d4e2b9f409e07983cd4928', 'PR 659 合并提交:同一还原的服务端合并收口,父母并集丢 131 行(TFS 无 union 驱动)'],
136
+ ]);
137
+ const HISTORY_BASELINE = (() => {
138
+ const v = process.env.LEDGER_HISTORY_BASELINE || BUILTIN_BASELINE;
139
+ // 装户新仓没有本仓基线提交:解析不出即视为无基线(全史扫描),不把本仓哈希当硬事实。
140
+ try { execFileSync('git', ['cat-file', '-e', `${v}^{commit}`], { cwd: ROOT, stdio: 'ignore' }); return v; }
141
+ catch { return ''; }
142
+ })();
143
+ // ---- 增量窗口缓存(2026-11-06 P1 减重)----
144
+ // 判据 = 「上次绿跑时的 HEAD」:该提交及其全部历史当时已验证通过,本轮只需验证 <lastHead>..HEAD。
145
+ // 缓存只记「验证到哪」(head),不记裁决内容;失效键四重——root / baseline / 脚本内容哈希 / HEAD 祖先关系:
146
+ // ① HEAD 未动 → 空窗口(跳过全部历史扫描,终树行级校验照跑);
147
+ // ② lastHead 是 HEAD 祖先 → 只扫 <lastHead>..HEAD;
148
+ // ③ 缓存缺失/损坏、HEAD 回退或无关、基线或脚本变更 → 全量(基线后)扫描。
149
+ // 红跑不写缓存(下轮重扫);写用 tmp+rename 原子替换,并发跑不产半份。
150
+ const LI_CACHE = path.join(ROOT, '.agents', 'cache', 'ledger-invariant.json');
151
+ const _liScriptHash = (() => {
152
+ try { return createHash('sha256').update(fs.readFileSync(process.argv[1] || '', 'utf8')).digest('hex').slice(0, 16); } catch { return ''; }
153
+ })();
154
+ const liCacheHead = () => {
155
+ try {
156
+ const c = JSON.parse(fs.readFileSync(LI_CACHE, 'utf8'));
157
+ if (c && c.v === 1 && c.root === ROOT && c.baseline === HISTORY_BASELINE && c.scriptHash === _liScriptHash && typeof c.head === 'string' && c.head) return c.head;
158
+ } catch { /* 无缓存/损坏 → 全量 */ }
159
+ return null;
160
+ };
161
+ const liCacheWrite = (head) => {
162
+ try {
163
+ fs.mkdirSync(path.dirname(LI_CACHE), { recursive: true });
164
+ const tmp = `${LI_CACHE}.tmp`;
165
+ fs.writeFileSync(tmp, JSON.stringify({ v: 1, root: ROOT, head, baseline: HISTORY_BASELINE, scriptHash: _liScriptHash }));
166
+ fs.renameSync(tmp, LI_CACHE);
167
+ } catch { /* 缓存写失败不影响裁决 */ }
168
+ };
169
+ const liIsAncestor = (a, b) => {
170
+ try { execFileSync('git', ['merge-base', '--is-ancestor', a, b], { cwd: ROOT, encoding: 'utf8' }); return true; } catch { return false; }
171
+ };
172
+ const FILE = path.join(ROOT, REL);
173
+ const VALID_STAGES = new Set(['approved', 'done', 'fixed', 'closed', 'superseded', 'cancelled',
174
+ 'revert-draft', 'revert-open']); // 回退注记行(check-loop :822 认可;fingerprint 恒 n/a)
175
+
176
+ const git = (args, opts = {}) => execFileSync('git', args, { cwd: ROOT, encoding: 'buffer', maxBuffer: 64 * 1024 * 1024, ...opts });
177
+ const gitText = (args) => execFileSync('git', args, { cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
178
+
179
+ // ---- blob 批量读取(2026-10-27 ledger-history-index)----
180
+ // 历史扫描对每个「路径 × 提交」「父 × 路径」都要读一次 blob——实测 2397 次 `git show` 共 122.7s,
181
+ // 是改掉 N 次 `git log`(159s)之后的剩余大头。`cat-file --batch` 一次喂完同样 2397 个对象名仅 0.5s。
182
+ // 语义等价:`git show <sha>:<path>` = `cat-file --batch` 取同一对象;对象不存在时前者非零退出、
183
+ // 后者回「missing」(映射为 null,与 tryBlob 的契约一致)。结果按 ref 永久缓存(索引内同一 ref 只读一次)。
184
+ //
185
+ // 批处理时机:全部待读 ref 一次性预取(调用方在扫描开始前传 refs 列表,见 warmBlobs)。
186
+ // 未预取到的 ref 退回逐个 spawnSync——保持「索引未覆盖/浅克隆」场景的原语义,不 fail-open。
187
+ const _blobCache = new Map();
188
+ const _blobBatchDone = new Set();
189
+ function warmBlobs(refs) {
190
+ const pending = [...new Set(refs)].filter((r) => !_blobCache.has(r) && !_blobBatchDone.has(r));
191
+ if (!pending.length) return;
192
+ pending.forEach((r) => _blobBatchDone.add(r));
193
+ const CHUNK = 2000; // 输入缓冲与输出缓冲双控;单批 ~30MB 输出
194
+ for (let i = 0; i < pending.length; i += CHUNK) {
195
+ const slice = pending.slice(i, i + CHUNK);
196
+ const r = spawnSync('git', ['cat-file', '--batch'], {
197
+ cwd: ROOT,
198
+ input: slice.map((ref) => `${ref}\n`).join(''),
199
+ maxBuffer: 512 * 1024 * 1024,
200
+ });
201
+ if (r.status !== 0 || !r.stdout) continue; // 整批失败 → 落回逐个读
202
+ const buf = r.stdout;
203
+ let off = 0;
204
+ for (const ref of slice) {
205
+ const nl = buf.indexOf(0x0a, off);
206
+ if (nl < 0) break;
207
+ const header = buf.toString('utf8', off, nl);
208
+ off = nl + 1;
209
+ const parts = header.split(' ');
210
+ if (parts.length >= 3) {
211
+ const size = Number(parts[2]);
212
+ if (Number.isFinite(size)) {
213
+ _blobCache.set(ref, buf.subarray(off, off + size));
214
+ off += size + 1; // 内容后跟一个 LF
215
+ continue;
216
+ }
217
+ }
218
+ _blobCache.set(ref, null); // missing / ambiguous
219
+ }
220
+ }
221
+ }
222
+ const blobOf = (ref) => {
223
+ if (_blobCache.has(ref)) {
224
+ const b = _blobCache.get(ref);
225
+ if (b === null) throw new Error(`blob 不存在: ${ref}`);
226
+ return b;
227
+ }
228
+ return git(['show', ref]);
229
+ };
230
+ // tryBlob:安全读 blob,失败返回 null 且**不向父进程外泄 git fatal 噪声**(删片场景读当前提交必失败,
231
+ // 那是预期路径不是错误——execFileSync 会把 fatal 直通 stderr 刷屏,2026-10-12 H3/H4 实证)。
232
+ const tryBlob = (ref) => {
233
+ if (_blobCache.has(ref)) return _blobCache.get(ref);
234
+ const r = spawnSync('git', ['show', ref], { cwd: ROOT, encoding: 'buffer', maxBuffer: 64 * 1024 * 1024 });
235
+ return r.status === 0 ? r.stdout : null;
236
+ };
237
+ const sha256 = (s) => createHash('sha256').update(s, 'utf8').digest('hex');
238
+ const linesOf = (buf) => buf.toString('utf8').split('\n').filter((l, i, a) => !(l === '' && i === a.length - 1) && l !== '');
239
+ const isShard = (rel) => rel.startsWith(`${SHARD_DIR}/`) && rel.endsWith('.jsonl');
240
+
241
+ // ④ 归档感知存在性(2026-10-13 archive-aware-doc):四目录原路径未命中再探 workflow/archive/*/——
242
+ // 归档是 sanctioned 的文档生命周期事件,行的审计价值(指向真实文档)不受移动影响;真消失(既不在
243
+ // 四目录也无归档批次)仍拦。
244
+ const docExists = (doc) => {
245
+ if (fs.existsSync(path.join(ROOT, doc))) return true;
246
+ const m = /^workflow\/(intents|specs|plans|incidents)\/([^/]+)\.md$/.exec(doc);
247
+ if (!m) return false;
248
+ try {
249
+ const arcRoot = path.join(ROOT, 'workflow', 'archive');
250
+ for (const batch of fs.readdirSync(arcRoot)) {
251
+ if (fs.existsSync(path.join(arcRoot, batch, m[1], `${m[2]}.md`))) return true;
252
+ }
253
+ } catch { /* archive 目录不存在 */ }
254
+ return false;
255
+ };
256
+
257
+ // 特许修剪对账:cur === head − manifest.removes 各行(保序);每个哈希恰命中一行且该行 doc ∈ manifest.docs。
258
+ // 返回 null(无 manifest/不匹配+原因)或 {removed, docs}。
259
+ const matchPrune = (headBuf, curBuf, manifest) => {
260
+ if (!manifest || !Array.isArray(manifest.removes) || !manifest.removes.length) return { err: 'manifest 缺失或 removes 为空' };
261
+ const head = linesOf(headBuf);
262
+ const cur = linesOf(curBuf);
263
+ const want = new Set(manifest.removes);
264
+ const kept = head.filter((l) => !want.has(sha256(l)));
265
+ const removedLines = head.filter((l) => want.has(sha256(l)));
266
+ if (removedLines.length !== manifest.removes.length) return { err: `manifest 哈希命中 ${removedLines.length} 行 ≠ 声明 ${manifest.removes.length} 行(哈希不存在或重复)` };
267
+ if (kept.join('\n') !== cur.join('\n')) return { err: '暂存内容 ≠ HEAD − manifest 所列行(存在 manifest 之外的增删改)' };
268
+ const docs = new Set(manifest.docs || []);
269
+ for (const l of removedLines) {
270
+ try {
271
+ const doc = JSON.parse(l).doc || '';
272
+ if (docs.size && !docs.has(path.basename(doc).replace(/\.md$/, ''))) return { err: `被删行 doc ${doc} 不在 manifest.docs 清单内` };
273
+ } catch { return { err: '被删行非 JSON' }; }
274
+ }
275
+ return { removed: removedLines.length, docs: [...docs] };
276
+ };
277
+ const loadManifest = (ref) => {
278
+ // spawnSync + status 判定:execFileSync 失败时 stderr 直通父进程(历史扫描探针在旧提交无 manifest 时
279
+ // 刷屏 fatal 噪声,2026-10-09 修剪实战暴露)——探测失败必须静默归 null
280
+ // 2026-10-27:命中 warmBlobs 预取缓存时零 spawn(历史扫描每次前缀破坏都要探两本 manifest)。
281
+ if (_blobCache.has(ref)) {
282
+ const b = _blobCache.get(ref);
283
+ if (b === null) return null;
284
+ try { return JSON.parse(b.toString('utf8')); } catch { return null; }
285
+ }
286
+ try {
287
+ const r = spawnSync('git', ['show', ref], { cwd: ROOT, encoding: 'utf8' });
288
+ if (r.status !== 0) return null;
289
+ return JSON.parse(r.stdout);
290
+ } catch { return null; }
291
+ };
292
+
293
+ // 特许重建对账(2026-10-15 ledger-rebuild-manifest,owner 明令的一次性重建通道):终态 = HEAD − 声明
294
+ // 副本数(多重集差集逐哈希对账),行内容零改动、零新增(cur − head 须空)、终态既有行不得增副本;
295
+ // 且终态逐行指纹与 manifest.finalRows 严格有序一致(钉死最终形态,排序外夹带必被检出)。
296
+ // 动机:b8ce1247 带病入库(远端机未挂 hooks)引入 18 行整块重复 + 尾部 ts 降序块——「去重 + 重排」
297
+ // 在保序修剪语义下无合法通道(manifest 修剪要求 kept 保序、append-only 禁中段改写),本路补齐;
298
+ // 凭据 = finalRows 全量指纹清单随 rebuild manifest 入库,事后逐行可对质。
299
+ // 返回 null(无 manifest/不匹配+原因)或 { removed, rows }。
300
+ const matchRebuild = (headBuf, curBuf, manifest) => {
301
+ // removes 允许为空(2026-10-16 纯重排放宽):行内容零改动、零新增的前提下,行序调整由 finalRows
302
+ // 指纹清单逐行钉死;仓库现役 manifest(.agents/config/ledger-rebuild-manifest.json,2026-10-18
303
+ // 分片按 ts 稳定排序)即 removes: [] 形态,旧守卫要求非空会把它判成「manifest 缺失」。
304
+ if (!manifest || !Array.isArray(manifest.removes) || !Array.isArray(manifest.finalRows) || !manifest.finalRows.length) return { err: 'rebuild manifest 缺失或 finalRows 为空' };
305
+ const multiset = (lines) => { const m = new Map(); for (const l of lines) { const h = sha256(l); m.set(h, (m.get(h) || 0) + 1); } return m; };
306
+ const head = multiset(linesOf(headBuf));
307
+ const cur = multiset(linesOf(curBuf));
308
+ // ① head − cur 须恰为声明差集(副本数逐哈希对账;cur 增既有行副本 = 禁)
309
+ const diff = new Map();
310
+ for (const [h, c] of head) {
311
+ const d = c - (cur.get(h) || 0);
312
+ if (d < 0) return { err: `终态比 HEAD 多出既有行副本 ${h.slice(0, 12)}…(rebuild 禁增行)` };
313
+ if (d > 0) diff.set(h, d);
314
+ }
315
+ const want = new Map(manifest.removes.map((r) => [r.hash, r.copies]));
316
+ if (diff.size !== want.size || [...want.entries()].some(([h, c]) => diff.get(h) !== c)) return { err: '差集对账失败:实际删除副本 ≠ manifest.removes 声明' };
317
+ // ② cur − head 须空(零新增、零内容改写)
318
+ for (const [h] of cur) if (!head.has(h)) return { err: `终态含 HEAD 没有的行 ${h.slice(0, 12)}…(rebuild 禁造行)` };
319
+ // ③ 终态逐行指纹有序一致
320
+ const curHashes = linesOf(curBuf).map(sha256);
321
+ if (curHashes.length !== manifest.finalRows.length || curHashes.some((h, i) => h !== manifest.finalRows[i])) return { err: '终态行序/指纹与 manifest.finalRows 不一致' };
322
+ return { removed: [...diff.values()].reduce((a, b) => a + b, 0), rows: curHashes.length };
323
+ };
324
+
325
+ const problems = [];
326
+ const fail = (msg) => { console.error(msg); process.exit(1); };
327
+
328
+ // 终树主台账行集(CRLF 归一;补登追认的比对基准——与行级校验「终树」同语义)
329
+ // 补登追认按**语义身份**比对:{doc, stage, fingerprint} 三元组——补登合法形态是补偿行
330
+ // (原 ts 早于尾行时须记现时刻 + note,内容字段沿原行),逐字节比对会漏掉全部合法补偿。
331
+ const finalLedgerRows = () => {
332
+ try {
333
+ return fs.readFileSync(path.join(ROOT, REL), 'utf8').replace(/\r\n/g, '\n').split('\n')
334
+ .filter((l) => l.trim())
335
+ .map((l) => { try { return JSON.parse(l); } catch { return null; } });
336
+ } catch { return null; }
337
+ };
338
+ const restoredInFinal = (missingLines, finRows) => {
339
+ if (!finRows) return false;
340
+ return missingLines.every((l) => {
341
+ let e;
342
+ try { e = JSON.parse(l); } catch { return false; }
343
+ return finRows.some((r) => r && r.doc === e.doc && r.stage === e.stage && r.fingerprint === e.fingerprint);
344
+ });
345
+ };
346
+
347
+ // ---- 分片删除合法性:该分片全部非空行须逐字存在于同一提交的主台账(compact-ledgers 归并凭据)----
348
+ // 返回 null = 合法归并;否则返回原因串。
349
+ // 读法要点:分片在**该提交已被删除**,其内容从各父取并集(2026-10-13 merge-aware-shard-delete)——
350
+ // 合并收口删片时分片可能只在第二父(首父已归并删片,实证 56c45b07),单读 `${sha}^:<rel>` 会误判;
351
+ // 主台账取该提交当时的版本(归并行把分片原样追加进主台账后同提交删片,故主台账须含全部行)。
352
+ const shardDeleteReason = (sha, rel) => {
353
+ const mainBuf = tryBlob(`${sha}:${REL}`);
354
+ if (mainBuf === null) return `该提交无主台账 ${REL}——无法认定归并`;
355
+ const shardLines = new Set();
356
+ let foundInParent = false;
357
+ for (const p of parentShas(sha)) {
358
+ const b = tryBlob(`${p}:${rel}`);
359
+ if (b === null) continue;
360
+ foundInParent = true;
361
+ for (const l of linesOf(b)) if (l.trim()) shardLines.add(l);
362
+ }
363
+ if (!foundInParent) return `父提交 ${sha.slice(0, 10)}^ 中无此分片(增删同提交?)——无法认定归并`;
364
+ const mainLines = new Set(linesOf(mainBuf).filter((l) => l.trim()));
365
+ const missing = [...shardLines].filter((l) => !mainLines.has(l));
366
+ if (missing.length) {
367
+ // 终树补登追认(merge-shard-restore-aware):缺行已按语义身份回append进终树主台账 → 丢失已追认
368
+ if (restoredInFinal(missing, finalLedgerRows())) {
369
+ console.error(`[info] ${sha.slice(0, 10)}:${rel} 合并删片缺 ${missing.length} 行已在终树主台账补登(例:${missing[0].slice(0, 60)}…)——丢失追认,续扫`);
370
+ return null;
371
+ }
372
+ return `删除时分片有 ${missing.length} 行不在同提交主台账内(例:${missing[0].slice(0, 60)}…)——只有 compact-ledgers 归并后才允许删片`;
373
+ }
374
+ return null;
375
+ };
376
+
377
+ // ---- 历史前缀扫描(单台账路径;2026-10-12 起主台账与分片共用)----
378
+ // allowShardDelete:分片允许「已归并后删片」这一种合法消失形态;主台账永不因归并被删。
379
+ // 返回该路径的提交史(空 = 从未入库:装户/新仓/尚在暂存区)——零史路径整体跳过,与原实现
380
+ // 「零提交历史即静默」的契约一致(行级校验也只覆盖有史的路径,否则新仓首版会被 doc 不存在误杀)。
381
+ //
382
+ // 历史索引(2026-10-27 ledger-history-index):此前每路径各跑一次 `git log --full-history`,
383
+ // 293 条路径实测 159.4s(全门 479~798s 的主要构成)。改为**一次** `git log -m --full-history
384
+ // --name-only` 建「路径 → 提交(按时间升序)」倒排,再按路径取。等价性已逐路径比对验证:
385
+ // 293/293 完全一致(`-m` 必需——合并提交默认不输出文件列表,漏了 280 条路径的合并提交)。
386
+ // 索引构建 0.8s;代价是常驻内存一个 Map,且 --staged 档不建索引(只查暂存前缀)。
387
+ let _historyIndex;
388
+ // HEAD 增量磁盘缓存(2026-11-06 P1):全史 `git log -m --full-history --name-only` 是本门剩余地板
389
+ // (实测 git 1.2s + 解析 0.5s;verify 并行负载下 3-4s)。缓存 = { v, root, scriptHash, head, index }:
390
+ // ① HEAD 未动 → 直接用(零 git);② HEAD 前进 → 只走 <cache.head>..HEAD,把新区间的 (路径,提交)
391
+ // 追加进索引(全史升序,区间提交更新 → 追加即保序);③ 回退/损坏/缺失 → 全量重建。
392
+ // 索引是「哪些提交存在」的事实、与裁决无关——故每次构建都写(红跑也写);失效键同 LI_CACHE。
393
+ const LI_IDX_CACHE = path.join(ROOT, '.agents', 'cache', 'ledger-history-index.json');
394
+ const historyIndex = () => {
395
+ if (_historyIndex !== undefined) return _historyIndex;
396
+ _historyIndex = new Map();
397
+ try {
398
+ const head = (gitText(['rev-parse', '--short', 'HEAD']) || '').trim();
399
+ let cached = null;
400
+ if (head) {
401
+ try {
402
+ const c = JSON.parse(fs.readFileSync(LI_IDX_CACHE, 'utf8'));
403
+ if (c && c.v === 1 && c.root === ROOT && c.scriptHash === _liScriptHash && typeof c.head === 'string' && c.head && c.index && typeof c.index === 'object') cached = c;
404
+ } catch { /* 无缓存/损坏 → 全量 */ }
405
+ }
406
+ if (cached && cached.head === head) {
407
+ for (const [k, v] of Object.entries(cached.index)) _historyIndex.set(k, v);
408
+ return _historyIndex; // 命中:零 git 调用
409
+ }
410
+ const out = cached && liIsAncestor(cached.head, head)
411
+ ? gitText(['log', '-m', '--full-history', '--reverse', '--name-only',
412
+ '--pretty=format:@@%H', `${cached.head}..${head}`, '--', SHARD_DIR, REL])
413
+ : gitText(['log', '-m', '--full-history', '--reverse', '--name-only',
414
+ '--pretty=format:@@%H', '--', SHARD_DIR, REL]);
415
+ let cur = null;
416
+ for (const line of out.split(/\r?\n/)) {
417
+ if (line.startsWith('@@')) { cur = line.slice(2).trim(); continue; }
418
+ const p = line.trim();
419
+ if (!cur || !p) continue;
420
+ if (p !== REL && !isShard(p)) continue;
421
+ let arr = _historyIndex.get(p);
422
+ if (!arr) { arr = []; _historyIndex.set(p, arr); }
423
+ if (arr[arr.length - 1] !== cur) arr.push(cur); // -m 会对同一提交重复列出同一路径(合并两亲)
424
+ }
425
+ if (cached) {
426
+ for (const [p, shas] of _historyIndex) {
427
+ const arr = cached.index[p] || [];
428
+ for (const s of shas) if (!arr.includes(s)) arr.push(s);
429
+ cached.index[p] = arr;
430
+ }
431
+ _historyIndex = new Map(Object.entries(cached.index));
432
+ }
433
+ try {
434
+ fs.mkdirSync(path.dirname(LI_IDX_CACHE), { recursive: true });
435
+ const tmp = `${LI_IDX_CACHE}.tmp`;
436
+ fs.writeFileSync(tmp, JSON.stringify({ v: 1, root: ROOT, scriptHash: _liScriptHash, head, index: Object.fromEntries(_historyIndex) }));
437
+ fs.renameSync(tmp, LI_IDX_CACHE);
438
+ } catch { /* 写失败不影响裁决 */ }
439
+ } catch { /* 非 git / 无历史:空索引 → 各路径零史即静默(与原契约一致) */ }
440
+ return _historyIndex;
441
+ };
442
+
443
+ function historyShas(rel) {
444
+ // --full-history 语义保留:不做历史简化——TREESAME 合并也入列,防「合并丢一侧行」被简化隐藏。
445
+ return historyIndex().get(rel) || [];
446
+ }
447
+
448
+ // 基线后提交集(含基线可达性探测)。基线不可解析分诊(2026-10-29 papercut 收口,d/2026-10.md 10-28/10-29 两行):
449
+ // ① 覆盖值(env,测试用口)解析失败 → loud WARN + 回落内置 owner 基线,**不退全史**——此前静默回退
450
+ // 全史曾双害:报 75 条已被 owner 豁免的历史违规(verify 假红 + fail-fast 跳过其后 8 门,一度被
451
+ // 误判为 HEAD 既存红);且把门拖进全史档(gate-cost 窗口 ledger-invariant 中位 182.4s/峰 797.6s
452
+ // 的双峰来源,快路径实测 ~2.8s)。覆盖值是「测试用」入口,残留垃圾值零信息量,回落默认基线
453
+ // ≠ 吞异常(WARN 保可见)。
454
+ // ② 内置基线解析失败(对象库异常/怪浅克隆)→ loud WARN + null = 全史扫描——fail-open 于深度、
455
+ // fail-closed 于内容的既有口径不变,只是不再无声。
456
+ let _postBaseline;
457
+ const postBaselineSet = () => {
458
+ if (_postBaseline !== undefined) return _postBaseline;
459
+ const resolve = (val) => {
460
+ gitText(['rev-parse', '--verify', '--quiet', `${val}^{commit}`]);
461
+ return new Set(gitText(['rev-list', `${val}..HEAD`]).split(/\s+/).filter(Boolean));
462
+ };
463
+ const override = process.env.LEDGER_HISTORY_BASELINE;
464
+ if (override && override !== BUILTIN_BASELINE) {
465
+ try {
466
+ _postBaseline = resolve(override);
467
+ console.error(`[warn] LEDGER_HISTORY_BASELINE 覆盖生效(${override})——测试用覆盖口,基线外提交不豁免`);
468
+ } catch {
469
+ console.error(`[warn] LEDGER_HISTORY_BASELINE="${override}" 在本仓解析不出(持久 shell 残留覆盖值?判据 env | grep LEDGER_HISTORY_BASELINE)——覆盖不生效,回落内置基线 ${BUILTIN_BASELINE.slice(0, 10)},不退全史`);
470
+ try {
471
+ _postBaseline = resolve(BUILTIN_BASELINE);
472
+ } catch {
473
+ console.error('[warn] 内置基线亦解析不出——基线不生效,全史扫描(对象库异常请排查)');
474
+ _postBaseline = null;
475
+ }
476
+ }
477
+ return _postBaseline;
478
+ }
479
+ // 新装户无内置基线(哈希在本仓不存在):直接按全史扫描,不刷无意义告警。
480
+ if (!BUILTIN_BASELINE) {
481
+ _postBaseline = null;
482
+ return _postBaseline;
483
+ }
484
+ try {
485
+ _postBaseline = resolve(BUILTIN_BASELINE);
486
+ } catch {
487
+ console.error(`[warn] 内置基线 ${BUILTIN_BASELINE.slice(0, 10)} 在本仓解析不出——基线不生效,全史扫描(对象库异常请排查)`);
488
+ _postBaseline = null;
489
+ }
490
+ return _postBaseline;
491
+ };
492
+
493
+ // 多父提交的父列表(%P 全父)
494
+ // 批量取(2026-10-27 ledger-history-index):原先每提交一次 `git log -1 --format=%P`,
495
+ // 895 个唯一提交实测 14.7s;`git rev-list --parents <sha...>` 一次取完(实测 0.3s/300 提交)。
496
+ // 2026-11-06 P1:加 `--no-walk`——不带它时 rev-list 会列出这些 sha 的**全部祖先**(200 sha 实测
497
+ // 4584 行 / 350ms),而本表只被「索引内提交」查询(parentShas 两个调用点皆然),故只取给定提交的
498
+ // 父行(200 sha → 200 行 / 119ms,8 批约 −1.9s);未覆盖的 sha 由 parentShas 的逐个兜底接住。
499
+ // 惰性:仅当首次被问到时一次性取全部已知提交的父表(索引内的提交 + HEAD)。
500
+ let _parentMap;
501
+ const parentMap = () => {
502
+ if (_parentMap !== undefined) return _parentMap;
503
+ _parentMap = new Map();
504
+ try {
505
+ const all = new Set(['HEAD']);
506
+ for (const shas of historyIndex().values()) for (const s of shas) all.add(s);
507
+ const list = [...all];
508
+ const CHUNK = 200; // 命令行长度上限保护
509
+ for (let i = 0; i < list.length; i += CHUNK) {
510
+ const out = gitText(['rev-list', '--parents', '--no-walk', ...list.slice(i, i + CHUNK)]);
511
+ for (const line of out.split(/\r?\n/)) {
512
+ const parts = line.trim().split(/\s+/).filter(Boolean);
513
+ if (!parts.length) continue;
514
+ _parentMap.set(parts[0], parts.slice(1));
515
+ }
516
+ }
517
+ } catch { /* 非 git:空表 → 各提交按无父处理(原实现同样退化为空数组) */ }
518
+ return _parentMap;
519
+ };
520
+ const parentShas = (sha) => {
521
+ const m = parentMap().get(sha);
522
+ if (m) return m;
523
+ // 兜底:索引未覆盖的提交(如 --rev 扫他树、浅克隆)仍逐个取,保持原语义
524
+ try {
525
+ return gitText(['log', '-1', '--format=%P', sha]).split(/\s+/).filter(Boolean);
526
+ } catch {
527
+ return [];
528
+ }
529
+ };
530
+
531
+ // 合并并集对账:cur 行集须恰为各父行集之并(无丢失、无凭空新增)。返回 null = 认可;否则返回原因。
532
+ // 父提交无此路径(单侧新增)跳过该父;行比对按整行字符串(与 linesOf/前缀判据同粒度)。
533
+ // 2026-10-15 staged-merge-union:签名自 sha 改收 parents 数组——--staged 合并态无提交 sha,
534
+ // 由调用方传 [HEAD, MERGE_HEAD…];历史全扫与 --staged 共用本判据(不新开口子)。
535
+ const mergeUnionProblem = (parents, rel, curBuf) => {
536
+ const curLines = new Set(linesOf(curBuf));
537
+ const parentLines = new Set();
538
+ for (const p of parents) {
539
+ const b = tryBlob(`${p}:${rel}`);
540
+ if (b === null) continue;
541
+ for (const l of linesOf(b)) parentLines.add(l);
542
+ }
543
+ const lost = [...parentLines].filter((l) => !curLines.has(l));
544
+ if (lost.length) return `合并丢失 ${lost.length} 行(例:${lost[0].slice(0, 60)}…)——union 合并不得丢行`;
545
+ const made = [...curLines].filter((l) => !parentLines.has(l));
546
+ if (made.length) return `合并凭空多出 ${made.length} 行(例:${made[0].slice(0, 60)}…)——合并结果须为各父行集之并`;
547
+ return null;
548
+ };
549
+
550
+ // 合并携带 manifest 的特许修剪对账(2026-10-13 merge-prune-set,独立复核②实修):集合口径——
551
+ // 每个 removes 哈希须恰命中父母并集中一行;cur 行集须恰为「父母并集 − 被删行集」。
552
+ // 支持「分支上修剪、合并时落地」的合法形态(修剪凭据随合并入库);对父母并集对账(非第一父)
553
+ // 堵住 p2 独有行借 p1 相对 manifest 无凭据消失(复核实证二)。返回 null = 认可;否则原因串。
554
+ const mergePruneProblem = (parents, rel, curBuf, manifest) => {
555
+ if (!manifest || !Array.isArray(manifest.removes) || !manifest.removes.length) return 'manifest 缺失或 removes 为空';
556
+ const union = new Set();
557
+ for (const p of parents) {
558
+ const b = tryBlob(`${p}:${rel}`);
559
+ if (b === null) continue;
560
+ for (const l of linesOf(b)) union.add(l);
561
+ }
562
+ const want = new Set(manifest.removes);
563
+ const removed = [...union].filter((l) => want.has(sha256(l)));
564
+ if (removed.length !== manifest.removes.length) return `manifest 哈希在父母并集中命中 ${removed.length} 行 ≠ 声明 ${manifest.removes.length} 行`;
565
+ const removedSet = new Set(removed);
566
+ const expected = [...union].filter((l) => !removedSet.has(l));
567
+ const expectedSet = new Set(expected);
568
+ const curLines = new Set(linesOf(curBuf));
569
+ const extra = [...curLines].filter((l) => !expectedSet.has(l));
570
+ if (extra.length) return `合并多出对账外 ${extra.length} 行(例:${extra[0].slice(0, 60)}…)`;
571
+ const stillLost = expected.filter((l) => !curLines.has(l));
572
+ if (stillLost.length) return `合并仍丢失 manifest 外 ${stillLost.length} 行(例:${stillLost[0].slice(0, 60)}…)`;
573
+ const docs = new Set(manifest.docs || []);
574
+ if (docs.size) {
575
+ for (const l of removed) {
576
+ try {
577
+ const doc = JSON.parse(l).doc || '';
578
+ if (!docs.has(path.basename(doc).replace(/\.md$/, ''))) return `被删行 doc ${doc} 不在 manifest.docs 清单内`;
579
+ } catch { return '被删行非 JSON'; }
580
+ }
581
+ }
582
+ return null;
583
+ };
584
+
585
+ function scanHistory(rel, { allowShardDelete, rangeSet }) {
586
+ const allShas = historyShas(rel);
587
+ if (!allShas.length) return allShas;
588
+ let shas = allShas;
589
+ // 历史基线:只走基线后提交(详见头注)——DAG 感知比对下各提交自对己父,无需线性化起点
590
+ const post = postBaselineSet();
591
+ if (post) {
592
+ const kept = shas.filter((sha) => post.has(sha));
593
+ if (kept.length !== shas.length) {
594
+ console.error(`[info] ${rel}:${shas.length - kept.length} 个前基线提交按 HISTORY_BASELINE 声明豁免(owner 授权,见脚本头注)`);
595
+ }
596
+ shas = kept;
597
+ }
598
+ // 增量窗口(2026-11-06 P1):只走 <lastHead>..HEAD 的提交;窗口外提交上次绿跑已验证
599
+ if (rangeSet) {
600
+ const kept = shas.filter((sha) => rangeSet.has(sha));
601
+ if (kept.length !== shas.length) {
602
+ console.error(`[info] ${rel}:${shas.length - kept.length} 个窗口外提交按增量窗口跳过(上次绿跑已验证)`);
603
+ }
604
+ shas = kept;
605
+ }
606
+ if (LEGACY_EXEMPT.size) {
607
+ const kept = shas.filter((sha) => !LEGACY_EXEMPT.has(sha));
608
+ if (kept.length !== shas.length) {
609
+ for (const sha of shas) if (LEGACY_EXEMPT.has(sha)) console.error(`[info] ${rel}:${sha.slice(0, 10)} 按 LEGACY_EXEMPT 声明豁免——${LEGACY_EXEMPT.get(sha)}`);
610
+ shas = kept;
611
+ }
612
+ }
613
+ for (const sha of shas) {
614
+ let cur;
615
+ try { cur = blobOf(`${sha}:${rel}`); } catch {
616
+ // 删除提交不是静默边界(复核 P2 收口):主台账在 append-only 世界里永不应删除——任一历史提交删除
617
+ // 主台账即 hard fail(否则「删除→次提交重加」会把重加 blob 当新基线绕过前缀判据)。
618
+ if (!allowShardDelete) {
619
+ problems.push(`- [台账删除] ${sha.slice(0, 10)}:该提交删除了 ${rel}(append-only 世界禁删文件)`);
620
+ continue;
621
+ }
622
+ const reason = shardDeleteReason(sha, rel);
623
+ if (reason) {
624
+ problems.push(`- [分片删除] ${sha.slice(0, 10)}:删除 ${rel} —— ${reason}`);
625
+ continue;
626
+ }
627
+ console.error(`[info] ${sha.slice(0, 10)}:${rel} 归并后删除(compact-ledgers 形态,全部行已在主台账对账)`);
628
+ continue;
629
+ }
630
+ // DAG 感知基准:本提交第一父的 blob(2026-10-13 dag-aware-base)——线性化「前一承」在分支汇合处
631
+ // 会拿另一侧提交当基准产生伪前缀破坏(M2 夹具实证);根提交(无父)视为新文件起步。
632
+ const parents = parentShas(sha);
633
+ const base = parents.length ? tryBlob(`${parents[0]}:${rel}`) : null;
634
+ if (base === null) continue; // 首现(父无此路径):无基线可比,行级校验兜底
635
+ if (parents.length >= 2) {
636
+ // 多父提交无条件走并集对账(2026-10-13 复核②实修:前缀通过不得短路——ours-resolution 合并
637
+ // 树与第一父逐字节同 blob,嵌套判法对静默丢行全盲)
638
+ const unionFail = mergeUnionProblem(parents, rel, cur);
639
+ if (!unionFail) {
640
+ console.error(`[info] ${sha.slice(0, 10)}:合并并集无丢失——union 合并语义认可,续扫`);
641
+ continue;
642
+ }
643
+ // union 不过 → manifest 集合对账(分支修剪合并落地;对父母并集对账,非第一父)
644
+ const setFail = mergePruneProblem(parents, rel, cur, loadManifest(`${sha}:${MANIFEST_REL}`));
645
+ if (!setFail) {
646
+ console.error(`[info] ${sha.slice(0, 10)}:合并携带特许修剪——父母并集集合对账通过`);
647
+ continue;
648
+ }
649
+ problems.push(`- [前缀破坏] ${sha.slice(0, 10)}(合并):${rel} 并集对账失败:${unionFail};修剪集合对账:${setFail}`);
650
+ continue;
651
+ }
652
+ if (!cur.subarray(0, base.length).equals(base)) {
653
+ // 前缀破坏 → 该提交树上携带 manifest 且逐行对账 = 特许修剪(loud 记录);
654
+ // 修剪不匹配再试特许重建(rebuild manifest + finalRows 指纹清单,2026-10-15 ledger-rebuild-manifest)
655
+ const m = matchPrune(base, cur, loadManifest(`${sha}:${MANIFEST_REL}`));
656
+ if (m && !m.err) {
657
+ console.error(`[info] ${sha.slice(0, 10)}:特许修剪 ${m.removed} 行(${(m.docs || []).length} 家族)——manifest 对账通过`);
658
+ } else {
659
+ const rb = matchRebuild(base, cur, loadManifest(`${sha}:${REBUILD_MANIFEST_REL}`));
660
+ if (rb && !rb.err) {
661
+ console.error(`[info] ${sha.slice(0, 10)}:特许重建 ${rb.removed > 0 ? `${rb.removed} 副本` : '纯重排(零删除、零新增)'} → 终态 ${rb.rows} 行——finalRows 指纹对账通过`);
662
+ } else {
663
+ let off = 0;
664
+ while (off < Math.min(base.length, cur.length) && base[off] === cur[off]) off++;
665
+ const removed = base.length > cur.length;
666
+ problems.push(`- [前缀破坏] ${sha.slice(0, 10)}(父 ${parents[0].slice(0, 10)}):${rel} 历史内容被${removed ? `删减 ${base.length - cur.length}B` : `改写(首异偏移 ${off},旧 ${base.length}B → 新 ${cur.length}B)`}${m && m.err ? `;特许修剪对账失败:${m.err}` : ''}${rb && rb.err ? `;特许重建对账失败:${rb.err}` : ''}`);
667
+ }
668
+ }
669
+ }
670
+ }
671
+ return allShas; // 交回该路径的全量提交史,供调用方判定「有史才进行级校验」
672
+ }
673
+
674
+ // ---- 行级校验(单文件终树,五项)----
675
+ function checkRows(text, label) {
676
+ const rows = String(text).split(/\r?\n/).filter((l) => l.trim()).map((l) => { try { return JSON.parse(l); } catch { return null; } });
677
+ let prevTs = '';
678
+ rows.forEach((e, idx) => {
679
+ const at = `${label} 第 ${idx + 1} 行`;
680
+ if (!e || typeof e !== 'object') { problems.push(`- [行级] ${at}:非 JSON 对象行`); return; }
681
+ if (typeof e.ts !== 'string' || Number.isNaN(Date.parse(e.ts))) problems.push(`- [行级] ${at}:ts 非 ISO 字符串`);
682
+ else {
683
+ if (prevTs && e.ts < prevTs) problems.push(`- [行级] ${at}:ts ${e.ts} 早于前行 ${prevTs}(追加时序非单调)`);
684
+ prevTs = e.ts;
685
+ }
686
+ const isRevertNote = typeof e.stage === 'string' && e.stage.startsWith('revert-');
687
+ if (isRevertNote) {
688
+ if (e.fingerprint !== 'n/a') problems.push(`- [行级] ${at}:回退注记行 fingerprint 恒为「n/a」`);
689
+ } else if (typeof e.fingerprint !== 'string' || !/^[0-9a-f]{64}$/.test(e.fingerprint)) {
690
+ problems.push(`- [行级] ${at}:fingerprint 非 64 位 hex`);
691
+ }
692
+ // ④' 承诺面指纹(approved-content-binding 2026-10-27):纯增字段、向后兼容——存量行无此键即跳过;
693
+ // 有则须为 16 位 hex(判据单源 stage-gates.commitmentFingerprint)。
694
+ if (typeof e.commit !== 'undefined' && (typeof e.commit !== 'string' || !/^[0-9a-f]{16}$/.test(e.commit))) {
695
+ problems.push(`- [行级] ${at}:commit 非 16 位 hex(承诺面指纹)`);
696
+ }
697
+ if (e.source === 'chat-delegated' && !(typeof e.quote === 'string' && e.quote.trim())) problems.push(`- [行级] ${at}:chat-delegated 行缺非空 quote(原话对质面)`);
698
+ if (typeof e.doc !== 'string' || !/^workflow\/(intents|specs|plans|incidents)\/[^/]+\.md$/.test(e.doc)) {
699
+ problems.push(`- [行级] ${at}:doc 路径不在 workflow 四目录协议内`);
700
+ } else if (!docExists(e.doc)) {
701
+ problems.push(`- [行级] ${at}:doc ${e.doc} 在当前树不存在(四目录与归档批次均未命中)`);
702
+ }
703
+ if (!VALID_STAGES.has(e.stage)) problems.push(`- [行级] ${at}:stage「${e.stage || '缺失'}」不在合法跳转终态集`);
704
+ });
705
+ }
706
+
707
+ // ---- 台账路径全集:主台账 + 历史上出现过的全部分片 ----
708
+ // 历史分片名单复用 historyIndex()(2026-10-27)——不再单独跑一次 log,且与 historyShas 同源,
709
+ // 避免「路径全集」与「各路径提交史」两处口径漂移。
710
+ function ledgerPaths() {
711
+ const rels = [REL];
712
+ try {
713
+ for (const p of historyIndex().keys()) if (isShard(p) && !rels.includes(p)) rels.push(p);
714
+ } catch { /* 非 git 或无历史:仅主台账 */ }
715
+ // 工作区里新出现(尚未入库)的分片也要进行 --staged 前缀判定
716
+ try {
717
+ const dir = path.join(ROOT, SHARD_DIR);
718
+ if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) {
719
+ for (const f of fs.readdirSync(dir)) {
720
+ const p = `${SHARD_DIR}/${f}`;
721
+ if (isShard(p) && !rels.includes(p)) rels.push(p);
722
+ }
723
+ }
724
+ } catch { /* 忽略 */ }
725
+ return rels;
726
+ }
727
+
728
+ // ---- --staged:各暂存台账文件 ⊇ 对应 HEAD 版本,或携带 manifest 的特许修剪 ----
729
+ // 合并态口径(2026-10-14 staged-merge-prune):MERGE_HEAD 在场时暂存内容是**多父合并结果**,单看 HEAD
730
+ // 一父不够——「分支上修剪、合并时落地」的合法形态下暂存 = 父母并集 − removes,其中还含对方分支的
731
+ // 新增/补偿行,故严格等式(HEAD − removes)必然不等而误拦(2026-10-14 实测:本仓合并 origin/develop
732
+ // 时 HEAD 529 行、远端修剪后 283 行,等式差 37 行全是对方合法新增)。此时在严格等格外**再试父母并集
733
+ // 集合对账**——与历史全扫同一函数 mergePruneProblem、同一口径,不新开口子:manifest 哈希须在并集中
734
+ // 恰命中、并集 − 被删行须与暂存逐行相等(既禁丢行也禁凭空行)。非合并态不启用,单父写入红线不变。
735
+ const mergeParents = (() => {
736
+ const r = spawnSync('git', ['rev-parse', 'MERGE_HEAD'], { cwd: ROOT, encoding: 'utf8' }); // octopus 可多行
737
+ if (r.status !== 0) return null; // 非合并态;spawnSync 吞 stderr,不外泄 fatal 噪声
738
+ const shas = String(r.stdout || '').split(/\s+/).filter(Boolean);
739
+ if (!shas.length) return null;
740
+ const h = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, encoding: 'utf8' });
741
+ return [String(h.stdout || '').trim(), ...shas];
742
+ })();
743
+ if (staged) {
744
+ const stagedHit = gitText(['-c', 'core.quotepath=off', 'diff', '--cached', '--name-only']).split(/\r?\n/);
745
+ const touched = ledgerPaths().filter((rel) => stagedHit.includes(rel));
746
+ if (!touched.length) process.exit(0);
747
+ for (const rel of touched) {
748
+ const headExists = (() => { try { gitText(['rev-parse', '--verify', '--quiet', `HEAD:${rel}`]); return true; } catch { return false; } })();
749
+ if (!headExists) continue; // 首次入库:无 HEAD 基线,历史全扫与终树行级校验覆盖
750
+ let head, cur;
751
+ try {
752
+ head = blobOf(`HEAD:${rel}`);
753
+ cur = blobOf(`:${rel}`); // 暂存区
754
+ } catch {
755
+ continue; // 对象读取异常(如极端并发)交由 CI 全扫兜底
756
+ }
757
+ if (!cur.subarray(0, head.length).equals(head)) {
758
+ // 前缀破坏 → 尝试特许修剪对账(manifest 必须同在暂存集)
759
+ const manifest = loadManifest(`:${MANIFEST_REL}`);
760
+ const m = matchPrune(head, cur, manifest);
761
+ if (m && !m.err) {
762
+ console.log(`台账不变量(--staged)— ${rel} 特许修剪通过:移除 ${m.removed} 行(${(m.docs || []).length} 家族)——凭据 ${MANIFEST_REL} 随笔入库,被删行可在 git 历史对质`);
763
+ continue;
764
+ }
765
+ // 特许重建对账(2026-10-15 ledger-rebuild-manifest):rebuild manifest 须同在暂存集
766
+ const rb = matchRebuild(head, cur, loadManifest(`:${REBUILD_MANIFEST_REL}`));
767
+ if (rb && !rb.err) {
768
+ console.log(`台账不变量(--staged)— ${rel} 特许重建通过:${rb.removed > 0 ? `删重复副本 ${rb.removed} 行` : '纯重排(零删除、零新增)'}、终态 ${rb.rows} 行与 finalRows 指纹清单逐行一致——凭据 ${REBUILD_MANIFEST_REL} 随笔入库,差集可对质`);
769
+ continue;
770
+ }
771
+ // 合并态:严格等式不适用 → 先纯并集对账(2026-10-15 staged-merge-union:与历史全扫同一函数
772
+ // mergeUnionProblem、同一判据。实战动机:本地侧自分叉基线未动台账时,三方合并整体取远端版——
773
+ // 其行序相对 HEAD 可为重排/中插(远端按 ts 时序插入),前缀判据必假阳性;并集「无丢失、无凭空行」
774
+ // 才是审计实质。判负再落 manifest 修剪对账,与历史全扫的判定顺序一致)。
775
+ const unionFail = mergeParents ? mergeUnionProblem(mergeParents, rel, cur) : '非合并态';
776
+ if (!unionFail) {
777
+ console.log(`台账不变量(--staged)— ${rel} 合并并集无丢失认可(${mergeParents.length} 父)——暂存行集恰为父母行集之并(无丢失、无凭空行),union 语义与历史全扫同口径`);
778
+ continue;
779
+ }
780
+ const setErr = mergeParents ? mergePruneProblem(mergeParents, rel, cur, manifest) : '非合并态';
781
+ if (!setErr) {
782
+ console.log(`台账不变量(--staged)— ${rel} 合并携带特许修剪通过:父母并集集合对账认可(${mergeParents.length} 父)——凭据 ${MANIFEST_REL} 随笔入库,被删行可在 git 历史对质`);
783
+ continue;
784
+ }
785
+ let off = 0;
786
+ while (off < Math.min(head.length, cur.length) && head[off] === cur[off]) off++;
787
+ problems.push(`- [台账重写] ${rel} 暂存内容不是 HEAD 的前缀扩展(首异偏移 ${off},HEAD ${head.length}B → 暂存 ${cur.length}B)${m && m.err ? `;特许修剪对账失败:${m.err}` : ''}${rb && rb.err ? `;特许重建对账失败:${rb.err}` : ''}${mergeParents ? `;合并并集集合对账亦失败:${setErr}` : ''}${mergeParents ? `;合并纯并集对账失败:${unionFail}` : ''}`);
788
+ }
789
+ }
790
+ if (problems.length) {
791
+ console.error('台账不可变(--staged)— BLOCK:\n' + problems.join('\n'));
792
+ console.error(' 修法:台账历史行禁删改——误写走追加补偿行(node .agents/scripts/confirm-doc.mjs ...);所有者明令清理须携带逐行 sha256 的 ledger-prune-manifest.json 同笔暂存');
793
+ if (problems.some((p) => p.startsWith('- [台账重写] .agents/confirmations.d/'))) {
794
+ console.error(' 分片重写另因:分片按 doc 命名、单端追加;跨端并发确认同一 doc 时须有 merge=jsonl-union 驱动(node .agents/scripts/check-local-gates.mjs --fix 配置)——驱动生效则合并自动取并集、不破坏前缀');
795
+ }
796
+ process.exit(1);
797
+ }
798
+ process.exit(0);
799
+ }
800
+
801
+ // ---- 历史全扫(缺省)----
802
+ // 有提交史的路径才进历史扫描**与终树行级校验**——零史路径(装户/新仓/尚在暂存区)整体跳过,
803
+ // 与原实现「零提交历史即静默」的契约一致(否则新仓首版会被 doc 不存在误杀)。
804
+ const withHistory = new Set();
805
+ let rangeSet = null; // 增量窗口(2026-11-06 P1):null = 全量(基线后);空集 = HEAD 未动,跳过历史扫描
806
+ {
807
+ // 批量预取(2026-10-27 ledger-history-index):扫描会读「每路径每提交的 blob」与「每父每路径的 blob」,
808
+ // 先按索引把全部候选 ref 一次喂给 cat-file(2397 次 show 122.7s → 一次批读 0.5s)。
809
+ // 只预取基线后的提交——基线前的提交在 scanHistory 里本就被过滤,不读其 blob。
810
+ // 增量窗口(2026-11-06 P1):rangeSet 非空时只预取窗口内提交的 ref(失效键见 LI_CACHE 头注)。
811
+ const post = postBaselineSet();
812
+ const rels = ledgerPaths();
813
+ // 新仓/装户首提交前 HEAD 不存在:rev-parse 会非零退出;按「零史路径整体跳过」契约继续。
814
+ let __head = '';
815
+ try { __head = (gitText(['rev-parse', '--short', 'HEAD']) || '').trim(); } catch { __head = ''; }
816
+ const __last = liCacheHead();
817
+ if (__last && __head) {
818
+ if (__last === __head) rangeSet = new Set();
819
+ else if (liIsAncestor(__last, __head)) {
820
+ rangeSet = new Set(gitText(['rev-list', `${__last}..${__head}`]).split(/\s+/).filter(Boolean));
821
+ }
822
+ }
823
+ const refs = [];
824
+ for (const rel of rels) {
825
+ const shas = (historyIndex().get(rel) || []).filter((s) => (!post || post.has(s)) && (!rangeSet || rangeSet.has(s)));
826
+ for (const sha of shas) {
827
+ refs.push(`${sha}:${rel}`);
828
+ const parents = parentMap().get(sha) || [];
829
+ for (const p of parents) refs.push(`${p}:${rel}`);
830
+ }
831
+ }
832
+ // manifest 也走批读(每次前缀破坏都要探测两本)
833
+ for (const sha of new Set(refs.map((r) => r.split(':')[0]))) {
834
+ refs.push(`${sha}:${MANIFEST_REL}`, `${sha}:${REBUILD_MANIFEST_REL}`);
835
+ }
836
+ warmBlobs(refs);
837
+ }
838
+ for (const rel of ledgerPaths()) {
839
+ const shas = scanHistory(rel, { allowShardDelete: isShard(rel), rangeSet });
840
+ if (shas && shas.length) withHistory.add(rel);
841
+ }
842
+
843
+ // ---- 行级校验(终树:主台账 + 各现存分片;仅覆盖有提交史的路径)----
844
+ const finalRels = [REL];
845
+ try {
846
+ const dir = path.join(ROOT, SHARD_DIR);
847
+ if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) {
848
+ for (const f of fs.readdirSync(dir)) {
849
+ const p = `${SHARD_DIR}/${f}`;
850
+ if (isShard(p)) finalRels.push(p);
851
+ }
852
+ }
853
+ } catch { /* 忽略 */ }
854
+ for (const rel of finalRels) {
855
+ if (!withHistory.has(rel)) continue; // 零提交历史:无基线可校验,静默跳过
856
+ const abs = path.join(ROOT, rel);
857
+ if (!fs.existsSync(abs)) continue;
858
+ let text;
859
+ try { text = fs.readFileSync(abs, 'utf8'); } catch { continue; }
860
+ checkRows(text, rel === REL ? '主台账' : path.basename(rel));
861
+ }
862
+
863
+ if (problems.length) {
864
+ console.error(`台账不可变(历史全扫)— HARD-BLOCK:\n\n${problems.join('\n')}\n`);
865
+ console.error(' 修法:台账历史行禁删改(append-only 前缀不变量)——误写只能追加补偿行;确需撤销历史提交请 git revert 后重新追加。篡改属审计事件,保留现场联系仓库所有者。');
866
+ process.exit(1);
867
+ }
868
+ // 增量窗口缓存(2026-11-06 P1):绿跑才写——记「历史已验证到 HEAD」;红跑不写,下轮重扫
869
+ try {
870
+ const __h = (gitText(['rev-parse', '--short', 'HEAD']) || '').trim();
871
+ if (__h) liCacheWrite(__h);
872
+ } catch { /* 非 git:不写 */ }
873
+ process.exit(0);