burnoff 1.3.0 → 1.4.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/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/burnoff-pr-gate.yml +3 -3
- package/.github/workflows/burnoff-startup-lint.yml +2 -2
- package/README.md +26 -12
- package/bin/burnoff.mjs +6 -5
- package/commands/burnoff.md +2 -2
- package/docs/CLAUDE_CODE_PLUGIN.md +6 -6
- package/docs/DESIGN_PARTNER_INTAKE.md +3 -3
- package/package.json +1 -1
- package/scripts/burnoff-statusline.mjs +20 -0
- package/src/cli/audit.mjs +82 -4
- package/src/cli/startup-audit.mjs +147 -2
- package/src/config/policy.mjs +13 -1
- package/src/guards/loop-breaker.mjs +49 -0
- package/src/guards/phase5-detectors.mjs +727 -0
- package/src/guards/pre-tool-engine.mjs +146 -14
- package/src/guards/snooze.mjs +5 -2
- package/src/storage/antigravity-parser.mjs +18 -1
- package/src/storage/jsonl-parser.mjs +29 -1
- package/src/storage/telemetry-metrics.mjs +703 -0
|
@@ -39,6 +39,12 @@ import {
|
|
|
39
39
|
consumeMatchingAskSnoozeAtomicSync,
|
|
40
40
|
matchesSnoozeEntry
|
|
41
41
|
} from './snooze.mjs';
|
|
42
|
+
import {
|
|
43
|
+
PHASE5_DEFAULTS,
|
|
44
|
+
evaluateDet07CommandOutputGuard,
|
|
45
|
+
evaluateDet08EditIntegrityGuard,
|
|
46
|
+
evaluateDet09EditThrash
|
|
47
|
+
} from './phase5-detectors.mjs';
|
|
42
48
|
|
|
43
49
|
const READ_TOOL_REGEX = /^(?:Read|read_file|view_file)$/i;
|
|
44
50
|
const EDIT_WRITE_OR_READ_REGEX = /^(?:Edit|Write|MultiEdit|NotebookEdit|Read|Grep|Glob|read_file|view_file|grep_search)$/i;
|
|
@@ -194,6 +200,72 @@ function evaluatePreToolUseCore(event = {}, options = {}) {
|
|
|
194
200
|
};
|
|
195
201
|
|
|
196
202
|
let advisoryNotice = null;
|
|
203
|
+
const appendAdvisory = (existing, nextVerdict) => {
|
|
204
|
+
if (!existing) return nextVerdict;
|
|
205
|
+
return {
|
|
206
|
+
...existing,
|
|
207
|
+
additionalContext: [
|
|
208
|
+
existing.additionalContext || existing.reason,
|
|
209
|
+
nextVerdict.additionalContext || nextVerdict.reason
|
|
210
|
+
]
|
|
211
|
+
.filter(Boolean)
|
|
212
|
+
.join('\n'),
|
|
213
|
+
reason: [existing.reason, nextVerdict.reason].filter(Boolean).join('\n')
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const handlePhase5Verdict = (verdict, snoozeTarget, ledgerCategory) => {
|
|
218
|
+
if (!verdict || !verdict.triggered) return null;
|
|
219
|
+
if (verdict.decision === 'allow') {
|
|
220
|
+
advisoryNotice = appendAdvisory(advisoryNotice, verdict);
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
if (verdict.decision === 'ask') {
|
|
224
|
+
const evaluated = evaluateAskWithSnooze(verdict, snoozeTarget);
|
|
225
|
+
if (evaluated.snoozed) {
|
|
226
|
+
return evaluated.response;
|
|
227
|
+
}
|
|
228
|
+
if (canRecordLedger) {
|
|
229
|
+
recordSavingsReceipt(
|
|
230
|
+
{
|
|
231
|
+
sessionId,
|
|
232
|
+
cwd: baseCwd,
|
|
233
|
+
category: ledgerCategory,
|
|
234
|
+
detectorId: verdict.detectorId,
|
|
235
|
+
ring0Violation: false,
|
|
236
|
+
modelId,
|
|
237
|
+
savedTokens: 0,
|
|
238
|
+
savedUSD: 0,
|
|
239
|
+
detail: verdict.reason
|
|
240
|
+
},
|
|
241
|
+
cwdOptions
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return evaluated.response;
|
|
245
|
+
}
|
|
246
|
+
if (canRecordLedger) {
|
|
247
|
+
recordSavingsReceipt(
|
|
248
|
+
{
|
|
249
|
+
sessionId,
|
|
250
|
+
cwd: baseCwd,
|
|
251
|
+
category: ledgerCategory,
|
|
252
|
+
detectorId: verdict.detectorId,
|
|
253
|
+
ring0Violation: false,
|
|
254
|
+
modelId,
|
|
255
|
+
savedTokens: 0,
|
|
256
|
+
savedUSD: 0,
|
|
257
|
+
detail: verdict.reason
|
|
258
|
+
},
|
|
259
|
+
cwdOptions
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
return finalize({
|
|
263
|
+
exitCode: 2,
|
|
264
|
+
stdout: '',
|
|
265
|
+
stderr: verdict.reason,
|
|
266
|
+
verdict
|
|
267
|
+
});
|
|
268
|
+
};
|
|
197
269
|
|
|
198
270
|
// 1. DET-20: Concurrent file-scope locks & quota hard brakes
|
|
199
271
|
if (guardsCfg.scopeLockEnabled !== false) {
|
|
@@ -441,23 +513,83 @@ function evaluatePreToolUseCore(event = {}, options = {}) {
|
|
|
441
513
|
}
|
|
442
514
|
|
|
443
515
|
if (det05.triggered) {
|
|
444
|
-
|
|
445
|
-
advisoryNotice = {
|
|
446
|
-
...advisoryNotice,
|
|
447
|
-
additionalContext: [
|
|
448
|
-
advisoryNotice.additionalContext || advisoryNotice.reason,
|
|
449
|
-
det05.additionalContext || det05.reason
|
|
450
|
-
]
|
|
451
|
-
.filter(Boolean)
|
|
452
|
-
.join('\n'),
|
|
453
|
-
reason: [advisoryNotice.reason, det05.reason].filter(Boolean).join('\n')
|
|
454
|
-
};
|
|
455
|
-
} else {
|
|
456
|
-
advisoryNotice = det05;
|
|
457
|
-
}
|
|
516
|
+
advisoryNotice = appendAdvisory(advisoryNotice, det05);
|
|
458
517
|
}
|
|
459
518
|
}
|
|
460
519
|
|
|
520
|
+
// 5c. DET-07: Bash Stdout-Flood & Read-Clamp Bypass Guard
|
|
521
|
+
if (guardsCfg.det07Enabled !== false && SHELL_TOOL_REGEX.test(toolName) && command) {
|
|
522
|
+
const det07 = evaluateDet07CommandOutputGuard({
|
|
523
|
+
toolName,
|
|
524
|
+
command,
|
|
525
|
+
cwd: baseCwd,
|
|
526
|
+
mode: guardMode,
|
|
527
|
+
flightMode,
|
|
528
|
+
action: options.det07Action ?? guardsCfg.det07Action ?? PHASE5_DEFAULTS.det07Action,
|
|
529
|
+
maxBytes:
|
|
530
|
+
options.det07ReadBypassMaxBytes ??
|
|
531
|
+
guardsCfg.det07ReadBypassMaxBytes ??
|
|
532
|
+
policy.readClamp?.maxBytes ??
|
|
533
|
+
PHASE5_DEFAULTS.det07ReadBypassMaxBytes,
|
|
534
|
+
maxLines:
|
|
535
|
+
options.det07ReadBypassMaxLines ??
|
|
536
|
+
guardsCfg.det07ReadBypassMaxLines ??
|
|
537
|
+
policy.readClamp?.maxLines ??
|
|
538
|
+
PHASE5_DEFAULTS.det07ReadBypassMaxLines,
|
|
539
|
+
neverClampExt: policy.readClamp?.neverClampExt ?? [],
|
|
540
|
+
neverClampCodeOffCliff: policy.readClamp?.neverClampCodeOffCliff ?? true
|
|
541
|
+
});
|
|
542
|
+
const det07Response = handlePhase5Verdict(det07, command, 'STDOUT_FLOOD_GUARDED');
|
|
543
|
+
if (det07Response) return det07Response;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// 5d. DET-08: Edit-Time Test-Weakening & Empty-Catch Guard (runs before DET-20 lock)
|
|
547
|
+
if (guardsCfg.det08Enabled !== false && EDIT_WRITE_SCOPE_LOCK_REGEX.test(toolName) && rawPath) {
|
|
548
|
+
const det08 = evaluateDet08EditIntegrityGuard({
|
|
549
|
+
toolName,
|
|
550
|
+
filePath: rawPath,
|
|
551
|
+
toolInput: tIn,
|
|
552
|
+
cwd: baseCwd,
|
|
553
|
+
mode: guardMode,
|
|
554
|
+
flightMode,
|
|
555
|
+
action: options.det08Action ?? guardsCfg.det08Action ?? PHASE5_DEFAULTS.det08Action,
|
|
556
|
+
checkTestSkip:
|
|
557
|
+
options.det08CheckTestSkip ?? guardsCfg.det08CheckTestSkip ?? PHASE5_DEFAULTS.det08CheckTestSkip,
|
|
558
|
+
checkEmptyCatch:
|
|
559
|
+
options.det08CheckEmptyCatch ?? guardsCfg.det08CheckEmptyCatch ?? PHASE5_DEFAULTS.det08CheckEmptyCatch
|
|
560
|
+
});
|
|
561
|
+
const det08Response = handlePhase5Verdict(det08, rawPath, 'EDIT_INTEGRITY_GUARDED');
|
|
562
|
+
if (det08Response) return det08Response;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// 5e. DET-09: Same-File Rapid Edit-Thrash Breaker (runs before DET-20 lock)
|
|
566
|
+
if (guardsCfg.det09Enabled !== false && EDIT_WRITE_SCOPE_LOCK_REGEX.test(toolName) && rawPath) {
|
|
567
|
+
const det09 = evaluateDet09EditThrash({
|
|
568
|
+
toolName,
|
|
569
|
+
filePath: rawPath,
|
|
570
|
+
cwd: baseCwd,
|
|
571
|
+
editThrashHistory:
|
|
572
|
+
event.editThrashHistory ??
|
|
573
|
+
options.editThrashHistory ??
|
|
574
|
+
priorSnap?.editThrashHistory ??
|
|
575
|
+
{},
|
|
576
|
+
maxEditsPerFile:
|
|
577
|
+
options.det09MaxEditsPerFile ??
|
|
578
|
+
guardsCfg.det09MaxEditsPerFile ??
|
|
579
|
+
PHASE5_DEFAULTS.det09MaxEditsPerFile,
|
|
580
|
+
windowSec:
|
|
581
|
+
options.det09WindowSec ??
|
|
582
|
+
guardsCfg.det09WindowSec ??
|
|
583
|
+
PHASE5_DEFAULTS.det09WindowSec,
|
|
584
|
+
mode: guardMode,
|
|
585
|
+
flightMode,
|
|
586
|
+
action: options.det09Action ?? guardsCfg.det09Action ?? PHASE5_DEFAULTS.det09Action,
|
|
587
|
+
nowMs: options.nowMs ?? Date.now()
|
|
588
|
+
});
|
|
589
|
+
const det09Response = handlePhase5Verdict(det09, rawPath, 'EDIT_THRASH_GUARDED');
|
|
590
|
+
if (det09Response) return det09Response;
|
|
591
|
+
}
|
|
592
|
+
|
|
461
593
|
// 6. Bounded Read Guard & Per-File Read-Interval Cache (`updatedInput`)
|
|
462
594
|
const isSubagent = Boolean(
|
|
463
595
|
canonical.isSidechain ||
|
package/src/guards/snooze.mjs
CHANGED
|
@@ -17,6 +17,9 @@ export const ALLOWED_SNOOZE_DETECTORS = Object.freeze([
|
|
|
17
17
|
'DET-02',
|
|
18
18
|
'DET-03',
|
|
19
19
|
'DET-04',
|
|
20
|
+
'DET-07',
|
|
21
|
+
'DET-08',
|
|
22
|
+
'DET-09',
|
|
20
23
|
'*'
|
|
21
24
|
]);
|
|
22
25
|
|
|
@@ -34,14 +37,14 @@ function readJsonSafe(filePath, fallback = null) {
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
/**
|
|
37
|
-
* Normalizes a detector identifier for ask snooze grants (`DET-01`..`DET-04` or `*`).
|
|
40
|
+
* Normalizes a detector identifier for ask snooze grants (`DET-01`..`DET-04`, `DET-07`..`DET-09`, or `*`).
|
|
38
41
|
* Returns `null` for unsupported or invalid IDs (such as `DET-20` or empty non-default input).
|
|
39
42
|
*/
|
|
40
43
|
export function normalizeSnoozeDetectorId(raw = '*') {
|
|
41
44
|
if (raw === undefined || raw === null || raw === '') return '*';
|
|
42
45
|
const s = String(raw).trim().toUpperCase();
|
|
43
46
|
if (!s || s === '*' || s === 'ALL') return '*';
|
|
44
|
-
if (/^DET-0[1-
|
|
47
|
+
if (/^DET-0[1-47-9]$/.test(s)) return s;
|
|
45
48
|
return null;
|
|
46
49
|
}
|
|
47
50
|
|
|
@@ -157,13 +157,30 @@ export function parseAntigravityTranscript(filePathOrContent = '', options = {})
|
|
|
157
157
|
if (tc.name) toolsUsedSet.add(tc.name);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
const finishedAt = entry.finished_at || entry.finishedAt || entry.completedAt || null;
|
|
161
|
+
const rawDur = Number(entry.duration_ms ?? entry.durationMs);
|
|
162
|
+
let durationMs = Number.isFinite(rawDur) && rawDur > 0 ? Number(rawDur.toFixed(2)) : null;
|
|
163
|
+
const createdAt = entry.created_at || entry.createdAt || null;
|
|
164
|
+
if (durationMs === null && createdAt && finishedAt) {
|
|
165
|
+
const startMs = Date.parse(createdAt);
|
|
166
|
+
const endMs = Date.parse(finishedAt);
|
|
167
|
+
if (Number.isFinite(startMs) && Number.isFinite(endMs) && endMs > startMs) {
|
|
168
|
+
durationMs = Number((endMs - startMs).toFixed(2));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const rawTtft = Number(entry.ttft_ms ?? entry.ttftMs);
|
|
172
|
+
const ttftMs = Number.isFinite(rawTtft) && rawTtft > 0 ? Number(rawTtft.toFixed(2)) : null;
|
|
173
|
+
|
|
160
174
|
steps.push({
|
|
161
175
|
stepIndex: Number.isFinite(Number(entry.step_index)) ? Number(entry.step_index) : steps.length,
|
|
162
176
|
type: 'assistant',
|
|
163
177
|
rawType: entry.type,
|
|
164
178
|
client: 'antigravity',
|
|
165
179
|
entrypoint: 'antigravity',
|
|
166
|
-
createdAt
|
|
180
|
+
createdAt,
|
|
181
|
+
finishedAt,
|
|
182
|
+
durationMs,
|
|
183
|
+
ttftMs,
|
|
167
184
|
model,
|
|
168
185
|
freshInputTokens,
|
|
169
186
|
cacheReadTokens,
|
|
@@ -217,11 +217,15 @@ export function stitchClaudeCodeDag(jsonlLinesOrContent = []) {
|
|
|
217
217
|
prevMsg.content ?? prev.content,
|
|
218
218
|
nextMsg.content ?? node.content
|
|
219
219
|
);
|
|
220
|
+
const prevTs = prev.firstChunkAt || prev.timestamp || prev.created_at || prev.createdAt || null;
|
|
221
|
+
const nextTs = node.timestamp || node.created_at || node.createdAt || prev.lastChunkAt || prevTs;
|
|
220
222
|
consolidatedActiveChain[idx] = {
|
|
221
223
|
...prev,
|
|
222
224
|
...node,
|
|
223
225
|
uuid: node.uuid || prev.uuid,
|
|
224
226
|
parentUuid: prev.parentUuid,
|
|
227
|
+
firstChunkAt: prevTs,
|
|
228
|
+
lastChunkAt: nextTs,
|
|
225
229
|
content: msg ? prev.content : mergedContent,
|
|
226
230
|
tool_calls: [
|
|
227
231
|
...(Array.isArray(prev.tool_calls) ? prev.tool_calls : []),
|
|
@@ -500,7 +504,27 @@ export function parseClaudeCodeJsonl(rawContent = '') {
|
|
|
500
504
|
) || 0);
|
|
501
505
|
const model = msg?.model || node.model || null;
|
|
502
506
|
if (model) latestModel = model;
|
|
503
|
-
const createdAt = node.timestamp || node.created_at || node.createdAt || null;
|
|
507
|
+
const createdAt = node.firstChunkAt || node.timestamp || node.created_at || node.createdAt || null;
|
|
508
|
+
const finishedAt = node.finished_at || node.finishedAt || node.completedAt || node.lastChunkAt || null;
|
|
509
|
+
const firstTokenAt = node.first_token_at || node.firstTokenAt || null;
|
|
510
|
+
const rawDur = Number(node.durationMs ?? node.duration_ms ?? node.latencyMs);
|
|
511
|
+
let durationMs = Number.isFinite(rawDur) && rawDur > 0 ? Number(rawDur.toFixed(2)) : null;
|
|
512
|
+
if (durationMs === null && createdAt && finishedAt) {
|
|
513
|
+
const startMs = Date.parse(createdAt);
|
|
514
|
+
const endMs = Date.parse(finishedAt);
|
|
515
|
+
if (Number.isFinite(startMs) && Number.isFinite(endMs) && endMs > startMs) {
|
|
516
|
+
durationMs = Number((endMs - startMs).toFixed(2));
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const rawTtft = Number(node.ttftMs ?? node.ttft_ms ?? node.firstTokenLatencyMs);
|
|
520
|
+
let ttftMs = Number.isFinite(rawTtft) && rawTtft > 0 ? Number(rawTtft.toFixed(2)) : null;
|
|
521
|
+
if (ttftMs === null && createdAt && firstTokenAt) {
|
|
522
|
+
const startMs = Date.parse(createdAt);
|
|
523
|
+
const firstMs = Date.parse(firstTokenAt);
|
|
524
|
+
if (Number.isFinite(startMs) && Number.isFinite(firstMs) && firstMs >= startMs) {
|
|
525
|
+
ttftMs = Number((firstMs - startMs).toFixed(2));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
504
528
|
const hasUsage = inputTokens > 0 || cacheReadTokens > 0 || cacheCreationTokens > 0 || outputTokens > 0;
|
|
505
529
|
const hadCompactionBefore = hasUsage ? pendingCompaction : false;
|
|
506
530
|
if (hasUsage) {
|
|
@@ -544,6 +568,10 @@ export function parseClaudeCodeJsonl(rawContent = '') {
|
|
|
544
568
|
systemSubtype,
|
|
545
569
|
status: 'DONE',
|
|
546
570
|
createdAt,
|
|
571
|
+
finishedAt,
|
|
572
|
+
firstTokenAt,
|
|
573
|
+
durationMs,
|
|
574
|
+
ttftMs,
|
|
547
575
|
model: model || latestModel || null,
|
|
548
576
|
toolCalls,
|
|
549
577
|
content,
|