burnoff 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.github/workflows/burnoff-pr-gate.yml +75 -0
  2. package/README.md +94 -20
  3. package/bin/burnoff.mjs +129 -30
  4. package/hooks/hook-io.mjs +27 -18
  5. package/hooks/post-tool-use.mjs +33 -26
  6. package/hooks/pre-tool-use.mjs +43 -41
  7. package/hooks/session-lifecycle.mjs +40 -0
  8. package/package.json +8 -5
  9. package/src/ci/ci-gate.mjs +84 -9
  10. package/src/ci/pr-cost.mjs +207 -22
  11. package/src/ci/team-digest.mjs +6 -4
  12. package/src/cli/audit.mjs +177 -23
  13. package/src/cli/doctor.mjs +230 -25
  14. package/src/cli/init.mjs +415 -75
  15. package/src/cli/startup-audit.mjs +2824 -0
  16. package/src/clients/antigravity.mjs +285 -0
  17. package/src/clients/claude-code.mjs +180 -0
  18. package/src/clients/detect.mjs +64 -0
  19. package/src/config/catalog.json +188 -45
  20. package/src/config/loader.mjs +96 -13
  21. package/src/config/paths.mjs +92 -2
  22. package/src/config/policy.mjs +103 -17
  23. package/src/config/pricing.mjs +1033 -0
  24. package/src/config/uncached-attribution.mjs +719 -0
  25. package/src/guards/loop-breaker.mjs +267 -24
  26. package/src/guards/post-tool-engine.mjs +316 -35
  27. package/src/guards/pre-tool-engine.mjs +389 -130
  28. package/src/guards/read-clamp.mjs +149 -75
  29. package/src/guards/session-hook.mjs +207 -0
  30. package/src/guards/shell-guard.mjs +610 -74
  31. package/src/ipc/daemon.mjs +50 -8
  32. package/src/ipc/fast-client.mjs +62 -5
  33. package/src/ipc/protocol.mjs +1 -1
  34. package/src/storage/antigravity-parser.mjs +258 -0
  35. package/src/storage/atomic-io.mjs +2 -2
  36. package/src/storage/file-lock.mjs +66 -13
  37. package/src/storage/fts5-archive.mjs +31 -16
  38. package/src/storage/jsonl-parser.mjs +209 -20
  39. package/src/storage/ledger.mjs +15 -10
  40. package/src/storage/sqlite-client.mjs +35 -11
  41. package/hooks/hooks.json +0 -12
@@ -15,6 +15,7 @@ import {
15
15
  tryTier1PostToolFastPath
16
16
  } from './hook-io.mjs';
17
17
  import { tryFastDaemonRpc } from '../src/ipc/fast-client.mjs';
18
+ import { getClientAdapter, normalizeHookEvent } from '../src/clients/detect.mjs';
18
19
 
19
20
  let _engineMod = null;
20
21
  if (!isCliEntrypoint(import.meta.url)) {
@@ -39,60 +40,56 @@ export function runPostToolUseHook(event = {}, options = {}) {
39
40
  return _engineMod.runPostToolUseHook(event, options);
40
41
  }
41
42
 
43
+ function emitPostToolResult(res, payload, traceBase, pathLabel, ioOverride) {
44
+ if (res.stdout) {
45
+ recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: pathLabel, exitCode: 0 });
46
+ exitWithStdoutJson(res.stdout, ioOverride);
47
+ } else {
48
+ recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: pathLabel, exitCode: 0 });
49
+ exitPassThrough(ioOverride.exitFn);
50
+ }
51
+ }
52
+
42
53
  export async function executePostToolUseCli(cliOptions = {}) {
43
54
  const readPayload = cliOptions.readPayload || readStdinJsonAsync;
44
55
  const ioOverride = cliOptions.ioOverride || {};
45
56
  let payload = {};
57
+ let detectedClient = 'claude-code';
46
58
  try {
47
59
  payload = await readPayload(cliOptions.timeoutMs);
60
+ const { client, adapter, canonical } = normalizeHookEvent(payload, cliOptions.hookOptions);
61
+ detectedClient = client;
48
62
  const hasCustomOptions = Boolean(cliOptions.runHook || cliOptions.hookOptions);
49
63
  const traceBase = { tracePath: cliOptions.tracePath };
50
64
 
51
65
  if (cliOptions.runHook) {
52
66
  const res = cliOptions.runHook(payload, { persistState: true, ...(cliOptions.hookOptions || {}) });
53
- if (res.stdout) {
54
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: 'custom', exitCode: 0 });
55
- exitWithStdoutJson(res.stdout, ioOverride);
56
- } else {
57
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'custom', exitCode: 0 });
58
- exitPassThrough(ioOverride.exitFn);
59
- }
67
+ emitPostToolResult(res, payload, traceBase, 'custom', ioOverride);
60
68
  return;
