specdojo 0.4.0 → 0.4.2
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.
- package/.github/agents/specdojo-orchestrator.md +61 -2
- package/CHANGELOG.md +65 -0
- package/README.md +8 -7
- package/dist/commands/init.js +88 -15
- package/dist/commands/night-orchestrator.js +287 -0
- package/dist/commands/orchestrator.js +10 -3
- package/dist/dashboard/timeline-build.js +4 -151
- package/dist/devcontainer/command.js +3 -1
- package/dist/devcontainer/scaffold.js +166 -5
- package/dist/exec/agent-config.js +60 -2
- package/dist/exec/events.js +17 -6
- package/dist/exec/parent-validation.js +14 -0
- package/dist/exec/pipeline-state.js +13 -0
- package/dist/exec/plans-core.js +16 -5
- package/dist/exec/plans-storage.js +11 -3
- package/dist/exec/register.js +23 -1
- package/dist/exec/repo-integration.js +1 -1
- package/dist/exec/reporter.js +113 -13
- package/dist/exec/results.js +36 -14
- package/dist/exec/run/agent-pipeline.js +3 -0
- package/dist/exec/run/agent.js +40 -5
- package/dist/exec/run/job.js +2 -2
- package/dist/exec/run/lifecycle-commands.js +2 -2
- package/dist/exec/run/register-command.js +23 -4
- package/dist/exec/run/register-core.js +17 -0
- package/dist/exec/run/register-mode.js +39 -16
- package/dist/exec/run/register-post-review.js +420 -0
- package/dist/exec/run/register-resume.js +27 -11
- package/dist/exec/run/register-worktree.js +66 -2
- package/dist/exec/run/run.js +1 -1
- package/dist/exec/run/shared.js +22 -24
- package/dist/exec/task-repos.js +102 -15
- package/dist/kata/kata.js +1 -1
- package/dist/register/core.js +17 -4
- package/dist/register/create-commands.js +62 -6
- package/dist/register/cross-project.js +134 -0
- package/dist/register/derivation.js +28 -7
- package/dist/register/event-merge.js +13 -1
- package/dist/register/events.js +4 -0
- package/dist/register/item.js +35 -5
- package/dist/register/migration.js +1 -0
- package/dist/register/register.js +47 -30
- package/dist/schedule/strategy-generate-scope.js +2 -1
- package/dist/shared/catalog-files.js +31 -0
- package/dist/shared/git.js +45 -15
- package/dist/shared/lefthook-scaffold.js +177 -0
- package/dist/shared/provider-scaffold.js +3 -2
- package/dist/shared/specdojo-config.js +87 -17
- package/dist/shared/text.js +4 -1
- package/dist/shared/timeline-index.js +125 -0
- package/dist/shared/workspace-scaffold.js +69 -0
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +2 -1
- package/docs/ja/specdojo/exec-templates/xep-register-template.md +2 -0
- package/docs/ja/specdojo/exec-templates/xrp-register-post-run-template.md +46 -0
- package/docs/ja/specdojo/guides/branch-workflow-guide.md +34 -1
- package/docs/ja/specdojo/guides/docs-structure-guide.md +2 -0
- package/docs/ja/specdojo/guides/exec-config-guide.md +79 -11
- package/docs/ja/specdojo/guides/exec-operation-guide.md +39 -1
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +9 -3
- package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +4 -2
- package/docs/ja/specdojo/guides/quick-start-guide.md +31 -6
- package/docs/ja/specdojo/guides/register-operation-guide.md +54 -0
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +52 -6
- package/docs/ja/specdojo/guides/specdojo-overview-guide.md +1 -1
- package/docs/ja/specdojo/guides/waza-guide.md +1 -1
- package/docs/ja/specdojo/references/command-reference.md +138 -64
- package/docs/ja/specdojo/references/specdojo-config-reference.md +41 -12
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +5 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +92 -18
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +6 -1
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +12 -0
- package/docs/specdojo/schemas/v1/register-events.schema.yaml +2 -0
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +21 -0
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +40 -0
- package/package.json +17 -17
- package/templates/antigravity/README.md +1 -1
- package/templates/antigravity/orchestrator.md +61 -2
- package/templates/claude/agents/specdojo-orchestrator.md +61 -2
- package/templates/codex/README.md +17 -0
- package/templates/codex/agents/specdojo-orchestrator.toml +61 -2
- package/templates/codex/orchestrator.md +61 -2
- package/templates/devcontainer/devcontainer.json +3 -0
- package/templates/devcontainer/post-create.sh +15 -7
- package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +38 -5
- package/templates/devcontainer/remote-host/ssh-config.sample +3 -0
- package/templates/devcontainer/vim/vimrc +37 -0
- package/templates/init-agent-members.yaml +6 -6
- package/templates/init-exec-defaults.yaml +20 -1
- package/templates/lefthook/tools/install-lefthook.mjs +46 -0
- package/templates/lefthook/tools/specdojo-pre-commit.mjs +207 -0
- package/templates/opencode/README.md +6 -1
- package/templates/opencode/agents/specdojo-orchestrator.md +62 -3
- /package/dist/{shared → kata}/yaml-schema-modeline.js +0 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join, relative } from "node:path";
|
|
4
|
+
import { resolveProjectPaths } from "../exec/project.js";
|
|
5
|
+
import { loadRegisterItems, resolveRegisterPaths } from "../register/register.js";
|
|
6
|
+
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
7
|
+
export function selectApprovedNightItems(items, limit) {
|
|
8
|
+
return items
|
|
9
|
+
.filter((item) => item.autopilot === "approved" &&
|
|
10
|
+
(item.type === "todo" || item.type === "issue") &&
|
|
11
|
+
item.status === "open")
|
|
12
|
+
.sort((a, b) => (a.id === b.id ? 0 : a.id < b.id ? -1 : 1))
|
|
13
|
+
.slice(0, limit);
|
|
14
|
+
}
|
|
15
|
+
export function parseRegisterRunSummary(output) {
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const line of output.split(/\r?\n/u)) {
|
|
18
|
+
const match = line.match(/^\s+(PJR-[0-9A-Z]{4})\s+(success|failure|skipped)\s+transition=(done|waiting|review|none)\s+commit=.*?(?:\s{2}reason=(.*))?$/u);
|
|
19
|
+
if (!match)
|
|
20
|
+
continue;
|
|
21
|
+
results.push({
|
|
22
|
+
id: match[1],
|
|
23
|
+
outcome: match[2],
|
|
24
|
+
transition: match[3],
|
|
25
|
+
...(match[4]?.trim() ? { reason: match[4].trim() } : {}),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return results;
|
|
29
|
+
}
|
|
30
|
+
export function consecutiveFailureCount(previous, outcomes) {
|
|
31
|
+
let count = previous;
|
|
32
|
+
for (const outcome of outcomes) {
|
|
33
|
+
if (outcome.outcome === "failure")
|
|
34
|
+
count += 1;
|
|
35
|
+
else if (outcome.outcome === "success")
|
|
36
|
+
count = 0;
|
|
37
|
+
}
|
|
38
|
+
return count;
|
|
39
|
+
}
|
|
40
|
+
export function requiresDerivedApproval(outcome) {
|
|
41
|
+
if (outcome.outcome !== "failure")
|
|
42
|
+
return false;
|
|
43
|
+
return /protected|agent-config-write|git-state|\b(?:tag|push|publish)\b|CHANGELOG|scope|範囲|承認/iu.test(outcome.reason ?? "");
|
|
44
|
+
}
|
|
45
|
+
function positiveInteger(value, option) {
|
|
46
|
+
if (!/^[1-9]\d*$/u.test(value))
|
|
47
|
+
throw new Error(`${option} must be a positive integer: ${value}`);
|
|
48
|
+
const parsed = Number(value);
|
|
49
|
+
if (!Number.isSafeInteger(parsed))
|
|
50
|
+
throw new Error(`${option} is too large: ${value}`);
|
|
51
|
+
return parsed;
|
|
52
|
+
}
|
|
53
|
+
function safeCell(value) {
|
|
54
|
+
return (value?.trim() || "-").replaceAll("|", "\\|").replace(/\r?\n/gu, " ");
|
|
55
|
+
}
|
|
56
|
+
export function renderNightReport(options) {
|
|
57
|
+
const stamp = options.startedAt
|
|
58
|
+
.replace(/[-:.]/gu, "")
|
|
59
|
+
.replace(/\.\d+Z$/u, "Z")
|
|
60
|
+
.toLowerCase();
|
|
61
|
+
const byId = new Map(options.outcomes.map((outcome) => [outcome.id, outcome]));
|
|
62
|
+
const rows = options.selected.map((item) => {
|
|
63
|
+
const outcome = byId.get(item.id);
|
|
64
|
+
return `| ${item.id} | ${outcome?.outcome ?? "skipped"} | ${outcome?.transition ?? "none"} | ${safeCell(outcome?.reason)} |`;
|
|
65
|
+
});
|
|
66
|
+
const closed = options.outcomes
|
|
67
|
+
.filter((item) => item.transition === "done")
|
|
68
|
+
.map((item) => item.id);
|
|
69
|
+
const waiting = options.outcomes
|
|
70
|
+
.filter((item) => item.transition === "waiting")
|
|
71
|
+
.map((item) => item.id);
|
|
72
|
+
const approvals = [...options.approvalIssues].map(([source, created]) => `${created}(${source} 由来)`);
|
|
73
|
+
const list = (values) => (values.length > 0 ? values.join("、") : "なし");
|
|
74
|
+
return `---
|
|
75
|
+
specdojo:
|
|
76
|
+
id: ${options.projectId}:night-orchestrator-report-${stamp}
|
|
77
|
+
type: report
|
|
78
|
+
status: draft
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
# 夜間 orchestrator 朝報告 ${options.startedAt.slice(0, 10)}
|
|
82
|
+
|
|
83
|
+
- 開始: \`${options.startedAt}\`
|
|
84
|
+
- 完了: \`${options.completedAt}\`
|
|
85
|
+
- 停止理由: ${safeCell(options.stopReason)}
|
|
86
|
+
|
|
87
|
+
## 集計
|
|
88
|
+
|
|
89
|
+
- close: ${list(closed)}
|
|
90
|
+
- \`waiting\`: ${list(waiting)}
|
|
91
|
+
- 新しい承認待ち: ${list(approvals)}
|
|
92
|
+
|
|
93
|
+
## 実行結果
|
|
94
|
+
|
|
95
|
+
| 項目 | 結果 | 遷移 | 理由 |
|
|
96
|
+
| ---- | ---- | ---- | ---- |
|
|
97
|
+
${rows.join("\n") || "| - | skipped | none | 承認済みの open todo/issue なし |"}
|
|
98
|
+
`;
|
|
99
|
+
}
|
|
100
|
+
const MAX_CAPTURED_OUTPUT = 2 * 1024 * 1024;
|
|
101
|
+
function appendOutputTail(current, chunk) {
|
|
102
|
+
const combined = current + chunk;
|
|
103
|
+
return combined.length <= MAX_CAPTURED_OUTPUT
|
|
104
|
+
? combined
|
|
105
|
+
: combined.slice(combined.length - MAX_CAPTURED_OUTPUT);
|
|
106
|
+
}
|
|
107
|
+
async function runCaptured(command, args) {
|
|
108
|
+
return await new Promise((resolveRun, reject) => {
|
|
109
|
+
const child = spawn(command, args, {
|
|
110
|
+
cwd: specdojoRootDir(),
|
|
111
|
+
env: process.env,
|
|
112
|
+
stdio: "pipe",
|
|
113
|
+
});
|
|
114
|
+
let stdout = "";
|
|
115
|
+
let stderr = "";
|
|
116
|
+
child.stdout.on("data", (chunk) => {
|
|
117
|
+
const text = chunk.toString();
|
|
118
|
+
stdout = appendOutputTail(stdout, text);
|
|
119
|
+
process.stdout.write(text);
|
|
120
|
+
});
|
|
121
|
+
child.stderr.on("data", (chunk) => {
|
|
122
|
+
const text = chunk.toString();
|
|
123
|
+
stderr = appendOutputTail(stderr, text);
|
|
124
|
+
process.stderr.write(text);
|
|
125
|
+
});
|
|
126
|
+
child.once("error", reject);
|
|
127
|
+
child.once("close", (code) => resolveRun({ code: code ?? 1, stdout, stderr }));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function cliInvocation(args) {
|
|
131
|
+
const entry = process.argv[1];
|
|
132
|
+
if (!entry)
|
|
133
|
+
throw new Error("Cannot resolve the current specdojo CLI entry point.");
|
|
134
|
+
return [process.execPath, [entry, ...args]];
|
|
135
|
+
}
|
|
136
|
+
async function addDerivedApprovalIssue(projectId, item, reason) {
|
|
137
|
+
const [command, args] = cliInvocation([
|
|
138
|
+
"register",
|
|
139
|
+
"add",
|
|
140
|
+
"--project",
|
|
141
|
+
projectId,
|
|
142
|
+
"--type",
|
|
143
|
+
"issue",
|
|
144
|
+
"--title",
|
|
145
|
+
`${item.id} 夜間実行で見つかった承認待ち`,
|
|
146
|
+
"--description",
|
|
147
|
+
`夜間 orchestrator は承認範囲外の対応が必要と判断した。元項目は ${item.id}。理由: ${reason}`,
|
|
148
|
+
"--priority",
|
|
149
|
+
item.priority,
|
|
150
|
+
"--owner",
|
|
151
|
+
item.owner,
|
|
152
|
+
"--from",
|
|
153
|
+
item.id,
|
|
154
|
+
"--topic",
|
|
155
|
+
`night-approval-${item.id.toLowerCase()}`,
|
|
156
|
+
"--by",
|
|
157
|
+
"night-orchestrator",
|
|
158
|
+
"--reason",
|
|
159
|
+
"approved night run requires human authorization",
|
|
160
|
+
]);
|
|
161
|
+
const result = await runCaptured(command, args);
|
|
162
|
+
if (result.code !== 0)
|
|
163
|
+
throw new Error(`Failed to create derived approval for ${item.id}.`);
|
|
164
|
+
const created = result.stdout.match(/\(added (PJR-[0-9A-Z]{4})\)/u)?.[1];
|
|
165
|
+
if (!created)
|
|
166
|
+
throw new Error(`Could not read the derived approval ID for ${item.id}.`);
|
|
167
|
+
return created;
|
|
168
|
+
}
|
|
169
|
+
export function registerNightOrchestratorCommand(orchestrator) {
|
|
170
|
+
orchestrator
|
|
171
|
+
.command("night")
|
|
172
|
+
.description("Run only human-approved register todo/issue items and write a morning report")
|
|
173
|
+
.option("--project <projectId>", "Project id in specdojo.config.json")
|
|
174
|
+
.option("--max-items <n>", "Maximum items in one night", "10")
|
|
175
|
+
.option("--parallel <n>", "Maximum parallel item runs", "2")
|
|
176
|
+
.option("--max-consecutive-failures <n>", "Stop after this many consecutive failures", "2")
|
|
177
|
+
.option("--on-rate-limit <action>", "Override the difficulty route's pinned-agent action: stop|wait|fallback")
|
|
178
|
+
.option("--fallback-executor-by <nickname>", "Fallback executor for rate limits or configured connection errors")
|
|
179
|
+
.option("--scheduled-at <dateTime>", "Scheduled occurrence time used in the report")
|
|
180
|
+
.option("--dry-run", "Print the approved queue without executing", false)
|
|
181
|
+
.action(async (opts) => {
|
|
182
|
+
try {
|
|
183
|
+
const maxItems = positiveInteger(opts.maxItems, "--max-items");
|
|
184
|
+
const parallel = positiveInteger(opts.parallel, "--parallel");
|
|
185
|
+
const maxFailures = positiveInteger(opts.maxConsecutiveFailures, "--max-consecutive-failures");
|
|
186
|
+
if (opts.onRateLimit !== undefined &&
|
|
187
|
+
!["stop", "wait", "fallback"].includes(opts.onRateLimit)) {
|
|
188
|
+
throw new Error('--on-rate-limit must be "stop", "wait", or "fallback".');
|
|
189
|
+
}
|
|
190
|
+
const resolved = resolveProjectPaths({ project: opts.project });
|
|
191
|
+
const projectId = resolved.projectId ?? opts.project;
|
|
192
|
+
if (!projectId)
|
|
193
|
+
throw new Error("orchestrator night requires --project <id>.");
|
|
194
|
+
const items = loadRegisterItems(resolveRegisterPaths({ project: projectId })).map((view) => view.item);
|
|
195
|
+
const selected = selectApprovedNightItems(items, maxItems);
|
|
196
|
+
process.stdout.write(`[night] approved queue (${selected.length}/${maxItems}): ${selected.map((item) => item.id).join(", ") || "none"}\n`);
|
|
197
|
+
if (opts.dryRun)
|
|
198
|
+
return;
|
|
199
|
+
const startedAt = opts.scheduledAt
|
|
200
|
+
? new Date(opts.scheduledAt).toISOString()
|
|
201
|
+
: new Date().toISOString();
|
|
202
|
+
const outcomes = [];
|
|
203
|
+
const approvalIssues = new Map();
|
|
204
|
+
let consecutiveFailures = 0;
|
|
205
|
+
let stopReason;
|
|
206
|
+
for (let offset = 0; offset < selected.length; offset += parallel) {
|
|
207
|
+
const wave = selected.slice(offset, offset + parallel);
|
|
208
|
+
const [command, args] = cliInvocation([
|
|
209
|
+
"exec",
|
|
210
|
+
"run",
|
|
211
|
+
"--project",
|
|
212
|
+
projectId,
|
|
213
|
+
"--register",
|
|
214
|
+
...wave.map((item) => item.id),
|
|
215
|
+
"--worktree",
|
|
216
|
+
"--post-review",
|
|
217
|
+
"--parallel",
|
|
218
|
+
String(parallel),
|
|
219
|
+
"--on-failure",
|
|
220
|
+
"continue",
|
|
221
|
+
...(opts.onRateLimit ? ["--on-rate-limit", opts.onRateLimit] : []),
|
|
222
|
+
...(opts.fallbackExecutorBy ? ["--fallback-executor-by", opts.fallbackExecutorBy] : []),
|
|
223
|
+
]);
|
|
224
|
+
const result = await runCaptured(command, args);
|
|
225
|
+
const parsed = parseRegisterRunSummary(result.stdout);
|
|
226
|
+
const parsedById = new Map(parsed.map((outcome) => [outcome.id, outcome]));
|
|
227
|
+
const waveOutcomes = wave.map((item) => parsedById.get(item.id) ?? {
|
|
228
|
+
id: item.id,
|
|
229
|
+
outcome: "failure",
|
|
230
|
+
transition: "waiting",
|
|
231
|
+
reason: `exec run ended with code ${result.code} without an item summary`,
|
|
232
|
+
});
|
|
233
|
+
outcomes.push(...waveOutcomes);
|
|
234
|
+
for (const outcome of waveOutcomes) {
|
|
235
|
+
if (!requiresDerivedApproval(outcome))
|
|
236
|
+
continue;
|
|
237
|
+
const source = wave.find((item) => item.id === outcome.id);
|
|
238
|
+
if (source) {
|
|
239
|
+
const existing = items.find((item) => item.type === "issue" &&
|
|
240
|
+
!["done", "decided", "rejected", "deferred"].includes(item.status) &&
|
|
241
|
+
item.derivedFrom?.includes(source.id) &&
|
|
242
|
+
item.title.startsWith(`${source.id} 夜間実行で見つかった承認待ち`));
|
|
243
|
+
approvalIssues.set(source.id, existing?.id ??
|
|
244
|
+
(await addDerivedApprovalIssue(projectId, source, outcome.reason ?? "approval required")));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
consecutiveFailures = consecutiveFailureCount(consecutiveFailures, waveOutcomes);
|
|
248
|
+
if (consecutiveFailures >= maxFailures) {
|
|
249
|
+
stopReason = `連続失敗が上限 ${maxFailures} 件に達した`;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const processed = new Set(outcomes.map((outcome) => outcome.id));
|
|
254
|
+
for (const item of selected) {
|
|
255
|
+
if (!processed.has(item.id)) {
|
|
256
|
+
outcomes.push({
|
|
257
|
+
id: item.id,
|
|
258
|
+
outcome: "skipped",
|
|
259
|
+
transition: "none",
|
|
260
|
+
reason: stopReason ?? "not started",
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const completedAt = new Date().toISOString();
|
|
265
|
+
const reportsPath = join(resolved.executionPath, "reports", "night-orchestrator");
|
|
266
|
+
mkdirSync(reportsPath, { recursive: true });
|
|
267
|
+
const reportName = `night-orchestrator-${startedAt.replace(/[-:.]/gu, "").replace(/\.\d+Z$/u, "Z")}.md`;
|
|
268
|
+
const reportPath = join(reportsPath, reportName);
|
|
269
|
+
writeFileSync(reportPath, renderNightReport({
|
|
270
|
+
projectId,
|
|
271
|
+
startedAt,
|
|
272
|
+
completedAt,
|
|
273
|
+
selected,
|
|
274
|
+
outcomes,
|
|
275
|
+
approvalIssues,
|
|
276
|
+
...(stopReason ? { stopReason } : {}),
|
|
277
|
+
}), "utf8");
|
|
278
|
+
process.stdout.write(`[night] morning report: ${relative(specdojoRootDir(), reportPath)}\n`);
|
|
279
|
+
if (outcomes.some((outcome) => outcome.outcome === "failure"))
|
|
280
|
+
process.exitCode = 2;
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
284
|
+
process.exitCode = 1;
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
@@ -3,6 +3,7 @@ import { constants as osConstants } from "node:os";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { agentExtraRootArguments, resolveProductRepos } from "../exec/task-repos.js";
|
|
5
5
|
import { loadConfig, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
6
|
+
import { registerNightOrchestratorCommand } from "./night-orchestrator.js";
|
|
6
7
|
const ORCHESTRATOR_EXECUTABLES = {
|
|
7
8
|
claude: "claude",
|
|
8
9
|
codex: "codex",
|
|
@@ -10,6 +11,7 @@ const ORCHESTRATOR_EXECUTABLES = {
|
|
|
10
11
|
copilot: "copilot",
|
|
11
12
|
opencode: "opencode",
|
|
12
13
|
};
|
|
14
|
+
const ORCHESTRATOR_CONFIG_ROOT_ENV = "SPECDOJO_ORCHESTRATOR_CONFIG_ROOT";
|
|
13
15
|
function isRecord(value) {
|
|
14
16
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15
17
|
}
|
|
@@ -122,18 +124,22 @@ export function buildOrchestratorLaunch(options) {
|
|
|
122
124
|
export function resolveOrchestratorLaunch(options) {
|
|
123
125
|
const env = options.env ?? process.env;
|
|
124
126
|
const rootDir = specdojoRootDir();
|
|
125
|
-
const
|
|
127
|
+
const configuredRoot = env[ORCHESTRATOR_CONFIG_ROOT_ENV]?.trim();
|
|
128
|
+
const configRootDir = configuredRoot ? resolve(rootDir, configuredRoot) : rootDir;
|
|
129
|
+
const { config, configPath } = loadConfig(configRootDir);
|
|
126
130
|
if (!config)
|
|
127
131
|
throw new Error(`No config found: ${configPath}`);
|
|
128
132
|
const projectId = resolveOrchestratorProjectId(config, options.project, env);
|
|
129
|
-
const repos = resolveProductRepos(
|
|
130
|
-
|
|
133
|
+
const repos = resolveProductRepos(configRootDir, config.projects[projectId]);
|
|
134
|
+
const launch = buildOrchestratorLaunch({
|
|
131
135
|
provider: options.provider,
|
|
132
136
|
providerArgs: options.providerArgs,
|
|
133
137
|
repoRoots: repos.map((repo) => repo.repoRoot),
|
|
134
138
|
cwd: rootDir,
|
|
135
139
|
env,
|
|
136
140
|
});
|
|
141
|
+
delete launch.env[ORCHESTRATOR_CONFIG_ROOT_ENV];
|
|
142
|
+
return launch;
|
|
137
143
|
}
|
|
138
144
|
function parseProvider(value) {
|
|
139
145
|
if (Object.hasOwn(ORCHESTRATOR_EXECUTABLES, value)) {
|
|
@@ -188,6 +194,7 @@ export function registerOrchestratorCommands(program) {
|
|
|
188
194
|
const orchestrator = program
|
|
189
195
|
.command("orchestrator")
|
|
190
196
|
.description("Launch an interactive orchestrator with declared repository access");
|
|
197
|
+
registerNightOrchestratorCommand(orchestrator);
|
|
191
198
|
orchestrator
|
|
192
199
|
.command("launch")
|
|
193
200
|
.description("Launch a provider CLI and allow only repositories declared by the project")
|
|
@@ -1,130 +1,8 @@
|
|
|
1
|
-
import { existsSync
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
function isRecord(value) {
|
|
7
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
-
}
|
|
9
|
-
function readStringArray(value, field, errors) {
|
|
10
|
-
if (value === undefined)
|
|
11
|
-
return [];
|
|
12
|
-
if (!Array.isArray(value)) {
|
|
13
|
-
errors.push(`${field}: must be an array of strings`);
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
const result = [];
|
|
17
|
-
for (const item of value) {
|
|
18
|
-
if (typeof item !== "string" || item.trim().length === 0) {
|
|
19
|
-
errors.push(`${field}: must contain non-empty strings only`);
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
result.push(item);
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
function parseTrack(raw, index, errors) {
|
|
27
|
-
const where = `tracks[${index}]`;
|
|
28
|
-
if (!isRecord(raw)) {
|
|
29
|
-
errors.push(`${where}: must be an object`);
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
const track = raw.track;
|
|
33
|
-
if (typeof track !== "string" || track.trim().length === 0) {
|
|
34
|
-
errors.push(`${where}.track: required non-empty string`);
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const domains = readStringArray(raw.domains, `${where}.domains`, errors);
|
|
38
|
-
if (domains.length === 0)
|
|
39
|
-
errors.push(`${where}.domains: required non-empty array`);
|
|
40
|
-
const catalogStatus = raw.catalog_status;
|
|
41
|
-
if (typeof catalogStatus !== "string" ||
|
|
42
|
-
!CATALOG_STATUSES.includes(catalogStatus)) {
|
|
43
|
-
errors.push(`${where}.catalog_status: must be one of ${CATALOG_STATUSES.join(" | ")}`);
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
const order = raw.order;
|
|
47
|
-
if (typeof order !== "number" || !Number.isInteger(order) || order < 1) {
|
|
48
|
-
errors.push(`${where}.order: must be an integer >= 1`);
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
if (raw.depends_on === undefined) {
|
|
52
|
-
errors.push(`${where}.depends_on: required (use [] when there is no prerequisite)`);
|
|
53
|
-
}
|
|
54
|
-
const dependsOn = readStringArray(raw.depends_on, `${where}.depends_on`, errors);
|
|
55
|
-
const estimate = raw.catalog_duration_estimate_days;
|
|
56
|
-
if (estimate !== undefined && (typeof estimate !== "number" || estimate <= 0)) {
|
|
57
|
-
errors.push(`${where}.catalog_duration_estimate_days: must be a number > 0`);
|
|
58
|
-
}
|
|
59
|
-
const parallelGroup = raw.parallel_group;
|
|
60
|
-
if (parallelGroup !== undefined && typeof parallelGroup !== "string") {
|
|
61
|
-
errors.push(`${where}.parallel_group: must be a string`);
|
|
62
|
-
}
|
|
63
|
-
const note = raw.note;
|
|
64
|
-
if (note !== undefined && typeof note !== "string") {
|
|
65
|
-
errors.push(`${where}.note: must be a string`);
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
track,
|
|
69
|
-
domains,
|
|
70
|
-
catalog_status: catalogStatus,
|
|
71
|
-
...(typeof estimate === "number" ? { catalog_duration_estimate_days: estimate } : {}),
|
|
72
|
-
order,
|
|
73
|
-
...(typeof parallelGroup === "string" ? { parallel_group: parallelGroup } : {}),
|
|
74
|
-
depends_on: dependsOn,
|
|
75
|
-
...(typeof note === "string" ? { note } : {}),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
export function loadTimelineIndex(filePath) {
|
|
79
|
-
const errors = [];
|
|
80
|
-
const parsed = readYaml(filePath);
|
|
81
|
-
if (!isRecord(parsed)) {
|
|
82
|
-
throw new Error(`${filePath}: invalid or empty YAML`);
|
|
83
|
-
}
|
|
84
|
-
const projectId = parsed.project_id;
|
|
85
|
-
if (typeof projectId !== "string" || projectId.trim().length === 0) {
|
|
86
|
-
errors.push(`project_id: required non-empty string`);
|
|
87
|
-
}
|
|
88
|
-
if (!Array.isArray(parsed.tracks) || parsed.tracks.length === 0) {
|
|
89
|
-
errors.push(`tracks: required non-empty array`);
|
|
90
|
-
return {
|
|
91
|
-
index: {
|
|
92
|
-
id: typeof parsed.id === "string" ? parsed.id : "",
|
|
93
|
-
project_id: typeof projectId === "string" ? projectId : "",
|
|
94
|
-
status: typeof parsed.status === "string" ? parsed.status : "",
|
|
95
|
-
tracks: [],
|
|
96
|
-
},
|
|
97
|
-
errors,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
const tracks = [];
|
|
101
|
-
parsed.tracks.forEach((raw, index) => {
|
|
102
|
-
const track = parseTrack(raw, index, errors);
|
|
103
|
-
if (track)
|
|
104
|
-
tracks.push(track);
|
|
105
|
-
});
|
|
106
|
-
// 計画開始日は YYYY-MM-DD に正規化する。不正な値はエラーとして報告し、未設定とみなす。
|
|
107
|
-
let plannedStartDate;
|
|
108
|
-
if (parsed.planned_start_date !== undefined && parsed.planned_start_date !== null) {
|
|
109
|
-
const normalized = normalizeDateOnly(parsed.planned_start_date);
|
|
110
|
-
if (!normalized) {
|
|
111
|
-
errors.push("planned_start_date: must be a YYYY-MM-DD date");
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
plannedStartDate = normalized;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
index: {
|
|
119
|
-
id: typeof parsed.id === "string" ? parsed.id : "",
|
|
120
|
-
project_id: typeof projectId === "string" ? projectId : "",
|
|
121
|
-
status: typeof parsed.status === "string" ? parsed.status : "",
|
|
122
|
-
tracks,
|
|
123
|
-
...(plannedStartDate !== undefined ? { planned_start_date: plannedStartDate } : {}),
|
|
124
|
-
},
|
|
125
|
-
errors,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
3
|
+
import { collectCatalogFilesByDomain } from "../shared/catalog-files.js";
|
|
4
|
+
import { loadTimelineIndex, } from "../shared/timeline-index.js";
|
|
5
|
+
export { collectCatalogFilesByDomain, loadTimelineIndex };
|
|
128
6
|
// depends_on の未定義参照・循環・order との矛盾を検出する。
|
|
129
7
|
export function validateTimelineTracks(tracks) {
|
|
130
8
|
const errors = [];
|
|
@@ -193,31 +71,6 @@ export function buildTimelineWaves(tracks) {
|
|
|
193
71
|
tracks: [...group].sort((a, b) => a.track.localeCompare(b.track)),
|
|
194
72
|
}));
|
|
195
73
|
}
|
|
196
|
-
// 1 ドメインが dct-<domain>-<sub>.yaml のように複数ファイルへ分割されることがあるため、
|
|
197
|
-
// ファイル名ではなく各カタログの domain 値で突き合わせる。
|
|
198
|
-
export function collectCatalogFilesByDomain(catalogPath) {
|
|
199
|
-
const byDomain = new Map();
|
|
200
|
-
if (!existsSync(catalogPath))
|
|
201
|
-
return byDomain;
|
|
202
|
-
const files = readdirSync(catalogPath)
|
|
203
|
-
.filter((file) => /^dct-.+\.ya?ml$/.test(file))
|
|
204
|
-
.sort();
|
|
205
|
-
for (const file of files) {
|
|
206
|
-
const fullPath = join(catalogPath, file);
|
|
207
|
-
const parsed = readYaml(fullPath);
|
|
208
|
-
if (!isRecord(parsed))
|
|
209
|
-
continue;
|
|
210
|
-
const domain = parsed.domain;
|
|
211
|
-
if (typeof domain !== "string" || domain.trim().length === 0)
|
|
212
|
-
continue;
|
|
213
|
-
const group = byDomain.get(domain);
|
|
214
|
-
if (group)
|
|
215
|
-
group.push(fullPath);
|
|
216
|
-
else
|
|
217
|
-
byDomain.set(domain, [fullPath]);
|
|
218
|
-
}
|
|
219
|
-
return byDomain;
|
|
220
|
-
}
|
|
221
74
|
// catalog_status と実カタログの有無から catalog scaffold の対象を決める。
|
|
222
75
|
export function buildCatalogScaffoldPlans(tracks, catalogPath) {
|
|
223
76
|
const scaffolds = [];
|
|
@@ -5,8 +5,9 @@ export function registerDevcontainerCommands(program) {
|
|
|
5
5
|
const dc = program.command("devcontainer").description("Dev Container helpers");
|
|
6
6
|
dc.command("scaffold")
|
|
7
7
|
.description("Scaffold .devcontainer/ configuration for the repository")
|
|
8
|
+
.option("--preset <name>", "Apply a bundled preset (available: recommended)")
|
|
8
9
|
.option("--provider <names>", "Comma-separated list of agent providers to install (e.g. claude,codex,opencode,antigravity)", "")
|
|
9
|
-
.option("--editor <names>", "Comma-separated list of editors to install and configure (
|
|
10
|
+
.option("--editor <names>", "Comma-separated list of editors to install and configure (emacs,vim)", "")
|
|
10
11
|
.option("--ollama", "Add Ollama connection settings", false)
|
|
11
12
|
.option("--cron", "Add cron support", false)
|
|
12
13
|
.option("--tmux", "Add tmux", false)
|
|
@@ -19,6 +20,7 @@ export function registerDevcontainerCommands(program) {
|
|
|
19
20
|
packageRoot: specdojoPackageRootDir(),
|
|
20
21
|
repoRoot: specdojoRootDir(),
|
|
21
22
|
workspaceName: opts.workspaceName === undefined ? undefined : String(opts.workspaceName),
|
|
23
|
+
preset: opts.preset === undefined ? undefined : String(opts.preset),
|
|
22
24
|
providers: opts.provider
|
|
23
25
|
? String(opts.provider)
|
|
24
26
|
.split(",")
|