opencode-orchestrator 0.8.10 → 0.8.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +265 -67
  2. package/dist/agents/commander.d.ts +6 -0
  3. package/dist/agents/prompts/commander/agents.d.ts +4 -0
  4. package/dist/agents/prompts/commander/execution.d.ts +4 -0
  5. package/dist/agents/prompts/commander/forbidden.d.ts +4 -0
  6. package/dist/agents/prompts/commander/identity.d.ts +4 -0
  7. package/dist/agents/prompts/commander/index.d.ts +12 -0
  8. package/dist/agents/prompts/commander/parallel.d.ts +4 -0
  9. package/dist/agents/prompts/commander/required.d.ts +4 -0
  10. package/dist/agents/prompts/commander/role.d.ts +4 -0
  11. package/dist/agents/prompts/commander/todo-format.d.ts +4 -0
  12. package/dist/agents/prompts/commander/tools.d.ts +4 -0
  13. package/dist/agents/prompts/common/anti-hallucination.d.ts +6 -0
  14. package/dist/agents/prompts/common/environment-discovery.d.ts +6 -0
  15. package/dist/agents/prompts/common/index.d.ts +11 -0
  16. package/dist/agents/prompts/common/mission-seal.d.ts +6 -0
  17. package/dist/agents/prompts/common/shared-workspace.d.ts +6 -0
  18. package/dist/agents/prompts/common/todo-rules.d.ts +6 -0
  19. package/dist/agents/prompts/common/verification.d.ts +6 -0
  20. package/dist/agents/prompts/index.d.ts +11 -0
  21. package/dist/agents/prompts/planner/forbidden.d.ts +4 -0
  22. package/dist/agents/prompts/planner/index.d.ts +8 -0
  23. package/dist/agents/prompts/planner/required.d.ts +4 -0
  24. package/dist/agents/prompts/planner/research.d.ts +4 -0
  25. package/dist/agents/prompts/planner/role.d.ts +4 -0
  26. package/dist/agents/prompts/planner/todo-format.d.ts +4 -0
  27. package/dist/agents/prompts/reviewer/forbidden.d.ts +4 -0
  28. package/dist/agents/prompts/reviewer/index.d.ts +9 -0
  29. package/dist/agents/prompts/reviewer/output.d.ts +4 -0
  30. package/dist/agents/prompts/reviewer/required.d.ts +4 -0
  31. package/dist/agents/prompts/reviewer/role.d.ts +4 -0
  32. package/dist/agents/prompts/reviewer/todo-update.d.ts +4 -0
  33. package/dist/agents/prompts/reviewer/verification.d.ts +4 -0
  34. package/dist/agents/prompts/worker/forbidden.d.ts +4 -0
  35. package/dist/agents/prompts/worker/index.d.ts +8 -0
  36. package/dist/agents/prompts/worker/quality.d.ts +4 -0
  37. package/dist/agents/prompts/worker/required.d.ts +4 -0
  38. package/dist/agents/prompts/worker/role.d.ts +4 -0
  39. package/dist/agents/prompts/worker/workflow.d.ts +4 -0
  40. package/dist/agents/subagents/planner.d.ts +8 -0
  41. package/dist/agents/subagents/reviewer.d.ts +9 -0
  42. package/dist/agents/subagents/worker.d.ts +8 -0
  43. package/dist/core/cache/interfaces/cache-document-entry.d.ts +10 -0
  44. package/dist/core/cache/interfaces/cache-list-entry.d.ts +12 -0
  45. package/dist/core/cache/interfaces/cache-metadata.d.ts +8 -0
  46. package/dist/core/cache/interfaces/cache-stats.d.ts +10 -0
  47. package/dist/core/cache/interfaces/cached-document.d.ts +11 -0
  48. package/dist/core/cache/interfaces/index.d.ts +8 -0
  49. package/dist/core/cache/interfaces.d.ts +3 -50
  50. package/dist/core/loop/interfaces/index.d.ts +5 -0
  51. package/dist/core/loop/interfaces/todo-stats.d.ts +11 -0
  52. package/dist/core/loop/interfaces/todo.d.ts +13 -0
  53. package/dist/core/loop/interfaces.d.ts +5 -32
  54. package/dist/core/loop/mission-seal-handler.d.ts +3 -0
  55. package/dist/core/loop/mission-seal.d.ts +3 -0
  56. package/dist/core/loop/types/index.d.ts +5 -0
  57. package/dist/core/loop/types/todo-priority.d.ts +4 -0
  58. package/dist/core/loop/types/todo-status.d.ts +4 -0
  59. package/dist/core/notification/presets/index.d.ts +9 -0
  60. package/dist/core/notification/presets/mission.d.ts +5 -0
  61. package/dist/core/notification/presets/parallel.d.ts +6 -0
  62. package/dist/core/notification/presets/session.d.ts +6 -0
  63. package/dist/core/notification/presets/task-lifecycle.d.ts +7 -0
  64. package/dist/core/notification/presets/tools.d.ts +6 -0
  65. package/dist/core/notification/presets/warnings.d.ts +7 -0
  66. package/dist/core/notification/presets.d.ts +5 -22
  67. package/dist/core/notification/types/index.d.ts +6 -0
  68. package/dist/core/notification/types/toast-message.d.ts +13 -0
  69. package/dist/core/notification/types/toast-options.d.ts +10 -0
  70. package/dist/core/notification/types/toast-variant.d.ts +4 -0
  71. package/dist/core/notification/types.d.ts +3 -16
  72. package/dist/core/progress/interfaces/index.d.ts +8 -0
  73. package/dist/core/progress/interfaces/progress-snapshot.d.ts +15 -0
  74. package/dist/core/progress/interfaces/snapshot-input.d.ts +13 -0
  75. package/dist/core/progress/interfaces/step-progress.d.ts +7 -0
  76. package/dist/core/progress/interfaces/task-progress.d.ts +10 -0
  77. package/dist/core/progress/interfaces/todo-progress.d.ts +9 -0
  78. package/dist/core/progress/interfaces.d.ts +3 -51
  79. package/dist/core/recovery/interfaces/error-context.d.ts +11 -0
  80. package/dist/core/recovery/interfaces/error-pattern.d.ts +10 -0
  81. package/dist/core/recovery/interfaces/index.d.ts +8 -0
  82. package/dist/core/recovery/interfaces/recovery-action.d.ts +24 -0
  83. package/dist/core/recovery/interfaces/recovery-record.d.ts +10 -0
  84. package/dist/core/recovery/interfaces/recovery-stats.d.ts +9 -0
  85. package/dist/core/recovery/interfaces.d.ts +3 -60
  86. package/dist/core/session/interfaces/context-stats.d.ts +9 -0
  87. package/dist/core/session/interfaces/index.d.ts +8 -0
  88. package/dist/core/session/interfaces/shared-context.d.ts +15 -0
  89. package/dist/core/session/interfaces/shared-decision.d.ts +10 -0
  90. package/dist/core/session/interfaces/shared-document.d.ts +9 -0
  91. package/dist/core/session/interfaces/shared-finding.d.ts +10 -0
  92. package/dist/core/session/interfaces.d.ts +3 -50
  93. package/dist/core/task/interfaces/index.d.ts +8 -0
  94. package/dist/core/task/interfaces/task-hierarchy.d.ts +9 -0
  95. package/dist/core/task/interfaces/task-input.d.ts +11 -0
  96. package/dist/core/task/interfaces/task-node.d.ts +20 -0
  97. package/dist/core/task/interfaces/task-progress.d.ts +11 -0
  98. package/dist/core/task/interfaces.d.ts +3 -51
  99. package/dist/index.js +1005 -773
  100. package/dist/plugin-handlers/chat-message-handler.d.ts +3 -10
  101. package/dist/plugin-handlers/event-handler.d.ts +4 -29
  102. package/dist/plugin-handlers/interfaces/assistant-done-context.d.ts +12 -0
  103. package/dist/plugin-handlers/interfaces/chat-message-context.d.ts +12 -0
  104. package/dist/plugin-handlers/interfaces/event-handler-context.d.ts +14 -0
  105. package/dist/plugin-handlers/interfaces/index.d.ts +9 -0
  106. package/dist/plugin-handlers/interfaces/orchestrator-state.d.ts +14 -0
  107. package/dist/plugin-handlers/interfaces/session-state.d.ts +10 -0
  108. package/dist/plugin-handlers/interfaces/tool-execute-context.d.ts +7 -0
  109. package/dist/plugin-handlers/tool-execute-handler.d.ts +3 -5
  110. package/dist/shared/agent/definition.d.ts +10 -0
  111. package/dist/shared/agent/index.d.ts +6 -0
  112. package/dist/shared/agent/names.d.ts +10 -0
  113. package/dist/shared/agent.d.ts +2 -21
  114. package/dist/shared/constants/background-status.d.ts +10 -0
  115. package/dist/shared/constants/background-task.d.ts +7 -0
  116. package/dist/shared/constants/cache-actions.d.ts +10 -0
  117. package/dist/shared/constants/filter-status.d.ts +12 -0
  118. package/dist/shared/constants/id-prefix.d.ts +8 -0
  119. package/dist/shared/constants/index.d.ts +28 -0
  120. package/dist/shared/constants/memory-limits.d.ts +12 -0
  121. package/dist/shared/constants/mission-seal.d.ts +24 -0
  122. package/dist/shared/constants/parallel-task.d.ts +13 -0
  123. package/dist/shared/constants/part-types.d.ts +9 -0
  124. package/dist/shared/constants/paths.d.ts +14 -0
  125. package/dist/shared/constants/prompts.d.ts +8 -0
  126. package/dist/shared/constants/slash-commands.d.ts +10 -0
  127. package/dist/shared/constants/status.d.ts +15 -0
  128. package/dist/shared/constants/time.d.ts +8 -0
  129. package/dist/shared/constants/toast-variants.d.ts +10 -0
  130. package/dist/shared/constants/tool-names.d.ts +22 -0
  131. package/dist/shared/constants.d.ts +3 -140
  132. package/dist/shared/error-patterns.d.ts +3 -35
  133. package/dist/shared/errors/detection.d.ts +5 -0
  134. package/dist/shared/errors/index.d.ts +7 -0
  135. package/dist/shared/errors/patterns.d.ts +14 -0
  136. package/dist/shared/errors/retry.d.ts +7 -0
  137. package/dist/tools/background-cmd/list.d.ts +2 -2
  138. package/dist/utils/common.d.ts +5 -13
  139. package/dist/utils/formatting/elapsed-time.d.ts +4 -0
  140. package/dist/utils/formatting/index.d.ts +5 -0
  141. package/dist/utils/formatting/timestamp.d.ts +4 -0
  142. package/dist/utils/parsing/index.d.ts +4 -0
  143. package/dist/utils/parsing/slash-command.d.ts +7 -0
  144. package/dist/utils/sanity.d.ts +0 -4
  145. package/package.json +1 -1
  146. package/dist/agents/consolidated/planner.d.ts +0 -8
  147. package/dist/agents/consolidated/reviewer.d.ts +0 -8
  148. package/dist/agents/consolidated/worker.d.ts +0 -8
