burnoff 1.0.0 → 1.1.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 +100 -14
- package/bin/burnoff.mjs +71 -16
- package/hooks/hook-io.mjs +8 -11
- package/package.json +3 -2
- package/src/ci/ci-gate.mjs +62 -9
- package/src/ci/pr-cost.mjs +167 -14
- package/src/ci/team-digest.mjs +1 -1
- package/src/cli/audit.mjs +74 -5
- package/src/cli/doctor.mjs +22 -12
- package/src/cli/init.mjs +92 -5
- package/src/cli/startup-audit.mjs +2348 -0
- package/src/config/catalog.json +188 -45
- package/src/config/loader.mjs +85 -9
- package/src/config/paths.mjs +30 -0
- package/src/config/policy.mjs +69 -12
- package/src/config/pricing.mjs +1022 -0
- package/src/config/uncached-attribution.mjs +719 -0
- package/src/guards/loop-breaker.mjs +72 -14
- package/src/guards/post-tool-engine.mjs +33 -12
- package/src/guards/pre-tool-engine.mjs +54 -2
- package/src/guards/read-clamp.mjs +73 -59
- package/src/guards/shell-guard.mjs +45 -19
- package/src/storage/atomic-io.mjs +2 -2
- package/src/storage/file-lock.mjs +53 -9
- package/src/storage/fts5-archive.mjs +27 -12
- package/src/storage/jsonl-parser.mjs +202 -19
- package/src/storage/ledger.mjs +7 -9
- package/src/storage/sqlite-client.mjs +31 -9
package/src/cli/init.mjs
CHANGED
|
@@ -22,11 +22,18 @@ const EXCLUDE_START_MARKER = '# burnoff-managed:start';
|
|
|
22
22
|
const EXCLUDE_END_MARKER = '# burnoff-managed:end';
|
|
23
23
|
const EXCLUDE_PATTERNS = Object.freeze([
|
|
24
24
|
'.claude/settings.local.json',
|
|
25
|
+
'.claude/burnoff-hook-shim.mjs',
|
|
25
26
|
'.claude/cache/',
|
|
26
27
|
'.claude/locks/',
|
|
28
|
+
'.burnoff/',
|
|
27
29
|
'.burnoff-ci/'
|
|
28
30
|
]);
|
|
29
31
|
|
|
32
|
+
export function isEphemeralNpxPath(pkgRoot = PACKAGE_ROOT) {
|
|
33
|
+
const norm = String(pkgRoot || '').replace(/\\/g, '/');
|
|
34
|
+
return /(?:^|\/)_npx(?:\/|$)|(?:^|\/)npm-cache\/_npx(?:\/|$)/i.test(norm);
|
|
35
|
+
}
|
|
36
|
+
|
|
30
37
|
function normalizeCommandPath(filePath) {
|
|
31
38
|
return path.resolve(filePath).replace(/\\/g, '/');
|
|
32
39
|
}
|
|
@@ -34,6 +41,7 @@ function normalizeCommandPath(filePath) {
|
|
|
34
41
|
function isBurnoffCommand(command = '') {
|
|
35
42
|
const cmd = String(command || '').replace(/\\/g, '/');
|
|
36
43
|
if (!cmd) return false;
|
|
44
|
+
if (/\.claude\/burnoff-hook-shim\.mjs/i.test(cmd)) return true;
|
|
37
45
|
return (
|
|
38
46
|
/(?:^|[/"'\s])hooks\/(?:pre|post)-tool-use\.mjs(?:["'\s]|$)/i.test(cmd) &&
|
|
39
47
|
(/burnoff/i.test(cmd) ||
|
|
@@ -116,13 +124,59 @@ function readJsonObjectSafe(filePath) {
|
|
|
116
124
|
return {};
|
|
117
125
|
}
|
|
118
126
|
|
|
127
|
+
function buildHookShimSource(fallbackPackageRoot) {
|
|
128
|
+
const fallback = normalizeCommandPath(fallbackPackageRoot);
|
|
129
|
+
return `import fs from 'node:fs';
|
|
130
|
+
import path from 'node:path';
|
|
131
|
+
import { createRequire } from 'node:module';
|
|
132
|
+
import { pathToFileURL } from 'node:url';
|
|
133
|
+
|
|
134
|
+
const hookArg = process.argv[2] === 'post' ? 'post-tool-use.mjs' : 'pre-tool-use.mjs';
|
|
135
|
+
const cwd = process.cwd();
|
|
136
|
+
const candidates = [
|
|
137
|
+
path.join(cwd, 'node_modules', 'burnoff', 'hooks', hookArg)
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
const req = createRequire(path.join(cwd, 'package.json'));
|
|
142
|
+
const pkgPath = req.resolve('burnoff/package.json');
|
|
143
|
+
candidates.push(path.join(path.dirname(pkgPath), 'hooks', hookArg));
|
|
144
|
+
} catch {
|
|
145
|
+
// ignore: local/global resolution miss falls back to bundled path
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
candidates.push(path.join(${JSON.stringify(fallback)}, 'hooks', hookArg));
|
|
149
|
+
|
|
150
|
+
const resolved = candidates.find((p) => {
|
|
151
|
+
try {
|
|
152
|
+
return fs.existsSync(p);
|
|
153
|
+
} catch {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
if (!resolved) {
|
|
159
|
+
process.stderr.write(
|
|
160
|
+
'[burnoff] Hook target missing (ephemeral npx cache cleared). Install persistently: npm i -D burnoff or npm i -g burnoff.\\n'
|
|
161
|
+
);
|
|
162
|
+
process.exit(0);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
await import(pathToFileURL(resolved).href);
|
|
166
|
+
`;
|
|
167
|
+
}
|
|
168
|
+
|
|
119
169
|
/**
|
|
120
170
|
* Builds Claude Code `PreToolUse` and `PostToolUse` hook definitions pointing to Burnoff's fast-shell hooks.
|
|
121
171
|
*/
|
|
122
172
|
export function buildClaudeHooksConfig(options = {}) {
|
|
123
173
|
const root = path.resolve(options.packageRoot || PACKAGE_ROOT);
|
|
124
|
-
const
|
|
125
|
-
|
|
174
|
+
const preCmd = options.shimPath
|
|
175
|
+
? `node "${normalizeCommandPath(options.shimPath)}" pre`
|
|
176
|
+
: `node "${normalizeCommandPath(path.join(root, 'hooks', 'pre-tool-use.mjs'))}"`;
|
|
177
|
+
const postCmd = options.shimPath
|
|
178
|
+
? `node "${normalizeCommandPath(options.shimPath)}" post`
|
|
179
|
+
: `node "${normalizeCommandPath(path.join(root, 'hooks', 'post-tool-use.mjs'))}"`;
|
|
126
180
|
const timeout = Number.isFinite(Number(options.timeout)) ? Number(options.timeout) : 5;
|
|
127
181
|
|
|
128
182
|
return {
|
|
@@ -132,7 +186,7 @@ export function buildClaudeHooksConfig(options = {}) {
|
|
|
132
186
|
hooks: [
|
|
133
187
|
{
|
|
134
188
|
type: 'command',
|
|
135
|
-
command:
|
|
189
|
+
command: preCmd,
|
|
136
190
|
timeout
|
|
137
191
|
}
|
|
138
192
|
]
|
|
@@ -144,7 +198,7 @@ export function buildClaudeHooksConfig(options = {}) {
|
|
|
144
198
|
hooks: [
|
|
145
199
|
{
|
|
146
200
|
type: 'command',
|
|
147
|
-
command:
|
|
201
|
+
command: postCmd,
|
|
148
202
|
timeout
|
|
149
203
|
}
|
|
150
204
|
]
|
|
@@ -160,8 +214,22 @@ export function buildClaudeHooksConfig(options = {}) {
|
|
|
160
214
|
export function initBurnoff(options = {}) {
|
|
161
215
|
const cwd = path.resolve(options.cwd || process.cwd());
|
|
162
216
|
const dryRun = Boolean(options.dryRun);
|
|
217
|
+
const pkgRoot = path.resolve(options.packageRoot || PACKAGE_ROOT);
|
|
218
|
+
const ephemeralNpx = isEphemeralNpxPath(pkgRoot);
|
|
219
|
+
const useShim = Boolean(options.useShim || ephemeralNpx);
|
|
220
|
+
const shimPath = useShim ? path.join(cwd, '.claude', 'burnoff-hook-shim.mjs') : null;
|
|
221
|
+
const warnings = [];
|
|
222
|
+
if (ephemeralNpx) {
|
|
223
|
+
warnings.push(
|
|
224
|
+
'Ephemeral npx cache path detected; wrote .claude/burnoff-hook-shim.mjs. Install persistently with "npm i -D burnoff" or "npm i -g burnoff".'
|
|
225
|
+
);
|
|
226
|
+
}
|
|
163
227
|
const settingsPath = path.join(cwd, '.claude', 'settings.local.json');
|
|
164
|
-
const hooks = buildClaudeHooksConfig(
|
|
228
|
+
const hooks = buildClaudeHooksConfig({
|
|
229
|
+
...options,
|
|
230
|
+
packageRoot: pkgRoot,
|
|
231
|
+
...(shimPath ? { shimPath } : {})
|
|
232
|
+
});
|
|
165
233
|
|
|
166
234
|
const current = readJsonObjectSafe(settingsPath);
|
|
167
235
|
const existingHooks =
|
|
@@ -182,6 +250,9 @@ export function initBurnoff(options = {}) {
|
|
|
182
250
|
};
|
|
183
251
|
|
|
184
252
|
if (!dryRun) {
|
|
253
|
+
if (shimPath) {
|
|
254
|
+
atomicWriteFileSync(shimPath, buildHookShimSource(pkgRoot), { encoding: 'utf8' });
|
|
255
|
+
}
|
|
185
256
|
atomicWriteJsonSync(settingsPath, nextSettings);
|
|
186
257
|
}
|
|
187
258
|
|
|
@@ -205,6 +276,9 @@ export function initBurnoff(options = {}) {
|
|
|
205
276
|
dryRun,
|
|
206
277
|
cwd,
|
|
207
278
|
settingsPath,
|
|
279
|
+
shimPath,
|
|
280
|
+
ephemeralNpx,
|
|
281
|
+
warnings,
|
|
208
282
|
excludePath,
|
|
209
283
|
excludeUpdated,
|
|
210
284
|
hooks
|
|
@@ -221,6 +295,19 @@ export function uninstallBurnoff(options = {}) {
|
|
|
221
295
|
let removedSettings = false;
|
|
222
296
|
let updatedSettings = false;
|
|
223
297
|
|
|
298
|
+
const shimPath = path.join(cwd, '.claude', 'burnoff-hook-shim.mjs');
|
|
299
|
+
let removedShim = false;
|
|
300
|
+
if (fs.existsSync(shimPath)) {
|
|
301
|
+
removedShim = true;
|
|
302
|
+
if (!dryRun) {
|
|
303
|
+
try {
|
|
304
|
+
fs.unlinkSync(shimPath);
|
|
305
|
+
} catch (err) {
|
|
306
|
+
void err; // ignore: shim unlink best-effort
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
224
311
|
if (fs.existsSync(settingsPath)) {
|
|
225
312
|
const current = readJsonObjectSafe(settingsPath);
|
|
226
313
|
const nextHooks =
|