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.
- package/.github/workflows/burnoff-pr-gate.yml +75 -0
- package/README.md +94 -20
- package/bin/burnoff.mjs +129 -30
- package/hooks/hook-io.mjs +27 -18
- package/hooks/post-tool-use.mjs +33 -26
- package/hooks/pre-tool-use.mjs +43 -41
- package/hooks/session-lifecycle.mjs +40 -0
- package/package.json +8 -5
- package/src/ci/ci-gate.mjs +84 -9
- package/src/ci/pr-cost.mjs +207 -22
- package/src/ci/team-digest.mjs +6 -4
- package/src/cli/audit.mjs +177 -23
- package/src/cli/doctor.mjs +230 -25
- package/src/cli/init.mjs +415 -75
- package/src/cli/startup-audit.mjs +2824 -0
- package/src/clients/antigravity.mjs +285 -0
- package/src/clients/claude-code.mjs +180 -0
- package/src/clients/detect.mjs +64 -0
- package/src/config/catalog.json +188 -45
- package/src/config/loader.mjs +96 -13
- package/src/config/paths.mjs +92 -2
- package/src/config/policy.mjs +103 -17
- package/src/config/pricing.mjs +1033 -0
- package/src/config/uncached-attribution.mjs +719 -0
- package/src/guards/loop-breaker.mjs +267 -24
- package/src/guards/post-tool-engine.mjs +316 -35
- package/src/guards/pre-tool-engine.mjs +389 -130
- package/src/guards/read-clamp.mjs +149 -75
- package/src/guards/session-hook.mjs +207 -0
- package/src/guards/shell-guard.mjs +610 -74
- package/src/ipc/daemon.mjs +50 -8
- package/src/ipc/fast-client.mjs +62 -5
- package/src/ipc/protocol.mjs +1 -1
- package/src/storage/antigravity-parser.mjs +258 -0
- package/src/storage/atomic-io.mjs +2 -2
- package/src/storage/file-lock.mjs +66 -13
- package/src/storage/fts5-archive.mjs +31 -16
- package/src/storage/jsonl-parser.mjs +209 -20
- package/src/storage/ledger.mjs +15 -10
- package/src/storage/sqlite-client.mjs +35 -11
- package/hooks/hooks.json +0 -12
package/src/config/paths.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
@@ -89,14 +90,17 @@ export function getHomeDir() {
|
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
92
|
* Resolves `~/.burnoff/` (or `BURNOFF_HOME` override) dynamically on every call.
|
|
93
|
+
* Explicit `homeDirOverride` takes precedence over `process.env.BURNOFF_HOME`.
|
|
92
94
|
*/
|
|
93
95
|
export function getBurnoffHomeDir(homeDirOverride = null) {
|
|
96
|
+
if (typeof homeDirOverride === 'string' && homeDirOverride.trim()) {
|
|
97
|
+
return path.join(path.resolve(homeDirOverride.trim()), '.burnoff');
|
|
98
|
+
}
|
|
94
99
|
const envOverride = typeof process !== 'undefined' && process.env?.BURNOFF_HOME
|
|
95
100
|
? String(process.env.BURNOFF_HOME).trim()
|
|
96
101
|
: '';
|
|
97
102
|
if (envOverride) return path.resolve(envOverride);
|
|
98
|
-
|
|
99
|
-
return path.join(home, '.burnoff');
|
|
103
|
+
return path.join(getHomeDir(), '.burnoff');
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
export function getBurnoffCacheDir(homeDirOverride = null) {
|
|
@@ -115,11 +119,93 @@ export function getBurnoffRunDir(homeDirOverride = null) {
|
|
|
115
119
|
return path.join(getBurnoffHomeDir(homeDirOverride), 'run');
|
|
116
120
|
}
|
|
117
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Computes a deterministic 10-char SHA-1 workspace hash matching IPC pipe naming.
|
|
124
|
+
*/
|
|
125
|
+
export function getWorkspaceHash(cwd = process.cwd()) {
|
|
126
|
+
const wsTarget = path.resolve(String(cwd || process.cwd()));
|
|
127
|
+
return crypto.createHash('sha1').update(wsTarget.toLowerCase()).digest('hex').slice(0, 10);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Resolves `~/.burnoff/state/<wshash>/` for per-workspace runtime state isolation.
|
|
132
|
+
*/
|
|
133
|
+
export function getWorkspaceStateDir(cwd = process.cwd(), homeDirOverride = null) {
|
|
134
|
+
return path.join(getBurnoffHomeDir(homeDirOverride), 'state', getWorkspaceHash(cwd));
|
|
135
|
+
}
|
|
136
|
+
|
|
118
137
|
export function getClaudeProjectsDir(homeDirOverride = null) {
|
|
119
138
|
const home = homeDirOverride || getHomeDir();
|
|
120
139
|
return path.join(home, '.claude', 'projects');
|
|
121
140
|
}
|
|
122
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Resolves Google Antigravity configuration, rules, MCP, and transcript paths for a workspace.
|
|
144
|
+
*/
|
|
145
|
+
export function resolveAntigravityConfigPaths({
|
|
146
|
+
homeDir = getHomeDir(),
|
|
147
|
+
cwd = process.cwd(),
|
|
148
|
+
platform = process.platform
|
|
149
|
+
} = {}) {
|
|
150
|
+
const resolvedHome = homeDir || getHomeDir();
|
|
151
|
+
const resolvedCwd = path.resolve(cwd || process.cwd());
|
|
152
|
+
const geminiConfigDir = path.join(resolvedHome, '.gemini', 'config');
|
|
153
|
+
const geminiRootDir = path.join(resolvedHome, '.gemini');
|
|
154
|
+
return {
|
|
155
|
+
homeDir: resolvedHome,
|
|
156
|
+
cwd: resolvedCwd,
|
|
157
|
+
platform,
|
|
158
|
+
geminiConfigDir,
|
|
159
|
+
userHooksJson: path.join(geminiConfigDir, 'hooks.json'),
|
|
160
|
+
userMcpJson: path.join(geminiConfigDir, 'mcp_config.json'),
|
|
161
|
+
projectAgentsDir: path.join(resolvedCwd, '.agents'),
|
|
162
|
+
projectHooksJson: path.join(resolvedCwd, '.agents', 'hooks.json'),
|
|
163
|
+
projectMcpJson: path.join(resolvedCwd, '.agents', 'mcp_config.json'),
|
|
164
|
+
projectRulesDir: path.join(resolvedCwd, '.agents', 'rules'),
|
|
165
|
+
globalRulesDir: path.join(geminiConfigDir, 'rules'),
|
|
166
|
+
brainDirs: [
|
|
167
|
+
path.join(geminiRootDir, 'antigravity', 'brain'),
|
|
168
|
+
path.join(geminiRootDir, 'antigravity-cli', 'brain'),
|
|
169
|
+
path.join(geminiRootDir, 'antigravity-ide', 'brain')
|
|
170
|
+
],
|
|
171
|
+
rulesFiles: [
|
|
172
|
+
path.join(geminiConfigDir, 'GEMINI.md'),
|
|
173
|
+
path.join(geminiConfigDir, 'AGENTS.md'),
|
|
174
|
+
path.join(resolvedCwd, 'GEMINI.md'),
|
|
175
|
+
path.join(resolvedCwd, 'AGENTS.md')
|
|
176
|
+
]
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Resolves Claude Code configuration, rules, MCP, and transcript paths for a workspace.
|
|
182
|
+
*/
|
|
183
|
+
export function resolveClaudeConfigPaths({
|
|
184
|
+
homeDir = getHomeDir(),
|
|
185
|
+
cwd = process.cwd(),
|
|
186
|
+
platform = process.platform
|
|
187
|
+
} = {}) {
|
|
188
|
+
const resolvedHome = homeDir || getHomeDir();
|
|
189
|
+
const resolvedCwd = path.resolve(cwd || process.cwd());
|
|
190
|
+
return {
|
|
191
|
+
homeDir: resolvedHome,
|
|
192
|
+
cwd: resolvedCwd,
|
|
193
|
+
platform,
|
|
194
|
+
claudeJson: path.join(resolvedHome, '.claude.json'),
|
|
195
|
+
userSettings: path.join(resolvedHome, '.claude', 'settings.json'),
|
|
196
|
+
projectSettings: path.join(resolvedCwd, '.claude', 'settings.json'),
|
|
197
|
+
projectLocalSettings: path.join(resolvedCwd, '.claude', 'settings.local.json'),
|
|
198
|
+
projectMcpJson: path.join(resolvedCwd, '.mcp.json'),
|
|
199
|
+
projectsDir: path.join(resolvedHome, '.claude', 'projects'),
|
|
200
|
+
rulesFiles: [
|
|
201
|
+
path.join(resolvedHome, '.claude', 'CLAUDE.md'),
|
|
202
|
+
path.join(resolvedCwd, 'CLAUDE.md'),
|
|
203
|
+
path.join(resolvedCwd, '.claude', 'CLAUDE.md'),
|
|
204
|
+
path.join(resolvedCwd, 'AGENTS.md')
|
|
205
|
+
]
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
123
209
|
export function ensureDirSync(dirPath, mode = 0o700) {
|
|
124
210
|
if (!dirPath) return '';
|
|
125
211
|
const resolved = path.resolve(dirPath);
|
|
@@ -189,7 +275,11 @@ export default {
|
|
|
189
275
|
getBurnoffRuntimeDir,
|
|
190
276
|
getBurnoffLedgerDir,
|
|
191
277
|
getBurnoffRunDir,
|
|
278
|
+
getWorkspaceHash,
|
|
279
|
+
getWorkspaceStateDir,
|
|
192
280
|
getClaudeProjectsDir,
|
|
281
|
+
resolveClaudeConfigPaths,
|
|
282
|
+
resolveAntigravityConfigPaths,
|
|
193
283
|
ensureDirSync,
|
|
194
284
|
formatNodeUpgradeHint,
|
|
195
285
|
ensureSupportedNodeVersion
|
package/src/config/policy.mjs
CHANGED
|
@@ -9,14 +9,21 @@ export const DEFAULT_POLICY = Object.freeze({
|
|
|
9
9
|
det03Enabled: true,
|
|
10
10
|
det04Enabled: true,
|
|
11
11
|
det04Threshold: 3,
|
|
12
|
+
secretAllow: Object.freeze([]),
|
|
12
13
|
strictTestIntegrity: false,
|
|
13
|
-
scopeLockEnabled: true
|
|
14
|
+
scopeLockEnabled: true,
|
|
15
|
+
subagentFanoutEnabled: true,
|
|
16
|
+
subagentFanoutAction: 'advisory',
|
|
17
|
+
subagentMaxBurstCount: 4,
|
|
18
|
+
subagentBurstWindowSec: 60,
|
|
19
|
+
subagentMaxPromptChars: 8000
|
|
14
20
|
}),
|
|
15
21
|
readClamp: Object.freeze({
|
|
16
22
|
enabled: true,
|
|
17
23
|
maxLines: 250,
|
|
18
24
|
maxBytes: 16384,
|
|
19
25
|
neverClampCodeOffCliff: true,
|
|
26
|
+
neverClampExt: Object.freeze([]),
|
|
20
27
|
headProbeMaxBytes: 8388608,
|
|
21
28
|
codeRealizationDiscount: 0.27
|
|
22
29
|
}),
|
|
@@ -27,19 +34,26 @@ export const DEFAULT_POLICY = Object.freeze({
|
|
|
27
34
|
outputMode: 'auto'
|
|
28
35
|
}),
|
|
29
36
|
ciBudgetGate: Object.freeze({
|
|
30
|
-
maxPrCostUsd:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
maxCacheMissRatio: 0.65,
|
|
37
|
+
maxPrCostUsd: 15,
|
|
38
|
+
maxPrTokens: 1_500_000,
|
|
39
|
+
maxCacheMissRatio: 0.50,
|
|
34
40
|
maxWasteRatio: 0.35,
|
|
41
|
+
maxRing0Violations: 0,
|
|
42
|
+
mode: 'enforce',
|
|
35
43
|
failOnMissingTranscripts: false
|
|
36
44
|
})
|
|
37
45
|
});
|
|
38
46
|
|
|
39
47
|
function cloneDefaultPolicy() {
|
|
40
48
|
return {
|
|
41
|
-
guards: {
|
|
42
|
-
|
|
49
|
+
guards: {
|
|
50
|
+
...DEFAULT_POLICY.guards,
|
|
51
|
+
secretAllow: [...DEFAULT_POLICY.guards.secretAllow]
|
|
52
|
+
},
|
|
53
|
+
readClamp: {
|
|
54
|
+
...DEFAULT_POLICY.readClamp,
|
|
55
|
+
neverClampExt: [...DEFAULT_POLICY.readClamp.neverClampExt]
|
|
56
|
+
},
|
|
43
57
|
postTool: { ...DEFAULT_POLICY.postTool },
|
|
44
58
|
ciBudgetGate: { ...DEFAULT_POLICY.ciBudgetGate }
|
|
45
59
|
};
|
|
@@ -102,6 +116,9 @@ export function parseSimpleYaml(text = '') {
|
|
|
102
116
|
for (let idx = 0; idx < lines.length; idx++) {
|
|
103
117
|
const rawLine = stripInlineComment(lines[idx]);
|
|
104
118
|
if (!rawLine.trim()) continue;
|
|
119
|
+
if (/^\t|^ *\t/.test(rawLine)) {
|
|
120
|
+
throw new SyntaxError(`Invalid YAML tab indentation at line ${idx + 1}`);
|
|
121
|
+
}
|
|
105
122
|
const indent = rawLine.match(/^ */)[0].length;
|
|
106
123
|
const content = rawLine.trim();
|
|
107
124
|
|
|
@@ -110,21 +127,25 @@ export function parseSimpleYaml(text = '') {
|
|
|
110
127
|
}
|
|
111
128
|
const top = stack[stack.length - 1];
|
|
112
129
|
|
|
113
|
-
if (content.startsWith('- ')) {
|
|
130
|
+
if (content === '-' || content.startsWith('- ')) {
|
|
114
131
|
const itemText = content.slice(2).trim();
|
|
115
132
|
if (!Array.isArray(top.container)) {
|
|
116
|
-
|
|
133
|
+
throw new SyntaxError(`Unexpected YAML list item at line ${idx + 1}`);
|
|
117
134
|
}
|
|
118
135
|
top.container.push(parseScalar(itemText));
|
|
119
136
|
continue;
|
|
120
137
|
}
|
|
121
138
|
|
|
122
139
|
const colonIdx = content.indexOf(':');
|
|
123
|
-
if (colonIdx === -1)
|
|
140
|
+
if (colonIdx === -1) {
|
|
141
|
+
throw new SyntaxError(`Invalid YAML syntax (missing ':') at line ${idx + 1}`);
|
|
142
|
+
}
|
|
124
143
|
|
|
125
144
|
const key = content.slice(0, colonIdx).trim().replace(/^['"]|['"]$/g, '');
|
|
126
145
|
const rest = content.slice(colonIdx + 1).trim();
|
|
127
|
-
if (!key)
|
|
146
|
+
if (!key) {
|
|
147
|
+
throw new SyntaxError(`Invalid YAML empty key at line ${idx + 1}`);
|
|
148
|
+
}
|
|
128
149
|
|
|
129
150
|
if (rest === '') {
|
|
130
151
|
// Peek next non-empty line to determine object vs array
|
|
@@ -160,6 +181,21 @@ function mergePolicy(base, override) {
|
|
|
160
181
|
result[section] = { ...result[section], ...override[section] };
|
|
161
182
|
}
|
|
162
183
|
}
|
|
184
|
+
if (Array.isArray(result.guards.secretAllow)) {
|
|
185
|
+
result.guards.secretAllow = result.guards.secretAllow
|
|
186
|
+
.map((item) => String(item || '').trim())
|
|
187
|
+
.filter(Boolean);
|
|
188
|
+
} else {
|
|
189
|
+
result.guards.secretAllow = [];
|
|
190
|
+
}
|
|
191
|
+
if (Array.isArray(result.readClamp.neverClampExt)) {
|
|
192
|
+
result.readClamp.neverClampExt = result.readClamp.neverClampExt
|
|
193
|
+
.map((item) => String(item || '').trim().toLowerCase())
|
|
194
|
+
.filter(Boolean)
|
|
195
|
+
.map((ext) => (ext.startsWith('.') ? ext : `.${ext}`));
|
|
196
|
+
} else {
|
|
197
|
+
result.readClamp.neverClampExt = [];
|
|
198
|
+
}
|
|
163
199
|
for (const [k, v] of Object.entries(override)) {
|
|
164
200
|
if (!(k in result)) {
|
|
165
201
|
result[k] = v;
|
|
@@ -168,41 +204,91 @@ function mergePolicy(base, override) {
|
|
|
168
204
|
return result;
|
|
169
205
|
}
|
|
170
206
|
|
|
207
|
+
const POLICY_CACHE = new Map();
|
|
208
|
+
const POLICY_CACHE_TTL_MS = 500;
|
|
209
|
+
|
|
210
|
+
export function clearBurnoffPolicyCache() {
|
|
211
|
+
POLICY_CACHE.clear();
|
|
212
|
+
}
|
|
213
|
+
|
|
171
214
|
/**
|
|
172
215
|
* Loads `.burnoff.yaml` (or `.burnoff.yml`) from `cwd` and merges with `DEFAULT_POLICY`.
|
|
173
216
|
*/
|
|
174
217
|
export function loadBurnoffPolicy(cwd = process.cwd()) {
|
|
175
218
|
const baseDir = path.resolve(cwd || process.cwd());
|
|
219
|
+
const nowMs = Date.now();
|
|
220
|
+
const cached = POLICY_CACHE.get(baseDir);
|
|
221
|
+
if (cached && nowMs - cached.ts < POLICY_CACHE_TTL_MS) {
|
|
222
|
+
try {
|
|
223
|
+
if (cached.value.sourcePath) {
|
|
224
|
+
const st = fs.statSync(cached.value.sourcePath);
|
|
225
|
+
if (st.mtimeMs === cached.mtimeMs) {
|
|
226
|
+
return cached.value;
|
|
227
|
+
}
|
|
228
|
+
} else if (
|
|
229
|
+
!fs.existsSync(path.join(baseDir, '.burnoff.yaml')) &&
|
|
230
|
+
!fs.existsSync(path.join(baseDir, '.burnoff.yml'))
|
|
231
|
+
) {
|
|
232
|
+
return cached.value;
|
|
233
|
+
}
|
|
234
|
+
} catch {
|
|
235
|
+
// ignore: stat/exists check failure invalidates cache entry cleanly
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
176
239
|
for (const name of ['.burnoff.yaml', '.burnoff.yml']) {
|
|
177
240
|
const candidate = path.join(baseDir, name);
|
|
178
241
|
if (!fs.existsSync(candidate)) continue;
|
|
242
|
+
let mtimeMs = 0;
|
|
243
|
+
try {
|
|
244
|
+
mtimeMs = fs.statSync(candidate).mtimeMs;
|
|
245
|
+
} catch {
|
|
246
|
+
// ignore: fallback mtimeMs = 0
|
|
247
|
+
}
|
|
179
248
|
try {
|
|
180
249
|
const raw = fs.readFileSync(candidate, 'utf8');
|
|
181
250
|
const parsed = parseSimpleYaml(raw);
|
|
182
|
-
|
|
251
|
+
const rawCiBudgetGate =
|
|
252
|
+
parsed?.ciBudgetGate && typeof parsed.ciBudgetGate === 'object' && !Array.isArray(parsed.ciBudgetGate)
|
|
253
|
+
? { ...parsed.ciBudgetGate }
|
|
254
|
+
: {};
|
|
255
|
+
const value = {
|
|
183
256
|
...mergePolicy(DEFAULT_POLICY, parsed),
|
|
257
|
+
rawCiBudgetGate,
|
|
184
258
|
sourcePath: candidate,
|
|
185
259
|
exists: true
|
|
186
260
|
};
|
|
187
|
-
|
|
188
|
-
|
|
261
|
+
if (POLICY_CACHE.size > 64) POLICY_CACHE.clear();
|
|
262
|
+
POLICY_CACHE.set(baseDir, { ts: nowMs, mtimeMs, value });
|
|
263
|
+
return value;
|
|
264
|
+
} catch (err) {
|
|
265
|
+
const value = {
|
|
189
266
|
...cloneDefaultPolicy(),
|
|
267
|
+
rawCiBudgetGate: {},
|
|
190
268
|
sourcePath: candidate,
|
|
191
269
|
exists: true,
|
|
192
|
-
parseError: true
|
|
270
|
+
parseError: true,
|
|
271
|
+
parseErrorMessage: err?.message || 'Invalid YAML syntax'
|
|
193
272
|
};
|
|
273
|
+
if (POLICY_CACHE.size > 64) POLICY_CACHE.clear();
|
|
274
|
+
POLICY_CACHE.set(baseDir, { ts: nowMs, mtimeMs, value });
|
|
275
|
+
return value;
|
|
194
276
|
}
|
|
195
277
|
}
|
|
196
278
|
|
|
197
|
-
|
|
279
|
+
const value = {
|
|
198
280
|
...cloneDefaultPolicy(),
|
|
199
281
|
sourcePath: null,
|
|
200
282
|
exists: false
|
|
201
283
|
};
|
|
284
|
+
if (POLICY_CACHE.size > 64) POLICY_CACHE.clear();
|
|
285
|
+
POLICY_CACHE.set(baseDir, { ts: nowMs, mtimeMs: 0, value });
|
|
286
|
+
return value;
|
|
202
287
|
}
|
|
203
288
|
|
|
204
289
|
export default {
|
|
205
290
|
DEFAULT_POLICY,
|
|
206
291
|
parseSimpleYaml,
|
|
207
|
-
loadBurnoffPolicy
|
|
292
|
+
loadBurnoffPolicy,
|
|
293
|
+
clearBurnoffPolicyCache
|
|
208
294
|
};
|