specdojo 0.7.0 → 0.8.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 (337) hide show
  1. package/.github/agents/specdojo-orchestrator.md +3 -2
  2. package/CHANGELOG.md +153 -0
  3. package/dist/catalog/build.js +24 -1
  4. package/dist/catalog/plan.js +1 -1
  5. package/dist/catalog/scaffold.js +4 -1
  6. package/dist/commands/init.js +5 -1
  7. package/dist/commands/night-orchestrator.js +6 -4
  8. package/dist/dashboard/dashboard-timeline.js +18 -16
  9. package/dist/dashboard/dashboard.js +612 -259
  10. package/dist/dashboard/epic-plan.js +81 -0
  11. package/dist/dashboard/exec-records.js +16 -20
  12. package/dist/dashboard/routines.js +8 -6
  13. package/dist/dashboard/timeline-build.js +5 -9
  14. package/dist/dashboard/timeline.js +9 -4
  15. package/dist/devcontainer/scaffold.js +18 -0
  16. package/dist/docs/frontmatter-namespace.js +1 -48
  17. package/dist/docs/yaml-pages.js +125 -3
  18. package/dist/exec/agent-config.js +22 -0
  19. package/dist/exec/agent-plan.js +3 -2
  20. package/dist/exec/commands.js +69 -21
  21. package/dist/exec/commit-hook-skips.js +78 -0
  22. package/dist/exec/core.js +19 -7
  23. package/dist/exec/events.js +159 -8
  24. package/dist/exec/evidence.js +64 -16
  25. package/dist/exec/handoff.js +9 -13
  26. package/dist/exec/limit.js +1 -1
  27. package/dist/exec/mechanical-result.js +45 -0
  28. package/dist/exec/migrate-records.js +249 -0
  29. package/dist/exec/parent-validation.js +153 -12
  30. package/dist/exec/pipeline-state.js +27 -5
  31. package/dist/exec/plans-condense-findings.js +89 -0
  32. package/dist/exec/plans-core.js +24 -17
  33. package/dist/exec/plans-generation.js +48 -25
  34. package/dist/exec/plans-grade-findings.js +8 -3
  35. package/dist/exec/plans-kata-findings.js +61 -0
  36. package/dist/exec/plans-planning.js +3 -3
  37. package/dist/exec/plans-storage.js +12 -24
  38. package/dist/exec/register-resume.js +55 -56
  39. package/dist/exec/register.js +26 -22
  40. package/dist/exec/repo-integration-sync.js +8 -4
  41. package/dist/exec/repo-integration.js +21 -1
  42. package/dist/exec/reporter.js +121 -23
  43. package/dist/exec/results.js +85 -24
  44. package/dist/exec/review-completion.js +47 -0
  45. package/dist/exec/review-kata.js +109 -0
  46. package/dist/exec/run/agent-pipeline.js +75 -6
  47. package/dist/exec/run/agent.js +20 -7
  48. package/dist/exec/run/in-place.js +69 -32
  49. package/dist/exec/run/job.js +81 -24
  50. package/dist/exec/run/lifecycle-commands.js +188 -36
  51. package/dist/exec/run/mode-shared.js +11 -3
  52. package/dist/exec/run/register-command.js +6 -10
  53. package/dist/exec/run/register-core.js +20 -13
  54. package/dist/exec/run/register-mode.js +12 -12
  55. package/dist/exec/run/register-post-review.js +21 -9
  56. package/dist/exec/run/register-resume.js +28 -18
  57. package/dist/exec/run/register-state.js +10 -7
  58. package/dist/exec/run/register-worktree.js +60 -30
  59. package/dist/exec/run/schedule-mode.js +4 -4
  60. package/dist/exec/run/schedule-prepare.js +201 -59
  61. package/dist/exec/run/schedule-task.js +129 -25
  62. package/dist/exec/run/shared.js +4 -3
  63. package/dist/exec/run/trailing-records.js +35 -0
  64. package/dist/exec/run-records.js +2 -0
  65. package/dist/exec/strategy.js +1 -0
  66. package/dist/exec/trailing-records.js +242 -0
  67. package/dist/exec/trial-commands.js +3 -2
  68. package/dist/exec/validate-records-commit.js +110 -0
  69. package/dist/exec/validate-records.js +148 -0
  70. package/dist/exec/worktree-command.js +29 -16
  71. package/dist/exec/worktree-ops-commit.js +119 -48
  72. package/dist/exec/worktree-ops-lifecycle.js +77 -48
  73. package/dist/exec/worktree-ops-merge.js +13 -2
  74. package/dist/exec/worktree-ops.js +2 -2
  75. package/dist/exec/worktree.js +19 -2
  76. package/dist/grade/apply.js +32 -6
  77. package/dist/grade/command-inspect.js +2 -2
  78. package/dist/grade/command-run.js +2 -0
  79. package/dist/grade/command-shared.js +1 -1
  80. package/dist/grade/core.js +18 -5
  81. package/dist/grade/markdown.js +3 -3
  82. package/dist/grade/pipeline-state.js +15 -11
  83. package/dist/grade/plan.js +37 -17
  84. package/dist/grade/result.js +3 -3
  85. package/dist/grade/run.js +23 -3
  86. package/dist/grade/target-discovery.js +17 -4
  87. package/dist/grade/targets.js +12 -11
  88. package/dist/job/job.js +31 -17
  89. package/dist/job/noop.js +104 -0
  90. package/dist/register/core.js +2 -0
  91. package/dist/register/create-commands.js +28 -3
  92. package/dist/register/deliverable-target.js +9 -1
  93. package/dist/register/epic.js +104 -26
  94. package/dist/register/event-merge.js +3 -0
  95. package/dist/register/events.js +4 -0
  96. package/dist/register/external-project.js +3 -0
  97. package/dist/register/item.js +6 -0
  98. package/dist/register/maintenance-commands.js +4 -1
  99. package/dist/register/planning.js +7 -14
  100. package/dist/register/register.js +43 -9
  101. package/dist/register/track-domains.js +34 -0
  102. package/dist/register/track-plan.js +78 -0
  103. package/dist/register/transition-commands.js +8 -0
  104. package/dist/register/work-table.js +64 -0
  105. package/dist/review/grade.js +35 -13
  106. package/dist/routine/definition.js +4 -3
  107. package/dist/routine/failure.js +30 -0
  108. package/dist/routine/routine.js +56 -32
  109. package/dist/routine/storage.js +33 -0
  110. package/dist/schedule/schedule.js +1 -0
  111. package/dist/schedule/strategy-generate-document.js +26 -14
  112. package/dist/schedule/strategy-generate-scope.js +17 -45
  113. package/dist/schedule/strategy-generate.js +33 -3
  114. package/dist/schedule/strategy-profiles.js +86 -12
  115. package/dist/shared/agent-types.js +2 -0
  116. package/dist/shared/condense-records.js +25 -0
  117. package/dist/shared/deprecation.js +8 -0
  118. package/dist/shared/document-metadata.js +20 -0
  119. package/dist/shared/finding-cause.js +20 -0
  120. package/dist/shared/frontmatter-namespace.js +48 -0
  121. package/dist/shared/git.js +142 -15
  122. package/dist/shared/grade-result.js +17 -1
  123. package/dist/shared/local-state.js +20 -0
  124. package/dist/shared/markdownlint-config.js +8 -3
  125. package/dist/shared/plan-conventions.js +129 -0
  126. package/dist/shared/plan-templates.js +57 -41
  127. package/dist/shared/run-records.js +224 -0
  128. package/dist/shared/specdojo-config.js +39 -21
  129. package/dist/shared/text.js +65 -5
  130. package/dist/shared/timeline-index.js +2 -0
  131. package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +9 -2
  132. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +4 -74
  133. package/docs/ja/specdojo/exec-templates/xep-condense-template.md +50 -0
  134. package/docs/ja/specdojo/exec-templates/xep-draft-template.md +17 -5
  135. package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +16 -3
  136. package/docs/ja/specdojo/exec-templates/xep-recipe-guided-template.md +15 -5
  137. package/docs/ja/specdojo/exec-templates/xep-recipe-maintenance-template.md +6 -0
  138. package/docs/ja/specdojo/exec-templates/xep-register-template.md +1 -1
  139. package/docs/ja/specdojo/exec-templates/xep-rulebook-maintenance-template.md +6 -0
  140. package/docs/ja/specdojo/exec-templates/xep-sample-maintenance-template.md +6 -0
  141. package/docs/ja/specdojo/exec-templates/xep-template-maintenance-template.md +6 -0
  142. package/docs/ja/specdojo/exec-templates/xer-condense-template.md +25 -0
  143. package/docs/ja/specdojo/exec-templates/xp-common-conventions-template.md +50 -0
  144. package/docs/ja/specdojo/exec-templates/xrp-common-conventions-template.md +30 -0
  145. package/docs/ja/specdojo/guides/branch-workflow-guide.md +1 -1
  146. package/docs/ja/specdojo/guides/docs-editing-guide.md +12 -0
  147. package/docs/ja/specdojo/guides/docs-structure-guide.md +48 -15
  148. package/docs/ja/specdojo/guides/exec-config-guide.md +47 -16
  149. package/docs/ja/specdojo/guides/exec-operation-guide.md +53 -17
  150. package/docs/ja/specdojo/guides/exec-worktree-guide.md +20 -11
  151. package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +92 -55
  152. package/docs/ja/specdojo/guides/project-move-guide.md +381 -0
  153. package/docs/ja/specdojo/guides/quick-start-guide.md +70 -14
  154. package/docs/ja/specdojo/guides/register-operation-guide.md +25 -5
  155. package/docs/ja/specdojo/guides/remote-host-development-guide.md +2 -0
  156. package/docs/ja/specdojo/guides/review-guide.md +22 -19
  157. package/docs/ja/specdojo/guides/routine-operation-guide.md +14 -8
  158. package/docs/ja/specdojo/guides/ryu-guide.md +23 -13
  159. package/docs/ja/specdojo/guides/schedule-design-guide.md +7 -4
  160. package/docs/ja/specdojo/guides/schedule-operation-guide.md +27 -3
  161. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +5 -4
  162. package/docs/ja/specdojo/guides/timeline-design-guide.md +27 -144
  163. package/docs/ja/specdojo/guides/use-case-guide.md +92 -155
  164. package/docs/ja/specdojo/recipes/bac-recipe.md +94 -0
  165. package/docs/ja/specdojo/recipes/bes-recipe.md +105 -0
  166. package/docs/ja/specdojo/recipes/br-recipe.md +84 -0
  167. package/docs/ja/specdojo/recipes/cdfd-uc-recipe.md +36 -24
  168. package/docs/ja/specdojo/recipes/cnd-recipe.md +125 -0
  169. package/docs/ja/specdojo/recipes/cpd-recipe.md +126 -0
  170. package/docs/ja/specdojo/recipes/cxd-recipe.md +145 -0
  171. package/docs/ja/specdojo/recipes/ifd-recipe.md +134 -0
  172. package/docs/ja/specdojo/recipes/ifx-cmd-recipe.md +135 -86
  173. package/docs/ja/specdojo/recipes/ifx-index-recipe.md +130 -0
  174. package/docs/ja/specdojo/recipes/pm-organization-recipe.md +29 -26
  175. package/docs/ja/specdojo/recipes/pm-plan-recipe.md +35 -26
  176. package/docs/ja/specdojo/recipes/pm-quality-management-plan-recipe.md +38 -28
  177. package/docs/ja/specdojo/recipes/pm-raci-recipe.md +39 -31
  178. package/docs/ja/specdojo/recipes/pm-roles-recipe.md +26 -28
  179. package/docs/ja/specdojo/recipes/prj-assumptions-constraints-dependencies-recipe.md +10 -8
  180. package/docs/ja/specdojo/recipes/prj-comparison-of-alternatives-recipe.md +18 -17
  181. package/docs/ja/specdojo/recipes/stsd-recipe.md +100 -62
  182. package/docs/ja/specdojo/recipes/sysd-critical-flows-recipe.md +106 -0
  183. package/docs/ja/specdojo/recipes/sysd-cross-cutting-policy-recipe.md +137 -0
  184. package/docs/ja/specdojo/recipes/sysd-index-recipe.md +122 -0
  185. package/docs/ja/specdojo/references/command-reference.md +79 -64
  186. package/docs/ja/specdojo/references/deliverables-reference.md +9 -4
  187. package/docs/ja/specdojo/references/directory-layout-reference.md +3 -2
  188. package/docs/ja/specdojo/references/specdojo-config-reference.md +17 -16
  189. package/docs/ja/specdojo/rulebooks/bac-rulebook.md +72 -290
  190. package/docs/ja/specdojo/rulebooks/bdd-rulebook.md +212 -79
  191. package/docs/ja/specdojo/rulebooks/bds-rulebook.md +138 -154
  192. package/docs/ja/specdojo/rulebooks/bes-index-rulebook.md +147 -59
  193. package/docs/ja/specdojo/rulebooks/bes-rulebook.md +100 -96
  194. package/docs/ja/specdojo/rulebooks/br-rulebook.md +88 -108
  195. package/docs/ja/specdojo/rulebooks/ccd-mermaid-rulebook.md +126 -211
  196. package/docs/ja/specdojo/rulebooks/cdfd-uc-rulebook.md +56 -35
  197. package/docs/ja/specdojo/rulebooks/cdsd-rulebook.md +102 -68
  198. package/docs/ja/specdojo/rulebooks/cdt-rulebook.md +152 -0
  199. package/docs/ja/specdojo/rulebooks/cld-rulebook.md +9 -184
  200. package/docs/ja/specdojo/rulebooks/clis-rulebook.md +187 -0
  201. package/docs/ja/specdojo/rulebooks/cnd-rulebook.md +93 -247
  202. package/docs/ja/specdojo/rulebooks/cpd-rulebook.md +104 -241
  203. package/docs/ja/specdojo/rulebooks/cxd-rulebook.md +124 -257
  204. package/docs/ja/specdojo/rulebooks/dct-index-rulebook.md +87 -98
  205. package/docs/ja/specdojo/rulebooks/dct-rulebook.md +9 -7
  206. package/docs/ja/specdojo/rulebooks/dec-rulebook.md +2 -1
  207. package/docs/ja/specdojo/rulebooks/dss-rulebook.md +193 -0
  208. package/docs/ja/specdojo/rulebooks/gl-rulebook.md +100 -54
  209. package/docs/ja/specdojo/rulebooks/ifd-mermaid-rulebook.md +69 -252
  210. package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +91 -76
  211. package/docs/ja/specdojo/rulebooks/ifx-file-rulebook.md +252 -226
  212. package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +118 -40
  213. package/docs/ja/specdojo/rulebooks/imp-business-rulebook.md +11 -11
  214. package/docs/ja/specdojo/rulebooks/imp-data-rulebook.md +9 -9
  215. package/docs/ja/specdojo/rulebooks/imp-interface-rulebook.md +4 -4
  216. package/docs/ja/specdojo/rulebooks/imp-operations-rulebook.md +11 -11
  217. package/docs/ja/specdojo/rulebooks/imp-test-rulebook.md +11 -11
  218. package/docs/ja/specdojo/rulebooks/mm-rulebook.md +4 -3
  219. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +34 -29
  220. package/docs/ja/specdojo/rulebooks/pm-change-request-log-rulebook.md +8 -8
  221. package/docs/ja/specdojo/rulebooks/pm-issue-log-rulebook.md +2 -2
  222. package/docs/ja/specdojo/rulebooks/pm-organization-rulebook.md +50 -56
  223. package/docs/ja/specdojo/rulebooks/pm-plan-rulebook.md +46 -55
  224. package/docs/ja/specdojo/rulebooks/pm-quality-management-plan-rulebook.md +57 -54
  225. package/docs/ja/specdojo/rulebooks/pm-raci-rulebook.md +50 -65
  226. package/docs/ja/specdojo/rulebooks/pm-risk-register-rulebook.md +2 -2
  227. package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +70 -97
  228. package/docs/ja/specdojo/rulebooks/pr-rulebook.md +2 -1
  229. package/docs/ja/specdojo/rulebooks/prj-assumptions-constraints-dependencies-rulebook.md +47 -56
  230. package/docs/ja/specdojo/rulebooks/prj-comparison-of-alternatives-rulebook.md +61 -135
  231. package/docs/ja/specdojo/rulebooks/sf-index-rulebook.md +116 -32
  232. package/docs/ja/specdojo/rulebooks/sf-rulebook.md +118 -61
  233. package/docs/ja/specdojo/rulebooks/sld-rulebook.md +152 -57
  234. package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +51 -39
  235. package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +101 -46
  236. package/docs/ja/specdojo/rulebooks/sysd-critical-flows-rulebook.md +72 -329
  237. package/docs/ja/specdojo/rulebooks/sysd-cross-cutting-policy-rulebook.md +74 -263
  238. package/docs/ja/specdojo/rulebooks/sysd-index-rulebook.md +78 -195
  239. package/docs/ja/specdojo/rulebooks/tml-rulebook.md +4 -9
  240. package/docs/ja/specdojo/rulebooks/trc-requirements-to-specs-rulebook.md +3 -4
  241. package/docs/ja/specdojo/rulebooks/trc-requirements-to-tests-rulebook.md +3 -3
  242. package/docs/ja/specdojo/rulebooks/uis-rulebook.md +140 -143
  243. package/docs/ja/specdojo/samples/bac-sample.md +106 -21
  244. package/docs/ja/specdojo/samples/bdd-sample.yaml +143 -35
  245. package/docs/ja/specdojo/samples/bds-sample.md +100 -21
  246. package/docs/ja/specdojo/samples/bes-index-sample.md +59 -20
  247. package/docs/ja/specdojo/samples/bes-sample.md +80 -21
  248. package/docs/ja/specdojo/samples/br-sample.md +68 -14
  249. package/docs/ja/specdojo/samples/ccd-sample.md +81 -19
  250. package/docs/ja/specdojo/samples/cdfd-sample.md +172 -99
  251. package/docs/ja/specdojo/samples/cdfd-uc-sample.md +9 -7
  252. package/docs/ja/specdojo/samples/cdsd-sample.md +89 -20
  253. package/docs/ja/specdojo/samples/cdt-sample.md +116 -0
  254. package/docs/ja/specdojo/samples/cld-sample.md +3 -30
  255. package/docs/ja/specdojo/samples/clis-sample.md +132 -0
  256. package/docs/ja/specdojo/samples/cnd-sample.md +127 -21
  257. package/docs/ja/specdojo/samples/cpd-sample.md +136 -22
  258. package/docs/ja/specdojo/samples/cxd-sample.md +108 -22
  259. package/docs/ja/specdojo/samples/dct-index-sample.yaml +63 -17
  260. package/docs/ja/specdojo/samples/dss-sample.md +175 -0
  261. package/docs/ja/specdojo/samples/gl-sample.yaml +50 -14
  262. package/docs/ja/specdojo/samples/ifd-sample.md +105 -21
  263. package/docs/ja/specdojo/samples/ifx-cmd-sample.yaml +91 -60
  264. package/docs/ja/specdojo/samples/ifx-file-sample.md +462 -21
  265. package/docs/ja/specdojo/samples/ifx-index-sample.yaml +87 -19
  266. package/docs/ja/specdojo/samples/pm-members-sample.yaml +37 -13
  267. package/docs/ja/specdojo/samples/pm-organization-sample.md +52 -20
  268. package/docs/ja/specdojo/samples/pm-plan-sample.md +84 -26
  269. package/docs/ja/specdojo/samples/pm-quality-management-plan-sample.md +55 -22
  270. package/docs/ja/specdojo/samples/pm-raci-sample.md +69 -28
  271. package/docs/ja/specdojo/samples/pm-roles-sample.yaml +13 -12
  272. package/docs/ja/specdojo/samples/prj-assumptions-constraints-dependencies-sample.md +50 -26
  273. package/docs/ja/specdojo/samples/prj-comparison-of-alternatives-sample.md +89 -62
  274. package/docs/ja/specdojo/samples/sf-index-sample.md +89 -20
  275. package/docs/ja/specdojo/samples/sf-sample.md +121 -21
  276. package/docs/ja/specdojo/samples/sld-sample.md +107 -21
  277. package/docs/ja/specdojo/samples/stsd-sample.md +54 -26
  278. package/docs/ja/specdojo/samples/sysd-critical-flows-sample.md +166 -21
  279. package/docs/ja/specdojo/samples/sysd-cross-cutting-policy-sample.md +178 -21
  280. package/docs/ja/specdojo/samples/sysd-index-sample.md +82 -21
  281. package/docs/ja/specdojo/samples/tml-sample.yaml +4 -1
  282. package/docs/ja/specdojo/samples/uis-sample.md +164 -20
  283. package/docs/ja/specdojo/standards/document-metadata-standard.md +33 -4
  284. package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +3 -1
  285. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +1 -0
  286. package/docs/ja/specdojo/templates/bac-template.md +76 -0
  287. package/docs/ja/specdojo/templates/bes-template.md +56 -0
  288. package/docs/ja/specdojo/templates/br-template.md +64 -0
  289. package/docs/ja/specdojo/templates/cdfd-template.md +81 -54
  290. package/docs/ja/specdojo/templates/cdfd-uc-template.md +9 -5
  291. package/docs/ja/specdojo/templates/cnd-template.md +137 -0
  292. package/docs/ja/specdojo/templates/cpd-template.md +129 -0
  293. package/docs/ja/specdojo/templates/cxd-template.md +105 -0
  294. package/docs/ja/specdojo/templates/dct-data-model-cdt-template.yaml +40 -0
  295. package/docs/ja/specdojo/templates/dct-data-model-cld-template.yaml +7 -14
  296. package/docs/ja/specdojo/templates/dct-index-template.md +9 -20
  297. package/docs/ja/specdojo/templates/dct-project-management-template.yaml +5 -1
  298. package/docs/ja/specdojo/templates/ifd-template.md +86 -0
  299. package/docs/ja/specdojo/templates/ifx-cmd-template.yaml +44 -28
  300. package/docs/ja/specdojo/templates/ifx-index-template.yaml +40 -0
  301. package/docs/ja/specdojo/templates/opr-template.md +2 -4
  302. package/docs/ja/specdojo/templates/pm-organization-template.md +9 -3
  303. package/docs/ja/specdojo/templates/pm-plan-template.md +4 -4
  304. package/docs/ja/specdojo/templates/pm-quality-management-plan-template.md +17 -9
  305. package/docs/ja/specdojo/templates/pm-raci-template.md +24 -13
  306. package/docs/ja/specdojo/templates/pm-roles-template.yaml +3 -2
  307. package/docs/ja/specdojo/templates/prj-assumptions-constraints-dependencies-template.md +6 -3
  308. package/docs/ja/specdojo/templates/prj-comparison-of-alternatives-template.md +22 -19
  309. package/docs/ja/specdojo/templates/stsd-template.md +46 -21
  310. package/docs/ja/specdojo/templates/sysd-critical-flows-template.md +94 -0
  311. package/docs/ja/specdojo/templates/sysd-cross-cutting-policy-template.md +122 -0
  312. package/docs/ja/specdojo/templates/sysd-index-template.md +89 -0
  313. package/docs/specdojo/lib/yaml-metadata.cjs +7 -0
  314. package/docs/specdojo/schemas/v1/bdd.schema.yaml +25 -57
  315. package/docs/specdojo/schemas/v1/condense-records.schema.yaml +26 -0
  316. package/docs/specdojo/schemas/v1/dct.schema.yaml +10 -0
  317. package/docs/specdojo/schemas/v1/deliverable-frontmatter.schema.yaml +3 -0
  318. package/docs/specdojo/schemas/v1/esil.schema.yaml +7 -141
  319. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +3 -0
  320. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +53 -3
  321. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +3 -0
  322. package/docs/specdojo/schemas/v1/exec-plan-frontmatter.schema.yaml +14 -0
  323. package/docs/specdojo/schemas/v1/exec-result-frontmatter.schema.yaml +18 -0
  324. package/docs/specdojo/schemas/v1/finding-cause.schema.yaml +22 -0
  325. package/docs/specdojo/schemas/v1/grade-pipeline-state.schema.yaml +1 -1
  326. package/docs/specdojo/schemas/v1/grade-result.schema.yaml +2 -0
  327. package/docs/specdojo/schemas/v1/ifx-cmd.schema.yaml +65 -5
  328. package/docs/specdojo/schemas/v1/ifx-index.schema.yaml +142 -0
  329. package/docs/specdojo/schemas/v1/register-events.schema.yaml +2 -0
  330. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +17 -1
  331. package/package.json +2 -2
  332. package/templates/antigravity/orchestrator.md +3 -2
  333. package/templates/claude/agents/specdojo-orchestrator.md +3 -2
  334. package/templates/codex/agents/specdojo-orchestrator.toml +3 -2
  335. package/templates/codex/orchestrator.md +3 -2
  336. package/templates/devcontainer/tmux.conf +6 -0
  337. package/templates/opencode/agents/specdojo-orchestrator.md +3 -2
