Skip to main content
Glama
README.md
<div align="center">
  <img src="./plugin-meta/assets/logo.svg" alt="Antigravity Delegate Logo" width="84" height="84" />
  <h1>antigravity-delegate</h1>
  <p><strong>T3 Code-inspired multi-agent task delegation MCP App plugin for Antigravity, starting with OpenAI Codex.</strong></p>

  <p>
    <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License" /></a>
    <img src="https://img.shields.io/badge/node-%E2%89%A522-brightgreen.svg" alt="Node.js 22+" />
    <img src="https://img.shields.io/badge/MCP-App%20%2B%20UI-indigo.svg" alt="MCP App + UI" />
    <img src="https://img.shields.io/badge/TypeScript-5.8-3178c6.svg" alt="TypeScript" />
  </p>
</div>

> **Disclaimer:** This is an unofficial open-source community plugin. It is not affiliated with, endorsed by, or sponsored by Google, OpenAI, or T3 Tools Inc.

---

**antigravity-delegate** brings [T3 Code](https://github.com/pingdotgg/t3code)'s orchestration discipline directly into **Google Antigravity** as a self-contained **MCP App** plugin.

Your primary Antigravity agent stays in charge as the **Brain**, while bounded child tasks—cross-model quality-gate reviews, architectural second opinions, isolated Git worktree experiments, or heavy test-writing—run in OpenAI's official `codex app-server` with live streaming timelines, persistent side-pane tracking, bounded diffs, and interactive user approvals.

## Why `antigravity-delegate`?

- **Opt-in per conversation**: Normal chats stay direct and fast. Delegation activates only when you ask Antigravity to use Codex or enable collaborative mode in the current conversation.
- **No bloated context forwarding**: Child agents receive a self-contained brief rather than your full parent chat transcript.
- **Independent cross-model quality gates**: Run `role: "review"` in a read-only `plan` sandbox after refactors or `/swarm` worker runs to catch real bugs with `file:line` severity rankings (`Critical`, `Major`, `Minor`) and a clear verdict.
- **Native Antigravity MCP App UI**: Combines inline chat task cards with a persistent `Delegate` right side pane (`aux_pane`) and full-page workspace (`global`) that stays visible as chat tool steps collapse.
- **Zero-polling wake-up**: Background execution notifies the parent agent immediately on completion or approval pause over a private local Unix socket—no busy-wait polling loops.

## Features

### Orchestration & Roles
- **Two-tier control**: You opt in per conversation; the main agent selects the best role per scenario:
  - `review` / `research`: defaults to a read-only `plan` sandbox (`approvalPolicy: "on-request"`), letting inspection commands run smoothly while blocking filesystem writes and network access.
  - `implementation` / `test` / `design` / `general`: defaults to `workspace-write` (`auto-accept-edits`).
- **Two execution isolation modes**:
  - `shared`: runs in your current workspace while snapshotting pre-existing dirty files (`baselineDirtyFiles`) so `task_diff` separates task edits from your unrelated uncommitted changes.
  - `worktree`: creates a clean detached Git worktree from `HEAD` (warns if the parent workspace has uncommitted edits) with explicit user-triggered **Apply to Workspace** and **Discard Worktree** controls.
- **Multi-turn & live steering**: Continue any settled or interrupted thread with `task_followup`, override model/effort/speed per turn, or redirect an active running turn mid-flight with `delivery: "steer"`.
- **Idempotency & crash recovery**: Supports `clientRequestId` deduplication and cleanly reconciles tasks interrupted by an MCP server restart so you can resume them via follow-up.

### Zero-Polling Background Watcher (`delegate-wait`)
- Every `delegate_task` / `task_followup` defaults to `mode: "async"` and returns a ready-to-run `watchCommand` (plus optional synchronous `mode: "wait"` up to `45s`).
- State changes broadcast over `${PLUGIN_DATA}/events-<pid>.sock` (`0600`) to `bin/delegate-wait.mjs`, waking the parent agent immediately on `all_settled` or `approval_needed`.
- Supports multi-task parallel waiting (`--task-id id1:2,id2:1`) with per-task `:turn` locks.
- Outputs exceeding 16 KiB are written losslessly to disk (`fullSummaryPath`) while inline results show a bounded head+tail preview.

### Interactive MCP App UI
Bundled into a single self-contained HTML artifact (`dist/plugin/ui/app.html`) with no external network assets:
- **Executor Config Bar**: Configure and persist panel defaults (`settings.json`) for **Provider**, **Model**, **Reasoning Effort** (e.g., `medium`–`max`/`ultra`), **Speed** (`Standard` / `Fast`), and **Access Ceiling**, with live CLI/auth status diagnostics and refresh.
- **Persistent `Delegate` Side Pane & Global Workspace** (`aux_pane` / `global`):
  - Filterable **Delegate Lineage** sidebar (`all`, `active`, `waiting`, `done`) with live elapsed timers and file counts.
  - **Timeline** tab: streaming commands, file changes, reasoning, MCP tools, web search, compaction, and warnings/errors (budgeted per response to stay well under Antigravity's 1 MiB MCP payload cap).
  - **Diff** tab: bounded unified Git diff with per-file stats, clickable file links that open in Antigravity's side pane (`com.google.antigravity/toggle-aux-pane`), and a `shared`-mode **Task files vs. Workspace** scope toggle.
  - **Summary** tab: full summary preview, one-click **Open full summary**, and context/token usage breakdown.
  - **Interactive Approvals & Elicitation**: Approve, Approve Session, Decline, or answer structured Codex user-input prompts (including secret inputs and custom text) inline or in the panel.
  - **User-triggered Handoff**: **Send to Chat** (`sendMessage`) and **Attach Context** (`updateModelContext`) trigger strictly on explicit clicks.

## Architecture

```mermaid
flowchart LR
  Host["Antigravity Host + Chat Model"] -->|MCP stdio / JSON-RPC| Server["server.mjs (MCP Server)"]
  Host -->|MCP App iframe| UI["ui/app.html (Single-File React UI)"]
  UI -->|app_* tools| Server
  Server --> Orch["Orchestrator + TaskStore + SettingsStore"]
  Orch -->|ProviderAdapter| Codex["CodexAdapter (codex app-server stdio)"]
  Orch -->|task.updated| Bus["LocalEventBus (events-PID.sock)"]
  Wait["delegate-wait.mjs (Background Watcher)"] -.->|Unix socket + turn lock| Bus
  Host -->|run_command background| Wait
```

## Quick Start

### Prerequisites

- **Google Antigravity** (with MCP Apps / plugin support)
- **Node.js 22+** and **pnpm**
- Official OpenAI **`codex` CLI** installed in `PATH` and signed in:

```bash
codex --version
codex login
```

### Build & Install Locally

```bash
git clone https://github.com/JamesGZM/antigravity-delegate.git
cd antigravity-delegate

pnpm install
pnpm run typecheck
pnpm test
pnpm run build
pnpm run install:local
```

- `pnpm run build` compiles the single-file UI (`dist/plugin/ui/app.html`), bundles `dist/plugin/bin/server.mjs` and `dist/plugin/bin/delegate-wait.mjs` via `esbuild`, and copies `plugin-meta/` and docs into `dist/plugin/`.
- `pnpm run install:local` installs `dist/plugin/` cleanly to `~/.gemini/config/plugins/antigravity-delegate/` without modifying `~/.gemini/config/config.json`.

After installing or updating, **restart/reload the `antigravity-delegate` MCP server** in Antigravity (or start a new chat) so the host picks up the latest bundle and skill instructions.

## Usage Examples

Ask Antigravity naturally in any project chat:

- **Independent Quality-Gate Review**
  > *"Delegate an independent Codex quality-gate review of my uncommitted git diff in read-only plan mode."*
- **Collaborative Brain + Codex Mode**
  > *"Enable collaborative Codex mode for this conversation so you act as Brain and dispatch Codex for reviews or heavy subtasks."*
- **Isolated Worktree Experiment**
  > *"Have Codex prototype the refactor in an isolated Git worktree (`role: implementation`) and show me the diff before applying anything."*
- **Open the Persistent Side Pane**
  > *"Open the Delegate panel to configure the default Codex model, effort, and speed, or inspect running task diffs and approvals."*

The main agent follows the bundled orchestration skill ([`SKILL.md`](./plugin-meta/skills/antigravity-delegate/SKILL.md)), probes `orchestrator_capabilities` once, launches `delegate_task`, opens the persistent `Delegate` right side pane via `open_delegate_panel`, and waits cleanly via `delegate-wait.mjs`.

## MCP Tool Reference

### Model-Visible Tools (8)

| Tool | Purpose |
| :--- | :--- |
| `orchestrator_capabilities` | Probes local CLI readiness, auth status, models, dynamic options (`reasoningEffort`, `serviceTier`), and saved panel defaults. |
| `delegate_task` | Starts a bounded child task with `role`, `isolation` (`shared` \| `worktree`), `mode` (`async` \| `wait`), optional `target` overrides, and optional `clientRequestId`. |
| `task_status` | Reads compact status, `workState`, pending approvals, changed files, and bounded summary for a task. |
| `task_read` | Paginates task timeline with UTF-8 byte budgets (`view: "messages"` \| `"activity"` or `itemId` + `textOffset` for large items). |
| `task_diff` | Computes bounded unified Git diff and changed files (`scope: "task"` \| `"workspace"`, optional `paths` filter). |
| `task_followup` | Sends a follow-up `prompt` to a settled/interrupted thread or steers a running turn (`delivery: "auto"` \| `"turn"` \| `"steer"`). |
| `task_cancel` | Interrupts and cancels an active task cleanly. |
| `open_delegate_panel` | Opens or focuses the persistent `Delegate` side/global UI panel (`aux_pane` & `global`). |

### App-Only Tools (11, hidden from models via `visibility: ["app"]`)

Used exclusively by the embedded MCP App UI over `callServerTool`:
`app_list_tasks`, `app_get_task`, `app_get_diff`, `app_respond_approval`, `app_followup_task`, `app_get_capabilities`, `app_get_settings`, `app_update_settings`, `app_cancel_task`, `app_apply_worktree`, `app_discard_worktree`.

## Runtime Modes & Access Ceiling

`antigravity-delegate` enforces T3 Code's monotonic permission ceiling: a child task can never escalate beyond the **Access Ceiling** configured by you in the Delegate panel (`settings.json`).

| Mode | Codex `approvalPolicy` | Codex `approvalsReviewer` | Sandbox (`interactionMode: "default"`) | Sandbox (`interactionMode: "plan"`) |
| :--- | :--- | :--- | :--- | :--- |
| `approval-required` | `untrusted` | `user` | `read-only` | `read-only` |
| `auto-accept-edits` | `on-request` | `user` | `workspace-write` (no network) | `read-only` |
| `auto` *(default ceiling)* | `on-request` | `auto_review` | `workspace-write` (no network) | `read-only` |
| `full-access` *(panel opt-in only)* | `granular` (`mcp_elicitations: true`) | `user` | `danger-full-access` | `read-only` |

Never emits `--dangerously-bypass-approvals-and-sandbox` or `approvalPolicy: "never"`.

## Security & Compliance

- **Zero-touch authentication**: Auth state is queried strictly through `codex app-server`'s official `account/read` RPC. The plugin never reads, parses, stores, or logs `~/.codex/auth.json`, OAuth tokens, or API keys.
- **Official protocol only**: Spawns only your locally installed official `codex` binary (`codex --version` and `codex app-server --listen stdio://`).
- **Sanitized persistence & path safety**: Data directory (`0700`), task/settings files (`0600`), and Unix sockets (`0600`) stay private to the user; `taskId` inputs are validated against `^[a-zA-Z0-9_-]{1,128}$` to block path traversal.
- **Strict UI isolation**: Single-file HTML bundle with no external network requests or remote scripts; `sendMessage` and `updateModelContext` fire only on explicit user clicks.

## Project Structure

```text
├── plugin-meta/
│   ├── assets/logo.svg
│   ├── mcp_config.json          # Antigravity MCP server launch config
│   ├── plugin.json              # Plugin manifest & suggested prompts
│   └── skills/antigravity-delegate/SKILL.md
├── scripts/
│   ├── build-plugin.mjs         # Vite single-file UI + esbuild server/watcher bundle
│   ├── gen-codex-types.mjs      # Optional Codex app-server TS definition generator
│   └── install-local.mjs        # Copies dist/plugin/ to ~/.gemini/config/plugins/
├── src/
│   ├── adapters/codex/          # CodexAdapter, JSON-RPC client, runtime mode mapping
│   ├── cli/delegate-wait.ts     # Socket-backed zero-polling watcher CLI
│   ├── core/                    # Orchestrator, TaskStore, SettingsStore, EventBus, Git worktree
│   ├── server/index.ts          # MCP Server & MCP App tool/resource registration
│   └── ui/                      # React MCP App UI (InlineTaskCard, PanelWorkspace, DiffViewer, etc.)
└── tests/                       # Vitest integration & unit test suites
```

## Development & Testing

```bash
pnpm run typecheck        # Type-check server, core, CLI, UI, and tests
pnpm test                 # Run Vitest unit & integration suites
pnpm run build:ui         # Build single-file UI bundle only
pnpm run build            # Build complete dist/plugin/ artifact
pnpm run install:local    # Install dist/plugin/ locally
pnpm run gen:codex-types  # Optional: regenerate Codex protocol types via local codex CLI
```

### Adding Another Provider

The orchestrator talks to providers through [`ProviderAdapter`](./src/core/adapter.ts). To support another coding CLI or runtime alongside [`CodexAdapter`](./src/adapters/codex/CodexAdapter.ts), implement `ProviderAdapter` (`probeCapabilities`, `startTurn`, optional `steerTurn`/`unloadThread`, `interruptTurn`, `respondApproval`, `dispose`) and register it in [`src/server/index.ts`](./src/server/index.ts).

## Acknowledgements

Architecture and orchestration semantics draw inspiration from [pingdotgg/t3code](https://github.com/pingdotgg/t3code) (MIT License). See [NOTICE](./NOTICE) for attribution details.

## License

Licensed under the [MIT License](./LICENSE).