specdojo 0.7.0 → 0.9.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 (462) hide show
  1. package/.github/agents/specdojo-orchestrator.md +7 -3
  2. package/CHANGELOG.md +217 -0
  3. package/dist/catalog/build.js +24 -1
  4. package/dist/catalog/catalog.js +16 -14
  5. package/dist/catalog/plan.js +1 -1
  6. package/dist/catalog/scaffold.js +4 -1
  7. package/dist/commands/agent.js +5 -3
  8. package/dist/commands/build.js +69 -10
  9. package/dist/commands/git.js +206 -0
  10. package/dist/commands/init.js +9 -3
  11. package/dist/commands/night-orchestrator.js +6 -4
  12. package/dist/commands/where.js +25 -0
  13. package/dist/dashboard/dashboard-timeline.js +18 -16
  14. package/dist/dashboard/dashboard.js +616 -261
  15. package/dist/dashboard/epic-plan.js +81 -0
  16. package/dist/dashboard/exec-records.js +16 -20
  17. package/dist/dashboard/routines.js +11 -12
  18. package/dist/dashboard/timeline-build.js +5 -9
  19. package/dist/dashboard/timeline.js +23 -18
  20. package/dist/devcontainer/scaffold.js +18 -0
  21. package/dist/docs/frontmatter-namespace.js +1 -48
  22. package/dist/docs/index-command.js +2 -2
  23. package/dist/docs/yaml-business-tables.js +243 -0
  24. package/dist/docs/yaml-interface-tables.js +106 -0
  25. package/dist/docs/yaml-pages-command.js +5 -3
  26. package/dist/docs/yaml-pages.js +268 -3
  27. package/dist/docs/yaml-table-shared.js +70 -0
  28. package/dist/docs/yaml-tables.js +39 -0
  29. package/dist/exec/agent-config.js +31 -0
  30. package/dist/exec/agent-plan.js +3 -2
  31. package/dist/exec/agent-protected-config.js +2 -0
  32. package/dist/exec/commands.js +100 -39
  33. package/dist/exec/commit-hook-skips.js +78 -0
  34. package/dist/exec/core.js +19 -7
  35. package/dist/exec/events.js +179 -8
  36. package/dist/exec/evidence.js +77 -19
  37. package/dist/exec/handoff.js +9 -13
  38. package/dist/exec/limit.js +1 -1
  39. package/dist/exec/mechanical-result.js +45 -0
  40. package/dist/exec/migrate-records.js +249 -0
  41. package/dist/exec/parent-validation.js +209 -15
  42. package/dist/exec/pipeline-state.js +27 -5
  43. package/dist/exec/plans-condense-findings.js +89 -0
  44. package/dist/exec/plans-core.js +45 -19
  45. package/dist/exec/plans-generation.js +52 -30
  46. package/dist/exec/plans-grade-findings.js +8 -3
  47. package/dist/exec/plans-kata-findings.js +61 -0
  48. package/dist/exec/plans-planning.js +3 -3
  49. package/dist/exec/plans-storage.js +12 -24
  50. package/dist/exec/post-integration.js +162 -0
  51. package/dist/exec/queue-command.js +166 -0
  52. package/dist/exec/queue.js +285 -0
  53. package/dist/exec/register-foreign-wait.js +84 -0
  54. package/dist/exec/register-resume.js +55 -56
  55. package/dist/exec/register.js +26 -22
  56. package/dist/exec/repo-integration-sync.js +21 -5
  57. package/dist/exec/repo-integration.js +21 -1
  58. package/dist/exec/reporter.js +121 -23
  59. package/dist/exec/results.js +106 -25
  60. package/dist/exec/review-completion.js +47 -0
  61. package/dist/exec/review-kata.js +112 -0
  62. package/dist/exec/run/agent-pipeline.js +78 -8
  63. package/dist/exec/run/agent.js +32 -13
  64. package/dist/exec/run/change-scope.js +365 -0
  65. package/dist/exec/run/deferred-cleanup.js +31 -0
  66. package/dist/exec/run/in-place.js +73 -33
  67. package/dist/exec/run/job-lock.js +66 -0
  68. package/dist/exec/run/job-sequence.js +137 -0
  69. package/dist/exec/run/job.js +135 -41
  70. package/dist/exec/run/lifecycle-commands.js +189 -37
  71. package/dist/exec/run/lock.js +22 -1
  72. package/dist/exec/run/mode-shared.js +11 -3
  73. package/dist/exec/run/register-command.js +14 -15
  74. package/dist/exec/run/register-core.js +20 -13
  75. package/dist/exec/run/register-mode.js +77 -17
  76. package/dist/exec/run/register-post-review.js +21 -9
  77. package/dist/exec/run/register-resume.js +95 -31
  78. package/dist/exec/run/register-state.js +23 -15
  79. package/dist/exec/run/register-worktree.js +184 -139
  80. package/dist/exec/run/schedule-mode.js +79 -18
  81. package/dist/exec/run/schedule-prepare.js +204 -59
  82. package/dist/exec/run/schedule-task.js +203 -49
  83. package/dist/exec/run/shared.js +9 -3
  84. package/dist/exec/run/trailing-records.js +35 -0
  85. package/dist/exec/run-records.js +2 -0
  86. package/dist/exec/schedule/schedule.js +116 -4
  87. package/dist/exec/shared.js +1 -1
  88. package/dist/exec/smoke.js +190 -0
  89. package/dist/exec/strategy.js +14 -3
  90. package/dist/exec/task-view.js +6 -4
  91. package/dist/exec/trailing-records.js +242 -0
  92. package/dist/exec/trial-commands.js +8 -4
  93. package/dist/exec/trial-core.js +6 -1
  94. package/dist/exec/validate-records-commit.js +110 -0
  95. package/dist/exec/validate-records.js +148 -0
  96. package/dist/exec/validation-metrics.js +181 -0
  97. package/dist/exec/worktree-cleanup-lock.js +26 -0
  98. package/dist/exec/worktree-command.js +38 -17
  99. package/dist/exec/worktree-ops-commit.js +119 -48
  100. package/dist/exec/worktree-ops-lifecycle.js +77 -48
  101. package/dist/exec/worktree-ops-merge.js +13 -2
  102. package/dist/exec/worktree-ops.js +2 -2
  103. package/dist/exec/worktree.js +32 -4
  104. package/dist/grade/apply.js +32 -6
  105. package/dist/grade/command-apply.js +3 -3
  106. package/dist/grade/command-inspect.js +7 -5
  107. package/dist/grade/command-plan.js +1 -1
  108. package/dist/grade/command-run.js +7 -1
  109. package/dist/grade/command-shared.js +1 -1
  110. package/dist/grade/core.js +18 -5
  111. package/dist/grade/markdown.js +3 -3
  112. package/dist/grade/pipeline-state.js +15 -11
  113. package/dist/grade/plan.js +37 -17
  114. package/dist/grade/result.js +3 -3
  115. package/dist/grade/run.js +87 -11
  116. package/dist/grade/target-discovery.js +17 -4
  117. package/dist/grade/targets.js +12 -11
  118. package/dist/job/definition.js +84 -8
  119. package/dist/job/job.js +109 -39
  120. package/dist/job/noop.js +104 -0
  121. package/dist/register/authoring-sources.js +22 -16
  122. package/dist/register/core.js +2 -0
  123. package/dist/register/create-commands.js +28 -3
  124. package/dist/register/deliverable-target.js +9 -1
  125. package/dist/register/epic.js +104 -26
  126. package/dist/register/event-merge.js +3 -0
  127. package/dist/register/events.js +4 -0
  128. package/dist/register/external-project.js +3 -0
  129. package/dist/register/item.js +6 -0
  130. package/dist/register/maintenance-commands.js +6 -3
  131. package/dist/register/planning.js +7 -14
  132. package/dist/register/register.js +74 -16
  133. package/dist/register/track-domains.js +34 -0
  134. package/dist/register/track-plan.js +78 -0
  135. package/dist/register/transition-commands.js +8 -0
  136. package/dist/register/work-table.js +64 -0
  137. package/dist/review/grade.js +35 -13
  138. package/dist/routine/definition.js +13 -3
  139. package/dist/routine/failure.js +30 -0
  140. package/dist/routine/routine.js +189 -71
  141. package/dist/routine/status.js +62 -0
  142. package/dist/routine/storage.js +33 -0
  143. package/dist/schedule/schedule.js +39 -39
  144. package/dist/schedule/strategy-generate-document.js +26 -14
  145. package/dist/schedule/strategy-generate-scope.js +17 -45
  146. package/dist/schedule/strategy-generate.js +33 -3
  147. package/dist/schedule/strategy-profiles.js +86 -12
  148. package/dist/shared/agent-types.js +7 -0
  149. package/dist/shared/condense-records.js +25 -0
  150. package/dist/shared/cross-process-lock.js +9 -1
  151. package/dist/shared/deprecation.js +8 -0
  152. package/dist/shared/dist-freshness.js +8 -2
  153. package/dist/shared/document-metadata.js +20 -0
  154. package/dist/shared/finding-cause.js +20 -0
  155. package/dist/shared/frontmatter-namespace.js +48 -0
  156. package/dist/shared/git-environment.js +2 -1
  157. package/dist/shared/git.js +186 -16
  158. package/dist/shared/grade-result.js +17 -1
  159. package/dist/shared/lefthook-scaffold.js +3 -0
  160. package/dist/shared/local-config.js +244 -0
  161. package/dist/shared/local-state.js +20 -0
  162. package/dist/shared/markdownlint-config.js +8 -3
  163. package/dist/shared/plan-conventions.js +129 -0
  164. package/dist/shared/plan-templates.js +57 -41
  165. package/dist/shared/run-records.js +224 -0
  166. package/dist/shared/specdojo-config.js +73 -41
  167. package/dist/shared/specdojo-gitignore.js +1 -0
  168. package/dist/shared/text.js +74 -6
  169. package/dist/shared/timeline-index.js +2 -0
  170. package/dist/shared/where-alias.js +13 -0
  171. package/dist/specdojo.js +4 -0
  172. package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +11 -2
  173. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +4 -74
  174. package/docs/ja/specdojo/exec-templates/xep-condense-template.md +50 -0
  175. package/docs/ja/specdojo/exec-templates/xep-draft-template.md +17 -5
  176. package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +16 -3
  177. package/docs/ja/specdojo/exec-templates/xep-recipe-guided-template.md +15 -5
  178. package/docs/ja/specdojo/exec-templates/xep-recipe-maintenance-template.md +6 -0
  179. package/docs/ja/specdojo/exec-templates/xep-register-template.md +1 -1
  180. package/docs/ja/specdojo/exec-templates/xep-rulebook-maintenance-template.md +6 -0
  181. package/docs/ja/specdojo/exec-templates/xep-sample-maintenance-template.md +6 -0
  182. package/docs/ja/specdojo/exec-templates/xep-template-maintenance-template.md +6 -0
  183. package/docs/ja/specdojo/exec-templates/xer-condense-template.md +25 -0
  184. package/docs/ja/specdojo/exec-templates/xp-common-conventions-template.md +50 -0
  185. package/docs/ja/specdojo/exec-templates/xrp-common-conventions-template.md +30 -0
  186. package/docs/ja/specdojo/guides/branch-workflow-guide.md +1 -1
  187. package/docs/ja/specdojo/guides/docs-editing-guide.md +12 -0
  188. package/docs/ja/specdojo/guides/docs-structure-guide.md +48 -15
  189. package/docs/ja/specdojo/guides/exec-config-guide.md +69 -19
  190. package/docs/ja/specdojo/guides/exec-operation-guide.md +97 -18
  191. package/docs/ja/specdojo/guides/exec-worktree-guide.md +20 -11
  192. package/docs/ja/specdojo/guides/job-sequence-guide.md +77 -0
  193. package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +92 -55
  194. package/docs/ja/specdojo/guides/project-move-guide.md +381 -0
  195. package/docs/ja/specdojo/guides/quick-start-guide.md +73 -17
  196. package/docs/ja/specdojo/guides/register-operation-guide.md +26 -6
  197. package/docs/ja/specdojo/guides/remote-host-development-guide.md +2 -0
  198. package/docs/ja/specdojo/guides/review-guide.md +22 -19
  199. package/docs/ja/specdojo/guides/routine-operation-guide.md +23 -12
  200. package/docs/ja/specdojo/guides/ryu-guide.md +23 -13
  201. package/docs/ja/specdojo/guides/schedule-design-guide.md +27 -21
  202. package/docs/ja/specdojo/guides/schedule-operation-guide.md +27 -3
  203. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +5 -4
  204. package/docs/ja/specdojo/guides/timeline-design-guide.md +27 -144
  205. package/docs/ja/specdojo/guides/use-case-guide.md +92 -155
  206. package/docs/ja/specdojo/guides/waza-guide.md +12 -8
  207. package/docs/ja/specdojo/recipes/bac-recipe.md +111 -0
  208. package/docs/ja/specdojo/recipes/bes-recipe.md +141 -0
  209. package/docs/ja/specdojo/recipes/bps-recipe.md +88 -139
  210. package/docs/ja/specdojo/recipes/br-recipe.md +77 -0
  211. package/docs/ja/specdojo/recipes/cdfd-overview-recipe.md +97 -109
  212. package/docs/ja/specdojo/recipes/cdfd-recipe.md +85 -146
  213. package/docs/ja/specdojo/recipes/cdfd-uc-recipe.md +92 -99
  214. package/docs/ja/specdojo/recipes/cnd-recipe.md +135 -0
  215. package/docs/ja/specdojo/recipes/cpd-recipe.md +140 -0
  216. package/docs/ja/specdojo/recipes/cxd-recipe.md +162 -0
  217. package/docs/ja/specdojo/recipes/ifd-recipe.md +145 -0
  218. package/docs/ja/specdojo/recipes/ifx-cmd-recipe.md +112 -90
  219. package/docs/ja/specdojo/recipes/ifx-index-recipe.md +164 -0
  220. package/docs/ja/specdojo/recipes/pm-communication-plan-recipe.md +60 -49
  221. package/docs/ja/specdojo/recipes/pm-members-recipe.md +50 -51
  222. package/docs/ja/specdojo/recipes/pm-organization-recipe.md +59 -48
  223. package/docs/ja/specdojo/recipes/pm-plan-recipe.md +72 -50
  224. package/docs/ja/specdojo/recipes/pm-quality-management-plan-recipe.md +40 -49
  225. package/docs/ja/specdojo/recipes/pm-raci-recipe.md +42 -48
  226. package/docs/ja/specdojo/recipes/pm-roles-recipe.md +52 -81
  227. package/docs/ja/specdojo/recipes/prj-assumptions-constraints-dependencies-recipe.md +64 -91
  228. package/docs/ja/specdojo/recipes/prj-charter-recipe.md +71 -106
  229. package/docs/ja/specdojo/recipes/prj-comparison-of-alternatives-recipe.md +78 -156
  230. package/docs/ja/specdojo/recipes/prj-issues-and-approach-recipe.md +62 -111
  231. package/docs/ja/specdojo/recipes/prj-scope-recipe.md +67 -123
  232. package/docs/ja/specdojo/recipes/prj-stakeholder-register-recipe.md +60 -96
  233. package/docs/ja/specdojo/recipes/prj-success-criteria-and-acceptance-criteria-recipe.md +61 -105
  234. package/docs/ja/specdojo/recipes/stsd-recipe.md +88 -80
  235. package/docs/ja/specdojo/recipes/sysd-critical-flows-recipe.md +129 -0
  236. package/docs/ja/specdojo/recipes/sysd-cross-cutting-policy-recipe.md +146 -0
  237. package/docs/ja/specdojo/recipes/sysd-index-recipe.md +141 -0
  238. package/docs/ja/specdojo/recipes/tsd-recipe.md +149 -129
  239. package/docs/ja/specdojo/references/command-reference.md +303 -148
  240. package/docs/ja/specdojo/references/deliverables-reference.md +30 -16
  241. package/docs/ja/specdojo/references/directory-layout-reference.md +3 -2
  242. package/docs/ja/specdojo/references/specdojo-config-reference.md +54 -18
  243. package/docs/ja/specdojo/rulebooks/atc-index-rulebook.md +101 -257
  244. package/docs/ja/specdojo/rulebooks/atc-rulebook.md +102 -228
  245. package/docs/ja/specdojo/rulebooks/bac-rulebook.md +63 -290
  246. package/docs/ja/specdojo/rulebooks/bdd-rulebook.md +162 -80
  247. package/docs/ja/specdojo/rulebooks/bds-rulebook.md +118 -155
  248. package/docs/ja/specdojo/rulebooks/bes-index-rulebook.md +128 -60
  249. package/docs/ja/specdojo/rulebooks/bes-rulebook.md +70 -94
  250. package/docs/ja/specdojo/rulebooks/bps-rulebook.md +24 -56
  251. package/docs/ja/specdojo/rulebooks/br-rulebook.md +58 -103
  252. package/docs/ja/specdojo/rulebooks/ccd-mermaid-rulebook.md +103 -223
  253. package/docs/ja/specdojo/rulebooks/cdfd-d2-rulebook.md +18 -93
  254. package/docs/ja/specdojo/rulebooks/cdfd-mermaid-rulebook.md +18 -52
  255. package/docs/ja/specdojo/rulebooks/cdfd-overview-rulebook.md +109 -147
  256. package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +80 -108
  257. package/docs/ja/specdojo/rulebooks/cdfd-uc-rulebook.md +51 -55
  258. package/docs/ja/specdojo/rulebooks/cdr-rulebook.md +144 -0
  259. package/docs/ja/specdojo/rulebooks/cdsd-rulebook.md +81 -68
  260. package/docs/ja/specdojo/rulebooks/cdt-rulebook.md +139 -0
  261. package/docs/ja/specdojo/rulebooks/cld-rulebook.md +9 -184
  262. package/docs/ja/specdojo/rulebooks/clis-rulebook.md +170 -0
  263. package/docs/ja/specdojo/rulebooks/cnd-mermaid-rulebook.md +33 -86
  264. package/docs/ja/specdojo/rulebooks/cnd-rulebook.md +79 -249
  265. package/docs/ja/specdojo/rulebooks/cop-index-rulebook.md +45 -131
  266. package/docs/ja/specdojo/rulebooks/cop-rulebook.md +69 -275
  267. package/docs/ja/specdojo/rulebooks/cpd-mermaid-rulebook.md +20 -112
  268. package/docs/ja/specdojo/rulebooks/cpd-rulebook.md +79 -249
  269. package/docs/ja/specdojo/rulebooks/cxd-mermaid-rulebook.md +12 -145
  270. package/docs/ja/specdojo/rulebooks/cxd-rulebook.md +115 -256
  271. package/docs/ja/specdojo/rulebooks/dct-index-rulebook.md +79 -109
  272. package/docs/ja/specdojo/rulebooks/dct-rulebook.md +119 -174
  273. package/docs/ja/specdojo/rulebooks/dec-rulebook.md +6 -14
  274. package/docs/ja/specdojo/rulebooks/dmd-index-rulebook.md +22 -66
  275. package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +36 -94
  276. package/docs/ja/specdojo/rulebooks/dss-rulebook.md +171 -0
  277. package/docs/ja/specdojo/rulebooks/etc-index-rulebook.md +31 -131
  278. package/docs/ja/specdojo/rulebooks/etc-rulebook.md +50 -104
  279. package/docs/ja/specdojo/rulebooks/gl-rulebook.md +93 -57
  280. package/docs/ja/specdojo/rulebooks/ifd-mermaid-rulebook.md +63 -253
  281. package/docs/ja/specdojo/rulebooks/ifx-api-rulebook.md +14 -20
  282. package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +79 -76
  283. package/docs/ja/specdojo/rulebooks/ifx-file-rulebook.md +182 -237
  284. package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +111 -40
  285. package/docs/ja/specdojo/rulebooks/ifx-msg-rulebook.md +14 -22
  286. package/docs/ja/specdojo/rulebooks/imp-business-rulebook.md +23 -46
  287. package/docs/ja/specdojo/rulebooks/imp-data-rulebook.md +41 -64
  288. package/docs/ja/specdojo/rulebooks/imp-interface-rulebook.md +16 -40
  289. package/docs/ja/specdojo/rulebooks/imp-operations-rulebook.md +34 -61
  290. package/docs/ja/specdojo/rulebooks/imp-test-rulebook.md +27 -50
  291. package/docs/ja/specdojo/rulebooks/itc-index-rulebook.md +70 -199
  292. package/docs/ja/specdojo/rulebooks/itc-rulebook.md +65 -153
  293. package/docs/ja/specdojo/rulebooks/mip-index-rulebook.md +74 -150
  294. package/docs/ja/specdojo/rulebooks/mm-rulebook.md +12 -23
  295. package/docs/ja/specdojo/rulebooks/mtp-rulebook.md +99 -176
  296. package/docs/ja/specdojo/rulebooks/nfr-availability-rulebook.md +35 -61
  297. package/docs/ja/specdojo/rulebooks/nfr-index-rulebook.md +75 -117
  298. package/docs/ja/specdojo/rulebooks/nfr-integrity-rulebook.md +31 -60
  299. package/docs/ja/specdojo/rulebooks/nfr-maintainability-rulebook.md +26 -81
  300. package/docs/ja/specdojo/rulebooks/nfr-operations-rulebook.md +32 -70
  301. package/docs/ja/specdojo/rulebooks/nfr-performance-rulebook.md +45 -87
  302. package/docs/ja/specdojo/rulebooks/nfr-reliability-rulebook.md +48 -101
  303. package/docs/ja/specdojo/rulebooks/nfr-security-safety-rulebook.md +44 -80
  304. package/docs/ja/specdojo/rulebooks/nfr-usability-rulebook.md +59 -127
  305. package/docs/ja/specdojo/rulebooks/opd-index-rulebook.md +31 -50
  306. package/docs/ja/specdojo/rulebooks/opd-rulebook.md +42 -109
  307. package/docs/ja/specdojo/rulebooks/opr-index-rulebook.md +29 -42
  308. package/docs/ja/specdojo/rulebooks/opr-rulebook.md +29 -87
  309. package/docs/ja/specdojo/rulebooks/otp-index-rulebook.md +62 -84
  310. package/docs/ja/specdojo/rulebooks/otp-rulebook.md +11 -61
  311. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +92 -102
  312. package/docs/ja/specdojo/rulebooks/pm-change-request-log-rulebook.md +25 -34
  313. package/docs/ja/specdojo/rulebooks/pm-communication-plan-rulebook.md +30 -53
  314. package/docs/ja/specdojo/rulebooks/pm-issue-log-rulebook.md +23 -35
  315. package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +27 -45
  316. package/docs/ja/specdojo/rulebooks/pm-organization-rulebook.md +45 -59
  317. package/docs/ja/specdojo/rulebooks/pm-plan-rulebook.md +56 -66
  318. package/docs/ja/specdojo/rulebooks/pm-quality-management-plan-rulebook.md +54 -62
  319. package/docs/ja/specdojo/rulebooks/pm-raci-rulebook.md +46 -65
  320. package/docs/ja/specdojo/rulebooks/pm-risk-register-rulebook.md +28 -35
  321. package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +65 -97
  322. package/docs/ja/specdojo/rulebooks/pr-rulebook.md +6 -18
  323. package/docs/ja/specdojo/rulebooks/prj-assumptions-constraints-dependencies-rulebook.md +48 -78
  324. package/docs/ja/specdojo/rulebooks/prj-charter-rulebook.md +23 -97
  325. package/docs/ja/specdojo/rulebooks/prj-comparison-of-alternatives-rulebook.md +61 -153
  326. package/docs/ja/specdojo/rulebooks/prj-issues-and-approach-rulebook.md +43 -116
  327. package/docs/ja/specdojo/rulebooks/prj-scope-rulebook.md +16 -51
  328. package/docs/ja/specdojo/rulebooks/prj-stakeholder-register-rulebook.md +47 -92
  329. package/docs/ja/specdojo/rulebooks/prj-success-criteria-and-acceptance-criteria-rulebook.md +25 -84
  330. package/docs/ja/specdojo/rulebooks/sac-rulebook.md +44 -107
  331. package/docs/ja/specdojo/rulebooks/sf-index-rulebook.md +106 -32
  332. package/docs/ja/specdojo/rulebooks/sf-rulebook.md +111 -61
  333. package/docs/ja/specdojo/rulebooks/sld-rulebook.md +129 -59
  334. package/docs/ja/specdojo/rulebooks/stc-index-rulebook.md +90 -189
  335. package/docs/ja/specdojo/rulebooks/stc-rulebook.md +45 -105
  336. package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +46 -40
  337. package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +104 -68
  338. package/docs/ja/specdojo/rulebooks/sysd-critical-flows-rulebook.md +64 -330
  339. package/docs/ja/specdojo/rulebooks/sysd-cross-cutting-policy-rulebook.md +70 -263
  340. package/docs/ja/specdojo/rulebooks/sysd-index-rulebook.md +58 -200
  341. package/docs/ja/specdojo/rulebooks/sysd-rulebook.md +47 -60
  342. package/docs/ja/specdojo/rulebooks/tml-rulebook.md +4 -9
  343. package/docs/ja/specdojo/rulebooks/trc-requirements-to-specs-rulebook.md +69 -71
  344. package/docs/ja/specdojo/rulebooks/trc-requirements-to-tests-rulebook.md +65 -72
  345. package/docs/ja/specdojo/rulebooks/tsd-index-rulebook.md +35 -46
  346. package/docs/ja/specdojo/rulebooks/tsd-rulebook.md +49 -66
  347. package/docs/ja/specdojo/rulebooks/tsp-index-rulebook.md +64 -139
  348. package/docs/ja/specdojo/rulebooks/uis-rulebook.md +91 -161
  349. package/docs/ja/specdojo/rulebooks/utc-index-rulebook.md +49 -144
  350. package/docs/ja/specdojo/rulebooks/utc-rulebook.md +67 -155
  351. package/docs/ja/specdojo/samples/bac-sample.md +106 -21
  352. package/docs/ja/specdojo/samples/bdd-sample.yaml +143 -35
  353. package/docs/ja/specdojo/samples/bds-sample.md +87 -21
  354. package/docs/ja/specdojo/samples/bes-index-sample.md +42 -20
  355. package/docs/ja/specdojo/samples/bes-sample.md +70 -21
  356. package/docs/ja/specdojo/samples/bps-sample.md +42 -54
  357. package/docs/ja/specdojo/samples/br-sample.md +57 -15
  358. package/docs/ja/specdojo/samples/ccd-sample.md +80 -19
  359. package/docs/ja/specdojo/samples/cdfd-sample.md +172 -99
  360. package/docs/ja/specdojo/samples/cdfd-uc-sample.md +9 -7
  361. package/docs/ja/specdojo/samples/cdr-sample.md +78 -0
  362. package/docs/ja/specdojo/samples/cdsd-sample.md +73 -20
  363. package/docs/ja/specdojo/samples/cdt-sample.md +116 -0
  364. package/docs/ja/specdojo/samples/cld-sample.md +3 -30
  365. package/docs/ja/specdojo/samples/clis-sample.md +125 -0
  366. package/docs/ja/specdojo/samples/cnd-sample.md +127 -21
  367. package/docs/ja/specdojo/samples/cpd-sample.md +136 -22
  368. package/docs/ja/specdojo/samples/cxd-sample.md +108 -22
  369. package/docs/ja/specdojo/samples/dct-index-sample.yaml +63 -17
  370. package/docs/ja/specdojo/samples/dec-sample.md +2 -3
  371. package/docs/ja/specdojo/samples/dss-sample.md +175 -0
  372. package/docs/ja/specdojo/samples/gl-sample.yaml +50 -14
  373. package/docs/ja/specdojo/samples/ifd-sample.md +105 -21
  374. package/docs/ja/specdojo/samples/ifx-api-sample.yaml +0 -2
  375. package/docs/ja/specdojo/samples/ifx-cmd-sample.yaml +91 -60
  376. package/docs/ja/specdojo/samples/ifx-file-sample.md +462 -21
  377. package/docs/ja/specdojo/samples/ifx-index-sample.yaml +87 -19
  378. package/docs/ja/specdojo/samples/ifx-msg-sample.yaml +0 -2
  379. package/docs/ja/specdojo/samples/job-sequence.yaml +67 -0
  380. package/docs/ja/specdojo/samples/mip-index-sample.md +98 -20
  381. package/docs/ja/specdojo/samples/pm-communication-plan-sample.md +26 -19
  382. package/docs/ja/specdojo/samples/pm-members-sample.yaml +37 -13
  383. package/docs/ja/specdojo/samples/pm-organization-sample.md +42 -21
  384. package/docs/ja/specdojo/samples/pm-plan-sample.md +78 -26
  385. package/docs/ja/specdojo/samples/pm-quality-management-plan-sample.md +41 -22
  386. package/docs/ja/specdojo/samples/pm-raci-sample.md +63 -28
  387. package/docs/ja/specdojo/samples/pm-roles-sample.yaml +13 -12
  388. package/docs/ja/specdojo/samples/prj-assumptions-constraints-dependencies-sample.md +33 -25
  389. package/docs/ja/specdojo/samples/prj-charter-sample.md +42 -59
  390. package/docs/ja/specdojo/samples/prj-comparison-of-alternatives-sample.md +83 -62
  391. package/docs/ja/specdojo/samples/prj-success-criteria-and-acceptance-criteria-sample.md +30 -33
  392. package/docs/ja/specdojo/samples/sf-index-sample.md +47 -20
  393. package/docs/ja/specdojo/samples/sf-sample.md +109 -21
  394. package/docs/ja/specdojo/samples/sld-sample.md +88 -21
  395. package/docs/ja/specdojo/samples/stsd-sample.md +54 -26
  396. package/docs/ja/specdojo/samples/sysd-critical-flows-sample.md +166 -21
  397. package/docs/ja/specdojo/samples/sysd-cross-cutting-policy-sample.md +178 -21
  398. package/docs/ja/specdojo/samples/sysd-index-sample.md +82 -21
  399. package/docs/ja/specdojo/samples/tml-sample.yaml +4 -1
  400. package/docs/ja/specdojo/samples/uis-sample.md +141 -20
  401. package/docs/ja/specdojo/standards/document-metadata-standard.md +33 -4
  402. package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +3 -1
  403. package/docs/ja/specdojo/standards/job-definition-standard.md +24 -9
  404. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +1 -0
  405. package/docs/ja/specdojo/templates/bac-template.md +76 -0
  406. package/docs/ja/specdojo/templates/bes-template.md +56 -0
  407. package/docs/ja/specdojo/templates/br-template.md +64 -0
  408. package/docs/ja/specdojo/templates/cdfd-template.md +81 -54
  409. package/docs/ja/specdojo/templates/cdfd-uc-template.md +9 -5
  410. package/docs/ja/specdojo/templates/cdr-template.md +58 -0
  411. package/docs/ja/specdojo/templates/cnd-template.md +137 -0
  412. package/docs/ja/specdojo/templates/cpd-template.md +129 -0
  413. package/docs/ja/specdojo/templates/cxd-template.md +105 -0
  414. package/docs/ja/specdojo/templates/dct-data-model-cdt-template.yaml +40 -0
  415. package/docs/ja/specdojo/templates/dct-data-model-cld-template.yaml +7 -14
  416. package/docs/ja/specdojo/templates/dct-index-template.md +9 -20
  417. package/docs/ja/specdojo/templates/dct-project-management-template.yaml +5 -1
  418. package/docs/ja/specdojo/templates/ifd-template.md +86 -0
  419. package/docs/ja/specdojo/templates/ifx-cmd-template.yaml +44 -28
  420. package/docs/ja/specdojo/templates/ifx-index-template.yaml +40 -0
  421. package/docs/ja/specdojo/templates/opr-template.md +2 -4
  422. package/docs/ja/specdojo/templates/pm-organization-template.md +9 -3
  423. package/docs/ja/specdojo/templates/pm-plan-template.md +4 -4
  424. package/docs/ja/specdojo/templates/pm-quality-management-plan-template.md +17 -9
  425. package/docs/ja/specdojo/templates/pm-raci-template.md +24 -13
  426. package/docs/ja/specdojo/templates/pm-roles-template.yaml +3 -2
  427. package/docs/ja/specdojo/templates/prj-assumptions-constraints-dependencies-template.md +6 -3
  428. package/docs/ja/specdojo/templates/prj-comparison-of-alternatives-template.md +22 -19
  429. package/docs/ja/specdojo/templates/stsd-template.md +46 -21
  430. package/docs/ja/specdojo/templates/sysd-critical-flows-template.md +94 -0
  431. package/docs/ja/specdojo/templates/sysd-cross-cutting-policy-template.md +122 -0
  432. package/docs/ja/specdojo/templates/sysd-index-template.md +89 -0
  433. package/docs/specdojo/lib/yaml-metadata.cjs +7 -0
  434. package/docs/specdojo/schemas/v1/bdd.schema.yaml +25 -57
  435. package/docs/specdojo/schemas/v1/condense-records.schema.yaml +26 -0
  436. package/docs/specdojo/schemas/v1/dct.schema.yaml +10 -0
  437. package/docs/specdojo/schemas/v1/deliverable-frontmatter.schema.yaml +3 -0
  438. package/docs/specdojo/schemas/v1/esil.schema.yaml +7 -141
  439. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +5 -1
  440. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +95 -8
  441. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +38 -0
  442. package/docs/specdojo/schemas/v1/exec-plan-frontmatter.schema.yaml +14 -0
  443. package/docs/specdojo/schemas/v1/exec-result-frontmatter.schema.yaml +18 -0
  444. package/docs/specdojo/schemas/v1/finding-cause.schema.yaml +22 -0
  445. package/docs/specdojo/schemas/v1/grade-pipeline-state.schema.yaml +1 -1
  446. package/docs/specdojo/schemas/v1/grade-result.schema.yaml +2 -0
  447. package/docs/specdojo/schemas/v1/ifx-cmd.schema.yaml +65 -5
  448. package/docs/specdojo/schemas/v1/ifx-index.schema.yaml +142 -0
  449. package/docs/specdojo/schemas/v1/job-run.schema.yaml +23 -0
  450. package/docs/specdojo/schemas/v1/job.schema.yaml +63 -2
  451. package/docs/specdojo/schemas/v1/register-events.schema.yaml +2 -0
  452. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +17 -1
  453. package/docs/specdojo/schemas/v1/sch-strategy.schema.yaml +2 -2
  454. package/package.json +10 -7
  455. package/templates/antigravity/orchestrator.md +7 -3
  456. package/templates/claude/agents/specdojo-orchestrator.md +7 -3
  457. package/templates/codex/agents/specdojo-orchestrator.toml +7 -3
  458. package/templates/codex/orchestrator.md +7 -3
  459. package/templates/devcontainer/tmux.conf +6 -0
  460. package/templates/init-exec-defaults.yaml +13 -0
  461. package/templates/lefthook/tools/specdojo-pre-commit.mjs +8 -0
  462. package/templates/opencode/agents/specdojo-orchestrator.md +8 -4
