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
@@ -4,7 +4,10 @@ import { isDeepStrictEqual } from "node:util";
4
4
  import { buildSpecdojoFrontmatter, parseSpecdojoDocument } from "./frontmatter-namespace.js";
5
5
  import { expandTemplate, stripTerminalControlSequences } from "./exec-shared.js";
6
6
  import { formatMarkdownFile } from "./exec-format.js";
7
+ import { deriveReporterFacts, mechanicallyNotApplicableReason, runnerOwnedValidationReason, } from "./exec-reporter.js";
7
8
  import { resolveSpecdojoPath, resolveSpecdojoPathIfExists } from "./template-resolution.js";
9
+ import { dump } from "./yaml.js";
10
+ const MISSING_CHANGED_FILE_SUMMARY = "reporter の説明がないため、変更差分を参照。";
8
11
  // ---------------------------------------------------------------------------
9
12
  // Frontmatter helpers
10
13
  // ---------------------------------------------------------------------------
@@ -13,28 +16,35 @@ import { resolveSpecdojoPath, resolveSpecdojoPathIfExists } from "./template-res
13
16
  function parseOrigin(value) {
14
17
  return value === "register" || value === "schedule" || value === "job" ? value : undefined;
15
18
  }
19
+ // js-yaml に単一スカラーとして直列化させ、通常の識別子は従来どおり plain style のまま
20
+ // 保つ。改行を含む値だけは block scalar を frontmatter の行配列へ安全に埋め込めないため、
21
+ // YAML 1.2 でも有効な JSON の二重引用符形式へフォールバックする。
22
+ function serializeYamlString(value) {
23
+ const serialized = dump(value, { lineWidth: -1, noRefs: true }).replace(/\n$/, "");
24
+ return serialized.includes("\n") ? JSON.stringify(value) : serialized;
25
+ }
16
26
  function serializeFrontmatter(meta) {
17
27
  const inner = [
18
- `id: ${meta.id}`,
28
+ `id: ${serializeYamlString(meta.id)}`,
19
29
  `type: ${meta.type}`,
20
- `task_id: ${meta.task_id}`,
30
+ `task_id: ${serializeYamlString(meta.task_id)}`,
21
31
  `mode: ${meta.mode}`,
22
32
  `status: ${meta.status}`,
23
- `project_id: ${meta.project_id}`,
33
+ `project_id: ${serializeYamlString(meta.project_id)}`,
24
34
  ];
25
35
  if (meta.origin)
26
36
  inner.push(`origin: ${meta.origin}`);
27
37
  if (meta.job_id)
28
- inner.push(`job_id: ${meta.job_id}`);
38
+ inner.push(`job_id: ${serializeYamlString(meta.job_id)}`);
29
39
  if (meta.run_id)
30
- inner.push(`run_id: ${meta.run_id}`);
40
+ inner.push(`run_id: ${serializeYamlString(meta.run_id)}`);
31
41
  if (meta.plan_ref)
32
- inner.push(`plan_ref: ${meta.plan_ref}`);
33
- inner.push(`started_at: "${meta.started_at}"`);
42
+ inner.push(`plan_ref: ${serializeYamlString(meta.plan_ref)}`);
43
+ inner.push(`started_at: ${JSON.stringify(meta.started_at)}`);
34
44
  if (meta.completed_at)
35
- inner.push(`completed_at: "${meta.completed_at}"`);
45
+ inner.push(`completed_at: ${JSON.stringify(meta.completed_at)}`);
36
46
  if (meta.agent)
37
- inner.push(`agent: ${meta.agent}`);
47
+ inner.push(`agent: ${serializeYamlString(meta.agent)}`);
38
48
  if (meta.execution)
39
49
  inner.push(`execution: ${meta.execution}`);
40
50
  if (meta.approach)
@@ -42,15 +52,14 @@ function serializeFrontmatter(meta) {
42
52
  if (meta.targets && meta.targets.length > 0) {
43
53
  inner.push("targets:");
44
54
  for (const target of meta.targets)
45
- inner.push(` - ${target}`);
55
+ inner.push(` - ${serializeYamlString(target)}`);
46
56
  }
47
57
  // reason は agent stderr や subprocess の生出力由来で任意文字を含みうる。まず ANSI エスケープ
48
- // シーケンスや制御文字を除去し(色付き hook 出力が result 表示を壊すのを防ぐ)、YAML として
49
- // 安全にするため二重引用符内へ収め、内部の二重引用符は単引用符へ置換する(extractBlockReason は
50
- // 単一行を返すため改行は無い)。
58
+ // シーケンスや制御文字を除去し(色付き hook 出力が result 表示を壊すのを防ぐ)、JSON の
59
+ // 文字列形式で YAML へ埋め込む。改行・引用符・バックスラッシュも値を変えずに保持できる。
51
60
  if (meta.block_reason) {
52
- const safeReason = stripTerminalControlSequences(meta.block_reason).replace(/"/g, "'");
53
- inner.push(`block_reason: "${safeReason}"`);
61
+ const safeReason = stripTerminalControlSequences(meta.block_reason);
62
+ inner.push(`block_reason: ${JSON.stringify(safeReason)}`);
54
63
  }
55
64
  return buildSpecdojoFrontmatter(inner);
56
65
  }
@@ -176,12 +185,6 @@ export async function scaffoldResult(opts) {
176
185
  ...(opts.targets && opts.targets.length > 0 ? { targets: opts.targets } : {}),
177
186
  };
178
187
  const values = { _FRONTMATTER_: serializeFrontmatter(meta) };
179
- // Review results pre-expand per-RVP sections (role / viewpoint_id / criterion) so the result
180
- // is self-contained. When the caller cannot resolve them, leave a language-neutral _TODO_
181
- // marker; the result template's own prose explains how to fill the sections.
182
- if (mode === "review") {
183
- values._REVIEW_RESULT_SECTIONS_ = opts.reviewSections ?? "_TODO_";
184
- }
185
188
  // Finalize results pre-expand the confirmation record (done_criteria checklist and
186
189
  // ready-promotion targets) so every finalize is verified against the same items.
187
190
  // When the caller cannot resolve them, leave _TODO_ markers for manual fill-in.
@@ -200,7 +203,9 @@ export async function scaffoldResult(opts) {
200
203
  // テンプレート文言を変えた場合はここも合わせて更新する。
201
204
  const MANDATORY_PLACEHOLDERS = {
202
205
  edit: ["_TODO_: 実施した内容", "_TODO_: 変更したファイル"],
203
- review: ["recommendation: _TODO_"],
206
+ // recommendation は review が観点ごとに評価していた時期の xrr-template.md で scaffold された
207
+ // result 用。改訂前の scaffold が未記入のまま完了扱いにならないよう検知を残す。
208
+ review: ["verdict: _TODO_", "recommendation: _TODO_"],
204
209
  };
205
210
  // runner が scaffold 時に必ず設定する識別・ライフサイクル項目。agent が frontmatter を
206
211
  // 独自形式へ置換しても本文の _TODO_ だけでは検知できないため、終了時に非空を確認する。
@@ -305,12 +310,59 @@ function reporterBulletList(values, empty) {
305
310
  return `- ${empty}`;
306
311
  return values.map((value) => `- ${reporterInlineText(value)}`).join("\n");
307
312
  }
308
- function renderEditReporterBody(output) {
309
- const changedFiles = output.changed_files.length === 0
313
+ function renderEditReporterBody(output, evidence) {
314
+ const facts = deriveReporterFacts(evidence);
315
+ const summariesByPath = new Map();
316
+ for (const file of output.changed_files) {
317
+ // The evidence path list remains authoritative. Ignore invented paths and keep the first
318
+ // description when a reporter repeats a path so rendering stays deterministic.
319
+ if (!summariesByPath.has(file.path))
320
+ summariesByPath.set(file.path, file.summary);
321
+ }
322
+ const changedFiles = facts.changed_files.length === 0
310
323
  ? "- なし"
311
- : output.changed_files
312
- .map((file) => `- \`${reporterInlineText(file.path).replace(/`/g, "'")}\`: ${reporterInlineText(file.summary)}`)
324
+ : facts.changed_files
325
+ .map((file) => `- \`${reporterInlineText(file.path).replace(/`/g, "'")}\`: ${reporterInlineText(summariesByPath.get(file.path) ?? MISSING_CHANGED_FILE_SUMMARY)}`)
313
326
  .join("\n");
327
+ const unchangedTargetNotes = (evidence?.target_coverage ?? [])
328
+ .filter((entry) => entry.status === "unchanged")
329
+ .map((entry) => {
330
+ const target = reporterInlineText(entry.target).replace(/`/g, "'");
331
+ return `対象 \`${target}\` は未変更: ${reporterInlineText(entry.reason)}`;
332
+ });
333
+ const humanValidationNotes = evidence.validations
334
+ .filter((validation) => validation.source !== "runner" && validation.status === "requires_human")
335
+ .map((validation) => {
336
+ const command = reporterInlineText(validation.command).replace(/`/g, "'");
337
+ const summary = reporterInlineText(validation.summary) || "要約なし";
338
+ return `人の確認が必要: \`${command}\`(${summary})`;
339
+ });
340
+ const notApplicableValidationNotes = evidence.validations
341
+ .filter((validation) => validation.source !== "runner" && validation.status === "not_applicable")
342
+ .map((validation) => {
343
+ const command = reporterInlineText(validation.command).replace(/`/g, "'");
344
+ const reason = reporterInlineText(validation.reason ?? "") || "理由なし";
345
+ return `適用外の検証: \`${command}\`(${reason})`;
346
+ });
347
+ const changedPaths = evidence.changes.map((change) => change.path);
348
+ const runnerOwnedValidationNotes = evidence.validations
349
+ .filter((validation) => validation.source !== "runner" && validation.status === "not_run")
350
+ .flatMap((validation) => {
351
+ const reason = runnerOwnedValidationReason(validation.command);
352
+ if (reason === undefined)
353
+ return [];
354
+ const command = reporterInlineText(validation.command).replace(/`/g, "'");
355
+ return [`runner が担う検証: \`${command}\`(${reporterInlineText(reason)})`];
356
+ });
357
+ const runnerJudgedNotApplicableNotes = evidence.validations
358
+ .filter((validation) => validation.source !== "runner" && validation.status === "not_run")
359
+ .flatMap((validation) => {
360
+ const reason = mechanicallyNotApplicableReason(validation.command, { changedPaths });
361
+ if (reason === undefined)
362
+ return [];
363
+ const command = reporterInlineText(validation.command).replace(/`/g, "'");
364
+ return [`適用外の検証(runner の判定): \`${command}\`(${reporterInlineText(reason)})`];
365
+ });
314
366
  return [
315
367
  "# Edit Result",
316
368
  "",
@@ -324,72 +376,52 @@ function renderEditReporterBody(output) {
324
376
  "",
325
377
  "## 3. 申し送り",
326
378
  "",
327
- reporterBulletList(output.handoff, "なし"),
379
+ reporterBulletList([
380
+ ...output.handoff,
381
+ ...unchangedTargetNotes,
382
+ ...notApplicableValidationNotes,
383
+ ...runnerOwnedValidationNotes,
384
+ ...runnerJudgedNotApplicableNotes,
385
+ ...humanValidationNotes,
386
+ ], "なし"),
328
387
  "",
329
388
  "## 4. 進め方と実践の型の適用",
330
389
  "",
331
390
  reporterInlineText(output.approach),
332
391
  ].join("\n");
333
392
  }
334
- function reviewViewpointContexts(body) {
335
- const contexts = [];
336
- const pattern = /^### (RVP-[0-9]{3})([^\n]*)\n\n\*\*確認基準\*\*: ([^\n]+)$/gmu;
337
- for (const match of body.matchAll(pattern)) {
338
- contexts.push({ id: match[1], suffix: match[2], criterion: match[3] });
339
- }
340
- return contexts;
341
- }
342
- function renderReviewReporterBody(output, scaffoldBody) {
343
- const contexts = reviewViewpointContexts(scaffoldBody);
344
- const expectedIds = contexts.map((context) => context.id);
345
- const actualIds = output.viewpoint_results.map((viewpoint) => viewpoint.id);
346
- if (!isDeepStrictEqual(actualIds, expectedIds)) {
347
- throw new Error(`reporter viewpoint ids must match scaffold order: expected=[${expectedIds.join(", ")}], actual=[${actualIds.join(", ")}]`);
348
- }
349
- const byId = new Map(output.viewpoint_results.map((viewpoint) => [viewpoint.id, viewpoint]));
350
- const viewpointSections = contexts.length === 0
351
- ? "- 観点別結果: 該当なし"
352
- : contexts
353
- .map((context) => {
354
- const viewpoint = byId.get(context.id);
355
- if (!viewpoint)
356
- throw new Error(`reporter viewpoint missing: ${context.id}`);
357
- return [
358
- `### ${context.id}${context.suffix}`,
359
- "",
360
- `**確認基準**: ${context.criterion}`,
361
- "",
362
- `- result: ${viewpoint.result}`,
363
- `- evidence: ${viewpoint.evidence.map(reporterInlineText).join(" / ")}`,
364
- `- notes: ${viewpoint.notes ? reporterInlineText(viewpoint.notes) : "なし"}`,
365
- ].join("\n");
366
- })
367
- .join("\n\n");
393
+ // review result の章立ては xrr-template.md と一致させる。review は成果物を再評価しないため、
394
+ // 観点別の結果ではなく評価結果の確認・判断根拠・改善指示・verdict を記録する。
395
+ function renderReviewReporterBody(output) {
368
396
  return [
369
397
  "# Review Result",
370
398
  "",
371
- "## 1. レビュー観点別結果",
399
+ "## 1. 評価結果の確認",
400
+ "",
401
+ reporterInlineText(output.grade_check),
402
+ "",
403
+ "## 2. 判断根拠",
372
404
  "",
373
- viewpointSections,
405
+ reporterBulletList(output.rationale, "なし"),
374
406
  "",
375
- "## 2. findings",
407
+ "## 3. 未充足事項・改善指示",
376
408
  "",
377
- reporterBulletList(output.findings, "なし"),
409
+ reporterBulletList(output.improvements, "なし"),
378
410
  "",
379
- "## 3. 実践の型との整合確認",
411
+ "## 4. approach に応じた確認",
380
412
  "",
381
413
  reporterInlineText(output.approach),
382
414
  "",
383
- "## 4. decision",
415
+ "## 5. decision",
384
416
  "",
385
- `- recommendation: ${output.recommendation}`,
417
+ `- verdict: ${output.verdict}`,
386
418
  ].join("\n");
387
419
  }
388
420
  /**
389
421
  * Replaces only the result body from schema-validated reporter data. The scaffolded frontmatter
390
422
  * remains byte-for-byte runner-owned until the lifecycle status update serializes it.
391
423
  */
392
- export async function renderReporterResult(resultPath, output) {
424
+ export async function renderReporterResult(resultPath, output, evidence) {
393
425
  if (!existsSync(resultPath))
394
426
  throw new Error(`Result not found: ${resultPath}`);
395
427
  const content = readFileSync(resultPath, "utf8");
@@ -401,8 +433,8 @@ export async function renderReporterResult(resultPath, output) {
401
433
  if (!frontmatter)
402
434
  throw new Error(`Result frontmatter not found: ${resultPath}`);
403
435
  const body = output.mode === "edit"
404
- ? renderEditReporterBody(output)
405
- : renderReviewReporterBody(output, parsed.body);
436
+ ? renderEditReporterBody(output, evidence)
437
+ : renderReviewReporterBody(output);
406
438
  writeFileSync(resultPath, frontmatterWithBody(frontmatter, body), "utf8");
407
439
  await formatMarkdownFile(resultPath);
408
440
  }
@@ -0,0 +1,256 @@
1
+ import { relative, sep } from "node:path";
2
+ import { recordExecutorEvidence, recordParentValidationFailureOutput, recordReporterFailureOutput, snapshotWorktreeChanges, writeExecutorEvidence, } from "./exec-evidence.js";
3
+ import { failedParentValidationReason, hasRecordedParentValidations, parentValidationRoots, replaceParentValidationResults, } from "./exec-parent-validation.js";
4
+ import { createPipelineState, pipelineStateLocation, updatePipelineStage, writePipelineState, } from "./exec-pipeline-state.js";
5
+ import { deriveReporterFacts, evidenceForReporter, runReporterWithFormatRetry, } from "./exec-reporter.js";
6
+ import { renderReporterResult } from "./exec-results.js";
7
+ import { randomHex } from "./exec-shared.js";
8
+ import { withProductRepoPrompt } from "./exec-task-repos.js";
9
+ import { worktreeStatusPaths } from "./exec-worktree-ops.js";
10
+ import { agentEnvironment, appendParentValidationsToExecutorEvidence, buildExecutorPrompt, extractBlockReason, resumedTargetCoverageFailure, runConfiguredParentValidationBatch, runWithRetry, } from "./exec-run-agent.js";
11
+ export async function refreshParentValidationsForReporterResume(params) {
12
+ const configuredEntries = params.execDefaults.pipeline?.parent_validations;
13
+ const force = params.force === true && (configuredEntries?.length ?? 0) > 0;
14
+ if (!force &&
15
+ hasRecordedParentValidations(params.evidence.validations, configuredEntries) &&
16
+ !failedParentValidationReason(params.evidence.validations)) {
17
+ return params.evidence;
18
+ }
19
+ process.stdout.write(` Refreshing parent validations before ${params.stageLabel ?? "reporter"} resume` +
20
+ `${force ? " (integration targets were merged into the worktree)" : ""}.\n`);
21
+ const parentValidationBatch = await runConfiguredParentValidationBatch(params.execDefaults, parentValidationRoots(params.cwd, params.productWorktrees), { label: params.evidence.task_id });
22
+ const evidenceWithValidations = replaceParentValidationResults(params.evidence, parentValidationBatch.validations);
23
+ const evidence = recordParentValidationFailureOutput({
24
+ worktreePath: params.cwd,
25
+ evidencePath: params.evidencePath,
26
+ evidence: evidenceWithValidations,
27
+ failureOutputs: parentValidationBatch.failureOutputs,
28
+ });
29
+ if (parentValidationBatch.failureOutputs.length === 0) {
30
+ writeExecutorEvidence(params.evidencePath, evidence);
31
+ }
32
+ process.stdout.write(` Refreshed executor evidence: ${relative(params.cwd, params.evidencePath).split(sep).join("/")}\n`);
33
+ return evidence;
34
+ }
35
+ // register pipeline の reporter 段だけを実行する。executor 直後の通常経路と、executor が
36
+ // 成功したまま reporter だけが失敗した run の再開経路の双方から共有し、reporter 起動・
37
+ // result 描画・pipeline-state 更新のみを担う(register の状態遷移と commit は呼び出し側)。
38
+ export async function runReporterStage(params) {
39
+ const { repoRoot, cwd, schedulePath, executionPath, reporterCandidates, execDefaults } = params;
40
+ const env = agentEnvironment(repoRoot, cwd, schedulePath, executionPath, params.productWorktrees);
41
+ const reporterEvidence = evidenceForReporter(params.evidence, {
42
+ repoRoot,
43
+ worktreePath: cwd,
44
+ executionPath,
45
+ resultPath: params.resultPath,
46
+ ...(params.registerPaths ? { registerPaths: params.registerPaths } : {}),
47
+ });
48
+ let state = params.state;
49
+ const reporterStartedAt = new Date().toISOString();
50
+ state = updatePipelineStage(state, "reporter", {
51
+ status: "running",
52
+ actor: reporterCandidates[0]?.actor ?? null,
53
+ started_at: reporterStartedAt,
54
+ completed_at: null,
55
+ }, reporterStartedAt);
56
+ writePipelineState(params.statePath, state);
57
+ process.stdout.write(` Running reporter: ${reporterCandidates[0]?.command ?? ""}\n`);
58
+ let reporterAttempts = 0;
59
+ const runReporter = () => runReporterWithFormatRetry({
60
+ plan: params.planPrompt,
61
+ evidence: reporterEvidence,
62
+ mode: params.mode ?? "edit",
63
+ invoke: async (reporterPrompt) => {
64
+ const reporterOutcome = await runWithRetry(reporterCandidates, reporterPrompt, execDefaults, cwd, env, params.resultPath);
65
+ reporterAttempts += reporterOutcome.attempts;
66
+ return {
67
+ result: reporterOutcome.result,
68
+ stdout: reporterOutcome.stdout,
69
+ stderr: reporterOutcome.stderr,
70
+ };
71
+ },
72
+ });
73
+ const reporter = params.providerConcurrencyGate
74
+ ? await params.providerConcurrencyGate.run(reporterCandidates[0]?.provider, runReporter, `${params.evidence.task_id} reporter`)
75
+ : await runReporter();
76
+ let exitCode = 1;
77
+ let blockReason;
78
+ if (reporter.result === "success") {
79
+ try {
80
+ await renderReporterResult(params.resultPath, reporter.output, reporterEvidence);
81
+ const facts = deriveReporterFacts(reporterEvidence, { mode: params.mode ?? "edit" });
82
+ exitCode = facts.outcome === "complete" ? 0 : 1;
83
+ blockReason = facts.block_reason || undefined;
84
+ process.stdout.write(` Reporter complete: ${reporterCandidates[0]?.actor ?? "reporter"} (format attempts: ${reporter.formatAttempts})\n`);
85
+ }
86
+ catch (error) {
87
+ exitCode = 1;
88
+ blockReason =
89
+ error instanceof Error
90
+ ? `reporter result rendering failed: ${error.message}`
91
+ : String(error);
92
+ }
93
+ }
94
+ else {
95
+ blockReason = reporter.reason;
96
+ recordReporterFailureOutput({
97
+ worktreePath: cwd,
98
+ evidencePath: params.evidencePath,
99
+ evidence: params.evidence,
100
+ invocationOutputs: reporter.invocationOutputs,
101
+ });
102
+ }
103
+ const reporterCompletedAt = new Date().toISOString();
104
+ state = updatePipelineStage(state, "reporter", {
105
+ status: exitCode === 0 ? "succeeded" : reporter.result === "rate_limit" ? "rate_limited" : "failed",
106
+ attempts: state.stages.reporter.attempts + reporterAttempts,
107
+ completed_at: reporterCompletedAt,
108
+ artifact_ref: reporter.result === "success"
109
+ ? relative(cwd, params.resultPath).split(sep).join("/")
110
+ : state.stages.reporter.artifact_ref,
111
+ }, reporterCompletedAt);
112
+ writePipelineState(params.statePath, state);
113
+ const runResult = exitCode === 0 ? "success" : reporter.result === "rate_limit" ? "rate_limit" : "failure";
114
+ return { exitCode, runResult, blockReason, state };
115
+ }
116
+ // 1件の plan/result を executor→reporter の2段階で実行する。register 項目と Job Run の
117
+ // 双方が使い、in-place(cwd: repoRoot)・worktree(cwd: worktree.path)から共有する。
118
+ // evidence・pipeline-state の記録先は
119
+ // Schedule タスクの pipeline と同じ形式(exec/evidence/<taskId>/<runId>/)にすることで、
120
+ // 監査証跡のフォーマットを実行経路によらず統一する。state には plan / result の参照も
121
+ // 記録し、reporter だけが失敗した場合に `--resume` が入力を復元できるようにする。
122
+ export async function runAgentPipeline(params) {
123
+ const { repoRoot, cwd, schedulePath, executionPath, taskId, executor, reporterCandidates, planPrompt, resultPath, execDefaults, } = params;
124
+ const startedAt = new Date().toISOString();
125
+ const runId = params.runId ?? `${new Date().toISOString().replace(/[-:.]/g, "")}-${randomHex(4)}`;
126
+ const stateLocation = pipelineStateLocation({
127
+ repoRoot,
128
+ worktreePath: cwd,
129
+ executionPath,
130
+ taskId,
131
+ runId,
132
+ });
133
+ let state = createPipelineState({
134
+ taskId,
135
+ runId,
136
+ updatedAt: startedAt,
137
+ executorActor: executor.actor,
138
+ reporterActor: reporterCandidates[0]?.actor,
139
+ // plan は root(統合ブランチ)で生成して checkpoint 済みのため、repo 相対パスが
140
+ // worktree 内の相対パスと一致する。result は cwd(in-place は root、worktree 実行は
141
+ // worktree)からの相対で、evidence の artifact_ref と同じ基準に揃える。
142
+ artifacts: {
143
+ plan_ref: relative(repoRoot, params.planPath).split(sep).join("/"),
144
+ result_ref: relative(cwd, resultPath).split(sep).join("/"),
145
+ },
146
+ });
147
+ state = updatePipelineStage(state, "executor", { status: "running", started_at: startedAt }, startedAt);
148
+ writePipelineState(stateLocation.path, state);
149
+ const env = agentEnvironment(repoRoot, cwd, schedulePath, executionPath, params.productWorktrees);
150
+ const executorPrompt = withProductRepoPrompt(buildExecutorPrompt(planPrompt, execDefaults.pipeline?.parent_validations, {
151
+ mode: params.mode ?? "edit",
152
+ resumed: params.resumedExecutor,
153
+ ...(params.resumedExecutor ? { existingChanges: worktreeStatusPaths(cwd) } : {}),
154
+ ...(params.resumedExecutor
155
+ ? { initialChangeTargets: params.initialChangeTargets ?? [] }
156
+ : {}),
157
+ ...(params.resumedExecutor ? { resumeHandoff: params.resumeHandoff ?? [] } : {}),
158
+ }), params.productWorktrees);
159
+ const changesBeforeAttempt = snapshotWorktreeChanges(cwd, params.productWorktrees);
160
+ const runExecutor = () => runWithRetry([executor], executorPrompt, execDefaults, cwd, env, resultPath);
161
+ const outcome = params.providerConcurrencyGate
162
+ ? await params.providerConcurrencyGate.run(executor.provider, runExecutor, `${taskId} executor`)
163
+ : await runExecutor();
164
+ const recorded = recordExecutorEvidence({
165
+ repoRoot,
166
+ worktreePath: cwd,
167
+ executionPath,
168
+ taskId,
169
+ runId,
170
+ actor: executor.actor,
171
+ status: outcome.result === "success"
172
+ ? "succeeded"
173
+ : outcome.result === "rate_limit"
174
+ ? "rate_limited"
175
+ : "failed",
176
+ startedAt,
177
+ completedAt: new Date().toISOString(),
178
+ exitCode: outcome.exitCode,
179
+ attempts: outcome.attempts,
180
+ stdout: outcome.stdout,
181
+ stderr: outcome.stderr,
182
+ changesBeforeAttempt,
183
+ productWorktrees: params.productWorktrees,
184
+ });
185
+ const coverageFailure = outcome.result === "success"
186
+ ? resumedTargetCoverageFailure({
187
+ resumed: !!params.resumedExecutor,
188
+ plan: planPrompt,
189
+ evidence: recorded.evidence,
190
+ evidencePath: recorded.evidencePath,
191
+ initialChangeTargets: params.initialChangeTargets,
192
+ })
193
+ : undefined;
194
+ const executorResult = coverageFailure ? "failure" : outcome.result;
195
+ const evidenceRef = relative(cwd, recorded.evidencePath).split(sep).join("/");
196
+ const executorCompletedAt = new Date().toISOString();
197
+ state = updatePipelineStage(state, "executor", {
198
+ status: executorResult === "success"
199
+ ? "succeeded"
200
+ : outcome.protectionBlock
201
+ ? "blocked"
202
+ : executorResult === "rate_limit"
203
+ ? "rate_limited"
204
+ : "failed",
205
+ attempts: outcome.attempts,
206
+ completed_at: executorCompletedAt,
207
+ artifact_ref: evidenceRef,
208
+ }, executorCompletedAt);
209
+ writePipelineState(stateLocation.path, state);
210
+ process.stdout.write(` Executor evidence: ${evidenceRef}\n`);
211
+ if (executorResult !== "success") {
212
+ const blockReason = coverageFailure ??
213
+ (executorResult === "rate_limit"
214
+ ? "executor rate limit reached"
215
+ : extractBlockReason(outcome.stderr));
216
+ return {
217
+ exitCode: 1,
218
+ runResult: executorResult,
219
+ blockReason,
220
+ stateRef: stateLocation.ref,
221
+ evidenceRef,
222
+ };
223
+ }
224
+ recorded.evidence = await appendParentValidationsToExecutorEvidence({
225
+ execDefaults,
226
+ cwd,
227
+ productWorktrees: params.productWorktrees,
228
+ evidence: recorded.evidence,
229
+ evidencePath: recorded.evidencePath,
230
+ });
231
+ const reporterOutcome = await runReporterStage({
232
+ repoRoot,
233
+ cwd,
234
+ schedulePath,
235
+ executionPath,
236
+ reporterCandidates,
237
+ planPrompt,
238
+ resultPath,
239
+ registerPaths: params.registerPaths,
240
+ execDefaults,
241
+ evidence: recorded.evidence,
242
+ evidencePath: recorded.evidencePath,
243
+ state,
244
+ statePath: stateLocation.path,
245
+ providerConcurrencyGate: params.providerConcurrencyGate,
246
+ productWorktrees: params.productWorktrees,
247
+ mode: params.mode,
248
+ });
249
+ return {
250
+ exitCode: reporterOutcome.exitCode,
251
+ runResult: reporterOutcome.runResult,
252
+ blockReason: reporterOutcome.blockReason,
253
+ stateRef: stateLocation.ref,
254
+ evidenceRef,
255
+ };
256
+ }