specdojo 0.3.1 → 0.4.1

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 (260) hide show
  1. package/.github/agents/specdojo-orchestrator.md +61 -2
  2. package/CHANGELOG.md +90 -0
  3. package/README.md +85 -25
  4. package/dist/{catalog-build-references.js → catalog/build-references.js} +4 -4
  5. package/dist/catalog/build-render.js +32 -0
  6. package/dist/{catalog-build.js → catalog/build.js} +9 -9
  7. package/dist/{catalog.js → catalog/catalog.js} +10 -10
  8. package/dist/{catalog-generate.js → catalog/generate.js} +8 -8
  9. package/dist/catalog/paths.js +1 -0
  10. package/dist/{catalog-plan-generate.js → catalog/plan-generate.js} +4 -4
  11. package/dist/{catalog-plan.js → catalog/plan.js} +4 -4
  12. package/dist/{catalog-scaffold.js → catalog/scaffold.js} +3 -3
  13. package/dist/{agent.js → commands/agent.js} +11 -11
  14. package/dist/{build-command.js → commands/build.js} +2 -2
  15. package/dist/{init-command.js → commands/init.js} +168 -45
  16. package/dist/commands/night-orchestrator.js +287 -0
  17. package/dist/{orchestrator.js → commands/orchestrator.js} +12 -5
  18. package/dist/{watch.js → commands/watch.js} +3 -3
  19. package/dist/{dashboard-timeline.js → dashboard/dashboard-timeline.js} +2 -2
  20. package/dist/{dashboard.js → dashboard/dashboard.js} +11 -10
  21. package/dist/{dashboard-exec-records.js → dashboard/exec-records.js} +2 -2
  22. package/dist/{dashboard-routines.js → dashboard/routines.js} +6 -5
  23. package/dist/{dashboard-shared.js → dashboard/shared.js} +1 -1
  24. package/dist/{timeline-build.js → dashboard/timeline-build.js} +2 -1
  25. package/dist/{timeline.js → dashboard/timeline.js} +1 -1
  26. package/dist/{deliverable.js → deliverable/deliverable.js} +5 -5
  27. package/dist/{deliverable-trash.js → deliverable/trash.js} +5 -5
  28. package/dist/{devcontainer-command.js → devcontainer/command.js} +8 -4
  29. package/dist/devcontainer/scaffold.js +418 -0
  30. package/dist/{doc-index.js → docs/doc-index.js} +1 -1
  31. package/dist/{frontmatter-namespace.js → docs/frontmatter-namespace.js} +1 -1
  32. package/dist/{index-command.js → docs/index-command.js} +1 -1
  33. package/dist/docs/template-resolution.js +1 -0
  34. package/dist/{viewpoint-document-kinds-check.js → docs/viewpoint-document-kinds-check.js} +1 -1
  35. package/dist/{yaml-pages-command.js → docs/yaml-pages-command.js} +1 -1
  36. package/dist/{yaml-pages.js → docs/yaml-pages.js} +2 -2
  37. package/dist/{exec-agent-config.js → exec/agent-config.js} +92 -5
  38. package/dist/{exec-agent-git-state.js → exec/agent-git-state.js} +1 -1
  39. package/dist/{exec-agent-protected-config.js → exec/agent-protected-config.js} +1 -1
  40. package/dist/{exec-commands.js → exec/commands.js} +22 -18
  41. package/dist/{exec-core.js → exec/core.js} +11 -11
  42. package/dist/{exec-events.js → exec/events.js} +2 -2
  43. package/dist/{exec-evidence.js → exec/evidence.js} +11 -6
  44. package/dist/exec/exec.js +2 -0
  45. package/dist/exec/format.js +1 -0
  46. package/dist/{exec-handoff.js → exec/handoff.js} +13 -12
  47. package/dist/{exec-limit.js → exec/limit.js} +93 -12
  48. package/dist/{exec-parent-validation.js → exec/parent-validation.js} +18 -4
  49. package/dist/{exec-pipeline-state.js → exec/pipeline-state.js} +29 -2
  50. package/dist/{exec-plans-core.js → exec/plans-core.js} +68 -114
  51. package/dist/{exec-plans-generation.js → exec/plans-generation.js} +53 -10
  52. package/dist/{exec-plans-storage.js → exec/plans-storage.js} +5 -5
  53. package/dist/{exec-plans.js → exec/plans.js} +3 -3
  54. package/dist/{exec-project.js → exec/project.js} +1 -1
  55. package/dist/{exec-protection-handoff.js → exec/protection-handoff.js} +3 -3
  56. package/dist/{exec-register-resume.js → exec/register-resume.js} +2 -2
  57. package/dist/{exec-register.js → exec/register.js} +114 -9
  58. package/dist/{exec-repo-integration-git.js → exec/repo-integration-git.js} +2 -2
  59. package/dist/{exec-repo-integration-sync.js → exec/repo-integration-sync.js} +4 -4
  60. package/dist/{exec-repo-integration.js → exec/repo-integration.js} +14 -11
  61. package/dist/{exec-repo-trace.js → exec/repo-trace.js} +3 -3
  62. package/dist/{exec-reporter-output.js → exec/reporter-output.js} +2 -2
  63. package/dist/{exec-reporter.js → exec/reporter.js} +142 -25
  64. package/dist/{exec-results.js → exec/results.js} +287 -31
  65. package/dist/{exec-run-agent-pipeline.js → exec/run/agent-pipeline.js} +35 -12
  66. package/dist/{exec-run-agent.js → exec/run/agent.js} +115 -28
  67. package/dist/{exec-run-in-place.js → exec/run/in-place.js} +56 -27
  68. package/dist/{exec-run-job.js → exec/run/job.js} +65 -36
  69. package/dist/{exec-run-lifecycle-commands.js → exec/run/lifecycle-commands.js} +30 -22
  70. package/dist/{exec-run-lock.js → exec/run/lock.js} +4 -3
  71. package/dist/{exec-run-mode-shared.js → exec/run/mode-shared.js} +3 -3
  72. package/dist/{exec-run-register-command.js → exec/run/register-command.js} +38 -11
  73. package/dist/{exec-run-register-core.js → exec/run/register-core.js} +63 -21
  74. package/dist/{exec-run-register-mode.js → exec/run/register-mode.js} +58 -31
  75. package/dist/exec/run/register-post-review.js +420 -0
  76. package/dist/{exec-run-register-resume.js → exec/run/register-resume.js} +48 -27
  77. package/dist/{exec-run-register-state.js → exec/run/register-state.js} +13 -10
  78. package/dist/{exec-run-register-worktree.js → exec/run/register-worktree.js} +119 -24
  79. package/dist/{exec-run.js → exec/run/run.js} +11 -11
  80. package/dist/{exec-run-schedule-mode.js → exec/run/schedule-mode.js} +17 -17
  81. package/dist/{exec-run-schedule-prepare.js → exec/run/schedule-prepare.js} +31 -18
  82. package/dist/{exec-run-schedule-task.js → exec/run/schedule-task.js} +45 -18
  83. package/dist/{exec-run-shared.js → exec/run/shared.js} +78 -30
  84. package/dist/{exec-schedule-calendar.js → exec/schedule/calendar.js} +1 -1
  85. package/dist/{exec-schedule-cpm.js → exec/schedule/cpm.js} +2 -2
  86. package/dist/{exec-schedule-gantt-chart-render.js → exec/schedule/gantt-chart-render.js} +2 -2
  87. package/dist/exec/schedule/gantt-chart.js +2 -0
  88. package/dist/{exec-schedule-hash.js → exec/schedule/hash.js} +2 -2
  89. package/dist/exec/schedule/index.js +1 -0
  90. package/dist/{exec-schedule-initial.js → exec/schedule/initial.js} +2 -2
  91. package/dist/{exec-schedule-progress.js → exec/schedule/progress.js} +2 -2
  92. package/dist/{exec-schedule-ready.js → exec/schedule/ready.js} +2 -2
  93. package/dist/{exec-schedule.js → exec/schedule/schedule.js} +11 -11
  94. package/dist/exec/shared.js +63 -0
  95. package/dist/exec/slot-lock.js +1 -0
  96. package/dist/{exec-strategy.js → exec/strategy.js} +2 -2
  97. package/dist/{exec-task-repos.js → exec/task-repos.js} +104 -17
  98. package/dist/{exec-task-view.js → exec/task-view.js} +4 -4
  99. package/dist/{exec-trial-commands.js → exec/trial-commands.js} +20 -22
  100. package/dist/{exec-trial-core.js → exec/trial-core.js} +6 -6
  101. package/dist/{exec-trial.js → exec/trial.js} +2 -2
  102. package/dist/{exec-worktree-command.js → exec/worktree-command.js} +25 -23
  103. package/dist/{exec-worktree-ops-commit.js → exec/worktree-ops-commit.js} +25 -60
  104. package/dist/{exec-worktree-ops-lifecycle.js → exec/worktree-ops-lifecycle.js} +13 -8
  105. package/dist/{exec-worktree-ops-merge.js → exec/worktree-ops-merge.js} +48 -7
  106. package/dist/{exec-worktree-ops.js → exec/worktree-ops.js} +3 -3
  107. package/dist/exec/worktree.js +305 -0
  108. package/dist/{grade-apply.js → grade/apply.js} +9 -9
  109. package/dist/{grade-command-apply.js → grade/command-apply.js} +7 -7
  110. package/dist/{grade-command-inspect.js → grade/command-inspect.js} +6 -6
  111. package/dist/{grade-command-plan.js → grade/command-plan.js} +5 -5
  112. package/dist/{grade-core.js → grade/core.js} +3 -3
  113. package/dist/grade/grade.js +19 -0
  114. package/dist/{grade-markdown.js → grade/markdown.js} +6 -6
  115. package/dist/{grade-pipeline-state.js → grade/pipeline-state.js} +4 -4
  116. package/dist/{grade-plan.js → grade/plan.js} +5 -5
  117. package/dist/{grade-result.js → grade/result.js} +5 -94
  118. package/dist/{grade-target-discovery.js → grade/target-discovery.js} +7 -7
  119. package/dist/{grade-targets.js → grade/targets.js} +11 -8
  120. package/dist/{job-definition.js → job/definition.js} +25 -6
  121. package/dist/{job.js → job/job.js} +12 -11
  122. package/dist/{kata-command.js → kata/command.js} +3 -3
  123. package/dist/{kata.js → kata/kata.js} +5 -5
  124. package/dist/register/approach.js +134 -0
  125. package/dist/{register-core.js → register/core.js} +26 -8
  126. package/dist/{register-create-commands.js → register/create-commands.js} +171 -8
  127. package/dist/{register-date.js → register/date.js} +1 -1
  128. package/dist/register/derivation.js +163 -0
  129. package/dist/{register-event-merge.js → register/event-merge.js} +44 -3
  130. package/dist/{register-events.js → register/events.js} +13 -3
  131. package/dist/{register-history.js → register/history.js} +7 -6
  132. package/dist/{register-item.js → register/item.js} +32 -5
  133. package/dist/register/lifecycle-lock.js +5 -0
  134. package/dist/{register-maintenance-commands.js → register/maintenance-commands.js} +13 -7
  135. package/dist/{register-migrate-timestamps.js → register/migrate-timestamps.js} +3 -3
  136. package/dist/{register-migration.js → register/migration.js} +5 -4
  137. package/dist/{register.js → register/register.js} +32 -27
  138. package/dist/{register-renumber.js → register/renumber.js} +38 -11
  139. package/dist/{register-transition-commands.js → register/transition-commands.js} +3 -3
  140. package/dist/{register-update.js → register/update.js} +5 -5
  141. package/dist/{register-views.js → register/views.js} +47 -7
  142. package/dist/{review-grade.js → review/grade.js} +2 -2
  143. package/dist/{review-plan.js → review/plan.js} +3 -3
  144. package/dist/{routine-definition.js → routine/definition.js} +2 -2
  145. package/dist/{routine.js → routine/routine.js} +49 -22
  146. package/dist/{schedule-approach.js → schedule/approach.js} +8 -8
  147. package/dist/{schedule-build.js → schedule/build.js} +7 -4
  148. package/dist/{schedule.js → schedule/schedule.js} +6 -6
  149. package/dist/{schedule-strategy-generate-document.js → schedule/strategy-generate-document.js} +2 -2
  150. package/dist/{schedule-strategy-generate-scope.js → schedule/strategy-generate-scope.js} +4 -4
  151. package/dist/{schedule-strategy-generate.js → schedule/strategy-generate.js} +10 -10
  152. package/dist/shared/agent-types.js +23 -0
  153. package/dist/shared/artifact-path.js +9 -0
  154. package/dist/{build-if-stale.js → shared/build-if-stale.js} +1 -1
  155. package/dist/{catalog-build-render.js → shared/catalog-render.js} +3 -32
  156. package/dist/{exec-slot-lock.js → shared/cross-process-lock.js} +3 -1
  157. package/dist/shared/fs.js +30 -0
  158. package/dist/shared/git.js +346 -0
  159. package/dist/shared/grade-result.js +94 -0
  160. package/dist/{package-paths.js → shared/package-paths.js} +3 -3
  161. package/dist/shared/plan-templates.js +114 -0
  162. package/dist/{exec-provider-scaffold.js → shared/provider-scaffold.js} +6 -3
  163. package/dist/shared/random.js +4 -0
  164. package/dist/{exec-schedule-index.js → shared/schedule-index.js} +3 -1
  165. package/dist/shared/schedule-paths.js +9 -0
  166. package/dist/{specdojo-config.js → shared/specdojo-config.js} +162 -21
  167. package/dist/{exec-shared.js → shared/text.js} +4 -135
  168. package/dist/shared/time.js +28 -0
  169. package/dist/shared/workspace-scaffold.js +69 -0
  170. package/dist/specdojo.js +22 -22
  171. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +31 -18
  172. package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +1 -2
  173. package/docs/ja/specdojo/exec-templates/xep-register-template.md +3 -2
  174. package/docs/ja/specdojo/exec-templates/xer-template.md +1 -3
  175. package/docs/ja/specdojo/exec-templates/xrp-job-template.md +6 -4
  176. package/docs/ja/specdojo/exec-templates/xrp-register-post-run-template.md +46 -0
  177. package/docs/ja/specdojo/guides/branch-workflow-guide.md +34 -1
  178. package/docs/ja/specdojo/guides/docs-structure-guide.md +2 -0
  179. package/docs/ja/specdojo/guides/exec-config-guide.md +169 -26
  180. package/docs/ja/specdojo/guides/exec-operation-guide.md +184 -13
  181. package/docs/ja/specdojo/guides/exec-worktree-guide.md +2 -0
  182. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +40 -3
  183. package/docs/ja/specdojo/guides/quick-start-guide.md +89 -21
  184. package/docs/ja/specdojo/guides/register-operation-guide.md +44 -1
  185. package/docs/ja/specdojo/guides/remote-host-development-guide.md +61 -6
  186. package/docs/ja/specdojo/guides/review-guide.md +1 -1
  187. package/docs/ja/specdojo/guides/routine-operation-guide.md +5 -5
  188. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +1 -1
  189. package/docs/ja/specdojo/guides/use-case-guide.md +1 -1
  190. package/docs/ja/specdojo/guides/waza-guide.md +1 -1
  191. package/docs/ja/specdojo/references/command-reference.md +124 -55
  192. package/docs/ja/specdojo/references/specdojo-config-reference.md +33 -7
  193. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +22 -13
  194. package/docs/ja/specdojo/standards/job-definition-standard.md +20 -18
  195. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +2 -2
  196. package/docs/ja/specdojo/templates/pjr-derived-items-template.md +22 -0
  197. package/docs/ja/specdojo/templates/pjr-index-template.md +1 -0
  198. package/docs/specdojo/schemas/v1/agent-members.schema.yaml +29 -2
  199. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +111 -17
  200. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +28 -0
  201. package/docs/specdojo/schemas/v1/job-run.schema.yaml +2 -2
  202. package/docs/specdojo/schemas/v1/job.schema.yaml +7 -0
  203. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +38 -0
  204. package/docs/specdojo/schemas/v1/register-events.schema.yaml +5 -0
  205. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +91 -7
  206. package/docs/specdojo/schemas/v1/routine-run.schema.yaml +1 -1
  207. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +36 -1
  208. package/package.json +17 -17
  209. package/templates/antigravity/README.md +6 -2
  210. package/templates/antigravity/agent-members-snippet.yaml +108 -12
  211. package/templates/antigravity/exec-defaults-snippet.yaml +8 -13
  212. package/templates/antigravity/orchestrator.md +61 -2
  213. package/templates/claude/README.md +27 -3
  214. package/templates/claude/agents/claude-executor.md +0 -1
  215. package/templates/claude/agents/claude-reporter.md +2 -1
  216. package/templates/claude/agents/claude-review-executor.md +0 -1
  217. package/templates/claude/agents/specdojo-orchestrator.md +61 -2
  218. package/templates/codex/README.md +40 -4
  219. package/templates/codex/agents/specdojo-orchestrator.toml +61 -2
  220. package/templates/codex/orchestrator.md +61 -2
  221. package/templates/devcontainer/devcontainer.json +5 -2
  222. package/templates/devcontainer/post-create.sh +15 -7
  223. package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +102 -0
  224. package/templates/devcontainer/remote-host/ssh-config.sample +19 -0
  225. package/templates/devcontainer/vim/vimrc +37 -0
  226. package/templates/init-agent-members.yaml +75 -25
  227. package/templates/init-exec-defaults.yaml +44 -9
  228. package/templates/opencode/README.md +17 -3
  229. package/templates/opencode/agents/opencode-executor.md +0 -1
  230. package/templates/opencode/agents/opencode-reporter.md +2 -1
  231. package/templates/opencode/agents/opencode-review-executor.md +0 -1
  232. package/templates/opencode/agents/specdojo-orchestrator.md +61 -2
  233. package/dist/devcontainer-scaffold.js +0 -165
  234. package/dist/exec-schedule-gantt-chart.js +0 -2
  235. package/dist/exec-worktree.js +0 -474
  236. package/dist/exec.js +0 -2
  237. package/dist/grade.js +0 -19
  238. package/templates/claude/agents/claude-expert-review-executor.md +0 -14
  239. /package/dist/{catalog-plan-prompt.js → catalog/plan-prompt.js} +0 -0
  240. /package/dist/{catalog-types.js → catalog/types.js} +0 -0
  241. /package/dist/{template-frontmatter.js → docs/template-frontmatter.js} +0 -0
  242. /package/dist/{role-types.js → exec/role-types.js} +0 -0
  243. /package/dist/{exec-schedule-gantt-chart-scope.js → exec/schedule/gantt-chart-scope.js} +0 -0
  244. /package/dist/{exec-types.js → exec/types.js} +0 -0
  245. /package/dist/{grade-command-shared.js → grade/command-shared.js} +0 -0
  246. /package/dist/{register-command-types.js → register/command-types.js} +0 -0
  247. /package/dist/{review-types.js → review/types.js} +0 -0
  248. /package/dist/{schedule-phase-sets.js → schedule/phase-sets.js} +0 -0
  249. /package/dist/{schedule-strategy-profiles.js → schedule/strategy-profiles.js} +0 -0
  250. /package/dist/{agent-response.js → shared/agent-response.js} +0 -0
  251. /package/dist/{catalog-paths.js → shared/catalog-paths.js} +0 -0
  252. /package/dist/{dist-freshness.js → shared/dist-freshness.js} +0 -0
  253. /package/dist/{git-environment.js → shared/git-environment.js} +0 -0
  254. /package/dist/{exec-format.js → shared/markdown-format.js} +0 -0
  255. /package/dist/{practice-id.js → shared/practice-id.js} +0 -0
  256. /package/dist/{spawn-self.js → shared/spawn-self.js} +0 -0
  257. /package/dist/{specdojo-gitignore.js → shared/specdojo-gitignore.js} +0 -0
  258. /package/dist/{template-resolution.js → shared/template-resolution.js} +0 -0
  259. /package/dist/{yaml-schema-modeline.js → shared/yaml-schema-modeline.js} +0 -0
  260. /package/dist/{yaml.js → shared/yaml.js} +0 -0
