specdojo 0.3.0 → 0.3.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 (104) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/catalog-build-references.js +144 -0
  3. package/dist/catalog-build-render.js +144 -0
  4. package/dist/catalog-build.js +13 -290
  5. package/dist/catalog-generate.js +6 -9
  6. package/dist/catalog-plan-generate.js +2 -2
  7. package/dist/catalog-plan.js +6 -6
  8. package/dist/catalog-scaffold.js +4 -4
  9. package/dist/catalog.js +2 -2
  10. package/dist/dashboard-exec-records.js +105 -0
  11. package/dist/dashboard-routines.js +255 -0
  12. package/dist/dashboard-shared.js +14 -0
  13. package/dist/dashboard-timeline.js +175 -0
  14. package/dist/dashboard.js +10 -544
  15. package/dist/deliverable-trash.js +3 -3
  16. package/dist/doc-index.js +3 -3
  17. package/dist/exec-commands.js +557 -0
  18. package/dist/exec-core.js +457 -0
  19. package/dist/exec-plans-core.js +693 -0
  20. package/dist/exec-plans-generation.js +206 -0
  21. package/dist/exec-plans-storage.js +131 -0
  22. package/dist/exec-plans.js +3 -1018
  23. package/dist/exec-repo-integration-git.js +23 -0
  24. package/dist/exec-repo-integration-sync.js +264 -0
  25. package/dist/exec-repo-integration.js +4 -281
  26. package/dist/exec-reporter-output.js +206 -0
  27. package/dist/exec-reporter.js +2 -206
  28. package/dist/exec-results.js +22 -15
  29. package/dist/exec-run-agent-pipeline.js +256 -0
  30. package/dist/exec-run-agent.js +531 -0
  31. package/dist/exec-run-in-place.js +541 -0
  32. package/dist/exec-run-job.js +717 -0
  33. package/dist/exec-run-lifecycle-commands.js +522 -0
  34. package/dist/exec-run-mode-shared.js +140 -0
  35. package/dist/exec-run-register-command.js +244 -0
  36. package/dist/exec-run-register-core.js +386 -0
  37. package/dist/exec-run-register-mode.js +206 -0
  38. package/dist/exec-run-register-resume.js +393 -0
  39. package/dist/exec-run-register-state.js +322 -0
  40. package/dist/exec-run-register-worktree.js +509 -0
  41. package/dist/exec-run-schedule-mode.js +294 -0
  42. package/dist/exec-run-schedule-prepare.js +353 -0
  43. package/dist/exec-run-schedule-task.js +572 -0
  44. package/dist/exec-run-shared.js +399 -0
  45. package/dist/exec-run.js +11 -6182
  46. package/dist/exec-shared.js +2 -2
  47. package/dist/exec-trial-commands.js +558 -0
  48. package/dist/exec-trial-core.js +371 -0
  49. package/dist/exec-trial.js +2 -921
  50. package/dist/exec-worktree-ops-commit.js +707 -0
  51. package/dist/exec-worktree-ops-lifecycle.js +292 -0
  52. package/dist/exec-worktree-ops-merge.js +303 -0
  53. package/dist/exec-worktree-ops.js +3 -1292
  54. package/dist/exec-worktree.js +32 -4
  55. package/dist/exec.js +2 -1006
  56. package/dist/frontmatter-namespace.js +2 -2
  57. package/dist/grade-apply.js +734 -0
  58. package/dist/grade-command-apply.js +250 -0
  59. package/dist/grade-command-inspect.js +138 -0
  60. package/dist/grade-command-plan.js +101 -0
  61. package/dist/grade-command-shared.js +68 -0
  62. package/dist/grade-core.js +307 -0
  63. package/dist/grade-markdown.js +274 -0
  64. package/dist/grade-pipeline-state.js +184 -0
  65. package/dist/grade-plan.js +507 -0
  66. package/dist/grade-result.js +5 -5
  67. package/dist/grade-target-discovery.js +265 -0
  68. package/dist/grade-targets.js +432 -0
  69. package/dist/grade.js +14 -3188
  70. package/dist/init-command.js +7 -7
  71. package/dist/job-definition.js +670 -0
  72. package/dist/job.js +9 -673
  73. package/dist/kata-command.js +2 -2
  74. package/dist/register-command-types.js +1 -0
  75. package/dist/register-core.js +363 -0
  76. package/dist/register-create-commands.js +245 -0
  77. package/dist/register-events.js +4 -4
  78. package/dist/register-item.js +6 -6
  79. package/dist/register-maintenance-commands.js +187 -0
  80. package/dist/register-migration.js +268 -0
  81. package/dist/register-renumber.js +314 -0
  82. package/dist/register-transition-commands.js +248 -0
  83. package/dist/register-update.js +230 -0
  84. package/dist/register-views.js +256 -0
  85. package/dist/register.js +61 -2069
  86. package/dist/review-plan.js +3 -3
  87. package/dist/routine-definition.js +401 -0
  88. package/dist/routine.js +6 -402
  89. package/dist/schedule-approach.js +2 -2
  90. package/dist/schedule-strategy-generate-document.js +273 -0
  91. package/dist/schedule-strategy-generate-scope.js +199 -0
  92. package/dist/schedule-strategy-generate.js +9 -473
  93. package/dist/schedule.js +4 -4
  94. package/dist/specdojo-config.js +3 -4
  95. package/dist/viewpoint-document-kinds-check.js +3 -3
  96. package/dist/yaml-pages.js +4 -4
  97. package/dist/yaml.js +28 -0
  98. package/docs/ja/specdojo/guides/exec-config-guide.md +6 -6
  99. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +20 -18
  100. package/docs/ja/specdojo/guides/routine-operation-guide.md +1 -1
  101. package/package.json +4 -5
  102. package/templates/antigravity/README.md +3 -3
  103. package/templates/antigravity/exec-defaults-snippet.yaml +6 -4
  104. package/templates/init-exec-defaults.yaml +3 -1
