@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.
- package/bin/lib/merged-config.js +9 -0
- package/bin/opencode-install.js +46 -1
- package/package.json +4 -1
- package/presets/_shared/hooks/README.md +137 -0
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +1288 -0
- package/presets/claude/android-kotlin/MCP.md +2 -2
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +171 -10
- package/presets/claude/android-kotlin/mcp.json +1 -1
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +6 -153
- package/presets/claude/android-kotlin/team/README.md +2 -6
- package/presets/claude/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/claude/go/MCP.md +2 -2
- package/presets/claude/go/hooks/chain-team-phases.sh +183 -16
- package/presets/claude/go/mcp.json +1 -1
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +6 -11
- package/presets/claude/go/team/README.md +2 -6
- package/presets/claude/ios-swift/MCP.md +2 -2
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +178 -17
- package/presets/claude/ios-swift/mcp.json +1 -1
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +6 -153
- package/presets/claude/ios-swift/team/README.md +2 -6
- package/presets/claude/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/claude/java/hooks/chain-team-phases.sh +183 -16
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +6 -28
- package/presets/claude/java/team/README.md +2 -6
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +182 -13
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +6 -14
- package/presets/claude/mcp-ts/team/README.md +2 -6
- package/presets/claude/next/MCP.md +2 -2
- package/presets/claude/next/commands/task.md +5 -3
- package/presets/claude/next/hooks/chain-team-phases.sh +102 -6
- package/presets/claude/next/mcp.json +1 -1
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +6 -226
- package/presets/claude/next/team/README.md +2 -6
- package/presets/claude/next/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/claude/nuxt/MCP.md +2 -2
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +148 -7
- package/presets/claude/nuxt/mcp.json +1 -1
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +6 -223
- package/presets/claude/nuxt/team/README.md +2 -6
- package/presets/claude/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +183 -16
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +6 -28
- package/presets/claude/php-hexagonal/team/README.md +2 -6
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +183 -16
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +6 -29
- package/presets/claude/php-laravel/team/README.md +2 -6
- package/presets/claude/svelte/MCP.md +2 -2
- package/presets/claude/svelte/hooks/chain-team-phases.sh +148 -7
- package/presets/claude/svelte/mcp.json +1 -1
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +6 -223
- package/presets/claude/svelte/team/README.md +2 -6
- package/presets/claude/svelte/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/android-kotlin/MCP.md +2 -2
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +150 -7
- package/presets/cursor/android-kotlin/mcp.json +1 -1
- package/presets/cursor/android-kotlin/team/README.md +2 -0
- package/presets/cursor/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/go/MCP.md +2 -2
- package/presets/cursor/go/hooks/chain-team-phases.sh +175 -8
- package/presets/cursor/go/mcp.json +1 -1
- package/presets/cursor/go/team/README.md +2 -0
- package/presets/cursor/ios-swift/MCP.md +2 -2
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +150 -7
- package/presets/cursor/ios-swift/mcp.json +1 -1
- package/presets/cursor/ios-swift/team/README.md +2 -0
- package/presets/cursor/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/java/hooks/chain-team-phases.sh +175 -8
- package/presets/cursor/java/team/README.md +2 -0
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +179 -10
- package/presets/cursor/mcp-ts/team/README.md +2 -0
- package/presets/cursor/next/MCP.md +2 -2
- package/presets/cursor/next/commands/task.md +5 -3
- package/presets/cursor/next/hooks/chain-team-phases.sh +99 -5
- package/presets/cursor/next/mcp.json +1 -1
- package/presets/cursor/next/team/README.md +2 -0
- package/presets/cursor/next/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/nuxt/MCP.md +2 -2
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +145 -6
- package/presets/cursor/nuxt/mcp.json +1 -1
- package/presets/cursor/nuxt/team/README.md +2 -0
- package/presets/cursor/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +175 -8
- package/presets/cursor/php-hexagonal/team/README.md +2 -0
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +175 -8
- package/presets/cursor/php-laravel/team/README.md +2 -0
- package/presets/cursor/svelte/MCP.md +2 -2
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +145 -6
- package/presets/cursor/svelte/mcp.json +1 -1
- package/presets/cursor/svelte/team/README.md +2 -0
- package/presets/cursor/svelte/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/android-kotlin/MCP.md +2 -2
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +150 -7
- package/presets/mavis/android-kotlin/mcp.json +1 -1
- package/presets/mavis/android-kotlin/team/README.md +2 -0
- package/presets/mavis/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/go/MCP.md +2 -2
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/hooks/chain-team-phases.sh +175 -8
- package/presets/mavis/go/mcp.json +1 -1
- package/presets/mavis/go/team/README.md +2 -0
- package/presets/mavis/ios-swift/MCP.md +2 -2
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +150 -7
- package/presets/mavis/ios-swift/mcp.json +1 -1
- package/presets/mavis/ios-swift/team/README.md +2 -0
- package/presets/mavis/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/hooks/chain-team-phases.sh +175 -8
- package/presets/mavis/java/team/README.md +2 -0
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +179 -10
- package/presets/mavis/mcp-ts/team/README.md +2 -0
- package/presets/mavis/next/MCP.md +2 -2
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/commands/task.md +5 -3
- package/presets/mavis/next/hooks/chain-team-phases.sh +99 -5
- package/presets/mavis/next/mcp.json +1 -1
- package/presets/mavis/next/team/README.md +2 -0
- package/presets/mavis/next/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/nuxt/MCP.md +2 -2
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +145 -6
- package/presets/mavis/nuxt/mcp.json +1 -1
- package/presets/mavis/nuxt/team/README.md +2 -0
- package/presets/mavis/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +175 -8
- package/presets/mavis/php-hexagonal/team/README.md +2 -0
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +175 -8
- package/presets/mavis/php-laravel/team/README.md +2 -0
- package/presets/mavis/svelte/MCP.md +2 -2
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +145 -6
- package/presets/mavis/svelte/mcp.json +1 -1
- package/presets/mavis/svelte/team/README.md +2 -0
- package/presets/mavis/svelte/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/android-kotlin/MCP.md +2 -2
- package/presets/opencode/android-kotlin/OPENCODE.md +6 -4
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +150 -7
- package/presets/opencode/android-kotlin/opencode.json +13 -1
- package/presets/opencode/android-kotlin/team/README.md +2 -0
- package/presets/opencode/android-kotlin/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/go/MCP.md +2 -2
- package/presets/opencode/go/OPENCODE.md +6 -4
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/hooks/chain-team-phases.sh +175 -8
- package/presets/opencode/go/opencode.json +13 -1
- package/presets/opencode/go/team/README.md +2 -0
- package/presets/opencode/ios-swift/MCP.md +2 -2
- package/presets/opencode/ios-swift/OPENCODE.md +6 -4
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +150 -7
- package/presets/opencode/ios-swift/opencode.json +13 -1
- package/presets/opencode/ios-swift/team/README.md +2 -0
- package/presets/opencode/ios-swift/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/java/OPENCODE.md +6 -4
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/hooks/chain-team-phases.sh +175 -8
- package/presets/opencode/java/opencode.json +12 -0
- package/presets/opencode/java/team/README.md +2 -0
- package/presets/opencode/mcp-ts/OPENCODE.md +6 -4
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +179 -10
- package/presets/opencode/mcp-ts/opencode.json +12 -0
- package/presets/opencode/mcp-ts/team/README.md +2 -0
- package/presets/opencode/next/MCP.md +2 -2
- package/presets/opencode/next/OPENCODE.md +6 -4
- package/presets/opencode/next/adapter-map.json +1 -1
- package/presets/opencode/next/commands/task.md +5 -3
- package/presets/opencode/next/hooks/chain-team-phases.sh +99 -5
- package/presets/opencode/next/opencode.json +13 -1
- package/presets/opencode/next/team/README.md +2 -0
- package/presets/opencode/next/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/nuxt/MCP.md +2 -2
- package/presets/opencode/nuxt/OPENCODE.md +6 -4
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +145 -6
- package/presets/opencode/nuxt/opencode.json +13 -1
- package/presets/opencode/nuxt/team/README.md +2 -0
- package/presets/opencode/nuxt/team/fixtures/artifact-manifest.example.json +1 -0
- package/presets/opencode/php-hexagonal/OPENCODE.md +6 -4
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +175 -8
- package/presets/opencode/php-hexagonal/opencode.json +12 -0
- package/presets/opencode/php-hexagonal/team/README.md +2 -0
- package/presets/opencode/php-laravel/OPENCODE.md +6 -4
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +175 -8
- package/presets/opencode/php-laravel/opencode.json +12 -0
- package/presets/opencode/php-laravel/team/README.md +2 -0
- package/presets/opencode/svelte/MCP.md +2 -2
- package/presets/opencode/svelte/OPENCODE.md +6 -4
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +145 -6
- package/presets/opencode/svelte/opencode.json +13 -1
- package/presets/opencode/svelte/team/README.md +2 -0
- package/presets/opencode/svelte/team/fixtures/artifact-manifest.example.json +1 -0
|
@@ -156,7 +156,21 @@ function mutateMetrics(mutator) {
|
|
|
156
156
|
try { metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8')); } catch {
|
|
157
157
|
const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
158
158
|
status.metricsRunId = runId;
|
|
159
|
-
|
|
159
|
+
// Resolve profile from pipeline.json (preferred) or status.json, falling back to 'unknown'.
|
|
160
|
+
// The router/agent must never write profile into status.json — pipeline.json is the SoT.
|
|
161
|
+
let profile = 'unknown';
|
|
162
|
+
try {
|
|
163
|
+
if (fs.existsSync(pipelinePath)) {
|
|
164
|
+
const pipe = JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
|
|
165
|
+
if (pipe && (pipe.profile === 'light' || pipe.profile === 'standard' || pipe.profile === 'full')) {
|
|
166
|
+
profile = pipe.profile;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
} catch {}
|
|
170
|
+
if (profile === 'unknown' && (status.profile === 'light' || status.profile === 'standard' || status.profile === 'full')) {
|
|
171
|
+
profile = status.profile;
|
|
172
|
+
}
|
|
173
|
+
metrics = { schemaVersion: 1, task: { runId, slug, preset: 'ai-rules', stack: STACK, platform: PLATFORM, intent: status.intent || 'unknown', profile }, events: [] };
|
|
160
174
|
metrics.events.push({ eventId: `${runId}:task_started`, type: 'task_started', at: now, source: 'hook', attributionConfidence: 'high' });
|
|
161
175
|
}
|
|
162
176
|
mutator(metrics);
|
|
@@ -227,21 +241,119 @@ function resolvedAttempt() {
|
|
|
227
241
|
const active = status.activeAttempts || {}; const entries = Object.entries(active);
|
|
228
242
|
const stableAttemptId = hookInput.attemptId;
|
|
229
243
|
if (stableAttemptId) {
|
|
230
|
-
return active[stableAttemptId]
|
|
244
|
+
return active[stableAttemptId]
|
|
245
|
+
? { attemptId: stableAttemptId, entry: active[stableAttemptId], confidence: 'high' }
|
|
246
|
+
: null;
|
|
231
247
|
}
|
|
232
248
|
if (entries.length === 1) return { attemptId: entries[0][0], entry: entries[0][1], confidence: 'high' };
|
|
233
249
|
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 {}
|
|
234
250
|
return null;
|
|
235
251
|
}
|
|
252
|
+
let artifactStallMessage = null;
|
|
253
|
+
|
|
254
|
+
// A1: seed the manifest a modern pipeline expects instead of advancing without
|
|
255
|
+
// one. Exclusive publish via hard link so a producer that wrote the file in the
|
|
256
|
+
// meantime is never overwritten; returns null on success (or when the file
|
|
257
|
+
// appeared) and the fs error otherwise.
|
|
258
|
+
function writeSkeletonManifest(manifestPath) {
|
|
259
|
+
const temporary = `${manifestPath}.${process.pid}.${Date.now()}.seed`;
|
|
260
|
+
const body = JSON.stringify({ schemaVersion: 1, slug, artifacts: [] }, null, 2) + '\n';
|
|
261
|
+
let descriptor = null;
|
|
262
|
+
try {
|
|
263
|
+
descriptor = fs.openSync(temporary, 'wx');
|
|
264
|
+
try { fs.writeSync(descriptor, body); try { fs.fsyncSync(descriptor); } catch {} } finally { fs.closeSync(descriptor); descriptor = null; }
|
|
265
|
+
fs.linkSync(temporary, manifestPath);
|
|
266
|
+
fs.unlinkSync(temporary);
|
|
267
|
+
return null;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (descriptor !== null) { try { fs.closeSync(descriptor); } catch {} }
|
|
270
|
+
try { fs.unlinkSync(temporary); } catch {}
|
|
271
|
+
if (error && error.code === 'EEXIST' && fs.existsSync(manifestPath)) return null;
|
|
272
|
+
return String(error && error.message ? error.message : error);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// A2: a `completed` receipt must cite evidence the harness can inspect. Order is
|
|
277
|
+
// the message order — the first failing predicate wins, so the operator sees one
|
|
278
|
+
// actionable line. `authoritativePaths[]` stays task-dir-relative; external
|
|
279
|
+
// references belong in `evidencePaths[]`.
|
|
280
|
+
function validateCompletedArtifact(entry) {
|
|
281
|
+
const artifactId = entry && entry.id ? entry.id : '(unnamed)';
|
|
282
|
+
const entryStatus = entry && entry.status;
|
|
283
|
+
if (entryStatus !== 'completed') {
|
|
284
|
+
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}`;
|
|
285
|
+
}
|
|
286
|
+
const authoritativePaths = entry && Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths : [];
|
|
287
|
+
if (authoritativePaths.length === 0) {
|
|
288
|
+
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}`;
|
|
289
|
+
}
|
|
290
|
+
for (const cited of authoritativePaths) {
|
|
291
|
+
const value = typeof cited === 'string' ? cited.trim() : '';
|
|
292
|
+
const resolvedPath = value ? path.resolve(taskDir, value) : taskDir;
|
|
293
|
+
const relative = path.relative(taskDir, resolvedPath);
|
|
294
|
+
const escapes = !value || path.isAbsolute(value) || relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative);
|
|
295
|
+
if (escapes) {
|
|
296
|
+
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}`;
|
|
297
|
+
}
|
|
298
|
+
let stat = null;
|
|
299
|
+
try { stat = fs.statSync(resolvedPath); } catch {}
|
|
300
|
+
if (!stat || !stat.isFile()) {
|
|
301
|
+
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}`;
|
|
302
|
+
}
|
|
303
|
+
if (/\.md[c]?$/i.test(value)) {
|
|
304
|
+
let content = '';
|
|
305
|
+
try { content = fs.readFileSync(resolvedPath, 'utf8'); } catch {}
|
|
306
|
+
if (!/\S/.test(content)) {
|
|
307
|
+
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}`;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
|
|
236
314
|
function readBoundReceiptOutcome(agent, step, resolved) {
|
|
237
315
|
if (!agent || !resolved) return { outcome: null, receiptRequired: false };
|
|
238
316
|
const manifestPath = path.join(taskDir, 'artifact-manifest.json');
|
|
239
|
-
|
|
317
|
+
const expectedOutputId = artifactOutputIdFor(step, agent);
|
|
318
|
+
if (!fs.existsSync(manifestPath)) {
|
|
319
|
+
// A1: absent manifest + a parsed modern pipeline denies silent advancement.
|
|
320
|
+
// Legacy/step-less pipelines keep their previous behaviour (legacyFlow owns them).
|
|
321
|
+
if (!(Array.isArray(steps) && steps.length > 0)) return { outcome: null, receiptRequired: false };
|
|
322
|
+
const seeded = writeSkeletonManifest(manifestPath);
|
|
323
|
+
const stepIndex = typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : 0;
|
|
324
|
+
if (seeded) {
|
|
325
|
+
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}` };
|
|
326
|
+
}
|
|
327
|
+
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}` };
|
|
328
|
+
}
|
|
240
329
|
try {
|
|
241
330
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
331
|
+
// Guard: the schema key is `artifacts` (see agent-artifact-contracts.md). A top-level
|
|
332
|
+
// `entries` key is a silent bug — producer wrote to a wrong field, hook would not
|
|
333
|
+
// see the receipt, and the step hangs in `awaiting_artifact_receipt`. Warn loudly.
|
|
334
|
+
if (manifest && typeof manifest === 'object' && !Array.isArray(manifest.artifacts) && Array.isArray(manifest.entries)) {
|
|
335
|
+
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');
|
|
336
|
+
} else if (manifest && typeof manifest === 'object' && Array.isArray(manifest.entries) && Array.isArray(manifest.artifacts)) {
|
|
337
|
+
process.stderr.write(`WARNING: ${manifestPath} has both "artifacts" and "entries" keys; reading only "artifacts" per schema. Foreign "entries" content is ignored.` + '\n');
|
|
338
|
+
}
|
|
242
339
|
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
243
|
-
const expectedOutputId = artifactOutputIdFor(step, agent);
|
|
244
340
|
const attemptStartedAt = Date.parse(resolved.entry.startedAt);
|
|
341
|
+
// Pre-scan: warn on the silent-bug classes the filter below would otherwise drop.
|
|
342
|
+
// A receipt with a non-matching attemptId is dropped silently; without this warning,
|
|
343
|
+
// the step hangs in `awaiting_artifact_receipt` with no signal of why. Same for
|
|
344
|
+
// receipts whose terminal timestamp is older than the active attempt (stale retry).
|
|
345
|
+
const activeIds = new Set(Object.keys(status.activeAttempts || {}));
|
|
346
|
+
for (const entry of artifacts) {
|
|
347
|
+
if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') continue;
|
|
348
|
+
const rid = entry.receipt.attemptId;
|
|
349
|
+
if (typeof rid === 'string' && rid !== resolved.attemptId && !activeIds.has(rid)) {
|
|
350
|
+
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');
|
|
351
|
+
}
|
|
352
|
+
const terminalAt = Date.parse(entry.timestamps?.completedAt || entry.timestamps?.updatedAt || '');
|
|
353
|
+
if (Number.isFinite(attemptStartedAt) && Number.isFinite(terminalAt) && terminalAt < attemptStartedAt) {
|
|
354
|
+
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');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
245
357
|
const owned = artifacts
|
|
246
358
|
.filter((entry) => {
|
|
247
359
|
if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') return false;
|
|
@@ -256,19 +368,33 @@ function readBoundReceiptOutcome(agent, step, resolved) {
|
|
|
256
368
|
const tb = Date.parse(b.timestamps?.completedAt || b.timestamps?.updatedAt || 0) || 0;
|
|
257
369
|
return tb - ta;
|
|
258
370
|
});
|
|
259
|
-
|
|
371
|
+
// Bonus: warn if the active attempt's receipts all lack attemptId in a non-parallel step.
|
|
372
|
+
// The orchestrator always provides attemptId, so a missing one means the agent dropped it
|
|
373
|
+
// (model output, JSON.stringify omission, etc.). boundByOutput still binds the receipt by
|
|
374
|
+
// expectedOutputId, so this is not fatal — but it is a contract violation worth flagging.
|
|
375
|
+
if (owned.length > 0 && owned[0].receipt.attemptId == null && !(step && step.parallel && Array.isArray(getStepAgents(step)) && getStepAgents(step).length > 1)) {
|
|
376
|
+
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');
|
|
377
|
+
}
|
|
378
|
+
const outcome = owned[0]?.receipt?.outcome || null;
|
|
379
|
+
if (outcome === 'completed') {
|
|
380
|
+
const stallMessage = validateCompletedArtifact(owned[0]);
|
|
381
|
+
if (stallMessage) return { outcome: null, receiptRequired: true, stallMessage };
|
|
382
|
+
}
|
|
383
|
+
return { outcome, receiptRequired: true };
|
|
260
384
|
} catch {
|
|
261
385
|
return { outcome: null, receiptRequired: false };
|
|
262
386
|
}
|
|
263
387
|
}
|
|
264
388
|
function reconcileStatusFromManifest(agent, step, resolved) {
|
|
265
389
|
const terminal = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
266
|
-
|
|
390
|
+
artifactStallMessage = null;
|
|
391
|
+
const { outcome, receiptRequired, stallMessage } = readBoundReceiptOutcome(agent, step, resolved);
|
|
267
392
|
if (terminal.has(outcome)) {
|
|
268
393
|
status.state = outcome;
|
|
269
394
|
return outcome;
|
|
270
395
|
}
|
|
271
396
|
if (receiptRequired) {
|
|
397
|
+
artifactStallMessage = stallMessage || null;
|
|
272
398
|
status.state = 'awaiting_artifact_receipt';
|
|
273
399
|
status.phase = 'blocked';
|
|
274
400
|
return status.state;
|
|
@@ -327,6 +453,15 @@ function out(message) {
|
|
|
327
453
|
process.stdout.write(JSON.stringify({ followup_message: message }));
|
|
328
454
|
}
|
|
329
455
|
|
|
456
|
+
// The stall text always reaches stderr so a second, different rejection is never
|
|
457
|
+
// silent; `out()` fires only when the stop enters the stall, so the follow-up
|
|
458
|
+
// message cannot loop.
|
|
459
|
+
function emitArtifactStall(message, announce) {
|
|
460
|
+
if (message) process.stderr.write(message + '\n');
|
|
461
|
+
if (message && announce) out(message);
|
|
462
|
+
else process.stdout.write('{}');
|
|
463
|
+
}
|
|
464
|
+
|
|
330
465
|
function readArtifact(name) {
|
|
331
466
|
const p = path.join(taskDir, name);
|
|
332
467
|
if (!fs.existsSync(p)) return '';
|
|
@@ -626,11 +761,11 @@ const AGENT_HANDOFF = {
|
|
|
626
761
|
|
|
627
762
|
const REVIEW_AGENTS = new Set([
|
|
628
763
|
'code-reviewer',
|
|
764
|
+
'accessibility-reviewer',
|
|
629
765
|
'security-reviewer',
|
|
630
766
|
'api-contract-reviewer',
|
|
631
767
|
]);
|
|
632
768
|
|
|
633
|
-
|
|
634
769
|
function metricsHandoff(agent) {
|
|
635
770
|
const matches = Object.entries(status.activeAttempts || {}).filter(([, entry]) => entry.agent === agent);
|
|
636
771
|
if (matches.length === 1) {
|
|
@@ -904,10 +1039,11 @@ const completingAgentHint = (() => {
|
|
|
904
1039
|
return getStepAgents(initialStep)[0];
|
|
905
1040
|
})();
|
|
906
1041
|
const reconcilingAttempt = resolvedAttempt();
|
|
1042
|
+
const wasWaitingForReceipt = status.state === 'awaiting_artifact_receipt';
|
|
907
1043
|
reconcileStatusFromManifest(completingAgentHint, initialStep, reconcilingAttempt);
|
|
908
1044
|
if (status.state === 'awaiting_artifact_receipt') {
|
|
909
1045
|
writeStatus({});
|
|
910
|
-
|
|
1046
|
+
emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
|
|
911
1047
|
process.exit(0);
|
|
912
1048
|
}
|
|
913
1049
|
let finishedAttempt = finishActiveAttempt();
|
|
@@ -917,6 +1053,11 @@ if (!finishedAttempt && activeAttemptCountBeforeFinish > 0) {
|
|
|
917
1053
|
if (repaired) {
|
|
918
1054
|
appendMetric({ type: 'parallel_attribution_repair', at: now, attemptIds: [repaired.attemptId], source: 'hook', attributionConfidence: 'fallback' });
|
|
919
1055
|
reconcileStatusFromManifest(repaired.entry.agent, steps[repaired.entry.stepIndex], repaired);
|
|
1056
|
+
if (status.state === 'awaiting_artifact_receipt') {
|
|
1057
|
+
writeStatus({});
|
|
1058
|
+
emitArtifactStall(artifactStallMessage, true);
|
|
1059
|
+
process.exit(0);
|
|
1060
|
+
}
|
|
920
1061
|
finishedAttempt = finishActiveAttempt(repaired);
|
|
921
1062
|
} else {
|
|
922
1063
|
writeStatus({});
|
|
@@ -973,6 +1114,7 @@ const waveIndexes = activeWave
|
|
|
973
1114
|
? [idx]
|
|
974
1115
|
: (isGraphMode() && finishedAttempt ? [completedStepIndex] : null));
|
|
975
1116
|
|
|
1117
|
+
|
|
976
1118
|
if (waveIndexes) {
|
|
977
1119
|
const waveAgents = waveIndexes.flatMap((i) => getStepAgents(steps[i]));
|
|
978
1120
|
const done = [...(status.parallelCompleted || [])];
|
|
@@ -1025,6 +1167,20 @@ if (waveIndexes) {
|
|
|
1025
1167
|
}
|
|
1026
1168
|
|
|
1027
1169
|
const retryReviewer = waveAgents.find((agent) => outcomes[agent]?.outcome === 'changes_requested');
|
|
1170
|
+
if (retryReviewer === 'mockup-reviewer') {
|
|
1171
|
+
beginHumanGate();
|
|
1172
|
+
writeStatus({
|
|
1173
|
+
awaitingHumanGate: true,
|
|
1174
|
+
state: 'awaiting_approval',
|
|
1175
|
+
currentAgent: 'mockup-reviewer',
|
|
1176
|
+
parallelCompleted: [],
|
|
1177
|
+
parallelOutcomes: {},
|
|
1178
|
+
waveSteps: [],
|
|
1179
|
+
waveId: null,
|
|
1180
|
+
});
|
|
1181
|
+
out(`Mockup review FAIL for slug "${slug}". Read mockup-review.md. Resume only via /task-continue. Do not retry feature-developer.`);
|
|
1182
|
+
process.exit(0);
|
|
1183
|
+
}
|
|
1028
1184
|
if (retryReviewer) {
|
|
1029
1185
|
if (isGraphMode()) {
|
|
1030
1186
|
const reviewerStepIndex = waveIndexes.find((i) => getStepAgents(steps[i]).includes(retryReviewer));
|
|
@@ -1131,6 +1287,17 @@ if (status.state === 'blocked') {
|
|
|
1131
1287
|
process.exit(0);
|
|
1132
1288
|
}
|
|
1133
1289
|
|
|
1290
|
+
if (status.state === 'changes_requested' && (completedAgent === 'mockup-reviewer' || status.currentAgent === 'mockup-reviewer')) {
|
|
1291
|
+
beginHumanGate();
|
|
1292
|
+
writeStatus({
|
|
1293
|
+
awaitingHumanGate: true,
|
|
1294
|
+
state: 'awaiting_approval',
|
|
1295
|
+
currentAgent: 'mockup-reviewer',
|
|
1296
|
+
});
|
|
1297
|
+
out(`Mockup review FAIL for slug "${slug}". Read mockup-review.md. Resume only via /task-continue. Do not retry feature-developer.`);
|
|
1298
|
+
process.exit(0);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1134
1301
|
if (status.state === 'changes_requested') {
|
|
1135
1302
|
const reviewer = status.currentAgent || finishedAttempt?.entry?.agent;
|
|
1136
1303
|
if (!reviewer) {
|
|
@@ -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).
|
|
@@ -9,9 +9,9 @@ Copied to `.cursor/mcp.json` on `ai-rules init cursor --preset svelte`.
|
|
|
9
9
|
| `context7` | `@upstash/context7-mcp` | Up-to-date Svelte/SvelteKit/TS and library docs (fewer stale APIs in agent replies) |
|
|
10
10
|
| `playwright` | `@playwright/mcp` | Browser automation for e2e agents (`playwright-test-*`) and selector checks |
|
|
11
11
|
| `chrome-devtools` | `chrome-devtools-mcp` | Live DOM/network/performance when debugging UI |
|
|
12
|
-
| `figma` |
|
|
12
|
+
| `figma` | desktop `http://127.0.0.1:3845/mcp` | Design context → code (layouts, tokens, Code Connect); local desktop server (enable in Figma Desktop, Dev/Full seat) |
|
|
13
13
|
|
|
14
|
-
Do not put secrets in the file. Optional: `CONTEXT7_API_KEY` in the environment — higher Context7 rate limits. Figma —
|
|
14
|
+
Do not put secrets in the file. Optional: `CONTEXT7_API_KEY` in the environment — higher Context7 rate limits. Figma — local desktop server (enable in Figma Desktop, Dev/Full seat).
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
## Agent usage
|
|
@@ -154,7 +154,21 @@ function mutateMetrics(mutator) {
|
|
|
154
154
|
try { metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8')); } catch {
|
|
155
155
|
const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
156
156
|
status.metricsRunId = runId;
|
|
157
|
-
|
|
157
|
+
// Resolve profile from pipeline.json (preferred) or status.json, falling back to 'unknown'.
|
|
158
|
+
// The router/agent must never write profile into status.json — pipeline.json is the SoT.
|
|
159
|
+
let profile = 'unknown';
|
|
160
|
+
try {
|
|
161
|
+
if (fs.existsSync(pipelinePath)) {
|
|
162
|
+
const pipe = JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
|
|
163
|
+
if (pipe && (pipe.profile === 'light' || pipe.profile === 'standard' || pipe.profile === 'full')) {
|
|
164
|
+
profile = pipe.profile;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
} catch {}
|
|
168
|
+
if (profile === 'unknown' && (status.profile === 'light' || status.profile === 'standard' || status.profile === 'full')) {
|
|
169
|
+
profile = status.profile;
|
|
170
|
+
}
|
|
171
|
+
metrics = { schemaVersion: 1, task: { runId, slug, preset: 'ai-rules', stack: STACK, platform: PLATFORM, intent: status.intent || 'unknown', profile }, events: [] };
|
|
158
172
|
metrics.events.push({ eventId: `${runId}:task_started`, type: 'task_started', at: now, source: 'hook', attributionConfidence: 'high' });
|
|
159
173
|
}
|
|
160
174
|
mutator(metrics);
|
|
@@ -235,15 +249,111 @@ function resolvedAttempt() {
|
|
|
235
249
|
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 {}
|
|
236
250
|
return null;
|
|
237
251
|
}
|
|
252
|
+
let artifactStallMessage = null;
|
|
253
|
+
|
|
254
|
+
// A1: seed the manifest a modern pipeline expects instead of advancing without
|
|
255
|
+
// one. Exclusive publish via hard link so a producer that wrote the file in the
|
|
256
|
+
// meantime is never overwritten; returns null on success (or when the file
|
|
257
|
+
// appeared) and the fs error otherwise.
|
|
258
|
+
function writeSkeletonManifest(manifestPath) {
|
|
259
|
+
const temporary = `${manifestPath}.${process.pid}.${Date.now()}.seed`;
|
|
260
|
+
const body = JSON.stringify({ schemaVersion: 1, slug, artifacts: [] }, null, 2) + '\n';
|
|
261
|
+
let descriptor = null;
|
|
262
|
+
try {
|
|
263
|
+
descriptor = fs.openSync(temporary, 'wx');
|
|
264
|
+
try { fs.writeSync(descriptor, body); try { fs.fsyncSync(descriptor); } catch {} } finally { fs.closeSync(descriptor); descriptor = null; }
|
|
265
|
+
fs.linkSync(temporary, manifestPath);
|
|
266
|
+
fs.unlinkSync(temporary);
|
|
267
|
+
return null;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (descriptor !== null) { try { fs.closeSync(descriptor); } catch {} }
|
|
270
|
+
try { fs.unlinkSync(temporary); } catch {}
|
|
271
|
+
if (error && error.code === 'EEXIST' && fs.existsSync(manifestPath)) return null;
|
|
272
|
+
return String(error && error.message ? error.message : error);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// A2: a `completed` receipt must cite evidence the harness can inspect. Order is
|
|
277
|
+
// the message order — the first failing predicate wins, so the operator sees one
|
|
278
|
+
// actionable line. `authoritativePaths[]` stays task-dir-relative; external
|
|
279
|
+
// references belong in `evidencePaths[]`.
|
|
280
|
+
function validateCompletedArtifact(entry) {
|
|
281
|
+
const artifactId = entry && entry.id ? entry.id : '(unnamed)';
|
|
282
|
+
const entryStatus = entry && entry.status;
|
|
283
|
+
if (entryStatus !== 'completed') {
|
|
284
|
+
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}`;
|
|
285
|
+
}
|
|
286
|
+
const authoritativePaths = entry && Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths : [];
|
|
287
|
+
if (authoritativePaths.length === 0) {
|
|
288
|
+
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}`;
|
|
289
|
+
}
|
|
290
|
+
for (const cited of authoritativePaths) {
|
|
291
|
+
const value = typeof cited === 'string' ? cited.trim() : '';
|
|
292
|
+
const resolvedPath = value ? path.resolve(taskDir, value) : taskDir;
|
|
293
|
+
const relative = path.relative(taskDir, resolvedPath);
|
|
294
|
+
const escapes = !value || path.isAbsolute(value) || relative === '' || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative);
|
|
295
|
+
if (escapes) {
|
|
296
|
+
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}`;
|
|
297
|
+
}
|
|
298
|
+
let stat = null;
|
|
299
|
+
try { stat = fs.statSync(resolvedPath); } catch {}
|
|
300
|
+
if (!stat || !stat.isFile()) {
|
|
301
|
+
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}`;
|
|
302
|
+
}
|
|
303
|
+
if (/\.md[c]?$/i.test(value)) {
|
|
304
|
+
let content = '';
|
|
305
|
+
try { content = fs.readFileSync(resolvedPath, 'utf8'); } catch {}
|
|
306
|
+
if (!/\S/.test(content)) {
|
|
307
|
+
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}`;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
|
|
238
314
|
function readBoundReceiptOutcome(agent, step, resolved) {
|
|
239
315
|
if (!agent || !resolved) return { outcome: null, receiptRequired: false };
|
|
240
316
|
const manifestPath = path.join(taskDir, 'artifact-manifest.json');
|
|
241
|
-
|
|
317
|
+
const expectedOutputId = artifactOutputIdFor(step, agent);
|
|
318
|
+
if (!fs.existsSync(manifestPath)) {
|
|
319
|
+
// A1: absent manifest + a parsed modern pipeline denies silent advancement.
|
|
320
|
+
// Legacy/step-less pipelines keep their previous behaviour (legacyFlow owns them).
|
|
321
|
+
if (!(Array.isArray(steps) && steps.length > 0)) return { outcome: null, receiptRequired: false };
|
|
322
|
+
const seeded = writeSkeletonManifest(manifestPath);
|
|
323
|
+
const stepIndex = typeof resolved.entry.stepIndex === 'number' ? resolved.entry.stepIndex : 0;
|
|
324
|
+
if (seeded) {
|
|
325
|
+
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}` };
|
|
326
|
+
}
|
|
327
|
+
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}` };
|
|
328
|
+
}
|
|
242
329
|
try {
|
|
243
330
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
331
|
+
// Guard: the schema key is `artifacts` (see agent-artifact-contracts.md). A top-level
|
|
332
|
+
// `entries` key is a silent bug — producer wrote to a wrong field, hook would not
|
|
333
|
+
// see the receipt, and the step hangs in `awaiting_artifact_receipt`. Warn loudly.
|
|
334
|
+
if (manifest && typeof manifest === 'object' && !Array.isArray(manifest.artifacts) && Array.isArray(manifest.entries)) {
|
|
335
|
+
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');
|
|
336
|
+
} else if (manifest && typeof manifest === 'object' && Array.isArray(manifest.entries) && Array.isArray(manifest.artifacts)) {
|
|
337
|
+
process.stderr.write(`WARNING: ${manifestPath} has both "artifacts" and "entries" keys; reading only "artifacts" per schema. Foreign "entries" content is ignored.` + '\n');
|
|
338
|
+
}
|
|
244
339
|
const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
|
|
245
|
-
const expectedOutputId = artifactOutputIdFor(step, agent);
|
|
246
340
|
const attemptStartedAt = Date.parse(resolved.entry.startedAt);
|
|
341
|
+
// Pre-scan: warn on the silent-bug classes the filter below would otherwise drop.
|
|
342
|
+
// A receipt with a non-matching attemptId is dropped silently; without this warning,
|
|
343
|
+
// the step hangs in `awaiting_artifact_receipt` with no signal of why. Same for
|
|
344
|
+
// receipts whose terminal timestamp is older than the active attempt (stale retry).
|
|
345
|
+
const activeIds = new Set(Object.keys(status.activeAttempts || {}));
|
|
346
|
+
for (const entry of artifacts) {
|
|
347
|
+
if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') continue;
|
|
348
|
+
const rid = entry.receipt.attemptId;
|
|
349
|
+
if (typeof rid === 'string' && rid !== resolved.attemptId && !activeIds.has(rid)) {
|
|
350
|
+
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');
|
|
351
|
+
}
|
|
352
|
+
const terminalAt = Date.parse(entry.timestamps?.completedAt || entry.timestamps?.updatedAt || '');
|
|
353
|
+
if (Number.isFinite(attemptStartedAt) && Number.isFinite(terminalAt) && terminalAt < attemptStartedAt) {
|
|
354
|
+
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');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
247
357
|
const owned = artifacts
|
|
248
358
|
.filter((entry) => {
|
|
249
359
|
if (!entry || entry.producer !== agent || !entry.receipt || typeof entry.receipt.outcome !== 'string') return false;
|
|
@@ -258,19 +368,33 @@ function readBoundReceiptOutcome(agent, step, resolved) {
|
|
|
258
368
|
const tb = Date.parse(b.timestamps?.completedAt || b.timestamps?.updatedAt || 0) || 0;
|
|
259
369
|
return tb - ta;
|
|
260
370
|
});
|
|
261
|
-
|
|
371
|
+
// Bonus: warn if the active attempt's receipts all lack attemptId in a non-parallel step.
|
|
372
|
+
// The orchestrator always provides attemptId, so a missing one means the agent dropped it
|
|
373
|
+
// (model output, JSON.stringify omission, etc.). boundByOutput still binds the receipt by
|
|
374
|
+
// expectedOutputId, so this is not fatal — but it is a contract violation worth flagging.
|
|
375
|
+
if (owned.length > 0 && owned[0].receipt.attemptId == null && !(step && step.parallel && Array.isArray(getStepAgents(step)) && getStepAgents(step).length > 1)) {
|
|
376
|
+
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');
|
|
377
|
+
}
|
|
378
|
+
const outcome = owned[0]?.receipt?.outcome || null;
|
|
379
|
+
if (outcome === 'completed') {
|
|
380
|
+
const stallMessage = validateCompletedArtifact(owned[0]);
|
|
381
|
+
if (stallMessage) return { outcome: null, receiptRequired: true, stallMessage };
|
|
382
|
+
}
|
|
383
|
+
return { outcome, receiptRequired: true };
|
|
262
384
|
} catch {
|
|
263
385
|
return { outcome: null, receiptRequired: false };
|
|
264
386
|
}
|
|
265
387
|
}
|
|
266
388
|
function reconcileStatusFromManifest(agent, step, resolved) {
|
|
267
389
|
const terminal = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
|
|
268
|
-
|
|
390
|
+
artifactStallMessage = null;
|
|
391
|
+
const { outcome, receiptRequired, stallMessage } = readBoundReceiptOutcome(agent, step, resolved);
|
|
269
392
|
if (terminal.has(outcome)) {
|
|
270
393
|
status.state = outcome;
|
|
271
394
|
return outcome;
|
|
272
395
|
}
|
|
273
396
|
if (receiptRequired) {
|
|
397
|
+
artifactStallMessage = stallMessage || null;
|
|
274
398
|
status.state = 'awaiting_artifact_receipt';
|
|
275
399
|
status.phase = 'blocked';
|
|
276
400
|
return status.state;
|
|
@@ -329,6 +453,15 @@ function out(message) {
|
|
|
329
453
|
process.stdout.write(JSON.stringify({ followup_message: message }));
|
|
330
454
|
}
|
|
331
455
|
|
|
456
|
+
// The stall text always reaches stderr so a second, different rejection is never
|
|
457
|
+
// silent; `out()` fires only when the stop enters the stall, so the follow-up
|
|
458
|
+
// message cannot loop.
|
|
459
|
+
function emitArtifactStall(message, announce) {
|
|
460
|
+
if (message) process.stderr.write(message + '\n');
|
|
461
|
+
if (message && announce) out(message);
|
|
462
|
+
else process.stdout.write('{}');
|
|
463
|
+
}
|
|
464
|
+
|
|
332
465
|
function readArtifact(name) {
|
|
333
466
|
const p = path.join(taskDir, name);
|
|
334
467
|
if (!fs.existsSync(p)) return '';
|
|
@@ -908,10 +1041,11 @@ const completingAgentHint = (() => {
|
|
|
908
1041
|
return getStepAgents(initialStep)[0];
|
|
909
1042
|
})();
|
|
910
1043
|
const reconcilingAttempt = resolvedAttempt();
|
|
1044
|
+
const wasWaitingForReceipt = status.state === 'awaiting_artifact_receipt';
|
|
911
1045
|
reconcileStatusFromManifest(completingAgentHint, initialStep, reconcilingAttempt);
|
|
912
1046
|
if (status.state === 'awaiting_artifact_receipt') {
|
|
913
1047
|
writeStatus({});
|
|
914
|
-
|
|
1048
|
+
emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
|
|
915
1049
|
process.exit(0);
|
|
916
1050
|
}
|
|
917
1051
|
let finishedAttempt = finishActiveAttempt();
|
|
@@ -921,6 +1055,11 @@ if (!finishedAttempt && activeAttemptCountBeforeFinish > 0) {
|
|
|
921
1055
|
if (repaired) {
|
|
922
1056
|
appendMetric({ type: 'parallel_attribution_repair', at: now, attemptIds: [repaired.attemptId], source: 'hook', attributionConfidence: 'fallback' });
|
|
923
1057
|
reconcileStatusFromManifest(repaired.entry.agent, steps[repaired.entry.stepIndex], repaired);
|
|
1058
|
+
if (status.state === 'awaiting_artifact_receipt') {
|
|
1059
|
+
writeStatus({});
|
|
1060
|
+
emitArtifactStall(artifactStallMessage, true);
|
|
1061
|
+
process.exit(0);
|
|
1062
|
+
}
|
|
924
1063
|
finishedAttempt = finishActiveAttempt(repaired);
|
|
925
1064
|
} else {
|
|
926
1065
|
writeStatus({});
|
|
@@ -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).
|
|
@@ -7,11 +7,11 @@ Staged at `.mavis/mcp.json` on `ai-rules init mavis --preset android-kotlin`.
|
|
|
7
7
|
| Name | Package | Purpose |
|
|
8
8
|
|------|---------|---------|
|
|
9
9
|
| `context7` | `@upstash/context7-mcp` | Up-to-date Kotlin / Jetpack Compose / Android SDK docs |
|
|
10
|
-
| `figma` |
|
|
10
|
+
| `figma` | desktop `http://127.0.0.1:3845/mcp` | Design context → Jetpack Compose; local desktop server (enable in Figma Desktop, Dev/Full seat) |
|
|
11
11
|
|
|
12
12
|
Playwright / Chrome DevTools are **not** part of the **android-kotlin preset** (browser e2e is forbidden for the agent team).
|
|
13
13
|
|
|
14
|
-
Do not put secrets in the file. Optional: `CONTEXT7_API_KEY` in the environment. Figma —
|
|
14
|
+
Do not put secrets in the file. Optional: `CONTEXT7_API_KEY` in the environment. Figma — local desktop server (enable in Figma Desktop, Dev/Full seat).
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
## Agent usage
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"platform": "mavis",
|
|
4
4
|
"stack": "android-kotlin",
|
|
5
5
|
"semanticSource": "cursor/android-kotlin",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "9c11ac6534821bd4e63749b2c55f31686d9d8415e9c8b7b33443886dca5cf05d",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
9
9
|
"source": "AGENTS.md",
|