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,206 @@
|
|
|
1
|
+
import Ajv2020Module from "ajv/dist/2020.js";
|
|
2
|
+
import { extractJsonText } from "../shared/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
|
+
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import Ajv2020Module from "ajv/dist/2020.js";
|
|
2
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
2
|
import { join, relative, resolve, sep } from "node:path";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
const MAX_TEXT_LENGTH = 4_000;
|
|
3
|
+
import { PARENT_VALIDATION_PROJECT_REPO, failedParentValidationReason, } from "./parent-validation.js";
|
|
4
|
+
import { getProjectExecutionPath, resolveRepoRoot, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
5
|
+
import { MAX_TEXT_LENGTH, parseReporterOutput, reporterOutputSchemaForMode, } from "./reporter-output.js";
|
|
6
|
+
export { REPORTER_OUTPUT_SCHEMA, REVIEW_VERDICTS, parseReporterOutput, reporterOutputSchemaForMode, } from "./reporter-output.js";
|
|
9
7
|
const REPORTER_FORMAT_ATTEMPTS = 3;
|
|
10
|
-
// review の verdict の正本は review-types.ts であり、verdict_definitions と同じ語彙を使う。
|
|
11
|
-
export { REVIEW_VERDICTS };
|
|
12
8
|
function isProjectConfig(value) {
|
|
13
9
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
10
|
}
|
|
@@ -248,6 +244,20 @@ function invokedScriptNameOf(command) {
|
|
|
248
244
|
return "test";
|
|
249
245
|
return /^npm run ([A-Za-z0-9:_.-]+)(?:\s|$)/u.exec(command)?.[1];
|
|
250
246
|
}
|
|
247
|
+
// `npm init` が入れる仮の test script(`echo "Error: no test specified" && exit 1`)。引用符の
|
|
248
|
+
// 有無・種類と空白の違いを許す。中身が常に失敗する仮置きなので、適用条件では script がないものとみなす。
|
|
249
|
+
const NPM_INIT_PLACEHOLDER_TEST_PATTERN = /^echo\s+(["']?)Error:\s*no\s+test\s+specified\1\s*&&\s*exit\s+1\s*;?$/iu;
|
|
250
|
+
function isNpmInitPlaceholderTestScript(body) {
|
|
251
|
+
return NPM_INIT_PLACEHOLDER_TEST_PATTERN.test(body.trim());
|
|
252
|
+
}
|
|
253
|
+
// 適用条件の判定で script があるとみなすか。`test` の仮の script は executor と runner の判断を
|
|
254
|
+
// そろえるため、ないものとして扱う(PJR-6EF8)。
|
|
255
|
+
function hasApplicableScript(scripts, scriptName) {
|
|
256
|
+
const body = scripts[scriptName];
|
|
257
|
+
if (body === undefined)
|
|
258
|
+
return false;
|
|
259
|
+
return !(scriptName === "test" && isNpmInitPlaceholderTestScript(body));
|
|
260
|
+
}
|
|
251
261
|
function npxPackageNameOf(command) {
|
|
252
262
|
return /^npx\s+((?:@[A-Za-z0-9_.-]+\/)?[A-Za-z0-9_.-]+)(?:\s|$)/u.exec(command)?.[1];
|
|
253
263
|
}
|
|
@@ -328,8 +338,10 @@ export function mechanicallyNotApplicableReason(command, options = {}) {
|
|
|
328
338
|
const manifest = commandManifest(normalized, options, config);
|
|
329
339
|
const packageJson = manifest.repoName === undefined ? "package.json" : `${manifest.repoName} の package.json`;
|
|
330
340
|
const scriptName = invokedScriptNameOf(manifest.command);
|
|
331
|
-
if (scriptName !== undefined && manifest.scripts
|
|
332
|
-
return
|
|
341
|
+
if (scriptName !== undefined && !hasApplicableScript(manifest.scripts, scriptName)) {
|
|
342
|
+
return manifest.scripts[scriptName] === undefined
|
|
343
|
+
? `${packageJson} に npm script '${scriptName}' がない`
|
|
344
|
+
: `${packageJson} の npm script '${scriptName}' は npm init の仮の script である`;
|
|
333
345
|
}
|
|
334
346
|
const packageName = npxPackageNameOf(manifest.command);
|
|
335
347
|
if (packageName !== undefined && !manifest.dependencies.has(packageName)) {
|
|
@@ -347,7 +359,7 @@ function isValidNotApplicableValidation(command, reason, options) {
|
|
|
347
359
|
return specdojo.applicable !== true;
|
|
348
360
|
const manifest = commandManifest(normalized, options, config);
|
|
349
361
|
const scriptName = invokedScriptNameOf(manifest.command);
|
|
350
|
-
if (scriptName !== undefined && manifest.scripts
|
|
362
|
+
if (scriptName !== undefined && hasApplicableScript(manifest.scripts, scriptName))
|
|
351
363
|
return false;
|
|
352
364
|
const packageName = npxPackageNameOf(manifest.command);
|
|
353
365
|
return packageName === undefined || !manifest.dependencies.has(packageName);
|
|
@@ -527,206 +539,6 @@ function readPackageManifest(packageJsonPath) {
|
|
|
527
539
|
: []);
|
|
528
540
|
return { scripts, dependencies: new Set(dependencyEntries.map(([name]) => name)) };
|
|
529
541
|
}
|
|
530
|
-
export const REPORTER_OUTPUT_SCHEMA = {
|
|
531
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
532
|
-
oneOf: [
|
|
533
|
-
{
|
|
534
|
-
type: "object",
|
|
535
|
-
additionalProperties: false,
|
|
536
|
-
required: ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"],
|
|
537
|
-
properties: {
|
|
538
|
-
schema_version: { const: 1 },
|
|
539
|
-
mode: { const: "edit" },
|
|
540
|
-
summary: { type: "array", minItems: 1, maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
541
|
-
changed_files: {
|
|
542
|
-
type: "array",
|
|
543
|
-
maxItems: 1_000,
|
|
544
|
-
items: {
|
|
545
|
-
type: "object",
|
|
546
|
-
additionalProperties: false,
|
|
547
|
-
required: ["path", "summary"],
|
|
548
|
-
properties: {
|
|
549
|
-
path: { $ref: "#/$defs/text" },
|
|
550
|
-
summary: { $ref: "#/$defs/text" },
|
|
551
|
-
},
|
|
552
|
-
},
|
|
553
|
-
},
|
|
554
|
-
handoff: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
555
|
-
approach: { $ref: "#/$defs/text" },
|
|
556
|
-
},
|
|
557
|
-
},
|
|
558
|
-
{
|
|
559
|
-
type: "object",
|
|
560
|
-
additionalProperties: false,
|
|
561
|
-
required: [
|
|
562
|
-
"schema_version",
|
|
563
|
-
"mode",
|
|
564
|
-
"grade_check",
|
|
565
|
-
"rationale",
|
|
566
|
-
"improvements",
|
|
567
|
-
"approach",
|
|
568
|
-
"verdict",
|
|
569
|
-
],
|
|
570
|
-
properties: {
|
|
571
|
-
schema_version: { const: 1 },
|
|
572
|
-
mode: { const: "review" },
|
|
573
|
-
grade_check: { $ref: "#/$defs/text" },
|
|
574
|
-
rationale: { type: "array", minItems: 1, maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
575
|
-
improvements: { type: "array", maxItems: 100, items: { $ref: "#/$defs/text" } },
|
|
576
|
-
approach: { $ref: "#/$defs/text" },
|
|
577
|
-
verdict: { enum: [...REVIEW_VERDICTS] },
|
|
578
|
-
},
|
|
579
|
-
},
|
|
580
|
-
],
|
|
581
|
-
$defs: {
|
|
582
|
-
text: { type: "string", minLength: 1, maxLength: MAX_TEXT_LENGTH },
|
|
583
|
-
},
|
|
584
|
-
};
|
|
585
|
-
const Ajv2020 = Ajv2020Module.default;
|
|
586
|
-
const validateReporterSchema = new Ajv2020({ allErrors: true, strict: true }).compile(REPORTER_OUTPUT_SCHEMA);
|
|
587
|
-
// oneOf の各分岐は `properties.mode.const` で mode を固定している。分岐の並び順に依存せず、
|
|
588
|
-
// mode から Ajv の schemaPath の接頭辞(`#/oneOf/<index>/`)を求める。
|
|
589
|
-
function reporterSchemaBranchPath(mode) {
|
|
590
|
-
const index = REPORTER_OUTPUT_SCHEMA.oneOf.findIndex((branch) => branch.properties.mode.const === mode);
|
|
591
|
-
return index >= 0 ? `#/oneOf/${index}/` : undefined;
|
|
592
|
-
}
|
|
593
|
-
/** Returns the single-mode schema supplied to the selected reporter agent. */
|
|
594
|
-
export function reporterOutputSchemaForMode(mode) {
|
|
595
|
-
const branch = REPORTER_OUTPUT_SCHEMA.oneOf.find((candidate) => candidate.properties.mode.const === mode);
|
|
596
|
-
if (!branch)
|
|
597
|
-
throw new Error(`Reporter schema branch not found for mode: ${mode}`);
|
|
598
|
-
return {
|
|
599
|
-
$schema: REPORTER_OUTPUT_SCHEMA.$schema,
|
|
600
|
-
...branch,
|
|
601
|
-
$defs: REPORTER_OUTPUT_SCHEMA.$defs,
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
function isRecord(value) {
|
|
605
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
606
|
-
}
|
|
607
|
-
function exactKeys(value, keys) {
|
|
608
|
-
const actual = Object.keys(value).sort();
|
|
609
|
-
const expected = [...keys].sort();
|
|
610
|
-
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
611
|
-
}
|
|
612
|
-
function isText(value, allowEmpty = false) {
|
|
613
|
-
return (typeof value === "string" &&
|
|
614
|
-
value.length <= MAX_TEXT_LENGTH &&
|
|
615
|
-
(allowEmpty || value.trim().length > 0));
|
|
616
|
-
}
|
|
617
|
-
function isTextArray(value, maxItems = 100, minItems = 0) {
|
|
618
|
-
return (Array.isArray(value) &&
|
|
619
|
-
value.length >= minItems &&
|
|
620
|
-
value.length <= maxItems &&
|
|
621
|
-
value.every((item) => isText(item)));
|
|
622
|
-
}
|
|
623
|
-
function validateCommon(value, mode) {
|
|
624
|
-
if (value.schema_version !== 1)
|
|
625
|
-
return "schema_version must equal 1";
|
|
626
|
-
if (value.mode !== mode)
|
|
627
|
-
return `mode must equal ${mode}`;
|
|
628
|
-
if (!isText(value.approach))
|
|
629
|
-
return "approach must be a non-empty bounded string";
|
|
630
|
-
return undefined;
|
|
631
|
-
}
|
|
632
|
-
function validateEdit(value) {
|
|
633
|
-
const keys = ["schema_version", "mode", "summary", "changed_files", "handoff", "approach"];
|
|
634
|
-
if (!exactKeys(value, keys))
|
|
635
|
-
return "edit output has missing or additional properties";
|
|
636
|
-
const common = validateCommon(value, "edit");
|
|
637
|
-
if (common)
|
|
638
|
-
return common;
|
|
639
|
-
if (!isTextArray(value.summary, 100, 1))
|
|
640
|
-
return "summary must contain 1-100 bounded strings";
|
|
641
|
-
if (!isTextArray(value.handoff, 100))
|
|
642
|
-
return "handoff must contain at most 100 bounded strings";
|
|
643
|
-
if (!Array.isArray(value.changed_files) || value.changed_files.length > 1_000) {
|
|
644
|
-
return "changed_files must be an array with at most 1000 items";
|
|
645
|
-
}
|
|
646
|
-
for (const file of value.changed_files) {
|
|
647
|
-
if (!isRecord(file) || !exactKeys(file, ["path", "summary"])) {
|
|
648
|
-
return "changed_files entries have missing or additional properties";
|
|
649
|
-
}
|
|
650
|
-
if (!isText(file.path))
|
|
651
|
-
return "changed_files path must be a non-empty bounded string";
|
|
652
|
-
if (!isText(file.summary))
|
|
653
|
-
return "changed_files summary must be a non-empty bounded string";
|
|
654
|
-
}
|
|
655
|
-
return undefined;
|
|
656
|
-
}
|
|
657
|
-
// 改訂前の decision.recommendation(approve / revise / reject)と verdict_definitions の旧値は、
|
|
658
|
-
// review の verdict へ統一した(PJR-XTAN)。
|
|
659
|
-
function legacyReviewVocabularyError(value) {
|
|
660
|
-
if (Object.hasOwn(value, "recommendation")) {
|
|
661
|
-
return `recommendation was replaced by verdict; ${describeInvalidReviewVerdict(value.recommendation)}`;
|
|
662
|
-
}
|
|
663
|
-
if (typeof value.verdict === "string" && !isReviewVerdict(value.verdict)) {
|
|
664
|
-
return `verdict is invalid: ${describeInvalidReviewVerdict(value.verdict)}`;
|
|
665
|
-
}
|
|
666
|
-
return undefined;
|
|
667
|
-
}
|
|
668
|
-
function validateReview(value) {
|
|
669
|
-
const keys = [
|
|
670
|
-
"schema_version",
|
|
671
|
-
"mode",
|
|
672
|
-
"grade_check",
|
|
673
|
-
"rationale",
|
|
674
|
-
"improvements",
|
|
675
|
-
"approach",
|
|
676
|
-
"verdict",
|
|
677
|
-
];
|
|
678
|
-
if (!exactKeys(value, keys))
|
|
679
|
-
return "review output has missing or additional properties";
|
|
680
|
-
const common = validateCommon(value, "review");
|
|
681
|
-
if (common)
|
|
682
|
-
return common;
|
|
683
|
-
if (!isText(value.grade_check))
|
|
684
|
-
return "grade_check must be a non-empty bounded string";
|
|
685
|
-
if (!isTextArray(value.rationale, 100, 1))
|
|
686
|
-
return "rationale must contain 1-100 bounded strings";
|
|
687
|
-
if (!isTextArray(value.improvements, 100)) {
|
|
688
|
-
return "improvements must contain at most 100 bounded strings";
|
|
689
|
-
}
|
|
690
|
-
if (!isReviewVerdict(value.verdict)) {
|
|
691
|
-
return `verdict is invalid: ${describeInvalidReviewVerdict(value.verdict)}`;
|
|
692
|
-
}
|
|
693
|
-
return undefined;
|
|
694
|
-
}
|
|
695
|
-
export function parseReporterOutput(raw, mode) {
|
|
696
|
-
let value;
|
|
697
|
-
try {
|
|
698
|
-
value = JSON.parse(extractJsonText(raw));
|
|
699
|
-
}
|
|
700
|
-
catch (error) {
|
|
701
|
-
return {
|
|
702
|
-
error: `response is not a single JSON value: ${error instanceof Error ? error.message : String(error)}`,
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
if (!isRecord(value))
|
|
706
|
-
return { error: "response root must be an object" };
|
|
707
|
-
// 旧語彙はスキーマの汎用エラーでは移行先が分からないため、スキーマ検証より先に移行先を示す。
|
|
708
|
-
const legacyError = mode === "review" ? legacyReviewVocabularyError(value) : undefined;
|
|
709
|
-
if (legacyError)
|
|
710
|
-
return { error: legacyError };
|
|
711
|
-
if (!validateReporterSchema(value)) {
|
|
712
|
-
// スキーマは edit / review の oneOf なので、両方の分岐のエラーが混ざる。先頭だけを
|
|
713
|
-
// 表示すると期待する mode と無関係な分岐のエラーで原因が隠れるため、mode の分岐に絞る。
|
|
714
|
-
const errors = validateReporterSchema.errors ?? [];
|
|
715
|
-
const modeBranch = reporterSchemaBranchPath(mode);
|
|
716
|
-
const modeErrors = modeBranch
|
|
717
|
-
? errors.filter((error) => error.schemaPath.startsWith(modeBranch))
|
|
718
|
-
: [];
|
|
719
|
-
const details = (modeErrors.length > 0 ? modeErrors : errors)
|
|
720
|
-
.slice(0, 5)
|
|
721
|
-
.map((error) => `${error.instancePath || "/"} ${error.keyword}: ${error.message ?? "invalid value"}`)
|
|
722
|
-
.join("; ");
|
|
723
|
-
return { error: `response does not match reporter JSON Schema: ${details}` };
|
|
724
|
-
}
|
|
725
|
-
const validationError = mode === "edit" ? validateEdit(value) : validateReview(value);
|
|
726
|
-
return validationError
|
|
727
|
-
? { error: validationError }
|
|
728
|
-
: { output: value };
|
|
729
|
-
}
|
|
730
542
|
export function buildReporterPrompt(opts) {
|
|
731
543
|
const correction = opts.validationError
|
|
732
544
|
? `\nThe previous response failed validation: ${opts.validationError}\nReturn a corrected JSON value.\n`
|
|
@@ -751,11 +563,12 @@ misread it as emphasis.
|
|
|
751
563
|
The plan below was written as generic instructions for a single agent that both edits the
|
|
752
564
|
deliverable and records its own result. In this pipeline, those two responsibilities are split:
|
|
753
565
|
the executor already completed the deliverable edit and intentionally left the result file
|
|
754
|
-
untouched because the runner writes it from your prose and machine facts. For edit mode,
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
566
|
+
untouched because the runner writes it from your prose and machine facts. For edit mode, explain
|
|
567
|
+
what was changed in each file in changed_files, especially deliverables (docs/), source files (src/),
|
|
568
|
+
and test files (tests/). Identify each changed_files summary with the exact path from its evidence.changes
|
|
569
|
+
entry. The runner matches descriptions by path: order does not matter, missing descriptions are filled
|
|
570
|
+
with Git change metadata by the runner, and paths absent from evidence are discarded. Do not include
|
|
571
|
+
statuses. An empty changes list requires an empty changed_files list. Validation entries with source="runner" were executed by the parent
|
|
759
572
|
process and remain authoritative machine facts. Do not turn them into outcome or block_reason
|
|
760
573
|
fields. When runner_context is present, it contains additional authoritative facts: do not ask for
|
|
761
574
|
a command in mechanically_not_applicable to be run, because the runner already determined that it
|