@bonesofspring/ai-rules 0.2.35 → 0.2.37

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 (201) hide show
  1. package/bin/lib/merged-config.js +9 -0
  2. package/bin/opencode-install.js +46 -1
  3. package/package.json +4 -1
  4. package/presets/_shared/hooks/README.md +137 -0
  5. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +1288 -0
  6. package/presets/claude/android-kotlin/MCP.md +2 -2
  7. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +171 -10
  8. package/presets/claude/android-kotlin/mcp.json +1 -1
  9. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +6 -153
  10. package/presets/claude/android-kotlin/team/README.md +2 -6
  11. package/presets/claude/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
  12. package/presets/claude/go/MCP.md +2 -2
  13. package/presets/claude/go/hooks/chain-team-phases.sh +183 -16
  14. package/presets/claude/go/mcp.json +1 -1
  15. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +6 -11
  16. package/presets/claude/go/team/README.md +2 -6
  17. package/presets/claude/ios-swift/MCP.md +2 -2
  18. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +178 -17
  19. package/presets/claude/ios-swift/mcp.json +1 -1
  20. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +6 -153
  21. package/presets/claude/ios-swift/team/README.md +2 -6
  22. package/presets/claude/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
  23. package/presets/claude/java/hooks/chain-team-phases.sh +183 -16
  24. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +6 -28
  25. package/presets/claude/java/team/README.md +2 -6
  26. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +182 -13
  27. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +6 -14
  28. package/presets/claude/mcp-ts/team/README.md +2 -6
  29. package/presets/claude/next/MCP.md +2 -2
  30. package/presets/claude/next/commands/task.md +5 -3
  31. package/presets/claude/next/hooks/chain-team-phases.sh +102 -6
  32. package/presets/claude/next/mcp.json +1 -1
  33. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +6 -226
  34. package/presets/claude/next/team/README.md +2 -6
  35. package/presets/claude/next/team/fixtures/artifact-manifest.example.json +1 -0
  36. package/presets/claude/nuxt/MCP.md +2 -2
  37. package/presets/claude/nuxt/hooks/chain-team-phases.sh +148 -7
  38. package/presets/claude/nuxt/mcp.json +1 -1
  39. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +6 -223
  40. package/presets/claude/nuxt/team/README.md +2 -6
  41. package/presets/claude/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
  42. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +183 -16
  43. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +6 -28
  44. package/presets/claude/php-hexagonal/team/README.md +2 -6
  45. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +183 -16
  46. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +6 -29
  47. package/presets/claude/php-laravel/team/README.md +2 -6
  48. package/presets/claude/svelte/MCP.md +2 -2
  49. package/presets/claude/svelte/hooks/chain-team-phases.sh +148 -7
  50. package/presets/claude/svelte/mcp.json +1 -1
  51. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +6 -223
  52. package/presets/claude/svelte/team/README.md +2 -6
  53. package/presets/claude/svelte/team/fixtures/artifact-manifest.example.json +1 -0
  54. package/presets/cursor/android-kotlin/MCP.md +2 -2
  55. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +150 -7
  56. package/presets/cursor/android-kotlin/mcp.json +1 -1
  57. package/presets/cursor/android-kotlin/team/README.md +2 -0
  58. package/presets/cursor/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
  59. package/presets/cursor/go/MCP.md +2 -2
  60. package/presets/cursor/go/hooks/chain-team-phases.sh +175 -8
  61. package/presets/cursor/go/mcp.json +1 -1
  62. package/presets/cursor/go/team/README.md +2 -0
  63. package/presets/cursor/ios-swift/MCP.md +2 -2
  64. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +150 -7
  65. package/presets/cursor/ios-swift/mcp.json +1 -1
  66. package/presets/cursor/ios-swift/team/README.md +2 -0
  67. package/presets/cursor/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
  68. package/presets/cursor/java/hooks/chain-team-phases.sh +175 -8
  69. package/presets/cursor/java/team/README.md +2 -0
  70. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +179 -10
  71. package/presets/cursor/mcp-ts/team/README.md +2 -0
  72. package/presets/cursor/next/MCP.md +2 -2
  73. package/presets/cursor/next/commands/task.md +5 -3
  74. package/presets/cursor/next/hooks/chain-team-phases.sh +99 -5
  75. package/presets/cursor/next/mcp.json +1 -1
  76. package/presets/cursor/next/team/README.md +2 -0
  77. package/presets/cursor/next/team/fixtures/artifact-manifest.example.json +1 -0
  78. package/presets/cursor/nuxt/MCP.md +2 -2
  79. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +145 -6
  80. package/presets/cursor/nuxt/mcp.json +1 -1
  81. package/presets/cursor/nuxt/team/README.md +2 -0
  82. package/presets/cursor/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
  83. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +175 -8
  84. package/presets/cursor/php-hexagonal/team/README.md +2 -0
  85. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +175 -8
  86. package/presets/cursor/php-laravel/team/README.md +2 -0
  87. package/presets/cursor/svelte/MCP.md +2 -2
  88. package/presets/cursor/svelte/hooks/chain-team-phases.sh +145 -6
  89. package/presets/cursor/svelte/mcp.json +1 -1
  90. package/presets/cursor/svelte/team/README.md +2 -0
  91. package/presets/cursor/svelte/team/fixtures/artifact-manifest.example.json +1 -0
  92. package/presets/mavis/android-kotlin/MCP.md +2 -2
  93. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  94. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +150 -7
  95. package/presets/mavis/android-kotlin/mcp.json +1 -1
  96. package/presets/mavis/android-kotlin/team/README.md +2 -0
  97. package/presets/mavis/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
  98. package/presets/mavis/go/MCP.md +2 -2
  99. package/presets/mavis/go/adapter-map.json +1 -1
  100. package/presets/mavis/go/hooks/chain-team-phases.sh +175 -8
  101. package/presets/mavis/go/mcp.json +1 -1
  102. package/presets/mavis/go/team/README.md +2 -0
  103. package/presets/mavis/ios-swift/MCP.md +2 -2
  104. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  105. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +150 -7
  106. package/presets/mavis/ios-swift/mcp.json +1 -1
  107. package/presets/mavis/ios-swift/team/README.md +2 -0
  108. package/presets/mavis/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
  109. package/presets/mavis/java/adapter-map.json +1 -1
  110. package/presets/mavis/java/hooks/chain-team-phases.sh +175 -8
  111. package/presets/mavis/java/team/README.md +2 -0
  112. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  113. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +179 -10
  114. package/presets/mavis/mcp-ts/team/README.md +2 -0
  115. package/presets/mavis/next/MCP.md +2 -2
  116. package/presets/mavis/next/adapter-map.json +1 -1
  117. package/presets/mavis/next/commands/task.md +5 -3
  118. package/presets/mavis/next/hooks/chain-team-phases.sh +99 -5
  119. package/presets/mavis/next/mcp.json +1 -1
  120. package/presets/mavis/next/team/README.md +2 -0
  121. package/presets/mavis/next/team/fixtures/artifact-manifest.example.json +1 -0
  122. package/presets/mavis/nuxt/MCP.md +2 -2
  123. package/presets/mavis/nuxt/adapter-map.json +1 -1
  124. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +145 -6
  125. package/presets/mavis/nuxt/mcp.json +1 -1
  126. package/presets/mavis/nuxt/team/README.md +2 -0
  127. package/presets/mavis/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
  128. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  129. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +175 -8
  130. package/presets/mavis/php-hexagonal/team/README.md +2 -0
  131. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  132. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +175 -8
  133. package/presets/mavis/php-laravel/team/README.md +2 -0
  134. package/presets/mavis/svelte/MCP.md +2 -2
  135. package/presets/mavis/svelte/adapter-map.json +1 -1
  136. package/presets/mavis/svelte/hooks/chain-team-phases.sh +145 -6
  137. package/presets/mavis/svelte/mcp.json +1 -1
  138. package/presets/mavis/svelte/team/README.md +2 -0
  139. package/presets/mavis/svelte/team/fixtures/artifact-manifest.example.json +1 -0
  140. package/presets/opencode/android-kotlin/MCP.md +2 -2
  141. package/presets/opencode/android-kotlin/OPENCODE.md +6 -4
  142. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  143. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +150 -7
  144. package/presets/opencode/android-kotlin/opencode.json +13 -1
  145. package/presets/opencode/android-kotlin/team/README.md +2 -0
  146. package/presets/opencode/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
  147. package/presets/opencode/go/MCP.md +2 -2
  148. package/presets/opencode/go/OPENCODE.md +6 -4
  149. package/presets/opencode/go/adapter-map.json +1 -1
  150. package/presets/opencode/go/hooks/chain-team-phases.sh +175 -8
  151. package/presets/opencode/go/opencode.json +13 -1
  152. package/presets/opencode/go/team/README.md +2 -0
  153. package/presets/opencode/ios-swift/MCP.md +2 -2
  154. package/presets/opencode/ios-swift/OPENCODE.md +6 -4
  155. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  156. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +150 -7
  157. package/presets/opencode/ios-swift/opencode.json +13 -1
  158. package/presets/opencode/ios-swift/team/README.md +2 -0
  159. package/presets/opencode/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
  160. package/presets/opencode/java/OPENCODE.md +6 -4
  161. package/presets/opencode/java/adapter-map.json +1 -1
  162. package/presets/opencode/java/hooks/chain-team-phases.sh +175 -8
  163. package/presets/opencode/java/opencode.json +12 -0
  164. package/presets/opencode/java/team/README.md +2 -0
  165. package/presets/opencode/mcp-ts/OPENCODE.md +6 -4
  166. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  167. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +179 -10
  168. package/presets/opencode/mcp-ts/opencode.json +12 -0
  169. package/presets/opencode/mcp-ts/team/README.md +2 -0
  170. package/presets/opencode/next/MCP.md +2 -2
  171. package/presets/opencode/next/OPENCODE.md +6 -4
  172. package/presets/opencode/next/adapter-map.json +1 -1
  173. package/presets/opencode/next/commands/task.md +5 -3
  174. package/presets/opencode/next/hooks/chain-team-phases.sh +99 -5
  175. package/presets/opencode/next/opencode.json +13 -1
  176. package/presets/opencode/next/team/README.md +2 -0
  177. package/presets/opencode/next/team/fixtures/artifact-manifest.example.json +1 -0
  178. package/presets/opencode/nuxt/MCP.md +2 -2
  179. package/presets/opencode/nuxt/OPENCODE.md +6 -4
  180. package/presets/opencode/nuxt/adapter-map.json +1 -1
  181. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +145 -6
  182. package/presets/opencode/nuxt/opencode.json +13 -1
  183. package/presets/opencode/nuxt/team/README.md +2 -0
  184. package/presets/opencode/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
  185. package/presets/opencode/php-hexagonal/OPENCODE.md +6 -4
  186. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  187. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +175 -8
  188. package/presets/opencode/php-hexagonal/opencode.json +12 -0
  189. package/presets/opencode/php-hexagonal/team/README.md +2 -0
  190. package/presets/opencode/php-laravel/OPENCODE.md +6 -4
  191. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  192. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +175 -8
  193. package/presets/opencode/php-laravel/opencode.json +12 -0
  194. package/presets/opencode/php-laravel/team/README.md +2 -0
  195. package/presets/opencode/svelte/MCP.md +2 -2
  196. package/presets/opencode/svelte/OPENCODE.md +6 -4
  197. package/presets/opencode/svelte/adapter-map.json +1 -1
  198. package/presets/opencode/svelte/hooks/chain-team-phases.sh +145 -6
  199. package/presets/opencode/svelte/opencode.json +13 -1
  200. package/presets/opencode/svelte/team/README.md +2 -0
  201. package/presets/opencode/svelte/team/fixtures/artifact-manifest.example.json +1 -0
