specdojo 0.8.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 (284) hide show
  1. package/.github/agents/specdojo-orchestrator.md +4 -1
  2. package/CHANGELOG.md +64 -0
  3. package/dist/catalog/catalog.js +16 -14
  4. package/dist/commands/agent.js +5 -3
  5. package/dist/commands/build.js +69 -10
  6. package/dist/commands/git.js +206 -0
  7. package/dist/commands/init.js +4 -2
  8. package/dist/commands/where.js +25 -0
  9. package/dist/dashboard/dashboard.js +5 -3
  10. package/dist/dashboard/routines.js +4 -7
  11. package/dist/dashboard/timeline.js +14 -14
  12. package/dist/docs/index-command.js +2 -2
  13. package/dist/docs/yaml-business-tables.js +243 -0
  14. package/dist/docs/yaml-interface-tables.js +106 -0
  15. package/dist/docs/yaml-pages-command.js +5 -3
  16. package/dist/docs/yaml-pages.js +146 -3
  17. package/dist/docs/yaml-table-shared.js +70 -0
  18. package/dist/docs/yaml-tables.js +39 -0
  19. package/dist/exec/agent-config.js +9 -0
  20. package/dist/exec/agent-protected-config.js +2 -0
  21. package/dist/exec/commands.js +31 -18
  22. package/dist/exec/events.js +34 -14
  23. package/dist/exec/evidence.js +13 -3
  24. package/dist/exec/parent-validation.js +56 -3
  25. package/dist/exec/plans-core.js +21 -2
  26. package/dist/exec/plans-generation.js +6 -7
  27. package/dist/exec/post-integration.js +162 -0
  28. package/dist/exec/queue-command.js +166 -0
  29. package/dist/exec/queue.js +285 -0
  30. package/dist/exec/register-foreign-wait.js +84 -0
  31. package/dist/exec/repo-integration-sync.js +17 -5
  32. package/dist/exec/reporter.js +2 -2
  33. package/dist/exec/results.js +24 -4
  34. package/dist/exec/review-kata.js +4 -1
  35. package/dist/exec/run/agent-pipeline.js +3 -2
  36. package/dist/exec/run/agent.js +12 -6
  37. package/dist/exec/run/change-scope.js +365 -0
  38. package/dist/exec/run/deferred-cleanup.js +31 -0
  39. package/dist/exec/run/in-place.js +4 -1
  40. package/dist/exec/run/job-lock.js +66 -0
  41. package/dist/exec/run/job-sequence.js +137 -0
  42. package/dist/exec/run/job.js +56 -19
  43. package/dist/exec/run/lifecycle-commands.js +1 -1
  44. package/dist/exec/run/lock.js +22 -1
  45. package/dist/exec/run/register-command.js +8 -5
  46. package/dist/exec/run/register-mode.js +68 -8
  47. package/dist/exec/run/register-resume.js +68 -14
  48. package/dist/exec/run/register-state.js +13 -8
  49. package/dist/exec/run/register-worktree.js +140 -125
  50. package/dist/exec/run/schedule-mode.js +75 -14
  51. package/dist/exec/run/schedule-prepare.js +3 -0
  52. package/dist/exec/run/schedule-task.js +88 -38
  53. package/dist/exec/run/shared.js +5 -0
  54. package/dist/exec/schedule/schedule.js +116 -4
  55. package/dist/exec/shared.js +1 -1
  56. package/dist/exec/smoke.js +190 -0
  57. package/dist/exec/strategy.js +13 -3
  58. package/dist/exec/task-view.js +6 -4
  59. package/dist/exec/trial-commands.js +5 -2
  60. package/dist/exec/trial-core.js +6 -1
  61. package/dist/exec/validation-metrics.js +181 -0
  62. package/dist/exec/worktree-cleanup-lock.js +26 -0
  63. package/dist/exec/worktree-command.js +9 -1
  64. package/dist/exec/worktree-ops-commit.js +2 -2
  65. package/dist/exec/worktree.js +13 -2
  66. package/dist/grade/command-apply.js +3 -3
  67. package/dist/grade/command-inspect.js +5 -3
  68. package/dist/grade/command-plan.js +1 -1
  69. package/dist/grade/command-run.js +5 -1
  70. package/dist/grade/run.js +64 -8
  71. package/dist/job/definition.js +84 -8
  72. package/dist/job/job.js +79 -23
  73. package/dist/register/authoring-sources.js +22 -16
  74. package/dist/register/maintenance-commands.js +2 -2
  75. package/dist/register/register.js +31 -7
  76. package/dist/routine/definition.js +9 -0
  77. package/dist/routine/routine.js +137 -43
  78. package/dist/routine/status.js +62 -0
  79. package/dist/schedule/schedule.js +38 -39
  80. package/dist/shared/agent-types.js +5 -0
  81. package/dist/shared/cross-process-lock.js +9 -1
  82. package/dist/shared/dist-freshness.js +8 -2
  83. package/dist/shared/git-environment.js +2 -1
  84. package/dist/shared/git.js +44 -1
  85. package/dist/shared/lefthook-scaffold.js +3 -0
  86. package/dist/shared/local-config.js +244 -0
  87. package/dist/shared/specdojo-config.js +34 -20
  88. package/dist/shared/specdojo-gitignore.js +1 -0
  89. package/dist/shared/text.js +9 -1
  90. package/dist/shared/where-alias.js +13 -0
  91. package/dist/specdojo.js +4 -0
  92. package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +2 -0
  93. package/docs/ja/specdojo/guides/exec-config-guide.md +23 -4
  94. package/docs/ja/specdojo/guides/exec-operation-guide.md +44 -1
  95. package/docs/ja/specdojo/guides/job-sequence-guide.md +77 -0
  96. package/docs/ja/specdojo/guides/quick-start-guide.md +3 -3
  97. package/docs/ja/specdojo/guides/register-operation-guide.md +1 -1
  98. package/docs/ja/specdojo/guides/routine-operation-guide.md +11 -6
  99. package/docs/ja/specdojo/guides/schedule-design-guide.md +20 -17
  100. package/docs/ja/specdojo/guides/waza-guide.md +12 -8
  101. package/docs/ja/specdojo/recipes/bac-recipe.md +66 -49
  102. package/docs/ja/specdojo/recipes/bes-recipe.md +90 -54
  103. package/docs/ja/specdojo/recipes/bps-recipe.md +88 -139
  104. package/docs/ja/specdojo/recipes/br-recipe.md +40 -47
  105. package/docs/ja/specdojo/recipes/cdfd-overview-recipe.md +97 -109
  106. package/docs/ja/specdojo/recipes/cdfd-recipe.md +85 -146
  107. package/docs/ja/specdojo/recipes/cdfd-uc-recipe.md +91 -110
  108. package/docs/ja/specdojo/recipes/cnd-recipe.md +79 -69
  109. package/docs/ja/specdojo/recipes/cpd-recipe.md +78 -64
  110. package/docs/ja/specdojo/recipes/cxd-recipe.md +92 -75
  111. package/docs/ja/specdojo/recipes/ifd-recipe.md +79 -68
  112. package/docs/ja/specdojo/recipes/ifx-cmd-recipe.md +78 -105
  113. package/docs/ja/specdojo/recipes/ifx-index-recipe.md +105 -71
  114. package/docs/ja/specdojo/recipes/pm-communication-plan-recipe.md +60 -49
  115. package/docs/ja/specdojo/recipes/pm-members-recipe.md +50 -51
  116. package/docs/ja/specdojo/recipes/pm-organization-recipe.md +59 -51
  117. package/docs/ja/specdojo/recipes/pm-plan-recipe.md +69 -56
  118. package/docs/ja/specdojo/recipes/pm-quality-management-plan-recipe.md +37 -56
  119. package/docs/ja/specdojo/recipes/pm-raci-recipe.md +39 -53
  120. package/docs/ja/specdojo/recipes/pm-roles-recipe.md +52 -79
  121. package/docs/ja/specdojo/recipes/prj-assumptions-constraints-dependencies-recipe.md +64 -93
  122. package/docs/ja/specdojo/recipes/prj-charter-recipe.md +71 -106
  123. package/docs/ja/specdojo/recipes/prj-comparison-of-alternatives-recipe.md +78 -157
  124. package/docs/ja/specdojo/recipes/prj-issues-and-approach-recipe.md +62 -111
  125. package/docs/ja/specdojo/recipes/prj-scope-recipe.md +67 -123
  126. package/docs/ja/specdojo/recipes/prj-stakeholder-register-recipe.md +60 -96
  127. package/docs/ja/specdojo/recipes/prj-success-criteria-and-acceptance-criteria-recipe.md +61 -105
  128. package/docs/ja/specdojo/recipes/stsd-recipe.md +79 -109
  129. package/docs/ja/specdojo/recipes/sysd-critical-flows-recipe.md +78 -55
  130. package/docs/ja/specdojo/recipes/sysd-cross-cutting-policy-recipe.md +82 -73
  131. package/docs/ja/specdojo/recipes/sysd-index-recipe.md +78 -59
  132. package/docs/ja/specdojo/recipes/tsd-recipe.md +149 -129
  133. package/docs/ja/specdojo/references/command-reference.md +257 -117
  134. package/docs/ja/specdojo/references/deliverables-reference.md +21 -12
  135. package/docs/ja/specdojo/references/specdojo-config-reference.md +37 -2
  136. package/docs/ja/specdojo/rulebooks/atc-index-rulebook.md +101 -257
  137. package/docs/ja/specdojo/rulebooks/atc-rulebook.md +102 -228
  138. package/docs/ja/specdojo/rulebooks/bac-rulebook.md +19 -28
  139. package/docs/ja/specdojo/rulebooks/bdd-rulebook.md +16 -67
  140. package/docs/ja/specdojo/rulebooks/bds-rulebook.md +30 -51
  141. package/docs/ja/specdojo/rulebooks/bes-index-rulebook.md +41 -61
  142. package/docs/ja/specdojo/rulebooks/bes-rulebook.md +22 -50
  143. package/docs/ja/specdojo/rulebooks/bps-rulebook.md +24 -56
  144. package/docs/ja/specdojo/rulebooks/br-rulebook.md +13 -38
  145. package/docs/ja/specdojo/rulebooks/ccd-mermaid-rulebook.md +41 -76
  146. package/docs/ja/specdojo/rulebooks/cdfd-d2-rulebook.md +18 -93
  147. package/docs/ja/specdojo/rulebooks/cdfd-mermaid-rulebook.md +18 -52
  148. package/docs/ja/specdojo/rulebooks/cdfd-overview-rulebook.md +109 -147
  149. package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +80 -108
  150. package/docs/ja/specdojo/rulebooks/cdfd-uc-rulebook.md +21 -46
  151. package/docs/ja/specdojo/rulebooks/cdr-rulebook.md +144 -0
  152. package/docs/ja/specdojo/rulebooks/cdsd-rulebook.md +27 -48
  153. package/docs/ja/specdojo/rulebooks/cdt-rulebook.md +37 -50
  154. package/docs/ja/specdojo/rulebooks/clis-rulebook.md +52 -69
  155. package/docs/ja/specdojo/rulebooks/cnd-mermaid-rulebook.md +33 -86
  156. package/docs/ja/specdojo/rulebooks/cnd-rulebook.md +16 -32
  157. package/docs/ja/specdojo/rulebooks/cop-index-rulebook.md +45 -131
  158. package/docs/ja/specdojo/rulebooks/cop-rulebook.md +69 -275
  159. package/docs/ja/specdojo/rulebooks/cpd-mermaid-rulebook.md +20 -112
  160. package/docs/ja/specdojo/rulebooks/cpd-rulebook.md +23 -56
  161. package/docs/ja/specdojo/rulebooks/cxd-mermaid-rulebook.md +12 -145
  162. package/docs/ja/specdojo/rulebooks/cxd-rulebook.md +39 -47
  163. package/docs/ja/specdojo/rulebooks/dct-index-rulebook.md +37 -56
  164. package/docs/ja/specdojo/rulebooks/dct-rulebook.md +118 -175
  165. package/docs/ja/specdojo/rulebooks/dec-rulebook.md +5 -14
  166. package/docs/ja/specdojo/rulebooks/dmd-index-rulebook.md +22 -66
  167. package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +36 -94
  168. package/docs/ja/specdojo/rulebooks/dss-rulebook.md +59 -81
  169. package/docs/ja/specdojo/rulebooks/etc-index-rulebook.md +31 -131
  170. package/docs/ja/specdojo/rulebooks/etc-rulebook.md +50 -104
  171. package/docs/ja/specdojo/rulebooks/gl-rulebook.md +51 -61
  172. package/docs/ja/specdojo/rulebooks/ifd-mermaid-rulebook.md +38 -45
  173. package/docs/ja/specdojo/rulebooks/ifx-api-rulebook.md +14 -20
  174. package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +26 -38
  175. package/docs/ja/specdojo/rulebooks/ifx-file-rulebook.md +26 -107
  176. package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +42 -49
  177. package/docs/ja/specdojo/rulebooks/ifx-msg-rulebook.md +14 -22
  178. package/docs/ja/specdojo/rulebooks/imp-business-rulebook.md +21 -44
  179. package/docs/ja/specdojo/rulebooks/imp-data-rulebook.md +41 -64
  180. package/docs/ja/specdojo/rulebooks/imp-interface-rulebook.md +14 -38
  181. package/docs/ja/specdojo/rulebooks/imp-operations-rulebook.md +34 -61
  182. package/docs/ja/specdojo/rulebooks/imp-test-rulebook.md +27 -50
  183. package/docs/ja/specdojo/rulebooks/itc-index-rulebook.md +70 -199
  184. package/docs/ja/specdojo/rulebooks/itc-rulebook.md +65 -153
  185. package/docs/ja/specdojo/rulebooks/mip-index-rulebook.md +74 -150
  186. package/docs/ja/specdojo/rulebooks/mm-rulebook.md +11 -23
  187. package/docs/ja/specdojo/rulebooks/mtp-rulebook.md +99 -176
  188. package/docs/ja/specdojo/rulebooks/nfr-availability-rulebook.md +35 -61
  189. package/docs/ja/specdojo/rulebooks/nfr-index-rulebook.md +75 -117
  190. package/docs/ja/specdojo/rulebooks/nfr-integrity-rulebook.md +31 -60
  191. package/docs/ja/specdojo/rulebooks/nfr-maintainability-rulebook.md +26 -81
  192. package/docs/ja/specdojo/rulebooks/nfr-operations-rulebook.md +32 -70
  193. package/docs/ja/specdojo/rulebooks/nfr-performance-rulebook.md +45 -87
  194. package/docs/ja/specdojo/rulebooks/nfr-reliability-rulebook.md +48 -101
  195. package/docs/ja/specdojo/rulebooks/nfr-security-safety-rulebook.md +44 -80
  196. package/docs/ja/specdojo/rulebooks/nfr-usability-rulebook.md +59 -127
  197. package/docs/ja/specdojo/rulebooks/opd-index-rulebook.md +31 -50
  198. package/docs/ja/specdojo/rulebooks/opd-rulebook.md +42 -109
  199. package/docs/ja/specdojo/rulebooks/opr-index-rulebook.md +29 -42
  200. package/docs/ja/specdojo/rulebooks/opr-rulebook.md +29 -87
  201. package/docs/ja/specdojo/rulebooks/otp-index-rulebook.md +62 -84
  202. package/docs/ja/specdojo/rulebooks/otp-rulebook.md +11 -61
  203. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +91 -106
  204. package/docs/ja/specdojo/rulebooks/pm-change-request-log-rulebook.md +25 -34
  205. package/docs/ja/specdojo/rulebooks/pm-communication-plan-rulebook.md +30 -53
  206. package/docs/ja/specdojo/rulebooks/pm-issue-log-rulebook.md +23 -35
  207. package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +27 -45
  208. package/docs/ja/specdojo/rulebooks/pm-organization-rulebook.md +37 -45
  209. package/docs/ja/specdojo/rulebooks/pm-plan-rulebook.md +45 -46
  210. package/docs/ja/specdojo/rulebooks/pm-quality-management-plan-rulebook.md +37 -48
  211. package/docs/ja/specdojo/rulebooks/pm-raci-rulebook.md +25 -29
  212. package/docs/ja/specdojo/rulebooks/pm-risk-register-rulebook.md +28 -35
  213. package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +36 -41
  214. package/docs/ja/specdojo/rulebooks/pr-rulebook.md +5 -18
  215. package/docs/ja/specdojo/rulebooks/prj-assumptions-constraints-dependencies-rulebook.md +16 -37
  216. package/docs/ja/specdojo/rulebooks/prj-charter-rulebook.md +23 -97
  217. package/docs/ja/specdojo/rulebooks/prj-comparison-of-alternatives-rulebook.md +39 -57
  218. package/docs/ja/specdojo/rulebooks/prj-issues-and-approach-rulebook.md +43 -116
  219. package/docs/ja/specdojo/rulebooks/prj-scope-rulebook.md +16 -51
  220. package/docs/ja/specdojo/rulebooks/prj-stakeholder-register-rulebook.md +47 -92
  221. package/docs/ja/specdojo/rulebooks/prj-success-criteria-and-acceptance-criteria-rulebook.md +25 -84
  222. package/docs/ja/specdojo/rulebooks/sac-rulebook.md +44 -107
  223. package/docs/ja/specdojo/rulebooks/sf-index-rulebook.md +39 -49
  224. package/docs/ja/specdojo/rulebooks/sf-rulebook.md +42 -49
  225. package/docs/ja/specdojo/rulebooks/sld-rulebook.md +64 -89
  226. package/docs/ja/specdojo/rulebooks/stc-index-rulebook.md +90 -189
  227. package/docs/ja/specdojo/rulebooks/stc-rulebook.md +45 -105
  228. package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +6 -12
  229. package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +49 -68
  230. package/docs/ja/specdojo/rulebooks/sysd-critical-flows-rulebook.md +51 -60
  231. package/docs/ja/specdojo/rulebooks/sysd-cross-cutting-policy-rulebook.md +46 -50
  232. package/docs/ja/specdojo/rulebooks/sysd-index-rulebook.md +39 -64
  233. package/docs/ja/specdojo/rulebooks/sysd-rulebook.md +47 -60
  234. package/docs/ja/specdojo/rulebooks/trc-requirements-to-specs-rulebook.md +69 -70
  235. package/docs/ja/specdojo/rulebooks/trc-requirements-to-tests-rulebook.md +65 -72
  236. package/docs/ja/specdojo/rulebooks/tsd-index-rulebook.md +35 -46
  237. package/docs/ja/specdojo/rulebooks/tsd-rulebook.md +49 -66
  238. package/docs/ja/specdojo/rulebooks/tsp-index-rulebook.md +64 -139
  239. package/docs/ja/specdojo/rulebooks/uis-rulebook.md +41 -108
  240. package/docs/ja/specdojo/rulebooks/utc-index-rulebook.md +49 -144
  241. package/docs/ja/specdojo/rulebooks/utc-rulebook.md +67 -155
  242. package/docs/ja/specdojo/samples/bds-sample.md +58 -71
  243. package/docs/ja/specdojo/samples/bes-index-sample.md +20 -37
  244. package/docs/ja/specdojo/samples/bes-sample.md +43 -53
  245. package/docs/ja/specdojo/samples/bps-sample.md +42 -54
  246. package/docs/ja/specdojo/samples/br-sample.md +40 -52
  247. package/docs/ja/specdojo/samples/ccd-sample.md +0 -1
  248. package/docs/ja/specdojo/samples/cdr-sample.md +78 -0
  249. package/docs/ja/specdojo/samples/cdsd-sample.md +47 -63
  250. package/docs/ja/specdojo/samples/clis-sample.md +70 -77
  251. package/docs/ja/specdojo/samples/dec-sample.md +2 -3
  252. package/docs/ja/specdojo/samples/ifx-api-sample.yaml +0 -2
  253. package/docs/ja/specdojo/samples/ifx-msg-sample.yaml +0 -2
  254. package/docs/ja/specdojo/samples/job-sequence.yaml +67 -0
  255. package/docs/ja/specdojo/samples/mip-index-sample.md +98 -20
  256. package/docs/ja/specdojo/samples/pm-communication-plan-sample.md +26 -19
  257. package/docs/ja/specdojo/samples/pm-organization-sample.md +39 -50
  258. package/docs/ja/specdojo/samples/pm-plan-sample.md +61 -67
  259. package/docs/ja/specdojo/samples/pm-quality-management-plan-sample.md +31 -45
  260. package/docs/ja/specdojo/samples/pm-raci-sample.md +31 -37
  261. package/docs/ja/specdojo/samples/prj-assumptions-constraints-dependencies-sample.md +32 -48
  262. package/docs/ja/specdojo/samples/prj-charter-sample.md +42 -59
  263. package/docs/ja/specdojo/samples/prj-comparison-of-alternatives-sample.md +55 -61
  264. package/docs/ja/specdojo/samples/prj-success-criteria-and-acceptance-criteria-sample.md +30 -33
  265. package/docs/ja/specdojo/samples/sf-index-sample.md +13 -55
  266. package/docs/ja/specdojo/samples/sf-sample.md +73 -85
  267. package/docs/ja/specdojo/samples/sld-sample.md +60 -79
  268. package/docs/ja/specdojo/samples/uis-sample.md +98 -121
  269. package/docs/ja/specdojo/standards/job-definition-standard.md +24 -9
  270. package/docs/ja/specdojo/templates/cdr-template.md +58 -0
  271. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +2 -1
  272. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +42 -5
  273. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +35 -0
  274. package/docs/specdojo/schemas/v1/job-run.schema.yaml +23 -0
  275. package/docs/specdojo/schemas/v1/job.schema.yaml +63 -2
  276. package/docs/specdojo/schemas/v1/sch-strategy.schema.yaml +2 -2
  277. package/package.json +9 -6
  278. package/templates/antigravity/orchestrator.md +4 -1
  279. package/templates/claude/agents/specdojo-orchestrator.md +4 -1
  280. package/templates/codex/agents/specdojo-orchestrator.toml +4 -1
  281. package/templates/codex/orchestrator.md +4 -1
  282. package/templates/init-exec-defaults.yaml +13 -0
  283. package/templates/lefthook/tools/specdojo-pre-commit.mjs +8 -0
  284. package/templates/opencode/agents/specdojo-orchestrator.md +5 -2
@@ -2,17 +2,18 @@ import { readPlanFile } from "../../shared/plan-conventions.js";
2
2
  import { spawnSync } from "node:child_process";
3
3
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { relative, resolve, sep } from "node:path";
5
- import { completeJobRun, executeJobCommand, generateJobReviewPlan, isJobCommandTask, jobRunUsesReviewedIntegration, loadJobDefinition, loadJobRunRecord, materializeJobRun, recordJobRunReview, resolveJobPaths, resolveJobReviewAgentNominations, } from "../../job/job.js";
5
+ import { completeJobRun, executeJobCommand, generateJobReviewPlan, isJobCommandTask, jobCommandText, jobRunUsesReviewedIntegration, loadJobDefinition, loadJobRunRecord, materializeJobRun, recordJobRunReview, resolveJobPaths, resolveJobReviewAgentNominations, } from "../../job/job.js";
6
6
  import { selfRunArgs } from "../../shared/spawn-self.js";
7
7
  import { specdojoRootDir } from "../../shared/specdojo-config.js";
8
8
  import { loadExecDefaultsConfig, resolveMemberCommand, } from "../agent-config.js";
9
9
  import { recordCommandEvidence } from "../evidence.js";
10
+ import { runPostIntegration } from "../post-integration.js";
10
11
  import { formatMarkdownFile } from "../format.js";