@@ -0,0 +1,64 @@
1
+ // 個票の「作業内容」の表が実績に合っているかを検査する。close の前に、未着手のまま
2
+ // 理由のない行や `_TODO_` の残った行を見つけ、完了を止める理由として返す。
3
+ const WORK_TABLE_HEADING_RE = /^##\s+(?:\d+\.\s*)?作業内容\s*$/;
4
+ const PLACEHOLDER_CELLS = new Set(["", "-", "_TODO_"]);
5
+ const DONE_STATE = "done";
6
+ function splitTableRow(line) {
7
+ const trimmed = line.trim().replace(/^\|/, "").replace(/\|$/, "");
8
+ // `\|` はセル内の文字であり、列の区切りではない。
9
+ return trimmed.split(/(?<!\\)\|/).map((cell) => cell.trim());
10
+ }
11
+ // インラインコードの `_TODO_` は記法の説明であり、未記入の目印ではない。
12
+ function hasTodoMarker(cell) {
13
+ return cell.replace(/`[^`]*`/g, "").includes("_TODO_");
14
+ }
15
+ function isSeparatorRow(cells) {
16
+ return cells.length > 0 && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
17
+ }
18
+ function workTableLines(content) {
19
+ const body = content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "");
20
+ const lines = body.split(/\r?\n/);
21
+ const heading = lines.findIndex((line) => WORK_TABLE_HEADING_RE.test(line));
22
+ if (heading < 0)
23
+ return [];
24
+ const section = [];
25
+ for (const line of lines.slice(heading + 1)) {
26
+ if (/^##\s+/.test(line))
27
+ break;
28
+ section.push(line);
29
+ }
30
+ const start = section.findIndex((line) => line.trim().startsWith("|"));
31
+ if (start < 0)
32
+ return [];
33
+ const endOffset = section.slice(start).findIndex((line) => !line.trim().startsWith("|"));
34
+ return section.slice(start, endOffset < 0 ? undefined : start + endOffset);
35
+ }
36
+ // 状態が done でない行は、メモに残した理由があれば通す。理由のない行と、どの列であれ
37
+ // `_TODO_` の目印が残る行を問題として返す。表や状態の列がない個票は検査の対象外とする。
38
+ export function registerWorkTableIssues(content) {
39
+ const [header, separator, ...rows] = workTableLines(content).map(splitTableRow);
40
+ if (!header || !separator || !isSeparatorRow(separator))
41
+ return [];
42
+ const stateIndex = header.indexOf("状態");
43
+ if (stateIndex < 0)
44
+ return [];
45
+ const noteIndex = header.indexOf("メモ");
46
+ const numberIndex = header.indexOf("No");
47
+ return rows.flatMap((cells, index) => {
48
+ const label = `row ${numberIndex >= 0 && cells[numberIndex] ? cells[numberIndex] : index + 1}`;
49
+ if (cells.some(hasTodoMarker)) {
50
+ return [`${label} still contains _TODO_`];
51
+ }
52
+ const state = cells[stateIndex] ?? "";
53
+ if (state === DONE_STATE)
54
+ return [];
55
+ const note = noteIndex >= 0 ? (cells[noteIndex] ?? "") : "";
56
+ if (!PLACEHOLDER_CELLS.has(note))
57
+ return [];
58
+ return [`${label} is "${state || "-"}" without a reason in メモ`];
59
+ });
60
+ }
61
+ export function registerWorkTableIssueMessage(id, issues) {
62
+ return (`the 作業内容 table of ${id} does not match the work done: ${issues.join("; ")}. ` +
63
+ `Set each row to done, or write why it remains in メモ.`);
64
+ }
@@ -1,4 +1,5 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { createHash } from "node:crypto";
2
3
  import { existsSync, readFileSync } from "node:fs";
3
4
  import { join } from "node:path";
4
5
  import { gitEnvironment } from "../shared/git-environment.js";
@@ -84,6 +85,9 @@ export function reviewGradeArgs(opts) {
84
85
  const args = [
85
86
  "grade",
86
87
  "run",
88
+ "--isolate-pipeline-state",
89
+ "--if-busy",
90
+ "wait",
87
91
  "--run-id",
88
92
  opts.runId,
89
93
  "--project",
@@ -123,10 +127,16 @@ function lastLine(text) {
123
127
  .filter(Boolean);
124
128
  return lines.at(-1) ?? "";
125
129
  }
130
+ // grade の出力の形式の誤りなど一過性の失敗に備え、review の前の grade は合計この回数まで試す
131
+ // (PJR-M18B)。各試行は別の run id を使い、失敗した試行の状態を引き継がない。
132
+ export const REVIEW_GRADE_MAX_ATTEMPTS = 3;
133
+ export function reviewGradeAttemptRunId(runId, attempt) {
134
+ return attempt <= 1 ? runId : `${runId}-a${attempt}`;
135
+ }
126
136
  /**
127
137
  * Runner-side grade before a review plan is generated. The executor never grades (PJR-2ZVS 3.6).
128
- * Failures are reported in the outcome instead of thrown so the review can still record
129
- * grade-stale / grade-unavailable as its verdict.
138
+ * A failed grade is retried up to maxAttempts times. Failures are reported in the outcome instead
139
+ * of thrown; the runner then blocks the review task instead of completing it (PJR-M18B).
130
140
  */
131
141
  export async function ensureReviewGrade(opts) {
132
142
  const freshness = reviewGradeFreshness({
@@ -135,12 +145,29 @@ export async function ensureReviewGrade(opts) {
135
145
  rootDir: opts.repoRoot,
136
146
  });
137
147
  const decision = decideReviewGradeAction({
138
- freshness,
148
+ freshness: freshness.state === "fresh" && freshness.result.target !== opts.target
149
+ ? { ...freshness, state: "stale" }
150
+ : freshness,
139
151
  dryRun: opts.dryRun,
140
152
  });
141
153
  if (!decision.run)
142
154
  return decision.outcome;
143
- const runId = reviewGradeRunId(opts.taskId, opts.now ?? new Date());
155
+ const subjectKey = createHash("sha256").update(opts.subjectPath).digest("hex").slice(0, 10);
156
+ const baseRunId = reviewGradeRunId(`${opts.taskId}-${subjectKey}`, opts.now ?? new Date());
157
+ const invoke = opts.invoke ?? defaultInvoke;
158
+ const maxAttempts = Math.max(1, Math.floor(opts.maxAttempts ?? REVIEW_GRADE_MAX_ATTEMPTS));
159
+ for (let attempt = 1;; attempt += 1) {
160
+ const runId = reviewGradeAttemptRunId(baseRunId, attempt);
161
+ const detail = await invokeReviewGrade(opts, runId, invoke);
162
+ if (detail === undefined)
163
+ return { action: "executed", runId };
164
+ if (attempt >= maxAttempts)
165
+ return { action: "failed", runId, detail, attempts: attempt };
166
+ process.stderr.write(`[grade] attempt ${attempt}/${maxAttempts} failed; retrying: ${detail}\n`);
167
+ }
168
+ }
169
+ /** Run one grade attempt. Returns undefined on success, or the failure detail. */
170
+ async function invokeReviewGrade(opts, runId, invoke) {
144
171
  const args = reviewGradeArgs({
145
172
  runId,
146
173
  projectId: opts.projectId,
@@ -149,7 +176,6 @@ export async function ensureReviewGrade(opts) {
149
176
  by: opts.by,
150
177
  execDefaultsPath: opts.execDefaultsPath,
151
178
  });
152
- const invoke = opts.invoke ?? defaultInvoke;
153
179
  try {
154
180
  // Resolve the entrypoint from this package, never from the consumer repository.
155
181
  const javascript = fileURLToPath(new URL("../specdojo.js", import.meta.url));
@@ -158,16 +184,12 @@ export async function ensureReviewGrade(opts) {
158
184
  : ["--import", "tsx", fileURLToPath(new URL("../specdojo.ts", import.meta.url))];
159
185
  const { exitCode, stderr } = await invoke(process.execPath, [...entryArgs, ...args], opts.repoRoot);
160
186
  if (exitCode === 0)
161
- return { action: "executed", runId };
187
+ return undefined;
162
188
  const reason = lastLine(stderr);
163
- return {
164
- action: "failed",
165
- runId,
166
- detail: `${opts.subjectPath}: exit ${exitCode}${reason ? `: ${reason}` : ""}`,
167
- };
189
+ return `${opts.subjectPath}: exit ${exitCode}${reason ? `: ${reason}` : ""}`;
168
190
  }
169
191
  catch (error) {
170
- return { action: "failed", runId, detail: `${opts.subjectPath}: ${errorMessage(error)}` };
192
+ return `${opts.subjectPath}: ${errorMessage(error)}`;
171
193
  }
172
194
  }
173
195
  function outcomeLine(outcome) {
@@ -179,7 +201,7 @@ function outcomeLine(outcome) {
179
201
  case "executed":
180
202
  return `- runner の grade 実行: 実行した(run id: \`${outcome.runId}\`)`;
181
203
  case "failed":
182
- return `- runner の grade 実行: 失敗した(run id: \`${outcome.runId}\`; ${outcome.detail})`;
204
+ return `- runner の grade 実行: ${outcome.attempts} 回試して失敗した(最後の run id: \`${outcome.runId}\`; ${outcome.detail})。runner はこの review タスクを完了にせず blocked にする`;
183
205
  case "not-run":
184
206
  return `- runner の grade 実行: 実行していない(${outcome.detail})`;
185
207
  }
@@ -1,6 +1,7 @@
1
1
  import { basename, join, resolve } from "node:path";
2
- import { getProjectRoutinesPath, loadConfig, loadEnv, specdojoRootDir, } from "../shared/specdojo-config.js";
2
+ import { getProjectRoutinesPath, getProjectExecutionPath, loadConfig, loadEnv, specdojoRootDir, } from "../shared/specdojo-config.js";
3
3
  import { listFilesRecursive, readYaml } from "../shared/fs.js";
4
+ import { routineStoragePaths } from "./storage.js";
4
5
  export function routineActionKindLabel(action) {
5
6
  const actions = Array.isArray(action) ? action : [action];
6
7
  return actions.length > 0 ? actions.map((item) => item.kind).join(" -> ") : "-";
@@ -33,6 +34,15 @@ export function isRoutineDue(doc, lastRun, now) {
33
34
  return true;
34
35
  return now.getTime() - last.getTime() >= parseIntervalMs(doc.interval);
35
36
  }
37
+ // state 込みの due 判定。busy skip の流し直し待ち(busy_skip_count が正)の interval routine は
38
+ // interval の経過を待たずに due とする。cron は last_scheduled_for を進めないことで流し直す。
39
+ export function isRoutineEntryDue(doc, entry, now) {
40
+ if (doc.trigger)
41
+ return cronOccurrences(doc, entry?.last_scheduled_for, now).length > 0;
42
+ if ((entry?.busy_skip_count ?? 0) > 0)
43
+ return true;
44
+ return isRoutineDue(doc, entry?.last_run, now);
45
+ }
36
46
  function parseCronField(text, min, max, label) {
37
47
  const result = new Set();
38
48
  for (const token of text.split(",")) {
@@ -359,8 +369,8 @@ export function resolveRoutinePaths(opts) {
359
369
  projectId,
360
370
  routinesPath: absRoutinesPath,
361
371
  generatedPath,
362
- statePath: join(generatedPath, "routine-state.json"),
363
- runsPath: join(generatedPath, "routine-runs.jsonl"),
372
+ ...routineStoragePaths(absRoutinesPath, baseDir),
373
+ failuresPath: resolve(baseDir, getProjectExecutionPath(project), "routines", "failures"),
364
374
  };
365
375
  }
366
376
  export function isRoutineYamlFile(filePath) {
@@ -0,0 +1,30 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { join, relative } from "node:path";
3
+ import { ensureDir, writeJson } from "../shared/fs.js";
4
+ import { gitOutput } from "../shared/git.js";
5
+ import { redactSensitiveText } from "../shared/text.js";
6
+ /** Durable diagnostics only when no Job Run exists to explain a failed routine. */
7
+ export function recordRoutineFailure(repoRoot, failuresPath, entry) {
8
+ if (entry.result !== "failure" || entry.job_run_ids.length > 0)
9
+ return undefined;
10
+ const runId = randomUUID();
11
+ const directory = join(failuresPath, entry.routine_id);
12
+ ensureDir(directory);
13
+ const file = join(directory, `${runId}.json`);
14
+ writeJson(file, {
15
+ ...entry,
16
+ run_id: runId,
17
+ ...(entry.reason ? { reason: redactSensitiveText(entry.reason) } : {}),
18
+ });
19
+ const target = relative(repoRoot, file);
20
+ gitOutput(repoRoot, ["add", "--", target]);
21
+ gitOutput(repoRoot, [
22
+ "commit",
23
+ "--only",
24
+ "-m",
25
+ `chore(routine): record failure ${entry.routine_id}`,
26
+ "--",
27
+ target,
28
+ ]);
29
+ return file;
30
+ }
@@ -1,3 +1,4 @@
1
+ import { registerDeprecatedWhereAlias } from "../shared/where-alias.js";
1
2
  import { spawnSync } from "node:child_process";
2
3
  import { appendFileSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
3
4
  import { join, resolve } from "node:path";
@@ -8,10 +9,13 @@ import { ensureDir, listFilesRecursive, readJson, writeJson } from "../shared/fs
8
9
  import { padEndDisplay } from "../shared/text.js";
9
10
  import { nowUtcIsoSeconds } from "../shared/time.js";
10
11
  import { jobDeclaresReview, jobRunUsesReviewedIntegration, loadJobDefinition, resolveJobPaths, resolveJobReviewAgentNominations, } from "../job/job.js";
11
- import { cronOccurrences, isRecord, isRoutineDue, isRoutineYamlFile, isoWeek, loadRoutines, resolveRoutinePaths, routineActionKindLabel, } from "./definition.js";
12
+ import { cronOccurrences, isRecord, isRoutineEntryDue, isRoutineYamlFile, isoWeek, loadRoutines, resolveRoutinePaths, routineActionKindLabel, } from "./definition.js";
12
13
  import { selfRunArgs } from "../shared/spawn-self.js";
13
14
  import { specdojoRootDir } from "../shared/specdojo-config.js";
14
- export { cronMatches, cronOccurrences, isRoutineDue, isoWeek, loadRoutines, parseCronExpression, parseIntervalMs, parseRoutineDoc, resolveRoutinePaths, routineActionKindLabel, } from "./definition.js";
15
+ import { migrateRoutineStorage } from "./storage.js";
16
+ import { recordRoutineFailure } from "./failure.js";
17
+ import { formatRoutineStatus, readRoutineHistoryLenient } from "./status.js";
18
+ export { cronMatches, cronOccurrences, isRoutineDue, isRoutineEntryDue, isoWeek, loadRoutines, parseCronExpression, parseIntervalMs, parseRoutineDoc, resolveRoutinePaths, routineActionKindLabel, } from "./definition.js";
15
19
  // ================================
16
20
  // State
17
21
  // ================================
@@ -30,7 +34,7 @@ function readRoutineState(statePath) {
30
34
  return { routines: {} };
31
35
  }
32
36
  function writeRoutineState(paths, state) {
33
- ensureDir(paths.generatedPath);
37
+ ensureDir(paths.stateDirectory);
34
38
  writeJson(paths.statePath, state);
35
39
  }
36
40
  export function recordRoutineStart(current, startedAt, scheduledAt) {
@@ -58,6 +62,46 @@ export function recordRoutineCompletion(current, result, reason, actionResults)
58
62
  delete next.last_action_results;
59
63
  return next;
60
64
  }
65
+ // busy skip の回を流し直す上限(同じ routine で続いた回数)。毎時の `routine run --due` で
66
+ // おおよそ 1 日ぶん試し、超えたらその回を済んだ回として扱い、理由を last_reason と履歴に残す。
67
+ export const ROUTINE_BUSY_RETRY_LIMIT = 24;
68
+ /**
69
+ * 完了を記録した state を、skip の内訳に合わせて確定する。別の run の lock による skip(busy)は
70
+ * 済んだ回として扱わず、cron は last_scheduled_for を開始前の値へ戻し、interval は
71
+ * busy_skip_count を正にして次の `routine run --due` で due にする。missed_run が skip の cron、
72
+ * Job の前提条件による skip、skipped 以外の結果は従来どおり済んだ回として扱う。
73
+ */
74
+ export function settleRoutineSkip(doc, previous, completed, result, busySkipped) {
75
+ const entry = { ...completed };
76
+ delete entry.busy_skip_count;
77
+ delete entry.last_skip_reason;
78
+ if (result !== "skipped")
79
+ return { entry, retryPending: false };
80
+ const skipReason = busySkipped ? "busy" : "precondition";
81
+ entry.last_skip_reason = skipReason;
82
+ if (!busySkipped || (doc.trigger && doc.policy?.missed_run === "skip")) {
83
+ return { entry, skipReason, retryPending: false };
84
+ }
85
+ const count = (previous?.busy_skip_count ?? 0) + 1;
86
+ if (count > ROUTINE_BUSY_RETRY_LIMIT) {
87
+ const note = `busy skip retry limit (${ROUTINE_BUSY_RETRY_LIMIT}) reached; occurrence not retried`;
88
+ entry.last_reason = entry.last_reason ? `${entry.last_reason}; ${note}` : note;
89
+ return { entry, skipReason, retryPending: false };
90
+ }
91
+ entry.busy_skip_count = count;
92
+ if (doc.trigger) {
93
+ if (previous?.last_scheduled_for)
94
+ entry.last_scheduled_for = previous.last_scheduled_for;
95
+ else
96
+ delete entry.last_scheduled_for;
97
+ }
98
+ return { entry, skipReason, retryPending: true };
99
+ }
100
+ // exec run / resume が別の run の lock で skip したときの出力(src/exec/run/shared.ts)。
101
+ // Job の前提条件による skip も同じ終了コードを返すため、出力で区別する。
102
+ export function isExecBusySkipOutput(output) {
103
+ return /^\[[a-z-]+\] skipped: exec busy$/m.test(output);
104
+ }
61
105
  export function appendRoutineRunHistory(runsPath, entry) {
62
106
  ensureDir(resolve(runsPath, ".."));
63
107
  appendFileSync(runsPath, `${JSON.stringify(entry)}\n`, "utf8");
@@ -68,8 +112,7 @@ export function appendRoutineRunHistory(runsPath, entry) {
68
112
  const ROUTINE_LOCK_STALE_MS = 60 * 60 * 1000;
69
113
  // routine run の多重起動(外部スケジューラの重複発火)を防ぐ簡易 lock。
70
114
  // 生存中の lock があれば即座に失敗し、stale(1 時間超)な lock は奪う。
71
- function acquireRoutineLock(routinesPath) {
72
- const lockDir = join(routinesPath, ".locks", "routine-run.lock");
115
+ function acquireRoutineLock(lockDir) {
73
116
  ensureDir(resolve(lockDir, ".."));
74
117
  try {
75
118
  mkdirSync(lockDir);
@@ -110,9 +153,16 @@ function ensureFreshDistForRoutineRun() {
110
153
  }
111
154
  let lastRoutineSpawnReason;
112
155
  let lastRoutineSpawnRunId;
113
- function spawnSelf(args) {
156
+ let lastRoutineSpawnNoop = false;
157
+ let lastRoutineSpawnBusy = false;
158
+ function resetRoutineSpawnMarkers() {
114
159
  lastRoutineSpawnReason = undefined;
115
160
  lastRoutineSpawnRunId = undefined;
161
+ lastRoutineSpawnNoop = false;
162
+ lastRoutineSpawnBusy = false;
163
+ }
164
+ function spawnSelf(args) {
165
+ resetRoutineSpawnMarkers();
116
166
  const [exe, fullArgs] = selfRunArgs(args);
117
167
  const result = spawnSync(exe, fullArgs, {
118
168
  encoding: "utf8",
@@ -128,6 +178,7 @@ function spawnSelf(args) {
128
178
  const output = `${result.stdout ?? ""}\n${result.stderr ?? ""}`;
129
179
  const marker = [...output.matchAll(/^\[routine-job\]\s+([^\n]+)$/gm)].at(-1)?.[1];
130
180
  if (marker) {
181
+ lastRoutineSpawnNoop = /\bstate=noop\b/.test(marker);
131
182
  lastRoutineSpawnRunId = marker.match(/\brun_id=([^\s]+)/)?.[1];
132
183
  lastRoutineSpawnReason = marker.match(/\breason=(.+)$/)?.[1]?.trim();
133
184
  }
@@ -138,8 +189,10 @@ function spawnSelf(args) {
138
189
  .filter(Boolean)
139
190
  .at(-1);
140
191
  }
141
- if (result.status === ROUTINE_BUSY_SKIP_EXIT_CODE)
192
+ if (result.status === ROUTINE_BUSY_SKIP_EXIT_CODE) {
193
+ lastRoutineSpawnBusy = isExecBusySkipOutput(output);
142
194
  return "skipped";
195
+ }
143
196
  if (result.status === 0 && marker?.match(/\bstate=([^\s]+)/)?.[1] === "partial") {
144
197
  return "partial";
145
198
  }
@@ -210,8 +263,7 @@ function executeRoutineAction(doc, action, projectId, dryRun, scheduledAt = new
210
263
  ? buildSpecdojoActionArgs(action, projectId)
211
264
  : buildJobRunArgs(action, projectId, scheduledAt, doc.trigger?.timezone ?? "UTC");
212
265
  if (dryRun) {
213
- lastRoutineSpawnReason = undefined;
214
- lastRoutineSpawnRunId = undefined;
266
+ resetRoutineSpawnMarkers();
215
267
  process.stdout.write(` [dry-run] specdojo ${args.join(" ")}\n`);
216
268
  if (action.kind === "job") {
217
269
  try {
@@ -231,7 +283,7 @@ export function buildSpecdojoActionArgs(action, projectId) {
231
283
  return [...action.args, "--project", projectId];
232
284
  }
233
285
  function findJobRunId(action, projectId, scheduledAt) {
234
- if (action.kind !== "job")
286
+ if (action.kind !== "job" || lastRoutineSpawnNoop)
235
287
  return undefined;
236
288
  const runsPath = resolveJobPaths(projectId).runsPath;
237
289
  if (!existsSync(runsPath))
@@ -261,36 +313,42 @@ function executeRoutine(routine, projectId, dryRun, scheduledAt = new Date()) {
261
313
  const actions = Array.isArray(doc.action) ? doc.action : [doc.action];
262
314
  const label = doc.name ?? (actions.length === 1 ? actions[0].kind : `${actions.length} actions`);
263
315
  process.stdout.write(`[routine] ${doc.id}: ${label}\n`);
264
- if (!Array.isArray(doc.action)) {
265
- const result = executeRoutineAction(doc, doc.action, projectId, dryRun, scheduledAt);
266
- const jobRunId = dryRun ? undefined : findJobRunId(doc.action, projectId, scheduledAt);
267
- return {
268
- result,
269
- jobRunIds: lastRoutineSpawnRunId ? [lastRoutineSpawnRunId] : jobRunId ? [jobRunId] : [],
270
- ...(lastRoutineSpawnReason ? { reason: lastRoutineSpawnReason } : {}),
271
- };
272
- }
316
+ const multiple = Array.isArray(doc.action);
317
+ const jobRunIds = [];
318
+ const reasons = [];
319
+ let busySkipped = false;
273
320
  const actionResults = executeRoutineActions(actions, (action, index) => {
274
- process.stdout.write(` action ${index}/${actions.length}: ${action.kind}\n`);
275
- const result = executeRoutineAction(doc, action, projectId, dryRun, scheduledAt);
276
- process.stdout.write(` action ${index}/${actions.length}: ${result}\n`);
321
+ if (multiple)
322
+ process.stdout.write(` action ${index}/${actions.length}: ${action.kind}\n`);
323
+ resetRoutineSpawnMarkers();
324
+ let result;
325
+ try {
326
+ result = executeRoutineAction(doc, action, projectId, dryRun, scheduledAt);
327
+ }
328
+ catch (error) {
329
+ result = "failure";
330
+ lastRoutineSpawnReason = error instanceof Error ? error.message : String(error);
331
+ }
332
+ const runId = lastRoutineSpawnRunId ?? (dryRun ? undefined : findJobRunId(action, projectId, scheduledAt));
333
+ if (runId)
334
+ jobRunIds.push(runId);
335
+ if (lastRoutineSpawnReason)
336
+ reasons.push(lastRoutineSpawnReason);
337
+ if (result === "skipped" && lastRoutineSpawnBusy)
338
+ busySkipped = true;
339
+ if (multiple)
340
+ process.stdout.write(` action ${index}/${actions.length}: ${result}\n`);
277
341
  return result;
278
342
  });
279
343
  const result = aggregateRoutineActionResults(actionResults.map((item) => item.result));
280
- process.stdout.write(` action summary: ${actionResults.map((item) => `${item.index}:${item.result}`).join(", ")} => ${result}\n`);
281
- const jobRunIds = dryRun
282
- ? []
283
- : doc.action.flatMap((action) => {
284
- const runId = findJobRunId(action, projectId, scheduledAt);
285
- return runId ? [runId] : [];
286
- });
344
+ if (multiple)
345
+ process.stdout.write(` action summary: ${actionResults.map((item) => `${item.index}:${item.result}`).join(", ")} => ${result}\n`);
287
346
  return {
288
347
  result,
289
- actionResults,
290
- jobRunIds: [
291
- ...new Set([...(lastRoutineSpawnRunId ? [lastRoutineSpawnRunId] : []), ...jobRunIds]),
292
- ],
293
- ...(lastRoutineSpawnReason ? { reason: lastRoutineSpawnReason } : {}),
348
+ ...(multiple ? { actionResults } : {}),
349
+ jobRunIds: [...new Set(jobRunIds)],
350
+ ...(reasons.length ? { reason: reasons.join("; ") } : {}),
351
+ busySkipped,
294
352
  };
295
353
  }
296
354
  // ================================
@@ -309,29 +367,27 @@ export function formatRoutineLastRun(entry) {
309
367
  return "-";
310
368
  return entry.last_result ? `${entry.last_run} (${entry.last_result})` : entry.last_run;
311
369
  }
370
+ export function printRoutinePaths(opts) {
371
+ try {
372
+ const paths = resolveRoutinePaths(opts);
373
+ process.stdout.write(`project: ${paths.projectId}\n`);
374
+ process.stdout.write(`routines: ${paths.routinesPath}\n`);
375
+ process.stdout.write(`state: ${paths.statePath}\n`);
376
+ process.stdout.write(`runs: ${paths.runsPath}\n`);
377
+ const files = listFilesRecursive(paths.routinesPath).filter(isRoutineYamlFile).sort();
378
+ for (const filePath of files) {
379
+ process.stdout.write(` ${filePath}\n`);
380
+ }
381
+ }
382
+ catch (error) {
383
+ printCommandError(error);
384
+ }
385
+ }
312
386
  export function registerRoutineCommands(program) {
313
387
  const routine = program
314
388
  .command("routine")
315
389
  .description("Periodic task execution from rtn-*.yaml definitions");
316
- // --- where ---
317
- const whereCmd = routine.command("where").description("Print resolved routine paths and files");
318
- addProjectOption(whereCmd);
319
- whereCmd.action((opts) => {
320
- try {
321
- const paths = resolveRoutinePaths(opts);
322
- process.stdout.write(`project: ${paths.projectId}\n`);
323
- process.stdout.write(`routines: ${paths.routinesPath}\n`);
324
- process.stdout.write(`state: ${paths.statePath}\n`);
325
- process.stdout.write(`runs: ${paths.runsPath}\n`);
326
- const files = listFilesRecursive(paths.routinesPath).filter(isRoutineYamlFile).sort();
327
- for (const filePath of files) {
328
- process.stdout.write(` ${filePath}\n`);
329
- }
330
- }
331
- catch (error) {
332
- printCommandError(error);
333
- }
334
- });
390
+ registerDeprecatedWhereAlias(routine, printRoutinePaths);
335
391
  // --- validate ---
336
392
  const validateCmd = routine.command("validate").description("Validate rtn-*.yaml definitions");
337
393
  addProjectOption(validateCmd);
@@ -368,6 +424,7 @@ export function registerRoutineCommands(program) {
368
424
  process.exitCode = 1;
369
425
  return;
370
426
  }
427
+ migrateRoutineStorage(paths.routinesPath);
371
428
  const state = readRoutineState(paths.statePath);
372
429
  const now = new Date();
373
430
  const rows = routines.map(({ doc }) => ({
@@ -376,15 +433,9 @@ export function registerRoutineCommands(program) {
376
433
  interval: doc.interval ?? doc.trigger?.cron ?? "-",
377
434
  kind: routineActionKindLabel(doc.action),
378
435
  lastRun: formatRoutineLastRun(state.routines[doc.id]),
379
- due: doc.enabled === false
380
- ? "-"
381
- : doc.trigger
382
- ? cronOccurrences(doc, state.routines[doc.id]?.last_scheduled_for, now).length > 0
383
- ? "due"
384
- : "-"
385
- : isRoutineDue(doc, state.routines[doc.id]?.last_run, now)
386
- ? "due"
387
- : "-",
436
+ due: doc.enabled !== false && isRoutineEntryDue(doc, state.routines[doc.id], now)
437
+ ? "due"
438
+ : "-",
388
439
  }));
389
440
  const idWidth = Math.max(2, ...rows.map((row) => row.id.length));
390
441
  for (const row of rows) {
@@ -399,6 +450,44 @@ export function registerRoutineCommands(program) {
399
450
  printCommandError(error);
400
451
  }
401
452
  });
453
+ // --- status ---
454
+ const statusCmd = routine
455
+ .command("status")
456
+ .description("Show each routine's state, busy-skip retries, and recent runs");
457
+ addProjectOption(statusCmd);
458
+ statusCmd.option("--id <routineId>", "Show only this routine");
459
+ statusCmd.option("--limit <count>", "Number of recent runs to show per routine", "5");
460
+ statusCmd.action((opts) => {
461
+ try {
462
+ const limit = Number(opts.limit);
463
+ if (!Number.isSafeInteger(limit) || limit < 0) {
464
+ throw new Error(`--limit must be a non-negative integer (got "${String(opts.limit)}")`);
465
+ }
466
+ const paths = resolveRoutinePaths(opts);
467
+ const { routines, errors } = loadRoutines(paths.routinesPath);
468
+ for (const message of errors) {
469
+ process.stderr.write(`ERROR: ${message}\n`);
470
+ }
471
+ if (errors.length > 0)
472
+ process.exitCode = 1;
473
+ const routineId = typeof opts.id === "string" ? opts.id.trim() : "";
474
+ const targets = routineId ? routines.filter((entry) => entry.doc.id === routineId) : routines;
475
+ if (routineId && targets.length === 0) {
476
+ throw new Error(`Routine not found: ${routineId} (in ${paths.routinesPath})`);
477
+ }
478
+ migrateRoutineStorage(paths.routinesPath);
479
+ const state = readRoutineState(paths.statePath);
480
+ const history = readRoutineHistoryLenient(paths.runsPath);
481
+ const now = new Date();
482
+ for (const { doc } of targets) {
483
+ const lines = formatRoutineStatus(doc, state.routines[doc.id], history, now, limit);
484
+ process.stdout.write(`${lines.join("\n")}\n`);
485
+ }
486
+ }
487
+ catch (error) {
488
+ printCommandError(error);
489
+ }
490
+ });
402
491
  // --- run ---
403
492
  const runCmd = routine
404
493
  .command("run")
@@ -423,6 +512,8 @@ export function registerRoutineCommands(program) {
423
512
  }
424
513
  if (errors.length > 0)
425
514
  process.exitCode = 1;
515
+ if (!opts.dryRun)
516
+ migrateRoutineStorage(paths.routinesPath);
426
517
  const state = readRoutineState(paths.statePath);
427
518
  const now = new Date();
428
519
  let selected;
@@ -442,9 +533,7 @@ export function registerRoutineCommands(program) {
442
533
  if (entry.doc.trigger) {
443
534
  return cronOccurrences(entry.doc, stateEntry?.last_scheduled_for, now).map((scheduledAt) => ({ entry, scheduledAt }));
444
535
  }
445
- return isRoutineDue(entry.doc, stateEntry?.last_run, now)
446
- ? [{ entry, scheduledAt: now }]
447
- : [];
536
+ return isRoutineEntryDue(entry.doc, stateEntry, now) ? [{ entry, scheduledAt: now }] : [];
448
537
  });
449
538
  }
450
539
  if (selected.length === 0) {
@@ -457,13 +546,21 @@ export function registerRoutineCommands(program) {
457
546
  process.exitCode = 1;
458
547
  return;
459
548
  }
460
- lockDir = acquireRoutineLock(paths.routinesPath);
549
+ lockDir = acquireRoutineLock(paths.lockPath);
461
550
  }
462
551
  let failed = 0;
463
552
  let partial = 0;
464
553
  let skipped = 0;
554
+ // busy skip した routine の残りの回(missed_run: all)は、この実行では流さない。
555
+ // 後の回だけ進めると last_scheduled_for が skip した回を越え、その回が流し直されなくなる。
556
+ const busyRoutineIds = new Set();
465
557
  for (const selectedRun of selected) {
466
558
  const { entry, scheduledAt } = selectedRun;
559
+ if (busyRoutineIds.has(entry.doc.id)) {
560
+ process.stdout.write(`[routine] deferred ${entry.doc.id} ${scheduledAt.toISOString()}: earlier occurrence skipped as busy\n`);
561
+ continue;
562
+ }
563
+ const previousEntry = state.routines[entry.doc.id];
467
564
  const startedAt = nowUtcIsoSeconds();
468
565
  // 実行の試行自体を last_run として先に記録する。失敗した routine が次の
469
566
  // 発火まで再試行されない代わりに、失敗が高頻度で連続発火することを防ぐ。
@@ -472,7 +569,18 @@ export function registerRoutineCommands(program) {
472
569
  state.routines[entry.doc.id] = recordRoutineStart(state.routines[entry.doc.id], startedAt, entry.doc.trigger ? scheduledAt.toISOString() : undefined);
473
570
  writeRoutineState(paths, state);
474
571
  }
475
- const execution = executeRoutine(entry, paths.projectId, dryRun, scheduledAt);
572
+ let execution;
573
+ try {
574
+ execution = executeRoutine(entry, paths.projectId, dryRun, scheduledAt);
575
+ }
576
+ catch (error) {
577
+ execution = {
578
+ result: "failure",
579
+ jobRunIds: [],
580
+ reason: error instanceof Error ? error.message : String(error),
581
+ busySkipped: false,
582
+ };
583
+ }
476
584
  const { result } = execution;
477
585
  if (result === "failure")
478
586
  failed++;
@@ -483,9 +591,15 @@ export function registerRoutineCommands(program) {
483
591
  process.stdout.write(`[routine] skipped ${entry.doc.id}: job action skipped\n`);
484
592
  }
485
593
  if (!dryRun) {
486
- state.routines[entry.doc.id] = recordRoutineCompletion(state.routines[entry.doc.id], result, execution.reason, execution.actionResults);
594
+ const settlement = settleRoutineSkip(entry.doc, previousEntry, recordRoutineCompletion(state.routines[entry.doc.id], result, execution.reason, execution.actionResults), result, execution.busySkipped);
595
+ state.routines[entry.doc.id] = settlement.entry;
487
596
  writeRoutineState(paths, state);
488
- appendRoutineRunHistory(paths.runsPath, {
597
+ if (settlement.retryPending) {
598
+ busyRoutineIds.add(entry.doc.id);
599
+ process.stdout.write(`[routine] ${entry.doc.id}: busy skip ${settlement.entry.busy_skip_count}/${ROUTINE_BUSY_RETRY_LIMIT}, retried on the next routine run --due\n`);
600
+ }
601
+ const historyReason = settlement.entry.last_reason;
602
+ const history = {
489
603
  version: 1,
490
604
  routine_id: entry.doc.id,
491
605
  scheduled_for: scheduledAt.toISOString(),
@@ -493,8 +607,12 @@ export function registerRoutineCommands(program) {
493
607
  completed_at: nowUtcIsoSeconds(),
494
608
  result,
495
609
  job_run_ids: execution.jobRunIds,
496
- ...(execution.reason ? { reason: execution.reason } : {}),
497
- });
610
+ ...(historyReason ? { reason: historyReason } : {}),
611
+ ...(settlement.skipReason ? { skip_reason: settlement.skipReason } : {}),
612
+ ...(settlement.retryPending ? { retry_pending: true } : {}),
613
+ };
614
+ appendRoutineRunHistory(paths.runsPath, history);
615
+ recordRoutineFailure(specdojoRootDir(), paths.failuresPath, history);
498
616
  }
499
617
  }
500
618
  process.stdout.write(`[routine] ${selected.length} routine(s) processed, ${partial} partial, ${skipped} skipped, ${failed} failed\n`);