package/README.md CHANGED
@@ -28,70 +28,202 @@ Multi-agent system that autonomously executes complex tasks. Commander delegates
28
28
 
29
29
  ---
30
30
 
31
- ## 🏛️ Master Session Architecture
31
+ ## 🏛️ Architecture Overview
32
+
33
+ ### 🚀 User Flow Architecture
34
+
35
+ ```
36
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
37
+ │ 👤 USER REQUEST │
38
+ │ /task "Build a REST API" │
39
+ └─────────────────────────────────────────────────────────────────────────────────┘
40
+
41
+
42
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
43
+ │ chat.message-handler.ts │
44
+ │ ┌────────────────────────────────────────────────────────────────────────────┐ │
45
+ │ │ 1. Detect /task command │ │
46
+ │ │ 2. Create SessionState in sessions Map │ │
47
+ │ │ 3. Call startMissionLoop() → Write .opencode/loop-state.json │ │
48
+ │ │ 4. Apply mission template + Inject prompt to Commander │ │
49
+ │ └────────────────────────────────────────────────────────────────────────────┘ │
50
+ └─────────────────────────────────────────────────────────────────────────────────┘
51
+
52
+
53
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
54
+ │ 🎯 MASTER SESSION (Commander) │
55
+ │ │
56
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
57
+ │ │ 1️⃣ THINK │───▶│ 2️⃣ PLAN │───▶│ 3️⃣ DELEGATE │───▶│ 4️⃣ MONITOR │ │
58
+ │ │ Analyze │ │ Create │ │ Spawn │ │ Watch │ │
59
+ │ │ request │ │ TODO.md │ │ Workers │ │ progress │ │
60
+ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
61
+ │ │
62
+ │ Core Systems Active: │
63
+ │ • 🔄 SessionRecovery (auto error handling) │
64
+ │ • 📋 TodoContinuation (auto-resume on idle) │
65
+ │ • 🎖️ MissionSealHandler (completion detection) │
66
+ │ • 📣 TaskToastManager (consolidated notifications) │
67
+ └─────────────────────────────────────────────────────────────────────────────────┘
68
+
69
+ delegate_task (background: true)
70
+
71
+ ┌──────────────────────────┼──────────────────────────┐
72
+ ▼ ▼ ▼
73
+ ┌────────────────────┐ ┌────────────────────┐ ┌────────────────────┐
74
+ │ ⚡ Worker Session 1 │ │ ⚡ Worker Session 2 │ │ ⚡ Worker Session N │
75
+ │ Agent: Planner │ │ Agent: Worker │ │ Agent: Reviewer │
76
+ ├────────────────────┤ ├────────────────────┤ ├────────────────────┤
77
+ │ • Independent exec │ │ • Independent exec │ │ • Read/Write │
78
+ │ • Read/Write │ │ • Read/Write │ │ .opencode/ │
79
+ │ .opencode/ │ │ .opencode/ │ │ • Notify parent │
80
+ │ • Notify parent │ │ • Notify parent │ │ on complete │
81
+ │ on complete │ │ on complete │ └────────────────────┘
82
+ └────────────────────┘ └────────────────────┘
83
+ │ │ │
84
+ └──────────────────────────┼──────────────────────────┘
85
+
86
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
87
+ │ 📁 SHARED CONTEXT (.opencode/) │
88
+ │ │
89
+ │ todo.md ◄── Planner creates │ Worker implements │ Reviewer checks ──▶ [x] │
90
+ │ │
91
+ │ ⚡ All sessions read/write this shared workspace │
92
+ │ 📊 Progress is tracked via todo.md checkboxes │
93
+ └─────────────────────────────────────────────────────────────────────────────────┘
94
+
95
+
96
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
97
+ │ 🎖️ MISSION SEAL LOOP │
98
+ │ │
99
+ │ ┌───────────────────────────────────────────────────────────────────────────┐ │
100
+ │ │ │ │
101
+ │ │ session.idle event ──▶ Check for <mission_seal>SEALED</mission_seal> │ │
102
+ │ │ │ │ │ │
103
+ │ │ │ ┌────────┴────────┐ │ │
104
+ │ │ │ ▼ ▼ │ │
105
+ │ │ │ [Seal Found] [Not Found] │ │
106
+ │ │ │ │ │ │ │
107
+ │ │ │ ▼ ▼ │ │
108
+ │ │ │ ✅ Mission Complete iteration < max? │ │
109
+ │ │ │ Clear state │ │ │
110
+ │ │ │ ┌──────┴──────┐ │ │
111
+ │ │ │ ▼ ▼ │ │
112
+ │ │ │ [YES] [NO] │ │
113
+ │ │ │ │ │ │ │
114
+ │ │ │ ▼ ▼ │ │
115
+ │ │ │ 3s countdown toast ⚠️ Max iterations │ │
116
+ │ │ │ Inject continuation Force stop │ │
117
+ │ │ │ │ │ │
118
+ │ │ └──────────────────────────┘ │ │
119
+ │ │ LOOP │ │
120
+ │ └───────────────────────────────────────────────────────────────────────────┘ │
121
+ └─────────────────────────────────────────────────────────────────────────────────┘
122
+ ```
123
+
124
+ ### 📊 Project Architecture
32
125
 
