specdojo 0.3.0 → 0.4.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 (245) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +77 -18
  3. package/dist/catalog/build-references.js +144 -0
  4. package/dist/catalog/build-render.js +32 -0
  5. package/dist/{catalog-build.js → catalog/build.js} +18 -295
  6. package/dist/{catalog.js → catalog/catalog.js} +11 -11
  7. package/dist/{catalog-generate.js → catalog/generate.js} +13 -16
  8. package/dist/catalog/paths.js +1 -0
  9. package/dist/{catalog-plan-generate.js → catalog/plan-generate.js} +5 -5
  10. package/dist/{catalog-plan.js → catalog/plan.js} +9 -9
  11. package/dist/{catalog-scaffold.js → catalog/scaffold.js} +6 -6
  12. package/dist/{agent.js → commands/agent.js} +11 -11
  13. package/dist/{build-command.js → commands/build.js} +2 -2
  14. package/dist/{init-command.js → commands/init.js} +103 -37
  15. package/dist/{orchestrator.js → commands/orchestrator.js} +2 -2
  16. package/dist/{watch.js → commands/watch.js} +3 -3
  17. package/dist/dashboard/dashboard-timeline.js +175 -0
  18. package/dist/{dashboard.js → dashboard/dashboard.js} +16 -549
  19. package/dist/dashboard/exec-records.js +105 -0
  20. package/dist/dashboard/routines.js +256 -0
  21. package/dist/dashboard/shared.js +14 -0
  22. package/dist/{timeline-build.js → dashboard/timeline-build.js} +2 -1
  23. package/dist/{timeline.js → dashboard/timeline.js} +1 -1
  24. package/dist/{deliverable.js → deliverable/deliverable.js} +5 -5
  25. package/dist/{deliverable-trash.js → deliverable/trash.js} +7 -7
  26. package/dist/{devcontainer-command.js → devcontainer/command.js} +5 -3
  27. package/dist/{devcontainer-scaffold.js → devcontainer/scaffold.js} +94 -2
  28. package/dist/{doc-index.js → docs/doc-index.js} +3 -3
  29. package/dist/{frontmatter-namespace.js → docs/frontmatter-namespace.js} +2 -2
  30. package/dist/{index-command.js → docs/index-command.js} +1 -1
  31. package/dist/docs/template-resolution.js +1 -0
  32. package/dist/{viewpoint-document-kinds-check.js → docs/viewpoint-document-kinds-check.js} +3 -3
  33. package/dist/{yaml-pages-command.js → docs/yaml-pages-command.js} +1 -1
  34. package/dist/{yaml-pages.js → docs/yaml-pages.js} +5 -5
  35. package/dist/{exec-agent-config.js → exec/agent-config.js} +33 -4
  36. package/dist/{exec-agent-git-state.js → exec/agent-git-state.js} +1 -1
  37. package/dist/{exec-agent-protected-config.js → exec/agent-protected-config.js} +1 -1
  38. package/dist/{exec.js → exec/commands.js} +22 -467
  39. package/dist/exec/core.js +457 -0
  40. package/dist/{exec-events.js → exec/events.js} +2 -2
  41. package/dist/{exec-evidence.js → exec/evidence.js} +11 -6
  42. package/dist/exec/exec.js +2 -0
  43. package/dist/exec/format.js +1 -0
  44. package/dist/{exec-handoff.js → exec/handoff.js} +13 -12
  45. package/dist/{exec-limit.js → exec/limit.js} +93 -12
  46. package/dist/{exec-parent-validation.js → exec/parent-validation.js} +4 -4
  47. package/dist/{exec-pipeline-state.js → exec/pipeline-state.js} +16 -2
  48. package/dist/{exec-plans.js → exec/plans-core.js} +97 -468
  49. package/dist/exec/plans-generation.js +249 -0
  50. package/dist/exec/plans-storage.js +131 -0
  51. package/dist/exec/plans.js +3 -0
  52. package/dist/{exec-project.js → exec/project.js} +1 -1
  53. package/dist/{exec-protection-handoff.js → exec/protection-handoff.js} +3 -3
  54. package/dist/{exec-register-resume.js → exec/register-resume.js} +2 -2
  55. package/dist/{exec-register.js → exec/register.js} +92 -9
  56. package/dist/exec/repo-integration-git.js +23 -0
  57. package/dist/exec/repo-integration-sync.js +264 -0
  58. package/dist/{exec-repo-integration.js → exec/repo-integration.js} +13 -287
  59. package/dist/{exec-repo-trace.js → exec/repo-trace.js} +3 -3
  60. package/dist/exec/reporter-output.js +206 -0
  61. package/dist/{exec-reporter.js → exec/reporter.js} +29 -216
  62. package/dist/{exec-results.js → exec/results.js} +277 -36
  63. package/dist/exec/run/agent-pipeline.js +276 -0
  64. package/dist/exec/run/agent.js +583 -0
  65. package/dist/exec/run/in-place.js +570 -0
  66. package/dist/exec/run/job.js +746 -0
  67. package/dist/exec/run/lifecycle-commands.js +530 -0
  68. package/dist/{exec-run-lock.js → exec/run/lock.js} +4 -3
  69. package/dist/exec/run/mode-shared.js +140 -0
  70. package/dist/exec/run/register-command.js +252 -0
  71. package/dist/exec/run/register-core.js +411 -0
  72. package/dist/exec/run/register-mode.js +210 -0
  73. package/dist/exec/run/register-resume.js +398 -0
  74. package/dist/exec/run/register-state.js +325 -0
  75. package/dist/exec/run/register-worktree.js +540 -0
  76. package/dist/exec/run/run.js +11 -0
  77. package/dist/exec/run/schedule-mode.js +294 -0
  78. package/dist/exec/run/schedule-prepare.js +366 -0
  79. package/dist/exec/run/schedule-task.js +599 -0
  80. package/dist/exec/run/shared.js +449 -0
  81. package/dist/{exec-schedule-calendar.js → exec/schedule/calendar.js} +1 -1
  82. package/dist/{exec-schedule-cpm.js → exec/schedule/cpm.js} +2 -2
  83. package/dist/{exec-schedule-gantt-chart-render.js → exec/schedule/gantt-chart-render.js} +2 -2
  84. package/dist/exec/schedule/gantt-chart.js +2 -0
  85. package/dist/{exec-schedule-hash.js → exec/schedule/hash.js} +2 -2
  86. package/dist/exec/schedule/index.js +1 -0
  87. package/dist/{exec-schedule-initial.js → exec/schedule/initial.js} +2 -2
  88. package/dist/{exec-schedule-progress.js → exec/schedule/progress.js} +2 -2
  89. package/dist/{exec-schedule-ready.js → exec/schedule/ready.js} +2 -2
  90. package/dist/{exec-schedule.js → exec/schedule/schedule.js} +11 -11
  91. package/dist/exec/shared.js +63 -0
  92. package/dist/exec/slot-lock.js +1 -0
  93. package/dist/{exec-strategy.js → exec/strategy.js} +2 -2
  94. package/dist/{exec-task-repos.js → exec/task-repos.js} +2 -2
  95. package/dist/{exec-task-view.js → exec/task-view.js} +4 -4
  96. package/dist/{exec-trial.js → exec/trial-commands.js} +23 -388
  97. package/dist/exec/trial-core.js +371 -0
  98. package/dist/exec/trial.js +2 -0
  99. package/dist/{exec-worktree-command.js → exec/worktree-command.js} +25 -23
  100. package/dist/exec/worktree-ops-commit.js +672 -0
  101. package/dist/exec/worktree-ops-lifecycle.js +297 -0
  102. package/dist/exec/worktree-ops-merge.js +344 -0
  103. package/dist/exec/worktree-ops.js +3 -0
  104. package/dist/exec/worktree.js +305 -0
  105. package/dist/grade/apply.js +734 -0
  106. package/dist/grade/command-apply.js +250 -0
  107. package/dist/grade/command-inspect.js +138 -0
  108. package/dist/grade/command-plan.js +101 -0
  109. package/dist/grade/command-shared.js +68 -0
  110. package/dist/grade/core.js +307 -0
  111. package/dist/grade/grade.js +19 -0
  112. package/dist/grade/markdown.js +274 -0
  113. package/dist/grade/pipeline-state.js +184 -0
  114. package/dist/grade/plan.js +507 -0
  115. package/dist/{grade-result.js → grade/result.js} +7 -96
  116. package/dist/grade/target-discovery.js +265 -0
  117. package/dist/grade/targets.js +435 -0
  118. package/dist/{job.js → job/definition.js} +32 -574
  119. package/dist/job/job.js +568 -0
  120. package/dist/{kata-command.js → kata/command.js} +4 -4
  121. package/dist/{kata.js → kata/kata.js} +5 -5
  122. package/dist/register/approach.js +134 -0
  123. package/dist/register/command-types.js +1 -0
  124. package/dist/register/core.js +369 -0
  125. package/dist/register/create-commands.js +352 -0
  126. package/dist/{register-date.js → register/date.js} +1 -1
  127. package/dist/register/derivation.js +163 -0
  128. package/dist/{register-event-merge.js → register/event-merge.js} +32 -3
  129. package/dist/{register-events.js → register/events.js} +12 -6
  130. package/dist/{register-history.js → register/history.js} +7 -6
  131. package/dist/{register-item.js → register/item.js} +28 -10
  132. package/dist/register/lifecycle-lock.js +5 -0
  133. package/dist/register/maintenance-commands.js +193 -0
  134. package/dist/{register-migrate-timestamps.js → register/migrate-timestamps.js} +3 -3
  135. package/dist/register/migration.js +268 -0
  136. package/dist/register/register.js +404 -0
  137. package/dist/register/renumber.js +341 -0
  138. package/dist/register/transition-commands.js +248 -0
  139. package/dist/register/update.js +230 -0
  140. package/dist/register/views.js +296 -0
  141. package/dist/{review-grade.js → review/grade.js} +2 -2
  142. package/dist/{review-plan.js → review/plan.js} +5 -5
  143. package/dist/routine/definition.js +401 -0
  144. package/dist/{routine.js → routine/routine.js} +50 -419
  145. package/dist/{schedule-approach.js → schedule/approach.js} +9 -9
  146. package/dist/{schedule-build.js → schedule/build.js} +7 -4
  147. package/dist/{schedule.js → schedule/schedule.js} +9 -9
  148. package/dist/schedule/strategy-generate-document.js +273 -0
  149. package/dist/schedule/strategy-generate-scope.js +199 -0
  150. package/dist/schedule/strategy-generate.js +348 -0
  151. package/dist/shared/agent-types.js +23 -0
  152. package/dist/shared/artifact-path.js +9 -0
  153. package/dist/{build-if-stale.js → shared/build-if-stale.js} +1 -1
  154. package/dist/shared/catalog-render.js +115 -0
  155. package/dist/{exec-slot-lock.js → shared/cross-process-lock.js} +3 -1
  156. package/dist/shared/fs.js +30 -0
  157. package/dist/shared/git.js +316 -0
  158. package/dist/shared/grade-result.js +94 -0
  159. package/dist/{package-paths.js → shared/package-paths.js} +3 -3
  160. package/dist/shared/plan-templates.js +114 -0
  161. package/dist/{exec-provider-scaffold.js → shared/provider-scaffold.js} +3 -1
  162. package/dist/shared/random.js +4 -0
  163. package/dist/{exec-schedule-index.js → shared/schedule-index.js} +3 -1
  164. package/dist/shared/schedule-paths.js +9 -0
  165. package/dist/{specdojo-config.js → shared/specdojo-config.js} +96 -9
  166. package/dist/{exec-shared.js → shared/text.js} +0 -134
  167. package/dist/shared/time.js +28 -0
  168. package/dist/shared/yaml.js +28 -0
  169. package/dist/specdojo.js +22 -22
  170. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +29 -17
  171. package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +1 -2
  172. package/docs/ja/specdojo/exec-templates/xep-register-template.md +1 -2
  173. package/docs/ja/specdojo/exec-templates/xer-template.md +1 -3
  174. package/docs/ja/specdojo/exec-templates/xrp-job-template.md +6 -4
  175. package/docs/ja/specdojo/guides/exec-config-guide.md +97 -22
  176. package/docs/ja/specdojo/guides/exec-operation-guide.md +145 -12
  177. package/docs/ja/specdojo/guides/exec-worktree-guide.md +2 -0
  178. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +51 -18
  179. package/docs/ja/specdojo/guides/quick-start-guide.md +81 -16
  180. package/docs/ja/specdojo/guides/register-operation-guide.md +2 -1
  181. package/docs/ja/specdojo/guides/remote-host-development-guide.md +10 -1
  182. package/docs/ja/specdojo/guides/review-guide.md +1 -1
  183. package/docs/ja/specdojo/guides/routine-operation-guide.md +6 -6
  184. package/docs/ja/specdojo/guides/use-case-guide.md +1 -1
  185. package/docs/ja/specdojo/references/command-reference.md +52 -28
  186. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +17 -11
  187. package/docs/ja/specdojo/standards/job-definition-standard.md +20 -18
  188. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +2 -2
  189. package/docs/ja/specdojo/templates/pjr-derived-items-template.md +22 -0
  190. package/docs/ja/specdojo/templates/pjr-index-template.md +1 -0
  191. package/docs/specdojo/schemas/v1/agent-members.schema.yaml +29 -2
  192. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +20 -0
  193. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +23 -0
  194. package/docs/specdojo/schemas/v1/job-run.schema.yaml +2 -2
  195. package/docs/specdojo/schemas/v1/job.schema.yaml +7 -0
  196. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +26 -0
  197. package/docs/specdojo/schemas/v1/register-events.schema.yaml +3 -0
  198. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +70 -7
  199. package/docs/specdojo/schemas/v1/routine-run.schema.yaml +1 -1
  200. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +1 -1
  201. package/package.json +4 -5
  202. package/templates/antigravity/README.md +7 -3
  203. package/templates/antigravity/agent-members-snippet.yaml +108 -12
  204. package/templates/antigravity/exec-defaults-snippet.yaml +10 -13
  205. package/templates/claude/README.md +27 -3
  206. package/templates/claude/agents/claude-executor.md +0 -1
  207. package/templates/claude/agents/claude-reporter.md +2 -1
  208. package/templates/claude/agents/claude-review-executor.md +0 -1
  209. package/templates/codex/README.md +23 -4
  210. package/templates/devcontainer/devcontainer.json +2 -2
  211. package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +69 -0
  212. package/templates/devcontainer/remote-host/ssh-config.sample +16 -0
  213. package/templates/init-agent-members.yaml +75 -25
  214. package/templates/init-exec-defaults.yaml +26 -8
  215. package/templates/opencode/README.md +17 -3
  216. package/templates/opencode/agents/opencode-executor.md +0 -1
  217. package/templates/opencode/agents/opencode-reporter.md +2 -1
  218. package/templates/opencode/agents/opencode-review-executor.md +0 -1
  219. package/dist/exec-run.js +0 -6182
  220. package/dist/exec-schedule-gantt-chart.js +0 -2
  221. package/dist/exec-worktree-ops.js +0 -1292
  222. package/dist/exec-worktree.js +0 -446
  223. package/dist/grade.js +0 -3193
  224. package/dist/register.js +0 -2407
  225. package/dist/schedule-strategy-generate.js +0 -812
  226. package/templates/claude/agents/claude-expert-review-executor.md +0 -14
  227. /package/dist/{catalog-plan-prompt.js → catalog/plan-prompt.js} +0 -0
  228. /package/dist/{catalog-types.js → catalog/types.js} +0 -0
  229. /package/dist/{template-frontmatter.js → docs/template-frontmatter.js} +0 -0
  230. /package/dist/{role-types.js → exec/role-types.js} +0 -0
  231. /package/dist/{exec-schedule-gantt-chart-scope.js → exec/schedule/gantt-chart-scope.js} +0 -0
  232. /package/dist/{exec-types.js → exec/types.js} +0 -0
  233. /package/dist/{review-types.js → review/types.js} +0 -0
  234. /package/dist/{schedule-phase-sets.js → schedule/phase-sets.js} +0 -0
  235. /package/dist/{schedule-strategy-profiles.js → schedule/strategy-profiles.js} +0 -0
  236. /package/dist/{agent-response.js → shared/agent-response.js} +0 -0
  237. /package/dist/{catalog-paths.js → shared/catalog-paths.js} +0 -0
  238. /package/dist/{dist-freshness.js → shared/dist-freshness.js} +0 -0
  239. /package/dist/{git-environment.js → shared/git-environment.js} +0 -0
  240. /package/dist/{exec-format.js → shared/markdown-format.js} +0 -0
  241. /package/dist/{practice-id.js → shared/practice-id.js} +0 -0
  242. /package/dist/{spawn-self.js → shared/spawn-self.js} +0 -0
  243. /package/dist/{specdojo-gitignore.js → shared/specdojo-gitignore.js} +0 -0
  244. /package/dist/{template-resolution.js → shared/template-resolution.js} +0 -0
  245. /package/dist/{yaml-schema-modeline.js → shared/yaml-schema-modeline.js} +0 -0