@@ -1,9 +1,11 @@
1
1
  import { readFileSync, renameSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join, relative, sep } from "node:path";
3
+ import { runLogPath, runnerRecordPrefixes, taskEvidencePaths, taskRecordPaths, } from "./run-records.js";
3
4
  import { ensureDir, redactSensitiveText, safeSlug } from "./shared.js";
4
5
  import { gitOutput } from "./worktree.js";
6
+ import { isCondenseRecords } from "../shared/condense-records.js";
5
7
  const MAX_LOG_BYTES = 64 * 1024;
6
- const MAX_CHANGE_FILES = 1_000;
8
+ export const MAX_CHANGE_FILES = 1_000;
7
9
  const MAX_FINAL_MESSAGE_LENGTH = 4_000;
8
10
  const MAX_HANDOFF_ITEMS = 100;
9
11
  const MAX_HANDOFF_LENGTH = 4_000;
@@ -108,6 +110,22 @@ export function parseExecutorReport(stdout) {
108
110
  });
109
111
  }
110
112
  }
113
+ const invalidCondense = report.condense_records !== undefined && !isCondenseRecords(report.condense_records);
114
+ if (invalidCondense) {
115
+ report.completion_status = "incomplete";
116
+ report.final_message =
117
+ "Invalid condense_records; supply records matching condense-records.schema.yaml";
118
+ }
119
+ const condenseRecords = isCondenseRecords(report.condense_records)
120
+ ? report.condense_records.map((record) => ({
121
+ ...record,
122
+ location: boundedText(record.location, 4000),
123
+ reason: boundedText(record.reason, 4000),
124
+ cause: record.cause.type === "kata"
125
+ ? { ...record.cause, location: boundedText(record.cause.location, 4000) }
126
+ : record.cause,
127
+ }))
128
+ : undefined;
111
129
  const fallback = stdout.replace(REPORT_PATTERN, "").trim();
112
130
  const handoff = Array.isArray(report.handoff)
113
131
  ? report.handoff
@@ -127,6 +145,7 @@ export function parseExecutorReport(stdout) {
127
145
  handoff,
128
146
  validations,
129
147
  targetCoverage,
148
+ ...(condenseRecords ? { condenseRecords } : {}),
130
149
  };
131
150
  }
132
151
  /** A successful process or validation batch cannot override an explicit incomplete report. */
@@ -136,6 +155,39 @@ export function executorCompletionFailure(evidence) {
136
155
  const detail = boundedText(evidence.final_message, MAX_VALIDATION_SUMMARY_LENGTH);
137
156
  return boundedText(detail ? `executor reported incomplete: ${detail}` : "executor reported incomplete", MAX_VALIDATION_SUMMARY_LENGTH);
138
157
  }
158
+ /**
159
+ * Returns why the executor envelope lacks a field the approach requires, or undefined when the
160
+ * contract holds. Only `condense` currently requires an extra field (`condense_records`).
161
+ */
162
+ export function executorReportContractFailure(evidence, contract) {
163
+ if (contract.approach !== "condense" || (contract.mode ?? "edit") !== "edit")
164
+ return undefined;
165
+ if (isCondenseRecords(evidence.condense_records))
166
+ return undefined;
167
+ return "executor evidence lacks valid condense_records required by approach condense (report [] when there are no candidates)";
168
+ }
169
+ /** Recovery command for a task whose executor stage must be redone in the kept worktree. */
170
+ export function executorStageResumeHint(target) {
171
+ const command = target.kind === "schedule"
172
+ ? `specdojo exec resume --task ${target.taskId} --resume-from executor`
173
+ : `specdojo exec run --register ${target.itemId} --worktree --resume --resume-from executor`;
174
+ return `${command} (add --executor-by <nickname> to switch the executor agent)`;
175
+ }
176
+ /**
177
+ * Checks the approach contract before the reporter stage. On failure the evidence is marked as an
178
+ * incomplete executor report and persisted, so resume selects the executor stage instead of
179
+ * re-running only the reporter on the same evidence.
180
+ */
181
+ export function enforceExecutorReportContract(input) {
182
+ const failure = executorReportContractFailure(input.evidence, input.contract);
183
+ if (!failure)
184
+ return undefined;
185
+ const reason = boundedText(`${failure}; next: ${input.resumeHint}`, MAX_VALIDATION_SUMMARY_LENGTH);
186
+ input.evidence.completion_status = "incomplete";
187
+ input.evidence.block_reason = reason;
188
+ writeExecutorEvidence(input.evidencePath, input.evidence);
189
+ return reason;
190
+ }
139
191
  function normalizedEvidencePath(value) {
140
192
  const normalized = value.replaceAll("\\", "/").replace(/^\.\//u, "");
141
193
  if (!normalized ||
@@ -333,6 +385,7 @@ export function buildExecutorEvidence(input) {
333
385
  summary: truncate(redactSensitiveText(input.diffStat.trim()), MAX_DIFF_SUMMARY_LENGTH),
334
386
  },
335
387
  validations,
388
+ ...(report.condenseRecords ? { condense_records: report.condenseRecords } : {}),
336
389
  ...(report.targetCoverage.length > 0 ? { target_coverage: report.targetCoverage } : {}),
337
390
  ...(input.rateLimitEvents?.length ? { rate_limit_events: input.rateLimitEvents } : {}),
338
391
  final_message: report.finalMessage,
@@ -362,10 +415,8 @@ export function buildExecutorEvidence(input) {
362
415
  export function recordExecutorEvidence(input) {
363
416
  const executionRel = repoRelative(input.repoRoot, input.executionPath);
364
417
  const runnerManagedPrefixes = [
365
- `${executionRel}/exec/plans/`,
366
- `${executionRel}/exec/results/`,
418
+ ...runnerRecordPrefixes(executionRel),
367
419
  `${executionRel}/exec/events/`,
368
- `${executionRel}/exec/evidence/`,
369
420
  `${executionRel}/generated/`,
370
421
  ];
371
422
  const productWorktrees = input.productWorktrees ?? [];
@@ -387,10 +438,9 @@ export function recordExecutorEvidence(input) {
387
438
  .filter(Boolean)
388
439
  .join("\n");
389
440
  const executionInWorktree = join(input.worktreePath, executionRel);
390
- const evidenceDir = join(executionInWorktree, "exec", "evidence", safeSlug(input.taskId), safeSlug(input.runId));
441
+ const { directory: evidenceDir, evidence: evidencePath } = taskEvidencePaths(executionInWorktree, input.taskId, input.runId);
391
442
  ensureDir(evidenceDir);
392
- const logPath = join(evidenceDir, "executor.log");
393
- const evidencePath = join(evidenceDir, "evidence.json");
443
+ const logPath = runLogPath(evidencePath, "executor.log");
394
444
  const { evidence, logExcerpt } = buildExecutorEvidence({
395
445
  taskId: input.taskId,
396
446
  runId: input.runId,
@@ -417,10 +467,8 @@ export function recordExecutorEvidence(input) {
417
467
  export function recordCommandEvidence(input) {
418
468
  const executionRel = repoRelative(input.repoRoot, input.executionPath);
419
469
  const runnerManagedPrefixes = [
420
- `${executionRel}/exec/plans/`,
421
- `${executionRel}/exec/results/`,
470
+ ...runnerRecordPrefixes(executionRel),
422
471
  `${executionRel}/exec/events/`,
423
- `${executionRel}/exec/evidence/`,
424
472
  `${executionRel}/generated/`,
425
473
  ];
426
474
  const changes = parseStatusPaths(input.worktreePath)
@@ -431,11 +479,11 @@ export function recordCommandEvidence(input) {
431
479
  status: boundedText(change.status, 40),
432
480
  }));
433
481
  const diffStat = gitOutput(input.worktreePath, ["diff", "--stat", "HEAD", "--"]);
434
- const evidenceDir = join(input.worktreePath, executionRel, "exec", "evidence", safeSlug(input.taskId), safeSlug(input.runId));
482
+ const evidenceDir = taskRecordPaths(join(input.worktreePath, executionRel), input.taskId, input.runId).directory;
435
483
  ensureDir(evidenceDir);
436
- const stdoutPath = join(evidenceDir, "command.stdout.log");
437
- const stderrPath = join(evidenceDir, "command.stderr.log");
438
- const evidencePath = join(evidenceDir, "evidence.json");
484
+ const evidencePath = taskRecordPaths(join(input.worktreePath, executionRel), input.taskId, input.runId).evidence;
485
+ const stdoutPath = runLogPath(evidencePath, "command.stdout.log");
486
+ const stderrPath = runLogPath(evidencePath, "command.stderr.log");
439
487
  const boundedStdout = boundedLog(input.stdout);
440
488
  const boundedStderr = boundedLog(input.stderr);
441
489
  writeFileSync(stdoutPath, boundedStdout.content, "utf8");
@@ -537,7 +585,7 @@ export function recordParentValidationFailureOutput(input) {
537
585
  const attempt = Math.max(0, ...priorAttempts) + 1;
538
586
  const refs = [];
539
587
  for (const output of input.failureOutputs) {
540
- const logPath = join(evidenceDir, `parent-validation-attempt-${attempt}-${safeSlug(output.label)}.log`);
588
+ const logPath = runLogPath(input.evidencePath, `parent-validation-attempt-${attempt}-${safeSlug(output.label)}.log`);
541
589
  const content = redactSensitiveText([
542
590
  `parent validation: ${output.label}`,
543
591
  `exit code: ${output.exitCode ?? "unknown"}`,
@@ -577,7 +625,7 @@ export function recordReporterFailureOutput(input) {
577
625
  input.invocationOutputs.forEach((output, index) => {
578
626
  const attempt = index + 1;
579
627
  for (const stream of ["stdout", "stderr"]) {
580
- const logPath = join(evidenceDir, `reporter-attempt-${attempt}.${stream}.log`);
628
+ const logPath = runLogPath(input.evidencePath, `reporter-attempt-${attempt}.${stream}.log`);
581
629
  const boundedOutput = boundedLog(output[stream]);
582
630
  writeFileSync(logPath, boundedOutput.content, "utf8");
583
631
  reporterRefs.push({
@@ -1,18 +1,19 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { existsSync, lstatSync, mkdtempSync, readFileSync, readdirSync, rmSync, unlinkSync, writeFileSync, } from "node:fs";
2
+ import { lstatSync, mkdtempSync, readFileSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
- import { createInterface } from "node:readline/promises";
5
4
  import { join, posix, resolve } from "node:path";
5
+ import { createInterface } from "node:readline/promises";
6
+ import { parseSpecdojoDocument } from "../docs/frontmatter-namespace.js";
7
+ import { specdojoRootDir } from "../shared/specdojo-config.js";
6
8
  import { isAgentProtectedConfigPath } from "./agent-protected-config.js";
7
9
  import { PROTECTION_HANDOFF_MARKER } from "./protection-handoff.js";
8
10
  import { normalizePjrId, resolveRegisterRunTarget } from "./register.js";
9
11
  import { refsTrailer, withCommitTrailers } from "./repo-trace.js";
10
- import { configuredProductReposForProject } from "./task-repos.js";
11
- import { parseSpecdojoDocument } from "../docs/frontmatter-namespace.js";
12
+ import { listRunRecords } from "./run-records.js";
12
13
  import { qualifyTaskId } from "./shared.js";
13
- import { specdojoRootDir } from "../shared/specdojo-config.js";
14
+ import { configuredProductReposForProject } from "./task-repos.js";
15
+ import { stabilizeCommitTargets, stageCommitTargets, unstageCommitTargets, worktreeStatusPaths, } from "./worktree-ops.js";
14
16
  import { findExecWorktree, formatGitResultFailure, gitEnvironment, gitOutput, gitResult, } from "./worktree.js";
15
- import { stageCommitTargets, stabilizeCommitTargets, unstageCommitTargets, worktreeStatusPaths, } from "./worktree-ops.js";
16
17
  const HANDOFF_MECHANISM = "agent-config-write";
17
18
  const TRUNCATED_EVIDENCE_RE = /^\.\.\. \((?:\d+ 行を省略|文字数上限で切り詰め)\)$/m;
18
19
  function sectionAfterMarker(content) {
@@ -56,13 +57,8 @@ export function extractProtectedConfigHandoff(content) {
56
57
  return { subjects, patch: `${patch}\n` };
57
58
  }
58
59
  function latestResultForTask(executionPath, taskId) {
59
- const resultsDir = join(executionPath, "exec", "results");
60
- if (!existsSync(resultsDir))
61
- throw new Error(`Result directory not found: ${resultsDir}`);
62
- const candidates = readdirSync(resultsDir)
63
- .filter((name) => name.endsWith("-result.md"))
64
- .flatMap((name) => {
65
- const path = join(resultsDir, name);
60
+ const candidates = listRunRecords(executionPath, "result")
61
+ .flatMap((path) => {
66
62
  const data = parseSpecdojoDocument(readFileSync(path, "utf8")).data;
67
63
  if (data.task_id !== taskId)
68
64
  return [];
@@ -247,7 +247,7 @@ function deferredTask(taskId, state, now) {
247
247
  const attempts = attemptsText && /^\d+$/.test(attemptsText) ? Number.parseInt(attemptsText, 10) : 0;
248
248
  return {
249
249
  taskId,
250
- actor: state.last_by ?? "",
250
+ actor: state.claimed_by ?? state.last_by ?? "",
251
251
  kind,
252
252
  resumeAt: resumeAt.toISOString(),
253
253
  attempts,
@@ -0,0 +1,45 @@
1
+ import { MAX_TEXT_LENGTH } from "./reporter-output.js";
2
+ import { deriveReporterFacts } from "./reporter.js";
3
+ const MAX_SUMMARY_ITEMS = 100;
4
+ export const MECHANICAL_RESULT_APPROACH = "reporter を使わず、runner が executor の報告(`final_message`・`handoff`)と証跡から機械的に作成した(`pipeline.mechanical_result`)。";
5
+ function bounded(text) {
6
+ return text.length <= MAX_TEXT_LENGTH ? text : `${text.slice(0, MAX_TEXT_LENGTH - 1)}…`;
7
+ }
8
+ // executor の `final_message` は箇条書きや複数行の要約になることがある。行頭の箇条書きの記号を
9
+ // 外し、1 行を実施内容の 1 項目にする。
10
+ function summaryItems(finalMessage) {
11
+ return finalMessage
12
+ .split(/\r?\n/)
13
+ .map((line) => line.replace(/^\s*(?:[-*+]|\d+\.)\s+/, "").trim())
14
+ .filter(Boolean)
15
+ .slice(0, MAX_SUMMARY_ITEMS)
16
+ .map(bounded);
17
+ }
18
+ /**
19
+ * PJR-T01P: the edit result fields the runner can fill without the reporter agent. Returns
20
+ * `undefined` when a field needs summarising or judgement, so the caller runs the reporter:
21
+ * review mode (verdict), a blocked outcome (the reporter explains partial work), or an executor
22
+ * report without `final_message`.
23
+ *
24
+ * - `summary`: the lines of the executor's `final_message`.
25
+ * - `changed_files`: empty; the renderer lists the evidence changes with git line counts.
26
+ * - `handoff`: empty; the renderer keeps the executor `handoff` and the runner-derived notes.
27
+ * - `approach`: a fixed sentence stating that the runner wrote the result.
28
+ */
29
+ export function mechanicalEditReporterOutput(evidence, mode = "edit") {
30
+ if (mode !== "edit")
31
+ return undefined;
32
+ const summary = summaryItems(evidence.final_message ?? "");
33
+ if (summary.length === 0)
34
+ return undefined;
35
+ if (deriveReporterFacts(evidence, { mode }).outcome !== "complete")
36
+ return undefined;
37
+ return {
38
+ schema_version: 1,
39
+ mode: "edit",
40
+ summary,
41
+ changed_files: [],
42
+ handoff: [],
43
+ approach: MECHANICAL_RESULT_APPROACH,
44
+ };
45
+ }
@@ -0,0 +1,249 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
+ import { readSpecdojoNamespace } from "../shared/frontmatter-namespace.js";
5
+ import { listFilesRecursive } from "../shared/fs.js";
6
+ import { gitEnvironment } from "../shared/git.js";
7
+ import { rebasePlanConventions } from "../shared/plan-conventions.js";
8
+ import { recordIdentity, taskRecordPaths } from "../shared/run-records.js";
9
+ import { specdojoRootDir } from "../shared/specdojo-config.js";
10
+ import { addProjectOptions, resolveProjectContext, resolveProjectId } from "./core.js";
11
+ import { qualifyTaskId } from "./shared.js";
12
+ import { listRegisteredWorktrees, worktreeNameFromTaskId } from "./worktree.js";
13
+ const posix = (path) => path.split(sep).join("/");
14
+ const json = (path) => JSON.parse(readFileSync(path, "utf8"));
15
+ /** Retain formatting and every non-reference value, including historical change paths. */
16
+ function rewriteJsonPaths(source, rewrite) {
17
+ JSON.parse(source);
18
+ const stack = [];
19
+ return source.replace(/"(?:[^"\\]|\\.)*"|[{}[\]]/g, (token, offset) => {
20
+ const parent = stack.at(-1);
21
+ if (token === "{" || token === "[") {
22
+ stack.push({ field: parent?.key ?? "", key: "" });
23
+ }
24
+ else if (token === "}" || token === "]") {
25
+ stack.pop();
26
+ }
27
+ else if (/^\s*:/.test(source.slice(offset + token.length))) {
28
+ if (parent)
29
+ parent.key = JSON.parse(token);
30
+ }
31
+ else if (parent &&
32
+ (/(?:_ref|_path)$/.test(parent.key) ||
33
+ (parent.key === "path" && stack.some((frame) => frame.field === "log_refs")))) {
34
+ return JSON.stringify(rewrite(JSON.parse(token)));
35
+ }
36
+ return token;
37
+ });
38
+ }
39
+ /** Plan first, validate every destination, then mutate. No clock or random identity is used. */
40
+ export function planRecordMigration(repoRoot, executionPath, projectId) {
41
+ const root = resolve(repoRoot);
42
+ const execution = resolve(executionPath);
43
+ const repoRef = (path) => posix(relative(root, path));
44
+ const pairs = new Map();
45
+ for (const kind of ["plan", "result"]) {
46
+ for (const path of listFilesRecursive(join(execution, "exec", `${kind}s`)).sort()) {
47
+ if (!path.endsWith(`-${kind}.md`))
48
+ throw new Error(`Unknown legacy record: ${path}`);
49
+ const stem = basename(path).replace(new RegExp(`-${kind}\\.md$`), "");
50
+ const fm = readSpecdojoNamespace(readFileSync(path, "utf8"));
51
+ if (typeof fm.task_id !== "string" || !fm.task_id.trim())
52
+ throw new Error(`Missing task_id: ${path}`);
53
+ const pair = pairs.get(stem) ?? { stem, task: fm.task_id };
54
+ if (pair[kind] || pair.task !== fm.task_id)
55
+ throw new Error(`Ambiguous pair: ${stem}`);
56
+ pair[kind] = path;
57
+ pairs.set(stem, pair);
58
+ }
59
+ }
60
+ const evidenceRoot = join(execution, "exec", "evidence");
61
+ const directories = new Map();
62
+ for (const path of listFilesRecursive(evidenceRoot).sort()) {
63
+ const directory = dirname(path);
64
+ directories.set(directory, [...(directories.get(directory) ?? []), path]);
65
+ }
66
+ const groups = [];
67
+ for (const [directory, files] of directories) {
68
+ const parts = relative(evidenceRoot, directory).split(sep);
69
+ if (parts.length !== 2)
70
+ throw new Error(`Unknown evidence directory: ${directory}`);
71
+ const metadata = ["pipeline-state.json", "evidence.json"]
72
+ .map((name) => join(directory, name))
73
+ .filter(existsSync)
74
+ .map(json);
75
+ const state = metadata.find((record) => record.artifacts);
76
+ const artifacts = state?.artifacts;
77
+ const task = metadata[0]?.task_id ?? parts[0];
78
+ const run = metadata[0]?.run_id ?? parts[1];
79
+ if (typeof task !== "string" || typeof run !== "string")
80
+ throw new Error(`Invalid evidence identity: ${directory}`);
81
+ if (metadata.some((record) => record.task_id !== task || record.run_id !== run))
82
+ throw new Error(`Conflicting evidence identities: ${directory}`);
83
+ groups.push({
84
+ task,
85
+ run,
86
+ files,
87
+ refs: Object.values(artifacts ?? {}).filter((value) => typeof value === "string"),
88
+ updated: String(metadata[0]?.updated_at ?? run),
89
+ });
90
+ }
91
+ // A retained exec worktree may still resume with the old paths and its own index.
92
+ // Refuse even dry-runs before planning updates; stopped processes alone are insufficient.
93
+ const tasks = new Set([...pairs.values(), ...groups].map(({ task }) => task));
94
+ if (tasks.size) {
95
+ for (const worktree of listRegisteredWorktrees(root)) {
96
+ if (!worktree.branch?.startsWith("exec/") || !existsSync(worktree.path))
97
+ continue;
98
+ for (const task of tasks) {
99
+ const names = [task, recordIdentity(task).itemId].map(worktreeNameFromTaskId);
100
+ const branchTask = worktree.branch.slice("exec/".length);
101
+ const matches = names.some((name) => branchTask === name ||
102
+ (projectId
103
+ ? branchTask === worktreeNameFromTaskId(qualifyTaskId(projectId, name))
104
+ : branchTask.endsWith(`-${name}`)));
105
+ if (matches)
106
+ throw new Error(`Migration target ${task} has a retained exec worktree: ${worktree.path} ` +
107
+ `(${worktree.branch}). Finish or discard the run and remove its worktree before migrating`);
108
+ }
109
+ }
110
+ }
111
+ const virtualRefs = [];
112
+ const moves = [];
113
+ const add = (from, to) => moves.push({ from: repoRef(from), to: repoRef(to) });
114
+ for (const group of groups) {
115
+ const records = taskRecordPaths(execution, group.task, group.run);
116
+ for (const path of group.files)
117
+ add(path, records.log(basename(path)));
118
+ virtualRefs.push({ from: repoRef(dirname(group.files[0])), to: repoRef(records.directory) });
119
+ }
120
+ const missing = [];
121
+ for (const pair of pairs.values()) {
122
+ if (!pair.plan || !pair.result)
123
+ missing.push({ stem: pair.stem, missing: pair.plan ? "result" : "plan" });
124
+ // Exact checkpoint refs are authoritative. For pre-checkpoint records, associate only
125
+ // an unambiguous task/pair; otherwise retain separate runs instead of guessing by time.
126
+ let candidates = groups.filter((group) => group.refs.some((ref) => [pair.plan, pair.result].some((path) => path && (ref === repoRef(path) || ref === posix(relative(execution, path))))));
127
+ if (candidates.length === 0 &&
128
+ [...pairs.values()].filter((p) => p.task === pair.task).length === 1)
129
+ candidates = groups.filter((group) => group.task === pair.task && group.refs.length === 0);
130
+ const latest = candidates
131
+ .sort((a, b) => a.updated.localeCompare(b.updated) || a.run.localeCompare(b.run))
132
+ .at(-1);
133
+ const records = taskRecordPaths(execution, pair.task, latest?.run ?? pair.stem);
134
+ if (pair.plan)
135
+ add(pair.plan, records.plan);
136
+ if (pair.result)
137
+ add(pair.result, records.result);
138
+ for (const kind of ["plan", "result"]) {
139
+ if (!pair[kind])
140
+ virtualRefs.push({
141
+ from: repoRef(join(execution, "exec", `${kind}s`, `${pair.stem}-${kind}.md`)),
142
+ to: repoRef(records[kind]),
143
+ });
144
+ }
145
+ }
146
+ moves.sort((a, b) => a.from.localeCompare(b.from));
147
+ const destinations = new Set();
148
+ for (const move of moves) {
149
+ if (destinations.has(move.to) || existsSync(join(root, move.to)))
150
+ throw new Error(`Migration destination already exists: ${move.to}`);
151
+ if (isAbsolute(move.to) || move.to.startsWith("../"))
152
+ throw new Error(`Migration destination outside repository: ${move.to}`);
153
+ destinations.add(move.to);
154
+ }
155
+ // References can be repository-relative, execution-relative, or absolute under a previous
156
+ // checkout. Match the execution suffix without changing prose, commands, IDs, or log bodies.
157
+ const refs = new Map();
158
+ for (const move of [...moves, ...virtualRefs]) {
159
+ refs.set(move.from, move.to);
160
+ refs.set(posix(relative(execution, join(root, move.from))), posix(relative(execution, join(root, move.to))));
161
+ }
162
+ const rewrite = (value) => {
163
+ const direct = refs.get(value);
164
+ if (direct)
165
+ return direct;
166
+ for (let slash = value.indexOf("/"); slash >= 0; slash = value.indexOf("/", slash + 1)) {
167
+ const target = refs.get(value.slice(slash + 1));
168
+ if (target)
169
+ return `${value.slice(0, slash + 1)}${target}`;
170
+ }
171
+ return value;
172
+ };
173
+ const updates = [];
174
+ const targets = new Map(moves.map((move) => [move.from, move.to]));
175
+ const structured = [
176
+ ...moves.map((move) => join(root, move.from)),
177
+ ...listFilesRecursive(join(execution, "jobs", "runs")),
178
+ ];
179
+ for (const path of structured) {
180
+ if (!/\.(json|md)$/.test(path))
181
+ continue;
182
+ const original = readFileSync(path, "utf8");
183
+ let content = original;
184
+ if (path.endsWith(".json")) {
185
+ content = rewriteJsonPaths(original, rewrite);
186
+ }
187
+ else if (path.endsWith(".md")) {
188
+ content = original.replace(/^---\r?\n[\s\S]*?\r?\n---/, (fm) => fm.replace(/^(\s*[\w]+(?:_ref|_path):\s*)([^\r\n]+)$/gm, (_line, key, raw) => {
189
+ const quote = raw.startsWith('"') ? '"' : raw.startsWith("'") ? "'" : "";
190
+ const value = quote ? raw.slice(1, -1) : raw;
191
+ return `${key}${quote}${rewrite(value)}${quote}`;
192
+ }));
193
+ if (path.endsWith("-plan.md"))
194
+ content = rebasePlanConventions(content, path, join(root, targets.get(repoRef(path))));
195
+ }
196
+ if (content !== original)
197
+ updates.push({ path: targets.get(repoRef(path)) ?? repoRef(path), content });
198
+ }
199
+ return { moves, updates, missing, skipped: [] };
200
+ }
201
+ export function applyRecordMigration(repoRoot, plan) {
202
+ if (!plan.moves.length && !plan.updates.length)
203
+ return;
204
+ const tracked = spawnSync("git", ["ls-files", "-z"], {
205
+ cwd: repoRoot,
206
+ env: gitEnvironment(),
207
+ encoding: "utf8",
208
+ });
209
+ if (tracked.status !== 0)
210
+ throw new Error(`git ls-files failed: ${tracked.stderr}`);
211
+ const files = new Set(tracked.stdout.split("\0"));
212
+ for (const move of plan.moves) {
213
+ if (!files.has(move.from))
214
+ throw new Error(`Migration source is not tracked: ${move.from}`);
215
+ }
216
+ for (const move of plan.moves) {
217
+ mkdirSync(dirname(join(repoRoot, move.to)), { recursive: true });
218
+ const result = spawnSync("git", ["mv", "--", move.from, move.to], {
219
+ cwd: repoRoot,
220
+ env: gitEnvironment(),
221
+ encoding: "utf8",
222
+ });
223
+ if (result.status !== 0)
224
+ throw new Error(`git mv failed: ${move.from}: ${result.stderr}`);
225
+ }
226
+ for (const update of plan.updates)
227
+ writeFileSync(join(repoRoot, update.path), update.content);
228
+ }
229
+ export function registerRecordMigrationCommand(exec) {
230
+ const command = exec
231
+ .command("migrate-records")
232
+ .description("Move tracked legacy run records with git mv");
233
+ addProjectOptions(command);
234
+ command.option("--dry-run", "List moves and reference updates without writing", false);
235
+ command.action((opts) => {
236
+ try {
237
+ const { executionPath } = resolveProjectContext(opts);
238
+ const root = specdojoRootDir();
239
+ const plan = planRecordMigration(root, executionPath, resolveProjectId(opts));
240
+ process.stdout.write(`${JSON.stringify({ ...plan, updates: plan.updates.map(({ path }) => path) }, null, 2)}\n`);
241
+ if (!opts.dryRun)
242
+ applyRecordMigration(root, plan);
243
+ }
244
+ catch (error) {
245
+ process.stderr.write(`blocked: ${error instanceof Error ? error.message : String(error)}; need=resolve migration precondition; ref=${opts.project ?? "current project"}\n`);
246
+ process.exitCode = 1;
247
+ }
248
+ });
249
+ }