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.
Files changed (242) hide show
  1. package/.github/agents/specdojo-orchestrator.md +165 -0
  2. package/CHANGELOG.md +298 -0
  3. package/README.md +92 -42
  4. package/dist/agent-response.js +20 -0
  5. package/dist/agent.js +4 -4
  6. package/dist/build-command.js +28 -8
  7. package/dist/catalog-build-references.js +144 -0
  8. package/dist/catalog-build-render.js +144 -0
  9. package/dist/catalog-build.js +13 -290
  10. package/dist/catalog-generate.js +6 -9
  11. package/dist/catalog-plan-generate.js +2 -2
  12. package/dist/catalog-plan.js +6 -6
  13. package/dist/catalog-scaffold.js +4 -4
  14. package/dist/catalog.js +2 -2
  15. package/dist/dashboard-exec-records.js +105 -0
  16. package/dist/dashboard-routines.js +255 -0
  17. package/dist/dashboard-shared.js +14 -0
  18. package/dist/dashboard-timeline.js +175 -0
  19. package/dist/dashboard.js +31 -444
  20. package/dist/deliverable-trash.js +3 -3
  21. package/dist/devcontainer-command.js +43 -0
  22. package/dist/devcontainer-scaffold.js +165 -0
  23. package/dist/doc-index.js +3 -3
  24. package/dist/exec-agent-config.js +107 -9
  25. package/dist/exec-agent-git-state.js +18 -0
  26. package/dist/exec-agent-protected-config.js +46 -8
  27. package/dist/exec-commands.js +557 -0
  28. package/dist/exec-core.js +457 -0
  29. package/dist/exec-evidence.js +254 -11
  30. package/dist/exec-handoff.js +336 -0
  31. package/dist/exec-parent-validation.js +317 -43
  32. package/dist/exec-pipeline-state.js +74 -9
  33. package/dist/exec-plans-core.js +693 -0
  34. package/dist/exec-plans-generation.js +206 -0
  35. package/dist/exec-plans-storage.js +131 -0
  36. package/dist/exec-plans.js +3 -1016
  37. package/dist/exec-protection-handoff.js +43 -2
  38. package/dist/exec-provider-scaffold.js +247 -15
  39. package/dist/exec-register-resume.js +65 -19
  40. package/dist/exec-register.js +9 -3
  41. package/dist/exec-repo-integration-git.js +23 -0
  42. package/dist/exec-repo-integration-sync.js +264 -0
  43. package/dist/exec-repo-integration.js +534 -0
  44. package/dist/exec-repo-trace.js +182 -0
  45. package/dist/exec-reporter-output.js +206 -0
  46. package/dist/exec-reporter.js +525 -248
  47. package/dist/exec-results.js +103 -71
  48. package/dist/exec-run-agent-pipeline.js +256 -0
  49. package/dist/exec-run-agent.js +531 -0
  50. package/dist/exec-run-in-place.js +541 -0
  51. package/dist/exec-run-job.js +717 -0
  52. package/dist/exec-run-lifecycle-commands.js +522 -0
  53. package/dist/exec-run-lock.js +110 -107
  54. package/dist/exec-run-mode-shared.js +140 -0
  55. package/dist/exec-run-register-command.js +244 -0
  56. package/dist/exec-run-register-core.js +386 -0
  57. package/dist/exec-run-register-mode.js +206 -0
  58. package/dist/exec-run-register-resume.js +393 -0
  59. package/dist/exec-run-register-state.js +322 -0
  60. package/dist/exec-run-register-worktree.js +509 -0
  61. package/dist/exec-run-schedule-mode.js +294 -0
  62. package/dist/exec-run-schedule-prepare.js +353 -0
  63. package/dist/exec-run-schedule-task.js +572 -0
  64. package/dist/exec-run-shared.js +399 -0
  65. package/dist/exec-run.js +11 -4953
  66. package/dist/exec-shared.js +9 -2
  67. package/dist/exec-slot-lock.js +242 -0
  68. package/dist/exec-task-repos.js +415 -0
  69. package/dist/exec-trial-commands.js +558 -0
  70. package/dist/exec-trial-core.js +371 -0
  71. package/dist/exec-trial.js +2 -895
  72. package/dist/exec-worktree-command.js +87 -43
  73. package/dist/exec-worktree-ops-commit.js +707 -0
  74. package/dist/exec-worktree-ops-lifecycle.js +292 -0
  75. package/dist/exec-worktree-ops-merge.js +303 -0
  76. package/dist/exec-worktree-ops.js +3 -847
  77. package/dist/exec-worktree.js +146 -31
  78. package/dist/exec.js +2 -999
  79. package/dist/frontmatter-namespace.js +2 -2
  80. package/dist/grade-apply.js +734 -0
  81. package/dist/grade-command-apply.js +250 -0
  82. package/dist/grade-command-inspect.js +138 -0
  83. package/dist/grade-command-plan.js +101 -0
  84. package/dist/grade-command-shared.js +68 -0
  85. package/dist/grade-core.js +307 -0
  86. package/dist/grade-markdown.js +274 -0
  87. package/dist/grade-pipeline-state.js +184 -0
  88. package/dist/grade-plan.js +507 -0
  89. package/dist/grade-result.js +133 -5
  90. package/dist/grade-target-discovery.js +265 -0
  91. package/dist/grade-targets.js +432 -0
  92. package/dist/grade.js +14 -2451
  93. package/dist/init-command.js +443 -0
  94. package/dist/job-definition.js +670 -0
  95. package/dist/job.js +64 -578
  96. package/dist/kata-command.js +2 -2
  97. package/dist/orchestrator.js +213 -0
  98. package/dist/register-command-types.js +1 -0
  99. package/dist/register-core.js +363 -0
  100. package/dist/register-create-commands.js +245 -0
  101. package/dist/register-event-merge.js +169 -0
  102. package/dist/register-events.js +4 -4
  103. package/dist/register-item.js +13 -7
  104. package/dist/register-maintenance-commands.js +187 -0
  105. package/dist/register-migration.js +268 -0
  106. package/dist/register-renumber.js +314 -0
  107. package/dist/register-transition-commands.js +248 -0
  108. package/dist/register-update.js +230 -0
  109. package/dist/register-views.js +256 -0
  110. package/dist/register.js +175 -1975
  111. package/dist/review-grade.js +252 -0
  112. package/dist/review-plan.js +114 -4
  113. package/dist/review-types.js +40 -1
  114. package/dist/routine-definition.js +401 -0
  115. package/dist/routine.js +73 -402
  116. package/dist/schedule-approach.js +2 -2
  117. package/dist/schedule-build.js +2 -2
  118. package/dist/schedule-strategy-generate-document.js +273 -0
  119. package/dist/schedule-strategy-generate-scope.js +199 -0
  120. package/dist/schedule-strategy-generate.js +9 -473
  121. package/dist/schedule.js +19 -6
  122. package/dist/specdojo-config.js +465 -20
  123. package/dist/specdojo-gitignore.js +135 -0
  124. package/dist/specdojo.js +6 -0
  125. package/dist/viewpoint-document-kinds-check.js +128 -0
  126. package/dist/yaml-pages.js +4 -4
  127. package/dist/yaml.js +28 -0
  128. package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
  129. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
  130. package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
  131. package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
  132. package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
  133. package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
  134. package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
  135. package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
  136. package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
  137. package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
  138. package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
  139. package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
  140. package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
  141. package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
  142. package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
  143. package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
  144. package/docs/ja/specdojo/guides/exec-config-guide.md +93 -49
  145. package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
  146. package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
  147. package/docs/ja/specdojo/guides/kata-guide.md +4 -4
  148. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +45 -22
  149. package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
  150. package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
  151. package/docs/ja/specdojo/guides/quick-start-guide.md +260 -30
  152. package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
  153. package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
  154. package/docs/ja/specdojo/guides/remote-host-development-guide.md +22 -1
  155. package/docs/ja/specdojo/guides/review-guide.md +195 -158
  156. package/docs/ja/specdojo/guides/routine-operation-guide.md +75 -10
  157. package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
  158. package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
  159. package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
  160. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
  161. package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
  162. package/docs/ja/specdojo/guides/waza-guide.md +15 -2
  163. package/docs/ja/specdojo/index.md +2 -2
  164. package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
  165. package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
  166. package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
  167. package/docs/ja/specdojo/references/command-reference.md +335 -92
  168. package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
  169. package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
  170. package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
  171. package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
  172. package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
  173. package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
  174. package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
  175. package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
  176. package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
  177. package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
  178. package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
  179. package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
  180. package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
  181. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
  182. package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
  183. package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
  184. package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
  185. package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
  186. package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
  187. package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
  188. package/docs/ja/specdojo/samples/bps-sample.md +74 -21
  189. package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
  190. package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
  191. package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
  192. package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
  193. package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
  194. package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
  195. package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
  196. package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
  197. package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
  198. package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
  199. package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
  200. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
  201. package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
  202. package/docs/ja/specdojo/templates/bps-template.md +91 -0
  203. package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
  204. package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
  205. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
  206. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
  207. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
  208. package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
  209. package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
  210. package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
  211. package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
  212. package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
  213. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
  214. package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
  215. package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
  216. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
  217. package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
  218. package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
  219. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
  220. package/package.json +17 -12
  221. package/templates/antigravity/README.md +29 -4
  222. package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
  223. package/templates/antigravity/exec-defaults-snippet.yaml +10 -7
  224. package/templates/antigravity/orchestrator.md +18 -7
  225. package/templates/antigravity/settings.global.json +55 -0
  226. package/templates/claude/agents/claude-executor.md +14 -0
  227. package/templates/claude/agents/claude-reporter.md +16 -0
  228. package/templates/claude/agents/specdojo-orchestrator.md +18 -7
  229. package/templates/claude/settings.edit.json +27 -1
  230. package/templates/codex/README.md +5 -4
  231. package/templates/codex/agents/specdojo-orchestrator.toml +18 -7
  232. package/templates/codex/orchestrator.md +18 -7
  233. package/templates/copilot/README.md +7 -5
  234. package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
  235. package/templates/devcontainer/devcontainer.json +27 -0
  236. package/templates/devcontainer/emacs/init.el +88 -0
  237. package/templates/devcontainer/post-create.sh +62 -0
  238. package/templates/init-agent-members.yaml +200 -0
  239. package/templates/init-exec-defaults.yaml +74 -0
  240. package/templates/opencode/agents/specdojo-orchestrator.md +18 -7
  241. package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
  242. package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