@@ -0,0 +1,273 @@
1
+ import { AUTHOR_PHASE_SETS, PHASE_SET_ORDER, profileFor, renderPhase, STRATEGY_PHASE_SETS, } from "./schedule-strategy-profiles.js";
2
+ import { artifactNameFromCatalogTitle, } from "./schedule-strategy-generate-scope.js";
3
+ function phaseSetsOf(approach) {
4
+ return profileFor(approach).phase_sets;
5
+ }
6
+ function orderPhaseSets(names) {
7
+ const unique = [...new Set(names)];
8
+ return unique.sort((left, right) => PHASE_SET_ORDER.indexOf(left) - PHASE_SET_ORDER.indexOf(right));
9
+ }
10
+ // Transitive catalog dependency check used to keep generated bootstrap ordering acyclic.
11
+ function dependsTransitively(from, target, dependsOn) {
12
+ const seen = new Set();
13
+ const stack = [...(dependsOn.get(from) ?? [])];
14
+ while (stack.length > 0) {
15
+ const current = stack.pop();
16
+ if (current === target)
17
+ return true;
18
+ if (seen.has(current))
19
+ continue;
20
+ seen.add(current);
21
+ stack.push(...(dependsOn.get(current) ?? []));
22
+ }
23
+ return false;
24
+ }
25
+ export function buildStrategyDocument(input) {
26
+ const warnings = [];
27
+ const errors = [];
28
+ const trackUpper = input.track.toUpperCase();
29
+ const maintenanceKind = (approach) => {
30
+ const match = approach.match(/^(rulebook|recipe|sample|template)-maintenance$/);
31
+ return match?.[1];
32
+ };
33
+ const eligibleDeliverables = input.deliverables.filter((deliverable) => {
34
+ const kind = maintenanceKind(deliverable.approach);
35
+ if (!kind || !deliverable.not_needed_kata?.includes(kind))
36
+ return true;
37
+ errors.push(`${deliverable.local_id}: ${kind} は not-needed と宣言されているため ${kind}-maintenance を生成しない。`);
38
+ return false;
39
+ });
40
+ const sorted = [...eligibleDeliverables].sort((left, right) => left.local_id.localeCompare(right.local_id));
41
+ // --- owner_rules: one rule per (owner, approach) pair -------------------------
42
+ const groups = new Map();
43
+ for (const deliverable of sorted) {
44
+ const owner = input.owners.get(deliverable.local_id);
45
+ if (!owner) {
46
+ errors.push(`${deliverable.local_id}: owner が解決できていない。`);
47
+ continue;
48
+ }
49
+ const key = JSON.stringify([owner, deliverable.approach]);
50
+ const group = groups.get(key) ?? { owner, approach: deliverable.approach, localIds: [] };
51
+ group.localIds.push(deliverable.local_id);
52
+ groups.set(key, group);
53
+ }
54
+ const orderedGroups = [...groups.values()].sort((left, right) => left.owner === right.owner
55
+ ? left.approach.localeCompare(right.approach)
56
+ : left.owner.localeCompare(right.owner));
57
+ // The most common profile becomes default_phase_sets so rules that follow it stay compact.
58
+ const byApproach = new Map();
59
+ for (const deliverable of sorted) {
60
+ byApproach.set(deliverable.approach, (byApproach.get(deliverable.approach) ?? 0) + 1);
61
+ }
62
+ const defaultApproach = [...byApproach.entries()].sort((left, right) => right[1] === left[1] ? left[0].localeCompare(right[0]) : right[1] - left[1])[0]?.[0];
63
+ const defaultSequence = defaultApproach ? phaseSetsOf(defaultApproach) : [];
64
+ const usedPhaseSets = orderPhaseSets(sorted.flatMap((d) => phaseSetsOf(d.approach)));
65
+ const phaseSets = {};
66
+ for (const name of usedPhaseSets) {
67
+ const definition = STRATEGY_PHASE_SETS[name];
68
+ if (!definition) {
69
+ errors.push(`未定義の phase_set '${name}' が profile から参照された。`);
70
+ continue;
71
+ }
72
+ phaseSets[name] = definition.map(renderPhase);
73
+ }
74
+ const ownerRules = orderedGroups.map((group) => {
75
+ const sequence = phaseSetsOf(group.approach);
76
+ const sameAsDefault = sequence.length === defaultSequence.length &&
77
+ sequence.every((name, index) => name === defaultSequence[index]);
78
+ const finalizeApproach = profileFor(group.approach).finalize_approach;
79
+ return {
80
+ local_ids: [...group.localIds].sort(),
81
+ owner: group.owner,
82
+ ...(sameAsDefault ? {} : { phase_sets: sequence.map((name) => ({ phase_set: name })) }),
83
+ ...(finalizeApproach === "bootstrap-finalize"
84
+ ? { phase_overrides: [{ phase: "finalize", approach: "bootstrap-finalize" }] }
85
+ : {}),
86
+ };
87
+ });
88
+ // --- phase gates -------------------------------------------------------------
89
+ const countUsing = (phaseSetName) => sorted.filter((d) => phaseSetsOf(d.approach).includes(phaseSetName)).length;
90
+ const authorPhaseSets = orderPhaseSets(usedPhaseSets.filter((name) => AUTHOR_PHASE_SETS.includes(name)));
91
+ const catalogScope = { catalogs: input.catalogs.map((catalog) => catalog.id) };
92
+ const artifactName = input.catalogs.length === 1 ? artifactNameFromCatalogTitle(input.catalogs[0].title) : undefined;
93
+ const withArtifact = artifactName ? { artifact_name: artifactName } : {};
94
+ const dedupLocalIds = sorted
95
+ .filter((d) => d.approach === "cross-deliverable-dedup")
96
+ .map((d) => d.local_id);
97
+ const authorPassDeliverables = sorted.filter((d) => phaseSetsOf(d.approach).some((name) => AUTHOR_PHASE_SETS.includes(name))).length;
98
+ const firstPassGateId = `G-${trackUpper}-first-pass`;
99
+ const gates = [];
100
+ const needsFirstPassGate = authorPhaseSets.length > 0 && (authorPassDeliverables >= 2 || dedupLocalIds.length >= 2);
101
+ if (needsFirstPassGate) {
102
+ gates.push({
103
+ id: firstPassGateId,
104
+ name: "初回パス完了",
105
+ ...withArtifact,
106
+ after_phase_sets: authorPhaseSets,
107
+ owner: input.gateOwner,
108
+ scope: catalogScope,
109
+ });
110
+ }
111
+ if (countUsing("refine-pass") >= 2) {
112
+ gates.push({
113
+ id: `G-${trackUpper}-refine-pass`,
114
+ name: "磨き込み完了",
115
+ ...withArtifact,
116
+ after_phase_sets: ["refine-pass"],
117
+ owner: input.gateOwner,
118
+ scope: catalogScope,
119
+ });
120
+ }
121
+ const reviewPhaseSets = orderPhaseSets(usedPhaseSets.filter((name) => name === "review-pass" || name === "retrofit-review-pass"));
122
+ if (reviewPhaseSets.length > 0 && sorted.length >= 2) {
123
+ gates.push({
124
+ id: `G-${trackUpper}-review-pass`,
125
+ name: "レビュー完了",
126
+ ...withArtifact,
127
+ after_phase_sets: reviewPhaseSets,
128
+ owner: input.gateOwner,
129
+ scope: catalogScope,
130
+ });
131
+ }
132
+ if (gates.length > 0 && !input.gateOwner) {
133
+ errors.push("phase gate の owner を決定できない。--gate-owner <ROLE> または --default-owner <ROLE> で明示する。");
134
+ }
135
+ // --- cross-deliverable pass --------------------------------------------------
136
+ const crossPasses = [];
137
+ if (dedupLocalIds.length === 1) {
138
+ errors.push(`cross-deliverable-dedup と判定された成果物が 1 件しかない (${dedupLocalIds[0]})。` +
139
+ `横断タスクは 2 件以上の成果物を対象にする。判定を見直す。`);
140
+ }
141
+ else if (dedupLocalIds.length >= 2) {
142
+ if (!needsFirstPassGate) {
143
+ errors.push(`cross-deliverable-dedup を配置する前段フェーズが無い。` +
144
+ `対象 track に author フェーズ(bootstrap / retrofit / draft)を持つ成果物が必要。`);
145
+ }
146
+ const passOwners = new Set(dedupLocalIds.map((localId) => input.owners.get(localId) ?? "").filter(Boolean));
147
+ const passOwner = input.passOwnerOverride ?? (passOwners.size === 1 ? [...passOwners][0] : undefined);
148
+ if (!passOwner) {
149
+ errors.push(`横断タスクの主担当を決定できない(対象成果物の owner が ${[...passOwners].join(", ")})。` +
150
+ `--owner ${input.track}-dedup=<ROLE> で明示する。`);
151
+ }
152
+ else {
153
+ crossPasses.push({
154
+ id: `${input.track}-dedup`,
155
+ name: "成果物間の正本選択・重複整理",
156
+ ...withArtifact,
157
+ task_suffix: "060",
158
+ duration_days: 0.5,
159
+ owner: passOwner,
160
+ after_gate: firstPassGateId,
161
+ before_phase_set: "refine-pass",
162
+ execution: "agent",
163
+ mode: "edit",
164
+ approach: "cross-deliverable-dedup",
165
+ agent_pipeline: {
166
+ stages: [
167
+ { stage_role: "executor", proficiency: "expert" },
168
+ { stage_role: "reporter", proficiency: "normal" },
169
+ ],
170
+ },
171
+ description: "対象成果物を横断し、同じ事実・手順・定義が複数文書へ重複していないか確認する。" +
172
+ "各情報の正本を選び、他の文書は必要な要約と参照へ整理する。各成果物の固有責務と " +
173
+ "done_criteria は維持し、用語と受け渡しを統一する。\n",
174
+ scope: { local_ids: [...dedupLocalIds].sort() },
175
+ });
176
+ }
177
+ }
178
+ // --- cross domain dependencies ----------------------------------------------
179
+ const crossDeps = [
180
+ ...(input.preserved.cross_domain_dependencies ?? []),
181
+ ];
182
+ const declared = new Set(crossDeps.map((dep) => JSON.stringify([dep.dependent, dep.requires])));
183
+ if (input.bootstrapOrdering) {
184
+ const bootstrapIds = sorted
185
+ .filter((d) => d.approach === "bootstrap")
186
+ .map((d) => d.local_id)
187
+ .sort();
188
+ for (const deliverable of sorted) {
189
+ if (deliverable.approach === "bootstrap")
190
+ continue;
191
+ if (deliverable.approach === "finalize" || deliverable.approach === "bootstrap-finalize") {
192
+ continue;
193
+ }
194
+ for (const bootstrapId of bootstrapIds) {
195
+ const catalogOf = sorted.find((d) => d.local_id === bootstrapId)?.catalog_id;
196
+ if (catalogOf !== deliverable.catalog_id)
197
+ continue;
198
+ if ((input.dependsOn.get(deliverable.local_id) ?? []).includes(bootstrapId))
199
+ continue;
200
+ if (dependsTransitively(bootstrapId, deliverable.local_id, input.dependsOn)) {
201
+ warnings.push(`bootstrap 順序: ${bootstrapId} が ${deliverable.local_id} に依存しているため、` +
202
+ `逆向きの待ち合わせは生成しない。`);
203
+ continue;
204
+ }
205
+ const key = JSON.stringify([deliverable.local_id, bootstrapId]);
206
+ if (declared.has(key))
207
+ continue;
208
+ declared.add(key);
209
+ crossDeps.push({
210
+ dependent: deliverable.local_id,
211
+ requires: bootstrapId,
212
+ note: "代表成果物の初期整備(bootstrap)で整った実践の型を前提にする",
213
+ });
214
+ }
215
+ }
216
+ }
217
+ // --- group milestones --------------------------------------------------------
218
+ const groupMilestones = input.catalogs.map((catalog) => {
219
+ const label = artifactNameFromCatalogTitle(catalog.title);
220
+ const sameDomainCount = input.catalogs.filter((item) => item.domain === catalog.domain).length;
221
+ const catalogLocalId = catalog.id.includes(":")
222
+ ? catalog.id.split(":").slice(1).join(":")
223
+ : catalog.id;
224
+ const milestoneSuffix = sameDomainCount > 1 ? catalogLocalId.replace(/^dct-/, "") : catalog.domain;
225
+ return {
226
+ catalog_id: catalog.id,
227
+ milestone: {
228
+ id: `M-${trackUpper}-${milestoneSuffix}`,
229
+ name: "ドメイン完了",
230
+ ...(label ? { artifact_name: label } : {}),
231
+ owner: input.milestoneOwner,
232
+ },
233
+ };
234
+ });
235
+ if (groupMilestones.length > 0 && !input.milestoneOwner) {
236
+ errors.push("group milestone の owner を決定できない。--milestone-owner <ROLE> または --default-owner <ROLE> で明示する。");
237
+ }
238
+ const doc = {
239
+ kind: "strategy",
240
+ id: `${input.projectId}:sch-strategy-${input.track}`,
241
+ type: "project",
242
+ status: input.preserved.status ?? "draft",
243
+ title: input.preserved.title ?? `スケジュール戦略(${input.track})`,
244
+ rulebook: "specdojo:sch-rulebook",
245
+ track: input.track,
246
+ ...(input.preserved.settings && Object.keys(input.preserved.settings).length > 0
247
+ ? { settings: input.preserved.settings }
248
+ : {}),
249
+ scope: {
250
+ catalogs: input.catalogs.map((catalog) => ({
251
+ id: catalog.id,
252
+ path: catalog.path,
253
+ ...(catalog.local_ids ? { local_ids: catalog.local_ids } : {}),
254
+ })),
255
+ include_kinds: input.includeKinds,
256
+ },
257
+ approach_rules: input.preserved.approachRules,
258
+ phase_sets: phaseSets,
259
+ ...(defaultSequence.length > 0
260
+ ? { default_phase_sets: defaultSequence.map((name) => ({ phase_set: name })) }
261
+ : {}),
262
+ owner_rules: ownerRules,
263
+ ...(crossPasses.length > 0 ? { cross_deliverable_passes: crossPasses } : {}),
264
+ ...(gates.length > 0 ? { phase_gates: gates } : {}),
265
+ ...(crossDeps.length > 0 ? { cross_domain_dependencies: crossDeps } : {}),
266
+ ...(groupMilestones.length > 0 ? { group_milestones: groupMilestones } : {}),
267
+ ...(input.preserved.initial_state ? { initial_state: input.preserved.initial_state } : {}),
268
+ };
269
+ if (ownerRules.length === 0) {
270
+ errors.push("owner_rules が空になる。判定済みの成果物が 1 件も無い。");
271
+ }
272
+ return { doc, warnings, errors };
273
+ }
@@ -0,0 +1,199 @@
1
+ import { existsSync } from "node:fs";
2
+ import { basename, join, relative, resolve } from "node:path";
3
+ import { collectResolvedDeliverables } from "./catalog-build.js";
4
+ import { resolveBasePath } from "./catalog-paths.js";
5
+ import { readYaml } from "./exec-shared.js";
6
+ import { collectCatalogFilesByDomain, loadTimelineIndex } from "./timeline-build.js";
7
+ export function isRecord(value) {
8
+ return typeof value === "object" && value !== null && !Array.isArray(value);
9
+ }
10
+ function toRepoAbsolute(absolutePath, repoRoot) {
11
+ return `/${relative(repoRoot, absolutePath).replace(/\\/g, "/")}`;
12
+ }
13
+ // ---- scope resolution ---------------------------------------------------------
14
+ // Artifact label shown in the timeline for gates and milestones. Catalog titles follow
15
+ // `成果物カタログ(<name>)`; anything else is left unset rather than guessed.
16
+ export function artifactNameFromCatalogTitle(title) {
17
+ const match = title?.match(/^成果物カタログ((.+))$/);
18
+ return match ? match[1] : undefined;
19
+ }
20
+ // Resolves the catalogs a track covers. An existing strategy is authoritative (a human may have
21
+ // narrowed the scope on purpose); otherwise the Timeline track plan decides which domains belong
22
+ // to the track, and every catalog file of those domains (including physical splits) is included.
23
+ export function resolveTrackScopeCatalogs(opts) {
24
+ const { repoRoot, catalogPath, timelinePath, track } = opts;
25
+ const warnings = [];
26
+ const errors = [];
27
+ const byDomain = collectCatalogFilesByDomain(catalogPath);
28
+ const refFor = (filePath, localIds) => {
29
+ const doc = readYaml(filePath);
30
+ if (!doc?.id || !doc.domain) {
31
+ errors.push(`${filePath}: id / domain が読み取れないため scope に含められない。`);
32
+ return null;
33
+ }
34
+ return {
35
+ id: doc.id,
36
+ path: toRepoAbsolute(filePath, repoRoot),
37
+ ...(localIds ? { local_ids: localIds } : {}),
38
+ domain: doc.domain,
39
+ ...(doc.title ? { title: doc.title } : {}),
40
+ };
41
+ };
42
+ const timelineCatalogs = [];
43
+ const indexFile = join(timelinePath, "tml-index.yaml");
44
+ if (existsSync(indexFile)) {
45
+ const { index, errors: loadErrors } = loadTimelineIndex(indexFile);
46
+ if (loadErrors.length > 0) {
47
+ warnings.push(`${basename(indexFile)}: ${loadErrors.join(" / ")}`);
48
+ }
49
+ const plan = index.tracks.find((entry) => entry.track === track);
50
+ if (plan) {
51
+ for (const domain of plan.domains) {
52
+ const files = byDomain.get(domain) ?? [];
53
+ if (files.length === 0) {
54
+ warnings.push(`timeline: track '${track}' の domain '${domain}' に対応する dct-*.yaml が無い(scope から除外)。`);
55
+ continue;
56
+ }
57
+ for (const filePath of files) {
58
+ const ref = refFor(filePath);
59
+ if (ref)
60
+ timelineCatalogs.push(ref);
61
+ }
62
+ }
63
+ if (plan.catalog_status !== "primary") {
64
+ warnings.push(`timeline: track '${track}' の catalog_status は '${plan.catalog_status}'。` +
65
+ `strategy 生成では昇格させないため、確認後に人間が primary へ更新する。`);
66
+ }
67
+ }
68
+ else {
69
+ warnings.push(`timeline: track '${track}' が tml-index.yaml に無い。`);
70
+ }
71
+ }
72
+ const existingScope = isRecord(opts.existingStrategy?.scope)
73
+ ? opts.existingStrategy.scope
74
+ : undefined;
75
+ const existingCatalogs = Array.isArray(existingScope?.catalogs) ? existingScope.catalogs : [];
76
+ if (existingCatalogs.length > 0) {
77
+ const catalogs = [];
78
+ for (const entry of existingCatalogs) {
79
+ if (!isRecord(entry) || typeof entry.path !== "string")
80
+ continue;
81
+ let localIds;
82
+ if (entry.local_ids !== undefined) {
83
+ if (!Array.isArray(entry.local_ids) ||
84
+ entry.local_ids.length === 0 ||
85
+ entry.local_ids.some((localId) => typeof localId !== "string" || localId.length === 0)) {
86
+ errors.push(`scope.catalogs: ${entry.path} の local_ids は空でない文字列配列にする。`);
87
+ }
88
+ else {
89
+ localIds = entry.local_ids;
90
+ }
91
+ }
92
+ const filePath = resolve(repoRoot, entry.path.replace(/^\//, ""));
93
+ if (!existsSync(filePath)) {
94
+ errors.push(`scope.catalogs: カタログが見つからない: ${entry.path}`);
95
+ continue;
96
+ }
97
+ const ref = refFor(filePath, localIds);
98
+ if (ref)
99
+ catalogs.push(ref);
100
+ }
101
+ const known = new Set(catalogs.map((catalog) => catalog.id));
102
+ for (const catalog of timelineCatalogs) {
103
+ if (known.has(catalog.id))
104
+ continue;
105
+ warnings.push(`timeline の domain から解決した ${catalog.id} が既存 scope に無い。scope を広げる場合は ` +
106
+ `sch-strategy-${track}.yaml の scope.catalogs を先に更新する。`);
107
+ }
108
+ return { catalogs, source: "strategy", warnings, errors };
109
+ }
110
+ if (timelineCatalogs.length === 0) {
111
+ errors.push(`track '${track}' の scope を解決できない。tml-index.yaml の domains と ` +
112
+ `dct-<domain>.yaml を用意するか、既存 strategy の scope.catalogs を先に定義する。`);
113
+ }
114
+ return { catalogs: timelineCatalogs, source: "timeline", warnings, errors };
115
+ }
116
+ // Deliverables of the scoped catalogs, in catalog order. `include_kinds` mirrors the strategy
117
+ // scope (work by default).
118
+ export function collectScopeDeliverables(opts) {
119
+ const errors = [];
120
+ const deliverables = [];
121
+ for (const catalog of opts.catalogs) {
122
+ const filePath = resolve(opts.repoRoot, catalog.path.replace(/^\//, ""));
123
+ const doc = readYaml(filePath);
124
+ if (!doc?.groups) {
125
+ errors.push(`${catalog.path}: groups が無い。`);
126
+ continue;
127
+ }
128
+ const collected = [];
129
+ collectResolvedDeliverables(doc.groups, resolveBasePath("", doc.base_path), collected);
130
+ const catalogLocalIds = new Set(collected.map(({ item }) => item.local_id));
131
+ for (const localId of catalog.local_ids ?? []) {
132
+ if (!catalogLocalIds.has(localId)) {
133
+ errors.push(`${catalog.id}: scope.local_ids の '${localId}' がカタログに存在しない。`);
134
+ }
135
+ }
136
+ const selectedLocalIds = catalog.local_ids ? new Set(catalog.local_ids) : null;
137
+ for (const { item } of collected) {
138
+ if (!opts.includeKinds.includes(item.kind))
139
+ continue;
140
+ if (selectedLocalIds && !selectedLocalIds.has(item.local_id))
141
+ continue;
142
+ deliverables.push({
143
+ local_id: item.local_id,
144
+ catalog_id: catalog.id,
145
+ depends_on: item.depends_on ?? [],
146
+ });
147
+ }
148
+ }
149
+ return { deliverables, errors };
150
+ }
151
+ // Owner derivation rule, in priority order:
152
+ // 1. explicit --owner <local_id>=<ROLE>
153
+ // 2. the owner already recorded in the existing strategy's owner_rules
154
+ // 3. --default-owner <ROLE>
155
+ // `done_criteria.roles` is deliberately not consulted: those are review viewpoints, not the
156
+ // role that performs the work. When no rule applies, generation stops instead of guessing.
157
+ export function resolveDeliverableOwners(opts) {
158
+ const owners = new Map();
159
+ const errors = [];
160
+ const warnings = [];
161
+ const unresolved = [];
162
+ for (const localId of opts.localIds) {
163
+ const owner = opts.overrides.get(localId) ?? opts.previous.get(localId) ?? opts.defaultOwner;
164
+ if (!owner) {
165
+ unresolved.push(localId);
166
+ continue;
167
+ }
168
+ if (opts.knownRoles && opts.knownRoles.size > 0 && !opts.knownRoles.has(owner)) {
169
+ errors.push(`owner '${owner}' は pm-roles.yaml に存在しない (${localId})。`);
170
+ continue;
171
+ }
172
+ owners.set(localId, owner);
173
+ }
174
+ for (const localId of opts.overrides.keys()) {
175
+ if (opts.localIds.includes(localId))
176
+ continue;
177
+ warnings.push(`--owner ${localId} は scope に含まれない成果物を指している(無視する)。`);
178
+ }
179
+ if (unresolved.length > 0) {
180
+ errors.push(`主担当ロールを決定できない成果物がある: ${unresolved.join(", ")}。` +
181
+ `--owner <local_id>=<ROLE> または --default-owner <ROLE> で明示する` +
182
+ `(done_criteria.roles はレビュー観点であり主担当ではない)。`);
183
+ }
184
+ return { owners, errors, warnings };
185
+ }
186
+ export function loadKnownRoles(repoRoot, rolesPath) {
187
+ if (!rolesPath)
188
+ return new Set();
189
+ const filePath = resolve(repoRoot, rolesPath);
190
+ if (!existsSync(filePath))
191
+ return new Set();
192
+ const doc = readYaml(filePath);
193
+ if (!isRecord(doc) || !Array.isArray(doc.roles))
194
+ return new Set();
195
+ const codes = doc.roles
196
+ .map((role) => (isRecord(role) && typeof role.code === "string" ? role.code : ""))
197
+ .filter(Boolean);
198
+ return new Set(codes);
199
+ }