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
package/dist/exec-reporter.js
CHANGED
|
@@ -1,53 +1,559 @@
|
|
|
1
1
|
import Ajv2020Module from "ajv/dist/2020.js";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
2
4
|
import { extractJsonText } from "./agent-response.js";
|
|
5
|
+
import { PARENT_VALIDATION_PROJECT_REPO, failedParentValidationReason, } from "./exec-parent-validation.js";
|
|
6
|
+
import { getProjectExecutionPath, resolveRepoRoot, specdojoRootDir, } from "./specdojo-config.js";
|
|
7
|
+
import { REVIEW_VERDICTS, describeInvalidReviewVerdict, isReviewVerdict } from "./review-types.js";
|
|
3
8
|
const MAX_TEXT_LENGTH = 4_000;
|
|
4
|
-
const MAX_ITEMS = 1_000;
|
|
5
9
|
const REPORTER_FORMAT_ATTEMPTS = 3;
|
|
10
|
+
// review の verdict の正本は review-types.ts であり、verdict_definitions と同じ語彙を使う。
|
|
11
|
+
export { REVIEW_VERDICTS };
|
|
12
|
+
function isProjectConfig(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Finds the single configured project whose execution directory is `executionPath`. Returns
|
|
17
|
+
* undefined when no project or more than one project matches, so ambiguity never picks a project.
|
|
18
|
+
*/
|
|
19
|
+
function projectIdForExecutionPath(config, repoRoot, executionPath) {
|
|
20
|
+
if (!config)
|
|
21
|
+
return undefined;
|
|
22
|
+
const target = resolve(executionPath);
|
|
23
|
+
const matches = Object.keys(config.projects)
|
|
24
|
+
.sort()
|
|
25
|
+
.filter((projectId) => {
|
|
26
|
+
const project = config.projects[projectId];
|
|
27
|
+
if (!isProjectConfig(project))
|
|
28
|
+
return false;
|
|
29
|
+
return resolve(repoRoot, getProjectExecutionPath(project)) === target;
|
|
30
|
+
});
|
|
31
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
32
|
+
}
|
|
33
|
+
function repoRelativePath(root, path) {
|
|
34
|
+
return relative(root, path).split(sep).join("/").replace(/^\.\//u, "");
|
|
35
|
+
}
|
|
36
|
+
function pathIsWithin(path, root) {
|
|
37
|
+
return path === root || path.startsWith(`${root}/`);
|
|
38
|
+
}
|
|
39
|
+
function isRunnerManagedChangePath(path, scope) {
|
|
40
|
+
const normalized = path.replaceAll("\\", "/").replace(/^\.\//u, "");
|
|
41
|
+
// exec/ 配下(evidence・plans・results・events・.locks など)はすべて runner の記録であり、
|
|
42
|
+
// executor の成果物ではない。
|
|
43
|
+
const execRoot = repoRelativePath(scope.repoRoot, join(scope.executionPath, "exec"));
|
|
44
|
+
const managedRoots = [
|
|
45
|
+
execRoot,
|
|
46
|
+
...(scope.registerPaths ?? []).map((path) => repoRelativePath(scope.repoRoot, path)),
|
|
47
|
+
];
|
|
48
|
+
const resultPath = scope.resultPath
|
|
49
|
+
? repoRelativePath(scope.worktreePath, scope.resultPath)
|
|
50
|
+
: undefined;
|
|
51
|
+
return managedRoots.some((root) => pathIsWithin(normalized, root)) || normalized === resultPath;
|
|
52
|
+
}
|
|
53
|
+
function isRunnerManagedChange(change, scope) {
|
|
54
|
+
// A rename can contain two repository-relative paths. Exclude the entry only when every side
|
|
55
|
+
// is runner-managed so a move between a managed location and a deliverable remains visible.
|
|
56
|
+
return change.path.split(" -> ").every((path) => isRunnerManagedChangePath(path, scope));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Builds the bounded evidence view used by the reporter and result renderer. Runner-owned
|
|
60
|
+
* bookkeeping remains in the persisted evidence, but it is not presented as executor output.
|
|
61
|
+
*/
|
|
62
|
+
export function evidenceForReporter(evidence, scope) {
|
|
63
|
+
const changes = evidence.changes.filter((change) => !isRunnerManagedChange(change, scope));
|
|
64
|
+
const attemptChanges = evidence.attempt_changes?.filter((change) => !isRunnerManagedChange(change, scope));
|
|
65
|
+
// `attempt_changes` excludes lifecycle changes that existed before the executor started. Its
|
|
66
|
+
// removed entries therefore tell the reporter that the executor really touched runner-owned
|
|
67
|
+
// bookkeeping, without putting those paths back into the authoritative deliverable list.
|
|
68
|
+
const runnerManagedAttemptChanges = (evidence.attempt_changes ?? []).filter((change) => isRunnerManagedChange(change, scope));
|
|
69
|
+
const factOptions = scope.factOptions ?? {};
|
|
70
|
+
const config = factOptions.specdojoConfig === undefined ? defaultSpecdojoConfig() : factOptions.specdojoConfig;
|
|
71
|
+
const projectId = scope.projectId ??
|
|
72
|
+
factOptions.projectId ??
|
|
73
|
+
projectIdForExecutionPath(config, scope.repoRoot, scope.executionPath);
|
|
74
|
+
const scopedFactOptions = {
|
|
75
|
+
...factOptions,
|
|
76
|
+
...(projectId ? { projectId } : {}),
|
|
77
|
+
changedPaths: changes.map((change) => change.path),
|
|
78
|
+
};
|
|
79
|
+
const mechanicallyNotApplicable = evidence.validations.flatMap((validation) => {
|
|
80
|
+
if (validation.source === "runner" || validation.status !== "not_run")
|
|
81
|
+
return [];
|
|
82
|
+
const reason = mechanicallyNotApplicableReason(validation.command, scopedFactOptions);
|
|
83
|
+
return reason === undefined ? [] : [{ command: validation.command, reason }];
|
|
84
|
+
});
|
|
85
|
+
const filtered = changes.length !== evidence.changes.length ||
|
|
86
|
+
attemptChanges?.length !== evidence.attempt_changes?.length;
|
|
87
|
+
const scoped = projectId
|
|
88
|
+
? { ...evidence, runner_scope: { project_id: projectId } }
|
|
89
|
+
: evidence;
|
|
90
|
+
const selected = filtered
|
|
91
|
+
? {
|
|
92
|
+
...scoped,
|
|
93
|
+
changes,
|
|
94
|
+
...(attemptChanges ? { attempt_changes: attemptChanges } : {}),
|
|
95
|
+
diff_summary: {
|
|
96
|
+
files_changed: changes.length,
|
|
97
|
+
summary: changes
|
|
98
|
+
.map((change) => `${change.status} ${change.path}`)
|
|
99
|
+
.join("\n")
|
|
100
|
+
.slice(0, MAX_TEXT_LENGTH),
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
: scoped;
|
|
104
|
+
if (mechanicallyNotApplicable.length === 0 && runnerManagedAttemptChanges.length === 0) {
|
|
105
|
+
return selected;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
...selected,
|
|
109
|
+
runner_context: {
|
|
110
|
+
mechanically_not_applicable: mechanicallyNotApplicable,
|
|
111
|
+
runner_managed_attempt_changes: runnerManagedAttemptChanges,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Derives result facts only from runner-owned evidence. Reporter prose is deliberately absent
|
|
117
|
+
* from this decision so an LLM cannot change paths or turn a failed run into a completed one.
|
|
118
|
+
*/
|
|
119
|
+
export function deriveReporterFacts(evidence, options = {}) {
|
|
120
|
+
const changedFiles = evidence.changes.map(({ path, status }) => ({ path, status }));
|
|
121
|
+
if (evidence.stage.status !== "succeeded" || evidence.stage.exit_code !== 0) {
|
|
122
|
+
const blockReason = evidence.block_reason ||
|
|
123
|
+
(evidence.stage.status === "rate_limited"
|
|
124
|
+
? "executor rate limit reached"
|
|
125
|
+
: evidence.stage.exit_code === null
|
|
126
|
+
? "executor failed without an exit code"
|
|
127
|
+
: evidence.stage.exit_code !== 0
|
|
128
|
+
? `executor exited with code ${evidence.stage.exit_code}`
|
|
129
|
+
: "executor stage failed");
|
|
130
|
+
return { outcome: "blocked", changed_files: changedFiles, block_reason: blockReason };
|
|
131
|
+
}
|
|
132
|
+
const validationFailure = failedParentValidationReason(evidence.validations);
|
|
133
|
+
if (validationFailure) {
|
|
134
|
+
return {
|
|
135
|
+
outcome: "blocked",
|
|
136
|
+
changed_files: changedFiles,
|
|
137
|
+
block_reason: validationFailure,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const packageScripts = options.packageScripts ?? defaultPackageScripts();
|
|
141
|
+
const packageDependencies = options.packageDependencies ?? defaultPackageDependencies();
|
|
142
|
+
const specdojoConfig = options.specdojoConfig === undefined ? defaultSpecdojoConfig() : options.specdojoConfig;
|
|
143
|
+
const projectId = options.projectId ?? evidence.runner_scope?.project_id;
|
|
144
|
+
const applicabilityOptions = {
|
|
145
|
+
packageScripts,
|
|
146
|
+
packageDependencies,
|
|
147
|
+
specdojoConfig,
|
|
148
|
+
...(projectId ? { projectId } : {}),
|
|
149
|
+
...(options.productPackageManifests
|
|
150
|
+
? { productPackageManifests: options.productPackageManifests }
|
|
151
|
+
: {}),
|
|
152
|
+
changedPaths: options.changedPaths ?? evidence.changes.map((change) => change.path),
|
|
153
|
+
};
|
|
154
|
+
const passedCommandsByRepo = new Map();
|
|
155
|
+
const runnerPassedCommandsByRepo = new Map();
|
|
156
|
+
const addPassedCommand = (target, repo, command) => {
|
|
157
|
+
const commands = target.get(repo) ?? new Set();
|
|
158
|
+
commands.add(command);
|
|
159
|
+
target.set(repo, commands);
|
|
160
|
+
};
|
|
161
|
+
// sandbox で実行できない検証を executor が not_run(親 runner へ委譲)と記録し、runner が
|
|
162
|
+
// 同じリポジトリで同じコマンドを実行して通した場合は満たされたものとして扱う。executor の
|
|
163
|
+
// failed は runner の結果で打ち消さない(PJR-2GZE)。
|
|
164
|
+
for (const validation of evidence.validations) {
|
|
165
|
+
if (validation.status !== "passed")
|
|
166
|
+
continue;
|
|
167
|
+
if (validation.source === "runner") {
|
|
168
|
+
const repo = validation.repo ?? PARENT_VALIDATION_PROJECT_REPO;
|
|
169
|
+
const command = normalizeValidationCommand(validation.command);
|
|
170
|
+
addPassedCommand(runnerPassedCommandsByRepo, repo, command);
|
|
171
|
+
addPassedCommand(passedCommandsByRepo, repo, command);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const manifest = commandManifest(normalizeValidationCommand(validation.command), applicabilityOptions, specdojoConfig);
|
|
175
|
+
addPassedCommand(passedCommandsByRepo, manifest.repoName ?? PARENT_VALIDATION_PROJECT_REPO, manifest.command);
|
|
176
|
+
}
|
|
177
|
+
// `npm run check` のような合成コマンドを executor が not_run(親 runner へ委譲)とした場合は、
|
|
178
|
+
// 対象リポジトリの package.json の script を展開し、構成する各コマンドが同じリポジトリの
|
|
179
|
+
// 親検証か executor 自身の検証で通っていれば満たされたものとして扱う(PJR-SDWF)。
|
|
180
|
+
const isDelegatedValidationSatisfied = (command) => {
|
|
181
|
+
const manifest = commandManifest(normalizeValidationCommand(command), applicabilityOptions, specdojoConfig);
|
|
182
|
+
const repo = manifest.repoName ?? PARENT_VALIDATION_PROJECT_REPO;
|
|
183
|
+
const runnerPassedCommands = runnerPassedCommandsByRepo.get(repo) ?? new Set();
|
|
184
|
+
if (runnerPassedCommands.has(manifest.command))
|
|
185
|
+
return true;
|
|
186
|
+
const passedCommands = passedCommandsByRepo.get(repo) ?? new Set();
|
|
187
|
+
const components = compositeComponents(manifest.command, manifest.scripts);
|
|
188
|
+
return (components !== undefined &&
|
|
189
|
+
components.every((component) => isComponentSatisfied(component, passedCommands, manifest.scripts)));
|
|
190
|
+
};
|
|
191
|
+
// runner が担う検証(index build)の executor 側の not_run / not_applicable は満たしたものとする。
|
|
192
|
+
// runner の再生成が失敗した場合は worktree の準備で run が止まり、runner の記録に失敗が残れば
|
|
193
|
+
// 上の failedParentValidationReason で block するため、ここまで到達しない。
|
|
194
|
+
const executorValidationFailures = evidence.validations.filter((validation) => {
|
|
195
|
+
if (validation.source === "runner")
|
|
196
|
+
return false;
|
|
197
|
+
if (validation.status === "passed" || validation.status === "requires_human")
|
|
198
|
+
return false;
|
|
199
|
+
// review executor の任意確認は verdict の判断材料であり、未実施・適用外そのものを
|
|
200
|
+
// pipeline の失敗にしない。実行して失敗した確認だけは mode にかかわらず block する。
|
|
201
|
+
if (options.mode === "review" &&
|
|
202
|
+
(validation.status === "not_run" || validation.status === "not_applicable")) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
if ((validation.status === "not_run" || validation.status === "not_applicable") &&
|
|
206
|
+
runnerOwnedValidationReason(validation.command) !== undefined) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
if (validation.status === "not_applicable") {
|
|
210
|
+
return !isValidNotApplicableValidation(validation.command, validation.reason, applicabilityOptions);
|
|
211
|
+
}
|
|
212
|
+
return !(validation.status === "not_run" &&
|
|
213
|
+
(isDelegatedValidationSatisfied(validation.command) ||
|
|
214
|
+
mechanicallyNotApplicableReason(validation.command, applicabilityOptions) !== undefined));
|
|
215
|
+
});
|
|
216
|
+
if (executorValidationFailures.length > 0) {
|
|
217
|
+
return {
|
|
218
|
+
outcome: "blocked",
|
|
219
|
+
changed_files: changedFiles,
|
|
220
|
+
block_reason: `executor validation failed or not run: ${executorValidationFailures
|
|
221
|
+
.map((validation) => validation.command)
|
|
222
|
+
.join(", ")}`,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return { outcome: "complete", changed_files: changedFiles, block_reason: "" };
|
|
226
|
+
}
|
|
227
|
+
// `npm test` は単体テストと統合テストの全件ゲートであり、親 runner は同じ範囲を
|
|
228
|
+
// `npm run test:unit` と `npm run test:integration` に分けて実行する。
|
|
229
|
+
const COMMAND_EQUIVALENTS = {
|
|
230
|
+
"npm test": ["npm run test:unit", "npm run test:integration"],
|
|
231
|
+
};
|
|
232
|
+
const MAX_COMPOSITE_DEPTH = 5;
|
|
233
|
+
function normalizeValidationCommand(command) {
|
|
234
|
+
const collapsed = command.trim().replace(/\s+/g, " ");
|
|
235
|
+
if (collapsed === "npm t" || collapsed === "npm run test")
|
|
236
|
+
return "npm test";
|
|
237
|
+
return collapsed.replace(/^npm run-script /, "npm run ");
|
|
238
|
+
}
|
|
239
|
+
function scriptNameOf(command) {
|
|
240
|
+
if (command === "npm test")
|
|
241
|
+
return "test";
|
|
242
|
+
return /^npm run ([A-Za-z0-9:_.-]+)$/.exec(command)?.[1];
|
|
243
|
+
}
|
|
244
|
+
// 適用条件の反証では npm が解決する script 名だけを取り出す。後続引数の有無は script の
|
|
245
|
+
// 存在を変えない。一方、委譲・合成コマンドの同一性判定は scriptNameOf の完全一致を保つ。
|
|
246
|
+
function invokedScriptNameOf(command) {
|
|
247
|
+
if (command === "npm test")
|
|
248
|
+
return "test";
|
|
249
|
+
return /^npm run ([A-Za-z0-9:_.-]+)(?:\s|$)/u.exec(command)?.[1];
|
|
250
|
+
}
|
|
251
|
+
function npxPackageNameOf(command) {
|
|
252
|
+
return /^npx\s+((?:@[A-Za-z0-9_.-]+\/)?[A-Za-z0-9_.-]+)(?:\s|$)/u.exec(command)?.[1];
|
|
253
|
+
}
|
|
254
|
+
function specdojoCommandArgs(command) {
|
|
255
|
+
const normalized = normalizeValidationCommand(command);
|
|
256
|
+
return (/^(?:npx\s+)?specdojo\s+(.+)$/u.exec(normalized)?.[1] ??
|
|
257
|
+
/^(?:(?:node --import tsx|npx tsx|tsx)\s+(?:\.\/)?src\/specdojo\.ts|node\s+(?:\.\/)?dist\/specdojo\.js)\s+(.+)$/u.exec(normalized)?.[1]);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Returns why a validation is owned by the runner rather than the executor. `specdojo index build`
|
|
261
|
+
* writes `.specdojo/doc-index.json`, which agents may not write; the runner regenerates the index
|
|
262
|
+
* while preparing the worktree and before integration, so the executor cannot and need not run it.
|
|
263
|
+
* Other SpecDojo subcommands return undefined and keep their usual `not_run` handling.
|
|
264
|
+
*/
|
|
265
|
+
export function runnerOwnedValidationReason(command) {
|
|
266
|
+
const args = specdojoCommandArgs(command);
|
|
267
|
+
if (args === undefined || !/^index\s+build(?:\s|$)/u.test(args))
|
|
268
|
+
return undefined;
|
|
269
|
+
return "index は runner が worktree の準備と統合の前に再生成する";
|
|
270
|
+
}
|
|
271
|
+
const PROJECT_DOCUMENTS_ROOT = "docs/ja/projects/";
|
|
272
|
+
function changesReachProjectDocuments(changedPaths) {
|
|
273
|
+
return changedPaths
|
|
274
|
+
.flatMap((path) => path.split(" -> "))
|
|
275
|
+
.some((path) => path.replaceAll("\\", "/").replace(/^\.\//u, "").startsWith(PROJECT_DOCUMENTS_ROOT));
|
|
276
|
+
}
|
|
277
|
+
function projectOptionOf(args) {
|
|
278
|
+
return /(?:^|\s)--project(?:=|\s+)([A-Za-z0-9_-]+)(?=\s|$)/u.exec(args)?.[1];
|
|
279
|
+
}
|
|
280
|
+
function specdojoCommandApplicability(command, config, runProjectId, changedPaths) {
|
|
281
|
+
const args = specdojoCommandArgs(command);
|
|
282
|
+
if (args === undefined)
|
|
283
|
+
return { recognized: false };
|
|
284
|
+
if (!/^catalog\s+validate(?:\s|$)/u.test(args)) {
|
|
285
|
+
return { recognized: true, applicable: undefined };
|
|
286
|
+
}
|
|
287
|
+
const configuredProjectId = config?.current_project;
|
|
288
|
+
// 明示の --project を優先し、次に run の対象 project を使う。current_project は run の対象を
|
|
289
|
+
// 特定できない場合の最後の手段にとどめる(別 project の catalog_path で判定しないため)。
|
|
290
|
+
const projectId = projectOptionOf(args) ??
|
|
291
|
+
runProjectId ??
|
|
292
|
+
(typeof configuredProjectId === "string" ? configuredProjectId : undefined);
|
|
293
|
+
const project = projectId ? config?.projects[projectId] : undefined;
|
|
294
|
+
if (!project || typeof project !== "object" || Array.isArray(project)) {
|
|
295
|
+
return { recognized: true, applicable: undefined };
|
|
296
|
+
}
|
|
297
|
+
if (typeof project.catalog_path === "string" && project.catalog_path.trim()) {
|
|
298
|
+
// plan の共通規約は catalog validate を docs/ja/projects/ 配下の変更に限って求める。
|
|
299
|
+
if (changedPaths !== undefined && !changesReachProjectDocuments(changedPaths)) {
|
|
300
|
+
return {
|
|
301
|
+
recognized: true,
|
|
302
|
+
applicable: false,
|
|
303
|
+
reason: `変更が ${PROJECT_DOCUMENTS_ROOT} 配下に及ばない`,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return { recognized: true, applicable: true };
|
|
307
|
+
}
|
|
308
|
+
if (project.catalog_path !== undefined) {
|
|
309
|
+
return { recognized: true, applicable: undefined };
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
recognized: true,
|
|
313
|
+
applicable: false,
|
|
314
|
+
reason: `project '${projectId}' に catalog_path が設定されていない`,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Returns the runner-owned reason when a command is mechanically known not to apply. Unknown
|
|
319
|
+
* applicability deliberately returns undefined so an ordinary `not_run` continues to block.
|
|
320
|
+
*/
|
|
321
|
+
export function mechanicallyNotApplicableReason(command, options = {}) {
|
|
322
|
+
const normalized = normalizeValidationCommand(command);
|
|
323
|
+
const config = options.specdojoConfig === undefined ? defaultSpecdojoConfig() : options.specdojoConfig;
|
|
324
|
+
const specdojo = specdojoCommandApplicability(normalized, config, options.projectId, options.changedPaths);
|
|
325
|
+
if (specdojo.recognized) {
|
|
326
|
+
return specdojo.applicable === false ? specdojo.reason : undefined;
|
|
327
|
+
}
|
|
328
|
+
const manifest = commandManifest(normalized, options, config);
|
|
329
|
+
const packageJson = manifest.repoName === undefined ? "package.json" : `${manifest.repoName} の package.json`;
|
|
330
|
+
const scriptName = invokedScriptNameOf(manifest.command);
|
|
331
|
+
if (scriptName !== undefined && manifest.scripts[scriptName] === undefined) {
|
|
332
|
+
return `${packageJson} に npm script '${scriptName}' がない`;
|
|
333
|
+
}
|
|
334
|
+
const packageName = npxPackageNameOf(manifest.command);
|
|
335
|
+
if (packageName !== undefined && !manifest.dependencies.has(packageName)) {
|
|
336
|
+
return `${packageJson} の dependencies / devDependencies に '${packageName}' がない`;
|
|
337
|
+
}
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
function isValidNotApplicableValidation(command, reason, options) {
|
|
341
|
+
if (!reason?.trim())
|
|
342
|
+
return false;
|
|
343
|
+
const normalized = normalizeValidationCommand(command);
|
|
344
|
+
const config = options.specdojoConfig === undefined ? defaultSpecdojoConfig() : options.specdojoConfig;
|
|
345
|
+
const specdojo = specdojoCommandApplicability(normalized, config, options.projectId, options.changedPaths);
|
|
346
|
+
if (specdojo.recognized)
|
|
347
|
+
return specdojo.applicable !== true;
|
|
348
|
+
const manifest = commandManifest(normalized, options, config);
|
|
349
|
+
const scriptName = invokedScriptNameOf(manifest.command);
|
|
350
|
+
if (scriptName !== undefined && manifest.scripts[scriptName] !== undefined)
|
|
351
|
+
return false;
|
|
352
|
+
const packageName = npxPackageNameOf(manifest.command);
|
|
353
|
+
return packageName === undefined || !manifest.dependencies.has(packageName);
|
|
354
|
+
}
|
|
355
|
+
const PREFIX_OPTION_PATTERN = /(?:^|\s)--prefix(?:=|\s+)(\S+)(?=\s|$)/u;
|
|
356
|
+
function normalizeRepoPathText(path) {
|
|
357
|
+
return path.replaceAll("\\", "/").replace(/^\.\//u, "").replace(/\/+$/u, "");
|
|
358
|
+
}
|
|
359
|
+
function declaredRepos(config, projectId) {
|
|
360
|
+
const targetProjectId = projectId ?? config?.current_project;
|
|
361
|
+
const project = targetProjectId ? config?.projects[targetProjectId] : undefined;
|
|
362
|
+
if (!isProjectConfig(project) || !Array.isArray(project.repos))
|
|
363
|
+
return [];
|
|
364
|
+
// 設定ファイル由来の値なので、型の宣言に頼らず name と path が文字列の要素だけを使う。
|
|
365
|
+
return project.repos.filter((repo) => typeof repo === "object" &&
|
|
366
|
+
repo !== null &&
|
|
367
|
+
typeof repo.name === "string" &&
|
|
368
|
+
typeof repo.path === "string");
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Identifies a command that targets a declared product repository, either through
|
|
372
|
+
* `--prefix <repo>` (the repository name or its configured path) or a `<repo>:<path>` argument.
|
|
373
|
+
*/
|
|
374
|
+
function productRepoCommand(command, repos) {
|
|
375
|
+
const prefix = PREFIX_OPTION_PATTERN.exec(command)?.[1];
|
|
376
|
+
if (prefix !== undefined) {
|
|
377
|
+
const value = normalizeRepoPathText(prefix);
|
|
378
|
+
const repo = repos.find((candidate) => candidate.name === value || normalizeRepoPathText(candidate.path) === value);
|
|
379
|
+
if (!repo)
|
|
380
|
+
return undefined;
|
|
381
|
+
return {
|
|
382
|
+
repo,
|
|
383
|
+
command: normalizeValidationCommand(command.replace(PREFIX_OPTION_PATTERN, " ")),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
const tokens = command.split(" ");
|
|
387
|
+
const repo = repos.find((candidate) => tokens.some((token) => token.startsWith(`${candidate.name}:`)));
|
|
388
|
+
return repo ? { repo, command } : undefined;
|
|
389
|
+
}
|
|
390
|
+
const productManifestCache = new Map();
|
|
391
|
+
function productPackageManifest(repo, options) {
|
|
392
|
+
const injected = options.productPackageManifests?.[repo.name];
|
|
393
|
+
if (injected)
|
|
394
|
+
return injected;
|
|
395
|
+
const packageJsonPath = join(resolveRepoRoot(specdojoRootDir(), repo), "package.json");
|
|
396
|
+
const cached = productManifestCache.get(packageJsonPath);
|
|
397
|
+
if (cached)
|
|
398
|
+
return cached;
|
|
399
|
+
const manifest = readPackageManifest(packageJsonPath);
|
|
400
|
+
productManifestCache.set(packageJsonPath, manifest);
|
|
401
|
+
return manifest;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Selects the package.json that decides a command's applicability: the product repository's
|
|
405
|
+
* when the command targets one declared by the run's project, otherwise the project repository's.
|
|
406
|
+
*/
|
|
407
|
+
function commandManifest(command, options, config) {
|
|
408
|
+
const product = productRepoCommand(command, declaredRepos(config, options.projectId));
|
|
409
|
+
if (product) {
|
|
410
|
+
return {
|
|
411
|
+
...productPackageManifest(product.repo, options),
|
|
412
|
+
command: product.command,
|
|
413
|
+
repoName: product.repo.name,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
scripts: options.packageScripts ?? defaultPackageScripts(),
|
|
418
|
+
dependencies: options.packageDependencies ?? defaultPackageDependencies(),
|
|
419
|
+
command,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
// package.json の script が npm script の呼び出しを `&&` でつないだだけの合成なら、直下の構成
|
|
423
|
+
// コマンドを返す。それ以外(任意のシェル、引数付きなど)は合成として扱わない。
|
|
424
|
+
function compositeComponents(command, scripts) {
|
|
425
|
+
const name = scriptNameOf(command);
|
|
426
|
+
const body = name === undefined ? undefined : scripts[name];
|
|
427
|
+
if (body === undefined)
|
|
428
|
+
return undefined;
|
|
429
|
+
const parts = body.split("&&").map((part) => normalizeValidationCommand(part));
|
|
430
|
+
if (parts.length < 2 || parts.some((part) => scriptNameOf(part) === undefined))
|
|
431
|
+
return undefined;
|
|
432
|
+
return parts;
|
|
433
|
+
}
|
|
434
|
+
// executor は `npm run <name>` の代わりに script の中身(例: `node --import tsx src/specdojo.ts
|
|
435
|
+
// catalog validate`)を直接実行して記録することがある。tsx の起動の書き方の違いだけをそろえて比べる。
|
|
436
|
+
// 対象のプロジェクトを指定する `--project <id>` は検証の範囲を変えないため、比較では取り除く。
|
|
437
|
+
function normalizeScriptBody(command) {
|
|
438
|
+
return normalizeValidationCommand(command)
|
|
439
|
+
.replace(/^(?:node --import tsx|npx tsx) /, "tsx ")
|
|
440
|
+
.replace(/ --project(?:=| )[A-Za-z0-9_-]+(?= |$)/g, "");
|
|
441
|
+
}
|
|
442
|
+
// 構成コマンドは、それ自体が通っていれば満たす。通っていなければ、同等のコマンドの組、script の
|
|
443
|
+
// 中身の直接実行、さらに合成ならその構成コマンドの順に確かめる(runner が合成の script を丸ごと
|
|
444
|
+
// 実行して通した場合に、中身を分解して探さないため)。
|
|
445
|
+
function isComponentSatisfied(command, passed, scripts, depth = 0) {
|
|
446
|
+
if (passed.has(command))
|
|
447
|
+
return true;
|
|
448
|
+
if (depth < MAX_COMPOSITE_DEPTH) {
|
|
449
|
+
const components = compositeComponents(command, scripts);
|
|
450
|
+
if (components?.every((component) => isComponentSatisfied(component, passed, scripts, depth + 1))) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const equivalents = COMMAND_EQUIVALENTS[command];
|
|
455
|
+
if (equivalents !== undefined && equivalents.every((equivalent) => passed.has(equivalent))) {
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
const name = scriptNameOf(command);
|
|
459
|
+
const body = name === undefined ? undefined : scripts[name];
|
|
460
|
+
if (body === undefined)
|
|
461
|
+
return false;
|
|
462
|
+
const normalizedBody = normalizeScriptBody(body);
|
|
463
|
+
return [...passed].some((candidate) => normalizeScriptBody(candidate) === normalizedBody);
|
|
464
|
+
}
|
|
465
|
+
let cachedPackageManifest;
|
|
466
|
+
let cachedSpecdojoConfig;
|
|
467
|
+
function defaultPackageManifest() {
|
|
468
|
+
if (cachedPackageManifest)
|
|
469
|
+
return cachedPackageManifest;
|
|
470
|
+
cachedPackageManifest = readPackageManifest(join(specdojoRootDir(), "package.json"));
|
|
471
|
+
return cachedPackageManifest;
|
|
472
|
+
}
|
|
473
|
+
function defaultPackageScripts() {
|
|
474
|
+
return defaultPackageManifest().scripts;
|
|
475
|
+
}
|
|
476
|
+
function defaultPackageDependencies() {
|
|
477
|
+
return defaultPackageManifest().dependencies;
|
|
478
|
+
}
|
|
479
|
+
function defaultSpecdojoConfig() {
|
|
480
|
+
if (cachedSpecdojoConfig !== undefined)
|
|
481
|
+
return cachedSpecdojoConfig;
|
|
482
|
+
const configPath = join(specdojoRootDir(), ".specdojo", "specdojo.config.json");
|
|
483
|
+
if (!existsSync(configPath)) {
|
|
484
|
+
cachedSpecdojoConfig = null;
|
|
485
|
+
return cachedSpecdojoConfig;
|
|
486
|
+
}
|
|
487
|
+
try {
|
|
488
|
+
const parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
|
489
|
+
cachedSpecdojoConfig =
|
|
490
|
+
parsed.version === 1 &&
|
|
491
|
+
typeof parsed.projects === "object" &&
|
|
492
|
+
parsed.projects !== null &&
|
|
493
|
+
!Array.isArray(parsed.projects)
|
|
494
|
+
? parsed
|
|
495
|
+
: null;
|
|
496
|
+
}
|
|
497
|
+
catch {
|
|
498
|
+
cachedSpecdojoConfig = null;
|
|
499
|
+
}
|
|
500
|
+
return cachedSpecdojoConfig;
|
|
501
|
+
}
|
|
502
|
+
export function readPackageScripts(packageJsonPath) {
|
|
503
|
+
return readPackageManifest(packageJsonPath).scripts;
|
|
504
|
+
}
|
|
505
|
+
function readPackageManifest(packageJsonPath) {
|
|
506
|
+
const empty = { scripts: {}, dependencies: new Set() };
|
|
507
|
+
if (!existsSync(packageJsonPath))
|
|
508
|
+
return empty;
|
|
509
|
+
let parsed;
|
|
510
|
+
try {
|
|
511
|
+
parsed = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
512
|
+
}
|
|
513
|
+
catch (error) {
|
|
514
|
+
process.stderr.write(`warning: cannot read package scripts from ${packageJsonPath}: ${String(error)}\n`);
|
|
515
|
+
return empty;
|
|
516
|
+
}
|
|
517
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
518
|
+
return empty;
|
|
519
|
+
const manifest = parsed;
|
|
520
|
+
const scripts = typeof manifest.scripts === "object" &&
|
|
521
|
+
manifest.scripts !== null &&
|
|
522
|
+
!Array.isArray(manifest.scripts)
|
|
523
|
+
? Object.fromEntries(Object.entries(manifest.scripts).filter((entry) => typeof entry[1] === "string"))
|
|
524
|
+
: {};
|
|
525
|
+
const dependencyEntries = [manifest.dependencies, manifest.devDependencies].flatMap((section) => typeof section === "object" && section !== null && !Array.isArray(section)
|
|
526
|
+
? Object.entries(section).filter((entry) => typeof entry[1] === "string")
|
|
527
|
+
: []);
|
|
528
|
+
return { scripts, dependencies: new Set(dependencyEntries.map(([name]) => name)) };
|
|
529
|
+
}
|
|
6
530
|
export const REPORTER_OUTPUT_SCHEMA = {
|
|
7
531
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
8
532
|
oneOf: [
|
|
9
533
|
{
|
|
10
534
|
type: "object",
|
|
11
535
|
additionalProperties: false,
|
|
12
|
-
required: [
|
|
13
|
-
"schema_version",
|
|
14
|
-
"mode",
|
|
15
|
-
"outcome",
|
|
16
|
-
"summary",
|
|
17
|
-
"changed_files",
|
|
18
|
-
"handoff",
|
|
19
|
-
"approach",
|
|
20
|
-
"block_reason",
|
|
21
|
-
],
|
|
536
|
+
required: ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"],
|
|
22
537
|
properties: {
|
|
23
538
|
schema_version: { const: 1 },
|
|
24
539
|
mode: { const: "edit" },
|
|
25
|
-
outcome: { enum: ["complete", "blocked"] },
|
|
26
540
|
summary: { type: "array", minItems: 1, maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
27
541
|
changed_files: {
|
|
28
542
|
type: "array",
|
|
29
|
-
maxItems:
|
|
543
|
+
maxItems: 1_000,
|
|
30
544
|
items: {
|
|
31
545
|
type: "object",
|
|
32
546
|
additionalProperties: false,
|
|
33
547
|
required: ["path", "summary"],
|
|
34
548
|
properties: {
|
|
35
|
-
path: {
|
|
549
|
+
path: { $ref: "#/$defs/text" },
|
|
36
550
|
summary: { $ref: "#/$defs/text" },
|
|
37
551
|
},
|
|
38
552
|
},
|
|
39
553
|
},
|
|
40
554
|
handoff: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
41
555
|
approach: { $ref: "#/$defs/text" },
|
|
42
|
-
block_reason: { type: "string", maxLength: MAX_TEXT_LENGTH },
|
|
43
556
|
},
|
|
44
|
-
allOf: [
|
|
45
|
-
{
|
|
46
|
-
if: { properties: { outcome: { const: "blocked" } } },
|
|
47
|
-
then: { properties: { block_reason: { type: "string", pattern: "\\S" } } },
|
|
48
|
-
else: { properties: { block_reason: { type: "string", maxLength: 0 } } },
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
557
|
},
|
|
52
558
|
{
|
|
53
559
|
type: "object",
|
|
@@ -55,49 +561,21 @@ export const REPORTER_OUTPUT_SCHEMA = {
|
|
|
55
561
|
required: [
|
|
56
562
|
"schema_version",
|
|
57
563
|
"mode",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
564
|
+
"grade_check",
|
|
565
|
+
"rationale",
|
|
566
|
+
"improvements",
|
|
61
567
|
"approach",
|
|
62
|
-
"
|
|
63
|
-
"block_reason",
|
|
568
|
+
"verdict",
|
|
64
569
|
],
|
|
65
570
|
properties: {
|
|
66
571
|
schema_version: { const: 1 },
|
|
67
572
|
mode: { const: "review" },
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
maxItems: 100,
|
|
72
|
-
items: {
|
|
73
|
-
type: "object",
|
|
74
|
-
additionalProperties: false,
|
|
75
|
-
required: ["id", "result", "evidence", "notes"],
|
|
76
|
-
properties: {
|
|
77
|
-
id: { type: "string", pattern: "^RVP-[0-9]{3}$" },
|
|
78
|
-
result: { enum: ["pass", "fail", "unclear"] },
|
|
79
|
-
evidence: {
|
|
80
|
-
type: "array",
|
|
81
|
-
minItems: 1,
|
|
82
|
-
maxItems: 100,
|
|
83
|
-
items: { $ref: "#/$defs/text" },
|
|
84
|
-
},
|
|
85
|
-
notes: { type: "string", maxLength: MAX_TEXT_LENGTH },
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
findings: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
573
|
+
grade_check: { $ref: "#/$defs/text" },
|
|
574
|
+
rationale: { type: "array", minItems: 1, maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
575
|
+
improvements: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
90
576
|
approach: { $ref: "#/$defs/text" },
|
|
91
|
-
|
|
92
|
-
block_reason: { type: "string", maxLength: MAX_TEXT_LENGTH },
|
|
577
|
+
verdict: { enum: [...REVIEW_VERDICTS] },
|
|
93
578
|
},
|
|
94
|
-
allOf: [
|
|
95
|
-
{
|
|
96
|
-
if: { properties: { outcome: { const: "blocked" } } },
|
|
97
|
-
then: { properties: { block_reason: { type: "string", pattern: "\\S" } } },
|
|
98
|
-
else: { properties: { block_reason: { type: "string", maxLength: 0 } } },
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
579
|
},
|
|
102
580
|
],
|
|
103
581
|
$defs: {
|
|
@@ -106,6 +584,23 @@ export const REPORTER_OUTPUT_SCHEMA = {
|
|
|
106
584
|
};
|
|
107
585
|
const Ajv2020 = Ajv2020Module.default;
|
|
108
586
|
const validateReporterSchema = new Ajv2020({ allErrors: true, strict: true }).compile(REPORTER_OUTPUT_SCHEMA);
|
|
587
|
+
// oneOf の各分岐は `properties.mode.const` で mode を固定している。分岐の並び順に依存せず、
|
|
588
|
+
// mode から Ajv の schemaPath の接頭辞(`#/oneOf/<index>/`)を求める。
|
|
589
|
+
function reporterSchemaBranchPath(mode) {
|
|
590
|
+
const index = REPORTER_OUTPUT_SCHEMA.oneOf.findIndex((branch) => branch.properties.mode.const === mode);
|
|
591
|
+
return index >= 0 ? `#/oneOf/${index}/` : undefined;
|
|
592
|
+
}
|
|
593
|
+
/** Returns the single-mode schema supplied to the selected reporter agent. */
|
|
594
|
+
export function reporterOutputSchemaForMode(mode) {
|
|
595
|
+
const branch = REPORTER_OUTPUT_SCHEMA.oneOf.find((candidate) => candidate.properties.mode.const === mode);
|
|
596
|
+
if (!branch)
|
|
597
|
+
throw new Error(`Reporter schema branch not found for mode: ${mode}`);
|
|
598
|
+
return {
|
|
599
|
+
$schema: REPORTER_OUTPUT_SCHEMA.$schema,
|
|
600
|
+
...branch,
|
|
601
|
+
$defs: REPORTER_OUTPUT_SCHEMA.$defs,
|
|
602
|
+
};
|
|
603
|
+
}
|
|
109
604
|
function isRecord(value) {
|
|
110
605
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
111
606
|
}
|
|
@@ -130,32 +625,12 @@ function validateCommon(value, mode) {
|
|
|
130
625
|
return "schema_version must equal 1";
|
|
131
626
|
if (value.mode !== mode)
|
|
132
627
|
return `mode must equal ${mode}`;
|
|
133
|
-
if (value.outcome !== "complete" && value.outcome !== "blocked") {
|
|
134
|
-
return "outcome must be complete or blocked";
|
|
135
|
-
}
|
|
136
|
-
if (!isText(value.block_reason, true))
|
|
137
|
-
return "block_reason must be a bounded string";
|
|
138
|
-
if (value.outcome === "blocked" && !String(value.block_reason).trim()) {
|
|
139
|
-
return "block_reason is required when outcome is blocked";
|
|
140
|
-
}
|
|
141
|
-
if (value.outcome === "complete" && String(value.block_reason).length > 0) {
|
|
142
|
-
return "block_reason must be empty when outcome is complete";
|
|
143
|
-
}
|
|
144
628
|
if (!isText(value.approach))
|
|
145
629
|
return "approach must be a non-empty bounded string";
|
|
146
630
|
return undefined;
|
|
147
631
|
}
|
|
148
632
|
function validateEdit(value) {
|
|
149
|
-
const keys = [
|
|
150
|
-
"schema_version",
|
|
151
|
-
"mode",
|
|
152
|
-
"outcome",
|
|
153
|
-
"summary",
|
|
154
|
-
"changed_files",
|
|
155
|
-
"handoff",
|
|
156
|
-
"approach",
|
|
157
|
-
"block_reason",
|
|
158
|
-
];
|
|
633
|
+
const keys = ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"];
|
|
159
634
|
if (!exactKeys(value, keys))
|
|
160
635
|
return "edit output has missing or additional properties";
|
|
161
636
|
const common = validateCommon(value, "edit");
|
|
@@ -165,68 +640,55 @@ function validateEdit(value) {
|
|
|
165
640
|
return "summary must contain 1-100 bounded strings";
|
|
166
641
|
if (!isTextArray(value.handoff, 100))
|
|
167
642
|
return "handoff must contain at most 100 bounded strings";
|
|
168
|
-
if (!Array.isArray(value.changed_files) || value.changed_files.length >
|
|
643
|
+
if (!Array.isArray(value.changed_files) || value.changed_files.length > 1_000) {
|
|
169
644
|
return "changed_files must be an array with at most 1000 items";
|
|
170
645
|
}
|
|
171
646
|
for (const file of value.changed_files) {
|
|
172
647
|
if (!isRecord(file) || !exactKeys(file, ["path", "summary"])) {
|
|
173
648
|
return "changed_files entries have missing or additional properties";
|
|
174
649
|
}
|
|
175
|
-
if (
|
|
650
|
+
if (!isText(file.path))
|
|
176
651
|
return "changed_files path must be a non-empty bounded string";
|
|
177
|
-
}
|
|
178
652
|
if (!isText(file.summary))
|
|
179
653
|
return "changed_files summary must be a non-empty bounded string";
|
|
180
654
|
}
|
|
181
655
|
return undefined;
|
|
182
656
|
}
|
|
657
|
+
// 改訂前の decision.recommendation(approve / revise / reject)と verdict_definitions の旧値は、
|
|
658
|
+
// review の verdict へ統一した(PJR-XTAN)。
|
|
659
|
+
function legacyReviewVocabularyError(value) {
|
|
660
|
+
if (Object.hasOwn(value, "recommendation")) {
|
|
661
|
+
return `recommendation was replaced by verdict; ${describeInvalidReviewVerdict(value.recommendation)}`;
|
|
662
|
+
}
|
|
663
|
+
if (typeof value.verdict === "string" && !isReviewVerdict(value.verdict)) {
|
|
664
|
+
return `verdict is invalid: ${describeInvalidReviewVerdict(value.verdict)}`;
|
|
665
|
+
}
|
|
666
|
+
return undefined;
|
|
667
|
+
}
|
|
183
668
|
function validateReview(value) {
|
|
184
669
|
const keys = [
|
|
185
670
|
"schema_version",
|
|
186
671
|
"mode",
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
"
|
|
672
|
+
"grade_check",
|
|
673
|
+
"rationale",
|
|
674
|
+
"improvements",
|
|
190
675
|
"approach",
|
|
191
|
-
"
|
|
192
|
-
"block_reason",
|
|
676
|
+
"verdict",
|
|
193
677
|
];
|
|
194
678
|
if (!exactKeys(value, keys))
|
|
195
679
|
return "review output has missing or additional properties";
|
|
196
680
|
const common = validateCommon(value, "review");
|
|
197
681
|
if (common)
|
|
198
682
|
return common;
|
|
199
|
-
if (!
|
|
200
|
-
return "
|
|
201
|
-
if (!
|
|
202
|
-
return "
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
for (const viewpoint of value.viewpoint_results) {
|
|
206
|
-
if (!isRecord(viewpoint) || !exactKeys(viewpoint, ["id", "result", "evidence", "notes"])) {
|
|
207
|
-
return "viewpoint_results entries have missing or additional properties";
|
|
208
|
-
}
|
|
209
|
-
if (typeof viewpoint.id !== "string" || !/^RVP-[0-9]{3}$/.test(viewpoint.id)) {
|
|
210
|
-
return "viewpoint id must match RVP-NNN";
|
|
211
|
-
}
|
|
212
|
-
if (ids.has(viewpoint.id))
|
|
213
|
-
return `duplicate viewpoint id: ${viewpoint.id}`;
|
|
214
|
-
ids.add(viewpoint.id);
|
|
215
|
-
if (viewpoint.result !== "pass" &&
|
|
216
|
-
viewpoint.result !== "fail" &&
|
|
217
|
-
viewpoint.result !== "unclear") {
|
|
218
|
-
return "viewpoint result must be pass, fail, or unclear";
|
|
219
|
-
}
|
|
220
|
-
if (!isTextArray(viewpoint.evidence, 100, 1)) {
|
|
221
|
-
return "viewpoint evidence must contain 1-100 bounded strings";
|
|
222
|
-
}
|
|
223
|
-
if (!isText(viewpoint.notes, true))
|
|
224
|
-
return "viewpoint notes must be a bounded string";
|
|
683
|
+
if (!isText(value.grade_check))
|
|
684
|
+
return "grade_check must be a non-empty bounded string";
|
|
685
|
+
if (!isTextArray(value.rationale, 100, 1))
|
|
686
|
+
return "rationale must contain 1-100 bounded strings";
|
|
687
|
+
if (!isTextArray(value.improvements, 100)) {
|
|
688
|
+
return "improvements must contain at most 100 bounded strings";
|
|
225
689
|
}
|
|
226
|
-
if (value.
|
|
227
|
-
|
|
228
|
-
value.recommendation !== "reject") {
|
|
229
|
-
return "recommendation must be approve, revise, or reject";
|
|
690
|
+
if (!isReviewVerdict(value.verdict)) {
|
|
691
|
+
return `verdict is invalid: ${describeInvalidReviewVerdict(value.verdict)}`;
|
|
230
692
|
}
|
|
231
693
|
return undefined;
|
|
232
694
|
}
|
|
@@ -242,8 +704,19 @@ export function parseReporterOutput(raw, mode) {
|
|
|
242
704
|
}
|
|
243
705
|
if (!isRecord(value))
|
|
244
706
|
return { error: "response root must be an object" };
|
|
707
|
+
// 旧語彙はスキーマの汎用エラーでは移行先が分からないため、スキーマ検証より先に移行先を示す。
|
|
708
|
+
const legacyError = mode === "review" ? legacyReviewVocabularyError(value) : undefined;
|
|
709
|
+
if (legacyError)
|
|
710
|
+
return { error: legacyError };
|
|
245
711
|
if (!validateReporterSchema(value)) {
|
|
246
|
-
|
|
712
|
+
// スキーマは edit / review の oneOf なので、両方の分岐のエラーが混ざる。先頭だけを
|
|
713
|
+
// 表示すると期待する mode と無関係な分岐のエラーで原因が隠れるため、mode の分岐に絞る。
|
|
714
|
+
const errors = validateReporterSchema.errors ?? [];
|
|
715
|
+
const modeBranch = reporterSchemaBranchPath(mode);
|
|
716
|
+
const modeErrors = modeBranch
|
|
717
|
+
? errors.filter((error) => error.schemaPath.startsWith(modeBranch))
|
|
718
|
+
: [];
|
|
719
|
+
const details = (modeErrors.length > 0 ? modeErrors : errors)
|
|
247
720
|
.slice(0, 5)
|
|
248
721
|
.map((error) => `${error.instancePath || "/"} ${error.keyword}: ${error.message ?? "invalid value"}`)
|
|
249
722
|
.join("; ");
|
|
@@ -258,12 +731,18 @@ export function buildReporterPrompt(opts) {
|
|
|
258
731
|
const correction = opts.validationError
|
|
259
732
|
? `\nThe previous response failed validation: ${opts.validationError}\nReturn a corrected JSON value.\n`
|
|
260
733
|
: "";
|
|
734
|
+
const reviewGuidance = opts.mode === "review"
|
|
735
|
+
? `\n\nFor review mode, the executor did not re-grade the deliverable; it judged task completion
|
|
736
|
+
from the stored grade result. Record that judgement in verdict and put unmet items and improvement
|
|
737
|
+
instructions in improvements. If evidence.final_message identifies "確認できなかった範囲",
|
|
738
|
+
record that scope in rationale or improvements and reflect it in the verdict.`
|
|
739
|
+
: "";
|
|
261
740
|
return `You are the reporter stage of a SpecDojo executor/reporter pipeline.
|
|
262
741
|
Use only the supplied plan and bounded executor evidence. Do not edit or inspect files. Do not
|
|
263
742
|
invent facts that are absent from evidence. Return exactly one JSON object matching the supplied
|
|
264
|
-
JSON Schema, without Markdown fences or commentary.
|
|
265
|
-
|
|
266
|
-
response
|
|
743
|
+
JSON Schema, without Markdown fences or commentary. The runner owns frontmatter, outcome,
|
|
744
|
+
block_reason, the authoritative changed-file list, and Markdown rendering. It derives those facts
|
|
745
|
+
mechanically from evidence; your response supplies prose associated with evidence paths.
|
|
267
746
|
|
|
268
747
|
The runner renders your free-text JSON fields as Markdown. Wrap every identifier or field name
|
|
269
748
|
containing an underscore in inline code (for example, \`depends_on\`) so Markdown parsers do not
|
|
@@ -272,16 +751,18 @@ misread it as emphasis.
|
|
|
272
751
|
The plan below was written as generic instructions for a single agent that both edits the
|
|
273
752
|
deliverable and records its own result. In this pipeline, those two responsibilities are split:
|
|
274
753
|
the executor already completed the deliverable edit and intentionally left the result file
|
|
275
|
-
untouched
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
754
|
+
untouched because the runner writes it from your prose and machine facts. For edit mode, identify
|
|
755
|
+
each changed_files summary with the exact path from its evidence.changes entry. The runner matches
|
|
756
|
+
descriptions by path: order does not matter, missing descriptions use a default message, and paths
|
|
757
|
+
absent from evidence are discarded. Do not include statuses. An empty changes list requires an
|
|
758
|
+
empty changed_files list. Validation entries with source="runner" were executed by the parent
|
|
759
|
+
process and remain authoritative machine facts. Do not turn them into outcome or block_reason
|
|
760
|
+
fields. When runner_context is present, it contains additional authoritative facts: do not ask for
|
|
761
|
+
a command in mechanically_not_applicable to be run, because the runner already determined that it
|
|
762
|
+
does not apply and will preserve that handoff itself. Paths in runner_managed_attempt_changes were
|
|
763
|
+
materially changed during the executor attempt but are intentionally absent from changed_files;
|
|
764
|
+
do not request confirmation solely because the executor mentions one of those changes while the
|
|
765
|
+
path is absent from changed_files.${reviewGuidance}${correction}
|
|
285
766
|
<specdojo_plan>
|
|
286
767
|
${opts.plan.trimEnd()}
|
|
287
768
|
</specdojo_plan>
|
|
@@ -291,7 +772,7 @@ ${JSON.stringify(opts.evidence, null, 2)}
|
|
|
291
772
|
</specdojo_executor_evidence>
|
|
292
773
|
|
|
293
774
|
<specdojo_reporter_output_schema mode="${opts.mode}">
|
|
294
|
-
${JSON.stringify(
|
|
775
|
+
${JSON.stringify(reporterOutputSchemaForMode(opts.mode), null, 2)}
|
|
295
776
|
</specdojo_reporter_output_schema>
|
|
296
777
|
`;
|
|
297
778
|
}
|