Skip to main content
Glama
README.md
<div align="center">
  <img src="docs/assets/mizan-hero-banner.jpg" alt="Mizan — Local-First Multi-Agent Control Plane" width="100%" />

  <br />
  <br />

  <h1>Mizan</h1>
  <p><strong>The Local-First Brain OS &amp; Fair-Quota Control Plane for Multi-Agent Coding Fleets</strong></p>
  <p>Orchestrate <strong>Claude Code</strong>, <strong>Codex</strong>, <strong>Cursor</strong>, <strong>OpenCode</strong>, and <strong>Antigravity</strong> from one hardened, zero-dependency hub &mdash; with <code>&lt; 3k</code> fixed prefix tokens, a 4-tool <code>stdio</code> SQLite FTS5 MCP server, and zero-token weekly Kaizen audits.</p>

  <p>
    <a href="https://github.com/csa7mdm/mizan/actions/workflows/ci.yml"><img src="https://github.com/csa7mdm/mizan/actions/workflows/ci.yml/badge.svg" alt="Mizan CI" /></a>
    <img src="https://img.shields.io/badge/Node.js-24%2B%20Zero--Dep-22c55e?style=flat-square&logo=node.js&logoColor=white" alt="Node 24 Zero-Dep" />
    <img src="https://img.shields.io/badge/Fleet-5%20AI%20Agents-38bdf8?style=flat-square" alt="5 AI Agents" />
    <img src="https://img.shields.io/badge/MCP-4--Tool%20stdio%20FTS5-d4a853?style=flat-square" alt="4-Tool stdio MCP" />
    <img src="https://img.shields.io/badge/Security-DNS%20Rebind%20%2B%20CSRF%20%2B%20Bearer-ef4444?style=flat-square" alt="Security Hardened" />
    <img src="https://img.shields.io/badge/Audit%20Cost-0%20LLM%20Tokens-a855f7?style=flat-square" alt="0 LLM Tokens" />
  </p>

  <p>
    <a href="#-live-action-center">Live Demo</a> &middot;
    <a href="#-60-second-zero-ai-quickstart">Quickstart</a> &middot;
    <a href="#-architecture">Architecture</a> &middot;
    <a href="#-mizan-oss-vs-mizan-enterprise">OSS vs Enterprise</a> &middot;
    <a href="docs/wiki/01-Architecture-and-5-Agent-Fleet.md">Full Wiki (8 Guides)</a>
  </p>
</div>

---

## Why Mizan? (The 5-Second Empirical Proof)