61
69
  }
62
70
 
63
71
  if (!hasCustomOptions) {
64
- if (tryTier1PostToolFastPath(payload)) {
65
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'tier1_fast', exitCode: 0 });
66
- exitPassThrough(ioOverride.exitFn);
72
+ const tier1 = tryTier1PostToolFastPath(canonical);
73
+ if (tier1) {
74
+ const rendered = client === 'antigravity' ? adapter.renderPost(tier1) : tier1;
75
+ emitPostToolResult(rendered, payload, traceBase, 'tier1_fast', ioOverride);
67
76
  return;
68
77
  }
69
78
 
70
79
  const ipcRes = await tryFastDaemonRpc(
71
- 'hook.claude.postToolUse',
72
- { event: payload },
80
+ 'hook.postToolUse',
81
+ { client, event: payload },
73
82
  { ipcPath: cliOptions.ipcPath }
74
83
  );
75
84
  if (ipcRes && ipcRes.fullVerdict === true) {
76
- if (ipcRes.stdout) {
77
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: 'daemon_ipc', exitCode: 0 });
78
- exitWithStdoutJson(ipcRes.stdout, ioOverride);
79
- } else {
80
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'daemon_ipc', exitCode: 0 });
81
- exitPassThrough(ioOverride.exitFn);
82
- }
85
+ emitPostToolResult(ipcRes, payload, traceBase, 'daemon_ipc', ioOverride);
83
86
  return;
84
87
  }
85
88
  }
86
89
 
87
90
  const { runPostToolUseHook: runCore } = await import('../src/guards/post-tool-engine.mjs');
88
91
  const res = runCore(payload, { persistState: true, ...(cliOptions.hookOptions || {}) });
89
- if (res.stdout) {
90
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: 'core', exitCode: 0 });
91
- exitWithStdoutJson(res.stdout, ioOverride);
92
- } else {
93
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'core', exitCode: 0 });
94
- exitPassThrough(ioOverride.exitFn);
95
- }
92
+ emitPostToolResult(res, payload, traceBase, 'core', ioOverride);
96
93
  } catch (err) {
97
94
  recordHookTrace('PostToolUse', payload, {
98
95
  tracePath: cliOptions.tracePath,
@@ -101,6 +98,16 @@ export async function executePostToolUseCli(cliOptions = {}) {
101
98
  exitCode: 0,
102
99
  error: err?.message || String(err)
103
100
  });
101
+ if (detectedClient === 'antigravity') {
102
+ const failRes = getClientAdapter(detectedClient).renderFailOpen(err?.message || String(err), 'PostToolUse');
103
+ const writeStderr =
104
+ ioOverride.stderrWrite ||
105
+ ioOverride.writeStderr ||
106
+ ((s) => globalThis.process?.stderr?.write?.(s));
107
+ writeStderr(failRes.stderr);
108
+ exitWithStdoutJson(failRes.stdout, ioOverride);
109
+ return;
110
+ }
104
111
  exitDiagnosticZero(err?.message || String(err), 'PostToolUse', ioOverride);
105
112
  }
106
113
  }
