specdojo 0.2.0 → 0.3.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.
Files changed (170) hide show
  1. package/.github/agents/specdojo-orchestrator.md +165 -0
  2. package/CHANGELOG.md +280 -0
  3. package/README.md +143 -30
  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/dashboard.js +140 -9
  8. package/dist/devcontainer-command.js +43 -0
  9. package/dist/devcontainer-scaffold.js +165 -0
  10. package/dist/exec-agent-config.js +107 -9
  11. package/dist/exec-agent-git-state.js +18 -0
  12. package/dist/exec-agent-protected-config.js +46 -8
  13. package/dist/exec-evidence.js +254 -11
  14. package/dist/exec-format.js +13 -4
  15. package/dist/exec-handoff.js +336 -0
  16. package/dist/exec-parent-validation.js +317 -43
  17. package/dist/exec-pipeline-state.js +74 -9
  18. package/dist/exec-plans.js +115 -113
  19. package/dist/exec-protection-handoff.js +43 -2
  20. package/dist/exec-provider-scaffold.js +247 -15
  21. package/dist/exec-register-resume.js +65 -19
  22. package/dist/exec-register.js +9 -3
  23. package/dist/exec-repo-integration.js +811 -0
  24. package/dist/exec-repo-trace.js +182 -0
  25. package/dist/exec-reporter.js +613 -132
  26. package/dist/exec-results.js +81 -56
  27. package/dist/exec-run-lock.js +110 -107
  28. package/dist/exec-run.js +1585 -356
  29. package/dist/exec-shared.js +7 -0
  30. package/dist/exec-slot-lock.js +242 -0
  31. package/dist/exec-task-repos.js +415 -0
  32. package/dist/exec-trial.js +51 -25
  33. package/dist/exec-worktree-command.js +87 -43
  34. package/dist/exec-worktree-ops.js +502 -57
  35. package/dist/exec-worktree.js +114 -27
  36. package/dist/exec.js +13 -6
  37. package/dist/grade-result.js +128 -0
  38. package/dist/grade.js +809 -72
  39. package/dist/init-command.js +443 -0
  40. package/dist/job.js +160 -10
  41. package/dist/orchestrator.js +213 -0
  42. package/dist/package-paths.js +19 -1
  43. package/dist/register-event-merge.js +169 -0
  44. package/dist/register-item.js +7 -1
  45. package/dist/register.js +294 -86
  46. package/dist/review-grade.js +252 -0
  47. package/dist/review-plan.js +111 -1
  48. package/dist/review-types.js +40 -1
  49. package/dist/routine.js +72 -5
  50. package/dist/schedule-build.js +2 -2
  51. package/dist/schedule.js +17 -4
  52. package/dist/specdojo-config.js +466 -20
  53. package/dist/specdojo-gitignore.js +135 -0
  54. package/dist/specdojo.js +8 -1
  55. package/dist/viewpoint-document-kinds-check.js +128 -0
  56. package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
  57. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
  58. package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
  59. package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
  60. package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
  61. package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
  62. package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
  63. package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
  64. package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
  65. package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
  66. package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
  67. package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
  68. package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
  69. package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
  70. package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
  71. package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
  72. package/docs/ja/specdojo/guides/exec-config-guide.md +91 -47
  73. package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
  74. package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
  75. package/docs/ja/specdojo/guides/kata-guide.md +4 -4
  76. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +25 -4
  77. package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
  78. package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
  79. package/docs/ja/specdojo/guides/quick-start-guide.md +261 -32
  80. package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
  81. package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
  82. package/docs/ja/specdojo/guides/remote-host-development-guide.md +184 -0
  83. package/docs/ja/specdojo/guides/review-guide.md +195 -158
  84. package/docs/ja/specdojo/guides/routine-operation-guide.md +74 -9
  85. package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
  86. package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
  87. package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
  88. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
  89. package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
  90. package/docs/ja/specdojo/guides/waza-guide.md +15 -2
  91. package/docs/ja/specdojo/index.md +2 -2
  92. package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
  93. package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
  94. package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
  95. package/docs/ja/specdojo/references/command-reference.md +336 -93
  96. package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
  97. package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
  98. package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
  99. package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
  100. package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
  101. package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
  102. package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
  103. package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
  104. package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
  105. package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
  106. package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
  107. package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
  108. package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
  109. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
  110. package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
  111. package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
  112. package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
  113. package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
  114. package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
  115. package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
  116. package/docs/ja/specdojo/samples/bps-sample.md +74 -21
  117. package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
  118. package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
  119. package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
  120. package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
  121. package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
  122. package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
  123. package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
  124. package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
  125. package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
  126. package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
  127. package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
  128. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
  129. package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
  130. package/docs/ja/specdojo/templates/bps-template.md +91 -0
  131. package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
  132. package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
  133. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
  134. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
  135. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
  136. package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
  137. package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
  138. package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
  139. package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
  140. package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
  141. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
  142. package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
  143. package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
  144. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
  145. package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
  146. package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
  147. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
  148. package/package.json +16 -9
  149. package/templates/antigravity/README.md +60 -0
  150. package/templates/antigravity/agent-members-snippet.yaml +61 -0
  151. package/templates/antigravity/exec-defaults-snippet.yaml +39 -0
  152. package/templates/antigravity/orchestrator.md +157 -0
  153. package/templates/antigravity/settings.global.json +55 -0
  154. package/templates/claude/agents/claude-executor.md +14 -0
  155. package/templates/claude/agents/claude-reporter.md +16 -0
  156. package/templates/claude/agents/specdojo-orchestrator.md +164 -0
  157. package/templates/claude/settings.edit.json +27 -1
  158. package/templates/codex/README.md +5 -4
  159. package/templates/codex/agents/specdojo-orchestrator.toml +165 -0
  160. package/templates/codex/orchestrator.md +157 -0
  161. package/templates/copilot/README.md +7 -5
  162. package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
  163. package/templates/devcontainer/devcontainer.json +27 -0
  164. package/templates/devcontainer/emacs/init.el +88 -0
  165. package/templates/devcontainer/post-create.sh +62 -0
  166. package/templates/init-agent-members.yaml +200 -0
  167. package/templates/init-exec-defaults.yaml +72 -0
  168. package/templates/opencode/agents/specdojo-orchestrator.md +204 -0
  169. package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
  170. package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
