Files
ECC/scripts/lib/antigravity-hooks.js
T
MohamedAfrash 31ecd4b1c3 fix: honor Antigravity runtime policy and contain managed installs
GREEN: hook policy 4/4, MCP policy 8/8, native Antigravity 1.2.9 import, tier suite 24/24, lifecycle 5/5 plus 73 existing checks. Use shared enable/profile/dry-run decisions and managed setup; stop importing source MCP definitions and filter mcp_config.json. Derive sibling workflow roots for doctor/repair/uninstall and refuse escapes. Restore upstream Claude setup behavior after four migration regressions. Update module targets, carrier schema, unchanged trigger binding, and native validation limits.
2026-10-13 16:23:24 +01:00

101 lines
2.7 KiB
JavaScript

'use strict';
const path = require('path');
const { shellQuote } = require('./control-pane/actions');
/**
* Antigravity Hooks Generator
*
* Generates valid Antigravity hooks.json configuration matching Antigravity's
* lifecycle schema (PreToolUse, PostToolUse, Stop) and pointing to the ECC
* hook bridge.
*/
function buildAntigravityHooksConfig(options = {}) {
const { bridgeScript } = options;
if (typeof bridgeScript !== 'string' || !path.isAbsolute(bridgeScript) || bridgeScript.includes('\0')) {
throw new Error('bridgeScript must be an absolute path');
}
let quotedBridgeScript;
if (process.platform === 'win32') {
if (/[%"!$`\r\n]/.test(bridgeScript)) {
throw new Error('bridgeScript contains unsafe shell expansion characters');
}
quotedBridgeScript = `"${bridgeScript}"`;
} else {
quotedBridgeScript = shellQuote(bridgeScript);
}
const preToolUseHandlers = [
{
matcher: 'run_command',
hooks: [
{
type: 'command',
command: `node ${quotedBridgeScript} --mode pre-tool-use --hook pre:bash:dispatcher`,
timeout: 15,
},
],
},
{
matcher: 'write_to_file|replace_file_content|multi_replace_file_content',
hooks: [
{
type: 'command',
command: `node ${quotedBridgeScript} --mode pre-tool-use --hook pre:edit-write:gateguard-fact-force`,
timeout: 10,
},
{
type: 'command',
command: `node ${quotedBridgeScript} --mode pre-tool-use --hook pre:config-protection`,
timeout: 5,
},
],
},
];
// Runtime hook flags select the profile, including explicit environment overrides.
preToolUseHandlers.push({
matcher: 'write_to_file',
hooks: [
{
type: 'command',
command: `node ${quotedBridgeScript} --mode pre-tool-use --hook pre:write:doc-file-warning`,
timeout: 5,
},
],
});
const stopHandlers = [
{
type: 'command',
command: `node ${quotedBridgeScript} --mode stop --hook stop:format-typecheck`,
timeout: 300,
},
{
type: 'command',
command: `node ${quotedBridgeScript} --mode stop --hook stop:check-console-log`,
timeout: 30,
},
];
return {
'ecc-guard': {
PreToolUse: preToolUseHandlers,
PostToolUse: [{
matcher: 'write_to_file|replace_file_content|multi_replace_file_content',
hooks: [{
type: 'command',
command: `node ${quotedBridgeScript} --mode post-tool-use --hook post:edit:accumulator`,
timeout: 10,
}],
}],
Stop: stopHandlers,
},
};
}
module.exports = {
buildAntigravityHooksConfig,
};