package/dist/job.js CHANGED
@@ -1,585 +1,16 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { spawn, spawnSync } from "node:child_process";
3
3
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
- import { basename, join, relative, resolve } from "node:path";
5
- import yaml from "js-yaml";
4
+ import { join, relative, resolve } from "node:path";
6
5
  import { buildSpecdojoFrontmatter } from "./frontmatter-namespace.js";
7
6
  import { formatMarkdownFile } from "./exec-format.js";
8
7
  import { execTemplatePath, injectCommonConventions, MISSING } from "./exec-plans.js";
9
- import { expandTemplate, listFilesRecursive, readJson, writeJson } from "./exec-shared.js";
8
+ import { expandTemplate, listFilesRecursive, writeJson } from "./exec-shared.js";
10
9
  import { gitEnvironment } from "./exec-worktree.js";
11
- import { getProjectJobsPath, getProjectExecutionPath, loadConfig, loadEnv, specdojoRootDir, } from "./specdojo-config.js";
10
+ import { isJobAgentTask, isJobCommandTask, getPath, loadAllJobs, loadJobDefinition, loadJobRunRecord, parseInputValue, parseJobInputs, renderJobTemplate, resolveJobPaths, validateJobInputValue, } from "./job-definition.js";
11
+ import { specdojoRootDir } from "./specdojo-config.js";
12
12
  import { selfRunCommand } from "./spawn-self.js";
