Skip to main content
Glama
README.md
# Codex Executor

An **Antigravity** plugin that turns **Antigravity** into the orchestrator (planning, architecture, design, copywriting, and verification) and **Codex CLI** into a strictly guarded, high-cache, minimal-output execution engine via MCP.

> **Antigravity 负责总控(规划、架构、审美、文案与验收) · Codex 负责执行(严格按边界写代码、跑命令与验证)**

---

## Why Codex Executor?

- **Clear division of labor**: Antigravity pre-decides design, copy, and architecture, then dispatches crisp imperative work orders to Codex—eliminating verbose GPT prose and unrequested freelancing.
- **Minimal output overhead**: Enforces `model_reasoning_summary="none"`, `hide_agent_reasoning=true`, zero pre-tool narration, and a 2-field JSON ACK (`{"ok": boolean, "err": string}`). All real file diffs, commands, and exit codes are captured directly by the MCP bridge from JSONL events and Git/filesystem snapshots.
- **Lean prefix & persistent cache lanes**: Disables unused Codex Desktop plugins/UI features on worker runs to cut cold input tokens, and persists workspace cache lanes (`session_mode: "auto"`) keyed by exact prefix signature `(cwd, lane, model, reasoning_effort, sandbox, prompt_hash, schema_hash)` for high prompt-cache reuse across turns.
- **Engine-level runtime guardrails**:
  - **Destructive command blocker**: Real-time JSONL watchdog kills processes attempting unauthorized `git reset --hard`, `git clean -f`, `git push --force`, root deletes, sensitive dotfile edits, or remote pipe execution.
  - **File-scope cage (`allowed_paths` / `forbidden_paths`)**: Real-time and post-run verification of all touched files, with automatic revert (`auto_revert_violations`) of unauthorized edits in Git repositories while preserving valid in-scope changes.
  - **Runaway loop breaker**: Enforces `max_commands` and terminates identical failing command loops automatically.
- **Parallel batch dispatch (`codex_batch_exec`)**: Runs up to 4 concurrent Codex workers on separate cache lanes with upfront disjoint-path validation and sibling Git delta isolation.
- **Zero npm dependencies**: Pure Node.js ESM (`>=18`), instant startup, automatic Codex binary discovery (`CODEX_BIN`, `PATH`, and Windows Store `OpenAI.Codex` MSIX packages).

---

## Architecture

```text
Antigravity (Orchestrator: Plan · Design · Audit · User Chat)
   │
   │  MCP (Stdio JSON-RPC 2.0) — codex-worker
   ▼
codex-executor/server/
   ├── Runtime Guardrails (Command Watchdog · Scope Cage · Auto-Revert · Loop Breaker)
   ├── Persistent Cache Lanes (lanes.json · Rollout Telemetry · Auto-Rotation)
   └── Parallel Batch Scheduler (codex_batch_exec · Disjoint Path Check)
   │
   │  codex exec / codex exec resume (--json, --output-schema, lean flags)
   ▼
Local Codex CLI (default: gpt-6.2-sol, reasoning_effort=max)
```

---

## Prerequisites

1. **Antigravity** (2.0 / IDE / CLI)
2. **Node.js `>= 18`** available in `PATH`
3. **Codex CLI** or **Codex Desktop** installed and configured (authentication/provider configured in `~/.codex/config.toml`)

---

## Installation

Clone this repository directly into your global Antigravity plugins directory:

### Windows (PowerShell)

```powershell
git clone https://github.com/WSDyi/codex-executor.git "$env:USERPROFILE\.gemini\config\plugins\codex-executor"
```

### macOS / Linux

```bash
git clone https://github.com/WSDyi/codex-executor.git ~/.gemini/config/plugins/codex-executor
```

Antigravity automatically discovers plugins placed under `~/.gemini/config/plugins/<name>/` (with `plugin.json`), loads `rules/AGENTS.md`, `skills/codex-orchestrator/SKILL.md`, and starts the `codex-worker` MCP server without requiring a manual build step.

---

## Configuration

Defaults are configured in `mcp_config.json` under `mcpServers.codex-worker.env` and can be adjusted at any time:

