mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-24 00:35:31 +00:00
fix(antigravity): resolve PR review comments on hooks bridge, mcp runtime, and quoting
This commit is contained in:
1 parent
689160048a
commit
aa457babfc
14 files changed
+507
-73
No files matched your search
@@ -14,7 +14,7 @@ const { spawnSync } = require('child_process');
|
||||
const { runPreBash } = require('./bash-hook-dispatcher');
|
||||
const { run: runGateGuard } = require('./gateguard-fact-force');
|
||||
const { run: runDocFileWarning } = require('./doc-file-warning');
|
||||
const { run: runStopFormatTypecheck } = require('./stop-format-typecheck');
|
||||
const { run: runPostEditAccumulator } = require('./post-edit-accumulator');
|
||||
const { readStdinRaw, resolveMaxStdin } = require('./hook-input');
|
||||
|
||||
function parseArgs(argv) {
|
||||
@@ -53,13 +53,22 @@ function adaptAntigravityInputToEcc(antigravityData) {
|
||||
};
|
||||
|
||||
return {
|
||||
tool_name: toolName,
|
||||
tool_name: ({ run_command: 'Bash', write_to_file: 'Write', replace_file_content: 'Edit', multi_replace_file_content: 'Edit' })[toolName] || toolName,
|
||||
tool_input: toolInput,
|
||||
session_id: antigravityData.conversationId || antigravityData.session_id || '',
|
||||
cwd: args.Cwd || antigravityData.cwd || antigravityData.workspacePaths?.[0] || '',
|
||||
conversation_id: antigravityData.conversationId || '',
|
||||
workspace_paths: antigravityData.workspacePaths || [],
|
||||
};
|
||||
}
|
||||
|
||||
function writeFailure(mode, reason) {
|
||||
process.stdout.write(JSON.stringify({
|
||||
decision: mode === 'pre-tool-use' ? 'deny' : 'allow',
|
||||
...(mode === 'pre-tool-use' ? { reason } : {}),
|
||||
}));
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const options = parseArgs(process.argv);
|
||||
const maxStdin = resolveMaxStdin(process.env.ECC_HOOK_INPUT_MAX_BYTES);
|
||||
@@ -67,19 +76,21 @@ async function main() {
|
||||
let raw = '';
|
||||
try {
|
||||
const inputResult = await readStdinRaw(process.stdin, { maxStdin });
|
||||
if (inputResult.truncated) throw new Error('Incomplete hook input');
|
||||
raw = inputResult.raw;
|
||||
} catch (_err) {
|
||||
// If stdin read fails, fail open safely
|
||||
process.stdout.write(JSON.stringify({ decision: 'allow' }));
|
||||
writeFailure(options.mode, 'ECC hook input could not be read completely');
|
||||
return;
|
||||
}
|
||||
|
||||
let antigravityPayload = {};
|
||||
try {
|
||||
antigravityPayload = raw.trim() ? JSON.parse(raw) : {};
|
||||
antigravityPayload = JSON.parse(raw);
|
||||
if (!antigravityPayload || typeof antigravityPayload !== 'object' || Array.isArray(antigravityPayload)) {
|
||||
throw new Error('Invalid hook input');
|
||||
}
|
||||
} catch (_parseErr) {
|
||||
// Malformed JSON on stdin
|
||||
process.stdout.write(JSON.stringify({ decision: 'allow' }));
|
||||
writeFailure(options.mode, 'ECC hook input must be a valid JSON object');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,45 +108,65 @@ async function main() {
|
||||
const child = spawnSync(process.execPath, [path.join(__dirname, 'config-protection.js')], {
|
||||
input: eccJsonString,
|
||||
encoding: 'utf8',
|
||||
timeout: 4000,
|
||||
});
|
||||
result = {
|
||||
exitCode: child.status || 0,
|
||||
exitCode: child.error || child.status === null ? 2 : child.status,
|
||||
stderr: child.stderr || '',
|
||||
};
|
||||
} else if (options.hook === 'pre:write:doc-file-warning') {
|
||||
result = runDocFileWarning(eccJsonString);
|
||||
}
|
||||
|
||||
if (result && (result.exitCode === 2 || result.denied || result.blocked)) {
|
||||
const reason = result.stderr || result.reason || 'Blocked by ECC safety hook';
|
||||
process.stdout.write(JSON.stringify({
|
||||
decision: 'deny',
|
||||
reason: reason.replace(/\r?\n/g, ' ').trim(),
|
||||
}));
|
||||
return;
|
||||
}
|
||||
const output = result && (result.stdout || result.output);
|
||||
const hookOutput = output ? JSON.parse(output).hookSpecificOutput : null;
|
||||
const denied = result && ((result.exitCode !== undefined && result.exitCode !== 0) || result.denied || result.blocked)
|
||||
|| hookOutput?.permissionDecision === 'deny';
|
||||
const context = result?.additionalContext || hookOutput?.additionalContext;
|
||||
const reason = denied
|
||||
? hookOutput?.permissionDecisionReason || result.stderr || result.reason || 'Blocked by ECC safety hook'
|
||||
: Array.isArray(context) ? context.join(' ') : context;
|
||||
process.stdout.write(JSON.stringify({
|
||||
decision: denied ? 'deny' : 'allow',
|
||||
...(reason ? { reason: String(reason).replace(/\r?\n/g, ' ').trim() } : {}),
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
process.stdout.write(JSON.stringify({ decision: 'allow' }));
|
||||
// Both accumulator and batch formatter use the same session-scoped temp file.
|
||||
if (eccPayload.session_id) process.env.CLAUDE_SESSION_ID = String(eccPayload.session_id);
|
||||
|
||||
if (options.mode === 'post-tool-use') {
|
||||
if (options.hook === 'post:edit:accumulator' && !antigravityPayload.error) {
|
||||
runPostEditAccumulator(eccJsonString);
|
||||
}
|
||||
process.stdout.write(JSON.stringify({}));
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.mode === 'stop') {
|
||||
if (antigravityPayload.fullyIdle === false) {
|
||||
process.stdout.write(JSON.stringify({ decision: 'allow' }));
|
||||
return;
|
||||
}
|
||||
let stopResult = { exitCode: 0, stderr: '' };
|
||||
|
||||
if (options.hook === 'stop:format-typecheck') {
|
||||
stopResult = runStopFormatTypecheck(eccJsonString);
|
||||
} else if (options.hook === 'stop:check-console-log') {
|
||||
const child = spawnSync(process.execPath, [path.join(__dirname, 'check-console-log.js')], {
|
||||
const stopScript = {
|
||||
'stop:format-typecheck': 'stop-format-typecheck.js',
|
||||
'stop:check-console-log': 'check-console-log.js',
|
||||
}[options.hook];
|
||||
if (stopScript) {
|
||||
const child = spawnSync(process.execPath, [path.join(__dirname, stopScript)], {
|
||||
input: eccJsonString,
|
||||
encoding: 'utf8',
|
||||
timeout: options.hook === 'stop:format-typecheck' ? 280000 : 25000,
|
||||
});
|
||||
stopResult = {
|
||||
exitCode: child.status || 0,
|
||||
stderr: child.stderr || '',
|
||||
stderr: child.stderr || (child.error ? 'ECC stop hook failed: ' + child.error.message : ''),
|
||||
};
|
||||
}
|
||||
|
||||
if (stopResult && stopResult.exitCode !== 0 && stopResult.stderr) {
|
||||
if (stopResult && stopResult.stderr) {
|
||||
process.stdout.write(JSON.stringify({
|
||||
decision: 'continue',
|
||||
reason: stopResult.stderr.replace(/\r?\n/g, ' ').trim(),
|
||||
@@ -143,7 +174,7 @@ async function main() {
|
||||
return;
|
||||
}
|
||||
|
||||
process.stdout.write(JSON.stringify({}));
|
||||
process.stdout.write(JSON.stringify({ decision: 'allow' }));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -153,7 +184,7 @@ async function main() {
|
||||
|
||||
if (require.main === module) {
|
||||
main().catch(() => {
|
||||
process.stdout.write(JSON.stringify({ decision: 'allow' }));
|
||||
writeFailure(parseArgs(process.argv).mode, 'ECC safety hook failed unexpectedly');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const { shellQuote } = require('./control-pane/actions');
|
||||
|
||||
/**
|
||||
* Antigravity Hooks Generator
|
||||
*
|
||||
@@ -10,7 +13,19 @@
|
||||
|
||||
function buildAntigravityHooksConfig(options = {}) {
|
||||
const profile = options.profile || 'standard';
|
||||
const bridgeScript = options.bridgeScript || 'scripts/hooks/antigravity-hook-bridge.js';
|
||||
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.includes(' ') ? `"${bridgeScript}"` : bridgeScript;
|
||||
} else {
|
||||
quotedBridgeScript = shellQuote(bridgeScript);
|
||||
}
|
||||
|
||||
const preToolUseHandlers = [
|
||||
{
|
||||
@@ -18,22 +33,22 @@ function buildAntigravityHooksConfig(options = {}) {
|
||||
hooks: [
|
||||
{
|
||||
type: 'command',
|
||||
command: `node ${bridgeScript} --mode pre-tool-use --hook pre:bash:dispatcher`,
|
||||
command: `node ${quotedBridgeScript} --mode pre-tool-use --hook pre:bash:dispatcher`,
|
||||
timeout: 15,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
matcher: 'write_to_file|replace_file_content',
|
||||
matcher: 'write_to_file|replace_file_content|multi_replace_file_content',
|
||||
hooks: [
|
||||
{
|
||||
type: 'command',
|
||||
command: `node ${bridgeScript} --mode pre-tool-use --hook pre:edit-write:gateguard-fact-force`,
|
||||
command: `node ${quotedBridgeScript} --mode pre-tool-use --hook pre:edit-write:gateguard-fact-force`,
|
||||
timeout: 10,
|
||||
},
|
||||
{
|
||||
type: 'command',
|
||||
command: `node ${bridgeScript} --mode pre-tool-use --hook pre:config-protection`,
|
||||
command: `node ${quotedBridgeScript} --mode pre-tool-use --hook pre:config-protection`,
|
||||
timeout: 5,
|
||||
},
|
||||
],
|
||||
@@ -46,7 +61,7 @@ function buildAntigravityHooksConfig(options = {}) {
|
||||
hooks: [
|
||||
{
|
||||
type: 'command',
|
||||
command: `node ${bridgeScript} --mode pre-tool-use --hook pre:write:doc-file-warning`,
|
||||
command: `node ${quotedBridgeScript} --mode pre-tool-use --hook pre:write:doc-file-warning`,
|
||||
timeout: 5,
|
||||
},
|
||||
],
|
||||
@@ -56,12 +71,12 @@ function buildAntigravityHooksConfig(options = {}) {
|
||||
const stopHandlers = [
|
||||
{
|
||||
type: 'command',
|
||||
command: `node ${bridgeScript} --mode stop --hook stop:format-typecheck`,
|
||||
timeout: 120,
|
||||
command: `node ${quotedBridgeScript} --mode stop --hook stop:format-typecheck`,
|
||||
timeout: 300,
|
||||
},
|
||||
{
|
||||
type: 'command',
|
||||
command: `node ${bridgeScript} --mode stop --hook stop:check-console-log`,
|
||||
command: `node ${quotedBridgeScript} --mode stop --hook stop:check-console-log`,
|
||||
timeout: 30,
|
||||
},
|
||||
];
|
||||
@@ -69,6 +84,14 @@ function buildAntigravityHooksConfig(options = {}) {
|
||||
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,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { createManagedScaffoldOperation } = require('./install-targets/helpers');
|
||||
|
||||
/**
|
||||
* Antigravity MCP Configuration Generator
|
||||
*
|
||||
@@ -8,7 +12,10 @@
|
||||
*/
|
||||
|
||||
function buildAntigravityMcpConfig(options = {}) {
|
||||
const memoryScript = options.memoryScript || 'scripts/memory-mcp.mjs';
|
||||
const { memoryScript } = options;
|
||||
if (typeof memoryScript !== 'string' || !path.isAbsolute(memoryScript) || memoryScript.includes('\0')) {
|
||||
throw new Error('memoryScript must be an absolute path');
|
||||
}
|
||||
|
||||
return {
|
||||
mcpServers: {
|
||||
@@ -23,6 +30,41 @@ function buildAntigravityMcpConfig(options = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
function planAntigravityMemoryRuntime(moduleId, repoRoot, targetRoot) {
|
||||
const sourcePaths = [
|
||||
'package.json',
|
||||
'scripts/memory-mcp.mjs',
|
||||
'scripts/lib/missing-dependency.js',
|
||||
'scripts/lib/memory-vault.js',
|
||||
'scripts/lib/memory-vault-format.js',
|
||||
'scripts/lib/path-safety.js',
|
||||
];
|
||||
const operations = sourcePaths.map(sourcePath => createManagedScaffoldOperation(
|
||||
moduleId, sourcePath, path.join(targetRoot, sourcePath), 'preserve-relative-path'
|
||||
));
|
||||
function addDependency(name, fromRoot, destinationRoot, ancestors = []) {
|
||||
let manifestPath;
|
||||
try {
|
||||
manifestPath = require.resolve(`${name}/package.json`, { paths: [fromRoot] });
|
||||
} catch (error) {
|
||||
throw new Error(`Cannot install Antigravity memory dependency ${name}. Run npm install in ${repoRoot}: ${error.message}`);
|
||||
}
|
||||
if (ancestors.includes(manifestPath)) return;
|
||||
const packageRoot = path.dirname(manifestPath);
|
||||
const destinationPath = path.join(destinationRoot, 'node_modules', name);
|
||||
operations.push(createManagedScaffoldOperation(
|
||||
moduleId, path.relative(repoRoot, packageRoot), destinationPath, 'preserve-relative-path'
|
||||
));
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
||||
for (const dependency of Object.keys(manifest.dependencies || {})) {
|
||||
addDependency(dependency, packageRoot, destinationPath, [...ancestors, manifestPath]);
|
||||
}
|
||||
}
|
||||
addDependency('ajv', repoRoot, targetRoot);
|
||||
return operations;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buildAntigravityMcpConfig,
|
||||
planAntigravityMemoryRuntime,
|
||||
};
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
function buildAntigravityPluginManifest(options = {}) {
|
||||
const version = options.version || '2.2.2';
|
||||
const version = options.version || require('../../package.json').version;
|
||||
return {
|
||||
name: 'ecc',
|
||||
description: 'ECC - The Agent Harness Operating System for Antigravity',
|
||||
|
||||
@@ -658,6 +658,7 @@ function setupClaudePlugin(options = {}, dependencies = {}) {
|
||||
spawnSync: dependencies.spawnSync,
|
||||
});
|
||||
const action = ensurePluginAtScope({
|
||||
hookConfiguration: hookOptions(hooks),
|
||||
hooks,
|
||||
installed: inventory.installed,
|
||||
projectRoot: paths.projectRoot,
|
||||
|
||||
@@ -13,7 +13,7 @@ const {
|
||||
normalizeRelativePath,
|
||||
} = require('./helpers');
|
||||
const { buildAntigravityHooksConfig } = require('../antigravity-hooks');
|
||||
const { buildAntigravityMcpConfig } = require('../antigravity-mcp');
|
||||
const { buildAntigravityMcpConfig, planAntigravityMemoryRuntime } = require('../antigravity-mcp');
|
||||
const { buildAntigravityPluginManifest } = require('../antigravity-plugin');
|
||||
|
||||
function readJsonObject(filePath, label) {
|
||||
@@ -131,6 +131,7 @@ module.exports = createInstallTargetAdapter({
|
||||
&& normalizedSourcePath === 'hooks'
|
||||
) {
|
||||
return [
|
||||
createManagedScaffoldOperation(module.id, 'package.json', path.join(targetRoot, 'package.json'), 'preserve-relative-path'),
|
||||
createManagedOperation({
|
||||
kind: 'merge-json',
|
||||
moduleId: module.id,
|
||||
@@ -141,6 +142,7 @@ module.exports = createInstallTargetAdapter({
|
||||
scaffoldOnly: false,
|
||||
mergePayload: buildAntigravityHooksConfig({
|
||||
profile: input.hookProfile || 'standard',
|
||||
bridgeScript: path.join(targetRoot, 'scripts', 'hooks', 'antigravity-hook-bridge.js'),
|
||||
}),
|
||||
}),
|
||||
];
|
||||
@@ -153,7 +155,9 @@ module.exports = createInstallTargetAdapter({
|
||||
const baseMcp = (repoRoot && fs.existsSync(path.join(repoRoot, '.mcp.json')))
|
||||
? readJsonObject(path.join(repoRoot, '.mcp.json'), '.mcp.json')
|
||||
: { mcpServers: {} };
|
||||
const antigravityMcp = buildAntigravityMcpConfig();
|
||||
const antigravityMcp = buildAntigravityMcpConfig({
|
||||
memoryScript: path.join(targetRoot, 'scripts', 'memory-mcp.mjs'),
|
||||
});
|
||||
const mergedMcp = {
|
||||
mcpServers: {
|
||||
...(baseMcp.mcpServers || {}),
|
||||
@@ -185,14 +189,7 @@ module.exports = createInstallTargetAdapter({
|
||||
];
|
||||
|
||||
if (repoRoot && fs.existsSync(path.join(repoRoot, 'scripts', 'memory-mcp.mjs'))) {
|
||||
operations.push(
|
||||
createManagedScaffoldOperation(
|
||||
module.id,
|
||||
'scripts/memory-mcp.mjs',
|
||||
path.join(targetRoot, 'scripts', 'memory-mcp.mjs'),
|
||||
'preserve-relative-path'
|
||||
)
|
||||
);
|
||||
operations.push(...planAntigravityMemoryRuntime(module.id, repoRoot, targetRoot));
|
||||
}
|
||||
|
||||
return operations;
|
||||
|
||||
@@ -9,7 +9,7 @@ const {
|
||||
normalizeRelativePath,
|
||||
} = require('./helpers');
|
||||
const { buildAntigravityHooksConfig } = require('../antigravity-hooks');
|
||||
const { buildAntigravityMcpConfig } = require('../antigravity-mcp');
|
||||
const { buildAntigravityMcpConfig, planAntigravityMemoryRuntime } = require('../antigravity-mcp');
|
||||
const { buildAntigravityPluginManifest } = require('../antigravity-plugin');
|
||||
|
||||
const SUPPORTED_SOURCE_PREFIXES = [
|
||||
@@ -149,6 +149,7 @@ module.exports = createInstallTargetAdapter({
|
||||
&& normalizedSourcePath === 'hooks'
|
||||
) {
|
||||
return [
|
||||
createManagedScaffoldOperation(module.id, 'package.json', path.join(targetRoot, 'package.json'), 'preserve-relative-path'),
|
||||
createManagedOperation({
|
||||
kind: 'merge-json',
|
||||
moduleId: module.id,
|
||||
@@ -159,6 +160,7 @@ module.exports = createInstallTargetAdapter({
|
||||
scaffoldOnly: false,
|
||||
mergePayload: buildAntigravityHooksConfig({
|
||||
profile: input.hookProfile || 'standard',
|
||||
bridgeScript: path.join(targetRoot, 'scripts', 'hooks', 'antigravity-hook-bridge.js'),
|
||||
}),
|
||||
}),
|
||||
];
|
||||
@@ -171,7 +173,9 @@ module.exports = createInstallTargetAdapter({
|
||||
const baseMcp = (repoRoot && fs.existsSync(path.join(repoRoot, '.mcp.json')))
|
||||
? readJsonObject(path.join(repoRoot, '.mcp.json'), '.mcp.json')
|
||||
: { mcpServers: {} };
|
||||
const antigravityMcp = buildAntigravityMcpConfig();
|
||||
const antigravityMcp = buildAntigravityMcpConfig({
|
||||
memoryScript: path.join(targetRoot, 'scripts', 'memory-mcp.mjs'),
|
||||
});
|
||||
const mergedMcp = {
|
||||
mcpServers: {
|
||||
...(baseMcp.mcpServers || {}),
|
||||
@@ -203,14 +207,7 @@ module.exports = createInstallTargetAdapter({
|
||||
];
|
||||
|
||||
if (repoRoot && fs.existsSync(path.join(repoRoot, 'scripts', 'memory-mcp.mjs'))) {
|
||||
operations.push(
|
||||
createManagedScaffoldOperation(
|
||||
module.id,
|
||||
'scripts/memory-mcp.mjs',
|
||||
path.join(targetRoot, 'scripts', 'memory-mcp.mjs'),
|
||||
'preserve-relative-path'
|
||||
)
|
||||
);
|
||||
operations.push(...planAntigravityMemoryRuntime(module.id, repoRoot, targetRoot));
|
||||
}
|
||||
|
||||
return operations;
|
||||
|
||||
Reference in new issue
Block a user