burnoff 1.3.0 → 1.4.1
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 +213 -195
- 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/hooks/hook-io.mjs +691 -599
- package/package.json +1 -1
- package/scripts/bench-hooks.mjs +252 -0
- package/scripts/burnoff-statusline.mjs +20 -0
- package/src/cli/audit.mjs +82 -4
- package/src/cli/doctor.mjs +583 -462
- package/src/cli/hook-health.mjs +429 -0
- package/src/cli/init.mjs +668 -646
- package/src/cli/startup-audit.mjs +147 -2
- package/src/clients/antigravity.mjs +285 -285
- package/src/config/policy.mjs +307 -294
- package/src/guards/credential-scrubber.mjs +185 -0
- package/src/guards/loop-breaker.mjs +797 -744
- package/src/guards/phase5-detectors.mjs +727 -0
- package/src/guards/post-tool-engine.mjs +875 -854
- package/src/guards/pre-tool-engine.mjs +973 -846
- package/src/guards/read-clamp.mjs +826 -804
- package/src/guards/shell-guard.mjs +1705 -1676
- package/src/guards/snooze.mjs +5 -2
- package/src/guards/structural-boundaries.mjs +175 -0
- package/src/ipc/fast-client.mjs +255 -255
- package/src/storage/antigravity-parser.mjs +18 -1
- package/src/storage/fts5-archive.mjs +734 -733
- package/src/storage/jsonl-parser.mjs +29 -1
- package/src/storage/telemetry-metrics.mjs +703 -0
package/src/ipc/fast-client.mjs
CHANGED
|
@@ -1,255 +1,255 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file src/ipc/fast-client.mjs
|
|
3
|
-
* Minimal zero-heavy-dependency JSON-RPC client for warm Burnoff Daemon IPC checks.
|
|
4
|
-
* Imports strictly Node built-ins (`node:fs`, `node:path`, `node:os`, `node:net`, `node:crypto`).
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import fs from 'node:fs';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import os from 'node:os';
|
|
10
|
-
import net from 'node:net';
|
|
11
|
-
import crypto from 'node:crypto';
|
|
12
|
-
|
|
13
|
-
function normalizeHomePath(raw = '') {
|
|
14
|
-
return String(raw || '').trim().replace(/\\/g, '/').replace(/\/+$/, '');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Ensures sandboxed tests overriding `HOME`/`USERPROFILE` never accidentally connect to a live
|
|
19
|
-
* host daemon pipe unless `BURNOFF_IPC_PATH` is explicitly set.
|
|
20
|
-
*/
|
|
21
|
-
export function isRealHostHomeEnv(env = process.env) {
|
|
22
|
-
if (env && typeof env.BURNOFF_IPC_PATH === 'string' && env.BURNOFF_IPC_PATH.trim()) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
const envHome = normalizeHomePath(env?.USERPROFILE || env?.HOME || '');
|
|
26
|
-
if (!envHome) return true;
|
|
27
|
-
let realHome = '';
|
|
28
|
-
try {
|
|
29
|
-
realHome = normalizeHomePath(os.userInfo()?.homedir || '');
|
|
30
|
-
} catch (err) {
|
|
31
|
-
void err; // ignore: fallback allows connection when userInfo is restricted
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
if (!realHome) return true;
|
|
35
|
-
if (process.platform === 'win32') {
|
|
36
|
-
return envHome.toLowerCase() === realHome.toLowerCase();
|
|
37
|
-
}
|
|
38
|
-
return envHome === realHome;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Mirrors `resolveIpcPath` from `src/ipc/protocol.mjs` without loading heavyweight modules.
|
|
43
|
-
*/
|
|
44
|
-
export function resolveFastIpcPipePath(options = {}) {
|
|
45
|
-
if (options.ipcPath || process.env.BURNOFF_IPC_PATH) {
|
|
46
|
-
return String(options.ipcPath || process.env.BURNOFF_IPC_PATH);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const wsTarget = path.resolve(options.cwd || process.cwd());
|
|
50
|
-
const wsHash = crypto.createHash('sha1').update(wsTarget.toLowerCase()).digest('hex').slice(0, 10);
|
|
51
|
-
|
|
52
|
-
if (process.platform === 'win32') {
|
|
53
|
-
let rawUser = process.env.USERNAME || process.env.USER;
|
|
54
|
-
if (!rawUser) {
|
|
55
|
-
try {
|
|
56
|
-
rawUser = typeof os.userInfo === 'function' ? os.userInfo()?.username : null;
|
|
57
|
-
} catch (err) {
|
|
58
|
-
void err; // ignore: fallback username
|
|
59
|
-
rawUser = null;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const cleanUser = String(rawUser || 'default').replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
63
|
-
return `\\\\.\\pipe\\burnoff-${cleanUser}-${wsHash}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
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');
|
|
71
|
-
return path.join(burnoffHome, 'run', `daemon-${wsHash}.sock`);
|
|
72
|
-
}
|
|
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
|
-
|
|
101
|
-
function sendRawDaemonRpc(method, params = {}, options = {}) {
|
|
102
|
-
if (!options.ipcPath && !process.env.BURNOFF_IPC_PATH && !isRealHostHomeEnv()) {
|
|
103
|
-
return Promise.resolve(null);
|
|
104
|
-
}
|
|
105
|
-
const derivedCwd = options.cwd || params?.event?.cwd || params?.input?.cwd || params?.cwd;
|
|
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)) {
|
|
135
|
-
return Promise.resolve(null);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const connectTimeoutMs = Math.max(1, Number(options.connectTimeoutMs ?? 15));
|
|
139
|
-
const requestTimeoutMs = Math.max(20, Number(options.requestTimeoutMs ?? 5000));
|
|
140
|
-
|
|
141
|
-
return new Promise((resolve) => {
|
|
142
|
-
let settled = false;
|
|
143
|
-
let connected = false;
|
|
144
|
-
let socket = null;
|
|
145
|
-
let connectTimer = null;
|
|
146
|
-
let requestTimer = null;
|
|
147
|
-
let buffer = '';
|
|
148
|
-
|
|
149
|
-
const settle = (val) => {
|
|
150
|
-
if (settled) return;
|
|
151
|
-
settled = true;
|
|
152
|
-
if (connectTimer) {
|
|
153
|
-
clearTimeout(connectTimer);
|
|
154
|
-
connectTimer = null;
|
|
155
|
-
}
|
|
156
|
-
if (requestTimer) {
|
|
157
|
-
clearTimeout(requestTimer);
|
|
158
|
-
requestTimer = null;
|
|
159
|
-
}
|
|
160
|
-
if (socket) {
|
|
161
|
-
try {
|
|
162
|
-
socket.removeAllListeners();
|
|
163
|
-
socket.destroy();
|
|
164
|
-
} catch (cleanupErr) {
|
|
165
|
-
void cleanupErr; // ignore: socket cleanup on settle
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
resolve(val);
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
socket = net.connect(pipePath);
|
|
173
|
-
} catch (connErr) {
|
|
174
|
-
void connErr; // ignore: unavailable daemon socket returns null
|
|
175
|
-
settle(null);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
connectTimer = setTimeout(() => {
|
|
180
|
-
if (!connected) settle(null);
|
|
181
|
-
}, connectTimeoutMs);
|
|
182
|
-
|
|
183
|
-
requestTimer = setTimeout(() => {
|
|
184
|
-
settle(null);
|
|
185
|
-
}, requestTimeoutMs);
|
|
186
|
-
|
|
187
|
-
socket.once('connect', () => {
|
|
188
|
-
connected = true;
|
|
189
|
-
if (connectTimer) {
|
|
190
|
-
clearTimeout(connectTimer);
|
|
191
|
-
connectTimer = null;
|
|
192
|
-
}
|
|
193
|
-
try {
|
|
194
|
-
const frame = JSON.stringify({ jsonrpc: '2.0', id: 1, method: String(method), params }) + '\n';
|
|
195
|
-
socket.write(frame);
|
|
196
|
-
} catch (writeErr) {
|
|
197
|
-
void writeErr; // ignore: broken pipe falls back to cold path
|
|
198
|
-
settle(null);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
socket.on('data', (chunk) => {
|
|
203
|
-
buffer += chunk.toString('utf8');
|
|
204
|
-
if (buffer.length > 2 * 1024 * 1024) {
|
|
205
|
-
settle(null);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const nlIdx = buffer.indexOf('\n');
|
|
209
|
-
if (nlIdx === -1) return;
|
|
210
|
-
const line = buffer.slice(0, nlIdx).trim();
|
|
211
|
-
if (!line) {
|
|
212
|
-
buffer = buffer.slice(nlIdx + 1);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
try {
|
|
216
|
-
const parsed = JSON.parse(line);
|
|
217
|
-
if (parsed && !parsed.error && parsed.result !== undefined) {
|
|
218
|
-
settle(parsed.result);
|
|
219
|
-
} else {
|
|
220
|
-
settle(null);
|
|
221
|
-
}
|
|
222
|
-
} catch (parseErr) {
|
|
223
|
-
void parseErr; // ignore: malformed RPC response falls back to null
|
|
224
|
-
settle(null);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
socket.once('error', () => settle(null));
|
|
229
|
-
socket.once('close', () => settle(null));
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Sends a JSON-RPC call to the warm daemon (for `daemon.ping`, `daemon.stop`, etc.).
|
|
235
|
-
*/
|
|
236
|
-
export function sendDaemonRpc(method, params = {}, options = {}) {
|
|
237
|
-
return sendRawDaemonRpc(method, params, options);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Attempts a fast hook RPC to the warm Burnoff Daemon pipe.
|
|
242
|
-
* Returns `result` strictly when `result?.fullVerdict === true`, otherwise `null`.
|
|
243
|
-
*/
|
|
244
|
-
export async function tryFastDaemonRpc(method, params = {}, options = {}) {
|
|
245
|
-
const result = await sendRawDaemonRpc(method, params, options);
|
|
246
|
-
return result && result.fullVerdict === true ? result : null;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export default {
|
|
250
|
-
isRealHostHomeEnv,
|
|
251
|
-
resolveFastIpcPipePath,
|
|
252
|
-
resolveFastDaemonMarkerPath,
|
|
253
|
-
sendDaemonRpc,
|
|
254
|
-
tryFastDaemonRpc
|
|
255
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @file src/ipc/fast-client.mjs
|
|
3
|
+
* Minimal zero-heavy-dependency JSON-RPC client for warm Burnoff Daemon IPC checks.
|
|
4
|
+
* Imports strictly Node built-ins (`node:fs`, `node:path`, `node:os`, `node:net`, `node:crypto`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import net from 'node:net';
|
|
11
|
+
import crypto from 'node:crypto';
|
|
12
|
+
|
|
13
|
+
function normalizeHomePath(raw = '') {
|
|
14
|
+
return String(raw || '').trim().replace(/\\/g, '/').replace(/\/+$/, '');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Ensures sandboxed tests overriding `HOME`/`USERPROFILE` never accidentally connect to a live
|
|
19
|
+
* host daemon pipe unless `BURNOFF_IPC_PATH` is explicitly set.
|
|
20
|
+
*/
|
|
21
|
+
export function isRealHostHomeEnv(env = process.env) {
|
|
22
|
+
if (env && typeof env.BURNOFF_IPC_PATH === 'string' && env.BURNOFF_IPC_PATH.trim()) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const envHome = normalizeHomePath(env?.USERPROFILE || env?.HOME || '');
|
|
26
|
+
if (!envHome) return true;
|
|
27
|
+
let realHome = '';
|
|
28
|
+
try {
|
|
29
|
+
realHome = normalizeHomePath(os.userInfo()?.homedir || '');
|
|
30
|
+
} catch (err) {
|
|
31
|
+
void err; // ignore: fallback allows connection when userInfo is restricted
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (!realHome) return true;
|
|
35
|
+
if (process.platform === 'win32') {
|
|
36
|
+
return envHome.toLowerCase() === realHome.toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
return envHome === realHome;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Mirrors `resolveIpcPath` from `src/ipc/protocol.mjs` without loading heavyweight modules.
|
|
43
|
+
*/
|
|
44
|
+
export function resolveFastIpcPipePath(options = {}) {
|
|
45
|
+
if (options.ipcPath || process.env.BURNOFF_IPC_PATH) {
|
|
46
|
+
return String(options.ipcPath || process.env.BURNOFF_IPC_PATH);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const wsTarget = path.resolve(options.cwd || process.cwd());
|
|
50
|
+
const wsHash = crypto.createHash('sha1').update(wsTarget.toLowerCase()).digest('hex').slice(0, 10);
|
|
51
|
+
|
|
52
|
+
if (process.platform === 'win32') {
|
|
53
|
+
let rawUser = process.env.USERNAME || process.env.USER;
|
|
54
|
+
if (!rawUser) {
|
|
55
|
+
try {
|
|
56
|
+
rawUser = typeof os.userInfo === 'function' ? os.userInfo()?.username : null;
|
|
57
|
+
} catch (err) {
|
|
58
|
+
void err; // ignore: fallback username
|
|
59
|
+
rawUser = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const cleanUser = String(rawUser || 'default').replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
63
|
+
return `\\\\.\\pipe\\burnoff-${cleanUser}-${wsHash}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
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');
|
|
71
|
+
return path.join(burnoffHome, 'run', `daemon-${wsHash}.sock`);
|
|
72
|
+
}
|
|
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
|
+
|
|
101
|
+
function sendRawDaemonRpc(method, params = {}, options = {}) {
|
|
102
|
+
if (!options.ipcPath && !options.homeDir && !process.env.BURNOFF_IPC_PATH && !isRealHostHomeEnv()) {
|
|
103
|
+
return Promise.resolve(null);
|
|
104
|
+
}
|
|
105
|
+
const derivedCwd = options.cwd || params?.event?.cwd || params?.input?.cwd || params?.cwd;
|
|
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)) {
|
|
135
|
+
return Promise.resolve(null);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const connectTimeoutMs = Math.max(1, Number(options.connectTimeoutMs ?? 15));
|
|
139
|
+
const requestTimeoutMs = Math.max(20, Number(options.requestTimeoutMs ?? 5000));
|
|
140
|
+
|
|
141
|
+
return new Promise((resolve) => {
|
|
142
|
+
let settled = false;
|
|
143
|
+
let connected = false;
|
|
144
|
+
let socket = null;
|
|
145
|
+
let connectTimer = null;
|
|
146
|
+
let requestTimer = null;
|
|
147
|
+
let buffer = '';
|
|
148
|
+
|
|
149
|
+
const settle = (val) => {
|
|
150
|
+
if (settled) return;
|
|
151
|
+
settled = true;
|
|
152
|
+
if (connectTimer) {
|
|
153
|
+
clearTimeout(connectTimer);
|
|
154
|
+
connectTimer = null;
|
|
155
|
+
}
|
|
156
|
+
if (requestTimer) {
|
|
157
|
+
clearTimeout(requestTimer);
|
|
158
|
+
requestTimer = null;
|
|
159
|
+
}
|
|
160
|
+
if (socket) {
|
|
161
|
+
try {
|
|
162
|
+
socket.removeAllListeners();
|
|
163
|
+
socket.destroy();
|
|
164
|
+
} catch (cleanupErr) {
|
|
165
|
+
void cleanupErr; // ignore: socket cleanup on settle
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
resolve(val);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
socket = net.connect(pipePath);
|
|
173
|
+
} catch (connErr) {
|
|
174
|
+
void connErr; // ignore: unavailable daemon socket returns null
|
|
175
|
+
settle(null);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
connectTimer = setTimeout(() => {
|
|
180
|
+
if (!connected) settle(null);
|
|
181
|
+
}, connectTimeoutMs);
|
|
182
|
+
|
|
183
|
+
requestTimer = setTimeout(() => {
|
|
184
|
+
settle(null);
|
|
185
|
+
}, requestTimeoutMs);
|
|
186
|
+
|
|
187
|
+
socket.once('connect', () => {
|
|
188
|
+
connected = true;
|
|
189
|
+
if (connectTimer) {
|
|
190
|
+
clearTimeout(connectTimer);
|
|
191
|
+
connectTimer = null;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const frame = JSON.stringify({ jsonrpc: '2.0', id: 1, method: String(method), params }) + '\n';
|
|
195
|
+
socket.write(frame);
|
|
196
|
+
} catch (writeErr) {
|
|
197
|
+
void writeErr; // ignore: broken pipe falls back to cold path
|
|
198
|
+
settle(null);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
socket.on('data', (chunk) => {
|
|
203
|
+
buffer += chunk.toString('utf8');
|
|
204
|
+
if (buffer.length > 2 * 1024 * 1024) {
|
|
205
|
+
settle(null);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const nlIdx = buffer.indexOf('\n');
|
|
209
|
+
if (nlIdx === -1) return;
|
|
210
|
+
const line = buffer.slice(0, nlIdx).trim();
|
|
211
|
+
if (!line) {
|
|
212
|
+
buffer = buffer.slice(nlIdx + 1);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
const parsed = JSON.parse(line);
|
|
217
|
+
if (parsed && !parsed.error && parsed.result !== undefined) {
|
|
218
|
+
settle(parsed.result);
|
|
219
|
+
} else {
|
|
220
|
+
settle(null);
|
|
221
|
+
}
|
|
222
|
+
} catch (parseErr) {
|
|
223
|
+
void parseErr; // ignore: malformed RPC response falls back to null
|
|
224
|
+
settle(null);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
socket.once('error', () => settle(null));
|
|
229
|
+
socket.once('close', () => settle(null));
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Sends a JSON-RPC call to the warm daemon (for `daemon.ping`, `daemon.stop`, etc.).
|
|
235
|
+
*/
|
|
236
|
+
export function sendDaemonRpc(method, params = {}, options = {}) {
|
|
237
|
+
return sendRawDaemonRpc(method, params, options);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Attempts a fast hook RPC to the warm Burnoff Daemon pipe.
|
|
242
|
+
* Returns `result` strictly when `result?.fullVerdict === true`, otherwise `null`.
|
|
243
|
+
*/
|
|
244
|
+
export async function tryFastDaemonRpc(method, params = {}, options = {}) {
|
|
245
|
+
const result = await sendRawDaemonRpc(method, params, options);
|
|
246
|
+
return result && result.fullVerdict === true ? result : null;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export default {
|
|
250
|
+
isRealHostHomeEnv,
|
|
251
|
+
resolveFastIpcPipePath,
|
|
252
|
+
resolveFastDaemonMarkerPath,
|
|
253
|
+
sendDaemonRpc,
|
|
254
|
+
tryFastDaemonRpc
|
|
255
|
+
};
|
|
@@ -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,
|