@@ -17,6 +17,7 @@ import {
17
17
  tryTier1PreToolFastPath
18
18
  } from './hook-io.mjs';
19
19
  import { tryFastDaemonRpc } from '../src/ipc/fast-client.mjs';
20
+ import { getClientAdapter, normalizeHookEvent } from '../src/clients/detect.mjs';
20
21
 
21
22
  let _engineMod = null;
22
23
  if (!isCliEntrypoint(import.meta.url)) {
@@ -41,8 +42,19 @@ export function runPreToolUseHook(event = {}, options = {}) {
41
42
  return _engineMod.runPreToolUseHook(event, options);
42
43
  }
43
44
 
44
- function exitOnInternalFault(err, ioOverride = {}) {
45
+ function exitOnInternalFault(err, ioOverride = {}, client = 'claude-code') {
45
46
  const msg = err?.message || String(err);
47
+ if (client === 'antigravity') {
48
+ const adapter = getClientAdapter(client);
49
+ const failRes = adapter.renderFailOpen(msg, 'PreToolUse');
50
+ const writeStderr =
51
+ ioOverride.stderrWrite ||
52
+ ioOverride.writeStderr ||
53
+ ((s) => globalThis.process?.stderr?.write?.(s));
54
+ writeStderr(failRes.stderr);
55
+ exitWithStdoutJson(failRes.stdout, ioOverride);
56
+ return;
57
+ }
46
58
  const strict =
47
59
  String(globalThis.process?.env?.BURNOFF_PRETOOL_FAIL_MODE || '').toLowerCase() === 'closed';
48
60
  if (strict) {
@@ -52,78 +64,68 @@ function exitOnInternalFault(err, ioOverride = {}) {
52
64
  exitDiagnosticZero(`internal error, tool call allowed (fail-open): ${msg}`, 'PreToolUse', ioOverride);
53
65
  }
54
66
 
67
+ function emitPreToolResult(res, payload, traceBase, pathLabel, ioOverride) {
68
+ if (res.exitCode === 2) {
69
+ recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'block', path: pathLabel, exitCode: 2 });
70
+ exitHardBlockStderr(res.stderr, 'PreToolUse', ioOverride);
71
+ } else if (res.stdout) {
72
+ recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: pathLabel, exitCode: 0 });
73
+ exitWithStdoutJson(res.stdout, ioOverride);
74
+ } else {
75
+ recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'pass_through', path: pathLabel, exitCode: 0 });
76
+ exitPassThrough(ioOverride.exitFn);
77
+ }
78
+ }
79
+
55
80
  export async function executePreToolUseCli(cliOptions = {}) {
56
81
  const readPayload = cliOptions.readPayload || readStdinJsonAsync;
57
82
  const ioOverride = cliOptions.ioOverride || {};
58
83
  let payload = {};
84
+ let detectedClient = 'claude-code';
59
85
  try {
60
86
  payload = await readPayload(cliOptions.timeoutMs);
87
+ const { client, adapter, canonical } = normalizeHookEvent(payload, cliOptions.hookOptions);
88
+ detectedClient = client;
61
89
  const hasCustomOptions = Boolean(cliOptions.runHook || cliOptions.hookOptions);
62
90
  const traceBase = { tracePath: cliOptions.tracePath };
63
91
 
64
92
  if (cliOptions.runHook) {
65
93
  const res = cliOptions.runHook(payload, { persistState: true, ...(cliOptions.hookOptions || {}) });
66
- if (res.exitCode === 2) {
67
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'block', path: 'custom', exitCode: 2 });
68
- exitHardBlockStderr(res.stderr, 'PreToolUse', ioOverride);
69
- } else if (res.stdout) {
70
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: 'custom', exitCode: 0 });
71
- exitWithStdoutJson(res.stdout, ioOverride);
72
- } else {
73
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'custom', exitCode: 0 });
74
- exitPassThrough(ioOverride.exitFn);
75
- }
94
+ emitPreToolResult(res, payload, traceBase, 'custom', ioOverride);
76
95
  return;
