Package Exports
- opencode-orchestrator
Readme
OpenCode Orchestrator
Production-Grade Multi-Agent Orchestration Engine for High-Integrity Software Engineering
β‘ Quick Start
npm install -g opencode-orchestratorInstall hooks are source-checkout safe, prefer opencode.jsonc when present, preserve sibling plugin entries, and skip automatic config mutation in CI environments.
Inside an OpenCode environment:
/task "Implement a new authentication module with JWT and audit logs"π Engine Workflow
Hub-and-Spoke Architecture with Work-Stealing Queues for parallel, context-isolated task execution.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INPUT /task "..." β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β C O M M A N D E R β β
β β [ Mission Analysis & Delegation ] β β
β β β β
β β β’ Interprets user intent β’ Coordinates multi-agent workflow β β
β β β’ Monitors progress β’ Manages work-stealing queues β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β P L A N N E R β β W O R K E R β β W O R K E R β
β [Architect] β β [Implementer] β β [Implementer] β
β β β β β β
β β’ Dependency β β β’ File coding β β β’ File coding β
β analysis β β β’ TDD workflow β β β’ TDD workflow β
β β’ Roadmap gen β β β’ Documentationβ β β’ Documentationβ
β β’ TODO.md β β β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β ββββββββββββββββΌββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββββββββββββββββββββββββββ
β SESSION POOL (MVCC Sync) β
β βββββββββββββββββββββββββββββββββββ β
β β Object Pool β Buffer Pool β β
β β String Pool β Connection Pool β β
β βββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββ
β MSVP MONITOR / REVIEWER β
β βββββββββββββββββββββββββββββββββββ β
β β β’ Adaptive polling (500ms-5s) β β
β β β’ Stability detection β β
β β β’ Unit test verification β β
β βββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββ
β β¨ COMPLETED β
ββββββββββββββββββποΈ Architecture Layers
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PRESENTATION LAYER β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββββββ β
β β Task Toast β β Progress β β Notificationβ β Mission Summary β β
β β Manager β β Notifier β β Manager β β Display β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β BUSINESS LOGIC LAYER β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Parallel Agent Orchestration β β
β β ββββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββββββββ β β
β β β Commander β β Planner β β Worker β β Reviewer β β β
β β β Agent β β Agent β β Agent β β Agent β β β
β β ββββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββββββββββββββ
β β Concurrency β β Task Store β β Hook System ββ
β β Controller β β (In-Memory) β β [Early/Normal/Late Phases] ββ
β βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β INFRASTRUCTURE LAYER β
β ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββββββββββββββ β
β β Session Pool β β Work-Stealing β β Memory Pools β β
β β [5 per agent] β β [Chase-Lev] β β ββββββββ ββββββββ ββββββββ β
β β [10 reuse max] β β [LIFO/FIFO] β β βObjectβ βStringβ βBufferββ β
β ββββββββββββββββββ ββββββββββββββββββ β β 200 β β internβ β 4KB ββ β
β β ββββββββ ββββββββ ββββββββ β
β ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββββββββββββββ β
β β MVCC State β β Circuit Breaker β ββββββββββββββββββββββββββββββ β
β β [Atomic Sync] β β [5 failuresβopenβ β Rust Connection Pool β β
β β β β [2 successβcloseβ β [4 processes, 30s idle] β β
β ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β SAFETY LAYER β
β ββββββββββββββββββ ββββββββββββββββββ βββββββββββββββββββββββββββββββ β
β β RAII Pattern β β Shutdown β β Auto-Recovery β β
β β [Zero Leaks] β β Manager β β [Exponential Backoff] β β
β β β β [5s timeout] β β [Rate limit handling] β β
β ββββββββββββββββββ ββββββββββββββββββ βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ§ͺ Test Utilities
Reusable test helpers keep filesystem, task, and process-heavy flows deterministic:
tests/harness/
βββ fixture.ts Disposable tmpdir utilities
β βββ tmpdir() async disposable with cleanup
β βββ tmpdirSync() sync disposable with cleanup
β βββ createMockFs() In-memory fs mock
β βββ waitFor() Async condition waiter
β
βββ builders.ts Factory functions for test objects
β βββ createParallelTask() Build ParallelTask instances
β βββ createBackgroundTask() Build BackgroundTask instances
β βββ createTodo() Build Todo instances
β
βββ mocks.ts Mock utilities
β βββ mockConsole() Spy on console.log/error
β βββ mockProcessExit() Mock process.exit
β βββ useFakeTimers() Time manipulation
β βββ createMockEmitter() EventEmitter spy
β
βββ index.ts Unified exportsUsage Example
import { tmpdir, createParallelTask, mockConsole } from "@/tests/harness";
describe("My test", () => {
let consoleMock;
beforeEach(() => {
consoleMock = mockConsole();
consoleMock.setup();
});
afterEach(() => {
consoleMock.restore();
});
it("should work", async () => {
await using tmp = await tmpdir({ git: true });
const task = createParallelTask({ description: "Test" });
expect(task.status).toBe("pending");
});
});β‘ Elite Multi-Agent Swarm
| Agent | Role | Core Responsibilities |
|---|---|---|
| Commander | Mission Hub | Task decomposition, agent coordination, work-stealing orchestration, final mission seal |
| Planner | Architect | Dependency analysis, roadmap generation, TODO.md creation via MVCC, file-level planning |
| Worker | Implementer | High-throughput coding, TDD workflow, documentation, isolated file execution |
| Reviewer | Auditor | Unit test verification, LSP/Lint validation, integration testing, quality gate |
π οΈ Core Capabilities
π Atomic MVCC State Synchronization
Solves the "Concurrent TODO Update" problem using MVCC + Mutex. Agents safely mark tasks complete in parallel without data loss or race conditions. Every state change is cryptographically hashed and logged.
π§© Advanced Hook Orchestration
Execution flows governed by a Priority-Phase Hook Registry. Hooks are grouped into phases (early, normal, late) and executed via Topological Sort for predictable, dependency-aware ordering.
π‘οΈ Autonomous Recovery
- Self-healing loops with adaptive stagnation detection
- Proactive Agency: Smart monitoring that audits logs and plans ahead during background tasks
- Auto-retry with backoff: Exponential backoff for transient failures
π― State-Level Session Isolation
Reused sessions in the SessionPool are explicitly reset via server-side compaction, ensuring previous task context never leaks into new tasks.
π Zero-Payload Turbo Mode
Leverages system.transform to unshift agent instruction sets server-side, reducing initial message payloads by 90%+ and preventing context fragmentation.
π§ Hierarchical Memory System
Maintains focus across thousands of conversation turns using a 4-tier memory structure with EMA-based Context Gating to preserve architectural truth while pruning noise.
π Adaptive Intelligence Loop
- Stagnation Detection: Senses when no progress is made across iterations
- Diagnostic Intervention: Forces "Diagnostic Mode" mandating log audits and strategy pivots
- Proactive Agency: Mandates Speculative Planning during background task execution
βοΈ Performance Benchmarks
| Metric | Improvement |
|---|---|
| CPU Utilization | 90%+ (up from 50-70%) |
| Tool Call Speed | 10x faster (5-10ms vs 50-100ms) via Rust pool |
| Session Creation | 90% faster (50ms vs 500ms) via session pooling |
| Memory Usage | 60% reduction via object/string/buffer pooling |
| GC Pressure | 80% reduction |
| Token Efficiency | 40% reduction via Incremental State & System Transform |
| Sync Accuracy | 99.95% via MVCC+Mutex |
| Parallel Efficiency | 80% improvement (50% β 90%+) |
ποΈ Infrastructure & Reliability
Resource Safety
- RAII Pattern: Guaranteed resource cleanup with zero leaks
- ShutdownManager: Priority-based graceful shutdown (5s timeout per handler)
- Atomic File Operations: Temp file + rename for corruption-proof writes
- Automatic Backups: Timestamped config backups with rollback support
Safety Features
- Circuit Breaker: Auto-recovery from API failures (5 failures β open)
- Resource Pressure Detection: Rejects low-priority tasks when memory > 80%
- Terminal Node Guard: Prevents infinite recursion via depth limit
- Auto-Scaling: Concurrency slots adjust based on success/failure rate
Technical Stack
- Runtime: Node.js 18+ (TypeScript)
- Tools: Rust-based CLI tools (grep, glob, ast) via connection pool
- Concurrency: Chase-Lev work-stealing deque + priority queues
- Memory: Object pooling + string interning + buffer pooling
- State Management: MVCC + Mutex
- Safety: RAII + circuit breaker + resource pressure detection
π§ Installation & Configuration
Safe Installation
The installation process is production-safe with multiple protection layers:
- β Never overwrites β always merges with existing config
- β Automatic backups β timestamped, last 5 kept
- β Atomic writes β temp file + rename (OS-level atomic)
- β Automatic rollback β restores from backup on any failure
- β Cross-platform β Windows (native, Git Bash, WSL2), macOS, Linux
- β CI-aware β skips non-essential operations in CI environments
- β Timeout protection β 30s timeout prevents hanging
- β Graceful degradation β exits 0 on non-critical failures
Configuration Logs
- Unix:
/tmp/opencode-orchestrator.log - Windows:
%TEMP%\opencode-orchestrator.log
π§ͺ Testing & Stability
Test Utilities
Reusable helpers under tests/harness/ provide:
- Disposable tmpdir: Automatic cleanup with
Symbol.asyncDispose/Symbol.dispose - Test builders: Factory functions for
ParallelTask,BackgroundTask,Todo - Mock utilities: Console, process, timers, file system, event emitter mocks
import { tmpdir, createParallelTask, mockConsole } from "@/tests/harness";
await using tmp = await tmpdir({ git: true });
const task = createParallelTask({ description: "Test" });TUI Stability
- Cleanup guarantees:
initToastClient()returns a cleanup function - Timeout protection: AbortController-based 2-10s timeout for async toast operations
- Error isolation: Try/catch around all toast operations prevents cascade failures
Cross-Platform Reliability
- Windows guard: Proper handling of WSL2, Git Bash, native Windows paths
- Signal handling: Graceful shutdown on SIGINT/SIGTERM
- Process isolation: Child process cleanup with timeout
π Documentation
π License
MIT License β see LICENSE for details.