burnoff 1.1.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 +3 -3
- package/README.md +66 -78
- package/bin/burnoff.mjs +67 -23
- package/hooks/hook-io.mjs +19 -7
- 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 +7 -5
- package/src/ci/ci-gate.mjs +22 -0
- package/src/ci/pr-cost.mjs +42 -10
- package/src/ci/team-digest.mjs +5 -3
- package/src/cli/audit.mjs +103 -18
- package/src/cli/doctor.mjs +209 -14
- package/src/cli/init.mjs +349 -96
- package/src/cli/startup-audit.mjs +500 -24
- 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/loader.mjs +11 -4
- package/src/config/paths.mjs +62 -2
- package/src/config/policy.mjs +34 -5
- package/src/config/pricing.mjs +16 -5
- package/src/guards/loop-breaker.mjs +198 -13
- package/src/guards/post-tool-engine.mjs +289 -29
- package/src/guards/pre-tool-engine.mjs +336 -129
- package/src/guards/read-clamp.mjs +78 -18
- package/src/guards/session-hook.mjs +207 -0
- package/src/guards/shell-guard.mjs +583 -73
- 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/file-lock.mjs +13 -4
- package/src/storage/fts5-archive.mjs +4 -4
- package/src/storage/jsonl-parser.mjs +7 -1
- package/src/storage/ledger.mjs +10 -3
- package/src/storage/sqlite-client.mjs +4 -2
- package/hooks/hooks.json +0 -12
package/src/ipc/daemon.mjs
CHANGED
|
@@ -17,11 +17,13 @@ import {
|
|
|
17
17
|
} from './protocol.mjs';
|
|
18
18
|
import { runPreToolUseHook } from '../guards/pre-tool-engine.mjs';
|
|
19
19
|
import { runPostToolUseHook } from '../guards/post-tool-engine.mjs';
|
|
20
|
+
import { resolveFastDaemonMarkerPath } from './fast-client.mjs';
|
|
20
21
|
|
|
21
22
|
export class BurnoffDaemon {
|
|
22
23
|
constructor(options = {}) {
|
|
23
24
|
this.options = options;
|
|
24
25
|
this.ipcPath = resolveIpcPath(options);
|
|
26
|
+
this.markerPath = null;
|
|
25
27
|
this.server = null;
|
|
26
28
|
this.methods = new Map();
|
|
27
29
|
this.activeSockets = new Set();
|
|
@@ -74,33 +76,46 @@ export class BurnoffDaemon {
|
|
|
74
76
|
return { stopping: true, pid: process.pid };
|
|
75
77
|
});
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
const handlePreToolUse = async (params = {}) => {
|
|
78
80
|
const event = params.event || params.input || params || {};
|
|
79
|
-
const sessionId = String(event.session_id || event.sessionId || 'default');
|
|
81
|
+
const sessionId = String(event.conversationId || event.session_id || event.sessionId || 'default');
|
|
80
82
|
const baseOpts = this.options.cwd && !event.cwd
|
|
81
83
|
? { persistState: true, cwd: this.options.cwd }
|
|
82
84
|
: { persistState: true };
|
|
83
|
-
const hookOpts = {
|
|
85
|
+
const hookOpts = {
|
|
86
|
+
...baseOpts,
|
|
87
|
+
...(params.client ? { client: params.client } : {}),
|
|
88
|
+
...(params.options || {})
|
|
89
|
+
};
|
|
84
90
|
|
|
85
91
|
return this.enqueueSessionTask(sessionId, async () => {
|
|
86
92
|
const res = runPreToolUseHook(event, hookOpts);
|
|
87
93
|
return { fullVerdict: true, ...res };
|
|
88
94
|
});
|
|
89
|
-
}
|
|
95
|
+
};
|
|
90
96
|
|
|
91
|
-
|
|
97
|
+
const handlePostToolUse = async (params = {}) => {
|
|
92
98
|
const event = params.event || params.input || params || {};
|
|
93
|
-
const sessionId = String(event.session_id || event.sessionId || 'default');
|
|
99
|
+
const sessionId = String(event.conversationId || event.session_id || event.sessionId || 'default');
|
|
94
100
|
const baseOpts = this.options.cwd && !event.cwd
|
|
95
101
|
? { persistState: true, cwd: this.options.cwd }
|
|
96
102
|
: { persistState: true };
|
|
97
|
-
const hookOpts = {
|
|
103
|
+
const hookOpts = {
|
|
104
|
+
...baseOpts,
|
|
105
|
+
...(params.client ? { client: params.client } : {}),
|
|
106
|
+
...(params.options || {})
|
|
107
|
+
};
|
|
98
108
|
|
|
99
109
|
return this.enqueueSessionTask(sessionId, async () => {
|
|
100
110
|
const res = runPostToolUseHook(event, hookOpts);
|
|
101
111
|
return { fullVerdict: true, ...res };
|
|
102
112
|
});
|
|
103
|
-
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
this.registerMethod('hook.preToolUse', handlePreToolUse);
|
|
116
|
+
this.registerMethod('hook.postToolUse', handlePostToolUse);
|
|
117
|
+
this.registerMethod('hook.claude.preToolUse', handlePreToolUse);
|
|
118
|
+
this.registerMethod('hook.claude.postToolUse', handlePostToolUse);
|
|
104
119
|
}
|
|
105
120
|
|
|
106
121
|
registerMethod(name, handler) {
|
|
@@ -216,6 +231,23 @@ export class BurnoffDaemon {
|
|
|
216
231
|
this.server.once('error', (err) => reject(err));
|
|
217
232
|
this.server.listen(this.ipcPath, () => {
|
|
218
233
|
this.startedAt = Date.now();
|
|
234
|
+
if (process.platform === 'win32' && !this.options.ipcPath && !process.env.BURNOFF_IPC_PATH) {
|
|
235
|
+
try {
|
|
236
|
+
const markerPath = resolveFastDaemonMarkerPath({
|
|
237
|
+
cwd: this.options.cwd,
|
|
238
|
+
homeDir: this.options.homeDir
|
|
239
|
+
});
|
|
240
|
+
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
|
241
|
+
fs.writeFileSync(
|
|
242
|
+
markerPath,
|
|
243
|
+
JSON.stringify({ pid: process.pid, ipcPath: this.ipcPath, startedAt: this.startedAt }),
|
|
244
|
+
'utf8'
|
|
245
|
+
);
|
|
246
|
+
this.markerPath = markerPath;
|
|
247
|
+
} catch (err) {
|
|
248
|
+
void err; // ignore: non-fatal Windows daemon marker write
|
|
249
|
+
}
|
|
250
|
+
}
|
|
219
251
|
if (process.platform !== 'win32') {
|
|
220
252
|
try {
|
|
221
253
|
fs.chmodSync(this.ipcPath, 0o600);
|
|
@@ -246,6 +278,16 @@ export class BurnoffDaemon {
|
|
|
246
278
|
const srv = this.server;
|
|
247
279
|
this.server = null;
|
|
248
280
|
srv.close(() => {
|
|
281
|
+
if (this.markerPath) {
|
|
282
|
+
try {
|
|
283
|
+
if (fs.existsSync(this.markerPath)) {
|
|
284
|
+
fs.unlinkSync(this.markerPath);
|
|
285
|
+
}
|
|
286
|
+
} catch (err) {
|
|
287
|
+
void err; // ignore: best-effort Windows daemon marker unlink on shutdown
|
|
288
|
+
}
|
|
289
|
+
this.markerPath = null;
|
|
290
|
+
}
|
|
249
291
|
if (process.platform !== 'win32') {
|
|
250
292
|
try {
|
|
251
293
|
if (fs.existsSync(this.ipcPath)) {
|
package/src/ipc/fast-client.mjs
CHANGED
|
@@ -63,19 +63,75 @@ export function resolveFastIpcPipePath(options = {}) {
|
|
|
63
63
|
return `\\\\.\\pipe\\burnoff-${cleanUser}-${wsHash}`;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const burnoffHome =
|
|
67
|
-
? path.resolve(
|
|
68
|
-
:
|
|
66
|
+
const burnoffHome = options.homeDir
|
|
67
|
+
? path.join(path.resolve(options.homeDir), '.burnoff')
|
|
68
|
+
: process.env.BURNOFF_HOME
|
|
69
|
+
? path.resolve(process.env.BURNOFF_HOME)
|
|
70
|
+
: path.join(process.env.HOME || os.homedir() || '/tmp', '.burnoff');
|
|
69
71
|
return path.join(burnoffHome, 'run', `daemon-${wsHash}.sock`);
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
function isPidAliveFast(pid) {
|
|
75
|
+
const num = Number(pid);
|
|
76
|
+
if (!Number.isInteger(num) || num <= 0) return false;
|
|
77
|
+
try {
|
|
78
|
+
process.kill(num, 0);
|
|
79
|
+
return true;
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (err?.code === 'EPERM') return true;
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Resolves the workspace-scoped Windows daemon readiness marker (`<BURNOFF_HOME>/run/daemon-<wsHash>.pid`)
|
|
88
|
+
* so cold hook invocations can verify daemon absence synchronously in <1ms without named-pipe connect timeouts.
|
|
89
|
+
*/
|
|
90
|
+
export function resolveFastDaemonMarkerPath(options = {}) {
|
|
91
|
+
const wsTarget = path.resolve(options.cwd || process.cwd());
|
|
92
|
+
const wsHash = crypto.createHash('sha1').update(wsTarget.toLowerCase()).digest('hex').slice(0, 10);
|
|
93
|
+
const burnoffHome = options.homeDir
|
|
94
|
+
? path.join(path.resolve(options.homeDir), '.burnoff')
|
|
95
|
+
: process.env.BURNOFF_HOME
|
|
96
|
+
? path.resolve(process.env.BURNOFF_HOME)
|
|
97
|
+
: path.join(process.env.USERPROFILE || process.env.HOME || os.homedir() || '/tmp', '.burnoff');
|
|
98
|
+
return path.join(burnoffHome, 'run', `daemon-${wsHash}.pid`);
|
|
99
|
+
}
|
|
100
|
+
|
|
72
101
|
function sendRawDaemonRpc(method, params = {}, options = {}) {
|
|
73
102
|
if (!options.ipcPath && !process.env.BURNOFF_IPC_PATH && !isRealHostHomeEnv()) {
|
|
74
103
|
return Promise.resolve(null);
|
|
75
104
|
}
|
|
76
105
|
const derivedCwd = options.cwd || params?.event?.cwd || params?.input?.cwd || params?.cwd;
|
|
77
|
-
const
|
|
78
|
-
|
|
106
|
+
const effectiveOptions = derivedCwd ? { ...options, cwd: derivedCwd } : options;
|
|
107
|
+
const pipePath = resolveFastIpcPipePath(effectiveOptions);
|
|
108
|
+
if (!pipePath) {
|
|
109
|
+
return Promise.resolve(null);
|
|
110
|
+
}
|
|
111
|
+
if (process.platform === 'win32') {
|
|
112
|
+
if (!options.ipcPath && !process.env.BURNOFF_IPC_PATH) {
|
|
113
|
+
const markerPath = resolveFastDaemonMarkerPath(effectiveOptions);
|
|
114
|
+
if (!markerPath || !fs.existsSync(markerPath)) {
|
|
115
|
+
return Promise.resolve(null);
|
|
116
|
+
}
|
|
117
|
+
let alive = false;
|
|
118
|
+
try {
|
|
119
|
+
const parsed = JSON.parse(fs.readFileSync(markerPath, 'utf8'));
|
|
120
|
+
alive = isPidAliveFast(parsed?.pid);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
void err; // ignore: unreadable daemon marker treated as stale
|
|
123
|
+
alive = false;
|
|
124
|
+
}
|
|
125
|
+
if (!alive) {
|
|
126
|
+
try {
|
|
127
|
+
fs.unlinkSync(markerPath);
|
|
128
|
+
} catch (unlinkErr) {
|
|
129
|
+
void unlinkErr; // ignore: best-effort stale daemon marker cleanup
|
|
130
|
+
}
|
|
131
|
+
return Promise.resolve(null);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
} else if (!fs.existsSync(pipePath)) {
|
|
79
135
|
return Promise.resolve(null);
|
|
80
136
|
}
|
|
81
137
|
|
|
@@ -193,6 +249,7 @@ export async function tryFastDaemonRpc(method, params = {}, options = {}) {
|
|
|
193
249
|
export default {
|
|
194
250
|
isRealHostHomeEnv,
|
|
195
251
|
resolveFastIpcPipePath,
|
|
252
|
+
resolveFastDaemonMarkerPath,
|
|
196
253
|
sendDaemonRpc,
|
|
197
254
|
tryFastDaemonRpc
|
|
198
255
|
};
|
package/src/ipc/protocol.mjs
CHANGED
|
@@ -53,7 +53,7 @@ export function resolveIpcPath(options = {}) {
|
|
|
53
53
|
return `\\\\.\\pipe\\burnoff-${cleanUser}-${wsHash}`;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const runDir = getBurnoffRunDir(options.homeDir ||
|
|
56
|
+
const runDir = getBurnoffRunDir(options.homeDir || null);
|
|
57
57
|
return path.join(runDir, `daemon-${wsHash}.sock`);
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/storage/antigravity-parser.mjs
|
|
3
|
+
* Parser and discovery helpers for Google Antigravity `transcript.jsonl` logs.
|
|
4
|
+
* Emits the same `steps[]` contract consumed by `audit.mjs`, `pr-cost.mjs`, and `team-digest.mjs`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { getHomeDir, resolveAntigravityConfigPaths } from '../config/paths.mjs';
|
|
10
|
+
|
|
11
|
+
function unwrapQuotedArgString(val) {
|
|
12
|
+
if (typeof val !== 'string') return val;
|
|
13
|
+
const trimmed = val.trim();
|
|
14
|
+
if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
15
|
+
try {
|
|
16
|
+
const unquoted = JSON.parse(trimmed);
|
|
17
|
+
if (typeof unquoted === 'string') return unquoted;
|
|
18
|
+
} catch {
|
|
19
|
+
// ignore: keep original string if not valid JSON-escaped string
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return val;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function normalizeToolCallArgs(args) {
|
|
26
|
+
if (!args || typeof args !== 'object' || Array.isArray(args)) return {};
|
|
27
|
+
const out = {};
|
|
28
|
+
for (const [k, v] of Object.entries(args)) {
|
|
29
|
+
out[k] = unwrapQuotedArgString(v);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function normalizeToolCalls(rawCalls = []) {
|
|
35
|
+
if (!Array.isArray(rawCalls)) return [];
|
|
36
|
+
return rawCalls
|
|
37
|
+
.filter((c) => c && typeof c === 'object')
|
|
38
|
+
.map((c) => ({
|
|
39
|
+
name: String(c.name || ''),
|
|
40
|
+
args: normalizeToolCallArgs(c.args || c.arguments || {})
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function extractSessionTitleFromUserInput(rawContent = '') {
|
|
45
|
+
const cleaned = String(rawContent || '')
|
|
46
|
+
.replace(/<\/?USER_REQUEST>/gi, '')
|
|
47
|
+
.replace(/\s+/g, ' ')
|
|
48
|
+
.trim();
|
|
49
|
+
return cleaned.slice(0, 80);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Returns true if the given JSONL string or parsed lines match Antigravity's transcript schema.
|
|
54
|
+
*/
|
|
55
|
+
export function isAntigravityTranscriptContent(jsonlLinesOrContent = '') {
|
|
56
|
+
const lines = Array.isArray(jsonlLinesOrContent)
|
|
57
|
+
? jsonlLinesOrContent
|
|
58
|
+
: String(jsonlLinesOrContent || '').split(/\r?\n/);
|
|
59
|
+
|
|
60
|
+
for (const raw of lines) {
|
|
61
|
+
if (!raw) continue;
|
|
62
|
+
let obj = raw;
|
|
63
|
+
if (typeof raw === 'string') {
|
|
64
|
+
const trimmed = raw.trim();
|
|
65
|
+
if (!trimmed) continue;
|
|
66
|
+
try {
|
|
67
|
+
obj = JSON.parse(trimmed);
|
|
68
|
+
} catch {
|
|
69
|
+
continue; // ignore: skip malformed line when probing transcript format
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!obj || typeof obj !== 'object') continue;
|
|
73
|
+
if (
|
|
74
|
+
typeof obj.step_index === 'number' &&
|
|
75
|
+
(obj.type === 'USER_INPUT' || obj.type === 'PLANNER_RESPONSE' || obj.type === 'GENERIC')
|
|
76
|
+
) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (obj.type === 'PLANNER_RESPONSE' && (obj.input_tokens !== undefined || obj.cache_read_tokens !== undefined)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Reads the head of a file to determine whether it is an Antigravity `transcript.jsonl`.
|
|
88
|
+
*/
|
|
89
|
+
export function isAntigravityTranscriptFile(filePath) {
|
|
90
|
+
if (!filePath || !fs.existsSync(filePath)) return false;
|
|
91
|
+
let fd = null;
|
|
92
|
+
try {
|
|
93
|
+
const stat = fs.statSync(filePath);
|
|
94
|
+
if (!stat.isFile() || stat.size === 0) return false;
|
|
95
|
+
const probeLen = Math.min(stat.size, 8192);
|
|
96
|
+
const buf = Buffer.alloc(probeLen);
|
|
97
|
+
fd = fs.openSync(filePath, 'r');
|
|
98
|
+
const bytesRead = fs.readSync(fd, buf, 0, probeLen, 0);
|
|
99
|
+
return isAntigravityTranscriptContent(buf.subarray(0, bytesRead).toString('utf8'));
|
|
100
|
+
} catch {
|
|
101
|
+
return false; // ignore: unreadable file falls back to false
|
|
102
|
+
} finally {
|
|
103
|
+
if (fd !== null) {
|
|
104
|
+
try { fs.closeSync(fd); } catch { /* ignore: fd close guard */ }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Parses an Antigravity `transcript.jsonl` string or file path into Burnoff's normalized `steps[]` contract.
|
|
111
|
+
*/
|
|
112
|
+
export function parseAntigravityTranscript(filePathOrContent = '', options = {}) {
|
|
113
|
+
let rawContent = '';
|
|
114
|
+
let resolvedPath = null;
|
|
115
|
+
if (
|
|
116
|
+
typeof filePathOrContent === 'string' &&
|
|
117
|
+
!filePathOrContent.includes('\n') &&
|
|
118
|
+
fs.existsSync(filePathOrContent)
|
|
119
|
+
) {
|
|
120
|
+
resolvedPath = path.resolve(filePathOrContent);
|
|
121
|
+
rawContent = fs.readFileSync(resolvedPath, 'utf8');
|
|
122
|
+
} else {
|
|
123
|
+
rawContent = String(filePathOrContent || '');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const lines = rawContent.split(/\r?\n/).filter((l) => l.trim().length > 0);
|
|
127
|
+
const steps = [];
|
|
128
|
+
let sessionTitle = '';
|
|
129
|
+
let lastModel = null;
|
|
130
|
+
const toolsUsedSet = new Set();
|
|
131
|
+
|
|
132
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
133
|
+
let entry = null;
|
|
134
|
+
try {
|
|
135
|
+
entry = JSON.parse(lines[i]);
|
|
136
|
+
} catch {
|
|
137
|
+
continue; // ignore: skip malformed JSONL line
|
|
138
|
+
}
|
|
139
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
140
|
+
|
|
141
|
+
if (entry.type === 'USER_INPUT' && !sessionTitle && entry.content) {
|
|
142
|
+
sessionTitle = extractSessionTitleFromUserInput(entry.content);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (entry.type !== 'PLANNER_RESPONSE') continue;
|
|
146
|
+
|
|
147
|
+
const freshInputTokens = Math.max(0, Number(entry.input_tokens ?? entry.inputTokens ?? 0));
|
|
148
|
+
const cacheReadTokens = Math.max(0, Number(entry.cache_read_tokens ?? entry.cacheReadTokens ?? 0));
|
|
149
|
+
const outputTokens = Math.max(0, Number(entry.output_tokens ?? entry.outputTokens ?? 0));
|
|
150
|
+
const thinkingTokens = Math.max(0, Number(entry.thinking_tokens ?? entry.thinkingTokens ?? 0));
|
|
151
|
+
const totalPromptTokens = freshInputTokens + cacheReadTokens;
|
|
152
|
+
const model = entry.model ? String(entry.model) : lastModel;
|
|
153
|
+
if (model) lastModel = model;
|
|
154
|
+
|
|
155
|
+
const toolCalls = normalizeToolCalls(entry.tool_calls || entry.toolCalls || []);
|
|
156
|
+
for (const tc of toolCalls) {
|
|
157
|
+
if (tc.name) toolsUsedSet.add(tc.name);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
steps.push({
|
|
161
|
+
stepIndex: Number.isFinite(Number(entry.step_index)) ? Number(entry.step_index) : steps.length,
|
|
162
|
+
type: 'assistant',
|
|
163
|
+
rawType: entry.type,
|
|
164
|
+
client: 'antigravity',
|
|
165
|
+
entrypoint: 'antigravity',
|
|
166
|
+
createdAt: entry.created_at || entry.createdAt || null,
|
|
167
|
+
model,
|
|
168
|
+
freshInputTokens,
|
|
169
|
+
cacheReadTokens,
|
|
170
|
+
cacheCreationTokens: 0,
|
|
171
|
+
outputTokens,
|
|
172
|
+
thinkingTokens,
|
|
173
|
+
totalPromptTokens,
|
|
174
|
+
tokenUsage: {
|
|
175
|
+
freshInputTokens,
|
|
176
|
+
inputTokens: freshInputTokens,
|
|
177
|
+
cacheReadTokens,
|
|
178
|
+
cacheCreationTokens: 0,
|
|
179
|
+
outputTokens,
|
|
180
|
+
thinkingTokens
|
|
181
|
+
},
|
|
182
|
+
toolCalls
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
schemaRev: 1,
|
|
188
|
+
client: 'antigravity',
|
|
189
|
+
filePath: resolvedPath,
|
|
190
|
+
sessionId: options.sessionId || (resolvedPath ? path.basename(path.dirname(path.dirname(path.dirname(resolvedPath)))) : 'antigravity-session'),
|
|
191
|
+
sessionTitle,
|
|
192
|
+
entrypoint: 'antigravity',
|
|
193
|
+
toolsUsed: Array.from(toolsUsedSet),
|
|
194
|
+
steps
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Discovers local Google Antigravity `transcript.jsonl` files across CLI, 2.0 App, and IDE brain directories.
|
|
200
|
+
*/
|
|
201
|
+
export function discoverAntigravityTranscripts(homeDirOrOptions = getHomeDir(), extraOptions = {}) {
|
|
202
|
+
const opts =
|
|
203
|
+
homeDirOrOptions && typeof homeDirOrOptions === 'object'
|
|
204
|
+
? homeDirOrOptions
|
|
205
|
+
: { homeDir: homeDirOrOptions, ...extraOptions };
|
|
206
|
+
const homeDir = opts.homeDir || getHomeDir();
|
|
207
|
+
const cwd = opts.cwd || process.cwd();
|
|
208
|
+
const brainDirs = Array.isArray(opts.brainDirs)
|
|
209
|
+
? opts.brainDirs
|
|
210
|
+
: resolveAntigravityConfigPaths({ homeDir, cwd }).brainDirs;
|
|
211
|
+
|
|
212
|
+
const discovered = [];
|
|
213
|
+
const seenFiles = new Set();
|
|
214
|
+
|
|
215
|
+
for (const brainDir of brainDirs) {
|
|
216
|
+
if (!brainDir || !fs.existsSync(brainDir)) continue;
|
|
217
|
+
let convDirs = [];
|
|
218
|
+
try {
|
|
219
|
+
convDirs = fs.readdirSync(brainDir, { withFileTypes: true }).filter((e) => e.isDirectory());
|
|
220
|
+
} catch {
|
|
221
|
+
continue; // ignore: unreadable brain directory
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
for (const convDir of convDirs) {
|
|
225
|
+
const candidates = [
|
|
226
|
+
path.join(brainDir, convDir.name, '.system_generated', 'logs', 'transcript.jsonl'),
|
|
227
|
+
path.join(brainDir, convDir.name, 'transcript.jsonl')
|
|
228
|
+
];
|
|
229
|
+
for (const filePath of candidates) {
|
|
230
|
+
if (!fs.existsSync(filePath) || seenFiles.has(filePath)) continue;
|
|
231
|
+
seenFiles.add(filePath);
|
|
232
|
+
try {
|
|
233
|
+
const st = fs.statSync(filePath);
|
|
234
|
+
if (!st.isFile() || st.size === 0) continue;
|
|
235
|
+
discovered.push({
|
|
236
|
+
filePath,
|
|
237
|
+
sessionId: convDir.name,
|
|
238
|
+
projectSlug: 'antigravity',
|
|
239
|
+
client: 'antigravity',
|
|
240
|
+
mtimeMs: st.mtimeMs
|
|
241
|
+
});
|
|
242
|
+
} catch {
|
|
243
|
+
// ignore: unreadable transcript metadata
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
discovered.sort((a, b) => (b.mtimeMs || 0) - (a.mtimeMs || 0));
|
|
250
|
+
return discovered;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export default {
|
|
254
|
+
isAntigravityTranscriptContent,
|
|
255
|
+
isAntigravityTranscriptFile,
|
|
256
|
+
parseAntigravityTranscript,
|
|
257
|
+
discoverAntigravityTranscripts
|
|
258
|
+
};
|
|
@@ -20,6 +20,7 @@ export const LOCK_ORDER_DOC = Object.freeze([
|
|
|
20
20
|
|
|
21
21
|
const DEFAULT_MAX_WAIT_MS = 2500;
|
|
22
22
|
const DEFAULT_STALE_MS = 5000;
|
|
23
|
+
const MIN_STALE_MS = 5000;
|
|
23
24
|
|
|
24
25
|
function isPidAlive(pid) {
|
|
25
26
|
const num = Number(pid);
|
|
@@ -90,8 +91,12 @@ export function withFileLockSync(targetPath, fn, options = {}) {
|
|
|
90
91
|
|
|
91
92
|
const fsMod = options.fsModule || fs;
|
|
92
93
|
const maxWaitMs = Math.max(50, Number(options.maxWaitMs ?? DEFAULT_MAX_WAIT_MS));
|
|
93
|
-
const
|
|
94
|
-
const
|
|
94
|
+
const rawStaleMs = Number(options.staleMs ?? options.staleLockAgeMs ?? DEFAULT_STALE_MS);
|
|
95
|
+
const staleMs = Math.max(MIN_STALE_MS, Number.isFinite(rawStaleMs) ? rawStaleMs : DEFAULT_STALE_MS);
|
|
96
|
+
const onTimeout =
|
|
97
|
+
options.onTimeout === 'throw' || options.onTimeout === 'fail-open'
|
|
98
|
+
? options.onTimeout
|
|
99
|
+
: 'skip';
|
|
95
100
|
|
|
96
101
|
const resolvedTarget = path.resolve(targetPath);
|
|
97
102
|
const lockPath = `${resolvedTarget}.lock`;
|
|
@@ -127,7 +132,8 @@ export function withFileLockSync(targetPath, fn, options = {}) {
|
|
|
127
132
|
(err?.code === 'EPERM' || err?.code === 'EBUSY' || err?.code === 'EACCES'));
|
|
128
133
|
if (!isContentionErr) {
|
|
129
134
|
if (onTimeout === 'throw') throw err;
|
|
130
|
-
return fn();
|
|
135
|
+
if (onTimeout === 'fail-open') return fn();
|
|
136
|
+
return options.fallbackValue !== undefined ? options.fallbackValue : null;
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
const info = inspectLockFile(lockPath, staleMs, fsMod);
|
|
@@ -150,7 +156,10 @@ export function withFileLockSync(targetPath, fn, options = {}) {
|
|
|
150
156
|
if (onTimeout === 'throw') {
|
|
151
157
|
throw new Error(`Timed out waiting for file lock: ${lockPath} (${maxWaitMs}ms)`);
|
|
152
158
|
}
|
|
153
|
-
|
|
159
|
+
if (onTimeout === 'fail-open') {
|
|
160
|
+
return fn();
|
|
161
|
+
}
|
|
162
|
+
return options.fallbackValue !== undefined ? options.fallbackValue : null;
|
|
154
163
|
}
|
|
155
164
|
|
|
156
165
|
try {
|
|
@@ -20,7 +20,7 @@ export const FTS5_COMPRESSOR_CONSTANTS = Object.freeze({
|
|
|
20
20
|
/(?:(?:^|[\s;|&])@['"]|\b(?:pytest|jest|vitest|cargo\s+(?:test|clippy|check|build)|tsc|go\s+test|eslint|biome|ruff|next\s+build|vite\s+build|(?:mvn|mvnw(?:\.cmd)?|gradle|gradlew(?:\.bat)?|kotlinc)\b|dotnet\s+(?:test|build)\b|make\b|ctest\b|bazel\s+(?:test|build)\b|(?:(?:npx|pnpm(?:\s+exec)?)\s+)?playwright\s+test\b|(?:bundle\s+exec\s+)?rspec\b|phpunit\b|deno\s+test\b|docker\s+(?:build|logs)|kubectl\s+(?:logs|get|describe)|gh\s+(?:pr|run|api|issue|release|workflow)|git\s+(?:diff|log|show|status|grep|ls-files|blame|branch|tag|stash|reflog|cherry-pick)|(?:npm|pnpm|yarn|bun)\s+(?:test|run\s+(?:test|lint|build|typecheck)|install|ci|add|update|audit|outdated|pack|publish)|(?:pip3?|uv|poetry)\s+(?:install|sync|audit|list|show)|node(?:\.exe)?|python3?(?:\.exe)?|select-string|get-childitem|gci|get-content|write-output|powershell|pwsh|rg|ripgrep|grep|find|fd|tree|curl|wget|aws|gcloud|terraform)\b)/i
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
export function getDefaultToolLogsDbPath(homeDir =
|
|
23
|
+
export function getDefaultToolLogsDbPath(homeDir = null) {
|
|
24
24
|
return path.join(getBurnoffCacheDir(homeDir), 'tool_logs_fts5.db');
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -598,7 +598,7 @@ export async function searchToolLogsFts5(dbPath, {
|
|
|
598
598
|
turnId = '',
|
|
599
599
|
keyword = '',
|
|
600
600
|
limit = 10,
|
|
601
|
-
homeDir =
|
|
601
|
+
homeDir = null,
|
|
602
602
|
DatabaseSync = null
|
|
603
603
|
} = {}) {
|
|
604
604
|
const resolvedDbPath = dbPath || getDefaultToolLogsDbPath(homeDir);
|
|
@@ -678,11 +678,11 @@ export async function searchToolLogsFts5(dbPath, {
|
|
|
678
678
|
}
|
|
679
679
|
|
|
680
680
|
export async function searchFts5Logs(options = {}) {
|
|
681
|
-
const { turnId = '', keyword = '', limit = 10, dbPath = null, homeDir =
|
|
681
|
+
const { turnId = '', keyword = '', limit = 10, dbPath = null, homeDir = null, DatabaseSync = null } = options;
|
|
682
682
|
return searchToolLogsFts5(dbPath, { turnId, keyword, limit, homeDir, DatabaseSync });
|
|
683
683
|
}
|
|
684
684
|
|
|
685
|
-
export function getFts5CompressionStats(dbPath = null, { DatabaseSync = null, homeDir =
|
|
685
|
+
export function getFts5CompressionStats(dbPath = null, { DatabaseSync = null, homeDir = null } = {}) {
|
|
686
686
|
const resolvedDbPath = dbPath || getDefaultToolLogsDbPath(homeDir);
|
|
687
687
|
if (!fs.existsSync(resolvedDbPath) && !fs.existsSync(resolveFallbackDbPath(resolvedDbPath))) {
|
|
688
688
|
return { active: true, logCount: 0, savedTokens: 0, formattedSavedK: '0.0k' };
|
|
@@ -488,6 +488,10 @@ export function parseClaudeCodeJsonl(rawContent = '') {
|
|
|
488
488
|
? flatCacheCreationTokens
|
|
489
489
|
: (cacheCreationEphemeral5mInputTokens + cacheCreationEphemeral1hInputTokens);
|
|
490
490
|
const totalPromptTokens = inputTokens + cacheReadTokens + cacheCreationTokens;
|
|
491
|
+
const hasExplicitThinkingTokens =
|
|
492
|
+
node.thinking_tokens != null ||
|
|
493
|
+
node.thinkingTokens != null ||
|
|
494
|
+
usage.thinking_tokens != null;
|
|
491
495
|
const thinkingTokens = Math.max(0, Number(
|
|
492
496
|
node.thinking_tokens ??
|
|
493
497
|
node.thinkingTokens ??
|
|
@@ -553,6 +557,8 @@ export function parseClaudeCodeJsonl(rawContent = '') {
|
|
|
553
557
|
totalPromptTokens,
|
|
554
558
|
totalPromptEnvelopeTokens: totalPromptTokens,
|
|
555
559
|
thinkingTokens,
|
|
560
|
+
thinkingTokensEstimated: !hasExplicitThinkingTokens && thinkingTokens > 0,
|
|
561
|
+
outputIncludesThinking: true,
|
|
556
562
|
untruncatedLength: content.length,
|
|
557
563
|
isTruncated: false,
|
|
558
564
|
isCompactSummary: Boolean(node.isCompactSummary),
|
|
@@ -706,7 +712,7 @@ export function parseTranscriptIncremental(transcriptPathOrDir, cacheDir = null,
|
|
|
706
712
|
};
|
|
707
713
|
}
|
|
708
714
|
|
|
709
|
-
const actualCacheDir = actualCacheDirArg || getBurnoffCacheDir(actualOpts.homeDir ||
|
|
715
|
+
const actualCacheDir = actualCacheDirArg || getBurnoffCacheDir(actualOpts.homeDir || null);
|
|
710
716
|
const stat = fs.statSync(filePath);
|
|
711
717
|
const currentPrefixSha256 = computeFilePrefixSha256(filePath, stat.size);
|
|
712
718
|
const pathHash = crypto.createHash('sha1').update(path.resolve(filePath)).digest('hex').slice(0, 10);
|
package/src/storage/ledger.mjs
CHANGED
|
@@ -129,8 +129,10 @@ export function getLedgerFilePath(options = {}) {
|
|
|
129
129
|
if (typeof options.ledgerPath === 'string' && options.ledgerPath.trim()) {
|
|
130
130
|
return options.ledgerPath.trim();
|
|
131
131
|
}
|
|
132
|
-
const
|
|
133
|
-
|
|
132
|
+
const explicitHomeDir = typeof options.homeDir === 'string' && options.homeDir.trim()
|
|
133
|
+
? options.homeDir.trim()
|
|
134
|
+
: null;
|
|
135
|
+
return path.join(getBurnoffLedgerDir(explicitHomeDir), 'burnoff_ledger.jsonl');
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
export function getLedgerMonthKey(tsMs = Date.now()) {
|
|
@@ -580,7 +582,12 @@ export function recordInterventionSavings(params = {}, options = {}) {
|
|
|
580
582
|
return { recorded: res.ok, deduplicated: false, receipt: res.entry };
|
|
581
583
|
};
|
|
582
584
|
|
|
583
|
-
return dedupeShortKey
|
|
585
|
+
return dedupeShortKey
|
|
586
|
+
? withFileLockSync(dedupeIndexPath, writeUnderLock, {
|
|
587
|
+
...options,
|
|
588
|
+
fallbackValue: { recorded: false, deduplicated: false, skippedByLockTimeout: true, receipt: null }
|
|
589
|
+
})
|
|
590
|
+
: writeUnderLock();
|
|
584
591
|
}
|
|
585
592
|
|
|
586
593
|
export function computeExPostRealizedSavings(params = {}) {
|
|
@@ -486,12 +486,14 @@ export class JsonlFallbackDatabaseSync {
|
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
|
|
489
|
-
|
|
489
|
+
const countMatch = normSql.match(/^SELECT\s+count\(\*\)(?:\s+as\s+([A-Za-z0-9_]+))?/i);
|
|
490
|
+
if (countMatch) {
|
|
491
|
+
const alias = countMatch[1] || 'count';
|
|
490
492
|
const totalBytes = filtered.reduce(
|
|
491
493
|
(sum, r) => sum + Buffer.byteLength(String(r.raw_output || r.rawOutput || ''), 'utf8'),
|
|
492
494
|
0
|
|
493
495
|
);
|
|
494
|
-
return [{ count: filtered.length, totalBytes }];
|
|
496
|
+
return [{ count: filtered.length, [alias]: filtered.length, totalBytes }];
|
|
495
497
|
}
|
|
496
498
|
|
|
497
499
|
if (/\bLIMIT\s+\?/i.test(normSql) && argIdx < args.length) {
|
package/hooks/hooks.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"hooks": {
|
|
3
|
-
"PreToolUse": [
|
|
4
|
-
{ "matcher": "Bash|PowerShell|Edit|MultiEdit|Write|NotebookEdit|Read|Grep|Glob|Task|Agent|WebFetch|mcp__.*",
|
|
5
|
-
"hooks": [{ "type": "command", "command": "node \"hooks/pre-tool-use.mjs\"", "timeout": 5 }] }
|
|
6
|
-
],
|
|
7
|
-
"PostToolUse": [
|
|
8
|
-
{ "matcher": "Bash|PowerShell|Grep|Glob|Task|Agent|WebFetch|mcp__.*",
|
|
9
|
-
"hooks": [{ "type": "command", "command": "node \"hooks/post-tool-use.mjs\"", "timeout": 5 }] }
|
|
10
|
-
]
|
|
11
|
-
}
|
|
12
|
-
}
|