@@ -0,0 +1,249 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
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
+ const cpm = task.cpm;
10
+ const onCriticalPath = cpm !== undefined && cpm.slack === 0;
11
+ const targets = planOverrides?.targets
12
+ ? [...planOverrides.targets]
13
+ : targetDocIdsForTask(projectId, task, deliverable, crossDeliverables);
14
+ const meta = {
15
+ id: execDocId(projectId, "xep", stem),
16
+ type: "exec-plan",
17
+ rulebook: "none",
18
+ task_id: task.id,
19
+ ...(task.name ? { name: task.name } : {}),
20
+ mode: "edit",
21
+ status: "ready",
22
+ project_id: projectId,
23
+ ...(planOverrides?.origin ? { origin: planOverrides.origin } : {}),
24
+ ...(task.owner ? { owner: task.owner } : {}),
25
+ ...(onCriticalPath ? { on_critical_path: true } : {}),
26
+ ...(task.approach ? { approach: task.approach } : {}),
27
+ ...(targets.length > 0 ? { targets } : {}),
28
+ };
29
+ const criteria = deliverable?.deliverable.done_criteria ?? [];
30
+ const ownerRole = ownerRoleFields(task.owner, roleMap, vpMap, deliverable?.deliverable.rulebook);
31
+ const refs = planOverrides?.refs ??
32
+ resolveKataRefs(deliverable?.deliverable.rulebook, deliverable?.deliverable.kind);
33
+ const values = {
34
+ _FRONTMATTER_: frontmatter(meta),
35
+ _TASK_ID_: task.id,
36
+ _PHASE_DESCRIPTION_: phaseDescriptionText(task),
37
+ _DELIVERABLE_NAME_: deliverableName(deliverable),
38
+ _DELIVERABLE_DEPENDS_ON_: deliverableDependsOn(deliverable, projectId, catalogPath),
39
+ _PROJECT_CONTEXT_: projectContextSection(projectContext, deliverable, task.approach, projectId),
40
+ _DELIVERABLE_OVERVIEW_: deliverableOverview(deliverable),
41
+ _IMPLEMENTATION_EVIDENCE_: implementationEvidence(deliverable),
42
+ _DELIVERABLE_PATH_: deliverablePath(deliverable),
43
+ _RESULT_REF_: resultRef,
44
+ _RULEBOOK_REF_: refs.rulebook,
45
+ _RULEBOOK_STATE_: kataRefState(refs.rulebook),
46
+ _RULEBOOK_INCLUDES_: rulebookIncludesText(deliverable?.deliverable.rulebook, deliverable?.deliverable.kind),
47
+ _RECIPE_REF_: refs.recipe,
48
+ _RECIPE_STATE_: kataRefState(refs.recipe),
49
+ _SAMPLE_REF_: refs.sample,
50
+ _SAMPLE_STATE_: kataRefState(refs.sample),
51
+ _TEMPLATE_REF_: refs.template,
52
+ _TEMPLATE_STATE_: kataRefState(refs.template),
53
+ _OWNER_ROLE_LABEL_: ownerRole.label,
54
+ _OWNER_ROLE_NOTE_: ownerRole.note,
55
+ _OWNER_ROLE_VIEWPOINTS_: ownerRole.viewpoints,
56
+ _DONE_CRITERIA_GOALS_: doneCriteriaGoals(criteria, task.owner),
57
+ _DONE_CRITERIA_CHECKLIST_: doneCriteriaChecklist(criteria),
58
+ _DONE_CRITERIA_ITEMS_: doneCriteriaItems(criteria),
59
+ _GRADE_FINDINGS_: gradeFindingsText(projectId, gradeFindingTargetPath(task.approach, deliverable, refs)),
60
+ _TARGET_DELIVERABLES_: crossDeliverableTargetDetails(projectId, task.target_local_ids ?? [], crossDeliverables, catalogPath),
61
+ };
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}`;
76
+ }
77
+ // review plan は成果物を再評価しない。grade の評価結果(サイドカー)の位置と完了条件を示し、
78
+ // 評価結果を事実として受け取ってタスクの完了可否を判断させる(bps-task-completion)。
79
+ function buildReviewPlanMarkdown(template, task, deliverable, criteria, vpMap, projectId, catalogPath, projectContext, resultRef, stem, reviewGradeOutcome) {
80
+ const cpm = task.cpm;
81
+ const onCriticalPath = cpm !== undefined && cpm.slack === 0;
82
+ const targets = targetDocIds(projectId, deliverable, task.approach, task.local_id);
83
+ const meta = {
84
+ id: execDocId(projectId, "xrp", stem),
85
+ type: "exec-plan",
86
+ rulebook: "none",
87
+ task_id: task.id,
88
+ ...(task.name ? { name: task.name } : {}),
89
+ mode: "review",
90
+ status: "ready",
91
+ project_id: projectId,
92
+ ...(task.owner ? { owner: task.owner } : {}),
93
+ ...(onCriticalPath ? { on_critical_path: true } : {}),
94
+ ...(task.approach ? { approach: task.approach } : {}),
95
+ ...(targets.length > 0 ? { targets } : {}),
96
+ };
97
+ const refs = resolveKataRefs(deliverable?.deliverable.rulebook, deliverable?.deliverable.kind);
98
+ const applicableCriteria = applicableReviewCriteria(criteria, vpMap, deliverable?.deliverable.rulebook);
99
+ const gradeSubjectPath = gradeFindingTargetPath(task.approach, deliverable, refs);
100
+ const values = {
101
+ _FRONTMATTER_: frontmatter(meta),
102
+ _TASK_ID_: task.id,
103
+ _PHASE_DESCRIPTION_: phaseDescriptionText(task),
104
+ _DELIVERABLE_NAME_: deliverableName(deliverable),
105
+ _DELIVERABLE_DEPENDS_ON_: deliverableDependsOn(deliverable, projectId, catalogPath),
106
+ _PROJECT_CONTEXT_: projectContextSection(projectContext, deliverable, task.approach, projectId),
107
+ _DELIVERABLE_OVERVIEW_: deliverableOverview(deliverable),
108
+ _IMPLEMENTATION_EVIDENCE_: implementationEvidence(deliverable),
109
+ _DELIVERABLE_PATH_: deliverablePath(deliverable),
110
+ _RESULT_REF_: resultRef,
111
+ _RULEBOOK_REF_: refs.rulebook,
112
+ _RULEBOOK_INCLUDES_: rulebookIncludesText(deliverable?.deliverable.rulebook, deliverable?.deliverable.kind),
113
+ _RECIPE_REF_: refs.recipe,
114
+ _SAMPLE_REF_: refs.sample,
115
+ _TEMPLATE_REF_: refs.template,
116
+ _GRADE_SUBJECT_PATH_: gradeSubjectPath,
117
+ _GRADE_TARGET_: gradeTargetKind(task.approach),
118
+ _GRADE_RESULT_PATH_: gradeResultRef(projectId, gradeSubjectPath),
119
+ _GRADE_SUMMARY_: reviewGradeSummaryText(projectId, gradeSubjectPath, reviewGradeOutcome),
120
+ _DONE_CRITERIA_ROWS_: reviewDoneCriteriaRows(applicableCriteria),
121
+ };
122
+ return expandTemplate(template, values);
123
+ }
124
+ async function writeTaskPlan(ctx, task, override) {
125
+ const mode = task.mode ?? "edit";
126
+ const localId = task.local_id;
127
+ const targetLocalIds = [...new Set(task.target_local_ids ?? [])];
128
+ const crossDeliverables = new Map();
129
+ for (const targetLocalId of targetLocalIds) {
130
+ const info = ctx.catalogPath ? findDeliverableInfo(ctx.catalogPath, targetLocalId) : null;
131
+ if (info)
132
+ crossDeliverables.set(targetLocalId, info);
133
+ }
134
+ const deliverable = override?.deliverable !== undefined
135
+ ? override.deliverable
136
+ : localId && ctx.catalogPath
137
+ ? findDeliverableInfo(ctx.catalogPath, localId)
138
+ : null;
139
+ // The stem links a plan to its result (both share `<stem>-{plan,result}.md` and the doc id).
140
+ // Defaults to the task id (fixed-name worktree/claim flow); in-place callers pass a unique stem.
141
+ const stem = override?.stem ?? task.id;
142
+ const resultRef = `${repoRelativePath(ctx.executionPath)}/exec/results/${stem}-result.md`;
143
+ const outPath = override?.outPath ?? join(ctx.plansDir, `${stem}-plan.md`);
144
+ const criteria = deliverable?.deliverable.done_criteria ?? [];
145
+ if ((task.execution ?? "agent") === "human") {
146
+ throw new Error(`Task ${task.id} has execution: human; claim it to create and use its result instead of a plan.`);
147
+ }
148
+ const planTask = { ...task, mode };
149
+ if (task.approach === "retrofit" && implementationEvidence(deliverable) === MISSING) {
150
+ throw new Error(`Task ${task.id} uses approach: retrofit but the target deliverable has no evidence_refs.`);
151
+ }
152
+ const template = loadPlanTemplate(mode, task.approach, ctx.templateCache);
153
+ const body = mode === "review"
154
+ ? buildReviewPlanMarkdown(template, planTask, deliverable, criteria, ctx.vpMap, ctx.projectId, ctx.catalogPath, ctx.projectContext, resultRef, stem, ctx.reviewGradeOutcome)
155
+ : buildEditPlanMarkdown(template, planTask, deliverable, ctx.roleMap, ctx.vpMap, ctx.projectId, ctx.catalogPath, ctx.projectContext, resultRef, stem, crossDeliverables, override);
156
+ const schemaRef = resolveDeliverableSchemaRef(deliverable?.resolvedPath);
157
+ const content = injectCommonConventions(body, schemaRef, ctx.templateCache, mode);
158
+ writeFileSync(outPath, content, "utf8");
159
+ await formatMarkdownFile(outPath);
160
+ return outPath;
161
+ }
162
+ // Generate the plan for a single agent task without touching other plan files,
163
+ // the index, or task state. Human tasks are result-only and are rejected here.
164
+ export async function generateSinglePlan(opts) {
165
+ if ((opts.task.execution ?? "agent") === "human") {
166
+ throw new Error(`Task ${opts.task.id} has execution: human; claim it to create and use its result instead of a plan.`);
167
+ }
168
+ const ctx = newPlanGenContext(opts);
169
+ if (opts.reviewGradeOutcome)
170
+ ctx.reviewGradeOutcome = opts.reviewGradeOutcome;
171
+ const override = opts.outPath || opts.stem
172
+ ? {
173
+ ...(opts.outPath ? { outPath: opts.outPath } : {}),
174
+ ...(opts.stem ? { stem: opts.stem } : {}),
175
+ }
176
+ : undefined;
177
+ return await writeTaskPlan(ctx, { ...opts.task, mode: opts.task.mode ?? "edit" }, override);
178
+ }
179
+ // Generate a plan directly from a catalog deliverable, independent of the
180
+ // schedule. The slug (`<domain>-<local_id>`) names the plan unless `outPath`
181
+ // overrides it. CPM is absent for ad-hoc targets; owner is absent unless the
182
+ // caller resolves it (e.g. from sch-strategy owner_rules via a track).
183
+ export async function generateDeliverablePlan(opts) {
184
+ const ctx = newPlanGenContext(opts);
185
+ const task = {
186
+ id: opts.target.slug,
187
+ local_id: opts.target.localId,
188
+ name: opts.target.info.deliverable.name,
189
+ mode: opts.mode ?? "edit",
190
+ ...(opts.approach ? { approach: opts.approach } : {}),
191
+ ...(opts.owner ? { owner: opts.owner } : {}),
192
+ schedule_file: "",
193
+ fifo_rank: 0,
194
+ critical_first_rank: 0,
195
+ };
196
+ return await writeTaskPlan(ctx, task, {
197
+ deliverable: opts.target.info,
198
+ ...(opts.outPath ? { outPath: opts.outPath } : {}),
199
+ ...(opts.stem ? { stem: opts.stem } : {}),
200
+ });
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
+ }
228
+ function newPlanGenContext(opts) {
229
+ const plansDir = join(opts.executionPath, "exec", "plans");
230
+ mkdirSync(plansDir, { recursive: true });
231
+ return {
232
+ plansDir,
233
+ executionPath: opts.executionPath,
234
+ projectId: opts.projectId,
235
+ catalogPath: opts.catalogPath,
236
+ vpMap: opts.viewpointsPath
237
+ ? loadViewpoints(opts.viewpointsPath)
238
+ : new Map(),
239
+ roleMap: loadRoles(opts.rolesPath),
240
+ projectContext: [
241
+ ...(opts.projectContext ??
242
+ (opts.projectId ? DEFAULT_PROJECT_CONTEXT : [])),
243
+ ],
244
+ templateCache: new Map(),
245
+ };
246
+ }
247
+ // Move a completed plan to exec/plans/done/ with a unique UTC + random suffix
248
+ // (same convention as event filenames), or delete it. The plan is regenerable
249
+ // from the catalog, so deletion is safe; the result remains as the record.
@@ -0,0 +1,131 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync } from "node:fs";
2
+ import { join, relative } from "node:path";
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
+ export function archivePlan(opts) {
9
+ const plansDir = join(opts.executionPath, "exec", "plans");
10
+ const from = join(plansDir, `${opts.slug}-plan.md`);
11
+ if (!existsSync(from))
12
+ throw new Error(`plan not found: ${from}`);
13
+ if (opts.delete) {
14
+ rmSync(from, { force: true });
15
+ return { from, deleted: true };
16
+ }
17
+ const doneDir = join(plansDir, "done");
18
+ mkdirSync(doneDir, { recursive: true });
19
+ const stamp = tsForFilenameUtc(nowUtcIsoSeconds());
20
+ const to = join(doneDir, `${opts.slug}-${stamp}-${randomHex(2)}-plan.md`);
21
+ renameSync(from, to);
22
+ return { from, to, deleted: false };
23
+ }
24
+ export function planPathForTask(executionPath, taskId) {
25
+ return join(executionPath, "exec", "plans", `${taskId}-plan.md`);
26
+ }
27
+ export function loadPlan(executionPath, taskId) {
28
+ const planPath = planPathForTask(executionPath, taskId);
29
+ if (existsSync(planPath))
30
+ return readFileSync(planPath, "utf8");
31
+ return null;
32
+ }
33
+ const PLAN_APPROACHES = [
34
+ "fully-guided",
35
+ "recipe-guided",
36
+ "freeform",
37
+ "bootstrap",
38
+ "retrofit",
39
+ "cross-deliverable-dedup",
40
+ "rulebook-maintenance",
41
+ "recipe-maintenance",
42
+ "sample-maintenance",
43
+ "template-maintenance",
44
+ "finalize",
45
+ "bootstrap-finalize",
46
+ ];
47
+ // Parse an exec-plan file's frontmatter to recover the task identity. Returns
48
+ // null when the frontmatter is missing or has no usable task_id, in which case
49
+ // the caller treats the plan as an ad-hoc plan with no managed identity.
50
+ export function parsePlanTaskIdentity(planContent) {
51
+ // exec-plan frontmatter は `specdojo:` 名前空間配下にある。
52
+ const parsed = readSpecdojoNamespace(planContent);
53
+ const taskId = typeof parsed.task_id === "string" ? parsed.task_id.trim() : "";
54
+ if (!taskId)
55
+ return null;
56
+ const mode = parsed.mode === "review" ? "review" : "edit";
57
+ const projectId = typeof parsed.project_id === "string" ? parsed.project_id.trim() : "";
58
+ const approach = typeof parsed.approach === "string" &&
59
+ PLAN_APPROACHES.includes(parsed.approach)
60
+ ? parsed.approach
61
+ : undefined;
62
+ const targets = Array.isArray(parsed.targets)
63
+ ? parsed.targets.filter((entry) => typeof entry === "string")
64
+ : [];
65
+ // 未知の値は採用せず undefined(= schedule)として扱う。
66
+ const origin = parsed.origin === "register" || parsed.origin === "schedule"
67
+ ? parsed.origin
68
+ : undefined;
69
+ return {
70
+ taskId,
71
+ mode,
72
+ projectId,
73
+ approach,
74
+ ...(origin ? { origin } : {}),
75
+ ...(targets.length > 0 ? { targets } : {}),
76
+ };
77
+ }
78
+ export function registerGradeFindingsText(projectId, ticketPath) {
79
+ if (!existsSync(ticketPath))
80
+ return "- なし";
81
+ const content = readFileSync(ticketPath, "utf8");
82
+ const metadata = readSpecdojoNamespace(content);
83
+ const targets = Array.isArray(metadata.targets)
84
+ ? metadata.targets
85
+ .filter((target) => typeof target === "string")
86
+ .map((target) => target.trim())
87
+ .filter((target) => target.length > 0)
88
+ : [];
89
+ if (targets.length === 0)
90
+ return "- なし";
91
+ const docIndexPath = join(specdojoRootDir(), ".specdojo", "doc-index.json");
92
+ const MAX_DOCS = 10;
93
+ const MAX_FINDINGS = 20;
94
+ const lines = [];
95
+ let docCount = 0;
96
+ for (const id of targets) {
97
+ if (docCount >= MAX_DOCS) {
98
+ lines.push(`- その他 ${targets.length - MAX_DOCS} 件の文書は省略されました`);
99
+ break;
100
+ }
101
+ const targetPath = lookupDocIndex(id, docIndexPath);
102
+ if (!targetPath)
103
+ continue;
104
+ const result = readGradeResultForDocument({ documentPath: targetPath, project: projectId });
105
+ if (!result || result.findings.length === 0) {
106
+ lines.push(`- [[${id}]]: finding なし`);
107
+ docCount++;
108
+ continue;
109
+ }
110
+ const sidecarPath = gradeResultPathForDocument({
111
+ documentPath: targetPath,
112
+ project: projectId,
113
+ });
114
+ // Use posix separators
115
+ const sidecarRel = relative(specdojoRootDir(), sidecarPath).replace(/\\/g, "/");
116
+ lines.push(`- [[${id}]] (サイドカー: \`${sidecarRel}\`):`);
117
+ let findingCount = 0;
118
+ for (const finding of result.findings) {
119
+ if (findingCount >= MAX_FINDINGS) {
120
+ lines.push(` - 他 ${result.findings.length - MAX_FINDINGS} 件の finding があります。詳細はサイドカーを参照してください。`);
121
+ break;
122
+ }
123
+ lines.push(` - [${finding.severity}/${finding.rule}; line=${finding.line}; anchor=${JSON.stringify(finding.anchor)}]: ${gradeFindingDisplayMessage(finding)}`);
124
+ findingCount++;
125
+ }
126
+ docCount++;
127
+ }
128
+ if (lines.length === 0)
129
+ return "- なし";
130
+ return lines.join("\n");
131
+ }
@@ -0,0 +1,3 @@
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,84 @@ 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 indexedDocumentPath(targetId) {
281
+ const repoRoot = specdojoRootDir();
282
+ const indexed = collectDocIndexEntries(join(repoRoot, "docs"), repoRoot)[targetId];
283
+ if (!indexed) {
284
+ throw new Error(`Target document id is not resolvable via the document index: ${targetId}`);
285
+ }
286
+ const withoutLine = indexed.replace(/:\d+$/, "");
287
+ return relative(repoRoot, resolve(repoRoot, withoutLine)).replace(/\\/g, "/");
288
+ }
249
289
  export async function generateRegisterPlan(opts) {
250
290
  const { item } = opts;
251
291
  const category = requireRunnableRegisterItem(item);
292
+ const ticketPath = ticketPathFromItem(item, opts.registerPaths.projectRegisterPath);
293
+ if (item.approach) {
294
+ const [targetId] = item.targets ?? [];
295
+ if (!targetId || (item.targets?.length ?? 0) !== 1) {
296
+ throw new Error(`Register item ${item.id} approach requires exactly one target document id.`);
297
+ }
298
+ const maintenanceKind = MAINTENANCE_TARGET_KIND[item.approach];
299
+ let deliverable = null;
300
+ let refs;
301
+ if (maintenanceKind) {
302
+ deliverable = opts.catalogPath
303
+ ? findUniqueDeliverableForKataTarget(opts.catalogPath, targetId, maintenanceKind)
304
+ : null;
305
+ refs = deliverable
306
+ ? resolveKataRefs(deliverable.deliverable.rulebook, deliverable.deliverable.kind)
307
+ : { rulebook: MISSING, recipe: MISSING, sample: MISSING, template: MISSING };
308
+ refs = { ...refs, [maintenanceKind]: indexedDocumentPath(targetId) };
309
+ }
310
+ else {
311
+ if (!opts.catalogPath) {
312
+ throw new Error(`Register item ${item.id} approach requires catalog_path to resolve ${targetId}.`);
313
+ }
314
+ deliverable = resolveDeliverableByDocId(opts.catalogPath, opts.projectId, targetId).info;
315
+ }
316
+ const planPath = await generateRegisterApproachPlan({
317
+ executionPath: opts.executionPath,
318
+ projectId: opts.projectId,
319
+ catalogPath: opts.catalogPath ?? "",
320
+ ...(opts.rolesPath ? { rolesPath: opts.rolesPath } : {}),
321
+ ...(opts.viewpointsPath ? { viewpointsPath: opts.viewpointsPath } : {}),
322
+ ...(opts.projectContext ? { projectContext: opts.projectContext } : {}),
323
+ taskId: item.id,
324
+ title: item.title,
325
+ description: item.description,
326
+ ...(item.owner && item.owner !== "-" && item.owner !== "_TODO_" ? { owner: item.owner } : {}),
327
+ approach: item.approach,
328
+ targets: item.targets ?? [],
329
+ deliverable,
330
+ ...(refs ? { refs } : {}),
331
+ additionalConditions: registerCompletionConditions(item, ticketPath),
332
+ ...(opts.outPath ? { outPath: opts.outPath } : {}),
333
+ stem: opts.stem,
334
+ });
335
+ return { planPath, category };
336
+ }
252
337
  const templatePath = execTemplatePath(REGISTER_PLAN_TEMPLATES[category]);
253
338
  if (!existsSync(templatePath)) {
254
339
  throw new Error(`Template not found: ${templatePath}`);
@@ -258,7 +343,6 @@ export async function generateRegisterPlan(opts) {
258
343
  mkdirSync(plansDir, { recursive: true });
259
344
  const planPath = opts.outPath ?? join(plansDir, `${opts.stem}-plan.md`);
260
345
  const resultRef = `${repoRelativePath(opts.executionPath)}/exec/results/${opts.stem}-result.md`;
261
- const ticketPath = ticketPathFromItem(item, opts.registerPaths.projectRegisterPath);
262
346
  const values = {
263
347
  _FRONTMATTER_: registerPlanFrontmatter(opts.projectId, opts.stem, item),
264
348
  _PJR_ID_: item.id,
@@ -273,7 +357,6 @@ export async function generateRegisterPlan(opts) {
273
357
  _PJR_PRIORITY_: item.priority,
274
358
  _PJR_OWNER_: item.owner,
275
359
  _PJR_DUE_: item.due,
276
- _PJR_INDEX_PATH_: repoRelativePath(opts.registerPaths.pjrIndexPath),
277
360
  _PJR_TICKET_REF_: ticketPath ? `\`${repoRelativePath(ticketPath)}\`` : "-",
278
361
  _RESULT_REF_: resultRef,
279
362
  _GRADE_FINDINGS_: ticketPath ? registerGradeFindingsText(opts.projectId, ticketPath) : "- なし",
@@ -0,0 +1,23 @@
1
+ import { gitOutput, gitResult } from "./worktree.js";
2
+ import { PROJECT_REPO_WORKTREE_DIRNAME } from "../shared/specdojo-config.js";
3
+ /** Name under which the project repository is recorded in `stages.integrate.repos`. */
4
+ export const PROJECT_REPO_NAME = PROJECT_REPO_WORKTREE_DIRNAME;
5
+ export function zeroSeparated(cwd, args) {
6
+ return gitOutput(cwd, args).split("\0").filter(Boolean);
7
+ }
8
+ export function gitText(value) {
9
+ return typeof value === "string" ? value : "";
10
+ }
11
+ export function dirtyPaths(cwd) {
12
+ return new Set([
13
+ ...zeroSeparated(cwd, ["diff", "--no-renames", "--name-only", "-z"]),
14
+ ...zeroSeparated(cwd, ["diff", "--cached", "--no-renames", "--name-only", "-z"]),
15
+ ...zeroSeparated(cwd, ["ls-files", "--others", "--exclude-standard", "-z"]),
16
+ ]);
17
+ }
18
+ export function mergeInProgress(cwd) {
19
+ return gitResult(cwd, ["rev-parse", "--verify", "--quiet", "MERGE_HEAD"]).status === 0;
20
+ }
21
+ export function branchExists(repoRoot, branch) {
22
+ return (gitResult(repoRoot, ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`]).status === 0);
23
+ }