specdojo 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/catalog-build-references.js +144 -0
- package/dist/catalog-build-render.js +144 -0
- package/dist/catalog-build.js +13 -290
- package/dist/catalog-generate.js +6 -9
- package/dist/catalog-plan-generate.js +2 -2
- package/dist/catalog-plan.js +6 -6
- package/dist/catalog-scaffold.js +4 -4
- package/dist/catalog.js +2 -2
- package/dist/dashboard-exec-records.js +105 -0
- package/dist/dashboard-routines.js +255 -0
- package/dist/dashboard-shared.js +14 -0
- package/dist/dashboard-timeline.js +175 -0
- package/dist/dashboard.js +10 -544
- package/dist/deliverable-trash.js +3 -3
- package/dist/doc-index.js +3 -3
- package/dist/exec-commands.js +557 -0
- package/dist/exec-core.js +457 -0
- package/dist/exec-plans-core.js +693 -0
- package/dist/exec-plans-generation.js +206 -0
- package/dist/exec-plans-storage.js +131 -0
- package/dist/exec-plans.js +3 -1018
- package/dist/exec-repo-integration-git.js +23 -0
- package/dist/exec-repo-integration-sync.js +264 -0
- package/dist/exec-repo-integration.js +4 -281
- package/dist/exec-reporter-output.js +206 -0
- package/dist/exec-reporter.js +2 -206
- package/dist/exec-results.js +22 -15
- package/dist/exec-run-agent-pipeline.js +256 -0
- package/dist/exec-run-agent.js +531 -0
- package/dist/exec-run-in-place.js +541 -0
- package/dist/exec-run-job.js +717 -0
- package/dist/exec-run-lifecycle-commands.js +522 -0
- package/dist/exec-run-mode-shared.js +140 -0
- package/dist/exec-run-register-command.js +244 -0
- package/dist/exec-run-register-core.js +386 -0
- package/dist/exec-run-register-mode.js +206 -0
- package/dist/exec-run-register-resume.js +393 -0
- package/dist/exec-run-register-state.js +322 -0
- package/dist/exec-run-register-worktree.js +509 -0
- package/dist/exec-run-schedule-mode.js +294 -0
- package/dist/exec-run-schedule-prepare.js +353 -0
- package/dist/exec-run-schedule-task.js +572 -0
- package/dist/exec-run-shared.js +399 -0
- package/dist/exec-run.js +11 -6182
- package/dist/exec-shared.js +2 -2
- package/dist/exec-trial-commands.js +558 -0
- package/dist/exec-trial-core.js +371 -0
- package/dist/exec-trial.js +2 -921
- package/dist/exec-worktree-ops-commit.js +707 -0
- package/dist/exec-worktree-ops-lifecycle.js +292 -0
- package/dist/exec-worktree-ops-merge.js +303 -0
- package/dist/exec-worktree-ops.js +3 -1292
- package/dist/exec-worktree.js +32 -4
- package/dist/exec.js +2 -1006
- package/dist/frontmatter-namespace.js +2 -2
- package/dist/grade-apply.js +734 -0
- package/dist/grade-command-apply.js +250 -0
- package/dist/grade-command-inspect.js +138 -0
- package/dist/grade-command-plan.js +101 -0
- package/dist/grade-command-shared.js +68 -0
- package/dist/grade-core.js +307 -0
- package/dist/grade-markdown.js +274 -0
- package/dist/grade-pipeline-state.js +184 -0
- package/dist/grade-plan.js +507 -0
- package/dist/grade-result.js +5 -5
- package/dist/grade-target-discovery.js +265 -0
- package/dist/grade-targets.js +432 -0
- package/dist/grade.js +14 -3188
- package/dist/init-command.js +7 -7
- package/dist/job-definition.js +670 -0
- package/dist/job.js +9 -673
- package/dist/kata-command.js +2 -2
- package/dist/register-command-types.js +1 -0
- package/dist/register-core.js +363 -0
- package/dist/register-create-commands.js +245 -0
- package/dist/register-events.js +4 -4
- package/dist/register-item.js +6 -6
- package/dist/register-maintenance-commands.js +187 -0
- package/dist/register-migration.js +268 -0
- package/dist/register-renumber.js +314 -0
- package/dist/register-transition-commands.js +248 -0
- package/dist/register-update.js +230 -0
- package/dist/register-views.js +256 -0
- package/dist/register.js +61 -2069
- package/dist/review-plan.js +3 -3
- package/dist/routine-definition.js +401 -0
- package/dist/routine.js +6 -402
- package/dist/schedule-approach.js +2 -2
- package/dist/schedule-strategy-generate-document.js +273 -0
- package/dist/schedule-strategy-generate-scope.js +199 -0
- package/dist/schedule-strategy-generate.js +9 -473
- package/dist/schedule.js +4 -4
- package/dist/specdojo-config.js +3 -4
- package/dist/viewpoint-document-kinds-check.js +3 -3
- package/dist/yaml-pages.js +4 -4
- package/dist/yaml.js +28 -0
- package/docs/ja/specdojo/guides/exec-config-guide.md +6 -6
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +20 -18
- package/docs/ja/specdojo/guides/routine-operation-guide.md +1 -1
- package/package.json +4 -5
- package/templates/antigravity/README.md +3 -3
- package/templates/antigravity/exec-defaults-snippet.yaml +6 -4
- package/templates/init-exec-defaults.yaml +3 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import Ajv2020Module from "ajv/dist/2020.js";
|
|
2
|
+
import { extractJsonText } from "./agent-response.js";
|
|
3
|
+
import { REVIEW_VERDICTS, describeInvalidReviewVerdict, isReviewVerdict } from "./review-types.js";
|
|
4
|
+
export const MAX_TEXT_LENGTH = 4_000;
|
|
5
|
+
// review の verdict の正本は review-types.ts であり、verdict_definitions と同じ語彙を使う。
|
|
6
|
+
export { REVIEW_VERDICTS };
|
|
7
|
+
export const REPORTER_OUTPUT_SCHEMA = {
|
|
8
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
9
|
+
oneOf: [
|
|
10
|
+
{
|
|
11
|
+
type: "object",
|
|
12
|
+
additionalProperties: false,
|
|
13
|
+
required: ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"],
|
|
14
|
+
properties: {
|
|
15
|
+
schema_version: { const: 1 },
|
|
16
|
+
mode: { const: "edit" },
|
|
17
|
+
summary: { type: "array", minItems: 1, maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
18
|
+
changed_files: {
|
|
19
|
+
type: "array",
|
|
20
|
+
maxItems: 1_000,
|
|
21
|
+
items: {
|
|
22
|
+
type: "object",
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
required: ["path", "summary"],
|
|
25
|
+
properties: {
|
|
26
|
+
path: { $ref: "#/$defs/text" },
|
|
27
|
+
summary: { $ref: "#/$defs/text" },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
handoff: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
32
|
+
approach: { $ref: "#/$defs/text" },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: "object",
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
required: [
|
|
39
|
+
"schema_version",
|
|
40
|
+
"mode",
|
|
41
|
+
"grade_check",
|
|
42
|
+
"rationale",
|
|
43
|
+
"improvements",
|
|
44
|
+
"approach",
|
|
45
|
+
"verdict",
|
|
46
|
+
],
|
|
47
|
+
properties: {
|
|
48
|
+
schema_version: { const: 1 },
|
|
49
|
+
mode: { const: "review" },
|
|
50
|
+
grade_check: { $ref: "#/$defs/text" },
|
|
51
|
+
rationale: { type: "array", minItems: 1, maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
52
|
+
improvements: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
53
|
+
approach: { $ref: "#/$defs/text" },
|
|
54
|
+
verdict: { enum: [...REVIEW_VERDICTS] },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
$defs: {
|
|
59
|
+
text: { type: "string", minLength: 1, maxLength: MAX_TEXT_LENGTH },
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const Ajv2020 = Ajv2020Module.default;
|
|
63
|
+
const validateReporterSchema = new Ajv2020({ allErrors: true, strict: true }).compile(REPORTER_OUTPUT_SCHEMA);
|
|
64
|
+
// oneOf の各分岐は `properties.mode.const` で mode を固定している。分岐の並び順に依存せず、
|
|
65
|
+
// mode から Ajv の schemaPath の接頭辞(`#/oneOf/<index>/`)を求める。
|
|
66
|
+
function reporterSchemaBranchPath(mode) {
|
|
67
|
+
const index = REPORTER_OUTPUT_SCHEMA.oneOf.findIndex((branch) => branch.properties.mode.const === mode);
|
|
68
|
+
return index >= 0 ? `#/oneOf/${index}/` : undefined;
|
|
69
|
+
}
|
|
70
|
+
/** Returns the single-mode schema supplied to the selected reporter agent. */
|
|
71
|
+
export function reporterOutputSchemaForMode(mode) {
|
|
72
|
+
const branch = REPORTER_OUTPUT_SCHEMA.oneOf.find((candidate) => candidate.properties.mode.const === mode);
|
|
73
|
+
if (!branch)
|
|
74
|
+
throw new Error(`Reporter schema branch not found for mode: ${mode}`);
|
|
75
|
+
return {
|
|
76
|
+
$schema: REPORTER_OUTPUT_SCHEMA.$schema,
|
|
77
|
+
...branch,
|
|
78
|
+
$defs: REPORTER_OUTPUT_SCHEMA.$defs,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function isRecord(value) {
|
|
82
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
83
|
+
}
|
|
84
|
+
function exactKeys(value, keys) {
|
|
85
|
+
const actual = Object.keys(value).sort();
|
|
86
|
+
const expected = [...keys].sort();
|
|
87
|
+
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
88
|
+
}
|
|
89
|
+
function isText(value, allowEmpty = false) {
|
|
90
|
+
return (typeof value === "string" &&
|
|
91
|
+
value.length <= MAX_TEXT_LENGTH &&
|
|
92
|
+
(allowEmpty || value.trim().length > 0));
|
|
93
|
+
}
|
|
94
|
+
function isTextArray(value, maxItems = 100, minItems = 0) {
|
|
95
|
+
return (Array.isArray(value) &&
|
|
96
|
+
value.length >= minItems &&
|
|
97
|
+
value.length <= maxItems &&
|
|
98
|
+
value.every((item) => isText(item)));
|
|
99
|
+
}
|
|
100
|
+
function validateCommon(value, mode) {
|
|
101
|
+
if (value.schema_version !== 1)
|
|
102
|
+
return "schema_version must equal 1";
|
|
103
|
+
if (value.mode !== mode)
|
|
104
|
+
return `mode must equal ${mode}`;
|
|
105
|
+
if (!isText(value.approach))
|
|
106
|
+
return "approach must be a non-empty bounded string";
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
function validateEdit(value) {
|
|
110
|
+
const keys = ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"];
|
|
111
|
+
if (!exactKeys(value, keys))
|
|
112
|
+
return "edit output has missing or additional properties";
|
|
113
|
+
const common = validateCommon(value, "edit");
|
|
114
|
+
if (common)
|
|
115
|
+
return common;
|
|
116
|
+
if (!isTextArray(value.summary, 100, 1))
|
|
117
|
+
return "summary must contain 1-100 bounded strings";
|
|
118
|
+
if (!isTextArray(value.handoff, 100))
|
|
119
|
+
return "handoff must contain at most 100 bounded strings";
|
|
120
|
+
if (!Array.isArray(value.changed_files) || value.changed_files.length > 1_000) {
|
|
121
|
+
return "changed_files must be an array with at most 1000 items";
|
|
122
|
+
}
|
|
123
|
+
for (const file of value.changed_files) {
|
|
124
|
+
if (!isRecord(file) || !exactKeys(file, ["path", "summary"])) {
|
|
125
|
+
return "changed_files entries have missing or additional properties";
|
|
126
|
+
}
|
|
127
|
+
if (!isText(file.path))
|
|
128
|
+
return "changed_files path must be a non-empty bounded string";
|
|
129
|
+
if (!isText(file.summary))
|
|
130
|
+
return "changed_files summary must be a non-empty bounded string";
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
// 改訂前の decision.recommendation(approve / revise / reject)と verdict_definitions の旧値は、
|
|
135
|
+
// review の verdict へ統一した(PJR-XTAN)。
|
|
136
|
+
function legacyReviewVocabularyError(value) {
|
|
137
|
+
if (Object.hasOwn(value, "recommendation")) {
|
|
138
|
+
return `recommendation was replaced by verdict; ${describeInvalidReviewVerdict(value.recommendation)}`;
|
|
139
|
+
}
|
|
140
|
+
if (typeof value.verdict === "string" && !isReviewVerdict(value.verdict)) {
|
|
141
|
+
return `verdict is invalid: ${describeInvalidReviewVerdict(value.verdict)}`;
|
|
142
|
+
}
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
function validateReview(value) {
|
|
146
|
+
const keys = [
|
|
147
|
+
"schema_version",
|
|
148
|
+
"mode",
|
|
149
|
+
"grade_check",
|
|
150
|
+
"rationale",
|
|
151
|
+
"improvements",
|
|
152
|
+
"approach",
|
|
153
|
+
"verdict",
|
|
154
|
+
];
|
|
155
|
+
if (!exactKeys(value, keys))
|
|
156
|
+
return "review output has missing or additional properties";
|
|
157
|
+
const common = validateCommon(value, "review");
|
|
158
|
+
if (common)
|
|
159
|
+
return common;
|
|
160
|
+
if (!isText(value.grade_check))
|
|
161
|
+
return "grade_check must be a non-empty bounded string";
|
|
162
|
+
if (!isTextArray(value.rationale, 100, 1))
|
|
163
|
+
return "rationale must contain 1-100 bounded strings";
|
|
164
|
+
if (!isTextArray(value.improvements, 100)) {
|
|
165
|
+
return "improvements must contain at most 100 bounded strings";
|
|
166
|
+
}
|
|
167
|
+
if (!isReviewVerdict(value.verdict)) {
|
|
168
|
+
return `verdict is invalid: ${describeInvalidReviewVerdict(value.verdict)}`;
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
export function parseReporterOutput(raw, mode) {
|
|
173
|
+
let value;
|
|
174
|
+
try {
|
|
175
|
+
value = JSON.parse(extractJsonText(raw));
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
return {
|
|
179
|
+
error: `response is not a single JSON value: ${error instanceof Error ? error.message : String(error)}`,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (!isRecord(value))
|
|
183
|
+
return { error: "response root must be an object" };
|
|
184
|
+
// 旧語彙はスキーマの汎用エラーでは移行先が分からないため、スキーマ検証より先に移行先を示す。
|
|
185
|
+
const legacyError = mode === "review" ? legacyReviewVocabularyError(value) : undefined;
|
|
186
|
+
if (legacyError)
|
|
187
|
+
return { error: legacyError };
|
|
188
|
+
if (!validateReporterSchema(value)) {
|
|
189
|
+
// スキーマは edit / review の oneOf なので、両方の分岐のエラーが混ざる。先頭だけを
|
|
190
|
+
// 表示すると期待する mode と無関係な分岐のエラーで原因が隠れるため、mode の分岐に絞る。
|
|
191
|
+
const errors = validateReporterSchema.errors ?? [];
|
|
192
|
+
const modeBranch = reporterSchemaBranchPath(mode);
|
|
193
|
+
const modeErrors = modeBranch
|
|
194
|
+
? errors.filter((error) => error.schemaPath.startsWith(modeBranch))
|
|
195
|
+
: [];
|
|
196
|
+
const details = (modeErrors.length > 0 ? modeErrors : errors)
|
|
197
|
+
.slice(0, 5)
|
|
198
|
+
.map((error) => `${error.instancePath || "/"} ${error.keyword}: ${error.message ?? "invalid value"}`)
|
|
199
|
+
.join("; ");
|
|
200
|
+
return { error: `response does not match reporter JSON Schema: ${details}` };
|
|
201
|
+
}
|
|
202
|
+
const validationError = mode === "edit" ? validateEdit(value) : validateReview(value);
|
|
203
|
+
return validationError
|
|
204
|
+
? { error: validationError }
|
|
205
|
+
: { output: value };
|
|
206
|
+
}
|
package/dist/exec-reporter.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import Ajv2020Module from "ajv/dist/2020.js";
|
|
2
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
2
|
import { join, relative, resolve, sep } from "node:path";
|
|
4
|
-
import { extractJsonText } from "./agent-response.js";
|
|
5
3
|
import { PARENT_VALIDATION_PROJECT_REPO, failedParentValidationReason, } from "./exec-parent-validation.js";
|
|
6
4
|
import { getProjectExecutionPath, resolveRepoRoot, specdojoRootDir, } from "./specdojo-config.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
5
|
+
import { MAX_TEXT_LENGTH, parseReporterOutput, reporterOutputSchemaForMode, } from "./exec-reporter-output.js";
|
|
6
|
+
export { REPORTER_OUTPUT_SCHEMA, REVIEW_VERDICTS, parseReporterOutput, reporterOutputSchemaForMode, } from "./exec-reporter-output.js";
|
|
9
7
|
const REPORTER_FORMAT_ATTEMPTS = 3;
|
|
10
|
-
// review の verdict の正本は review-types.ts であり、verdict_definitions と同じ語彙を使う。
|
|
11
|
-
export { REVIEW_VERDICTS };
|
|
12
8
|
function isProjectConfig(value) {
|
|
13
9
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
10
|
}
|
|
@@ -527,206 +523,6 @@ function readPackageManifest(packageJsonPath) {
|
|
|
527
523
|
: []);
|
|
528
524
|
return { scripts, dependencies: new Set(dependencyEntries.map(([name]) => name)) };
|
|
529
525
|
}
|
|
530
|
-
export const REPORTER_OUTPUT_SCHEMA = {
|
|
531
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
532
|
-
oneOf: [
|
|
533
|
-
{
|
|
534
|
-
type: "object",
|
|
535
|
-
additionalProperties: false,
|
|
536
|
-
required: ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"],
|
|
537
|
-
properties: {
|
|
538
|
-
schema_version: { const: 1 },
|
|
539
|
-
mode: { const: "edit" },
|
|
540
|
-
summary: { type: "array", minItems: 1, maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
541
|
-
changed_files: {
|
|
542
|
-
type: "array",
|
|
543
|
-
maxItems: 1_000,
|
|
544
|
-
items: {
|
|
545
|
-
type: "object",
|
|
546
|
-
additionalProperties: false,
|
|
547
|
-
required: ["path", "summary"],
|
|
548
|
-
properties: {
|
|
549
|
-
path: { $ref: "#/$defs/text" },
|
|
550
|
-
summary: { $ref: "#/$defs/text" },
|
|
551
|
-
},
|
|
552
|
-
},
|
|
553
|
-
},
|
|
554
|
-
handoff: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
555
|
-
approach: { $ref: "#/$defs/text" },
|
|
556
|
-
},
|
|
557
|
-
},
|
|
558
|
-
{
|
|
559
|
-
type: "object",
|
|
560
|
-
additionalProperties: false,
|
|
561
|
-
required: [
|
|
562
|
-
"schema_version",
|
|
563
|
-
"mode",
|
|
564
|
-
"grade_check",
|
|
565
|
-
"rationale",
|
|
566
|
-
"improvements",
|
|
567
|
-
"approach",
|
|
568
|
-
"verdict",
|
|
569
|
-
],
|
|
570
|
-
properties: {
|
|
571
|
-
schema_version: { const: 1 },
|
|
572
|
-
mode: { const: "review" },
|
|
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" } },
|
|
576
|
-
approach: { $ref: "#/$defs/text" },
|
|
577
|
-
verdict: { enum: [...REVIEW_VERDICTS] },
|
|
578
|
-
},
|
|
579
|
-
},
|
|
580
|
-
],
|
|
581
|
-
$defs: {
|
|
582
|
-
text: { type: "string", minLength: 1, maxLength: MAX_TEXT_LENGTH },
|
|
583
|
-
},
|
|
584
|
-
};
|
|
585
|
-
const Ajv2020 = Ajv2020Module.default;
|
|
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
|
-
}
|
|
604
|
-
function isRecord(value) {
|
|
605
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
606
|
-
}
|
|
607
|
-
function exactKeys(value, keys) {
|
|
608
|
-
const actual = Object.keys(value).sort();
|
|
609
|
-
const expected = [...keys].sort();
|
|
610
|
-
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
611
|
-
}
|
|
612
|
-
function isText(value, allowEmpty = false) {
|
|
613
|
-
return (typeof value === "string" &&
|
|
614
|
-
value.length <= MAX_TEXT_LENGTH &&
|
|
615
|
-
(allowEmpty || value.trim().length > 0));
|
|
616
|
-
}
|
|
617
|
-
function isTextArray(value, maxItems = 100, minItems = 0) {
|
|
618
|
-
return (Array.isArray(value) &&
|
|
619
|
-
value.length >= minItems &&
|
|
620
|
-
value.length <= maxItems &&
|
|
621
|
-
value.every((item) => isText(item)));
|
|
622
|
-
}
|
|
623
|
-
function validateCommon(value, mode) {
|
|
624
|
-
if (value.schema_version !== 1)
|
|
625
|
-
return "schema_version must equal 1";
|
|
626
|
-
if (value.mode !== mode)
|
|
627
|
-
return `mode must equal ${mode}`;
|
|
628
|
-
if (!isText(value.approach))
|
|
629
|
-
return "approach must be a non-empty bounded string";
|
|
630
|
-
return undefined;
|
|
631
|
-
}
|
|
632
|
-
function validateEdit(value) {
|
|
633
|
-
const keys = ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"];
|
|
634
|
-
if (!exactKeys(value, keys))
|
|
635
|
-
return "edit output has missing or additional properties";
|
|
636
|
-
const common = validateCommon(value, "edit");
|
|
637
|
-
if (common)
|
|
638
|
-
return common;
|
|
639
|
-
if (!isTextArray(value.summary, 100, 1))
|
|
640
|
-
return "summary must contain 1-100 bounded strings";
|
|
641
|
-
if (!isTextArray(value.handoff, 100))
|
|
642
|
-
return "handoff must contain at most 100 bounded strings";
|
|
643
|
-
if (!Array.isArray(value.changed_files) || value.changed_files.length > 1_000) {
|
|
644
|
-
return "changed_files must be an array with at most 1000 items";
|
|
645
|
-
}
|
|
646
|
-
for (const file of value.changed_files) {
|
|
647
|
-
if (!isRecord(file) || !exactKeys(file, ["path", "summary"])) {
|
|
648
|
-
return "changed_files entries have missing or additional properties";
|
|
649
|
-
}
|
|
650
|
-
if (!isText(file.path))
|
|
651
|
-
return "changed_files path must be a non-empty bounded string";
|
|
652
|
-
if (!isText(file.summary))
|
|
653
|
-
return "changed_files summary must be a non-empty bounded string";
|
|
654
|
-
}
|
|
655
|
-
return undefined;
|
|
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
|
-
}
|
|
668
|
-
function validateReview(value) {
|
|
669
|
-
const keys = [
|
|
670
|
-
"schema_version",
|
|
671
|
-
"mode",
|
|
672
|
-
"grade_check",
|
|
673
|
-
"rationale",
|
|
674
|
-
"improvements",
|
|
675
|
-
"approach",
|
|
676
|
-
"verdict",
|
|
677
|
-
];
|
|
678
|
-
if (!exactKeys(value, keys))
|
|
679
|
-
return "review output has missing or additional properties";
|
|
680
|
-
const common = validateCommon(value, "review");
|
|
681
|
-
if (common)
|
|
682
|
-
return common;
|
|
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";
|
|
689
|
-
}
|
|
690
|
-
if (!isReviewVerdict(value.verdict)) {
|
|
691
|
-
return `verdict is invalid: ${describeInvalidReviewVerdict(value.verdict)}`;
|
|
692
|
-
}
|
|
693
|
-
return undefined;
|
|
694
|
-
}
|
|
695
|
-
export function parseReporterOutput(raw, mode) {
|
|
696
|
-
let value;
|
|
697
|
-
try {
|
|
698
|
-
value = JSON.parse(extractJsonText(raw));
|
|
699
|
-
}
|
|
700
|
-
catch (error) {
|
|
701
|
-
return {
|
|
702
|
-
error: `response is not a single JSON value: ${error instanceof Error ? error.message : String(error)}`,
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
if (!isRecord(value))
|
|
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 };
|
|
711
|
-
if (!validateReporterSchema(value)) {
|
|
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)
|
|
720
|
-
.slice(0, 5)
|
|
721
|
-
.map((error) => `${error.instancePath || "/"} ${error.keyword}: ${error.message ?? "invalid value"}`)
|
|
722
|
-
.join("; ");
|
|
723
|
-
return { error: `response does not match reporter JSON Schema: ${details}` };
|
|
724
|
-
}
|
|
725
|
-
const validationError = mode === "edit" ? validateEdit(value) : validateReview(value);
|
|
726
|
-
return validationError
|
|
727
|
-
? { error: validationError }
|
|
728
|
-
: { output: value };
|
|
729
|
-
}
|
|
730
526
|
export function buildReporterPrompt(opts) {
|
|
731
527
|
const correction = opts.validationError
|
|
732
528
|
? `\nThe previous response failed validation: ${opts.validationError}\nReturn a corrected JSON value.\n`
|
package/dist/exec-results.js
CHANGED
|
@@ -6,6 +6,7 @@ import { expandTemplate, stripTerminalControlSequences } from "./exec-shared.js"
|
|
|
6
6
|
import { formatMarkdownFile } from "./exec-format.js";
|
|
7
7
|
import { deriveReporterFacts, mechanicallyNotApplicableReason, runnerOwnedValidationReason, } from "./exec-reporter.js";
|
|
8
8
|
import { resolveSpecdojoPath, resolveSpecdojoPathIfExists } from "./template-resolution.js";
|
|
9
|
+
import { dump } from "./yaml.js";
|
|
9
10
|
const MISSING_CHANGED_FILE_SUMMARY = "reporter の説明がないため、変更差分を参照。";
|
|
10
11
|
// ---------------------------------------------------------------------------
|
|
11
12
|
// Frontmatter helpers
|
|
@@ -15,28 +16,35 @@ const MISSING_CHANGED_FILE_SUMMARY = "reporter の説明がないため、変更
|
|
|
15
16
|
function parseOrigin(value) {
|
|
16
17
|
return value === "register" || value === "schedule" || value === "job" ? value : undefined;
|
|
17
18
|
}
|
|
19
|
+
// js-yaml に単一スカラーとして直列化させ、通常の識別子は従来どおり plain style のまま
|
|
20
|
+
// 保つ。改行を含む値だけは block scalar を frontmatter の行配列へ安全に埋め込めないため、
|
|
21
|
+
// YAML 1.2 でも有効な JSON の二重引用符形式へフォールバックする。
|
|
22
|
+
function serializeYamlString(value) {
|
|
23
|
+
const serialized = dump(value, { lineWidth: -1, noRefs: true }).replace(/\n$/, "");
|
|
24
|
+
return serialized.includes("\n") ? JSON.stringify(value) : serialized;
|
|
25
|
+
}
|
|
18
26
|
function serializeFrontmatter(meta) {
|
|
19
27
|
const inner = [
|
|
20
|
-
`id: ${meta.id}`,
|
|
28
|
+
`id: ${serializeYamlString(meta.id)}`,
|
|
21
29
|
`type: ${meta.type}`,
|
|
22
|
-
`task_id: ${meta.task_id}`,
|
|
30
|
+
`task_id: ${serializeYamlString(meta.task_id)}`,
|
|
23
31
|
`mode: ${meta.mode}`,
|
|
24
32
|
`status: ${meta.status}`,
|
|
25
|
-
`project_id: ${meta.project_id}`,
|
|
33
|
+
`project_id: ${serializeYamlString(meta.project_id)}`,
|
|
26
34
|
];
|
|
27
35
|
if (meta.origin)
|
|
28
36
|
inner.push(`origin: ${meta.origin}`);
|
|
29
37
|
if (meta.job_id)
|
|
30
|
-
inner.push(`job_id: ${meta.job_id}`);
|
|
38
|
+
inner.push(`job_id: ${serializeYamlString(meta.job_id)}`);
|
|
31
39
|
if (meta.run_id)
|
|
32
|
-
inner.push(`run_id: ${meta.run_id}`);
|
|
40
|
+
inner.push(`run_id: ${serializeYamlString(meta.run_id)}`);
|
|
33
41
|
if (meta.plan_ref)
|
|
34
|
-
inner.push(`plan_ref: ${meta.plan_ref}`);
|
|
35
|
-
inner.push(`started_at:
|
|
42
|
+
inner.push(`plan_ref: ${serializeYamlString(meta.plan_ref)}`);
|
|
43
|
+
inner.push(`started_at: ${JSON.stringify(meta.started_at)}`);
|
|
36
44
|
if (meta.completed_at)
|
|
37
|
-
inner.push(`completed_at:
|
|
45
|
+
inner.push(`completed_at: ${JSON.stringify(meta.completed_at)}`);
|
|
38
46
|
if (meta.agent)
|
|
39
|
-
inner.push(`agent: ${meta.agent}`);
|
|
47
|
+
inner.push(`agent: ${serializeYamlString(meta.agent)}`);
|
|
40
48
|
if (meta.execution)
|
|
41
49
|
inner.push(`execution: ${meta.execution}`);
|
|
42
50
|
if (meta.approach)
|
|
@@ -44,15 +52,14 @@ function serializeFrontmatter(meta) {
|
|
|
44
52
|
if (meta.targets && meta.targets.length > 0) {
|
|
45
53
|
inner.push("targets:");
|
|
46
54
|
for (const target of meta.targets)
|
|
47
|
-
inner.push(` - ${target}`);
|
|
55
|
+
inner.push(` - ${serializeYamlString(target)}`);
|
|
48
56
|
}
|
|
49
57
|
// reason は agent stderr や subprocess の生出力由来で任意文字を含みうる。まず ANSI エスケープ
|
|
50
|
-
// シーケンスや制御文字を除去し(色付き hook 出力が result 表示を壊すのを防ぐ)、
|
|
51
|
-
//
|
|
52
|
-
// 単一行を返すため改行は無い)。
|
|
58
|
+
// シーケンスや制御文字を除去し(色付き hook 出力が result 表示を壊すのを防ぐ)、JSON の
|
|
59
|
+
// 文字列形式で YAML へ埋め込む。改行・引用符・バックスラッシュも値を変えずに保持できる。
|
|
53
60
|
if (meta.block_reason) {
|
|
54
|
-
const safeReason = stripTerminalControlSequences(meta.block_reason)
|
|
55
|
-
inner.push(`block_reason:
|
|
61
|
+
const safeReason = stripTerminalControlSequences(meta.block_reason);
|
|
62
|
+
inner.push(`block_reason: ${JSON.stringify(safeReason)}`);
|
|
56
63
|
}
|
|
57
64
|
return buildSpecdojoFrontmatter(inner);
|
|
58
65
|
}
|