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/config/policy.mjs
CHANGED
|
@@ -27,11 +27,12 @@ export const DEFAULT_POLICY = Object.freeze({
|
|
|
27
27
|
outputMode: 'auto'
|
|
28
28
|
}),
|
|
29
29
|
ciBudgetGate: Object.freeze({
|
|
30
|
-
maxPrCostUsd:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
maxCacheMissRatio: 0.65,
|
|
30
|
+
maxPrCostUsd: 15,
|
|
31
|
+
maxPrTokens: 1_500_000,
|
|
32
|
+
maxCacheMissRatio: 0.50,
|
|
34
33
|
maxWasteRatio: 0.35,
|
|
34
|
+
maxRing0Violations: 0,
|
|
35
|
+
mode: 'enforce',
|
|
35
36
|
failOnMissingTranscripts: false
|
|
36
37
|
})
|
|
37
38
|
});
|
|
@@ -102,6 +103,9 @@ export function parseSimpleYaml(text = '') {
|
|
|
102
103
|
for (let idx = 0; idx < lines.length; idx++) {
|
|
103
104
|
const rawLine = stripInlineComment(lines[idx]);
|
|
104
105
|
if (!rawLine.trim()) continue;
|
|
106
|
+
if (/^\t|^ *\t/.test(rawLine)) {
|
|
107
|
+
throw new SyntaxError(`Invalid YAML tab indentation at line ${idx + 1}`);
|
|
108
|
+
}
|
|
105
109
|
const indent = rawLine.match(/^ */)[0].length;
|
|
106
110
|
const content = rawLine.trim();
|
|
107
111
|
|
|
@@ -110,21 +114,25 @@ export function parseSimpleYaml(text = '') {
|
|
|
110
114
|
}
|
|
111
115
|
const top = stack[stack.length - 1];
|
|
112
116
|
|
|
113
|
-
if (content.startsWith('- ')) {
|
|
117
|
+
if (content === '-' || content.startsWith('- ')) {
|
|
114
118
|
const itemText = content.slice(2).trim();
|
|
115
119
|
if (!Array.isArray(top.container)) {
|
|
116
|
-
|
|
120
|
+
throw new SyntaxError(`Unexpected YAML list item at line ${idx + 1}`);
|
|
117
121
|
}
|
|
118
122
|
top.container.push(parseScalar(itemText));
|
|
119
123
|
continue;
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
const colonIdx = content.indexOf(':');
|
|
123
|
-
if (colonIdx === -1)
|
|
127
|
+
if (colonIdx === -1) {
|
|
128
|
+
throw new SyntaxError(`Invalid YAML syntax (missing ':') at line ${idx + 1}`);
|
|
129
|
+
}
|
|
124
130
|
|
|
125
131
|
const key = content.slice(0, colonIdx).trim().replace(/^['"]|['"]$/g, '');
|
|
126
132
|
const rest = content.slice(colonIdx + 1).trim();
|
|
127
|
-
if (!key)
|
|
133
|
+
if (!key) {
|
|
134
|
+
throw new SyntaxError(`Invalid YAML empty key at line ${idx + 1}`);
|
|
135
|
+
}
|
|
128
136
|
|
|
129
137
|
if (rest === '') {
|
|
130
138
|
// Peek next non-empty line to determine object vs array
|
|
@@ -168,41 +176,90 @@ function mergePolicy(base, override) {
|
|
|
168
176
|
return result;
|
|
169
177
|
}
|
|
170
178
|
|
|
179
|
+
const POLICY_CACHE = new Map();
|
|
180
|
+
const POLICY_CACHE_TTL_MS = 500;
|
|
181
|
+
|
|
182
|
+
export function clearBurnoffPolicyCache() {
|
|
183
|
+
POLICY_CACHE.clear();
|
|
184
|
+
}
|
|
185
|
+
|
|
171
186
|
/**
|
|
172
187
|
* Loads `.burnoff.yaml` (or `.burnoff.yml`) from `cwd` and merges with `DEFAULT_POLICY`.
|
|
173
188
|
*/
|
|
174
189
|
export function loadBurnoffPolicy(cwd = process.cwd()) {
|
|
175
190
|
const baseDir = path.resolve(cwd || process.cwd());
|
|
191
|
+
const nowMs = Date.now();
|
|
192
|
+
const cached = POLICY_CACHE.get(baseDir);
|
|
193
|
+
if (cached && nowMs - cached.ts < POLICY_CACHE_TTL_MS) {
|
|
194
|
+
try {
|
|
195
|
+
if (cached.value.sourcePath) {
|
|
196
|
+
const st = fs.statSync(cached.value.sourcePath);
|
|
197
|
+
if (st.mtimeMs === cached.mtimeMs) {
|
|
198
|
+
return cached.value;
|
|
199
|
+
}
|
|
200
|
+
} else if (
|
|
201
|
+
!fs.existsSync(path.join(baseDir, '.burnoff.yaml')) &&
|
|
202
|
+
!fs.existsSync(path.join(baseDir, '.burnoff.yml'))
|
|
203
|
+
) {
|
|
204
|
+
return cached.value;
|
|
205
|
+
}
|
|
206
|
+
} catch {
|
|
207
|
+
// ignore: stat/exists check failure invalidates cache entry cleanly
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
176
211
|
for (const name of ['.burnoff.yaml', '.burnoff.yml']) {
|
|
177
212
|
const candidate = path.join(baseDir, name);
|
|
178
213
|
if (!fs.existsSync(candidate)) continue;
|
|
214
|
+
let mtimeMs = 0;
|
|
215
|
+
try {
|
|
216
|
+
mtimeMs = fs.statSync(candidate).mtimeMs;
|
|
217
|
+
} catch {
|
|
218
|
+
// ignore: fallback mtimeMs = 0
|
|
219
|
+
}
|
|
179
220
|
try {
|
|
180
221
|
const raw = fs.readFileSync(candidate, 'utf8');
|
|
181
222
|
const parsed = parseSimpleYaml(raw);
|
|
182
|
-
|
|
223
|
+
const rawCiBudgetGate =
|
|
224
|
+
parsed?.ciBudgetGate && typeof parsed.ciBudgetGate === 'object' && !Array.isArray(parsed.ciBudgetGate)
|
|
225
|
+
? { ...parsed.ciBudgetGate }
|
|
226
|
+
: {};
|
|
227
|
+
const value = {
|
|
183
228
|
...mergePolicy(DEFAULT_POLICY, parsed),
|
|
229
|
+
rawCiBudgetGate,
|
|
184
230
|
sourcePath: candidate,
|
|
185
231
|
exists: true
|
|
186
232
|
};
|
|
233
|
+
if (POLICY_CACHE.size > 64) POLICY_CACHE.clear();
|
|
234
|
+
POLICY_CACHE.set(baseDir, { ts: nowMs, mtimeMs, value });
|
|
235
|
+
return value;
|
|
187
236
|
} catch {
|
|
188
|
-
|
|
237
|
+
const value = {
|
|
189
238
|
...cloneDefaultPolicy(),
|
|
239
|
+
rawCiBudgetGate: {},
|
|
190
240
|
sourcePath: candidate,
|
|
191
241
|
exists: true,
|
|
192
242
|
parseError: true
|
|
193
243
|
};
|
|
244
|
+
if (POLICY_CACHE.size > 64) POLICY_CACHE.clear();
|
|
245
|
+
POLICY_CACHE.set(baseDir, { ts: nowMs, mtimeMs, value });
|
|
246
|
+
return value;
|
|
194
247
|
}
|
|
195
248
|
}
|
|
196
249
|
|
|
197
|
-
|
|
250
|
+
const value = {
|
|
198
251
|
...cloneDefaultPolicy(),
|
|
199
252
|
sourcePath: null,
|
|
200
253
|
exists: false
|
|
201
254
|
};
|
|
255
|
+
if (POLICY_CACHE.size > 64) POLICY_CACHE.clear();
|
|
256
|
+
POLICY_CACHE.set(baseDir, { ts: nowMs, mtimeMs: 0, value });
|
|
257
|
+
return value;
|
|
202
258
|
}
|
|
203
259
|
|
|
204
260
|
export default {
|
|
205
261
|
DEFAULT_POLICY,
|
|
206
262
|
parseSimpleYaml,
|
|
207
|
-
loadBurnoffPolicy
|
|
263
|
+
loadBurnoffPolicy,
|
|
264
|
+
clearBurnoffPolicyCache
|
|
208
265
|
};
|