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,250 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { extractJsonArrayText } from "./agent-response.js";
|
|
4
|
+
import { applyGradeSubmission, buildGradeSubmissionFromAnalysis, parseGradeSubmission, validateGradeReporterFidelity, } from "./grade-apply.js";
|
|
5
|
+
import { addGradeSelectionOptions as addSelection, commandError, requireNonNegativeInteger, requireTarget, } from "./grade-command-shared.js";
|
|
6
|
+
import { discoverGradeTargets } from "./grade-target-discovery.js";
|
|
7
|
+
import { applyGradeFindingTranslations, gradeFindingTranslationInput, gradeResultPathForDocument, readGradeResult, readGradeResultForDocument, writeGradeResult, } from "./grade-result.js";
|
|
8
|
+
import { loadViewpoints, repoRelativePath, resolveDeliverableDoneCriteria, resolveGradeActor, resolveProject, resolveSafeRepositoryPath, } from "./grade-targets.js";
|
|
9
|
+
import { getProjectExecutionPath, loadMemberRoster, specdojoRootDir } from "./specdojo-config.js";
|
|
10
|
+
export function renderGradeFindingTranslationPlan(result, translationIndex) {
|
|
11
|
+
const messages = gradeFindingTranslationInput(result, translationIndex);
|
|
12
|
+
return [
|
|
13
|
+
"# Grade finding translation",
|
|
14
|
+
"",
|
|
15
|
+
"次の JSON 文字列配列に含まれる英語の finding だけを、簡潔で自然な日本語へ翻訳してください。入力と同じ件数・同じ順序の、訳文だけの JSON 文字列配列を返してください。元の文にあるインラインコード(バッククォートで囲んだ部分)は一字一句変えずに残し、元の文にないインラインコードやバッククォートは追加しないでください。インラインコード以外の英語の語句は、固有名詞・識別子を除いて日本語に訳してください。Markdown fence、説明、番号、token、判定の変更は不要です。",
|
|
16
|
+
"",
|
|
17
|
+
"```json",
|
|
18
|
+
JSON.stringify(messages, null, 2),
|
|
19
|
+
"```",
|
|
20
|
+
"",
|
|
21
|
+
].join("\n");
|
|
22
|
+
}
|
|
23
|
+
export function registerGradeApplyCommands(grade) {
|
|
24
|
+
addSelection(grade
|
|
25
|
+
.command("apply")
|
|
26
|
+
.description("Convert executor markers (or validate reporter JSON), calculate scores, and update documents"))
|
|
27
|
+
.option("--from <path>", "GradeSubmission JSON produced by an LLM reporter; omit to convert --analysis-from mechanically")
|
|
28
|
+
.requiredOption("--by <nickname>", "Grading agent nickname from agent-members.yaml")
|
|
29
|
+
.option("--analysis-from <path>", "Executor analysis converted to GradeSubmission, or used to verify --from fidelity")
|
|
30
|
+
.option("--submission-out <path>", "Write the GradeSubmission converted from --analysis-from to this repository path")
|
|
31
|
+
.option("--reference <pathOrId>", "Comparison reference used during grading; recorded as a document id")
|
|
32
|
+
.option("--dry-run", "Validate and list updates without writing", false)
|
|
33
|
+
.action((options) => {
|
|
34
|
+
try {
|
|
35
|
+
const target = requireTarget(options.target);
|
|
36
|
+
const viewpoints = loadViewpoints(options.project);
|
|
37
|
+
const { project } = resolveProject(options.project);
|
|
38
|
+
const gradedBy = resolveGradeActor(options.by, loadMemberRoster(specdojoRootDir(), project));
|
|
39
|
+
if (!options.from && !options.analysisFrom) {
|
|
40
|
+
throw new Error("grade apply requires --analysis-from, --from, or both");
|
|
41
|
+
}
|
|
42
|
+
if (options.submissionOut && (options.from || !options.analysisFrom)) {
|
|
43
|
+
throw new Error("--submission-out requires --analysis-from without --from");
|
|
44
|
+
}
|
|
45
|
+
const selected = new Set(discoverGradeTargets({
|
|
46
|
+
target,
|
|
47
|
+
project: options.project,
|
|
48
|
+
paths: options.path,
|
|
49
|
+
changedOnly: options.changedOnly,
|
|
50
|
+
dependencyChanged: options.dependencyChanged,
|
|
51
|
+
rulebookChanged: options.rulebookChanged,
|
|
52
|
+
unreviewed: options.unreviewed,
|
|
53
|
+
verdict: options.verdict,
|
|
54
|
+
minScore: options.minScore,
|
|
55
|
+
maxFindings: options.maxFindings,
|
|
56
|
+
ungraded: options.ungraded,
|
|
57
|
+
incomplete: options.incomplete,
|
|
58
|
+
rubricOutdated: options.rubricOutdated,
|
|
59
|
+
}).map(repoRelativePath));
|
|
60
|
+
const doneCriteriaByPath = target === "deliverable"
|
|
61
|
+
? resolveDeliverableDoneCriteria([...selected], options.project)
|
|
62
|
+
: undefined;
|
|
63
|
+
let submission;
|
|
64
|
+
if (options.analysisFrom) {
|
|
65
|
+
if (selected.size !== 1) {
|
|
66
|
+
throw new Error("--analysis-from requires exactly one selected --path");
|
|
67
|
+
}
|
|
68
|
+
const expectedPath = [...selected][0];
|
|
69
|
+
const executorOutput = readFileSync(resolveSafeRepositoryPath(options.analysisFrom, "--analysis-from"), "utf8");
|
|
70
|
+
const conversionOptions = {
|
|
71
|
+
executorOutput,
|
|
72
|
+
viewpoints,
|
|
73
|
+
target,
|
|
74
|
+
expectedPath,
|
|
75
|
+
doneCriteria: doneCriteriaByPath?.get(expectedPath),
|
|
76
|
+
};
|
|
77
|
+
if (options.from) {
|
|
78
|
+
// LLM reporter の JSON を executor marker と照合する互換・比較用の経路。
|
|
79
|
+
submission = parseGradeSubmission(readFileSync(resolveSafeRepositoryPath(options.from, "--from"), "utf8"));
|
|
80
|
+
const fidelityIssues = validateGradeReporterFidelity({
|
|
81
|
+
...conversionOptions,
|
|
82
|
+
submission,
|
|
83
|
+
});
|
|
84
|
+
if (fidelityIssues.length > 0) {
|
|
85
|
+
throw new Error(fidelityIssues.map((issue) => `${issue.path}: ${issue.message}`).join("\n"));
|
|
86
|
+
}
|
|
87
|
+
const converted = buildGradeSubmissionFromAnalysis(conversionOptions);
|
|
88
|
+
if (converted.submission === undefined) {
|
|
89
|
+
throw new Error(converted.issues.map((issue) => `${issue.path}: ${issue.message}`).join("\n"));
|
|
90
|
+
}
|
|
91
|
+
const convertedDocument = converted.submission.documents[0];
|
|
92
|
+
const correctedLevels = new Map(convertedDocument.viewpoints.map((viewpoint) => [viewpoint.id, viewpoint.level]));
|
|
93
|
+
submission.documents[0] = {
|
|
94
|
+
...submission.documents[0],
|
|
95
|
+
viewpoints: submission.documents[0].viewpoints.map((viewpoint) => ({
|
|
96
|
+
...viewpoint,
|
|
97
|
+
level: correctedLevels.get(viewpoint.id) ?? viewpoint.level,
|
|
98
|
+
})),
|
|
99
|
+
...(convertedDocument.level_corrections
|
|
100
|
+
? { level_corrections: convertedDocument.level_corrections }
|
|
101
|
+
: {}),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const converted = buildGradeSubmissionFromAnalysis(conversionOptions);
|
|
106
|
+
if (converted.submission === undefined) {
|
|
107
|
+
throw new Error([
|
|
108
|
+
"executor analysis rejected; rerun the executor",
|
|
109
|
+
...converted.issues.map((issue) => `${issue.path}: ${issue.message}`),
|
|
110
|
+
].join("\n"));
|
|
111
|
+
}
|
|
112
|
+
submission = converted.submission;
|
|
113
|
+
if (options.submissionOut && !options.dryRun) {
|
|
114
|
+
const submissionOut = resolveSafeRepositoryPath(options.submissionOut, "--submission-out");
|
|
115
|
+
mkdirSync(dirname(submissionOut), { recursive: true });
|
|
116
|
+
writeFileSync(submissionOut, `${JSON.stringify(submission, null, 2)}\n`, "utf8");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
submission = parseGradeSubmission(readFileSync(resolveSafeRepositoryPath(options.from, "--from"), "utf8"));
|
|
122
|
+
}
|
|
123
|
+
for (const document of submission.documents)
|
|
124
|
+
if (!selected.has(repoRelativePath(resolve(specdojoRootDir(), document.path))))
|
|
125
|
+
throw new Error(`${document.path}: not selected by the current grade filters`);
|
|
126
|
+
const changed = applyGradeSubmission({
|
|
127
|
+
submission,
|
|
128
|
+
viewpoints,
|
|
129
|
+
target,
|
|
130
|
+
gradedBy,
|
|
131
|
+
reference: options.reference,
|
|
132
|
+
dryRun: options.dryRun,
|
|
133
|
+
doneCriteriaByPath,
|
|
134
|
+
criteriaDirectory: join(getProjectExecutionPath(project), "grade", "criteria"),
|
|
135
|
+
resultsDirectory: join(getProjectExecutionPath(project), "grade", "results"),
|
|
136
|
+
project: options.project,
|
|
137
|
+
});
|
|
138
|
+
for (const path of changed)
|
|
139
|
+
process.stdout.write(`${options.dryRun ? "would update" : "updated"}: ${path}\n`);
|
|
140
|
+
process.stdout.write(`Graded: ${submission.documents.length}, updated: ${changed.length}\n`);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
commandError(error);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
addSelection(grade
|
|
147
|
+
.command("translation-plan")
|
|
148
|
+
.description("Create a Japanese translation request for the latest canonical findings"))
|
|
149
|
+
.requiredOption("--out <path>", "Write the translation plan to this repository path")
|
|
150
|
+
.option("--translation-index <index>", "Translate only this zero-based index from the translatable findings", requireNonNegativeInteger)
|
|
151
|
+
.action((options) => {
|
|
152
|
+
try {
|
|
153
|
+
const target = requireTarget(options.target);
|
|
154
|
+
const selected = discoverGradeTargets({
|
|
155
|
+
target,
|
|
156
|
+
project: options.project,
|
|
157
|
+
paths: options.path,
|
|
158
|
+
changedOnly: options.changedOnly,
|
|
159
|
+
dependencyChanged: options.dependencyChanged,
|
|
160
|
+
rulebookChanged: options.rulebookChanged,
|
|
161
|
+
unreviewed: options.unreviewed,
|
|
162
|
+
verdict: options.verdict,
|
|
163
|
+
minScore: options.minScore,
|
|
164
|
+
maxFindings: options.maxFindings,
|
|
165
|
+
ungraded: options.ungraded,
|
|
166
|
+
incomplete: options.incomplete,
|
|
167
|
+
rubricOutdated: options.rubricOutdated,
|
|
168
|
+
}).map(repoRelativePath);
|
|
169
|
+
if (selected.length !== 1) {
|
|
170
|
+
throw new Error("grade translation-plan requires exactly one selected --path");
|
|
171
|
+
}
|
|
172
|
+
const result = readGradeResultForDocument({
|
|
173
|
+
documentPath: selected[0],
|
|
174
|
+
project: options.project,
|
|
175
|
+
});
|
|
176
|
+
if (!result)
|
|
177
|
+
throw new Error(`${selected[0]}: grade result not found`);
|
|
178
|
+
if (result.target !== target) {
|
|
179
|
+
throw new Error(`${selected[0]}: grade result target=${result.target}, expected=${target}`);
|
|
180
|
+
}
|
|
181
|
+
const output = resolveSafeRepositoryPath(options.out, "--out");
|
|
182
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
183
|
+
const messages = gradeFindingTranslationInput(result, options.translationIndex);
|
|
184
|
+
writeFileSync(output, renderGradeFindingTranslationPlan(result, options.translationIndex), "utf8");
|
|
185
|
+
process.stdout.write(`written: ${repoRelativePath(output)}\nTranslations: ${messages.length}\n`);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
commandError(error);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
addSelection(grade
|
|
192
|
+
.command("localize")
|
|
193
|
+
.description("Attach Japanese display messages to the latest canonical grade findings"))
|
|
194
|
+
.requiredOption("--from <path>", "JSON string array returned by the translation agent")
|
|
195
|
+
.option("--translation-index <index>", "Apply a retry for this zero-based index from the translatable findings", requireNonNegativeInteger)
|
|
196
|
+
.requiredOption("--rejections-out <path>", "Write machine-readable rejected translation details as JSON")
|
|
197
|
+
.action((options) => {
|
|
198
|
+
try {
|
|
199
|
+
const target = requireTarget(options.target);
|
|
200
|
+
const selected = discoverGradeTargets({
|
|
201
|
+
target,
|
|
202
|
+
project: options.project,
|
|
203
|
+
paths: options.path,
|
|
204
|
+
changedOnly: options.changedOnly,
|
|
205
|
+
dependencyChanged: options.dependencyChanged,
|
|
206
|
+
rulebookChanged: options.rulebookChanged,
|
|
207
|
+
unreviewed: options.unreviewed,
|
|
208
|
+
verdict: options.verdict,
|
|
209
|
+
minScore: options.minScore,
|
|
210
|
+
maxFindings: options.maxFindings,
|
|
211
|
+
ungraded: options.ungraded,
|
|
212
|
+
incomplete: options.incomplete,
|
|
213
|
+
rubricOutdated: options.rubricOutdated,
|
|
214
|
+
}).map(repoRelativePath);
|
|
215
|
+
if (selected.length !== 1) {
|
|
216
|
+
throw new Error("grade localize requires exactly one selected --path");
|
|
217
|
+
}
|
|
218
|
+
const resultPath = gradeResultPathForDocument({
|
|
219
|
+
documentPath: selected[0],
|
|
220
|
+
project: options.project,
|
|
221
|
+
});
|
|
222
|
+
const result = readGradeResult(resultPath);
|
|
223
|
+
if (!result)
|
|
224
|
+
throw new Error(`${selected[0]}: grade result not found`);
|
|
225
|
+
if (result.target !== target) {
|
|
226
|
+
throw new Error(`${selected[0]}: grade result target=${result.target}, expected=${target}`);
|
|
227
|
+
}
|
|
228
|
+
let translations;
|
|
229
|
+
try {
|
|
230
|
+
translations = JSON.parse(extractJsonArrayText(readFileSync(resolveSafeRepositoryPath(options.from, "--from"), "utf8")));
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
translations = undefined;
|
|
234
|
+
process.stderr.write(`warning: could not parse grade finding translations: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
235
|
+
}
|
|
236
|
+
const localized = applyGradeFindingTranslations(result, translations, options.translationIndex);
|
|
237
|
+
if (!localized.accepted) {
|
|
238
|
+
process.stderr.write(`warning: rejected grade finding translations: ${localized.reason ?? "invalid output"}\n`);
|
|
239
|
+
}
|
|
240
|
+
const rejectionsPath = resolveSafeRepositoryPath(options.rejectionsOut, "--rejections-out");
|
|
241
|
+
mkdirSync(dirname(rejectionsPath), { recursive: true });
|
|
242
|
+
writeFileSync(rejectionsPath, `${JSON.stringify({ version: 1, rejections: localized.rejections }, null, 2)}\n`, "utf8");
|
|
243
|
+
const changed = writeGradeResult(resultPath, localized.result);
|
|
244
|
+
process.stdout.write(`${changed ? "updated" : "unchanged"}: ${repoRelativePath(resultPath)}\n`);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
commandError(error);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { addGradeSelectionOptions as addSelection, commandError, collectPathOption, requirePipelineStatus, requirePositiveInteger, requireTarget, } from "./grade-command-shared.js";
|
|
2
|
+
import { discoverGradeTargets } from "./grade-target-discovery.js";
|
|
3
|
+
import { listExhaustedGradePipelineStates, readGradePipelineState, recordGradePipelineStage, } from "./grade-pipeline-state.js";
|
|
4
|
+
import { migrateInlineGrades, validateGradeResultForDocument } from "./grade-markdown.js";
|
|
5
|
+
import { readGradeResultForDocument } from "./grade-result.js";
|
|
6
|
+
import { repoRelativePath, resolveSafeMarkdownPath } from "./grade-targets.js";
|
|
7
|
+
export function registerGradeInspectionCommands(grade) {
|
|
8
|
+
addSelection(grade.command("validate").description("Validate stored grade hashes and finding counts")).action((options) => {
|
|
9
|
+
try {
|
|
10
|
+
const target = requireTarget(options.target);
|
|
11
|
+
const paths = discoverGradeTargets({
|
|
12
|
+
target,
|
|
13
|
+
project: options.project,
|
|
14
|
+
paths: options.path,
|
|
15
|
+
changedOnly: options.changedOnly,
|
|
16
|
+
dependencyChanged: options.dependencyChanged,
|
|
17
|
+
rulebookChanged: options.rulebookChanged,
|
|
18
|
+
unreviewed: options.unreviewed,
|
|
19
|
+
verdict: options.verdict,
|
|
20
|
+
minScore: options.minScore,
|
|
21
|
+
maxFindings: options.maxFindings,
|
|
22
|
+
ungraded: options.ungraded,
|
|
23
|
+
incomplete: options.incomplete,
|
|
24
|
+
rubricOutdated: options.rubricOutdated,
|
|
25
|
+
});
|
|
26
|
+
const errors = paths.flatMap((path) => validateGradeResultForDocument({ path, target, project: options.project }));
|
|
27
|
+
for (const error of errors)
|
|
28
|
+
process.stderr.write(`ERROR: ${error}\n`);
|
|
29
|
+
process.stdout.write(`Validated: ${paths.length} document(s), ${errors.length} error(s)\n`);
|
|
30
|
+
if (errors.length > 0)
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
commandError(error);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
grade
|
|
38
|
+
.command("result")
|
|
39
|
+
.description("Print the stored grade result sidecar for one document as JSON")
|
|
40
|
+
.requiredOption("--path <path>", "Markdown document whose grade result is read")
|
|
41
|
+
.option("--project <projectId>", "Project id in specdojo.config.json")
|
|
42
|
+
.action((options) => {
|
|
43
|
+
try {
|
|
44
|
+
const absolute = resolveSafeMarkdownPath(options.path);
|
|
45
|
+
const rel = repoRelativePath(absolute);
|
|
46
|
+
const result = readGradeResultForDocument({ documentPath: rel, project: options.project });
|
|
47
|
+
if (result)
|
|
48
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
commandError(error);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
grade
|
|
55
|
+
.command("state")
|
|
56
|
+
.description("Read or update persistent per-document grade pipeline state")
|
|
57
|
+
.requiredOption("--target <target>", "kata or deliverable")
|
|
58
|
+
.option("--project <projectId>", "Project id in specdojo.config.json")
|
|
59
|
+
.option("--path <path>", "Markdown document whose pipeline state is read or updated")
|
|
60
|
+
.option("--status <status>", "Record passed, failed, or complete", requirePipelineStatus)
|
|
61
|
+
.option("--stage <number>", "Current pipeline stage", requirePositiveInteger)
|
|
62
|
+
.option("--stage-total <number>", "Total pipeline stages", requirePositiveInteger, 3)
|
|
63
|
+
.option("--max-failures <number>", "Consecutive failures allowed before reporting only", requirePositiveInteger, 3)
|
|
64
|
+
.option("--run-id <id>", "Job Run id that observed this state")
|
|
65
|
+
.option("--exhausted", "List documents whose consecutive failure limit was reached", false)
|
|
66
|
+
.action((options) => {
|
|
67
|
+
try {
|
|
68
|
+
const target = requireTarget(options.target);
|
|
69
|
+
if (options.exhausted) {
|
|
70
|
+
if (options.path || options.status) {
|
|
71
|
+
throw new Error("--exhausted cannot be combined with --path or --status");
|
|
72
|
+
}
|
|
73
|
+
for (const state of listExhaustedGradePipelineStates({
|
|
74
|
+
target,
|
|
75
|
+
project: options.project,
|
|
76
|
+
})) {
|
|
77
|
+
process.stdout.write(`${state.document}\n`);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!options.path)
|
|
82
|
+
throw new Error("--path is required unless --exhausted is used");
|
|
83
|
+
if (options.status) {
|
|
84
|
+
if (!options.runId)
|
|
85
|
+
throw new Error("--run-id is required with --status");
|
|
86
|
+
if (!options.stage)
|
|
87
|
+
throw new Error("--stage is required with --status");
|
|
88
|
+
const state = recordGradePipelineStage({
|
|
89
|
+
target,
|
|
90
|
+
project: options.project,
|
|
91
|
+
path: options.path,
|
|
92
|
+
runId: options.runId,
|
|
93
|
+
stage: options.stage,
|
|
94
|
+
stageTotal: options.stageTotal,
|
|
95
|
+
maxFailures: options.maxFailures,
|
|
96
|
+
status: options.status,
|
|
97
|
+
});
|
|
98
|
+
if (state)
|
|
99
|
+
process.stdout.write(`${JSON.stringify(state)}\n`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const state = readGradePipelineState({
|
|
103
|
+
target,
|
|
104
|
+
project: options.project,
|
|
105
|
+
path: options.path,
|
|
106
|
+
});
|
|
107
|
+
if (state)
|
|
108
|
+
process.stdout.write(`${JSON.stringify(state)}\n`);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
commandError(error);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
grade
|
|
115
|
+
.command("migrate")
|
|
116
|
+
.description("Move legacy inline grade snapshots and findings to result sidecars")
|
|
117
|
+
.option("--target <target>", "Restrict migration to kata or deliverable", requireTarget)
|
|
118
|
+
.option("--project <projectId>", "Project id in specdojo.config.json")
|
|
119
|
+
.option("--path <path>", "Migrate only this Markdown document (repeatable)", collectPathOption, [])
|
|
120
|
+
.option("--dry-run", "List updates without writing", false)
|
|
121
|
+
.action((options) => {
|
|
122
|
+
try {
|
|
123
|
+
const changed = migrateInlineGrades({
|
|
124
|
+
project: options.project,
|
|
125
|
+
target: options.target,
|
|
126
|
+
paths: options.path,
|
|
127
|
+
dryRun: options.dryRun,
|
|
128
|
+
});
|
|
129
|
+
for (const path of changed) {
|
|
130
|
+
process.stdout.write(`${options.dryRun ? "would update" : "updated"}: ${path}\n`);
|
|
131
|
+
}
|
|
132
|
+
process.stdout.write(`Migrated updates: ${changed.length}\n`);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
commandError(error);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { discoverGradeTargets } from "./grade-target-discovery.js";
|
|
3
|
+
import { writeGradePlans } from "./grade-plan.js";
|
|
4
|
+
import { loadViewpoints, repoRelativePath, resolveDeliverableDoneCriteria, resolveProject, } from "./grade-targets.js";
|
|
5
|
+
import { getProjectExecutionPath } from "./specdojo-config.js";
|
|
6
|
+
import { addGradeSelectionOptions as addSelection, commandError, requireTarget, } from "./grade-command-shared.js";
|
|
7
|
+
export function registerGradePlanCommands(grade) {
|
|
8
|
+
addSelection(grade.command("list").description("Print selected document paths without writing grade plans")).action((options) => {
|
|
9
|
+
try {
|
|
10
|
+
const paths = discoverGradeTargets({
|
|
11
|
+
target: requireTarget(options.target),
|
|
12
|
+
project: options.project,
|
|
13
|
+
paths: options.path,
|
|
14
|
+
changedOnly: options.changedOnly,
|
|
15
|
+
dependencyChanged: options.dependencyChanged,
|
|
16
|
+
rulebookChanged: options.rulebookChanged,
|
|
17
|
+
unreviewed: options.unreviewed,
|
|
18
|
+
verdict: options.verdict,
|
|
19
|
+
minScore: options.minScore,
|
|
20
|
+
maxFindings: options.maxFindings,
|
|
21
|
+
ungraded: options.ungraded,
|
|
22
|
+
incomplete: options.incomplete,
|
|
23
|
+
rubricOutdated: options.rubricOutdated,
|
|
24
|
+
});
|
|
25
|
+
for (const path of paths)
|
|
26
|
+
process.stdout.write(`${repoRelativePath(path)}\n`);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
commandError(error);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
addSelection(grade
|
|
33
|
+
.command("plan")
|
|
34
|
+
.description("Write reusable executor and reporter plans per selected document"))
|
|
35
|
+
.option("--out <directory>", "Write plans below this repository-relative directory")
|
|
36
|
+
.option("--reference <path>", "Use this document as the comparison reference")
|
|
37
|
+
.option("--embed-documents", "Embed the target and reference documents in the executor plan", false)
|
|
38
|
+
.option("--random-reference", "Select a comparison reference at random from ready documents", false)
|
|
39
|
+
.action((options) => {
|
|
40
|
+
try {
|
|
41
|
+
const target = requireTarget(options.target);
|
|
42
|
+
const viewpoints = loadViewpoints(options.project);
|
|
43
|
+
const { id: projectId, project } = resolveProject(options.project);
|
|
44
|
+
const paths = discoverGradeTargets({
|
|
45
|
+
target,
|
|
46
|
+
project: options.project,
|
|
47
|
+
paths: options.path,
|
|
48
|
+
changedOnly: options.changedOnly,
|
|
49
|
+
dependencyChanged: options.dependencyChanged,
|
|
50
|
+
rulebookChanged: options.rulebookChanged,
|
|
51
|
+
unreviewed: options.unreviewed,
|
|
52
|
+
verdict: options.verdict,
|
|
53
|
+
minScore: options.minScore,
|
|
54
|
+
maxFindings: options.maxFindings,
|
|
55
|
+
ungraded: options.ungraded,
|
|
56
|
+
incomplete: options.incomplete,
|
|
57
|
+
rubricOutdated: options.rubricOutdated,
|
|
58
|
+
});
|
|
59
|
+
if (options.reference && options.randomReference) {
|
|
60
|
+
throw new Error("--reference and --random-reference cannot be combined");
|
|
61
|
+
}
|
|
62
|
+
// 比較リファレンスは既定で付けない。効果が未実証であり、付けると executor の
|
|
63
|
+
// 読み込み対象が増えるためである。利用する場合は明示的に指定する。
|
|
64
|
+
const referenceExampleCandidates = options.randomReference
|
|
65
|
+
? discoverGradeTargets({ target, project: options.project, changedOnly: false })
|
|
66
|
+
: [];
|
|
67
|
+
const outputDirectory = options.out ??
|
|
68
|
+
join(getProjectExecutionPath(project), "grade", "generated", "plans", target);
|
|
69
|
+
const plans = writeGradePlans({
|
|
70
|
+
target,
|
|
71
|
+
paths,
|
|
72
|
+
referenceExampleCandidates,
|
|
73
|
+
referenceExampleOverride: options.reference,
|
|
74
|
+
viewpoints,
|
|
75
|
+
projectId,
|
|
76
|
+
outputDirectory,
|
|
77
|
+
embedDocuments: options.embedDocuments,
|
|
78
|
+
doneCriteriaByPath: target === "deliverable"
|
|
79
|
+
? resolveDeliverableDoneCriteria(paths, options.project)
|
|
80
|
+
: undefined,
|
|
81
|
+
});
|
|
82
|
+
for (const plan of plans) {
|
|
83
|
+
// 無作為選定を求めたのに同種別の ready が無い場合は、種別を跨いで代用せず
|
|
84
|
+
// リファレンスなしで続行する。種別が違うと記載水準の基準として誤りを招く。
|
|
85
|
+
// 気づかないまま基準なしで評価し続けることを避けるため警告する。
|
|
86
|
+
if (options.randomReference && !plan.referenceExample) {
|
|
87
|
+
process.stderr.write(`warning: no ready reference of the same kind for ${plan.target}; grading without a reference\n`);
|
|
88
|
+
}
|
|
89
|
+
if (options.embedDocuments && !plan.documentsEmbedded) {
|
|
90
|
+
process.stderr.write(`warning: embedded documents for ${plan.target} would use ${plan.embeddingCharacterCount} characters and exceed the ${plan.embeddingCharacterLimit} character limit; falling back to path references\n`);
|
|
91
|
+
}
|
|
92
|
+
process.stdout.write(`${plan.changed ? "written" : "unchanged"}: ${plan.path}\n`);
|
|
93
|
+
process.stdout.write(`${plan.reporterChanged ? "written" : "unchanged"}: ${plan.reporterPath}\n`);
|
|
94
|
+
}
|
|
95
|
+
process.stdout.write(`Planned: ${plans.length} document(s)\n`);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
commandError(error);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export function collectPathOption(value, previous) {
|
|
2
|
+
return [...previous, value];
|
|
3
|
+
}
|
|
4
|
+
export function requireTarget(value) {
|
|
5
|
+
if (value !== "kata" && value !== "deliverable")
|
|
6
|
+
throw new Error("--target must be kata or deliverable");
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
export function requireGradeVerdict(value) {
|
|
10
|
+
if (value !== "pass" && value !== "needs-work" && value !== "fail") {
|
|
11
|
+
throw new Error("--verdict must be pass, needs-work, or fail");
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
export function requireMaxFindings(value) {
|
|
16
|
+
const parsed = Number(value);
|
|
17
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) {
|
|
18
|
+
throw new Error("--max-findings must be a non-negative integer");
|
|
19
|
+
}
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
export function requireMinScore(value) {
|
|
23
|
+
const parsed = Number(value);
|
|
24
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0 || parsed > 100) {
|
|
25
|
+
throw new Error("--min-score must be an integer between 0 and 100");
|
|
26
|
+
}
|
|
27
|
+
return parsed;
|
|
28
|
+
}
|
|
29
|
+
export function requirePositiveInteger(value) {
|
|
30
|
+
const parsed = Number(value);
|
|
31
|
+
if (!Number.isSafeInteger(parsed) || parsed < 1) {
|
|
32
|
+
throw new Error("value must be a positive integer");
|
|
33
|
+
}
|
|
34
|
+
return parsed;
|
|
35
|
+
}
|
|
36
|
+
export function requireNonNegativeInteger(value) {
|
|
37
|
+
const parsed = Number(value);
|
|
38
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) {
|
|
39
|
+
throw new Error("value must be a non-negative integer");
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
|
43
|
+
export function requirePipelineStatus(value) {
|
|
44
|
+
if (value !== "passed" && value !== "failed" && value !== "complete") {
|
|
45
|
+
throw new Error("--status must be passed, failed, or complete");
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
export function commandError(error) {
|
|
50
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
}
|
|
53
|
+
export function addGradeSelectionOptions(command) {
|
|
54
|
+
return command
|
|
55
|
+
.requiredOption("--target <target>", "kata or deliverable")
|
|
56
|
+
.option("--project <projectId>", "Project id in specdojo.config.json")
|
|
57
|
+
.option("--path <path>", "Grade only this Markdown document (repeatable)", collectPathOption, [])
|
|
58
|
+
.option("--changed-only", "Select documents changed since their latest grade", false)
|
|
59
|
+
.option("--dependency-changed", "Select documents whose dependencies have been graded more recently", false)
|
|
60
|
+
.option("--rulebook-changed", "Select documents whose declared rulebook has been graded more recently", false)
|
|
61
|
+
.option("--unreviewed", "Select ungraded or changed documents that do not have a schedule task", false)
|
|
62
|
+
.option("--verdict <verdict>", "Select documents with this latest verdict: pass, needs-work, or fail", requireGradeVerdict)
|
|
63
|
+
.option("--min-score <score>", "Select graded documents with at least this score (0-100)", requireMinScore)
|
|
64
|
+
.option("--max-findings <count>", "Select graded documents with at most this many findings", requireMaxFindings)
|
|
65
|
+
.option("--ungraded", "Select documents without a stored grade", false)
|
|
66
|
+
.option("--incomplete", "Select documents with a retryable incomplete pipeline", false)
|
|
67
|
+
.option("--rubric-outdated", "Select graded documents whose stored result was not graded with the current rubric", false);
|
|
68
|
+
}
|