77
96
  }
78
97
 
79
98
  if (!hasCustomOptions) {
80
- if (tryTier1PreToolFastPath(payload)) {
81
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'tier1_fast', exitCode: 0 });
82
- exitPassThrough(ioOverride.exitFn);
99
+ const tier1 = tryTier1PreToolFastPath(canonical);
100
+ if (tier1) {
101
+ const rendered = client === 'antigravity' ? adapter.renderPre(tier1) : tier1;
102
+ emitPreToolResult(rendered, payload, traceBase, 'tier1_fast', ioOverride);
83
103
  return;
84
104
  }
85
105
 
86
106
  const ipcRes = await tryFastDaemonRpc(
87
- 'hook.claude.preToolUse',
88
- { event: payload },
107
+ 'hook.preToolUse',
108
+ { client, event: payload },
89
109
  { ipcPath: cliOptions.ipcPath }
90
110
  );
91
111
  if (ipcRes && ipcRes.fullVerdict === true) {
92
- if (ipcRes.exitCode === 2) {
93
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'block', path: 'daemon_ipc', exitCode: 2 });
94
- exitHardBlockStderr(ipcRes.stderr, 'PreToolUse', ioOverride);
95
- } else if (ipcRes.stdout) {
96
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: 'daemon_ipc', exitCode: 0 });
97
- exitWithStdoutJson(ipcRes.stdout, ioOverride);
98
- } else {
99
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'daemon_ipc', exitCode: 0 });
100
- exitPassThrough(ioOverride.exitFn);
101
- }
112
+ emitPreToolResult(ipcRes, payload, traceBase, 'daemon_ipc', ioOverride);
102
113
  return;
103
114
  }
104
115
 
105
- if (canFastAllowBoundedRead(payload, { cwd: payload?.cwd })) {
106
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'bounded_read_fast', exitCode: 0 });
107
- exitPassThrough(ioOverride.exitFn);
116
+ if (canFastAllowBoundedRead(payload, { cwd: canonical.cwd })) {
117
+ const fastRes = client === 'antigravity' ? adapter.renderPre({ exitCode: 0, stdout: '', stderr: '', verdict: { decision: 'allow' } }) : { exitCode: 0, stdout: '', stderr: '' };
118
+ emitPreToolResult(fastRes, payload, traceBase, 'bounded_read_fast', ioOverride);
108
119
  return;
109
120
  }
110
121
  }
111
122
 
112
123
  const { runPreToolUseHook: runCore } = await import('../src/guards/pre-tool-engine.mjs');
113
124
  const res = runCore(payload, { persistState: true, ...(cliOptions.hookOptions || {}) });
114
-
115
- if (res.exitCode === 2) {
116
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'block', path: 'core', exitCode: 2 });
117
- exitHardBlockStderr(res.stderr, 'PreToolUse', ioOverride);
118
- } else if (res.stdout) {
119
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: 'core', exitCode: 0 });
120
- exitWithStdoutJson(res.stdout, ioOverride);
121
- } else {
122
- recordHookTrace('PreToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'core', exitCode: 0 });
123
- exitPassThrough(ioOverride.exitFn);
124
- }
125
+ emitPreToolResult(res, payload, traceBase, 'core', ioOverride);
125
126
  } catch (err) {
126
127
  const strict =
128
+ detectedClient !== 'antigravity' &&
127
129
  String(globalThis.process?.env?.BURNOFF_PRETOOL_FAIL_MODE || '').toLowerCase() === 'closed';
128
130
  recordHookTrace('PreToolUse', payload, {
129
131
  tracePath: cliOptions.tracePath,
@@ -132,7 +134,7 @@ export async function executePreToolUseCli(cliOptions = {}) {
132
134
  exitCode: strict ? 2 : 0,
133
135
  error: err?.message || String(err)
134
136
  });
135
- exitOnInternalFault(err, ioOverride);
137
+ exitOnInternalFault(err, ioOverride, detectedClient);
136
138
  }
137
139
  }