33
126
  ```
34
- ┌─────────────────────────────────────────────────────────────────────────────┐
35
- 👤 USER REQUEST
36
- "/task Build a REST API"
37
- └─────────────────────────────────────────────────────────────────────────────┘
38
-
39
-
40
- ┌─────────────────────────────────────────────────────────────────────────────┐
41
- │ 🎯 MASTER SESSION (Commander Agent) │
42
-
43
- ┌───────────────────────────────────────────────────────────────────────┐
44
- │ 1️⃣ THINK → Analyze request, assess complexity (L1/L2/L3) │
45
- 2️⃣ PLAN Create .opencode/todo.md via Planner
46
- 3️⃣ DELEGATE → Spawn Worker Sessions via delegate_task │ │
47
- 4️⃣ MONITOR → Watch .opencode/ for progress, handle completions │ │
48
- └───────────────────────────────────────────────────────────────────────┘
49
-
50
- ┌─────────────────┐ ┌─────────────────────────────────────────────────┐
51
- │ │ Session State 4 CONSOLIDATED AGENTS │ │
52
- Map<id,state> │ 🎯 Commander 📋 Planner
53
- └─────────────────┘ 🔨 Worker ✅ Reviewer
54
- └─────────────────────────────────────────────────┘
55
- ┌─────────────────┐
56
- │ Plugin Hooks
57
- event │ ┌─────────────────────────────────────────────────┐ │
58
- │ chat.message │ │ 🔄 SessionRecovery (auto error handling)
59
- │ tool.execute │ 📋 TodoContinuation (auto-resume on idle) │ │
60
- │ └─────────────────┘ │ 📣 TaskToastManager (consolidated notifications)│ │
61
- └─────────────────────────────────────────────────┘ │
62
- └─────────────────────────────────────────────────────────────────────────────┘
63
-
64
- delegate_task (async)
65
-
66
- ┌─────────────────────────┼─────────────────────────┐
67
- ▼ ▼ ▼
127
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
128
+ OpenCode Orchestrator Plugin
129
+ src/index.ts
130
+ └─────────────────────────────────────────────────────────────────────────────────┘
131
+
132
+ ┌───────────────────────────┼───────────────────────────┐
133
+ ▼ ▼ ▼
134
+ ┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────────────┐
135
+ Plugin Hooks │ Core Systems │ │ Tools │
136
+ plugin-handlers/ src/core/ │ │ src/tools/ │
137
+ ├─────────────────────┤ ├─────────────────────┤ ├─────────────────────────────┤
138
+ chat.message │ │ agents/ │ │ parallel/
139
+ event │ ParallelManager │ delegate_task │
140
+ tool.execute │ │ TaskStore │ │ get_task_result │
141
+ • assistant.done │ │ Concurrency │ • web/ │
142
+ └─────────────────────┘ • loop/ │ webfetch, websearch │
143
+ MissionSeal │ • background-cmd/ │
144
+ TodoContinuation │ │ run_background
145
+ • recovery/ │ │ search
146
+ SessionRecovery │ grep, glob, mgrep
147
+ • notification/ │ └─────────────────────────────┘
148
+ Toast, Manager │
149
+ • session/
150
+ SharedContext
151
+ cache/
152
+ DocumentCache
153
+ └─────────────────────┘
154
+
155
+ ┌───────────────────────────┼───────────────────────────┐
156
+ ▼ ▼ ▼
68
157
  ┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
69
- Worker Session 1 │ │ Worker Session 2 │ │ Worker Session N
70
- Agent: Planner │ │ Agent: Worker │ │ Agent: Reviewer
71
- │ │ │ │ │ │
72
- Independent exec │ │ Independent exec │ │ Independent exec
73
- Read/Write │ │ Read/Write │ │ Read/Write
74
- .opencode/ │ │ .opencode/ │ │ .opencode/
75
- │ • Notify parent │ │ • Notify parent │ │ • Notify parent │
76
- │ on complete │ │ on complete │ │ on complete │
158
+ 🎯 Commander │ │ 📋 Planner │ │ 🔨 Worker
159
+ Orchestrator │ │ Research+Plan │ │ Implementation
160
+ ├─────────────────────┤ ├─────────────────────┤ ├─────────────────────┤
161
+ Mission control │ │ Task decompose │ │ Code writing
162
+ Parallel delegate │ │ Doc research │ │ File operations
163
+ • TODO monitoring │ │ • TODO creation │ │ • Command execution
77
164
  └─────────────────────┘ └─────────────────────┘ └─────────────────────┘
78
-
79
- └─────────────────────────┼─────────────────────────┘
80
-
81
- ┌─────────────────────────────────────────────────────────────────────────────┐
82
- 📁 SHARED CONTEXT (.opencode/)
83
-
84
- .opencode/todo.md ← Master TODO (Planner creates, Reviewer updates)
85
- .opencode/context.md ← Adaptive context (shrinks as progress increases)
86
- .opencode/docs/ Cached docs (Planner/Worker save, auto-expire)
87
- .opencode/archive/ ← Old context for reference
88
-
89
- ⚡ All sessions read/write this shared workspace
90
- 📊 Progress is tracked via todo.md checkboxes
91
- └─────────────────────────────────────────────────────────────────────────────┘
165
+
166
+ │ │ │
167
+ │ ┌────────┴────────┐ │
168
+ │ ▼ │ │
169
+ ┌─────────────────────┐
170
+ ✅ Reviewer │ │ │
171
+ Quality+Context │ │ │
172
+ ├─────────────────────┤
173
+ Verification │ │
174
+ TODO updates │ │
175
+ • Context manage │ │ │
176
+ └─────────────────────┘
177
+ │ │
178
+ └──────────────────┼─────────────────┴──────────────────┘
179
+
180
+ ┌─────────────────────────────────────────────────────────────────────────────────┐
181
+ │ 📁 Shared Workspace (.opencode/) │
182
+ ├─────────────────────────────────────────────────────────────────────────────────┤
183
+ │ todo.md │ Hierarchical task list (Epic → Task → Subtask) │
184
+ │ context.md │ Adaptive context (shrinks with progress) │
185
+ │ loop-state.json │ Mission loop iteration state │
186
+ │ docs/ │ Cached documentation (auto-expire) │
187
+ │ archive/ │ Old context snapshots │
188
+ └─────────────────────────────────────────────────────────────────────────────────┘
189
+ ```
190
+
191
+
192
+ ### 📂 Directory Structure
193
+
194
+ ```
195
+ src/
196
+ ├── index.ts # Plugin main entry point
197
+ ├── agents/
198
+ │ ├── commander.ts # Commander agent definition
199
+ │ ├── definitions.ts # Agent exports
200
+ │ ├── prompts/ # Prompt fragments (commander/, planner/, worker/, reviewer/)
201
+ │ └── subagents/ # Subagent definitions (planner.ts, worker.ts, reviewer.ts)
202
+ ├── core/
203
+ │ ├── agents/ # ParallelAgentManager, TaskStore, ConcurrencyController
204
+ │ ├── cache/ # DocumentCache
205
+ │ ├── loop/ # MissionSeal, TodoContinuation, TodoEnforcer
206
+ │ ├── notification/ # Toast, TaskToastManager
207
+ │ ├── recovery/ # SessionRecovery, ErrorPatterns
208
+ │ ├── session/ # SharedContext
209
+ │ └── task/ # TaskScheduler, TaskParser
210
+ ├── plugin-handlers/
211
+ │ ├── chat-message-handler.ts # /task detection, mission start
212
+ │ ├── event-handler.ts # session.idle, session.error handling
213
+ │ ├── tool-execute-handler.ts # Tool completion tracking
214
+ │ └── assistant-done-handler.ts # Response completion
215
+ ├── shared/
216
+ │ ├── constants/ # PATHS, TOOL_NAMES, MISSION_SEAL, etc.
217
+ │ ├── agent/ # Agent definitions, names
218
+ │ └── errors/ # Error types
219
+ ├── tools/
220
+ │ ├── parallel/ # delegate_task, get_task_result, list_tasks, cancel_task
221
+ │ ├── web/ # webfetch, websearch, codesearch, cache_docs
222
+ │ ├── background-cmd/ # run_background, check_background, list_background
223
+ │ └── search.ts # grep_search, glob_search, mgrep
224
+ └── utils/ # Utility functions
92
225
  ```