Running 3 to 5 AI coding agents in parallel creates **terminal chaos, silent token burn, skill prefix bloat, and exposed localhost dashboards**. **Mizan** (inspired by *Ma'at* balance, *Al-Mizan* fair measure, and Japanese *Kaizen* continuous improvement) restores calm, deterministic control from one single source of truth.

| Metric (Measured on Real Sessions) | Before Mizan | With Mizan | Impact |
| :--- | :---: | :---: | :--- |
| **Installed Skills per Agent** | `1,247` / `1,265` | **`6` – `11`** | Eliminates silent prompt-prefix bloat |
| **Estimated Fixed Prefix Tokens** | `50,644+` tok | **`278` – `2,986` tok** | **~94% prefix reduction** (target `< 15k`) |
| **Weekly OS Health & Skill ROI Audit** | Manual / ad-hoc | **`0` LLM tokens** | Automated Windows Task Scheduler |
| **Localhost Dashboard Security** | Open `127.0.0.1` | **`401` + `403` Guards** | Blocks DNS Rebinding & CSRF attacks |
| **New Venture Triad Bootstrap** | Hours of setup | **`< 1` second (`23` files)** | Platform + Social + Partnerships wired |

---

## Live Action Center (The Aperture Control Plane)

A zero-dependency Node 24 local & remote control plane (`127.0.0.1:4321`) built on a **Headless State + Layout Plugin Registry** architecture:

- **Per-Project Isolated Cockpit (`Operate`):** Focuses on one project at a time with active-only tasks (`ops/boards/<slug>.json`, completed items archived behind a toggle), **Live Agent Screen** (real-time logs + `Pause` / `Resume` / tree-`Terminate` / direct `stdin` or directive input), and **1-Click Quick Actions** (`Proceed`, `Approve & Proceed`, `Submit`, or auto-extracted choices) whenever an agent pauses.
- **Interactive Multi-Model Space (`Arena`):** Talk 1-on-1 or compare 2–4 models side-by-side (`Claude Code`, `Codex CLI`, `OpenCode $0`, `Ollama $0`) via live SSE streaming, protected by **Quota Guard**, with **Promote Winner -> Project Task**.
- **Zero-Noise Blocker Detection & Auto-Discovery:** Combines `ops/session-hook.mjs` (Claude Code hooks), a **Stall Watchdog**, and **Live Session Auto-Discovery** (Antigravity + Claude Code transcripts) so blocked or silent agents surface immediately in the `NEEDS ATTENTION` banner.
- **Bilingual EN / Egyptian Arabic (`RTL`) + BiDi Fix:** Instant toggle between English and Egyptian founder-friendly Arabic with `<bdi dir="auto">` / `unicode-bidi: plaintext` isolation for mixed code/Arabic logs.
- **One-Command Auto-Connect (`hub-mcp/connect.mjs`):** Automatically wires `brain-hub` into Claude Code, OpenCode, Codex, and Cursor without manual JSON edits (`node hub-mcp/connect.mjs --dry-run`).
- **Remote Streamable HTTP MCP (`/mcp`):** Bearer-authenticated endpoint restricted to **5 safe Control-Plane tools** (zero shell execution) for ChatGPT & Claude Mobile via Cloudflare Tunnel or Tailscale Funnel.
- **Searchable `knowledge/` Playbooks + Unified `ops/ACTIVITY-LOG.jsonl`:** Curated Browser, Mobile (Android USB ADB / Wi-Fi Wireless Debugging / iOS), and Token-Optimal playbooks indexed in `hub-mcp` SQLite FTS5 with zero prefix-token increase.
- **Invalidated-on-Edit Verification Receipts & `AGENTS.md` Bloat Linter:** Every `Verify Diff` run stamps a SHA-256 git-tree receipt (`PASS` automatically flips to `STALE` if any file is edited afterward). Built-in linter warns when `AGENTS.md`/`CLAUDE.md` exceeds 150 lines or contains auto-generated directory trees.
- **Worktree Isolation, 10-Port Blocks & 3-Gram Loop Circuit Breaker:** Parallel workers launch in `.mizan-worktrees/<id>` with deterministic 10-port blocks (`MIZAN_PORT=4400, 4410...`), exFAT/WSL `/mnt/c` I/O guards, and a Circuit Breaker that kills workers on repeated errors, 3-gram action loops, or runtime cap.
- **Fail-Closed Federated Privacy Distiller (`ops/distill-lesson.mjs` + `ops/feed-sync.mjs`):** Zero-dependency 7-stage deterministic sanitizer (hard 16 KB cap, zero `--force` bypass flags, compiled secret regexes + Shannon entropy scanner, OS/WSL path & username stripping, prompt-injection & Base64/shell-pipe rejection) with built-in Node 24 **Ed25519 signing/verification** and 5 signed starter lessons in `feed/lessons/`.
- **Dynamic Drop-In Layout Plugins (`action-center/plugins/`):** Auto-discovered via `GET /api/plugins` (`atc-grid.js` Air-Traffic Ops multi-project radar + `tiling-split.js` 2x2 live agent panes).
- **Worktree Merge UI, Setup Wizard, `mizan` CLI & Air-Gapped Docker:** Merge/discard `.mizan-worktrees/*` from the browser, onboard fresh installs via the Setup Wizard, run `node bin/mizan.mjs start|connect|sync-feed|distill|test`, or deploy air-gapped with `Dockerfile`, `docker-compose.yml`, and `ops/POLICY.example.json`.

<div align="center">
  <img src="docs/assets/mizan-action-center.gif" alt="Mizan Action Center Live Walkthrough" width="100%" />
</div>

---

## Architecture

One local source of truth propagates rules, lessons (`<= 30` cap), and fleet identity across all 5 agents, while `hub-mcp` exposes 4 read/write primitives over **`stdio` only** (zero network exposure).

```mermaid
flowchart TD
    Founder["Founder / Tech Lead"] --> AC["Mizan Action Center (127.0.0.1:4321)\nHost/Origin Guard + Bearer Auth + Tailscale"]

    subgraph Core["Single Source of Truth (~/.claude/brain)"]
        OPS["ops/ Live Control Bus\nFLEET-STATUS.json | BROADCAST.md\nDECISION-QUEUE.json | health-snapshot.json"]
        RULES["Rules & Memory\nAGENTS-CORE.md | LESSONS.md (<=30)\nMODEL-REGISTRY.json | active-projects.md"]
        MCP["hub-mcp/ (stdio-only, Node 24 SQLite FTS5)\nbrain_search_lessons | brain_search_components\nbrain_get_ops_state | brain_log_decision"]
    end

    AC <-->|"Live JSON State & Decisions"| OPS
    MCP <-->|"Zero-Network stdio JSON-RPC"| Fleet

    subgraph Fleet["5-Agent Coding Fleet (Desktop Apps + CLIs)"]
        AGY["Antigravity\nLead + Browser + MCP"]
        CC["Claude Code\nDeep Refactors + --worktree"]
        CDX["Codex CLI/App\nIndependent Review + Tests"]
        OC["OpenCode Free Tier\n$0 Boilerplate (Verify-Gated)"]
        CUR["Cursor Entry Plan\nTight Quota (yellow-conserve)"]
    end

    RULES -->|"05-APPLY-BRAIN.sh (Copy, No Symlinks)"| Fleet
    OPS <--> Fleet
```

### Bounded 3-Layer Self-Healing (Kaizen Loop)

```mermaid
flowchart LR
    F["Anomaly / CI Fail / Stall"] --> L1["Layer 1: Deterministic Guard (0 Tokens)\noxlint | gitleaks | check:rls | pnpm audit"]
    L1 --> L2["Layer 2: Bounded Recovery (Max 2 Tries)\nquiet-run error tail -> recipe -> verify"]
    L2 -->|Green| L3["Layer 3: Sandboxed Kaizen\n1-sentence lesson -> LESSONS.md (<=30)"]
    L2 -->|Still Failing| ESC["Hard Stop -> ops/DECISION-QUEUE.json\nExact logs + 1 recommendation"]
```

---

## 60-Second Zero-AI Quickstart (Fresh Windows 11 PC)

Bootstrap a brand-new machine **without needing any AI installed first**:

```powershell
# 1. Clone and run the PowerShell 5.1-safe zero-AI bootstrapper
git clone https://github.com/csa7mdm/Brain.git "$env:USERPROFILE\.claude\brain"
cd "$env:USERPROFILE\.claude\brain"
powershell -ExecutionPolicy Bypass -File .\bootstrap.ps1 -InstallAgents

# 2. Start the hardened Action Center (token auto-generated in ops/.ac-token)
node .\action-center\server.mjs

# 3. Connect the 4-tool stdio Hub MCP (Claude Code example)
claude mcp add brain-hub -- node "$env:USERPROFILE\.claude\brain\hub-mcp\index.mjs"

# 4. Bootstrap a new Three-Workspace Venture Triad in < 1 second
python .\06-VENTURE-OS\new-venture.py my-venture --domain="Developer Tools" --region="Global"
```

### macOS & Linux Quickstart (Node 24+)

```bash
git clone https://github.com/csa7mdm/mizan.git ~/.claude/brain && cd ~/.claude/brain
bash ./bootstrap.sh --connect --sync-feed
node ./action-center/server.mjs
```

---

## Core Modules

| Module | Path | Purpose |
| :--- | :--- | :--- |
| **Hardened Action Center** | `action-center/` | Live web UI (`Host/Origin` guard, Bearer auth, Tailscale mobile mode, Broadcast bus, Decision Queue). |
| **4-Tool Local Hub MCP** | `hub-mcp/` | Zero-dep `stdio` MCP server using Node 24 `node:sqlite` FTS5 over lessons, shared components, and ops state. |
| **5-Agent Fleet Sync** | `05-APPLY-BRAIN.sh`, `07-VERIFY.sh` | Propagates rules, identity headers, and `<= 30`-line Cursor thin rule across all 5 agents. |
| **Venture Triad Engine** | `06-VENTURE-OS/` | `new-venture.py`, `brain-doctor.py`, parameterized Platform + Social + Partnerships templates, static guards (`check:rls`, `check:em-dash`, `check:portability`). |
| **Weekly Kaizen Audit** | `scripts/weekly-health.py` | 0-token scheduled audit: 5-agent prefix budget, 30d Skill ROI, live `opencode models` deprecation probe, portfolio pulse. |
| **NotebookLM Exporter** | `scripts/export-notebooklm-pack.py` | Compiles lessons, decisions, wiki, and weekly health into a clean NotebookLM source pack for Audio Overviews & Mind Maps. |
| **Zero-AI Bootstrapper** | `bootstrap.ps1` | Installs minimum prerequisites (`winget`), optional CLI agents, syncs fleet, and registers Windows Task Scheduler. |

---

## Mizan OSS vs. Mizan Enterprise (Open-Core Roadmap)

| Capability | Mizan OSS (Community / Solo) | Mizan Enterprise (AAA Corporate) |
| :--- | :---: | :---: |
| **5-Agent Fleet Sync & Pre-Flight Gate** | Included | Included |
| **Hardened Local Action Center + Tailscale** | Included | Included + SSO / SAML / RBAC |
| **4-Tool `stdio` Hub MCP (SQLite FTS5)** | Included | Team-Shared Postgres/Vector Hub |
| **Weekly 0-Token Health & Skill ROI Audit** | Included | Org-Wide Telemetry & FinOps Spend Caps |
| **Static Security & RLS Guards** | Included | Policy-as-Code + Immutable Audit Trails |
| **Deployment & Compliance** | Local-First (Windows/Mac/Linux) | Air-Gapped / On-Prem + SOC 2 / ISO 27001 Readiness |

---

## Full Documentation Wiki

All 8 architecture, security, operations, and extraction guides live in [`docs/wiki/`](docs/wiki/):

1. [01 — Architecture & 5-Agent Fleet](docs/wiki/01-Architecture-and-5-Agent-Fleet.md)
2. [02 — Zero-AI Quickstart (Windows 11)](docs/wiki/02-Zero-AI-Quickstart-Windows.md)
3. [03 — Action Center & Hardened Mobile Control](docs/wiki/03-Action-Center-and-Mobile-Control.md)
4. [04 — 4-Tool Local Hub MCP Server](docs/wiki/04-Hub-MCP-Server.md)
5. [05 — Venture Triad & Zero-Cost Static Guards](docs/wiki/05-Venture-Triad-and-Static-Guards.md)
6. [06 — Token Discipline, Kaizen & Skill ROI](docs/wiki/06-Token-Discipline-and-Skill-ROI.md)
7. [07 — Security & Threat Model](docs/wiki/07-Security-Model.md)
8. [08 — Private-to-Public OSS & Enterprise Extraction Guide](docs/wiki/08-Private-to-Public-Extraction-Guide.md)

---

## GitHub SEO Topics (Copy to Repo Settings)

`multi-agent-orchestration` · `ai-coding-agents` · `claude-code` · `codex-cli` · `opencode` · `cursor-rules` · `mcp-server` · `sqlite-fts5` · `local-first` · `developer-productivity` · `agent-control-plane` · `indie-hacker`