@@ -1,18 +1,18 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { basename, join, relative, resolve } from "node:path";
3
- import { load } from "./yaml.js";
4
- import { specdojoRootDir } from "./specdojo-config.js";
5
- import { kataDirsForKinds, resolveIncludedRulebooks, resolveKataRefs } from "./kata.js";
6
- import { resolveBasePath, resolveDeliverablePath } from "./catalog-paths.js";
7
- import { isDctPlanFileName } from "./catalog-plan.js";
8
- import { buildSpecdojoFrontmatter, readSpecdojoNamespace } from "./frontmatter-namespace.js";
9
- import { qualifyPracticeId, SPECDOJO_PRACTICE_AUTHORITY } from "./practice-id.js";
10
- import { resolveViewpointsDoc, viewpointAppliesToDocument } from "./review-plan.js";
11
- import { listFilesRecursive, nowUtcIsoSeconds, randomHex, tsForFilenameUtc, } from "./exec-shared.js";
12
- import { gradeFindingDisplayMessage, gradeResultPathForDocument, readGradeResultForDocument, } from "./grade-result.js";
13
- import { resolveSpecdojoPath, resolveSpecdojoPathIfExists } from "./template-resolution.js";
14
- import { renderReviewGradeSummary, reviewGradeFreshness } from "./review-grade.js";
15
- export const MISSING = "_MISSING_";
3
+ import { load } from "../shared/yaml.js";
4
+ import { specdojoRootDir } from "../shared/specdojo-config.js";
5
+ import { kataDirsForKinds, resolveIncludedRulebooks, resolveKataRefs } from "../kata/kata.js";
6
+ import { resolveBasePath, resolveDeliverablePath } from "../catalog/paths.js";
7
+ import { isDctPlanFileName } from "../catalog/plan.js";
8
+ import { buildSpecdojoFrontmatter, readSpecdojoNamespace } from "../docs/frontmatter-namespace.js";
9
+ import { qualifyPracticeId, SPECDOJO_PRACTICE_AUTHORITY } from "../shared/practice-id.js";
10
+ import { MISSING } from "../shared/plan-templates.js";
11
+ export { MISSING, execTemplatePath, execTemplatesDir, injectCommonConventions, loadPlanTemplate, } from "../shared/plan-templates.js";
12
+ import { resolveViewpointsDoc, viewpointAppliesToDocument } from "../review/plan.js";
13
+ import { listFilesRecursive, nowUtcIsoSeconds, randomHex, tsForFilenameUtc } from "./shared.js";
14
+ import { gradeFindingDisplayMessage, gradeResultPathForDocument, readGradeResultForDocument, } from "../shared/grade-result.js";
15
+ import { renderReviewGradeSummary, reviewGradeFreshness } from "../review/grade.js";
16
16
  export function execDocId(projectId, prefix, localBase) {
17
17
  const localId = `${prefix}-${localBase.toLowerCase()}`;
18
18
  return projectId ? `${projectId}:${localId}` : localId;
@@ -95,6 +95,60 @@ export function loadCatalogDocs(catalogPath) {
95
95
  }
96
96
  return docs;
97
97
  }
