๐ŸŒ‰ Bifrost

The bridge between your portal and local CLI agents. Fire-and-forget autonomous execution with real-time streaming.

What is Bifrost?

Bifrost is a local Node.js Express server that bridges the portal UI with CLI agents (Claude and Gemini). It receives job instructions, spawns CLI processes, streams their output in real-time via SSE, and reports results back to the portal.

Think of it as your autonomous execution engine โ€” you submit a job from the portal, and Bifrost runs it for you while you're away. No interactive prompts, no approvals needed.

Why "Bifrost"? In Norse mythology, the Bifrost is the rainbow bridge connecting Midgard (Earth) to Asgard (realm of the gods). Here, it connects the portal (your command center) to the powerful CLI agents that do the real work.

Architecture

Bifrost uses an air-gapped pull model โ€” no public tunnels or webhooks needed. The portal writes jobs to D1, and Bifrost polls for pending work.

Execution Flow

Portal UI โ†’ POST D1 (queue) โ† poll Bifrost API โ†’ spawn CLI Agent
CLI Agent โ†’ NDJSON Bifrost API โ†’ SSE Portal UI

Components

ComponentFilePurpose
Server apps/bifrost-api/server.js Express app with routes, auth, SSE streaming, heartbeat
Job Controller apps/bifrost-api/controllers/jobs.js Job queue, CLI spawning, NDJSON parsing, error detection
Retry Queue apps/bifrost-api/lib/retry-queue.js In-memory queue for rate-limited jobs awaiting auto-retry
Portal Client apps/bifrost-api/lib/portal.js Helper to PATCH jobs and POST messages to portal D1

Key Concepts

ConceptWhat
Stateless Bifrost holds jobs in-memory while running. Durable state lives in D1. Restarting Bifrost loses active jobs but not history.
PM2-managed Runs as a PM2 service for auto-restart and process management. Port 4003, accessible at bifrost.mipos.io.
Dual-backend Supports both Claude CLI and Gemini CLI. Switch globally or per-job. See LLM Providers.
Auto-retry Rate-limited jobs auto-queue for retry when quota resets. Countdown timer shown in portal UI.
SSE Streaming Real-time output via Server-Sent Events. Portal connects to /jobs/:id/stream for live logs.
Channel Messages Each job gets a #job-{id} channel with start, progress, and completion messages.

Bifrost API Endpoints

MethodEndpointDescription
GET/healthService health + active job count + uptime
POST/jobsSubmit a new job (id, type, payload)
GET/jobsList all active in-memory jobs
GET/jobs/:idSingle job status + metadata
DELETE/jobs/:idCancel a running job
GET/jobs/:id/streamSSE stream โ€” live output from CLI
DELETE/jobs/:id/retryCancel a queued auto-retry
GET/settingsCurrent config (backend, models, effort levels)
POST/settingsUpdate config (switch default backend)
Auth: All endpoints except /health and /jobs/:id/stream require X-API-Key header.