138
140
 
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @file hooks/session-lifecycle.mjs
3
+ * Thin Tier-2 command hook entrypoint for `SessionStart` and `PreCompact`.
4
+ * Fails open (`exitCode: 0`) so session startup or compaction is never blocked.
5
+ */
6
+
7
+ import {
8
+ isCliEntrypoint,
9
+ readStdinJsonAsync,
10
+ exitPassThrough,
11
+ exitDiagnosticZero,
12
+ exitWithStdoutJson
13
+ } from './hook-io.mjs';
14
+ import { runSessionLifecycleHook } from '../src/guards/session-hook.mjs';
15
+
16
+ export async function executeSessionLifecycleCli(cliOptions = {}) {
17
+ const readPayload = cliOptions.readPayload || readStdinJsonAsync;
18
+ const ioOverride = cliOptions.ioOverride || {};
19
+ try {
20
+ const payload = await readPayload(cliOptions.timeoutMs);
21
+ const res = runSessionLifecycleHook(payload, cliOptions.hookOptions || {});
22
+ if (res.stdout) {
23
+ exitWithStdoutJson(res.stdout, ioOverride);
24
+ } else {
25
+ exitPassThrough(ioOverride.exitFn);
26
+ }
27
+ } catch (err) {
28
+ exitDiagnosticZero(err?.message || String(err), 'SessionStart', ioOverride);
29
+ }
30
+ }
31
+
32
+ if (isCliEntrypoint(import.meta.url)) {
33
+ executeSessionLifecycleCli().catch((err) => {
34
+ exitDiagnosticZero(err?.message || String(err), 'SessionStart');
35
+ });
36
+ }
37
+
38
+ export default {
39
+ executeSessionLifecycleCli
40
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "burnoff",
3
- "version": "1.0.0",
4
- "description": "Deterministic circuit breakers, bounded file-read guards, and CI spend gates for Claude Code.",
3
+ "version": "1.2.0",
4
+ "description": "Deterministic circuit breakers, bounded file-read guards, and CI spend gates for Claude Code and Google Antigravity.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "Gizzant",
@@ -15,6 +15,8 @@
15
15
  },
16
16
  "keywords": [
17
17
  "claude-code",
18
+ "antigravity",
19
+ "google-antigravity",
18
20
  "hooks",
19
21
  "circuit-breaker",
20
22
  "finops",
@@ -29,16 +31,17 @@
29
31
  },
30
32
  "files": [
31
33
  "bin/",
32
- "hooks/",
34
+ "hooks/*.mjs",
33
35
  "src/",
36
+ ".github/workflows/burnoff-pr-gate.yml",
34
37
  "LICENSE",
35
38
  "README.md"
36
39
  ],
37
40
  "dependencies": {},
38
41
  "scripts": {
39
- "test": "node --test test/*.test.mjs",
42
+ "test": "node --test --test-concurrency=1",
40
43
  "test:bench": "node --test test/ipc-daemon-bench.test.mjs",
41
44
  "doctor": "node bin/burnoff.mjs doctor",
42
- "check:brands": "node -e \"import('node:fs').then(async fs=>{const p=await import('node:path');const bad=new RegExp(['ctx'+'top','high'+'beam','attention[-_]'+'horizon','ga-visual'+'izer-v2','anti'+'gravity','pro_'+'license','ah-status'+'line'].join('|'),'i');const dirs=['bin','hooks','src','.github'];let hits=[];const walk=(d)=>{if(!fs.existsSync(d))return;for(const e of fs.readdirSync(d,{withFileTypes:true})){const f=p.join(d,e.name);if(e.isDirectory())walk(f);else if(/\\.(mjs|json|ya?ml|md)$/.test(e.name)){const t=fs.readFileSync(f,'utf8');if(bad.test(t))hits.push(f);}}};dirs.forEach(walk);['package.json','README.md'].forEach(f=>{if(fs.existsSync(f)&&bad.test(fs.readFileSync(f,'utf8')))hits.push(f);});if(hits.length){console.error('Brand leaks:',hits);process.exit(1);}console.log('Zero legacy brand strings found.');})\""
45
+ "check:brands": "node -e \"import('node:fs').then(async fs=>{const p=await import('node:path');const bad=new RegExp(['ctx'+'top','high'+'beam','attention[-_]'+'horizon','ga-visual'+'izer-v2','pro_'+'license','ah-status'+'line','\\\\bHB'+'-(?:CFG|MCP|SEC)-','\\\\ba'+'gy','default'+'_api:','phase0'+'_' ].join('|'),'i');const dirs=['bin','hooks','src','.github'];let hits=[];const walk=(d)=>{if(!fs.existsSync(d))return;for(const e of fs.readdirSync(d,{withFileTypes:true})){const f=p.join(d,e.name);if(e.isDirectory())walk(f);else if(/\\.(mjs|json|ya?ml|md)$/.test(e.name)){const t=fs.readFileSync(f,'utf8');if(bad.test(t))hits.push(f);}}};dirs.forEach(walk);['package.json','README.md'].forEach(f=>{if(fs.existsSync(f)&&bad.test(fs.readFileSync(f,'utf8')))hits.push(f);});if(hits.length){console.error('Brand leaks:',hits);process.exit(1);}console.log('Zero legacy brand strings found.');})\""
43
46
  }
44
47
  }
@@ -18,7 +18,8 @@ export const DEFAULT_CI_BUDGET_POLICY = Object.freeze({
18
18
  minCacheHitPct: 50,
19
19
  maxWasteRatioPct: 35,
20
20
  maxRing0Violations: 0,
21
- mode: 'enforce'
21
+ mode: 'enforce',
22
+ failOnMissingTranscripts: false
22
23
  });
23
24
 