11
12
  import { createPipelineState, pipelineStateLocation, updatePipelineStage, writePipelineState, } from "../pipeline-state.js";
12
13
  import { activateResolvedProjectPaths, resolveProjectPaths } from "../project.js";
13
14
  import { evidenceForReporter } from "../reporter.js";
14
15
  import { isResultUnfilled, readResultFrontmatterSnapshot, renderReporterResult, scaffoldResult, stripLeadingListMarker, updateResultStatus, } from "../results.js";
15
- import { taskRecordPrefixes } from "../run-records.js";
16
+ import { runLogPath, taskRecordPrefixes } from "../run-records.js";
16
17
  import { mergeWorktreeIntoCurrent, removeWorktree, stabilizeCommitTargets, stageCommitTargets, worktreeStatusPaths, } from "../worktree-ops.js";
17
18
  import { ensureExecWorktree, formatGitResultFailure, gitEnvironment, gitOutput, gitResult, resolveWorktreeBase, summarizeGitHookFailure, } from "../worktree.js";
18
19
  import { runAgentPipeline, runReporterStage } from "./agent-pipeline.js";
@@ -21,6 +22,7 @@ import { resolveInPlaceCommand, spawnAgentInPlace } from "./in-place.js";
21
22
  import { ROUTINE_BUSY_SKIP_EXIT_CODE, ROUTINE_EXEC_ENV } from "./lock.js";