98
+ function resolvedDeliverablesInCatalog(catalogPath) {
99
+ const deliverables = [];
100
+ const visit = (sections, parentBase, domain) => {
101
+ for (const section of sections) {
102
+ const sectionBase = resolveBasePath(parentBase, section.base_path);
103
+ for (const item of section.deliverables ?? []) {
104
+ deliverables.push({
105
+ domain,
106
+ localId: item.local_id,
107
+ slug: item.local_id,
108
+ info: {
109
+ deliverable: item,
110
+ resolvedPath: resolveDeliverablePath(sectionBase, item.path),
111
+ },
112
+ });
113
+ }
114
+ visit(section.groups ?? [], sectionBase, domain);
115
+ }
116
+ };
117
+ for (const doc of loadCatalogDocs(catalogPath)) {
118
+ visit(doc.groups, resolveBasePath("", doc.base_path), doc.domain);
119
+ }
120
+ return deliverables;
121
+ }
122
+ // Register targets use document IDs rather than schedule local_ids. Resolve the document ID
123
+ // back to its catalog entry so register-originated approach plans can share schedule rendering.
124
+ export function resolveDeliverableByDocId(catalogPath, projectId, targetId) {
125
+ const matches = resolvedDeliverablesInCatalog(catalogPath).filter((target) => {
126
+ const docId = deliverableDocId(projectId, target.info.deliverable.local_id, target.info.resolvedPath);
127
+ return (targetId === docId ||
128
+ targetId === target.localId ||
129
+ targetId === qualifiedDocId(projectId, target.localId));
130
+ });
131
+ if (matches.length === 0) {
132
+ throw new Error(`catalog deliverable target not found for document id: ${targetId}`);
133
+ }
134
+ if (matches.length > 1) {
135
+ throw new Error(`ambiguous catalog deliverable target for document id ${targetId}: ${matches
136
+ .map((match) => match.localId)
137
+ .join(", ")}`);
138
+ }
139
+ return matches[0];
140
+ }
141
+ // A kata may be declared by zero, one, or several deliverables. Only a unique declaration is
142
+ // used as the maintenance plan's evidence context; otherwise the explicitly targeted kata remains
143
+ // executable without selecting an arbitrary deliverable.
144
+ export function findUniqueDeliverableForKataTarget(catalogPath, targetId, kind) {
145
+ const matches = resolvedDeliverablesInCatalog(catalogPath).filter((target) => {
146
+ const refs = resolveKataRefs(target.info.deliverable.rulebook, target.info.deliverable.kind);
147
+ const refPath = refs[kind];
148
+ return refPath !== MISSING && refDocIdFromPath(refPath) === targetId;
149
+ });
150
+ return matches.length === 1 ? matches[0].info : null;
151
+ }
98
152
  // Resolve a `--deliverable` identifier (a bare `local_id`) to a catalog deliverable.
