gemini-handoff
by luminous-JT8
README.md
# Antigravity Gemini Handoff (`gemini-handoff`)
An open-source **Antigravity** plugin (MCP Server + Skill) that **automatically offloads** heavy-reasoning, architecture design, long-document review, and standalone code generation subtasks from Antigravity to **Gemini** — with **zero manual copy-paste**, **zero-token-relay disk packing**, **hybrid execution engines**, and **strict Token ROI caps**.
> **You only decide two things**: ① whether the plugin is on (`ask` / `manual` / `off`), and ② which recommended subtasks to check off. Packing, sending, waiting, and compact summary collection all happen automatically.
---
## Why This Exists
- **Save Antigravity Quota**: Offload heavy thinking / long-output tasks to Gemini Desktop or Web while keeping rapid file editing, testing, and debugging inside Antigravity.
- **Compliant & Resilient**: No cookie scraping, no undocumented private APIs, no brittle GUI click automation. You pick the exact model in Gemini Desktop and stay in full control.
- **Zero-Token-Relay Packing**: Antigravity passes only file paths + a brief goal; the local MCP server reads, trims, and packs files directly from disk into your clipboard and `.handoff/outbox/` — large source files never enter Antigravity's context just to be forwarded.
- **Summary-First Collection**: Long replies from Gemini Desktop are saved verbatim to `.handoff/inbox/`, while Antigravity receives only a compact summary + structured code section index (`<= 4KB` hard cap) and pulls specific code blocks on demand.
---
## Architecture
```mermaid
flowchart LR
A["Antigravity Agent"] -->|"1. User checks subtasks → handoff_run(goal + filePaths)"| B["gemini-handoff MCP Server"]
B -->|"2. Read disk directly + trim (0 tokens relayed)"| C["Hybrid Transport Engine"]
C -->|"desktop_auto (UIA) / gemini_cli / api"| D["Gemini Desktop or Headless Gemini"]
D -->|"3. Auto-capture reply → .handoff/inbox/"| B
B -->|"4. Return <=4KB summary + section index"| A
A -->|"5. Pull only needed code blocks & verify"| A
```
---
## Hybrid Transport Engines (Switch Anytime)
Configure `transport` via `handoff_config`:
| Transport | How It Works | Cost / Trade-off |
| :--- | :--- | :--- |
| **`desktop_auto`** *(Default)* | Automatically launches/focuses local Gemini Desktop (`F:\Gemini\App`), pastes prompt, sends, waits for completion, clicks Copy, and collects Markdown via Windows UI Automation. Falls back cleanly to `clipboard` if UIA cannot reach the window. | **Zero extra API cost** (uses your Gemini Desktop subscription). |
| **`gemini_cli`** | Spawns Google's official `@google/gemini-cli` headlessly via stdin/stdout. | **100% background, zero window focus stealing, parallelizable** (uses Gemini CLI OAuth quota). |
| **`api`** | Calls official Google Generative Language REST API using `GEMINI_API_KEY` (Node 20+ native `fetch`, zero extra deps). | **100% background & deterministic** (uses AI Studio API key). |
| **`clipboard`** | Classic manual clipboard + desktop launch mode. | Zero automation dependencies; always available as fallback. |
---
## Operating Modes (Toggle Anytime)
Switch modes anytime via `handoff_config` (or just tell Antigravity):
| Mode | Behavior |
| :--- | :--- |
| **`ask`** *(Default — Form 1)* | For complex tasks, Antigravity splits subtasks and asks you (multi-select) which ones to hand off to Gemini Desktop, with model suggestions. |
| **`manual`** *(Form 2)* | Silent during normal work; activates only when you explicitly ask to hand off or collect a task. |
| **`off`** | Disabled; zero intervention. |
---
## Built-in Guardrails
### Token ROI Protection
1. **Direct Disk Packing**: Files are read directly by the local MCP server, never echoed through Antigravity's LLM context.
2. **Hard Size Caps**: Enforces `maxFilesPerTask` (20), `maxFileBytes` (40 KB), `maxPackBytes` (120 KB), and `maxResponseBytes` (4 KB) on tool outputs.
3. **Built-in ROI Ledger**: Every pack & collect logs estimated bypassed input tokens and compressed output tokens (`handoff_stats`).
### Stability & Security
1. **Pure `stdio` MCP Stream**: `console.log` is redirected to `stderr`; JSON-RPC stdout can never be polluted.
2. **Non-blocking & Crash-Proof**: Global `uncaughtException`/`unhandledRejection` handlers, detached desktop launch, clipboard subprocess timeouts (`5s`), and structured error responses.
3. **Path Traversal Protection**: Every packed file and every `file=...` target in collected code blocks is checked against `workspaceRoot` via `path.resolve` / `path.relative`.
---
## Installation (Antigravity Plugin)
1. Clone this repository into your Antigravity plugins directory:
```bash
git clone <your-repo-url> ~/.gemini/config/plugins/gemini-handoff
cd ~/.gemini/config/plugins/gemini-handoff
npm install
npm run build
```
2. Run the verification suite:
```bash
npm test
```
3. Configure your local Gemini Desktop path (optional — e.g. on Windows):
Tell Antigravity:
> Configure `gemini-handoff` with `desktopAppPath` set to `F:\Gemini\App` and mode `ask`.
---
## MCP Tools Provided
| Tool | Purpose |
| :--- | :--- |
| `handoff_config` | Get/set `enabled`, `mode` (`ask` / `manual` / `off`), `transport` (`desktop_auto` / `gemini_cli` / `api` / `clipboard`), `desktopAppPath`, `cliCommand`, `apiModel`, `desktopTimeoutSec`. |
| `handoff_run` | **Primary zero-copy-paste tool**: reads files directly from disk, dispatches via configured transport, waits for Gemini's reply, saves full output to `.handoff/inbox/`, and returns `<= 4KB` summary + section index. |
| `handoff_read_section` | Read a single parsed code block (`S1`, `S2`, ...) on demand with strict byte caps. |
| `handoff_stats` | Display cumulative Token ROI ledger and recent tasks. |
| `handoff_pack` / `handoff_collect` | Manual two-step pack & collect tools kept for custom workflows and clipboard fallback. |
---
## Verification & Real A/B Token Benchmark
### Measured E2E Handoff (Windows + Gemini Desktop `F:\Gemini\App`)
Real task: **Full Security & Ergonomics Audit of `gemini-handoff`** (8 TypeScript source & test files, 47,609 bytes packed directly from disk → Gemini Desktop → collected via clipboard).
| Metric | Without Handoff (Direct in Antigravity) | With `gemini-handoff` | Savings |
| :--- | ---: | ---: | ---: |
| **Input context loaded into Antigravity** | ~11,902 tokens (8 files read into context) | ~330 tokens (path list + brief goal only) | **11,572 tokens bypassed (-97.2%)** |
| **Output loaded back into Antigravity** | ~2,246 tokens (8,990 B full audit reply) | 173 tokens (`<<<HANDOFF_SUMMARY>>>` + index) | **2,073 tokens compressed (-92.3%)** |
| **Total Antigravity Token Footprint** | **~14,148 tokens** | **~503 tokens** | **~13,645 net tokens saved (-96.4%)** |
> **Tip**: In Gemini Desktop/Web, click the **"Copy"** icon on the response (rather than dragging to highlight rendered HTML) so fenced code blocks (` ```ts `) are preserved for `handoff_read_section`.
### Pre-Release Checklist
- [x] Unit tests: config recovery, path traversal & symlink defense, UTF-8 byte truncation, binary skip, ROI ledger (`npm test`)
- [x] Live MCP `stdio` integration test: full `initialize` → `tools/list` → `tools/call` lifecycle + error survival (`npm test`)
- [x] Local E2E smoke test with Gemini Desktop client (`F:\Gemini\App\Gemini.exe`) via live Antigravity MCP server
- [x] Real A/B Token comparison recorded in this README
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues