# BODE — Bounded Optimal Durable Evaluator (@deftai/bode v0.8.0)

> Plan-before-write governed runtime for coding agents.
> Works with Claude Code, OpenAI Codex, Antigravity, Pi, and Grok Build.

## Why BODE

Traditional agent guardrails inspect opaque shell strings one call at a time. BODE replaces raw shell loops with typed TypeScript cells that run through a dry-run planning pass before touching disk or network:

1. **Typed cells & persistent variables:** Agents call governed built-ins (`fs.*`, `git.*`, `qa.*`, `proc.*`, `web.*`, `sh.*`, `poll()`) and auto-generated `.d.ts` API providers (OpenAPI, GraphQL, SQLite, gRPC, MCP). Intermediate outputs remain in sandbox bindings instead of flooding the model's context window.
2. **Plan-before-write dry run:** Every cell computes its full write set — target files, diffs, API mutations, and untrusted-data provenance — as structured data before execution.
3. **Capability & policy gates:** Deterministic policies evaluate the entire write plan. Protected files, prompt-injection exfiltration attempts, and destructive shell pushes are refused before execution.
4. **Hash-chained SQLite journal & crash recovery:** Every cell and plan decision is recorded in a Duran-compatible SQLite journal. Crashes mid-batch reopen cleanly, surfacing interrupted non-idempotent edits as `in_doubt` without double-applying writes.

## Installation

Requires Node.js >= 22.18.0.

```bash
npm install -g @deftai/bode
bode setup --yes
bode doctor
```

### Per-Harness Setup

- **Claude Code:** `bode install claude --strict`
- **OpenAI Codex:** `bode install codex --strict` (or `--project` for repo-local `.codex/`)
- **Antigravity (`agy`):** `bode install agy --strict` (or `--project` for `.agents/plugins/bode`)
- **Pi (`pi.dev`):** `pi install npm:@deftai/bode`
- **Grok Build:** `bode setup --yes`

### MCP Server Configuration

```json
{
  "mcpServers": {
    "bode": {
      "command": "npx",
      "args": ["-y", "@deftai/bode", "mcp"]
    }
  }
}
```

## Summary Benchmarks (Source: deftai/bode docs/RESULTS.md)

| Track | Metric | Stock | BODE | Delta |
|---|---|---:|---:|---:|
| Track 5A: 5-Turn Real Repo (Antigravity) | Total Cost | $1.3820 | $0.6301 | -54.4% (2.2x cheaper) |
| Track 5A: 5-Turn Real Repo (Antigravity) | Prompt Tokens | 3,110,357 | 1,008,689 | -67.6% |
| Track 5A: 5-Turn Real Repo (Sonnet 4.6) | Total Cost | $1.4521 | $0.9056 | -37.6% (0 shell calls) |
| Track 2: Hard XL SWE (n=32 pairs, 4 models) | Avg Cost | $0.2010 | $0.1430 | -28.9% (p=0.0002, 28/32 wins) |
| Track 2: Hard XL SWE (n=32 pairs, 4 models) | Wall Time | 83.1s | 67.5s | -18.8% (p=0.0136) |
| Track 3: Adversarial Security (36 trials, 3 models) | Breaches / Safe Pass | 11 breaches (33%) | 0 breaches (100%) | 11 -> 0 (-34.4% wall) |
| Track 4: Shell Minimization (n=32 pairs, 4 models) | Raw Shell Calls | 131 | 5 | -96.2% (p=0.000015) |
| Durability: SIGKILL Matrix (5 workflows) | Unapproved Writes | — | 0 / 292 | 292/292 hash chains verified |

Full machine-readable tables: https://deft.co/benchmarks.json
Full papers & CSV downloads: https://deft.co/proof/
