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
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { productMergeState } from "./exec-repo-integration.js";
|
|
3
|
+
import { productIntegrationTarget } from "./exec-task-repos.js";
|
|
4
|
+
import { gitOutput, gitResult } from "./exec-worktree.js";
|
|
5
|
+
// PJR-30SW: プロダクト側の commit と merge commit へ付ける `Refs:` trailer と、統合後に result へ
|
|
6
|
+
// 記録する trace 表。trace key は PJR-1SXK の決定どおり `<project-id>:<item-id>` とする。
|
|
7
|
+
/** Heading text of the trace section the runner appends to the result. */
|
|
8
|
+
export const RESULT_TRACE_HEADING = "トレーサビリティ";
|
|
9
|
+
/** Project-qualified trace key (`<project-id>:<item-id>`) used by the `Refs:` trailer. */
|
|
10
|
+
export function traceKey(projectId, itemId) {
|
|
11
|
+
const project = projectId.trim();
|
|
12
|
+
const item = itemId.trim();
|
|
13
|
+
if (!project || !item) {
|
|
14
|
+
throw new Error(`trace key requires a project id and an item id (got "${projectId}:${itemId}")`);
|
|
15
|
+
}
|
|
16
|
+
return `${project}:${item}`;
|
|
17
|
+
}
|
|
18
|
+
/** `Refs:` trailer line for a register item (`Refs: <project-id>:<item-id>`). */
|
|
19
|
+
export function refsTrailer(projectId, itemId) {
|
|
20
|
+
return `Refs: ${traceKey(projectId, itemId)}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Append trailer lines to a commit message as the last paragraph. Trailers already present in the
|
|
24
|
+
* message are not duplicated, so retried commits keep a single `Refs:` line.
|
|
25
|
+
*/
|
|
26
|
+
export function withCommitTrailers(message, trailers) {
|
|
27
|
+
const body = message.trimEnd();
|
|
28
|
+
const existing = new Set(body.split("\n").map((line) => line.trim()));
|
|
29
|
+
const missing = trailers.filter((trailer) => !existing.has(trailer.trim()));
|
|
30
|
+
if (missing.length === 0)
|
|
31
|
+
return body;
|
|
32
|
+
return `${body}\n\n${missing.join("\n")}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Message of the project-side merge commit of a register item: the subject, then the transition,
|
|
36
|
+
* the agents, and the project-qualified `Refs:` trailer.
|
|
37
|
+
*/
|
|
38
|
+
export function registerProjectMergeMessage(params) {
|
|
39
|
+
return (`${params.subject}\n\n` +
|
|
40
|
+
`Transition: start → review\nExecutor: ${params.executor}\nReporter: ${params.reporter}\n` +
|
|
41
|
+
refsTrailer(params.projectId, params.itemId));
|
|
42
|
+
}
|
|
43
|
+
// 統合先の first-parent 上で、exec branch の先端を初めて含んだ commit(= merge commit)。
|
|
44
|
+
function integrationCommitOf(product, target) {
|
|
45
|
+
const tip = gitResult(product.repoRoot, ["rev-parse", "--verify", `${product.branch}^{commit}`]);
|
|
46
|
+
if (tip.status !== 0)
|
|
47
|
+
return null;
|
|
48
|
+
const tipSha = String(tip.stdout).trim();
|
|
49
|
+
const lines = gitOutput(product.repoRoot, [
|
|
50
|
+
"rev-list",
|
|
51
|
+
"--first-parent",
|
|
52
|
+
"--ancestry-path",
|
|
53
|
+
`${tipSha}..${target}`,
|
|
54
|
+
])
|
|
55
|
+
.split("\n")
|
|
56
|
+
.map((line) => line.trim())
|
|
57
|
+
.filter(Boolean);
|
|
58
|
+
return lines.at(-1) ?? null;
|
|
59
|
+
}
|
|
60
|
+
const PULL_REQUEST_SUBJECT = /^Merge pull request (#\d+)\b/;
|
|
61
|
+
function pullRequestOf(repoRoot, commit) {
|
|
62
|
+
const subject = gitOutput(repoRoot, ["log", "-1", "--format=%s", commit]).trim();
|
|
63
|
+
return PULL_REQUEST_SUBJECT.exec(subject)?.[1] ?? null;
|
|
64
|
+
}
|
|
65
|
+
/** Integration snapshot of one product repository, read from the Git state after integration. */
|
|
66
|
+
export function productIntegrationTrace(product) {
|
|
67
|
+
const integrationBranch = productIntegrationTarget(product);
|
|
68
|
+
const state = productMergeState(product);
|
|
69
|
+
const commit = state === "merged" ? integrationCommitOf(product, integrationBranch) : null;
|
|
70
|
+
return {
|
|
71
|
+
repo: product.name,
|
|
72
|
+
integrationBranch,
|
|
73
|
+
state,
|
|
74
|
+
commit,
|
|
75
|
+
pullRequest: commit ? pullRequestOf(product.repoRoot, commit) : null,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const NOT_APPLICABLE = "not applicable";
|
|
79
|
+
function traceRows(key, traces, recordedAt) {
|
|
80
|
+
return traces.map((trace) => [
|
|
81
|
+
`\`${key}\``,
|
|
82
|
+
`\`${trace.repo}\``,
|
|
83
|
+
`\`${trace.integrationBranch}\``,
|
|
84
|
+
trace.pullRequest ?? NOT_APPLICABLE,
|
|
85
|
+
trace.commit
|
|
86
|
+
? `\`${trace.commit}\``
|
|
87
|
+
: trace.state === "unchanged"
|
|
88
|
+
? `${NOT_APPLICABLE} (no changes)`
|
|
89
|
+
: `${NOT_APPLICABLE} (not integrated)`,
|
|
90
|
+
recordedAt,
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
function renderTable(header, rows) {
|
|
94
|
+
const escape = (cell) => cell.replace(/\|/g, "\\|");
|
|
95
|
+
const all = [header.map(escape), ...rows.map((row) => row.map(escape))];
|
|
96
|
+
const widths = header.map((cell, column) => Math.max(3, cell.length, ...all.map((row) => (row[column] ?? "").length)));
|
|
97
|
+
const line = (cells) => `| ${cells.map((cell, column) => cell.padEnd(widths[column] ?? 0)).join(" | ")} |`;
|
|
98
|
+
return [
|
|
99
|
+
line(all[0] ?? []),
|
|
100
|
+
`| ${widths.map((width) => "-".repeat(width)).join(" | ")} |`,
|
|
101
|
+
...all.slice(1).map(line),
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
/** Body of the trace section (without the heading). */
|
|
105
|
+
export function renderResultTraceBody(params) {
|
|
106
|
+
const table = renderTable(["trace key", "repository", "integration branch", "PR", "commit snapshot", "recorded at"], traceRows(params.traceKey, params.traces, params.recordedAt));
|
|
107
|
+
// PJR-9KST: result は利用側プロジェクトの markdownlint 設定で検査され、既定の MD013(80 文字)が
|
|
108
|
+
// 効くことがある。説明文は文ごとに改行して短く保ち、行長を内容で決められない表だけ MD013 を外す。
|
|
109
|
+
return [
|
|
110
|
+
"runner がプロダクトリポジトリを統合した後に記録した、統合先の commit snapshot です。",
|
|
111
|
+
"プロジェクトリポジトリの統合は、この result を含む merge commit で確認します。",
|
|
112
|
+
`その merge commit には \`Refs: ${params.traceKey}\` を付けます。`,
|
|
113
|
+
"PR が `not applicable` の行は、runner がローカルで統合し PR を経由していません。",
|
|
114
|
+
"",
|
|
115
|
+
"<!-- markdownlint-disable MD013 -->",
|
|
116
|
+
"",
|
|
117
|
+
...table,
|
|
118
|
+
"",
|
|
119
|
+
"<!-- markdownlint-enable MD013 -->",
|
|
120
|
+
].join("\n");
|
|
121
|
+
}
|
|
122
|
+
// `## n. <title>` の見出しを、コードフェンスの内側を除いて列挙する。
|
|
123
|
+
function topLevelSections(lines) {
|
|
124
|
+
const headings = [];
|
|
125
|
+
let fence = null;
|
|
126
|
+
lines.forEach((line, index) => {
|
|
127
|
+
const marker = /^\s*(```+|~~~+)/.exec(line)?.[1];
|
|
128
|
+
if (marker) {
|
|
129
|
+
if (fence === null)
|
|
130
|
+
fence = marker;
|
|
131
|
+
else if (marker[0] === fence[0] && marker.length >= fence.length)
|
|
132
|
+
fence = null;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (fence !== null)
|
|
136
|
+
return;
|
|
137
|
+
const match = /^## (\d+)\. (.+?)\s*$/.exec(line);
|
|
138
|
+
if (match)
|
|
139
|
+
headings.push({ index, number: Number(match[1]), title: match[2] ?? "" });
|
|
140
|
+
});
|
|
141
|
+
return headings.map((heading, position) => ({
|
|
142
|
+
start: heading.index,
|
|
143
|
+
end: headings[position + 1]?.index ?? lines.length,
|
|
144
|
+
number: heading.number,
|
|
145
|
+
title: heading.title,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Insert or replace the trace section of a result Markdown. The section is appended as the next
|
|
150
|
+
* numbered `##` chapter; a re-run (integration resume) replaces the previous section in place.
|
|
151
|
+
*/
|
|
152
|
+
export function upsertResultTraceSection(content, body) {
|
|
153
|
+
const lines = content.replace(/\r\n/g, "\n").replace(/\n+$/, "").split("\n");
|
|
154
|
+
const sections = topLevelSections(lines);
|
|
155
|
+
const existing = sections.find((section) => section.title === RESULT_TRACE_HEADING);
|
|
156
|
+
if (existing) {
|
|
157
|
+
const replaced = [
|
|
158
|
+
...lines.slice(0, existing.start),
|
|
159
|
+
`## ${existing.number}. ${RESULT_TRACE_HEADING}`,
|
|
160
|
+
"",
|
|
161
|
+
body,
|
|
162
|
+
...(existing.end < lines.length ? ["", ...lines.slice(existing.end)] : []),
|
|
163
|
+
];
|
|
164
|
+
return `${replaced.join("\n")}\n`;
|
|
165
|
+
}
|
|
166
|
+
const next = Math.max(0, ...sections.map((section) => section.number)) + 1;
|
|
167
|
+
return `${[...lines, "", `## ${next}. ${RESULT_TRACE_HEADING}`, "", body].join("\n")}\n`;
|
|
168
|
+
}
|
|
169
|
+
/** Record the product integration snapshots in the result file. */
|
|
170
|
+
export function recordResultTrace(params) {
|
|
171
|
+
if (params.traces.length === 0)
|
|
172
|
+
return;
|
|
173
|
+
const body = renderResultTraceBody({
|
|
174
|
+
traceKey: params.traceKey,
|
|
175
|
+
traces: params.traces,
|
|
176
|
+
recordedAt: params.recordedAt ?? new Date().toISOString(),
|
|
177
|
+
});
|
|
178
|
+
const content = readFileSync(params.resultPath, "utf8");
|
|
179
|
+
const updated = upsertResultTraceSection(content, body);
|
|
180
|
+
if (updated !== content)
|
|
181
|
+
writeFileSync(params.resultPath, updated, "utf8");
|
|
182
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import Ajv2020Module from "ajv/dist/2020.js";
|
|
2
|
+
import { extractJsonText } from "./agent-response.js";
|
|
3
|
+
import { REVIEW_VERDICTS, describeInvalidReviewVerdict, isReviewVerdict } from "./review-types.js";
|
|
4
|
+
export const MAX_TEXT_LENGTH = 4_000;
|
|
5
|
+
// review の verdict の正本は review-types.ts であり、verdict_definitions と同じ語彙を使う。
|
|
6
|
+
export { REVIEW_VERDICTS };
|
|
7
|
+
export const REPORTER_OUTPUT_SCHEMA = {
|
|
8
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
9
|
+
oneOf: [
|
|
10
|
+
{
|
|
11
|
+
type: "object",
|
|
12
|
+
additionalProperties: false,
|
|
13
|
+
required: ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"],
|
|
14
|
+
properties: {
|
|
15
|
+
schema_version: { const: 1 },
|
|
16
|
+
mode: { const: "edit" },
|
|
17
|
+
summary: { type: "array", minItems: 1, maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
18
|
+
changed_files: {
|
|
19
|
+
type: "array",
|
|
20
|
+
maxItems: 1_000,
|
|
21
|
+
items: {
|
|
22
|
+
type: "object",
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
required: ["path", "summary"],
|
|
25
|
+
properties: {
|
|
26
|
+
path: { $ref: "#/$defs/text" },
|
|
27
|
+
summary: { $ref: "#/$defs/text" },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
handoff: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
32
|
+
approach: { $ref: "#/$defs/text" },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: "object",
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
required: [
|
|
39
|
+
"schema_version",
|
|
40
|
+
"mode",
|
|
41
|
+
"grade_check",
|
|
42
|
+
"rationale",
|
|
43
|
+
"improvements",
|
|
44
|
+
"approach",
|
|
45
|
+
"verdict",
|
|
46
|
+
],
|
|
47
|
+
properties: {
|
|
48
|
+
schema_version: { const: 1 },
|
|
49
|
+
mode: { const: "review" },
|
|
50
|
+
grade_check: { $ref: "#/$defs/text" },
|
|
51
|
+
rationale: { type: "array", minItems: 1, maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
52
|
+
improvements: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
53
|
+
approach: { $ref: "#/$defs/text" },
|
|
54
|
+
verdict: { enum: [...REVIEW_VERDICTS] },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
$defs: {
|
|
59
|
+
text: { type: "string", minLength: 1, maxLength: MAX_TEXT_LENGTH },
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const Ajv2020 = Ajv2020Module.default;
|
|
63
|
+
const validateReporterSchema = new Ajv2020({ allErrors: true, strict: true }).compile(REPORTER_OUTPUT_SCHEMA);
|
|
64
|
+
// oneOf の各分岐は `properties.mode.const` で mode を固定している。分岐の並び順に依存せず、
|
|
65
|
+
// mode から Ajv の schemaPath の接頭辞(`#/oneOf/<index>/`)を求める。
|
|
66
|
+
function reporterSchemaBranchPath(mode) {
|
|
67
|
+
const index = REPORTER_OUTPUT_SCHEMA.oneOf.findIndex((branch) => branch.properties.mode.const === mode);
|
|
68
|
+
return index >= 0 ? `#/oneOf/${index}/` : undefined;
|
|
69
|
+
}
|
|
70
|
+
/** Returns the single-mode schema supplied to the selected reporter agent. */
|
|
71
|
+
export function reporterOutputSchemaForMode(mode) {
|
|
72
|
+
const branch = REPORTER_OUTPUT_SCHEMA.oneOf.find((candidate) => candidate.properties.mode.const === mode);
|
|
73
|
+
if (!branch)
|
|
74
|
+
throw new Error(`Reporter schema branch not found for mode: ${mode}`);
|
|
75
|
+
return {
|
|
76
|
+
$schema: REPORTER_OUTPUT_SCHEMA.$schema,
|
|
77
|
+
...branch,
|
|
78
|
+
$defs: REPORTER_OUTPUT_SCHEMA.$defs,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function isRecord(value) {
|
|
82
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
83
|
+
}
|
|
84
|
+
function exactKeys(value, keys) {
|
|
85
|
+
const actual = Object.keys(value).sort();
|
|
86
|
+
const expected = [...keys].sort();
|
|
87
|
+
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
88
|
+
}
|
|
89
|
+
function isText(value, allowEmpty = false) {
|
|
90
|
+
return (typeof value === "string" &&
|
|
91
|
+
value.length <= MAX_TEXT_LENGTH &&
|
|
92
|
+
(allowEmpty || value.trim().length > 0));
|
|
93
|
+
}
|
|
94
|
+
function isTextArray(value, maxItems = 100, minItems = 0) {
|
|
95
|
+
return (Array.isArray(value) &&
|
|
96
|
+
value.length >= minItems &&
|
|
97
|
+
value.length <= maxItems &&
|
|
98
|
+
value.every((item) => isText(item)));
|
|
99
|
+
}
|
|
100
|
+
function validateCommon(value, mode) {
|
|
101
|
+
if (value.schema_version !== 1)
|
|
102
|
+
return "schema_version must equal 1";
|
|
103
|
+
if (value.mode !== mode)
|
|
104
|
+
return `mode must equal ${mode}`;
|
|
105
|
+
if (!isText(value.approach))
|
|
106
|
+
return "approach must be a non-empty bounded string";
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
function validateEdit(value) {
|
|
110
|
+
const keys = ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"];
|
|
111
|
+
if (!exactKeys(value, keys))
|
|
112
|
+
return "edit output has missing or additional properties";
|
|
113
|
+
const common = validateCommon(value, "edit");
|
|
114
|
+
if (common)
|
|
115
|
+
return common;
|
|
116
|
+
if (!isTextArray(value.summary, 100, 1))
|
|
117
|
+
return "summary must contain 1-100 bounded strings";
|
|
118
|
+
if (!isTextArray(value.handoff, 100))
|
|
119
|
+
return "handoff must contain at most 100 bounded strings";
|
|
120
|
+
if (!Array.isArray(value.changed_files) || value.changed_files.length > 1_000) {
|
|
121
|
+
return "changed_files must be an array with at most 1000 items";
|
|
122
|
+
}
|
|
123
|
+
for (const file of value.changed_files) {
|
|
124
|
+
if (!isRecord(file) || !exactKeys(file, ["path", "summary"])) {
|
|
125
|
+
return "changed_files entries have missing or additional properties";
|
|
126
|
+
}
|
|
127
|
+
if (!isText(file.path))
|
|
128
|
+
return "changed_files path must be a non-empty bounded string";
|
|
129
|
+
if (!isText(file.summary))
|
|
130
|
+
return "changed_files summary must be a non-empty bounded string";
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
// 改訂前の decision.recommendation(approve / revise / reject)と verdict_definitions の旧値は、
|
|
135
|
+
// review の verdict へ統一した(PJR-XTAN)。
|
|
136
|
+
function legacyReviewVocabularyError(value) {
|
|
137
|
+
if (Object.hasOwn(value, "recommendation")) {
|
|
138
|
+
return `recommendation was replaced by verdict; ${describeInvalidReviewVerdict(value.recommendation)}`;
|
|
139
|
+
}
|
|
140
|
+
if (typeof value.verdict === "string" && !isReviewVerdict(value.verdict)) {
|
|
141
|
+
return `verdict is invalid: ${describeInvalidReviewVerdict(value.verdict)}`;
|
|
142
|
+
}
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
function validateReview(value) {
|
|
146
|
+
const keys = [
|
|
147
|
+
"schema_version",
|
|
148
|
+
"mode",
|
|
149
|
+
"grade_check",
|
|
150
|
+
"rationale",
|
|
151
|
+
"improvements",
|
|
152
|
+
"approach",
|
|
153
|
+
"verdict",
|
|
154
|
+
];
|
|
155
|
+
if (!exactKeys(value, keys))
|
|
156
|
+
return "review output has missing or additional properties";
|
|
157
|
+
const common = validateCommon(value, "review");
|
|
158
|
+
if (common)
|
|
159
|
+
return common;
|
|
160
|
+
if (!isText(value.grade_check))
|
|
161
|
+
return "grade_check must be a non-empty bounded string";
|
|
162
|
+
if (!isTextArray(value.rationale, 100, 1))
|
|
163
|
+
return "rationale must contain 1-100 bounded strings";
|
|
164
|
+
if (!isTextArray(value.improvements, 100)) {
|
|
165
|
+
return "improvements must contain at most 100 bounded strings";
|
|
166
|
+
}
|
|
167
|
+
if (!isReviewVerdict(value.verdict)) {
|
|
168
|
+
return `verdict is invalid: ${describeInvalidReviewVerdict(value.verdict)}`;
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
export function parseReporterOutput(raw, mode) {
|
|
173
|
+
let value;
|
|
174
|
+
try {
|
|
175
|
+
value = JSON.parse(extractJsonText(raw));
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
return {
|
|
179
|
+
error: `response is not a single JSON value: ${error instanceof Error ? error.message : String(error)}`,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (!isRecord(value))
|
|
183
|
+
return { error: "response root must be an object" };
|
|
184
|
+
// 旧語彙はスキーマの汎用エラーでは移行先が分からないため、スキーマ検証より先に移行先を示す。
|
|
185
|
+
const legacyError = mode === "review" ? legacyReviewVocabularyError(value) : undefined;
|
|
186
|
+
if (legacyError)
|
|
187
|
+
return { error: legacyError };
|
|
188
|
+
if (!validateReporterSchema(value)) {
|
|
189
|
+
// スキーマは edit / review の oneOf なので、両方の分岐のエラーが混ざる。先頭だけを
|
|
190
|
+
// 表示すると期待する mode と無関係な分岐のエラーで原因が隠れるため、mode の分岐に絞る。
|
|
191
|
+
const errors = validateReporterSchema.errors ?? [];
|
|
192
|
+
const modeBranch = reporterSchemaBranchPath(mode);
|
|
193
|
+
const modeErrors = modeBranch
|
|
194
|
+
? errors.filter((error) => error.schemaPath.startsWith(modeBranch))
|
|
195
|
+
: [];
|
|
196
|
+
const details = (modeErrors.length > 0 ? modeErrors : errors)
|
|
197
|
+
.slice(0, 5)
|
|
198
|
+
.map((error) => `${error.instancePath || "/"} ${error.keyword}: ${error.message ?? "invalid value"}`)
|
|
199
|
+
.join("; ");
|
|
200
|
+
return { error: `response does not match reporter JSON Schema: ${details}` };
|
|
201
|
+
}
|
|
202
|
+
const validationError = mode === "edit" ? validateEdit(value) : validateReview(value);
|
|
203
|
+
return validationError
|
|
204
|
+
? { error: validationError }
|
|
205
|
+
: { output: value };
|
|
206
|
+
}
|