specdojo 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/README.md +77 -18
- package/dist/catalog/build-references.js +144 -0
- package/dist/catalog/build-render.js +32 -0
- package/dist/{catalog-build.js → catalog/build.js} +18 -295
- package/dist/{catalog.js → catalog/catalog.js} +11 -11
- package/dist/{catalog-generate.js → catalog/generate.js} +13 -16
- package/dist/catalog/paths.js +1 -0
- package/dist/{catalog-plan-generate.js → catalog/plan-generate.js} +5 -5
- package/dist/{catalog-plan.js → catalog/plan.js} +9 -9
- package/dist/{catalog-scaffold.js → catalog/scaffold.js} +6 -6
- package/dist/{agent.js → commands/agent.js} +11 -11
- package/dist/{build-command.js → commands/build.js} +2 -2
- package/dist/{init-command.js → commands/init.js} +103 -37
- package/dist/{orchestrator.js → commands/orchestrator.js} +2 -2
- package/dist/{watch.js → commands/watch.js} +3 -3
- package/dist/dashboard/dashboard-timeline.js +175 -0
- package/dist/{dashboard.js → dashboard/dashboard.js} +16 -549
- package/dist/dashboard/exec-records.js +105 -0
- package/dist/dashboard/routines.js +256 -0
- package/dist/dashboard/shared.js +14 -0
- package/dist/{timeline-build.js → dashboard/timeline-build.js} +2 -1
- package/dist/{timeline.js → dashboard/timeline.js} +1 -1
- package/dist/{deliverable.js → deliverable/deliverable.js} +5 -5
- package/dist/{deliverable-trash.js → deliverable/trash.js} +7 -7
- package/dist/{devcontainer-command.js → devcontainer/command.js} +5 -3
- package/dist/{devcontainer-scaffold.js → devcontainer/scaffold.js} +94 -2
- package/dist/{doc-index.js → docs/doc-index.js} +3 -3
- package/dist/{frontmatter-namespace.js → docs/frontmatter-namespace.js} +2 -2
- package/dist/{index-command.js → docs/index-command.js} +1 -1
- package/dist/docs/template-resolution.js +1 -0
- package/dist/{viewpoint-document-kinds-check.js → docs/viewpoint-document-kinds-check.js} +3 -3
- package/dist/{yaml-pages-command.js → docs/yaml-pages-command.js} +1 -1
- package/dist/{yaml-pages.js → docs/yaml-pages.js} +5 -5
- package/dist/{exec-agent-config.js → exec/agent-config.js} +33 -4
- package/dist/{exec-agent-git-state.js → exec/agent-git-state.js} +1 -1
- package/dist/{exec-agent-protected-config.js → exec/agent-protected-config.js} +1 -1
- package/dist/{exec.js → exec/commands.js} +22 -467
- package/dist/exec/core.js +457 -0
- package/dist/{exec-events.js → exec/events.js} +2 -2
- package/dist/{exec-evidence.js → exec/evidence.js} +11 -6
- package/dist/exec/exec.js +2 -0
- package/dist/exec/format.js +1 -0
- package/dist/{exec-handoff.js → exec/handoff.js} +13 -12
- package/dist/{exec-limit.js → exec/limit.js} +93 -12
- package/dist/{exec-parent-validation.js → exec/parent-validation.js} +4 -4
- package/dist/{exec-pipeline-state.js → exec/pipeline-state.js} +16 -2
- package/dist/{exec-plans.js → exec/plans-core.js} +97 -468
- package/dist/exec/plans-generation.js +249 -0
- package/dist/exec/plans-storage.js +131 -0
- package/dist/exec/plans.js +3 -0
- package/dist/{exec-project.js → exec/project.js} +1 -1
- package/dist/{exec-protection-handoff.js → exec/protection-handoff.js} +3 -3
- package/dist/{exec-register-resume.js → exec/register-resume.js} +2 -2
- package/dist/{exec-register.js → exec/register.js} +92 -9
- package/dist/exec/repo-integration-git.js +23 -0
- package/dist/exec/repo-integration-sync.js +264 -0
- package/dist/{exec-repo-integration.js → exec/repo-integration.js} +13 -287
- package/dist/{exec-repo-trace.js → exec/repo-trace.js} +3 -3
- package/dist/exec/reporter-output.js +206 -0
- package/dist/{exec-reporter.js → exec/reporter.js} +29 -216
- package/dist/{exec-results.js → exec/results.js} +277 -36
- package/dist/exec/run/agent-pipeline.js +276 -0
- package/dist/exec/run/agent.js +583 -0
- package/dist/exec/run/in-place.js +570 -0
- package/dist/exec/run/job.js +746 -0
- package/dist/exec/run/lifecycle-commands.js +530 -0
- package/dist/{exec-run-lock.js → exec/run/lock.js} +4 -3
- package/dist/exec/run/mode-shared.js +140 -0
- package/dist/exec/run/register-command.js +252 -0
- package/dist/exec/run/register-core.js +411 -0
- package/dist/exec/run/register-mode.js +210 -0
- package/dist/exec/run/register-resume.js +398 -0
- package/dist/exec/run/register-state.js +325 -0
- package/dist/exec/run/register-worktree.js +540 -0
- package/dist/exec/run/run.js +11 -0
- package/dist/exec/run/schedule-mode.js +294 -0
- package/dist/exec/run/schedule-prepare.js +366 -0
- package/dist/exec/run/schedule-task.js +599 -0
- package/dist/exec/run/shared.js +449 -0
- package/dist/{exec-schedule-calendar.js → exec/schedule/calendar.js} +1 -1
- package/dist/{exec-schedule-cpm.js → exec/schedule/cpm.js} +2 -2
- package/dist/{exec-schedule-gantt-chart-render.js → exec/schedule/gantt-chart-render.js} +2 -2
- package/dist/exec/schedule/gantt-chart.js +2 -0
- package/dist/{exec-schedule-hash.js → exec/schedule/hash.js} +2 -2
- package/dist/exec/schedule/index.js +1 -0
- package/dist/{exec-schedule-initial.js → exec/schedule/initial.js} +2 -2
- package/dist/{exec-schedule-progress.js → exec/schedule/progress.js} +2 -2
- package/dist/{exec-schedule-ready.js → exec/schedule/ready.js} +2 -2
- package/dist/{exec-schedule.js → exec/schedule/schedule.js} +11 -11
- package/dist/exec/shared.js +63 -0
- package/dist/exec/slot-lock.js +1 -0
- package/dist/{exec-strategy.js → exec/strategy.js} +2 -2
- package/dist/{exec-task-repos.js → exec/task-repos.js} +2 -2
- package/dist/{exec-task-view.js → exec/task-view.js} +4 -4
- package/dist/{exec-trial.js → exec/trial-commands.js} +23 -388
- package/dist/exec/trial-core.js +371 -0
- package/dist/exec/trial.js +2 -0
- package/dist/{exec-worktree-command.js → exec/worktree-command.js} +25 -23
- package/dist/exec/worktree-ops-commit.js +672 -0
- package/dist/exec/worktree-ops-lifecycle.js +297 -0
- package/dist/exec/worktree-ops-merge.js +344 -0
- package/dist/exec/worktree-ops.js +3 -0
- package/dist/exec/worktree.js +305 -0
- 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/grade.js +19 -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 → grade/result.js} +7 -96
- package/dist/grade/target-discovery.js +265 -0
- package/dist/grade/targets.js +435 -0
- package/dist/{job.js → job/definition.js} +32 -574
- package/dist/job/job.js +568 -0
- package/dist/{kata-command.js → kata/command.js} +4 -4
- package/dist/{kata.js → kata/kata.js} +5 -5
- package/dist/register/approach.js +134 -0
- package/dist/register/command-types.js +1 -0
- package/dist/register/core.js +369 -0
- package/dist/register/create-commands.js +352 -0
- package/dist/{register-date.js → register/date.js} +1 -1
- package/dist/register/derivation.js +163 -0
- package/dist/{register-event-merge.js → register/event-merge.js} +32 -3
- package/dist/{register-events.js → register/events.js} +12 -6
- package/dist/{register-history.js → register/history.js} +7 -6
- package/dist/{register-item.js → register/item.js} +28 -10
- package/dist/register/lifecycle-lock.js +5 -0
- package/dist/register/maintenance-commands.js +193 -0
- package/dist/{register-migrate-timestamps.js → register/migrate-timestamps.js} +3 -3
- package/dist/register/migration.js +268 -0
- package/dist/register/register.js +404 -0
- package/dist/register/renumber.js +341 -0
- package/dist/register/transition-commands.js +248 -0
- package/dist/register/update.js +230 -0
- package/dist/register/views.js +296 -0
- package/dist/{review-grade.js → review/grade.js} +2 -2
- package/dist/{review-plan.js → review/plan.js} +5 -5
- package/dist/routine/definition.js +401 -0
- package/dist/{routine.js → routine/routine.js} +50 -419
- package/dist/{schedule-approach.js → schedule/approach.js} +9 -9
- package/dist/{schedule-build.js → schedule/build.js} +7 -4
- package/dist/{schedule.js → schedule/schedule.js} +9 -9
- package/dist/schedule/strategy-generate-document.js +273 -0
- package/dist/schedule/strategy-generate-scope.js +199 -0
- package/dist/schedule/strategy-generate.js +348 -0
- package/dist/shared/agent-types.js +23 -0
- package/dist/shared/artifact-path.js +9 -0
- package/dist/{build-if-stale.js → shared/build-if-stale.js} +1 -1
- package/dist/shared/catalog-render.js +115 -0
- package/dist/{exec-slot-lock.js → shared/cross-process-lock.js} +3 -1
- package/dist/shared/fs.js +30 -0
- package/dist/shared/git.js +316 -0
- package/dist/shared/grade-result.js +94 -0
- package/dist/{package-paths.js → shared/package-paths.js} +3 -3
- package/dist/shared/plan-templates.js +114 -0
- package/dist/{exec-provider-scaffold.js → shared/provider-scaffold.js} +3 -1
- package/dist/shared/random.js +4 -0
- package/dist/{exec-schedule-index.js → shared/schedule-index.js} +3 -1
- package/dist/shared/schedule-paths.js +9 -0
- package/dist/{specdojo-config.js → shared/specdojo-config.js} +96 -9
- package/dist/{exec-shared.js → shared/text.js} +0 -134
- package/dist/shared/time.js +28 -0
- package/dist/shared/yaml.js +28 -0
- package/dist/specdojo.js +22 -22
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +29 -17
- package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xep-register-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xer-template.md +1 -3
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +6 -4
- package/docs/ja/specdojo/guides/exec-config-guide.md +97 -22
- package/docs/ja/specdojo/guides/exec-operation-guide.md +145 -12
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +2 -0
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +51 -18
- package/docs/ja/specdojo/guides/quick-start-guide.md +81 -16
- package/docs/ja/specdojo/guides/register-operation-guide.md +2 -1
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +10 -1
- package/docs/ja/specdojo/guides/review-guide.md +1 -1
- package/docs/ja/specdojo/guides/routine-operation-guide.md +6 -6
- package/docs/ja/specdojo/guides/use-case-guide.md +1 -1
- package/docs/ja/specdojo/references/command-reference.md +52 -28
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +17 -11
- package/docs/ja/specdojo/standards/job-definition-standard.md +20 -18
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +2 -2
- package/docs/ja/specdojo/templates/pjr-derived-items-template.md +22 -0
- package/docs/ja/specdojo/templates/pjr-index-template.md +1 -0
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +29 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +20 -0
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +23 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +2 -2
- package/docs/specdojo/schemas/v1/job.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +26 -0
- package/docs/specdojo/schemas/v1/register-events.schema.yaml +3 -0
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +70 -7
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +1 -1
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +1 -1
- package/package.json +4 -5
- package/templates/antigravity/README.md +7 -3
- package/templates/antigravity/agent-members-snippet.yaml +108 -12
- package/templates/antigravity/exec-defaults-snippet.yaml +10 -13
- package/templates/claude/README.md +27 -3
- package/templates/claude/agents/claude-executor.md +0 -1
- package/templates/claude/agents/claude-reporter.md +2 -1
- package/templates/claude/agents/claude-review-executor.md +0 -1
- package/templates/codex/README.md +23 -4
- package/templates/devcontainer/devcontainer.json +2 -2
- package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +69 -0
- package/templates/devcontainer/remote-host/ssh-config.sample +16 -0
- package/templates/init-agent-members.yaml +75 -25
- package/templates/init-exec-defaults.yaml +26 -8
- package/templates/opencode/README.md +17 -3
- package/templates/opencode/agents/opencode-executor.md +0 -1
- package/templates/opencode/agents/opencode-reporter.md +2 -1
- package/templates/opencode/agents/opencode-review-executor.md +0 -1
- package/dist/exec-run.js +0 -6182
- package/dist/exec-schedule-gantt-chart.js +0 -2
- package/dist/exec-worktree-ops.js +0 -1292
- package/dist/exec-worktree.js +0 -446
- package/dist/grade.js +0 -3193
- package/dist/register.js +0 -2407
- package/dist/schedule-strategy-generate.js +0 -812
- package/templates/claude/agents/claude-expert-review-executor.md +0 -14
- /package/dist/{catalog-plan-prompt.js → catalog/plan-prompt.js} +0 -0
- /package/dist/{catalog-types.js → catalog/types.js} +0 -0
- /package/dist/{template-frontmatter.js → docs/template-frontmatter.js} +0 -0
- /package/dist/{role-types.js → exec/role-types.js} +0 -0
- /package/dist/{exec-schedule-gantt-chart-scope.js → exec/schedule/gantt-chart-scope.js} +0 -0
- /package/dist/{exec-types.js → exec/types.js} +0 -0
- /package/dist/{review-types.js → review/types.js} +0 -0
- /package/dist/{schedule-phase-sets.js → schedule/phase-sets.js} +0 -0
- /package/dist/{schedule-strategy-profiles.js → schedule/strategy-profiles.js} +0 -0
- /package/dist/{agent-response.js → shared/agent-response.js} +0 -0
- /package/dist/{catalog-paths.js → shared/catalog-paths.js} +0 -0
- /package/dist/{dist-freshness.js → shared/dist-freshness.js} +0 -0
- /package/dist/{git-environment.js → shared/git-environment.js} +0 -0
- /package/dist/{exec-format.js → shared/markdown-format.js} +0 -0
- /package/dist/{practice-id.js → shared/practice-id.js} +0 -0
- /package/dist/{spawn-self.js → shared/spawn-self.js} +0 -0
- /package/dist/{specdojo-gitignore.js → shared/specdojo-gitignore.js} +0 -0
- /package/dist/{template-resolution.js → shared/template-resolution.js} +0 -0
- /package/dist/{yaml-schema-modeline.js → shared/yaml-schema-modeline.js} +0 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { basename, extname, join } from "node:path";
|
|
4
|
+
import { dump } from "../shared/yaml.js";
|
|
5
|
+
import { GRADE_PLAN_EMBEDDED_DOCUMENT_CHARACTER_LIMIT, agentViewpoints, gradedViewpoints, levelCapForFindings, parseMarkdown, } from "./core.js";
|
|
6
|
+
import { gradeResultPath, readGradeResult, readGradeResultForDocument } from "./result.js";
|
|
7
|
+
import { assertRubric, loadKataReferences, parseGradeReferenceExample, repoRelativePath, resolveGradeReferencePathsFromCatalog, resolveSafeMarkdownPath, resolveSafeRepositoryPath, selectGradeReferenceExampleFromCatalog, } from "./targets.js";
|
|
8
|
+
import { viewpointAppliesToDocument } from "../review/plan.js";
|
|
9
|
+
export function deterministicResults(document, definitions, target) {
|
|
10
|
+
const results = [];
|
|
11
|
+
const metadata = document.data.specdojo;
|
|
12
|
+
for (const viewpoint of gradedViewpoints(definitions, target, metadata).filter((item) => item.evaluation === "deterministic")) {
|
|
13
|
+
const findings = [];
|
|
14
|
+
const specdojo = document.data.specdojo;
|
|
15
|
+
if (viewpoint.id === "vp-arc-document-structure") {
|
|
16
|
+
for (const key of ["id", "type", "status"]) {
|
|
17
|
+
if (typeof specdojo[key] !== "string" || !String(specdojo[key]).trim()) {
|
|
18
|
+
findings.push({
|
|
19
|
+
severity: "major",
|
|
20
|
+
message: `Frontmatter の specdojo.${key} が未設定です。`,
|
|
21
|
+
line: 1,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!/^#\s+\S/m.test(document.body)) {
|
|
26
|
+
findings.push({ severity: "major", message: "本文に H1 見出しがありません。", line: 1 });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (viewpoint.id === "vp-qe-config-validity") {
|
|
30
|
+
const placeholderLine = document.body
|
|
31
|
+
.split("\n")
|
|
32
|
+
.findIndex((line) => /(?:_TODO_|_ASSUMPTION_)/.test(line));
|
|
33
|
+
if (placeholderLine >= 0) {
|
|
34
|
+
findings.push({
|
|
35
|
+
severity: "major",
|
|
36
|
+
message: "未解決の _TODO_ / _ASSUMPTION_ が残っています。",
|
|
37
|
+
line: placeholderLine + 1,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const cap = levelCapForFindings(findings);
|
|
42
|
+
results.push({ id: viewpoint.id, level: cap, findings });
|
|
43
|
+
}
|
|
44
|
+
return results;
|
|
45
|
+
}
|
|
46
|
+
function doneCriteriaPlanLines(doneCriteria, definitions) {
|
|
47
|
+
const titles = new Map((definitions.viewpoints ?? []).map((viewpoint) => [viewpoint.id, viewpoint.title]));
|
|
48
|
+
return [
|
|
49
|
+
"### 3.4. 完了条件(done_criteria)",
|
|
50
|
+
"",
|
|
51
|
+
"成果物カタログが対象へ宣言する完了条件である。viewpoint と rubric による level 判定とは別の軸として、各条件を現在の本文の根拠だけで `satisfied` / `unsatisfied` のどちらかに判定する。score や level の高低から充足を推論せず、条件文が要求する内容を本文で確認できるかだけで判定する。`roles` は条件の確認責任を持つ Role code、`viewpoint` は条件を見る観点であり、`evaluation: discretionary` の観点に紐づく条件も本文の根拠で一次判定する。",
|
|
52
|
+
"",
|
|
53
|
+
...doneCriteria.map((criterion) => {
|
|
54
|
+
const title = titles.get(criterion.viewpoint);
|
|
55
|
+
const viewpoint = title ? `${criterion.viewpoint}(${title})` : criterion.viewpoint;
|
|
56
|
+
return `- ${criterion.id} [roles=${criterion.roles.join(",")}; viewpoint=${viewpoint}]: ${criterion.text}`;
|
|
57
|
+
}),
|
|
58
|
+
"",
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
export function applicableDoneCriteria(doneCriteria, definitions, metadata) {
|
|
62
|
+
const viewpoints = new Map((definitions.viewpoints ?? []).map((viewpoint) => [viewpoint.id, viewpoint]));
|
|
63
|
+
return doneCriteria.filter((criterion) => {
|
|
64
|
+
const viewpoint = viewpoints.get(criterion.viewpoint);
|
|
65
|
+
return viewpoint === undefined || viewpointAppliesToDocument(viewpoint, metadata);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function markdownFence(content) {
|
|
69
|
+
let longestRun = 0;
|
|
70
|
+
for (const match of content.matchAll(/`+/g))
|
|
71
|
+
longestRun = Math.max(longestRun, match[0].length);
|
|
72
|
+
return "`".repeat(Math.max(3, longestRun + 1));
|
|
73
|
+
}
|
|
74
|
+
function splitDocumentForEmbedding(content) {
|
|
75
|
+
const normalized = content.replace(/\r\n?/g, "\n");
|
|
76
|
+
const match = normalized.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
77
|
+
if (!match)
|
|
78
|
+
return { body: normalized.replace(/\n$/, "") };
|
|
79
|
+
return {
|
|
80
|
+
frontmatter: match[1],
|
|
81
|
+
body: (match[2] ?? "").replace(/^\n+/, "").replace(/\n$/, ""),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function renderEmbeddedGradeDocument(path, roles) {
|
|
85
|
+
const content = readFileSync(resolveSafeRepositoryPath(path, "embedded document"), "utf8");
|
|
86
|
+
const { frontmatter, body } = splitDocumentForEmbedding(content);
|
|
87
|
+
const bodyLines = body === "" ? [] : body.split("\n");
|
|
88
|
+
const numberedBody = bodyLines.map((line, index) => `${index + 1} | ${line}`).join("\n");
|
|
89
|
+
const lines = [
|
|
90
|
+
`#### ${roles.join("・")}: \`${path}\``,
|
|
91
|
+
"",
|
|
92
|
+
"Frontmatter(`finding.line` の行番号対象外):",
|
|
93
|
+
"",
|
|
94
|
+
];
|
|
95
|
+
if (frontmatter === undefined) {
|
|
96
|
+
lines.push("- なし", "");
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const fence = markdownFence(frontmatter);
|
|
100
|
+
lines.push(`${fence}yaml`, frontmatter, fence, "");
|
|
101
|
+
}
|
|
102
|
+
const bodyFence = markdownFence(numberedBody);
|
|
103
|
+
lines.push("本文(左端は `finding.line` と同じ、Frontmatter を除く1始まりの行番号):", "", `${bodyFence}text`, numberedBody, bodyFence, "");
|
|
104
|
+
return lines;
|
|
105
|
+
}
|
|
106
|
+
function gradePlanEmbedding(opts) {
|
|
107
|
+
if (!Number.isSafeInteger(opts.limit) || opts.limit < 1) {
|
|
108
|
+
throw new Error("maxEmbeddedDocumentCharacters must be a positive integer");
|
|
109
|
+
}
|
|
110
|
+
if (!opts.requested) {
|
|
111
|
+
return { requested: false, embedded: false, characterCount: 0, limit: opts.limit, lines: [] };
|
|
112
|
+
}
|
|
113
|
+
const rolesByPath = new Map();
|
|
114
|
+
const add = (path, role) => {
|
|
115
|
+
const roles = rolesByPath.get(path);
|
|
116
|
+
if (roles) {
|
|
117
|
+
if (!roles.includes(role))
|
|
118
|
+
roles.push(role);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
rolesByPath.set(path, [role]);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
add(opts.targetPath, "評価対象");
|
|
125
|
+
for (const reference of opts.references)
|
|
126
|
+
add(reference, "参考資料");
|
|
127
|
+
if (opts.referenceExample)
|
|
128
|
+
add(opts.referenceExample, "良い実例");
|
|
129
|
+
const lines = [...rolesByPath].flatMap(([path, roles]) => renderEmbeddedGradeDocument(path, roles));
|
|
130
|
+
const characterCount = lines.join("\n").length;
|
|
131
|
+
return {
|
|
132
|
+
requested: true,
|
|
133
|
+
embedded: characterCount <= opts.limit,
|
|
134
|
+
characterCount,
|
|
135
|
+
limit: opts.limit,
|
|
136
|
+
lines: characterCount <= opts.limit ? lines : [],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function renderGradePlanWithEmbedding(opts) {
|
|
140
|
+
const rubric = assertRubric(opts.viewpoints);
|
|
141
|
+
const absolute = resolveSafeMarkdownPath(opts.path);
|
|
142
|
+
const rel = repoRelativePath(absolute);
|
|
143
|
+
const document = parseMarkdown(readFileSync(absolute, "utf8"), rel);
|
|
144
|
+
const metadata = document.data.specdojo;
|
|
145
|
+
const viewpoints = agentViewpoints(opts.viewpoints, opts.target, metadata);
|
|
146
|
+
const documentId = typeof metadata.id === "string" ? metadata.id : rel;
|
|
147
|
+
const priorFindings = (opts.resultsDirectory
|
|
148
|
+
? readGradeResult(gradeResultPath(opts.resultsDirectory, documentId))
|
|
149
|
+
: readGradeResultForDocument({ documentPath: rel, project: opts.projectId }))?.findings ?? [];
|
|
150
|
+
const taskHash = createHash("sha256").update(rel).digest("hex").slice(0, 12).toUpperCase();
|
|
151
|
+
const taskId = `GRADE-${opts.target.toUpperCase()}-${taskHash}`;
|
|
152
|
+
const references = (opts.references ?? []).map((reference) => repoRelativePath(resolveSafeRepositoryPath(reference, "reference")));
|
|
153
|
+
const referenceExample = opts.referenceExample
|
|
154
|
+
? repoRelativePath(resolveSafeMarkdownPath(opts.referenceExample))
|
|
155
|
+
: undefined;
|
|
156
|
+
const embedding = gradePlanEmbedding({
|
|
157
|
+
requested: opts.embedDocuments ?? false,
|
|
158
|
+
targetPath: rel,
|
|
159
|
+
references,
|
|
160
|
+
referenceExample,
|
|
161
|
+
limit: opts.maxEmbeddedDocumentCharacters ?? GRADE_PLAN_EMBEDDED_DOCUMENT_CHARACTER_LIMIT,
|
|
162
|
+
});
|
|
163
|
+
const doneCriteria = opts.target === "deliverable"
|
|
164
|
+
? applicableDoneCriteria(opts.doneCriteria ?? [], opts.viewpoints, metadata)
|
|
165
|
+
: [];
|
|
166
|
+
const lines = [
|
|
167
|
+
"---",
|
|
168
|
+
dump({
|
|
169
|
+
specdojo: {
|
|
170
|
+
id: `${opts.projectId}:grade-${opts.target}-${taskHash.toLowerCase()}-plan`,
|
|
171
|
+
type: "exec-plan",
|
|
172
|
+
rulebook: "none",
|
|
173
|
+
task_id: taskId,
|
|
174
|
+
name: `grade: ${rel}`,
|
|
175
|
+
mode: "review",
|
|
176
|
+
status: "ready",
|
|
177
|
+
project_id: opts.projectId,
|
|
178
|
+
targets: [documentId],
|
|
179
|
+
},
|
|
180
|
+
}, { lineWidth: 120, noRefs: true }).trimEnd(),
|
|
181
|
+
"---",
|
|
182
|
+
"",
|
|
183
|
+
`# Review Plan: ${taskId} grade: ${rel}`,
|
|
184
|
+
"",
|
|
185
|
+
"この plan は grade pipeline の executor stage 用である。評価と根拠の記述だけを行い、GradeSubmission JSON は作成しない。`grade apply` が最終応答の marker を機械的に解析して GradeSubmission を生成し、契約を満たさない応答は拒否して executor を再実行する。",
|
|
186
|
+
"",
|
|
187
|
+
"## 1. このタスクで行うこと",
|
|
188
|
+
"",
|
|
189
|
+
`評価対象 \`${rel}\` を共通 viewpoint と category rubric で 0-4 判定する。deterministic viewpoint は CLI が判定するため、agent の出力には含めない。`,
|
|
190
|
+
"",
|
|
191
|
+
"## 2. 対象項目",
|
|
192
|
+
"",
|
|
193
|
+
`- \`target\`: ${opts.target}`,
|
|
194
|
+
`- \`rubric\`: ${rubric.id}`,
|
|
195
|
+
`- \`document_id\`: ${documentId}`,
|
|
196
|
+
`- \`評価対象\`: \`${rel}\``,
|
|
197
|
+
"",
|
|
198
|
+
"### 参考資料",
|
|
199
|
+
"",
|
|
200
|
+
"参考資料は評価対象ではなく、成果物間整合を判定するための材料である。参考資料自体を評価しない。",
|
|
201
|
+
"",
|
|
202
|
+
...(references.length > 0 ? references.map((reference) => `- \`${reference}\``) : ["- なし"]),
|
|
203
|
+
"",
|
|
204
|
+
// 比較リファレンスは任意である。指定がない場合は節ごと省略する。空の節を残すと
|
|
205
|
+
// 候補が存在しないのか指定していないのかを読み手が区別できない。
|
|
206
|
+
...(referenceExample
|
|
207
|
+
? [
|
|
208
|
+
"### 良い実例(比較リファレンス)",
|
|
209
|
+
"",
|
|
210
|
+
"`status: ready` の文書から選んだ比較材料である。記載水準を具体化するために使い、評価対象へ含めず、内容を正解として機械的に模倣しない。`ready` は品質保証ではないため、実例自体の問題を評価対象へ転用しない。",
|
|
211
|
+
"",
|
|
212
|
+
`- \`${referenceExample}\``,
|
|
213
|
+
"",
|
|
214
|
+
]
|
|
215
|
+
: []),
|
|
216
|
+
...(embedding.embedded
|
|
217
|
+
? [
|
|
218
|
+
"### 埋め込み資料",
|
|
219
|
+
"",
|
|
220
|
+
`評価対象・参考資料・良い実例を plan 生成時点の内容で埋め込む。埋め込み部分は ${embedding.characterCount.toLocaleString("en-US")} 文字(上限 ${embedding.limit.toLocaleString("en-US")} 文字)である。`,
|
|
221
|
+
"",
|
|
222
|
+
...embedding.lines,
|
|
223
|
+
]
|
|
224
|
+
: embedding.requested
|
|
225
|
+
? [
|
|
226
|
+
"### 埋め込み資料",
|
|
227
|
+
"",
|
|
228
|
+
`警告: 埋め込み部分が ${embedding.characterCount.toLocaleString("en-US")} 文字となり、上限 ${embedding.limit.toLocaleString("en-US")} 文字を超えたため、本文を埋め込まずパス参照へフォールバックした。`,
|
|
229
|
+
"",
|
|
230
|
+
]
|
|
231
|
+
: []),
|
|
232
|
+
"## 3. 進め方",
|
|
233
|
+
"",
|
|
234
|
+
...(embedding.embedded
|
|
235
|
+
? [
|
|
236
|
+
"1. plan の「埋め込み資料」にある評価対象の本文を全文読む。Frontmatter は行番号の対象外であり、本文左端の番号を finding の `line` に使う。",
|
|
237
|
+
"2. 埋め込まれた参考資料と良い実例がある場合はすべて読む。ファイル読み取りツールと検索ツールを使わず、plan に埋め込まれた資料だけで判定し、参考資料や良い実例を評価対象と混同しない。",
|
|
238
|
+
]
|
|
239
|
+
: [
|
|
240
|
+
"1. 評価対象をファイル読み取りツールで全文読み、実行ログに読み取り操作を残す。plan に対象本文は埋め込まれていないため、この手順を省略しない。",
|
|
241
|
+
"2. 参考資料と良い実例がある場合は列挙された全ファイルを全文読み、実行ログに各パスの読み取り操作を残す。参考資料や良い実例を評価対象と混同しない。",
|
|
242
|
+
]),
|
|
243
|
+
"3. 良い実例がある場合は、章ごとの具体性、根拠の密度、過不足を評価対象と比較して記載水準を判定する。表現の類似や実例自体の欠点を評価理由にせず、rubric と viewpoint を最終的な判定基準にする。",
|
|
244
|
+
"4. 評価対象を次の rubric と viewpoint に照らし、各 viewpoint を 0-4 で判定する。ある viewpoint の finding の有無から、ほかの viewpoint の判定を推論しない。",
|
|
245
|
+
"5. 判定根拠と新しい finding の message は英語で記述する。固有名詞・識別子・引用は原文を保ってよい。日本語だけの既存 finding は互換用の正本として扱い、未解消ならその message を翻訳せず原文のまま再掲する。",
|
|
246
|
+
"6. level 3 以下には finding を付ける。finding には severity(blocker / major / minor / note)、対象直前の本文行番号、具体的な修正理由を含める。line は Frontmatter を除く本文の1始まり(通常は H1 が1行目)とする。level 4 は finding なしとする。",
|
|
247
|
+
"7. 前回の指摘を対象の現在内容と照合し、解消済みか確認する。未解消なら前回の canonical message を変更せず今回の finding に含め、severity は前回と同等以上を指定する。前回の rule は前回評価時の分類として扱い、各 viewpoint は現在の根拠から独立に評価する。前回の問題が解消され、別の軽微な問題だけが残るため severity を引き下げる場合は、その根拠を新しい finding の message に含める。",
|
|
248
|
+
"8. 前回の指摘の確認だけで終了せず、前回の指摘にない問題もすべての viewpoint で独立して検出する。",
|
|
249
|
+
...(doneCriteria.length > 0
|
|
250
|
+
? [
|
|
251
|
+
"9. 完了条件(done_criteria)を1件ずつ本文の根拠と照合し、`satisfied` / `unsatisfied` を判定する。viewpoint の level や総合 score とは独立した判定であり、level が高いことを理由に条件を満たしたとみなさない。`unsatisfied` には不足している内容を英語で1行に記す。",
|
|
252
|
+
]
|
|
253
|
+
: []),
|
|
254
|
+
"",
|
|
255
|
+
"### 3.1. 前回の指摘",
|
|
256
|
+
"",
|
|
257
|
+
"grade result サイドカーに記録された前回の finding を示す。対象本文には評価コメントを書き込まない。",
|
|
258
|
+
"",
|
|
259
|
+
// 前回の id は今回の採番と混同させないため渡さない。事実(severity / rule / 位置 / message)だけを示す。
|
|
260
|
+
...(priorFindings.length > 0
|
|
261
|
+
? [
|
|
262
|
+
"```json",
|
|
263
|
+
JSON.stringify(priorFindings.map(({ severity, rule, line, anchor, message }) => ({
|
|
264
|
+
severity,
|
|
265
|
+
rule,
|
|
266
|
+
line,
|
|
267
|
+
anchor,
|
|
268
|
+
message,
|
|
269
|
+
})), null, 2),
|
|
270
|
+
"```",
|
|
271
|
+
]
|
|
272
|
+
: ["- なし"]),
|
|
273
|
+
"",
|
|
274
|
+
"### 3.2. Rubric",
|
|
275
|
+
"",
|
|
276
|
+
...rubric.levels.map((level) => `- ${level.level} (${level.name}, review=${level.review_verdict}): ${level.description}`),
|
|
277
|
+
"",
|
|
278
|
+
"### 3.3. Viewpoints",
|
|
279
|
+
"",
|
|
280
|
+
...viewpoints.map((viewpoint) => `- ${viewpoint.id} [${viewpoint.category}/${viewpoint.evaluation}]: ${viewpoint.check} Evidence: ${viewpoint.evidence}`),
|
|
281
|
+
"",
|
|
282
|
+
...(doneCriteria.length > 0 ? doneCriteriaPlanLines(doneCriteria, opts.viewpoints) : []),
|
|
283
|
+
"## 4. 完了手順",
|
|
284
|
+
"",
|
|
285
|
+
"1. すべての agent viewpoint の判定と、必要な finding が揃っていることを確認する。",
|
|
286
|
+
"2. 最終応答では各 viewpoint を次のマーカーで1回ずつ宣言する。マーカー間には根拠や検討過程を自由形式で詳しく記述してよい。JSON、Markdown コードフェンス、GradeSubmission は出力しない。",
|
|
287
|
+
"3. `LEVEL` と各 `FINDING` は `grade apply` が機械的に読み取る申告値である。marker・`LEVEL`・`FINDING` はそれぞれ行頭に1行で記し、message は英語で1行に具体的に記す。message は正本としてそのまま記録される。finding がない場合は `FINDING` 行を記さない。",
|
|
288
|
+
"4. すべての viewpoint marker、0-4 の level、level 3 以下の finding、severity と非空 message が揃っていることを確認する。",
|
|
289
|
+
...(doneCriteria.length > 0
|
|
290
|
+
? [
|
|
291
|
+
"5. 完了条件は `[DONE_CRITERIA]` と `[END DONE_CRITERIA]` で囲んだブロックを1回だけ置き、列挙されたすべての条件 ID を1行ずつ `<ID>: satisfied` または `<ID>: unsatisfied: <不足内容>` の形で申告する。列挙にない ID を追加せず、ID を省略しない。",
|
|
292
|
+
]
|
|
293
|
+
: []),
|
|
294
|
+
"",
|
|
295
|
+
"```text",
|
|
296
|
+
...viewpoints.flatMap((viewpoint) => [
|
|
297
|
+
`[VIEWPOINT ${viewpoint.id}]`,
|
|
298
|
+
"LEVEL: <0-4>",
|
|
299
|
+
"根拠を自由形式で記述する。",
|
|
300
|
+
"FINDING <severity> line=<line>: level 3 以下の場合だけ、具体的な修正理由を1行で記述する。",
|
|
301
|
+
"[END VIEWPOINT]",
|
|
302
|
+
"",
|
|
303
|
+
]),
|
|
304
|
+
...(doneCriteria.length > 0
|
|
305
|
+
? [
|
|
306
|
+
"[DONE_CRITERIA]",
|
|
307
|
+
...doneCriteria.map((criterion) => `${criterion.id}: <satisfied|unsatisfied>: 不足内容を1行で記述する。`),
|
|
308
|
+
"[END DONE_CRITERIA]",
|
|
309
|
+
"",
|
|
310
|
+
]
|
|
311
|
+
: []),
|
|
312
|
+
"```",
|
|
313
|
+
"",
|
|
314
|
+
"## 5. 異常終了の条件",
|
|
315
|
+
"",
|
|
316
|
+
...(embedding.embedded
|
|
317
|
+
? [
|
|
318
|
+
"- plan に評価対象、参考資料、または良い実例の埋め込み内容が欠けている場合は、内容を推測せず異常終了する。",
|
|
319
|
+
]
|
|
320
|
+
: ["- 評価対象、参考資料、または良い実例を読み取れない場合は、内容を推測せず異常終了する。"]),
|
|
321
|
+
"- rubric または viewpoint に不足があり、全項目を判定できない場合は異常終了する。",
|
|
322
|
+
"- すべての viewpoint の level と finding を申告できない場合は異常終了する。",
|
|
323
|
+
...(doneCriteria.length > 0
|
|
324
|
+
? ["- 列挙された完了条件のいずれかを判定できない場合は異常終了する。"]
|
|
325
|
+
: []),
|
|
326
|
+
];
|
|
327
|
+
return { content: `${lines.join("\n")}\n`, embedding };
|
|
328
|
+
}
|
|
329
|
+
export function renderGradePlan(opts) {
|
|
330
|
+
return renderGradePlanWithEmbedding(opts).content;
|
|
331
|
+
}
|
|
332
|
+
export function renderGradeReporterPlan(opts) {
|
|
333
|
+
const rubric = assertRubric(opts.viewpoints);
|
|
334
|
+
const absolute = resolveSafeMarkdownPath(opts.path);
|
|
335
|
+
const rel = repoRelativePath(absolute);
|
|
336
|
+
const document = parseMarkdown(readFileSync(absolute, "utf8"), rel);
|
|
337
|
+
const metadata = document.data.specdojo;
|
|
338
|
+
const viewpoints = agentViewpoints(opts.viewpoints, opts.target, metadata);
|
|
339
|
+
const documentId = typeof metadata.id === "string" ? metadata.id : rel;
|
|
340
|
+
const taskHash = createHash("sha256").update(rel).digest("hex").slice(0, 12).toUpperCase();
|
|
341
|
+
const taskId = `GRADE-${opts.target.toUpperCase()}-${taskHash}-REPORTER`;
|
|
342
|
+
const doneCriteria = opts.target === "deliverable"
|
|
343
|
+
? applicableDoneCriteria(opts.doneCriteria ?? [], opts.viewpoints, metadata)
|
|
344
|
+
: [];
|
|
345
|
+
const lines = [
|
|
346
|
+
"---",
|
|
347
|
+
dump({
|
|
348
|
+
specdojo: {
|
|
349
|
+
id: `${opts.projectId}:grade-${opts.target}-${taskHash.toLowerCase()}-reporter-plan`,
|
|
350
|
+
type: "exec-plan",
|
|
351
|
+
rulebook: "none",
|
|
352
|
+
task_id: taskId,
|
|
353
|
+
name: `grade reporter: ${rel}`,
|
|
354
|
+
mode: "review",
|
|
355
|
+
status: "ready",
|
|
356
|
+
project_id: opts.projectId,
|
|
357
|
+
targets: [documentId],
|
|
358
|
+
},
|
|
359
|
+
}, { lineWidth: 120, noRefs: true }).trimEnd(),
|
|
360
|
+
"---",
|
|
361
|
+
"",
|
|
362
|
+
`# Reporter Plan: ${taskId} grade: ${rel}`,
|
|
363
|
+
"",
|
|
364
|
+
"この plan は grade pipeline の reporter stage 用である。既定の pipeline は reporter を起動せず、`grade apply` が executor の marker から GradeSubmission を機械的に生成する。この plan は LLM reporter を明示指定して書き写しの精度を比較・検証する場合にだけ使う。executor の最終応答が `<grade_executor_output>` としてこの plan と一緒に渡される。評価やファイル読み取りは行わず、申告済みの判定を GradeSubmission JSON へ忠実に構造化する。",
|
|
365
|
+
"",
|
|
366
|
+
"## 1. このタスクで行うこと",
|
|
367
|
+
"",
|
|
368
|
+
"executor が申告した全 viewpoint の level と finding を、追加・省略・変更せず GradeSubmission JSON へ写す。",
|
|
369
|
+
"",
|
|
370
|
+
"## 2. 対象項目",
|
|
371
|
+
"",
|
|
372
|
+
`- \`target\`: ${opts.target}`,
|
|
373
|
+
`- \`rubric\`: ${rubric.id}`,
|
|
374
|
+
`- \`document_id\`: ${documentId}`,
|
|
375
|
+
`- \`評価対象\`: \`${rel}\``,
|
|
376
|
+
"",
|
|
377
|
+
"## 3. 進め方",
|
|
378
|
+
"",
|
|
379
|
+
"1. `<grade_executor_output>` の `[VIEWPOINT <id>]` ごとに `LEVEL` とすべての `FINDING` を読み取る。対象文書や参考資料は読まない。",
|
|
380
|
+
"2. level、severity、line、message を executor の申告どおりにコピーする。message の要約、言い換え、校正を行わない。",
|
|
381
|
+
"3. executor が述べていない finding を追加せず、述べた finding を省略しない。finding の `id` は出力しない。",
|
|
382
|
+
"4. finding の severity により viewpoint の level に上限がある(`blocker` は上限 0、`major` は上限 2、`minor` は上限 3)。executor の申告が上限を超えていても level は申告どおりにコピーし、補正は `grade apply` に委ねる。marker 欠落など、それ以外の GradeSubmission 契約違反は推測で補わず異常終了する。",
|
|
383
|
+
...(doneCriteria.length > 0
|
|
384
|
+
? [
|
|
385
|
+
"5. `[DONE_CRITERIA]` ブロックの各行を `done_criteria` へ写す。`id` と `status`(`satisfied` / `unsatisfied`)は申告どおりにコピーし、`unsatisfied` に続く不足内容は `reason` へ一字一句コピーする。条件の追加・省略・判定変更を行わない。",
|
|
386
|
+
]
|
|
387
|
+
: []),
|
|
388
|
+
"",
|
|
389
|
+
"## 4. 完了手順",
|
|
390
|
+
"",
|
|
391
|
+
"1. facts である `rubric` と `path` を次のテンプレートから変更しない。",
|
|
392
|
+
"2. すべての agent viewpoint が1回ずつあり、level と finding が executor の申告と一致することを確認する。",
|
|
393
|
+
...(doneCriteria.length > 0
|
|
394
|
+
? [
|
|
395
|
+
"3. `done_criteria` の各要素が executor の申告した ID と status に一致することを確認する。",
|
|
396
|
+
"4. 正常終了時の最終応答は GradeSubmission JSON オブジェクト1個だけとする。前置き、要約、Markdown コードフェンスを含めない。",
|
|
397
|
+
]
|
|
398
|
+
: [
|
|
399
|
+
"3. 正常終了時の最終応答は GradeSubmission JSON オブジェクト1個だけとする。前置き、要約、Markdown コードフェンスを含めない。",
|
|
400
|
+
]),
|
|
401
|
+
"",
|
|
402
|
+
"```json",
|
|
403
|
+
JSON.stringify({
|
|
404
|
+
rubric: rubric.id,
|
|
405
|
+
documents: [
|
|
406
|
+
{
|
|
407
|
+
path: rel,
|
|
408
|
+
viewpoints: viewpoints.map((viewpoint) => ({
|
|
409
|
+
id: viewpoint.id,
|
|
410
|
+
level: 4,
|
|
411
|
+
findings: [],
|
|
412
|
+
})),
|
|
413
|
+
...(doneCriteria.length > 0
|
|
414
|
+
? {
|
|
415
|
+
done_criteria: doneCriteria.map((criterion) => ({
|
|
416
|
+
id: criterion.id,
|
|
417
|
+
status: "satisfied",
|
|
418
|
+
})),
|
|
419
|
+
}
|
|
420
|
+
: {}),
|
|
421
|
+
},
|
|
422
|
+
],
|
|
423
|
+
}, null, 2),
|
|
424
|
+
"```",
|
|
425
|
+
"",
|
|
426
|
+
"## 5. 異常終了の条件",
|
|
427
|
+
"",
|
|
428
|
+
"- `<grade_executor_output>` が渡されていない、または marker 契約を解析できない場合は異常終了する。",
|
|
429
|
+
"- level の下方向補正を除き、executor の申告を変更しなければ GradeSubmission の契約を満たせない場合は異常終了する。",
|
|
430
|
+
];
|
|
431
|
+
return `${lines.join("\n")}\n`;
|
|
432
|
+
}
|
|
433
|
+
export function gradePlanFilename(path) {
|
|
434
|
+
const rel = repoRelativePath(path);
|
|
435
|
+
const stem = basename(path, extname(path))
|
|
436
|
+
.toLowerCase()
|
|
437
|
+
.replace(/[^a-z0-9-]+/g, "-")
|
|
438
|
+
.replace(/^-+|-+$/g, "");
|
|
439
|
+
const hash = createHash("sha256").update(rel).digest("hex").slice(0, 10);
|
|
440
|
+
return `${stem || "document"}-${hash}-grade-plan.md`;
|
|
441
|
+
}
|
|
442
|
+
function gradeReporterPlanFilename(path) {
|
|
443
|
+
return gradePlanFilename(path).replace(/-grade-plan\.md$/, "-grade-reporter-plan.md");
|
|
444
|
+
}
|
|
445
|
+
export function writeGradePlans(opts) {
|
|
446
|
+
const outputDirectory = resolveSafeRepositoryPath(opts.outputDirectory, "--out");
|
|
447
|
+
if (opts.paths.length === 0)
|
|
448
|
+
return [];
|
|
449
|
+
mkdirSync(outputDirectory, { recursive: true });
|
|
450
|
+
const kataReferences = loadKataReferences();
|
|
451
|
+
const referenceExamples = opts.referenceExampleCandidates.flatMap((candidate) => {
|
|
452
|
+
const parsed = parseGradeReferenceExample(candidate, opts.target);
|
|
453
|
+
return parsed ? [parsed] : [];
|
|
454
|
+
});
|
|
455
|
+
return opts.paths.map((path) => {
|
|
456
|
+
const absolute = resolveSafeMarkdownPath(path);
|
|
457
|
+
const output = join(outputDirectory, gradePlanFilename(absolute));
|
|
458
|
+
const reporterOutput = join(outputDirectory, gradeReporterPlanFilename(absolute));
|
|
459
|
+
const referenceExample = opts.referenceExampleOverride ??
|
|
460
|
+
selectGradeReferenceExampleFromCatalog({
|
|
461
|
+
target: opts.target,
|
|
462
|
+
path: absolute,
|
|
463
|
+
candidates: referenceExamples,
|
|
464
|
+
random: opts.random,
|
|
465
|
+
});
|
|
466
|
+
const doneCriteria = opts.doneCriteriaByPath?.get(repoRelativePath(absolute));
|
|
467
|
+
const rendered = renderGradePlanWithEmbedding({
|
|
468
|
+
target: opts.target,
|
|
469
|
+
path: absolute,
|
|
470
|
+
references: resolveGradeReferencePathsFromCatalog(absolute, kataReferences),
|
|
471
|
+
referenceExample,
|
|
472
|
+
viewpoints: opts.viewpoints,
|
|
473
|
+
projectId: opts.projectId,
|
|
474
|
+
doneCriteria,
|
|
475
|
+
embedDocuments: opts.embedDocuments,
|
|
476
|
+
});
|
|
477
|
+
const content = rendered.content;
|
|
478
|
+
const reporterContent = renderGradeReporterPlan({
|
|
479
|
+
target: opts.target,
|
|
480
|
+
path: absolute,
|
|
481
|
+
viewpoints: opts.viewpoints,
|
|
482
|
+
projectId: opts.projectId,
|
|
483
|
+
doneCriteria,
|
|
484
|
+
});
|
|
485
|
+
const changed = !existsSync(output) || readFileSync(output, "utf8") !== content;
|
|
486
|
+
const reporterChanged = !existsSync(reporterOutput) || readFileSync(reporterOutput, "utf8") !== reporterContent;
|
|
487
|
+
if (changed)
|
|
488
|
+
writeFileSync(output, content, "utf8");
|
|
489
|
+
if (reporterChanged)
|
|
490
|
+
writeFileSync(reporterOutput, reporterContent, "utf8");
|
|
491
|
+
return {
|
|
492
|
+
path: repoRelativePath(output),
|
|
493
|
+
changed,
|
|
494
|
+
reporterPath: repoRelativePath(reporterOutput),
|
|
495
|
+
reporterChanged,
|
|
496
|
+
target: repoRelativePath(absolute),
|
|
497
|
+
referenceExample,
|
|
498
|
+
documentsEmbedded: rendered.embedding.embedded,
|
|
499
|
+
embeddingCharacterCount: rendered.embedding.characterCount,
|
|
500
|
+
embeddingCharacterLimit: rendered.embedding.limit,
|
|
501
|
+
};
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
// executor の最終応答に現れる marker 行の軽微な書式の揺れを正規化する。受理するのは、行頭の
|
|
505
|
+
// 空白、ブロッククオート `>`、リスト記号(`-` / `*` / `+` と空白)、および marker・LEVEL・
|
|
506
|
+
// FINDING・DC-NNN の見出し部分を囲む `**` だけである。message と reason の本文は変更しない。
|
|
507
|
+
// 文中に埋もれた FINDING などは marker とみなさず、従来どおり無視または拒否する。
|
|
@@ -1,101 +1,18 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { dirname,
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { dirname, relative, sep } from "node:path";
|
|
3
|
+
import { dump } from "../shared/yaml.js";
|
|
4
|
+
import { resolveSpecdojoPath } from "../docs/template-resolution.js";
|
|
5
|
+
import { SEVERITIES, gradeContentHash, markdownDocumentId, resolveGradeResultsDirectory, gradeResultFileName, gradeResultPath, gradeResultPathForDocument, parseGradeResult, gradeFindingDisplayMessage, readGradeResult, readGradeResultForDocument, gradeFindingCount, } from "../shared/grade-result.js";
|
|
6
|
+
export { SEVERITIES, gradeContentHash, markdownDocumentId, resolveGradeResultsDirectory, gradeResultFileName, gradeResultPath, gradeResultPathForDocument, parseGradeResult, gradeFindingDisplayMessage, readGradeResult, readGradeResultForDocument, gradeFindingCount, };
|
|
7
7
|
const GRADE_RESULT_SCHEMA = "docs/specdojo/schemas/v1/grade-result.schema.yaml";
|
|
8
|
-
const DOCUMENT_ID_RE = /^[a-z0-9][a-z0-9-:]*$/;
|
|
9
|
-
const SEVERITIES = ["blocker", "major", "minor", "note"];
|
|
10
|
-
function isRecord(value) {
|
|
11
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
-
}
|
|
13
|
-
export function gradeContentHash(content) {
|
|
14
|
-
return createHash("sha256").update(content).digest("hex");
|
|
15
|
-
}
|
|
16
|
-
export function markdownDocumentId(content, path) {
|
|
17
|
-
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
18
|
-
if (!match)
|
|
19
|
-
throw new Error(`${path}: Markdown frontmatter is required`);
|
|
20
|
-
const parsed = yaml.load(match[1]);
|
|
21
|
-
const specdojo = isRecord(parsed) && isRecord(parsed.specdojo) ? parsed.specdojo : undefined;
|
|
22
|
-
const id = specdojo?.id;
|
|
23
|
-
if (typeof id !== "string" || !DOCUMENT_ID_RE.test(id)) {
|
|
24
|
-
throw new Error(`${path}: specdojo.id is required to store a grade result`);
|
|
25
|
-
}
|
|
26
|
-
return id;
|
|
27
|
-
}
|
|
28
|
-
export function resolveGradeResultsDirectory(projectOption, rootDir = specdojoRootDir()) {
|
|
29
|
-
const { config } = loadConfig();
|
|
30
|
-
if (!config)
|
|
31
|
-
throw new Error("grade commands require .specdojo/specdojo.config.json");
|
|
32
|
-
const projectId = projectOption?.trim() || config.current_project || Object.keys(config.projects)[0] || "";
|
|
33
|
-
const project = config.projects[projectId];
|
|
34
|
-
if (!project)
|
|
35
|
-
throw new Error(`Unknown project: ${projectId}`);
|
|
36
|
-
return resolve(rootDir, getProjectExecutionPath(project), "grade", "results");
|
|
37
|
-
}
|
|
38
|
-
// ファイル名では名前空間区切りの ":" を "." に置き換える(Windows で ":" は使えない)。
|
|
39
|
-
// DOCUMENT_ID_RE は "." を許さないため、置換後も元の id と一対一に対応する。
|
|
40
|
-
export function gradeResultFileName(documentId) {
|
|
41
|
-
if (!DOCUMENT_ID_RE.test(documentId)) {
|
|
42
|
-
throw new Error(`Invalid grade result document id: ${documentId}`);
|
|
43
|
-
}
|
|
44
|
-
return `${documentId.replace(/:/g, ".")}.yaml`;
|
|
45
|
-
}
|
|
46
|
-
export function gradeResultPath(resultsDirectory, documentId) {
|
|
47
|
-
return join(resultsDirectory, gradeResultFileName(documentId));
|
|
48
|
-
}
|
|
49
|
-
export function gradeResultPathForDocument(opts) {
|
|
50
|
-
const rootDir = opts.rootDir ?? specdojoRootDir();
|
|
51
|
-
const absolute = resolve(rootDir, opts.documentPath);
|
|
52
|
-
const content = readFileSync(absolute, "utf8");
|
|
53
|
-
return gradeResultPath(resolveGradeResultsDirectory(opts.project, rootDir), markdownDocumentId(content, opts.documentPath));
|
|
54
|
-
}
|
|
55
|
-
export function parseGradeResult(content, path) {
|
|
56
|
-
const parsed = yaml.load(content);
|
|
57
|
-
if (!isRecord(parsed))
|
|
58
|
-
throw new Error(`${path}: grade result must be a mapping`);
|
|
59
|
-
const result = parsed;
|
|
60
|
-
if (result.version !== 1 ||
|
|
61
|
-
typeof result.document !== "string" ||
|
|
62
|
-
typeof result.path !== "string" ||
|
|
63
|
-
(result.target !== "kata" && result.target !== "deliverable") ||
|
|
64
|
-
typeof result.rubric !== "string" ||
|
|
65
|
-
(result.verdict !== "pass" && result.verdict !== "needs-work" && result.verdict !== "fail") ||
|
|
66
|
-
!Number.isSafeInteger(result.score) ||
|
|
67
|
-
typeof result.graded_at !== "string" ||
|
|
68
|
-
typeof result.graded_by !== "string" ||
|
|
69
|
-
typeof result.content_hash !== "string" ||
|
|
70
|
-
!isRecord(result.categories) ||
|
|
71
|
-
!isRecord(result.viewpoints) ||
|
|
72
|
-
!isRecord(result.finding_counts) ||
|
|
73
|
-
!Array.isArray(result.findings)) {
|
|
74
|
-
throw new Error(`${path}: invalid grade result`);
|
|
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
|
-
}
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
export function readGradeResult(path) {
|
|
84
|
-
if (!existsSync(path))
|
|
85
|
-
return undefined;
|
|
86
|
-
return parseGradeResult(readFileSync(path, "utf8"), path);
|
|
87
|
-
}
|
|
88
|
-
export function readGradeResultForDocument(opts) {
|
|
89
|
-
return readGradeResult(gradeResultPathForDocument(opts));
|
|
90
|
-
}
|
|
91
8
|
export function renderGradeResult(result, path) {
|
|
92
9
|
const schemaRef = relative(dirname(path), resolveSpecdojoPath(GRADE_RESULT_SCHEMA))
|
|
93
10
|
.split(sep)
|
|
94
11
|
.join("/");
|
|
95
|
-
return `# yaml-language-server: $schema=${schemaRef}\n${
|
|
12
|
+
return `# yaml-language-server: $schema=${schemaRef}\n${dump(result, {
|
|
96
13
|
lineWidth: 120,
|
|
97
14
|
noRefs: true,
|
|
98
|
-
|
|
15
|
+
quoteStyle: "double",
|
|
99
16
|
})}`;
|
|
100
17
|
}
|
|
101
18
|
export function writeGradeResult(path, result, dryRun = false) {
|
|
@@ -108,12 +25,6 @@ export function writeGradeResult(path, result, dryRun = false) {
|
|
|
108
25
|
}
|
|
109
26
|
return true;
|
|
110
27
|
}
|
|
111
|
-
export function gradeFindingCount(result) {
|
|
112
|
-
return SEVERITIES.reduce((sum, severity) => sum + result.finding_counts[severity], 0);
|
|
113
|
-
}
|
|
114
|
-
export function gradeFindingDisplayMessage(finding) {
|
|
115
|
-
return finding.message_ja?.trim() || finding.message;
|
|
116
|
-
}
|
|
117
28
|
function isJapaneseFindingMessage(message) {
|
|
118
29
|
// 英語の finding は対象文書の日本語を inline code で引用できるため、その引用は
|
|
119
30
|
// 言語判定から外す。引用以外に仮名がある文、または漢字だけの短文を日本語と扱う。
|