13
- function isRecord(value) {
14
- return typeof value === "object" && value !== null && !Array.isArray(value);
15
- }
16
- export function isJobCommandTask(task) {
17
- return task.mode === "command";
18
- }
19
- export function isJobAgentTask(task) {
20
- return task.mode === "edit" || task.mode === "review";
21
- }
22
- function validStringList(value) {
23
- return (Array.isArray(value) &&
24
- value.length > 0 &&
25
- value.every((item) => typeof item === "string" && item.trim()));
26
- }
27
- // Same nickname shape as pm-members.schema.yaml. The roster is not loaded here, so a
28
- // definition only guarantees the format; an unknown nickname fails when the Run resolves
29
- // the agent command.
30
- function isAgentNickname(value) {
31
- return typeof value === "string" && /^[a-z0-9][a-z0-9_-]{0,62}$/.test(value.trim());
32
- }
33
- function isJobAgentDefinition(value) {
34
- return (isRecord(value) &&
35
- isAgentNickname(value.executor) &&
36
- (value.reporter === undefined || isAgentNickname(value.reporter)));
37
- }
38
- // Parses task.agent and reports why it was rejected. Unknown keys are refused so a typo
39
- // (for example `reporters`) cannot silently drop the reporter stage.
40
- function parseJobAgent(value) {
41
- if (!isRecord(value)) {
42
- return { error: "task.agent must be a mapping with executor and optional reporter" };
43
- }
44
- const unknownKeys = Object.keys(value).filter((key) => key !== "executor" && key !== "reporter");
45
- if (unknownKeys.length > 0) {
46
- return { error: `task.agent has unknown key(s): ${unknownKeys.sort().join(", ")}` };
47
- }
48
- if (!isAgentNickname(value.executor)) {
49
- return { error: "task.agent.executor must be an agent nickname from pm-members.yaml" };
50
- }
51
- if (value.reporter !== undefined && !isAgentNickname(value.reporter)) {
52
- return { error: "task.agent.reporter must be an agent nickname from pm-members.yaml" };
53
- }
54
- return {
55
- agent: {
56
- executor: value.executor.trim(),
57
- ...(isAgentNickname(value.reporter) ? { reporter: value.reporter.trim() } : {}),
58
- },
59
- };
60
- }
61
- function isJobRunState(value) {
62
- return value === "running" || value === "succeeded" || value === "failed" || value === "noop";
63
- }
64
- function isJobTaskDefinition(value) {
65
- if (!isRecord(value))
66
- return false;
67
- if (value.owner !== undefined && typeof value.owner !== "string")
68
- return false;
69
- if (!["targets", "paths"].every((field) => value[field] === undefined || validStringList(value[field])))
70
- return false;
71
- if (value.mode === "command") {
72
- return (typeof value.command === "string" &&
73
- (value.precondition === undefined ||
74
- (isRecord(value.precondition) &&
75
- typeof value.precondition.command === "string" &&
76
- (value.precondition.skip_when === "empty-output" ||
77
- (Number.isSafeInteger(value.precondition.skip_when) &&
78
- Number(value.precondition.skip_when) >= 0 &&
79
- Number(value.precondition.skip_when) <= 255)))) &&
80
- (value.analysis === undefined ||
81
- (isRecord(value.analysis) &&
82
- isAgentNickname(value.analysis.agent) &&
83
- typeof value.analysis.description === "string")));
84
- }
85
- if (value.mode !== "edit" && value.mode !== "review")
86
- return false;
87
- if (typeof value.description !== "string")
88
- return false;
89
- if (value.agent !== undefined && !isJobAgentDefinition(value.agent))
90
- return false;
91
- return ["capabilities"].every((field) => value[field] === undefined || validStringList(value[field]));
92
- }
93
- function isJobRunAttempt(value) {
94
- return (isRecord(value) &&
95
- typeof value.attempt === "number" &&
96
- typeof value.started_at === "string" &&
97
- isJobRunState(value.status) &&
98
- (value.evidence_ref === undefined || typeof value.evidence_ref === "string") &&
99
- (value.exit_code === undefined ||
100
- value.exit_code === null ||
101
- typeof value.exit_code === "number"));
102
- }
103
- function isJobRunRecord(value) {
104
- if (!isRecord(value))
105
- return false;
106
- const stringFields = [
107
- "run_id",
108
- "job_id",
109
- "idempotency_key",
110
- "project_id",
111
- "scheduled_at",
112
- "created_at",
113
- "updated_at",
114
- "plan_ref",
115
- "result_ref",
116
- ];
117
- return (value.version === 1 &&
118
- stringFields.every((field) => typeof value[field] === "string") &&
119
- (value.trigger === "manual" || value.trigger === "routine" || value.trigger === "ci") &&
120
- isJobRunState(value.state) &&
121
- isRecord(value.inputs) &&
122
- isJobTaskDefinition(value.task) &&
123
- isRecord(value.checkpoint_before) &&
124
- (value.checkpoint_after === undefined || isRecord(value.checkpoint_after)) &&
125
- Array.isArray(value.attempts) &&
126
- value.attempts.every(isJobRunAttempt));
127
- }
128
- function readJobRunRecord(filePath) {
129
- const raw = readJson(filePath);
130
- if (!isJobRunRecord(raw))
131
- throw new Error(`Invalid Job Run file: ${filePath}`);
132
- return raw;
133
- }
134
- function validateJobInputValue(value, input, key) {
135
- const values = input.type === "list" ? value : [value];
136
- if (input.enum) {
137
- for (const item of values) {
138
- if (!input.enum.includes(item)) {
139
- throw new Error(`Input ${key} must be one of: ${input.enum.join(", ")}`);
140
- }
141
- }
142
- }
143
- if (input.type === "integer") {
144
- const integer = value;
145
- if (input.minimum !== undefined && integer < input.minimum) {
146
- throw new Error(`Input ${key} must be at least ${input.minimum}`);
147
- }
148
- if (input.maximum !== undefined && integer > input.maximum) {
149
- throw new Error(`Input ${key} must be at most ${input.maximum}`);
150
- }
151
- }
152
- }
153
- export function parseJobDefinition(value, fileName) {
154
- const errors = [];
155
- if (!isRecord(value))
156
- return { errors: [`${fileName}: job file must be a YAML mapping`] };
157
- const expectedId = fileName.replace(/\.(yaml|yml)$/, "");
158
- const id = typeof value.id === "string" ? value.id.trim() : "";
159
- if (!/^job-[a-z0-9][a-z0-9-]*$/.test(id))
160
- errors.push("id must match job-<slug>");
161
- if (id && id !== expectedId)
162
- errors.push(`id "${id}" must match the file name base "${expectedId}"`);
163
- const name = typeof value.name === "string" ? value.name.trim() : "";
164
- if (!name)
165
- errors.push("name is required");
166
- const inputDefinitions = {};
167
- if (value.inputs !== undefined) {
168
- if (!isRecord(value.inputs))
169
- errors.push("inputs must be a mapping");
170
- else {
171
- for (const [key, raw] of Object.entries(value.inputs)) {
172
- if (!/^[a-z][a-z0-9_]*$/.test(key)) {
173
- errors.push(`inputs.${key} must use lowercase snake_case`);
174
- continue;
175
- }
176
- if (!isRecord(raw)) {
177
- errors.push(`inputs.${key} must be a mapping`);
178
- continue;
179
- }
180
- const unknownInputKeys = Object.keys(raw).filter((field) => ![
181
- "type",
182
- "required",
183
- "default",
184
- "enum",
185
- "minimum",
186
- "maximum",
187
- "from_checkpoint",
188
- "resolve",
189
- "git_revision",
190
- ].includes(field));
191
- if (unknownInputKeys.length > 0) {
192
- errors.push(`inputs.${key} has unknown key(s): ${unknownInputKeys.sort().join(", ")}`);
193
- }
194
- const type = raw.type;
195
- if (type !== "string" && type !== "integer" && type !== "boolean" && type !== "list") {
196
- errors.push(`inputs.${key}.type must be string|integer|boolean|list`);
197
- continue;
198
- }
199
- if (raw.required !== undefined && typeof raw.required !== "boolean") {
200
- errors.push(`inputs.${key}.required must be a boolean`);
201
- }
202
- if (raw.from_checkpoint !== undefined && typeof raw.from_checkpoint !== "string") {
203
- errors.push(`inputs.${key}.from_checkpoint must be a string`);
204
- }
205
- if (raw.resolve !== undefined && raw.resolve !== "git_head") {
206
- errors.push(`inputs.${key}.resolve must be git_head`);
207
- }
208
- if (raw.git_revision !== undefined && typeof raw.git_revision !== "boolean") {
209
- errors.push(`inputs.${key}.git_revision must be a boolean`);
210
- }
211
- const enumValues = raw.enum;
212
- if (enumValues !== undefined &&
213
- (!Array.isArray(enumValues) ||
214
- enumValues.length === 0 ||
215
- new Set(enumValues).size !== enumValues.length ||
216
- enumValues.some((item) => type === "integer"
217
- ? !Number.isSafeInteger(item)
218
- : type === "boolean"
219
- ? typeof item !== "boolean"
220
- : typeof item !== "string"))) {
221
- errors.push(`inputs.${key}.enum must be a non-empty unique list of ${type === "list" ? "string" : type} values`);
222
- }
223
- if (raw.minimum !== undefined &&
224
- (type !== "integer" || !Number.isSafeInteger(raw.minimum))) {
225
- errors.push(`inputs.${key}.minimum is only allowed as an integer constraint`);
226
- }
227
- if (raw.maximum !== undefined &&
228
- (type !== "integer" || !Number.isSafeInteger(raw.maximum))) {
229
- errors.push(`inputs.${key}.maximum is only allowed as an integer constraint`);
230
- }
231
- if (Number.isSafeInteger(raw.minimum) &&
232
- Number.isSafeInteger(raw.maximum) &&
233
- Number(raw.minimum) > Number(raw.maximum)) {
234
- errors.push(`inputs.${key}.minimum must not exceed maximum`);
235
- }
236
- const definition = {
237
- type,
238
- ...(typeof raw.required === "boolean" ? { required: raw.required } : {}),
239
- ...(raw.default !== undefined ? { default: raw.default } : {}),
240
- ...(Array.isArray(enumValues)
241
- ? { enum: enumValues }
242
- : {}),
243
- ...(Number.isSafeInteger(raw.minimum) ? { minimum: Number(raw.minimum) } : {}),
244
- ...(Number.isSafeInteger(raw.maximum) ? { maximum: Number(raw.maximum) } : {}),
245
- ...(typeof raw.from_checkpoint === "string"
246
- ? { from_checkpoint: raw.from_checkpoint }
247
- : {}),
248
- ...(raw.resolve === "git_head" ? { resolve: "git_head" } : {}),
249
- ...(typeof raw.git_revision === "boolean" ? { git_revision: raw.git_revision } : {}),
250
- };
251
- if (raw.default !== undefined) {
252
- try {
253
- const parsedDefault = parseInputValue(raw.default, type, key);
254
- validateJobInputValue(parsedDefault, definition, key);
255
- }
256
- catch (error) {
257
- errors.push(`inputs.${key}.default is invalid: ${error instanceof Error ? error.message : String(error)}`);
258
- }
259
- }
260
- inputDefinitions[key] = definition;
261
- }
262
- }
263
- }
264
- let task;
265
- if (!isRecord(value.task))
266
- errors.push("task is required and must be a mapping");
267
- else {
268
- const mode = value.task.mode;
269
- const targets = validStringList(value.task.targets) ? value.task.targets : undefined;
270
- const paths = validStringList(value.task.paths) ? value.task.paths : undefined;
271
- if (value.task.targets !== undefined && !targets)
272
- errors.push("task.targets must be a non-empty string list");
273
- if (value.task.paths !== undefined && !paths)
274
- errors.push("task.paths must be a non-empty string list");
275
- if (value.task.owner !== undefined && typeof value.task.owner !== "string")
276
- errors.push("task.owner must be a string");
277
- const common = {
278
- ...(targets ? { targets: targets.map((target) => target.trim()) } : {}),
279
- ...(paths ? { paths: paths.map((path) => path.trim()) } : {}),
280
- ...(typeof value.task.owner === "string" ? { owner: value.task.owner.trim() } : {}),
281
- };
282
- if (mode === "command") {
283
- const command = typeof value.task.command === "string" ? value.task.command.trim() : "";
284
- if (!command)
285
- errors.push("task.command is required for command mode");
286
- let precondition;
287
- if (value.task.precondition !== undefined) {
288
- if (!isRecord(value.task.precondition)) {
289
- errors.push("task.precondition must be a mapping with command and skip_when");
290
- }
291
- else {
292
- const unknownPreconditionKeys = Object.keys(value.task.precondition).filter((key) => key !== "command" && key !== "skip_when");
293
- if (unknownPreconditionKeys.length > 0) {
294
- errors.push(`task.precondition has unknown key(s): ${unknownPreconditionKeys.sort().join(", ")}`);
295
- }
296
- const preconditionCommand = typeof value.task.precondition.command === "string"
297
- ? value.task.precondition.command.trim()
298
- : "";
299
- if (!preconditionCommand)
300
- errors.push("task.precondition.command is required");
301
- const skipWhen = value.task.precondition.skip_when;
302
- if (skipWhen !== "empty-output" &&
303
- (!Number.isSafeInteger(skipWhen) || Number(skipWhen) < 0 || Number(skipWhen) > 255)) {
304
- errors.push("task.precondition.skip_when must be empty-output or an exit code from 0 to 255");
305
- }
306
- if (preconditionCommand &&
307
- (skipWhen === "empty-output" || Number.isSafeInteger(skipWhen))) {
308
- precondition = {
309
- command: preconditionCommand,
310
- skip_when: skipWhen,
311
- };
312
- }
313
- }
314
- }
315
- let analysis;
316
- if (value.task.analysis !== undefined) {
317
- if (!isRecord(value.task.analysis)) {
318
- errors.push("task.analysis must be a mapping with agent and description");
319
- }
320
- else {
321
- const unknownAnalysisKeys = Object.keys(value.task.analysis).filter((key) => key !== "agent" && key !== "description");
322
- if (unknownAnalysisKeys.length > 0) {
323
- errors.push(`task.analysis has unknown key(s): ${unknownAnalysisKeys.sort().join(", ")}`);
324
- }
325
- if (!isAgentNickname(value.task.analysis.agent)) {
326
- errors.push("task.analysis.agent must be an agent nickname from pm-members.yaml");
327
- }
328
- const analysisDescription = typeof value.task.analysis.description === "string"
329
- ? value.task.analysis.description.trim()
330
- : "";
331
- if (!analysisDescription)
332
- errors.push("task.analysis.description is required");
333
- if (isAgentNickname(value.task.analysis.agent) && analysisDescription) {
334
- analysis = {
335
- agent: value.task.analysis.agent.trim(),
336
- description: analysisDescription,
337
- };
338
- }
339
- }
340
- }
341
- if (value.task.agent !== undefined)
342
- errors.push("task.agent is not allowed in command mode; use task.analysis.agent");
343
- if (value.task.description !== undefined)
344
- errors.push("task.description is not allowed in command mode; use task.analysis.description");
345
- if (value.task.capabilities !== undefined || value.task.proficiency !== undefined) {
346
- errors.push("task.capabilities and task.proficiency are not allowed in command mode");
347
- }
348
- if (command)
349
- task = {
350
- mode: "command",
351
- ...(precondition ? { precondition } : {}),
352
- command,
353
- ...(analysis ? { analysis } : {}),
354
- ...common,
355
- };
356
- }
357
- else {
358
- if (mode !== "edit" && mode !== "review") {
359
- errors.push("task.mode must be edit, review, or command");
360
- }
361
- const description = typeof value.task.description === "string" ? value.task.description.trim() : "";
362
- if (!description)
363
- errors.push("task.description is required");
364
- if (!targets && !paths)
365
- errors.push("task.targets or task.paths must be a non-empty string list");
366
- let agent;
367
- if (value.task.agent !== undefined) {
368
- const parsedAgent = parseJobAgent(value.task.agent);
369
- if (parsedAgent.error)
370
- errors.push(parsedAgent.error);
371
- agent = parsedAgent.agent;
372
- }
373
- if (value.task.analysis !== undefined ||
374
- value.task.command !== undefined ||
375
- value.task.precondition !== undefined) {
376
- errors.push("task.command, task.precondition, and task.analysis are only allowed in command mode");
377
- }
378
- if (value.task.capabilities !== undefined && !validStringList(value.task.capabilities)) {
379
- errors.push("task.capabilities must be a non-empty string list");
380
- }
381
- const proficiency = value.task.proficiency;
382
- if (proficiency !== undefined &&
383
- !["low", "normal", "high", "expert"].includes(String(proficiency))) {
384
- errors.push("task.proficiency must be low|normal|high|expert");
385
- }
386
- if ((mode === "edit" || mode === "review") && description && (targets || paths)) {
387
- task = {
388
- mode,
389
- description,
390
- ...common,
391
- ...(agent ? { agent } : {}),
392
- ...(validStringList(value.task.capabilities)
393
- ? { capabilities: value.task.capabilities }
394
- : {}),
395
- ...(proficiency !== undefined ? { proficiency: proficiency } : {}),
396
- };
397
- }
398
- }
399
- }
400
- const idempotencyKey = isRecord(value.run) && typeof value.run.idempotency_key === "string"
401
- ? value.run.idempotency_key.trim()
402
- : "";
403
- if (!idempotencyKey)
404
- errors.push("run.idempotency_key is required");
405
- let checkpoint;
406
- if (value.checkpoint !== undefined) {
407
- if (!isRecord(value.checkpoint) || !isRecord(value.checkpoint.values)) {
408
- errors.push("checkpoint.values must be a mapping");
409
- }
410
- else {
411
- const values = {};
412
- for (const [key, raw] of Object.entries(value.checkpoint.values)) {
413
- if (!/^[a-z][a-z0-9_]*$/.test(key) || typeof raw !== "string") {
414
- errors.push(`checkpoint.values.${key} must be a string with a lowercase snake_case key`);
415
- }
416
- else
417
- values[key] = raw;
418
- }
419
- const advance = value.checkpoint.advance_on;
420
- if (advance !== undefined &&
421
- (!Array.isArray(advance) || advance.some((item) => item !== "succeeded" && item !== "noop"))) {
422
- errors.push("checkpoint.advance_on must contain succeeded and/or noop");
423
- }
424
- checkpoint = {
425
- values,
426
- ...(Array.isArray(advance) ? { advance_on: advance } : {}),
427
- };
428
- }
429
- }
430
- if (errors.length > 0 || !task)
431
- return { errors: errors.map((error) => `${fileName}: ${error}`) };
432
- return {
433
- job: {
434
- id,
435
- name,
436
- ...(typeof value.description === "string" ? { description: value.description } : {}),
437
- ...(Object.keys(inputDefinitions).length ? { inputs: inputDefinitions } : {}),
438
- task,
439
- run: { idempotency_key: idempotencyKey },
440
- ...(checkpoint ? { checkpoint } : {}),
441
- },
442
- errors: [],
443
- };
444
- }
445
- function configProject(projectId) {
446
- loadEnv();
447
- const { config, configPath } = loadConfig();
448
- if (!config)
449
- throw new Error(`job commands require specdojo.config.json: ${configPath}`);
450
- const id = projectId?.trim() || process.env.SPECDOJO_PROJECT?.trim() || config.current_project;
451
- if (!id)
452
- throw new Error("Project id is required. Use --project or set current_project.");
453
- const project = config.projects[id];
454
- if (!project)
455
- throw new Error(`Unknown project: ${id}`);
456
- return { id, project };
457
- }
458
- export function resolveJobPaths(projectId) {
459
- const { id, project } = configProject(projectId);
460
- const jobsPath = getProjectJobsPath(project);
461
- if (!jobsPath)
462
- throw new Error(`jobs_path not set for project '${id}' in specdojo.config.json`);
463
- const root = specdojoRootDir();
464
- const executionPath = resolve(root, getProjectExecutionPath(project));
465
- const absoluteJobsPath = resolve(root, jobsPath);
466
- return {
467
- projectId: id,
468
- jobsPath: absoluteJobsPath,
469
- executionPath,
470
- runsPath: join(executionPath, "jobs", "runs"),
471
- statePath: join(executionPath, "jobs", "generated", "job-state.json"),
472
- };
473
- }
474
- export function loadJobDefinition(paths, jobId) {
475
- const normalized = jobId.trim();
476
- if (!/^job-[a-z0-9][a-z0-9-]*$/.test(normalized))
477
- throw new Error(`Invalid job id: ${jobId}`);
478
- const candidates = [
479
- join(paths.jobsPath, `${normalized}.yaml`),
480
- join(paths.jobsPath, `${normalized}.yml`),
481
- ];
482
- const filePath = candidates.find(existsSync);
483
- if (!filePath)
484
- throw new Error(`Job not found: ${normalized} (in ${paths.jobsPath})`);
485
- const parsed = parseJobDefinition(yaml.load(readFileSync(filePath, "utf8")), basename(filePath));
486
- if (!parsed.job)
487
- throw new Error(parsed.errors.join("\n"));
488
- return parsed.job;
489
- }
490
- export function loadAllJobs(jobsPath) {
491
- if (!existsSync(jobsPath))
492
- return { jobs: [], errors: [] };
493
- const jobs = [];
494
- const errors = [];
495
- for (const filePath of listFilesRecursive(jobsPath)
496
- .filter((path) => /(?:^|\/)job-[^/]+\.ya?ml$/.test(path))
497
- .sort()) {
498
- try {
499
- const parsed = parseJobDefinition(yaml.load(readFileSync(filePath, "utf8")), basename(filePath));
500
- errors.push(...parsed.errors);
501
- if (parsed.job)
502
- jobs.push(parsed.job);
503
- }
504
- catch (error) {
505
- errors.push(`${basename(filePath)}: ${error instanceof Error ? error.message : String(error)}`);
506
- }
507
- }
508
- return { jobs, errors };
509
- }
510
- export function parseJobInputs(raw) {
511
- const result = {};
512
- for (const token of raw === undefined ? [] : Array.isArray(raw) ? raw : [raw]) {
513
- const index = token.indexOf("=");
514
- if (index <= 0)
515
- throw new Error(`Invalid --input value: ${token}. Use key=value.`);
516
- const key = token.slice(0, index).trim();
517
- if (!/^[a-z][a-z0-9_]*$/.test(key))
518
- throw new Error(`Invalid input key: ${key}`);
519
- if (Object.hasOwn(result, key))
520
- throw new Error(`Duplicate input: ${key}`);
521
- result[key] = token.slice(index + 1);
522
- }
523
- return result;
524
- }
525
- function parseInputValue(value, type, key) {
526
- if (type === "string")
527
- return String(value);
528
- if (type === "integer") {
529
- const parsed = typeof value === "number" ? value : Number(value);
530
- if (!Number.isSafeInteger(parsed))
531
- throw new Error(`Input ${key} must be an integer`);
532
- return parsed;
533
- }
534
- if (type === "boolean") {
535
- if (value === true || value === "true")
536
- return true;
537
- if (value === false || value === "false")
538
- return false;
539
- throw new Error(`Input ${key} must be true or false`);
540
- }
541
- if (Array.isArray(value))
542
- return value.map(String);
543
- return String(value)
544
- .split(",")
545
- .map((item) => item.trim())
546
- .filter(Boolean);
547
- }
548
- function getPath(source, path) {
549
- let current = source;
550
- for (const part of path.split(".")) {
551
- if (!isRecord(current) || !Object.hasOwn(current, part))
552
- return undefined;
553
- current = current[part];
554
- }
555
- return current;
556
- }
557
- function templateValue(value) {
558
- return Array.isArray(value) ? value.join(",") : String(value ?? "");
559
- }
560
- export function renderJobTemplate(template, context) {
561
- return template.replace(/\{\{\s*([a-z_][a-z0-9_.]*)\s*\}\}/gi, (_match, path) => {
562
- if (path === "job_id")
563
- return context.job_id;
564
- if (path === "job_run_id") {
565
- if (!context.job_run_id) {
566
- throw new Error("Job template value job_run_id is unavailable before Run identity exists");
567
- }
568
- return context.job_run_id;
569
- }
570
- if (path === "project_id")
571
- return context.project_id;
572
- if (path === "specdojo")
573
- return context.specdojo;
574
- if (path === "scheduled_at")
575
- return context.scheduled_at;
576
- if (path.startsWith("inputs."))
577
- return templateValue(getPath(context.inputs, path.slice(7)));
578
- if (path.startsWith("checkpoint."))
579
- return templateValue(getPath(context.checkpoint, path.slice(11)));
580
- throw new Error(`Unknown job template value: ${path}`);
581
- });
582
- }
13
+ export { isJobAgentTask, isJobCommandTask, jobDeclaresReview, jobRunUsesReviewedIntegration, loadAllJobs, loadJobDefinition, loadJobRunRecord, parseJobDefinition, parseJobInputs, renderJobTemplate, resolveJobPaths, resolveJobReviewAgentNominations, } from "./job-definition.js";
583
14
  export function jobCheckpoint(paths, jobId) {
584
15
  return deriveJobState(paths).jobs[jobId]?.checkpoint ?? {};
585
16
  }