| Environment Variable | Default | Description |
| :--- | :--- | :--- |
| `CODEX_DEFAULT_MODEL` | `gpt-6.2-sol` | Default Codex model slug |
| `CODEX_DEFAULT_REASONING_EFFORT` | `max` | Default reasoning effort (`low`, `medium`, `high`, `xhigh`, `max`) |
| `CODEX_AUTO_ROTATE_TOKENS` | `175000` | Soft context token threshold before rotating a hot lane to a fresh thread |
| `CODEX_LANE_IDLE_MINUTES` | `45` | Idle expiration window for cached workspace lanes |
| `CODEX_DEFAULT_MAX_COMMANDS` | `80` | Default per-job shell command ceiling |
| `CODEX_BIN` | *(auto-discovered)* | Optional explicit path to the `codex` executable |

---

## MCP Tools (`codex-worker`)

| Tool | Purpose |
| :--- | :--- |
| `codex_exec` | Execute a guarded Work Order on a workspace cache lane (supports `allowed_paths`, `forbidden_paths`, `strict_guard`, `auto_revert_violations`, `profile`, `lane`, `session_mode`, and `async`) |
| `codex_batch_exec` | Dispatch multiple independent Work Orders in parallel on separate cache lanes with upfront disjoint `allowed_paths` validation |
| `codex_resume` | Send a follow-up or fix directive to an existing `thread_id` while preserving identical cache flags and guardrails |
| `codex_job_status` | Inspect live command progress, `guard_audit`, `observed_evidence`, and `cache_metrics` (supports `wait_sec` long-polling) |
| `codex_job_cancel` | Immediately terminate a running Codex worker process tree |
| `codex_cache_manage` | List (`status`), reset (`reset`), or prune (`prune`) persistent workspace cache lanes |
| `codex_health` | Check Codex binary discovery, CLI version, model catalog status, guardrail defaults, and active cache lanes |

---

## Testing

Run the end-to-end integration test suite (unit guardrail tests + MCP handshake + live parallel batch & hot cache-lane reuse):

```bash
npm test
# or
node server/test-mcp.mjs
```

---

## Repository Layout

```text
codex-executor/
├── plugin.json                         # Antigravity plugin manifest
├── mcp_config.json                     # Stdio MCP server definition
├── package.json                        # Zero-dependency ESM metadata & scripts
├── assets/logo.svg                     # Plugin icon
├── rules/AGENTS.md                     # Always-on orchestration rules
├── skills/codex-orchestrator/SKILL.md  # Orchestration playbook
├── prompts/
│   ├── codex-worker.md                 # Minimal silent worker instructions
│   └── worker-output-schema.json       # 2-field JSON ACK schema ({"ok","err"})
└── server/
    ├── index.mjs                       # Zero-dependency MCP stdio server
    ├── codex-runner.mjs                # Runner, runtime guardrails, cache lanes, batch scheduler
    └── test-mcp.mjs                    # Unit & live integration test suite
```

---

## License

[MIT](./LICENSE)

TDQS

B3.4/5.0

Scored across 7 tools

Disambiguation4/5

Each tool maps to a distinct lifecycle stage: single execution, batch execution, status inspection, cancellation, resume, cache management, and health checking. The only mild overlap is between codex_exec, codex_batch_exec, and codex_resume, since all can start or continue coding work, but descriptions clearly differentiate new jobs, parallel jobs, and follow-ups to existing threads.

Naming Consistency4/5

All names use a consistent snake_case codex_ prefix, making the family easy to recognize. However, the suffix ordering is mixed: some are object_action (codex_job_status, codex_cache_manage) and others are action or bare noun (codex_exec, codex_resume, codex_health), which is a minor inconsistency but still readable.

Tool Count5/5

Seven tools is well-scoped for a Codex worker orchestration server. Each tool covers a meaningful capability—execution, monitoring, cancellation, resumption, batching, cache control, and health—without obvious redundancy.

Completeness5/5

The surface covers the full worker lifecycle: launch single or batch jobs, inspect status, cancel stuck jobs, resume threads, manage cache lanes, and verify environment health. No obvious operational gaps remain for the stated purpose.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues