specdojo 0.1.0 → 0.2.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 (531) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +82 -38
  3. package/dist/agent-response.js +27 -0
  4. package/dist/agent.js +124 -0
  5. package/dist/build-command.js +149 -0
  6. package/dist/build-if-stale.js +35 -0
  7. package/dist/catalog-build.js +1079 -0
  8. package/dist/catalog-generate.js +226 -0
  9. package/dist/catalog-paths.js +31 -0
  10. package/dist/catalog-plan-generate.js +301 -0
  11. package/dist/catalog-plan-prompt.js +73 -0
  12. package/dist/catalog-plan.js +471 -0
  13. package/dist/catalog-scaffold.js +255 -0
  14. package/dist/catalog-types.js +4 -0
  15. package/dist/catalog.js +606 -0
  16. package/dist/dashboard.js +980 -0
  17. package/dist/deliverable-trash.js +148 -0
  18. package/dist/deliverable.js +97 -0
  19. package/dist/dist-freshness.js +150 -0
  20. package/dist/doc-index.js +424 -0
  21. package/dist/exec-agent-config.js +172 -0
  22. package/dist/exec-agent-git-state.js +136 -0
  23. package/dist/exec-agent-protected-config.js +276 -0
  24. package/dist/exec-events.js +250 -112
  25. package/dist/exec-evidence.js +317 -0
  26. package/dist/exec-format.js +45 -0
  27. package/dist/exec-limit.js +202 -0
  28. package/dist/exec-parent-validation.js +169 -0
  29. package/dist/exec-pipeline-state.js +160 -0
  30. package/dist/exec-plans.js +1016 -0
  31. package/dist/exec-project.js +25 -11
  32. package/dist/exec-protection-handoff.js +169 -0
  33. package/dist/exec-provider-scaffold.js +99 -0
  34. package/dist/exec-register-resume.js +196 -0
  35. package/dist/exec-register.js +281 -0
  36. package/dist/exec-reporter.js +329 -0
  37. package/dist/exec-results.js +510 -0
  38. package/dist/exec-run-lock.js +149 -0
  39. package/dist/exec-run.js +4953 -0
  40. package/dist/exec-schedule-calendar.js +86 -9
  41. package/dist/exec-schedule-cpm.js +30 -12
  42. package/dist/exec-schedule-gantt-chart-render.js +428 -0
  43. package/dist/exec-schedule-gantt-chart-scope.js +111 -0
  44. package/dist/exec-schedule-gantt-chart.js +2 -0
  45. package/dist/exec-schedule-hash.js +34 -25
  46. package/dist/exec-schedule-index.js +200 -67
  47. package/dist/exec-schedule-initial.js +100 -0
  48. package/dist/exec-schedule-progress.js +51 -26
  49. package/dist/exec-schedule-ready.js +71 -27
  50. package/dist/exec-schedule.js +171 -93
  51. package/dist/exec-shared.js +146 -25
  52. package/dist/exec-strategy.js +547 -0
  53. package/dist/exec-task-view.js +64 -0
  54. package/dist/exec-trial.js +895 -0
  55. package/dist/exec-worktree-command.js +426 -0
  56. package/dist/exec-worktree-ops.js +847 -0
  57. package/dist/exec-worktree.js +359 -0
  58. package/dist/exec.js +744 -192
  59. package/dist/frontmatter-namespace.js +48 -0
  60. package/dist/git-environment.js +23 -0
  61. package/dist/grade-result.js +137 -0
  62. package/dist/grade.js +2456 -0
  63. package/dist/index-command.js +103 -0
  64. package/dist/job.js +1081 -0
  65. package/dist/kata-command.js +303 -0
  66. package/dist/kata.js +187 -0
  67. package/dist/package-paths.js +15 -0
  68. package/dist/practice-id.js +24 -0
  69. package/dist/register-date.js +122 -0
  70. package/dist/register-events.js +363 -0
  71. package/dist/register-history.js +323 -0
  72. package/dist/register-item.js +455 -0
  73. package/dist/register-migrate-timestamps.js +176 -0
  74. package/dist/register.js +2199 -0
  75. package/dist/review-plan.js +199 -0
  76. package/dist/review-types.js +1 -0
  77. package/dist/role-types.js +1 -0
  78. package/dist/routine.js +814 -0
  79. package/dist/schedule-approach.js +252 -0
  80. package/dist/schedule-build.js +552 -0
  81. package/dist/schedule-phase-sets.js +73 -0
  82. package/dist/schedule-strategy-generate.js +812 -0
  83. package/dist/schedule-strategy-profiles.js +276 -0
  84. package/dist/schedule.js +420 -0
  85. package/dist/spawn-self.js +28 -0
  86. package/dist/specdojo-config.js +133 -39
  87. package/dist/specdojo.js +55 -7
  88. package/dist/template-frontmatter.js +89 -0
  89. package/dist/template-resolution.js +92 -0
  90. package/dist/timeline-build.js +334 -0
  91. package/dist/timeline.js +107 -0
  92. package/dist/watch.js +313 -0
  93. package/dist/yaml-pages-command.js +28 -0
  94. package/dist/yaml-pages.js +180 -0
  95. package/dist/yaml-schema-modeline.js +49 -0
  96. package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +600 -0
  97. package/docs/ja/specdojo/exec-templates/xep-bootstrap-template.md +120 -0
  98. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +37 -0
  99. package/docs/ja/specdojo/exec-templates/xep-cross-deliverable-dedup-template.md +51 -0
  100. package/docs/ja/specdojo/exec-templates/xep-freeform-template.md +74 -0
  101. package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +109 -0
  102. package/docs/ja/specdojo/exec-templates/xep-job-template.md +43 -0
  103. package/docs/ja/specdojo/exec-templates/xep-recipe-guided-template.md +82 -0
  104. package/docs/ja/specdojo/exec-templates/xep-recipe-maintenance-template.md +86 -0
  105. package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +42 -0
  106. package/docs/ja/specdojo/exec-templates/xep-register-template.md +49 -0
  107. package/docs/ja/specdojo/exec-templates/xep-retrofit-template.md +98 -0
  108. package/docs/ja/specdojo/exec-templates/xep-rulebook-maintenance-template.md +86 -0
  109. package/docs/ja/specdojo/exec-templates/xep-sample-maintenance-template.md +86 -0
  110. package/docs/ja/specdojo/exec-templates/xep-template-maintenance-template.md +86 -0
  111. package/docs/ja/specdojo/exec-templates/xep-template.md +66 -0
  112. package/docs/ja/specdojo/exec-templates/xer-cross-deliverable-dedup-template.md +31 -0
  113. package/docs/ja/specdojo/exec-templates/xer-human-bootstrap-finalize-template.md +40 -0
  114. package/docs/ja/specdojo/exec-templates/xer-human-finalize-template.md +30 -0
  115. package/docs/ja/specdojo/exec-templates/xer-template.md +19 -0
  116. package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +70 -0
  117. package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +97 -0
  118. package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +76 -0
  119. package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +73 -0
  120. package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +74 -0
  121. package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +74 -0
  122. package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +73 -0
  123. package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +73 -0
  124. package/docs/ja/specdojo/exec-templates/xrp-template.md +67 -0
  125. package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +7 -0
  126. package/docs/ja/specdojo/exec-templates/xrr-template.md +21 -0
  127. package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +7 -0
  128. package/docs/ja/specdojo/guides/branch-workflow-guide.md +354 -0
  129. package/docs/ja/specdojo/guides/docs-editing-guide.md +327 -0
  130. package/docs/ja/specdojo/guides/docs-structure-guide.md +519 -0
  131. package/docs/ja/specdojo/guides/exec-config-guide.md +589 -0
  132. package/docs/ja/specdojo/guides/exec-operation-guide.md +440 -0
  133. package/docs/ja/specdojo/guides/exec-worktree-guide.md +318 -0
  134. package/docs/ja/specdojo/guides/kata-guide.md +89 -0
  135. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +127 -0
  136. package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +228 -0
  137. package/docs/ja/specdojo/guides/practice-system-composition-guide.md +111 -0
  138. package/docs/ja/specdojo/guides/quick-start-guide.md +473 -0
  139. package/docs/ja/specdojo/guides/register-operation-guide.md +418 -0
  140. package/docs/ja/specdojo/guides/review-guide.md +428 -0
  141. package/docs/ja/specdojo/guides/routine-operation-guide.md +282 -0
  142. package/docs/ja/specdojo/guides/ryu-guide.md +230 -0
  143. package/docs/ja/specdojo/guides/schedule-design-guide.md +429 -0
  144. package/docs/ja/specdojo/guides/schedule-operation-guide.md +151 -0
  145. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +257 -0
  146. package/docs/ja/specdojo/guides/timeline-design-guide.md +160 -0
  147. package/docs/ja/specdojo/guides/track-design-guide.md +215 -0
  148. package/docs/ja/specdojo/guides/use-case-guide.md +133 -0
  149. package/docs/ja/specdojo/guides/waza-guide.md +224 -0
  150. package/docs/ja/specdojo/index.md +33 -0
  151. package/docs/ja/specdojo/philosophy/needs-to-implementation-philosophy.md +212 -0
  152. package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +242 -0
  153. package/docs/ja/specdojo/recipes/cdfd-overview-recipe.md +198 -0
  154. package/docs/ja/specdojo/recipes/cdfd-recipe.md +218 -0
  155. package/docs/ja/specdojo/recipes/cdfd-uc-recipe.md +198 -0
  156. package/docs/ja/specdojo/recipes/exec-human-finalize-recipe.md +100 -0
  157. package/docs/ja/specdojo/recipes/ifx-cmd-recipe.md +148 -0
  158. package/docs/ja/specdojo/recipes/pm-communication-plan-recipe.md +97 -0
  159. package/docs/ja/specdojo/recipes/pm-members-recipe.md +149 -0
  160. package/docs/ja/specdojo/recipes/pm-organization-recipe.md +96 -0
  161. package/docs/ja/specdojo/recipes/pm-plan-recipe.md +98 -0
  162. package/docs/ja/specdojo/recipes/pm-quality-management-plan-recipe.md +97 -0
  163. package/docs/ja/specdojo/recipes/pm-raci-recipe.md +96 -0
  164. package/docs/ja/specdojo/recipes/pm-roles-recipe.md +136 -0
  165. package/docs/ja/specdojo/recipes/prj-assumptions-constraints-dependencies-recipe.md +162 -0
  166. package/docs/ja/specdojo/recipes/prj-charter-recipe.md +187 -0
  167. package/docs/ja/specdojo/recipes/prj-comparison-of-alternatives-recipe.md +235 -0
  168. package/docs/ja/specdojo/recipes/prj-issues-and-approach-recipe.md +205 -0
  169. package/docs/ja/specdojo/recipes/prj-overview-recipe.md +289 -0
  170. package/docs/ja/specdojo/recipes/prj-scope-recipe.md +201 -0
  171. package/docs/ja/specdojo/recipes/prj-stakeholder-register-recipe.md +168 -0
  172. package/docs/ja/specdojo/recipes/prj-success-criteria-and-acceptance-criteria-recipe.md +179 -0
  173. package/docs/ja/specdojo/recipes/stsd-recipe.md +138 -0
  174. package/docs/ja/specdojo/references/command-reference.md +718 -0
  175. package/docs/ja/specdojo/references/deliverables-reference.md +407 -0
  176. package/docs/ja/specdojo/references/directory-layout-reference.md +280 -0
  177. package/docs/ja/specdojo/references/specdojo-config-reference.md +133 -0
  178. package/docs/ja/specdojo/rulebooks/atc-index-rulebook.md +372 -0
  179. package/docs/ja/specdojo/rulebooks/atc-rulebook.md +302 -0
  180. package/docs/ja/specdojo/rulebooks/bac-rulebook.md +331 -0
  181. package/docs/ja/specdojo/rulebooks/bdd-rulebook.md +134 -0
  182. package/docs/ja/specdojo/rulebooks/bds-rulebook.md +207 -0
  183. package/docs/ja/specdojo/rulebooks/bes-index-rulebook.md +102 -0
  184. package/docs/ja/specdojo/rulebooks/bes-rulebook.md +131 -0
  185. package/docs/ja/specdojo/rulebooks/bps-rulebook.md +269 -0
  186. package/docs/ja/specdojo/rulebooks/br-rulebook.md +187 -0
  187. package/docs/ja/specdojo/rulebooks/ccd-mermaid-rulebook.md +279 -0
  188. package/docs/ja/specdojo/rulebooks/cdfd-mermaid-rulebook.md +219 -0
  189. package/docs/ja/specdojo/rulebooks/cdfd-overview-rulebook.md +233 -0
  190. package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +182 -0
  191. package/docs/ja/specdojo/rulebooks/cdfd-uc-rulebook.md +171 -0
  192. package/docs/ja/specdojo/rulebooks/cdsd-rulebook.md +105 -0
  193. package/docs/ja/specdojo/rulebooks/cld-rulebook.md +195 -0
  194. package/docs/ja/specdojo/rulebooks/cnd-mermaid-rulebook.md +285 -0
  195. package/docs/ja/specdojo/rulebooks/cnd-rulebook.md +292 -0
  196. package/docs/ja/specdojo/rulebooks/cop-index-rulebook.md +171 -0
  197. package/docs/ja/specdojo/rulebooks/cop-rulebook.md +325 -0
  198. package/docs/ja/specdojo/rulebooks/cpd-mermaid-rulebook.md +266 -0
  199. package/docs/ja/specdojo/rulebooks/cpd-rulebook.md +294 -0
  200. package/docs/ja/specdojo/rulebooks/cstd-rulebook.md +21 -0
  201. package/docs/ja/specdojo/rulebooks/cxd-mermaid-rulebook.md +401 -0
  202. package/docs/ja/specdojo/rulebooks/cxd-rulebook.md +311 -0
  203. package/docs/ja/specdojo/rulebooks/dct-index-rulebook.md +158 -0
  204. package/docs/ja/specdojo/rulebooks/dct-rulebook.md +287 -0
  205. package/docs/ja/specdojo/rulebooks/dec-rulebook.md +62 -0
  206. package/docs/ja/specdojo/rulebooks/dmd-index-rulebook.md +100 -0
  207. package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +298 -0
  208. package/docs/ja/specdojo/rulebooks/etc-index-rulebook.md +379 -0
  209. package/docs/ja/specdojo/rulebooks/etc-rulebook.md +310 -0
  210. package/docs/ja/specdojo/rulebooks/gl-rulebook.md +86 -0
  211. package/docs/ja/specdojo/rulebooks/ifd-mermaid-rulebook.md +297 -0
  212. package/docs/ja/specdojo/rulebooks/ifx-api-rulebook.md +79 -0
  213. package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +213 -0
  214. package/docs/ja/specdojo/rulebooks/ifx-file-rulebook.md +311 -0
  215. package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +94 -0
  216. package/docs/ja/specdojo/rulebooks/ifx-msg-rulebook.md +81 -0
  217. package/docs/ja/specdojo/rulebooks/imp-business-rulebook.md +117 -0
  218. package/docs/ja/specdojo/rulebooks/imp-data-rulebook.md +118 -0
  219. package/docs/ja/specdojo/rulebooks/imp-interface-rulebook.md +116 -0
  220. package/docs/ja/specdojo/rulebooks/imp-operations-rulebook.md +116 -0
  221. package/docs/ja/specdojo/rulebooks/imp-test-rulebook.md +116 -0
  222. package/docs/ja/specdojo/rulebooks/itc-index-rulebook.md +421 -0
  223. package/docs/ja/specdojo/rulebooks/itc-rulebook.md +307 -0
  224. package/docs/ja/specdojo/rulebooks/mip-index-rulebook.md +312 -0
  225. package/docs/ja/specdojo/rulebooks/mm-rulebook.md +63 -0
  226. package/docs/ja/specdojo/rulebooks/mtp-rulebook.md +353 -0
  227. package/docs/ja/specdojo/rulebooks/nfr-availability-rulebook.md +184 -0
  228. package/docs/ja/specdojo/rulebooks/nfr-index-rulebook.md +179 -0
  229. package/docs/ja/specdojo/rulebooks/nfr-integrity-rulebook.md +184 -0
  230. package/docs/ja/specdojo/rulebooks/nfr-maintainability-rulebook.md +183 -0
  231. package/docs/ja/specdojo/rulebooks/nfr-operations-rulebook.md +185 -0
  232. package/docs/ja/specdojo/rulebooks/nfr-performance-rulebook.md +185 -0
  233. package/docs/ja/specdojo/rulebooks/nfr-reliability-rulebook.md +186 -0
  234. package/docs/ja/specdojo/rulebooks/nfr-security-safety-rulebook.md +186 -0
  235. package/docs/ja/specdojo/rulebooks/nfr-usability-rulebook.md +184 -0
  236. package/docs/ja/specdojo/rulebooks/ntp-rulebook.md +61 -0
  237. package/docs/ja/specdojo/rulebooks/opd-index-rulebook.md +84 -0
  238. package/docs/ja/specdojo/rulebooks/opd-rulebook.md +357 -0
  239. package/docs/ja/specdojo/rulebooks/opr-index-rulebook.md +80 -0
  240. package/docs/ja/specdojo/rulebooks/opr-rulebook.md +484 -0
  241. package/docs/ja/specdojo/rulebooks/otp-index-rulebook.md +120 -0
  242. package/docs/ja/specdojo/rulebooks/otp-rulebook.md +293 -0
  243. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +211 -0
  244. package/docs/ja/specdojo/rulebooks/pm-change-request-log-rulebook.md +94 -0
  245. package/docs/ja/specdojo/rulebooks/pm-communication-plan-rulebook.md +116 -0
  246. package/docs/ja/specdojo/rulebooks/pm-issue-log-rulebook.md +93 -0
  247. package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +190 -0
  248. package/docs/ja/specdojo/rulebooks/pm-organization-rulebook.md +108 -0
  249. package/docs/ja/specdojo/rulebooks/pm-plan-rulebook.md +122 -0
  250. package/docs/ja/specdojo/rulebooks/pm-quality-management-plan-rulebook.md +117 -0
  251. package/docs/ja/specdojo/rulebooks/pm-raci-rulebook.md +116 -0
  252. package/docs/ja/specdojo/rulebooks/pm-risk-register-rulebook.md +93 -0
  253. package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +146 -0
  254. package/docs/ja/specdojo/rulebooks/pr-rulebook.md +65 -0
  255. package/docs/ja/specdojo/rulebooks/prj-assumptions-constraints-dependencies-rulebook.md +178 -0
  256. package/docs/ja/specdojo/rulebooks/prj-charter-rulebook.md +232 -0
  257. package/docs/ja/specdojo/rulebooks/prj-comparison-of-alternatives-rulebook.md +235 -0
  258. package/docs/ja/specdojo/rulebooks/prj-issues-and-approach-rulebook.md +242 -0
  259. package/docs/ja/specdojo/rulebooks/prj-overview-rulebook.md +187 -0
  260. package/docs/ja/specdojo/rulebooks/prj-scope-rulebook.md +201 -0
  261. package/docs/ja/specdojo/rulebooks/prj-stakeholder-register-rulebook.md +165 -0
  262. package/docs/ja/specdojo/rulebooks/prj-success-criteria-and-acceptance-criteria-rulebook.md +165 -0
  263. package/docs/ja/specdojo/rulebooks/sac-rulebook.md +202 -0
  264. package/docs/ja/specdojo/rulebooks/sch-rulebook.md +139 -0
  265. package/docs/ja/specdojo/rulebooks/sf-index-rulebook.md +63 -0
  266. package/docs/ja/specdojo/rulebooks/sf-rulebook.md +93 -0
  267. package/docs/ja/specdojo/rulebooks/sld-rulebook.md +93 -0
  268. package/docs/ja/specdojo/rulebooks/stc-index-rulebook.md +329 -0
  269. package/docs/ja/specdojo/rulebooks/stc-rulebook.md +297 -0
  270. package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +132 -0
  271. package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +215 -0
  272. package/docs/ja/specdojo/rulebooks/sysd-critical-flows-rulebook.md +376 -0
  273. package/docs/ja/specdojo/rulebooks/sysd-cross-cutting-policy-rulebook.md +313 -0
  274. package/docs/ja/specdojo/rulebooks/sysd-index-rulebook.md +246 -0
  275. package/docs/ja/specdojo/rulebooks/sysd-rulebook.md +119 -0
  276. package/docs/ja/specdojo/rulebooks/tml-rulebook.md +188 -0
  277. package/docs/ja/specdojo/rulebooks/trc-requirements-to-specs-rulebook.md +114 -0
  278. package/docs/ja/specdojo/rulebooks/trc-requirements-to-tests-rulebook.md +117 -0
  279. package/docs/ja/specdojo/rulebooks/tsd-index-rulebook.md +101 -0
  280. package/docs/ja/specdojo/rulebooks/tsd-rulebook.md +103 -0
  281. package/docs/ja/specdojo/rulebooks/tsp-index-rulebook.md +396 -0
  282. package/docs/ja/specdojo/rulebooks/uis-rulebook.md +207 -0
  283. package/docs/ja/specdojo/rulebooks/utc-index-rulebook.md +387 -0
  284. package/docs/ja/specdojo/rulebooks/utc-rulebook.md +303 -0
  285. package/docs/ja/specdojo/samples/atc-index-sample.md +38 -0
  286. package/docs/ja/specdojo/samples/atc-sample.md +41 -0
  287. package/docs/ja/specdojo/samples/bac-sample.md +38 -0
  288. package/docs/ja/specdojo/samples/bdd-sample.yaml +71 -0
  289. package/docs/ja/specdojo/samples/bds-sample.md +38 -0
  290. package/docs/ja/specdojo/samples/bes-index-sample.md +38 -0
  291. package/docs/ja/specdojo/samples/bes-sample.md +38 -0
  292. package/docs/ja/specdojo/samples/bps-sample.md +38 -0
  293. package/docs/ja/specdojo/samples/br-sample.md +40 -0
  294. package/docs/ja/specdojo/samples/ccd-sample.md +38 -0
  295. package/docs/ja/specdojo/samples/cdfd-overview-sample.md +284 -0
  296. package/docs/ja/specdojo/samples/cdfd-sample.md +229 -0
  297. package/docs/ja/specdojo/samples/cdfd-uc-sample.md +146 -0
  298. package/docs/ja/specdojo/samples/cdsd-sample.md +38 -0
  299. package/docs/ja/specdojo/samples/cld-sample.md +38 -0
  300. package/docs/ja/specdojo/samples/cnd-sample.md +38 -0
  301. package/docs/ja/specdojo/samples/cop-index-sample.md +38 -0
  302. package/docs/ja/specdojo/samples/cop-sample.md +38 -0
  303. package/docs/ja/specdojo/samples/cpd-sample.md +38 -0
  304. package/docs/ja/specdojo/samples/cstd-sample.md +11 -0
  305. package/docs/ja/specdojo/samples/cxd-sample.md +38 -0
  306. package/docs/ja/specdojo/samples/dct-index-sample.yaml +39 -0
  307. package/docs/ja/specdojo/samples/dct-sample.yaml +91 -0
  308. package/docs/ja/specdojo/samples/dec-sample.md +39 -0
  309. package/docs/ja/specdojo/samples/dmd-index-sample.md +50 -0
  310. package/docs/ja/specdojo/samples/dmd-sample.md +74 -0
  311. package/docs/ja/specdojo/samples/etc-index-sample.md +38 -0
  312. package/docs/ja/specdojo/samples/etc-sample.md +38 -0
  313. package/docs/ja/specdojo/samples/gl-sample.yaml +37 -0
  314. package/docs/ja/specdojo/samples/ifd-sample.md +38 -0
  315. package/docs/ja/specdojo/samples/ifx-api-sample.yaml +102 -0
  316. package/docs/ja/specdojo/samples/ifx-cmd-sample.yaml +107 -0
  317. package/docs/ja/specdojo/samples/ifx-file-sample.md +38 -0
  318. package/docs/ja/specdojo/samples/ifx-msg-sample.yaml +89 -0
  319. package/docs/ja/specdojo/samples/imp-business-sample.md +66 -0
  320. package/docs/ja/specdojo/samples/imp-data-sample.md +60 -0
  321. package/docs/ja/specdojo/samples/imp-interface-sample.md +60 -0
  322. package/docs/ja/specdojo/samples/imp-operations-sample.md +60 -0
  323. package/docs/ja/specdojo/samples/imp-test-sample.md +60 -0
  324. package/docs/ja/specdojo/samples/itc-index-sample.md +38 -0
  325. package/docs/ja/specdojo/samples/itc-sample.md +38 -0
  326. package/docs/ja/specdojo/samples/mip-index-sample.md +38 -0
  327. package/docs/ja/specdojo/samples/mm-sample.md +35 -0
  328. package/docs/ja/specdojo/samples/mtp-sample.md +38 -0
  329. package/docs/ja/specdojo/samples/nfr-availability-sample.md +38 -0
  330. package/docs/ja/specdojo/samples/nfr-index-sample.md +38 -0
  331. package/docs/ja/specdojo/samples/nfr-integrity-sample.md +38 -0
  332. package/docs/ja/specdojo/samples/nfr-maintainability-sample.md +38 -0
  333. package/docs/ja/specdojo/samples/nfr-operations-sample.md +38 -0
  334. package/docs/ja/specdojo/samples/nfr-performance-sample.md +38 -0
  335. package/docs/ja/specdojo/samples/nfr-reliability-sample.md +38 -0
  336. package/docs/ja/specdojo/samples/nfr-security-safety-sample.md +38 -0
  337. package/docs/ja/specdojo/samples/nfr-usability-sample.md +38 -0
  338. package/docs/ja/specdojo/samples/ntp-sample.md +38 -0
  339. package/docs/ja/specdojo/samples/opd-access-control-sample.md +29 -0
  340. package/docs/ja/specdojo/samples/opd-incident-management-sample.md +31 -0
  341. package/docs/ja/specdojo/samples/opd-index-sample.md +41 -0
  342. package/docs/ja/specdojo/samples/opd-monitoring-sample.md +32 -0
  343. package/docs/ja/specdojo/samples/opd-sample.md +38 -0
  344. package/docs/ja/specdojo/samples/opr-access-control-sample.md +24 -0
  345. package/docs/ja/specdojo/samples/opr-backup-restore-sample.md +27 -0
  346. package/docs/ja/specdojo/samples/opr-batch-sample.md +23 -0
  347. package/docs/ja/specdojo/samples/opr-change-sample.md +24 -0
  348. package/docs/ja/specdojo/samples/opr-incident-sample.md +38 -0
  349. package/docs/ja/specdojo/samples/opr-index-sample.md +43 -0
  350. package/docs/ja/specdojo/samples/opr-monitoring-sample.md +27 -0
  351. package/docs/ja/specdojo/samples/opr-sample.md +38 -0
  352. package/docs/ja/specdojo/samples/opr-support-sample.md +23 -0
  353. package/docs/ja/specdojo/samples/otp-index-sample.md +66 -0
  354. package/docs/ja/specdojo/samples/otp-sample.md +68 -0
  355. package/docs/ja/specdojo/samples/pm-change-request-log-sample.md +47 -0
  356. package/docs/ja/specdojo/samples/pm-communication-plan-sample.md +46 -0
  357. package/docs/ja/specdojo/samples/pm-issue-log-sample.md +45 -0
  358. package/docs/ja/specdojo/samples/pm-members-sample.yaml +103 -0
  359. package/docs/ja/specdojo/samples/pm-organization-sample.md +46 -0
  360. package/docs/ja/specdojo/samples/pm-plan-sample.md +57 -0
  361. package/docs/ja/specdojo/samples/pm-quality-management-plan-sample.md +52 -0
  362. package/docs/ja/specdojo/samples/pm-raci-sample.md +57 -0
  363. package/docs/ja/specdojo/samples/pm-risk-register-sample.md +43 -0
  364. package/docs/ja/specdojo/samples/pm-roles-sample.yaml +41 -0
  365. package/docs/ja/specdojo/samples/pr-sample.md +39 -0
  366. package/docs/ja/specdojo/samples/prj-assumptions-constraints-dependencies-sample.md +57 -0
  367. package/docs/ja/specdojo/samples/prj-charter-sample.md +121 -0
  368. package/docs/ja/specdojo/samples/prj-comparison-of-alternatives-sample.md +105 -0
  369. package/docs/ja/specdojo/samples/prj-issues-and-approach-sample.md +78 -0
  370. package/docs/ja/specdojo/samples/prj-overview-sample.md +95 -0
  371. package/docs/ja/specdojo/samples/prj-scope-sample.md +71 -0
  372. package/docs/ja/specdojo/samples/prj-stakeholder-register-sample.md +60 -0
  373. package/docs/ja/specdojo/samples/prj-success-criteria-and-acceptance-criteria-sample.md +62 -0
  374. package/docs/ja/specdojo/samples/sac-sample.md +38 -0
  375. package/docs/ja/specdojo/samples/sf-index-sample.md +38 -0
  376. package/docs/ja/specdojo/samples/sf-sample.md +38 -0
  377. package/docs/ja/specdojo/samples/sld-sample.md +38 -0
  378. package/docs/ja/specdojo/samples/stc-index-sample.md +38 -0
  379. package/docs/ja/specdojo/samples/stc-sample.md +38 -0
  380. package/docs/ja/specdojo/samples/stsd-sample.md +58 -0
  381. package/docs/ja/specdojo/samples/sysd-critical-flows-sample.md +38 -0
  382. package/docs/ja/specdojo/samples/sysd-cross-cutting-policy-sample.md +38 -0
  383. package/docs/ja/specdojo/samples/sysd-index-sample.md +38 -0
  384. package/docs/ja/specdojo/samples/trc-requirements-to-specs-sample.md +56 -0
  385. package/docs/ja/specdojo/samples/trc-requirements-to-tests-sample.md +56 -0
  386. package/docs/ja/specdojo/samples/tsd-index-sample.md +29 -0
  387. package/docs/ja/specdojo/samples/tsd-sample.md +38 -0
  388. package/docs/ja/specdojo/samples/tsp-index-sample.md +38 -0
  389. package/docs/ja/specdojo/samples/uis-sample.md +38 -0
  390. package/docs/ja/specdojo/samples/utc-index-sample.md +38 -0
  391. package/docs/ja/specdojo/samples/utc-sample.md +38 -0
  392. package/docs/ja/specdojo/schemas/v1/guide-content.schema.yaml +20 -0
  393. package/docs/ja/specdojo/schemas/v1/philosophy-content.schema.yaml +21 -0
  394. package/docs/ja/specdojo/schemas/v1/reference-content.schema.yaml +21 -0
  395. package/docs/ja/specdojo/standards/document-metadata-standard.md +323 -0
  396. package/docs/ja/specdojo/standards/exec-human-finalize-standard.md +75 -0
  397. package/docs/ja/specdojo/standards/git-branching-standard.md +227 -0
  398. package/docs/ja/specdojo/standards/guide-authoring-standard.md +124 -0
  399. package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +929 -0
  400. package/docs/ja/specdojo/standards/job-definition-standard.md +148 -0
  401. package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +431 -0
  402. package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +113 -0
  403. package/docs/ja/specdojo/standards/recipe-authoring-standard.md +143 -0
  404. package/docs/ja/specdojo/standards/reference-authoring-standard.md +99 -0
  405. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +140 -0
  406. package/docs/ja/specdojo/standards/sample-authoring-standard.md +151 -0
  407. package/docs/ja/specdojo/standards/standard-authoring-standard.md +108 -0
  408. package/docs/ja/specdojo/standards/template-authoring-standard.md +101 -0
  409. package/docs/ja/specdojo/standards/test-document-scope-standard.md +176 -0
  410. package/docs/ja/specdojo/templates/cdfd-overview-template.md +199 -0
  411. package/docs/ja/specdojo/templates/cdfd-template.md +173 -0
  412. package/docs/ja/specdojo/templates/cdfd-uc-template.md +148 -0
  413. package/docs/ja/specdojo/templates/dct-architecture-template.yaml +136 -0
  414. package/docs/ja/specdojo/templates/dct-business-acceptance-criteria-template.yaml +34 -0
  415. package/docs/ja/specdojo/templates/dct-business-model-bes-template.yaml +75 -0
  416. package/docs/ja/specdojo/templates/dct-business-model-bps-template.yaml +49 -0
  417. package/docs/ja/specdojo/templates/dct-business-model-br-template.yaml +50 -0
  418. package/docs/ja/specdojo/templates/dct-data-flow-template.yaml +40 -0
  419. package/docs/ja/specdojo/templates/dct-data-model-bdd-template.yaml +46 -0
  420. package/docs/ja/specdojo/templates/dct-data-model-ccd-template.yaml +46 -0
  421. package/docs/ja/specdojo/templates/dct-data-model-cdsd-template.yaml +41 -0
  422. package/docs/ja/specdojo/templates/dct-data-model-cld-template.yaml +38 -0
  423. package/docs/ja/specdojo/templates/dct-data-model-sld-template.yaml +38 -0
  424. package/docs/ja/specdojo/templates/dct-data-model-stsd-template.yaml +46 -0
  425. package/docs/ja/specdojo/templates/dct-external-interface-specs-template.yaml +114 -0
  426. package/docs/ja/specdojo/templates/dct-glossary-template.yaml +35 -0
  427. package/docs/ja/specdojo/templates/dct-impact-analysis-template.yaml +138 -0
  428. package/docs/ja/specdojo/templates/dct-index-template.md +40 -0
  429. package/docs/ja/specdojo/templates/dct-migration-planning-template.yaml +148 -0
  430. package/docs/ja/specdojo/templates/dct-non-functional-requirements-template.yaml +222 -0
  431. package/docs/ja/specdojo/templates/dct-operations-template.yaml +108 -0
  432. package/docs/ja/specdojo/templates/dct-project-definition-template.yaml +210 -0
  433. package/docs/ja/specdojo/templates/dct-project-management-template.yaml +423 -0
  434. package/docs/ja/specdojo/templates/dct-system-acceptance-criteria-template.yaml +37 -0
  435. package/docs/ja/specdojo/templates/dct-system-design-template.yaml +82 -0
  436. package/docs/ja/specdojo/templates/dct-system-functions-template.yaml +58 -0
  437. package/docs/ja/specdojo/templates/dct-test-specs-template.yaml +261 -0
  438. package/docs/ja/specdojo/templates/dct-user-interface-model-template.yaml +60 -0
  439. package/docs/ja/specdojo/templates/ifx-cmd-template.yaml +88 -0
  440. package/docs/ja/specdojo/templates/opr-template.md +85 -0
  441. package/docs/ja/specdojo/templates/pjr-change-request-template.md +60 -0
  442. package/docs/ja/specdojo/templates/pjr-decision-template.md +61 -0
  443. package/docs/ja/specdojo/templates/pjr-index-template.md +49 -0
  444. package/docs/ja/specdojo/templates/pjr-issue-template.md +50 -0
  445. package/docs/ja/specdojo/templates/pjr-note-template.md +35 -0
  446. package/docs/ja/specdojo/templates/pjr-question-template.md +53 -0
  447. package/docs/ja/specdojo/templates/pjr-risk-template.md +49 -0
  448. package/docs/ja/specdojo/templates/pjr-todo-template.md +41 -0
  449. package/docs/ja/specdojo/templates/pjr-views-by-owner-template.md +22 -0
  450. package/docs/ja/specdojo/templates/pjr-views-by-priority-template.md +22 -0
  451. package/docs/ja/specdojo/templates/pjr-views-by-status-template.md +22 -0
  452. package/docs/ja/specdojo/templates/pm-change-request-log-template.md +20 -0
  453. package/docs/ja/specdojo/templates/pm-communication-plan-template.md +46 -0
  454. package/docs/ja/specdojo/templates/pm-decision-log-template.md +20 -0
  455. package/docs/ja/specdojo/templates/pm-issue-log-template.md +20 -0
  456. package/docs/ja/specdojo/templates/pm-members-template.yaml +105 -0
  457. package/docs/ja/specdojo/templates/pm-organization-template.md +44 -0
  458. package/docs/ja/specdojo/templates/pm-plan-template.md +52 -0
  459. package/docs/ja/specdojo/templates/pm-quality-management-plan-template.md +46 -0
  460. package/docs/ja/specdojo/templates/pm-raci-template.md +51 -0
  461. package/docs/ja/specdojo/templates/pm-risk-register-template.md +20 -0
  462. package/docs/ja/specdojo/templates/pm-roles-template.yaml +53 -0
  463. package/docs/ja/specdojo/templates/prj-assumptions-constraints-dependencies-template.md +59 -0
  464. package/docs/ja/specdojo/templates/prj-charter-template.md +116 -0
  465. package/docs/ja/specdojo/templates/prj-comparison-of-alternatives-template.md +116 -0
  466. package/docs/ja/specdojo/templates/prj-issues-and-approach-template.md +89 -0
  467. package/docs/ja/specdojo/templates/prj-overview-template.md +85 -0
  468. package/docs/ja/specdojo/templates/prj-scope-template.md +75 -0
  469. package/docs/ja/specdojo/templates/prj-stakeholder-register-template.md +64 -0
  470. package/docs/ja/specdojo/templates/prj-success-criteria-and-acceptance-criteria-template.md +60 -0
  471. package/docs/ja/specdojo/templates/stsd-template.md +57 -0
  472. package/docs/specdojo/schemas/v1/bdd.schema.yaml +230 -0
  473. package/docs/specdojo/schemas/v1/common-frontmatter.schema.yaml +77 -0
  474. package/docs/specdojo/schemas/v1/dct-index.schema.yaml +85 -0
  475. package/docs/specdojo/schemas/v1/dct-plan.schema.yaml +324 -0
  476. package/docs/specdojo/schemas/v1/dct.schema.yaml +368 -0
  477. package/docs/specdojo/schemas/v1/deliverable-frontmatter.schema.yaml +91 -0
  478. package/docs/specdojo/schemas/v1/esil.schema.yaml +142 -0
  479. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +101 -0
  480. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +272 -0
  481. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +162 -0
  482. package/docs/specdojo/schemas/v1/exec-plan-frontmatter.schema.yaml +126 -0
  483. package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +151 -0
  484. package/docs/specdojo/schemas/v1/exec-result-frontmatter.schema.yaml +144 -0
  485. package/docs/specdojo/schemas/v1/grade-done-criteria.schema.yaml +79 -0
  486. package/docs/specdojo/schemas/v1/grade-pipeline-state.schema.yaml +60 -0
  487. package/docs/specdojo/schemas/v1/grade-result.schema.yaml +118 -0
  488. package/docs/specdojo/schemas/v1/guide-frontmatter.schema.yaml +19 -0
  489. package/docs/specdojo/schemas/v1/ifx-cmd.schema.yaml +293 -0
  490. package/docs/specdojo/schemas/v1/job-run.schema.yaml +90 -0
  491. package/docs/specdojo/schemas/v1/job.schema.yaml +198 -0
  492. package/docs/specdojo/schemas/v1/philosophy-frontmatter.schema.yaml +19 -0
  493. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +56 -0
  494. package/docs/specdojo/schemas/v1/pm-members.schema.yaml +252 -0
  495. package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +387 -0
  496. package/docs/specdojo/schemas/v1/pm-roles.schema.yaml +106 -0
  497. package/docs/specdojo/schemas/v1/recipe-frontmatter.schema.yaml +27 -0
  498. package/docs/specdojo/schemas/v1/reference-frontmatter.schema.yaml +18 -0
  499. package/docs/specdojo/schemas/v1/register-events.schema.yaml +106 -0
  500. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +204 -0
  501. package/docs/specdojo/schemas/v1/routine-run.schema.yaml +36 -0
  502. package/docs/specdojo/schemas/v1/routine.schema.yaml +87 -0
  503. package/docs/specdojo/schemas/v1/rulebook-frontmatter.schema.yaml +61 -0
  504. package/docs/specdojo/schemas/v1/sch-common.schema.yaml +258 -0
  505. package/docs/specdojo/schemas/v1/sch-defaults.schema.yaml +48 -0
  506. package/docs/specdojo/schemas/v1/sch-milestones.schema.yaml +64 -0
  507. package/docs/specdojo/schemas/v1/sch-strategy.schema.yaml +772 -0
  508. package/docs/specdojo/schemas/v1/sch-track.schema.yaml +66 -0
  509. package/docs/specdojo/schemas/v1/standard-frontmatter.schema.yaml +18 -0
  510. package/docs/specdojo/schemas/v1/tml-index.schema.yaml +103 -0
  511. package/package.json +120 -24
  512. package/templates/claude/README.md +46 -0
  513. package/templates/claude/agents/claude-expert-review-executor.md +14 -0
  514. package/templates/claude/agents/claude-review-executor.md +14 -0
  515. package/templates/claude/settings.edit.json +6 -0
  516. package/templates/claude/settings.report.json +6 -0
  517. package/templates/claude/settings.review.json +7 -0
  518. package/templates/codex/README.md +61 -0
  519. package/templates/codex/agents/codex-executor.toml +12 -0
  520. package/templates/codex/agents/codex-expert-executor.toml +12 -0
  521. package/templates/codex/agents/codex-expert-review-executor.toml +10 -0
  522. package/templates/codex/agents/codex-review-executor.toml +10 -0
  523. package/templates/copilot/README.md +41 -0
  524. package/templates/copilot/exec-defaults-snippet.yaml +28 -0
  525. package/templates/copilot/pm-members-snippet.yaml +44 -0
  526. package/templates/opencode/README.md +41 -0
  527. package/templates/opencode/agents/opencode-executor.md +59 -0
  528. package/templates/opencode/agents/opencode-reporter.md +26 -0
  529. package/templates/opencode/agents/opencode-review-executor.md +48 -0
  530. package/dist/exec-schedule-timeline-render.js +0 -201
  531. package/dist/exec-schedule-timeline.js +0 -2
@@ -0,0 +1,510 @@
1
+ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { isDeepStrictEqual } from "node:util";
4
+ import { buildSpecdojoFrontmatter, parseSpecdojoDocument } from "./frontmatter-namespace.js";
5
+ import { expandTemplate, stripTerminalControlSequences } from "./exec-shared.js";
6
+ import { formatMarkdownFile } from "./exec-format.js";
7
+ import { resolveSpecdojoPath, resolveSpecdojoPathIfExists } from "./template-resolution.js";
8
+ // ---------------------------------------------------------------------------
9
+ // Frontmatter helpers
10
+ // ---------------------------------------------------------------------------
11
+ // frontmatter から読んだ origin を検証して返す。未知の値は採用せず undefined(= schedule)
12
+ // として扱う。status 更新のたびに meta を組み直すため、既存値の持ち回しに使う。
13
+ function parseOrigin(value) {
14
+ return value === "register" || value === "schedule" || value === "job" ? value : undefined;
15
+ }
16
+ function serializeFrontmatter(meta) {
17
+ const inner = [
18
+ `id: ${meta.id}`,
19
+ `type: ${meta.type}`,
20
+ `task_id: ${meta.task_id}`,
21
+ `mode: ${meta.mode}`,
22
+ `status: ${meta.status}`,
23
+ `project_id: ${meta.project_id}`,
24
+ ];
25
+ if (meta.origin)
26
+ inner.push(`origin: ${meta.origin}`);
27
+ if (meta.job_id)
28
+ inner.push(`job_id: ${meta.job_id}`);
29
+ if (meta.run_id)
30
+ inner.push(`run_id: ${meta.run_id}`);
31
+ if (meta.plan_ref)
32
+ inner.push(`plan_ref: ${meta.plan_ref}`);
33
+ inner.push(`started_at: "${meta.started_at}"`);
34
+ if (meta.completed_at)
35
+ inner.push(`completed_at: "${meta.completed_at}"`);
36
+ if (meta.agent)
37
+ inner.push(`agent: ${meta.agent}`);
38
+ if (meta.execution)
39
+ inner.push(`execution: ${meta.execution}`);
40
+ if (meta.approach)
41
+ inner.push(`approach: ${meta.approach}`);
42
+ if (meta.targets && meta.targets.length > 0) {
43
+ inner.push("targets:");
44
+ for (const target of meta.targets)
45
+ inner.push(` - ${target}`);
46
+ }
47
+ // reason は agent stderr や subprocess の生出力由来で任意文字を含みうる。まず ANSI エスケープ
48
+ // シーケンスや制御文字を除去し(色付き hook 出力が result 表示を壊すのを防ぐ)、YAML として
49
+ // 安全にするため二重引用符内へ収め、内部の二重引用符は単引用符へ置換する(extractBlockReason は
50
+ // 単一行を返すため改行は無い)。
51
+ if (meta.block_reason) {
52
+ const safeReason = stripTerminalControlSequences(meta.block_reason).replace(/"/g, "'");
53
+ inner.push(`block_reason: "${safeReason}"`);
54
+ }
55
+ return buildSpecdojoFrontmatter(inner);
56
+ }
57
+ // exec-result frontmatter は `specdojo:` 名前空間配下にある。YAML パース後、スカラー値を
58
+ // 文字列へ寄せて Record<string, string> として返す(引用符の正規化は js-yaml が行う)。
59
+ // targets はリスト値のため meta とは別に返し、再シリアライズで欠落しないようにする。
60
+ function parseFrontmatter(content) {
61
+ const { data, body } = parseSpecdojoDocument(content);
62
+ const meta = {};
63
+ let targets;
64
+ for (const [key, value] of Object.entries(data)) {
65
+ if (key === "targets" && Array.isArray(value)) {
66
+ const list = value.filter((entry) => typeof entry === "string");
67
+ if (list.length > 0)
68
+ targets = list;
69
+ continue;
70
+ }
71
+ if (typeof value === "string")
72
+ meta[key] = value;
73
+ else if (typeof value === "number" || typeof value === "boolean")
74
+ meta[key] = String(value);
75
+ }
76
+ return { meta, ...(targets ? { targets } : {}), body };
77
+ }
78
+ function frontmatterWithBody(frontmatter, body) {
79
+ return `${frontmatter}\n\n${body.replace(/^\n+/, "")}`;
80
+ }
81
+ // ---------------------------------------------------------------------------
82
+ // Template-based generation (edit-result / review-result テンプレートの展開)
83
+ // ---------------------------------------------------------------------------
84
+ function templateFileName(mode) {
85
+ return mode === "review" ? "xrr-template.md" : "xer-template.md";
86
+ }
87
+ // finalize / bootstrap-finalize は human 確定タスクの approach。result は確認記録
88
+ // (done_criteria チェックリスト・確定対象・確定判断)を持つ専用テンプレートを使う。
89
+ function isFinalizeApproach(approach) {
90
+ return approach === "finalize" || approach === "bootstrap-finalize";
91
+ }
92
+ function execResultDocId(projectId, mode, localBase) {
93
+ const prefix = mode === "review" ? "xrr" : "xer";
94
+ const localId = `${prefix}-${localBase.toLowerCase()}`;
95
+ return projectId ? `${projectId}:${localId}` : localId;
96
+ }
97
+ // approach が finalize 系なら xer-human-<approach>-template.md を優先し、無ければ
98
+ // mode 別の標準テンプレートへフォールバックする(plan 側の human × approach 解決と対称)。
99
+ function loadResultTemplate(mode, approach) {
100
+ if (mode === "edit" && approach === "cross-deliverable-dedup") {
101
+ const crossDeliverablePath = resolveSpecdojoPathIfExists("docs/ja/specdojo/exec-templates/xer-cross-deliverable-dedup-template.md");
102
+ if (crossDeliverablePath)
103
+ return readFileSync(crossDeliverablePath, "utf8");
104
+ }
105
+ if (mode === "edit" && isFinalizeApproach(approach)) {
106
+ const finalizePath = resolveSpecdojoPathIfExists(`docs/ja/specdojo/exec-templates/xer-human-${approach}-template.md`);
107
+ if (finalizePath)
108
+ return readFileSync(finalizePath, "utf8");
109
+ }
110
+ const templatePath = resolveSpecdojoPath(`docs/ja/specdojo/exec-templates/${templateFileName(mode)}`);
111
+ return readFileSync(templatePath, "utf8");
112
+ }
113
+ // ---------------------------------------------------------------------------
114
+ // Public API
115
+ // ---------------------------------------------------------------------------
116
+ export function resultPathForTask(executionPath, nameBase) {
117
+ return join(executionPath, "exec", "results", `${nameBase}-result.md`);
118
+ }
119
+ // A unique-name run retains every attempt as a separate result. When a new result is scaffolded,
120
+ // close older unfinished attempts for the same task so they no longer look active or actionable.
121
+ // Fixed-name runs return before this helper is reached and continue to reuse their single result.
122
+ async function supersedePriorResults(resultsDir, taskId, nextResultPath, supersededAt) {
123
+ const supersededPaths = [];
124
+ for (const fileName of readdirSync(resultsDir).sort()) {
125
+ if (!fileName.endsWith("-result.md"))
126
+ continue;
127
+ const candidatePath = join(resultsDir, fileName);
128
+ if (candidatePath === nextResultPath)
129
+ continue;
130
+ let meta;
131
+ try {
132
+ meta = parseFrontmatter(readFileSync(candidatePath, "utf8")).meta;
133
+ }
134
+ catch {
135
+ // A malformed unrelated historical result must not prevent a new run from starting. It will
136
+ // remain visible to the normal frontmatter/schema validation and can be repaired separately.
137
+ continue;
138
+ }
139
+ if (meta.type !== "exec-result" ||
140
+ meta.task_id !== taskId ||
141
+ (meta.status !== "in_progress" && meta.status !== "blocked")) {
142
+ continue;
143
+ }
144
+ await updateResultStatus(candidatePath, "superseded", supersededAt);
145
+ supersededPaths.push(candidatePath);
146
+ }
147
+ return supersededPaths;
148
+ }
149
+ export async function scaffoldResult(opts) {
150
+ const { executionPath, taskId, mode, projectId, planRef, agent, startedAt, approach } = opts;
151
+ const stem = opts.stem ?? taskId;
152
+ const resultPath = resultPathForTask(executionPath, stem);
153
+ // Idempotent: claim and exec run can both reach this; never clobber an in-progress result.
154
+ if (existsSync(resultPath)) {
155
+ return { resultPath, created: false, supersededPaths: [] };
156
+ }
157
+ const resultsDir = join(executionPath, "exec", "results");
158
+ if (!existsSync(resultsDir))
159
+ mkdirSync(resultsDir, { recursive: true });
160
+ const template = loadResultTemplate(mode, approach);
161
+ const meta = {
162
+ id: execResultDocId(projectId, mode, stem),
163
+ type: "exec-result",
164
+ task_id: taskId,
165
+ mode,
166
+ status: "in_progress",
167
+ project_id: projectId,
168
+ started_at: startedAt,
169
+ agent,
170
+ ...(opts.origin ? { origin: opts.origin } : {}),
171
+ ...(opts.jobId ? { job_id: opts.jobId } : {}),
172
+ ...(opts.runId ? { run_id: opts.runId } : {}),
173
+ ...(planRef ? { plan_ref: planRef } : {}),
174
+ ...(opts.execution ? { execution: opts.execution } : {}),
175
+ ...(approach ? { approach } : {}),
176
+ ...(opts.targets && opts.targets.length > 0 ? { targets: opts.targets } : {}),
177
+ };
178
+ const values = { _FRONTMATTER_: serializeFrontmatter(meta) };
179
+ // Review results pre-expand per-RVP sections (role / viewpoint_id / criterion) so the result
180
+ // is self-contained. When the caller cannot resolve them, leave a language-neutral _TODO_
181
+ // marker; the result template's own prose explains how to fill the sections.
182
+ if (mode === "review") {
183
+ values._REVIEW_RESULT_SECTIONS_ = opts.reviewSections ?? "_TODO_";
184
+ }
185
+ // Finalize results pre-expand the confirmation record (done_criteria checklist and
186
+ // ready-promotion targets) so every finalize is verified against the same items.
187
+ // When the caller cannot resolve them, leave _TODO_ markers for manual fill-in.
188
+ if (isFinalizeApproach(approach)) {
189
+ values._DONE_CRITERIA_CHECKLIST_ = opts.finalizeSections?.doneCriteriaChecklist ?? "_TODO_";
190
+ values._FINALIZE_TARGETS_CHECKLIST_ = opts.finalizeSections?.targetsChecklist ?? "_TODO_";
191
+ }
192
+ const content = expandTemplate(template, values);
193
+ writeFileSync(resultPath, content, "utf8");
194
+ await formatMarkdownFile(resultPath);
195
+ const supersededPaths = await supersedePriorResults(resultsDir, taskId, resultPath, startedAt);
196
+ return { resultPath, created: true, supersededPaths };
197
+ }
198
+ // 必須節が未記入(テンプレートのプレースホルダのまま)かを検知するためのマーカー。
199
+ // result テンプレート(xer-template.md / xrr-template.md)の必須節プレースホルダに対応する。
200
+ // テンプレート文言を変えた場合はここも合わせて更新する。
201
+ const MANDATORY_PLACEHOLDERS = {
202
+ edit: ["_TODO_: 実施した内容", "_TODO_: 変更したファイル"],
203
+ review: ["recommendation: _TODO_"],
204
+ };
205
+ // runner が scaffold 時に必ず設定する識別・ライフサイクル項目。agent が frontmatter を
206
+ // 独自形式へ置換しても本文の _TODO_ だけでは検知できないため、終了時に非空を確認する。
207
+ const REQUIRED_SCAFFOLD_FIELDS = [
208
+ "id",
209
+ "type",
210
+ "task_id",
211
+ "mode",
212
+ "status",
213
+ "project_id",
214
+ "started_at",
215
+ "agent",
216
+ ];
217
+ // runner が試行間で更新する lifecycle 項目。rate-limit 後の resume では worktree 側だけが
218
+ // blocked へ更新されるため、元 scaffold との不変項目比較からは除外する。一方、同じ試行の
219
+ // 開始時スナップショットとの比較ではこれらも含め、agent による変更を許可しない。
220
+ const RUNNER_MANAGED_LIFECYCLE_FIELDS = new Set(["status", "completed_at", "block_reason"]);
221
+ function immutableScaffoldFields(data) {
222
+ return Object.fromEntries(Object.entries(data).filter(([field]) => !RUNNER_MANAGED_LIFECYCLE_FIELDS.has(field)));
223
+ }
224
+ function hasNonEmptyScaffoldFields(data, mode) {
225
+ if (data.type !== "exec-result" ||
226
+ data.mode !== mode ||
227
+ !["in_progress", "complete", "blocked", "superseded"].includes(String(data.status))) {
228
+ return false;
229
+ }
230
+ if (!REQUIRED_SCAFFOLD_FIELDS.every((field) => {
231
+ const value = data[field];
232
+ return typeof value === "string" && value.trim().length > 0;
233
+ })) {
234
+ return false;
235
+ }
236
+ const optionalScalars = ["origin", "job_id", "run_id", "plan_ref", "execution", "approach"];
237
+ if (optionalScalars.some((field) => {
238
+ if (!(field in data))
239
+ return false;
240
+ const value = data[field];
241
+ return typeof value !== "string" || value.trim().length === 0;
242
+ })) {
243
+ return false;
244
+ }
245
+ if ("targets" in data) {
246
+ const targets = data.targets;
247
+ if (!Array.isArray(targets) ||
248
+ targets.length === 0 ||
249
+ targets.some((target) => typeof target !== "string" || target.trim().length === 0)) {
250
+ return false;
251
+ }
252
+ }
253
+ return true;
254
+ }
255
+ // in-place 実行後の result が「scaffold のまま(必須節が未記入)」かを判定する。
256
+ // agent プロセスの終了コードだけでは block を検知できない(例えば claude -p は
257
+ // モデルが「blocked」と結論してもターン正常終了で 0 を返す)ため、agent 本来の責務で
258
+ // ある result 必須節の記入が行われたかを内容から確認する補助に使う。
259
+ // 必須節のプレースホルダが 1 つでも残っている、必須 frontmatter が非空でない、または
260
+ // agent 起動前に保持した scaffold の specdojo 名前空間からキー・値が変わっていれば未完了と
261
+ // みなす。YAML の引用符やキー順など表記だけの変更は、パース後の値が同じなら許容する。
262
+ export function isResultUnfilled(resultPath, mode, scaffoldFrontmatter, originalScaffoldFrontmatter) {
263
+ if (!existsSync(resultPath))
264
+ return scaffoldFrontmatter !== undefined;
265
+ const current = parseSpecdojoDocument(readFileSync(resultPath, "utf8"));
266
+ if (MANDATORY_PLACEHOLDERS[mode].some((marker) => current.body.includes(marker)))
267
+ return true;
268
+ if (!hasNonEmptyScaffoldFields(current.data, mode))
269
+ return true;
270
+ if (scaffoldFrontmatter !== undefined) {
271
+ if (!hasNonEmptyScaffoldFields(scaffoldFrontmatter, mode))
272
+ return true;
273
+ if (!isDeepStrictEqual(current.data, scaffoldFrontmatter))
274
+ return true;
275
+ }
276
+ // resume 時は、実行直前の worktree result を上の厳密比較に使う。さらに root に保持した
277
+ // 元 scaffold と不変項目を比較し、前回試行で生じた frontmatter 破壊を新しい基準として
278
+ // 取り込まない。status / completed_at / block_reason のみ runner 管理差分として許容する。
279
+ if (originalScaffoldFrontmatter !== undefined) {
280
+ if (!hasNonEmptyScaffoldFields(originalScaffoldFrontmatter, mode))
281
+ return true;
282
+ if (!isDeepStrictEqual(immutableScaffoldFields(current.data), immutableScaffoldFields(originalScaffoldFrontmatter))) {
283
+ return true;
284
+ }
285
+ }
286
+ return false;
287
+ }
288
+ // agent 起動前の result から、完了ガードで比較する specdojo frontmatter だけを保持する。
289
+ // 本文や YAML の表記差ではなく、scaffold されたキーと値を実行単位の正本にする。
290
+ export function readResultFrontmatterSnapshot(resultPath) {
291
+ if (!existsSync(resultPath))
292
+ return {};
293
+ return parseSpecdojoDocument(readFileSync(resultPath, "utf8")).data;
294
+ }
295
+ function reporterInlineText(value) {
296
+ return value
297
+ .replace(/[\r\n]+/g, " ")
298
+ .replace(/\s+/g, " ")
299
+ .replace(/</g, "&lt;")
300
+ .replace(/>/g, "&gt;")
301
+ .trim();
302
+ }
303
+ function reporterBulletList(values, empty) {
304
+ if (values.length === 0)
305
+ return `- ${empty}`;
306
+ return values.map((value) => `- ${reporterInlineText(value)}`).join("\n");
307
+ }
308
+ function renderEditReporterBody(output) {
309
+ const changedFiles = output.changed_files.length === 0
310
+ ? "- なし"
311
+ : output.changed_files
312
+ .map((file) => `- \`${reporterInlineText(file.path).replace(/`/g, "'")}\`: ${reporterInlineText(file.summary)}`)
313
+ .join("\n");
314
+ return [
315
+ "# Edit Result",
316
+ "",
317
+ "## 1. 実施内容",
318
+ "",
319
+ reporterBulletList(output.summary, "実施内容なし"),
320
+ "",
321
+ "## 2. 変更ファイル",
322
+ "",
323
+ changedFiles,
324
+ "",
325
+ "## 3. 申し送り",
326
+ "",
327
+ reporterBulletList(output.handoff, "なし"),
328
+ "",
329
+ "## 4. 進め方と実践の型の適用",
330
+ "",
331
+ reporterInlineText(output.approach),
332
+ ].join("\n");
333
+ }
334
+ function reviewViewpointContexts(body) {
335
+ const contexts = [];
336
+ const pattern = /^### (RVP-[0-9]{3})([^\n]*)\n\n\*\*確認基準\*\*: ([^\n]+)$/gmu;
337
+ for (const match of body.matchAll(pattern)) {
338
+ contexts.push({ id: match[1], suffix: match[2], criterion: match[3] });
339
+ }
340
+ return contexts;
341
+ }
342
+ function renderReviewReporterBody(output, scaffoldBody) {
343
+ const contexts = reviewViewpointContexts(scaffoldBody);
344
+ const expectedIds = contexts.map((context) => context.id);
345
+ const actualIds = output.viewpoint_results.map((viewpoint) => viewpoint.id);
346
+ if (!isDeepStrictEqual(actualIds, expectedIds)) {
347
+ throw new Error(`reporter viewpoint ids must match scaffold order: expected=[${expectedIds.join(", ")}], actual=[${actualIds.join(", ")}]`);
348
+ }
349
+ const byId = new Map(output.viewpoint_results.map((viewpoint) => [viewpoint.id, viewpoint]));
350
+ const viewpointSections = contexts.length === 0
351
+ ? "- 観点別結果: 該当なし"
352
+ : contexts
353
+ .map((context) => {
354
+ const viewpoint = byId.get(context.id);
355
+ if (!viewpoint)
356
+ throw new Error(`reporter viewpoint missing: ${context.id}`);
357
+ return [
358
+ `### ${context.id}${context.suffix}`,
359
+ "",
360
+ `**確認基準**: ${context.criterion}`,
361
+ "",
362
+ `- result: ${viewpoint.result}`,
363
+ `- evidence: ${viewpoint.evidence.map(reporterInlineText).join(" / ")}`,
364
+ `- notes: ${viewpoint.notes ? reporterInlineText(viewpoint.notes) : "なし"}`,
365
+ ].join("\n");
366
+ })
367
+ .join("\n\n");
368
+ return [
369
+ "# Review Result",
370
+ "",
371
+ "## 1. レビュー観点別結果",
372
+ "",
373
+ viewpointSections,
374
+ "",
375
+ "## 2. findings",
376
+ "",
377
+ reporterBulletList(output.findings, "なし"),
378
+ "",
379
+ "## 3. 実践の型との整合確認",
380
+ "",
381
+ reporterInlineText(output.approach),
382
+ "",
383
+ "## 4. decision",
384
+ "",
385
+ `- recommendation: ${output.recommendation}`,
386
+ ].join("\n");
387
+ }
388
+ /**
389
+ * Replaces only the result body from schema-validated reporter data. The scaffolded frontmatter
390
+ * remains byte-for-byte runner-owned until the lifecycle status update serializes it.
391
+ */
392
+ export async function renderReporterResult(resultPath, output) {
393
+ if (!existsSync(resultPath))
394
+ throw new Error(`Result not found: ${resultPath}`);
395
+ const content = readFileSync(resultPath, "utf8");
396
+ const parsed = parseSpecdojoDocument(content);
397
+ if (parsed.data.mode !== output.mode) {
398
+ throw new Error(`reporter mode does not match result scaffold: ${output.mode}`);
399
+ }
400
+ const frontmatter = content.match(/^---\r?\n[\s\S]*?\r?\n---/)?.[0];
401
+ if (!frontmatter)
402
+ throw new Error(`Result frontmatter not found: ${resultPath}`);
403
+ const body = output.mode === "edit"
404
+ ? renderEditReporterBody(output)
405
+ : renderReviewReporterBody(output, parsed.body);
406
+ writeFileSync(resultPath, frontmatterWithBody(frontmatter, body), "utf8");
407
+ await formatMarkdownFile(resultPath);
408
+ }
409
+ export async function updateResultStatus(resultPath, status, completedAt, reason) {
410
+ if (!existsSync(resultPath))
411
+ return;
412
+ const content = readFileSync(resultPath, "utf8");
413
+ const { meta: existingMeta, targets: existingTargets, body } = parseFrontmatter(content);
414
+ // block 理由は blocked のときのみ保持する。新しい reason を優先し、無ければ既存値を残す。
415
+ // complete へ遷移した場合は理由を消す。
416
+ const blockReason = status === "blocked" ? (reason ?? existingMeta.block_reason ?? undefined) : undefined;
417
+ const updatedMeta = {
418
+ id: existingMeta.id ?? "",
419
+ type: "exec-result",
420
+ task_id: existingMeta.task_id ?? "",
421
+ mode: existingMeta.mode ?? "edit",
422
+ status,
423
+ project_id: existingMeta.project_id ?? "",
424
+ started_at: existingMeta.started_at ?? "",
425
+ completed_at: completedAt,
426
+ agent: existingMeta.agent,
427
+ ...(parseOrigin(existingMeta.origin) ? { origin: parseOrigin(existingMeta.origin) } : {}),
428
+ ...(existingMeta.job_id ? { job_id: existingMeta.job_id } : {}),
429
+ ...(existingMeta.run_id ? { run_id: existingMeta.run_id } : {}),
430
+ ...(existingMeta.plan_ref ? { plan_ref: existingMeta.plan_ref } : {}),
431
+ ...(existingMeta.execution === "human" || existingMeta.execution === "agent"
432
+ ? { execution: existingMeta.execution }
433
+ : {}),
434
+ approach: existingMeta.approach ? existingMeta.approach : undefined,
435
+ ...(existingTargets ? { targets: existingTargets } : {}),
436
+ ...(blockReason ? { block_reason: blockReason } : {}),
437
+ };
438
+ writeFileSync(resultPath, frontmatterWithBody(serializeFrontmatter(updatedMeta), body), "utf8");
439
+ await formatMarkdownFile(resultPath);
440
+ }
441
+ // A fixed-name result is retained across attempts. Re-claiming starts a new attempt by resetting
442
+ // harness-owned lifecycle fields while preserving the prior body as handoff context; Git and exec
443
+ // events retain the previous completion record.
444
+ export async function resetResultForClaim(resultPath, agent, startedAt, execution) {
445
+ if (!existsSync(resultPath))
446
+ return;
447
+ const content = readFileSync(resultPath, "utf8");
448
+ const { meta: existingMeta, targets: existingTargets, body } = parseFrontmatter(content);
449
+ const existingExecution = existingMeta.execution === "human" || existingMeta.execution === "agent"
450
+ ? existingMeta.execution
451
+ : undefined;
452
+ const nextExecution = execution ?? existingExecution;
453
+ const updatedMeta = {
454
+ id: existingMeta.id ?? "",
455
+ type: "exec-result",
456
+ task_id: existingMeta.task_id ?? "",
457
+ mode: existingMeta.mode ?? "edit",
458
+ status: "in_progress",
459
+ project_id: existingMeta.project_id ?? "",
460
+ started_at: startedAt,
461
+ agent,
462
+ ...(parseOrigin(existingMeta.origin) ? { origin: parseOrigin(existingMeta.origin) } : {}),
463
+ ...(existingMeta.job_id ? { job_id: existingMeta.job_id } : {}),
464
+ ...(existingMeta.run_id ? { run_id: existingMeta.run_id } : {}),
465
+ ...(execution !== "human" && existingMeta.plan_ref ? { plan_ref: existingMeta.plan_ref } : {}),
466
+ ...(nextExecution ? { execution: nextExecution } : {}),
467
+ approach: existingMeta.approach ? existingMeta.approach : undefined,
468
+ ...(existingTargets ? { targets: existingTargets } : {}),
469
+ };
470
+ writeFileSync(resultPath, frontmatterWithBody(serializeFrontmatter(updatedMeta), body), "utf8");
471
+ await formatMarkdownFile(resultPath);
472
+ }
473
+ // human タスクの commit scope を、plan ではなく checkpoint 済み result から復元する。
474
+ // 不正な値は採用せず、呼び出し側が既存の plan 由来解決へフォールバックできるようにする。
475
+ export function parseResultTaskIdentity(resultContent) {
476
+ const { meta, targets } = parseFrontmatter(resultContent);
477
+ const taskId = meta.task_id?.trim() ?? "";
478
+ if (!taskId)
479
+ return null;
480
+ const mode = meta.mode === "review" ? "review" : "edit";
481
+ const projectId = meta.project_id?.trim() ?? "";
482
+ const execution = meta.execution === "human" || meta.execution === "agent" ? meta.execution : undefined;
483
+ const approach = meta.approach &&
484
+ [
485
+ "fully-guided",
486
+ "recipe-guided",
487
+ "freeform",
488
+ "bootstrap",
489
+ "retrofit",
490
+ "cross-deliverable-dedup",
491
+ "rulebook-maintenance",
492
+ "recipe-maintenance",
493
+ "sample-maintenance",
494
+ "template-maintenance",
495
+ "finalize",
496
+ "bootstrap-finalize",
497
+ ].includes(meta.approach)
498
+ ? meta.approach
499
+ : undefined;
500
+ const origin = parseOrigin(meta.origin);
501
+ return {
502
+ taskId,
503
+ mode,
504
+ projectId,
505
+ ...(execution ? { execution } : {}),
506
+ ...(approach ? { approach } : {}),
507
+ ...(origin ? { origin } : {}),
508
+ ...(targets ? { targets } : {}),
509
+ };
510
+ }
@@ -0,0 +1,149 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, utimesSync, } from "node:fs";
2
+ import { spawn } from "node:child_process";
3
+ import { join } from "node:path";
4
+ import { ensureDir, nowUtcIsoSeconds, randomHex, writeJson } from "./exec-shared.js";
5
+ export const EXEC_RUN_LOCK_HEARTBEAT_MS = 5_000;
6
+ export const EXEC_RUN_LOCK_STALE_MS = 30_000;
7
+ export const EXEC_RUN_LOCK_TOKEN_ENV = "SPECDOJO_EXEC_RUN_LOCK_TOKEN";
8
+ export const ROUTINE_EXEC_ENV = "SPECDOJO_ROUTINE_EXEC";
9
+ export const ROUTINE_BUSY_SKIP_EXIT_CODE = 75;
10
+ const EXEC_RUN_LOCK_POLL_MS = 200;
11
+ export class ExecRunBusyError extends Error {
12
+ lockDir;
13
+ owner;
14
+ constructor(lockDir, owner) {
15
+ super(`Exec run is busy for this project.\nLock: ${lockDir}\nOwner: ${owner}`);
16
+ this.lockDir = lockDir;
17
+ this.owner = owner;
18
+ this.name = "ExecRunBusyError";
19
+ }
20
+ }
21
+ export function execRunLockPath(executionPath) {
22
+ return join(executionPath, "exec", ".locks", "exec-run.lock");
23
+ }
24
+ function readOwner(lockDir) {
25
+ try {
26
+ return JSON.parse(readFileSync(join(lockDir, "owner.json"), "utf8"));
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ export function inheritsExecRunLock(executionPath) {
33
+ const inheritedToken = process.env[EXEC_RUN_LOCK_TOKEN_ENV];
34
+ if (!inheritedToken)
35
+ return false;
36
+ return readOwner(execRunLockPath(executionPath))?.token === inheritedToken;
37
+ }
38
+ function formatOwner(lockDir) {
39
+ const owner = readOwner(lockDir);
40
+ return owner ? JSON.stringify(owner) : "(owner metadata unavailable)";
41
+ }
42
+ function delay(ms) {
43
+ return new Promise((resolve) => setTimeout(resolve, ms));
44
+ }
45
+ const HEARTBEAT_SCRIPT = String.raw `
46
+ const fs = require("node:fs");
47
+ const path = require("node:path");
48
+ const [lockDir, token, intervalText, parentText] = process.argv.slice(1);
49
+ const ownerPath = path.join(lockDir, "owner.json");
50
+ const intervalMs = Number(intervalText);
51
+ const parentPid = Number(parentText);
52
+ function heartbeat() {
53
+ try {
54
+ process.kill(parentPid, 0);
55
+ const owner = JSON.parse(fs.readFileSync(ownerPath, "utf8"));
56
+ if (owner.token !== token) process.exit(0);
57
+ const now = new Date();
58
+ fs.utimesSync(lockDir, now, now);
59
+ } catch {
60
+ process.exit(0);
61
+ }
62
+ }
63
+ heartbeat();
64
+ setInterval(heartbeat, intervalMs);
65
+ `;
66
+ function startHeartbeat(lockDir, token, intervalMs) {
67
+ // A separate process keeps the heartbeat alive while the runner is inside spawnSync-based
68
+ // validate / refresh / git operations. It exits when the owner PID or token disappears.
69
+ const heartbeat = spawn(process.execPath, ["-e", HEARTBEAT_SCRIPT, lockDir, token, String(intervalMs), String(process.pid)], { detached: true, stdio: "ignore" });
70
+ heartbeat.unref();
71
+ return heartbeat;
72
+ }
73
+ function tryRemoveStaleLock(lockDir, staleMs) {
74
+ let ageMs;
75
+ try {
76
+ ageMs = Date.now() - statSync(lockDir).mtimeMs;
77
+ }
78
+ catch (error) {
79
+ if (error?.code === "ENOENT")
80
+ return true;
81
+ throw error;
82
+ }
83
+ if (ageMs <= staleMs)
84
+ return false;
85
+ const staleDir = `${lockDir}.stale-${process.pid}-${randomHex(4)}`;
86
+ try {
87
+ // Rename first so a competing process can never make us delete its newly acquired lock.
88
+ renameSync(lockDir, staleDir);
89
+ }
90
+ catch (error) {
91
+ if (error?.code === "ENOENT")
92
+ return true;
93
+ throw error;
94
+ }
95
+ rmSync(staleDir, { recursive: true, force: true });
96
+ return true;
97
+ }
98
+ export async function acquireExecRunLock(executionPath, opts) {
99
+ const lockDir = execRunLockPath(executionPath);
100
+ ensureDir(join(executionPath, "exec", ".locks"));
101
+ const heartbeatMs = opts.heartbeatMs ?? EXEC_RUN_LOCK_HEARTBEAT_MS;
102
+ const staleMs = opts.staleMs ?? EXEC_RUN_LOCK_STALE_MS;
103
+ const pollMs = opts.pollMs ?? EXEC_RUN_LOCK_POLL_MS;
104
+ const token = `${process.pid}-${randomHex(8)}`;
105
+ let waitingAnnounced = false;
106
+ while (true) {
107
+ try {
108
+ mkdirSync(lockDir);
109
+ writeJson(join(lockDir, "owner.json"), {
110
+ actor: opts.actor,
111
+ pid: process.pid,
112
+ token,
113
+ acquired_at_utc: nowUtcIsoSeconds(),
114
+ });
115
+ const now = new Date();
116
+ utimesSync(lockDir, now, now);
117
+ return {
118
+ lockDir,
119
+ token,
120
+ heartbeat: startHeartbeat(lockDir, token, heartbeatMs),
121
+ };
122
+ }
123
+ catch (error) {
124
+ if (error?.code !== "EEXIST")
125
+ throw error;
126
+ }
127
+ if (tryRemoveStaleLock(lockDir, staleMs))
128
+ continue;
129
+ if (opts.ifBusy === "skip")
130
+ return null;
131
+ if (opts.ifBusy === "fail") {
132
+ throw new ExecRunBusyError(lockDir, formatOwner(lockDir));
133
+ }
134
+ if (!waitingAnnounced) {
135
+ opts.onWait?.();
136
+ waitingAnnounced = true;
137
+ }
138
+ await delay(pollMs);
139
+ }
140
+ }
141
+ export function releaseExecRunLock(handle) {
142
+ handle.heartbeat.kill();
143
+ if (!existsSync(handle.lockDir))
144
+ return;
145
+ const owner = readOwner(handle.lockDir);
146
+ if (owner?.token !== handle.token)
147
+ return;
148
+ rmSync(handle.lockDir, { recursive: true, force: true });
149
+ }