99
153
  // `local_id` is unique project-wide (catalog validate warns otherwise); an ambiguous
100
154
  // match is an error rather than a silent first match.
@@ -171,106 +225,6 @@ export function frontmatter(meta) {
171
225
  return buildSpecdojoFrontmatter(inner);
172
226
  }
173
227
  // ---------------------------------------------------------------------------
174
- // Template-based generation (edit-plan / review-plan テンプレートの展開)
175
- // ---------------------------------------------------------------------------
176
- // Shared conventions (link notation など) appended to every generated plan. The plan is the
177
- // only context guaranteed to reach the executing agent regardless of tool (it is piped via
178
- // stdin), so cross-tool rules must travel with the plan rather than tool-specific instruction
179
- // files. Kept as a single fragment to avoid duplicating the rule across every plan template.
180
- const COMMON_CONVENTIONS_TEMPLATE = "xep-common-conventions-template.md";
181
- export function execTemplatesDir() {
182
- return resolveSpecdojoPath("docs/ja/specdojo/exec-templates");
183
- }
184
- export function execTemplatePath(fileName) {
185
- return resolveSpecdojoPath(`docs/ja/specdojo/exec-templates/${fileName}`);
186
- }
187
- function templatePrefix(mode) {
188
- return mode === "review" ? "xrp" : "xep";
189
- }
190
- function standardTemplateFileName(mode) {
191
- return `${templatePrefix(mode)}-template.md`;
192
- }
193
- function approachTemplateFileName(mode, approach) {
194
- return `${templatePrefix(mode)}-${approach}-template.md`;
195
- }
196
- // Selects <prefix>-<approach>-template.md when it exists, falling back
197
- // to the standard <prefix>-template.md. Any missing variant falls through to the
198
- // next candidate so a plan is always produced.
199
- function resolvePlanTemplatePath(mode, approach) {
200
- if (approach) {
201
- const candidatePath = resolveSpecdojoPathIfExists(`docs/ja/specdojo/exec-templates/${approachTemplateFileName(mode, approach)}`);
202
- if (candidatePath)
203
- return candidatePath;
204
- }
205
- return execTemplatePath(standardTemplateFileName(mode));
206
- }
207
- function readTemplate(templatePath, cache) {
208
- const cached = cache.get(templatePath);
209
- if (cached !== undefined)
210
- return cached;
211
- if (!existsSync(templatePath)) {
212
- throw new Error(`Template not found: ${templatePath}`);
213
- }
214
- const content = readFileSync(templatePath, "utf8");
215
- cache.set(templatePath, content);
216
- return content;
217
- }
218
- export function loadPlanTemplate(mode, approach, cache) {
219
- return readTemplate(resolvePlanTemplatePath(mode, approach), cache);
220
- }
221
- // Marker a plan template places to control where the shared conventions fragment lands.
222
- const COMMON_CONVENTIONS_PLACEHOLDER = "_COMMON_CONVENTIONS_";
223
- // Lines delimiting the review-only block of the conventions fragment (review の判断手順). The
224
- // block is kept, without the marker lines, in review plans and dropped from every other plan.
225
- const REVIEW_ONLY_START = "<!-- review-only:start -->";
226
- const REVIEW_ONLY_END = "<!-- review-only:end -->";
227
- function selectReviewOnlyBlock(conventions, isReview) {
228
- const kept = [];
229
- let inside = false;
230
- for (const line of conventions.split("\n")) {
231
- const marker = line.trim();
232
- if (marker === REVIEW_ONLY_START) {
233
- inside = true;
234
- continue;
235
- }
236
- if (marker === REVIEW_ONLY_END) {
237
- inside = false;
238
- continue;
239
- }
240
- if (!inside || isReview)
241
- kept.push(line);
242
- }
243
- return kept
244
- .join("\n")
245
- .replace(/\n{3,}/g, "\n\n")
246
- .trimEnd();
247
- }
248
- // Placeholder in the conventions fragment for the resolved schema path. The agent cannot derive
249
- // the schema path on its own (it would have to hunt for it and risks burning its turn before
250
- // filling the result), so the generator resolves it deterministically and bakes it in here.
251
- const SCHEMA_REF_PLACEHOLDER = "_SCHEMA_REF_";
252
- // Injects the shared conventions fragment into a built plan body so every generated plan carries
253
- // the same rules (e.g. link notation) in its own text, independent of the executing tool. A
254
- // template controls placement via the COMMON_CONVENTIONS_PLACEHOLDER marker; templates without the
255
- // marker get the block appended so the rules are never silently dropped.
256
- // schemaRef is the resolved schema path: when MISSING (non-yaml deliverable or no schema), the
257
- // schema-validation bullet is dropped so the plan never asks for a check it cannot specify.
258
- // mode selects whether the review-only block (review の判断手順) is kept; it defaults to edit so
259
- // register / job plans never carry review instructions.
260
- export function injectCommonConventions(body, schemaRef, cache, mode = "edit") {
261
- let conventions = selectReviewOnlyBlock(readTemplate(execTemplatePath(COMMON_CONVENTIONS_TEMPLATE), cache), mode === "review");
262
- conventions =
263
- schemaRef === MISSING
264
- ? conventions
265
- .split("\n")
266
- .filter((line) => !line.includes(SCHEMA_REF_PLACEHOLDER))
267
- .join("\n")
268
- : conventions.split(SCHEMA_REF_PLACEHOLDER).join(schemaRef);
269
- if (body.includes(COMMON_CONVENTIONS_PLACEHOLDER)) {
270
- return body.split(COMMON_CONVENTIONS_PLACEHOLDER).join(conventions);
271
- }
272
- return `${body.trimEnd()}\n\n${conventions}\n`;
273
- }
274
228
  export function phaseDescriptionText(task) {
275
229
  if (task.description)
276
230
  return task.description.trimEnd();
@@ -360,7 +314,7 @@ export function kataRefState(refPath) {
360
314
  }
361
315
  // 対象成果物の depends_on を、依存先 doc の [[id]] 参照の入れ子リストで提示する。
362
316
  // id は依存先の frontmatter、未作成なら配置規約から解決する。agent へ plan を渡すときに
363
- // expandPromptRefs(src/exec-run.ts, format:'path')が
317
+ // expandPromptRefs(src/exec/run/agent.ts, format:'path')が
364
318
  // この [[id]] を doc-index 経由でリポジトリ相対パスへ展開し、agent が先行成果物を直接開ける。
365
319
  // テンプレート側はラベル直後にこの値を差し込むため、件数 0・成果物未解決時は先頭スペース付きの
366
320
  // インライン値、依存ありの場合は改行始まりの入れ子リストを返す。
@@ -1,14 +1,16 @@
1
1
  import { mkdirSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { DEFAULT_PROJECT_CONTEXT } from "./specdojo-config.js";
4
- import { resolveDeliverableSchemaRef, resolveKataRefs } from "./kata.js";
5
- import { formatMarkdownFile } from "./exec-format.js";
6
- import { expandTemplate } from "./exec-shared.js";
7
- import { MISSING, applicableReviewCriteria, crossDeliverableTargetDetails, deliverableDependsOn, deliverableName, deliverableOverview, deliverablePath, doneCriteriaChecklist, doneCriteriaGoals, doneCriteriaItems, execDocId, findDeliverableInfo, frontmatter, gradeFindingsText, gradeFindingTargetPath, gradeResultRef, gradeTargetKind, implementationEvidence, injectCommonConventions, kataRefState, loadPlanTemplate, loadRoles, loadViewpoints, ownerRoleFields, phaseDescriptionText, projectContextSection, repoRelativePath, reviewDoneCriteriaRows, reviewGradeSummaryText, rulebookIncludesText, targetDocIds, targetDocIdsForTask, } from "./exec-plans-core.js";
8
- function buildEditPlanMarkdown(template, task, deliverable, roleMap, vpMap, projectId, catalogPath, projectContext, resultRef, stem, crossDeliverables = new Map()) {
3
+ import { DEFAULT_PROJECT_CONTEXT } from "../shared/specdojo-config.js";
4
+ import { resolveDeliverableSchemaRef, resolveKataRefs } from "../kata/kata.js";
5
+ import { formatMarkdownFile } from "./format.js";
6
+ import { expandTemplate } from "./shared.js";
7
+ import { MISSING, applicableReviewCriteria, crossDeliverableTargetDetails, deliverableDependsOn, deliverableName, deliverableOverview, deliverablePath, doneCriteriaChecklist, doneCriteriaGoals, doneCriteriaItems, execDocId, findDeliverableInfo, frontmatter, gradeFindingsText, gradeFindingTargetPath, gradeResultRef, gradeTargetKind, implementationEvidence, injectCommonConventions, kataRefState, loadPlanTemplate, loadRoles, loadViewpoints, ownerRoleFields, phaseDescriptionText, projectContextSection, repoRelativePath, reviewDoneCriteriaRows, reviewGradeSummaryText, rulebookIncludesText, targetDocIds, targetDocIdsForTask, } from "./plans-core.js";
8
+ function buildEditPlanMarkdown(template, task, deliverable, roleMap, vpMap, projectId, catalogPath, projectContext, resultRef, stem, crossDeliverables = new Map(), planOverrides) {
9
9
  const cpm = task.cpm;
10
10
  const onCriticalPath = cpm !== undefined && cpm.slack === 0;
11
- const targets = targetDocIdsForTask(projectId, task, deliverable, crossDeliverables);
11
+ const targets = planOverrides?.targets
12
+ ? [...planOverrides.targets]
13
+ : targetDocIdsForTask(projectId, task, deliverable, crossDeliverables);
12
14
  const meta = {
13
15
  id: execDocId(projectId, "xep", stem),
14
16
  type: "exec-plan",
@@ -18,6 +20,7 @@ function buildEditPlanMarkdown(template, task, deliverable, roleMap, vpMap, proj
18
20
  mode: "edit",
19
21
  status: "ready",
20
22
  project_id: projectId,
23
+ ...(planOverrides?.origin ? { origin: planOverrides.origin } : {}),
21
24
  ...(task.owner ? { owner: task.owner } : {}),
22
25
  ...(onCriticalPath ? { on_critical_path: true } : {}),
23
26
  ...(task.approach ? { approach: task.approach } : {}),
@@ -25,7 +28,8 @@ function buildEditPlanMarkdown(template, task, deliverable, roleMap, vpMap, proj
25
28
  };
26
29
  const criteria = deliverable?.deliverable.done_criteria ?? [];
27
30
  const ownerRole = ownerRoleFields(task.owner, roleMap, vpMap, deliverable?.deliverable.rulebook);
28
- const refs = resolveKataRefs(deliverable?.deliverable.rulebook, deliverable?.deliverable.kind);
31
+ const refs = planOverrides?.refs ??
32
+ resolveKataRefs(deliverable?.deliverable.rulebook, deliverable?.deliverable.kind);
29
33
  const values = {
30
34
  _FRONTMATTER_: frontmatter(meta),
31
35
  _TASK_ID_: task.id,
@@ -55,7 +59,20 @@ function buildEditPlanMarkdown(template, task, deliverable, roleMap, vpMap, proj
55
59
  _GRADE_FINDINGS_: gradeFindingsText(projectId, gradeFindingTargetPath(task.approach, deliverable, refs)),
56
60
  _TARGET_DELIVERABLES_: crossDeliverableTargetDetails(projectId, task.target_local_ids ?? [], crossDeliverables, catalogPath),
57
61
  };
58
- return expandTemplate(template, values);
62
+ const body = expandTemplate(template, values);
63
+ if (!planOverrides?.additionalConditions)
64
+ return body;
65
+ const section = [
66
+ "## 個票の追加完了条件",
67
+ "",
68
+ "成果物カタログの `done_criteria` に加え、登録簿の個票が定める次の条件も満たす。",
69
+ "",
70
+ planOverrides.additionalConditions.trim(),
71
+ "",
72
+ ].join("\n");
73
+ return body.includes("_COMMON_CONVENTIONS_")
74
+ ? body.replace("_COMMON_CONVENTIONS_", `${section}\n_COMMON_CONVENTIONS_`)
75
+ : `${body.trimEnd()}\n\n${section}`;
59
76
  }
60
77
  // review plan は成果物を再評価しない。grade の評価結果(サイドカー)の位置と完了条件を示し、
61
78
  // 評価結果を事実として受け取ってタスクの完了可否を判断させる(bps-task-completion)。
@@ -135,7 +152,7 @@ async function writeTaskPlan(ctx, task, override) {
135
152
  const template = loadPlanTemplate(mode, task.approach, ctx.templateCache);
136
153
  const body = mode === "review"
137
154
  ? buildReviewPlanMarkdown(template, planTask, deliverable, criteria, ctx.vpMap, ctx.projectId, ctx.catalogPath, ctx.projectContext, resultRef, stem, ctx.reviewGradeOutcome)
138
- : buildEditPlanMarkdown(template, planTask, deliverable, ctx.roleMap, ctx.vpMap, ctx.projectId, ctx.catalogPath, ctx.projectContext, resultRef, stem, crossDeliverables);
155
+ : buildEditPlanMarkdown(template, planTask, deliverable, ctx.roleMap, ctx.vpMap, ctx.projectId, ctx.catalogPath, ctx.projectContext, resultRef, stem, crossDeliverables, override);
139
156
  const schemaRef = resolveDeliverableSchemaRef(deliverable?.resolvedPath);
140
157
  const content = injectCommonConventions(body, schemaRef, ctx.templateCache, mode);
141
158
  writeFileSync(outPath, content, "utf8");
@@ -182,6 +199,32 @@ export async function generateDeliverablePlan(opts) {
182
199
  ...(opts.stem ? { stem: opts.stem } : {}),
183
200
  });
184
201
  }
202
+ // Register items with an approach use the same template and catalog/kata resolution as
203
+ // schedule tasks, while keeping register identity and target coverage in the plan metadata.
204
+ export async function generateRegisterApproachPlan(opts) {
205
+ const ctx = newPlanGenContext(opts);
206
+ const task = {
207
+ id: opts.taskId,
208
+ name: opts.title,
209
+ description: opts.description,
210
+ mode: "edit",
211
+ approach: opts.approach,
212
+ ...(opts.deliverable ? { local_id: opts.deliverable.deliverable.local_id } : {}),
213
+ ...(opts.owner ? { owner: opts.owner } : {}),
214
+ schedule_file: "",
215
+ fifo_rank: 0,
216
+ critical_first_rank: 0,
217
+ };
218
+ return await writeTaskPlan(ctx, task, {
219
+ deliverable: opts.deliverable ?? null,
220
+ origin: "register",
221
+ targets: opts.targets,
222
+ ...(opts.refs ? { refs: opts.refs } : {}),
223
+ additionalConditions: opts.additionalConditions,
224
+ ...(opts.outPath ? { outPath: opts.outPath } : {}),
225
+ stem: opts.stem,
226
+ });
227
+ }
185
228
  function newPlanGenContext(opts) {
186
229
  const plansDir = join(opts.executionPath, "exec", "plans");
187
230
  mkdirSync(plansDir, { recursive: true });
@@ -1,10 +1,10 @@
1
1
  import { existsSync, mkdirSync, readFileSync, renameSync, rmSync } from "node:fs";
2
2
  import { join, relative } from "node:path";
3
- import { specdojoRootDir } from "./specdojo-config.js";
4
- import { nowUtcIsoSeconds, randomHex, tsForFilenameUtc } from "./exec-shared.js";
5
- import { readSpecdojoNamespace } from "./frontmatter-namespace.js";
6
- import { gradeFindingDisplayMessage, gradeResultPathForDocument, readGradeResultForDocument, } from "./grade-result.js";
7
- import { lookupDocIndex } from "./doc-index.js";
3
+ import { specdojoRootDir } from "../shared/specdojo-config.js";
4
+ import { nowUtcIsoSeconds, randomHex, tsForFilenameUtc } from "./shared.js";
5
+ import { readSpecdojoNamespace } from "../docs/frontmatter-namespace.js";
6
+ import { gradeFindingDisplayMessage, gradeResultPathForDocument, readGradeResultForDocument, } from "../shared/grade-result.js";
7
+ import { lookupDocIndex } from "../docs/doc-index.js";
8
8
  export function archivePlan(opts) {
9
9
  const plansDir = join(opts.executionPath, "exec", "plans");
10
10
  const from = join(plansDir, `${opts.slug}-plan.md`);
@@ -1,3 +1,3 @@
1
- export { MISSING, applicableReviewCriteria, buildInPlaceStem, deliverableDocId, deliverableDocPath, execTemplatePath, execTemplatesDir, finalizeResultSectionsForDeliverable, injectCommonConventions, ownerRoleFields, resolveDeliverableTarget, reviewGradeSubject, stemFromPlanPath, targetDocIdsForDeliverable, targetDocIdsForScheduledTask, targetReferenceDirsForApproach, } from "./exec-plans-core.js";
2
- export { generateDeliverablePlan, generateSinglePlan } from "./exec-plans-generation.js";
3
- export { archivePlan, loadPlan, parsePlanTaskIdentity, planPathForTask, registerGradeFindingsText, } from "./exec-plans-storage.js";
1
+ export { MISSING, applicableReviewCriteria, buildInPlaceStem, deliverableDocId, deliverableDocPath, execTemplatePath, execTemplatesDir, finalizeResultSectionsForDeliverable, injectCommonConventions, ownerRoleFields, resolveDeliverableTarget, reviewGradeSubject, stemFromPlanPath, targetDocIdsForDeliverable, targetDocIdsForScheduledTask, targetReferenceDirsForApproach, } from "./plans-core.js";
2
+ export { generateDeliverablePlan, generateRegisterApproachPlan, generateSinglePlan, } from "./plans-generation.js";
3
+ export { archivePlan, loadPlan, parsePlanTaskIdentity, planPathForTask, registerGradeFindingsText, } from "./plans-storage.js";
@@ -1,5 +1,5 @@
1
1
  import { join, resolve } from "node:path";
2
- import { getProjectCatalogPath, getProjectContext, getProjectExecutionPath, getProjectRolesPath, getProjectSchedulePath, getProjectViewpointsPath, loadConfig, loadEnv, specdojoRootDir, } from "./specdojo-config.js";
2
+ import { getProjectCatalogPath, getProjectContext, getProjectExecutionPath, getProjectRolesPath, getProjectSchedulePath, getProjectViewpointsPath, loadConfig, loadEnv, specdojoRootDir, } from "../shared/specdojo-config.js";
3
3
  function projectBaseDir() {
4
4
  return specdojoRootDir();
5
5
  }
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
- import { stripTerminalControlSequences } from "./exec-shared.js";
3
- import { describeAgentProtectedConfigChanges, qualifiedRepoPaths, } from "./exec-agent-protected-config.js";
4
- import { describeAgentGitStateChanges, qualifiedGitStateFields, } from "./exec-agent-git-state.js";
2
+ import { stripTerminalControlSequences } from "./shared.js";
3
+ import { describeAgentProtectedConfigChanges, qualifiedRepoPaths, } from "./agent-protected-config.js";
4
+ import { describeAgentGitStateChanges, qualifiedGitStateFields, } from "./agent-git-state.js";
5
5
  // PJR-VH6R: 保護機構が agent の変更を止めたとき、規約は「対象・変更理由・提案差分・
6
6
  // 変更後に必要な検証」を result の申し送りへ書くことを求めている。しかし block は agent の
7
7
  // 記入を待たずに成立するため、実際には _TODO_ のまま残り、orchestrator が worktree の
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readdirSync } from "node:fs";
2
2
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
- import { loadPipelineResumeCheckpoint } from "./exec-pipeline-state.js";
4
- import { safeSlug } from "./exec-shared.js";
3
+ import { loadPipelineResumeCheckpoint } from "./pipeline-state.js";
4
+ import { safeSlug } from "./shared.js";
5
5
  function executorResumeHandoff(evidence) {
6
6
  if (!evidence)
7
7
  return [];
@@ -1,11 +1,15 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { join, relative } from "node:path";
3
- import { findRegisterItem, loadRegisterItems, PJR_ID_RE, resolveRegisterPaths, TERMINAL_STATUSES_SET, VALID_PRIORITIES, VALID_STATUSES, VALID_TYPES, } from "./register.js";
4
- import { execTemplatePath, injectCommonConventions, MISSING, registerGradeFindingsText, } from "./exec-plans.js";
5
- import { buildSpecdojoFrontmatter } from "./frontmatter-namespace.js";
6
- import { escapeMarkdownInline, expandTemplate, inlineCodeAnglePlaceholders, stripTerminalControlSequences, } from "./exec-shared.js";
7
- import { formatMarkdownFile } from "./exec-format.js";
8
- import { specdojoRootDir } from "./specdojo-config.js";
2
+ import { join, relative, resolve } from "node:path";
3
+ import { findRegisterItem, loadRegisterItems, PJR_ID_RE, resolveRegisterPaths, TERMINAL_STATUSES_SET, VALID_PRIORITIES, VALID_STATUSES, VALID_TYPES, } from "../register/register.js";
4
+ import { execTemplatePath, injectCommonConventions, MISSING, registerGradeFindingsText, } from "./plans.js";
5
+ import { generateRegisterApproachPlan } from "./plans-generation.js";
6
+ import { findUniqueDeliverableForKataTarget, resolveDeliverableByDocId, } from "./plans-core.js";
7
+ import { collectDocIndexEntries } from "../docs/doc-index.js";
8
+ import { resolveKataRefs } from "../kata/kata.js";
9
+ import { buildSpecdojoFrontmatter } from "../docs/frontmatter-namespace.js";
10
+ import { escapeMarkdownInline, expandTemplate, inlineCodeAnglePlaceholders, stripTerminalControlSequences, } from "./shared.js";
11
+ import { formatMarkdownFile } from "./format.js";
12
+ import { specdojoRootDir } from "../shared/specdojo-config.js";
9
13
  const EDIT_TYPES = new Set(["todo", "issue", "change-request"]);
10
14
  const INVESTIGATE_TYPES = new Set(["question", "risk"]);
11
15
  export function registerItemCategory(itemType) {
@@ -211,6 +215,12 @@ const REGISTER_PLAN_TEMPLATES = {
211
215
  edit: "xep-register-template.md",
212
216
  investigate: "xep-register-investigate-template.md",
213
217
  };
218
+ const MAINTENANCE_TARGET_KIND = {
219
+ "rulebook-maintenance": "rulebook",
220
+ "recipe-maintenance": "recipe",
221
+ "sample-maintenance": "sample",
222
+ "template-maintenance": "template",
223
+ };
214
224
  // Canonical repo-root-relative path (POSIX separators, no leading slash); mirrors the
215
225
  // convention used by exec-plans for agent-consumed paths.
216
226
  function repoRelativePath(absPath) {
@@ -246,9 +256,103 @@ function registerPlanFrontmatter(projectId, stem, item) {
246
256
  }
247
257
  return buildSpecdojoFrontmatter(inner);
248
258
  }
259
+ function registerCompletionConditions(item, ticketPath) {
260
+ if (ticketPath && existsSync(ticketPath)) {
261
+ const content = readFileSync(ticketPath, "utf8");
262
+ const body = content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "");
263
+ const lines = body.split(/\r?\n/);
264
+ const heading = lines.findIndex((line) => /^##\s+(?:\d+\.\s*)?完了条件\s*$/.test(line));
265
+ if (heading >= 0) {
266
+ const endOffset = lines.slice(heading + 1).findIndex((line) => /^##\s+/.test(line));
267
+ const end = endOffset >= 0 ? heading + 1 + endOffset : lines.length;
268
+ const conditions = lines
269
+ .slice(heading + 1, end)
270
+ .join("\n")
271
+ .trim();
272
+ if (conditions)
273
+ return conditions;
274
+ }
275
+ }
276
+ return item.description && item.description !== "_TODO_"
277
+ ? escapeMarkdownInline(item.description)
278
+ : "- 個票に明示的な完了条件がないため、タイトルと概要を追加条件として扱う。";
279
+ }
280
+ function registerAutopilotConstraints(item) {
281
+ if (item.autopilot !== "approved")
282
+ return "";
283
+ return [
284
+ "### 夜間 autopilot の制約",
285
+ "",
286
+ "この個票は人が記載済みの完了条件だけを承認した。次の操作は行わない。必要になった場合は、理由を result の申し送りへ記録して異常終了する。",
287
+ "",
288
+ "- decision の決定、保護された設定の変更、公開・tag・push。",
289
+ "- 公開済み CHANGELOG 節の変更、未承認項目の実行、完了条件や変更範囲の拡張。",
290
+ "- 別の登録項目を自分で実行すること。見つけた別問題は夜間 orchestrator が承認待ちとして起票する。",
291
+ "",
292
+ ].join("\n");
293
+ }
294
+ function indexedDocumentPath(targetId) {
295
+ const repoRoot = specdojoRootDir();
296
+ const indexed = collectDocIndexEntries(join(repoRoot, "docs"), repoRoot)[targetId];
297
+ if (!indexed) {
298
+ throw new Error(`Target document id is not resolvable via the document index: ${targetId}`);
299
+ }
300
+ const withoutLine = indexed.replace(/:\d+$/, "");
301
+ return relative(repoRoot, resolve(repoRoot, withoutLine)).replace(/\\/g, "/");
302
+ }
249
303
  export async function generateRegisterPlan(opts) {
250
304
  const { item } = opts;
251
305
  const category = requireRunnableRegisterItem(item);
306
+ const ticketPath = ticketPathFromItem(item, opts.registerPaths.projectRegisterPath);
307
+ if (item.approach) {
308
+ const [targetId] = item.targets ?? [];
309
+ if (!targetId || (item.targets?.length ?? 0) !== 1) {
310
+ throw new Error(`Register item ${item.id} approach requires exactly one target document id.`);
311
+ }
312
+ const maintenanceKind = MAINTENANCE_TARGET_KIND[item.approach];
313
+ let deliverable = null;
314
+ let refs;
315
+ if (maintenanceKind) {
316
+ deliverable = opts.catalogPath
317
+ ? findUniqueDeliverableForKataTarget(opts.catalogPath, targetId, maintenanceKind)
318
+ : null;
319
+ refs = deliverable
320
+ ? resolveKataRefs(deliverable.deliverable.rulebook, deliverable.deliverable.kind)
321
+ : { rulebook: MISSING, recipe: MISSING, sample: MISSING, template: MISSING };
322
+ refs = { ...refs, [maintenanceKind]: indexedDocumentPath(targetId) };
323
+ }
324
+ else {
325
+ if (!opts.catalogPath) {
326
+ throw new Error(`Register item ${item.id} approach requires catalog_path to resolve ${targetId}.`);
327
+ }
328
+ deliverable = resolveDeliverableByDocId(opts.catalogPath, opts.projectId, targetId).info;
329
+ }
330
+ const planPath = await generateRegisterApproachPlan({
331
+ executionPath: opts.executionPath,
332
+ projectId: opts.projectId,
333
+ catalogPath: opts.catalogPath ?? "",
334
+ ...(opts.rolesPath ? { rolesPath: opts.rolesPath } : {}),
335
+ ...(opts.viewpointsPath ? { viewpointsPath: opts.viewpointsPath } : {}),
336
+ ...(opts.projectContext ? { projectContext: opts.projectContext } : {}),
337
+ taskId: item.id,
338
+ title: item.title,
339
+ description: item.description,
340
+ ...(item.owner && item.owner !== "-" && item.owner !== "_TODO_" ? { owner: item.owner } : {}),
341
+ approach: item.approach,
342
+ targets: item.targets ?? [],
343
+ deliverable,
344
+ ...(refs ? { refs } : {}),
345
+ additionalConditions: [
346
+ registerCompletionConditions(item, ticketPath),
347
+ registerAutopilotConstraints(item),
348
+ ]
349
+ .filter(Boolean)
350
+ .join("\n\n"),
351
+ ...(opts.outPath ? { outPath: opts.outPath } : {}),
352
+ stem: opts.stem,
353
+ });
354
+ return { planPath, category };
355
+ }
252
356
  const templatePath = execTemplatePath(REGISTER_PLAN_TEMPLATES[category]);
253
357
  if (!existsSync(templatePath)) {
254
358
  throw new Error(`Template not found: ${templatePath}`);
@@ -258,7 +362,6 @@ export async function generateRegisterPlan(opts) {
258
362
  mkdirSync(plansDir, { recursive: true });
259
363
  const planPath = opts.outPath ?? join(plansDir, `${opts.stem}-plan.md`);
260
364
  const resultRef = `${repoRelativePath(opts.executionPath)}/exec/results/${opts.stem}-result.md`;
261
- const ticketPath = ticketPathFromItem(item, opts.registerPaths.projectRegisterPath);
262
365
  const values = {
263
366
  _FRONTMATTER_: registerPlanFrontmatter(opts.projectId, opts.stem, item),
264
367
  _PJR_ID_: item.id,
@@ -273,11 +376,13 @@ export async function generateRegisterPlan(opts) {
273
376
  _PJR_PRIORITY_: item.priority,
274
377
  _PJR_OWNER_: item.owner,
275
378
  _PJR_DUE_: item.due,
276
- _PJR_INDEX_PATH_: repoRelativePath(opts.registerPaths.pjrIndexPath),
277
379
  _PJR_TICKET_REF_: ticketPath ? `\`${repoRelativePath(ticketPath)}\`` : "-",
278
380
  _RESULT_REF_: resultRef,
279
381
  _GRADE_FINDINGS_: ticketPath ? registerGradeFindingsText(opts.projectId, ticketPath) : "- なし",
382
+ _AUTOPILOT_CONSTRAINTS_: registerAutopilotConstraints(item),
280
383
  };
384
+ // 空に展開される段落(夜間の承認の印がない個票の _AUTOPILOT_CONSTRAINTS_ など)で重なる空行は
385
+ // expandTemplate がまとめる(PJR-283N)。
281
386
  const body = expandTemplate(template, values);
282
387
  // register 項目は対象成果物の schema を特定できないため、schema 検査の項目は落とす。
283
388
  const content = injectCommonConventions(body, MISSING, new Map());
@@ -1,5 +1,5 @@
1
- import { gitOutput, gitResult } from "./exec-worktree.js";
2
- import { PROJECT_REPO_WORKTREE_DIRNAME } from "./specdojo-config.js";
1
+ import { gitOutput, gitResult } from "./worktree.js";
2
+ import { PROJECT_REPO_WORKTREE_DIRNAME } from "../shared/specdojo-config.js";
3
3
  /** Name under which the project repository is recorded in `stages.integrate.repos`. */
4
4
  export const PROJECT_REPO_NAME = PROJECT_REPO_WORKTREE_DIRNAME;
5
5
  export function zeroSeparated(cwd, args) {
@@ -1,8 +1,8 @@
1
1
  import { existsSync } from "node:fs";
2
- import { productIntegrationTarget } from "./exec-task-repos.js";
3
- import { abortMerge } from "./exec-worktree-ops.js";
4
- import { gitOutput, gitResult } from "./exec-worktree.js";
5
- import { PROJECT_REPO_NAME, branchExists, dirtyPaths, gitText, mergeInProgress, zeroSeparated, } from "./exec-repo-integration-git.js";
2
+ import { productIntegrationTarget } from "./task-repos.js";
3
+ import { abortMerge } from "./worktree-ops.js";
4
+ import { gitOutput, gitResult } from "./worktree.js";
5
+ import { PROJECT_REPO_NAME, branchExists, dirtyPaths, gitText, mergeInProgress, zeroSeparated, } from "./repo-integration-git.js";
6
6
  function isAncestor(cwd, ancestor, descendant) {
7
7
  return gitResult(cwd, ["merge-base", "--is-ancestor", ancestor, descendant]).status === 0;
8
8
  }
@@ -1,12 +1,12 @@
1
1
  import { appendFileSync, existsSync, mkdirSync } from "node:fs";
2
2
  import { dirname, resolve } from "node:path";
3
- import { acquireSchedulerLock, releaseSchedulerLock } from "./exec-events.js";
4
- import { productIntegrationTarget } from "./exec-task-repos.js";
5
- import { abortMerge, commitTargetPaths, isExecBranchMergedIntoCurrent, recordRootNewFilesHandoff, REGISTER_NEW_FILE_DIR_PREFIXES, repoRelative, stabilizeCommitTargets, stageCommitTargets, worktreeStatusPaths, } from "./exec-worktree-ops.js";
6
- import { appendGitFailureLog, gitOutput, gitResult, listRegisteredWorktrees, summarizeGitHookFailure, } from "./exec-worktree.js";
7
- import { resolveRepoQualifiedRef } from "./specdojo-config.js";
8
- import { PROJECT_REPO_NAME, branchExists, dirtyPaths, gitText, mergeInProgress, zeroSeparated, } from "./exec-repo-integration-git.js";
9
- export { PROJECT_REPO_NAME } from "./exec-repo-integration-git.js";
3
+ import { acquireSchedulerLock, releaseSchedulerLock } from "./events.js";
4
+ import { productIntegrationTarget } from "./task-repos.js";
5
+ import { abortMerge, commitTargetPaths, isExecBranchMergedIntoCurrent, recordRootNewFilesHandoff, REGISTER_NEW_FILE_DIR_PREFIXES, repoRelative, stabilizeCommitTargets, stageCommitTargets, worktreeStatusPaths, } from "./worktree-ops.js";
6
+ import { appendGitFailureLog, appendGitResultFailureLog, formatGitResultFailure, gitOutput, gitResult, listRegisteredWorktrees, summarizeGitHookFailure, } from "./worktree.js";
7
+ import { resolveRepoQualifiedRef } from "../shared/specdojo-config.js";
8
+ import { PROJECT_REPO_NAME, branchExists, dirtyPaths, gitText, mergeInProgress, zeroSeparated, } from "./repo-integration-git.js";
9
+ export { PROJECT_REPO_NAME } from "./repo-integration-git.js";
10
10
  // PJR-0WAA: 1 つのタスクがプロジェクトリポジトリと宣言済みのプロダクトリポジトリ(`repos`)を
11
11
  // 変更する場合の統合段。commit 対象の算出と commit はリポジトリごとに行い、統合の前に全リポジトリ
12
12
  // で merge 可否を確かめる。統合は宣言順にプロダクト、最後にプロジェクトの順で行い、リポジトリ別の
@@ -104,12 +104,15 @@ export function commitProductWorktree(product, params) {
104
104
  return { repo: product.name, targets, outOfScope, committed: false, rootNewFiles: [] };
105
105
  }
106
106
  stageCommitTargets(product.path, targets);
107
- const staged = gitResult(product.path, ["diff", "--cached", "--quiet", "--", ...targets]);
107
+ const stagedArgs = ["diff", "--cached", "--quiet", "--", ...targets];
108
+ const staged = gitResult(product.path, stagedArgs);
108
109
  if (staged.status === 0) {
109
110
  return { repo: product.name, targets, outOfScope, committed: false, rootNewFiles: [] };
110
111
  }
111
112
  if (staged.status !== 1) {
112
- throw new Error(`${product.name}: failed to inspect staged changes in ${product.path}`);
113
+ appendGitResultFailureLog(params.failureLogPath, `${product.name}: git diff staged-change inspection`, staged);
114
+ throw new Error(`${product.name}: failed to inspect staged changes in ${product.path}: ` +
115
+ formatGitResultFailure(stagedArgs, staged));
113
116
  }
114
117
  const commit = gitResult(product.path, ["commit", "-m", params.message, "--", ...targets]);
115
118
  if (commit.status !== 0) {
@@ -245,7 +248,7 @@ export function productMergeBlockers(product) {
245
248
  const target = productIntegrationTarget(product);
246
249
  if (target === "HEAD" || !branchExists(product.repoRoot, target)) {
247
250
  blockers.push(block(`integration branch ${target === "HEAD" ? "(detached HEAD)" : target} is not a local ` +
248
- `branch; set repos[].integration_branch`));
251
+ `branch; set repos[].integration_branch or exec run --integration-branch`));
249
252
  return blockers;
250
253
  }
251
254
  if (target === product.branch) {
@@ -391,7 +394,7 @@ export function mergeProductIntoTarget(params) {
391
394
  }
392
395
  return commit;
393
396
  }
394
- export { syncTaskWorktreesWithIntegrationTargets, syncWorktreeWithIntegrationTarget, } from "./exec-repo-integration-sync.js";
397
+ export { syncTaskWorktreesWithIntegrationTargets, syncWorktreeWithIntegrationTarget, } from "./repo-integration-sync.js";
395
398
  /** Integration failure that names the integrated and the remaining repositories. */
396
399
  export class RepoIntegrationError extends Error {
397
400
  repo;
@@ -1,7 +1,7 @@
1
1
  import { readFileSync, writeFileSync } from "node:fs";
2
- import { productMergeState } from "./exec-repo-integration.js";
3
- import { productIntegrationTarget } from "./exec-task-repos.js";
4
- import { gitOutput, gitResult } from "./exec-worktree.js";
2
+ import { productMergeState } from "./repo-integration.js";
3
+ import { productIntegrationTarget } from "./task-repos.js";
4
+ import { gitOutput, gitResult } from "./worktree.js";
5
5
  // PJR-30SW: プロダクト側の commit と merge commit へ付ける `Refs:` trailer と、統合後に result へ
6
6
  // 記録する trace 表。trace key は PJR-1SXK の決定どおり `<project-id>:<item-id>` とする。
7
7
  /** Heading text of the trace section the runner appends to the result. */
@@ -1,6 +1,6 @@
1
1
  import Ajv2020Module from "ajv/dist/2020.js";
2
- import { extractJsonText } from "./agent-response.js";
3
- import { REVIEW_VERDICTS, describeInvalidReviewVerdict, isReviewVerdict } from "./review-types.js";
2
+ import { extractJsonText } from "../shared/agent-response.js";
3
+ import { REVIEW_VERDICTS, describeInvalidReviewVerdict, isReviewVerdict } from "../review/types.js";
4
4
  export const MAX_TEXT_LENGTH = 4_000;
5
5
  // review の verdict の正本は review-types.ts であり、verdict_definitions と同じ語彙を使う。
6
6
  export { REVIEW_VERDICTS };