Package Exports
- opencode-orchestrator
Readme
OpenCode Orchestrator
Autonomous multi-agent plugin for OpenCode
Overview
Multi-agent system that autonomously executes complex tasks. Commander delegates work to specialized agents, manages parallel execution, and maintains shared context.
| Capability | Detail |
|---|---|
| Agents | 4 consolidated (Commander, Planner, Worker, Reviewer) |
| Parallel Sessions | Up to 50 concurrent Worker Sessions |
| Context Management | .opencode/ with adaptive summarization |
| Memory Safety | Auto GC, disk archiving |
| Error Handling | Pattern-based auto recovery + session recovery |
| Todo Continuation | Auto-continues when todos remain |
| Smart Notifications | TaskToastManager with consolidated views |
ποΈ Architecture Overview
π User Flow: Real Scenario
Example:
/task "Build a REST API with user authentication"
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π€ USER: /task "Build a REST API with user authentication" β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π― COMMANDER (Master Session) β
β β
β "I'll break this into parallel tasks and delegate to specialized agents" β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β π Creates TODO.md: β β
β β - [ ] Research: Express.js + JWT best practices β β
β β - [ ] Setup: Project structure + dependencies β β
β β - [ ] Implement: User model + auth routes β β
β β - [ ] Test: API endpoints verification β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββ βββββββββββββββββββββ βββββββββββββββββββββ
β π PLANNER β β π¨ WORKER #1 β β π¨ WORKER #2 β
β Session: ses_001 β β Session: ses_002 β β Session: ses_003 β
β ββββββββββββββββββββ£ β ββββββββββββββββββββ£ β ββββββββββββββββββββ£
β Research Express β β Create src/ β β Write auth.ts β
β + JWT docs β β Setup package.jsonβ β + user.model.ts β
β β β β β β
β π₯ websearch() β β π₯ write files β β π₯ write files β
β β³ cache_docs() β β β³ run_background β β β
βββββββββββββββββββββ β β npm install β βββββββββββββββββββββ
β βββββββββββββββββββββ β
β β β
β β‘ ALL RUN IN PARALLEL (async: true) β
β β±οΈ Commander monitors, doesn't wait β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π BACKGROUND PROCESSES β
β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β npm install β β npm run build β β npm test β β
β β (bg_cmd_001) β β (bg_cmd_002) β β (bg_cmd_003) β β
β β β³ running... β β β³ running... β β β³ pending... β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β
β β’ Check with: check_background / list_background β
β β’ Non-blocking: Commander continues other work β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π ASYNC RESULT COLLECTION β
β β
β get_task_result("ses_001") βββΆ β
Planner done: "Found JWT patterns..." β
β get_task_result("ses_002") βββΆ β
Worker #1 done: "Project setup complete" β
β get_task_result("ses_003") βββΆ β³ Still running... β
β β
β Commander: "Worker #2 still working, I'll delegate review task meanwhile" β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββ
β β
REVIEWER β
β Session: ses_004 β
β ββββββββββββββββββββ£
β Verify endpoints β
β Update TODO.md: β
β - [x] Research β β
β - [x] Setup β β
β - [x] Implement ββ
β - [x] Test β β
βββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ποΈ MISSION COMPLETE β
β β
β Commander: "All TODOs checked. Mission complete." β
β β
β Output: <mission_seal>SEALED</mission_seal> β
β β
β β
Session cleanup β Resources freed β Ready for next mission β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββKey Concepts Visualized:
| Concept | How It Works |
|---|---|
| Session | Each agent runs in isolated session (ses_001, ses_002...) |
| Parallel Agents | Multiple Workers execute simultaneously, not sequentially |
| Background Commands | Long-running commands (npm install) don't block agents |
| Async Collection | Commander polls results, continues work while waiting |
| Auto-Continue | If TODOs remain, loop continues until all [x] checked |
π Project Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β OpenCode Orchestrator Plugin β
β src/index.ts β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββββββ βββββββββββββββββββββββ βββββββββββββββββββββββββββββββ
β Plugin Hooks β β Core Systems β β Tools β
β plugin-handlers/ β β src/core/ β β src/tools/ β
βββββββββββββββββββββββ€ βββββββββββββββββββββββ€ βββββββββββββββββββββββββββββββ€
β β’ chat.message β β β’ agents/ β β β’ parallel/ β
β β’ event β β ParallelManager β β delegate_task β
β β’ tool.execute β β TaskStore β β get_task_result β
β β’ assistant.done β β Concurrency β β β’ web/ β
βββββββββββββββββββββββ β β’ loop/ β β webfetch, websearch β
β MissionSeal β β β’ background-cmd/ β
β TodoContinuation β β run_background β
β β’ recovery/ β β β’ search β
β SessionRecovery β β grep, glob, mgrep β
β β’ notification/ β βββββββββββββββββββββββββββββββ
β Toast, Manager β
β β’ session/ β
β SharedContext β
β β’ cache/ β
β DocumentCache β
βββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββββββ βββββββββββββββββββββββ βββββββββββββββββββββββ
β π― Commander β β π Planner β β π¨ Worker β
β Orchestrator β β Research+Plan β β Implementation β
βββββββββββββββββββββββ€ βββββββββββββββββββββββ€ βββββββββββββββββββββββ€
β β’ Mission control β β β’ Task decompose β β β’ Code writing β
β β’ Parallel delegate β β β’ Doc research β β β’ File operations β
β β’ TODO monitoring β β β’ TODO creation β β β’ Command execution β
βββββββββββββββββββββββ βββββββββββββββββββββββ βββββββββββββββββββββββ
β β β
β β β
β ββββββββββ΄βββββββββ β
β βΌ β β
β βββββββββββββββββββββββ β β
β β β
Reviewer β β β
β β Quality+Context β β β
β βββββββββββββββββββββββ€ β β
β β β’ Verification β β β
β β β’ TODO updates β β β
β β β’ Context manage β β β
β βββββββββββββββββββββββ β β
β β β β
ββββββββββββββββββββΌββββββββββββββββββ΄βββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Shared Workspace (.opencode/) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β todo.md β Hierarchical task list (Epic β Task β Subtask) β
β context.md β Adaptive context (shrinks with progress) β
β loop-state.json β Mission loop iteration state β
β docs/ β Cached documentation (auto-expire) β
β archive/ β Old context snapshots β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββπ Directory Structure
src/
βββ index.ts # Plugin main entry point
βββ agents/
β βββ commander.ts # Commander agent definition
β βββ definitions.ts # Agent exports
β βββ prompts/ # Prompt fragments (commander/, planner/, worker/, reviewer/)
β βββ subagents/ # Subagent definitions (planner.ts, worker.ts, reviewer.ts)
βββ core/
β βββ agents/ # ParallelAgentManager, TaskStore, ConcurrencyController
β βββ cache/ # DocumentCache
β βββ loop/ # MissionSeal, TodoContinuation, TodoEnforcer
β βββ notification/ # Toast, TaskToastManager
β βββ recovery/ # SessionRecovery, ErrorPatterns
β βββ session/ # SharedContext
β βββ task/ # TaskScheduler, TaskParser
βββ plugin-handlers/
β βββ chat-message-handler.ts # /task detection, mission start
β βββ event-handler.ts # session.idle, session.error handling
β βββ tool-execute-handler.ts # Tool completion tracking
β βββ assistant-done-handler.ts # Response completion
βββ shared/
β βββ constants/ # PATHS, TOOL_NAMES, MISSION_SEAL, etc.
β βββ agent/ # Agent definitions, names
β βββ errors/ # Error types
βββ tools/
β βββ parallel/ # delegate_task, get_task_result, list_tasks, cancel_task
β βββ web/ # webfetch, websearch, codesearch, cache_docs
β βββ background-cmd/ # run_background, check_background, list_background
β βββ search.ts # grep_search, glob_search, mgrep
βββ utils/ # Utility functionsInstallation
npm install -g opencode-orchestratorRestart OpenCode after installation.
Usage
π Two Modes of Operation
| Mode | Trigger | Behavior |
|---|---|---|
| Commander Mode π― | /task "mission" |
Full autonomous execution until sealed |
| Chat Mode π¬ | Regular conversation | Simple Q&A, no autonomous behavior |
π― Commander Mode - /task (Recommended for Real Work)
Use /task when you need the AI to complete a mission autonomously:
/task "Fix the login bug in the docker-compose environment"
/task "Add dark mode support to the entire app"
/task "Refactor the API to use TypeScript"What Commander Mode Does:
- βΎοΈ Runs until sealed β Loops until agent outputs
<mission_seal>SEALED</mission_seal> - π§ Anti-Hallucination β Researches docs before coding
- β‘ Parallel Execution β Up to 50 concurrent Worker Sessions
- π Auto-Recovery β Handles errors automatically with pattern matching
- π Progress Tracking β Monitors TODO completion and shows progress
Concurrency Limits (per agent type):
| Agent | Max Concurrent | Purpose |
|---|---|---|
| Commander | 1 | Single orchestrator per mission |
| Planner | 3 | Research and TODO planning |
| Worker | 10 | Implementation tasks |
| Reviewer | 5 | Verification and testing |
ποΈ Mission Seal Loop:
/task "mission" β Agent works β Idle? β Seal found?
β β
β No β Yes
ββββββββββββββββ΄βββ β
CompleteWhen the agent finishes ALL work, it outputs:
<mission_seal>SEALED</mission_seal>Control Commands:
/stopor/cancelβ Stop the loop manually- Max 20 iterations (configurable)
/task "mission" triggers full Commander mode with Mission Seal loop
π¬ Chat Mode - Regular Conversation (Simple Q&A)
Just type normally without /task for simple questions:
How do I add a loading spinner?
What's the difference between useState and useReducer?Chat Mode is just regular conversation β no autonomous execution, no parallel agents, no mission tracking.
π‘ Pro Tip: Use
/taskfor anything that requires multiple steps, file changes, or verification. Use Chat Mode for quick questions.
π Mission Loop Mechanism
The Commander uses an event-driven mission loop to autonomously complete missions:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MISSION LOOP LIFECYCLE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1οΈβ£ User sends "/task 'mission'"
β
2οΈβ£ chat.message handler detects /task
β
3οΈβ£ Create session + startMissionLoop()
β
Write .opencode/loop-state.json:
{
"active": true,
"sessionID": "ses_abc",
"iteration": 1,
"maxIterations": 20
}
β
4οΈβ£ Commander receives prompt β delegates work
β
5οΈβ£ Worker sessions execute β results collected
β
6οΈβ£ session.idle event triggers
β
Check for <mission_seal>SEALED</mission_seal>
ββ Seal found? β Clear loop state β Complete β
ββ Not found? β Increment iteration β Continue loop
β
Show countdown toast (3 seconds)
β
Inject continuation prompt
β
[Loop back to step 4]Key Loop Components:
| Component | File | Purpose |
|---|---|---|
| Loop State | src/core/loop/mission-seal.ts |
State management (.opencode/loop-state.json) |
| Seal Detection | src/core/loop/mission-seal-handler.ts |
Detect <mission_seal> in responses |
| Continuation | src/core/loop/mission-seal-handler.ts |
Inject prompts to continue work |
| Countdown | src/core/loop/mission-seal-handler.ts |
3-second countdown toast |
| Idle Handler | src/plugin-handlers/assistant-done-handler.ts |
Monitor session.idle events |
Why Event-Driven?
- No fixed iteration limits - loop continues until sealed
- Resilient to network delays
- Can be interrupted by user at any time
- Efficient polling (500ms interval with backoff)
The 4 Agents
| Agent | Role | Responsibility |
|---|---|---|
| Commander π― | Orchestrator | Autonomous mission control |
| Planner π | Planner + Research | Task decomposition, research, caching docs |
| Worker π¨ | Developer + Docs | Full-stack implementation, documentation |
| Reviewer β | Quality + Context | Verification, TODO updates, context management |
π οΈ Available Tools
| Tool | Description |
|---|---|
delegate_task |
Delegate work to subagent (async/sync) |
get_task_result |
Get result from delegated task |
list_tasks |
List all running/completed tasks |
cancel_task |
Cancel a running task |
webfetch |
Fetch URL content as Markdown |
websearch |
Search web (SearXNG β Brave β DuckDuckGo) |
codesearch |
Search open source code patterns |
cache_docs |
Manage cached documentation |
run_background |
Run command in background |
check_background / list_background |
Monitor background jobs |
grep_search / glob_search / mgrep |
Fast file search |
π Resource Guarantees
| Resource | Limit | Safety Mechanism |
|---|---|---|
| Parallel Sessions | 50 | Queue overflow protection |
| Tasks in Memory | 1,000 | Auto GC + disk archive |
| Notifications | 100/parent | FIFO eviction |
| Event History | 100 | Ring buffer |
| Session TTL | 60 min | Auto cleanup |
| Poll Interval | 500ms | Fast completion detection |
| Max Poll Count | 600 | Hard limit prevents infinite loops |
| Sync Timeout | 5 min | Safe delegate_task timeout |
| Recovery Attempts | 3 | Auto session error recovery |
π§ͺ Test Coverage
Test Files: 19 passed
Tests: 216 passed
Duration: ~4.3sπ Reliability Features
Session Recovery
Automatic recovery from common errors:
tool_result_missing- Tool crash recoverythinking_block_order- Thinking block issuesrate_limit- API rate limiting with backoff- Max 3 recovery attempts per session
Todo Continuation
- Monitors
session.idleevents - 3-second countdown toast before auto-continuation
- Cancels on user interaction
- Skips if background tasks running or session is recovering
noReply Optimization
- Individual task completion:
noReply: true(saves tokens) - All tasks complete:
noReply: false(AI processes results)
Uninstall
npm uninstall -g opencode-orchestratorπ§ Debugging
Log file location:
# Find log path (macOS uses /var/folders/...)
npm run log
# or:
tail -f "$(node -e 'console.log(require("os").tmpdir())')/opencode-orchestrator.log"
# Windows
# C:\Users\<username>\AppData\Local\Temp\opencode-orchestrator.logDocumentation
- System Architecture β Detailed technical docs
- Architecture and Flow β Complete architecture guide with scenarios
- Improvement Suggestions β Project improvement recommendations
- Release Notes β Version history
License
MIT License. LICENSE