From 7e7ca11f218b2baebf0ef8aaa290683b05c27b47 Mon Sep 17 00:00:00 2001 From: MohamedAfrash Date: Wed, 23 Sep 2026 09:55:46 +0100 Subject: [PATCH] feat(antigravity): elevate Google Antigravity to Tier 1 native plugin and lifecycle hooks - Add antigravity-home target adapter installing directly into ~/.gemini/config/plugins/ecc/ - Support full Antigravity lifecycle hooks (PreToolUse, Stop) adhering to the protojson contract ({ decision, reason }) via scripts/hooks/antigravity-hook-bridge.js - Generate native Antigravity plugin manifest (plugin.json) and shared ECC memory vault MCP config (mcp_config.json) - Support dual scope (user and project) with full harness capability integration - Update install schemas and manifests to recognize antigravity-home - Fix upstream regressions in plan.js scaffoldOnly, plan-canvas child_process spawn, codex-hooks pre-push test, and claude-plugin-setup hook arguments - Add comprehensive Tier 1 test suite (13 passing tests) with 100% pass across all 4919 repository tests --- docs/ANTIGRAVITY-GUIDE.md | 34 ++ manifests/install-modules.json | 29 +- schemas/ecc-install-config.schema.json | 1 + schemas/install-modules.schema.json | 1 + scripts/hooks/antigravity-hook-bridge.js | 162 ++++++++ scripts/lib/antigravity-hooks.js | 79 ++++ scripts/lib/antigravity-mcp.js | 28 ++ scripts/lib/antigravity-plugin.js | 20 + scripts/lib/claude-plugin-setup.js | 19 +- scripts/lib/harness-capabilities.js | 23 +- scripts/lib/install-manifests.js | 10 +- .../lib/install-targets/antigravity-home.js | 209 ++++++++++ .../install-targets/antigravity-project.js | 108 +++++- scripts/lib/install-targets/registry.js | 2 + scripts/lib/install/codex-user-config.js | 2 +- scripts/lib/install/hook-consent.js | 1 + scripts/lib/install/plan.js | 6 +- scripts/lib/resolve-ecc-root.js | 8 +- scripts/plan-canvas.js | 1 + tests/lib/antigravity-tier1.test.js | 356 ++++++++++++++++++ tests/lib/harness-capabilities.test.js | 15 +- tests/scripts/codex-hooks.test.js | 3 +- tests/scripts/control-pane.test.js | 5 +- 23 files changed, 1094 insertions(+), 28 deletions(-) create mode 100644 scripts/hooks/antigravity-hook-bridge.js create mode 100644 scripts/lib/antigravity-hooks.js create mode 100644 scripts/lib/antigravity-mcp.js create mode 100644 scripts/lib/antigravity-plugin.js create mode 100644 scripts/lib/install-targets/antigravity-home.js create mode 100644 tests/lib/antigravity-tier1.test.js diff --git a/docs/ANTIGRAVITY-GUIDE.md b/docs/ANTIGRAVITY-GUIDE.md index 998915216..80c03fa27 100644 --- a/docs/ANTIGRAVITY-GUIDE.md +++ b/docs/ANTIGRAVITY-GUIDE.md @@ -150,6 +150,40 @@ node "$EccRoot\scripts\uninstall.js" --target antigravity --dry-run - Confirm the files are under `.agents/workflows/`. - Invoke a workflow with `/` after restarting Antigravity. +## Tier 1 Native Plugin and Global Installation (`antigravity-home`) + +Antigravity supports global plugins located in `~/.gemini/config/plugins//`. Installing ECC as a native Antigravity plugin enables: +1. **Global Scope**: ECC rules, skills, agents, workflows, and memory MCP are active across all projects automatically, without requiring a `.agents/` folder in every repository. +2. **Lifecycle Hooks (`hooks.json`)**: Full support for `PreToolUse` (command security gates, file modification guards) and `Stop` hooks using Antigravity's protojson protocol (`{ decision, reason }`). +3. **Shared Memory Vault (`mcp_config.json`)**: Direct integration with `ecc-memory-mcp` across all Antigravity sessions. +4. **Native Plugin Manifest (`plugin.json`)**: Declares the ECC plugin metadata. + +### Installing Globally + +```bash +# Using install.sh from source +"$ECC_ROOT/install.sh" --target antigravity-home --profile core --enable-hooks +``` + +PowerShell: + +```powershell +& "$EccRoot\install.ps1" --target antigravity-home --profile core --enable-hooks +``` + +### Global Plugin Structure + +```text +~/.gemini/config/plugins/ecc/ +├── plugin.json # Antigravity plugin manifest +├── hooks.json # PreToolUse and Stop lifecycle hooks +├── mcp_config.json # Shared ECC Memory Vault MCP server +├── rules/ # Rules applied to all workspaces +├── workflows/ # Global slash workflows +├── skills/ # Global Agent Skills +└── scripts/hooks/ # Antigravity hook bridge +``` + ## Official Antigravity references - [Skills](https://antigravity.google/docs/skills) diff --git a/manifests/install-modules.json b/manifests/install-modules.json index 884c7d39d..85ebc638c 100644 --- a/manifests/install-modules.json +++ b/manifests/install-modules.json @@ -13,6 +13,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codebuddy", "joycode", "qwen", @@ -41,6 +42,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "codebuddy", "joycode", @@ -70,6 +72,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "opencode", "codebuddy", "joycode", @@ -99,7 +102,8 @@ "claude-project", "cursor", "opencode", - "codebuddy" + "codebuddy", + "antigravity-home" ], "dependencies": [], "defaultInstall": true, @@ -132,6 +136,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "gemini", "opencode", @@ -229,6 +234,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -264,6 +270,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -290,6 +297,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "gemini", "opencode", @@ -367,6 +375,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -404,6 +413,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -450,6 +460,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -484,6 +495,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -523,6 +535,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -567,6 +580,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -595,6 +609,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -626,6 +641,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -641,7 +657,7 @@ { "id": "ito-compute", "kind": "skills", - "description": "Authenticated It\u00f4 GPU inventory, RFQ, status, device revocation, and explicitly gated node-qualification workflows through the separately installed canonical CLI.", + "description": "Authenticated Itô GPU inventory, RFQ, status, device revocation, and explicitly gated node-qualification workflows through the separately installed canonical CLI.", "paths": [ "skills/ito-compute", "skills/ito-inference", @@ -652,6 +668,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "gemini", "opencode", @@ -683,6 +700,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "gemini", "opencode", @@ -715,6 +733,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -808,6 +827,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -869,6 +889,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -911,6 +932,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -940,6 +962,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -977,6 +1000,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", @@ -1004,6 +1028,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "opencode", "codebuddy", diff --git a/schemas/ecc-install-config.schema.json b/schemas/ecc-install-config.schema.json index 29b57538f..44f3566a1 100644 --- a/schemas/ecc-install-config.schema.json +++ b/schemas/ecc-install-config.schema.json @@ -22,6 +22,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "gemini", "opencode", diff --git a/schemas/install-modules.schema.json b/schemas/install-modules.schema.json index 620f616dc..bcc055d46 100644 --- a/schemas/install-modules.schema.json +++ b/schemas/install-modules.schema.json @@ -52,6 +52,7 @@ "claude-project", "cursor", "antigravity", + "antigravity-home", "codex", "gemini", "opencode", diff --git a/scripts/hooks/antigravity-hook-bridge.js b/scripts/hooks/antigravity-hook-bridge.js new file mode 100644 index 000000000..f0dc01dea --- /dev/null +++ b/scripts/hooks/antigravity-hook-bridge.js @@ -0,0 +1,162 @@ +#!/usr/bin/env node +'use strict'; + +/** + * Antigravity Lifecycle Hook Bridge + * + * Bridges Google Antigravity's protojson hook contract (stdin/stdout JSON with + * camelCase keys and { decision, reason } responses) to ECC's internal hook + * runtime (exit-code/stderr based). + */ + +const path = require('path'); +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 { readStdinRaw, resolveMaxStdin } = require('./hook-input'); + +function parseArgs(argv) { + const options = { + mode: 'pre-tool-use', + hook: null, + }; + + for (let i = 2; i < argv.length; i += 1) { + if (argv[i] === '--mode') { + options.mode = argv[i + 1] || options.mode; + i += 1; + } else if (argv[i] === '--hook') { + options.hook = argv[i + 1] || options.hook; + i += 1; + } + } + + return options; +} + +function adaptAntigravityInputToEcc(antigravityData) { + if (!antigravityData || typeof antigravityData !== 'object') { + return { tool_name: '', tool_input: {} }; + } + + const toolCall = antigravityData.toolCall || {}; + const toolName = toolCall.name || antigravityData.tool_name || ''; + const args = toolCall.args || antigravityData.tool_input || {}; + + // Normalize Antigravity tools to ECC tool conventions + const toolInput = { + ...args, + command: args.CommandLine || args.command || '', + file_path: args.TargetFile || args.file_path || args.path || '', + }; + + return { + tool_name: toolName, + tool_input: toolInput, + conversation_id: antigravityData.conversationId || '', + workspace_paths: antigravityData.workspacePaths || [], + }; +} + +async function main() { + const options = parseArgs(process.argv); + const maxStdin = resolveMaxStdin(process.env.ECC_HOOK_INPUT_MAX_BYTES); + + let raw = ''; + try { + const inputResult = await readStdinRaw(process.stdin, { maxStdin }); + raw = inputResult.raw; + } catch (_err) { + // If stdin read fails, fail open safely + process.stdout.write(JSON.stringify({ decision: 'allow' })); + return; + } + + let antigravityPayload = {}; + try { + antigravityPayload = raw.trim() ? JSON.parse(raw) : {}; + } catch (_parseErr) { + // Malformed JSON on stdin + process.stdout.write(JSON.stringify({ decision: 'allow' })); + return; + } + + const eccPayload = adaptAntigravityInputToEcc(antigravityPayload); + const eccJsonString = JSON.stringify(eccPayload); + + if (options.mode === 'pre-tool-use') { + let result = { exitCode: 0, stderr: '' }; + + if (options.hook === 'pre:bash:dispatcher') { + result = runPreBash(eccJsonString); + } else if (options.hook === 'pre:edit-write:gateguard-fact-force') { + result = runGateGuard(eccJsonString); + } else if (options.hook === 'pre:config-protection') { + const child = spawnSync(process.execPath, [path.join(__dirname, 'config-protection.js')], { + input: eccJsonString, + encoding: 'utf8', + }); + result = { + exitCode: child.status || 0, + 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; + } + + process.stdout.write(JSON.stringify({ decision: 'allow' })); + return; + } + + if (options.mode === 'stop') { + 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')], { + input: eccJsonString, + encoding: 'utf8', + }); + stopResult = { + exitCode: child.status || 0, + stderr: child.stderr || '', + }; + } + + if (stopResult && stopResult.exitCode !== 0 && stopResult.stderr) { + process.stdout.write(JSON.stringify({ + decision: 'continue', + reason: stopResult.stderr.replace(/\r?\n/g, ' ').trim(), + })); + return; + } + + process.stdout.write(JSON.stringify({})); + return; + } + + // Default passthrough + process.stdout.write(JSON.stringify({ decision: 'allow' })); +} + +if (require.main === module) { + main().catch(() => { + process.stdout.write(JSON.stringify({ decision: 'allow' })); + }); +} + +module.exports = { + adaptAntigravityInputToEcc, +}; diff --git a/scripts/lib/antigravity-hooks.js b/scripts/lib/antigravity-hooks.js new file mode 100644 index 000000000..b7ae6327c --- /dev/null +++ b/scripts/lib/antigravity-hooks.js @@ -0,0 +1,79 @@ +'use strict'; + +/** + * Antigravity Hooks Generator + * + * Generates valid Antigravity hooks.json configuration matching Antigravity's + * lifecycle schema (PreToolUse, PostToolUse, Stop) and pointing to the ECC + * hook bridge. + */ + +function buildAntigravityHooksConfig(options = {}) { + const profile = options.profile || 'standard'; + const bridgeScript = options.bridgeScript || 'scripts/hooks/antigravity-hook-bridge.js'; + + const preToolUseHandlers = [ + { + matcher: 'run_command', + hooks: [ + { + type: 'command', + command: `node ${bridgeScript} --mode pre-tool-use --hook pre:bash:dispatcher`, + timeout: 15, + }, + ], + }, + { + matcher: 'write_to_file|replace_file_content', + hooks: [ + { + type: 'command', + command: `node ${bridgeScript} --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`, + timeout: 5, + }, + ], + }, + ]; + + if (profile === 'standard' || profile === 'strict') { + preToolUseHandlers.push({ + matcher: 'write_to_file', + hooks: [ + { + type: 'command', + command: `node ${bridgeScript} --mode pre-tool-use --hook pre:write:doc-file-warning`, + timeout: 5, + }, + ], + }); + } + + const stopHandlers = [ + { + type: 'command', + command: `node ${bridgeScript} --mode stop --hook stop:format-typecheck`, + timeout: 120, + }, + { + type: 'command', + command: `node ${bridgeScript} --mode stop --hook stop:check-console-log`, + timeout: 30, + }, + ]; + + return { + 'ecc-guard': { + PreToolUse: preToolUseHandlers, + Stop: stopHandlers, + }, + }; +} + +module.exports = { + buildAntigravityHooksConfig, +}; diff --git a/scripts/lib/antigravity-mcp.js b/scripts/lib/antigravity-mcp.js new file mode 100644 index 000000000..dc726e54c --- /dev/null +++ b/scripts/lib/antigravity-mcp.js @@ -0,0 +1,28 @@ +'use strict'; + +/** + * Antigravity MCP Configuration Generator + * + * Generates valid Antigravity mcp_config.json containing the ECC Memory Vault + * stdio server so that Antigravity agents have native access to .ecc/memory/. + */ + +function buildAntigravityMcpConfig(options = {}) { + const memoryScript = options.memoryScript || 'scripts/memory-mcp.mjs'; + + return { + mcpServers: { + 'ecc-memory': { + command: 'node', + args: [memoryScript], + env: { + ECC_MEMORY_HARNESS: 'antigravity', + }, + }, + }, + }; +} + +module.exports = { + buildAntigravityMcpConfig, +}; diff --git a/scripts/lib/antigravity-plugin.js b/scripts/lib/antigravity-plugin.js new file mode 100644 index 000000000..a93f0a90b --- /dev/null +++ b/scripts/lib/antigravity-plugin.js @@ -0,0 +1,20 @@ +'use strict'; + +/** + * Antigravity Plugin Manifest Generator + * + * Generates valid Antigravity plugin.json declaring the ECC plugin. + */ + +function buildAntigravityPluginManifest(options = {}) { + const version = options.version || '2.2.2'; + return { + name: 'ecc', + description: 'ECC - The Agent Harness Operating System for Antigravity', + version, + }; +} + +module.exports = { + buildAntigravityPluginManifest, +}; diff --git a/scripts/lib/claude-plugin-setup.js b/scripts/lib/claude-plugin-setup.js index 63c116759..47b0232fd 100644 --- a/scripts/lib/claude-plugin-setup.js +++ b/scripts/lib/claude-plugin-setup.js @@ -570,6 +570,7 @@ function verifyPluginAtScope(options) { function ensurePluginAtScope(options) { const run = options.run || runClaude; + const configuredHooks = options.hookConfiguration; if (options.installed) { run( ['plugin', 'update', CURRENT_PLUGIN_ID, '--scope', options.scope], @@ -577,13 +578,17 @@ function ensurePluginAtScope(options) { ); return 'updated'; } - run( - [ - 'plugin', 'install', CURRENT_PLUGIN_ID, - '--scope', options.scope, - ], - { cwd: options.projectRoot, phase: 'plugin-install' } - ); + const installArgs = [ + 'plugin', 'install', CURRENT_PLUGIN_ID, + '--scope', options.scope, + ]; + if (configuredHooks) { + installArgs.push( + '--config', `hooks_enabled=${configuredHooks.hooks_enabled}`, + '--config', `hook_profile=${configuredHooks.hook_profile}` + ); + } + run(installArgs, { cwd: options.projectRoot, phase: 'plugin-install' }); return 'installed'; } diff --git a/scripts/lib/harness-capabilities.js b/scripts/lib/harness-capabilities.js index c42f0488e..8e606cff9 100644 --- a/scripts/lib/harness-capabilities.js +++ b/scripts/lib/harness-capabilities.js @@ -103,16 +103,23 @@ const HARNESS_CAPABILITIES = deepFreeze([ }, { id: 'antigravity', - label: 'Antigravity', - targetIds: ['antigravity'], - channel: 'managed-project', - installMode: 'managed-project', + label: 'Google Antigravity', + targetIds: ['antigravity-home', 'antigravity'], + channel: 'native-plugin', + installMode: 'native-plugin', guidedReady: false, availability: 'advanced', - destination: './.agents', - scopes: [scope('project', 'antigravity', './.agents')], - hooks: hooks('not-configured', false, 'ECC hooks are not configured by this adapter.'), - aliases: ['google-antigravity'], + destination: 'Selected Antigravity scope: ~/.gemini/config/plugins/ecc or ./.agents', + scopes: [ + scope('user', 'antigravity-home', '~/.gemini/config/plugins/ecc'), + scope('project', 'antigravity', './.agents'), + ], + hooks: hooks( + 'profile-selection', + true, + 'ECC hooks are configured through Antigravity PreToolUse and Stop lifecycle hooks.' + ), + aliases: ['google-antigravity', 'gemini-antigravity', 'agy'], }, { id: 'gemini', diff --git a/scripts/lib/install-manifests.js b/scripts/lib/install-manifests.js index bb16cc93c..926948f34 100644 --- a/scripts/lib/install-manifests.js +++ b/scripts/lib/install-manifests.js @@ -5,7 +5,7 @@ const { getInstallTargetAdapter, planInstallTargetScaffold } = require('./instal const { resolveInvocationEnvironment } = require('./invocation-environment'); const DEFAULT_REPO_ROOT = path.join(__dirname, '../..'); -const SUPPORTED_INSTALL_TARGETS = ['claude', 'claude-project', 'cursor', 'antigravity', 'codex', 'gemini', 'opencode', 'codebuddy', 'joycode', 'qwen', 'zed', 'hermes', 'openclaw', 'kimi', 'adal']; +const SUPPORTED_INSTALL_TARGETS = ['claude', 'claude-project', 'cursor', 'antigravity', 'antigravity-home', 'codex', 'gemini', 'opencode', 'codebuddy', 'joycode', 'qwen', 'zed', 'hermes', 'openclaw', 'kimi', 'adal']; const COMPONENT_FAMILY_PREFIXES = { baseline: 'baseline:', language: 'lang:', @@ -71,6 +71,14 @@ const LEGACY_COMPAT_BASE_MODULE_IDS_BY_TARGET = Object.freeze({ 'skill-unified-memory', 'workflow-quality', ], + 'antigravity-home': [ + 'rules-core', + 'agents-core', + 'commands-core', + 'hooks-runtime', + 'platform-configs', + 'workflow-quality', + ], zed: [ 'rules-core', 'agents-core', diff --git a/scripts/lib/install-targets/antigravity-home.js b/scripts/lib/install-targets/antigravity-home.js new file mode 100644 index 000000000..553ebd175 --- /dev/null +++ b/scripts/lib/install-targets/antigravity-home.js @@ -0,0 +1,209 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); + +const { + HOME_INSTALL_EXCLUDED_SOURCE_PATHS, + createFlatRuleOperations, + createInstallTargetAdapter, + createManagedOperation, + createManagedScaffoldOperation, + isForeignPlatformPath, + normalizeRelativePath, +} = require('./helpers'); +const { buildAntigravityHooksConfig } = require('../antigravity-hooks'); +const { buildAntigravityMcpConfig } = require('../antigravity-mcp'); +const { buildAntigravityPluginManifest } = require('../antigravity-plugin'); + +function readJsonObject(filePath, label) { + let parsed; + try { + parsed = JSON.parse(fs.readFileSync(filePath, 'utf8')); + } catch (error) { + throw new Error(`Failed to parse ${label} at ${filePath}: ${error.message}`); + } + + if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) { + throw new Error(`Invalid ${label} at ${filePath}: expected a JSON object`); + } + + return parsed; +} + +module.exports = createInstallTargetAdapter({ + id: 'antigravity-home', + target: 'antigravity-home', + kind: 'home', + rootSegments: ['.gemini', 'config', 'plugins', 'ecc'], + installStatePathSegments: ['ecc-install-state.json'], + nativeRootRelativePath: '.gemini', + excludedSourcePaths: HOME_INSTALL_EXCLUDED_SOURCE_PATHS, + planOperations(input, adapter) { + const modules = Array.isArray(input.modules) + ? input.modules + : (input.module ? [input.module] : []); + const { + repoRoot, + projectRoot, + homeDir, + } = input; + const planningInput = { + repoRoot, + projectRoot, + homeDir, + }; + const targetRoot = adapter.resolveRoot(planningInput); + + return modules.flatMap(module => { + const paths = Array.isArray(module.paths) ? module.paths : []; + return paths + .filter(p => !isForeignPlatformPath(p, 'antigravity') && !adapter.excludesSourcePath(p)) + .flatMap(sourceRelativePath => { + const normalizedSourcePath = normalizeRelativePath(sourceRelativePath); + + if ( + normalizedSourcePath === 'rules' + || normalizedSourcePath.startsWith('rules/') + ) { + return createFlatRuleOperations({ + moduleId: module.id, + repoRoot, + sourceRelativePath: normalizedSourcePath, + destinationDir: path.join(targetRoot, 'rules'), + }); + } + + if ( + normalizedSourcePath === 'commands' + || normalizedSourcePath.startsWith('commands/') + ) { + const commandRelativePath = normalizedSourcePath === 'commands' + ? '' + : normalizedSourcePath.slice('commands/'.length); + return [ + createManagedScaffoldOperation( + module.id, + normalizedSourcePath, + path.join(targetRoot, 'workflows', commandRelativePath), + 'preserve-relative-path' + ), + ]; + } + + if ( + normalizedSourcePath === 'agents' + || normalizedSourcePath.startsWith('agents/') + ) { + const agentRelativePath = normalizedSourcePath === 'agents' + ? '' + : normalizedSourcePath.slice('agents/'.length); + return [ + createManagedOperation({ + moduleId: module.id, + sourceRelativePath: normalizedSourcePath, + destinationPath: path.join(targetRoot, 'agents', agentRelativePath), + strategy: 'preserve-relative-path', + contentTransform: 'antigravity-agent-frontmatter', + }), + ]; + } + + if ( + normalizedSourcePath === 'skills' + || normalizedSourcePath.startsWith('skills/') + ) { + const skillRelativePath = normalizedSourcePath === 'skills' + ? '' + : normalizedSourcePath.slice('skills/'.length); + return [ + createManagedScaffoldOperation( + module.id, + normalizedSourcePath, + path.join(targetRoot, 'skills', skillRelativePath), + 'preserve-relative-path' + ), + ]; + } + + if ( + module.id === 'hooks-runtime' + && normalizedSourcePath === 'hooks' + ) { + return [ + createManagedOperation({ + kind: 'merge-json', + moduleId: module.id, + sourceRelativePath: 'hooks/hooks.json', + destinationPath: path.join(targetRoot, 'hooks.json'), + strategy: 'merge-json', + ownership: 'managed', + scaffoldOnly: false, + mergePayload: buildAntigravityHooksConfig({ + profile: input.hookProfile || 'standard', + }), + }), + ]; + } + + if ( + module.id === 'platform-configs' + && (normalizedSourcePath === 'mcp-configs' || normalizedSourcePath === '.mcp.json') + ) { + const baseMcp = (repoRoot && fs.existsSync(path.join(repoRoot, '.mcp.json'))) + ? readJsonObject(path.join(repoRoot, '.mcp.json'), '.mcp.json') + : { mcpServers: {} }; + const antigravityMcp = buildAntigravityMcpConfig(); + const mergedMcp = { + mcpServers: { + ...(baseMcp.mcpServers || {}), + ...(antigravityMcp.mcpServers || {}), + }, + }; + + const operations = [ + createManagedOperation({ + kind: 'merge-json', + moduleId: module.id, + sourceRelativePath: '.mcp.json', + destinationPath: path.join(targetRoot, 'mcp_config.json'), + strategy: 'merge-json', + ownership: 'managed', + scaffoldOnly: false, + mergePayload: mergedMcp, + }), + createManagedOperation({ + kind: 'merge-json', + moduleId: module.id, + sourceRelativePath: 'plugin.json', + destinationPath: path.join(targetRoot, 'plugin.json'), + strategy: 'merge-json', + ownership: 'managed', + scaffoldOnly: false, + mergePayload: buildAntigravityPluginManifest(), + }), + ]; + + 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' + ) + ); + } + + return operations; + } + + if (normalizedSourcePath === 'scripts/hooks' || normalizedSourcePath === 'scripts/lib') { + return [adapter.createScaffoldOperation(module.id, normalizedSourcePath, planningInput)]; + } + + return []; + }); + }); + }, +}); diff --git a/scripts/lib/install-targets/antigravity-project.js b/scripts/lib/install-targets/antigravity-project.js index 7861bbc25..9f5b8a8fd 100644 --- a/scripts/lib/install-targets/antigravity-project.js +++ b/scripts/lib/install-targets/antigravity-project.js @@ -1,3 +1,4 @@ +const fs = require('fs'); const path = require('path'); const { @@ -7,8 +8,21 @@ const { createManagedScaffoldOperation, normalizeRelativePath, } = require('./helpers'); +const { buildAntigravityHooksConfig } = require('../antigravity-hooks'); +const { buildAntigravityMcpConfig } = require('../antigravity-mcp'); +const { buildAntigravityPluginManifest } = require('../antigravity-plugin'); -const SUPPORTED_SOURCE_PREFIXES = ['rules', 'commands', 'agents', 'skills']; +const SUPPORTED_SOURCE_PREFIXES = [ + 'rules', + 'commands', + 'agents', + 'skills', + 'hooks', + 'scripts/hooks', + 'scripts/lib', + 'mcp-configs', + '.mcp.json', +]; function supportsAntigravitySourcePath(sourceRelativePath) { const normalizedPath = normalizeRelativePath(sourceRelativePath); @@ -17,12 +31,28 @@ function supportsAntigravitySourcePath(sourceRelativePath) { )); } +function readJsonObject(filePath, label) { + let parsed; + try { + parsed = JSON.parse(fs.readFileSync(filePath, 'utf8')); + } catch (error) { + throw new Error(`Failed to parse ${label} at ${filePath}: ${error.message}`); + } + + if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) { + throw new Error(`Invalid ${label} at ${filePath}: expected a JSON object`); + } + + return parsed; +} + module.exports = createInstallTargetAdapter({ id: 'antigravity-project', target: 'antigravity', kind: 'project', rootSegments: ['.agents'], installStatePathSegments: ['ecc-install-state.json'], + nativeRootRelativePath: '.agents', supportsModule(module) { const paths = Array.isArray(module && module.paths) ? module.paths : []; return paths.length > 0; @@ -114,6 +144,82 @@ module.exports = createInstallTargetAdapter({ ]; } + if ( + module.id === 'hooks-runtime' + && normalizedSourcePath === 'hooks' + ) { + return [ + createManagedOperation({ + kind: 'merge-json', + moduleId: module.id, + sourceRelativePath: 'hooks/hooks.json', + destinationPath: path.join(targetRoot, 'hooks.json'), + strategy: 'merge-json', + ownership: 'managed', + scaffoldOnly: false, + mergePayload: buildAntigravityHooksConfig({ + profile: input.hookProfile || 'standard', + }), + }), + ]; + } + + if ( + module.id === 'platform-configs' + && (normalizedSourcePath === 'mcp-configs' || normalizedSourcePath === '.mcp.json') + ) { + const baseMcp = (repoRoot && fs.existsSync(path.join(repoRoot, '.mcp.json'))) + ? readJsonObject(path.join(repoRoot, '.mcp.json'), '.mcp.json') + : { mcpServers: {} }; + const antigravityMcp = buildAntigravityMcpConfig(); + const mergedMcp = { + mcpServers: { + ...(baseMcp.mcpServers || {}), + ...(antigravityMcp.mcpServers || {}), + }, + }; + + const operations = [ + createManagedOperation({ + kind: 'merge-json', + moduleId: module.id, + sourceRelativePath: '.mcp.json', + destinationPath: path.join(targetRoot, 'mcp_config.json'), + strategy: 'merge-json', + ownership: 'managed', + scaffoldOnly: false, + mergePayload: mergedMcp, + }), + createManagedOperation({ + kind: 'merge-json', + moduleId: module.id, + sourceRelativePath: 'plugin.json', + destinationPath: path.join(targetRoot, 'plugins', 'ecc', 'plugin.json'), + strategy: 'merge-json', + ownership: 'managed', + scaffoldOnly: false, + mergePayload: buildAntigravityPluginManifest(), + }), + ]; + + 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' + ) + ); + } + + return operations; + } + + if (normalizedSourcePath === 'scripts/hooks' || normalizedSourcePath === 'scripts/lib') { + return [adapter.createScaffoldOperation(module.id, normalizedSourcePath, planningInput)]; + } + return []; }); }); diff --git a/scripts/lib/install-targets/registry.js b/scripts/lib/install-targets/registry.js index 8dd7cf848..864a91a22 100644 --- a/scripts/lib/install-targets/registry.js +++ b/scripts/lib/install-targets/registry.js @@ -1,4 +1,5 @@ const adalProject = require('./adal-project'); +const antigravityHome = require('./antigravity-home'); const antigravityProject = require('./antigravity-project'); const claudeHome = require('./claude-home'); const claudeProject = require('./claude-project'); @@ -19,6 +20,7 @@ const ADAPTERS = Object.freeze([ claudeHome, claudeProject, cursorProject, + antigravityHome, antigravityProject, codexHome, geminiProject, diff --git a/scripts/lib/install/codex-user-config.js b/scripts/lib/install/codex-user-config.js index 5b7aa612c..a4e95df05 100644 --- a/scripts/lib/install/codex-user-config.js +++ b/scripts/lib/install/codex-user-config.js @@ -6,7 +6,7 @@ const path = require('path'); const { assertWithinTrustedRoot } = require('../path-safety'); function isCodexUserConfig(plan, operation) { - if (plan.adapter.id !== 'codex-home' || operation.kind !== 'copy-file') { + if (plan?.adapter?.id !== 'codex-home' || operation?.kind !== 'copy-file') { return false; } const relativePath = path.relative(plan.targetRoot, operation.destinationPath); diff --git a/scripts/lib/install/hook-consent.js b/scripts/lib/install/hook-consent.js index 883c121d7..4b84a6b4e 100644 --- a/scripts/lib/install/hook-consent.js +++ b/scripts/lib/install/hook-consent.js @@ -60,6 +60,7 @@ function isHookRuntimeOperation(operation = {}) { || source.startsWith('.cursor/hooks/') || source === '.cursor/hooks.json' || destination.endsWith('/hooks/hooks.json') + || destination.endsWith('/hooks.json') || destination.endsWith('/.cursor/hooks.json') || destination.includes('/.cursor/hooks/') ); diff --git a/scripts/lib/install/plan.js b/scripts/lib/install/plan.js index 1400557c7..91774b6e0 100644 --- a/scripts/lib/install/plan.js +++ b/scripts/lib/install/plan.js @@ -167,8 +167,10 @@ function materializeScaffoldOperation(sourceRoot, operation) { destinationPath: operation.destinationPath, strategy: operation.strategy || 'merge-json', ownership: operation.ownership || 'managed', - scaffoldOnly: Object.hasOwn(operation, 'scaffoldOnly') ? operation.scaffoldOnly : false, - mergePayload: readJsonObject(path.join(sourceRoot, operation.sourceRelativePath), operation.sourceRelativePath) + scaffoldOnly: typeof operation.scaffoldOnly === 'boolean' ? operation.scaffoldOnly : false, + mergePayload: operation.mergePayload !== undefined + ? JSON.parse(JSON.stringify(operation.mergePayload)) + : readJsonObject(path.join(sourceRoot, operation.sourceRelativePath), operation.sourceRelativePath) } ]; } diff --git a/scripts/lib/resolve-ecc-root.js b/scripts/lib/resolve-ecc-root.js index c9b8ee423..1b2da3684 100644 --- a/scripts/lib/resolve-ecc-root.js +++ b/scripts/lib/resolve-ecc-root.js @@ -55,7 +55,7 @@ const DEFAULT_SKILL_PROBE = path.join('skills', 'continuous-learning-v2'); function resolveEccRoot(options = {}) { const envRoot = options.envRoot !== undefined ? options.envRoot - : (process.env.CLAUDE_PLUGIN_ROOT || ''); + : (process.env.CLAUDE_PLUGIN_ROOT || process.env.ANTIGRAVITY_PLUGIN_ROOT || process.env.GEMINI_PLUGIN_ROOT || ''); if (envRoot && envRoot.trim()) { return envRoot.trim(); @@ -80,6 +80,12 @@ function resolveEccRoot(options = {}) { return claudeDir; } + // Antigravity global plugin install — ~/.gemini/config/plugins/ecc + const antigravityPluginDir = path.join(homeDir, '.gemini', 'config', 'plugins', 'ecc'); + if (isRoot(antigravityPluginDir)) { + return antigravityPluginDir; + } + // Exact legacy plugin install locations. These preserve backwards // compatibility without scanning arbitrary plugin trees. const legacyPluginRoots = PLUGIN_ROOT_SEGMENTS.map((segments) => diff --git a/scripts/plan-canvas.js b/scripts/plan-canvas.js index 6ecefe49a..9b692821a 100755 --- a/scripts/plan-canvas.js +++ b/scripts/plan-canvas.js @@ -17,6 +17,7 @@ * so stdout stays parseable. */ +const { spawn } = require('child_process'); const fs = require('fs'); const http = require('http'); const path = require('path'); diff --git a/tests/lib/antigravity-tier1.test.js b/tests/lib/antigravity-tier1.test.js new file mode 100644 index 000000000..145947bcd --- /dev/null +++ b/tests/lib/antigravity-tier1.test.js @@ -0,0 +1,356 @@ +'use strict'; + +const assert = require('assert'); +const fs = require('fs'); +const os = require('os'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const { adaptAntigravityInputToEcc } = require('../../scripts/hooks/antigravity-hook-bridge'); +const { buildAntigravityHooksConfig } = require('../../scripts/lib/antigravity-hooks'); +const { buildAntigravityMcpConfig } = require('../../scripts/lib/antigravity-mcp'); +const { buildAntigravityPluginManifest } = require('../../scripts/lib/antigravity-plugin'); +const { getInstallTargetAdapter, listInstallTargetAdapters } = require('../../scripts/lib/install-targets/registry'); +const { resolveInstallPlan } = require('../../scripts/lib/install-manifests'); +const { resolveEccRoot } = require('../../scripts/lib/resolve-ecc-root'); + +let passed = 0; +let failed = 0; + +function test(name, fn) { + try { + fn(); + console.log(` ✓ ${name}`); + passed += 1; + return true; + } catch (error) { + console.log(` ✗ ${name}`); + console.log(` Error: ${error.message}`); + failed += 1; + return false; + } +} + +function createTempDir(prefix) { + return fs.mkdtempSync(path.join(os.tmpdir(), prefix)); +} + +function cleanup(dirPath) { + fs.rmSync(dirPath, { recursive: true, force: true }); +} + +function runTests() { + console.log('\n=== Testing Antigravity Tier 1 Parity ===\n'); + + test('adaptAntigravityInputToEcc normalizes run_command tool calls', () => { + const rawInput = { + conversationId: 'conv-1234', + workspacePaths: ['/workspace/app'], + stepIdx: 5, + toolCall: { + name: 'run_command', + args: { + CommandLine: 'npm test', + Cwd: '/workspace/app', + }, + }, + }; + + const adapted = adaptAntigravityInputToEcc(rawInput); + assert.strictEqual(adapted.tool_name, 'run_command'); + assert.strictEqual(adapted.tool_input.command, 'npm test'); + assert.strictEqual(adapted.tool_input.CommandLine, 'npm test'); + assert.strictEqual(adapted.conversation_id, 'conv-1234'); + assert.deepStrictEqual(adapted.workspace_paths, ['/workspace/app']); + }); + + test('adaptAntigravityInputToEcc normalizes write_to_file and replace_file_content tool calls', () => { + const writeInput = { + toolCall: { + name: 'write_to_file', + args: { + TargetFile: '/workspace/app/src/index.js', + CodeContent: 'console.log("hello");', + }, + }, + }; + const adaptedWrite = adaptAntigravityInputToEcc(writeInput); + assert.strictEqual(adaptedWrite.tool_name, 'write_to_file'); + assert.strictEqual(adaptedWrite.tool_input.file_path, '/workspace/app/src/index.js'); + + const replaceInput = { + toolCall: { + name: 'replace_file_content', + args: { + TargetFile: '/workspace/app/src/index.js', + TargetContent: 'hello', + ReplacementContent: 'world', + }, + }, + }; + const adaptedReplace = adaptAntigravityInputToEcc(replaceInput); + assert.strictEqual(adaptedReplace.tool_name, 'replace_file_content'); + assert.strictEqual(adaptedReplace.tool_input.file_path, '/workspace/app/src/index.js'); + }); + + test('adaptAntigravityInputToEcc handles malformed or empty payloads safely', () => { + const emptyAdapted = adaptAntigravityInputToEcc(null); + assert.strictEqual(emptyAdapted.tool_name, ''); + assert.deepStrictEqual(emptyAdapted.tool_input, {}); + + const emptyObjAdapted = adaptAntigravityInputToEcc({}); + assert.strictEqual(emptyObjAdapted.tool_name, ''); + assert.deepStrictEqual(emptyObjAdapted.tool_input, { command: '', file_path: '' }); + }); + + test('buildAntigravityHooksConfig generates valid Antigravity hooks specification', () => { + const config = buildAntigravityHooksConfig({ profile: 'standard' }); + assert.ok(config['ecc-guard'], 'Should have ecc-guard hook entry'); + const guard = config['ecc-guard']; + + assert.ok(Array.isArray(guard.PreToolUse), 'PreToolUse should be an array'); + assert.ok(Array.isArray(guard.Stop), 'Stop should be an array'); + + const commandMatcher = guard.PreToolUse.find(entry => entry.matcher === 'run_command'); + assert.ok(commandMatcher, 'Should have run_command matcher in PreToolUse'); + assert.ok( + commandMatcher.hooks.some(h => h.command.includes('pre:bash:dispatcher')), + 'Should invoke pre:bash:dispatcher on run_command' + ); + + const editMatcher = guard.PreToolUse.find(entry => entry.matcher === 'write_to_file|replace_file_content'); + assert.ok(editMatcher, 'Should have write_to_file|replace_file_content matcher'); + assert.ok( + editMatcher.hooks.some(h => h.command.includes('pre:edit-write:gateguard-fact-force')), + 'Should invoke GateGuard on write operations' + ); + }); + + test('buildAntigravityMcpConfig generates valid stdio MCP configuration for ecc-memory', () => { + const config = buildAntigravityMcpConfig(); + assert.ok(config.mcpServers, 'Should declare mcpServers'); + assert.ok(config.mcpServers['ecc-memory'], 'Should declare ecc-memory server'); + const memoryServer = config.mcpServers['ecc-memory']; + assert.strictEqual(memoryServer.command, 'node'); + assert.strictEqual(memoryServer.env.ECC_MEMORY_HARNESS, 'antigravity'); + }); + + test('buildAntigravityPluginManifest generates valid Antigravity plugin manifest', () => { + const manifest = buildAntigravityPluginManifest({ version: '2.2.2' }); + assert.strictEqual(manifest.name, 'ecc'); + assert.strictEqual(manifest.version, '2.2.2'); + assert.ok(manifest.description.includes('Antigravity')); + }); + + test('antigravity-home adapter resolves root to ~/.gemini/config/plugins/ecc', () => { + const homeDir = '/home/testuser'; + const adapter = getInstallTargetAdapter('antigravity-home'); + assert.strictEqual(adapter.id, 'antigravity-home'); + assert.strictEqual(adapter.kind, 'home'); + assert.strictEqual( + adapter.resolveRoot({ homeDir }), + path.join(homeDir, '.gemini', 'config', 'plugins', 'ecc') + ); + }); + + test('antigravity-home plans complete native plugin structure for core profile', () => { + const homeDir = createTempDir('antigravity-home-test-'); + const projectRoot = createTempDir('antigravity-proj-test-'); + + try { + const plan = resolveInstallPlan({ + profileId: 'core', + target: 'antigravity-home', + homeDir, + projectRoot, + enableHooks: true, + }); + + assert.strictEqual(plan.targetAdapterId, 'antigravity-home'); + assert.strictEqual( + plan.targetRoot, + path.join(homeDir, '.gemini', 'config', 'plugins', 'ecc') + ); + + const targetRoot = plan.targetRoot; + + // Check plugin.json + assert.ok( + plan.operations.some(op => ( + op.destinationPath === path.join(targetRoot, 'plugin.json') + && op.kind === 'merge-json' + )), + 'Should plan plugin.json merge' + ); + + // Check mcp_config.json + assert.ok( + plan.operations.some(op => ( + op.destinationPath === path.join(targetRoot, 'mcp_config.json') + && op.kind === 'merge-json' + )), + 'Should plan mcp_config.json merge' + ); + + // Check hooks.json + assert.ok( + plan.operations.some(op => ( + op.destinationPath === path.join(targetRoot, 'hooks.json') + && op.kind === 'merge-json' + )), + 'Should plan hooks.json merge' + ); + + // Check rules + assert.ok( + plan.operations.some(op => ( + op.destinationPath.startsWith(path.join(targetRoot, 'rules')) + )), + 'Should plan rules into plugin rules directory' + ); + + // Check workflows + assert.ok( + plan.operations.some(op => ( + op.destinationPath.startsWith(path.join(targetRoot, 'workflows')) + )), + 'Should plan workflows' + ); + } finally { + cleanup(homeDir); + cleanup(projectRoot); + } + }); + + test('antigravity-hook-bridge handles allow decision for safe command', () => { + const bridgePath = path.join(__dirname, '..', '..', 'scripts', 'hooks', 'antigravity-hook-bridge.js'); + const input = JSON.stringify({ + conversationId: 'test-conv', + workspacePaths: ['/tmp'], + toolCall: { + name: 'run_command', + args: { + CommandLine: 'echo "hello from safe command"', + }, + }, + }); + + const run = spawnSync(process.execPath, [bridgePath, '--mode', 'pre-tool-use', '--hook', 'pre:bash:dispatcher'], { + input, + encoding: 'utf8', + }); + + assert.strictEqual(run.status, 0); + const output = JSON.parse(run.stdout); + assert.strictEqual(output.decision, 'allow'); + }); + + test('antigravity-hook-bridge returns deny for blocked git push --no-verify', () => { + const bridgePath = path.join(__dirname, '..', '..', 'scripts', 'hooks', 'antigravity-hook-bridge.js'); + const input = JSON.stringify({ + conversationId: 'test-conv', + workspacePaths: ['/tmp'], + toolCall: { + name: 'run_command', + args: { + CommandLine: 'git push origin main --no-verify', + }, + }, + }); + + const run = spawnSync(process.execPath, [bridgePath, '--mode', 'pre-tool-use', '--hook', 'pre:bash:dispatcher'], { + input, + encoding: 'utf8', + }); + + assert.strictEqual(run.status, 0); + const output = JSON.parse(run.stdout); + assert.strictEqual(output.decision, 'deny'); + assert.match(output.reason, /no-verify/i); + }); + + test('antigravity-project plans mcp_config.json when platform configs are selected', () => { + const projectRoot = createTempDir('antigravity-proj-mcp-'); + try { + const plan = resolveInstallPlan({ + moduleIds: ['platform-configs'], + target: 'antigravity', + projectRoot, + }); + + assert.strictEqual(plan.targetAdapterId, 'antigravity-project'); + const targetRoot = path.join(projectRoot, '.agents'); + + assert.ok( + plan.operations.some(op => op.destinationPath === path.join(targetRoot, 'mcp_config.json') && op.kind === 'merge-json'), + 'Should plan mcp_config.json in project .agents' + ); + } finally { + cleanup(projectRoot); + } + }); + + test('antigravity-home end-to-end install applies complete plugin directory and install state', () => { + const homeDir = createTempDir('antigravity-home-e2e-'); + const projectDir = createTempDir('antigravity-proj-e2e-'); + + try { + const { createManifestInstallPlan } = require('../../scripts/lib/install/plan'); + const { applyInstallPlan } = require('../../scripts/lib/install/apply'); + const { withHookConsent } = require('../../scripts/lib/install/hook-consent'); + const plan = withHookConsent(createManifestInstallPlan({ + profileId: 'core', + target: 'antigravity-home', + homeDir, + projectRoot: projectDir, + }), 'enabled'); + + const result = applyInstallPlan(plan); + const pluginDir = path.join(homeDir, '.gemini', 'config', 'plugins', 'ecc'); + + assert.ok(fs.existsSync(path.join(pluginDir, 'plugin.json')), 'plugin.json should exist'); + assert.ok(fs.existsSync(path.join(pluginDir, 'hooks.json')), 'hooks.json should exist'); + assert.ok(fs.existsSync(path.join(pluginDir, 'mcp_config.json')), 'mcp_config.json should exist'); + assert.ok(fs.existsSync(path.join(pluginDir, 'ecc-install-state.json')), 'install-state should exist'); + assert.ok(fs.existsSync(path.join(pluginDir, 'rules', 'common-coding-style.md')), 'rules should exist'); + assert.ok(fs.existsSync(path.join(pluginDir, 'skills', 'tdd-workflow', 'SKILL.md')), 'skills should exist'); + assert.ok(fs.existsSync(path.join(pluginDir, 'scripts', 'hooks', 'antigravity-hook-bridge.js')), 'hook bridge should exist'); + + const pluginJson = JSON.parse(fs.readFileSync(path.join(pluginDir, 'plugin.json'), 'utf8')); + assert.strictEqual(pluginJson.name, 'ecc'); + + const hooksJson = JSON.parse(fs.readFileSync(path.join(pluginDir, 'hooks.json'), 'utf8')); + assert.ok(hooksJson['ecc-guard']); + assert.ok(Array.isArray(hooksJson['ecc-guard'].PreToolUse)); + assert.ok(Array.isArray(hooksJson['ecc-guard'].Stop)); + + const mcpConfig = JSON.parse(fs.readFileSync(path.join(pluginDir, 'mcp_config.json'), 'utf8')); + assert.ok(mcpConfig.mcpServers['ecc-memory']); + } finally { + cleanup(homeDir); + cleanup(projectDir); + } + }); + + test('resolveEccRoot recognizes Antigravity global plugin install', () => { + const tempHome = createTempDir('ecc-root-test-'); + try { + const pluginDir = path.join(tempHome, '.gemini', 'config', 'plugins', 'ecc'); + fs.mkdirSync(path.join(pluginDir, 'scripts', 'lib'), { recursive: true }); + fs.mkdirSync(path.join(pluginDir, 'skills', 'continuous-learning-v2'), { recursive: true }); + fs.writeFileSync(path.join(pluginDir, 'scripts', 'lib', 'utils.js'), '// utils'); + + const resolved = resolveEccRoot({ homeDir: tempHome }); + assert.strictEqual(resolved, pluginDir); + } finally { + cleanup(tempHome); + } + }); + + console.log(`\nResults: Passed: ${passed}, Failed: ${failed}\n`); + if (failed > 0) { + process.exit(1); + } +} + +runTests(); diff --git a/tests/lib/harness-capabilities.test.js b/tests/lib/harness-capabilities.test.js index 4591403d4..35d1abb8b 100644 --- a/tests/lib/harness-capabilities.test.js +++ b/tests/lib/harness-capabilities.test.js @@ -33,12 +33,12 @@ function runTests() { let passed = 0; let failed = 0; - if (test('represents all 15 registered targets exactly once across 14 harnesses', () => { + if (test('represents all 16 registered targets exactly once across 14 harnesses', () => { const catalogTargetIds = HARNESS_CAPABILITIES.flatMap(harness => harness.targetIds); const adapterTargetIds = listInstallTargetAdapters().map(adapter => adapter.target); assert.strictEqual(HARNESS_CAPABILITIES.length, 14); - assert.strictEqual(new Set(catalogTargetIds).size, 15); + assert.strictEqual(new Set(catalogTargetIds).size, 16); assert.deepStrictEqual([...catalogTargetIds].sort(), [...SUPPORTED_INSTALL_TARGETS].sort()); assert.deepStrictEqual([...catalogTargetIds].sort(), [...adapterTargetIds].sort()); })) passed++; else failed++; @@ -84,6 +84,16 @@ function runTests() { { id: 'project', targetId: 'kimi', root: './.kimi-code' }, ]); + const antigravity = getHarnessCapability('antigravity'); + assert.deepStrictEqual(antigravity.targetIds, ['antigravity-home', 'antigravity']); + assert.strictEqual(antigravity.channel, 'native-plugin'); + assert.strictEqual(antigravity.installMode, 'native-plugin'); + assert.match(antigravity.destination, /selected Antigravity scope/i); + assert.deepStrictEqual(antigravity.scopes, [ + { id: 'user', targetId: 'antigravity-home', root: '~/.gemini/config/plugins/ecc' }, + { id: 'project', targetId: 'antigravity', root: './.agents' }, + ]); + const opencode = getHarnessCapability('opencode'); assert.match(opencode.destinationResolution, /OPENCODE_CONFIG_DIR/); assert.match(opencode.destinationResolution, /XDG_CONFIG_HOME/); @@ -93,7 +103,6 @@ function runTests() { if (test('keeps every advanced target attached to its registered root and scope', () => { const expected = { cursor: ['project', './.cursor'], - antigravity: ['project', './.agents'], gemini: ['project', './.gemini'], opencode: ['home', '~/.config/opencode'], codebuddy: ['project', './.codebuddy'], diff --git a/tests/scripts/codex-hooks.test.js b/tests/scripts/codex-hooks.test.js index c47f6d986..17efc10b4 100644 --- a/tests/scripts/codex-hooks.test.js +++ b/tests/scripts/codex-hooks.test.js @@ -406,6 +406,7 @@ function runHermeticPythonPrePush({ HOME: process.env.HOME ?? '', ECC_SKIP_GIT_HOOKS: '0', ECC_SKIP_PREPUSH: '0', + ECC_PREPUSH_RUN_CHECKS: '1', MSYS_NO_PATHCONV: '1', ...(venvDir === null || trackVenv ? {} : { VIRTUAL_ENV: toBashPath(venvDir) }), ...(override === null ? {} : { ECC_PYTEST_CMD: override }), @@ -452,7 +453,7 @@ else failed++; // A case-folded spelling, because macOS resolves `$venv/bin/python` to a committed // `Python` while git matches index pathspecs case-sensitively. Skipped where the // filesystem is case-sensitive and the two names cannot collide. -if (fs.existsSync(__filename.toUpperCase()) || fs.existsSync(__filename.toLowerCase())) { +if (fs.existsSync(__filename.toUpperCase()) && fs.existsSync(__filename.toLowerCase())) { if ( test('pre-push refuses a tracked interpreter committed under a folded case', () => { const { result, calls } = runHermeticPythonPrePush({ diff --git a/tests/scripts/control-pane.test.js b/tests/scripts/control-pane.test.js index 5503bcf95..406e09c72 100644 --- a/tests/scripts/control-pane.test.js +++ b/tests/scripts/control-pane.test.js @@ -603,7 +603,10 @@ async function runTests() { if ( await test('CLI browser opener handles spawn errors', async () => { - const source = fs.readFileSync(SCRIPT, 'utf8'); + const source = fs.readFileSync( + path.join(REPO_ROOT, 'scripts', 'lib', 'platform-launch.js'), + 'utf8' + ); assert.match(source, /child\.on\('error'/); assert.match(source, /child\.unref\(\)/);