# Makima Cloudflare Agent Edge relay agent for [Makima](https://github.com/soryu-co/makima) — distributed task orchestration for AI coding agents. This Cloudflare Worker acts as a **WebSocket relay** between the Makima server and native daemon instances. It runs on Cloudflare's edge network using Durable Objects for persistent state and connections. ## Why an Edge Relay? The full Makima daemon requires native capabilities (process spawning, git operations, filesystem access) that aren't available on Cloudflare Workers. Instead, this agent serves as: 1. **WebSocket Relay** — Bridges the Makima server with remote daemon instances via persistent WebSocket connections 2. **Task Queue Manager** — Receives tasks from the server and dispatches them to the least-loaded downstream daemon 3. **Status Aggregator** — Tracks daemon health and task history across edge locations 4. **API Proxy** — Provides HTTP endpoints for monitoring and management from the edge ## Architecture ``` Cloudflare Edge ┌─────────────────────────┐ │ │ Makima Server ◄──►│ MakimaAgent │◄──► Native Daemon 1 (wss://...) │ (Durable Object) │◄──► Native Daemon 2 │ │◄──► Native Daemon N │ ┌───────────────────┐ │ │ │ SQLite State │ │ │ │ - Task history │ │ │ │ - Connection logs │ │ │ └───────────────────┘ │ │ │ └─────────────────────────┘ ``` **Message flow:** 1. The agent maintains a persistent WebSocket to the Makima server (upstream) 2. Native daemons connect to the agent via WebSocket at `/ws/daemon` (downstream) 3. When the server sends a `SpawnTask` command, the agent selects the least-loaded downstream daemon and forwards the task 4. Task output, progress, and completion messages from daemons are relayed back to the server 5. The agent sends periodic heartbeats and tracks all task dispatches in SQLite ## Prerequisites - **Cloudflare Account** with Workers and Durable Objects enabled - **Node.js 18+** and npm - **Makima Server** running and accessible (default: `wss://api.makima.jp`) - **API Key** from your Makima server dashboard ## Quick Setup ```bash # Clone and navigate to the cloudflare-agent directory cd makima/cloudflare-agent # Run the interactive setup script chmod +x setup.sh ./setup.sh ``` The setup script will: 1. Check prerequisites (Node.js 18+, npm, npx) 2. Prompt for your Makima server URL and API key 3. Install npm dependencies 4. Create `.dev.vars` with your secrets 5. Check Cloudflare authentication (offer to log in) 6. Optionally set production secrets 7. Offer to deploy immediately or start a dev server ## Manual Setup If you prefer manual configuration: ```bash # 1. Install dependencies npm install # 2. Create local secrets file cat > .dev.vars <