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.
This commit is contained in:
MohamedAfrash committed 2026-10-13 16:23:24 +01:00
1 parent 6443b39a7a
commit 31ecd4b1c3
19 files changed
+169 -128

No files matched your search

+7
View File
@@ -16,6 +16,7 @@ const { run: runGateGuard } = require('./gateguard-fact-force');
const { run: runDocFileWarning } = require('./doc-file-warning');
const { run: runPostEditAccumulator } = require('./post-edit-accumulator');
const { readStdinRaw, resolveMaxStdin } = require('./hook-input');
const { isHookEnabled, isDryRun } = require('../lib/hook-flags');
function parseArgs(argv) {
const options = {
@@ -71,6 +72,12 @@ function writeFailure(mode, reason) {
async function main() {
const options = parseArgs(process.argv);
process.env.ECC_HOOK_CONFIG ||= path.resolve(__dirname, '../../ecc/setup.json');
const profiles = options.hook === 'pre:bash:dispatcher' ? 'minimal,standard,strict' : undefined;
if (!isHookEnabled(options.hook, { profiles }) || isDryRun()) {
process.stdout.write(JSON.stringify(options.mode === 'post-tool-use' ? {} : { decision: 'allow' }));
return;
}
const maxStdin = resolveMaxStdin(process.env.ECC_HOOK_INPUT_MAX_BYTES);
let raw = '';
+3 -5
View File
@@ -12,7 +12,6 @@ const { shellQuote } = require('./control-pane/actions');
*/
function buildAntigravityHooksConfig(options = {}) {
const profile = options.profile || 'standard';
const { bridgeScript } = options;
if (typeof bridgeScript !== 'string' || !path.isAbsolute(bridgeScript) || bridgeScript.includes('\0')) {
throw new Error('bridgeScript must be an absolute path');
@@ -55,8 +54,8 @@ function buildAntigravityHooksConfig(options = {}) {
},
];
if (profile === 'standard' || profile === 'strict') {
preToolUseHandlers.push({
// Runtime hook flags select the profile, including explicit environment overrides.
preToolUseHandlers.push({
matcher: 'write_to_file',
hooks: [
{
@@ -65,8 +64,7 @@ function buildAntigravityHooksConfig(options = {}) {
timeout: 5,
},
],
});
}
});
const stopHandlers = [
{
+7 -13
View File
@@ -572,7 +572,6 @@ function verifyPluginAtScope(options) {
function ensurePluginAtScope(options) {
const run = options.run || runClaude;
const configuredHooks = options.hookConfiguration;
if (options.installed) {
run(
['plugin', 'update', CURRENT_PLUGIN_ID, '--scope', options.scope],
@@ -580,17 +579,13 @@ function ensurePluginAtScope(options) {
);
return 'updated';
}
const installArgs = [
'plugin', 'install', CURRENT_PLUGIN_ID,
'--scope', options.scope,
];
if (configuredHooks) {
installArgs.push(
'--config', `hooks_enabled=${configuredHooks.hooks_enabled}`,
'--config', `hook_profile=${configuredHooks.hook_profile}`
);
}
run(installArgs, { cwd: options.projectRoot, phase: 'plugin-install' });
run(
[
'plugin', 'install', CURRENT_PLUGIN_ID,
'--scope', options.scope,
],
{ cwd: options.projectRoot, phase: 'plugin-install' }
);
return 'installed';
}
@@ -660,7 +655,6 @@ function setupClaudePlugin(options = {}, dependencies = {}) {
spawnSync: dependencies.spawnSync,
});
const action = ensurePluginAtScope({
hookConfiguration: hookOptions(hooks),
hooks,
installed: inventory.installed,
projectRoot: paths.projectRoot,
+2 -1
View File
@@ -874,7 +874,8 @@ function inspectManagedOperation(repoRoot, trustedRoot, operation, linkIndex = n
}
function trustedRootForDestination(destinationPath, targetRoot, trustedRoots = [targetRoot]) {
return trustedRoots.find(root => isWithinRoot(destinationPath, root)) || targetRoot;
const parent = typeof destinationPath === 'string' ? path.dirname(destinationPath) : destinationPath;
return trustedRoots.find(root => isWithinRoot(parent, root)) || targetRoot;
}
function summarizeManagedOperationHealth(repoRoot, trustedRoot, operations, target = null, trustedRoots = [trustedRoot]) {
+20 -30
View File
@@ -15,21 +15,8 @@ const {
const { buildAntigravityHooksConfig } = require('../antigravity-hooks');
const { buildAntigravityMcpConfig, planAntigravityMemoryRuntime } = require('../antigravity-mcp');
const { buildAntigravityPluginManifest } = require('../antigravity-plugin');
function readJsonObject(filePath, label) {
let parsed;
try {
parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
} catch (error) {
throw new Error(`Failed to parse ${label} at ${filePath}: ${error.message}`);
}
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new Error(`Invalid ${label} at ${filePath}: expected a JSON object`);
}
return parsed;
}
const { getHookProfile } = require('../hook-flags');
const { isWithinRoot } = require('../path-safety');
module.exports = createInstallTargetAdapter({
id: 'antigravity-home',
@@ -40,10 +27,11 @@ module.exports = createInstallTargetAdapter({
nativeRootRelativePath: '.gemini',
excludedSourcePaths: HOME_INSTALL_EXCLUDED_SOURCE_PATHS,
resolveTrustedRoots(input, targetRoot) {
const workflowsRoot = path.join(
path.dirname(path.dirname(targetRoot)),
'workflows'
);
const configRoot = path.dirname(path.dirname(targetRoot));
const workflowsRoot = path.join(configRoot, 'workflows');
if (!isWithinRoot(workflowsRoot, configRoot)) {
throw new Error('Refusing Antigravity workflows outside the trusted config root.');
}
return [targetRoot, workflowsRoot];
},
planOperations(input, adapter) {
@@ -141,6 +129,7 @@ module.exports = createInstallTargetAdapter({
module.id === 'hooks-runtime'
&& normalizedSourcePath === 'hooks'
) {
const profile = getHookProfile(input.env);
return [
createManagedScaffoldOperation(module.id, 'package.json', path.join(targetRoot, 'package.json'), 'preserve-relative-path'),
createManagedOperation({
@@ -152,10 +141,20 @@ module.exports = createInstallTargetAdapter({
ownership: 'managed',
scaffoldOnly: false,
mergePayload: buildAntigravityHooksConfig({
profile: input.hookProfile || 'standard',
profile,
bridgeScript: path.join(targetRoot, 'scripts', 'hooks', 'antigravity-hook-bridge.js'),
}),
}),
createManagedOperation({
kind: 'merge-json',
moduleId: module.id,
sourceRelativePath: 'hooks/hooks.json',
destinationPath: path.join(targetRoot, 'ecc', 'setup.json'),
strategy: 'merge-json',
ownership: 'managed',
scaffoldOnly: false,
mergePayload: { hooks: { enabled: true, profile } },
}),
];
}
@@ -163,18 +162,9 @@ module.exports = createInstallTargetAdapter({
module.id === 'platform-configs'
&& (normalizedSourcePath === 'mcp-configs' || normalizedSourcePath === '.mcp.json')
) {
const baseMcp = (repoRoot && fs.existsSync(path.join(repoRoot, '.mcp.json')))
? readJsonObject(path.join(repoRoot, '.mcp.json'), '.mcp.json')
: { mcpServers: {} };
const antigravityMcp = buildAntigravityMcpConfig({
memoryScript: path.join(targetRoot, 'scripts', 'memory-mcp.mjs'),
});
const mergedMcp = {
mcpServers: {
...(baseMcp.mcpServers || {}),
...(antigravityMcp.mcpServers || {}),
},
};
const operations = [
createManagedOperation({
@@ -185,7 +175,7 @@ module.exports = createInstallTargetAdapter({
strategy: 'merge-json',
ownership: 'managed',
scaffoldOnly: false,
mergePayload: mergedMcp,
mergePayload: antigravityMcp,
}),
createManagedOperation({
kind: 'merge-json',
@@ -11,6 +11,7 @@ const {
const { buildAntigravityHooksConfig } = require('../antigravity-hooks');
const { buildAntigravityMcpConfig, planAntigravityMemoryRuntime } = require('../antigravity-mcp');
const { buildAntigravityPluginManifest } = require('../antigravity-plugin');
const { getHookProfile } = require('../hook-flags');
const SUPPORTED_SOURCE_PREFIXES = [
'rules',
@@ -31,21 +32,6 @@ function supportsAntigravitySourcePath(sourceRelativePath) {
));
}
function readJsonObject(filePath, label) {
let parsed;
try {
parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
} catch (error) {
throw new Error(`Failed to parse ${label} at ${filePath}: ${error.message}`);
}
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new Error(`Invalid ${label} at ${filePath}: expected a JSON object`);
}
return parsed;
}
module.exports = createInstallTargetAdapter({
id: 'antigravity-project',
target: 'antigravity',
@@ -148,6 +134,7 @@ module.exports = createInstallTargetAdapter({
module.id === 'hooks-runtime'
&& normalizedSourcePath === 'hooks'
) {
const profile = getHookProfile(input.env);
return [
createManagedScaffoldOperation(module.id, 'package.json', path.join(targetRoot, 'package.json'), 'preserve-relative-path'),
createManagedOperation({
@@ -159,10 +146,20 @@ module.exports = createInstallTargetAdapter({
ownership: 'managed',
scaffoldOnly: false,
mergePayload: buildAntigravityHooksConfig({
profile: input.hookProfile || 'standard',
profile,
bridgeScript: path.join(targetRoot, 'scripts', 'hooks', 'antigravity-hook-bridge.js'),
}),
}),
createManagedOperation({
kind: 'merge-json',
moduleId: module.id,
sourceRelativePath: 'hooks/hooks.json',
destinationPath: path.join(targetRoot, 'ecc', 'setup.json'),
strategy: 'merge-json',
ownership: 'managed',
scaffoldOnly: false,
mergePayload: { hooks: { enabled: true, profile } },
}),
];
}
@@ -170,18 +167,9 @@ module.exports = createInstallTargetAdapter({
module.id === 'platform-configs'
&& (normalizedSourcePath === 'mcp-configs' || normalizedSourcePath === '.mcp.json')
) {
const baseMcp = (repoRoot && fs.existsSync(path.join(repoRoot, '.mcp.json')))
? readJsonObject(path.join(repoRoot, '.mcp.json'), '.mcp.json')
: { mcpServers: {} };
const antigravityMcp = buildAntigravityMcpConfig({
memoryScript: path.join(targetRoot, 'scripts', 'memory-mcp.mjs'),
});
const mergedMcp = {
mcpServers: {
...(baseMcp.mcpServers || {}),
...(antigravityMcp.mcpServers || {}),
},
};
const operations = [
createManagedOperation({
@@ -192,7 +180,7 @@ module.exports = createInstallTargetAdapter({
strategy: 'merge-json',
ownership: 'managed',
scaffoldOnly: false,
mergePayload: mergedMcp,
mergePayload: antigravityMcp,
}),
createManagedOperation({
kind: 'merge-json',
+1 -1
View File
@@ -254,7 +254,7 @@ function writeClaudeCommitAttributionPreference(settingsPath, options = {}) {
function isMcpConfigPath(filePath) {
const basename = path.basename(String(filePath || ''));
return basename === '.mcp.json' || basename === 'mcp.json';
return basename === '.mcp.json' || basename === 'mcp.json' || basename === 'mcp_config.json';
}
function getTrustedRootsForPlan(plan) {
-1
View File
@@ -17,7 +17,6 @@
* so stdout stays parseable.
*/
const { spawn } = require('child_process');
const fs = require('fs');
const http = require('http');
const path = require('path');