@@ -1,6 +1,6 @@
1
1
  import { readFileSync, renameSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join, relative, sep } from "node:path";
3
- import { ensureDir, safeSlug } from "./exec-shared.js";
3
+ import { ensureDir, redactSensitiveText, safeSlug } from "./exec-shared.js";
4
4
  import { gitOutput } from "./exec-worktree.js";
5
5
  const MAX_LOG_BYTES = 64 * 1024;
6
6
  const MAX_CHANGE_FILES = 1_000;
@@ -29,16 +29,21 @@ function boundedLog(value) {
29
29
  truncated: true,
30
30
  };
31
31
  }
32
- /** Redacts common credential forms before agent output is persisted as evidence or a log excerpt. */
33
- export function redactSensitiveText(value) {
34
- return value
35
- .replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/giu, "Bearer [REDACTED]")
36
- .replace(/\b(sk-(?:proj-)?[A-Za-z0-9_-]{8,}|gh[opsu]_[A-Za-z0-9_]{8,})\b/gu, "[REDACTED]")
37
- .replace(/\b(api[_-]?key|access[_-]?token|auth(?:orization)?|password|passwd|secret)\b(\s*[:=]\s*)([^\s,;]+)/giu, "$1$2[REDACTED]");
38
- }
32
+ export { redactSensitiveText } from "./exec-shared.js";
39
33
  function boundedText(value, limit) {
40
34
  return truncate(redactSensitiveText(typeof value === "string" ? value.trim() : ""), limit);
41
35
  }