22
23
  import { configuredWorktreeBase, resolveAgentOverride, resolveExecDefaultsPath, selectCandidates, } from "./shared.js";
23
24
  import { localJobNoopPath, snapshotJobOutput } from "../../job/noop.js";
25
+ import { executeJobSequence } from "./job-sequence.js";
24
26
  async function runCommandJobMode(params) {
25
27
  const { opts, record, runPath, planPath, projectId, schedulePath, executionPath } = params;
26
28
  if (!isJobCommandTask(record.task))
@@ -34,7 +36,7 @@ async function runCommandJobMode(params) {
34
36
  const repoRoot = specdojoRootDir();
35
37
  const roster = loadRosterForExecutionPath(executionPath);
36
38
  const execDefaults = loadExecDefaultsConfig(resolveExecDefaultsPath(opts, schedulePath), executionPath);
37
- const analysisNickname = record.task.analysis
39
+ const analysisNickname = record.task.analysis && !opts.sequenceDeferredReason
38
40
  ? opts.reporterBy?.trim() || record.task.analysis.agent
39
41
  : undefined;
40
42
  const analysisResolution = analysisNickname
@@ -58,7 +60,9 @@ async function runCommandJobMode(params) {
58
60
  process.stdout.write(`[dry-run] precondition:\n${record.task.precondition.command}\n`);
59
61
  process.stdout.write(`[dry-run] precondition skip_when: ${record.task.precondition.skip_when}\n`);
60
62
  }
61
- process.stdout.write(`[dry-run] command:\n${record.task.command}\n`);
63
+ process.stdout.write(`[dry-run] command:\n${jobCommandText(record.task)}\n`);
64
+ if (record.task.steps)
65
+ process.stdout.write(`[dry-run] sequence:\n${JSON.stringify(record.task.steps, null, 2)}\n`);
62
66
  if (analysisCandidate) {
63
67
  process.stdout.write(`[dry-run] agent: ${analysisCandidate.actor ?? ""} (analysis reporter)\n`);
64
68
  process.stdout.write(`[dry-run] reporter command: ${analysisCandidate.command}\n`);
@@ -82,7 +86,17 @@ async function runCommandJobMode(params) {
82
86
  });
83
87
  const evidenceRunId = record.run_id;
84
88
  process.stdout.write(`Running Job Run ${record.run_id} command in place.\n`);
85
- const commandOutcome = await executeJobCommand(record.task.command, repoRoot);
89
+ const commandOutcome = record.task.steps
90
+ ? await executeJobSequence({
91
+ task: record.task,
92
+ runId: record.run_id,
93
+ attempt: record.attempts.length,
94
+ runPath,
95
+ cwd: repoRoot,
96
+ executionPath,
97
+ deferredReason: opts.sequenceDeferredReason,
98
+ })
99
+ : await executeJobCommand(record.task.command, repoRoot);
86
100
  const commandPartial = !commandOutcome.error &&
87
101
  record.task.partial_exit_code !== undefined &&
88
102
  commandOutcome.exitCode === record.task.partial_exit_code;
@@ -93,7 +107,7 @@ async function runCommandJobMode(params) {
93
107
  taskId: record.run_id,
94
108
  runId: evidenceRunId,
95
109
  actor: "specdojo-runner",
96
- command: record.task.command,
110
+ command: jobCommandText(record.task),
97
111
  shell: process.platform === "win32" ? process.env.ComSpec || "cmd.exe" : "/bin/sh -eu",
98
112
  startedAt: commandOutcome.startedAt,
99
113
  completedAt: commandOutcome.completedAt,
@@ -118,9 +132,11 @@ async function runCommandJobMode(params) {
118
132
  });
119
133
  const reason = commandAccepted
120
134
  ? undefined
121
- : commandOutcome.error
122
- ? `command spawn failed: ${commandOutcome.error}`
123
- : `command exited with code ${commandOutcome.exitCode ?? "unknown"}`;
135
+ : commandOutcome.reason
136
+ ? commandOutcome.reason
137
+ : commandOutcome.error
138
+ ? `command spawn failed: ${commandOutcome.error}`
139
+ : `command exited with code ${commandOutcome.exitCode ?? "unknown"}`;
124
140
  await renderReporterResult(resultPath, {
125
141
  schema_version: 1,
126
142
  mode: "edit",
@@ -584,12 +600,20 @@ async function runJobWorktreeMode(opts) {
584
600
  process.exitCode = child.status || 1;
585
601
  return;
586
602
  }
603
+ const preIntegrationCommit = gitOutput(repoRoot, ["rev-parse", "HEAD"]).trim();
587
604
  mergeWorktreeIntoCurrent({
588
605
  context: { repoRoot, schedulePath, executionPath },
589
606
  worktree,
590
607
  taskId: reviewTaskId,
591
608
  message: `chore(routine): merge ${record.run_id}`,
592
609
  });
610
+ await runPostIntegration({
611
+ entries: execDefaults.pipeline?.post_integration,
612
+ repoRoot,
613
+ baseCommit: preIntegrationCommit,
614
+ outputCommit: gitOutput(repoRoot, ["rev-parse", "HEAD"]).trim(),
615
+ logPath: runLogPath(resolve(repoRoot, relative(worktree.path, resultPath)), "post-integration.log"),
616
+ });
593
617
  removeWorktree({
594
618
  context: { repoRoot, schedulePath, executionPath },
595
619
  worktree,
@@ -601,7 +625,7 @@ async function runJobWorktreeMode(opts) {
601
625
  async function runJobModeUnchecked(opts, resolvePipelineAgents, isWorktreeChild) {
602
626
  const resolvedPaths = resolveProjectPaths({ project: opts.project });
603
627
  activateResolvedProjectPaths(resolvedPaths);
604
- if (!isWorktreeChild) {
628
+ if (!isWorktreeChild && !opts.sequenceDeferredReason) {
605
629
  // A Job's task.review declaration takes precedence over the caller: it routes the Run
606
630
  // through the reviewed integration path even without --worktree (routine action.commit).
607
631
  const reviewProjectId = resolvedPaths.projectId ?? opts.project ?? process.env.SPECDOJO_PROJECT ?? "";
@@ -627,6 +651,7 @@ async function runJobModeUnchecked(opts, resolvePipelineAgents, isWorktreeChild)
627
651
  scheduledAt: opts.scheduledAt,
628
652
  trigger,
629
653
  dryRun: !!opts.dryRun,
654
+ skipPrecondition: !!opts.sequenceDeferredReason,
630
655
  });
631
656
  const { definition, record, runPath, planPath } = materialized;
632
657
  if (materialized.preconditionSkipped) {
@@ -645,15 +670,26 @@ async function runJobModeUnchecked(opts, resolvePipelineAgents, isWorktreeChild)
645
670
  return;
646
671
  }
647
672
  if (isJobCommandTask(record.task)) {
648
- await runCommandJobMode({
649
- opts,
650
- record,
651
- runPath,
652
- planPath,
653
- projectId,
654
- schedulePath,
655
- executionPath,
656
- });
673
+ try {
674
+ await runCommandJobMode({
675
+ opts,
676
+ record,
677
+ runPath,
678
+ planPath,
679
+ projectId,
680
+ schedulePath,
681
+ executionPath,
682
+ });
683
+ }
684
+ catch (error) {
685
+ completeJobRun({
686
+ projectId,
687
+ runPath,
688
+ status: "failed",
689
+ reason: error instanceof Error ? error.message : String(error),
690
+ });
691
+ throw error;
692
+ }
657
693
  return;
658
694
  }
659
695
  const task = {
@@ -770,6 +806,7 @@ export async function runJobMode(opts, resolvePipelineAgents) {
770
806
  const projectId = paths.projectId ?? opts.project;
771
807
  const definition = loadJobDefinition(resolveJobPaths(projectId), String(opts.job).trim());
772
808
  if (opts.dryRun ||
809
+ opts.sequenceDeferredReason ||
773
810
  jobRunUsesReviewedIntegration(definition, {
774
811
  worktree: opts.worktree,
775
812
  isWorktreeChild,
@@ -65,7 +65,7 @@ export function formatExecSlotsReport(executionPath, execDefaults) {
65
65
  }
66
66
  export function registerSlotsCommand(exec) {
67
67
  const cmd = exec
68
- .command("slots")
68
+ .command("slots", { hidden: true })
69
69
  .description("Show the limits and current usage of the slots shared by concurrent exec runs of a project");
70
70
  cmd.option("--project <projectId>", "Project id in .specdojo/specdojo.config.json");
71
71
  cmd.option("--exec-defaults <path>", "Path to exec-defaults.yaml global config (default: .specdojo/exec-defaults.yaml)");
@@ -17,6 +17,15 @@ export class ExecRunBusyError extends Error {
17
17
  this.name = "ExecRunBusyError";
18
18
  }
19
19
  }
20
+ export class ExecRunLockTimeoutError extends ExecRunBusyError {
21
+ waitTimeoutMs;
22
+ constructor(lockDir, owner, waitTimeoutMs) {
23
+ super(lockDir, owner);
24
+ this.waitTimeoutMs = waitTimeoutMs;
25
+ this.name = "ExecRunLockTimeoutError";
26
+ this.message = `Exec lock wait timed out after ${waitTimeoutMs} ms.\n${this.message}`;
27
+ }
28
+ }
20
29
  export function execLocksDir(executionPath) {
21
30
  return join(executionPath, "exec", ".locks");
22
31
  }
@@ -81,7 +90,16 @@ export async function acquireExecRunLock(executionPath, opts) {
81
90
  const staleMs = opts.staleMs ?? EXEC_RUN_LOCK_STALE_MS;
82
91
  const pollMs = opts.pollMs ?? LOCK_POLL_MS;
83
92
  let waitingAnnounced = false;
93
+ if (opts.waitTimeoutMs !== undefined &&
94
+ (!Number.isFinite(opts.waitTimeoutMs) || opts.waitTimeoutMs < 0))
95
+ throw new Error("waitTimeoutMs must be a finite non-negative number");
96
+ const deadline = opts.waitTimeoutMs === undefined ? Infinity : Date.now() + opts.waitTimeoutMs;
97
+ let firstAttempt = true;
84
98
  while (true) {
99
+ if (!firstAttempt && opts.ifBusy === "wait" && Date.now() >= deadline) {
100
+ throw new ExecRunLockTimeoutError(execRunLockPath(executionPath), describeHolders(executionPath, staleMs), opts.waitTimeoutMs);
101
+ }
102
+ firstAttempt = false;
85
103
  const handle = opts.join
86
104
  ? tryAcquireJoin(executionPath, opts, opts.join.limit, staleMs)
87
105
  : tryAcquireExclusive(executionPath, opts, staleMs);
@@ -96,7 +114,10 @@ export async function acquireExecRunLock(executionPath, opts) {
96
114
  opts.onWait?.();
97
115
  waitingAnnounced = true;
98
116
  }
99
- await delay(pollMs);
117
+ if (Date.now() >= deadline) {
118
+ throw new ExecRunLockTimeoutError(execRunLockPath(executionPath), describeHolders(executionPath, staleMs), opts.waitTimeoutMs);
119
+ }
120
+ await delay(Math.min(pollMs, Math.max(0, deadline - Date.now())));
100
121
  }
101
122
  }
102
123
  export function releaseExecRunLock(handle) {
@@ -4,13 +4,14 @@ import { resolveProjectPaths } from "../project.js";
4
4
  import { isRegisterFailureMode } from "../register.js";
5
5
  import { configuredProductRepos } from "../task-repos.js";
6
6
  import { runInPlaceMode } from "./in-place.js";
7
- import { runJobMode } from "./job.js";
7
+ import { runJobWithProjectLock } from "./job-lock.js";
8
8
  import { spawnRefresh, spawnValidate } from "./mode-shared.js";
9
9
  import { resolveRegisterPipelineCommand } from "./register-core.js";
10
10
  import { runRegisterMode } from "./register-mode.js";
11
11
  import { runBatchMode, runManualMode } from "./schedule-mode.js";
12
12
  import { EXCLUSIVE_EXEC_RUN, parseParallel, resolveExecDefaultsPath, resolveRegisterWorktree, withProjectExecRunLock, } from "./shared.js";
13
13
  import { withTrailingRunRecords } from "./trailing-records.js";
14
+ import { parseUnknownScopePolicy } from "./change-scope.js";
14
15
  export function registerRunCommand(exec) {
15
16
  const rcmd = exec
16
17
  .command("run")
@@ -45,6 +46,7 @@ export function registerRunCommand(exec) {
45
46
  rcmd.option("--integration-branch <repo=branch>", "With register worktree mode: integrate the declared product repository <repo> into the local branch <branch> for this run (repeatable; overrides repos[].integration_branch; resume reuses the value recorded at the start)", (value, previous = []) => [...previous, value]);
46
47
  rcmd.option("--branch <repo=name>", "With register worktree mode: override a declared product work branch (repeatable; resume keeps the recorded branch)", (value, previous = []) => [...previous, value]);
47
48
  rcmd.option("--parallel <n>", "Number of worktree instances to run in parallel", "1");
49
+ rcmd.option("--unknown-scope <policy>", "Items with an unknown change scope: parallel|serialize (default: parallel)");
48
50
  rcmd.option("--worktree-base <path>", "Override worktree base directory");
49
51
  rcmd.option("--strategy <s>", "Task selection strategy: critical-first|fifo (default: critical-first)");
50
52
  rcmd.option("--loop", "Repeat rounds until no ready tasks remain, rebuilding doc-index and running exec refresh between rounds", false);
@@ -63,6 +65,7 @@ export function registerRunCommand(exec) {
63
65
  rcmd.option("--dry-run", "Print resolved command without executing", false);
64
66
  rcmd.action(async (opts) => {
65
67
  try {
68
+ parseUnknownScopePolicy(opts.unknownScope);
66
69
  const isAuto = !!opts.auto;
67
70
  const hasTask = !!opts.task;
68
71
  const hasDeliverable = !!opts.deliverable;
@@ -246,6 +249,10 @@ export function registerRunCommand(exec) {
246
249
  }
247
250
  // register worktree 実行だけが共有資源をプロセス横断で統制するため、後から --join する
248
251
  // run を受け入れる。それ以外の run は従来どおり project 全体を排他する。
252
+ if (hasJob) {
253
+ await runJobWithProjectLock(opts, resolveRegisterPipelineCommand);
254
+ return;
255
+ }
249
256
  const registerWorktreeLockSharing = hasRegister && opts.worktree ? { shareable: true, join: !!opts.join } : EXCLUSIVE_EXEC_RUN;
250
257
  await withProjectExecRunLock(opts, "run", async () => {
251
258
  // Register-item run: use the configured location or an explicit CLI override, with state tracked
@@ -254,10 +261,6 @@ export function registerRunCommand(exec) {
254
261
  await runRegisterMode(opts);
255
262
  return;
256
263
  }
257
- if (hasJob) {
258
- await runJobMode(opts, resolveRegisterPipelineCommand);
259
- return;
260
- }
261
264
  // In-place manual run (default): generate the plan on demand and run in the
262
265
  // current repository. No validate/refresh pass — that is orchestration only.
263
266
  if (isManual && !opts.worktree) {
@@ -1,22 +1,24 @@
1
1
  import { registerDependencyBlockReason } from "../../register/dependency.js";
2
+ import { existsSync, readFileSync } from "node:fs";
2
3
  import { loadRegisterItems, resolveRegisterPaths } from "../../register/register.js";
3
4
  import { specdojoRootDir } from "../../shared/specdojo-config.js";
4
5
  import { loadExecDefaultsConfig, ProviderConcurrencyGate } from "../agent-config.js";
5
6
  import { buildInPlaceStem } from "../plans.js";
6
7
  import { activateResolvedProjectPaths, resolveProjectPaths } from "../project.js";
7
8
  import { findResumableRegisterRun } from "../register-resume.js";
8
- import { formatRegisterRunSummary, parseRegisterIds, parseRegisterSelectionFilter, registerRunExitCode, requireRunnableRegisterItem, resolveRegisterRunTarget, selectRegisterItems, } from "../register.js";
9
- import { taskRecordPaths } from "../run-records.js";
9
+ import { formatRegisterRunSummary, parseRegisterIds, parseRegisterSelectionFilter, registerRunExitCode, requireRunnableRegisterItem, resolveRegisterRunTarget, selectRegisterItems, ticketPathFromItem, } from "../register.js";
10
+ import { findRunRecord, taskRecordPaths } from "../run-records.js";
10
11
  import { qualifyTaskId } from "../shared.js";
11
12
  import { CrossProcessMutex } from "../slot-lock.js";
12
13
  import { findExecWorktree, resolveWorktreeBase } from "../worktree.js";
13
14
  import { loadRosterForExecutionPath } from "./agent.js";
14
15
  import { execLifecyclePoolPath, execLocksDir } from "./lock.js";
16
+ import { ChangeScopeGate, inferChangeScope, parseUnknownScopePolicy, scopePlanMetadata, } from "./change-scope.js";
15
17
  import { applyRegisterDifficultyRouting, isRegisterPipelineRequested, parseRegisterExecutorSelection, resolveRegisterCommand, resolveRegisterPipelineCommand, runSingleRegisterItem, selectedRegisterExecutor, } from "./register-core.js";
16
18
  import { resolveRegisterPostReviewAgents } from "./register-post-review.js";
17
19
  import { resumeSingleRegisterItemWorktree } from "./register-resume.js";
18
20
  import { runSingleRegisterItemWorktree } from "./register-worktree.js";
19
- import { configuredWorktreeBase, parseParallel, resolveExecDefaultsPath, runCompletionDrivenWorkerPool, } from "./shared.js";
21
+ import { configuredWorktreeBase, parseParallel, resolveExecDefaultsPath, resolvePinnedRateLimitRunOptions, runCompletionDrivenWorkerPool, } from "./shared.js";
20
22
  // register 項目の実行(複数ID)。in-place モードは指定順に1件ずつ直列実行し、各IDが plan/result
21
23
  // 生成・start・agent実行・review/waiting 遷移まで完結してから次へ進む。worktree モードは成果物を
22
24
  // worktree に隔離し、状態遷移を root で直列化する(--parallel で並列化可能)。失敗時は
@@ -92,8 +94,8 @@ export async function runRegisterMode(opts) {
92
94
  }
93
95
  : routed;
94
96
  };
95
- // Validate the effective per-item selection before creating worktrees or changing register
96
- // state. A route may supply the counterpart of one explicitly overridden stage.
97
+ // Validate every item's effective stages and recovery before creating any worktree or changing
98
+ // register state. CLI overrides can make a routed fallback identical to the primary agent.
97
99
  if (!opts.resume) {
98
100
  for (const pjrId of ids) {
99
101
  const itemOpts = optsForItem(pjrId);
@@ -101,6 +103,15 @@ export async function runRegisterMode(opts) {
101
103
  (!itemOpts.executorBy && itemOpts.reporterBy)) {
102
104
  throw new Error("--register pipeline execution requires both --executor-by and --reporter-by, either explicitly or from the item's difficulty route.");
103
105
  }
106
+ if (itemOpts.executorBy || itemOpts.reporterBy) {
107
+ const agents = resolveRegisterPipelineCommand(roster, itemOpts, execDefaults);
108
+ if (itemOpts.executorBy) {
109
+ resolvePinnedRateLimitRunOptions(itemOpts, execDefaults, roster, "executor", agents.executor);
110
+ }
111
+ if (itemOpts.reporterBy) {
112
+ resolvePinnedRateLimitRunOptions(itemOpts, execDefaults, roster, "reporter", agents.reporterCandidates[0]);
113
+ }
114
+ }
104
115
  }
105
116
  }
106
117
  const useWorktree = !!opts.worktree;
@@ -196,9 +207,58 @@ export async function runRegisterMode(opts) {
196
207
  const summaries = [];
197
208
  // 再開は既存 worktree の reporter 段だけを実行する。それ以外の経路(plan 生成・executor 実行)
198
209
  // は通らないため、通常実行と同じ並列・直列の枠だけを共有する。
199
- const runItem = (pjrId, lifecycleLock) => opts.resume
200
- ? resumeSingleRegisterItemWorktree(context, optsForItem(pjrId), pjrId, lifecycleLock)
201
- : runSingleRegisterItemWorktree(context, optsForItem(pjrId), pjrId, lifecycleLock);
210
+ const scopeGate = new ChangeScopeGate(executionPath, parseUnknownScopePolicy(opts.unknownScope));
211
+ const runItem = async (pjrId, lifecycleLock) => {
212
+ const { item, registerPaths: paths } = resolveRegisterRunTarget(projectId, pjrId);
213
+ const ticket = ticketPathFromItem(item, paths.projectRegisterPath);
214
+ const planPath = findRunRecord(executionPath, "plan", pjrId);
215
+ const plan = planPath && existsSync(planPath) ? readFileSync(planPath, "utf8") : "";
216
+ const metadata = scopePlanMetadata(plan);
217
+ const scope = inferChangeScope({
218
+ targets: [...new Set([...(item.targets ?? []), ...(metadata.targets ?? [])])],
219
+ approach: item.approach ?? metadata.approach,
220
+ targetPath: item.targetPath,
221
+ text: [ticket && existsSync(ticket) ? readFileSync(ticket, "utf8") : "", plan],
222
+ projectId,
223
+ repoRoot,
224
+ catalogPath: context.catalogPath,
225
+ schedulePath,
226
+ });
227
+ let lease;
228
+ let integrated = false;
229
+ try {
230
+ // Wait outside the lifecycle lock: its holder must be able to integrate and release us.
231
+ lease = await scopeGate.acquire(pjrId, scope);
232
+ const itemOpts = {
233
+ ...optsForItem(pjrId),
234
+ changeScopeWaits: lease.waits,
235
+ onScopeIntegrated: async () => {
236
+ integrated = true;
237
+ await lease?.finish(true);
238
+ },
239
+ };
240
+ const summary = opts.resume
241
+ ? await resumeSingleRegisterItemWorktree(context, itemOpts, pjrId, lifecycleLock)
242
+ : await runSingleRegisterItemWorktree(context, itemOpts, pjrId, lifecycleLock);
243
+ integrated ||= summary.outcome === "success";
244
+ return summary;
245
+ }
246
+ catch (error) {
247
+ const reason = error instanceof Error ? error.message : String(error);
248
+ process.stderr.write(`${reason}\n`);
249
+ return {
250
+ id: pjrId,
251
+ title: item.title,
252
+ outcome: "failure",
253
+ transition: "none",
254
+ commit: "off",
255
+ reason,
256
+ };
257
+ }
258
+ finally {
259
+ await lease?.finish(integrated);
260
+ }
261
+ };
202
262
  // worktree 実行の root 側の手順(start 遷移・checkpoint・merge・wait commit・派生ビューの
203
263
  // 再生成)は、同じ project の別プロセス(--join run)とも重ならないよう、ロックディレクトリの
204
264
  // mutex で直列化する。一方の run が root に記帳ファイルを書いている途中で、もう一方の統合が
@@ -7,6 +7,7 @@ import { loadConfig } from "../../shared/specdojo-config.js";
7
7
  import { failedParentValidationReason } from "../parent-validation.js";
8
8
  import { integratedRepoNames } from "../pipeline-state.js";
9
9
  import { resolveProductBranches } from "../product-branches.js";
10
+ import { adoptForeignWaitRecords, countForeignCommits, findForeignWaitRecords, } from "../register-foreign-wait.js";
10
11
  import { findResumableRegisterRun, resolveRegisterResumeArtifacts, } from "../register-resume.js";
11
12
  import { requireRunnableRegisterItem, resolveRegisterRunTarget, sanitizeRegisterConclusion, ticketPathFromItem, } from "../register.js";
12
13
  import { syncTaskWorktreesWithIntegrationTargets, } from "../repo-integration.js";
@@ -19,8 +20,9 @@ import { refreshParentValidationsForReporterResume, runAgentPipeline, runReporte
19
20
  import { expandPromptRefs } from "./agent.js";
20
21
  import { repoRelativePath } from "./mode-shared.js";
21
22
  import { registerReporterManagedPaths, spawnRegisterTransition, } from "./register-core.js";
22
- import { copyRepoPaths, rebuildRootRegisterViews, registerBookkeepingPaths, registerTransitionPaths, } from "./register-state.js";
23
+ import { copyRepoPaths, overlayRegisterTicketLifecycle, rebuildRootRegisterViews, registerBookkeepingPaths, registerTransitionPaths, } from "./register-state.js";
23
24
  import { finalizeRegisterWorktreeRun } from "./register-worktree.js";
25
+ import { isWorktreeCleanupInProgress, worktreeCleanupInProgressReason, } from "../worktree-cleanup-lock.js";
24
26
  import { rateLimitRecoveryReason, resolveAgentOverride, resolvePinnedRateLimitRunOptions, } from "./shared.js";
25
27
  // reporter 再開に使う agent を解決する。--reporter-by を優先し、省略時は再開対象 run の
26
28
  // pipeline-state に記録された reporter actor(通常は前回と同じ agent)へフォールバックする。
@@ -80,6 +82,21 @@ export function resolveRegisterResumeExecutor(roster, opts, execDefaults, record
80
82
  },
81
83
  };
82
84
  }
85
+ // PJR-EWZG: 再開の前の同期で、項目自身の記帳ファイルの競合は統合先(waiting の記録)を採る。
86
+ // ただし個票は、wait の commit が結果なしでやり直されたり失敗したりして統合先に executor の
87
+ // 本文が無い場合も、exec branch の本文(executor が書いた対応結果など)を保ち、frontmatter の
88
+ // 状態の欄だけを統合先に揃える。
89
+ export function registerResumeConflictPaths(repoRoot, bookkeepingPaths, ticketRelPath) {
90
+ const relPaths = bookkeepingPaths.map((path) => repoRelativePath(repoRoot, path));
91
+ const projectResolvedPaths = new Map();
92
+ if (ticketRelPath) {
93
+ projectResolvedPaths.set(ticketRelPath, (execContent, targetContent) => overlayRegisterTicketLifecycle(execContent, targetContent, ticketRelPath));
94
+ }
95
+ return {
96
+ projectTheirsPaths: relPaths.filter((path) => path !== ticketRelPath),
97
+ projectResolvedPaths,
98
+ };
99
+ }
83
100
  // 統合段だけの再開。executor と reporter が成功済みで、commit → merge → worktree 撤去のいずれかが
84
101
  // 失敗した run を、agent を1つも起動せずに統合からやり直す。worktree の成果物と evidence をそのまま
85
102
  // 使い、成功なら通常実行と同じ review 遷移、merge 前の失敗なら waiting へ戻す。すでに merge
@@ -122,7 +139,7 @@ export async function resumeRegisterIntegration(params) {
122
139
  // reporter が記入済みの result をそのまま使う。agent は起動しないため、成果は success 扱いで
123
140
  // 統合だけを実行する(result が未記入なら finalize 側の downgrade が blocked に落とす)。
124
141
  const resultScaffold = readResultFrontmatterSnapshot(worktreeResultPath);
125
- const finalize = async () => finalizeRegisterWorktreeRun({
142
+ return finalizeRegisterWorktreeRun({
126
143
  context: params.context,
127
144
  opts: params.opts,
128
145
  registerPaths: params.registerPaths,
@@ -136,11 +153,11 @@ export async function resumeRegisterIntegration(params) {
136
153
  stderr: validationFailure ?? "",
137
154
  ...(validationFailure ? { runnerBlockReason: validationFailure } : {}),
138
155
  actor,
139
- bookkeepingPaths: params.bookkeepingPaths(),
156
+ bookkeepingPaths: params.bookkeepingPaths,
140
157
  pipelineStatePath: target.statePath,
141
158
  resumedIntegration: true,
159
+ lifecycleLock: params.lifecycleLock,
142
160
  });
143
- return params.lifecycleLock ? params.lifecycleLock.runExclusive(finalize) : finalize();
144
161
  }
145
162
  // register 項目1件の再開。途中で止まった run を、既存 worktree と evidence を保持したまま
146
163
  // 止まった段からやり直す。running のまま残った executor は同じ plan/result と worktree 上で
@@ -181,6 +198,10 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
181
198
  if (!foundWorktree) {
182
199
  return refuse(`no exec worktree to resume for ${item.id}; run the item again instead`);
183
200
  }
201
+ // 前の統合の後の撤去がロックの外で進んでいる間は、同じ worktree を再開しない(PJR-NHT7)。
202
+ if (isWorktreeCleanupInProgress(executionPath, worktreeTaskId)) {
203
+ return refuse(worktreeCleanupInProgressReason(worktreeTaskId));
204
+ }
184
205
  const lookup = findResumableRegisterRun({
185
206
  repoRoot,
186
207
  worktreePath: foundWorktree.path,
@@ -219,6 +240,35 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
219
240
  return refuse(`product worktrees are missing for ${item.id}: ${missingProducts.join(", ")}; ` +
220
241
  `run the item again instead`);
221
242
  }
243
+ // PJR-97KE: job の worktree の中で止まった子の run は、wait の記録が job の branch にしかない。
244
+ // 本体から再開する場合は、register の遷移と agent の起動より前に、その記録を本体へ取り込む。
245
+ const foreignWait = findForeignWaitRecords({ repoRoot, worktree, itemId: item.id });
246
+ if (foreignWait) {
247
+ const adopt = () => {
248
+ try {
249
+ const count = countForeignCommits(repoRoot, foreignWait);
250
+ adoptForeignWaitRecords({
251
+ repoRoot,
252
+ schedulePath,
253
+ itemId: item.id,
254
+ records: foreignWait,
255
+ });
256
+ process.stdout.write(` [resume] merged the wait records of ${item.id} from ${foreignWait.target} ` +
257
+ `(${foreignWait.commit.slice(0, 12)}, ${count} commit(s) not yet in ${currentBranch(repoRoot)})\n`);
258
+ rebuildRootRegisterViews(projectId, item.id);
259
+ return null;
260
+ }
261
+ catch (error) {
262
+ return (`cannot bring the wait records of run ${target.runId} from ${foreignWait.target} ` +
263
+ `into the current branch: ${error instanceof Error ? error.message : String(error)}; ` +
264
+ `resolve it and resume again, resume inside the worktree of ${foreignWait.target}, ` +
265
+ `or discard the run with --force-restart (without --resume)`);
266
+ }
267
+ };
268
+ const adoptFailure = lifecycleLock ? await lifecycleLock.runExclusive(adopt) : adopt();
269
+ if (adoptFailure)
270
+ return refuse(adoptFailure);
271
+ }
222
272
  const artifacts = resolveRegisterResumeArtifacts({
223
273
  repoRoot,
224
274
  worktreePath: worktree.path,
@@ -227,10 +277,12 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
227
277
  state: target.state,
228
278
  });
229
279
  if (!artifacts)
230
- return refuse(`cannot restore the plan/result of run ${target.runId}`);
280
+ return refuse(`cannot restore the plan/result of run ${target.runId}; ` +
281
+ `discard the run with --force-restart (without --resume)`);
231
282
  const worktreeResultPath = resolve(worktree.path, artifacts.resultRef);
232
283
  if (!existsSync(worktreeResultPath)) {
233
- return refuse(`result not found in the worktree: ${artifacts.resultRef}`);
284
+ return refuse(`result not found in the worktree: ${artifacts.resultRef}; ` +
285
+ `discard the run with --force-restart (without --resume)`);
234
286
  }
235
287
  // root 側の実行管理ファイル。plan / result は前回の wait commit で統合ブランチに入っている。
236
288
  // begin は個票と event を root へ写し、派生ビューを再生成する。その後の差分を拾うため、
@@ -289,7 +341,7 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
289
341
  worktree,
290
342
  projectTarget,
291
343
  message: `exec(register ${item.id}): merge integration target before resume`,
292
- projectTheirsPaths: bookkeepingPaths().map((path) => repoRelativePath(repoRoot, path)),
344
+ ...registerResumeConflictPaths(repoRoot, bookkeepingPaths(), ticketPath ? repoRelativePath(repoRoot, ticketPath) : null),
293
345
  integratedProducts: integratedRepoNames(target.state),
294
346
  });
295
347
  }
@@ -339,7 +391,9 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
339
391
  const worktreePlanPath = resolve(worktree.path, artifacts.planRef);
340
392
  const promptPlanPath = target.stage === "executor" && existsSync(worktreePlanPath) ? worktreePlanPath : planPath;
341
393
  if (!existsSync(promptPlanPath))
342
- return refuse(`plan not found for the resumed run: ${artifacts.planRef}`);
394
+ return refuse(`plan not found for the resumed run: ${artifacts.planRef}; merge the branch that holds ` +
395
+ `the wait commit of run ${target.runId} into ${currentBranch(repoRoot)} and resume again, ` +
396
+ `or discard the run with --force-restart (without --resume)`);
343
397
  const prompt = expandPromptRefs(readPlanFile(promptPlanPath));
344
398
  if (target.stage === "executor") {
345
399
  const executor = resolveRegisterResumeExecutor(context.roster, opts, context.execDefaults, target.state.stages.executor.actor);
@@ -379,7 +433,7 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
379
433
  executorRateLimitOptions: resolvePinnedRateLimitRunOptions(opts, context.execDefaults, context.roster, "executor", executor.candidate),
380
434
  reporterRateLimitOptions: resolvePinnedRateLimitRunOptions(opts, context.execDefaults, context.roster, "reporter", reporter.candidate),
381
435
  });
382
- const finalize = async () => finalizeRegisterWorktreeRun({
436
+ return finalizeRegisterWorktreeRun({
383
437
  context,
384
438
  opts,
385
439
  registerPaths,
@@ -393,12 +447,12 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
393
447
  stderr: outcome.blockReason ?? "",
394
448
  runnerBlockReason: outcome.blockReason,
395
449
  actor: executor.candidate.actor,
396
- bookkeepingPaths: bookkeepingPaths(),
450
+ bookkeepingPaths,
397
451
  pipelineStatePath: resolve(worktree.path, outcome.stateRef),
398
452
  transitionReason: rateLimitRecoveryReason(outcome.rateLimitEvents) || undefined,
399
453
  resumedExecutor: true,
454
+ lifecycleLock,
400
455
  });
401
- return lifecycleLock ? lifecycleLock.runExclusive(finalize) : finalize();
402
456
  }
403
457
  const reporter = resolveRegisterResumeReporter(context.roster, opts, context.execDefaults, target.state.stages.reporter.actor);
404
458
  if (reporter.kind === "error")
@@ -437,7 +491,7 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
437
491
  rateLimitOptions: resolvePinnedRateLimitRunOptions(opts, context.execDefaults, context.roster, "reporter", reporter.candidate),
438
492
  productWorktrees: worktree.repos,
439
493
  });
440
- const finalize = async () => finalizeRegisterWorktreeRun({
494
+ return finalizeRegisterWorktreeRun({
441
495
  context,
442
496
  opts,
443
497
  registerPaths,
@@ -450,9 +504,9 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
450
504
  agentResult: outcome.runResult,
451
505
  stderr: outcome.blockReason ?? "",
452
506
  actor: reporter.candidate.actor,
453
- bookkeepingPaths: bookkeepingPaths(),
507
+ bookkeepingPaths,
454
508
  pipelineStatePath: target.statePath,
455
509
  transitionReason: rateLimitRecoveryReason(outcome.state.stages.reporter.rate_limit_events ?? []) || undefined,
510
+ lifecycleLock,
456
511
  });
457
- return lifecycleLock ? lifecycleLock.runExclusive(finalize) : finalize();
458
512
  }
@@ -106,6 +106,18 @@ export function registerFailureArtifactPaths(repoRoot, paths) {
106
106
  return paths.filter((path) => /(?:^|\/)exec\/(?:plans|results)\//.test(repoRelativePath(repoRoot, path)) ||
107
107
  isRunRecordPath(path));
108
108
  }
109
+ // 個票の本文(executor が書いた対応結果など)は bodyContent を保ち、frontmatter の状態の欄
110
+ // (登録簿の項目の欄と block_reason)だけを lifecycleContent の値へ揃える。lifecycleContent を
111
+ // 解析できない場合は例外を投げる。
112
+ export function overlayRegisterTicketLifecycle(bodyContent, lifecycleContent, ticketRelPath) {
113
+ const parsed = readRegisterItemContent(lifecycleContent, basename(ticketRelPath));
114
+ if (!parsed)
115
+ throw new Error(`could not parse register item: ${ticketRelPath}`);
116
+ return applyRegisterItemFields(bodyContent, {
117
+ ...registerItemFieldsFromItem(parsed.item),
118
+ block_reason: parsed.blockReason === CELL_NONE ? null : parsed.blockReason,
119
+ });
120
+ }
109
121
  // wait commit の個票は検証済みの root 本文を使う一方、exec branch には agent が編集した本文を
110
122
  // 残す。root の frontmatter から lifecycle フィールドだけを重ね、resume 後も waiting 状態と
111
123
  // 未統合の作業内容の両方を保持する。
@@ -121,14 +133,7 @@ export function restorePreservedRegisterTicket(worktreePath, repoRoot, preserved
121
133
  return;
122
134
  }
123
135
  try {
124
- const rootContent = readFileSync(rootTicketPath, "utf8");
125
- const parsed = readRegisterItemContent(rootContent, basename(rel));
126
- if (!parsed)
127
- throw new Error(`could not parse register item: ${rel}`);
128
- const content = applyRegisterItemFields(preserved.content, {
129
- ...registerItemFieldsFromItem(parsed.item),
130
- block_reason: parsed.blockReason === CELL_NONE ? null : parsed.blockReason,
131
- });
136
+ const content = overlayRegisterTicketLifecycle(preserved.content, readFileSync(rootTicketPath, "utf8"), rel);
132
137
  mkdirSync(dirname(worktreeTicketPath), { recursive: true });
133
138
  writeFileSync(worktreeTicketPath, content, "utf8");
134
139
  }