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
@@ -0,0 +1,84 @@
1
+ import { stagedMergeBlocker } from "../shared/git.js";
2
+ import { acquireSchedulerLock, releaseSchedulerLock } from "./events.js";
3
+ import { currentBranch } from "./worktree-ops-commit.js";
4
+ import { abortMerge } from "./worktree-ops-merge.js";
5
+ import { gitOutput, gitResult, summarizeGitHookFailure } from "./worktree.js";
6
+ // PJR-97KE: job の worktree の中で作られた子の run は、wait の commit が job の branch に入り、
7
+ // 本体の作業ツリー(日中の再開の起点)には plan も waiting の記録も無い。wait の後に exec branch
8
+ // へ統合先を取り込む merge(`merge <target> after wait`)の第2親が、その記録を持つ統合先の
9
+ // commit である。本体の HEAD がこの commit を含まないとき、再開の前に本体へ merge する。
10
+ // exec branch の先端ではなくこの commit を取り込むのは、exec branch を本体の祖先にすると
11
+ // 統合の段が「merge 済み」と誤認するためである。記録を複製せず履歴として取り込むので、
12
+ // 後で job の branch を本体へ統合しても、同じ commit を共有して衝突しない。
13
+ const LOCK_TIMEOUT_MS = 10_000;
14
+ const LOCK_STALE_MS = 300_000;
15
+ function escapeRegExp(value) {
16
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
17
+ }
18
+ // exec branch の first-parent 履歴から最新の wait 後の同期 merge を探し、その統合先の commit が
19
+ // 本体の HEAD に含まれていなければ返す。同期 merge が無い、または含まれている場合は null。
20
+ export function findForeignWaitRecords(params) {
21
+ const { repoRoot, worktree, itemId } = params;
22
+ const subject = new RegExp(`^exec\\(register ${escapeRegExp(itemId)}\\): merge (.+) after wait$`);
23
+ const log = gitResult(repoRoot, [
24
+ "log",
25
+ "--first-parent",
26
+ "--merges",
27
+ "--format=%P%x09%s",
28
+ worktree.branch,
29
+ "--",
30
+ ]);
31
+ if (log.status !== 0 || typeof log.stdout !== "string")
32
+ return null;
33
+ for (const line of log.stdout.split("\n")) {
34
+ const tab = line.indexOf("\t");
35
+ if (tab < 0)
36
+ continue;
37
+ const match = subject.exec(line.slice(tab + 1));
38
+ if (!match)
39
+ continue;
40
+ const parents = line.slice(0, tab).trim().split(/\s+/);
41
+ const commit = parents[1];
42
+ if (!commit)
43
+ return null;
44
+ const contained = gitResult(repoRoot, ["merge-base", "--is-ancestor", commit, "HEAD"]).status === 0;
45
+ return contained ? null : { commit, target: match[1] };
46
+ }
47
+ return null;
48
+ }
49
+ // 統合先の wait の記録を本体の現在の branch へ merge commit 1件で取り込む。取り込めない場合は
50
+ // merge を中止して本体を元に戻し、理由を例外で返す。
51
+ export function adoptForeignWaitRecords(params) {
52
+ const { repoRoot, schedulePath, itemId, records } = params;
53
+ const targetBranch = currentBranch(repoRoot);
54
+ const lockDir = acquireSchedulerLock(schedulePath, {
55
+ actor: `register-adopt:${itemId}`,
56
+ lockTimeoutMs: LOCK_TIMEOUT_MS,
57
+ lockStaleMs: LOCK_STALE_MS,
58
+ });
59
+ try {
60
+ const staged = stagedMergeBlocker(repoRoot);
61
+ if (staged)
62
+ throw new Error(staged);
63
+ const message = `exec(register ${itemId}): merge ${records.target} records before resume`;
64
+ const merge = gitResult(repoRoot, ["merge", "--no-ff", "-m", message, records.commit]);
65
+ if (merge.status === 0)
66
+ return;
67
+ const output = [merge.stdout, merge.stderr]
68
+ .filter((part) => typeof part === "string" && part.length > 0)
69
+ .join("\n");
70
+ if (gitResult(repoRoot, ["rev-parse", "--verify", "--quiet", "MERGE_HEAD"]).status === 0) {
71
+ abortMerge(repoRoot);
72
+ }
73
+ throw new Error(`git merge of ${records.target} (${records.commit.slice(0, 12)}) into ${targetBranch} failed: ` +
74
+ summarizeGitHookFailure(output));
75
+ }
76
+ finally {
77
+ releaseSchedulerLock(lockDir);
78
+ }
79
+ }
80
+ // 取り込んだ commit のうち、本体に無かったものの数(利用者への表示用)。
81
+ export function countForeignCommits(repoRoot, records) {
82
+ const count = Number.parseInt(gitOutput(repoRoot, ["rev-list", "--count", `HEAD..${records.commit}`]).trim(), 10);
83
+ return Number.isFinite(count) ? count : 0;
84
+ }
@@ -1,4 +1,5 @@
1
- import { existsSync } from "node:fs";
1
+ import { existsSync, writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
2
3
  import { productIntegrationTarget } from "./task-repos.js";
3
4
  import { abortMerge } from "./worktree-ops.js";
4
5
  import { gitOutput, gitResult } from "./worktree.js";
@@ -95,8 +96,9 @@ function restoreOriginalWorktree(params) {
95
96
  * Merge `target` into the branch checked out at `cwd` (an exec worktree) with a merge commit.
96
97
  * Uncommitted changes (including untracked files) are stashed before the merge and restored
97
98
  * without restoring the old index. Conflicts on `theirsPaths` (repository-relative) take the
98
- * target side and conflicts on `oursPaths` keep the exec branch side. Any other committed conflict
99
- * aborts the merge. If restoring the stash conflicts,
99
+ * target side and conflicts on `oursPaths` keep the exec branch side. Conflicts on `resolvedPaths`
100
+ * write the resolver's combination of both sides (when either side deleted the file, the target
101
+ * side is taken). Any other committed conflict aborts the merge. If restoring the stash conflicts,
100
102
  * the merge commit is rolled back and the executor changes are restored on the original HEAD.
101
103
  */
102
104
  export function syncWorktreeWithIntegrationTarget(params) {
@@ -126,12 +128,21 @@ export function syncWorktreeWithIntegrationTarget(params) {
126
128
  const conflicted = zeroSeparated(cwd, ["diff", "--name-only", "--diff-filter=U", "-z"]);
127
129
  const theirs = new Set(params.theirsPaths ?? []);
128
130
  const ours = new Set(params.oursPaths ?? []);
129
- const unexpected = conflicted.filter((path) => !theirs.has(path) && !ours.has(path));
131
+ const resolvers = params.resolvedPaths ?? new Map();
132
+ const unexpected = conflicted.filter((path) => !theirs.has(path) && !ours.has(path) && !resolvers.has(path));
130
133
  if (unexpected.length > 0) {
131
134
  throw new Error(`${repo}: merge conflicts with ${target}: ${unexpected.join(", ")}`);
132
135
  }
133
136
  for (const path of conflicted) {
134
- const side = theirs.has(path) ? target : "HEAD";
137
+ const resolver = resolvers.get(path);
138
+ if (resolver && hasPathAt(cwd, "HEAD", path) && hasPathAt(cwd, target, path)) {
139
+ const execContent = gitOutput(cwd, ["show", `HEAD:${path}`]);
140
+ const targetContent = gitOutput(cwd, ["show", `${target}:${path}`]);
141
+ writeFileSync(resolve(cwd, path), resolver(execContent, targetContent), "utf8");
142
+ gitOutput(cwd, ["add", "--", path]);
143
+ continue;
144
+ }
145
+ const side = theirs.has(path) || resolver ? target : "HEAD";
135
146
  if (hasPathAt(cwd, side, path)) {
136
147
  gitOutput(cwd, ["checkout", side, "--", path]);
137
148
  gitOutput(cwd, ["add", "--", path]);
@@ -274,6 +285,7 @@ export function syncTaskWorktreesWithIntegrationTargets(params) {
274
285
  message: params.message,
275
286
  theirsPaths: params.projectTheirsPaths,
276
287
  oursPaths: params.projectOursPaths,
288
+ resolvedPaths: params.projectResolvedPaths,
277
289
  }));
278
290
  return synced;
279
291
  }
@@ -377,7 +377,7 @@ function isHistoryLinkTargetPath(path) {
377
377
  if (normalized === "pjr-index.md" || normalized.endsWith("/pjr-index.md")) {
378
378
  return false;
379
379
  }
380
- return (/(?:^|\/)pjr-[^/]+\.md$/u.test(normalized) ||
380
+ return (/^docs\/ja\/projects\/.+\/controls\/project-register\/pjr-[^/]+\.md$/u.test(normalized) ||
381
381
  /^docs\/ja\/projects\/.+\/exec\/(?:plans|results)\/.+\.md$/u.test(normalized) ||
382
382
  (isRunRecordPath(normalized) && /\/(plan|result)\.md$/u.test(normalized)));
383
383
  }
@@ -407,7 +407,7 @@ const CHANGE_SCOPED_VALIDATIONS = [
407
407
  matchesPath: hasExtension([".md"]),
408
408
  },
409
409
  {
410
- pathCondition: "履歴蓄積ファイル(pjr-*.md など、pjr-index.md と runner が書く plan・result を除く)",
410
+ pathCondition: "履歴蓄積ファイル(登録簿の個票 controls/project-register/pjr-*.md など、pjr-index.md と runner が書く plan・result を除く)",
411
411
  matchesCommand: (command) => /^npm run validate:history-links(?:\s|$)/u.test(command) ||
412
412
  /^(?:npx\s+)?specdojo-docs-lint\s+history-links(?:\s|$)/u.test(command) ||
413
413
  /^node\s+\S*specdojo-docs-lint\.js\s+history-links(?:\s|$)/u.test(command),
@@ -9,7 +9,7 @@ import { dump } from "../shared/yaml.js";
9
9
  import { formatMarkdownFile } from "./format.js";
10
10
  import { deriveReporterFacts, mechanicallyNotApplicableReason, runnerOwnedValidationReason, } from "./reporter.js";
11
11
  import { isRunRecordPath, listRunRecords, recordPathForRead, recordStem, resolveRunPlanRef, resultForPlan, taskRecordPaths, } from "./run-records.js";
12
- import { escapeMarkdownInline, expandTemplate, stripTerminalControlSequences } from "./shared.js";
12
+ import { escapeMarkdownInline, expandTemplate, inlineCodeFrontmatterAnglePlaceholders, stripTerminalControlSequences, } from "./shared.js";
13
13
  import { isCondenseRecords } from "../shared/condense-records.js";
14
14
  import { inlineCode } from "./plans-grade-findings.js";
15
15
  export const MAX_INDIVIDUAL_CHANGED_FILES = 50;
@@ -28,6 +28,22 @@ function serializeYamlString(value) {
28
28
  const serialized = dump(value, { lineWidth: -1, noRefs: true }).replace(/\n$/, "");
29
29
  return serialized.includes("\n") ? JSON.stringify(value) : serialized;
30
30
  }
31
+ // executor 由来の condense の記録を frontmatter へ書き写す前に、コードスパン外の山括弧を
32
+ // code span 化する。むき出しの `<provider>` などは lint-fm で失敗する(PJR-V141)。
33
+ // 既に code span の語は変えないため、再シリアライズでも値は変わらない。
34
+ function frontmatterCondenseRecords(records) {
35
+ return records.map((record) => ({
36
+ ...record,
37
+ location: inlineCodeFrontmatterAnglePlaceholders(record.location),
38
+ reason: inlineCodeFrontmatterAnglePlaceholders(record.reason),
39
+ cause: record.cause.type === "kata"
40
+ ? {
41
+ ...record.cause,
42
+ location: inlineCodeFrontmatterAnglePlaceholders(record.cause.location),
43
+ }
44
+ : record.cause,
45
+ }));
46
+ }
31
47
  function serializeFrontmatter(meta) {
32
48
  const inner = [
33
49
  `id: ${serializeYamlString(meta.id)}`,
@@ -60,7 +76,7 @@ function serializeFrontmatter(meta) {
60
76
  inner.push(` - ${serializeYamlString(target)}`);
61
77
  }
62
78
  if (meta.condense_records) {
63
- inner.push(...dump({ condense_records: meta.condense_records }, { lineWidth: -1, noRefs: true })
79
+ inner.push(...dump({ condense_records: frontmatterCondenseRecords(meta.condense_records) }, { lineWidth: -1, noRefs: true })
64
80
  .trimEnd()
65
81
  .split("\n"));
66
82
  }
@@ -68,7 +84,8 @@ function serializeFrontmatter(meta) {
68
84
  // シーケンスや制御文字を除去し(色付き hook 出力が result 表示を壊すのを防ぐ)、JSON の
69
85
  // 文字列形式で YAML へ埋め込む。改行・引用符・バックスラッシュも値を変えずに保持できる。
70
86
  if (meta.block_reason) {
71
- const safeReason = stripTerminalControlSequences(meta.block_reason);
87
+ // executor の stderr(`blocked: <reason>` など)の山括弧も lint-fm で失敗するため code span 化する。
88
+ const safeReason = inlineCodeFrontmatterAnglePlaceholders(stripTerminalControlSequences(meta.block_reason));
72
89
  inner.push(`block_reason: ${JSON.stringify(safeReason)}`);
73
90
  }
74
91
  return buildSpecdojoFrontmatter(inner);
@@ -745,7 +762,10 @@ export async function renderReporterResult(resultPath, output, evidence, options
745
762
  throw new Error("condense requires valid executor condense_records (use [] when no candidates)");
746
763
  }
747
764
  // Preserve scaffold ownership; add only validated executor facts, never reporter prose.
748
- const scaffold = { ...parsed.data, condense_records: evidence.condense_records };
765
+ const scaffold = {
766
+ ...parsed.data,
767
+ condense_records: frontmatterCondenseRecords(evidence.condense_records),
768
+ };
749
769
  frontmatter = `---\n${dump({ specdojo: scaffold }, { lineWidth: -1, noRefs: true }).trimEnd()}\n---`;
750
770
  recordsBody = `\n\n## 5. 修正・保持の記録\n\n${renderCondenseRecords(evidence.condense_records)}`;
751
771
  }
@@ -37,7 +37,10 @@ export function scheduleKataReviewSubjects(task, deliverable, projectId) {
37
37
  if (!rule || !["improve-kata", "bootstrap-kata-set"].includes(rule.intent))
38
38
  return [];
39
39
  const rulebook = deliverable?.deliverable.rulebook;
40
- const refs = resolveKataRefs(rulebook, deliverable?.deliverable.kind);
40
+ // improve-kata・bootstrap-kata-set の段は実践の型そのものを評価するため、kind: generated の
41
+ // 成果物でも宣言された rulebook を解決する(PJR-DM9B)。generated の扱いだけを外す。
42
+ const kind = deliverable?.deliverable.kind;
43
+ const refs = resolveKataRefs(rulebook, kind === "generated" ? undefined : kind);
41
44
  const subjects = [{ path: refs.rulebook, label: "rulebook" }];
42
45
  const declarations = rulebook ? loadRulebookRefs(rulebook) : {};
43
46
  const declared = rulebook ? declaredKata(rulebook) : [];
@@ -1,4 +1,4 @@
1
- import { relative, sep } from "node:path";
1
+ import { dirname, join, relative, sep } from "node:path";
2
2
  import { enforceExecutorReportContract, executorCompletionFailure, recordExecutorEvidence, recordParentValidationFailureOutput, recordReporterFailureOutput, snapshotWorktreeChanges, writeExecutorEvidence, } from "../evidence.js";
3
3
  import { failedParentValidationReason, hasRecordedParentValidations, parentValidationRoots, parentValidationSelectionForEvidence, replaceParentValidationResults, } from "../parent-validation.js";
4
4
  import { createPipelineState, pipelineStateLocation, updatePipelineStage, writePipelineState, } from "../pipeline-state.js";
@@ -22,6 +22,7 @@ export async function refreshParentValidationsForReporterResume(params) {
22
22
  `${force ? " (integration targets were merged into the worktree)" : ""}.\n`);
23
23
  const parentValidationBatch = await runConfiguredParentValidationBatch(params.execDefaults, parentValidationRoots(params.cwd, params.productWorktrees), {
24
24
  label: params.evidence.task_id,
25
+ metricsPath: join(dirname(params.evidencePath), "parent-validation-metrics.jsonl"),
25
26
  // 統合先を取り込んだ後は executor の変更以外も入るため、変更の種類で選ばずすべて流す。
26
27
  ...(force ? {} : { selection: parentValidationSelectionForEvidence(params.evidence) }),
27
28
  });
@@ -127,7 +128,7 @@ export async function runReporterStage(params) {
127
128
  evidence: reporterEvidence,
128
129
  mode: params.mode ?? "edit",
129
130
  invoke: async (reporterPrompt) => {
130
- const reporterOutcome = await runWithRetry(reporterCandidates, reporterPrompt, execDefaults, cwd, env, params.resultPath, params.rateLimitOptions);
131
+ const reporterOutcome = await runWithRetry(reporterCandidates, reporterPrompt, execDefaults, cwd, env, params.resultPath, params.rateLimitOptions, "reporter");
131
132
  reporterAttempts += reporterOutcome.attempts;
132
133
  reporterActor = reporterOutcome.actor ?? reporterActor;
133
134
  rateLimitEvents.push(...reporterOutcome.rateLimitEvents);
@@ -1,9 +1,11 @@
1
1
  import { spawn } from "node:child_process";
2
2
  import { existsSync } from "node:fs";
3
- import { basename, relative, resolve, sep } from "node:path";
3
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
4
+ import { trackExecutor, withValidationMetrics } from "../validation-metrics.js";
4
5
  import { resolveConnectionErrorDetection, resolveMemberCommand, resolveRateLimitDetection, resolveRateLimitPolicy, } from "../agent-config.js";
5
6
  import { decidePinnedWait, normalizeAgentLimit, } from "../limit.js";
6
7
  import { replaceDocIndexRefs } from "../../docs/doc-index.js";
8
+ import { localConfigEnvironment } from "../../shared/local-config.js";
7
9
  import { loadPlan, parsePlanTaskIdentity } from "../plans.js";
8
10
  import { recordParentValidationFailureOutput, validateResumedTargetCoverage, writeExecutorEvidence, } from "../evidence.js";
9
11
  import { parentValidationDisplayCommands, parentValidationGateFor, parentValidationLabels, parentValidationRoots, parentValidationSelectionForEvidence, recordedParentValidationLabel, replaceParentValidationResults, runParentValidationBatch, } from "../parent-validation.js";
@@ -211,10 +213,10 @@ export async function runConfiguredParentValidationBatch(execDefaults, cwd, opti
211
213
  return { validations: [], failureOutputs: [] };
212
214
  const labels = parentValidationLabels(entries);
213
215
  const label = options.label ?? basename(typeof cwd === "string" ? cwd : cwd.project);
214
- const batch = await parentValidationGateFor(execDefaults).run(label, labels, async () => {
216
+ const batch = await withValidationMetrics(label, options.metricsPath, () => parentValidationGateFor(execDefaults).run(label, labels, async () => {
215
217
  process.stdout.write(` Running parent validations (${label}): ${labels.join(", ")}\n`);
216
218
  return await runParentValidationBatch(entries, cwd, options.invoke, options.selection);
217
- });
219
+ }));
218
220
  for (const validation of batch.validations) {
219
221
  process.stdout.write(` Parent validation ${recordedParentValidationLabel(validation)}: ${validation.status}\n`);
220
222
  }
@@ -229,6 +231,7 @@ export async function runConfiguredParentValidations(execDefaults, cwd, options
229
231
  export async function appendParentValidationsToExecutorEvidence(params) {
230
232
  const parentValidationBatch = await runConfiguredParentValidationBatch(params.execDefaults, parentValidationRoots(params.cwd, params.productWorktrees), {
231
233
  label: params.evidence.task_id,
234
+ metricsPath: join(dirname(params.evidencePath), "parent-validation-metrics.jsonl"),
232
235
  selection: parentValidationSelectionForEvidence(params.evidence),
233
236
  });
234
237
  const evidenceWithValidations = replaceParentValidationResults(params.evidence, parentValidationBatch.validations);
@@ -313,7 +316,7 @@ export function loadRosterForExecutionPath(executionPath) {
313
316
  }
314
317
  return null;
315
318
  }
316
- export async function executeAgent(agentCommand, prompt, detection, provider, cooldownSeconds, cwd, env, quiet = false) {
319
+ export async function executeAgent(agentCommand, prompt, detection, provider, cooldownSeconds, cwd, env, quiet = false, stageRole = "executor") {
317
320
  if (!agentCommand.trim()) {
318
321
  return { result: "failure", exitCode: null, stdout: "", stderr: "Empty agent command" };
319
322
  }
@@ -326,6 +329,7 @@ export async function executeAgent(agentCommand, prompt, detection, provider, co
326
329
  shell: true,
327
330
  stdio: ["pipe", "pipe", "pipe"],
328
331
  });
332
+ const stopTracking = stageRole === "executor" ? trackExecutor(child.pid, cwd) : () => undefined;
329
333
  // stdin を読まずに即終了するコマンドへの書き込みは EPIPE になる。未処理だと
330
334
  // プロセスごと落ちて失敗時の後処理(block 遷移・result 更新)が走らないため無視する。
331
335
  // 実行結果は終了コードで判定する。
@@ -351,6 +355,7 @@ export async function executeAgent(agentCommand, prompt, detection, provider, co
351
355
  });
352
356
  child.once("close", (code) => resolveExit(code));
353
357
  });
358
+ stopTracking();
354
359
  const combinedOutput = `${stdout}\n${stderr}`;
355
360
  if (isRateLimitError(exitCode, combinedOutput, detection)) {
356
361
  return {
@@ -392,7 +397,7 @@ export function reportProtectionHandoffRecord(recorded, resultPath) {
392
397
  function rateLimitPrefix(result) {
393
398
  return result === "rate_limit" ? "rate limit reached; " : "";
394
399
  }
395
- export async function runWithRetry(candidates, prompt, execDefaults, cwd, env, resultPath, pinned) {
400
+ export async function runWithRetry(candidates, prompt, execDefaults, cwd, env, resultPath, pinned, stageRole = "executor") {
396
401
  const policy = resolveRateLimitPolicy(execDefaults, candidates[0]?.provider);
397
402
  let attempts = 0;
398
403
  // PJR-98G4: agentEnvironment が渡したプロダクト worktree を、provider の追加ディレクトリと
@@ -420,7 +425,7 @@ export async function runWithRetry(candidates, prompt, execDefaults, cwd, env, r
420
425
  lastActor = candidate.actor;
421
426
  const protectedConfigBefore = captureAgentProtectedConfigAcrossRepos(agentRepos);
422
427
  const gitStateBefore = captureAgentGitStateAcrossRepos(agentRepos);
423
- const attempt = await executeAgent(withAgentExtraRoots(candidate.command, candidate.provider, productRoots.map((root) => root.path)), prompt, detection, candidate.provider, candidatePolicy?.cooldown_seconds, cwd, env);
428
+ const attempt = await executeAgent(withAgentExtraRoots(candidate.command, candidate.provider, productRoots.map((root) => root.path)), prompt, detection, candidate.provider, candidatePolicy?.cooldown_seconds, cwd, env, false, stageRole);
424
429
  const protectedConfigChanges = changedAgentProtectedConfigAcrossRepos(protectedConfigBefore);
425
430
  if (protectedConfigChanges.length > 0) {
426
431
  // 利用上限で止まった場合も保護の検査は飛ばさない。止まった理由として利用上限を先に記録する。
@@ -618,6 +623,7 @@ export function reportProductWorktrees(worktree) {
618
623
  export function agentEnvironment(repoRoot, worktreePath, schedulePath, executionPath, productWorktrees) {
619
624
  return {
620
625
  ...withoutInheritedRepoEnvironment(gitEnvironment()),
626
+ ...localConfigEnvironment(repoRoot),
621
627
  SPECDOJO_SCHEDULE_PATH: pathInsideWorktree(repoRoot, worktreePath, schedulePath),
622
628
  SPECDOJO_EXECUTION_PATH: pathInsideWorktree(repoRoot, worktreePath, executionPath),
623
629
  ...productRepoEnvironment(worktreePath, productWorktrees),