93
226
 
94
- ---
95
227
 
96
228
  ## Installation
97
229
 
@@ -127,9 +259,17 @@ Use `/task` when you need the AI to **complete a mission autonomously**:
127
259
  **What Commander Mode Does:**
128
260
  - ♾️ **Runs until sealed** — Loops until agent outputs `<mission_seal>SEALED</mission_seal>`
129
261
  - 🧠 **Anti-Hallucination** — Researches docs before coding
130
- - ⚡ **Parallel Execution** — Up to 50 concurrent agents
131
- - 🔄 **Auto-Recovery** — Handles errors automatically
132
- - 📊 **Triage System** — Adapts strategy to complexity (L1/L2/L3)
262
+ - ⚡ **Parallel Execution** — Up to 50 concurrent Worker Sessions
263
+ - 🔄 **Auto-Recovery** — Handles errors automatically with pattern matching
264
+ - 📊 **Progress Tracking** — Monitors TODO completion and shows progress
265
+
266
+ **Concurrency Limits (per agent type):**
267
+ | Agent | Max Concurrent | Purpose |
268
+ |--------|---------------|-----------|
269
+ | Commander | 1 | Single orchestrator per mission |
270
+ | Planner | 3 | Research and TODO planning |
271
+ | Worker | 10 | Implementation tasks |
272
+ | Reviewer | 5 | Verification and testing |
133
273
 
