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,348 @@
1
+ // Deterministic strategy generator: turns the deliverable catalogs (DCT), the track plan
2
+ // (Timeline), intent declarations, current facts/grades and the standard strategy profiles into
3
+ // sch-strategy-<track>.yaml. Approach selection and all generated schedule structures are decided
4
+ // by code so `schedule build` and `exec refresh` stay deterministic.
5
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync, } from "node:fs";
6
+ import { tmpdir } from "node:os";
7
+ import { basename, join, resolve } from "node:path";
8
+ import { dump, load as loadYaml } from "../shared/yaml.js";
9
+ import { resolveSpecdojoPath } from "../docs/template-resolution.js";
10
+ import Ajv2020Module from "ajv/dist/2020.js";
11
+ import { diffPlanText } from "../catalog/plan.js";
12
+ import { readYaml } from "../shared/fs.js";
13
+ import { buildScheduleTrack } from "./build.js";
14
+ import { collectApproachFacts, deriveApproaches, } from "./approach.js";
15
+ import { buildStrategyDocument, } from "./strategy-generate-document.js";
16
+ import { collectScopeDeliverables, isRecord, loadKnownRoles, resolveDeliverableOwners, resolveTrackScopeCatalogs, } from "./strategy-generate-scope.js";
17
+ export const SCH_STRATEGY_SCHEMA_PATH = "docs/specdojo/schemas/v1/sch-strategy.schema.yaml";
18
+ export { artifactNameFromCatalogTitle, collectScopeDeliverables, loadKnownRoles, resolveDeliverableOwners, resolveTrackScopeCatalogs, } from "./strategy-generate-scope.js";
19
+ export { buildStrategyDocument } from "./strategy-generate-document.js";
20
+ // ---- serialization & validation ------------------------------------------------
21
+ export function dumpStrategy(doc) {
22
+ return dump(doc, {
23
+ lineWidth: 120,
24
+ noRefs: true,
25
+ quoteStyle: "double",
26
+ forceQuotes: false,
27
+ });
28
+ }
29
+ const Ajv2020 = Ajv2020Module.default;
30
+ let compiledSchemaCache = null;
31
+ function compileStrategySchema(repoRoot) {
32
+ const schemaPath = resolveSpecdojoPath(SCH_STRATEGY_SCHEMA_PATH, {
33
+ repositoryRoot: repoRoot,
34
+ });
35
+ if (compiledSchemaCache && compiledSchemaCache.schemaPath === schemaPath) {
36
+ return compiledSchemaCache.validate;
37
+ }
38
+ const ajv = new Ajv2020({ allErrors: true, strict: false });
39
+ const load = (fileName) => {
40
+ const filePath = resolveSpecdojoPath(`docs/specdojo/schemas/v1/${fileName}`, {
41
+ repositoryRoot: repoRoot,
42
+ });
43
+ try {
44
+ return loadYaml(readFileSync(filePath, "utf8"));
45
+ }
46
+ catch (error) {
47
+ throw new Error(`Failed to read strategy schema: ${filePath} (${error instanceof Error ? error.message : String(error)})`);
48
+ }
49
+ };
50
+ // Relative $refs resolve against the empty base URI, so the referenced files are registered
51
+ // under their bare file names first.
52
+ ajv.addSchema(load("sch-common.schema.yaml"), "sch-common.schema.yaml");
53
+ ajv.addSchema(load("exec-common.schema.yaml"), "exec-common.schema.yaml");
54
+ const validate = ajv.compile(load(basename(SCH_STRATEGY_SCHEMA_PATH)));
55
+ compiledSchemaCache = { schemaPath, validate };
56
+ return validate;
57
+ }
58
+ export function validateStrategySchema(doc, repoRoot) {
59
+ const validate = compileStrategySchema(repoRoot);
60
+ if (validate(doc))
61
+ return [];
62
+ return (validate.errors ?? []).map((error) => {
63
+ const at = error.instancePath || "/";
64
+ const params = isRecord(error.params) ? error.params : {};
65
+ const detail = typeof params.additionalProperty === "string"
66
+ ? ` (${params.additionalProperty})`
67
+ : typeof params.missingProperty === "string"
68
+ ? ` (${params.missingProperty})`
69
+ : Array.isArray(params.allowedValues)
70
+ ? ` (allowed: ${params.allowedValues.join(", ")})`
71
+ : "";
72
+ return `${at}: ${error.message ?? "schema violation"}${detail}`;
73
+ });
74
+ }
75
+ // `schedule build --dry-run` equivalent for a candidate strategy that is not on disk yet. The
76
+ // candidate is evaluated from a temporary file whose name does not match sch-strategy-*.yaml,
77
+ // so no other command can pick it up while it exists.
78
+ export function dryRunStrategy(opts) {
79
+ const { repoRoot, schedulePath, track, projectId, content } = opts;
80
+ const errors = [];
81
+ const warnings = [];
82
+ const candidateDir = mkdtempSync(join(tmpdir(), "specdojo-strategy-candidate-"));
83
+ const candidatePath = join(candidateDir, `sch-strategy-${track}.yaml`);
84
+ const targetFileName = `sch-strategy-${track}.yaml`;
85
+ writeFileSync(candidatePath, content, "utf8");
86
+ try {
87
+ const result = buildScheduleTrack(candidatePath, repoRoot);
88
+ errors.push(...result.errors);
89
+ warnings.push(...result.warnings);
90
+ if (result.projectId !== projectId) {
91
+ errors.push(`生成した strategy の project id '${result.projectId}' が '${projectId}' と一致しない。`);
92
+ }
93
+ const milestoneIds = result.milestones.map((milestone) => milestone.id);
94
+ const owners = new Map();
95
+ for (const id of milestoneIds)
96
+ owners.set(id, targetFileName);
97
+ const otherFiles = (existsSync(schedulePath) ? readdirSync(schedulePath) : [])
98
+ .filter((file) => /^sch-strategy-.+\.yaml$/.test(file))
99
+ .filter((file) => file !== targetFileName)
100
+ .sort();
101
+ for (const file of otherFiles) {
102
+ try {
103
+ const other = buildScheduleTrack(join(schedulePath, file), repoRoot);
104
+ for (const milestone of other.milestones) {
105
+ const previous = owners.get(milestone.id);
106
+ if (previous) {
107
+ errors.push(`Milestone ID '${milestone.id}' が ${previous} と ${file} で重複している。`);
108
+ continue;
109
+ }
110
+ owners.set(milestone.id, file);
111
+ }
112
+ }
113
+ catch (error) {
114
+ warnings.push(`${file}: ${error instanceof Error ? error.message : String(error)}`);
115
+ }
116
+ }
117
+ return { taskCount: result.tasks.length, milestoneIds, errors, warnings };
118
+ }
119
+ catch (error) {
120
+ errors.push(error instanceof Error ? error.message : String(error));
121
+ return { taskCount: 0, milestoneIds: [], errors, warnings };
122
+ }
123
+ finally {
124
+ rmSync(candidateDir, { recursive: true, force: true });
125
+ }
126
+ }
127
+ export function strategyPathFor(schedulePath, track) {
128
+ return join(schedulePath, `sch-strategy-${track}.yaml`);
129
+ }
130
+ // Writes the strategy to its canonical path with the same overwrite protection the other
131
+ // generators use: an existing file is never replaced without --force, and the diff is returned
132
+ // so the operator can review the change first.
133
+ export function writeStrategyFile(opts) {
134
+ const path = strategyPathFor(opts.schedulePath, opts.track);
135
+ const exists = existsSync(path);
136
+ const current = exists ? readFileSync(path, "utf8") : "";
137
+ const diff = diffPlanText(current, opts.content);
138
+ if (exists && diff.length === 0) {
139
+ return { path, written: false, skippedReason: "unchanged", diff };
140
+ }
141
+ if (exists && !opts.force) {
142
+ return { path, written: false, skippedReason: "exists", diff };
143
+ }
144
+ if (opts.dryRun) {
145
+ return { path, written: false, skippedReason: "dry-run", diff };
146
+ }
147
+ mkdirSync(opts.schedulePath, { recursive: true });
148
+ const temporaryPath = join(opts.schedulePath, `.sch-strategy-${opts.track}.${process.pid}.tmp`);
149
+ try {
150
+ writeFileSync(temporaryPath, opts.content, "utf8");
151
+ renameSync(temporaryPath, path);
152
+ }
153
+ finally {
154
+ rmSync(temporaryPath, { force: true });
155
+ }
156
+ return { path, written: true, diff };
157
+ }
158
+ // Fields a regenerated strategy keeps from the existing file. They record human decisions
159
+ // (intent, start date, completed deliverables, extra ordering, owner assignments) that cannot be
160
+ // derived from the catalogs or the timeline.
161
+ export function readPreservedFields(strategyPath) {
162
+ const ownerByLocalId = new Map();
163
+ if (!existsSync(strategyPath))
164
+ return { ownerByLocalId, approachRules: [] };
165
+ const doc = readYaml(strategyPath);
166
+ if (!isRecord(doc))
167
+ return { ownerByLocalId, approachRules: [] };
168
+ const approachRules = (Array.isArray(doc.approach_rules) ? doc.approach_rules : []).filter((rule) => isRecord(rule) && Array.isArray(rule.local_ids) && typeof rule.intent === "string");
169
+ for (const rule of Array.isArray(doc.owner_rules) ? doc.owner_rules : []) {
170
+ if (!isRecord(rule) || typeof rule.owner !== "string")
171
+ continue;
172
+ for (const localId of Array.isArray(rule.local_ids) ? rule.local_ids : []) {
173
+ if (typeof localId === "string")
174
+ ownerByLocalId.set(localId, rule.owner);
175
+ }
176
+ }
177
+ const crossDeps = [];
178
+ for (const dep of Array.isArray(doc.cross_domain_dependencies)
179
+ ? doc.cross_domain_dependencies
180
+ : []) {
181
+ if (!isRecord(dep))
182
+ continue;
183
+ if (typeof dep.dependent !== "string" || typeof dep.requires !== "string")
184
+ continue;
185
+ crossDeps.push({
186
+ dependent: dep.dependent,
187
+ requires: dep.requires,
188
+ ...(typeof dep.note === "string" ? { note: dep.note } : {}),
189
+ });
190
+ }
191
+ const firstOwner = (field) => {
192
+ if (!Array.isArray(field))
193
+ return undefined;
194
+ const entry = field.find((item) => isRecord(item) && typeof item.owner === "string");
195
+ return isRecord(entry) && typeof entry.owner === "string" ? entry.owner : undefined;
196
+ };
197
+ const milestoneEntries = Array.isArray(doc.group_milestones)
198
+ ? doc.group_milestones.map((item) => (isRecord(item) ? item.milestone : undefined))
199
+ : [];
200
+ const gateOwner = firstOwner(doc.phase_gates);
201
+ const milestoneOwner = firstOwner(milestoneEntries);
202
+ const passOwner = firstOwner(doc.cross_deliverable_passes);
203
+ return {
204
+ ...(typeof doc.status === "string" ? { status: doc.status } : {}),
205
+ ...(typeof doc.title === "string" ? { title: doc.title } : {}),
206
+ ...(isRecord(doc.settings) ? { settings: doc.settings } : {}),
207
+ ...(isRecord(doc.initial_state) ? { initial_state: doc.initial_state } : {}),
208
+ ...(crossDeps.length > 0 ? { cross_domain_dependencies: crossDeps } : {}),
209
+ ...(gateOwner ? { gateOwner } : {}),
210
+ ...(milestoneOwner ? { milestoneOwner } : {}),
211
+ ...(passOwner ? { passOwner } : {}),
212
+ ownerByLocalId,
213
+ approachRules,
214
+ };
215
+ }
216
+ export function loadStrategyDocument(strategyPath) {
217
+ if (!existsSync(strategyPath))
218
+ return null;
219
+ const doc = readYaml(strategyPath);
220
+ return isRecord(doc) ? doc : null;
221
+ }
222
+ // Complete generation pipeline used by the CLI and tests. Every input is re-read and validated
223
+ // before a candidate is returned; missing intent, grade, scope coverage, owners or references stop
224
+ // generation instead of producing a guessed strategy.
225
+ export function generateStrategy(opts) {
226
+ const errors = [];
227
+ const warnings = [];
228
+ const targetPath = strategyPathFor(opts.schedulePath, opts.track);
229
+ const existing = loadStrategyDocument(targetPath);
230
+ const preserved = readPreservedFields(targetPath);
231
+ const scope = resolveTrackScopeCatalogs({
232
+ repoRoot: opts.repoRoot,
233
+ catalogPath: opts.catalogPath,
234
+ timelinePath: opts.timelinePath,
235
+ track: opts.track,
236
+ existingStrategy: existing,
237
+ });
238
+ errors.push(...scope.errors);
239
+ warnings.push(...scope.warnings);
240
+ const strategyScope = {
241
+ strategyId: `${opts.projectId}:sch-strategy-${opts.track}`,
242
+ track: opts.track,
243
+ projectId: opts.projectId,
244
+ catalogs: scope.catalogs.map((catalog) => ({
245
+ id: catalog.id,
246
+ path: catalog.path,
247
+ ...(catalog.local_ids ? { local_ids: catalog.local_ids } : {}),
248
+ })),
249
+ includeKinds: ["work"],
250
+ };
251
+ const current = collectApproachFacts({ repoRoot: opts.repoRoot, scope: strategyScope });
252
+ errors.push(...current.errors);
253
+ warnings.push(...current.warnings);
254
+ const catalogDeliverables = collectScopeDeliverables({
255
+ repoRoot: opts.repoRoot,
256
+ catalogs: scope.catalogs,
257
+ includeKinds: ["work"],
258
+ });
259
+ errors.push(...catalogDeliverables.errors);
260
+ const catalogByLocalId = new Map();
261
+ for (const deliverable of catalogDeliverables.deliverables) {
262
+ const previous = catalogByLocalId.get(deliverable.local_id);
263
+ if (previous) {
264
+ errors.push(`local_id '${deliverable.local_id}' が ${previous.catalog_id} と ${deliverable.catalog_id} で重複している。`);
265
+ continue;
266
+ }
267
+ catalogByLocalId.set(deliverable.local_id, deliverable);
268
+ }
269
+ const approaches = deriveApproaches({
270
+ facts: current.deliverables,
271
+ rules: preserved.approachRules,
272
+ });
273
+ errors.push(...approaches.errors);
274
+ warnings.push(...approaches.warnings);
275
+ const approachIds = new Set(approaches.deliverables.map((deliverable) => deliverable.local_id));
276
+ for (const localId of catalogByLocalId.keys()) {
277
+ if (!approachIds.has(localId))
278
+ errors.push(`${localId}: strategy profile の選択結果が無い。`);
279
+ }
280
+ if (opts.rolesPath && !existsSync(resolve(opts.repoRoot, opts.rolesPath))) {
281
+ errors.push(`roles_path が見つからない: ${opts.rolesPath}`);
282
+ }
283
+ const knownRoles = loadKnownRoles(opts.repoRoot, opts.rolesPath);
284
+ const owners = resolveDeliverableOwners({
285
+ localIds: [...catalogByLocalId.keys()],
286
+ overrides: opts.ownerOverrides ?? new Map(),
287
+ previous: preserved.ownerByLocalId,
288
+ ...(opts.defaultOwner ? { defaultOwner: opts.defaultOwner } : {}),
289
+ ...(knownRoles.size > 0 ? { knownRoles } : {}),
290
+ });
291
+ errors.push(...owners.errors);
292
+ warnings.push(...owners.warnings);
293
+ const gateOwner = opts.gateOwner ?? preserved.gateOwner ?? opts.defaultOwner ?? "";
294
+ const milestoneOwner = opts.milestoneOwner ?? preserved.milestoneOwner ?? opts.defaultOwner ?? gateOwner;
295
+ const passOwnerOverride = opts.passOwnerOverride ?? preserved.passOwner;
296
+ for (const [label, owner] of [
297
+ ["gate", gateOwner],
298
+ ["milestone", milestoneOwner],
299
+ ["cross-deliverable pass", passOwnerOverride],
300
+ ]) {
301
+ if (owner && knownRoles.size > 0 && !knownRoles.has(owner)) {
302
+ errors.push(`${label} owner '${owner}' は pm-roles.yaml に存在しない。`);
303
+ }
304
+ }
305
+ const dependsOn = new Map(catalogDeliverables.deliverables.map((deliverable) => [
306
+ deliverable.local_id,
307
+ deliverable.depends_on,
308
+ ]));
309
+ const built = buildStrategyDocument({
310
+ projectId: opts.projectId,
311
+ track: opts.track,
312
+ catalogs: scope.catalogs,
313
+ deliverables: approaches.deliverables,
314
+ dependsOn,
315
+ owners: owners.owners,
316
+ gateOwner,
317
+ milestoneOwner,
318
+ ...(passOwnerOverride ? { passOwnerOverride } : {}),
319
+ bootstrapOrdering: opts.bootstrapOrdering ?? true,
320
+ includeKinds: ["work"],
321
+ preserved,
322
+ });
323
+ errors.push(...built.errors);
324
+ warnings.push(...built.warnings);
325
+ const strategySchemaErrors = validateStrategySchema(built.doc, opts.repoRoot);
326
+ errors.push(...strategySchemaErrors.map((error) => `sch-strategy-${opts.track}.yaml${error}`));
327
+ const content = dumpStrategy(built.doc);
328
+ if (errors.length > 0) {
329
+ return { doc: null, content, taskCount: 0, milestoneIds: [], errors, warnings };
330
+ }
331
+ const dryRun = dryRunStrategy({
332
+ repoRoot: opts.repoRoot,
333
+ schedulePath: opts.schedulePath,
334
+ track: opts.track,
335
+ projectId: opts.projectId,
336
+ content,
337
+ });
338
+ errors.push(...dryRun.errors);
339
+ warnings.push(...dryRun.warnings);
340
+ return {
341
+ doc: errors.length === 0 ? built.doc : null,
342
+ content,
343
+ taskCount: dryRun.taskCount,
344
+ milestoneIds: dryRun.milestoneIds,
345
+ errors,
346
+ warnings,
347
+ };
348
+ }
@@ -0,0 +1,23 @@
1
+ // タスクの進め方プロファイル。前3者は成果物作業で参考資料をどの程度参照するかを表し、
2
+ // <kind>-maintenance は成果物や finding が指す規範を根拠に対象の参考資料を見直す進め方
3
+ // (参照の向きが逆転する)。
4
+ // bootstrap は成果物とその参考資料一式(rulebook/recipe/sample/template)を一貫した一組として
5
+ // 同一タスクで作成・整備する進め方(初期立ち上げ専用)。
6
+ // retrofit は宣言済みの実装エビデンスを現在動作の根拠として読み、成果物へ反映・新設する。
7
+ // cross-deliverable-dedup は明示した成果物群を横断して正本を選び、重複を要約と参照へ置換する。
8
+ // finalize は human が成果物のみを最終確認して status を ready へ確定する進め方、
9
+ // bootstrap-finalize は bootstrap と対になり、成果物と参考資料一式をまとめて確定する進め方。
10
+ export const APPROACHES = [
11
+ "fully-guided",
12
+ "recipe-guided",
13
+ "freeform",
14
+ "bootstrap",
15
+ "retrofit",
16
+ "cross-deliverable-dedup",
17
+ "rulebook-maintenance",
18
+ "recipe-maintenance",
19
+ "sample-maintenance",
20
+ "template-maintenance",
21
+ "finalize",
22
+ "bootstrap-finalize",
23
+ ];
@@ -0,0 +1,9 @@
1
+ import { relative } from "node:path";
2
+ import { specdojoRootDir } from "./specdojo-config.js";
3
+ export function toPortablePath(path) {
4
+ return path.replace(/\\/g, "/");
5
+ }
6
+ export function toArtifactPath(path) {
7
+ const rel = relative(specdojoRootDir(), path);
8
+ return toPortablePath(rel || ".");
9
+ }
@@ -18,7 +18,7 @@ function isPrimaryWorktree(repoRoot) {
18
18
  return existsSync(gitEntry) && lstatSync(gitEntry).isDirectory();
19
19
  }
20
20
  function main() {
21
- const repoRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
21
+ const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
22
22
  if (!isPrimaryWorktree(repoRoot)) {
23
23
  // linked worktree は dist を持たず、agent は tsx で src を直接実行するため対象外。
24
24
  return;
@@ -0,0 +1,115 @@
1
+ import { resolveBasePath } from "./catalog-paths.js";
2
+ function formatDependsOn(deps) {
3
+ if (!deps || deps.length === 0)
4
+ return "-";
5
+ return deps.map((d) => `\`${d}\``).join(", ");
6
+ }
7
+ export function renderTable(deliverables) {
8
+ const lines = ["<!-- prettier-ignore -->"];
9
+ const hasInstanceIdPattern = deliverables.some((item) => item.instance_id_pattern);
10
+ if (hasInstanceIdPattern) {
11
+ lines.push("| local-id | 実体IDパターン | 成果物名 | 種別 | 根拠 | 概要 |");
12
+ lines.push("| --- | --- | --- | --- | --- | --- |");
13
+ }
14
+ else {
15
+ lines.push("| local-id | 成果物名 | 種別 | 根拠 | 概要 |");
16
+ lines.push("| --- | --- | --- | --- | --- |");
17
+ }
18
+ for (const item of deliverables) {
19
+ const localId = `\`${item.local_id}\``;
20
+ const deps = formatDependsOn(item.depends_on);
21
+ if (hasInstanceIdPattern) {
22
+ const instanceIdPattern = item.instance_id_pattern ? `\`${item.instance_id_pattern}\`` : "-";
23
+ lines.push(`| ${localId} | ${instanceIdPattern} | ${item.name} | ${item.kind} | ${deps} | ${item.overview} |`);
24
+ }
25
+ else {
26
+ lines.push(`| ${localId} | ${item.name} | ${item.kind} | ${deps} | ${item.overview} |`);
27
+ }
28
+ }
29
+ return lines;
30
+ }
31
+ export function renderDoneCriteria(deliverables) {
32
+ const lines = [];
33
+ for (const item of deliverables) {
34
+ if (item.kind !== "work" || !item.done_criteria || item.done_criteria.length === 0)
35
+ continue;
36
+ lines.push("");
37
+ lines.push(`**\`${item.local_id}\`** の完了条件:`);
38
+ lines.push("");
39
+ for (const criterion of item.done_criteria) {
40
+ lines.push(`- ${criterion.text}`);
41
+ }
42
+ }
43
+ return lines;
44
+ }
45
+ export function renderSections(sections, parentBase, depth, prefix) {
46
+ const lines = [];
47
+ const hashes = "#".repeat(depth + 1);
48
+ let counter = 0;
49
+ for (const section of sections) {
50
+ const sectionBase = resolveBasePath(parentBase, section.base_path);
51
+ if (!section.name) {
52
+ // Unnamed section: output content without heading
53
+ if (section.base_path) {
54
+ lines.push("");
55
+ lines.push(`- 配置先: \`${sectionBase}\``);
56
+ }
57
+ if (section.note) {
58
+ lines.push("");
59
+ lines.push(section.note);
60
+ }
61
+ if (section.deliverables && section.deliverables.length > 0) {
62
+ lines.push("");
63
+ lines.push(...renderTable(section.deliverables));
64
+ lines.push(...renderDoneCriteria(section.deliverables));
65
+ }
66
+ if (section.groups && section.groups.length > 0) {
67
+ lines.push(...renderSections(section.groups, sectionBase, depth, prefix));
68
+ }
69
+ continue;
70
+ }
71
+ counter++;
72
+ const nums = [...prefix, counter];
73
+ const numStr = nums.join(".");
74
+ lines.push("");
75
+ lines.push(`${hashes} ${numStr}. ${section.name}`);
76
+ if (section.base_path) {
77
+ lines.push("");
78
+ lines.push(`- 配置先: \`${sectionBase}\``);
79
+ }
80
+ if (section.note) {
81
+ lines.push("");
82
+ lines.push(section.note);
83
+ }
84
+ if (section.deliverables && section.deliverables.length > 0) {
85
+ lines.push("");
86
+ lines.push(...renderTable(section.deliverables));
87
+ lines.push(...renderDoneCriteria(section.deliverables));
88
+ }
89
+ if (section.groups && section.groups.length > 0) {
90
+ lines.push(...renderSections(section.groups, sectionBase, depth + 1, nums));
91
+ }
92
+ }
93
+ return lines;
94
+ }
95
+ export function isRecord(value) {
96
+ return typeof value === "object" && value !== null && !Array.isArray(value);
97
+ }
98
+ // dct 成果物カタログのテンプレート(type: template)YAML かを判定する。
99
+ // テンプレートはインスタンス(type: project)と違い project_id を持たず local_id に
100
+ // プレースホルダを含むため、validateDctDoc/buildMarkdown は適用できない。yaml-pages の
101
+ // 表示ページで、YAML 丸写しのコードブロックではなく可読な表形式で描画するために使う。
102
+ export function isDctTemplateCatalog(yamlRelPath, parsed) {
103
+ if (!/\/templates\/dct-.+-template\.ya?ml$/.test(yamlRelPath))
104
+ return false;
105
+ if (!isRecord(parsed))
106
+ return false;
107
+ return (parsed.type === "template" && typeof parsed.domain === "string" && Array.isArray(parsed.groups));
108
+ }
109
+ // dct テンプレートの本文(成果物表+完了条件)を描画する。frontmatter・H1・注記は
110
+ // 呼び出し側(yaml-pages 表示ページ)が付与するため、ここでは本文セクションのみ返す。
111
+ // インスタンス(buildMarkdown)と同じ renderSections を共用し、表現を一致させる。
112
+ export function renderCatalogTemplateBody(doc) {
113
+ const topBase = resolveBasePath("", doc.base_path);
114
+ return renderSections(doc.groups, topBase, 1, []).join("\n").trim();
115
+ }
@@ -1,7 +1,9 @@
1
1
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, utimesSync, } from "node:fs";
2
2
  import { spawn } from "node:child_process";
3
3
  import { join } from "node:path";
4
- import { ensureDir, nowUtcIsoSeconds, randomHex, writeJson } from "./exec-shared.js";
4
+ import { ensureDir, writeJson } from "./fs.js";
5
+ import { randomHex } from "./random.js";
6
+ import { nowUtcIsoSeconds } from "./time.js";
5
7
  // Cross-process locks and counting semaphores built on atomic `mkdir`. Every held lock is a
6
8
  // directory with an `owner.json` and a detached heartbeat process that keeps its mtime fresh.
7
9
  // A lock whose heartbeat stopped (the owner crashed) becomes stale after `staleMs` and may be
@@ -0,0 +1,30 @@
1
+ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { load } from "./yaml.js";
4
+ export function ensureDir(path) {
5
+ if (!existsSync(path))
6
+ mkdirSync(path, { recursive: true });
7
+ }
8
+ export function listFilesRecursive(dir) {
9
+ const out = [];
10
+ if (!existsSync(dir))
11
+ return out;
12
+ for (const name of readdirSync(dir)) {
13
+ const full = join(dir, name);
14
+ const st = statSync(full);
15
+ if (st.isDirectory())
16
+ out.push(...listFilesRecursive(full));
17
+ else if (st.isFile())
18
+ out.push(full);
19
+ }
20
+ return out;
21
+ }
22
+ export function readJson(path) {
23
+ return JSON.parse(readFileSync(path, "utf8"));
24
+ }
25
+ export function writeJson(path, data) {
26
+ writeFileSync(path, JSON.stringify(data, null, 2) + "\n", "utf8");
27
+ }
28
+ export function readYaml(path) {
29
+ return load(readFileSync(path, "utf8"));
30
+ }