specdojo 0.2.1 → 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 (168) hide show
  1. package/.github/agents/specdojo-orchestrator.md +165 -0
  2. package/CHANGELOG.md +280 -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/dashboard.js +122 -1
  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-handoff.js +336 -0
  15. package/dist/exec-parent-validation.js +317 -43
  16. package/dist/exec-pipeline-state.js +74 -9
  17. package/dist/exec-plans.js +115 -113
  18. package/dist/exec-protection-handoff.js +43 -2
  19. package/dist/exec-provider-scaffold.js +247 -15
  20. package/dist/exec-register-resume.js +65 -19
  21. package/dist/exec-register.js +9 -3
  22. package/dist/exec-repo-integration.js +811 -0
  23. package/dist/exec-repo-trace.js +182 -0
  24. package/dist/exec-reporter.js +613 -132
  25. package/dist/exec-results.js +81 -56
  26. package/dist/exec-run-lock.js +110 -107
  27. package/dist/exec-run.js +1585 -356
  28. package/dist/exec-shared.js +7 -0
  29. package/dist/exec-slot-lock.js +242 -0
  30. package/dist/exec-task-repos.js +415 -0
  31. package/dist/exec-trial.js +51 -25
  32. package/dist/exec-worktree-command.js +87 -43
  33. package/dist/exec-worktree-ops.js +502 -57
  34. package/dist/exec-worktree.js +114 -27
  35. package/dist/exec.js +13 -6
  36. package/dist/grade-result.js +128 -0
  37. package/dist/grade.js +809 -72
  38. package/dist/init-command.js +443 -0
  39. package/dist/job.js +160 -10
  40. package/dist/orchestrator.js +213 -0
  41. package/dist/register-event-merge.js +169 -0
  42. package/dist/register-item.js +7 -1
  43. package/dist/register.js +294 -86
  44. package/dist/review-grade.js +252 -0
  45. package/dist/review-plan.js +111 -1
  46. package/dist/review-types.js +40 -1
  47. package/dist/routine.js +72 -5
  48. package/dist/schedule-build.js +2 -2
  49. package/dist/schedule.js +17 -4
  50. package/dist/specdojo-config.js +465 -19
  51. package/dist/specdojo-gitignore.js +135 -0
  52. package/dist/specdojo.js +6 -0
  53. package/dist/viewpoint-document-kinds-check.js +128 -0
  54. package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
  55. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
  56. package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
  57. package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
  58. package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
  59. package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
  60. package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
  61. package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
  62. package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
  63. package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
  64. package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
  65. package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
  66. package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
  67. package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
  68. package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
  69. package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
  70. package/docs/ja/specdojo/guides/exec-config-guide.md +91 -47
  71. package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
  72. package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
  73. package/docs/ja/specdojo/guides/kata-guide.md +4 -4
  74. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +25 -4
  75. package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
  76. package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
  77. package/docs/ja/specdojo/guides/quick-start-guide.md +260 -30
  78. package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
  79. package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
  80. package/docs/ja/specdojo/guides/remote-host-development-guide.md +22 -1
  81. package/docs/ja/specdojo/guides/review-guide.md +195 -158
  82. package/docs/ja/specdojo/guides/routine-operation-guide.md +74 -9
  83. package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
  84. package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
  85. package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
  86. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
  87. package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
  88. package/docs/ja/specdojo/guides/waza-guide.md +15 -2
  89. package/docs/ja/specdojo/index.md +2 -2
  90. package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
  91. package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
  92. package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
  93. package/docs/ja/specdojo/references/command-reference.md +335 -92
  94. package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
  95. package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
  96. package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
  97. package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
  98. package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
  99. package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
  100. package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
  101. package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
  102. package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
  103. package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
  104. package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
  105. package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
  106. package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
  107. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
  108. package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
  109. package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
  110. package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
  111. package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
  112. package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
  113. package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
  114. package/docs/ja/specdojo/samples/bps-sample.md +74 -21
  115. package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
  116. package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
  117. package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
  118. package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
  119. package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
  120. package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
  121. package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
  122. package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
  123. package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
  124. package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
  125. package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
  126. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
  127. package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
  128. package/docs/ja/specdojo/templates/bps-template.md +91 -0
  129. package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
  130. package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
  131. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
  132. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
  133. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
  134. package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
  135. package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
  136. package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
  137. package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
  138. package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
  139. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
  140. package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
  141. package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
  142. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
  143. package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
  144. package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
  145. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
  146. package/package.json +15 -9
  147. package/templates/antigravity/README.md +27 -2
  148. package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
  149. package/templates/antigravity/exec-defaults-snippet.yaml +7 -6
  150. package/templates/antigravity/orchestrator.md +18 -7
  151. package/templates/antigravity/settings.global.json +55 -0
  152. package/templates/claude/agents/claude-executor.md +14 -0
  153. package/templates/claude/agents/claude-reporter.md +16 -0
  154. package/templates/claude/agents/specdojo-orchestrator.md +18 -7
  155. package/templates/claude/settings.edit.json +27 -1
  156. package/templates/codex/README.md +5 -4
  157. package/templates/codex/agents/specdojo-orchestrator.toml +18 -7
  158. package/templates/codex/orchestrator.md +18 -7
  159. package/templates/copilot/README.md +7 -5
  160. package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
  161. package/templates/devcontainer/devcontainer.json +27 -0
  162. package/templates/devcontainer/emacs/init.el +88 -0
  163. package/templates/devcontainer/post-create.sh +62 -0
  164. package/templates/init-agent-members.yaml +200 -0
  165. package/templates/init-exec-defaults.yaml +72 -0
  166. package/templates/opencode/agents/specdojo-orchestrator.md +18 -7
  167. package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
  168. package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
