[KINAN]: [Request interrupted by user for tool use] [KINAN]: Implement the following plan: # Complete Interactive Sync with Google Antigravity ## Context Genesis V2 has a fully built MCP server (`genesis_v2/mcp/`) with 10 tools (KG, browser, identity, health) running via stdio. The Antigravity system (Gemini-powered orchestration) has workflow planning, memory bridging, and a Chrome extension frontend - but none of these are accessible from Claude Code sessions. The `mcp-config.json` at root is for the Gemini ADK agent, NOT Claude Code. Claude Code's `.claude/settings.json` has no `mcpServers` section. **Goal**: Make Genesis V2's full capability set available as Claude Code MCP tools, add Antigravity sync tools for bidirectional Gemini interaction, create a shared state protocol, and build the WebSocket backend the Chrome extension expects. --- ## Phase 1: Register Genesis V2 MCP in Claude Code **Files to modify:** - `/mnt/e/genesis-system/.claude/settings.json` - Add `mcpServers` section - `/mnt/e/genesis-system/genesis_v2/mcp/stdio_server.py` - Add missing `health_check` tool **What happens:** 1. Add `mcpServers.genesis-v2` to `.claude/settings.json` with WSL paths: ```json "mcpServers": { "genesis-v2": { "command": "python3", "args": ["-m", "genesis_v2.mcp.stdio_server"], "cwd": "/mnt/e/genesis-system", "env": { "PYTHONPATH": "/mnt/e/genesis-system" } } } ``` 2. Add `health_check` import + TOOLS entry + TOOL_HANDLERS entry to `stdio_server.py` (currently missing despite being in `native_server.py`) **Verification:** Start new Claude Code session, call `kg_search("pricing")`, `health_check()`, `get_identity()` --- ## Phase 2: Add Antigravity Sync Tools to MCP Server **Files to create:** - `/mnt/e/genesis-system/genesis_v2/mcp/antigravity_tools.py` - 8 new tool functions **Files to modify:** - `/mnt/e/genesis-system/genesis_v2/mcp/stdio_server.py` - Import + register 8 new tools - `/mnt/e/genesis-system/genesis_v2/mcp/native_server.py` - Register in `get_mcp_tools()` **8 new tools (all return JSON strings, follow existing pattern):** | Tool | Purpose | Wraps | |------|---------|-------| | `antigravity_plan(goal, context_json)` | Create workflow plan via Gemini | `AntigravityWorkflow.create_plan()` | | `antigravity_execute(plan_id)` | Execute a planned workflow | `AntigravityWorkflow.execute_plan()` | | `gemini_query(prompt, task_type, temperature)` | Direct Gemini execution | `GeminiClient.generate()` | | `sync_push(context_json)` | Push context to shared state | File-based state write | | `sync_pull()` | Pull latest shared state | File-based state read | | `sync_status()` | Get sync health | Component health check | | `memory_query(query)` | Query memory bridge with Gemini context | `MemoryBridge.query_with_memory()` | | `memory_store(insight_json)` | Store insight in memory bridge | `MemoryBridge.store_insight()` | **Key dependencies reused (not recreated):** - `swarms/implementations/gemini-integration/antigravity_workflow.py` - `AntigravityWorkflow` class - `swarms/implementations/gemini-integration/gemini_memory_bridge.py` - `MemoryBridge`, `GeminiClient` - `genesis_v2/mcp/validation.py` - `check_rate_limit()` for all tools **Graceful degradation:** All Gemini-dependent tools wrapped in try/except. If `GEMINI_API_KEY` is missing, tools return clear error messages. Existing KG/browser/identity tools remain unaffected. --- ## Phase 3: Shared State Protocol **Files to create:** - `/mnt/e/genesis-system/data/antigravity-sync/` directory structure (created by tools on first use) **State format:** ``` data/antigravity-sync/ current_state.json # Merged state (last_updated, active_plan, agent contexts) events.jsonl # Append-only event log (source, type, data, timestamp) plans/ # Workflow plans from antigravity_plan() executions/ # Results from antigravity_execute() context/ # Per-agent context snapshots ``` - `events.jsonl` is append-only (safe for concurrent writes) - `current_state.json` uses read-modify-write with advisory file locking - Both Claude Code (via MCP tools) and Gemini (via AntigravityWorkflow) read/write to same state --- ## Phase 4: Extension Backend + WebSocket Server **Files to create:** - `/mnt/e/genesis-system/genesis_v2/server/__init__.py` - `/mnt/e/genesis-system/genesis_v2/server/websocket_bridge.py` - aiohttp server on port 8765 - `/mnt/e/genesis-system/scripts/start_ws_bridge.sh` - Launch script **Files to modify:** - `/mnt/e/genesis-system/genesis_v2/core/browser.py` - Auto-detect stub mode (check if WS server is running before defaulting to stub) **Server provides:** - `POST /session/start` - Chrome extension session init - `POST /vision` - DOM/screenshot data from extension (auto-extracts decisions when on gemini.google.com) - `POST /tools/call` - HTTP-accessible tool execution (any of the 18 tools) - `GET /health` - Server health - `WS /voice` - Voice I/O bridge for extension - `WS /ws` - Browser command bridge for `BrowserController` **Gemini decision extraction:** When the extension sends vision data from `gemini.google.com`, the server uses `gemini_query()` to analyze the DOM and extract decisions/action items, then pushes them to shared state via `sync_push()`. **Dependency:** `aiohttp` package (add to requirements) --- ## Verification Plan 1. **Phase 1:** Start Claude Code session, verify `mcp__genesis-v2__kg_search` appears in tool list, call it 2. **Phase 2:** Call `mcp__genesis-v2__sync_status`, `mcp__genesis-v2__gemini_query` from Claude Code 3. **Phase 3:** Call `sync_push` then `sync_pull`, verify round-trip in `data/antigravity-sync/` 4. **Phase 4:** Start WS bridge, verify `curl http://localhost:8765/health` returns healthy, test `/tools/call` --- ## Execution Order ``` Phase 1 (MCP Registration) ← Start here, no dependencies Phase 2 (Antigravity Tools) ← After Phase 1 (needs MCP server working) Phase 3 (Shared State) ← Parallel with Phase 2 (created by tools on first use) Phase 4 (WS Bridge Server) ← After Phase 2+3 (uses all tools + shared state) ``` **Total new files:** 4 | **Total modified files:** 4 If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /home/authentic88/.claude/projects/-mnt-e-genesis-system/6ca72d1c-7c39-49f2-b648-dfeecda05520.jsonl [GENESIS]: I'll implement this plan across all 4 phases. Let me start by reading the existing files I need to modify. [GENESIS]: Now let me read all the files I need to understand. [GENESIS]: Now let me read the key dependency files in parallel. [GENESIS]: Now let me read the Antigravity dependencies. [GENESIS]: Good, I have all the context I need. Let me start implementing Phase 1. [GENESIS]: **Phase 1: Register Genesis V2 MCP in Claude Code** First, add `mcpServers` to `.claude/settings.json` and add `health_check` to `stdio_server.py`. [GENESIS]: Now add `health_check` to `stdio_server.py`: [GENESIS]: Now add the `health_check` tool definition and handler: [GENESIS]: Phase 1 is done. Now Phase 2 and 3 together (shared state is created on first use by the tools). [GENESIS]: **Phase 2 + 3: Create antigravity_tools.py with shared state protocol** [GENESIS]: Now register all 8 tools in `stdio_server.py`: [GENESIS]: Now add the antigravity tools imports and registrations to `stdio_server.py`: [GENESIS]: Now add all 8 tool definitions to `TOOLS`: [GENESIS]: Now add the 8 tool handlers: [GENESIS]: Now register the 8 tools in `native_server.py`'s `get_mcp_tools()`: [GENESIS]: Phases 2 and 3 are complete. Now Phase 4. [GENESIS]: **Phase 4: Extension Backend + WebSocket Server** Let me read the existing browser.py to understand the stub mode detection I need to modify. [GENESIS]: Now modify `browser.py` to auto-detect stub mode by checking if the WS server is running: [GENESIS]: Now create the server directory and WebSocket bridge: [GENESIS]: Now create the launch script: [GENESIS]: Now add `aiohttp` to the requirements file: [GENESIS]: Now let me verify the `__init__.py` for the MCP module exports the new tools: [GENESIS]: Now let me do a quick syntax verification on all the new/modified files: [GENESIS]: All files pass syntax check. Let me also verify the native_server.py and browser.py edits: [GENESIS]: All 8 files pass syntax validation. [GENESIS]: Let me verify the final state of the settings file: [GENESIS]: All 4 phases are complete. Here's a summary of everything implemented: ## Implementation Summary ### Phase 1: MCP Registration - **`.claude/settings.json`** - Added `mcpServers.genesis-v2` section with stdio transport pointing to `genesis_v2.mcp.stdio_server` - **`genesis_v2/mcp/stdio_server.py`** - Added `health_check` import, TOOLS entry, and TOOL_HANDLERS entry (was missing despite existing in `native_server.py`) ### Phase 2: Antigravity Sync Tools - **`genesis_v2/mcp/antigravity_tools.py`** (new, 440 lines) - 8 tool functions: - `antigravity_plan` / `antigravity_execute` - Gemini workflow planning and execution - `gemini_query` - Direct Gemini execution with task type and temperature control - `sync_push` / `sync_pull` / `sync_status` - Shared state read/write/health - `memory_query` / `memory_store` - Memory bridge integration - All tools have rate limiting, input validation, and graceful degradation when Gemini API key is missing - **`genesis_v2/mcp/stdio_server.py`** - Registered all 8 tools (imports, TOOLS dict, TOOL_HANDLERS dict) - **`genesis_v2/mcp/native_server.py`** - Registered all 8 as `FunctionTool` in `get_mcp_tools()` - **`genesis_v2/mcp/__init__.py`** - Updated exports ### Phase 3: Shared State Protocol Built into `antigravity_tools.py` - creates `data/antigravity-sync/` on first use: - `current_state.json` - Advisory file-locked read-modify-write - `events.jsonl` - Append-only event log (concurrent-write safe) - `plans/`, `executions/`, `context/` - Subdirectories for artifacts ### Phase 4: WebSocket Bridge Server - **`genesis_v2/server/__init__.py`** (new) - Module init - **`genesis_v2/server/websocket_bridge.py`** (new, 370 lines) - aiohttp server on port 8765: - `GET /health` - Server health - `POST /session/start` - Chrome extension session init - `POST /vision` - DOM/screenshot with Gemini decision extraction from `gemini.google.com` - `POST /tools/call` - HTTP access to all 18 tools - `WS /ws` - Browser command bridge - `WS /voice` - Voice I/O bridge - CORS middleware for Chrome extension access - **`genesis_v2/core/browser.py`** - Added `_detect_ws_server()` for auto-detection of real mode - **`scripts/start_ws_bridge.sh`** (new) - Launch script - **`infra/requirements.txt`** - Added `aiohttp>=3.9.0` ### Verification Steps 1. Start a new Claude Code session - `mcp__genesis-v2__*` tools should appear (18 total) 2. Call `sync_status` to verify sync system health 3. Call `sync_push` then `sync_pull` to verify round-trip 4. Run `./scripts/start_ws_bridge.sh` then `curl http://localhost:8765/health`