@bonesofspring/ai-rules 0.2.71 → 0.2.72
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/CHANGELOG.md +24 -0
- package/bin/lib/engine-scripts.js +9 -0
- package/docs/OPENCODE.md +4 -2
- package/docs/TEAM-DB.md +10 -7
- package/package.json +1 -1
- package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +201 -0
- package/presets/_shared/ai-local/scripts/incidents.mjs +452 -0
- package/presets/_shared/ai-local/scripts/record-usage.mjs +163 -0
- package/presets/_shared/ai-local/scripts/team-db-project.mjs +2 -0
- package/presets/_shared/ai-local/scripts/verification.mjs +374 -0
- package/presets/_shared/core/agent-team/agent-task-metrics.md +61 -1
- package/presets/_shared/core/agent-team/agent-team-orchestrator.md +5 -4
- package/presets/_shared/core/agent-team/incident-registry.md +47 -0
- package/presets/_shared/core/architecture/feature-delivery-workflow.md +1 -1
- package/presets/_shared/hooks/chain-team-phases.sh.tmpl +108 -1
- package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/go/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/go/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/ios-swift/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/java/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/java/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/mcp-ts/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/mol/rules/architecture/feature-delivery-workflow.md +1 -1
- package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/next/agents/README.md +4 -3
- package/presets/claude/next/agents/api-contract-reviewer.md +1 -1
- package/presets/claude/next/agents/mockup-reviewer.md +1 -1
- package/presets/claude/next/agents/task-router.md +4 -4
- package/presets/claude/next/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/next/rules/architecture/feature-delivery-workflow.md +2 -2
- package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/nuxt/rules/architecture/feature-delivery-workflow.md +1 -1
- package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/php-hexagonal/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/php-laravel/rules/architecture/feature-delivery.md +1 -1
- package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/claude/svelte/hooks/chain-team-phases.sh +108 -1
- package/presets/claude/svelte/rules/architecture/feature-delivery-workflow.md +1 -1
- package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
- package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/go/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/java/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/next/agents/README.md +4 -3
- package/presets/cursor/next/agents/api-contract-reviewer.md +1 -1
- package/presets/cursor/next/agents/mockup-reviewer.md +1 -1
- package/presets/cursor/next/agents/task-router.md +4 -4
- package/presets/cursor/next/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/next/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/next/rules/feature-delivery-workflow.mdc +1 -1
- package/presets/cursor/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/cursor/svelte/hooks/chain-team-phases.sh +108 -1
- package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
- package/presets/mavis/android-kotlin/adapter-map.json +1 -1
- package/presets/mavis/android-kotlin/agents/README.md +3 -3
- package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/go/adapter-map.json +1 -1
- package/presets/mavis/go/agents/README.md +2 -2
- package/presets/mavis/go/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/go/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/go/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/ios-swift/adapter-map.json +1 -1
- package/presets/mavis/ios-swift/agents/README.md +3 -3
- package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/ios-swift/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/java/adapter-map.json +1 -1
- package/presets/mavis/java/agents/README.md +2 -2
- package/presets/mavis/java/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/java/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/java/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/mcp-ts/adapter-map.json +1 -1
- package/presets/mavis/mcp-ts/agents/README.md +1 -1
- package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/mcp-ts/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/mol/adapter-map.json +1 -1
- package/presets/mavis/mol/agents/README.md +3 -3
- package/presets/mavis/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/mol/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/mol/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/next/adapter-map.json +1 -1
- package/presets/mavis/next/agents/README.md +3 -3
- package/presets/mavis/next/agents/task-router.md +4 -4
- package/presets/mavis/next/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/next/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/next/rules/feature-delivery-workflow.md +2 -2
- package/presets/mavis/nuxt/adapter-map.json +1 -1
- package/presets/mavis/nuxt/agents/README.md +3 -3
- package/presets/mavis/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/nuxt/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
- package/presets/mavis/php-hexagonal/agents/README.md +2 -2
- package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/php-hexagonal/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/php-laravel/adapter-map.json +1 -1
- package/presets/mavis/php-laravel/agents/README.md +2 -2
- package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/php-laravel/rules/feature-delivery-workflow.md +1 -1
- package/presets/mavis/svelte/adapter-map.json +1 -1
- package/presets/mavis/svelte/agents/README.md +3 -3
- package/presets/mavis/svelte/hooks/chain-team-phases.sh +108 -1
- package/presets/mavis/svelte/rules/agent-team-orchestrator.md +5 -4
- package/presets/mavis/svelte/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/android-kotlin/adapter-map.json +1 -1
- package/presets/opencode/android-kotlin/agents/README.md +4 -4
- package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/go/adapter-map.json +1 -1
- package/presets/opencode/go/agents/README.md +3 -3
- package/presets/opencode/go/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/go/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/go/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/ios-swift/adapter-map.json +1 -1
- package/presets/opencode/ios-swift/agents/README.md +4 -4
- package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/ios-swift/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/java/adapter-map.json +1 -1
- package/presets/opencode/java/agents/README.md +3 -3
- package/presets/opencode/java/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/java/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/java/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/mcp-ts/adapter-map.json +1 -1
- package/presets/opencode/mcp-ts/agents/README.md +2 -2
- package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/mcp-ts/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/mol/adapter-map.json +1 -1
- package/presets/opencode/mol/agents/README.md +4 -4
- package/presets/opencode/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/mol/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/mol/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/next/adapter-map.json +1 -1
- package/presets/opencode/next/agents/README.md +4 -4
- package/presets/opencode/next/agents/task-router.md +4 -4
- package/presets/opencode/next/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/next/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/next/rules/feature-delivery-workflow.md +2 -2
- package/presets/opencode/nuxt/adapter-map.json +1 -1
- package/presets/opencode/nuxt/agents/README.md +4 -4
- package/presets/opencode/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/nuxt/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
- package/presets/opencode/php-hexagonal/agents/README.md +3 -3
- package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/php-hexagonal/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/php-laravel/adapter-map.json +1 -1
- package/presets/opencode/php-laravel/agents/README.md +3 -3
- package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/php-laravel/rules/feature-delivery-workflow.md +1 -1
- package/presets/opencode/plugins/output-guard/README.md +17 -4
- package/presets/opencode/plugins/output-guard/index.ts +27 -9
- package/presets/opencode/plugins/output-guard/rewrite.ts +104 -1
- package/presets/opencode/svelte/adapter-map.json +1 -1
- package/presets/opencode/svelte/agents/README.md +4 -4
- package/presets/opencode/svelte/hooks/chain-team-phases.sh +108 -1
- package/presets/opencode/svelte/rules/agent-team-orchestrator.md +5 -4
- package/presets/opencode/svelte/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/android-kotlin/adapter-map.json +1 -1
- package/presets/zcode/android-kotlin/agents/README.md +3 -3
- package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/go/adapter-map.json +1 -1
- package/presets/zcode/go/agents/README.md +2 -2
- package/presets/zcode/go/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/go/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/go/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/ios-swift/adapter-map.json +1 -1
- package/presets/zcode/ios-swift/agents/README.md +3 -3
- package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/ios-swift/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/java/adapter-map.json +1 -1
- package/presets/zcode/java/agents/README.md +2 -2
- package/presets/zcode/java/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/java/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/java/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/mcp-ts/adapter-map.json +1 -1
- package/presets/zcode/mcp-ts/agents/README.md +1 -1
- package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/mcp-ts/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/mol/adapter-map.json +1 -1
- package/presets/zcode/mol/agents/README.md +3 -3
- package/presets/zcode/mol/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/mol/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/mol/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/next/adapter-map.json +1 -1
- package/presets/zcode/next/agents/README.md +3 -3
- package/presets/zcode/next/agents/task-router.md +4 -4
- package/presets/zcode/next/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/next/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/next/rules/feature-delivery-workflow.md +2 -2
- package/presets/zcode/nuxt/adapter-map.json +1 -1
- package/presets/zcode/nuxt/agents/README.md +3 -3
- package/presets/zcode/nuxt/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/nuxt/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
- package/presets/zcode/php-hexagonal/agents/README.md +2 -2
- package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/php-hexagonal/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/php-laravel/adapter-map.json +1 -1
- package/presets/zcode/php-laravel/agents/README.md +2 -2
- package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/php-laravel/rules/feature-delivery-workflow.md +1 -1
- package/presets/zcode/svelte/adapter-map.json +1 -1
- package/presets/zcode/svelte/agents/README.md +3 -3
- package/presets/zcode/svelte/hooks/chain-team-phases.sh +108 -1
- package/presets/zcode/svelte/rules/agent-team-orchestrator.md +5 -4
- package/presets/zcode/svelte/rules/feature-delivery-workflow.md +1 -1
- package/scripts/aggregate-agent-task-metrics.mjs +201 -0
- package/scripts/report-context-cost.mjs +126 -0
|
@@ -979,11 +979,117 @@ function reconcileStatusFromManifest(agent, step, resolved) {
|
|
|
979
979
|
return status.state;
|
|
980
980
|
}
|
|
981
981
|
|
|
982
|
+
/**
|
|
983
|
+
* Keep only the numeric usage fields and the two provenance fields. A host may
|
|
984
|
+
* forward richer objects; the ledger is allowlisted so nothing unbounded or
|
|
985
|
+
* secret-shaped reaches `metrics.json`.
|
|
986
|
+
*/
|
|
987
|
+
function sanitizeUsage(value) {
|
|
988
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
989
|
+
const num = (input) => (typeof input === 'number' && Number.isFinite(input) && input >= 0 ? input : null);
|
|
990
|
+
const usage = {
|
|
991
|
+
input: num(value.input), output: num(value.output), reasoning: num(value.reasoning),
|
|
992
|
+
cacheRead: num(value.cacheRead === undefined ? value.cached : value.cacheRead),
|
|
993
|
+
cacheWrite: num(value.cacheWrite), costUsd: num(value.costUsd),
|
|
994
|
+
model: typeof value.model === 'string' ? value.model.slice(0, 120) : null,
|
|
995
|
+
origin: value.origin === 'estimated' ? 'estimated' : 'measured',
|
|
996
|
+
};
|
|
997
|
+
const reported = usage.input !== null || usage.output !== null || usage.reasoning !== null ||
|
|
998
|
+
usage.cacheRead !== null || usage.cacheWrite !== null || usage.costUsd !== null;
|
|
999
|
+
return reported ? usage : null;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Freshness of a persisted verification snapshot against the current worktree.
|
|
1004
|
+
* Read-only: closure warns, it never blocks on a stale snapshot.
|
|
1005
|
+
*/
|
|
1006
|
+
function gitSnapshot() {
|
|
1007
|
+
const { spawnSync } = require('child_process');
|
|
1008
|
+
const git = (args) => {
|
|
1009
|
+
const result = spawnSync('git', args, { cwd: process.cwd(), encoding: 'utf8', timeout: 10000, maxBuffer: 32 * 1024 * 1024 });
|
|
1010
|
+
return result && result.status === 0 ? String(result.stdout || '') : null;
|
|
1011
|
+
};
|
|
1012
|
+
const head = git(['rev-parse', 'HEAD']);
|
|
1013
|
+
if (head === null) return null;
|
|
1014
|
+
const branch = git(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
1015
|
+
const exclude = ['--', '.', ':(exclude).ai.local'];
|
|
1016
|
+
const statusText = git(['status', '--porcelain=v1', ...exclude]) || '';
|
|
1017
|
+
const diffText = git(['diff', '--binary', 'HEAD', ...exclude]) || '';
|
|
1018
|
+
const untracked = git(['ls-files', '--others', '--exclude-standard', ...exclude]) || '';
|
|
1019
|
+
return {
|
|
1020
|
+
head: head.trim(),
|
|
1021
|
+
branch: branch === null ? null : branch.trim(),
|
|
1022
|
+
dirtyFiles: statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length,
|
|
1023
|
+
worktreeHash: crypto.createHash('sha256').update(`${statusText}\u0000${diffText}\u0000${untracked}`).digest('hex'),
|
|
1024
|
+
capturedAt: now,
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Seed the evidence file when the verifier finishes without an explicit
|
|
1030
|
+
* `verification.mjs record`: the snapshot plus a hash of `validation-report.md`.
|
|
1031
|
+
* An existing file is never refreshed — its binding must keep pointing at the
|
|
1032
|
+
* tree the commands actually ran on.
|
|
1033
|
+
*/
|
|
1034
|
+
function ensureVerificationSnapshot(dir, agent) {
|
|
1035
|
+
const file = path.join(dir, 'verification.json');
|
|
1036
|
+
if (fs.existsSync(file)) return;
|
|
1037
|
+
const snapshot = gitSnapshot();
|
|
1038
|
+
if (!snapshot) return;
|
|
1039
|
+
const reportPath = path.join(dir, 'validation-report.md');
|
|
1040
|
+
let report = null;
|
|
1041
|
+
try {
|
|
1042
|
+
const text = fs.readFileSync(reportPath);
|
|
1043
|
+
report = { path: 'validation-report.md', sha256: crypto.createHash('sha256').update(text).digest('hex') };
|
|
1044
|
+
} catch {}
|
|
1045
|
+
const verification = {
|
|
1046
|
+
schemaVersion: 1,
|
|
1047
|
+
task: path.basename(dir),
|
|
1048
|
+
snapshot,
|
|
1049
|
+
report,
|
|
1050
|
+
commands: [],
|
|
1051
|
+
gate: { status: 'snapshot-only', recordedBy: agent || null, checkedAt: now },
|
|
1052
|
+
};
|
|
1053
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
1054
|
+
fs.writeFileSync(temporary, JSON.stringify(verification, null, 2) + '\n');
|
|
1055
|
+
fs.renameSync(temporary, file);
|
|
1056
|
+
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head, worktreeHash: snapshot.worktreeHash, source: 'hook', attributionConfidence: 'high' });
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function verificationFreshness(dir) {
|
|
1060
|
+
const file = path.join(dir, 'verification.json');
|
|
1061
|
+
if (!fs.existsSync(file)) return { present: false };
|
|
1062
|
+
let verification;
|
|
1063
|
+
try { verification = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return { present: true, fresh: false, reasons: ['unreadable'] }; }
|
|
1064
|
+
const snapshot = verification && verification.snapshot;
|
|
1065
|
+
if (!snapshot || typeof snapshot.head !== 'string') return { present: true, fresh: false, reasons: ['no-snapshot'] };
|
|
1066
|
+
const current = gitSnapshot();
|
|
1067
|
+
if (!current) return { present: true, fresh: false, reasons: ['no-git'] };
|
|
1068
|
+
const reasons = [];
|
|
1069
|
+
if (current.head !== snapshot.head) reasons.push('head-changed');
|
|
1070
|
+
if (current.worktreeHash !== snapshot.worktreeHash) reasons.push('worktree-changed');
|
|
1071
|
+
return { present: true, fresh: reasons.length === 0, reasons };
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
let verificationStaleNoted = false;
|
|
1075
|
+
|
|
1076
|
+
function noteVerificationFreshness(dir, agent) {
|
|
1077
|
+
if (verificationStaleNoted) return;
|
|
1078
|
+
const freshness = verificationFreshness(dir);
|
|
1079
|
+
if (!freshness.present) return;
|
|
1080
|
+
if (freshness.fresh) return;
|
|
1081
|
+
verificationStaleNoted = true;
|
|
1082
|
+
appendMetric({ type: 'verification_stale', at: now, agent: agent || null, reasons: freshness.reasons, source: 'hook', attributionConfidence: 'high' });
|
|
1083
|
+
process.stderr.write(`verification evidence is stale (${freshness.reasons.join(', ')}); re-run the gate and record it before closure\n`);
|
|
1084
|
+
}
|
|
1085
|
+
|
|
982
1086
|
function finishActiveAttempt(forced) {
|
|
983
1087
|
const resolved = forced || resolvedAttempt(); if (!resolved) return null;
|
|
984
1088
|
const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
|
|
985
1089
|
const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
|
|
986
|
-
|
|
1090
|
+
const usage = sanitizeUsage(hookInput.usage);
|
|
1091
|
+
appendMetric({ type: 'attempt_finished', at: now, attemptId: resolved.attemptId, outcome, durationMs: Number.isFinite(durationMs) && durationMs >= 0 ? durationMs : null, retryAfterFix: status.retryAfterFix || null, source: resolved.source || 'hook', attributionConfidence: resolved.confidence, ...(usage ? { usage } : {}) });
|
|
1092
|
+
if (resolved.entry && resolved.entry.agent === 'build-verifier') { ensureVerificationSnapshot(taskDir, resolved.entry.agent); noteVerificationFreshness(taskDir, resolved.entry.agent); }
|
|
987
1093
|
const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
|
|
988
1094
|
}
|
|
989
1095
|
function missingConsumerArtifacts() {
|
|
@@ -1013,6 +1119,7 @@ function completePipeline(statusPatch) {
|
|
|
1013
1119
|
// task_completed is written only on this branch. A missing receipt blocks
|
|
1014
1120
|
// above and must not be counted as a finished task.
|
|
1015
1121
|
status.state = 'completed';
|
|
1122
|
+
noteVerificationFreshness(taskDir, null);
|
|
1016
1123
|
completeTaskMetrics();
|
|
1017
1124
|
writeStatus(statusPatch);
|
|
1018
1125
|
out(`Pipeline complete for "${slug}". Run /technical-retro ${slug}.`);
|
|
@@ -99,7 +99,7 @@ Each producing agent runs a **pre-receipt self-review** of its own output — go
|
|
|
99
99
|
|
|
100
100
|
## Context budget & checkpoint/resume
|
|
101
101
|
|
|
102
|
-
Work in bounded waves (one artifact class across the surface). **Checkpoint** each completed wave to `.memlog.md` (`## <date>` + an `event:` line) and record produced paths on the `implementation` manifest entry `authoritativePaths`. A resumed run (e.g. `/task-continue`) reads `artifact-manifest.json` + `.memlog.md` and continues at the first stage whose exit criteria are unmet — never re-derive state from the chat. An **interrupted producer** (tool abort, killed session) is resumed, not restarted: run the stack's compile gate on the working tree first, and when it is red hand the failing output to the same producer with a `fix and finish` brief instead of starting a second parallel attempt. When the host runtime writes no `status.json` (manual-hook hosts such as OpenCode), the resume checkpoint is `artifact-manifest.json` + `.memlog.md`; never gate a resume on a file the runtime does not produce. Mechanical waves (generation, embed sync) are delegated to repo scripts. A large command output (log, diff, test run, `git log`) is piped through `.ai.local/scripts/dump-output.mjs` instead of being read whole: take its ≤40-line head, then `grep -n` the stored file or find it with `team-db.mjs search "<term>"`.
|
|
102
|
+
Work in bounded waves (one artifact class across the surface). **Checkpoint** each completed wave to `.memlog.md` (`## <date>` + an `event:` line) and record produced paths on the `implementation` manifest entry `authoritativePaths`. A resumed run (e.g. `/task-continue`) reads `artifact-manifest.json` + `.memlog.md` and continues at the first stage whose exit criteria are unmet — never re-derive state from the chat. A session approaching ~50 turns does not keep growing its history: the producer finishes the current wave, checkpoints it (`focus.md` + `artifact-manifest.json` + `.memlog.md`), and hands off to a fresh session. A wave that cannot finish before the cap checkpoints its partial state the same way. An **interrupted producer** (tool abort, killed session) is resumed, not restarted: run the stack's compile gate on the working tree first, and when it is red hand the failing output to the same producer with a `fix and finish` brief instead of starting a second parallel attempt. When the host runtime writes no `status.json` (manual-hook hosts such as OpenCode), the resume checkpoint is `artifact-manifest.json` + `.memlog.md`; never gate a resume on a file the runtime does not produce. Mechanical waves (generation, embed sync) are delegated to repo scripts. A large command output (log, diff, test run, `git log`) is piped through `.ai.local/scripts/dump-output.mjs` instead of being read whole: take its ≤40-line head, then `grep -n` the stored file or find it with `team-db.mjs search "<term>"`.
|
|
103
103
|
|
|
104
104
|
## status.json (pipeline mode)
|
|
105
105
|
|
|
@@ -967,11 +967,117 @@ function reconcileStatusFromManifest(agent, step, resolved) {
|
|
|
967
967
|
return status.state;
|
|
968
968
|
}
|
|
969
969
|
|
|
970
|
+
/**
|
|
971
|
+
* Keep only the numeric usage fields and the two provenance fields. A host may
|
|
972
|
+
* forward richer objects; the ledger is allowlisted so nothing unbounded or
|
|
973
|
+
* secret-shaped reaches `metrics.json`.
|
|
974
|
+
*/
|
|
975
|
+
function sanitizeUsage(value) {
|
|
976
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
977
|
+
const num = (input) => (typeof input === 'number' && Number.isFinite(input) && input >= 0 ? input : null);
|
|
978
|
+
const usage = {
|
|
979
|
+
input: num(value.input), output: num(value.output), reasoning: num(value.reasoning),
|
|
980
|
+
cacheRead: num(value.cacheRead === undefined ? value.cached : value.cacheRead),
|
|
981
|
+
cacheWrite: num(value.cacheWrite), costUsd: num(value.costUsd),
|
|
982
|
+
model: typeof value.model === 'string' ? value.model.slice(0, 120) : null,
|
|
983
|
+
origin: value.origin === 'estimated' ? 'estimated' : 'measured',
|
|
984
|
+
};
|
|
985
|
+
const reported = usage.input !== null || usage.output !== null || usage.reasoning !== null ||
|
|
986
|
+
usage.cacheRead !== null || usage.cacheWrite !== null || usage.costUsd !== null;
|
|
987
|
+
return reported ? usage : null;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Freshness of a persisted verification snapshot against the current worktree.
|
|
992
|
+
* Read-only: closure warns, it never blocks on a stale snapshot.
|
|
993
|
+
*/
|
|
994
|
+
function gitSnapshot() {
|
|
995
|
+
const { spawnSync } = require('child_process');
|
|
996
|
+
const git = (args) => {
|
|
997
|
+
const result = spawnSync('git', args, { cwd: process.cwd(), encoding: 'utf8', timeout: 10000, maxBuffer: 32 * 1024 * 1024 });
|
|
998
|
+
return result && result.status === 0 ? String(result.stdout || '') : null;
|
|
999
|
+
};
|
|
1000
|
+
const head = git(['rev-parse', 'HEAD']);
|
|
1001
|
+
if (head === null) return null;
|
|
1002
|
+
const branch = git(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
1003
|
+
const exclude = ['--', '.', ':(exclude).ai.local'];
|
|
1004
|
+
const statusText = git(['status', '--porcelain=v1', ...exclude]) || '';
|
|
1005
|
+
const diffText = git(['diff', '--binary', 'HEAD', ...exclude]) || '';
|
|
1006
|
+
const untracked = git(['ls-files', '--others', '--exclude-standard', ...exclude]) || '';
|
|
1007
|
+
return {
|
|
1008
|
+
head: head.trim(),
|
|
1009
|
+
branch: branch === null ? null : branch.trim(),
|
|
1010
|
+
dirtyFiles: statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length,
|
|
1011
|
+
worktreeHash: crypto.createHash('sha256').update(`${statusText}\u0000${diffText}\u0000${untracked}`).digest('hex'),
|
|
1012
|
+
capturedAt: now,
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* Seed the evidence file when the verifier finishes without an explicit
|
|
1018
|
+
* `verification.mjs record`: the snapshot plus a hash of `validation-report.md`.
|
|
1019
|
+
* An existing file is never refreshed — its binding must keep pointing at the
|
|
1020
|
+
* tree the commands actually ran on.
|
|
1021
|
+
*/
|
|
1022
|
+
function ensureVerificationSnapshot(dir, agent) {
|
|
1023
|
+
const file = path.join(dir, 'verification.json');
|
|
1024
|
+
if (fs.existsSync(file)) return;
|
|
1025
|
+
const snapshot = gitSnapshot();
|
|
1026
|
+
if (!snapshot) return;
|
|
1027
|
+
const reportPath = path.join(dir, 'validation-report.md');
|
|
1028
|
+
let report = null;
|
|
1029
|
+
try {
|
|
1030
|
+
const text = fs.readFileSync(reportPath);
|
|
1031
|
+
report = { path: 'validation-report.md', sha256: crypto.createHash('sha256').update(text).digest('hex') };
|
|
1032
|
+
} catch {}
|
|
1033
|
+
const verification = {
|
|
1034
|
+
schemaVersion: 1,
|
|
1035
|
+
task: path.basename(dir),
|
|
1036
|
+
snapshot,
|
|
1037
|
+
report,
|
|
1038
|
+
commands: [],
|
|
1039
|
+
gate: { status: 'snapshot-only', recordedBy: agent || null, checkedAt: now },
|
|
1040
|
+
};
|
|
1041
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
1042
|
+
fs.writeFileSync(temporary, JSON.stringify(verification, null, 2) + '\n');
|
|
1043
|
+
fs.renameSync(temporary, file);
|
|
1044
|
+
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head, worktreeHash: snapshot.worktreeHash, source: 'hook', attributionConfidence: 'high' });
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function verificationFreshness(dir) {
|
|
1048
|
+
const file = path.join(dir, 'verification.json');
|
|
1049
|
+
if (!fs.existsSync(file)) return { present: false };
|
|
1050
|
+
let verification;
|
|
1051
|
+
try { verification = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return { present: true, fresh: false, reasons: ['unreadable'] }; }
|
|
1052
|
+
const snapshot = verification && verification.snapshot;
|
|
1053
|
+
if (!snapshot || typeof snapshot.head !== 'string') return { present: true, fresh: false, reasons: ['no-snapshot'] };
|
|
1054
|
+
const current = gitSnapshot();
|
|
1055
|
+
if (!current) return { present: true, fresh: false, reasons: ['no-git'] };
|
|
1056
|
+
const reasons = [];
|
|
1057
|
+
if (current.head !== snapshot.head) reasons.push('head-changed');
|
|
1058
|
+
if (current.worktreeHash !== snapshot.worktreeHash) reasons.push('worktree-changed');
|
|
1059
|
+
return { present: true, fresh: reasons.length === 0, reasons };
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
let verificationStaleNoted = false;
|
|
1063
|
+
|
|
1064
|
+
function noteVerificationFreshness(dir, agent) {
|
|
1065
|
+
if (verificationStaleNoted) return;
|
|
1066
|
+
const freshness = verificationFreshness(dir);
|
|
1067
|
+
if (!freshness.present) return;
|
|
1068
|
+
if (freshness.fresh) return;
|
|
1069
|
+
verificationStaleNoted = true;
|
|
1070
|
+
appendMetric({ type: 'verification_stale', at: now, agent: agent || null, reasons: freshness.reasons, source: 'hook', attributionConfidence: 'high' });
|
|
1071
|
+
process.stderr.write(`verification evidence is stale (${freshness.reasons.join(', ')}); re-run the gate and record it before closure\n`);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
970
1074
|
function finishActiveAttempt(forced) {
|
|
971
1075
|
const resolved = forced || resolvedAttempt(); if (!resolved) return null;
|
|
972
1076
|
const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
|
|
973
1077
|
const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
|
|
974
|
-
|
|
1078
|
+
const usage = sanitizeUsage(hookInput.usage);
|
|
1079
|
+
appendMetric({ type: 'attempt_finished', at: now, attemptId: resolved.attemptId, outcome, durationMs: Number.isFinite(durationMs) && durationMs >= 0 ? durationMs : null, retryAfterFix: status.retryAfterFix || null, source: resolved.source || 'hook', attributionConfidence: resolved.confidence, ...(usage ? { usage } : {}) });
|
|
1080
|
+
if (resolved.entry && resolved.entry.agent === 'build-verifier') { ensureVerificationSnapshot(taskDir, resolved.entry.agent); noteVerificationFreshness(taskDir, resolved.entry.agent); }
|
|
975
1081
|
const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
|
|
976
1082
|
}
|
|
977
1083
|
function missingConsumerArtifacts() {
|
|
@@ -1001,6 +1107,7 @@ function completePipeline(statusPatch) {
|
|
|
1001
1107
|
// task_completed is written only on this branch. A missing receipt blocks
|
|
1002
1108
|
// above and must not be counted as a finished task.
|
|
1003
1109
|
status.state = 'completed';
|
|
1110
|
+
noteVerificationFreshness(taskDir, null);
|
|
1004
1111
|
completeTaskMetrics();
|
|
1005
1112
|
writeStatus(statusPatch);
|
|
1006
1113
|
out(`Pipeline complete for "${slug}". Run /technical-retro ${slug}.`);
|
|
@@ -99,7 +99,7 @@ Each producing agent runs a **pre-receipt self-review** of its own output — go
|
|
|
99
99
|
|
|
100
100
|
## Context budget & checkpoint/resume
|
|
101
101
|
|
|
102
|
-
Work in bounded waves (one artifact class across the surface). **Checkpoint** each completed wave to `.memlog.md` (`## <date>` + an `event:` line) and record produced paths on the `implementation` manifest entry `authoritativePaths`. A resumed run (e.g. `/task-continue`) reads `artifact-manifest.json` + `.memlog.md` and continues at the first stage whose exit criteria are unmet — never re-derive state from the chat. An **interrupted producer** (tool abort, killed session) is resumed, not restarted: run the stack's compile gate on the working tree first, and when it is red hand the failing output to the same producer with a `fix and finish` brief instead of starting a second parallel attempt. When the host runtime writes no `status.json` (manual-hook hosts such as OpenCode), the resume checkpoint is `artifact-manifest.json` + `.memlog.md`; never gate a resume on a file the runtime does not produce. Mechanical waves (generation, embed sync) are delegated to repo scripts. A large command output (log, diff, test run, `git log`) is piped through `.ai.local/scripts/dump-output.mjs` instead of being read whole: take its ≤40-line head, then `grep -n` the stored file or find it with `team-db.mjs search "<term>"`.
|
|
102
|
+
Work in bounded waves (one artifact class across the surface). **Checkpoint** each completed wave to `.memlog.md` (`## <date>` + an `event:` line) and record produced paths on the `implementation` manifest entry `authoritativePaths`. A resumed run (e.g. `/task-continue`) reads `artifact-manifest.json` + `.memlog.md` and continues at the first stage whose exit criteria are unmet — never re-derive state from the chat. A session approaching ~50 turns does not keep growing its history: the producer finishes the current wave, checkpoints it (`focus.md` + `artifact-manifest.json` + `.memlog.md`), and hands off to a fresh session. A wave that cannot finish before the cap checkpoints its partial state the same way. An **interrupted producer** (tool abort, killed session) is resumed, not restarted: run the stack's compile gate on the working tree first, and when it is red hand the failing output to the same producer with a `fix and finish` brief instead of starting a second parallel attempt. When the host runtime writes no `status.json` (manual-hook hosts such as OpenCode), the resume checkpoint is `artifact-manifest.json` + `.memlog.md`; never gate a resume on a file the runtime does not produce. Mechanical waves (generation, embed sync) are delegated to repo scripts. A large command output (log, diff, test run, `git log`) is piped through `.ai.local/scripts/dump-output.mjs` instead of being read whole: take its ≤40-line head, then `grep -n` the stored file or find it with `team-db.mjs search "<term>"`.
|
|
103
103
|
|
|
104
104
|
## status.json (pipeline mode)
|
|
105
105
|
|
|
@@ -980,11 +980,117 @@ function reconcileStatusFromManifest(agent, step, resolved) {
|
|
|
980
980
|
return status.state;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
/**
|
|
984
|
+
* Keep only the numeric usage fields and the two provenance fields. A host may
|
|
985
|
+
* forward richer objects; the ledger is allowlisted so nothing unbounded or
|
|
986
|
+
* secret-shaped reaches `metrics.json`.
|
|
987
|
+
*/
|
|
988
|
+
function sanitizeUsage(value) {
|
|
989
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
990
|
+
const num = (input) => (typeof input === 'number' && Number.isFinite(input) && input >= 0 ? input : null);
|
|
991
|
+
const usage = {
|
|
992
|
+
input: num(value.input), output: num(value.output), reasoning: num(value.reasoning),
|
|
993
|
+
cacheRead: num(value.cacheRead === undefined ? value.cached : value.cacheRead),
|
|
994
|
+
cacheWrite: num(value.cacheWrite), costUsd: num(value.costUsd),
|
|
995
|
+
model: typeof value.model === 'string' ? value.model.slice(0, 120) : null,
|
|
996
|
+
origin: value.origin === 'estimated' ? 'estimated' : 'measured',
|
|
997
|
+
};
|
|
998
|
+
const reported = usage.input !== null || usage.output !== null || usage.reasoning !== null ||
|
|
999
|
+
usage.cacheRead !== null || usage.cacheWrite !== null || usage.costUsd !== null;
|
|
1000
|
+
return reported ? usage : null;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Freshness of a persisted verification snapshot against the current worktree.
|
|
1005
|
+
* Read-only: closure warns, it never blocks on a stale snapshot.
|
|
1006
|
+
*/
|
|
1007
|
+
function gitSnapshot() {
|
|
1008
|
+
const { spawnSync } = require('child_process');
|
|
1009
|
+
const git = (args) => {
|
|
1010
|
+
const result = spawnSync('git', args, { cwd: process.cwd(), encoding: 'utf8', timeout: 10000, maxBuffer: 32 * 1024 * 1024 });
|
|
1011
|
+
return result && result.status === 0 ? String(result.stdout || '') : null;
|
|
1012
|
+
};
|
|
1013
|
+
const head = git(['rev-parse', 'HEAD']);
|
|
1014
|
+
if (head === null) return null;
|
|
1015
|
+
const branch = git(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
1016
|
+
const exclude = ['--', '.', ':(exclude).ai.local'];
|
|
1017
|
+
const statusText = git(['status', '--porcelain=v1', ...exclude]) || '';
|
|
1018
|
+
const diffText = git(['diff', '--binary', 'HEAD', ...exclude]) || '';
|
|
1019
|
+
const untracked = git(['ls-files', '--others', '--exclude-standard', ...exclude]) || '';
|
|
1020
|
+
return {
|
|
1021
|
+
head: head.trim(),
|
|
1022
|
+
branch: branch === null ? null : branch.trim(),
|
|
1023
|
+
dirtyFiles: statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length,
|
|
1024
|
+
worktreeHash: crypto.createHash('sha256').update(`${statusText}\u0000${diffText}\u0000${untracked}`).digest('hex'),
|
|
1025
|
+
capturedAt: now,
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* Seed the evidence file when the verifier finishes without an explicit
|
|
1031
|
+
* `verification.mjs record`: the snapshot plus a hash of `validation-report.md`.
|
|
1032
|
+
* An existing file is never refreshed — its binding must keep pointing at the
|
|
1033
|
+
* tree the commands actually ran on.
|
|
1034
|
+
*/
|
|
1035
|
+
function ensureVerificationSnapshot(dir, agent) {
|
|
1036
|
+
const file = path.join(dir, 'verification.json');
|
|
1037
|
+
if (fs.existsSync(file)) return;
|
|
1038
|
+
const snapshot = gitSnapshot();
|
|
1039
|
+
if (!snapshot) return;
|
|
1040
|
+
const reportPath = path.join(dir, 'validation-report.md');
|
|
1041
|
+
let report = null;
|
|
1042
|
+
try {
|
|
1043
|
+
const text = fs.readFileSync(reportPath);
|
|
1044
|
+
report = { path: 'validation-report.md', sha256: crypto.createHash('sha256').update(text).digest('hex') };
|
|
1045
|
+
} catch {}
|
|
1046
|
+
const verification = {
|
|
1047
|
+
schemaVersion: 1,
|
|
1048
|
+
task: path.basename(dir),
|
|
1049
|
+
snapshot,
|
|
1050
|
+
report,
|
|
1051
|
+
commands: [],
|
|
1052
|
+
gate: { status: 'snapshot-only', recordedBy: agent || null, checkedAt: now },
|
|
1053
|
+
};
|
|
1054
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
1055
|
+
fs.writeFileSync(temporary, JSON.stringify(verification, null, 2) + '\n');
|
|
1056
|
+
fs.renameSync(temporary, file);
|
|
1057
|
+
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head, worktreeHash: snapshot.worktreeHash, source: 'hook', attributionConfidence: 'high' });
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function verificationFreshness(dir) {
|
|
1061
|
+
const file = path.join(dir, 'verification.json');
|
|
1062
|
+
if (!fs.existsSync(file)) return { present: false };
|
|
1063
|
+
let verification;
|
|
1064
|
+
try { verification = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return { present: true, fresh: false, reasons: ['unreadable'] }; }
|
|
1065
|
+
const snapshot = verification && verification.snapshot;
|
|
1066
|
+
if (!snapshot || typeof snapshot.head !== 'string') return { present: true, fresh: false, reasons: ['no-snapshot'] };
|
|
1067
|
+
const current = gitSnapshot();
|
|
1068
|
+
if (!current) return { present: true, fresh: false, reasons: ['no-git'] };
|
|
1069
|
+
const reasons = [];
|
|
1070
|
+
if (current.head !== snapshot.head) reasons.push('head-changed');
|
|
1071
|
+
if (current.worktreeHash !== snapshot.worktreeHash) reasons.push('worktree-changed');
|
|
1072
|
+
return { present: true, fresh: reasons.length === 0, reasons };
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
let verificationStaleNoted = false;
|
|
1076
|
+
|
|
1077
|
+
function noteVerificationFreshness(dir, agent) {
|
|
1078
|
+
if (verificationStaleNoted) return;
|
|
1079
|
+
const freshness = verificationFreshness(dir);
|
|
1080
|
+
if (!freshness.present) return;
|
|
1081
|
+
if (freshness.fresh) return;
|
|
1082
|
+
verificationStaleNoted = true;
|
|
1083
|
+
appendMetric({ type: 'verification_stale', at: now, agent: agent || null, reasons: freshness.reasons, source: 'hook', attributionConfidence: 'high' });
|
|
1084
|
+
process.stderr.write(`verification evidence is stale (${freshness.reasons.join(', ')}); re-run the gate and record it before closure\n`);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
983
1087
|
function finishActiveAttempt(forced) {
|
|
984
1088
|
const resolved = forced || resolvedAttempt(); if (!resolved) return null;
|
|
985
1089
|
const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
|
|
986
1090
|
const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
|
|
987
|
-
|
|
1091
|
+
const usage = sanitizeUsage(hookInput.usage);
|
|
1092
|
+
appendMetric({ type: 'attempt_finished', at: now, attemptId: resolved.attemptId, outcome, durationMs: Number.isFinite(durationMs) && durationMs >= 0 ? durationMs : null, retryAfterFix: status.retryAfterFix || null, source: resolved.source || 'hook', attributionConfidence: resolved.confidence, ...(usage ? { usage } : {}) });
|
|
1093
|
+
if (resolved.entry && resolved.entry.agent === 'build-verifier') { ensureVerificationSnapshot(taskDir, resolved.entry.agent); noteVerificationFreshness(taskDir, resolved.entry.agent); }
|
|
988
1094
|
const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
|
|
989
1095
|
}
|
|
990
1096
|
function missingConsumerArtifacts() {
|
|
@@ -1014,6 +1120,7 @@ function completePipeline(statusPatch) {
|
|
|
1014
1120
|
// task_completed is written only on this branch. A missing receipt blocks
|
|
1015
1121
|
// above and must not be counted as a finished task.
|
|
1016
1122
|
status.state = 'completed';
|
|
1123
|
+
noteVerificationFreshness(taskDir, null);
|
|
1017
1124
|
completeTaskMetrics();
|
|
1018
1125
|
writeStatus(statusPatch);
|
|
1019
1126
|
out(`Pipeline complete for "${slug}". Run /technical-retro ${slug}.`);
|
|
@@ -140,7 +140,7 @@ Each producing agent runs a **pre-receipt self-review** of its own output — go
|
|
|
140
140
|
|
|
141
141
|
## Context budget & checkpoint/resume
|
|
142
142
|
|
|
143
|
-
Work in bounded waves (one artifact class across the target surface). **Checkpoint** each completed wave to `.memlog.md` (`## <date>` + an `event:` line) and record the produced paths on the `implementation` manifest entry (`authoritativePaths`). That checkpoint is the hook `writeStatus` path: it rewrites `.ai.local/team/tasks/<slug>/focus.md`. `focus.md` is a view, not the system of record. It lists slug, pipeline step index, authoritative paths for incomplete manifest ids, the last `.memlog.md` `event:` line, the next gate, one decomposition ready-set line, and one archive index line, and it stays under 100 lines. `status.json`, `metrics.json`, `artifact-manifest.json`, and `.memlog.md` stay the system of record. A resumed run (`/task-continue`) reads `focus.md` first, then `artifact-manifest.json` and `.memlog.md`, and continues at the first stage whose exit criteria are unmet — never re-derive state from the chat. A completed manifest entry keeps id, status, and `authoritativePaths`, and the default resume read omits that entry's markdown body; closing it appends one new `.memlog.md` event: line, moves the bulky body to `.ai.local/team/tasks/<slug>/archive/YYYY-MM-DD/`, and leaves earlier memlog lines, the human-readable slug and artifact ids, and the manifest entry in place, with no Beads hash ids and no Taskmaster tags. An **interrupted producer** (tool abort, killed session) is resumed, not restarted: run the stack's compile gate on the working tree first, and when it is red hand the failing output to the same producer with a `fix and finish` brief instead of starting a second parallel attempt. When the host runtime writes no `status.json` (manual-hook hosts such as OpenCode), the resume checkpoint is `artifact-manifest.json` + `.memlog.md`; never gate a resume on a file the runtime does not produce. Mechanical waves (generation, embed sync) are delegated to repo scripts. A large command output (log, diff, test run, `git log`) is piped through `.ai.local/scripts/dump-output.mjs` instead of being read whole: take its ≤40-line head, then `grep -n` the stored file or find it with `team-db.mjs search "<term>"`. See **context-and-iteration** for the budget, checkpoint, resume, and refinement loop.
|
|
143
|
+
Work in bounded waves (one artifact class across the target surface). **Checkpoint** each completed wave to `.memlog.md` (`## <date>` + an `event:` line) and record the produced paths on the `implementation` manifest entry (`authoritativePaths`). That checkpoint is the hook `writeStatus` path: it rewrites `.ai.local/team/tasks/<slug>/focus.md`. `focus.md` is a view, not the system of record. It lists slug, pipeline step index, authoritative paths for incomplete manifest ids, the last `.memlog.md` `event:` line, the next gate, one decomposition ready-set line, and one archive index line, and it stays under 100 lines. `status.json`, `metrics.json`, `artifact-manifest.json`, and `.memlog.md` stay the system of record. A resumed run (`/task-continue`) reads `focus.md` first, then `artifact-manifest.json` and `.memlog.md`, and continues at the first stage whose exit criteria are unmet — never re-derive state from the chat. A session approaching ~50 turns does not keep growing its history: the producer finishes the current wave, checkpoints it (`focus.md` + `artifact-manifest.json` + `.memlog.md`), and hands off to a fresh session. A wave that cannot finish before the cap checkpoints its partial state the same way. A completed manifest entry keeps id, status, and `authoritativePaths`, and the default resume read omits that entry's markdown body; closing it appends one new `.memlog.md` event: line, moves the bulky body to `.ai.local/team/tasks/<slug>/archive/YYYY-MM-DD/`, and leaves earlier memlog lines, the human-readable slug and artifact ids, and the manifest entry in place, with no Beads hash ids and no Taskmaster tags. An **interrupted producer** (tool abort, killed session) is resumed, not restarted: run the stack's compile gate on the working tree first, and when it is red hand the failing output to the same producer with a `fix and finish` brief instead of starting a second parallel attempt. When the host runtime writes no `status.json` (manual-hook hosts such as OpenCode), the resume checkpoint is `artifact-manifest.json` + `.memlog.md`; never gate a resume on a file the runtime does not produce. Mechanical waves (generation, embed sync) are delegated to repo scripts. A large command output (log, diff, test run, `git log`) is piped through `.ai.local/scripts/dump-output.mjs` instead of being read whole: take its ≤40-line head, then `grep -n` the stored file or find it with `team-db.mjs search "<term>"`. See **context-and-iteration** for the budget, checkpoint, resume, and refinement loop.
|
|
144
144
|
|
|
145
145
|
## status.json (pipeline mode)
|
|
146
146
|
|
|
@@ -72,9 +72,9 @@ Default SoT — YAML `model` in each agent file. Optional `steps[].model` (`chea
|
|
|
72
72
|
|
|
73
73
|
| Tier | Default frontmatter | Agents |
|
|
74
74
|
|------|---------------------|--------|
|
|
75
|
-
| **cheap** | `fast` | `task-router`, `task-analyst`, `build-verifier`, `code-reviewer`, `tech-writer`, `codebase-analyzer` |
|
|
76
|
-
| **standard** | `inherit` | `feature-developer`, `debugger`, `ci-investigator`, `
|
|
77
|
-
| **strong** | `claude-opus-4-8[effort=high]` | `solution-architect`, `migration-specialist`, `security-reviewer`, `performance-auditor
|
|
75
|
+
| **cheap** | `fast` | `task-router`, `task-analyst`, `build-verifier`, `code-reviewer`, `api-contract-reviewer`, `mockup-reviewer`, `tech-writer`, `codebase-analyzer` |
|
|
76
|
+
| **standard** | `inherit` | `feature-developer`, `debugger`, `ci-investigator`, `accessibility-reviewer`, `qa-tester`, `unit-test-*`, `playwright-test-*`, `openspec-author` |
|
|
77
|
+
| **strong** | `claude-opus-4-8[effort=high]` | `solution-architect`, `migration-specialist`, `security-reviewer`, `performance-auditor` |
|
|
78
78
|
|
|
79
79
|
**Notes**
|
|
80
80
|
|
|
@@ -82,6 +82,7 @@ Default SoT — YAML `model` in each agent file. Optional `steps[].model` (`chea
|
|
|
82
82
|
- Strong pin uses Cursor bracket options (`[effort=high]`). If the ID is blocked by plan/admin, Cursor falls back to a compatible model.
|
|
83
83
|
- Alternate strong pin when Opus unavailable: `composer-2.5[fast=false]` (edit frontmatter locally).
|
|
84
84
|
- Never put `strong` on `build-verifier` / `tech-writer` / `task-router`.
|
|
85
|
+
- Review-shaped reviewers (`code-reviewer`, `build-verifier`, `api-contract-reviewer`, `mockup-reviewer`) sit on `cheap` (`fast` here). OpenCode does not pin a provider in the agent file; this repo maps `cheap` in `.ai.local/team/model-tiers.json`. The 2026-11-16 flash vs v4-pro bench on `guard-tests` (n=5) was cost −76.7% and tokens +12.3%. Its oracle checks that a test script's last line is echoed. That run did not measure code review, contract review, or mockup review, and it did not measure Cursor `fast` or Claude `haiku`.
|
|
85
86
|
|
|
86
87
|
## Orchestration
|
|
87
88
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: api-contract-reviewer
|
|
3
3
|
description: API contract review specialist. Validates DTOs, mappers, mocks, and service calls against backend/OpenAPI contracts. Readonly — writes api-contract-review.md only; never edits production code.
|
|
4
4
|
readonly: false
|
|
5
|
-
model:
|
|
5
|
+
model: fast
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: mockup-reviewer
|
|
3
3
|
description: Figma mockup review specialist. Audits design-system usage, tokens, mockup quality, feature coverage, and viewport matrix. Writes mockup-review.md only; never edits production code or Figma.
|
|
4
4
|
readonly: false
|
|
5
|
-
model:
|
|
5
|
+
model: fast
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
|
|
@@ -99,7 +99,7 @@ SoT: `agent-team/task-classification` (shared-core marker above; do not invent a
|
|
|
99
99
|
**L2-lite routing.** When `.ai.local/rules/task-levels.md` selects L2-lite:
|
|
100
100
|
|
|
101
101
|
- keep `profile: standard`; do not set `full` because generated trees, snapshots, CLI goldens, docs, or test fixtures push the raw file count over 10;
|
|
102
|
-
- keep only the risk specialists: `api-contract-reviewer` when the public contract changes, `security-reviewer` when destructive/auth-bearing, `mockup-reviewer` when `app/src/ui/**` changes;
|
|
102
|
+
- keep only the risk specialists: `api-contract-reviewer` when the public contract changes (skipIf no API/DTO diff), `security-reviewer` when destructive/auth-bearing, `mockup-reviewer` when `app/src/ui/**` changes (skipIf no Figma/UI surface);
|
|
103
103
|
- set `humanGates` to exactly `["after:task-analyst"]`; the contract gate and review freeze the design — a second architecture gate needs a real open decision;
|
|
104
104
|
- do not add `solution-architect`, `openspec-author`, or `tech-writer` unless a genuine open decision or install-surface docs require them; fold docs into the developer or one docs step;
|
|
105
105
|
- count substantive files only. Record the L2-lite selection and the machine-checked gate in `routingReasons`.
|
|
@@ -149,7 +149,7 @@ Keep top-level `profile` and emit this top-level object in every new `pipeline.j
|
|
|
149
149
|
|
|
150
150
|
## Adjust steps (when context is clear)
|
|
151
151
|
|
|
152
|
-
- If prompt or `brief.md` contains `figma.com` on `feature` / `refactor` / `spike` / `spec-gen`, insert **mockup-reviewer** after **task-analyst** (when present) and before **solution-architect** and **feature-developer**.
|
|
152
|
+
- If prompt or `brief.md` contains `figma.com` on `feature` / `refactor` / `spike` / `spec-gen`, insert **mockup-reviewer** after **task-analyst** (when present) and before **solution-architect** and **feature-developer**. Do not set `model` on that step: `mockup-reviewer` stays on its cheap frontmatter. Do not add static `humanGates: ["after:mockup-reviewer"]` (FAIL-only hook exception). Never put `mockup-reviewer` in a `parallel: true` step (FAIL-only gate is serial).
|
|
153
153
|
- Classify intent `mockup-review` **before** `ux-design` **before** `review-only`. A `figma.com` URL with review-not-implement language is `mockup-review` even without the word «макет», including when the user said «ревью UX». <!-- i18n-keep: E4 -->
|
|
154
154
|
- If UI stack and (required-signal or advisory UI AC), instruct **task-analyst** to load skill `ux-design` (no new pipeline step; analyst default model, not `strong`). Required-signal: user asked UX, or AC require flows/states, or spec-gen page/feature.
|
|
155
155
|
- If the resolved scope touches UI paths (`app/src/ui/**`, or the repo's component-catalog root) on `feature` / `refactor`, insert **mockup-reviewer** before **feature-developer**. This includes a UI change with no `figma.com` URL; the reviewer then uses the AC / `ux-design.md`. Do not insert it when `profile` is `light` and the prompt has no `figma.com` URL and no required-signal UX AC. A `figma.com` URL still inserts **mockup-reviewer** on every profile, including `light`.
|
|
@@ -182,11 +182,11 @@ Optional per-step field: `"model": "cheap" | "standard" | "strong"`. Omit → ag
|
|
|
182
182
|
|
|
183
183
|
| When | What to write |
|
|
184
184
|
|------|----------------|
|
|
185
|
-
| `profile: light` | set `cheap` on **all** steps (
|
|
185
|
+
| `profile: light` | set `cheap` on **all** steps (exception: unclear bug root cause on `debugger` → `strong`) |
|
|
186
186
|
| `profile: standard` | omit (frontmatter defaults) |
|
|
187
187
|
| `profile: full` | set `strong` on `solution-architect`, `migration-specialist`, `security-reviewer`, `performance-auditor` when present; omit others |
|
|
188
188
|
| `intent: spike` | set `strong` on `solution-architect` (and analyst may stay default/`cheap`) |
|
|
189
|
-
| `intent: perf-audit` /
|
|
189
|
+
| `intent: perf-audit` / security-heavy feature | `strong` on `security-reviewer` / `performance-auditor` when that step exists. `mockup-review` does not set `strong` — `mockup-reviewer` stays cheap |
|
|
190
190
|
| Always | **never** `strong` on `build-verifier`, `tech-writer`, `task-router` |
|
|
191
191
|
|
|
192
192
|
Cursor mapping when orchestrator invokes Task: `cheap` → pass `model: "fast"` if the tool accepts it; `standard`/`strong` → **do not** pass `fast` (rely on agent frontmatter pin / inherit).
|
|
@@ -980,11 +980,117 @@ function reconcileStatusFromManifest(agent, step, resolved) {
|
|
|
980
980
|
return status.state;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
/**
|
|
984
|
+
* Keep only the numeric usage fields and the two provenance fields. A host may
|
|
985
|
+
* forward richer objects; the ledger is allowlisted so nothing unbounded or
|
|
986
|
+
* secret-shaped reaches `metrics.json`.
|
|
987
|
+
*/
|
|
988
|
+
function sanitizeUsage(value) {
|
|
989
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
990
|
+
const num = (input) => (typeof input === 'number' && Number.isFinite(input) && input >= 0 ? input : null);
|
|
991
|
+
const usage = {
|
|
992
|
+
input: num(value.input), output: num(value.output), reasoning: num(value.reasoning),
|
|
993
|
+
cacheRead: num(value.cacheRead === undefined ? value.cached : value.cacheRead),
|
|
994
|
+
cacheWrite: num(value.cacheWrite), costUsd: num(value.costUsd),
|
|
995
|
+
model: typeof value.model === 'string' ? value.model.slice(0, 120) : null,
|
|
996
|
+
origin: value.origin === 'estimated' ? 'estimated' : 'measured',
|
|
997
|
+
};
|
|
998
|
+
const reported = usage.input !== null || usage.output !== null || usage.reasoning !== null ||
|
|
999
|
+
usage.cacheRead !== null || usage.cacheWrite !== null || usage.costUsd !== null;
|
|
1000
|
+
return reported ? usage : null;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Freshness of a persisted verification snapshot against the current worktree.
|
|
1005
|
+
* Read-only: closure warns, it never blocks on a stale snapshot.
|
|
1006
|
+
*/
|
|
1007
|
+
function gitSnapshot() {
|
|
1008
|
+
const { spawnSync } = require('child_process');
|
|
1009
|
+
const git = (args) => {
|
|
1010
|
+
const result = spawnSync('git', args, { cwd: process.cwd(), encoding: 'utf8', timeout: 10000, maxBuffer: 32 * 1024 * 1024 });
|
|
1011
|
+
return result && result.status === 0 ? String(result.stdout || '') : null;
|
|
1012
|
+
};
|
|
1013
|
+
const head = git(['rev-parse', 'HEAD']);
|
|
1014
|
+
if (head === null) return null;
|
|
1015
|
+
const branch = git(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
1016
|
+
const exclude = ['--', '.', ':(exclude).ai.local'];
|
|
1017
|
+
const statusText = git(['status', '--porcelain=v1', ...exclude]) || '';
|
|
1018
|
+
const diffText = git(['diff', '--binary', 'HEAD', ...exclude]) || '';
|
|
1019
|
+
const untracked = git(['ls-files', '--others', '--exclude-standard', ...exclude]) || '';
|
|
1020
|
+
return {
|
|
1021
|
+
head: head.trim(),
|
|
1022
|
+
branch: branch === null ? null : branch.trim(),
|
|
1023
|
+
dirtyFiles: statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length,
|
|
1024
|
+
worktreeHash: crypto.createHash('sha256').update(`${statusText}\u0000${diffText}\u0000${untracked}`).digest('hex'),
|
|
1025
|
+
capturedAt: now,
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* Seed the evidence file when the verifier finishes without an explicit
|
|
1031
|
+
* `verification.mjs record`: the snapshot plus a hash of `validation-report.md`.
|
|
1032
|
+
* An existing file is never refreshed — its binding must keep pointing at the
|
|
1033
|
+
* tree the commands actually ran on.
|
|
1034
|
+
*/
|
|
1035
|
+
function ensureVerificationSnapshot(dir, agent) {
|
|
1036
|
+
const file = path.join(dir, 'verification.json');
|
|
1037
|
+
if (fs.existsSync(file)) return;
|
|
1038
|
+
const snapshot = gitSnapshot();
|
|
1039
|
+
if (!snapshot) return;
|
|
1040
|
+
const reportPath = path.join(dir, 'validation-report.md');
|
|
1041
|
+
let report = null;
|
|
1042
|
+
try {
|
|
1043
|
+
const text = fs.readFileSync(reportPath);
|
|
1044
|
+
report = { path: 'validation-report.md', sha256: crypto.createHash('sha256').update(text).digest('hex') };
|
|
1045
|
+
} catch {}
|
|
1046
|
+
const verification = {
|
|
1047
|
+
schemaVersion: 1,
|
|
1048
|
+
task: path.basename(dir),
|
|
1049
|
+
snapshot,
|
|
1050
|
+
report,
|
|
1051
|
+
commands: [],
|
|
1052
|
+
gate: { status: 'snapshot-only', recordedBy: agent || null, checkedAt: now },
|
|
1053
|
+
};
|
|
1054
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
1055
|
+
fs.writeFileSync(temporary, JSON.stringify(verification, null, 2) + '\n');
|
|
1056
|
+
fs.renameSync(temporary, file);
|
|
1057
|
+
appendMetric({ type: 'verification_recorded', at: now, kind: 'snapshot-only', agent: agent || null, head: snapshot.head, worktreeHash: snapshot.worktreeHash, source: 'hook', attributionConfidence: 'high' });
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function verificationFreshness(dir) {
|
|
1061
|
+
const file = path.join(dir, 'verification.json');
|
|
1062
|
+
if (!fs.existsSync(file)) return { present: false };
|
|
1063
|
+
let verification;
|
|
1064
|
+
try { verification = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return { present: true, fresh: false, reasons: ['unreadable'] }; }
|
|
1065
|
+
const snapshot = verification && verification.snapshot;
|
|
1066
|
+
if (!snapshot || typeof snapshot.head !== 'string') return { present: true, fresh: false, reasons: ['no-snapshot'] };
|
|
1067
|
+
const current = gitSnapshot();
|
|
1068
|
+
if (!current) return { present: true, fresh: false, reasons: ['no-git'] };
|
|
1069
|
+
const reasons = [];
|
|
1070
|
+
if (current.head !== snapshot.head) reasons.push('head-changed');
|
|
1071
|
+
if (current.worktreeHash !== snapshot.worktreeHash) reasons.push('worktree-changed');
|
|
1072
|
+
return { present: true, fresh: reasons.length === 0, reasons };
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
let verificationStaleNoted = false;
|
|
1076
|
+
|
|
1077
|
+
function noteVerificationFreshness(dir, agent) {
|
|
1078
|
+
if (verificationStaleNoted) return;
|
|
1079
|
+
const freshness = verificationFreshness(dir);
|
|
1080
|
+
if (!freshness.present) return;
|
|
1081
|
+
if (freshness.fresh) return;
|
|
1082
|
+
verificationStaleNoted = true;
|
|
1083
|
+
appendMetric({ type: 'verification_stale', at: now, agent: agent || null, reasons: freshness.reasons, source: 'hook', attributionConfidence: 'high' });
|
|
1084
|
+
process.stderr.write(`verification evidence is stale (${freshness.reasons.join(', ')}); re-run the gate and record it before closure\n`);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
983
1087
|
function finishActiveAttempt(forced) {
|
|
984
1088
|
const resolved = forced || resolvedAttempt(); if (!resolved) return null;
|
|
985
1089
|
const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
|
|
986
1090
|
const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
|
|
987
|
-
|
|
1091
|
+
const usage = sanitizeUsage(hookInput.usage);
|
|
1092
|
+
appendMetric({ type: 'attempt_finished', at: now, attemptId: resolved.attemptId, outcome, durationMs: Number.isFinite(durationMs) && durationMs >= 0 ? durationMs : null, retryAfterFix: status.retryAfterFix || null, source: resolved.source || 'hook', attributionConfidence: resolved.confidence, ...(usage ? { usage } : {}) });
|
|
1093
|
+
if (resolved.entry && resolved.entry.agent === 'build-verifier') { ensureVerificationSnapshot(taskDir, resolved.entry.agent); noteVerificationFreshness(taskDir, resolved.entry.agent); }
|
|
988
1094
|
const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
|
|
989
1095
|
}
|
|
990
1096
|
function missingConsumerArtifacts() {
|
|
@@ -1014,6 +1120,7 @@ function completePipeline(statusPatch) {
|
|
|
1014
1120
|
// task_completed is written only on this branch. A missing receipt blocks
|
|
1015
1121
|
// above and must not be counted as a finished task.
|
|
1016
1122
|
status.state = 'completed';
|
|
1123
|
+
noteVerificationFreshness(taskDir, null);
|
|
1017
1124
|
completeTaskMetrics();
|
|
1018
1125
|
writeStatus(statusPatch);
|
|
1019
1126
|
out(`Pipeline complete for "${slug}". Run /technical-retro ${slug}.`);
|