@@ -1,8 +1,12 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { join } from "node:path";
2
3
  import { gitEnvironment } from "./exec-worktree.js";
4
+ import { acquirePoolSlot, getActiveExecLocksDir, releaseLock } from "./exec-slot-lock.js";
3
5
  import { redactSensitiveText } from "./exec-evidence.js";
4
- const MAX_CAPTURE_BYTES = 64 * 1024;
6
+ import { PROJECT_REPO_WORKTREE_DIRNAME, REPO_NAME_PATTERN } from "./specdojo-config.js";
7
+ export const MAX_PARENT_VALIDATION_STREAM_BYTES = 1024 * 1024;
5
8
  const MAX_SUMMARY_LENGTH = 1_000;
9
+ const CAPTURE_MARKER_RESERVE_BYTES = 256;
6
10
  const PARENT_VALIDATION_REGISTRY = {
7
11
  "validate-schema": {
8
12
  id: "validate-schema",
@@ -32,41 +36,164 @@ const PARENT_VALIDATION_REGISTRY = {
32
36
  displayCommand: "npm run test:integration",
33
37
  timeoutMs: 10 * 60 * 1_000,
34
38
  },
39
+ "lint-ts": {
40
+ id: "lint-ts",
41
+ command: process.platform === "win32" ? "npm.cmd" : "npm",
42
+ args: ["run", "lint:ts"],
43
+ displayCommand: "npm run lint:ts",
44
+ timeoutMs: 10 * 60 * 1_000,
45
+ },
46
+ "lint-fm": {
47
+ id: "lint-fm",
48
+ command: process.platform === "win32" ? "npm.cmd" : "npm",
49
+ args: ["run", "lint:fm"],
50
+ displayCommand: "npm run lint:fm",
51
+ timeoutMs: 10 * 60 * 1_000,
52
+ },
53
+ "lint-md": {
54
+ id: "lint-md",
55
+ command: process.platform === "win32" ? "npm.cmd" : "npm",
56
+ args: ["run", "lint:md"],
57
+ displayCommand: "npm run lint:md",
58
+ timeoutMs: 10 * 60 * 1_000,
59
+ },
35
60
  };
36
- function truncate(value, limit) {
61
+ function truncateHead(value, limit) {
37
62
  if (value.length <= limit)
38
63
  return value;
39
64
  return `${value.slice(0, Math.max(0, limit - 1))}…`;
40
65
  }
41
- function appendBounded(chunks, chunk, currentBytes) {
42
- if (currentBytes >= MAX_CAPTURE_BYTES)
43
- return currentBytes;
44
- const remaining = MAX_CAPTURE_BYTES - currentBytes;
45
- chunks.push(chunk.subarray(0, remaining));
46
- return currentBytes + Math.min(chunk.length, remaining);
66
+ function truncateMiddle(value, limit) {
67
+ if (value.length <= limit)
68
+ return value;
69
+ const marker = "\n… output omitted …\n";
70
+ if (limit <= marker.length)
71
+ return truncateHead(value, limit);
72
+ const retained = limit - marker.length;
73
+ const headLength = Math.ceil(retained / 2);
74
+ return `${value.slice(0, headLength)}${marker}${value.slice(-Math.floor(retained / 2))}`;
75
+ }
76
+ function appendBounded(capture, chunk) {
77
+ capture.totalBytes += chunk.length;
78
+ const payloadBytes = MAX_PARENT_VALIDATION_STREAM_BYTES - CAPTURE_MARKER_RESERVE_BYTES;
79
+ const headBytes = Math.ceil(payloadBytes / 2);
80
+ const tailBytes = Math.floor(payloadBytes / 2);
81
+ if (!capture.head && capture.totalBytes <= MAX_PARENT_VALIDATION_STREAM_BYTES) {
82
+ capture.chunks.push(chunk);
83
+ return;
84
+ }
85
+ if (!capture.head) {
86
+ const buffered = Buffer.concat([...capture.chunks, chunk]);
87
+ capture.chunks = [];
88
+ capture.head = buffered.subarray(0, headBytes);
89
+ capture.tail = buffered.subarray(-tailBytes);
90
+ return;
91
+ }
92
+ const tail = Buffer.concat([capture.tail ?? Buffer.alloc(0), chunk]);
93
+ capture.tail = tail.subarray(Math.max(0, tail.length - tailBytes));
94
+ }
95
+ function completeUtf8Prefix(buffer) {
96
+ if (buffer.length === 0)
97
+ return buffer;
98
+ let start = buffer.length - 1;
99
+ while (start > 0 && (buffer[start] & 0xc0) === 0x80)
100
+ start--;
101
+ const lead = buffer[start];
102
+ const expectedBytes = (lead & 0x80) === 0 ? 1 : (lead & 0xe0) === 0xc0 ? 2 : (lead & 0xf0) === 0xe0 ? 3 : 4;
103
+ return buffer.length - start < expectedBytes ? buffer.subarray(0, start) : buffer;
104
+ }
105
+ function capturedOutput(capture) {
106
+ if (!capture.head) {
107
+ return { output: Buffer.concat(capture.chunks).toString("utf8"), truncated: false };
108
+ }
109
+ const omitted = Math.max(0, capture.totalBytes - capture.head.length - (capture.tail?.length ?? 0));
110
+ const marker = Buffer.from(`\n… ${omitted} bytes omitted …\n`, "utf8");
111
+ const head = completeUtf8Prefix(capture.head);
112
+ const tail = capture.tail ?? Buffer.alloc(0);
113
+ let tailStart = 0;
114
+ while (tailStart < tail.length && (tail[tailStart] & 0xc0) === 0x80)
115
+ tailStart++;
116
+ return {
117
+ output: Buffer.concat([head, marker, tail.subarray(tailStart)]).toString("utf8"),
118
+ truncated: true,
119
+ };
120
+ }
121
+ // PJR-V96B: `pipeline.parent_validations` の要素は ID の文字列か `{ id, repo }`。文字列は
122
+ // プロジェクトリポジトリ(`project`)で実行する。ID が同じなら、どのリポジトリでも同じ固定 argv
123
+ // を実行する(リポジトリ別の command 指定は受け付けない)。
124
+ export const PARENT_VALIDATION_PROJECT_REPO = PROJECT_REPO_WORKTREE_DIRNAME;
125
+ export function parentValidationRoots(projectPath, productWorktrees) {
126
+ if (!productWorktrees || productWorktrees.length === 0)
127
+ return { project: projectPath };
128
+ return {
129
+ project: projectPath,
130
+ repos: Object.fromEntries(productWorktrees.map((product) => [product.name, product.path])),
131
+ };
132
+ }
133
+ function isRecord(value) {
134
+ return typeof value === "object" && value !== null && !Array.isArray(value);
135
+ }
136
+ function assignmentLabel(id, repo) {
137
+ return repo === PARENT_VALIDATION_PROJECT_REPO ? id : `${repo}:${id}`;
138
+ }
139
+ function parseEntry(entry, index) {
140
+ const where = `pipeline.parent_validations[${index}] in exec-defaults`;
141
+ if (typeof entry === "string")
142
+ return { id: entry, repo: PARENT_VALIDATION_PROJECT_REPO };
143
+ if (!isRecord(entry)) {
144
+ throw new Error(`${where} must be a validation id or { id, repo }: ${JSON.stringify(entry)}`);
145
+ }
146
+ const unknownKeys = Object.keys(entry)
147
+ .filter((key) => key !== "id" && key !== "repo")
148
+ .sort();
149
+ if (unknownKeys.length > 0) {
150
+ throw new Error(`${where}: unknown key(s) ${unknownKeys.map((key) => `"${key}"`).join(", ")}`);
151
+ }
152
+ if (typeof entry.id !== "string" || entry.id.length === 0) {
153
+ throw new Error(`${where}.id must be a non-empty string`);
154
+ }
155
+ if (typeof entry.repo !== "string" || !REPO_NAME_PATTERN.test(entry.repo)) {
156
+ throw new Error(`${where}.repo must match ${String(REPO_NAME_PATTERN)} (got ${JSON.stringify(entry.repo)})`);
157
+ }
158
+ return { id: entry.id, repo: entry.repo };
47
159
  }
48
- export function resolveParentValidationDefinitions(ids) {
49
- if (!ids)
160
+ export function resolveParentValidationAssignments(entries) {
161
+ if (!entries)
50
162
  return [];
51
163
  const seen = new Set();
52
- return ids.map((id) => {
53
- if (seen.has(id)) {
54
- throw new Error(`Duplicate parent validation id in exec-defaults: ${id}`);
164
+ return entries.map((entry, index) => {
165
+ const { id, repo } = parseEntry(entry, index);
166
+ const label = assignmentLabel(id, repo);
167
+ if (seen.has(label)) {
168
+ throw new Error(`Duplicate parent validation id in exec-defaults: ${label}`);
55
169
  }
56
- seen.add(id);
57
- const definition = PARENT_VALIDATION_REGISTRY[id];
170
+ seen.add(label);
171
+ const definition = Object.hasOwn(PARENT_VALIDATION_REGISTRY, id)
172
+ ? PARENT_VALIDATION_REGISTRY[id]
173
+ : undefined;
58
174
  if (!definition) {
59
175
  throw new Error(`Unknown parent validation id in exec-defaults: ${id} (allowed: ${Object.keys(PARENT_VALIDATION_REGISTRY).join(", ")})`);
60
176
  }
61
- return definition;
177
+ return { definition, repo, label };
62
178
  });
63
179
  }
180
+ export function resolveParentValidationDefinitions(entries) {
181
+ return resolveParentValidationAssignments(entries).map((assignment) => assignment.definition);
182
+ }
183
+ /** Labels (`<id>` or `<repo>:<id>`) of the configured parent validations, in order. */
184
+ export function parentValidationLabels(entries) {
185
+ return resolveParentValidationAssignments(entries).map((assignment) => assignment.label);
186
+ }
187
+ /** Display command with the repository for product assignments (`npm run test:unit (in app1)`). */
188
+ export function parentValidationDisplayCommands(entries) {
189
+ return resolveParentValidationAssignments(entries).map((assignment) => assignment.repo === PARENT_VALIDATION_PROJECT_REPO
190
+ ? assignment.definition.displayCommand
191
+ : `${assignment.definition.displayCommand} (in ${assignment.repo})`);
192
+ }
64
193
  async function invokeParentValidation(definition, cwd) {
65
194
  return await new Promise((resolve) => {
66
- const stdoutChunks = [];
67
- const stderrChunks = [];
68
- let stdoutBytes = 0;
69
- let stderrBytes = 0;
195
+ const stdoutCapture = { chunks: [], totalBytes: 0 };
196
+ const stderrCapture = { chunks: [], totalBytes: 0 };
70
197
  let settled = false;
71
198
  let timedOut = false;
72
199
  const child = spawn(definition.command, [...definition.args], {
@@ -77,10 +204,10 @@ async function invokeParentValidation(definition, cwd) {
77
204
  windowsHide: true,
78
205
  });
79
206
  child.stdout.on("data", (chunk) => {
80
- stdoutBytes = appendBounded(stdoutChunks, chunk, stdoutBytes);
207
+ appendBounded(stdoutCapture, chunk);
81
208
  });
82
209
  child.stderr.on("data", (chunk) => {
83
- stderrBytes = appendBounded(stderrChunks, chunk, stderrBytes);
210
+ appendBounded(stderrCapture, chunk);
84
211
  });
85
212
  const timer = setTimeout(() => {
86
213
  timedOut = true;
@@ -94,53 +221,200 @@ async function invokeParentValidation(definition, cwd) {
94
221
  resolve(result);
95
222
  };
96
223
  child.on("error", (error) => {
224
+ const stdout = capturedOutput(stdoutCapture);
225
+ const stderr = capturedOutput(stderrCapture);
97
226
  finish({
98
227
  exitCode: null,
99
- stdout: Buffer.concat(stdoutChunks).toString("utf8"),
100
- stderr: Buffer.concat(stderrChunks).toString("utf8"),
228
+ stdout: stdout.output,
229
+ stderr: stderr.output,
101
230
  error: error.message,
102
231
  timedOut,
232
+ stdoutTruncated: stdout.truncated,
233
+ stderrTruncated: stderr.truncated,
103
234
  });
104
235
  });
105
236
  child.on("close", (exitCode) => {
237
+ const stdout = capturedOutput(stdoutCapture);
238
+ const stderr = capturedOutput(stderrCapture);
106
239
  finish({
107
240
  exitCode,
108
- stdout: Buffer.concat(stdoutChunks).toString("utf8"),
109
- stderr: Buffer.concat(stderrChunks).toString("utf8"),
241
+ stdout: stdout.output,
242
+ stderr: stderr.output,
110
243
  timedOut,
244
+ stdoutTruncated: stdout.truncated,
245
+ stderrTruncated: stderr.truncated,
111
246
  });
112
247
  });
113
248
  });
114
249
  }
115
250
  function validationSummary(result) {
116
- const output = redactSensitiveText([result.stdout, result.stderr].filter(Boolean).join("\n").trim());
251
+ const output = [result.stdout, result.stderr].filter(Boolean).join("\n").trim();
117
252
  const prefix = result.timedOut
118
253
  ? "timed out"
119
254
  : result.error
120
255
  ? `spawn failed: ${result.error}`
121
256
  : `exit ${result.exitCode ?? "unknown"}`;
122
- return truncate(output ? `${prefix}: ${output}` : prefix, MAX_SUMMARY_LENGTH);
257
+ return truncateMiddle(redactSensitiveText(output ? `${prefix}: ${output}` : prefix), MAX_SUMMARY_LENGTH);
123
258
  }
124
- export async function runParentValidations(ids, cwd, invoke = invokeParentValidation) {
125
- const definitions = resolveParentValidationDefinitions(ids);
259
+ /**
260
+ * Run the configured parent validations in order. Each validation runs with the worktree of its
261
+ * assigned repository as cwd, whether or not that repository changed (to detect breakage of the
262
+ * integration target). A validation assigned to a repository without a worktree in `cwd` fails
263
+ * without spawning anything. Results carry `repo` when the run spans product repositories or the
264
+ * assignment names one, so single-repository evidence keeps its previous shape.
265
+ */
266
+ export async function runParentValidationBatch(entries, cwd, invoke = invokeParentValidation) {
267
+ const assignments = resolveParentValidationAssignments(entries);
268
+ const roots = typeof cwd === "string" ? { project: cwd } : cwd;
269
+ const recordsRepo = Object.keys(roots.repos ?? {}).length > 0 ||
270
+ assignments.some((assignment) => assignment.repo !== PARENT_VALIDATION_PROJECT_REPO);
126
271
  const validations = [];
127
- for (const definition of definitions) {
128
- const result = await invoke(definition, cwd);
272
+ const failureOutputs = [];
273
+ for (const { definition, repo } of assignments) {
274
+ const repoField = recordsRepo ? { repo } : {};
275
+ const root = repo === PARENT_VALIDATION_PROJECT_REPO
276
+ ? roots.project
277
+ : Object.hasOwn(roots.repos ?? {}, repo)
278
+ ? roots.repos?.[repo]
279
+ : undefined;
280
+ if (!root) {
281
+ validations.push({
282
+ id: definition.id,
283
+ source: "runner",
284
+ ...repoField,
285
+ command: definition.displayCommand,
286
+ status: "failed",
287
+ summary: truncateHead(`repository "${repo}" has no worktree for this task; declare it in projects.<project-id>.repos ` +
288
+ `or assign ${definition.id} to another repository in pipeline.parent_validations`, MAX_SUMMARY_LENGTH),
289
+ });
290
+ continue;
291
+ }
292
+ const result = await invoke(definition, root);
293
+ const passed = result.exitCode === 0 && !result.error && !result.timedOut;
129
294
  validations.push({
130
295
  id: definition.id,
131
296
  source: "runner",
297
+ ...repoField,
132
298
  command: definition.displayCommand,
133
- status: result.exitCode === 0 && !result.error && !result.timedOut ? "passed" : "failed",
299
+ status: passed ? "passed" : "failed",
134
300
  summary: validationSummary(result),
135
301
  });
302
+ if (!passed) {
303
+ failureOutputs.push({
304
+ ...result,
305
+ id: definition.id,
306
+ ...(recordsRepo ? { repo } : {}),
307
+ label: assignmentLabel(definition.id, repo),
308
+ });
309
+ }
310
+ }
311
+ return { validations, failureOutputs };
312
+ }
313
+ export async function runParentValidations(entries, cwd, invoke = invokeParentValidation) {
314
+ return (await runParentValidationBatch(entries, cwd, invoke)).validations;
315
+ }
316
+ /** `<id>` or `<repo>:<id>` of a recorded runner validation (no `repo` means the project). */
317
+ export function recordedParentValidationLabel(validation) {
318
+ const id = validation.id ?? validation.command;
319
+ return assignmentLabel(id, validation.repo ?? PARENT_VALIDATION_PROJECT_REPO);
320
+ }
321
+ // 並列の worktree 実行で親検証(vitest など複数 worker を起動するコマンド)が重なると、
322
+ // コンテナの負荷で成果物と無関係なタイムアウトが起きる。既定では 1 つの exec run 内の
323
+ // 親検証を直列化し、executor / reporter の並列性は維持する。
324
+ export const DEFAULT_PARENT_VALIDATION_CONCURRENCY = 1;
325
+ export function resolveParentValidationConcurrency(value) {
326
+ if (value === undefined)
327
+ return DEFAULT_PARENT_VALIDATION_CONCURRENCY;
328
+ if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
329
+ throw new Error(`pipeline.parent_validation_concurrency in exec-defaults must be a positive integer: ${String(value)}`);
330
+ }
331
+ return value;
332
+ }
333
+ export function parentValidationPoolPath(lockRoot) {
334
+ return join(lockRoot, "parent-validation");
335
+ }
336
+ /**
337
+ * Limits how many parent-validation batches run at once within one `exec run` process.
338
+ * Waiters are served in arrival order and each waiting item is logged with the validations it
339
+ * is waiting to run.
340
+ *
341
+ * When `lockRoot` is given, the same limit also holds across the `exec run` processes that share
342
+ * the project's lock directory (a primary run and its `--join` runs): after the in-process slot,
343
+ * the batch takes one of the slot locks under `<lockRoot>/parent-validation/`.
344
+ */
345
+ export class ParentValidationGate {
346
+ limit;
347
+ log;
348
+ lockRoot;
349
+ active = [];
350
+ waiters = [];
351
+ constructor(limit, log = (line) => {
352
+ process.stdout.write(line);
353
+ }, lockRoot) {
354
+ this.limit = limit;
355
+ this.log = log;
356
+ this.lockRoot = lockRoot;
357
+ }
358
+ async run(label, ids, task) {
359
+ await this.acquire(label, ids);
360
+ try {
361
+ if (!this.lockRoot)
362
+ return await task();
363
+ const slot = await acquirePoolSlot(parentValidationPoolPath(this.lockRoot), this.limit, { actor: "parent-validation", label }, {
364
+ onWait: () => this.log(` Waiting for parent validation slot held by another exec run: ${label} (${ids.join(", ")})\n`),
365
+ });
366
+ try {
367
+ return await task();
368
+ }
369
+ finally {
370
+ releaseLock(slot);
371
+ }
372
+ }
373
+ finally {
374
+ this.release(label);
375
+ }
376
+ }
377
+ async acquire(label, ids) {
378
+ if (this.active.length < this.limit) {
379
+ this.active.push(label);
380
+ return;
381
+ }
382
+ this.log(` Waiting for parent validation slot: ${label} (${ids.join(", ")}); running: ${this.active.join(", ")}\n`);
383
+ await new Promise((resolve) => {
384
+ this.waiters.push({ label, resolve });
385
+ });
386
+ this.log(` Parent validation slot acquired: ${label}\n`);
387
+ }
388
+ release(label) {
389
+ const index = this.active.indexOf(label);
390
+ if (index >= 0)
391
+ this.active.splice(index, 1);
392
+ const next = this.waiters.shift();
393
+ if (!next)
394
+ return;
395
+ // Hand the freed slot directly to the oldest waiter so later arrivals cannot overtake it.
396
+ this.active.push(next.label);
397
+ next.resolve();
136
398
  }
137
- return validations;
399
+ }
400
+ // exec-defaults は 1 回の exec run につき 1 度だけ読み込まれ、その run の全項目・全 stage で
401
+ // 同じオブジェクトが共有される。設定オブジェクトをキーにすることで、呼び出し経路へ gate を
402
+ // 引き回さずに run 全体の排他を得る。別プロセスの exec run(主 run と `--join` run)とは、
403
+ // exec-run lock を取得したプロセスが設定する project のロックディレクトリを介して枠を共有する。
404
+ const gatesByConfig = new WeakMap();
405
+ export function parentValidationGateFor(execDefaults, lockRoot = getActiveExecLocksDir()) {
406
+ const existing = gatesByConfig.get(execDefaults);
407
+ if (existing)
408
+ return existing;
409
+ const gate = new ParentValidationGate(resolveParentValidationConcurrency(execDefaults.pipeline?.parent_validation_concurrency), undefined, lockRoot);
410
+ gatesByConfig.set(execDefaults, gate);
411
+ return gate;
138
412
  }
139
413
  export function failedParentValidationReason(validations) {
140
414
  const failed = validations.filter((validation) => validation.source === "runner" && validation.status !== "passed");
141
415
  if (failed.length === 0)
142
416
  return undefined;
143
- return `parent validation failed: ${failed.map((validation) => validation.id ?? validation.command).join(", ")}`;
417
+ return `parent validation failed: ${failed.map(recordedParentValidationLabel).join(", ")}`;
144
418
  }
145
419
  /**
146
420
  * Replaces stale runner-owned validation results while preserving executor-owned evidence.
@@ -158,12 +432,12 @@ export function replaceParentValidationResults(evidence, parentValidations) {
158
432
  ],
159
433
  };
160
434
  }
161
- export function hasRecordedParentValidations(validations, configuredIds) {
162
- const expectedIds = resolveParentValidationDefinitions(configuredIds).map((definition) => definition.id);
163
- const recordedIds = validations
164
- .filter((validation) => validation.source === "runner")
165
- .map((validation) => validation.id)
166
- .filter((id) => typeof id === "string");
167
- return (recordedIds.length === expectedIds.length &&
168
- expectedIds.every((id, index) => recordedIds[index] === id));
435
+ export function hasRecordedParentValidations(validations, configuredEntries) {
436
+ // Compare `<repo>:<id>` pairs so a changed repository assignment re-runs the validations.
437
+ const expectedLabels = parentValidationLabels(configuredEntries);
438
+ const recordedLabels = validations
439
+ .filter((validation) => validation.source === "runner" && typeof validation.id === "string")
440
+ .map(recordedParentValidationLabel);
441
+ return (recordedLabels.length === expectedLabels.length &&
442
+ expectedLabels.every((label, index) => recordedLabels[index] === label));
169
443
  }
@@ -52,6 +52,28 @@ function isStageState(value) {
52
52
  (typeof stage.completed_at === "string" || stage.completed_at === null) &&
53
53
  (typeof stage.artifact_ref === "string" || stage.artifact_ref === null));
54
54
  }
55
+ function isRepoIntegrationState(value) {
56
+ if (!value || typeof value !== "object" || Array.isArray(value))
57
+ return false;
58
+ const repo = value;
59
+ return ((repo.status === "pending" ||
60
+ repo.status === "merged" ||
61
+ repo.status === "unchanged" ||
62
+ repo.status === "failed") &&
63
+ (typeof repo.commit === "string" || repo.commit === null) &&
64
+ (typeof repo.merged_at === "string" || repo.merged_at === null) &&
65
+ (repo.error === undefined || typeof repo.error === "string"));
66
+ }
67
+ function isIntegrateStageState(value) {
68
+ if (!isStageState(value))
69
+ return false;
70
+ const repos = value.repos;
71
+ if (repos === undefined)
72
+ return true;
73
+ if (!repos || typeof repos !== "object" || Array.isArray(repos))
74
+ return false;
75
+ return Object.values(repos).every(isRepoIntegrationState);
76
+ }
55
77
  function isArtifactRefs(value) {
56
78
  if (!value || typeof value !== "object" || Array.isArray(value))
57
79
  return false;
@@ -79,7 +101,7 @@ export function isPipelineState(value) {
79
101
  if (state.artifacts !== undefined && !isArtifactRefs(state.artifacts))
80
102
  return false;
81
103
  const stages = state.stages;
82
- if (stages.integrate !== undefined && !isStageState(stages.integrate))
104
+ if (stages.integrate !== undefined && !isIntegrateStageState(stages.integrate))
83
105
  return false;
84
106
  return isStageState(stages.executor) && isStageState(stages.reporter);
85
107
  }
@@ -101,6 +123,41 @@ export function updatePipelineStage(state, role, patch, updatedAt) {
101
123
  stages[role] = { ...(stages[role] ?? emptyStage()), ...patch };
102
124
  return { ...state, updated_at: updatedAt, stages };
103
125
  }
126
+ /**
127
+ * Record the integration state of one repository under `stages.integrate.repos`. Other repositories
128
+ * and the stage fields are kept; a repository recorded for the first time is appended (so the keys
129
+ * follow the integration order).
130
+ */
131
+ export function updatePipelineRepoIntegration(state, repo, patch, updatedAt) {
132
+ const integrate = state.stages.integrate ?? emptyStage();
133
+ const current = integrate.repos?.[repo] ?? {
134
+ status: "pending",
135
+ commit: null,
136
+ merged_at: null,
137
+ };
138
+ const next = { ...current, ...patch };
139
+ // 成功へ変わった記録に、前回の失敗理由を残さない。
140
+ if (next.status !== "failed" && patch.error === undefined)
141
+ delete next.error;
142
+ return {
143
+ ...state,
144
+ updated_at: updatedAt,
145
+ stages: {
146
+ ...state.stages,
147
+ integrate: { ...integrate, repos: { ...(integrate.repos ?? {}), [repo]: next } },
148
+ },
149
+ };
150
+ }
151
+ /**
152
+ * Names of the repositories recorded as integrated (`merged` or `unchanged`) under
153
+ * `stages.integrate.repos`. A state without per-repository records yields an empty set.
154
+ */
155
+ export function integratedRepoNames(state) {
156
+ const repos = state.stages.integrate?.repos ?? {};
157
+ return new Set(Object.entries(repos)
158
+ .filter(([, entry]) => entry.status === "merged" || entry.status === "unchanged")
159
+ .map(([name]) => name));
160
+ }
104
161
  function resolveArtifactRef(worktreePath, ref) {
105
162
  const root = resolve(worktreePath);
106
163
  const path = resolve(root, ref);
@@ -109,7 +166,7 @@ function resolveArtifactRef(worktreePath, ref) {
109
166
  return null;
110
167
  return path;
111
168
  }
112
- function isSucceededExecutorEvidence(value, taskId, runId) {
169
+ function isExecutorEvidence(value, taskId, runId) {
113
170
  if (!value || typeof value !== "object" || Array.isArray(value))
114
171
  return false;
115
172
  const evidence = value;
@@ -117,7 +174,9 @@ function isSucceededExecutorEvidence(value, taskId, runId) {
117
174
  evidence.task_id === taskId &&
118
175
  evidence.run_id === runId &&
119
176
  evidence.stage?.role === "executor" &&
120
- evidence.stage.status === "succeeded" &&
177
+ (evidence.stage.status === "succeeded" ||
178
+ evidence.stage.status === "failed" ||
179
+ evidence.stage.status === "rate_limited") &&
121
180
  Number.isSafeInteger(evidence.stage.attempts) &&
122
181
  evidence.stage.attempts >= 1);
123
182
  }
@@ -141,18 +200,24 @@ export function loadPipelineResumeCheckpoint(input) {
141
200
  .split(sep)
142
201
  .join("/")
143
202
  : null);
144
- if ((state.stages.executor.status !== "succeeded" && state.stages.executor.status !== "running") ||
145
- !evidenceRef) {
203
+ if (!evidenceRef)
146
204
  return { state, statePath };
147
- }
148
205
  const evidencePath = resolveArtifactRef(input.worktreePath, evidenceRef);
149
206
  if (!evidencePath || !existsSync(evidencePath))
150
207
  return { state, statePath };
151
208
  try {
152
209
  const evidence = JSON.parse(readFileSync(evidencePath, "utf8"));
153
- return isSucceededExecutorEvidence(evidence, input.taskId, state.run_id)
154
- ? { state, statePath, evidence }
155
- : { state, statePath };
210
+ if (!isExecutorEvidence(evidence, input.taskId, state.run_id))
211
+ return { state, statePath };
212
+ return {
213
+ state,
214
+ statePath,
215
+ executorEvidence: evidence,
216
+ ...(evidence.stage.status === "succeeded" &&
217
+ (state.stages.executor.status === "succeeded" || state.stages.executor.status === "running")
218
+ ? { evidence }
219
+ : {}),
220
+ };
156
221
  }
157
222
  catch {
158
223
  return { state, statePath };