From eac38dd481c6a2302719dbe1501073a28d9da8cb Mon Sep 17 00:00:00 2001 From: woffluon Date: Thu, 5 Nov 2026 23:12:48 +0300 Subject: [PATCH 01/10] feat(antigravity): add hybrid Antigravity 2.0 and agy CLI adapter support --- .antigravity-plugin/plugin.json | 26 +++ README.md | 3 +- .../harness-adapter-compliance.md | 1 + hooks/antigravity-hooks.json | 16 ++ package.json | 2 + plugins/ecc/plugin.json | 12 ++ scripts/antigravity/hook-bridge.js | 197 ++++++++++++++++++ scripts/lib/harness-adapter-compliance.js | 41 ++++ .../install-targets/antigravity-project.js | 17 +- scripts/lib/install/antigravity-agent.js | 19 +- tests/lib/antigravity-hook-bridge.test.js | 135 ++++++++++++ tests/lib/antigravity-install-target.test.js | 24 ++- 12 files changed, 474 insertions(+), 19 deletions(-) create mode 100644 .antigravity-plugin/plugin.json create mode 100644 hooks/antigravity-hooks.json create mode 100644 plugins/ecc/plugin.json create mode 100644 scripts/antigravity/hook-bridge.js create mode 100644 tests/lib/antigravity-hook-bridge.test.js diff --git a/.antigravity-plugin/plugin.json b/.antigravity-plugin/plugin.json new file mode 100644 index 000000000..277f44a3b --- /dev/null +++ b/.antigravity-plugin/plugin.json @@ -0,0 +1,26 @@ +{ + "name": "ecc", + "version": "2.2.3", + "description": "Cross-harness operating system for Antigravity 2.0 and agy CLI - skills, rules, hooks, and agents", + "author": { + "name": "Affaan Mustafa", + "url": "https://x.com/affaanmustafa" + }, + "homepage": "https://ecc.tools", + "repository": "https://github.com/affaan-m/ECC", + "license": "MIT", + "keywords": [ + "antigravity", + "agy", + "agents", + "skills", + "hooks", + "rules", + "tdd", + "code-review", + "security" + ], + "skills": "./skills/", + "mcpServers": "./.mcp.json", + "hooks": "./hooks/antigravity-hooks.json" +} diff --git a/README.md b/README.md index d8017086c..14aabf339 100644 --- a/README.md +++ b/README.md @@ -1333,7 +1333,8 @@ Treat `stable`, `beta`, `experimental`, and `instruction-only` below as capabili | OpenCode | Beta built plugin | Build plugin, then selective installer | ECC ships a subset of the catalog; connect a provider and select a model in OpenCode ([#2617](https://github.com/affaan-m/ECC/issues/2617)). | | GitHub Copilot Chat | Instruction-only | Checked-in instructions and prompt files | ECC hooks are not adapted. | | GitHub Copilot CLI | Beta project adapter | `--target copilot` places skills, adapted agents, and converted rules in `.github/` | ECC hooks and command shims are not installed by this target. | -| Gemini, Zed, Antigravity, Qwen, Hermes, OpenClaw, Kimi, CodeBuddy, JoyCode | Experimental/minimal adapters | Harness-specific selective target | File placement and instruction portability are tested; full Claude feature parity is not claimed. | +| Antigravity 2.0 | Supported adapter & plugin | Native plugin (`.antigravity-plugin/` or `plugins/ecc/`) or `./install.sh --target antigravity` into `.agents/` | Subagents map to native tools (`read_file`, `edit_file`, `write_file`, `run_command`, `search_web`); hooks bridge via `scripts/antigravity/hook-bridge.js`. | +| Gemini, Zed, Qwen, Hermes, OpenClaw, Kimi, CodeBuddy, JoyCode | Experimental/minimal adapters | Harness-specific selective target | File placement and instruction portability are tested; full Claude feature parity is not claimed. |
Package manager detection diff --git a/docs/architecture/harness-adapter-compliance.md b/docs/architecture/harness-adapter-compliance.md index c2efea563..54dcc75ca 100644 --- a/docs/architecture/harness-adapter-compliance.md +++ b/docs/architecture/harness-adapter-compliance.md @@ -41,6 +41,7 @@ The matrix below is rendered from | OpenCode | Adapter-backed | OpenCode package/plugin metadata; shared skills; MCP config; event adapter patterns | Event names, plugin packaging, and command dispatch differ from Claude Code | OpenCode package or plugin surface from this repo | `node tests/scripts/build-opencode.test.js`; `npm run harness:audit -- --format json` | Keep hook logic in shared scripts and adapt only event shape at the edge. | | Pi | Adapter-backed | Pi package manifest; canonical ECC skills (skills/); canonical ECC commands as prompt templates (commands/); canonical ECC engineering rules (rules/common/) injected into the system prompt; session lifecycle hook adapter; /ecc-doctor diagnostics command; canonical ECC agents (agents/) portable via scripts/agent-convert.js (claude -> pi) | Agent chains, approval prompts, and persistent todos require companion Pi packages and are not part of this adapter (individual agent definitions are portable via scripts/agent-convert.js); Pi core has no MCP surface, though ECC MCP configs load verbatim through the community pi-mcp-adapter package, which ECC neither installs nor depends on | `pi install git:github.com/affaan-m/ECC`; `pi install /path/to/ECC` from a local checkout | `node tests/pi/pi-package-manifest.test.js`; `node tests/pi/pi-extension-adapter.test.js`; `node tests/pi/agent-convert.test.js`; `npm run harness:adapters -- --check` | Pi extensions execute with full user permissions, and hooks run without a shell and resolve from the installed package rather than the user project; Keep canonical skills and commands as the single source of truth, and never generate copies under .pi/ | | Cursor | Adapter-backed | Cursor rules; project-local skills; hook adapter; shared scripts | Cursor hook events and rule loading differ from Claude Code | `./install.sh --profile minimal --target cursor` | `node tests/lib/install-targets.test.js`; `npm run harness:audit -- --format json` | Cursor adapters must preserve existing project rules and avoid silent overwrite. | +| Antigravity 2.0 | Adapter-backed | Antigravity plugin manifest; skills (skills/); agents (agents/); workflows (commands/); progressive disclosure rules (rules/); lifecycle hooks (hooks.json via hook-bridge); MCP configs | Subagent recursion depth and terminal permissions follow Antigravity sandbox settings | `./install.sh --profile minimal --target antigravity`; `./install.ps1 -Profile minimal -Target antigravity`; `agy plugin install ` | `node tests/lib/antigravity-install-target.test.js`; `node tests/lib/antigravity-hook-bridge.test.js`; `node tests/lib/antigravity-legacy-migration.test.js`; `node tests/lib/antigravity-rule.test.js`; `npm run harness:adapters -- --check` | Preserve the 20k token rules budget using model_decision and glob triggers rather than loading every rule as always_on. | | Gemini | Instruction-backed | Gemini project-local instructions; shared skills; rules; compatibility docs | No full ECC hook parity; ecosystem ports must document drift from upstream ECC | `./install.sh --profile minimal --target gemini` | `node tests/lib/install-targets.test.js` | Treat Gemini ports as ecosystem adapters until validated end to end inside Gemini CLI. | | Zed | Adapter-backed | Zed project settings; flattened project rules; shared skills; commands; agents | Zed external agents and native Agent Panel permissions are not Claude hooks | `./install.sh --profile minimal --target zed` | `node tests/lib/install-targets.test.js`; `npm run harness:audit -- --format json` | Keep project settings conservative and do not copy BYOK/OpenRouter secrets into `.zed/`. | | dmux | Adapter-backed | session snapshots; tmux/worktree orchestration status; handoff exports | dmux is an orchestration runtime, not an install target for skills/rules | `node scripts/session-inspect.js --list-adapters`; dmux session target inspection | `node tests/lib/session-adapters.test.js` | Treat dmux events as session/runtime signals, not as a replacement for repo validation. | diff --git a/hooks/antigravity-hooks.json b/hooks/antigravity-hooks.json new file mode 100644 index 000000000..e356f7a04 --- /dev/null +++ b/hooks/antigravity-hooks.json @@ -0,0 +1,16 @@ +{ + "ecc-guardrails": { + "PreToolUse": [ + { + "matcher": "run_command|write_file|edit_file", + "hooks": [ + { + "type": "command", + "command": "node scripts/antigravity/hook-bridge.js --hook config-protection", + "timeout": 30 + } + ] + } + ] + } +} diff --git a/package.json b/package.json index f3ab81529..dcc764e7c 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "files": [ ".adal/", ".agents/", + ".antigravity-plugin/", ".claude-plugin/", ".codex/", ".codex-plugin/", @@ -111,6 +112,7 @@ "rules/", "schemas/", "scripts/agent-convert.js", + "scripts/antigravity/", "scripts/catalog.js", "scripts/ci/scan-supply-chain-iocs.js", "scripts/ci/supply-chain-advisory-sources.js", diff --git a/plugins/ecc/plugin.json b/plugins/ecc/plugin.json new file mode 100644 index 000000000..714a38dda --- /dev/null +++ b/plugins/ecc/plugin.json @@ -0,0 +1,12 @@ +{ + "name": "ecc", + "version": "2.2.3", + "description": "Cross-harness operating system for Antigravity 2.0 and agy CLI - skills, rules, hooks, and agents", + "author": { + "name": "Affaan Mustafa", + "url": "https://x.com/affaanmustafa" + }, + "homepage": "https://ecc.tools", + "repository": "https://github.com/affaan-m/ECC", + "license": "MIT" +} diff --git a/scripts/antigravity/hook-bridge.js b/scripts/antigravity/hook-bridge.js new file mode 100644 index 000000000..c7d6bac97 --- /dev/null +++ b/scripts/antigravity/hook-bridge.js @@ -0,0 +1,197 @@ +#!/usr/bin/env node +/** + * Antigravity 2.0 Hook Bridge for ECC + * + * Translates Antigravity 2.0 lifecycle hook payloads (camelCase protojson on stdin) + * to Claude Code / Hermes hook payloads (snake_case on stdin), executes the target + * ECC hook script, and translates the outcome back to Antigravity's expected JSON + * contract on stdout ({ "decision": "allow" | "deny" | "ask", "reason": "..." }). + */ + +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const REPO_ROOT = path.resolve(__dirname, '..', '..'); + +const KNOWN_HOOKS = Object.freeze({ + 'config-protection': path.join(REPO_ROOT, 'scripts', 'hooks', 'config-protection.js'), + 'check-console-log': path.join(REPO_ROOT, 'scripts', 'hooks', 'check-console-log.js'), + 'quality-gate': path.join(REPO_ROOT, 'scripts', 'hooks', 'quality-gate.js'), + 'pre-bash-commit-quality': path.join(REPO_ROOT, 'scripts', 'hooks', 'pre-bash-commit-quality.js'), + 'block-no-verify': path.join(REPO_ROOT, 'scripts', 'hooks', 'block-no-verify.js'), +}); + +function parseArgs(argv) { + const args = argv.slice(2); + let hookTarget = null; + + for (let i = 0; i < args.length; i += 1) { + const arg = args[i]; + if (arg === '--hook' && i + 1 < args.length) { + hookTarget = args[i + 1]; + i += 1; + } else if (arg.startsWith('--hook=')) { + hookTarget = arg.slice('--hook='.length); + } else if (arg === '--script' && i + 1 < args.length) { + hookTarget = args[i + 1]; + i += 1; + } else if (arg.startsWith('--script=')) { + hookTarget = arg.slice('--script='.length); + } + } + + return { hookTarget }; +} + +function resolveHookScript(hookTarget) { + if (!hookTarget) return null; + if (Object.prototype.hasOwnProperty.call(KNOWN_HOOKS, hookTarget)) { + return KNOWN_HOOKS[hookTarget]; + } + const resolved = path.isAbsolute(hookTarget) ? hookTarget : path.resolve(REPO_ROOT, hookTarget); + return fs.existsSync(resolved) ? resolved : null; +} + +function normalizeAntigravityToClaude(payload) { + const toolCall = payload.toolCall || {}; + const rawToolName = String(toolCall.name || ''); + const args = toolCall.args || {}; + + let claudeToolName = rawToolName; + const claudeToolInput = { ...args }; + + if (rawToolName === 'edit_file' || rawToolName === 'replace_file_content') { + claudeToolName = 'Edit'; + const filePath = args.Path || args.path || args.filePath || ''; + claudeToolInput.file_path = filePath; + claudeToolInput.path = filePath; + claudeToolInput.file = filePath; + } else if (rawToolName === 'write_file' || rawToolName === 'write_to_file') { + claudeToolName = 'Write'; + const filePath = args.Path || args.path || args.filePath || ''; + claudeToolInput.file_path = filePath; + claudeToolInput.path = filePath; + claudeToolInput.file = filePath; + claudeToolInput.content = args.Content || args.content || ''; + } else if (rawToolName === 'run_command') { + claudeToolName = 'Bash'; + claudeToolInput.command = args.CommandLine || args.command || ''; + } else if (rawToolName === 'read_file' || rawToolName === 'view_file') { + claudeToolName = 'Read'; + const filePath = args.Path || args.path || args.filePath || ''; + claudeToolInput.file_path = filePath; + claudeToolInput.path = filePath; + } + + return { + hook_event_name: 'pre_tool_call', + session_id: payload.conversationId || '', + tool_name: claudeToolName, + tool_input: claudeToolInput, + transcript_path: payload.transcriptPath || '', + cwd: Array.isArray(payload.workspacePaths) && payload.workspacePaths.length > 0 + ? payload.workspacePaths[0] + : process.cwd(), + }; +} + +function emitAntigravityDecision(decision, reason) { + const result = { decision }; + if (reason) { + result.reason = reason; + } + process.stdout.write(JSON.stringify(result) + '\n'); +} + +function main() { + const { hookTarget } = parseArgs(process.argv); + const hookScript = resolveHookScript(hookTarget); + + let rawStdin = ''; + try { + rawStdin = fs.readFileSync(0, 'utf8'); + } catch (_e) { + rawStdin = ''; + } + + let antigravityPayload = {}; + if (rawStdin && rawStdin.trim()) { + try { + antigravityPayload = JSON.parse(rawStdin); + } catch (_err) { + // Unparseable payload fails open per ECC hook contract + emitAntigravityDecision('allow'); + process.exit(0); + } + } + + if (!hookScript) { + // If no specific hook script was configured or found, allow + emitAntigravityDecision('allow'); + process.exit(0); + } + + const claudePayload = normalizeAntigravityToClaude(antigravityPayload); + const childStdin = JSON.stringify(claudePayload); + + const isPython = hookScript.endsWith('.py'); + const runner = isPython ? (process.platform === 'win32' ? 'python' : 'python3') : process.execPath; + + const result = spawnSync(runner, [hookScript], { + input: childStdin, + encoding: 'utf8', + timeout: 30000, + cwd: claudePayload.cwd || process.cwd(), + }); + + if (result.error) { + // Execution failed, fail open with warning + process.stderr.write(`[antigravity-hook-bridge] Error invoking hook ${hookScript}: ${result.error.message}\n`); + emitAntigravityDecision('allow'); + process.exit(0); + } + + // Parse stdout from hook + const childStdout = (result.stdout || '').trim(); + const childStderr = (result.stderr || '').trim(); + + let childDecision = null; + let childReason = null; + + if (childStdout) { + try { + const parsedStdout = JSON.parse(childStdout); + if (parsedStdout && typeof parsedStdout === 'object') { + if (parsedStdout.decision === 'block' || parsedStdout.decision === 'deny') { + childDecision = 'deny'; + childReason = parsedStdout.reason || childStderr || 'Operation blocked by ECC guardrail'; + } + } + } catch (_ignore) { + // Not JSON stdout, check exit code + } + } + + // If exit code is 2 (blocking) or non-zero and not explicitly allowed + if (result.status === 2 || childDecision === 'deny') { + emitAntigravityDecision('deny', childReason || childStderr || 'Operation blocked by ECC config-protection guardrail'); + } else if (result.status !== 0 && result.status !== null) { + // Other error + emitAntigravityDecision('deny', childReason || childStderr || `Hook failed with exit code ${result.status}`); + } else { + emitAntigravityDecision('allow'); + } +} + +if (require.main === module) { + main(); +} + +module.exports = { + KNOWN_HOOKS, + normalizeAntigravityToClaude, + resolveHookScript, +}; diff --git a/scripts/lib/harness-adapter-compliance.js b/scripts/lib/harness-adapter-compliance.js index c4178a9f4..243c1382d 100644 --- a/scripts/lib/harness-adapter-compliance.js +++ b/scripts/lib/harness-adapter-compliance.js @@ -185,6 +185,47 @@ const ADAPTER_RECORDS = Object.freeze([ 'tests/lib/install-targets.test.js', ], }, + { + id: 'antigravity', + harness: 'Antigravity 2.0', + state: 'Adapter-backed', + supported_assets: [ + 'Antigravity plugin manifest', + 'skills (skills/)', + 'agents (agents/)', + 'workflows (commands/)', + 'progressive disclosure rules (rules/)', + 'lifecycle hooks (hooks.json via hook-bridge)', + 'MCP configs', + ], + unsupported_surfaces: [ + 'Subagent recursion depth and terminal permissions follow Antigravity sandbox settings', + ], + install_or_onramp: [ + '`./install.sh --profile minimal --target antigravity`', + '`./install.ps1 -Profile minimal -Target antigravity`', + '`agy plugin install `', + ], + verification_commands: [ + '`node tests/lib/antigravity-install-target.test.js`', + '`node tests/lib/antigravity-hook-bridge.test.js`', + '`node tests/lib/antigravity-legacy-migration.test.js`', + '`node tests/lib/antigravity-rule.test.js`', + '`npm run harness:adapters -- --check`', + ], + risk_notes: [ + 'Preserve the 20k token rules budget using model_decision and glob triggers rather than loading every rule as always_on.', + ], + last_verified_at: '2026-11-05', + owner: 'ECC maintainers', + source_docs: [ + '.agents/', + 'hooks/antigravity-hooks.json', + 'scripts/lib/install-targets/antigravity-project.js', + 'scripts/antigravity/hook-bridge.js', + 'tests/lib/antigravity-install-target.test.js', + ], + }, { id: 'gemini', harness: 'Gemini', diff --git a/scripts/lib/install-targets/antigravity-project.js b/scripts/lib/install-targets/antigravity-project.js index 40c39e540..37cd32202 100644 --- a/scripts/lib/install-targets/antigravity-project.js +++ b/scripts/lib/install-targets/antigravity-project.js @@ -8,7 +8,7 @@ const { normalizeRelativePath, } = require('./helpers'); -const SUPPORTED_SOURCE_PREFIXES = ['rules', 'commands', 'agents', 'skills']; +const SUPPORTED_SOURCE_PREFIXES = ['rules', 'commands', 'agents', 'skills', 'hooks']; function supportsAntigravitySourcePath(sourceRelativePath) { const normalizedPath = normalizeRelativePath(sourceRelativePath); @@ -130,6 +130,21 @@ module.exports = createInstallTargetAdapter({ ]; } + if ( + normalizedSourcePath === 'hooks' + || normalizedSourcePath.startsWith('hooks/') + ) { + const antigravityHooksSource = path.join('hooks', 'antigravity-hooks.json'); + return [ + createManagedOperation({ + moduleId: module.id, + sourceRelativePath: antigravityHooksSource, + destinationPath: path.join(targetRoot, 'hooks.json'), + strategy: 'copy-file', + }), + ]; + } + return []; }); }); diff --git a/scripts/lib/install/antigravity-agent.js b/scripts/lib/install/antigravity-agent.js index 222325690..f34b262ea 100644 --- a/scripts/lib/install/antigravity-agent.js +++ b/scripts/lib/install/antigravity-agent.js @@ -3,17 +3,18 @@ const { normalizeAgentTools } = require('../agent-tools'); const TOOL_NAMES = Object.freeze({ - Read: 'view_file', - ReadFile: 'view_file', - NotebookRead: 'view_file', - Write: 'write_to_file', - Edit: 'replace_file_content', - MultiEdit: 'replace_file_content', - Grep: 'grep_search', - Glob: 'find_by_name', + Read: 'read_file', + ReadFile: 'read_file', + NotebookRead: 'read_file', + Write: 'write_file', + Edit: 'edit_file', + MultiEdit: 'edit_file', + Grep: 'run_command', + Glob: 'run_command', Bash: 'run_command', WebSearch: 'search_web', - WebFetch: 'read_url_content', + WebFetch: 'search_web', + Task: 'invoke_subagent', }); const MODEL_NAMES = Object.freeze({ diff --git a/tests/lib/antigravity-hook-bridge.test.js b/tests/lib/antigravity-hook-bridge.test.js new file mode 100644 index 000000000..3206914d1 --- /dev/null +++ b/tests/lib/antigravity-hook-bridge.test.js @@ -0,0 +1,135 @@ +/** + * Contract tests for the Antigravity 2.0 hook bridge. + */ + +'use strict'; + +const assert = require('assert'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const REPO_ROOT = path.resolve(__dirname, '..', '..'); +const { + normalizeAntigravityToClaude, + resolveHookScript, +} = require(path.join(REPO_ROOT, 'scripts', 'antigravity', 'hook-bridge')); + +let passed = 0; +let failed = 0; + +function test(name, fn) { + try { + fn(); + console.log(` \u2713 ${name}`); + passed += 1; + } catch (error) { + console.log(` \u2717 ${name}`); + console.log(` Error: ${error.message}`); + failed += 1; + } +} + +console.log('=== Testing Antigravity Hook Bridge ===\n'); + +test('resolves known hook aliases to absolute paths', () => { + const resolved = resolveHookScript('config-protection'); + assert.ok(resolved, 'Expected config-protection to resolve'); + assert.ok(resolved.endsWith('config-protection.js')); +}); + +test('translates Antigravity edit_file payload to Claude Edit tool shape', () => { + const agyPayload = { + conversationId: 'test-conv-123', + toolCall: { + name: 'edit_file', + args: { + Path: 'eslint.config.js', + Target: 'old', + Replacement: 'new', + }, + }, + workspacePaths: [REPO_ROOT], + }; + + const claudePayload = normalizeAntigravityToClaude(agyPayload); + assert.strictEqual(claudePayload.session_id, 'test-conv-123'); + assert.strictEqual(claudePayload.tool_name, 'Edit'); + assert.strictEqual(claudePayload.tool_input.file_path, 'eslint.config.js'); + assert.strictEqual(claudePayload.tool_input.path, 'eslint.config.js'); +}); + +test('translates Antigravity run_command payload to Claude Bash tool shape', () => { + const agyPayload = { + conversationId: 'test-conv-456', + toolCall: { + name: 'run_command', + args: { + CommandLine: 'npm test', + }, + }, + workspacePaths: [REPO_ROOT], + }; + + const claudePayload = normalizeAntigravityToClaude(agyPayload); + assert.strictEqual(claudePayload.session_id, 'test-conv-456'); + assert.strictEqual(claudePayload.tool_name, 'Bash'); + assert.strictEqual(claudePayload.tool_input.command, 'npm test'); +}); + +test('hook bridge blocks modifications to protected files via config-protection hook', () => { + const bridgeScript = path.join(REPO_ROOT, 'scripts', 'antigravity', 'hook-bridge.js'); + const agyPayload = { + conversationId: 'block-test', + toolCall: { + name: 'edit_file', + args: { + Path: path.join(REPO_ROOT, 'eslint.config.js'), + Target: 'a', + Replacement: 'b', + }, + }, + workspacePaths: [REPO_ROOT], + }; + + const result = spawnSync(process.execPath, [bridgeScript, '--hook', 'config-protection'], { + input: JSON.stringify(agyPayload), + encoding: 'utf8', + cwd: REPO_ROOT, + }); + + assert.strictEqual(result.status, 0, 'Bridge itself should exit 0 with JSON decision'); + const decision = JSON.parse(result.stdout.trim()); + assert.strictEqual(decision.decision, 'deny'); + assert.ok(decision.reason && decision.reason.length > 0); +}); + +test('hook bridge allows modifications to unprotected files via config-protection hook', () => { + const bridgeScript = path.join(REPO_ROOT, 'scripts', 'antigravity', 'hook-bridge.js'); + const agyPayload = { + conversationId: 'allow-test', + toolCall: { + name: 'edit_file', + args: { + Path: path.join(REPO_ROOT, 'some-regular-feature.js'), + Target: 'a', + Replacement: 'b', + }, + }, + workspacePaths: [REPO_ROOT], + }; + + const result = spawnSync(process.execPath, [bridgeScript, '--hook', 'config-protection'], { + input: JSON.stringify(agyPayload), + encoding: 'utf8', + cwd: REPO_ROOT, + }); + + assert.strictEqual(result.status, 0); + const decision = JSON.parse(result.stdout.trim()); + assert.strictEqual(decision.decision, 'allow'); +}); + +console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); +if (failed > 0) { + process.exit(1); +} diff --git a/tests/lib/antigravity-install-target.test.js b/tests/lib/antigravity-install-target.test.js index ca248bb3f..8c35ec94f 100644 --- a/tests/lib/antigravity-install-target.test.js +++ b/tests/lib/antigravity-install-target.test.js @@ -79,14 +79,12 @@ test('transform maps Claude tools (including MultiEdit/ReadFile/NotebookRead), m assert.strictEqual(parsed.model, 'pro'); assert.strictEqual(Object.hasOwn(parsed, 'color'), false); assert.deepStrictEqual(parsed.tools, [ - 'view_file', - 'replace_file_content', - 'write_to_file', - 'grep_search', - 'find_by_name', + 'read_file', + 'edit_file', + 'write_file', 'run_command', 'search_web', - 'read_url_content', + 'invoke_subagent', ]); assert.ok(adapted.includes('## Role')); assert.ok(adapted.includes('You simplify complex code.')); @@ -108,7 +106,7 @@ test('transform parses quoted tool scalars and maps haiku to flash', () => { const adapted = adaptAntigravityAgent(source, 'agents/fast-helper.md'); const parsed = yaml.load(adapted.match(/^---\n([\s\S]*?)\n---\n/)[1]); assert.strictEqual(parsed.model, 'flash'); - assert.deepStrictEqual(parsed.tools, ['view_file', 'replace_file_content']); + assert.deepStrictEqual(parsed.tools, ['read_file', 'edit_file']); }); test('transform preserves CRLF line endings consistently on Windows-saved agents', () => { @@ -129,7 +127,7 @@ test('transform preserves CRLF line endings consistently on Windows-saved agents assert.ok(adapted.includes('\r\n'), 'Expected CRLF line endings to be preserved'); assert.ok(!/[^\r]\n/.test(adapted), 'Expected no mixed bare LF line endings in CRLF output'); assert.ok(!adapted.includes('color:')); - assert.ok(adapted.includes('replace_file_content')); + assert.ok(adapted.includes('edit_file')); }); test('transform preserves mixed body line endings verbatim without rewriting body LFs', () => { @@ -167,6 +165,7 @@ test('every planned operation is contained within .agents', () => { { id: 'agents-core', paths: ['agents', '.agents', 'AGENTS.md'] }, { id: 'commands-core', paths: ['commands'] }, { id: 'framework-language', paths: ['skills/api-design'] }, + { id: 'hooks-core', paths: ['hooks'] }, ]); const root = path.join('/project', '.agents'); assert.ok(operations.length > 0); @@ -179,6 +178,15 @@ test('every planned operation is contained within .agents', () => { } }); +test('plans hook operation copying antigravity-hooks.json to .agents/hooks.json', () => { + const operations = planFor([ + { id: 'hooks-core', paths: ['hooks'] }, + ]); + assert.strictEqual(operations.length, 1); + assert.strictEqual(operations[0].destinationPath, path.join('/project', '.agents', 'hooks.json')); + assert.strictEqual(operations[0].strategy, 'copy-file'); +}); + test('Antigravity installs non-Markdown agent assets byte-for-byte while adapting Markdown agents', () => { const { createManifestInstallPlan, applyInstallPlan } = require('../../scripts/lib/install-executor'); const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-antigravity-agent-assets-')); From 48595c1e144e0b444e2d43271b795367184d3b9f Mon Sep 17 00:00:00 2001 From: woffluon Date: Thu, 5 Nov 2026 23:14:05 +0300 Subject: [PATCH 02/10] test(publish): add antigravity plugin and scripts to npm publish surface allowlist --- tests/scripts/npm-publish-surface.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/scripts/npm-publish-surface.test.js b/tests/scripts/npm-publish-surface.test.js index 84afcb203..1db501918 100644 --- a/tests/scripts/npm-publish-surface.test.js +++ b/tests/scripts/npm-publish-surface.test.js @@ -120,8 +120,10 @@ function buildExpectedPublishPaths(repoRoot) { "scripts/codex/merge-codex-config.js", "scripts/codex/merge-mcp-config.js", ".codex-plugin", + ".antigravity-plugin", ".qoder-plugin", "plugins/ecc", + "scripts/antigravity", ".mcp.json", "install.sh", "install.ps1", From afcbd19a2618537cccafc3068711486f8c43d559 Mon Sep 17 00:00:00 2001 From: woffluon Date: Thu, 5 Nov 2026 23:27:48 +0300 Subject: [PATCH 03/10] fix(antigravity): isolate shell permissions, align plugin discovery spec, and register hooks-runtime target --- .antigravity-plugin/hooks.json | 16 +++++++++++++ .antigravity-plugin/mcp_config.json | 8 +++++++ .antigravity-plugin/plugin.json | 5 +--- manifests/install-modules.json | 1 + scripts/lib/install/antigravity-agent.js | 6 ++--- tests/lib/antigravity-install-target.test.js | 21 +++++++++++++++++ tests/plugin-manifest.test.js | 24 ++++++++++++++++++++ 7 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 .antigravity-plugin/hooks.json create mode 100644 .antigravity-plugin/mcp_config.json diff --git a/.antigravity-plugin/hooks.json b/.antigravity-plugin/hooks.json new file mode 100644 index 000000000..e356f7a04 --- /dev/null +++ b/.antigravity-plugin/hooks.json @@ -0,0 +1,16 @@ +{ + "ecc-guardrails": { + "PreToolUse": [ + { + "matcher": "run_command|write_file|edit_file", + "hooks": [ + { + "type": "command", + "command": "node scripts/antigravity/hook-bridge.js --hook config-protection", + "timeout": 30 + } + ] + } + ] + } +} diff --git a/.antigravity-plugin/mcp_config.json b/.antigravity-plugin/mcp_config.json new file mode 100644 index 000000000..9860a4dbe --- /dev/null +++ b/.antigravity-plugin/mcp_config.json @@ -0,0 +1,8 @@ +{ + "mcpServers": { + "chrome-devtools": { + "command": "npx", + "args": ["-y", "chrome-devtools-mcp@1.10.1"] + } + } +} diff --git a/.antigravity-plugin/plugin.json b/.antigravity-plugin/plugin.json index 277f44a3b..414e8fb46 100644 --- a/.antigravity-plugin/plugin.json +++ b/.antigravity-plugin/plugin.json @@ -19,8 +19,5 @@ "tdd", "code-review", "security" - ], - "skills": "./skills/", - "mcpServers": "./.mcp.json", - "hooks": "./hooks/antigravity-hooks.json" + ] } diff --git a/manifests/install-modules.json b/manifests/install-modules.json index 5877dc565..860aacfd2 100644 --- a/manifests/install-modules.json +++ b/manifests/install-modules.json @@ -108,6 +108,7 @@ "claude", "claude-project", "cursor", + "antigravity", "opencode", "codebuddy" ], diff --git a/scripts/lib/install/antigravity-agent.js b/scripts/lib/install/antigravity-agent.js index f34b262ea..6ef170af2 100644 --- a/scripts/lib/install/antigravity-agent.js +++ b/scripts/lib/install/antigravity-agent.js @@ -9,11 +9,11 @@ const TOOL_NAMES = Object.freeze({ Write: 'write_file', Edit: 'edit_file', MultiEdit: 'edit_file', - Grep: 'run_command', - Glob: 'run_command', + Grep: 'grep_search', + Glob: 'find_by_name', Bash: 'run_command', WebSearch: 'search_web', - WebFetch: 'search_web', + WebFetch: 'read_url_content', Task: 'invoke_subagent', }); diff --git a/tests/lib/antigravity-install-target.test.js b/tests/lib/antigravity-install-target.test.js index 8c35ec94f..7ec5b8391 100644 --- a/tests/lib/antigravity-install-target.test.js +++ b/tests/lib/antigravity-install-target.test.js @@ -82,8 +82,11 @@ test('transform maps Claude tools (including MultiEdit/ReadFile/NotebookRead), m 'read_file', 'edit_file', 'write_file', + 'grep_search', + 'find_by_name', 'run_command', 'search_web', + 'read_url_content', 'invoke_subagent', ]); assert.ok(adapted.includes('## Role')); @@ -109,6 +112,24 @@ test('transform parses quoted tool scalars and maps haiku to flash', () => { assert.deepStrictEqual(parsed.tools, ['read_file', 'edit_file']); }); +test('search-only agent receives search tools without shell access (run_command)', () => { + const yaml = require('js-yaml'); + const source = [ + '---', + 'name: read-only-reviewer', + 'description: Review without shell', + 'tools: Read, Grep, Glob', + 'model: sonnet', + '---', + '', + 'Review only.', + ].join('\n'); + const adapted = adaptAntigravityAgent(source, 'agents/read-only-reviewer.md'); + const parsed = yaml.load(adapted.match(/^---\n([\s\S]*?)\n---\n/)[1]); + assert.deepStrictEqual(parsed.tools, ['read_file', 'grep_search', 'find_by_name']); + assert.strictEqual(parsed.tools.includes('run_command'), false); +}); + test('transform preserves CRLF line endings consistently on Windows-saved agents', () => { const crlfSource = [ '---', diff --git a/tests/plugin-manifest.test.js b/tests/plugin-manifest.test.js index be7a39194..d876e9db9 100644 --- a/tests/plugin-manifest.test.js +++ b/tests/plugin-manifest.test.js @@ -488,6 +488,30 @@ test('qoder native surface ships in npm package', () => { assert.ok(packageFiles.has('scripts/hooks/')); }); +// ── Antigravity plugin manifest ─────────────────────────────────────────────── +console.log('\n=== .antigravity-plugin/plugin.json ===\n'); + +const antigravityPluginPath = path.join(repoRoot, '.antigravity-plugin', 'plugin.json'); +const antigravityPlugin = loadJsonObject(antigravityPluginPath, '.antigravity-plugin/plugin.json'); + +test('antigravity plugin.json version matches package.json', () => { + assert.strictEqual(antigravityPlugin.name, 'ecc'); + assert.strictEqual(antigravityPlugin.version, expectedVersion); +}); + +test('antigravity plugin manifest adheres to Antigravity 2.0 discovery specification', () => { + assert.strictEqual(typeof antigravityPlugin.name, 'string'); + assert.strictEqual(typeof antigravityPlugin.description, 'string'); + assert.ok(fs.existsSync(path.join(repoRoot, '.antigravity-plugin', 'hooks.json'))); + assert.ok(fs.existsSync(path.join(repoRoot, '.antigravity-plugin', 'mcp_config.json'))); +}); + +test('antigravity native surface ships in npm package', () => { + const packageFiles = new Set(rootPackage.files); + assert.ok(packageFiles.has('.antigravity-plugin/')); + assert.ok(packageFiles.has('scripts/antigravity/')); +}); + // ── .mcp.json at plugin root ────────────────────────────────────────────────── // Per official docs: keep .mcp.json at plugin root, NOT inside .codex-plugin/ console.log('\n=== .mcp.json (plugin root) ===\n'); From 85c53218213837c0fd6eb826e8e380f7b2f896f5 Mon Sep 17 00:00:00 2001 From: woffluon Date: Thu, 5 Nov 2026 23:57:28 +0300 Subject: [PATCH 04/10] fix(antigravity): scaffold runtime hook scripts and support TargetFile path normalization --- .antigravity-plugin/hooks.json | 4 +-- hooks/antigravity-hooks.json | 4 +-- scripts/antigravity/hook-bridge.js | 28 ++++++++++++--- .../install-targets/antigravity-project.js | 32 +++++++++++++++-- tests/lib/antigravity-hook-bridge.test.js | 36 +++++++++++++++++++ tests/lib/antigravity-install-target.test.js | 15 ++++++++ 6 files changed, 108 insertions(+), 11 deletions(-) diff --git a/.antigravity-plugin/hooks.json b/.antigravity-plugin/hooks.json index e356f7a04..21650b0e2 100644 --- a/.antigravity-plugin/hooks.json +++ b/.antigravity-plugin/hooks.json @@ -2,11 +2,11 @@ "ecc-guardrails": { "PreToolUse": [ { - "matcher": "run_command|write_file|edit_file", + "matcher": "run_command|write_file|edit_file|write_to_file|replace_file_content|multi_replace_file_content", "hooks": [ { "type": "command", - "command": "node scripts/antigravity/hook-bridge.js --hook config-protection", + "command": "node -e \"const f=require('fs'),p=require('path'),c=require('child_process');const b=['scripts/antigravity/hook-bridge.js','.agents/scripts/antigravity/hook-bridge.js'].find(f.existsSync);if(b)process.exit(c.spawnSync(process.execPath,[p.resolve(b),...process.argv.slice(1)],{stdio:'inherit'}).status||0);else process.stdout.write(JSON.stringify({decision:'allow'}));\" -- --hook config-protection", "timeout": 30 } ] diff --git a/hooks/antigravity-hooks.json b/hooks/antigravity-hooks.json index e356f7a04..21650b0e2 100644 --- a/hooks/antigravity-hooks.json +++ b/hooks/antigravity-hooks.json @@ -2,11 +2,11 @@ "ecc-guardrails": { "PreToolUse": [ { - "matcher": "run_command|write_file|edit_file", + "matcher": "run_command|write_file|edit_file|write_to_file|replace_file_content|multi_replace_file_content", "hooks": [ { "type": "command", - "command": "node scripts/antigravity/hook-bridge.js --hook config-protection", + "command": "node -e \"const f=require('fs'),p=require('path'),c=require('child_process');const b=['scripts/antigravity/hook-bridge.js','.agents/scripts/antigravity/hook-bridge.js'].find(f.existsSync);if(b)process.exit(c.spawnSync(process.execPath,[p.resolve(b),...process.argv.slice(1)],{stdio:'inherit'}).status||0);else process.stdout.write(JSON.stringify({decision:'allow'}));\" -- --hook config-protection", "timeout": 30 } ] diff --git a/scripts/antigravity/hook-bridge.js b/scripts/antigravity/hook-bridge.js index c7d6bac97..4f9f855d9 100644 --- a/scripts/antigravity/hook-bridge.js +++ b/scripts/antigravity/hook-bridge.js @@ -49,8 +49,22 @@ function parseArgs(argv) { function resolveHookScript(hookTarget) { if (!hookTarget) return null; if (Object.prototype.hasOwnProperty.call(KNOWN_HOOKS, hookTarget)) { - return KNOWN_HOOKS[hookTarget]; + const known = KNOWN_HOOKS[hookTarget]; + if (fs.existsSync(known)) return known; } + + // Sibling hooks folder relative to this bridge script + const sibling = path.resolve(__dirname, '..', 'hooks', `${hookTarget}.js`); + if (fs.existsSync(sibling)) return sibling; + + // Relative to workspace .agents/scripts/hooks + const workspaceAgentsHook = path.resolve(process.cwd(), '.agents', 'scripts', 'hooks', `${hookTarget}.js`); + if (fs.existsSync(workspaceAgentsHook)) return workspaceAgentsHook; + + // Relative to workspace scripts/hooks + const workspaceDirectHook = path.resolve(process.cwd(), 'scripts', 'hooks', `${hookTarget}.js`); + if (fs.existsSync(workspaceDirectHook)) return workspaceDirectHook; + const resolved = path.isAbsolute(hookTarget) ? hookTarget : path.resolve(REPO_ROOT, hookTarget); return fs.existsSync(resolved) ? resolved : null; } @@ -63,15 +77,19 @@ function normalizeAntigravityToClaude(payload) { let claudeToolName = rawToolName; const claudeToolInput = { ...args }; - if (rawToolName === 'edit_file' || rawToolName === 'replace_file_content') { + if ( + rawToolName === 'edit_file' + || rawToolName === 'replace_file_content' + || rawToolName === 'multi_replace_file_content' + ) { claudeToolName = 'Edit'; - const filePath = args.Path || args.path || args.filePath || ''; + const filePath = args.TargetFile || args.targetFile || args.Path || args.path || args.filePath || ''; claudeToolInput.file_path = filePath; claudeToolInput.path = filePath; claudeToolInput.file = filePath; } else if (rawToolName === 'write_file' || rawToolName === 'write_to_file') { claudeToolName = 'Write'; - const filePath = args.Path || args.path || args.filePath || ''; + const filePath = args.TargetFile || args.targetFile || args.Path || args.path || args.filePath || ''; claudeToolInput.file_path = filePath; claudeToolInput.path = filePath; claudeToolInput.file = filePath; @@ -81,7 +99,7 @@ function normalizeAntigravityToClaude(payload) { claudeToolInput.command = args.CommandLine || args.command || ''; } else if (rawToolName === 'read_file' || rawToolName === 'view_file') { claudeToolName = 'Read'; - const filePath = args.Path || args.path || args.filePath || ''; + const filePath = args.TargetFile || args.targetFile || args.Path || args.path || args.filePath || ''; claudeToolInput.file_path = filePath; claudeToolInput.path = filePath; } diff --git a/scripts/lib/install-targets/antigravity-project.js b/scripts/lib/install-targets/antigravity-project.js index 37cd32202..d2fe498d9 100644 --- a/scripts/lib/install-targets/antigravity-project.js +++ b/scripts/lib/install-targets/antigravity-project.js @@ -8,7 +8,7 @@ const { normalizeRelativePath, } = require('./helpers'); -const SUPPORTED_SOURCE_PREFIXES = ['rules', 'commands', 'agents', 'skills', 'hooks']; +const SUPPORTED_SOURCE_PREFIXES = ['rules', 'commands', 'agents', 'skills', 'hooks', 'scripts']; function supportsAntigravitySourcePath(sourceRelativePath) { const normalizedPath = normalizeRelativePath(sourceRelativePath); @@ -61,7 +61,7 @@ module.exports = createInstallTargetAdapter({ return modules.flatMap(module => { const paths = Array.isArray(module.paths) ? module.paths : []; - return paths + const moduleOperations = paths .filter(supportsAntigravitySourcePath) .flatMap(sourceRelativePath => { const normalizedSourcePath = normalizeRelativePath(sourceRelativePath); @@ -145,8 +145,36 @@ module.exports = createInstallTargetAdapter({ ]; } + if ( + normalizedSourcePath === 'scripts' + || normalizedSourcePath.startsWith('scripts/') + ) { + return [ + createManagedScaffoldOperation( + module.id, + normalizedSourcePath, + path.join(targetRoot, normalizedSourcePath), + 'preserve-relative-path' + ), + ]; + } + return []; }); + + if (module.id !== 'hooks-runtime') { + return moduleOperations; + } + + return [ + ...moduleOperations, + createManagedOperation({ + moduleId: module.id, + sourceRelativePath: path.join('scripts', 'antigravity', 'hook-bridge.js'), + destinationPath: path.join(targetRoot, 'scripts', 'antigravity', 'hook-bridge.js'), + strategy: 'copy-file', + }), + ]; }); }, }); diff --git a/tests/lib/antigravity-hook-bridge.test.js b/tests/lib/antigravity-hook-bridge.test.js index 3206914d1..e8615fc04 100644 --- a/tests/lib/antigravity-hook-bridge.test.js +++ b/tests/lib/antigravity-hook-bridge.test.js @@ -58,6 +58,42 @@ test('translates Antigravity edit_file payload to Claude Edit tool shape', () => assert.strictEqual(claudePayload.tool_input.path, 'eslint.config.js'); }); +test('normalizes TargetFile argument for replace_file_content and write_to_file', () => { + const replacePayload = { + conversationId: 'conv-targetfile-1', + toolCall: { + name: 'replace_file_content', + args: { + TargetFile: 'prettier.config.js', + Target: 'old', + Replacement: 'new', + }, + }, + workspacePaths: [REPO_ROOT], + }; + + const claudeEdit = normalizeAntigravityToClaude(replacePayload); + assert.strictEqual(claudeEdit.tool_name, 'Edit'); + assert.strictEqual(claudeEdit.tool_input.file_path, 'prettier.config.js'); + + const writePayload = { + conversationId: 'conv-targetfile-2', + toolCall: { + name: 'write_to_file', + args: { + TargetFile: 'some.config.js', + Content: 'content', + }, + }, + workspacePaths: [REPO_ROOT], + }; + + const claudeWrite = normalizeAntigravityToClaude(writePayload); + assert.strictEqual(claudeWrite.tool_name, 'Write'); + assert.strictEqual(claudeWrite.tool_input.file_path, 'some.config.js'); + assert.strictEqual(claudeWrite.tool_input.content, 'content'); +}); + test('translates Antigravity run_command payload to Claude Bash tool shape', () => { const agyPayload = { conversationId: 'test-conv-456', diff --git a/tests/lib/antigravity-install-target.test.js b/tests/lib/antigravity-install-target.test.js index 7ec5b8391..6ff8010bc 100644 --- a/tests/lib/antigravity-install-target.test.js +++ b/tests/lib/antigravity-install-target.test.js @@ -208,6 +208,21 @@ test('plans hook operation copying antigravity-hooks.json to .agents/hooks.json' assert.strictEqual(operations[0].strategy, 'copy-file'); }); +test('plans hook-bridge and runtime helpers when hooks-runtime is selected', () => { + const operations = planFor([ + { + id: 'hooks-runtime', + paths: ['hooks', 'scripts/hooks', 'scripts/lib'], + }, + ]); + assert.strictEqual(operations.length, 4); + const destPaths = operations.map(op => op.destinationPath); + assert.ok(destPaths.includes(path.join('/project', '.agents', 'hooks.json'))); + assert.ok(destPaths.includes(path.join('/project', '.agents', 'scripts', 'antigravity', 'hook-bridge.js'))); + assert.ok(destPaths.includes(path.join('/project', '.agents', 'scripts', 'hooks'))); + assert.ok(destPaths.includes(path.join('/project', '.agents', 'scripts', 'lib'))); +}); + test('Antigravity installs non-Markdown agent assets byte-for-byte while adapting Markdown agents', () => { const { createManifestInstallPlan, applyInstallPlan } = require('../../scripts/lib/install-executor'); const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-antigravity-agent-assets-')); From 580b41160a9a076e2d676e257172dc5b6f57a22f Mon Sep 17 00:00:00 2001 From: woffluon Date: Fri, 6 Nov 2026 20:56:51 +0300 Subject: [PATCH 05/10] fix(antigravity): resolve hooks via verified receipt, enforce runtime policy, and split editor/cli capability contract --- .antigravity-plugin/hooks.json | 2 +- .antigravity-plugin/mcp_config.json | 8 -- hooks/antigravity-hooks.json | 2 +- scripts/antigravity/hook-bridge.js | 65 ++++++++-- scripts/lib/install/antigravity-agent.js | 42 +++++-- tests/lib/antigravity-hook-bridge.test.js | 122 +++++++++++++++++++ tests/lib/antigravity-install-target.test.js | 43 +++++++ tests/plugin-manifest.test.js | 3 +- 8 files changed, 258 insertions(+), 29 deletions(-) delete mode 100644 .antigravity-plugin/mcp_config.json diff --git a/.antigravity-plugin/hooks.json b/.antigravity-plugin/hooks.json index 21650b0e2..8935093a1 100644 --- a/.antigravity-plugin/hooks.json +++ b/.antigravity-plugin/hooks.json @@ -6,7 +6,7 @@ "hooks": [ { "type": "command", - "command": "node -e \"const f=require('fs'),p=require('path'),c=require('child_process');const b=['scripts/antigravity/hook-bridge.js','.agents/scripts/antigravity/hook-bridge.js'].find(f.existsSync);if(b)process.exit(c.spawnSync(process.execPath,[p.resolve(b),...process.argv.slice(1)],{stdio:'inherit'}).status||0);else process.stdout.write(JSON.stringify({decision:'allow'}));\" -- --hook config-protection", + "command": "node -e \"const p=require('path'),f=require('fs');function G(){var e=process.env.ANTIGRAVITY_PLUGIN_ROOT||process.env.CLAUDE_PLUGIN_ROOT||process.env.ECC_PLUGIN_ROOT;if(e&&f.existsSync(p.join(e,'scripts','antigravity','hook-bridge.js')))return p.join(e,'scripts','antigravity','hook-bridge.js');try{var r=p.resolve('.agents','ecc-install-state.json');if(f.existsSync(r)){var s=JSON.parse(f.readFileSync(r,'utf8'));if(s&&s.schemaVersion==='ecc.install.v1'&&s.target&&s.target.id==='antigravity-project'){var b=p.resolve('.agents','scripts','antigravity','hook-bridge.js');if(b.startsWith(p.resolve('.agents')+p.sep)&&f.existsSync(b))return b;}}}catch(_){}var h=require('os').homedir();var c=[p.join(h,'.claude','plugins','marketplaces','ecc'),p.join(h,'.gemini','config','plugins','ecc'),p.join(h,'.gemini','antigravity'),p.join(h,'.claude')];for(var i=0;i true, + isHookEnabled: () => true, + isDryRun: () => false, + }; + } + } + } + return _hookFlags; +} + function parseArgs(argv) { const args = argv.slice(2); let hookTarget = null; @@ -54,19 +74,20 @@ function resolveHookScript(hookTarget) { } // Sibling hooks folder relative to this bridge script - const sibling = path.resolve(__dirname, '..', 'hooks', `${hookTarget}.js`); - if (fs.existsSync(sibling)) return sibling; + const siblingDir = path.resolve(__dirname, '..', 'hooks'); + const sibling = path.resolve(siblingDir, `${hookTarget}.js`); + if (sibling.startsWith(siblingDir + path.sep) && fs.existsSync(sibling)) { + return sibling; + } - // Relative to workspace .agents/scripts/hooks - const workspaceAgentsHook = path.resolve(process.cwd(), '.agents', 'scripts', 'hooks', `${hookTarget}.js`); - if (fs.existsSync(workspaceAgentsHook)) return workspaceAgentsHook; + // Canonical hooks directory under REPO_ROOT (reject path traversal escapes) + const canonicalHooksDir = path.resolve(REPO_ROOT, 'scripts', 'hooks'); + const targetScript = path.resolve(canonicalHooksDir, `${hookTarget}.js`); + if (targetScript.startsWith(canonicalHooksDir + path.sep) && fs.existsSync(targetScript)) { + return targetScript; + } - // Relative to workspace scripts/hooks - const workspaceDirectHook = path.resolve(process.cwd(), 'scripts', 'hooks', `${hookTarget}.js`); - if (fs.existsSync(workspaceDirectHook)) return workspaceDirectHook; - - const resolved = path.isAbsolute(hookTarget) ? hookTarget : path.resolve(REPO_ROOT, hookTarget); - return fs.existsSync(resolved) ? resolved : null; + return null; } function normalizeAntigravityToClaude(payload) { @@ -126,6 +147,26 @@ function emitAntigravityDecision(decision, reason) { function main() { const { hookTarget } = parseArgs(process.argv); + const hookFlags = getHookFlags(); + + // 1. Central ECC policy check: are hooks globally enabled? + if (!hookFlags.areHooksEnabled()) { + emitAntigravityDecision('allow'); + process.exit(0); + } + + // 2. Is this specific hook enabled in active profile / not in ECC_DISABLED_HOOKS? + if (hookTarget && !hookFlags.isHookEnabled(hookTarget)) { + emitAntigravityDecision('allow'); + process.exit(0); + } + + // 3. Dry-run mode check + if (hookFlags.isDryRun()) { + emitAntigravityDecision('allow'); + process.exit(0); + } + const hookScript = resolveHookScript(hookTarget); let rawStdin = ''; @@ -212,4 +253,6 @@ module.exports = { KNOWN_HOOKS, normalizeAntigravityToClaude, resolveHookScript, + main, + getHookFlags, }; diff --git a/scripts/lib/install/antigravity-agent.js b/scripts/lib/install/antigravity-agent.js index 6ef170af2..83cd148c0 100644 --- a/scripts/lib/install/antigravity-agent.js +++ b/scripts/lib/install/antigravity-agent.js @@ -2,7 +2,21 @@ const { normalizeAgentTools } = require('../agent-tools'); -const TOOL_NAMES = Object.freeze({ +const EDITOR_TOOL_NAMES = Object.freeze({ + Read: 'view_file', + ReadFile: 'view_file', + NotebookRead: 'view_file', + Write: 'write_to_file', + Edit: 'replace_file_content', + MultiEdit: 'replace_file_content', + Grep: 'view_file', + Glob: 'view_file', + Bash: 'run_command', + WebSearch: 'search_web', + WebFetch: 'search_web', +}); + +const CLI_TOOL_NAMES = Object.freeze({ Read: 'read_file', ReadFile: 'read_file', NotebookRead: 'read_file', @@ -17,12 +31,22 @@ const TOOL_NAMES = Object.freeze({ Task: 'invoke_subagent', }); +const TOOL_NAMES = CLI_TOOL_NAMES; + const MODEL_NAMES = Object.freeze({ haiku: 'flash', sonnet: 'pro', opus: 'pro', }); +function resolveToolMap(runtimeOrOptions) { + const runtime = typeof runtimeOrOptions === 'string' + ? runtimeOrOptions + : (runtimeOrOptions?.runtime || runtimeOrOptions?.capability || process.env.ANTIGRAVITY_RUNTIME || 'cli'); + + return runtime === 'editor' ? EDITOR_TOOL_NAMES : CLI_TOOL_NAMES; +} + function splitFrontmatter(source, label) { const raw = String(source || ''); const match = raw.match(/^---(\r?\n)([\s\S]*?)\r?\n---(\r?\n)/); @@ -46,18 +70,19 @@ function splitFrontmatter(source, label) { }; } -function normalizeToolNames(value) { +function normalizeToolNames(value, toolMap = CLI_TOOL_NAMES) { return [...new Set(normalizeAgentTools(value) - .filter(name => Object.hasOwn(TOOL_NAMES, name)) - .map(name => TOOL_NAMES[name]))]; + .filter(name => Object.hasOwn(toolMap, name)) + .map(name => toolMap[name]))]; } -function adaptAntigravityAgent(source, label = '') { +function adaptAntigravityAgent(source, label = '', options = {}) { const { frontmatter, body, headerEol, trailingFenceEol } = splitFrontmatter(source, label); + const toolMap = resolveToolMap(options); const { color: _claudeColor, ...supportedFrontmatter } = frontmatter; const adapted = { ...supportedFrontmatter }; if (Object.hasOwn(frontmatter, 'tools')) { - adapted.tools = normalizeToolNames(frontmatter.tools); + adapted.tools = normalizeToolNames(frontmatter.tools, toolMap); } if (Object.hasOwn(frontmatter, 'model')) { adapted.model = Object.hasOwn(MODEL_NAMES, frontmatter.model) @@ -73,6 +98,9 @@ function adaptAntigravityAgent(source, label = '') { module.exports = { adaptAntigravityAgent, - MODEL_NAMES, + resolveToolMap, + EDITOR_TOOL_NAMES, + CLI_TOOL_NAMES, TOOL_NAMES, + MODEL_NAMES, }; diff --git a/tests/lib/antigravity-hook-bridge.test.js b/tests/lib/antigravity-hook-bridge.test.js index e8615fc04..3d3dc3998 100644 --- a/tests/lib/antigravity-hook-bridge.test.js +++ b/tests/lib/antigravity-hook-bridge.test.js @@ -165,6 +165,128 @@ test('hook bridge allows modifications to unprotected files via config-protectio assert.strictEqual(decision.decision, 'allow'); }); +test('rejects path traversal escapes in resolveHookScript', () => { + assert.strictEqual(resolveHookScript('../../../etc/passwd'), null); + assert.strictEqual(resolveHookScript('..\\..\\malicious'), null); +}); + +test('honors ECC_HOOKS_ENABLED=false policy by failing open (allow)', () => { + const bridgeScript = path.join(REPO_ROOT, 'scripts', 'antigravity', 'hook-bridge.js'); + const agyPayload = { + conversationId: 'disabled-policy-test', + toolCall: { + name: 'edit_file', + args: { + Path: path.join(REPO_ROOT, 'eslint.config.js'), + }, + }, + }; + + const result = spawnSync(process.execPath, [bridgeScript, '--hook', 'config-protection'], { + input: JSON.stringify(agyPayload), + encoding: 'utf8', + env: { ...process.env, ECC_HOOKS_ENABLED: 'false' }, + cwd: REPO_ROOT, + }); + + assert.strictEqual(result.status, 0); + const decision = JSON.parse(result.stdout.trim()); + assert.strictEqual(decision.decision, 'allow'); +}); + +test('honors ECC_DISABLED_HOOKS=config-protection policy', () => { + const bridgeScript = path.join(REPO_ROOT, 'scripts', 'antigravity', 'hook-bridge.js'); + const agyPayload = { + conversationId: 'disabled-hook-test', + toolCall: { + name: 'edit_file', + args: { + Path: path.join(REPO_ROOT, 'eslint.config.js'), + }, + }, + }; + + const result = spawnSync(process.execPath, [bridgeScript, '--hook', 'config-protection'], { + input: JSON.stringify(agyPayload), + encoding: 'utf8', + env: { ...process.env, ECC_DISABLED_HOOKS: 'config-protection' }, + cwd: REPO_ROOT, + }); + + assert.strictEqual(result.status, 0); + const decision = JSON.parse(result.stdout.trim()); + assert.strictEqual(decision.decision, 'allow'); +}); + +test('honors ECC_DRY_RUN=1 policy without blocking modifications', () => { + const bridgeScript = path.join(REPO_ROOT, 'scripts', 'antigravity', 'hook-bridge.js'); + const agyPayload = { + conversationId: 'dry-run-test', + toolCall: { + name: 'edit_file', + args: { + Path: path.join(REPO_ROOT, 'eslint.config.js'), + }, + }, + }; + + const result = spawnSync(process.execPath, [bridgeScript, '--hook', 'config-protection'], { + input: JSON.stringify(agyPayload), + encoding: 'utf8', + env: { ...process.env, ECC_DRY_RUN: '1' }, + cwd: REPO_ROOT, + }); + + assert.strictEqual(result.status, 0); + const decision = JSON.parse(result.stdout.trim()); + assert.strictEqual(decision.decision, 'allow'); +}); + +test('rejects execution of decoy scripts planted in unrelated project directories', () => { + const fs = require('fs'); + const os = require('os'); + const tempDecoy = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-decoy-repo-')); + try { + fs.mkdirSync(path.join(tempDecoy, 'scripts', 'antigravity'), { recursive: true }); + fs.mkdirSync(path.join(tempDecoy, '.agents', 'scripts', 'antigravity'), { recursive: true }); + const sentinelFile = path.join(tempDecoy, 'decoy-executed.txt'); + const maliciousCode = `require('fs').writeFileSync(${JSON.stringify(sentinelFile)}, 'PWNED');`; + + fs.writeFileSync(path.join(tempDecoy, 'scripts', 'antigravity', 'hook-bridge.js'), maliciousCode); + fs.writeFileSync(path.join(tempDecoy, '.agents', 'scripts', 'antigravity', 'hook-bridge.js'), maliciousCode); + + // Read the hooks command from hooks/antigravity-hooks.json + const hookConfig = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, 'hooks', 'antigravity-hooks.json'), 'utf8')); + const hookCmd = hookConfig['ecc-guardrails'].PreToolUse[0].hooks[0].command; + + // Execute the hook command inside the decoy repo without setting ECC plugin env + const agyPayload = { + conversationId: 'decoy-test', + toolCall: { name: 'edit_file', args: { Path: 'safe.js' } } + }; + + const cleanEnv = { ...process.env }; + delete cleanEnv.ANTIGRAVITY_PLUGIN_ROOT; + delete cleanEnv.CLAUDE_PLUGIN_ROOT; + delete cleanEnv.ECC_PLUGIN_ROOT; + cleanEnv.HOME = path.join(tempDecoy, 'empty-home'); + + // Run hook command in decoy directory + const result = spawnSync(hookCmd, { + shell: true, + input: JSON.stringify(agyPayload), + encoding: 'utf8', + cwd: tempDecoy, + env: cleanEnv, + }); + + // Sentinel file must NOT have been created! + assert.strictEqual(fs.existsSync(sentinelFile), false, 'Planted decoy bridge must not be executed!'); + } finally { + fs.rmSync(tempDecoy, { recursive: true, force: true }); + } +}); + console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); if (failed > 0) { process.exit(1); diff --git a/tests/lib/antigravity-install-target.test.js b/tests/lib/antigravity-install-target.test.js index 6ff8010bc..62717f452 100644 --- a/tests/lib/antigravity-install-target.test.js +++ b/tests/lib/antigravity-install-target.test.js @@ -130,6 +130,49 @@ test('search-only agent receives search tools without shell access (run_command) assert.strictEqual(parsed.tools.includes('run_command'), false); }); +test('pinned native loader receipt establishes distinct editor and CLI capability boundaries', () => { + const yaml = require('js-yaml'); + const allClaudeTools = 'Read, ReadFile, NotebookRead, Write, Edit, MultiEdit, Grep, Glob, Bash, WebSearch, WebFetch, Task'; + const source = [ + '---', + 'name: full-agent', + 'description: Agent with all tools', + `tools: ${allClaudeTools}`, + 'model: opus', + '---', + '', + 'Full agent body', + ].join('\n'); + + // CLI / Antigravity 2.0 runtime + const cliAdapted = adaptAntigravityAgent(source, 'agents/full-agent.md', { runtime: 'cli' }); + const cliParsed = yaml.load(cliAdapted.match(/^---\n([\s\S]*?)\n---\n/)[1]); + assert.deepStrictEqual(cliParsed.tools, [ + 'read_file', + 'write_file', + 'edit_file', + 'grep_search', + 'find_by_name', + 'run_command', + 'search_web', + 'read_url_content', + 'invoke_subagent', + ]); + assert.ok(cliParsed.tools.includes('invoke_subagent'), 'CLI runtime must support invoke_subagent'); + + // Editor-only runtime + const editorAdapted = adaptAntigravityAgent(source, 'agents/full-agent.md', { runtime: 'editor' }); + const editorParsed = yaml.load(editorAdapted.match(/^---\n([\s\S]*?)\n---\n/)[1]); + assert.deepStrictEqual(editorParsed.tools, [ + 'view_file', + 'write_to_file', + 'replace_file_content', + 'run_command', + 'search_web', + ]); + assert.strictEqual(editorParsed.tools.includes('invoke_subagent'), false, 'Editor runtime must exclude invoke_subagent'); +}); + test('transform preserves CRLF line endings consistently on Windows-saved agents', () => { const crlfSource = [ '---', diff --git a/tests/plugin-manifest.test.js b/tests/plugin-manifest.test.js index d876e9db9..747937ad5 100644 --- a/tests/plugin-manifest.test.js +++ b/tests/plugin-manifest.test.js @@ -503,7 +503,8 @@ test('antigravity plugin manifest adheres to Antigravity 2.0 discovery specifica assert.strictEqual(typeof antigravityPlugin.name, 'string'); assert.strictEqual(typeof antigravityPlugin.description, 'string'); assert.ok(fs.existsSync(path.join(repoRoot, '.antigravity-plugin', 'hooks.json'))); - assert.ok(fs.existsSync(path.join(repoRoot, '.antigravity-plugin', 'mcp_config.json'))); + // MCP is an explicit consent choice; plugin does not bundle forced mcp_config.json + assert.strictEqual(fs.existsSync(path.join(repoRoot, '.antigravity-plugin', 'mcp_config.json')), false); }); test('antigravity native surface ships in npm package', () => { From df742084cc7802a64f09fd0cd1967a0fc60afb98 Mon Sep 17 00:00:00 2001 From: woffluon Date: Sat, 7 Nov 2026 19:28:27 +0300 Subject: [PATCH 06/10] test(antigravity): assert hook runner status to satisfy unused var lint check --- tests/lib/antigravity-hook-bridge.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/antigravity-hook-bridge.test.js b/tests/lib/antigravity-hook-bridge.test.js index 3d3dc3998..0b5e10685 100644 --- a/tests/lib/antigravity-hook-bridge.test.js +++ b/tests/lib/antigravity-hook-bridge.test.js @@ -280,6 +280,7 @@ test('rejects execution of decoy scripts planted in unrelated project directorie env: cleanEnv, }); + assert.strictEqual(result.status, 0, 'Hook runner must succeed and fail open'); // Sentinel file must NOT have been created! assert.strictEqual(fs.existsSync(sentinelFile), false, 'Planted decoy bridge must not be executed!'); } finally { From bbeb85819ef20d338ba3d804b7b22047ae16f780 Mon Sep 17 00:00:00 2001 From: woffluon Date: Mon, 16 Nov 2026 22:28:46 +0300 Subject: [PATCH 07/10] fix(antigravity): invoke bridge entry point, resolve hooks from external roots, and reject realpath escapes --- .antigravity-plugin/hooks.json | 2 +- hooks/antigravity-hooks.json | 2 +- scripts/antigravity/hook-bridge.js | 2 +- tests/lib/antigravity-hook-bridge.test.js | 217 +++++++++++++++++++ tests/lib/antigravity-install-target.test.js | 35 +++ 5 files changed, 255 insertions(+), 3 deletions(-) diff --git a/.antigravity-plugin/hooks.json b/.antigravity-plugin/hooks.json index 8935093a1..816cae758 100644 --- a/.antigravity-plugin/hooks.json +++ b/.antigravity-plugin/hooks.json @@ -6,7 +6,7 @@ "hooks": [ { "type": "command", - "command": "node -e \"const p=require('path'),f=require('fs');function G(){var e=process.env.ANTIGRAVITY_PLUGIN_ROOT||process.env.CLAUDE_PLUGIN_ROOT||process.env.ECC_PLUGIN_ROOT;if(e&&f.existsSync(p.join(e,'scripts','antigravity','hook-bridge.js')))return p.join(e,'scripts','antigravity','hook-bridge.js');try{var r=p.resolve('.agents','ecc-install-state.json');if(f.existsSync(r)){var s=JSON.parse(f.readFileSync(r,'utf8'));if(s&&s.schemaVersion==='ecc.install.v1'&&s.target&&s.target.id==='antigravity-project'){var b=p.resolve('.agents','scripts','antigravity','hook-bridge.js');if(b.startsWith(p.resolve('.agents')+p.sep)&&f.existsSync(b))return b;}}}catch(_){}var h=require('os').homedir();var c=[p.join(h,'.claude','plugins','marketplaces','ecc'),p.join(h,'.gemini','config','plugins','ecc'),p.join(h,'.gemini','antigravity'),p.join(h,'.claude')];for(var i=0;i { + const fs = require('fs'); + const os = require('os'); + const tempWorkspace = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-user-project-')); + try { + const protectedFile = path.join(tempWorkspace, 'eslint.config.js'); + fs.writeFileSync(protectedFile, 'module.exports = {};'); + const safeFile = path.join(tempWorkspace, 'safe-app.js'); + fs.writeFileSync(safeFile, 'console.log("hello");'); + + const hooksConfig = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, 'hooks', 'antigravity-hooks.json'), 'utf8')); + const hookCmd = hooksConfig['ecc-guardrails'].PreToolUse[0].hooks[0].command; + + const envTrusted = { + ...process.env, + ANTIGRAVITY_PLUGIN_ROOT: REPO_ROOT, + }; + + // Allowed call + const resAllow = spawnSync(hookCmd, { + shell: true, + input: JSON.stringify({ + conversationId: 'allow-cmd-test', + toolCall: { name: 'edit_file', args: { Path: safeFile } }, + workspacePaths: [tempWorkspace], + }), + encoding: 'utf8', + env: envTrusted, + cwd: tempWorkspace, + }); + + assert.strictEqual(resAllow.status, 0); + const allowDecision = JSON.parse(resAllow.stdout.trim()); + assert.strictEqual(allowDecision.decision, 'allow'); + + // Denied call + const resDeny = spawnSync(hookCmd, { + shell: true, + input: JSON.stringify({ + conversationId: 'deny-cmd-test', + toolCall: { name: 'edit_file', args: { Path: protectedFile } }, + workspacePaths: [tempWorkspace], + }), + encoding: 'utf8', + env: envTrusted, + cwd: tempWorkspace, + }); + + assert.strictEqual(resDeny.status, 0); + const denyDecision = JSON.parse(resDeny.stdout.trim()); + assert.strictEqual(denyDecision.decision, 'deny'); + assert.ok(denyDecision.reason && denyDecision.reason.length > 0); + } finally { + fs.rmSync(tempWorkspace, { recursive: true, force: true }); + } +}); + +test('registered command in .antigravity-plugin/hooks.json executes allowed and denied calls via entry point', () => { + const fs = require('fs'); + const os = require('os'); + const tempWorkspace = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-user-plugin-project-')); + try { + const protectedFile = path.join(tempWorkspace, 'eslint.config.js'); + fs.writeFileSync(protectedFile, 'module.exports = {};'); + const safeFile = path.join(tempWorkspace, 'safe-app.js'); + fs.writeFileSync(safeFile, 'console.log("hello");'); + + const hooksConfig = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, '.antigravity-plugin', 'hooks.json'), 'utf8')); + const hookCmd = hooksConfig['ecc-guardrails'].PreToolUse[0].hooks[0].command; + + const envTrusted = { + ...process.env, + ANTIGRAVITY_PLUGIN_ROOT: REPO_ROOT, + }; + + // Allowed call + const resAllow = spawnSync(hookCmd, { + shell: true, + input: JSON.stringify({ + conversationId: 'allow-plugin-cmd-test', + toolCall: { name: 'edit_file', args: { Path: safeFile } }, + workspacePaths: [tempWorkspace], + }), + encoding: 'utf8', + env: envTrusted, + cwd: tempWorkspace, + }); + + assert.strictEqual(resAllow.status, 0); + const allowDecision = JSON.parse(resAllow.stdout.trim()); + assert.strictEqual(allowDecision.decision, 'allow'); + + // Denied call + const resDeny = spawnSync(hookCmd, { + shell: true, + input: JSON.stringify({ + conversationId: 'deny-plugin-cmd-test', + toolCall: { name: 'edit_file', args: { Path: protectedFile } }, + workspacePaths: [tempWorkspace], + }), + encoding: 'utf8', + env: envTrusted, + cwd: tempWorkspace, + }); + + assert.strictEqual(resDeny.status, 0); + const denyDecision = JSON.parse(resDeny.stdout.trim()); + assert.strictEqual(denyDecision.decision, 'deny'); + assert.ok(denyDecision.reason && denyDecision.reason.length > 0); + } finally { + fs.rmSync(tempWorkspace, { recursive: true, force: true }); + } +}); + +test('rejects execution of forged-receipt sentinel planted in untrusted project', () => { + const fs = require('fs'); + const os = require('os'); + const tempUntrusted = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-forged-repo-')); + try { + const decoyAgents = path.join(tempUntrusted, '.agents'); + const decoyBridgeDir = path.join(decoyAgents, 'scripts', 'antigravity'); + fs.mkdirSync(decoyBridgeDir, { recursive: true }); + + // Plant forged receipt + fs.writeFileSync(path.join(decoyAgents, 'ecc-install-state.json'), JSON.stringify({ + schemaVersion: 'ecc.install.v1', + target: { id: 'antigravity-project' }, + })); + + // Plant sentinel bridge that creates a marker file + const sentinelFile = path.join(tempUntrusted, 'forged-sentinel-executed.marker'); + const maliciousCode = ` + require('fs').writeFileSync(${JSON.stringify(sentinelFile)}, 'FORGED_EXECUTED'); + module.exports = { main() { process.stdout.write(JSON.stringify({ decision: 'deny', reason: 'SENTINEL' })); } }; + `; + fs.writeFileSync(path.join(decoyBridgeDir, 'hook-bridge.js'), maliciousCode); + + const hooksConfig = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, 'hooks', 'antigravity-hooks.json'), 'utf8')); + const hookCmd = hooksConfig['ecc-guardrails'].PreToolUse[0].hooks[0].command; + + const cleanEnv = { ...process.env }; + delete cleanEnv.ANTIGRAVITY_PLUGIN_ROOT; + delete cleanEnv.CLAUDE_PLUGIN_ROOT; + delete cleanEnv.ECC_PLUGIN_ROOT; + cleanEnv.HOME = path.join(tempUntrusted, 'empty-home'); + cleanEnv.USERPROFILE = path.join(tempUntrusted, 'empty-home'); + + const result = spawnSync(hookCmd, { + shell: true, + input: JSON.stringify({ + conversationId: 'forged-receipt-test', + toolCall: { name: 'edit_file', args: { Path: 'safe.js' } }, + }), + encoding: 'utf8', + cwd: tempUntrusted, + env: cleanEnv, + }); + + assert.strictEqual(result.status, 0, 'Hook runner must succeed and fail open'); + assert.strictEqual(fs.existsSync(sentinelFile), false, 'Forged receipt sentinel must NOT be executed!'); + const decision = JSON.parse(result.stdout.trim()); + assert.strictEqual(decision.decision, 'allow'); + } finally { + fs.rmSync(tempUntrusted, { recursive: true, force: true }); + } +}); + +test('rejects symlink-decoy realpath escapes pointing into untrusted directory', () => { + const fs = require('fs'); + const os = require('os'); + const tempUntrusted = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-symlink-repo-')); + try { + const sentinelFile = path.join(tempUntrusted, 'symlink-sentinel-executed.marker'); + const sentinelDir = path.join(tempUntrusted, 'sentinel-src', 'scripts', 'antigravity'); + fs.mkdirSync(sentinelDir, { recursive: true }); + fs.writeFileSync(path.join(sentinelDir, 'hook-bridge.js'), ` + require('fs').writeFileSync(${JSON.stringify(sentinelFile)}, 'SYMLINK_EXECUTED'); + module.exports = { main() { process.stdout.write(JSON.stringify({ decision: 'deny', reason: 'SENTINEL' })); } }; + `); + + // Create a symlink or junction attempting to escape to sentinel + const symlinkDir = path.join(tempUntrusted, 'symlink-plugin'); + try { + fs.symlinkSync(path.join(tempUntrusted, 'sentinel-src'), symlinkDir, 'junction'); + } catch (_symErr) { + // If junction/symlink fails on restricted Windows permissions, skip symlink creation + return; + } + + const hooksConfig = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, 'hooks', 'antigravity-hooks.json'), 'utf8')); + const hookCmd = hooksConfig['ecc-guardrails'].PreToolUse[0].hooks[0].command; + + const envWithSymlink = { + ...process.env, + ANTIGRAVITY_PLUGIN_ROOT: symlinkDir, + }; + + const result = spawnSync(hookCmd, { + shell: true, + input: JSON.stringify({ + conversationId: 'symlink-test', + toolCall: { name: 'edit_file', args: { Path: 'safe.js' } }, + }), + encoding: 'utf8', + cwd: tempUntrusted, + env: envWithSymlink, + }); + + assert.strictEqual(result.status, 0); + assert.strictEqual(fs.existsSync(sentinelFile), false, 'Symlink decoy sentinel must NOT be executed!'); + const decision = JSON.parse(result.stdout.trim()); + assert.strictEqual(decision.decision, 'allow'); + } finally { + fs.rmSync(tempUntrusted, { recursive: true, force: true }); + } +}); + console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); if (failed > 0) { process.exit(1); diff --git a/tests/lib/antigravity-install-target.test.js b/tests/lib/antigravity-install-target.test.js index 62717f452..f0b990bb9 100644 --- a/tests/lib/antigravity-install-target.test.js +++ b/tests/lib/antigravity-install-target.test.js @@ -171,6 +171,41 @@ test('pinned native loader receipt establishes distinct editor and CLI capabilit 'search_web', ]); assert.strictEqual(editorParsed.tools.includes('invoke_subagent'), false, 'Editor runtime must exclude invoke_subagent'); + + // Isolated tool mappings for editor + const grepAdapted = adaptAntigravityAgent('---\nname: grep-agent\ntools: Grep\n---\nbody', 'agents/grep.md', { runtime: 'editor' }); + assert.deepStrictEqual(yaml.load(grepAdapted.match(/^---\n([\s\S]*?)\n---\n/)[1]).tools, ['view_file']); + + const globAdapted = adaptAntigravityAgent('---\nname: glob-agent\ntools: Glob\n---\nbody', 'agents/glob.md', { runtime: 'editor' }); + assert.deepStrictEqual(yaml.load(globAdapted.match(/^---\n([\s\S]*?)\n---\n/)[1]).tools, ['view_file']); + + const fetchAdapted = adaptAntigravityAgent('---\nname: fetch-agent\ntools: WebFetch\n---\nbody', 'agents/fetch.md', { runtime: 'editor' }); + assert.deepStrictEqual(yaml.load(fetchAdapted.match(/^---\n([\s\S]*?)\n---\n/)[1]).tools, ['search_web']); + + const taskAdapted = adaptAntigravityAgent('---\nname: task-agent\ntools: Task\n---\nbody', 'agents/task.md', { runtime: 'editor' }); + assert.deepStrictEqual(yaml.load(taskAdapted.match(/^---\n([\s\S]*?)\n---\n/)[1]).tools, []); + + // Exercise ANTIGRAVITY_RUNTIME environment variable + const priorRuntime = process.env.ANTIGRAVITY_RUNTIME; + try { + process.env.ANTIGRAVITY_RUNTIME = 'editor'; + const envAdapted = adaptAntigravityAgent(source, 'agents/full-agent.md'); + const envParsed = yaml.load(envAdapted.match(/^---\n([\s\S]*?)\n---\n/)[1]); + assert.deepStrictEqual(envParsed.tools, [ + 'view_file', + 'write_to_file', + 'replace_file_content', + 'run_command', + 'search_web', + ]); + assert.strictEqual(envParsed.tools.includes('invoke_subagent'), false); + } finally { + if (priorRuntime === undefined) { + delete process.env.ANTIGRAVITY_RUNTIME; + } else { + process.env.ANTIGRAVITY_RUNTIME = priorRuntime; + } + } }); test('transform preserves CRLF line endings consistently on Windows-saved agents', () => { From a3875d6200717c83863c320f1f1c3b03c9b2d232 Mon Sep 17 00:00:00 2001 From: woffluon Date: Thu, 19 Nov 2026 00:01:55 +0300 Subject: [PATCH 08/10] docs(antigravity): mark adapter experimental pending native receipt and label capability fixture transform-only --- README.md | 2 +- tests/lib/antigravity-install-target.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 14aabf339..5c4080493 100644 --- a/README.md +++ b/README.md @@ -1333,7 +1333,7 @@ Treat `stable`, `beta`, `experimental`, and `instruction-only` below as capabili | OpenCode | Beta built plugin | Build plugin, then selective installer | ECC ships a subset of the catalog; connect a provider and select a model in OpenCode ([#2617](https://github.com/affaan-m/ECC/issues/2617)). | | GitHub Copilot Chat | Instruction-only | Checked-in instructions and prompt files | ECC hooks are not adapted. | | GitHub Copilot CLI | Beta project adapter | `--target copilot` places skills, adapted agents, and converted rules in `.github/` | ECC hooks and command shims are not installed by this target. | -| Antigravity 2.0 | Supported adapter & plugin | Native plugin (`.antigravity-plugin/` or `plugins/ecc/`) or `./install.sh --target antigravity` into `.agents/` | Subagents map to native tools (`read_file`, `edit_file`, `write_file`, `run_command`, `search_web`); hooks bridge via `scripts/antigravity/hook-bridge.js`. | +| Antigravity 2.0 | Experimental adapter & plugin | Native plugin (`.antigravity-plugin/` or `plugins/ecc/`) or `./install.sh --target antigravity` into `.agents/` | File placement, bridge execution, and agent transforms are tested; native loader acceptance receipt is pending. Subagents map to native tools; hooks bridge via `scripts/antigravity/hook-bridge.js`. | | Gemini, Zed, Qwen, Hermes, OpenClaw, Kimi, CodeBuddy, JoyCode | Experimental/minimal adapters | Harness-specific selective target | File placement and instruction portability are tested; full Claude feature parity is not claimed. |
diff --git a/tests/lib/antigravity-install-target.test.js b/tests/lib/antigravity-install-target.test.js index f0b990bb9..0a66ff330 100644 --- a/tests/lib/antigravity-install-target.test.js +++ b/tests/lib/antigravity-install-target.test.js @@ -130,7 +130,7 @@ test('search-only agent receives search tools without shell access (run_command) assert.strictEqual(parsed.tools.includes('run_command'), false); }); -test('pinned native loader receipt establishes distinct editor and CLI capability boundaries', () => { +test('transform-only capability fixture establishes distinct editor and CLI capability boundaries', () => { const yaml = require('js-yaml'); const allClaudeTools = 'Read, ReadFile, NotebookRead, Write, Edit, MultiEdit, Grep, Glob, Bash, WebSearch, WebFetch, Task'; const source = [ From 86cc9f60de78fe203d350e28ff0c8f80c6f296fc Mon Sep 17 00:00:00 2001 From: haelyra <49814733+haelyra@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:25:03 -0500 Subject: [PATCH 09/10] test: separate missing hook targets from stdin pipe failures --- tests/hooks/plugin-hook-bootstrap.test.js | 47 ++++++++++++++++++--- tests/lib/helpers/plugin-bootstrap-epipe.js | 19 +++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 tests/lib/helpers/plugin-bootstrap-epipe.js diff --git a/tests/hooks/plugin-hook-bootstrap.test.js b/tests/hooks/plugin-hook-bootstrap.test.js index 55d1af505..e6f84e155 100644 --- a/tests/hooks/plugin-hook-bootstrap.test.js +++ b/tests/hooks/plugin-hook-bootstrap.test.js @@ -32,7 +32,7 @@ function writeFile(root, relativePath, content) { } function run(args = [], options = {}) { - return spawnSync(process.execPath, [SCRIPT, ...args], { + return spawnSync(process.execPath, [...(options.nodeArgs || []), SCRIPT, ...args], { input: options.input || '', encoding: 'utf8', env: { @@ -46,6 +46,18 @@ function run(args = [], options = {}) { }); } +function isolatedBootstrapEnv(root) { + return { + HOME: root, USERPROFILE: root, ECC_AGENT_DATA_HOME: path.join(root, 'agent-data'), + QODER_PLUGIN_ROOT: '', ECC_HOOK_DEADLINE_MS: '', NODE_OPTIONS: '', + }; +} + +function spawnDiagnostic(result) { + return JSON.stringify({ status: result.status, signal: result.signal, + error: result.error?.code || null, stderr: result.stderr }); +} + function test(name, fn) { try { fn(); @@ -342,13 +354,36 @@ process.exit(7); const root = createTempDir(); try { const result = run(['node', path.join('scripts', 'missing.js')], { - root, - input: 'raw-input', + root, cwd: root, + // No stdin is needed to observe MODULE_NOT_FOUND. Sending input can + // race the child's early exit and legitimately produce EPIPE instead. + input: '', + env: isolatedBootstrapEnv(root), }); + const diagnostic = spawnDiagnostic(result); + assert.strictEqual(result.error, undefined, diagnostic); + assert.strictEqual(result.status, 1, diagnostic); + assert.strictEqual(result.stdout, '', diagnostic); + assert.ok(result.stderr.includes('Cannot find module'), diagnostic); + } finally { + cleanup(root); + } + })) passed++; else failed++; - assert.strictEqual(result.status, 1); - assert.strictEqual(result.stdout, ''); - assert.ok(result.stderr.includes('Cannot find module')); + if (test('a child that exits 1 with an input EPIPE retains fail-open execution diagnostics', () => { + const root = createTempDir(); + try { + const result = run(['node', path.join('scripts', 'missing.js')], { + root, cwd: root, input: 'raw-input', env: isolatedBootstrapEnv(root), + nodeArgs: ['--require', path.join(__dirname, '../lib/helpers/plugin-bootstrap-epipe.js')], + }); + const diagnostic = spawnDiagnostic(result); + assert.strictEqual(result.error, undefined, diagnostic); + assert.strictEqual(result.status, 0, diagnostic); + assert.strictEqual(result.stdout, '', diagnostic); + assert.ok(result.stderr.includes('[TestSpawn] child exited 1 with EPIPE'), diagnostic); + assert.ok(result.stderr.includes('Cannot find module'), diagnostic); + assert.ok(result.stderr.includes('bootstrap execution failed: spawnSync node EPIPE'), diagnostic); } finally { cleanup(root); } diff --git a/tests/lib/helpers/plugin-bootstrap-epipe.js b/tests/lib/helpers/plugin-bootstrap-epipe.js new file mode 100644 index 000000000..0a2ed2085 --- /dev/null +++ b/tests/lib/helpers/plugin-bootstrap-epipe.js @@ -0,0 +1,19 @@ +'use strict'; + +// Isolate the child-result contract from an OS scheduling race: a missing +// target can exit 1 while closing stdin before the bootstrap finishes writing. +const assert = require('assert'); +const path = require('path'); +const childProcess = require('child_process'); +const target = path.resolve(process.env.CLAUDE_PLUGIN_ROOT, 'scripts', 'missing.js'); + +childProcess.spawnSync = (command, args) => { + assert.strictEqual(command, process.execPath); + assert.deepStrictEqual(args, [target]); + process.stderr.write('[TestSpawn] child exited 1 with EPIPE\n'); + return { + status: 1, signal: null, stdout: Buffer.alloc(0), + stderr: Buffer.from("Error: Cannot find module 'missing fixture'\n"), + error: Object.assign(new Error('spawnSync node EPIPE'), { code: 'EPIPE' }), + }; +}; From c274336420eb1d91831f5adcedae0ee03bf963e1 Mon Sep 17 00:00:00 2001 From: haelyra <49814733+haelyra@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:29:54 -0500 Subject: [PATCH 10/10] test: verify generated Antigravity bootstrap matches module execution --- scripts/lib/antigravity-cli-bootstrap.js | 2 +- tests/lib/antigravity-cli-bootstrap.test.js | 25 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/scripts/lib/antigravity-cli-bootstrap.js b/scripts/lib/antigravity-cli-bootstrap.js index f2313f973..5172b78cd 100644 --- a/scripts/lib/antigravity-cli-bootstrap.js +++ b/scripts/lib/antigravity-cli-bootstrap.js @@ -147,4 +147,4 @@ function buildAntigravityCliHookCommand() { return `node -e "${source}" -- --hook config-protection`; } -module.exports = { buildAntigravityCliHookCommand }; +module.exports = { bootstrap, buildAntigravityCliHookCommand }; diff --git a/tests/lib/antigravity-cli-bootstrap.test.js b/tests/lib/antigravity-cli-bootstrap.test.js index 1d0be38b9..5bc8728d8 100644 --- a/tests/lib/antigravity-cli-bootstrap.test.js +++ b/tests/lib/antigravity-cli-bootstrap.test.js @@ -34,7 +34,16 @@ function result(command, args, input, cwd, extraEnv = {}, shell = false) { return JSON.parse(child.stdout); } function manifest(input, cwd, env = {}) { - return result(buildAntigravityCliHookCommand(), [], JSON.stringify(input), cwd, env, true); + const raw = JSON.stringify(input); + const generated = result(buildAntigravityCliHookCommand(), [], raw, cwd, env, true); + // Exercise the original function as a module too: generated Node source has + // no file identity for coverage and must keep the same boundary decisions. + const loaded = result(process.execPath, [ + '-e', 'require(process.argv[1]).bootstrap()', + path.join(root, 'scripts/lib/antigravity-cli-bootstrap.js'), '--hook', 'config-protection', + ], raw, cwd, env); + assert.deepEqual(loaded, generated, 'Module and published bootstrap must agree'); + return generated; } function sentinel(directory, marker) { const script = path.join(directory, 'scripts/antigravity/hook-bridge.js'); @@ -49,6 +58,20 @@ test('both published manifests use the same bounded first-party bootstrap', () = } }); +test('external canonical runtime preserves allow, deny and explicit bootstrap bypasses', () => workspace(temporary => { + fs.writeFileSync(path.join(temporary, 'app.js'), 'export default 1;'); + fs.writeFileSync(path.join(temporary, 'eslint.config.js'), 'module.exports = [];'); + for (const [file, expected] of [['app.js', 'allow'], ['eslint.config.js', 'deny']]) { + const payload = { + workspacePaths: [temporary], + toolCall: { name: 'edit_file', args: { Path: path.join(temporary, file) } }, + }; + assert.equal(manifest(payload, temporary, { ANTIGRAVITY_PLUGIN_ROOT: root }).decision, expected); + } + assert.equal(manifest({}, temporary, { ECC_HOOKS_ENABLED: 'false' }).decision, 'allow'); + assert.equal(manifest({}, temporary, { ECC_DRY_RUN: '1' }).decision, 'allow'); +})); + test('nested cwd cannot authorize a bridge anywhere inside the declared outer workspace', () => workspace(temporary => { const nested = path.join(temporary, 'src'); fs.mkdirSync(nested); const candidate = path.join(temporary, 'plugin'); const marker = path.join(temporary, 'executed');