Skip to main content
Glama
README.md
# CortexHands

**Let frontier AI models think & review. Let cheap CLI & API agents do the hands-on coding — safely inside isolated Git worktrees.**

[![CI](https://github.com/DuskstarXiao/cortex-hands/actions/workflows/ci.yml/badge.svg)](https://github.com/DuskstarXiao/cortex-hands/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
[![Node.js](https://img.shields.io/badge/Node.js-%3E%3D20-339933?logo=node.js)](https://nodejs.org/)
[![MCP](https://img.shields.io/badge/Protocol-MCP%20stdio-0ea5e9)](https://modelcontextprotocol.io/)

[English](./README.md) | [简体中文](./README.zh-CN.md) | [Architecture & Interview Guide](./docs/ARCHITECTURE.md) | [WorkBuddy Setup](./docs/WORKBUDDY_SETUP.md) | [Launch Posts](./docs/LAUNCH_POSTS.md)

---

## Why CortexHands?

Frontier reasoning models (**Google Antigravity**, **Claude Code**, **Codex**, **Cursor**) are expensive and rate-limited — burning their quota on boilerplate edits, test-fix loops, and multi-file exploration hurts. On the other hand, cheap or free coding workers (**Tencent WorkBuddy / CodeBuddy**, **DeepSeek**, **Ollama**, **OpenCode**, **Aider**) have generous quota, but left unsupervised they can edit unrelated files, break tests, or pollute your working branch.

**CortexHands** is a cross-platform **Planner-Executor-Reviewer MCP Orchestrator** (`v0.2.0`) that combines the best of both worlds:

- **Git Worktree Sandbox**: Every delegated task runs in `.cortex-hands/worktrees/<taskId>` on its own branch — your main branch is never touched until you approve. Supports `squash` / `merge` / `patch-only` delivery and one-click rollback (`abort_task`).
- **Parallel Multi-Worktree Batching (`dispatch_batch`)**: Run 2–5 disjoint subtasks concurrently in separate isolated worktrees with bounded concurrency and pre-flight scope-overlap warnings.
- **Scope Guard + Auto-Detect Quality Gate**: Enforce `allowedPaths` glob whitelists (with `!exclusions`), block sensitive files (`.env`, `*.key`, `*.pem`) by default, auto-detect project test/typecheck commands (`Node` / `Go` / `Rust` / `Python`), and return a **token-compressed Review Packet** instead of noisy raw logs.
- **Same-Session Rework + Circuit Breaker**: Rejections via `request_rework` resume the worker's existing session (`--resume <sessionId>`) in the same worktree, capped by `maxRounds` to stop infinite retry loops.
- **First-Class Windows & macOS WorkBuddy 5.11.3 Support**: Auto-discovers WorkBuddy via Windows Registry / common drives / macOS app bundles, handles WorkBuddy 5.11.3 `codebuddy-lite-wb.mjs` routing (`CODEBUDDY_FORCE_LITE_WB_BUNDLE=1`), and kills Windows process trees cleanly (`taskkill /T /F`) so zero zombie locks remain.
- **Built-in Sandboxed OpenAI-Compatible Worker (`openai-api`)**: Works out-of-the-box with **DeepSeek**, **Ollama**, **SiliconFlow**, **OpenRouter**, or any `/v1/chat/completions` endpoint — with worktree path-traversal protection and multi-round session memory.
- **Zero-Dependency Local Observability Dashboard**: Run `cortex-hands dashboard` to inspect live tasks, Scope Guard alerts, color-highlighted diffs, and token savings in your browser (`127.0.0.1:3847`).
- **Native Antigravity Plugin + Standard MCP**: Ships both a ready-to-install Antigravity plugin (MCP + workflow `SKILL.md` + `rules/AGENTS.md`) and standard `stdio` MCP configs for Claude Code, Cursor, and Codex.

---

## Architecture

```mermaid
flowchart LR
    Planner["Frontier Planner & Reviewer\n(Antigravity / Claude Code / Codex)"]
    MCP["CortexHands MCP Server\n(9 tools over stdio)"]
    Core["Orchestrator State Machine\n• Parallel Git Worktree Sandbox\n• Scope Guard & Auto-Detect Gate\n• Diff Compressor & Circuit Breaker\n• Live Dashboard & Telemetry"]
    Worker["Pluggable Cheap Workers\n• WorkBuddy CLI (Win/macOS)\n• OpenAI-API (DeepSeek/Ollama)\n• Generic CLI (OpenCode/Aider)"]

    Planner -->|"1. dispatch_task / dispatch_batch"| MCP
    MCP --> Core
    Core -->|"2. isolated worktree(s)"| Worker
    Worker -->|"3. edits + self-test"| Core
    Core -->|"4. compressed Review Packet"| Planner
    Planner -->|"5a. request_rework (--resume)"| MCP
    Planner -->|"5b. approve_and_merge / abort_task"| MCP
```

---

## Quick Start (60 Seconds)

### 1. Try the Zero-Cost End-to-End Demo & Live Dashboard

No API key or quota required — watches a full Round 1 scope violation + failing test -> automated interception -> Round 2 rework fix -> squash merge -> telemetry report in 3 seconds:

```bash
git clone https://github.com/DuskstarXiao/cortex-hands.git
cd cortex-hands
npm install && npm run build
node dist/index.js demo --persist
node dist/index.js dashboard
```

### 2. Run Environment Doctor

Checks Node.js, Git, WorkBuddy CLI auto-discovery, OpenAI/Generic workers, and Antigravity plugin status:

```bash
node dist/index.js doctor
```

If WorkBuddy headless CLI reports `Authentication required`, sign in once interactively:

```bash
node dist/index.js login-workbuddy
# Inside the prompt, run /login once, then /exit
```

### 3. Install into Antigravity (One Command)

```bash
node dist/index.js init --target antigravity
```

This installs the complete Antigravity Plugin (MCP server + `cortex-hands-workflow` skill + rules) into `~/.gemini/config/plugins/cortex-hands/`.

For other MCP clients:

```bash
node dist/index.js init --target claude   # Claude Code
node dist/index.js init --target cursor   # Cursor
node dist/index.js init --target codex    # OpenAI Codex CLI
```

---

## MCP Tools Reference (9 High-Cohesion Tools)

| Tool | Role | Purpose |
| :--- | :--- | :--- |
| `dispatch_task` | Planner | Creates an isolated Git worktree, injects the execution contract, runs the worker, and executes automated gates |
| `dispatch_batch` | Planner | Executes 1–5 independent subtasks concurrently across separate Git worktrees with scope-overlap warnings |
| `get_task_status` | Planner | Polls live status, round number, and recent worker events (for `async: true` runs) |
| `get_review_packet` | Reviewer | Returns Scope Guard findings, compressed gate test summaries, diff stat, and bounded unified diff |
| `request_rework` | Reviewer | Rejects output and sends targeted comments back to the same worktree & worker session (`--resume`), guarded by `maxRounds` circuit breaker |
| `approve_and_merge` | Reviewer | Blocks merge if gate failed (unless forced), cleanly merges via `squash` / `merge` / `patch-only`, and cleans up the worktree |
| `abort_task` | Reviewer | Terminates the worker process tree safely and removes the temporary worktree & branch |
| `list_tasks` | Utility | Lists recent tasks and available worker adapters |
| `get_telemetry_report` | Analytics | Reports first-pass approval rate, avg rounds, context compression ratio, and estimated planner tokens saved |

---

## Pluggable Workers & `.cortex-hands.json`

### Option A: Tencent WorkBuddy (Default, Zero API Key)
Auto-discovered on Windows (`5.11.3+`) and macOS. See [docs/WORKBUDDY_SETUP.md](./docs/WORKBUDDY_SETUP.md).

### Option B: Built-in Sandboxed OpenAI-Compatible API (`worker: "openai-api"`)
Works with DeepSeek, local Ollama, SiliconFlow, OpenRouter, Moonshot/Kimi, Zhipu, etc.:

```bash
export CORTEX_HANDS_OPENAI_BASE_URL="https://api.deepseek.com/v1"   # or http://127.0.0.1:11434/v1
export CORTEX_HANDS_OPENAI_MODEL="deepseek-chat"                    # or qwen2.5-coder:14b
export CORTEX_HANDS_OPENAI_API_KEY="sk-..."                         # optional for Ollama
```

### Option C: Any Local CLI (`worker: "generic-cli"`)

```bash
export CORTEX_HANDS_GENERIC_CLI_CMD="opencode run {prompt}"
```

### Optional Repo Defaults (`.cortex-hands.json`)

```json
{
  "defaultWorker": "workbuddy",
  "maxRounds": 3,
  "autoDetectGates": true,
  "allowedPaths": ["src/**", "tests/**"],
  "mergeStrategy": "squash"
}
```

---

## Development & Verification

```bash
npm run typecheck   # Strict TypeScript checking
npm run build       # Bundle single-file ESM CLI via tsup
npm test            # 17 unit + real Git worktree + dashboard + MCP JSON-RPC tests
```

---

## Compliance Notice

CortexHands strictly invokes official user-installed CLIs, user-supplied standard APIs, and open protocols (MCP / Git). It does **not** reverse-engineer private APIs, extract browser cookies, bypass rate limits, or automate multi-account farming.

## License

[MIT](./LICENSE)

TDQS

A3.7/5.0

Scored across 9 tools

Disambiguation4/5

Each tool maps to a distinct lifecycle step (dispatch, status, review, rework, merge, abort, telemetry), so the core set is easy to tell apart. The only real overlaps are dispatch_task vs dispatch_batch and list_tasks vs get_task_status, which descriptions do resolve but still require reading.

Naming Consistency4/5

All names are snake_case and verb-first (get_, list_, dispatch_, abort_, request_, approve_), giving a predictable pattern. approve_and_merge is the one compound outlier, and the get_ prefix is used for three different resource types, but overall it reads consistently.

Tool Count5/5

Nine tools is well within the ideal band and every tool corresponds to a meaningful workflow step: orchestration, monitoring, review, remediation, cleanup, and reporting. Nothing feels padded or missing in count terms.

Completeness4/5

The dispatch-to-merge lifecycle is fully closed: single and batch dispatch, status polling, review packet retrieval, rework with a round circuit breaker, approval/merge, and abort with cleanup, plus telemetry. Minor gaps remain, such as standalone worker management or deeper raw log retrieval for failed runs, but core workflows have no dead ends.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues