specdojo 0.2.1 → 0.3.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.
- package/.github/agents/specdojo-orchestrator.md +165 -0
- package/CHANGELOG.md +280 -0
- package/README.md +92 -42
- package/dist/agent-response.js +20 -0
- package/dist/agent.js +4 -4
- package/dist/build-command.js +28 -8
- package/dist/dashboard.js +122 -1
- package/dist/devcontainer-command.js +43 -0
- package/dist/devcontainer-scaffold.js +165 -0
- package/dist/exec-agent-config.js +107 -9
- package/dist/exec-agent-git-state.js +18 -0
- package/dist/exec-agent-protected-config.js +46 -8
- package/dist/exec-evidence.js +254 -11
- package/dist/exec-handoff.js +336 -0
- package/dist/exec-parent-validation.js +317 -43
- package/dist/exec-pipeline-state.js +74 -9
- package/dist/exec-plans.js +115 -113
- package/dist/exec-protection-handoff.js +43 -2
- package/dist/exec-provider-scaffold.js +247 -15
- package/dist/exec-register-resume.js +65 -19
- package/dist/exec-register.js +9 -3
- package/dist/exec-repo-integration.js +811 -0
- package/dist/exec-repo-trace.js +182 -0
- package/dist/exec-reporter.js +613 -132
- package/dist/exec-results.js +81 -56
- package/dist/exec-run-lock.js +110 -107
- package/dist/exec-run.js +1585 -356
- package/dist/exec-shared.js +7 -0
- package/dist/exec-slot-lock.js +242 -0
- package/dist/exec-task-repos.js +415 -0
- package/dist/exec-trial.js +51 -25
- package/dist/exec-worktree-command.js +87 -43
- package/dist/exec-worktree-ops.js +502 -57
- package/dist/exec-worktree.js +114 -27
- package/dist/exec.js +13 -6
- package/dist/grade-result.js +128 -0
- package/dist/grade.js +809 -72
- package/dist/init-command.js +443 -0
- package/dist/job.js +160 -10
- package/dist/orchestrator.js +213 -0
- package/dist/register-event-merge.js +169 -0
- package/dist/register-item.js +7 -1
- package/dist/register.js +294 -86
- package/dist/review-grade.js +252 -0
- package/dist/review-plan.js +111 -1
- package/dist/review-types.js +40 -1
- package/dist/routine.js +72 -5
- package/dist/schedule-build.js +2 -2
- package/dist/schedule.js +17 -4
- package/dist/specdojo-config.js +465 -19
- package/dist/specdojo-gitignore.js +135 -0
- package/dist/specdojo.js +6 -0
- package/dist/viewpoint-document-kinds-check.js +128 -0
- package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
- package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
- package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
- package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
- package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
- package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
- package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
- package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
- package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
- package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
- package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
- package/docs/ja/specdojo/guides/exec-config-guide.md +91 -47
- package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
- package/docs/ja/specdojo/guides/kata-guide.md +4 -4
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +25 -4
- package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
- package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
- package/docs/ja/specdojo/guides/quick-start-guide.md +260 -30
- package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
- package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +22 -1
- package/docs/ja/specdojo/guides/review-guide.md +195 -158
- package/docs/ja/specdojo/guides/routine-operation-guide.md +74 -9
- package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
- package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
- package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
- package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
- package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
- package/docs/ja/specdojo/guides/waza-guide.md +15 -2
- package/docs/ja/specdojo/index.md +2 -2
- package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
- package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
- package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
- package/docs/ja/specdojo/references/command-reference.md +335 -92
- package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
- package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
- package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
- package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
- package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
- package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
- package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
- package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
- package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
- package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
- package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
- package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
- package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
- package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
- package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
- package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
- package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
- package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
- package/docs/ja/specdojo/samples/bps-sample.md +74 -21
- package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
- package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
- package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
- package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
- package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
- package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
- package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
- package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
- package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
- package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
- package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
- package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
- package/docs/ja/specdojo/templates/bps-template.md +91 -0
- package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
- package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
- package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
- package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
- package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
- package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
- package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
- package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
- package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
- package/package.json +15 -9
- package/templates/antigravity/README.md +27 -2
- package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
- package/templates/antigravity/exec-defaults-snippet.yaml +7 -6
- package/templates/antigravity/orchestrator.md +18 -7
- package/templates/antigravity/settings.global.json +55 -0
- package/templates/claude/agents/claude-executor.md +14 -0
- package/templates/claude/agents/claude-reporter.md +16 -0
- package/templates/claude/agents/specdojo-orchestrator.md +18 -7
- package/templates/claude/settings.edit.json +27 -1
- package/templates/codex/README.md +5 -4
- package/templates/codex/agents/specdojo-orchestrator.toml +18 -7
- package/templates/codex/orchestrator.md +18 -7
- package/templates/copilot/README.md +7 -5
- package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
- package/templates/devcontainer/devcontainer.json +27 -0
- package/templates/devcontainer/emacs/init.el +88 -0
- package/templates/devcontainer/post-create.sh +62 -0
- package/templates/init-agent-members.yaml +200 -0
- package/templates/init-exec-defaults.yaml +72 -0
- package/templates/opencode/agents/specdojo-orchestrator.md +18 -7
- package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
- package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { copyFile, mkdir, readdir } from "node:fs/promises";
|
|
2
|
+
import { copyFile, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
5
|
+
import { isRecord } from "./exec-shared.js";
|
|
4
6
|
export { specdojoPackageRootDir } from "./package-paths.js";
|
|
7
|
+
export const ORCHESTRATOR_NPM_SCRIPTS = {
|
|
8
|
+
claude: {
|
|
9
|
+
"orch:opus": "specdojo orchestrator launch --provider claude -- --agent specdojo-orchestrator --model opus",
|
|
10
|
+
"orch:sonnet": "specdojo orchestrator launch --provider claude -- --agent specdojo-orchestrator --model sonnet",
|
|
11
|
+
},
|
|
12
|
+
codex: {
|
|
13
|
+
"orch:codex": 'specdojo orchestrator launch --provider codex -- "$(cat .specdojo/codex/orchestrator.md)"',
|
|
14
|
+
},
|
|
15
|
+
antigravity: {
|
|
16
|
+
"orch:agy": 'specdojo orchestrator launch --provider antigravity -- --add-dir "$(pwd)" -i "$(cat .specdojo/antigravity/orchestrator.md)"',
|
|
17
|
+
},
|
|
18
|
+
opencode: {
|
|
19
|
+
"orch:opencode": "specdojo orchestrator launch --provider opencode -- --agent specdojo-orchestrator",
|
|
20
|
+
},
|
|
21
|
+
copilot: {
|
|
22
|
+
"orch:copilot": "specdojo orchestrator launch --provider copilot -- --agent specdojo-orchestrator",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const PROVIDER_GLOBAL_SETTINGS = {
|
|
26
|
+
antigravity: {
|
|
27
|
+
templateRelPath: "settings.global.json",
|
|
28
|
+
destinationSegments: [".gemini", "antigravity-cli", "settings.json"],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
5
31
|
export async function listProviderTemplates(packageRoot) {
|
|
6
32
|
const templatesDir = path.join(packageRoot, "templates");
|
|
7
33
|
if (!existsSync(templatesDir))
|
|
@@ -40,9 +66,12 @@ export async function buildProviderScaffoldPlan(opts) {
|
|
|
40
66
|
const relFiles = (await collectFilesRecursively(templateDir)).map(toPosix).sort();
|
|
41
67
|
const entries = [];
|
|
42
68
|
for (const relFile of relFiles) {
|
|
43
|
-
//
|
|
44
|
-
|
|
69
|
+
// 配布原本の説明書と、明示的な --global でだけ利用するユーザー設定は
|
|
70
|
+
// repository 内へコピーしない。
|
|
71
|
+
if (relFile === "README.md" ||
|
|
72
|
+
relFile === PROVIDER_GLOBAL_SETTINGS[provider]?.templateRelPath) {
|
|
45
73
|
continue;
|
|
74
|
+
}
|
|
46
75
|
const destinationRelPath = relFile.startsWith("agents/")
|
|
47
76
|
? `.${provider}/${relFile}`
|
|
48
77
|
: `.specdojo/${provider}/${relFile}`;
|
|
@@ -52,12 +81,138 @@ export async function buildProviderScaffoldPlan(opts) {
|
|
|
52
81
|
destinationRelPath,
|
|
53
82
|
});
|
|
54
83
|
}
|
|
55
|
-
|
|
84
|
+
// GitHub Copilot CLI discovers custom agents under .github/agents rather than
|
|
85
|
+
// .copilot/agents. The canonical wrapper is shipped directly from that native location.
|
|
86
|
+
if (provider === "copilot") {
|
|
87
|
+
const sourcePath = path.join(packageRoot, ".github", "agents", "specdojo-orchestrator.md");
|
|
88
|
+
if (existsSync(sourcePath)) {
|
|
89
|
+
entries.push({
|
|
90
|
+
sourcePath,
|
|
91
|
+
destinationPath: path.join(repoRoot, ".github", "agents", "specdojo-orchestrator.md"),
|
|
92
|
+
destinationRelPath: ".github/agents/specdojo-orchestrator.md",
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
provider,
|
|
98
|
+
entries: entries.sort((a, b) => a.destinationRelPath.localeCompare(b.destinationRelPath)),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function parseJsonObject(content, sourcePath) {
|
|
102
|
+
let parsed;
|
|
103
|
+
try {
|
|
104
|
+
parsed = JSON.parse(content);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
108
|
+
throw new Error(`Invalid JSON in ${sourcePath}: ${message}`);
|
|
109
|
+
}
|
|
110
|
+
if (!isRecord(parsed)) {
|
|
111
|
+
throw new Error(`Invalid JSON in ${sourcePath}: top-level value must be an object`);
|
|
112
|
+
}
|
|
113
|
+
return parsed;
|
|
114
|
+
}
|
|
115
|
+
function permissionList(permissions, name, sourcePath) {
|
|
116
|
+
const value = permissions[name];
|
|
117
|
+
if (value === undefined)
|
|
118
|
+
return [];
|
|
119
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string")) {
|
|
120
|
+
throw new Error(`Invalid ${sourcePath}: permissions.${name} must be an array of strings`);
|
|
121
|
+
}
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
function mergePermissionSettings(current, required, currentPath, templatePath) {
|
|
125
|
+
const currentPermissionsValue = current.permissions;
|
|
126
|
+
if (currentPermissionsValue !== undefined && !isRecord(currentPermissionsValue)) {
|
|
127
|
+
throw new Error(`Invalid ${currentPath}: permissions must be an object`);
|
|
128
|
+
}
|
|
129
|
+
if (!isRecord(required.permissions)) {
|
|
130
|
+
throw new Error(`Invalid ${templatePath}: permissions must be an object`);
|
|
131
|
+
}
|
|
132
|
+
const currentPermissions = isRecord(currentPermissionsValue) ? currentPermissionsValue : {};
|
|
133
|
+
const mergedPermissions = { ...currentPermissions };
|
|
134
|
+
const additions = { allow: [], deny: [], ask: [] };
|
|
135
|
+
for (const name of ["allow", "deny", "ask"]) {
|
|
136
|
+
const existing = permissionList(currentPermissions, name, currentPath);
|
|
137
|
+
const requiredItems = permissionList(required.permissions, name, templatePath);
|
|
138
|
+
const existingSet = new Set(existing);
|
|
139
|
+
additions[name] = requiredItems.filter((item) => !existingSet.has(item));
|
|
140
|
+
if (existing.length > 0 || requiredItems.length > 0) {
|
|
141
|
+
mergedPermissions[name] = [...existing, ...additions[name]];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
merged: { ...current, permissions: mergedPermissions },
|
|
146
|
+
additions,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function hasPermissionAdditions(additions) {
|
|
150
|
+
return additions.allow.length + additions.deny.length + additions.ask.length > 0;
|
|
151
|
+
}
|
|
152
|
+
function displayHomePath(segments) {
|
|
153
|
+
return `~/${segments.join("/")}`;
|
|
154
|
+
}
|
|
155
|
+
function printGlobalSettingsDiff(displayPath, additions, dryRun) {
|
|
156
|
+
const prefix = dryRun ? "[dry-run] " : "";
|
|
157
|
+
process.stdout.write(`${prefix}global settings diff: ${displayPath}\n`);
|
|
158
|
+
process.stdout.write(`--- ${displayPath} (current)\n`);
|
|
159
|
+
process.stdout.write(`+++ ${displayPath} (merged)\n`);
|
|
160
|
+
for (const name of ["allow", "deny", "ask"]) {
|
|
161
|
+
if (additions[name].length === 0)
|
|
162
|
+
continue;
|
|
163
|
+
process.stdout.write(`@@ permissions.${name} @@\n`);
|
|
164
|
+
for (const rule of additions[name])
|
|
165
|
+
process.stdout.write(`+ ${JSON.stringify(rule)}\n`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function nextBackupPath(settingsPath) {
|
|
169
|
+
const stamp = new Date().toISOString().replace(/[-:.]/g, "");
|
|
170
|
+
const base = `${settingsPath}.backup-${stamp}`;
|
|
171
|
+
let candidate = base;
|
|
172
|
+
let suffix = 1;
|
|
173
|
+
while (existsSync(candidate)) {
|
|
174
|
+
candidate = `${base}-${suffix}`;
|
|
175
|
+
suffix += 1;
|
|
176
|
+
}
|
|
177
|
+
return candidate;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* provider のユーザーディレクトリ設定へ、テンプレートの permission rule だけを追記する。
|
|
181
|
+
* 既存キー・既存配列要素は保持し、実書き込み前には必ず元ファイルをバックアップする。
|
|
182
|
+
*/
|
|
183
|
+
export async function mergeProviderGlobalSettings(provider, opts) {
|
|
184
|
+
const definition = PROVIDER_GLOBAL_SETTINGS[provider];
|
|
185
|
+
if (!definition) {
|
|
186
|
+
throw new Error(`Provider ${provider} does not define global settings for --global`);
|
|
187
|
+
}
|
|
188
|
+
const templatePath = path.join(opts.packageRoot, "templates", provider, ...definition.templateRelPath.split("/"));
|
|
189
|
+
const settingsPath = path.join(opts.homeDir ?? homedir(), ...definition.destinationSegments);
|
|
190
|
+
const displayPath = displayHomePath(definition.destinationSegments);
|
|
191
|
+
const required = parseJsonObject(await readFile(templatePath, "utf8"), templatePath);
|
|
192
|
+
const currentContent = existsSync(settingsPath) ? await readFile(settingsPath, "utf8") : "{}\n";
|
|
193
|
+
const current = parseJsonObject(currentContent, settingsPath);
|
|
194
|
+
const { merged, additions } = mergePermissionSettings(current, required, settingsPath, templatePath);
|
|
195
|
+
if (!hasPermissionAdditions(additions)) {
|
|
196
|
+
process.stdout.write(`Global settings unchanged: ${displayPath}\n`);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
printGlobalSettingsDiff(displayPath, additions, opts.dryRun);
|
|
200
|
+
if (opts.dryRun)
|
|
201
|
+
return;
|
|
202
|
+
await mkdir(path.dirname(settingsPath), { recursive: true });
|
|
203
|
+
if (existsSync(settingsPath)) {
|
|
204
|
+
const backupPath = await nextBackupPath(settingsPath);
|
|
205
|
+
await copyFile(settingsPath, backupPath);
|
|
206
|
+
process.stdout.write(`Backup: ${displayHomePath([...definition.destinationSegments])}${backupPath.slice(settingsPath.length)}\n`);
|
|
207
|
+
}
|
|
208
|
+
await writeFile(settingsPath, `${JSON.stringify(merged, null, detectIndent(currentContent))}\n`, "utf8");
|
|
209
|
+
process.stdout.write(`Merged global settings: ${displayPath}\n`);
|
|
56
210
|
}
|
|
57
211
|
export async function applyProviderScaffoldPlan(plan, opts) {
|
|
58
212
|
const outcomes = [];
|
|
59
213
|
for (const entry of plan.entries) {
|
|
60
|
-
if (
|
|
214
|
+
if (path.resolve(entry.sourcePath) === path.resolve(entry.destinationPath) ||
|
|
215
|
+
(existsSync(entry.destinationPath) && !opts.force)) {
|
|
61
216
|
outcomes.push({ entry, written: false });
|
|
62
217
|
continue;
|
|
63
218
|
}
|
|
@@ -78,22 +233,99 @@ export async function runProviderScaffold(provider, opts) {
|
|
|
78
233
|
repoRoot: opts.repoRoot,
|
|
79
234
|
provider,
|
|
80
235
|
});
|
|
236
|
+
if (opts.global && !PROVIDER_GLOBAL_SETTINGS[provider]) {
|
|
237
|
+
throw new Error(`Provider ${provider} does not define global settings for --global`);
|
|
238
|
+
}
|
|
81
239
|
if (opts.dryRun) {
|
|
82
240
|
for (const entry of plan.entries) {
|
|
83
|
-
|
|
241
|
+
if (path.resolve(entry.sourcePath) === path.resolve(entry.destinationPath) ||
|
|
242
|
+
(existsSync(entry.destinationPath) && !opts.force)) {
|
|
243
|
+
process.stdout.write(`Skipped (already exists): ${entry.destinationRelPath}\n`);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
process.stdout.write(`[dry-run] would write: ${entry.destinationRelPath}\n`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
const outcomes = await applyProviderScaffoldPlan(plan, { force: opts.force });
|
|
252
|
+
for (const { entry, written } of outcomes) {
|
|
253
|
+
if (written) {
|
|
254
|
+
process.stdout.write(`Written: ${entry.destinationRelPath}\n`);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
process.stdout.write(`Skipped (already exists): ${entry.destinationRelPath}\n`);
|
|
258
|
+
}
|
|
84
259
|
}
|
|
260
|
+
}
|
|
261
|
+
const scriptsToAdd = ORCHESTRATOR_NPM_SCRIPTS[provider];
|
|
262
|
+
if (scriptsToAdd) {
|
|
263
|
+
await addOrchestratorNpmScripts(path.join(opts.repoRoot, "package.json"), scriptsToAdd, {
|
|
264
|
+
dryRun: !!opts.dryRun,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
if (opts.global) {
|
|
268
|
+
await mergeProviderGlobalSettings(provider, opts);
|
|
269
|
+
}
|
|
270
|
+
if (opts.dryRun) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (opts.showNextSteps !== false) {
|
|
274
|
+
process.stdout.write("Next steps:\n" +
|
|
275
|
+
" 1. Commit the scaffolded files (worktree runs read committed content).\n" +
|
|
276
|
+
` 2. Define providers.${provider}.command_template in .specdojo/exec-defaults.yaml (see templates/${provider}/README.md).\n` +
|
|
277
|
+
" 3. Define agent members in .specdojo/agent-members.yaml (merge any agent-members-snippet.yaml members).\n");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* provider のオーケストレーター起動スクリプトを package.json へ加える。
|
|
282
|
+
* 利用者が書き換えたスクリプトを壊さないよう、既存のキーは --force でも上書きしない。
|
|
283
|
+
* package.json の読み書きに失敗した場合は、成功扱いにしないため終了コードを 1 にする。
|
|
284
|
+
*/
|
|
285
|
+
async function addOrchestratorNpmScripts(packageJsonPath, scriptsToAdd, opts) {
|
|
286
|
+
if (!existsSync(packageJsonPath)) {
|
|
287
|
+
process.stdout.write("Skipped (package.json not found)\n");
|
|
85
288
|
return;
|
|
86
289
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
290
|
+
try {
|
|
291
|
+
const content = await readFile(packageJsonPath, "utf8");
|
|
292
|
+
const parsed = JSON.parse(content);
|
|
293
|
+
if (!isRecord(parsed)) {
|
|
294
|
+
throw new Error("top-level value is not an object");
|
|
295
|
+
}
|
|
296
|
+
if (parsed.scripts !== undefined && !isRecord(parsed.scripts)) {
|
|
297
|
+
throw new Error('"scripts" is not an object');
|
|
91
298
|
}
|
|
92
|
-
|
|
93
|
-
|
|
299
|
+
const scripts = isRecord(parsed.scripts) ? parsed.scripts : {};
|
|
300
|
+
let modified = false;
|
|
301
|
+
for (const [scriptName, scriptCommand] of Object.entries(scriptsToAdd)) {
|
|
302
|
+
if (Object.hasOwn(scripts, scriptName)) {
|
|
303
|
+
process.stdout.write(`Skipped (script already exists): ${scriptName} in package.json\n`);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (opts.dryRun) {
|
|
307
|
+
process.stdout.write(`[dry-run] would add script: "${scriptName}": "${scriptCommand}" to package.json\n`);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
scripts[scriptName] = scriptCommand;
|
|
311
|
+
process.stdout.write(`Added script: ${scriptName} to package.json\n`);
|
|
312
|
+
modified = true;
|
|
94
313
|
}
|
|
314
|
+
if (modified) {
|
|
315
|
+
parsed.scripts = scripts;
|
|
316
|
+
await writeFile(packageJsonPath, JSON.stringify(parsed, null, detectIndent(content)) + "\n", "utf8");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
321
|
+
process.stderr.write(`Failed to update package.json (${packageJsonPath}): ${message}\n`);
|
|
322
|
+
process.exitCode = 1;
|
|
95
323
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
324
|
+
}
|
|
325
|
+
/** 既存の package.json の字下げ(空白の数またはタブ)を保つ。判別できなければ 2 とする。 */
|
|
326
|
+
function detectIndent(content) {
|
|
327
|
+
const match = content.match(/^[{[]\r?\n([ \t]+)\S/u);
|
|
328
|
+
if (!match)
|
|
329
|
+
return 2;
|
|
330
|
+
return match[1].includes("\t") ? "\t" : match[1].length;
|
|
99
331
|
}
|
|
@@ -2,6 +2,22 @@ import { existsSync, readdirSync } from "node:fs";
|
|
|
2
2
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { loadPipelineResumeCheckpoint } from "./exec-pipeline-state.js";
|
|
4
4
|
import { safeSlug } from "./exec-shared.js";
|
|
5
|
+
function executorResumeHandoff(evidence) {
|
|
6
|
+
if (!evidence)
|
|
7
|
+
return [];
|
|
8
|
+
const failedParentValidations = evidence.validations
|
|
9
|
+
.filter((validation) => validation.source === "runner" && validation.status === "failed")
|
|
10
|
+
.map((validation) => {
|
|
11
|
+
const id = validation.id?.trim() || validation.command.trim() || "parent validation";
|
|
12
|
+
const label = validation.repo && validation.repo !== "project" ? `${validation.repo}:${id}` : id;
|
|
13
|
+
const summary = validation.summary.trim() || "failed without a summary";
|
|
14
|
+
return `parent validation ${label} failed: ${summary}`;
|
|
15
|
+
});
|
|
16
|
+
if (failedParentValidations.length > 0)
|
|
17
|
+
return failedParentValidations;
|
|
18
|
+
const blockReason = evidence.block_reason?.trim();
|
|
19
|
+
return blockReason ? [blockReason] : [];
|
|
20
|
+
}
|
|
5
21
|
export function registerEvidenceDir(input) {
|
|
6
22
|
const executionRel = relative(input.repoRoot, input.executionPath);
|
|
7
23
|
return join(input.worktreePath, executionRel, "exec", "evidence", safeSlug(input.taskId));
|
|
@@ -35,6 +51,7 @@ export function loadRegisterResumeCandidates(input) {
|
|
|
35
51
|
stateRef,
|
|
36
52
|
statePath: checkpoint.statePath,
|
|
37
53
|
state: checkpoint.state,
|
|
54
|
+
...(checkpoint.executorEvidence ? { executorEvidence: checkpoint.executorEvidence } : {}),
|
|
38
55
|
...(checkpoint.evidence ? { evidence: checkpoint.evidence } : {}),
|
|
39
56
|
...(checkpoint.evidence
|
|
40
57
|
? {
|
|
@@ -50,16 +67,38 @@ export function loadRegisterResumeCandidates(input) {
|
|
|
50
67
|
}
|
|
51
68
|
// 再開対象は「最新の run」だけに限定する。より古い run へ遡ると、後続 run が作った
|
|
52
69
|
// 未コミット成果や result と食い違うため、最新 run が再開できない場合は理由を返して止める。
|
|
53
|
-
export function selectResumableRegisterRun(candidates) {
|
|
70
|
+
export function selectResumableRegisterRun(candidates, options = {}) {
|
|
54
71
|
if (candidates.length === 0) {
|
|
55
72
|
return { kind: "not-resumable", reason: "no pipeline run state found in the worktree" };
|
|
56
73
|
}
|
|
57
|
-
const
|
|
74
|
+
const ordered = [...candidates].sort((a, b) => {
|
|
58
75
|
if (a.state.updated_at !== b.state.updated_at) {
|
|
59
76
|
return a.state.updated_at < b.state.updated_at ? -1 : 1;
|
|
60
77
|
}
|
|
61
78
|
return a.runId < b.runId ? -1 : a.runId > b.runId ? 1 : 0;
|
|
62
|
-
})
|
|
79
|
+
});
|
|
80
|
+
const latest = ordered[candidates.length - 1];
|
|
81
|
+
// The earliest rate-limited executor attempt is the stable lower bound for every later resume.
|
|
82
|
+
// Rejected protection-block changes are intentionally excluded; the handoff requires removing
|
|
83
|
+
// them before resume. `attempt_changes` also excludes runner lifecycle changes that predated the
|
|
84
|
+
// executor invocation.
|
|
85
|
+
const firstAttemptEvidence = ordered
|
|
86
|
+
.map((candidate) => candidate.executorEvidence ?? candidate.evidence)
|
|
87
|
+
.find((evidence) => evidence?.stage.status === "rate_limited");
|
|
88
|
+
const initialChanges = [
|
|
89
|
+
...new Set((firstAttemptEvidence?.attempt_changes ?? firstAttemptEvidence?.changes ?? [])
|
|
90
|
+
.map((change) => change.path.trim())
|
|
91
|
+
.filter(Boolean)),
|
|
92
|
+
];
|
|
93
|
+
const executorTarget = (candidate, changes = initialChanges) => ({
|
|
94
|
+
stage: "executor",
|
|
95
|
+
runId: candidate.runId,
|
|
96
|
+
stateRef: candidate.stateRef,
|
|
97
|
+
statePath: candidate.statePath,
|
|
98
|
+
state: candidate.state,
|
|
99
|
+
initialChanges: [...changes],
|
|
100
|
+
handoff: executorResumeHandoff(candidate.executorEvidence ?? candidate.evidence),
|
|
101
|
+
});
|
|
63
102
|
// rate limit または保護機構の block で打ち切られた executor は、evidence が記録されていても
|
|
64
103
|
// 作業を完了していない。reporter へ進めず、申し送りを反映できるよう既存 worktree 上で
|
|
65
104
|
// executor を再開する。通常のプロセス失敗は failed のまま区別し、再開対象にしない。
|
|
@@ -67,13 +106,7 @@ export function selectResumableRegisterRun(candidates) {
|
|
|
67
106
|
latest.state.stages.executor.status === "blocked") {
|
|
68
107
|
return {
|
|
69
108
|
kind: "resumable",
|
|
70
|
-
target:
|
|
71
|
-
stage: "executor",
|
|
72
|
-
runId: latest.runId,
|
|
73
|
-
stateRef: latest.stateRef,
|
|
74
|
-
statePath: latest.statePath,
|
|
75
|
-
state: latest.state,
|
|
76
|
-
},
|
|
109
|
+
target: executorTarget(latest),
|
|
77
110
|
};
|
|
78
111
|
}
|
|
79
112
|
if (latest.state.stages.executor.status === "running") {
|
|
@@ -93,6 +126,12 @@ export function selectResumableRegisterRun(candidates) {
|
|
|
93
126
|
},
|
|
94
127
|
},
|
|
95
128
|
};
|
|
129
|
+
if (options.resumeFrom === "executor") {
|
|
130
|
+
const forcedChanges = initialChanges.length > 0
|
|
131
|
+
? initialChanges
|
|
132
|
+
: (latest.evidence.attempt_changes ?? latest.evidence.changes).map((change) => change.path);
|
|
133
|
+
return { kind: "resumable", target: executorTarget(latest, forcedChanges) };
|
|
134
|
+
}
|
|
96
135
|
return {
|
|
97
136
|
kind: "resumable",
|
|
98
137
|
target: {
|
|
@@ -108,13 +147,7 @@ export function selectResumableRegisterRun(candidates) {
|
|
|
108
147
|
}
|
|
109
148
|
return {
|
|
110
149
|
kind: "resumable",
|
|
111
|
-
target:
|
|
112
|
-
stage: "executor",
|
|
113
|
-
runId: latest.runId,
|
|
114
|
-
stateRef: latest.stateRef,
|
|
115
|
-
statePath: latest.statePath,
|
|
116
|
-
state: latest.state,
|
|
117
|
-
},
|
|
150
|
+
target: executorTarget(latest),
|
|
118
151
|
};
|
|
119
152
|
}
|
|
120
153
|
if (latest.state.stages.executor.status !== "succeeded") {
|
|
@@ -130,11 +163,24 @@ export function selectResumableRegisterRun(candidates) {
|
|
|
130
163
|
reason: `executor evidence is missing or invalid for run ${latest.runId}`,
|
|
131
164
|
};
|
|
132
165
|
}
|
|
166
|
+
const inferredStage = latest.state.stages.reporter.status === "succeeded" ? "integrate" : "reporter";
|
|
167
|
+
if (options.resumeFrom === "executor") {
|
|
168
|
+
if (inferredStage !== "reporter") {
|
|
169
|
+
return {
|
|
170
|
+
kind: "not-resumable",
|
|
171
|
+
reason: `cannot resume the executor from the ${inferredStage} stage of run ${latest.runId}`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const forcedChanges = initialChanges.length > 0
|
|
175
|
+
? initialChanges
|
|
176
|
+
: (latest.evidence.attempt_changes ?? latest.evidence.changes).map((change) => change.path);
|
|
177
|
+
return { kind: "resumable", target: executorTarget(latest, forcedChanges) };
|
|
178
|
+
}
|
|
133
179
|
return {
|
|
134
180
|
kind: "resumable",
|
|
135
181
|
target: {
|
|
136
182
|
// reporter が成功済みなら残っているのは統合だけ。executor / reporter は起動しない。
|
|
137
|
-
stage:
|
|
183
|
+
stage: inferredStage,
|
|
138
184
|
runId: latest.runId,
|
|
139
185
|
stateRef: latest.stateRef,
|
|
140
186
|
statePath: latest.statePath,
|
|
@@ -145,7 +191,7 @@ export function selectResumableRegisterRun(candidates) {
|
|
|
145
191
|
};
|
|
146
192
|
}
|
|
147
193
|
export function findResumableRegisterRun(input) {
|
|
148
|
-
return selectResumableRegisterRun(loadRegisterResumeCandidates(input));
|
|
194
|
+
return selectResumableRegisterRun(loadRegisterResumeCandidates(input), input.resumeFrom ? { resumeFrom: input.resumeFrom } : {});
|
|
149
195
|
}
|
|
150
196
|
// plan / result のファイル名は `<pjr-id>-<UTC>-<rand>-(plan|result).md`(buildInPlaceStem)。
|
|
151
197
|
// state に artifacts が無い旧 run のために、worktree の result 一覧から最新の stem を復元する。
|
package/dist/exec-register.js
CHANGED
|
@@ -227,17 +227,23 @@ function registerPlanFrontmatter(projectId, stem, item) {
|
|
|
227
227
|
`type: exec-plan`,
|
|
228
228
|
`rulebook: none`,
|
|
229
229
|
`task_id: ${item.id}`,
|
|
230
|
-
`name:
|
|
230
|
+
`name: ${JSON.stringify(item.title)}`,
|
|
231
231
|
`mode: edit`,
|
|
232
232
|
`status: ready`,
|
|
233
233
|
`project_id: ${projectId}`,
|
|
234
|
-
//
|
|
235
|
-
//
|
|
234
|
+
// schedule 由来のタスクと区別できるよう出自を明示する(schema の targets 必須判定
|
|
235
|
+
// にも使う)。個票が targets を宣言していれば plan にも転記し、target coverage
|
|
236
|
+
// 検証を有効にする。宣言がない項目は targets を持たず、検証は skip される。
|
|
236
237
|
`origin: register`,
|
|
237
238
|
];
|
|
238
239
|
if (item.owner && item.owner !== "-" && item.owner !== "_TODO_") {
|
|
239
240
|
inner.push(`owner: ${item.owner}`);
|
|
240
241
|
}
|
|
242
|
+
if (item.targets && item.targets.length > 0) {
|
|
243
|
+
inner.push("targets:");
|
|
244
|
+
for (const target of item.targets)
|
|
245
|
+
inner.push(` - ${target}`);
|
|
246
|
+
}
|
|
241
247
|
return buildSpecdojoFrontmatter(inner);
|
|
242
248
|
}
|
|
243
249
|
export async function generateRegisterPlan(opts) {
|