24
25
  function toFiniteNumber(value) {
@@ -35,9 +36,14 @@ function toFiniteNumber(value) {
35
36
  export function loadCiBudgetPolicy(cwd, overrides = {}) {
36
37
  const repoDir = path.resolve(cwd || process.cwd());
37
38
  const loaded = loadBurnoffPolicy(repoDir);
38
- const filePolicy = loaded.exists && loaded.ciBudgetGate && typeof loaded.ciBudgetGate === 'object'
39
- ? loaded.ciBudgetGate
40
- : {};
39
+ const filePolicy =
40
+ loaded.exists && !loaded.parseError
41
+ ? loaded.rawCiBudgetGate && typeof loaded.rawCiBudgetGate === 'object'
42
+ ? loaded.rawCiBudgetGate
43
+ : loaded.ciBudgetGate && typeof loaded.ciBudgetGate === 'object'
44
+ ? loaded.ciBudgetGate
45
+ : {}
46
+ : {};
41
47
 
42
48
  const merged = { ...DEFAULT_CI_BUDGET_POLICY };
43
49
 
@@ -64,16 +70,32 @@ export function loadCiBudgetPolicy(cwd, overrides = {}) {
64
70
  if (toFiniteNumber(layer.maxRing0Violations) !== null) {
65
71
  merged.maxRing0Violations = toFiniteNumber(layer.maxRing0Violations);
66
72
  }
73
+ if (typeof layer.failOnMissingTranscripts === 'boolean') {
74
+ merged.failOnMissingTranscripts = layer.failOnMissingTranscripts;
75
+ }
67
76
  if (layer.mode !== undefined && layer.mode !== null) {
68
77
  merged.mode = String(layer.mode).toLowerCase();
69
78
  }
70
79
  };
71
80
 
81
+ const hasFileFailOnMissing =
82
+ loaded.exists &&
83
+ !loaded.parseError &&
84
+ typeof filePolicy?.failOnMissingTranscripts === 'boolean';
85
+ const hasOverrideFailOnMissing = typeof overrides?.failOnMissingTranscripts === 'boolean';
86
+ const isCiEnv = Boolean(
87
+ overrides?.isCi ?? (globalThis.process?.env?.CI || globalThis.process?.env?.GITHUB_ACTIONS)
88
+ );
89
+
72
90
  if (loaded.exists) {
73
91
  applyLayer(filePolicy);
74
92
  }
75
93
  applyLayer(overrides);
76
94
 
95
+ if (!hasFileFailOnMissing && !hasOverrideFailOnMissing) {
96
+ merged.failOnMissingTranscripts = isCiEnv;
97
+ }
98
+
77
99
  if (overrides?.strict === true) {
78
100
  merged.mode = 'enforce';
79
101
  }
@@ -88,6 +110,15 @@ export function loadCiBudgetPolicy(cwd, overrides = {}) {
88
110
  */
89
111
  export function evaluateCiBudgetGate(options = {}) {
90
112
  const cwd = path.resolve(options.cwd || process.cwd());
113
+ const loadedPolicy = loadBurnoffPolicy(cwd);
114
+ if (loadedPolicy.exists && loadedPolicy.parseError) {
115
+ return {
116
+ ok: false,
117
+ verdict: 'ERROR',
118
+ exitCode: 1,
119
+ error: `Failed to parse ${path.basename(loadedPolicy.sourcePath || '.burnoff.yaml')}: ${loadedPolicy.parseErrorMessage || 'Invalid YAML syntax'}`
120
+ };
121
+ }
91
122
  const policyOverrides = {
92
123
  ...(options.policyOverrides || options),
93
124
  ...(options.strict ? { strict: true, mode: 'enforce' } : {})
@@ -148,9 +179,34 @@ export function evaluateCiBudgetGate(options = {}) {
148
179
  const cacheHitPct = Number(summary.cacheHitPct || 0);
149
180
  const wasteRatioPct = Number(summary.wasteRatioPct || 0);
150
181
  const ring0Violations = Number(summary.ring0Violations || 0);
182
+ const sessionCount =
183
+ typeof summary.sessionCount === 'number' && Number.isFinite(summary.sessionCount)
184
+ ? summary.sessionCount
185
+ : null;
186
+ const missingTranscripts =
187
+ reconciledCostUsd === null &&
188
+ totalTokens === 0 &&
189
+ totalInputTokens === 0 &&
190
+ totalCacheReadTokens === 0 &&
191
+ (sessionCount === null || sessionCount === 0);
151
192
 
193
+ const notices = [];
152
194
  const violations = [];
153
195
 
196
+ if (missingTranscripts) {
197
+ const noticeMsg =
198
+ 'No Claude Code session transcripts matched this PR window (0 tokens attributed). Upload .burnoff-ci/provider-usage.json or session transcripts, or set failOnMissingTranscripts: true to enforce.';
199
+ notices.push({ code: 'MISSING_TRANSCRIPTS', message: noticeMsg });
200
+ if (policy.failOnMissingTranscripts === true) {
201
+ violations.push({
202
+ ruleId: 'MISSING_TRANSCRIPTS',
203
+ actual: 0,
204
+ limit: 1,
205
+ message: noticeMsg
206
+ });
207
+ }
208
+ }
209
+
154
210
  if (effectiveCostUsd > policy.maxPrCostUsd) {
155
211
  violations.push({
156
212
  ruleId: 'MAX_PR_COST_USD',
@@ -205,9 +261,14 @@ export function evaluateCiBudgetGate(options = {}) {
205
261
  }
206
262
 
207
263
  const annotationLevel = verdict === 'FAIL' ? '::error' : '::warning';
208
- const annotations = violations.map(
209
- (v) => `${annotationLevel} title=Burnoff CI Budget Gate (${v.ruleId})::${v.message}`
210
- );
264
+ const annotations = [
265
+ ...violations.map((v) => `${annotationLevel} title=Burnoff CI Budget Gate (${v.ruleId})::${v.message}`),
266
+ ...(verdict !== 'FAIL'
267
+ ? notices
268
+ .filter((n) => !violations.some((v) => v.ruleId === n.code))
269
+ .map((n) => `::warning title=Burnoff CI Budget Gate (${n.code})::${n.message}`)
270
+ : [])
271
+ ];
211
272
 
212
273
  return {
213
274
  ok: verdict !== 'FAIL',
@@ -217,14 +278,17 @@ export function evaluateCiBudgetGate(options = {}) {
217
278
  metrics: {
218
279
  estimatedCostUsd,
219
280
  reconciledCostUsd,
281
+ effectiveCostUsd,
220
282
  attributionVariancePct,
221
283
  totalTokens,
222
284
  cacheHitPct,
223
285
  wasteRatioPct,
224
286
  ring0Violations,
225
287
  totalInputTokens,
226
- totalCacheReadTokens
288
+ totalCacheReadTokens,
289
+ sessionCount
227
290
  },
291
+ notices,
228
292
  violations,
229
293
  annotations
230
294
  };
@@ -239,19 +303,30 @@ export function formatCiGateMarkdown(result = {}) {
239
303
  const violatedSet = new Set((result.violations || []).map((v) => v.ruleId));
240
304
 
241
305
  const statusTag = (ruleId) => (violatedSet.has(ruleId) ? result.verdict : 'PASS');
306
+ const costDisplay =
307
+ typeof m.reconciledCostUsd === 'number' && m.reconciledCostUsd > Number(m.estimatedCostUsd || 0)
308
+ ? `$${m.reconciledCostUsd.toFixed(4)} (reconciled)`
309
+ : `$${Number(m.estimatedCostUsd || 0).toFixed(4)}`;
242
310
 
243
311
  const lines = [
244
312
  `### Burnoff CI / PR Token-Budget Gate: **${result.verdict || 'UNKNOWN'}** (\`mode: ${p.mode}\`)`,
245
313
  '',
246
314
  '| Check | Actual | Limit | Status |',
247
315
  '| :--- | :---: | :---: | :---: |',
248
- `| \`MAX_PR_COST_USD\` | \`$${Number(m.estimatedCostUsd || 0).toFixed(4)}\` | \`<=$${Number(p.maxPrCostUsd).toFixed(2)}\` | **${statusTag('MAX_PR_COST_USD')}** |`,
316
+ `| \`MAX_PR_COST_USD\` | \`${costDisplay}\` | \`<=$${Number(p.maxPrCostUsd).toFixed(2)}\` | **${statusTag('MAX_PR_COST_USD')}** |`,
249
317
  `| \`MAX_PR_TOKENS\` | \`${Number(m.totalTokens || 0).toLocaleString('en-US')}\` | \`<=${Number(p.maxPrTokens).toLocaleString('en-US')}\` | **${statusTag('MAX_PR_TOKENS')}** |`,
250
318
  `| \`MIN_CACHE_HIT_PCT\` | \`${m.cacheHitPct ?? 0}%\` | \`>=${p.minCacheHitPct}%\` | **${statusTag('MIN_CACHE_HIT_PCT')}** |`,
251
319
  `| \`MAX_WASTE_RATIO_PCT\` | \`${m.wasteRatioPct ?? 0}%\` | \`<=${p.maxWasteRatioPct}%\` | **${statusTag('MAX_WASTE_RATIO_PCT')}** |`,
252
320
  `| \`MAX_RING0_VIOLATIONS\` | \`${m.ring0Violations ?? 0}\` | \`<=${p.maxRing0Violations}\` | **${statusTag('MAX_RING0_VIOLATIONS')}** |`
253
321
  ];
254
322
 
323
+ if (Array.isArray(result.notices) && result.notices.length > 0) {
324
+ lines.push('', '#### Notices', '');
325
+ for (const n of result.notices) {
326
+ lines.push(`- **${n.code}**: ${n.message}`);
327
+ }
328
+ }
329
+
255
330
  if (Array.isArray(result.violations) && result.violations.length > 0) {
256
331
  lines.push('', '#### Violations', '');
257
332
  for (const v of result.violations) {