specdojo 0.2.1 → 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/.github/agents/specdojo-orchestrator.md +165 -0
- package/CHANGELOG.md +298 -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/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 +31 -444
- package/dist/deliverable-trash.js +3 -3
- package/dist/devcontainer-command.js +43 -0
- package/dist/devcontainer-scaffold.js +165 -0
- package/dist/doc-index.js +3 -3
- 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-commands.js +557 -0
- package/dist/exec-core.js +457 -0
- 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-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 -1016
- 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-git.js +23 -0
- package/dist/exec-repo-integration-sync.js +264 -0
- package/dist/exec-repo-integration.js +534 -0
- package/dist/exec-repo-trace.js +182 -0
- package/dist/exec-reporter-output.js +206 -0
- package/dist/exec-reporter.js +525 -248
- package/dist/exec-results.js +103 -71
- 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-lock.js +110 -107
- 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 -4953
- package/dist/exec-shared.js +9 -2
- package/dist/exec-slot-lock.js +242 -0
- package/dist/exec-task-repos.js +415 -0
- package/dist/exec-trial-commands.js +558 -0
- package/dist/exec-trial-core.js +371 -0
- package/dist/exec-trial.js +2 -895
- package/dist/exec-worktree-command.js +87 -43
- 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 -847
- package/dist/exec-worktree.js +146 -31
- package/dist/exec.js +2 -999
- 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 +133 -5
- package/dist/grade-target-discovery.js +265 -0
- package/dist/grade-targets.js +432 -0
- package/dist/grade.js +14 -2451
- package/dist/init-command.js +443 -0
- package/dist/job-definition.js +670 -0
- package/dist/job.js +64 -578
- package/dist/kata-command.js +2 -2
- package/dist/orchestrator.js +213 -0
- 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-event-merge.js +169 -0
- package/dist/register-events.js +4 -4
- package/dist/register-item.js +13 -7
- 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 +175 -1975
- package/dist/review-grade.js +252 -0
- package/dist/review-plan.js +114 -4
- package/dist/review-types.js +40 -1
- package/dist/routine-definition.js +401 -0
- package/dist/routine.js +73 -402
- package/dist/schedule-approach.js +2 -2
- package/dist/schedule-build.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 +19 -6
- package/dist/specdojo-config.js +465 -20
- package/dist/specdojo-gitignore.js +135 -0
- package/dist/specdojo.js +6 -0
- package/dist/viewpoint-document-kinds-check.js +128 -0
- package/dist/yaml-pages.js +4 -4
- package/dist/yaml.js +28 -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 +93 -49
- 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 +45 -22
- 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 +75 -10
- 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 +17 -12
- package/templates/antigravity/README.md +29 -4
- package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
- package/templates/antigravity/exec-defaults-snippet.yaml +10 -7
- 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 +74 -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/grade-result.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
-
import
|
|
4
|
+
import { dump, load } from "./yaml.js";
|
|
5
5
|
import { getProjectExecutionPath, loadConfig, specdojoRootDir } from "./specdojo-config.js";
|
|
6
6
|
import { resolveSpecdojoPath } from "./template-resolution.js";
|
|
7
7
|
const GRADE_RESULT_SCHEMA = "docs/specdojo/schemas/v1/grade-result.schema.yaml";
|
|
@@ -17,7 +17,7 @@ export function markdownDocumentId(content, path) {
|
|
|
17
17
|
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
18
18
|
if (!match)
|
|
19
19
|
throw new Error(`${path}: Markdown frontmatter is required`);
|
|
20
|
-
const parsed =
|
|
20
|
+
const parsed = load(match[1]);
|
|
21
21
|
const specdojo = isRecord(parsed) && isRecord(parsed.specdojo) ? parsed.specdojo : undefined;
|
|
22
22
|
const id = specdojo?.id;
|
|
23
23
|
if (typeof id !== "string" || !DOCUMENT_ID_RE.test(id)) {
|
|
@@ -53,7 +53,7 @@ export function gradeResultPathForDocument(opts) {
|
|
|
53
53
|
return gradeResultPath(resolveGradeResultsDirectory(opts.project, rootDir), markdownDocumentId(content, opts.documentPath));
|
|
54
54
|
}
|
|
55
55
|
export function parseGradeResult(content, path) {
|
|
56
|
-
const parsed =
|
|
56
|
+
const parsed = load(content);
|
|
57
57
|
if (!isRecord(parsed))
|
|
58
58
|
throw new Error(`${path}: grade result must be a mapping`);
|
|
59
59
|
const result = parsed;
|
|
@@ -73,6 +73,11 @@ export function parseGradeResult(content, path) {
|
|
|
73
73
|
!Array.isArray(result.findings)) {
|
|
74
74
|
throw new Error(`${path}: invalid grade result`);
|
|
75
75
|
}
|
|
76
|
+
if (result.source_hashes !== undefined &&
|
|
77
|
+
(!isRecord(result.source_hashes) ||
|
|
78
|
+
Object.values(result.source_hashes).some((hash) => typeof hash !== "string" || !/^[a-f0-9]{64}$/.test(hash)))) {
|
|
79
|
+
throw new Error(`${path}: source_hashes must map sources to SHA-256 hex digests`);
|
|
80
|
+
}
|
|
76
81
|
return result;
|
|
77
82
|
}
|
|
78
83
|
export function readGradeResult(path) {
|
|
@@ -87,10 +92,10 @@ export function renderGradeResult(result, path) {
|
|
|
87
92
|
const schemaRef = relative(dirname(path), resolveSpecdojoPath(GRADE_RESULT_SCHEMA))
|
|
88
93
|
.split(sep)
|
|
89
94
|
.join("/");
|
|
90
|
-
return `# yaml-language-server: $schema=${schemaRef}\n${
|
|
95
|
+
return `# yaml-language-server: $schema=${schemaRef}\n${dump(result, {
|
|
91
96
|
lineWidth: 120,
|
|
92
97
|
noRefs: true,
|
|
93
|
-
|
|
98
|
+
quoteStyle: "double",
|
|
94
99
|
})}`;
|
|
95
100
|
}
|
|
96
101
|
export function writeGradeResult(path, result, dryRun = false) {
|
|
@@ -106,6 +111,129 @@ export function writeGradeResult(path, result, dryRun = false) {
|
|
|
106
111
|
export function gradeFindingCount(result) {
|
|
107
112
|
return SEVERITIES.reduce((sum, severity) => sum + result.finding_counts[severity], 0);
|
|
108
113
|
}
|
|
114
|
+
export function gradeFindingDisplayMessage(finding) {
|
|
115
|
+
return finding.message_ja?.trim() || finding.message;
|
|
116
|
+
}
|
|
117
|
+
function isJapaneseFindingMessage(message) {
|
|
118
|
+
// 英語の finding は対象文書の日本語を inline code で引用できるため、その引用は
|
|
119
|
+
// 言語判定から外す。引用以外に仮名がある文、または漢字だけの短文を日本語と扱う。
|
|
120
|
+
const prose = message.replace(/`[^`]*`/gu, "");
|
|
121
|
+
if (/[\p{Script=Hiragana}\p{Script=Katakana}]/u.test(prose))
|
|
122
|
+
return true;
|
|
123
|
+
return /\p{Script=Han}/u.test(prose) && !/[A-Za-z]/u.test(prose);
|
|
124
|
+
}
|
|
125
|
+
function translatableGradeFindings(result) {
|
|
126
|
+
return result.findings
|
|
127
|
+
.map((finding, findingIndex) => ({ finding, findingIndex }))
|
|
128
|
+
.filter(({ finding }) => !isJapaneseFindingMessage(finding.message));
|
|
129
|
+
}
|
|
130
|
+
function selectTranslationTargets(result, translationIndex) {
|
|
131
|
+
const targets = translatableGradeFindings(result).map((target, index) => ({
|
|
132
|
+
...target,
|
|
133
|
+
translationIndex: index,
|
|
134
|
+
}));
|
|
135
|
+
if (translationIndex === undefined)
|
|
136
|
+
return targets;
|
|
137
|
+
const selected = targets[translationIndex];
|
|
138
|
+
if (!selected) {
|
|
139
|
+
throw new Error(`translation index out of range: index=${translationIndex}, count=${targets.length}`);
|
|
140
|
+
}
|
|
141
|
+
return [selected];
|
|
142
|
+
}
|
|
143
|
+
export function gradeFindingTranslationInput(result, translationIndex) {
|
|
144
|
+
return selectTranslationTargets(result, translationIndex).map(({ finding }) => finding.message);
|
|
145
|
+
}
|
|
146
|
+
export function applyGradeFindingTranslations(result, translations, translationIndex) {
|
|
147
|
+
const targets = selectTranslationTargets(result, translationIndex);
|
|
148
|
+
const targetFindingIndexes = new Set(targets.map(({ findingIndex }) => findingIndex));
|
|
149
|
+
const localizedFindings = result.findings.map((finding, findingIndex) => {
|
|
150
|
+
if (translationIndex === undefined || targetFindingIndexes.has(findingIndex)) {
|
|
151
|
+
return { ...finding, message_ja: finding.message };
|
|
152
|
+
}
|
|
153
|
+
return { ...finding };
|
|
154
|
+
});
|
|
155
|
+
const fallback = () => ({ ...result, findings: localizedFindings });
|
|
156
|
+
const rejectAll = (reason, detail) => targets.map(({ finding, translationIndex: index }) => ({
|
|
157
|
+
translation_index: index,
|
|
158
|
+
finding_id: finding.id,
|
|
159
|
+
reason,
|
|
160
|
+
...(detail ? { detail } : {}),
|
|
161
|
+
}));
|
|
162
|
+
if (!Array.isArray(translations)) {
|
|
163
|
+
return {
|
|
164
|
+
result: fallback(),
|
|
165
|
+
accepted: false,
|
|
166
|
+
reason: "translation output must be a string array",
|
|
167
|
+
rejections: rejectAll("invalid-output", "translation output must be a string array"),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (translations.length !== targets.length) {
|
|
171
|
+
const reason = `translation count mismatch: expected=${targets.length}, actual=${translations.length}`;
|
|
172
|
+
return {
|
|
173
|
+
result: fallback(),
|
|
174
|
+
accepted: false,
|
|
175
|
+
reason,
|
|
176
|
+
rejections: rejectAll("count-mismatch", reason),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const rejections = [];
|
|
180
|
+
for (const [arrayIndex, value] of translations.entries()) {
|
|
181
|
+
const target = targets[arrayIndex];
|
|
182
|
+
let reason;
|
|
183
|
+
let detail;
|
|
184
|
+
if (typeof value !== "string") {
|
|
185
|
+
reason = "not-string";
|
|
186
|
+
}
|
|
187
|
+
else if (!value.trim()) {
|
|
188
|
+
reason = "empty";
|
|
189
|
+
}
|
|
190
|
+
else if (!/[\p{Script=Hiragana}\p{Script=Katakana}]/u.test(value)) {
|
|
191
|
+
reason = "missing-kana";
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
const sourceInlineCode = target.finding.message.match(/`[^`\r\n]*`/gu) ?? [];
|
|
195
|
+
const translatedInlineCode = value.match(/`[^`\r\n]*`/gu) ?? [];
|
|
196
|
+
const unmatchedTranslatedInlineCode = [...translatedInlineCode];
|
|
197
|
+
const missingInlineCode = sourceInlineCode.find((code) => {
|
|
198
|
+
const matchedIndex = unmatchedTranslatedInlineCode.indexOf(code);
|
|
199
|
+
if (matchedIndex === -1)
|
|
200
|
+
return true;
|
|
201
|
+
unmatchedTranslatedInlineCode.splice(matchedIndex, 1);
|
|
202
|
+
return false;
|
|
203
|
+
});
|
|
204
|
+
if (missingInlineCode) {
|
|
205
|
+
reason = "missing-inline-code";
|
|
206
|
+
detail = missingInlineCode;
|
|
207
|
+
}
|
|
208
|
+
else if (unmatchedTranslatedInlineCode.length > 0) {
|
|
209
|
+
reason = "extra-inline-code";
|
|
210
|
+
detail = unmatchedTranslatedInlineCode[0];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (reason) {
|
|
214
|
+
rejections.push({
|
|
215
|
+
translation_index: target.translationIndex,
|
|
216
|
+
finding_id: target.finding.id,
|
|
217
|
+
reason,
|
|
218
|
+
...(detail ? { detail } : {}),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
localizedFindings[target.findingIndex] = {
|
|
223
|
+
...localizedFindings[target.findingIndex],
|
|
224
|
+
message_ja: value.trim(),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
accepted: rejections.length === 0,
|
|
230
|
+
...(rejections.length > 0
|
|
231
|
+
? { reason: `rejected ${rejections.length} of ${targets.length} translations` }
|
|
232
|
+
: {}),
|
|
233
|
+
rejections,
|
|
234
|
+
result: { ...result, findings: localizedFindings },
|
|
235
|
+
};
|
|
236
|
+
}
|
|
109
237
|
export function validateGradeResult(result, documentContent, documentPath, expectedTarget) {
|
|
110
238
|
const errors = [];
|
|
111
239
|
let documentId;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { buildScheduleIndex } from "./exec-schedule-index.js";
|
|
4
|
+
import { listFilesRecursive } from "./exec-shared.js";
|
|
5
|
+
import { gradeContentHash, gradeFindingCount, readGradeResultForDocument } from "./grade-result.js";
|
|
6
|
+
import { KATA_DIRS, isRecord, legacyInlineContentHash, parseMarkdown, } from "./grade-core.js";
|
|
7
|
+
import { currentGradePipelineState, isIncompleteGradePipelineState, loadGradePipelineStates, } from "./grade-pipeline-state.js";
|
|
8
|
+
import { comparisonSourceKeys, createGradeSourceContext, currentSourceHashes, dependencySourceKeys, gradedComparisonSources, isGeneratedGradeTarget, isTrashedGradeTarget, loadDeliverableCatalog, loadViewpointsIfConfigured, relativePathFromRoot, resolveProject, resolveSafeMarkdownPath, sourceHashesChanged, } from "./grade-targets.js";
|
|
9
|
+
import { getProjectExecutionPath, specdojoRootDir } from "./specdojo-config.js";
|
|
10
|
+
export function discoverGradeTargets(opts, rootDir = specdojoRootDir()) {
|
|
11
|
+
validateGradeTargetFilters(opts);
|
|
12
|
+
let candidates;
|
|
13
|
+
if (opts.paths && opts.paths.length > 0) {
|
|
14
|
+
candidates = opts.paths.map((path) => resolveSafeMarkdownPath(path, rootDir));
|
|
15
|
+
const generated = candidates.find((path) => isGeneratedGradeTarget(path, rootDir));
|
|
16
|
+
if (generated) {
|
|
17
|
+
throw new Error(`${relativePathFromRoot(generated, rootDir)}: generated documents cannot be graded`);
|
|
18
|
+
}
|
|
19
|
+
const trashed = candidates.find((path) => isTrashedGradeTarget(path, rootDir));
|
|
20
|
+
if (trashed) {
|
|
21
|
+
throw new Error(`${relativePathFromRoot(trashed, rootDir)}: trashed documents cannot be graded`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else if (opts.target === "kata") {
|
|
25
|
+
// 対象の列挙は利用リポジトリ限定。eject されていない kata は評価対象にしない。
|
|
26
|
+
candidates = KATA_DIRS.flatMap((dir) => listFilesRecursive(join(rootDir, "docs/ja/specdojo", dir)).filter((entry) => entry.endsWith(".md")));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
candidates = [...loadDeliverableCatalog(opts.project, rootDir).keys()];
|
|
30
|
+
}
|
|
31
|
+
const unique = [...new Set(candidates)]
|
|
32
|
+
.filter((path) => !isGeneratedGradeTarget(path, rootDir))
|
|
33
|
+
.filter((path) => !isTrashedGradeTarget(path, rootDir))
|
|
34
|
+
.sort();
|
|
35
|
+
if (!opts.changedOnly &&
|
|
36
|
+
!opts.dependencyChanged &&
|
|
37
|
+
!opts.rulebookChanged &&
|
|
38
|
+
!opts.unreviewed &&
|
|
39
|
+
opts.verdict === undefined &&
|
|
40
|
+
opts.minScore === undefined &&
|
|
41
|
+
opts.maxFindings === undefined &&
|
|
42
|
+
!opts.ungraded &&
|
|
43
|
+
!opts.incomplete &&
|
|
44
|
+
!opts.rubricOutdated) {
|
|
45
|
+
return unique;
|
|
46
|
+
}
|
|
47
|
+
const pipelineStates = opts.incomplete
|
|
48
|
+
? loadGradePipelineStates(opts.project, rootDir)
|
|
49
|
+
: new Map();
|
|
50
|
+
const sourceContext = createGradeSourceContext(opts.project, rootDir);
|
|
51
|
+
const viewpoints = opts.changedOnly || opts.rubricOutdated
|
|
52
|
+
? loadViewpointsIfConfigured(opts.project, rootDir)
|
|
53
|
+
: undefined;
|
|
54
|
+
const currentRubricId = opts.rubricOutdated ? currentGradeRubricId(viewpoints) : undefined;
|
|
55
|
+
let scheduledDocuments;
|
|
56
|
+
if (opts.unreviewed) {
|
|
57
|
+
const { project } = resolveProject(opts.project);
|
|
58
|
+
const schedulePath = join(rootDir, getProjectExecutionPath(project), "../schedule");
|
|
59
|
+
try {
|
|
60
|
+
const index = buildScheduleIndex(schedulePath);
|
|
61
|
+
scheduledDocuments = new Set();
|
|
62
|
+
for (const node of index.nodes.values()) {
|
|
63
|
+
if (node.local_id)
|
|
64
|
+
scheduledDocuments.add(node.local_id);
|
|
65
|
+
if (node.target_local_ids) {
|
|
66
|
+
for (const tid of node.target_local_ids)
|
|
67
|
+
scheduledDocuments.add(tid);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
scheduledDocuments = new Set();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const gradeDates = new Map();
|
|
76
|
+
function getMemoizedGradeDate(p) {
|
|
77
|
+
if (!gradeDates.has(p)) {
|
|
78
|
+
const res = readGradeResultForDocument({
|
|
79
|
+
documentPath: relativePathFromRoot(p, rootDir),
|
|
80
|
+
project: opts.project,
|
|
81
|
+
rootDir,
|
|
82
|
+
});
|
|
83
|
+
gradeDates.set(p, res ? new Date(res.graded_at).getTime() : 0);
|
|
84
|
+
}
|
|
85
|
+
return gradeDates.get(p);
|
|
86
|
+
}
|
|
87
|
+
function getRulebookPath(rulebookId) {
|
|
88
|
+
if (rulebookId.startsWith("specdojo:")) {
|
|
89
|
+
const id = rulebookId.slice("specdojo:".length);
|
|
90
|
+
return join(rootDir, "docs/ja/specdojo/rulebooks", `${id}.md`);
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
return unique.filter((path) => {
|
|
95
|
+
const rel = relativePathFromRoot(path, rootDir);
|
|
96
|
+
const content = readFileSync(path, "utf8");
|
|
97
|
+
const document = parseMarkdown(content, rel);
|
|
98
|
+
const pipelineState = currentGradePipelineState(document, rel, pipelineStates.get(rel), opts.target);
|
|
99
|
+
const result = readGradeResultForDocument({
|
|
100
|
+
documentPath: rel,
|
|
101
|
+
project: opts.project,
|
|
102
|
+
rootDir,
|
|
103
|
+
});
|
|
104
|
+
if (opts.verdict !== undefined && (result === undefined || result.verdict !== opts.verdict)) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (opts.minScore !== undefined && (result === undefined || result.score < opts.minScore)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (opts.maxFindings !== undefined &&
|
|
111
|
+
(result === undefined || gradeFindingCount(result) > opts.maxFindings)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
if (opts.unreviewed) {
|
|
115
|
+
if (!scheduledDocuments)
|
|
116
|
+
return false;
|
|
117
|
+
const id = document.data.specdojo?.id;
|
|
118
|
+
if (!id || scheduledDocuments.has(id.split(":").pop()))
|
|
119
|
+
return false;
|
|
120
|
+
if (result !== undefined && result.content_hash === gradeContentHash(content))
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (opts.incomplete && pipelineState) {
|
|
124
|
+
if (!isIncompleteGradePipelineState(pipelineState))
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
else if (opts.incomplete) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (opts.ungraded && result !== undefined)
|
|
131
|
+
return false;
|
|
132
|
+
if (currentRubricId !== undefined && !isGradeRubricOutdated(result, currentRubricId)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (result === undefined) {
|
|
136
|
+
if (opts.dependencyChanged || opts.rulebookChanged)
|
|
137
|
+
return false;
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
const docDate = new Date(result.graded_at).getTime();
|
|
141
|
+
if (opts.rulebookChanged) {
|
|
142
|
+
const rb = document.data.specdojo?.rulebook;
|
|
143
|
+
if (!rb)
|
|
144
|
+
return false;
|
|
145
|
+
const rbPath = getRulebookPath(rb);
|
|
146
|
+
if (!rbPath || !existsSync(rbPath))
|
|
147
|
+
return false;
|
|
148
|
+
if (getMemoizedGradeDate(rbPath) <= docDate)
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
// 依存先の評価日時ではなく内容の hash で判定する。再評価しただけの依存先は変更扱いにしない。
|
|
152
|
+
if (opts.dependencyChanged) {
|
|
153
|
+
if (opts.target !== "deliverable")
|
|
154
|
+
return false;
|
|
155
|
+
const keys = dependencySourceKeys(path, sourceContext);
|
|
156
|
+
if (keys.length === 0)
|
|
157
|
+
return false;
|
|
158
|
+
const current = currentSourceHashes(keys, path, sourceContext);
|
|
159
|
+
if (!sourceHashesChanged(result.source_hashes, current))
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
if (opts.changedOnly && result.content_hash === gradeContentHash(content)) {
|
|
163
|
+
const metadata = isRecord(document.data.specdojo) ? document.data.specdojo : {};
|
|
164
|
+
const keys = comparisonSourceKeys(gradedComparisonSources(viewpoints, opts.target, metadata), path, sourceContext);
|
|
165
|
+
if (keys.length === 0)
|
|
166
|
+
return false;
|
|
167
|
+
const current = currentSourceHashes(keys, path, sourceContext);
|
|
168
|
+
if (!sourceHashesChanged(result.source_hashes, current))
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function currentGradeRubricId(viewpoints) {
|
|
175
|
+
const id = viewpoints?.grade_rubric?.id;
|
|
176
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
177
|
+
throw new Error("--rubric-outdated requires grade_rubric.id in the resolved review viewpoints");
|
|
178
|
+
}
|
|
179
|
+
return id;
|
|
180
|
+
}
|
|
181
|
+
// 保存済みの結果が現在の rubric 以外で付けられたかを判定する。rubric の記録がない結果は
|
|
182
|
+
// どの版で付けたか確かめられないため旧版として扱う。結果がない文書は --ungraded の対象である。
|
|
183
|
+
export function isGradeRubricOutdated(result, currentRubricId) {
|
|
184
|
+
if (result === undefined)
|
|
185
|
+
return false;
|
|
186
|
+
if (typeof result.rubric !== "string" || result.rubric.length === 0)
|
|
187
|
+
return true;
|
|
188
|
+
return result.rubric !== currentRubricId;
|
|
189
|
+
}
|
|
190
|
+
function validateGradeTargetFilters(filters) {
|
|
191
|
+
if (filters.verdict !== undefined &&
|
|
192
|
+
filters.verdict !== "pass" &&
|
|
193
|
+
filters.verdict !== "needs-work" &&
|
|
194
|
+
filters.verdict !== "fail") {
|
|
195
|
+
throw new Error("--verdict must be pass, needs-work, or fail");
|
|
196
|
+
}
|
|
197
|
+
if (filters.minScore !== undefined &&
|
|
198
|
+
(!Number.isSafeInteger(filters.minScore) || filters.minScore < 0 || filters.minScore > 100)) {
|
|
199
|
+
throw new Error("--min-score must be an integer between 0 and 100");
|
|
200
|
+
}
|
|
201
|
+
if (filters.maxFindings !== undefined &&
|
|
202
|
+
(!Number.isSafeInteger(filters.maxFindings) || filters.maxFindings < 0)) {
|
|
203
|
+
throw new Error("--max-findings must be a non-negative integer");
|
|
204
|
+
}
|
|
205
|
+
if (filters.ungraded &&
|
|
206
|
+
(filters.verdict !== undefined ||
|
|
207
|
+
filters.minScore !== undefined ||
|
|
208
|
+
filters.maxFindings !== undefined)) {
|
|
209
|
+
throw new Error("--ungraded cannot be combined with --verdict, --min-score, or --max-findings");
|
|
210
|
+
}
|
|
211
|
+
if (filters.ungraded && filters.rubricOutdated) {
|
|
212
|
+
throw new Error("--ungraded cannot be combined with --rubric-outdated");
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function storedGradeScore(grade, path) {
|
|
216
|
+
const score = grade.score;
|
|
217
|
+
if (!Number.isSafeInteger(score) || score < 0 || score > 100) {
|
|
218
|
+
throw new Error(`${path}: specdojo.grade.score must be an integer between 0 and 100`);
|
|
219
|
+
}
|
|
220
|
+
return score;
|
|
221
|
+
}
|
|
222
|
+
function storedFindingCount(grade, path) {
|
|
223
|
+
const findings = grade.findings;
|
|
224
|
+
if (!isRecord(findings))
|
|
225
|
+
throw new Error(`${path}: specdojo.grade.findings is missing`);
|
|
226
|
+
return ["blocker", "major", "minor", "note"].reduce((total, severity) => {
|
|
227
|
+
const count = findings[severity];
|
|
228
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
229
|
+
throw new Error(`${path}: specdojo.grade.findings.${severity} must be a non-negative integer`);
|
|
230
|
+
}
|
|
231
|
+
return total + count;
|
|
232
|
+
}, 0);
|
|
233
|
+
}
|
|
234
|
+
function matchesParsedGradeTargetFilters(document, path, filters, incomplete = false) {
|
|
235
|
+
if (filters.dependencyChanged ||
|
|
236
|
+
filters.rulebookChanged ||
|
|
237
|
+
filters.unreviewed ||
|
|
238
|
+
filters.rubricOutdated) {
|
|
239
|
+
throw new Error("dependencyChanged, rulebookChanged, unreviewed, rubricOutdated cannot be evaluated individually without context");
|
|
240
|
+
}
|
|
241
|
+
const specdojo = document.data.specdojo;
|
|
242
|
+
const grade = isRecord(specdojo.grade) ? specdojo.grade : undefined;
|
|
243
|
+
if (filters.incomplete && !incomplete)
|
|
244
|
+
return false;
|
|
245
|
+
if (filters.ungraded && grade !== undefined)
|
|
246
|
+
return false;
|
|
247
|
+
if (filters.verdict !== undefined && grade?.verdict !== filters.verdict)
|
|
248
|
+
return false;
|
|
249
|
+
if (filters.minScore !== undefined &&
|
|
250
|
+
(grade === undefined || storedGradeScore(grade, path) < filters.minScore)) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
if (filters.maxFindings !== undefined &&
|
|
254
|
+
(grade === undefined || storedFindingCount(grade, path) > filters.maxFindings)) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
return !filters.changedOnly || grade?.content_hash !== legacyInlineContentHash(document);
|
|
258
|
+
}
|
|
259
|
+
export function matchesGradeTargetFilters(content, path, filters, pipelineState) {
|
|
260
|
+
validateGradeTargetFilters(filters);
|
|
261
|
+
const document = parseMarkdown(content, path);
|
|
262
|
+
const currentState = currentGradePipelineState(document, path, pipelineState);
|
|
263
|
+
return matchesParsedGradeTargetFilters(document, path, filters, isIncompleteGradePipelineState(currentState));
|
|
264
|
+
}
|
|
265
|
+
// grade の対象は grade_targets と文書の種類(document_kinds)だけで決まる。
|