@@ -591,7 +22,7 @@ export function deriveJobState(paths) {
591
22
  .filter((path) => path.endsWith(".json"))
592
23
  .sort()) {
593
24
  try {
594
- const run = readJobRunRecord(filePath);
25
+ const run = loadJobRunRecord(filePath);
595
26
  if (!run.checkpoint_after || (run.state !== "succeeded" && run.state !== "noop"))
596
27
  continue;
597
28
  const current = state.jobs[run.job_id];
@@ -770,7 +201,7 @@ function jobPlanFrontmatter(projectId, definition, record) {
770
201
  "type: exec-plan",
771
202
  "rulebook: none",
772
203
  `task_id: ${record.run_id}`,
773
- `name: "${definition.name.replaceAll('"', "'")}"`,
204
+ `name: ${JSON.stringify(definition.name)}`,
774
205
  // A command Run's plan is consumed only by the optional analysis reporter. Exec result
775
206
  // frontmatter intentionally keeps the existing edit/review vocabulary for compatibility.
776
207
  `mode: ${isJobCommandTask(record.task) ? "edit" : record.task.mode}`,
@@ -839,6 +270,61 @@ export async function generateJobPlan(paths, definition, record) {
839
270
  await formatMarkdownFile(planPath);
840
271
  return planPath;
841
272
  }
273
+ function jobReviewPlanFrontmatter(projectId, definition, record) {
274
+ return buildSpecdojoFrontmatter([
275
+ `id: ${projectId}:xrp-${record.run_id.toLowerCase()}-review`,
276
+ "type: exec-plan",
277
+ "rulebook: none",
278
+ `task_id: ${record.run_id}-review`,
279
+ `name: ${JSON.stringify(`${definition.name} の実行結果レビュー`)}`,
280
+ "mode: review",
281
+ "status: ready",
282
+ `project_id: ${projectId}`,
283
+ "origin: job",
284
+ `job_id: ${definition.id}`,
285
+ `run_id: ${record.run_id}`,
286
+ ]);
287
+ }
288
+ export async function generateJobReviewPlan(paths, definition, record, opts) {
289
+ const templatePath = execTemplatePath("xrp-job-template.md");
290
+ if (!existsSync(templatePath))
291
+ throw new Error(`Template not found: ${templatePath}`);
292
+ const planPath = join(paths.executionPath, "exec", "plans", `${record.run_id}-review-plan.md`);
293
+ const resultPath = join(paths.executionPath, "exec", "results", `${record.run_id}-review-result.md`);
294
+ mkdirSync(resolve(planPath, ".."), { recursive: true });
295
+ const values = {
296
+ _FRONTMATTER_: jobReviewPlanFrontmatter(paths.projectId, definition, record),
297
+ _JOB_ID_: definition.id,
298
+ _JOB_NAME_: definition.name,
299
+ _RUN_ID_: record.run_id,
300
+ _RUN_STATE_: record.state,
301
+ _BRANCH_: opts.branch,
302
+ _BASE_COMMIT_: opts.baseCommit,
303
+ _OUTPUT_COMMIT_: opts.outputCommit,
304
+ _JOB_DESCRIPTION_: definition.description ?? "-",
305
+ _ANALYSIS_DESCRIPTION_: isJobCommandTask(record.task)
306
+ ? (record.task.analysis?.description ?? "コマンドの終了結果と出力を確認する。")
307
+ : record.task.description,
308
+ _RESULT_REF_: repoRelative(resultPath),
309
+ _RUN_RESULT_REF_: repoRelative(join(paths.executionPath, record.result_ref)),
310
+ };
311
+ const body = expandTemplate(readFileSync(templatePath, "utf8"), values);
312
+ const content = injectCommonConventions(body, MISSING, new Map(), "review");
313
+ writeFileSync(planPath, content, "utf8");
314
+ await formatMarkdownFile(planPath);
315
+ return { planPath, resultPath };
316
+ }
317
+ export function recordJobRunReview(runPath, review) {
318
+ const record = loadJobRunRecord(runPath);
319
+ const reviewedAt = review.reviewed_at ?? new Date().toISOString();
320
+ const updated = {
321
+ ...record,
322
+ updated_at: reviewedAt,
323
+ review: { ...review, reviewed_at: reviewedAt },
324
+ };
325
+ writeJson(runPath, updated);
326
+ return updated;
327
+ }
842
328
  export async function materializeJobRun(opts) {
843
329
  const paths = resolveJobPaths(opts.projectId);
844
330
  const definition = loadJobDefinition(paths, opts.jobId);
@@ -890,7 +376,7 @@ export async function materializeJobRun(opts) {
890
376
  const existingRun = existsSync(runPath);
891
377
  let record;
892
378
  if (existingRun) {
893
- record = readJobRunRecord(runPath);
379
+ record = loadJobRunRecord(runPath);
894
380
  if (record.idempotency_key !== idempotencyKey || record.job_id !== definition.id) {
895
381
  throw new Error(`Job Run identity collision: ${runId}`);
896
382
  }
@@ -961,7 +447,7 @@ export async function materializeJobRun(opts) {
961
447
  }
962
448
  export function completeJobRun(opts) {
963
449
  const paths = resolveJobPaths(opts.projectId);
964
- const record = readJobRunRecord(opts.runPath);
450
+ const record = loadJobRunRecord(opts.runPath);
965
451
  const definition = loadJobDefinition(paths, record.job_id);
966
452
  const completedAt = new Date().toISOString();
967
453
  const attempts = [...record.attempts];