Skip to content

🐝 Multi-agent swarm coordination for OpenCode with learning capabilities, agent issue tracking, and management

Notifications You must be signed in to change notification settings

joelhooks/swarm-tools

Repository files navigation

opencode-swarm-plugin

npm version Documentation Website

 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—    β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•—
 β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•‘    β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘
 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘ β–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
 β•šβ•β•β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘
 β•šβ•β•β•β•β•β•β• β•šβ•β•β•β•šβ•β•β• β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•šβ•β•     β•šβ•β•

    \ ` - ' /
   - .(o o). -
    (  >.<  )        Break big tasks into small ones.
     /|   |\         Spawn agents to work in parallel.
    (_|   |_)        Learn from what works.
      bzzzz...

AI agents that coordinate, learn, and survive context death.

🐝 swarmtools.ai | πŸ“š Documentation


30-Second Start

# Install
npm install -g opencode-swarm-plugin@latest

# Set up (one-time)
swarm setup

# Use it
/swarm "Add OAuth authentication"

That's it. The coordinator breaks the task into pieces, spawns parallel workers, tracks progress, and learns what works.


Your First Swarm

In any OpenCode session:

/swarm "Add user authentication with OAuth"

What happens:

  1. Coordinator analyzes - queries CASS (past agent sessions) for similar work
  2. Picks a strategy - file-based, feature-based, or risk-based decomposition
  3. Creates cells - git-backed work items in the hive:
    Epic: Add OAuth
    β”œβ”€ Cell 1: OAuth provider integration (src/auth/oauth.ts)
    β”œβ”€ Cell 2: Session management (src/auth/session.ts)
    └─ Cell 3: Integration tests (tests/auth/)
    
  4. Spawns workers - parallel agents with file reservations (no conflicts)
  5. Coordinates via Swarm Mail - agents message each other through actor-model primitives
  6. Checkpoints progress - survives context compaction at 25%, 50%, 75%
  7. Reviews work - coordinator validates each subtask before approval
  8. Records outcome - fast+success = good signal, slow+errors = bad signal

Next time you ask for something similar, it remembers what worked.


What You Get

πŸ”„ Parallel Execution

Workers don't wait for each other. File reservations prevent conflicts. Swarm Mail coordinates dependencies.

🧠 Learning System

Every outcome feeds back into strategy selection. Patterns that fail >60% get auto-inverted to anti-patterns. Confidence decays over 90 days unless revalidated.

πŸ’Ύ Survives Context Death

Checkpoints capture state in libSQL (embedded SQLite). When OpenCode compacts context, swarms resume from last checkpoint. No external servers.

πŸ“¬ Actor-Model Messaging

Swarm Mail: DurableMailbox, DurableLock, DurableDeferred built on event sourcing. Full audit trail, exactly-once processing, type-safe with Effect-TS.

πŸ“‹ Git-Backed Work Items

The "hive" is a .hive/ directory in your repo. Work items (cells) sync via git. Distributed coordination without a server.

🧩 Knowledge Injection

Skills are packages of domain knowledge. Load testing-patterns for Feathers seams, swarm-coordination for multi-agent workflows, or create your own.

πŸ” Cross-Agent Search

CASS indexes all your AI coding sessions (Claude, Cursor, Aider, etc). Query before solving - someone might've solved it already.

πŸ›‘οΈ Verification Gates

Coordinator reviews worker output before approval. 3-strike rule: after 3 rejections, task is blocked (signals architectural problem).


How It Works

                            "Add OAuth"
                                 β”‚
                                 β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚      COORDINATOR       β”‚
                    β”‚                        β”‚
                    β”‚  1. Query CASS:        β”‚
                    β”‚     "How did we solve  β”‚
                    β”‚      this before?"     β”‚
                    β”‚                        β”‚
                    β”‚  2. Pick strategy:     β”‚
                    β”‚     file-based?        β”‚
                    β”‚     feature-based?     β”‚
                    β”‚     risk-based?        β”‚
                    β”‚                        β”‚
                    β”‚  3. Break into pieces  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β–Ό                     β–Ό                     β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  Worker A   β”‚       β”‚  Worker B   β”‚       β”‚  Worker C   β”‚
    β”‚             β”‚       β”‚             β”‚       β”‚             β”‚
    β”‚ auth/oauth  β”‚       β”‚ auth/sessionβ”‚       β”‚ auth/tests  β”‚
    β”‚   πŸ”’ files  β”‚       β”‚   πŸ”’ files  β”‚       β”‚   πŸ”’ files  β”‚
    β”‚             β”‚       β”‚             β”‚       β”‚             β”‚
    β”‚ "I need     │──────►│ "Got it,    β”‚       β”‚ "Running    β”‚
    β”‚  session    β”‚       β”‚  here's the β”‚       β”‚  tests..."  β”‚
    β”‚  types"     β”‚       β”‚  interface" β”‚       β”‚             β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚                     β”‚                     β”‚
           β”‚                     β”‚                     β”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                                 β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    LEARNING SYSTEM     β”‚
                    β”‚                        β”‚
                    β”‚  "File-based split     β”‚
                    β”‚   worked well for      β”‚
                    β”‚   auth - 3 workers,    β”‚
                    β”‚   15 min, 0 conflicts" β”‚
                    β”‚                        β”‚
                    β”‚  Next time: use this   β”‚
                    β”‚  pattern again         β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

CLI Commands

swarm setup     # Install and configure (one-time)
swarm doctor    # Check dependencies (CASS, UBS, Ollama)
swarm init      # Initialize hive in current project
swarm config    # Show config file paths

Docs & Architecture

Want to understand the internals? Here's the deep dive:


Architecture Deep Dive

Everything runs in-process. No external servers.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         YOUR TASK                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  DECOMPOSITION         strategy selection, subtask creation     β”‚
β”‚                        (queries CASS, semantic memory)          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  HIVE                  git-backed work items for each subtask   β”‚
β”‚                        (atomic epic + cell creation)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  SWARM MAIL            actor-model coordination (local-first)   β”‚
β”‚                        (DurableMailbox, DurableLock, libSQL)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LIBSQL                embedded SQLite, event-sourced state     β”‚
β”‚                        (append-only log, materialized views)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LEARNING              outcomes feed back into decomposition    β”‚
β”‚                        (confidence decay, pattern maturity)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Event Sourcing

All state is stored as an append-only event log:

Event Log (libSQL)
β”œβ”€ agent_registered      β†’ Agent joins swarm
β”œβ”€ message_sent          β†’ Agent-to-agent communication
β”œβ”€ file_reserved         β†’ Exclusive file lock acquired
β”œβ”€ file_released         β†’ Lock released
β”œβ”€ swarm_checkpointed    β†’ Progress snapshot saved
β”œβ”€ decomposition_generated β†’ Task broken into subtasks
└─ subtask_outcome       β†’ Worker completion result

Materialized Views (derived from events)
β”œβ”€ agents                β†’ Active agents per project
β”œβ”€ messages              β†’ Agent inbox/outbox
β”œβ”€ file_reservations     β†’ Current file locks
└─ eval_records          β†’ Outcome data for learning

Why event sourcing?

  • Audit trail - full history of what happened
  • Replay - reconstruct state from events
  • Debugging - see exactly what went wrong
  • Learning - analyze outcomes over time

Swarm Mail: Actor-Model Coordination

Workers coordinate via Swarm Mail, an event-sourced actor model built on local-first primitives.

What makes it different:

  • Actor model over durable streams - DurableMailbox, DurableLock, DurableDeferred
  • Local-first with libSQL - embedded SQLite, no external servers, survives across sessions
  • Event-sourced coordination - append-only log, materialized views, full audit trail
  • Context-safe by design - hard caps on inbox (max 5 messages), thread summarization, body-on-demand
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      SWARM MAIL                              β”‚
β”‚                                                              β”‚
β”‚  Worker A: "I need the SessionUser type"                    β”‚
β”‚            ↓                                                 β”‚
β”‚  Worker B: "Here's the interface:"                          β”‚
β”‚            interface SessionUser {                           β”‚
β”‚              id: string                                      β”‚
β”‚              email: string                                   β”‚
β”‚              roles: string[]                                 β”‚
β”‚            }                                                 β”‚
β”‚            ↓                                                 β”‚
β”‚  Worker A: "Got it, implementing OAuth flow now"            β”‚
β”‚                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

File reservations prevent conflicts:

  • Worker A reserves src/auth/oauth.ts (exclusive via DurableLock)
  • Worker B tries to reserve it β†’ blocked
  • Worker B waits or works on something else

Inbox limits prevent context bloat:

  • Max 5 messages per fetch (headers only)
  • Read individual message bodies on demand
  • Thread summarization for long conversations

All coordination state survives context compaction and session restarts.

3-Tier Stack

Swarm Mail is built on Durable Streams primitives (inspired by Kyle Matthews' Electric SQL patterns):

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     SWARM MAIL STACK                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                             β”‚
β”‚  TIER 3: COORDINATION                                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  ask<Req, Res>() - Request/Response (RPC-style)       β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                          β”‚                                  β”‚
β”‚  TIER 2: PATTERNS        β–Ό                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚ DurableMailbox  β”‚  β”‚  DurableLock    β”‚                  β”‚
β”‚  β”‚ Actor Inbox     β”‚  β”‚  File Mutex     β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚          β”‚                    β”‚                             β”‚
β”‚  TIER 1: PRIMITIVES           β–Ό                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚ DurableCursor   β”‚  β”‚ DurableDeferred β”‚                  β”‚
β”‚  β”‚ Checkpointed    β”‚  β”‚ Distributed     β”‚                  β”‚
β”‚  β”‚ Reader          β”‚  β”‚ Promise         β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                          β”‚                                  β”‚
β”‚  STORAGE                 β–Ό                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚      libSQL (Embedded SQLite) + Migrations            β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tier 1 - Primitives:

  • DurableCursor - Positioned event stream consumption with checkpointing (exactly-once)
  • DurableDeferred - URL-addressable distributed promises for async coordination
  • DurableLock - CAS-based mutual exclusion for file reservations (TTL + retry/backoff)

Tier 2 - Patterns:

  • DurableMailbox - Actor inbox with typed envelopes (sender, replyTo, payload)
  • File reservation protocol built on DurableLock

Tier 3 - Coordination:

  • ask() pattern - Synchronous-style RPC over async streams (creates DurableDeferred, appends to mailbox, returns promise)

Message Flow Example

Agent A                    Event Stream                Agent B
   β”‚                            β”‚                         β”‚
   β”‚  ask("get SessionUser")    β”‚                         β”‚
   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€>β”‚                         β”‚
   β”‚  (creates deferred)        β”‚                         β”‚
   β”‚                            β”‚   consume event         β”‚
   β”‚                            β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€>β”‚
   β”‚                            β”‚                         β”‚
   β”‚                            β”‚   reply to deferred     β”‚
   β”‚                            β”‚<─────────────────────────
   β”‚  await deferred.value      β”‚                         β”‚
   β”‚<────────────────────────────                         β”‚
   β”‚                            β”‚                         β”‚
   β”‚  SessionUser interface     β”‚                         β”‚
   β”‚                            β”‚                         β”‚

Why this matters:

  • No external servers (Redis, Kafka, NATS) - just libSQL
  • Full audit trail - every message is an event
  • Resumable - cursors checkpoint position, survive crashes
  • Type-safe - Effect-TS with full inference

Architecture deep-dive: See Swarm Mail Architecture for complete implementation details, database schemas, and Effect-TS patterns.


Surviving Context Death

OpenCode compacts context when it gets too long. Swarms survive this.

     Session 1                    Context                   Session 2
         β”‚                       Compacts                       β”‚
         β–Ό                          πŸ’₯                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ swarm running   β”‚                                   β”‚ swarm_recover() β”‚
β”‚ β”œβ”€ 25% βœ“ saved  β”‚                                   β”‚       β”‚         β”‚
β”‚ β”œβ”€ 50% βœ“ saved  β”‚ ─────────────────────────────────►│       β–Ό         β”‚
β”‚ └─ 75% βœ“ saved  β”‚      checkpoints survive          β”‚ resume at 75%   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Checkpoints capture:

  • Which subtasks are done/in-progress/pending
  • File reservations (who owns what)
  • Shared context for workers
  • Progress percentage

Recovery restores:

  • Swarm state from last checkpoint
  • File locks (prevents conflicts)
  • Worker context (what they were doing)

All stored in libSQL (embedded SQLite) - no external servers, survives across sessions.


Learning From Outcomes

Every swarm completion records:

  • Duration (how long did it take?)
  • Errors (how many retries?)
  • Files touched (did scope match prediction?)
  • Success (did tests pass? were changes accepted?)

This feeds back into the decomposition strategy:

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚         LEARNING LOOP           β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β–Ό                           β–Ό                           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   OUTCOMES    β”‚           β”‚   PATTERNS    β”‚           β”‚ ANTI-PATTERNS β”‚
β”‚               β”‚           β”‚               β”‚           β”‚               β”‚
β”‚ fast+success  β”‚           β”‚  candidate    β”‚           β”‚ >60% failure  β”‚
β”‚ = good signal │──────────►│      ↓        │──────────►│ = auto-invert β”‚
β”‚               β”‚           β”‚  established  β”‚           β”‚               β”‚
β”‚ slow+errors   β”‚           β”‚      ↓        β”‚           β”‚ "split by X"  β”‚
β”‚ = bad signal  β”‚           β”‚    proven     β”‚           β”‚ becomes       β”‚
β”‚               β”‚           β”‚               β”‚           β”‚ "DON'T split  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚  by X"        β”‚
                                                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

                    Confidence decays over 90 days
                    unless patterns are revalidated

Pattern maturity lifecycle:

  • candidate β†’ new pattern, low confidence
  • established β†’ validated 3+ times
  • proven β†’ 10+ successes (gets 1.5x weight in future decompositions)
  • deprecated β†’ >60% failure rate (auto-inverted to anti-pattern)

Confidence decay: Patterns fade over 90 days unless revalidated. Prevents stale knowledge from dominating.


Skills: Knowledge Injection

Skills are reusable knowledge packages. Load them on-demand for specialized tasks.

skills_use(name="testing-patterns")     // Feathers seams + Beck's 4 rules
skills_use(name="swarm-coordination")   // Multi-agent decomposition

Bundled skills:

  • testing-patterns - 25 dependency-breaking techniques, characterization tests
  • swarm-coordination - Multi-agent decomposition, file reservations
  • cli-builder - Argument parsing, help text, subcommands
  • system-design - Architecture decisions, module boundaries
  • learning-systems - Confidence decay, pattern maturity

Create your own:

swarm init  # Creates .opencode/skills/ in project

Skills can include:

  • Step-by-step workflows
  • Code examples
  • Reference documentation
  • Executable scripts

Monorepo Structure

This is a Bun + Turborepo monorepo with two packages:

opencode-swarm-plugin/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ swarm-mail/              # Event sourcing primitives
β”‚   β”‚   └── src/streams/         # DurableMailbox, DurableLock, etc.
β”‚   └── opencode-swarm-plugin/   # Main plugin
β”‚       β”œβ”€β”€ src/                 # Plugin tools
β”‚       β”œβ”€β”€ global-skills/       # Bundled skills
β”‚       └── docs/                # Architecture docs
β”œβ”€β”€ package.json                 # Workspace root
└── turbo.json                   # Pipeline config

swarm-mail

Standalone event sourcing package for multi-agent coordination:

  • EventStore - append-only event log with libSQL
  • Projections - materialized views (agents, messages, reservations)
  • Effect-TS durable primitives (DurableMailbox, DurableCursor, DurableLock, DurableDeferred)
  • DatabaseAdapter interface for dependency injection

opencode-swarm-plugin

OpenCode plugin providing:

  • Hive integration (git-backed work item tracking)
  • Swarm coordination (task decomposition, parallel agents)
  • Agent Mail (inter-agent messaging)
  • Learning system (pattern maturity, anti-pattern detection)
  • Skills system (knowledge injection)

Development

# Install all workspace dependencies
bun install

# Build all packages (respects dependency order)
bun turbo build

# Test all packages
bun turbo test

# Typecheck all packages
bun turbo typecheck

# Build/test specific package
bun turbo build --filter=swarm-mail
bun turbo test --filter=opencode-swarm-plugin

# Add dependency to specific package
cd packages/swarm-mail && bun add zod

See AGENTS.md for detailed monorepo guidance.


Dependencies

Required Optional
OpenCode CASS - historical context
UBS - bug scanning
Ollama - local embeddings for semantic memory

Note: Semantic memory is embedded in the plugin. Install Ollama for vector search, or it falls back to full-text search.

Run swarm doctor to check status.


Credits

Inspiration & Core Ideas:

  • MCP Agent Mail - THE INSPIRATION for multi-agent coordination. Swarm Mail is our implementation built on actor-model primitives (DurableMailbox, DurableLock) with local-first libSQL and event sourcing.
  • Superpowers - verification patterns, Socratic planning, skill architecture
  • Electric SQL - durable streams and event sourcing patterns that power Swarm Mail
  • Evalite - outcome-based evaluation framework for learning systems

"With event sourcing, you can design an event such that it is a self-contained description of a user action." β€” Martin Kleppmann, Designing Data-Intensive Applications


License

MIT

About

🐝 Multi-agent swarm coordination for OpenCode with learning capabilities, agent issue tracking, and management

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

Languages