@@ -155,7 +155,21 @@ function mutateMetrics(mutator) {
155
155
  try { metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8')); } catch {
156
156
  const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
157
157
  status.metricsRunId = runId;
158
- metrics = { schemaVersion: 1, task: { runId, slug, preset: 'ai-rules', stack: STACK, platform: PLATFORM, intent: status.intent || 'unknown', profile: 'unknown' }, events: [] };
158
+ // Resolve profile from pipeline.json (preferred) or status.json, falling back to 'unknown'.
159
+ // The router/agent must never write profile into status.json — pipeline.json is the SoT.
160
+ let profile = 'unknown';
161
+ try {
162
+ if (fs.existsSync(pipelinePath)) {
163
+ const pipe = JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
164
+ if (pipe && (pipe.profile === 'light' || pipe.profile === 'standard' || pipe.profile === 'full')) {
165
+ profile = pipe.profile;
166
+ }
167
+ }
168
+ } catch {}
169
+ if (profile === 'unknown' && (status.profile === 'light' || status.profile === 'standard' || status.profile === 'full')) {
170
+ profile = status.profile;
171
+ }
172
+ metrics = { schemaVersion: 1, task: { runId, slug, preset: 'ai-rules', stack: STACK, platform: PLATFORM, intent: status.intent || 'unknown', profile }, events: [] };
159
173
  metrics.events.push({ eventId: `${runId}:task_started`, type: 'task_started', at: now, source: 'hook', attributionConfidence: 'high' });
160
174
  }
161
175
  mutator(metrics);
@@ -226,21 +240,119 @@ function resolvedAttempt() {
226
240
  const active = status.activeAttempts || {}; const entries = Object.entries(active);
227
241
  const stableAttemptId = hookInput.attemptId;
228
242
  if (stableAttemptId) {
229
- return active[stableAttemptId] ? { attemptId: stableAttemptId, entry: active[stableAttemptId], confidence: 'high' } : null;
243
+ return active[stableAttemptId]
244
+ ? { attemptId: stableAttemptId, entry: active[stableAttemptId], confidence: 'high' }
245
+ : null;
230
246
  }
231
247
  if (entries.length === 1) return { attemptId: entries[0][0], entry: entries[0][1], confidence: 'high' };
232
248
  try { const receipts = JSON.parse(fs.readFileSync(path.join(taskDir, '.metrics-receipts.json'), 'utf8')); const receipt = Array.isArray(receipts) ? receipts.find((item) => active[item.attemptId]) : null; if (receipt) return { attemptId: receipt.attemptId, entry: active[receipt.attemptId], confidence: 'fallback', source: 'agent' }; } catch {}
233
249
  return null;
234
250
  }
251
+ let artifactStallMessage = null;
252
+
253
+ // A1: seed the manifest a modern pipeline expects instead of advancing without
254
+ // one. Exclusive publish via hard link so a producer that wrote the file in the
255
+ // meantime is never overwritten; returns null on success (or when the file
256
+ // appeared) and the fs error otherwise.
257
+ function writeSkeletonManifest(manifestPath) {
258
+ const temporary = `${manifestPath}.${process.pid}.${Date.now()}.seed`;
259
+ const body = JSON.stringify({ schemaVersion: 1, slug, artifacts: [] }, null, 2) + '\n';
260
+ let descriptor = null;
261
+ try {
262
+ descriptor = fs.openSync(temporary, 'wx');
263
+ try { fs.writeSync(descriptor, body); try { fs.fsyncSync(descriptor); } catch {} } finally { fs.closeSync(descriptor); descriptor = null; }
264
+ fs.linkSync(temporary, manifestPath);
265
+ fs.unlinkSync(temporary);
266
+ return null;
267
+ } catch (error) {
268
+ if (descriptor !== null) { try { fs.closeSync(descriptor); } catch {} }
269
+ try { fs.unlinkSync(temporary); } catch {}
270
+ if (error && error.code === 'EEXIST' && fs.existsSync(manifestPath)) return null;
271
+ return String(error && error.message ? error.message : error);
272
+ }
273
+ }
274
+
275
+ // A2: a `completed` receipt must cite evidence the harness can inspect. Order is
276
+ // the message order — the first failing predicate wins, so the operator sees one
277
+ // actionable line. `authoritativePaths[]` stays task-dir-relative; external
278
+ // references belong in `evidencePaths[]`.
279
+ function validateCompletedArtifact(entry) {
280
+ const artifactId = entry && entry.id ? entry.id : '(unnamed)';
281
+ const entryStatus = entry && entry.status;
282
+ if (entryStatus !== 'completed') {
283
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" has receipt.outcome "completed" but entry status "${entryStatus}". Make entry.status and receipt.outcome agree, then resume with: /task-continue ${slug}`;
284
+ }
285
+ const authoritativePaths = entry && Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths : [];
286
+ if (authoritativePaths.length === 0) {
287
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" is "completed" but authoritativePaths[] is empty. Record at least one file you produced under .ai.local/team/tasks/${slug}/, then resume with: /task-continue ${slug}`;
288
+ }
289
+ for (const cited of authoritativePaths) {
290
+ const value = typeof cited === 'string' ? cited.trim() : '';
291
+ const resolvedPath = value ? path.resolve(taskDir, value) : taskDir;
292
+ const relative = path.relative(taskDir, resolvedPath);
293
+ const escapes = !value || path.isAbsolute(value) || relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative);
294
+ if (escapes) {
295
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" cites "${value}", which resolves outside .ai.local/team/tasks/${slug}/ (relative: "${relative}"). Cite a task-relative path; keep external references in evidencePaths[]. Then resume with: /task-continue ${slug}`;
296
+ }
297
+ let stat = null;
298
+ try { stat = fs.statSync(resolvedPath); } catch {}
299
+ if (!stat || !stat.isFile()) {
300
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" cites "${value}" but no such file exists under .ai.local/team/tasks/${slug}/. Write the file, then resume with: /task-continue ${slug}`;
301
+ }
302
+ if (/\.md[c]?$/i.test(value)) {
303
+ let content = '';
304
+ try { content = fs.readFileSync(resolvedPath, 'utf8'); } catch {}
305
+ if (!/\S/.test(content)) {
306
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" is "completed" but authoritative path "${value}" has no non-whitespace content. Produce the artifact, then resume with: /task-continue ${slug}`;
307
+ }
308
+ }
309
+ }
310
+ return null;
311
+ }
312
+
235
313
  function readBoundReceiptOutcome(agent, step, resolved) {
236
314
  if (!agent || !resolved) return { outcome: null, receiptRequired: false };
237
315
  const manifestPath = path.join(taskDir, 'artifact-manifest.json');
238
- if (!fs.existsSync(manifestPath)) return { outcome: null, receiptRequired: false };
316
+ const expectedOutputId = artifactOutputIdFor(step, agent);
317
+ if (!fs.existsSync(manifestPath)) {
318
+ // A1: absent manifest + a parsed modern pipeline denies silent advancement.
319
+ // Legacy/step-less pipelines keep their previous behaviour (legacyFlow owns them).
320
+ if (!(Array.isArray(steps) && steps.length > 0)) return { outcome: null, receiptRequired: false };
321
+ const seeded = writeSkeletonManifest(manifestPath);
322
+ const stepIndex = typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : 0;
323
+ if (seeded) {
324
+ return { outcome: null, receiptRequired: true, stallMessage: `[chain-team-phases] ${slug}: artifact-manifest.json is missing and the skeleton could not be written (${seeded}). Create .ai.local/team/tasks/${slug}/artifact-manifest.json with {schemaVersion:1, slug, artifacts:[]}, add the receipt for artifactOutputId "${expectedOutputId}", then resume with: /task-continue ${slug}` };
325
+ }
326
+ return { outcome: null, receiptRequired: true, stallMessage: `[chain-team-phases] ${slug}: no artifact-manifest.json for step ${stepIndex} (${agent}). Wrote a skeleton {schemaVersion:1, slug, artifacts:[]}. Expected artifactOutputId "${expectedOutputId}". Write the artifact and its receipt, then resume with: /task-continue ${slug}` };
327
+ }
239
328
  try {
240
329
  const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
330
+ // Guard: the schema key is `artifacts` (see agent-artifact-contracts.md). A top-level
331
+ // `entries` key is a silent bug — producer wrote to a wrong field, hook would not
332
+ // see the receipt, and the step hangs in `awaiting_artifact_receipt`. Warn loudly.
333
+ if (manifest && typeof manifest === 'object' && !Array.isArray(manifest.artifacts) && Array.isArray(manifest.entries)) {
334
+ process.stderr.write(`WARNING: ${manifestPath} has top-level "entries" but no "artifacts" array; reading only "artifacts" per schema. The producer likely upserted into the wrong key. See agent-artifact-contracts.md (Schema field name).` + '\n');
335
+ } else if (manifest && typeof manifest === 'object' && Array.isArray(manifest.entries) && Array.isArray(manifest.artifacts)) {
336
+ process.stderr.write(`WARNING: ${manifestPath} has both "artifacts" and "entries" keys; reading only "artifacts" per schema. Foreign "entries" content is ignored.` + '\n');
337
+ }
241
338
  const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
242
- const expectedOutputId = artifactOutputIdFor(step, agent);
243
339
  const attemptStartedAt = Date.parse(resolved.entry.startedAt);
340
+ // Pre-scan: warn on the silent-bug classes the filter below would otherwise drop.
341
+ // A receipt with a non-matching attemptId is dropped silently; without this warning,
342
+ // the step hangs in `awaiting_artifact_receipt` with no signal of why. Same for
343
+ // receipts whose terminal timestamp is older than the active attempt (stale retry).
344
+ const activeIds = new Set(Object.keys(status.activeAttempts || {}));
345
+ for (const entry of artifacts) {
346
+ if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') continue;
347
+ const rid = entry.receipt.attemptId;
348
+ if (typeof rid === 'string' && rid !== resolved.attemptId && !activeIds.has(rid)) {
349
+ process.stderr.write(`WARNING: ${manifestPath} receipt for producer "${agent}" id "${entry.id}" carries attemptId "${rid}" that does not match the active attempt "${resolved.attemptId}". The receipt is being dropped; step will hang in \`awaiting_artifact_receipt\` unless the producer retries. Common cause: agent reused an attemptId from a prior failed attempt. See agent-artifact-contracts.md (Receipt binding).` + '\n');
350
+ }
351
+ const terminalAt = Date.parse(entry.timestamps?.completedAt || entry.timestamps?.updatedAt || '');
352
+ if (Number.isFinite(attemptStartedAt) && Number.isFinite(terminalAt) && terminalAt < attemptStartedAt) {
353
+ process.stderr.write(`WARNING: ${manifestPath} receipt for producer "${agent}" id "${entry.id}" has timestamps.completedAt older than the active attempt's startedAt. Likely a stale receipt from a previous attempt; it is being dropped. See agent-artifact-contracts.md (Receipt binding).` + '\n');
354
+ }
355
+ }
244
356
  const owned = artifacts
245
357
  .filter((entry) => {
246
358
  if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') return false;
@@ -255,19 +367,33 @@ function readBoundReceiptOutcome(agent, step, resolved) {
255
367
  const tb = Date.parse(b.timestamps?.completedAt || b.timestamps?.updatedAt || 0) || 0;
256
368
  return tb - ta;
257
369
  });
258
- return { outcome: owned[0]?.receipt?.outcome || null, receiptRequired: true };
370
+ // Bonus: warn if the active attempt's receipts all lack attemptId in a non-parallel step.
371
+ // The orchestrator always provides attemptId, so a missing one means the agent dropped it
372
+ // (model output, JSON.stringify omission, etc.). boundByOutput still binds the receipt by
373
+ // expectedOutputId, so this is not fatal — but it is a contract violation worth flagging.
374
+ if (owned.length > 0 && owned[0].receipt.attemptId == null && !(step && step.parallel && Array.isArray(getStepAgents(step)) && getStepAgents(step).length > 1)) {
375
+ process.stderr.write(`WARNING: ${manifestPath} receipt for producer "${agent}" id "${owned[0].id}" lacks entry.receipt.attemptId on a non-parallel step. The receipt is bound by output-id fallback; the agent should always include the attemptId the orchestrator provides. See agent-artifact-contracts.md (Receipt binding).` + '\n');
376
+ }
377
+ const outcome = owned[0]?.receipt?.outcome || null;
378
+ if (outcome === 'completed') {
379
+ const stallMessage = validateCompletedArtifact(owned[0]);
380
+ if (stallMessage) return { outcome: null, receiptRequired: true, stallMessage };
381
+ }
382
+ return { outcome, receiptRequired: true };
259
383
  } catch {
260
384
  return { outcome: null, receiptRequired: false };
261
385
  }
262
386
  }
263
387
  function reconcileStatusFromManifest(agent, step, resolved) {
264
388
  const terminal = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
265
- const { outcome, receiptRequired } = readBoundReceiptOutcome(agent, step, resolved);
389
+ artifactStallMessage = null;
390
+ const { outcome, receiptRequired, stallMessage } = readBoundReceiptOutcome(agent, step, resolved);
266
391
  if (terminal.has(outcome)) {
267
392
  status.state = outcome;
268
393
  return outcome;
269
394
  }
270
395
  if (receiptRequired) {
396
+ artifactStallMessage = stallMessage || null;
271
397
  status.state = 'awaiting_artifact_receipt';
272
398
  status.phase = 'blocked';
273
399
  return status.state;
@@ -326,6 +452,15 @@ function out(message) {
326
452
  process.stdout.write(JSON.stringify({ followup_message: message }));
327
453
  }
328
454
 
455
+ // The stall text always reaches stderr so a second, different rejection is never
456
+ // silent; `out()` fires only when the stop enters the stall, so the follow-up
457
+ // message cannot loop.
458
+ function emitArtifactStall(message, announce) {
459
+ if (message) process.stderr.write(message + '\n');
460
+ if (message && announce) out(message);
461
+ else process.stdout.write('{}');
462
+ }
463
+
329
464
  function readArtifact(name) {
330
465
  const p = path.join(taskDir, name);
331
466
  if (!fs.existsSync(p)) return '';
@@ -625,11 +760,11 @@ const AGENT_HANDOFF = {
625
760
 
626
761
  const REVIEW_AGENTS = new Set([
627
762
  'code-reviewer',
763
+ 'accessibility-reviewer',
628
764
  'security-reviewer',
629
765
  'api-contract-reviewer',
630
766
  ]);
631
767
 
632
-
633
768
  function metricsHandoff(agent) {
634
769
  const matches = Object.entries(status.activeAttempts || {}).filter(([, entry]) => entry.agent === agent);
635
770
  if (matches.length === 1) {
@@ -903,10 +1038,11 @@ const completingAgentHint = (() => {
903
1038
  return getStepAgents(initialStep)[0];
904
1039
  })();
905
1040
  const reconcilingAttempt = resolvedAttempt();
1041
+ const wasWaitingForReceipt = status.state === 'awaiting_artifact_receipt';
906
1042
  reconcileStatusFromManifest(completingAgentHint, initialStep, reconcilingAttempt);
907
1043
  if (status.state === 'awaiting_artifact_receipt') {
908
1044
  writeStatus({});
909
- process.stdout.write('{}');
1045
+ emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
910
1046
  process.exit(0);
911
1047
  }
912
1048
  let finishedAttempt = finishActiveAttempt();
@@ -916,6 +1052,11 @@ if (!finishedAttempt && activeAttemptCountBeforeFinish > 0) {
916
1052
  if (repaired) {
917
1053
  appendMetric({ type: 'parallel_attribution_repair', at: now, attemptIds: [repaired.attemptId], source: 'hook', attributionConfidence: 'fallback' });
918
1054
  reconcileStatusFromManifest(repaired.entry.agent, steps[repaired.entry.stepIndex], repaired);
1055
+ if (status.state === 'awaiting_artifact_receipt') {
1056
+ writeStatus({});
1057
+ emitArtifactStall(artifactStallMessage, true);
1058
+ process.exit(0);
1059
+ }
919
1060
  finishedAttempt = finishActiveAttempt(repaired);
920
1061
  } else {
921
1062
  writeStatus({});
@@ -972,6 +1113,7 @@ const waveIndexes = activeWave
972
1113
  ? [idx]
973
1114
  : (isGraphMode() && finishedAttempt ? [completedStepIndex] : null));
974
1115
 
1116
+
975
1117
  if (waveIndexes) {
976
1118
  const waveAgents = waveIndexes.flatMap((i) => getStepAgents(steps[i]));
977
1119
  const done = [...(status.parallelCompleted || [])];
@@ -1024,6 +1166,20 @@ if (waveIndexes) {
1024
1166
  }
1025
1167
 
1026
1168
  const retryReviewer = waveAgents.find((agent) => outcomes[agent]?.outcome === 'changes_requested');
1169
+ if (retryReviewer === 'mockup-reviewer') {
1170
+ beginHumanGate();
1171
+ writeStatus({
1172
+ awaitingHumanGate: true,
1173
+ state: 'awaiting_approval',
1174
+ currentAgent: 'mockup-reviewer',
1175
+ parallelCompleted: [],
1176
+ parallelOutcomes: {},
1177
+ waveSteps: [],
1178
+ waveId: null,
1179
+ });
1180
+ out(`Mockup review FAIL for slug "${slug}". Read mockup-review.md. Resume only via /task-continue. Do not retry feature-developer.`);
1181
+ process.exit(0);
1182
+ }
1027
1183
  if (retryReviewer) {
1028
1184
  if (isGraphMode()) {
1029
1185
  const reviewerStepIndex = waveIndexes.find((i) => getStepAgents(steps[i]).includes(retryReviewer));
@@ -1130,6 +1286,17 @@ if (status.state === 'blocked') {
1130
1286
  process.exit(0);
1131
1287
  }
1132
1288
 
1289
+ if (status.state === 'changes_requested' && (completedAgent === 'mockup-reviewer' || status.currentAgent === 'mockup-reviewer')) {
1290
+ beginHumanGate();
1291
+ writeStatus({
1292
+ awaitingHumanGate: true,
1293
+ state: 'awaiting_approval',
1294
+ currentAgent: 'mockup-reviewer',
1295
+ });
1296
+ out(`Mockup review FAIL for slug "${slug}". Read mockup-review.md. Resume only via /task-continue. Do not retry feature-developer.`);
1297
+ process.exit(0);
1298
+ }
1299
+
1133
1300
  if (status.state === 'changes_requested') {
1134
1301
  const reviewer = status.currentAgent || finishedAttempt?.entry?.agent;
1135
1302
  if (!reviewer) {
@@ -14,6 +14,18 @@
14
14
  "git push *": "deny"
15
15
  }
16
16
  },
17
+ "policies": [
18
+ {
19
+ "action": "tool.use",
20
+ "resource": "shell:git commit *",
21
+ "effect": "deny"
22
+ },
23
+ {
24
+ "action": "tool.use",
25
+ "resource": "shell:git push *",
26
+ "effect": "deny"
27
+ }
28
+ ],
17
29
  "mcp": {
18
30
  "context7": {
19
31
  "type": "local",
@@ -86,6 +86,8 @@ Same JSON on Claude, Mavis, or OpenCode: `bash .<tool>/hooks/chain-team-phases.s
86
86
 
87
87
  ## Contracts
88
88
 
89
+ - **Manifest field name:** receipts go in `artifacts[]`. Anything written under `entries` is ignored — the hook reads only `artifacts` and prints a dual-read warning naming the file. See `agent-team/agent-artifact-contracts.md` § Schema field name.
90
+ - **Evidence paths:** `authoritativePaths[]` must be task-relative (`.ai.local/team/tasks/<slug>/…`). Put anything outside the task directory — e.g. `openspec/changes/**` — in `evidencePaths[]`.
89
91
  - Manifest schema: shared core `agent-team/agent-artifact-contracts.md`. Read it first; producers upsert only their IDs.
90
92
  - Metrics: append-only allowlisted events — `agent-team/agent-task-metrics.md`. Aggregate: `node node_modules/@bonesofspring/ai-rules/scripts/aggregate-agent-task-metrics.mjs --team-root .ai.local/team`.
91
93
  - Commit `.ai.local/team/` templates (and slugs if you want them in clones).
@@ -34,10 +34,12 @@ See `.opencode/rules/README.md` for the full catalog and loading strategy.
34
34
  ## Harness wiring
35
35
 
36
36
  - `opencode.json` carries a compact `instructions` list (always-on rule
37
- paths + `.opencode/AGENTS.md`) and a harness-level `permission.bash`
38
- block. On re-init, `mergeOpencodeConfig` unions preset instruction paths
39
- into the consumer list and fills missing bash keys. Extra paths and
40
- same-key overrides stay.
37
+ paths + `.opencode/AGENTS.md`), a harness-level `permission.bash`
38
+ block, and a top-level `policies` hard-deny — `git commit`/`git push`
39
+ are non-overridable, even by an `allow` rule or a saved `Always allow`
40
+ approval. On re-init, `mergeOpencodeConfig` unions preset instruction
41
+ paths into the consumer list and fills missing bash keys and policy
42
+ statements. Extra paths and same-key overrides stay.
41
43
  - **Subagent rules** are re-declared inside every `.opencode/agents/*.md`
42
44
  via the `## Rules to load (subagent context)` block (always-on + zone
43
45
  rules filtered to stems that exist for this stack). `Task`-launched
@@ -3,7 +3,7 @@
3
3
  "platform": "opencode",
4
4
  "stack": "mcp-ts",
5
5
  "semanticSource": "cursor/mcp-ts",
6
- "sourceRevision": "4de8fc526390531c9cbfdb71eeed5e1b871a93be49df28afd740c7df03466172",
6
+ "sourceRevision": "872f67267898bb1dd8618084ac93c240bdb588c60ea50d8a9654c545c7b4fea2",
7
7
  "entries": [
8
8
  {
9
9
  "source": "AGENTS.md",
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
  # preset: mcp-ts (TypeScript MCP) — chain handoffs use build-verifier + security-reviewer; no contract-test-*
3
+ # mcp-ts Phase-1 chain: validation via typecheck/tests + security-reviewer (no contract-test-* handoffs)
4
+ # Phase-2 reserved: debugger / ci-investigator are not in mcp-ts Phase 1 roster.
3
5
  # Chains agent team steps from pipeline.json after subagentStop.
4
6
  # Falls back to legacy phase-based flow when pipeline.json is absent.
5
7
 
@@ -12,7 +14,6 @@ const fs = require('fs');
12
14
  const path = require('path');
13
15
  const crypto = require('crypto');
14
16
 
15
- // mcp-ts Phase-1 chain: validation via typecheck/tests + security-reviewer (no contract-test-* handoffs)
16
17
  const TEAM_ROOT = path.join(process.cwd(), '.ai.local', 'team');
17
18
 
18
19
  const inputRaw = process.env.INPUT || '';
@@ -156,7 +157,21 @@ function mutateMetrics(mutator) {
156
157
  try { metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8')); } catch {
157
158
  const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
158
159
  status.metricsRunId = runId;
159
- metrics = { schemaVersion: 1, task: { runId, slug, preset: 'ai-rules', stack: STACK, platform: PLATFORM, intent: status.intent || 'unknown', profile: 'unknown' }, events: [] };
160
+ // Resolve profile from pipeline.json (preferred) or status.json, falling back to 'unknown'.
161
+ // The router/agent must never write profile into status.json — pipeline.json is the SoT.
162
+ let profile = 'unknown';
163
+ try {
164
+ if (fs.existsSync(pipelinePath)) {
165
+ const pipe = JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
166
+ if (pipe && (pipe.profile === 'light' || pipe.profile === 'standard' || pipe.profile === 'full')) {
167
+ profile = pipe.profile;
168
+ }
169
+ }
170
+ } catch {}
171
+ if (profile === 'unknown' && (status.profile === 'light' || status.profile === 'standard' || status.profile === 'full')) {
172
+ profile = status.profile;
173
+ }
174
+ metrics = { schemaVersion: 1, task: { runId, slug, preset: 'ai-rules', stack: STACK, platform: PLATFORM, intent: status.intent || 'unknown', profile }, events: [] };
160
175
  metrics.events.push({ eventId: `${runId}:task_started`, type: 'task_started', at: now, source: 'hook', attributionConfidence: 'high' });
161
176
  }
162
177
  mutator(metrics);
@@ -213,21 +228,119 @@ function resolvedAttempt() {
213
228
  const active = status.activeAttempts || {}; const entries = Object.entries(active);
214
229
  const stableAttemptId = hookInput.attemptId;
215
230
  if (stableAttemptId) {
216
- return active[stableAttemptId] ? { attemptId: stableAttemptId, entry: active[stableAttemptId], confidence: 'high' } : null;
231
+ return active[stableAttemptId]
232
+ ? { attemptId: stableAttemptId, entry: active[stableAttemptId], confidence: 'high' }
233
+ : null;
217
234
  }
218
235
  if (entries.length === 1) return { attemptId: entries[0][0], entry: entries[0][1], confidence: 'high' };
219
236
  try { const receipts = JSON.parse(fs.readFileSync(path.join(taskDir, '.metrics-receipts.json'), 'utf8')); const receipt = Array.isArray(receipts) ? receipts.find((item) => active[item.attemptId]) : null; if (receipt) return { attemptId: receipt.attemptId, entry: active[receipt.attemptId], confidence: 'fallback', source: 'agent' }; } catch {}
220
237
  return null;
221
238
  }
239
+ let artifactStallMessage = null;
240
+
241
+ // A1: seed the manifest a modern pipeline expects instead of advancing without
242
+ // one. Exclusive publish via hard link so a producer that wrote the file in the
243
+ // meantime is never overwritten; returns null on success (or when the file
244
+ // appeared) and the fs error otherwise.
245
+ function writeSkeletonManifest(manifestPath) {
246
+ const temporary = `${manifestPath}.${process.pid}.${Date.now()}.seed`;
247
+ const body = JSON.stringify({ schemaVersion: 1, slug, artifacts: [] }, null, 2) + '\n';
248
+ let descriptor = null;
249
+ try {
250
+ descriptor = fs.openSync(temporary, 'wx');
251
+ try { fs.writeSync(descriptor, body); try { fs.fsyncSync(descriptor); } catch {} } finally { fs.closeSync(descriptor); descriptor = null; }
252
+ fs.linkSync(temporary, manifestPath);
253
+ fs.unlinkSync(temporary);
254
+ return null;
255
+ } catch (error) {
256
+ if (descriptor !== null) { try { fs.closeSync(descriptor); } catch {} }
257
+ try { fs.unlinkSync(temporary); } catch {}
258
+ if (error && error.code === 'EEXIST' && fs.existsSync(manifestPath)) return null;
259
+ return String(error && error.message ? error.message : error);
260
+ }
261
+ }
262
+
263
+ // A2: a `completed` receipt must cite evidence the harness can inspect. Order is
264
+ // the message order — the first failing predicate wins, so the operator sees one
265
+ // actionable line. `authoritativePaths[]` stays task-dir-relative; external
266
+ // references belong in `evidencePaths[]`.
267
+ function validateCompletedArtifact(entry) {
268
+ const artifactId = entry && entry.id ? entry.id : '(unnamed)';
269
+ const entryStatus = entry && entry.status;
270
+ if (entryStatus !== 'completed') {
271
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" has receipt.outcome "completed" but entry status "${entryStatus}". Make entry.status and receipt.outcome agree, then resume with: /task-continue ${slug}`;
272
+ }
273
+ const authoritativePaths = entry && Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths : [];
274
+ if (authoritativePaths.length === 0) {
275
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" is "completed" but authoritativePaths[] is empty. Record at least one file you produced under .ai.local/team/tasks/${slug}/, then resume with: /task-continue ${slug}`;
276
+ }
277
+ for (const cited of authoritativePaths) {
278
+ const value = typeof cited === 'string' ? cited.trim() : '';
279
+ const resolvedPath = value ? path.resolve(taskDir, value) : taskDir;
280
+ const relative = path.relative(taskDir, resolvedPath);
281
+ const escapes = !value || path.isAbsolute(value) || relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative);
282
+ if (escapes) {
283
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" cites "${value}", which resolves outside .ai.local/team/tasks/${slug}/ (relative: "${relative}"). Cite a task-relative path; keep external references in evidencePaths[]. Then resume with: /task-continue ${slug}`;
284
+ }
285
+ let stat = null;
286
+ try { stat = fs.statSync(resolvedPath); } catch {}
287
+ if (!stat || !stat.isFile()) {
288
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" cites "${value}" but no such file exists under .ai.local/team/tasks/${slug}/. Write the file, then resume with: /task-continue ${slug}`;
289
+ }
290
+ if (/\.md[c]?$/i.test(value)) {
291
+ let content = '';
292
+ try { content = fs.readFileSync(resolvedPath, 'utf8'); } catch {}
293
+ if (!/\S/.test(content)) {
294
+ return `[chain-team-phases] ${slug}: receipt "${artifactId}" is "completed" but authoritative path "${value}" has no non-whitespace content. Produce the artifact, then resume with: /task-continue ${slug}`;
295
+ }
296
+ }
297
+ }
298
+ return null;
299
+ }
300
+
222
301
  function readBoundReceiptOutcome(agent, step, resolved) {
223
302
  if (!agent || !resolved) return { outcome: null, receiptRequired: false };
224
303
  const manifestPath = path.join(taskDir, 'artifact-manifest.json');
225
- if (!fs.existsSync(manifestPath)) return { outcome: null, receiptRequired: false };
304
+ const expectedOutputId = artifactOutputIdFor(step, agent);
305
+ if (!fs.existsSync(manifestPath)) {
306
+ // A1: absent manifest + a parsed modern pipeline denies silent advancement.
307
+ // Legacy/step-less pipelines keep their previous behaviour (legacyFlow owns them).
308
+ if (!(Array.isArray(steps) && steps.length > 0)) return { outcome: null, receiptRequired: false };
309
+ const seeded = writeSkeletonManifest(manifestPath);
310
+ const stepIndex = typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : 0;
311
+ if (seeded) {
312
+ return { outcome: null, receiptRequired: true, stallMessage: `[chain-team-phases] ${slug}: artifact-manifest.json is missing and the skeleton could not be written (${seeded}). Create .ai.local/team/tasks/${slug}/artifact-manifest.json with {schemaVersion:1, slug, artifacts:[]}, add the receipt for artifactOutputId "${expectedOutputId}", then resume with: /task-continue ${slug}` };
313
+ }
314
+ return { outcome: null, receiptRequired: true, stallMessage: `[chain-team-phases] ${slug}: no artifact-manifest.json for step ${stepIndex} (${agent}). Wrote a skeleton {schemaVersion:1, slug, artifacts:[]}. Expected artifactOutputId "${expectedOutputId}". Write the artifact and its receipt, then resume with: /task-continue ${slug}` };
315
+ }
226
316
  try {
227
317
  const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
318
+ // Guard: the schema key is `artifacts` (see agent-artifact-contracts.md). A top-level
319
+ // `entries` key is a silent bug — producer wrote to a wrong field, hook would not
320
+ // see the receipt, and the step hangs in `awaiting_artifact_receipt`. Warn loudly.
321
+ if (manifest && typeof manifest === 'object' && !Array.isArray(manifest.artifacts) && Array.isArray(manifest.entries)) {
322
+ process.stderr.write(`WARNING: ${manifestPath} has top-level "entries" but no "artifacts" array; reading only "artifacts" per schema. The producer likely upserted into the wrong key. See agent-artifact-contracts.md (Schema field name).` + '\n');
323
+ } else if (manifest && typeof manifest === 'object' && Array.isArray(manifest.entries) && Array.isArray(manifest.artifacts)) {
324
+ process.stderr.write(`WARNING: ${manifestPath} has both "artifacts" and "entries" keys; reading only "artifacts" per schema. Foreign "entries" content is ignored.` + '\n');
325
+ }
228
326
  const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
229
- const expectedOutputId = artifactOutputIdFor(step, agent);
230
327
  const attemptStartedAt = Date.parse(resolved.entry.startedAt);
328
+ // Pre-scan: warn on the silent-bug classes the filter below would otherwise drop.
329
+ // A receipt with a non-matching attemptId is dropped silently; without this warning,
330
+ // the step hangs in `awaiting_artifact_receipt` with no signal of why. Same for
331
+ // receipts whose terminal timestamp is older than the active attempt (stale retry).
332
+ const activeIds = new Set(Object.keys(status.activeAttempts || {}));
333
+ for (const entry of artifacts) {
334
+ if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') continue;
335
+ const rid = entry.receipt.attemptId;
336
+ if (typeof rid === 'string' && rid !== resolved.attemptId && !activeIds.has(rid)) {
337
+ process.stderr.write(`WARNING: ${manifestPath} receipt for producer "${agent}" id "${entry.id}" carries attemptId "${rid}" that does not match the active attempt "${resolved.attemptId}". The receipt is being dropped; step will hang in \`awaiting_artifact_receipt\` unless the producer retries. Common cause: agent reused an attemptId from a prior failed attempt. See agent-artifact-contracts.md (Receipt binding).` + '\n');
338
+ }
339
+ const terminalAt = Date.parse(entry.timestamps?.completedAt || entry.timestamps?.updatedAt || '');
340
+ if (Number.isFinite(attemptStartedAt) && Number.isFinite(terminalAt) && terminalAt < attemptStartedAt) {
341
+ process.stderr.write(`WARNING: ${manifestPath} receipt for producer "${agent}" id "${entry.id}" has timestamps.completedAt older than the active attempt's startedAt. Likely a stale receipt from a previous attempt; it is being dropped. See agent-artifact-contracts.md (Receipt binding).` + '\n');
342
+ }
343
+ }
231
344
  const owned = artifacts
232
345
  .filter((entry) => {
233
346
  if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') return false;
@@ -242,19 +355,33 @@ function readBoundReceiptOutcome(agent, step, resolved) {
242
355
  const tb = Date.parse(b.timestamps?.completedAt || b.timestamps?.updatedAt || 0) || 0;
243
356
  return tb - ta;
244
357
  });
245
- return { outcome: owned[0]?.receipt?.outcome || null, receiptRequired: true };
358
+ // Bonus: warn if the active attempt's receipts all lack attemptId in a non-parallel step.
359
+ // The orchestrator always provides attemptId, so a missing one means the agent dropped it
360
+ // (model output, JSON.stringify omission, etc.). boundByOutput still binds the receipt by
361
+ // expectedOutputId, so this is not fatal — but it is a contract violation worth flagging.
362
+ if (owned.length > 0 && owned[0].receipt.attemptId == null && !(step && step.parallel && Array.isArray(getStepAgents(step)) && getStepAgents(step).length > 1)) {
363
+ process.stderr.write(`WARNING: ${manifestPath} receipt for producer "${agent}" id "${owned[0].id}" lacks entry.receipt.attemptId on a non-parallel step. The receipt is bound by output-id fallback; the agent should always include the attemptId the orchestrator provides. See agent-artifact-contracts.md (Receipt binding).` + '\n');
364
+ }
365
+ const outcome = owned[0]?.receipt?.outcome || null;
366
+ if (outcome === 'completed') {
367
+ const stallMessage = validateCompletedArtifact(owned[0]);
368
+ if (stallMessage) return { outcome: null, receiptRequired: true, stallMessage };
369
+ }
370
+ return { outcome, receiptRequired: true };
246
371
  } catch {
247
372
  return { outcome: null, receiptRequired: false };
248
373
  }
249
374
  }
250
375
  function reconcileStatusFromManifest(agent, step, resolved) {
251
376
  const terminal = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
252
- const { outcome, receiptRequired } = readBoundReceiptOutcome(agent, step, resolved);
377
+ artifactStallMessage = null;
378
+ const { outcome, receiptRequired, stallMessage } = readBoundReceiptOutcome(agent, step, resolved);
253
379
  if (terminal.has(outcome)) {
254
380
  status.state = outcome;
255
381
  return outcome;
256
382
  }
257
383
  if (receiptRequired) {
384
+ artifactStallMessage = stallMessage || null;
258
385
  status.state = 'awaiting_artifact_receipt';
259
386
  status.phase = 'blocked';
260
387
  return status.state;
@@ -313,6 +440,15 @@ function out(message) {
313
440
  process.stdout.write(JSON.stringify({ followup_message: message }));
314
441
  }
315
442
 
443
+ // The stall text always reaches stderr so a second, different rejection is never
444
+ // silent; `out()` fires only when the stop enters the stall, so the follow-up
445
+ // message cannot loop.
446
+ function emitArtifactStall(message, announce) {
447
+ if (message) process.stderr.write(message + '\n');
448
+ if (message && announce) out(message);
449
+ else process.stdout.write('{}');
450
+ }
451
+
316
452
  function readArtifact(name) {
317
453
  const p = path.join(taskDir, name);
318
454
  if (!fs.existsSync(p)) return '';
@@ -330,7 +466,6 @@ function getStepAgents(step) {
330
466
 
331
467
  function skipIfMatches(skipIf, dir) {
332
468
  if (!skipIf) return false;
333
- // Phase-2 reserved: debugger / ci-investigator are not in mcp-ts Phase 1 roster.
334
469
  if (skipIf === 'debugger.fixed') {
335
470
  const text = readArtifact('debug-report.md');
336
471
  return /fixApplied:\s*true/i.test(text) || /\*\*Fix applied:\*\*\s*true/i.test(text);
@@ -571,10 +706,12 @@ const AGENT_HANDOFF = {
571
706
  };
572
707
 
573
708
  const REVIEW_AGENTS = new Set([
709
+ 'code-reviewer',
710
+ 'accessibility-reviewer',
574
711
  'security-reviewer',
712
+ 'api-contract-reviewer',
575
713
  ]);
576
714
 
577
-
578
715
  function metricsHandoff(agent) {
579
716
  const matches = Object.entries(status.activeAttempts || {}).filter(([, entry]) => entry.agent === agent);
580
717
  if (matches.length === 1) {
@@ -848,10 +985,11 @@ const completingAgentHint = (() => {
848
985
  return getStepAgents(initialStep)[0];
849
986
  })();
850
987
  const reconcilingAttempt = resolvedAttempt();
988
+ const wasWaitingForReceipt = status.state === 'awaiting_artifact_receipt';
851
989
  reconcileStatusFromManifest(completingAgentHint, initialStep, reconcilingAttempt);
852
990
  if (status.state === 'awaiting_artifact_receipt') {
853
991
  writeStatus({});
854
- process.stdout.write('{}');
992
+ emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
855
993
  process.exit(0);
856
994
  }
857
995
  let finishedAttempt = finishActiveAttempt();
@@ -861,6 +999,11 @@ if (!finishedAttempt && activeAttemptCountBeforeFinish > 0) {
861
999
  if (repaired) {
862
1000
  appendMetric({ type: 'parallel_attribution_repair', at: now, attemptIds: [repaired.attemptId], source: 'hook', attributionConfidence: 'fallback' });
863
1001
  reconcileStatusFromManifest(repaired.entry.agent, steps[repaired.entry.stepIndex], repaired);
1002
+ if (status.state === 'awaiting_artifact_receipt') {
1003
+ writeStatus({});
1004
+ emitArtifactStall(artifactStallMessage, true);
1005
+ process.exit(0);
1006
+ }
864
1007
  finishedAttempt = finishActiveAttempt(repaired);
865
1008
  } else {
866
1009
  writeStatus({});
@@ -917,6 +1060,7 @@ const waveIndexes = activeWave
917
1060
  ? [idx]
918
1061
  : (isGraphMode() && finishedAttempt ? [completedStepIndex] : null));
919
1062
 
1063
+
920
1064
  if (waveIndexes) {
921
1065
  const waveAgents = waveIndexes.flatMap((i) => getStepAgents(steps[i]));
922
1066
  const done = [...(status.parallelCompleted || [])];
@@ -969,6 +1113,20 @@ if (waveIndexes) {
969
1113
  }
970
1114
 
971
1115
  const retryReviewer = waveAgents.find((agent) => outcomes[agent]?.outcome === 'changes_requested');
1116
+ if (retryReviewer === 'mockup-reviewer') {
1117
+ beginHumanGate();
1118
+ writeStatus({
1119
+ awaitingHumanGate: true,
1120
+ state: 'awaiting_approval',
1121
+ currentAgent: 'mockup-reviewer',
1122
+ parallelCompleted: [],
1123
+ parallelOutcomes: {},
1124
+ waveSteps: [],
1125
+ waveId: null,
1126
+ });
1127
+ out(`Mockup review FAIL for slug "${slug}". Read mockup-review.md. Resume only via /task-continue. Do not retry feature-developer.`);
1128
+ process.exit(0);
1129
+ }
972
1130
  if (retryReviewer) {
973
1131
  if (isGraphMode()) {
974
1132
  const reviewerStepIndex = waveIndexes.find((i) => getStepAgents(steps[i]).includes(retryReviewer));
@@ -1075,6 +1233,17 @@ if (status.state === 'blocked') {
1075
1233
  process.exit(0);
1076
1234
  }
1077
1235
 
1236
+ if (status.state === 'changes_requested' && (completedAgent === 'mockup-reviewer' || status.currentAgent === 'mockup-reviewer')) {
1237
+ beginHumanGate();
1238
+ writeStatus({
1239
+ awaitingHumanGate: true,
1240
+ state: 'awaiting_approval',
1241
+ currentAgent: 'mockup-reviewer',
1242
+ });
1243
+ out(`Mockup review FAIL for slug "${slug}". Read mockup-review.md. Resume only via /task-continue. Do not retry feature-developer.`);
1244
+ process.exit(0);
1245
+ }
1246
+
1078
1247
  if (status.state === 'changes_requested') {
1079
1248
  const reviewer = status.currentAgent || finishedAttempt?.entry?.agent;
1080
1249
  if (!reviewer) {