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
|
@@ -1,285 +1,285 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file src/clients/antigravity.mjs
|
|
3
|
-
* Google Antigravity hook adapter (supports both Antigravity 2.0 CLI/App and IDE v1/Cascade).
|
|
4
|
-
* Normalizes camelCase/PascalCase `toolCall` payloads into Burnoff's `CanonicalEvent` and
|
|
5
|
-
* renders verdicts strictly in Antigravity's `exitCode: 0` JSON stdout contract.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export const CLIENT_ID = 'antigravity';
|
|
9
|
-
|
|
10
|
-
const ANTIGRAVITY_TOOL_MAP = Object.freeze({
|
|
11
|
-
run_command: 'Bash',
|
|
12
|
-
read_file: 'Read',
|
|
13
|
-
view_file: 'Read',
|
|
14
|
-
write_file: 'Write',
|
|
15
|
-
write_to_file: 'Write',
|
|
16
|
-
edit_file: 'Edit',
|
|
17
|
-
replace_file_content: 'Edit',
|
|
18
|
-
multi_replace_file_content: 'Edit',
|
|
19
|
-
grep_search: 'Grep',
|
|
20
|
-
find_by_name: 'Glob',
|
|
21
|
-
list_dir: 'Glob',
|
|
22
|
-
invoke_subagent: 'Task',
|
|
23
|
-
read_url_content: 'WebFetch'
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Returns true if the payload matches Google Antigravity's camelCase `toolCall` / `conversationId` contract.
|
|
28
|
-
*/
|
|
29
|
-
export function detect(payload = {}) {
|
|
30
|
-
if (!payload || typeof payload !== 'object') return false;
|
|
31
|
-
if (payload.toolCall && typeof payload.toolCall === 'object') return true;
|
|
32
|
-
if (typeof payload.conversationId === 'string' && payload.conversationId.length > 0) return true;
|
|
33
|
-
if (Array.isArray(payload.workspacePaths) && payload.workspacePaths.length > 0) return true;
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function mapToolName(rawName, args = {}) {
|
|
38
|
-
const key = String(rawName || '').trim();
|
|
39
|
-
if (!key) return '';
|
|
40
|
-
const lower = key.toLowerCase();
|
|
41
|
-
if (ANTIGRAVITY_TOOL_MAP[lower]) {
|
|
42
|
-
return ANTIGRAVITY_TOOL_MAP[lower];
|
|
43
|
-
}
|
|
44
|
-
if (lower === 'call_mcp_tool') {
|
|
45
|
-
const server = String(args.ServerName || args.serverName || args.server || 'server').trim();
|
|
46
|
-
const tool = String(args.ToolName || args.toolName || args.tool || 'tool').trim();
|
|
47
|
-
return `mcp__${server}__${tool}`;
|
|
48
|
-
}
|
|
49
|
-
if (lower.startsWith('mcp_') && !lower.startsWith('mcp__')) {
|
|
50
|
-
const rest = key.slice(4);
|
|
51
|
-
const sep = rest.indexOf('_');
|
|
52
|
-
if (sep > 0) {
|
|
53
|
-
return `mcp__${rest.slice(0, sep)}__${rest.slice(sep + 1)}`;
|
|
54
|
-
}
|
|
55
|
-
return `mcp__${rest}`;
|
|
56
|
-
}
|
|
57
|
-
return key;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function mapToolArgs(rawName, args = {}, payload = {}) {
|
|
61
|
-
const lower = String(rawName || '').trim().toLowerCase();
|
|
62
|
-
const mapped = { ...(args && typeof args === 'object' ? args : {}) };
|
|
63
|
-
|
|
64
|
-
if (lower === 'run_command') {
|
|
65
|
-
if (mapped.CommandLine !== undefined && mapped.command === undefined) {
|
|
66
|
-
mapped.command = String(mapped.CommandLine);
|
|
67
|
-
}
|
|
68
|
-
if (mapped.Cwd !== undefined && mapped.cwd === undefined) {
|
|
69
|
-
mapped.cwd = String(mapped.Cwd);
|
|
70
|
-
} else if (mapped.cwd === undefined && payload.cwd) {
|
|
71
|
-
mapped.cwd = String(payload.cwd);
|
|
72
|
-
}
|
|
73
|
-
return mapped;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (lower === 'read_file' || lower === 'view_file') {
|
|
77
|
-
const targetPath = mapped.
|
|
78
|
-
if (targetPath && mapped.file_path === undefined) {
|
|
79
|
-
mapped.file_path = String(targetPath);
|
|
80
|
-
}
|
|
81
|
-
const startRaw = mapped.StartLine ?? mapped.start_line ?? mapped.offset;
|
|
82
|
-
const endRaw = mapped.EndLine ?? mapped.end_line;
|
|
83
|
-
if (startRaw !== undefined && startRaw !== null) {
|
|
84
|
-
const startNum = Math.max(1, Math.floor(Number(startRaw) || 1));
|
|
85
|
-
if (mapped.offset === undefined) mapped.offset = startNum;
|
|
86
|
-
if (endRaw !== undefined && endRaw !== null && mapped.limit === undefined) {
|
|
87
|
-
const endNum = Math.floor(Number(endRaw) || startNum);
|
|
88
|
-
mapped.limit = Math.max(1, endNum - startNum + 1);
|
|
89
|
-
}
|
|
90
|
-
} else if (endRaw !== undefined && endRaw !== null && mapped.limit === undefined) {
|
|
91
|
-
const endNum = Math.max(1, Math.floor(Number(endRaw) || 1));
|
|
92
|
-
mapped.offset = 1;
|
|
93
|
-
mapped.limit = endNum;
|
|
94
|
-
}
|
|
95
|
-
return mapped;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
lower === 'write_file' ||
|
|
100
|
-
lower === 'write_to_file' ||
|
|
101
|
-
lower === 'edit_file' ||
|
|
102
|
-
lower === 'replace_file_content' ||
|
|
103
|
-
lower === 'multi_replace_file_content'
|
|
104
|
-
) {
|
|
105
|
-
const targetPath =
|
|
106
|
-
mapped.
|
|
107
|
-
if (targetPath && mapped.file_path === undefined) {
|
|
108
|
-
mapped.file_path = String(targetPath);
|
|
109
|
-
}
|
|
110
|
-
return mapped;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (lower === 'grep_search') {
|
|
114
|
-
if (mapped.SearchPath !== undefined && mapped.path === undefined) {
|
|
115
|
-
mapped.path = String(mapped.SearchPath);
|
|
116
|
-
}
|
|
117
|
-
if (mapped.Query !== undefined && mapped.pattern === undefined) {
|
|
118
|
-
mapped.pattern = String(mapped.Query);
|
|
119
|
-
}
|
|
120
|
-
return mapped;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (lower === 'find_by_name' || lower === 'list_dir') {
|
|
124
|
-
const dir = mapped.SearchDirectory ?? mapped.DirectoryPath ?? mapped.path;
|
|
125
|
-
if (dir !== undefined && mapped.path === undefined) {
|
|
126
|
-
mapped.path = String(dir);
|
|
127
|
-
}
|
|
128
|
-
if (mapped.Pattern !== undefined && mapped.pattern === undefined) {
|
|
129
|
-
mapped.pattern = String(mapped.Pattern);
|
|
130
|
-
}
|
|
131
|
-
return mapped;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (lower === 'read_url_content') {
|
|
135
|
-
if (mapped.Url !== undefined && mapped.url === undefined) {
|
|
136
|
-
mapped.url = String(mapped.Url);
|
|
137
|
-
}
|
|
138
|
-
return mapped;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return mapped;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Normalizes a Google Antigravity hook payload into Burnoff's `CanonicalEvent`.
|
|
146
|
-
*/
|
|
147
|
-
export function normalize(payload = {}, options = {}) {
|
|
148
|
-
if (payload && payload.__canonical === true && payload.client === CLIENT_ID) {
|
|
149
|
-
return payload;
|
|
150
|
-
}
|
|
151
|
-
const toolCall = payload.toolCall && typeof payload.toolCall === 'object' ? payload.toolCall : {};
|
|
152
|
-
const rawToolName = String(toolCall.name || payload.toolName || payload.tool_name || '');
|
|
153
|
-
const rawArgs =
|
|
154
|
-
toolCall.args && typeof toolCall.args === 'object'
|
|
155
|
-
? { ...toolCall.args }
|
|
156
|
-
: payload.args && typeof payload.args === 'object'
|
|
157
|
-
? { ...payload.args }
|
|
158
|
-
: {};
|
|
159
|
-
const toolInput = mapToolArgs(rawToolName, rawArgs, payload);
|
|
160
|
-
const canonicalToolName = mapToolName(rawToolName, rawArgs);
|
|
161
|
-
|
|
162
|
-
const firstWorkspace = Array.isArray(payload.workspacePaths) && payload.workspacePaths[0]
|
|
163
|
-
? String(payload.workspacePaths[0])
|
|
164
|
-
: '';
|
|
165
|
-
const cwd = String(payload.cwd || firstWorkspace || options.cwd || '');
|
|
166
|
-
const hasErrorStr = typeof payload.error === 'string' && payload.error.trim().length > 0;
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
__canonical: true,
|
|
170
|
-
client: CLIENT_ID,
|
|
171
|
-
hookEventName: String(payload.hookEventName || payload.hook_event_name || ''),
|
|
172
|
-
sessionId: String(payload.conversationId || payload.sessionId || payload.session_id || 'default'),
|
|
173
|
-
cwd,
|
|
174
|
-
toolName: canonicalToolName,
|
|
175
|
-
rawToolName,
|
|
176
|
-
toolInput,
|
|
177
|
-
rawArgs,
|
|
178
|
-
toolUseId: String(toolCall.id || payload.toolUseId || payload.tool_use_id || ''),
|
|
179
|
-
model: String(payload.modelName || (typeof payload.model === 'string' ? payload.model : payload.model?.id) || ''),
|
|
180
|
-
lastUserInput: String(payload.lastUserInput || payload.prompt || ''),
|
|
181
|
-
transcriptPath: String(payload.transcriptPath || payload.transcript_path || ''),
|
|
182
|
-
failed: hasErrorStr || payload.isError === true || payload.is_error === true,
|
|
183
|
-
raw: payload
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Renders a `PreToolUse` engine result into Antigravity's JSON stdout contract.
|
|
189
|
-
* Always exits with code 0 and never emits `hookSpecificOutput`.
|
|
190
|
-
*/
|
|
191
|
-
export function renderPre(engineResult = {}) {
|
|
192
|
-
const verdict = engineResult.verdict || null;
|
|
193
|
-
|
|
194
|
-
if (engineResult.exitCode === 2 || verdict?.decision === 'deny') {
|
|
195
|
-
const reason = String(engineResult.stderr || verdict?.reason || 'Blocked by Burnoff guardrail').trim();
|
|
196
|
-
return {
|
|
197
|
-
...engineResult,
|
|
198
|
-
exitCode: 0,
|
|
199
|
-
stdout: JSON.stringify({ decision: 'deny', reason }),
|
|
200
|
-
stderr: ''
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (verdict?.decision === 'ask' || verdict?.decision === 'force_ask') {
|
|
205
|
-
const decision = verdict.decision === 'force_ask' ? 'force_ask' : 'ask';
|
|
206
|
-
const reason = String(verdict?.reason || 'Requires user confirmation').trim();
|
|
207
|
-
return {
|
|
208
|
-
...engineResult,
|
|
209
|
-
exitCode: 0,
|
|
210
|
-
stdout: JSON.stringify({ decision, reason }),
|
|
211
|
-
stderr: ''
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (
|
|
216
|
-
verdict?.updatedInput &&
|
|
217
|
-
(verdict.updatedInput.offset !== undefined || verdict.updatedInput.limit !== undefined)
|
|
218
|
-
) {
|
|
219
|
-
const startLine = Math.max(1, Math.floor(Number(verdict.updatedInput.offset || 1)));
|
|
220
|
-
const limit = Math.max(1, Math.floor(Number(verdict.updatedInput.limit || 250)));
|
|
221
|
-
const endLine = startLine + limit - 1;
|
|
222
|
-
const out = {
|
|
223
|
-
decision: 'allow',
|
|
224
|
-
overwrite: {
|
|
225
|
-
StartLine: startLine,
|
|
226
|
-
EndLine: endLine
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
if (verdict.reason) {
|
|
230
|
-
out.reason = String(verdict.reason).trim();
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
...engineResult,
|
|
234
|
-
exitCode: 0,
|
|
235
|
-
stdout: JSON.stringify(out),
|
|
236
|
-
stderr: ''
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const out = { decision: 'allow' };
|
|
241
|
-
const advisory = verdict?.additionalContext || verdict?.reason;
|
|
242
|
-
if (advisory) {
|
|
243
|
-
out.reason = String(advisory).trim();
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
...engineResult,
|
|
247
|
-
exitCode: 0,
|
|
248
|
-
stdout: JSON.stringify(out),
|
|
249
|
-
stderr: ''
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Renders a `PostToolUse` result into Antigravity's `{}` stdout contract.
|
|
255
|
-
*/
|
|
256
|
-
export function renderPost(engineResult = {}) {
|
|
257
|
-
return {
|
|
258
|
-
...engineResult,
|
|
259
|
-
exitCode: 0,
|
|
260
|
-
stdout: '{}',
|
|
261
|
-
stderr: ''
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Renders a fail-open JSON response on internal hook faults so Antigravity receives valid JSON.
|
|
267
|
-
*/
|
|
268
|
-
export function renderFailOpen(reason, hookEventName = 'PreToolUse') {
|
|
269
|
-
const msg = String(reason || 'Unexpected hook diagnostic').trim();
|
|
270
|
-
const stdout = hookEventName === 'PostToolUse' ? '{}' : JSON.stringify({ decision: 'allow' });
|
|
271
|
-
return {
|
|
272
|
-
exitCode: 0,
|
|
273
|
-
stdout,
|
|
274
|
-
stderr: `[Burnoff ${hookEventName} Diagnostic] ${msg}\n`
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export default {
|
|
279
|
-
CLIENT_ID,
|
|
280
|
-
detect,
|
|
281
|
-
normalize,
|
|
282
|
-
renderPre,
|
|
283
|
-
renderPost,
|
|
284
|
-
renderFailOpen
|
|
285
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @file src/clients/antigravity.mjs
|
|
3
|
+
* Google Antigravity hook adapter (supports both Antigravity 2.0 CLI/App and IDE v1/Cascade).
|
|
4
|
+
* Normalizes camelCase/PascalCase `toolCall` payloads into Burnoff's `CanonicalEvent` and
|
|
5
|
+
* renders verdicts strictly in Antigravity's `exitCode: 0` JSON stdout contract.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const CLIENT_ID = 'antigravity';
|
|
9
|
+
|
|
10
|
+
const ANTIGRAVITY_TOOL_MAP = Object.freeze({
|
|
11
|
+
run_command: 'Bash',
|
|
12
|
+
read_file: 'Read',
|
|
13
|
+
view_file: 'Read',
|
|
14
|
+
write_file: 'Write',
|
|
15
|
+
write_to_file: 'Write',
|
|
16
|
+
edit_file: 'Edit',
|
|
17
|
+
replace_file_content: 'Edit',
|
|
18
|
+
multi_replace_file_content: 'Edit',
|
|
19
|
+
grep_search: 'Grep',
|
|
20
|
+
find_by_name: 'Glob',
|
|
21
|
+
list_dir: 'Glob',
|
|
22
|
+
invoke_subagent: 'Task',
|
|
23
|
+
read_url_content: 'WebFetch'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns true if the payload matches Google Antigravity's camelCase `toolCall` / `conversationId` contract.
|
|
28
|
+
*/
|
|
29
|
+
export function detect(payload = {}) {
|
|
30
|
+
if (!payload || typeof payload !== 'object') return false;
|
|
31
|
+
if (payload.toolCall && typeof payload.toolCall === 'object') return true;
|
|
32
|
+
if (typeof payload.conversationId === 'string' && payload.conversationId.length > 0) return true;
|
|
33
|
+
if (Array.isArray(payload.workspacePaths) && payload.workspacePaths.length > 0) return true;
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function mapToolName(rawName, args = {}) {
|
|
38
|
+
const key = String(rawName || '').trim();
|
|
39
|
+
if (!key) return '';
|
|
40
|
+
const lower = key.toLowerCase();
|
|
41
|
+
if (ANTIGRAVITY_TOOL_MAP[lower]) {
|
|
42
|
+
return ANTIGRAVITY_TOOL_MAP[lower];
|
|
43
|
+
}
|
|
44
|
+
if (lower === 'call_mcp_tool') {
|
|
45
|
+
const server = String(args.ServerName || args.serverName || args.server || 'server').trim();
|
|
46
|
+
const tool = String(args.ToolName || args.toolName || args.tool || 'tool').trim();
|
|
47
|
+
return `mcp__${server}__${tool}`;
|
|
48
|
+
}
|
|
49
|
+
if (lower.startsWith('mcp_') && !lower.startsWith('mcp__')) {
|
|
50
|
+
const rest = key.slice(4);
|
|
51
|
+
const sep = rest.indexOf('_');
|
|
52
|
+
if (sep > 0) {
|
|
53
|
+
return `mcp__${rest.slice(0, sep)}__${rest.slice(sep + 1)}`;
|
|
54
|
+
}
|
|
55
|
+
return `mcp__${rest}`;
|
|
56
|
+
}
|
|
57
|
+
return key;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function mapToolArgs(rawName, args = {}, payload = {}) {
|
|
61
|
+
const lower = String(rawName || '').trim().toLowerCase();
|
|
62
|
+
const mapped = { ...(args && typeof args === 'object' ? args : {}) };
|
|
63
|
+
|
|
64
|
+
if (lower === 'run_command') {
|
|
65
|
+
if (mapped.CommandLine !== undefined && mapped.command === undefined) {
|
|
66
|
+
mapped.command = String(mapped.CommandLine);
|
|
67
|
+
}
|
|
68
|
+
if (mapped.Cwd !== undefined && mapped.cwd === undefined) {
|
|
69
|
+
mapped.cwd = String(mapped.Cwd);
|
|
70
|
+
} else if (mapped.cwd === undefined && payload.cwd) {
|
|
71
|
+
mapped.cwd = String(payload.cwd);
|
|
72
|
+
}
|
|
73
|
+
return mapped;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (lower === 'read_file' || lower === 'view_file') {
|
|
77
|
+
const targetPath = mapped.AbsolutePath ?? mapped.Path ?? mapped.path ?? mapped.file_path ?? '';
|
|
78
|
+
if (targetPath && mapped.file_path === undefined) {
|
|
79
|
+
mapped.file_path = String(targetPath);
|
|
80
|
+
}
|
|
81
|
+
const startRaw = mapped.StartLine ?? mapped.start_line ?? mapped.offset;
|
|
82
|
+
const endRaw = mapped.EndLine ?? mapped.end_line;
|
|
83
|
+
if (startRaw !== undefined && startRaw !== null) {
|
|
84
|
+
const startNum = Math.max(1, Math.floor(Number(startRaw) || 1));
|
|
85
|
+
if (mapped.offset === undefined) mapped.offset = startNum;
|
|
86
|
+
if (endRaw !== undefined && endRaw !== null && mapped.limit === undefined) {
|
|
87
|
+
const endNum = Math.floor(Number(endRaw) || startNum);
|
|
88
|
+
mapped.limit = Math.max(1, endNum - startNum + 1);
|
|
89
|
+
}
|
|
90
|
+
} else if (endRaw !== undefined && endRaw !== null && mapped.limit === undefined) {
|
|
91
|
+
const endNum = Math.max(1, Math.floor(Number(endRaw) || 1));
|
|
92
|
+
mapped.offset = 1;
|
|
93
|
+
mapped.limit = endNum;
|
|
94
|
+
}
|
|
95
|
+
return mapped;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (
|
|
99
|
+
lower === 'write_file' ||
|
|
100
|
+
lower === 'write_to_file' ||
|
|
101
|
+
lower === 'edit_file' ||
|
|
102
|
+
lower === 'replace_file_content' ||
|
|
103
|
+
lower === 'multi_replace_file_content'
|
|
104
|
+
) {
|
|
105
|
+
const targetPath =
|
|
106
|
+
mapped.AbsolutePath ?? mapped.Path ?? mapped.TargetFile ?? mapped.path ?? mapped.file_path ?? '';
|
|
107
|
+
if (targetPath && mapped.file_path === undefined) {
|
|
108
|
+
mapped.file_path = String(targetPath);
|
|
109
|
+
}
|
|
110
|
+
return mapped;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (lower === 'grep_search') {
|
|
114
|
+
if (mapped.SearchPath !== undefined && mapped.path === undefined) {
|
|
115
|
+
mapped.path = String(mapped.SearchPath);
|
|
116
|
+
}
|
|
117
|
+
if (mapped.Query !== undefined && mapped.pattern === undefined) {
|
|
118
|
+
mapped.pattern = String(mapped.Query);
|
|
119
|
+
}
|
|
120
|
+
return mapped;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (lower === 'find_by_name' || lower === 'list_dir') {
|
|
124
|
+
const dir = mapped.SearchDirectory ?? mapped.DirectoryPath ?? mapped.path;
|
|
125
|
+
if (dir !== undefined && mapped.path === undefined) {
|
|
126
|
+
mapped.path = String(dir);
|
|
127
|
+
}
|
|
128
|
+
if (mapped.Pattern !== undefined && mapped.pattern === undefined) {
|
|
129
|
+
mapped.pattern = String(mapped.Pattern);
|
|
130
|
+
}
|
|
131
|
+
return mapped;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (lower === 'read_url_content') {
|
|
135
|
+
if (mapped.Url !== undefined && mapped.url === undefined) {
|
|
136
|
+
mapped.url = String(mapped.Url);
|
|
137
|
+
}
|
|
138
|
+
return mapped;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return mapped;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Normalizes a Google Antigravity hook payload into Burnoff's `CanonicalEvent`.
|
|
146
|
+
*/
|
|
147
|
+
export function normalize(payload = {}, options = {}) {
|
|
148
|
+
if (payload && payload.__canonical === true && payload.client === CLIENT_ID) {
|
|
149
|
+
return payload;
|
|
150
|
+
}
|
|
151
|
+
const toolCall = payload.toolCall && typeof payload.toolCall === 'object' ? payload.toolCall : {};
|
|
152
|
+
const rawToolName = String(toolCall.name || payload.toolName || payload.tool_name || '');
|
|
153
|
+
const rawArgs =
|
|
154
|
+
toolCall.args && typeof toolCall.args === 'object'
|
|
155
|
+
? { ...toolCall.args }
|
|
156
|
+
: payload.args && typeof payload.args === 'object'
|
|
157
|
+
? { ...payload.args }
|
|
158
|
+
: {};
|
|
159
|
+
const toolInput = mapToolArgs(rawToolName, rawArgs, payload);
|
|
160
|
+
const canonicalToolName = mapToolName(rawToolName, rawArgs);
|
|
161
|
+
|
|
162
|
+
const firstWorkspace = Array.isArray(payload.workspacePaths) && payload.workspacePaths[0]
|
|
163
|
+
? String(payload.workspacePaths[0])
|
|
164
|
+
: '';
|
|
165
|
+
const cwd = String(payload.cwd || firstWorkspace || options.cwd || '');
|
|
166
|
+
const hasErrorStr = typeof payload.error === 'string' && payload.error.trim().length > 0;
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
__canonical: true,
|
|
170
|
+
client: CLIENT_ID,
|
|
171
|
+
hookEventName: String(payload.hookEventName || payload.hook_event_name || ''),
|
|
172
|
+
sessionId: String(payload.conversationId || payload.sessionId || payload.session_id || 'default'),
|
|
173
|
+
cwd,
|
|
174
|
+
toolName: canonicalToolName,
|
|
175
|
+
rawToolName,
|
|
176
|
+
toolInput,
|
|
177
|
+
rawArgs,
|
|
178
|
+
toolUseId: String(toolCall.id || payload.toolUseId || payload.tool_use_id || ''),
|
|
179
|
+
model: String(payload.modelName || (typeof payload.model === 'string' ? payload.model : payload.model?.id) || ''),
|
|
180
|
+
lastUserInput: String(payload.lastUserInput || payload.prompt || ''),
|
|
181
|
+
transcriptPath: String(payload.transcriptPath || payload.transcript_path || ''),
|
|
182
|
+
failed: hasErrorStr || payload.isError === true || payload.is_error === true,
|
|
183
|
+
raw: payload
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Renders a `PreToolUse` engine result into Antigravity's JSON stdout contract.
|
|
189
|
+
* Always exits with code 0 and never emits `hookSpecificOutput`.
|
|
190
|
+
*/
|
|
191
|
+
export function renderPre(engineResult = {}) {
|
|
192
|
+
const verdict = engineResult.verdict || null;
|
|
193
|
+
|
|
194
|
+
if (engineResult.exitCode === 2 || verdict?.decision === 'deny') {
|
|
195
|
+
const reason = String(engineResult.stderr || verdict?.reason || 'Blocked by Burnoff guardrail').trim();
|
|
196
|
+
return {
|
|
197
|
+
...engineResult,
|
|
198
|
+
exitCode: 0,
|
|
199
|
+
stdout: JSON.stringify({ decision: 'deny', reason }),
|
|
200
|
+
stderr: ''
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (verdict?.decision === 'ask' || verdict?.decision === 'force_ask') {
|
|
205
|
+
const decision = verdict.decision === 'force_ask' ? 'force_ask' : 'ask';
|
|
206
|
+
const reason = String(verdict?.reason || 'Requires user confirmation').trim();
|
|
207
|
+
return {
|
|
208
|
+
...engineResult,
|
|
209
|
+
exitCode: 0,
|
|
210
|
+
stdout: JSON.stringify({ decision, reason }),
|
|
211
|
+
stderr: ''
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (
|
|
216
|
+
verdict?.updatedInput &&
|
|
217
|
+
(verdict.updatedInput.offset !== undefined || verdict.updatedInput.limit !== undefined)
|
|
218
|
+
) {
|
|
219
|
+
const startLine = Math.max(1, Math.floor(Number(verdict.updatedInput.offset || 1)));
|
|
220
|
+
const limit = Math.max(1, Math.floor(Number(verdict.updatedInput.limit || 250)));
|
|
221
|
+
const endLine = startLine + limit - 1;
|
|
222
|
+
const out = {
|
|
223
|
+
decision: 'allow',
|
|
224
|
+
overwrite: {
|
|
225
|
+
StartLine: startLine,
|
|
226
|
+
EndLine: endLine
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
if (verdict.reason) {
|
|
230
|
+
out.reason = String(verdict.reason).trim();
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
...engineResult,
|
|
234
|
+
exitCode: 0,
|
|
235
|
+
stdout: JSON.stringify(out),
|
|
236
|
+
stderr: ''
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const out = { decision: 'allow' };
|
|
241
|
+
const advisory = verdict?.additionalContext || verdict?.reason;
|
|
242
|
+
if (advisory) {
|
|
243
|
+
out.reason = String(advisory).trim();
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
...engineResult,
|
|
247
|
+
exitCode: 0,
|
|
248
|
+
stdout: JSON.stringify(out),
|
|
249
|
+
stderr: ''
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Renders a `PostToolUse` result into Antigravity's `{}` stdout contract.
|
|
255
|
+
*/
|
|
256
|
+
export function renderPost(engineResult = {}) {
|
|
257
|
+
return {
|
|
258
|
+
...engineResult,
|
|
259
|
+
exitCode: 0,
|
|
260
|
+
stdout: '{}',
|
|
261
|
+
stderr: ''
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Renders a fail-open JSON response on internal hook faults so Antigravity receives valid JSON.
|
|
267
|
+
*/
|
|
268
|
+
export function renderFailOpen(reason, hookEventName = 'PreToolUse') {
|
|
269
|
+
const msg = String(reason || 'Unexpected hook diagnostic').trim();
|
|
270
|
+
const stdout = hookEventName === 'PostToolUse' ? '{}' : JSON.stringify({ decision: 'allow' });
|
|
271
|
+
return {
|
|
272
|
+
exitCode: 0,
|
|
273
|
+
stdout,
|
|
274
|
+
stderr: `[Burnoff ${hookEventName} Diagnostic] ${msg}\n`
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export default {
|
|
279
|
+
CLIENT_ID,
|
|
280
|
+
detect,
|
|
281
|
+
normalize,
|
|
282
|
+
renderPre,
|
|
283
|
+
renderPost,
|
|
284
|
+
renderFailOpen
|
|
285
|
+
};
|