36
+ function executorBlockReason(status, stderr) {
37
+ if (status === "rate_limited")
38
+ return "executor rate limit reached";
39
+ const lines = stderr
40
+ .split("\n")
41
+ .map((line) => line.trim())
42
+ .filter(Boolean);
43
+ const tagged = lines.find((line) => /^(blocked|review-blocked):/iu.test(line));
44
+ const detail = tagged ?? lines.at(-1);
45
+ return boundedText(detail ? `agent exited with non-zero code: ${detail}` : "agent exited with non-zero code", MAX_VALIDATION_SUMMARY_LENGTH);
46
+ }
42
47
  export function parseExecutorReport(stdout) {
43
48
  const matches = [...stdout.matchAll(REPORT_PATTERN)];
44
49
  const raw = matches.at(-1)?.[1];
@@ -62,7 +67,12 @@ export function parseExecutorReport(stdout) {
62
67
  const candidate = item;
63
68
  const command = boundedText(candidate.command, MAX_VALIDATION_COMMAND_LENGTH);
64
69
  const status = candidate.status;
65
- if (!command || (status !== "passed" && status !== "failed" && status !== "not_run")) {
70
+ if (!command ||
71
+ (status !== "passed" &&
72
+ status !== "failed" &&
73
+ status !== "not_run" &&
74
+ status !== "not_applicable" &&
75
+ status !== "requires_human")) {
66
76
  continue;
67
77
  }
68
78
  validations.push({
@@ -70,6 +80,29 @@ export function parseExecutorReport(stdout) {
70
80
  command,
71
81
  status,
72
82
  summary: boundedText(candidate.summary, MAX_VALIDATION_SUMMARY_LENGTH),
83
+ ...(status === "not_applicable"
84
+ ? { reason: boundedText(candidate.reason, MAX_VALIDATION_SUMMARY_LENGTH) }
85
+ : {}),
86
+ });
87
+ }
88
+ }
89
+ const targetCoverage = [];
90
+ if (Array.isArray(report.target_coverage)) {
91
+ for (const item of report.target_coverage.slice(0, MAX_CHANGE_FILES)) {
92
+ if (!item || typeof item !== "object" || Array.isArray(item))
93
+ continue;
94
+ const candidate = item;
95
+ const target = boundedText(candidate.target, 1_000);
96
+ const status = candidate.status;
97
+ const path = boundedText(candidate.path, 1_000);
98
+ const reason = boundedText(candidate.reason, MAX_VALIDATION_SUMMARY_LENGTH);
99
+ if (!target || (status !== "changed" && status !== "unchanged"))
100
+ continue;
101
+ targetCoverage.push({
102
+ target,
103
+ status,
104
+ ...(path ? { path } : {}),
105
+ reason,
73
106
  });
74
107
  }
75
108
  }
@@ -77,8 +110,141 @@ export function parseExecutorReport(stdout) {
77
110
  return {
78
111
  finalMessage: boundedText(report.final_message ?? fallback, MAX_FINAL_MESSAGE_LENGTH),
79
112
  validations,
113
+ targetCoverage,
80
114
  };
81
115
  }
116
+ function normalizedEvidencePath(value) {
117
+ const normalized = value.replaceAll("\\", "/").replace(/^\.\//u, "");
118
+ if (!normalized ||
119
+ normalized.startsWith("/") ||
120
+ /^[A-Za-z]:\//u.test(normalized) ||
121
+ normalized.split("/").includes("..")) {
122
+ return null;
123
+ }
124
+ return normalized;
125
+ }
126
+ function changedEvidencePaths(changes) {
127
+ const paths = new Set();
128
+ for (const change of changes) {
129
+ // Rename/copy entries use "old -> new". Either side is sufficient to prove that the target
130
+ // was handled, and both remain repository-relative paths produced by git status.
131
+ for (const value of change.path.split(" -> ")) {
132
+ const normalized = normalizedEvidencePath(value);
133
+ if (normalized)
134
+ paths.add(normalized);
135
+ }
136
+ }
137
+ return paths;
138
+ }
139
+ function changeFingerprint(worktreePath, change) {
140
+ const hashes = change.path.split(" -> ").map((path) => {
141
+ try {
142
+ return gitOutput(worktreePath, ["hash-object", "--", path]).trim();
143
+ }
144
+ catch {
145
+ return "missing";
146
+ }
147
+ });
148
+ return `${change.status}\0${hashes.join("\0")}`;
149
+ }
150
+ /** Captures bounded fingerprints of the current cumulative worktree diff without storing content. */
151
+ export function snapshotWorktreeChanges(worktreePath, productWorktrees = []) {
152
+ return new Map(repoStatusChanges(worktreePath, productWorktrees)
153
+ .slice(0, MAX_CHANGE_FILES)
154
+ .map((change) => [change.path, changeFingerprint(change.root, change.local)]));
155
+ }
156
+ function qualifyEvidencePath(name, path) {
157
+ // Rename entries are "old -> new"; qualify each side so both stay attributable to the repository.
158
+ return path
159
+ .split(" -> ")
160
+ .map((side) => `${name}:${side}`)
161
+ .join(" -> ");
162
+ }
163
+ // PJR-98G4: プロジェクト worktree の変更は従来どおり相対パス、プロダクト worktree の変更は
164
+ // `<name>:<path>` で記録する。targets・paths の `<repo>:<path>` と同じ書式にそろえる。
165
+ function repoStatusChanges(worktreePath, productWorktrees) {
166
+ return [
167
+ ...parseStatusPaths(worktreePath).map((change) => ({
168
+ ...change,
169
+ root: worktreePath,
170
+ local: change,
171
+ })),
172
+ ...productWorktrees.flatMap((product) => parseStatusPaths(product.path).map((change) => ({
173
+ path: qualifyEvidencePath(product.name, change.path),
174
+ status: change.status,
175
+ root: product.path,
176
+ local: change,
177
+ }))),
178
+ ];
179
+ }
180
+ function productDiffStat(productWorktrees) {
181
+ return productWorktrees
182
+ .map((product) => {
183
+ const stat = gitOutput(product.path, ["diff", "--stat", "HEAD", "--"]).trim();
184
+ return stat ? `[${product.name}]\n${stat}` : "";
185
+ })
186
+ .filter(Boolean)
187
+ .join("\n");
188
+ }
189
+ /**
190
+ * Validates the stricter completion contract used when an interrupted executor is resumed.
191
+ * A changed target must point at a path present in the cumulative worktree diff; an unchanged
192
+ * target must carry a concrete reason that can be preserved in the result by the reporter path.
193
+ */
194
+ export function validateResumedTargetCoverage(targets, evidence) {
195
+ const expected = [...new Set(targets.map((target) => target.trim()).filter(Boolean))];
196
+ if (expected.length === 0)
197
+ return { ok: true };
198
+ const coverage = evidence.target_coverage ?? [];
199
+ const byTarget = new Map();
200
+ const duplicates = new Set();
201
+ for (const entry of coverage) {
202
+ if (byTarget.has(entry.target))
203
+ duplicates.add(entry.target);
204
+ else
205
+ byTarget.set(entry.target, entry);
206
+ }
207
+ if (duplicates.size > 0) {
208
+ return {
209
+ ok: false,
210
+ reason: `resumed executor target coverage has duplicate entries: ${[...duplicates].join(", ")}`,
211
+ };
212
+ }
213
+ const missing = expected.filter((target) => !byTarget.has(target));
214
+ if (missing.length > 0) {
215
+ return {
216
+ ok: false,
217
+ reason: `resumed executor did not account for every plan target: ${missing.join(", ")}`,
218
+ };
219
+ }
220
+ const changedPaths = changedEvidencePaths(evidence.changes);
221
+ for (const target of expected) {
222
+ const entry = byTarget.get(target);
223
+ if (entry.status === "unchanged") {
224
+ if (!entry.reason.trim()) {
225
+ return {
226
+ ok: false,
227
+ reason: `resumed executor reported an unchanged target without a reason: ${target}`,
228
+ };
229
+ }
230
+ continue;
231
+ }
232
+ const path = entry.path ? normalizedEvidencePath(entry.path) : null;
233
+ if (!path) {
234
+ return {
235
+ ok: false,
236
+ reason: `resumed executor reported a changed target without a valid repository-relative path: ${target}`,
237
+ };
238
+ }
239
+ if (!changedPaths.has(path)) {
240
+ return {
241
+ ok: false,
242
+ reason: `resumed executor target path is absent from the cumulative worktree diff: ${target} (${path})`,
243
+ };
244
+ }
245
+ }
246
+ return { ok: true };
247
+ }
82
248
  function parseStatusPaths(worktreePath) {
83
249
  const output = gitOutput(worktreePath, [
84
250
  "status",
@@ -115,6 +281,10 @@ export function buildExecutorEvidence(input) {
115
281
  path: boundedText(change.path, 1_000),
116
282
  status: boundedText(change.status, 40),
117
283
  }));
284
+ const attemptChanges = (input.attemptChanges ?? []).slice(0, MAX_CHANGE_FILES).map((change) => ({
285
+ path: boundedText(change.path, 1_000),
286
+ status: boundedText(change.status, 40),
287
+ }));
118
288
  const output = `${input.stdout}\n${input.stderr}`.trim();
119
289
  const boundedOutput = boundedLog(output);
120
290
  const logExcerpt = boundedOutput.content;
@@ -134,12 +304,17 @@ export function buildExecutorEvidence(input) {
134
304
  attempts: input.attempts,
135
305
  },
136
306
  changes,
307
+ ...(input.attemptChanges ? { attempt_changes: attemptChanges } : {}),
137
308
  diff_summary: {
138
309
  files_changed: changes.length,
139
310
  summary: truncate(redactSensitiveText(input.diffStat.trim()), MAX_DIFF_SUMMARY_LENGTH),
140
311
  },
141
312
  validations,
313
+ ...(report.targetCoverage.length > 0 ? { target_coverage: report.targetCoverage } : {}),
142
314
  final_message: report.finalMessage,
315
+ ...(input.status === "succeeded"
316
+ ? {}
317
+ : { block_reason: executorBlockReason(input.status, input.stderr) }),
143
318
  log_refs: [
144
319
  {
145
320
  kind: "agent-output-excerpt",
@@ -160,8 +335,24 @@ export function recordExecutorEvidence(input) {
160
335
  `${executionRel}/exec/evidence/`,
161
336
  `${executionRel}/generated/`,
162
337
  ];
163
- const changesBeforeEvidence = parseStatusPaths(input.worktreePath).filter((change) => runnerManagedPrefixes.every((prefix) => !change.path.startsWith(prefix)));
164
- const diffStat = gitOutput(input.worktreePath, ["diff", "--stat", "HEAD", "--"]);
338
+ const productWorktrees = input.productWorktrees ?? [];
339
+ const repoChanges = repoStatusChanges(input.worktreePath, productWorktrees).filter((change) => change.root !== input.worktreePath ||
340
+ runnerManagedPrefixes.every((prefix) => !change.path.startsWith(prefix)));
341
+ const changesBeforeEvidence = repoChanges.map(({ path, status }) => ({ path, status }));
342
+ // The attempt delta is needed both for interrupted-run target coverage and for telling the
343
+ // reporter which filtered runner-owned records the executor itself changed on a successful run.
344
+ const attemptChanges = input.changesBeforeAttempt
345
+ ? repoChanges
346
+ .filter((change) => input.changesBeforeAttempt?.get(change.path) !==
347
+ changeFingerprint(change.root, change.local))
348
+ .map(({ path, status }) => ({ path, status }))
349
+ : undefined;
350
+ const diffStat = [
351
+ gitOutput(input.worktreePath, ["diff", "--stat", "HEAD", "--"]).trimEnd(),
352
+ productDiffStat(productWorktrees),
353
+ ]
354
+ .filter(Boolean)
355
+ .join("\n");
165
356
  const executionInWorktree = join(input.worktreePath, executionRel);
166
357
  const evidenceDir = join(executionInWorktree, "exec", "evidence", safeSlug(input.taskId), safeSlug(input.runId));
167
358
  ensureDir(evidenceDir);
@@ -179,6 +370,7 @@ export function recordExecutorEvidence(input) {
179
370
  stdout: input.stdout,
180
371
  stderr: input.stderr,
181
372
  changes: changesBeforeEvidence,
373
+ attemptChanges,
182
374
  diffStat,
183
375
  logRefPath: repoRelative(input.worktreePath, logPath),
184
376
  parentValidations: input.parentValidations,
@@ -249,6 +441,13 @@ export function recordCommandEvidence(input) {
249
441
  },
250
442
  ],
251
443
  final_message: `Runner command ${summary}.`,
444
+ ...(!succeeded
445
+ ? {
446
+ block_reason: input.error
447
+ ? `command spawn failed: ${boundedText(input.error, MAX_VALIDATION_SUMMARY_LENGTH)}`
448
+ : `command exited with code ${input.exitCode ?? "unknown"}`,
449
+ }
450
+ : {}),
252
451
  command: {
253
452
  shell: input.shell,
254
453
  value: safeCommand,
@@ -285,6 +484,50 @@ export function writeExecutorEvidence(path, evidence) {
285
484
  writeFileSync(temporaryPath, `${JSON.stringify(evidence, null, 2)}\n`, "utf8");
286
485
  renameSync(temporaryPath, path);
287
486
  }
487
+ /**
488
+ * Persists failed parent-validation output beside executor evidence. A new numbered set is added
489
+ * for every validation batch so reporter/integration resume never overwrites the prior failure.
490
+ */
491
+ export function recordParentValidationFailureOutput(input) {
492
+ if (input.failureOutputs.length === 0)
493
+ return input.evidence;
494
+ const evidenceDir = dirname(input.evidencePath);
495
+ ensureDir(evidenceDir);
496
+ const priorAttempts = input.evidence.log_refs
497
+ .map((ref) => /^parent-validation-attempt-(\d+)-/u.exec(ref.path.split("/").at(-1) ?? "")?.[1])
498
+ .filter((attempt) => attempt !== undefined)
499
+ .map(Number);
500
+ const attempt = Math.max(0, ...priorAttempts) + 1;
501
+ const refs = [];
502
+ for (const output of input.failureOutputs) {
503
+ const logPath = join(evidenceDir, `parent-validation-attempt-${attempt}-${safeSlug(output.label)}.log`);
504
+ const content = redactSensitiveText([
505
+ `parent validation: ${output.label}`,
506
+ `exit code: ${output.exitCode ?? "unknown"}`,
507
+ `timed out: ${output.timedOut === true ? "yes" : "no"}`,
508
+ ...(output.error ? [`spawn error: ${output.error}`] : []),
509
+ "",
510
+ "--- stdout ---",
511
+ output.stdout,
512
+ "",
513
+ "--- stderr ---",
514
+ output.stderr,
515
+ ].join("\n"));
516
+ writeFileSync(logPath, content, "utf8");
517
+ refs.push({
518
+ kind: "parent-validation-output",
519
+ path: repoRelative(input.worktreePath, logPath),
520
+ bytes: Buffer.byteLength(content, "utf8"),
521
+ truncated: output.stdoutTruncated === true || output.stderrTruncated === true,
522
+ });
523
+ }
524
+ const evidence = {
525
+ ...input.evidence,
526
+ log_refs: [...input.evidence.log_refs, ...refs],
527
+ };
528
+ writeExecutorEvidence(input.evidencePath, evidence);
529
+ return evidence;
530
+ }
288
531
  /**
289
532
  * Persists the latest failed reporter invocation streams beside executor evidence.
290
533
  * Each stream is independently redacted and bounded so stdout/stderr remain distinguishable.
@@ -26,17 +26,26 @@ export async function isPrettierIgnored(filePath) {
26
26
  const info = await getFileInfo(path.resolve(filePath), { ignorePath });
27
27
  return info.ignored;
28
28
  }
29
+ function normalizeTrailingNewline(source) {
30
+ return `${source.replace(/[\r\n]+$/u, "")}\n`;
31
+ }
29
32
  export async function formatMarkdownFile(filePath) {
30
33
  try {
31
- if (await isPrettierIgnored(filePath))
32
- return;
33
34
  const source = await readFile(filePath, "utf8");
35
+ const normalized = normalizeTrailingNewline(source);
36
+ // exec の plan / result は本文保護のため Prettier 対象外だが、runner が生成する
37
+ // Markdown として末尾改行だけは同じ書き出し経路で必ず正規化する。
38
+ if (await isPrettierIgnored(filePath)) {
39
+ if (normalized !== source)
40
+ await writeFile(filePath, normalized, "utf8");
41
+ return;
42
+ }
34
43
  const config = await resolveConfig(filePath);
35
- const formatted = await format(source, {
44
+ const formatted = await format(normalized, {
36
45
  ...(config ?? {}),
37
46
  filepath: filePath,
38
47
  });
39
- await writeFile(filePath, formatted, "utf8");
48
+ await writeFile(filePath, normalizeTrailingNewline(formatted), "utf8");
40
49
  }
41
50
  catch (error) {
42
51
  const cause = error instanceof Error ? `: ${error.message}` : "";