134
274
  **🎖️ Mission Seal Loop:**
135
275
  ```
@@ -172,7 +312,65 @@ What's the difference between useState and useReducer?
172
312
 
173
313
  ---
174
314
 
175
- ## The 7 Agents
315
+ ## 🔄 Mission Loop Mechanism
316
+
317
+ The Commander uses an event-driven mission loop to autonomously complete missions:
318
+
319
+ ```
320
+ ┌─────────────────────────────────────────────────────────────────┐
321
+ │ MISSION LOOP LIFECYCLE │
322
+ └─────────────────────────────────────────────────────────────────┘
323
+
324
+ 1️⃣ User sends "/task 'mission'"
325
+
326
+ 2️⃣ chat.message handler detects /task
327
+
328
+ 3️⃣ Create session + startMissionLoop()
329
+
330
+ Write .opencode/loop-state.json:
331
+ {
332
+ "active": true,
333
+ "sessionID": "ses_abc",
334
+ "iteration": 1,
335
+ "maxIterations": 20
336
+ }
337
+
338
+ 4️⃣ Commander receives prompt → delegates work
339
+
340
+ 5️⃣ Worker sessions execute → results collected
341
+
342
+ 6️⃣ session.idle event triggers
343
+
344
+ Check for <mission_seal>SEALED</mission_seal>
345
+ ├─ Seal found? → Clear loop state → Complete ✅
346
+ └─ Not found? → Increment iteration → Continue loop
347
+
348
+ Show countdown toast (3 seconds)
349
+
350
+ Inject continuation prompt
351
+
352
+ [Loop back to step 4]
353
+ ```
354
+
355
+ **Key Loop Components:**
356
+
357
+ | Component | File | Purpose |
358
+ |-----------|-------|---------|
359
+ | Loop State | `src/core/loop/mission-seal.ts` | State management (.opencode/loop-state.json) |
360
+ | Seal Detection | `src/core/loop/mission-seal-handler.ts` | Detect `<mission_seal>` in responses |
361
+ | Continuation | `src/core/loop/mission-seal-handler.ts` | Inject prompts to continue work |
362
+ | Countdown | `src/core/loop/mission-seal-handler.ts` | 3-second countdown toast |
363
+ | Idle Handler | `src/plugin-handlers/assistant-done-handler.ts` | Monitor session.idle events |
364
+
365
+ **Why Event-Driven?**
366
+ - No fixed iteration limits - loop continues until sealed
367
+ - Resilient to network delays
368
+ - Can be interrupted by user at any time
369
+ - Efficient polling (500ms interval with backoff)
370
+
371
+ ---
372
+
373
+ ## The 4 Agents
176
374
 
177
375
  | Agent | Role | Responsibility |
178
376
  | :--------------- | :----------- | :--------------------------------- |
@@ -210,7 +408,7 @@ What's the difference between useState and useReducer?
210
408
  | Notifications | 100/parent | FIFO eviction |
211
409
  | Event History | 100 | Ring buffer |
212
410
  | Session TTL | 60 min | Auto cleanup |
213
- | Poll Interval | 1 second | Fast completion detection |
411
+ | Poll Interval | 500ms | Fast completion detection |
214
412
  | Max Poll Count | 600 | Hard limit prevents infinite loops |
215
413
  | Sync Timeout | 5 min | Safe delegate_task timeout |
216
414
  | Recovery Attempts | 3 | Auto session error recovery |
@@ -238,9 +436,9 @@ Automatic recovery from common errors:
238
436
 
239
437
  ### Todo Continuation
240
438
  - Monitors `session.idle` events
241
- - 2-second countdown before auto-continuation
439
+ - 3-second countdown toast before auto-continuation
242
440
  - Cancels on user interaction
243
- - Skips if background tasks running
441
+ - Skips if background tasks running or session is recovering
244
442
 
245
443
  ### noReply Optimization
246
444
  - Individual task completion: `noReply: true` (saves tokens)
@@ -274,9 +472,9 @@ tail -f "$(node -e 'console.log(require("os").tmpdir())')/opencode-orchestrator.
274
472
  ## Documentation
275
473
 
276
474
  - **[System Architecture](docs/SYSTEM_ARCHITECTURE.md)** — Detailed technical docs
277
- - **[OpenCode SDK Reference](docs/OPENCODE_SDK_REFERENCE.md)** — API usage reference
475
+ - **[Architecture and Flow](docs/ARCHITECTURE_AND_FLOW.md)** — Complete architecture guide with scenarios
476
+ - **[Improvement Suggestions](docs/IMPROVEMENT_SUGGESTIONS.md)** — Project improvement recommendations
278
477
  - [Release Notes](docs/releases/) — Version history
279
- - [Troubleshooting](docs/PLUGIN_TROUBLESHOOTING.md)
280
478
 
281
479
  ---
282
480
 
@@ -1,2 +1,8 @@
1
+ /**
2
+ * Commander Agent
3
+ *
4
+ * Master orchestrator with parallel execution capabilities.
5
+ * Uses modular prompt fragments for flexible composition.
6
+ */
1
7
  import { AgentDefinition } from "../shared/agent.js";
2
8
  export declare const commander: AgentDefinition;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Commander Agent Delegation
3
+ */
4
+ export declare const COMMANDER_AGENTS: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Commander Execution Strategy
3
+ */
4
+ export declare const COMMANDER_EXECUTION: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Commander Forbidden Actions
3
+ */
4
+ export declare const COMMANDER_FORBIDDEN: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Commander Identity
3
+ */
4
+ export declare const COMMANDER_IDENTITY = "<identity>\n- You are the ORCHESTRATOR, not the implementer\n- You DELEGATE work to specialized agents\n- You COORDINATE parallel execution\n- You VERIFY completion before sealing\n- You are RELENTLESS - never stop mid-mission\n</identity>";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Commander Prompts - Index
3
+ */
4
+ export { COMMANDER_ROLE } from "./role.js";
5
+ export { COMMANDER_IDENTITY } from "./identity.js";
6
+ export { COMMANDER_FORBIDDEN } from "./forbidden.js";
7
+ export { COMMANDER_REQUIRED } from "./required.js";
8
+ export { COMMANDER_TOOLS } from "./tools.js";
9
+ export { COMMANDER_EXECUTION } from "./execution.js";
10
+ export { COMMANDER_PARALLEL } from "./parallel.js";
11
+ export { COMMANDER_AGENTS } from "./agents.js";
12
+ export { COMMANDER_TODO_FORMAT } from "./todo-format.js";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Commander Parallel Execution
3
+ */
4
+ export declare const COMMANDER_PARALLEL: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Commander Required Actions
3
+ */
4
+ export declare const COMMANDER_REQUIRED: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Commander Role Definition
3
+ */
4
+ export declare const COMMANDER_ROLE = "<role>\nYou are Commander. Autonomous mission controller with parallel execution.\nYou NEVER stop until the mission is SEALED. You are RELENTLESS.\nYou ORCHESTRATE - you delegate, coordinate, and verify.\n</role>";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Commander TODO Format - Hierarchical
3
+ */
4
+ export declare const COMMANDER_TODO_FORMAT: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Commander Tools Overview
3
+ */
4
+ export declare const COMMANDER_TOOLS: string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Anti-Hallucination Rules
3
+ *
4
+ * Core rules to prevent LLM from making up information.
5
+ */
6
+ export declare const ANTI_HALLUCINATION_CORE = "<anti_hallucination>\n ZERO TOLERANCE FOR GUESSING\n\nBEFORE ANY IMPLEMENTATION:\n1. Check .opencode/docs/ for cached documentation\n2. If not found \u2192 websearch for OFFICIAL docs\n3. webfetch with cache=true\n4. Use EXACT syntax from docs\n\nTRUSTED SOURCES ONLY:\n- Official docs: docs.[framework].com\n- GitHub: github.com/[org]/[repo]\n- Package registries: npmjs.com, pypi.org\n\n FORBIDDEN:\n- Inventing function signatures\n- Assuming API compatibility\n- Guessing version-specific syntax\n- Using outdated knowledge\n\n REQUIRED:\n- Source URL for every claim\n- Confidence level: HIGH (official) / MEDIUM (github) / LOW (blog)\n- Say \"NOT FOUND\" if documentation unavailable\n</anti_hallucination>";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Environment Discovery Prompt
3
+ *
4
+ * PHASE 0: Mandatory first step - understand project before ANY action
5
+ */
6
+ export declare const ENVIRONMENT_DISCOVERY = "<environment_discovery>\n MANDATORY FIRST STEP - Before any planning or coding:\n\n## 1. Project Structure Analysis\n- Read file tree: ls -la, find . -type f -name \"*.ts\" | head -50\n- Identify: src/, tests/, docs/, config files\n- Check for: package.json, Dockerfile, docker-compose.yml, Makefile\n\n## 2. Build Environment Detection\n| Check | Command | Look For |\n|-------|---------|----------|\n| Node.js | cat package.json | scripts.build, scripts.test |\n| Docker | ls Dockerfile* | Multi-stage build, base image |\n| Make | cat Makefile | build, test, deploy targets |\n| Rust | cat Cargo.toml | [package], [dependencies] |\n\n## 3. Documentation Review\n- README.md \u2192 Project overview, setup instructions\n- CONTRIBUTING.md \u2192 Code standards, PR process\n- docs/ \u2192 Architecture, API docs\n- .opencode/ \u2192 Existing context, todos\n\n## 4. Context Summary (SAVE TO .opencode/context.md)\n```markdown\n# Project Context\n## Environment\n- Runtime: [Node.js 20 / Python 3.11 / Rust 1.75]\n- Build: [npm / Docker / Make]\n- Test: [npm test / pytest / cargo test]\n\n## Structure\n- Source: src/\n- Tests: tests/\n- Docs: docs/\n\n## Key Files\n- Entry: [src/index.ts]\n- Config: [tsconfig.json, package.json]\n\n## Conventions\n- [observed patterns from existing code]\n```\n\nNEVER skip this step. NEVER assume without checking.\n</environment_discovery>";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Common Prompts - Index
3
+ *
4
+ * Re-exports all common prompt fragments.
5
+ */
6
+ export { ENVIRONMENT_DISCOVERY } from "./environment-discovery.js";
7
+ export { ANTI_HALLUCINATION_CORE } from "./anti-hallucination.js";
8
+ export { TODO_RULES } from "./todo-rules.js";
9
+ export { SHARED_WORKSPACE } from "./shared-workspace.js";
10
+ export { MISSION_SEAL_RULES } from "./mission-seal.js";
11
+ export { VERIFICATION_REQUIREMENTS } from "./verification.js";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Mission Seal Rules
3
+ *
4
+ * Requirements for completing and sealing a mission.
5
+ */
6
+ export declare const MISSION_SEAL_RULES: string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Shared Workspace Configuration
3
+ *
4
+ * Defines the .opencode/ directory structure.
5
+ */
6
+ export declare const SHARED_WORKSPACE = "<shared_workspace>\n .opencode/ - Shared Context Directory\n\n```\n.opencode/\n\u251C\u2500\u2500 todo.md - Master task list\n\u251C\u2500\u2500 context.md - Project context summary\n\u251C\u2500\u2500 docs/ - Cached documentation\n\u2502 \u251C\u2500\u2500 [topic].md\n\u2502 \u2514\u2500\u2500 ...\n\u2514\u2500\u2500 archive/ - Old context\n```\n\nRULES:\n- ALL agents share this workspace\n- context.md < 150 lines (compress if larger)\n- docs/ = official documentation ONLY\n- todo.md = single source of truth for tasks\n</shared_workspace>";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * TODO Rules - Hierarchical Structure
3
+ *
4
+ * Three-level TODO system with completion rollup.
5
+ */
6
+ export declare const TODO_RULES: string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Verification Requirements
3
+ *
4
+ * Checklist for verifying code before marking complete.
5
+ */
6
+ export declare const VERIFICATION_REQUIREMENTS = "<verification>\n VERIFICATION CHECKLIST\n\n## Code Verification\n\u25A1 lsp_diagnostics clean (no errors)\n\u25A1 Build passes (npm run build)\n\u25A1 Tests pass (npm test)\n\u25A1 No TypeScript 'any' types\n\u25A1 No console.log debugging left\n\n## Documentation Verification\n\u25A1 Implementation matches .opencode/docs/\n\u25A1 API usage matches official docs\n\u25A1 Version compatibility confirmed\n\n## Security Verification\n\u25A1 No hardcoded secrets/passwords\n\u25A1 Input validation present\n\u25A1 Error messages don't leak info\n\nONLY mark complete after ALL checks pass!\n</verification>";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Agent Prompts - Index
3
+ *
4
+ * Exports all modular prompt fragments.
5
+ * Structure: 1 folder per agent/category, 1 file per const
6
+ */
7
+ export * from "./common/index.js";
8
+ export * from "./commander/index.js";
9
+ export * from "./planner/index.js";
10
+ export * from "./worker/index.js";
11
+ export * from "./reviewer/index.js";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Planner Forbidden Actions
3
+ */
4
+ export declare const PLANNER_FORBIDDEN = "<forbidden_actions>\nNEVER implement code - only plan and research\nNEVER guess API syntax - always verify with official docs\nNEVER create TODO without parallel groups\nNEVER claim knowledge without source URL\nNEVER assume version compatibility\nNEVER create TODOs with [x] already marked\nNEVER skip environment discovery\n</forbidden_actions>";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Planner Prompts - Index
3
+ */
4
+ export { PLANNER_ROLE } from "./role.js";
5
+ export { PLANNER_FORBIDDEN } from "./forbidden.js";
6
+ export { PLANNER_REQUIRED } from "./required.js";
7
+ export { PLANNER_TODO_FORMAT } from "./todo-format.js";
8
+ export { PLANNER_RESEARCH } from "./research.js";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Planner Required Actions
3
+ */
4
+ export declare const PLANNER_REQUIRED = "<required_actions>\nALWAYS analyze project structure first\nALWAYS cite sources with URLs\nALWAYS maximize parallelism in TODO\nALWAYS include confidence level (HIGH/MEDIUM/LOW)\nALWAYS save docs to .opencode/docs/\nALWAYS include task dependencies explicitly\nALWAYS create tasks with [ ] (unchecked)\n</required_actions>";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Planner Research Workflow
3
+ */
4
+ export declare const PLANNER_RESEARCH = "<research_workflow>\n1. websearch \"[topic] official documentation [version]\"\n2. webfetch official URL with cache=true\n3. Extract EXACT syntax (not paraphrased)\n4. Save to .opencode/docs/[topic].md\n\nOUTPUT:\n```markdown\n# Research: [topic]\nSource: [official URL]\nConfidence: HIGH/MEDIUM/LOW\nVersion: [version]\n\n## Exact Syntax\n```[lang]\n[code from official docs]\n```\n```\n</research_workflow>";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Planner Role
3
+ */
4
+ export declare const PLANNER_ROLE: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Planner TODO Format - Hierarchical
3
+ */
4
+ export declare const PLANNER_TODO_FORMAT: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Reviewer Forbidden Actions
3
+ */
4
+ export declare const REVIEWER_FORBIDDEN: string;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Reviewer Prompts - Index
3
+ */
4
+ export { REVIEWER_ROLE } from "./role.js";
5
+ export { REVIEWER_FORBIDDEN } from "./forbidden.js";
6
+ export { REVIEWER_REQUIRED } from "./required.js";
7
+ export { REVIEWER_VERIFICATION } from "./verification.js";
8
+ export { REVIEWER_TODO_UPDATE } from "./todo-update.js";
9
+ export { REVIEWER_OUTPUT } from "./output.js";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Reviewer Output Format
3
+ */
4
+ export declare const REVIEWER_OUTPUT: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Reviewer Required Actions
3
+ */
4
+ export declare const REVIEWER_REQUIRED = "<required_actions>\nALWAYS run lsp_diagnostics\nALWAYS run build command (npm run build)\nALWAYS run test command (npm test)\nALWAYS check implementation matches .opencode/docs/\nALWAYS update .opencode/todo.md checkboxes ONLY after verification\nALWAYS provide PASS/FAIL with evidence\nALWAYS check for security issues\nALWAYS verify tests exist for new code\n</required_actions>";