AGY Leader
README.md
# AGY Leader
<p align="center">
<img src="assets/logo.svg" alt="AGY Leader" width="96">
</p>
English | [简体中文](README.zh-CN.md)
An Antigravity plugin and Model Context Protocol (MCP) server that routes coding and review tasks to local Codex and Claude Code CLIs in isolated Git worktrees.
AGY Leader lets **Gemini in Antigravity act as your Chief of Staff and Commander**—translating natural human intent into clear engineering specifications, dispatching work to local `codex` and `claude` CLIs over stdio MCP, and reporting results back in plain language. Instead of letting multiple execution agents overwrite the same working tree or forcing you to wrestle with rigid prompt phrasing, it leases separate Git worktrees for parallel tasks, audits every turn, and lets you inspect diffs before applying patches back to your main checkout.
The plugin also ships two built-in MCP Apps—**AGY Leader · Monitor** (global dashboard) and **AGY Leader · Trace** (conversation side pane)—so you can track active jobs, Project/Session history, four-stage timing, and changed files without leaving Antigravity.
## Features
- **Multi-provider routing**: Dispatch tasks to local Codex CLI or Claude Code CLI through a unified MCP toolset (`agent_ask`, `agent_run_task`, `agent_start_task`).
- **Isolated parallel Git worktrees**: Run concurrent edits safely with `isolate_worktree: true`, review patches via `diff`, and run conflict-checked `apply` or `cleanup`.
- **Built-in observability**: Inspect live task execution, Project/Session history, success rates, and four-stage latency in **AGY Leader · Monitor** and **AGY Leader · Trace**.
- **Restricted Claude Code isolation**: Supports `claude auth login` as well as `ANTHROPIC_API_KEY` / `ANTHROPIC_AUTH_TOKEN` and custom `ANTHROPIC_BASE_URL` gateways while keeping turns under `--restricted --safe-mode`.
- **Optional Rust/WASM acceleration**: Uses `crates/accel-wasm` for fast file fingerprinting, UTF-8 truncation, and NDJSON parsing, with an automatic TypeScript fallback.
### Preview
| Task delegation in Antigravity | AGY Leader · Monitor dashboard |
| --- | --- |
|  |  |
## Project status
> [!NOTE]
> Current version: `0.3.0` (`plugin.json` / `package.json`). Active development; suitable for local daily workflows with Antigravity, Codex CLI, and Claude Code CLI.
## Table of contents
- [Quick start](#quick-start)
- [Requirements](#requirements)
- [Installation and configuration](#installation-and-configuration)
- [Usage](#usage)
- [Architecture and project structure](#architecture-and-project-structure)
- [Testing and development](#testing-and-development)
- [Troubleshooting](#troubleshooting)
- [License](#license)
## Quick start
### 1. Install dependencies, build UI, and run diagnostics
From the repository root:
```sh
bun install
bun run build
bun run doctor
```
`bun run doctor` verifies the UI bundle, optional WASM module, and each provider's binary path and authentication status. Confirm that at least one provider reports `healthy: true` and the UI assets are built.
### 2. Install and enable the Antigravity plugin
```sh
bun run install:plugin --symlink && agy plugin enable agy-leader
```
### 3. Verify in Antigravity
Open **Customizations → Installed** in Antigravity and confirm **AGY Leader** is enabled. You can then open **AGY Leader · Monitor** from the global **Plugins** sidebar or **AGY Leader · Trace** from a conversation's side pane.
## Requirements
| Dependency | Minimum | Recommended | Notes |
| --- | --- | --- | --- |
| Bun | `1.4.5` | Latest `1.4.x` | Runtime, package manager, and test runner |
| Git | `2.30+` | Latest | Required for isolated worktrees and patch audit |
| Codex CLI | Authenticated | Latest | Optional if using Claude Code only |
| Claude Code CLI | `2.1.259` | Latest | Optional if using Codex only |
| Antigravity CLI (`agy`) | Installed | Latest | Required for `agy plugin enable` and strict validation |
| Rust + `wasm-pack` | `1.100.0` (CI) | Latest | Optional; TypeScript fallback is used when absent |
## Installation and configuration
### Antigravity plugin installation
- **Development symlink mode** (`bun run install:plugin --symlink`): Creates `~/.gemini/config/plugins/agy-leader` linked to your checkout and generates an absolute-path `mcp_config.json` (mode `0600`). Re-running refreshes links and preserves an existing `mcpServers["agy-leader"].env` object.
- **Standalone copy mode** (`bun run install:plugin`): Copies the plugin into `~/.gemini/config/plugins/agy-leader` without symlinking the checkout.
- **Custom config root**: Pass `--config-dir <path>` to target an isolated Antigravity configuration directory.
### Standalone MCP server
To run the stdio MCP server directly from the checkout (or register it in another MCP host using the absolute path to `src/index.ts`):
```sh
bun run start
```
### Environment variables
Set these in the MCP server's `env` (for example in `~/.gemini/config/plugins/agy-leader/mcp_config.json`):
| Variable | Required | Default | Description |
| --- | --- | --- | --- |
| `CODEX_BIN` | No | `codex` on `PATH` | Explicit path to the Codex CLI binary |
| `CLAUDE_BIN` | No | `claude` on `PATH` | Explicit path to the Claude Code CLI binary |
| `DEFAULT_AGENT_PROVIDER` | No | First ready provider | Default provider ID (`codex` or `claude-code`) |
| `AGY_LEADER_TRACE_FILE` | No | `~/.gemini/config/agy-leader-traces.jsonl` | Path to local trace history JSONL (legacy alias: `AGENT_MCP_TRACE_FILE`) |
| `AGY_LEADER_WORKTREE_DIR` | No | `~/.gemini/cache/agy-leader-worktrees` | Directory for managed Git worktrees (legacy alias: `AGENT_MCP_WORKTREE_DIR`) |
### Claude Code authentication and custom gateways
Claude Code works either via `claude auth login` or by setting `ANTHROPIC_API_KEY` / `ANTHROPIC_AUTH_TOKEN` (and `ANTHROPIC_BASE_URL` for a custom gateway) in the MCP server `env` or in `~/.claude/settings.json` (or `$CLAUDE_CONFIG_DIR/settings.json`):
```json
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "<your-gateway-token>",
"ANTHROPIC_BASE_URL": "https://gateway.example.com",
"ANTHROPIC_MODEL": "sonnet",
"CLAUDE_CODE_EFFORT_LEVEL": "high"
}
}
```
Nonblank MCP process `env` values take precedence over `~/.claude/settings.json`. Turns always run with `--restricted --safe-mode`; project-level `.claude/settings.json`, hooks, permissions, and executable variables like `PATH` or `NODE_OPTIONS` are never imported from user settings. See [Claude authentication and isolation](docs/architecture.md#claude-authentication-and-isolation) for the full allowlist and `apiKeyHelper` behavior.
## Usage
### Typical workflow
1. **Discover providers and models**: Call `agent_list_providers` to check readiness, and `agent_list_models` to inspect available models.
2. **Run a read-only query or isolated edit**:
- Use `agent_ask` for synchronous, read-only questions or code reviews.
- Use `agent_start_task` with an absolute `cwd`, `prompt`, `provider` (`codex` or `claude-code`), and `isolate_worktree: true` to run background edits in an isolated checkout.
3. **Monitor, review, and apply**:
- Poll `agent_task_status` with the returned `job_id`.
- Inspect the patch with `agent_manage_worktrees` (`action: "diff"`).
- Apply approved changes back to the original checkout with `action: "apply"`, or discard them with `action: "cleanup"`.
For session resumption, routing guidelines, and cleanup policies, see [skills/agy-leader/SKILL.md](skills/agy-leader/SKILL.md) and [rules/AGENTS.md](rules/AGENTS.md).
### MCP tools
| Tool | Purpose |
| --- | --- |
| `agent_list_providers` | List registered providers and their health/readiness |
| `agent_list_models` | List available models for a provider |
| `agent_ask` | Run a synchronous read-only query |
| `agent_run_task` | Run a synchronous task |
| `agent_start_task` | Launch a background task (supports `isolate_worktree: true`) |
| `agent_task_status` | Poll status, output, and audit metadata for a `job_id` |
| `agent_cancel_task` | Cancel a queued or running background job |
| `agent_manage_threads` | List or inspect provider conversation threads |
| `agent_manage_worktrees` | Inspect `diff`, `apply` patches, or `cleanup` worktrees |
| `agent_open_status` | Open **AGY Leader · Trace** in the conversation side pane |
| `agent_open_monitor` | Open **AGY Leader · Monitor** in the global Plugins view |
## Architecture and project structure
```mermaid
flowchart LR
AGY["Antigravity"] -->|MCP over stdio| Server["AGY Leader MCP server"]
Server --> Jobs["Task scheduler"]
Jobs --> Registry["Provider registry"]
Registry --> Codex["Codex CLI"]
Registry --> Claude["Claude Code CLI"]
Jobs --> Worktree["Git worktree & audit"]
Jobs --> Traces["Local trace store"]
Traces --> Apps["Trace pane & Monitor dashboard"]
```
```text
.
├── src/
│ ├── index.ts # Stdio MCP entry point, --doctor flag, default registry
│ ├── mcp/ # MCP tool registration and request validation
│ ├── core/ # Job manager, worktree lifecycle, git audit, trace store, accelerator
│ └── providers/ # Codex and Claude Code CLI adapters
├── ui/ # MCP App sources and built HTML bundles (sidebar & dashboard)
├── crates/accel-wasm/ # Optional Rust/WASM accelerator crate
├── skills/agy-leader/ # /agy-leader skill instructions
├── rules/ # Default routing rules (AGENTS.md)
├── scripts/ # Build (build-ui, build-wasm) and plugin installer scripts
├── docs/ # Detailed architecture, lifecycle, and auth isolation docs
├── assets/ # Plugin logo and documentation screenshots
└── tests/ # Unit and mocked subprocess integration tests
```
See [docs/architecture.md](docs/architecture.md) for provider protocol details, worktree lifecycle, trace storage limits, and instructions on [adding a new provider](docs/architecture.md#add-a-provider).
## Testing and development
Run the full verification suite from the repository root:
```sh
bun run build:ui
bun run typecheck
bun test
cargo fmt --check --manifest-path crates/accel-wasm/Cargo.toml
cargo test --locked --manifest-path crates/accel-wasm/Cargo.toml
cargo clippy --locked --manifest-path crates/accel-wasm/Cargo.toml --all-targets -- -D warnings
agy plugin validate --strict .
```
Provider tests use local mocked subprocesses and do not require live provider credentials.
## Troubleshooting
- **Provider reports unavailable**: Run `bun run doctor` and check `healthy` and `message`. If the binary is outside standard `PATH` (common in GUI hosts), set `CODEX_BIN` or `CLAUDE_BIN` in the installed `mcp_config.json`.
- **Monitor or Trace panel fails to load**: Rebuild the UI assets with `bun run build:ui` and re-run `bun run doctor`.
- **Duplicate or legacy plugin entries**: The installer reports legacy entries during `bun run install:plugin`; disable older entries under **Customizations → Installed** in Antigravity after verifying the new installation.
## License
Released under the [MIT License](LICENSE).