@te-river/opencode-team-mode 1.5.5 → 1.5.7

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 (163) hide show
  1. package/README.md +544 -634
  2. package/README.zh-CN.md +511 -576
  3. package/dist/agents.d.ts +6 -1
  4. package/dist/agents.d.ts.map +1 -1
  5. package/dist/agents.js +113 -533
  6. package/dist/agents.js.map +1 -1
  7. package/dist/approval-gate.d.ts +16 -0
  8. package/dist/approval-gate.d.ts.map +1 -1
  9. package/dist/approval-gate.js +8 -1
  10. package/dist/approval-gate.js.map +1 -1
  11. package/dist/blackboard.d.ts.map +1 -1
  12. package/dist/blackboard.js +3 -2
  13. package/dist/blackboard.js.map +1 -1
  14. package/dist/commands.d.ts.map +1 -1
  15. package/dist/commands.js +7 -6
  16. package/dist/commands.js.map +1 -1
  17. package/dist/envprotect/bash-classify.d.ts +42 -0
  18. package/dist/envprotect/bash-classify.d.ts.map +1 -0
  19. package/dist/envprotect/bash-classify.js +221 -0
  20. package/dist/envprotect/bash-classify.js.map +1 -0
  21. package/dist/envprotect/gate-predicates.d.ts +57 -0
  22. package/dist/envprotect/gate-predicates.d.ts.map +1 -0
  23. package/dist/envprotect/gate-predicates.js +174 -0
  24. package/dist/envprotect/gate-predicates.js.map +1 -0
  25. package/dist/envprotect/hook.d.ts +45 -0
  26. package/dist/envprotect/hook.d.ts.map +1 -0
  27. package/dist/envprotect/hook.js +158 -0
  28. package/dist/envprotect/hook.js.map +1 -0
  29. package/dist/envprotect/path-classify.d.ts +16 -0
  30. package/dist/envprotect/path-classify.d.ts.map +1 -0
  31. package/dist/envprotect/path-classify.js +72 -0
  32. package/dist/envprotect/path-classify.js.map +1 -0
  33. package/dist/envprotect/patterns.d.ts +77 -0
  34. package/dist/envprotect/patterns.d.ts.map +1 -0
  35. package/dist/envprotect/patterns.js +182 -0
  36. package/dist/envprotect/patterns.js.map +1 -0
  37. package/dist/envprotect.d.ts +19 -217
  38. package/dist/envprotect.d.ts.map +1 -1
  39. package/dist/envprotect.js +18 -803
  40. package/dist/envprotect.js.map +1 -1
  41. package/dist/fs-safe.d.ts +16 -0
  42. package/dist/fs-safe.d.ts.map +1 -0
  43. package/dist/fs-safe.js +56 -0
  44. package/dist/fs-safe.js.map +1 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +22 -6
  47. package/dist/index.js.map +1 -1
  48. package/dist/prompts/lead.d.ts +7 -0
  49. package/dist/prompts/lead.d.ts.map +1 -0
  50. package/dist/prompts/lead.js +233 -0
  51. package/dist/prompts/lead.js.map +1 -0
  52. package/dist/prompts/shared.d.ts +8 -0
  53. package/dist/prompts/shared.d.ts.map +1 -0
  54. package/dist/prompts/shared.js +120 -0
  55. package/dist/prompts/shared.js.map +1 -0
  56. package/dist/prompts/specialists.d.ts +12 -0
  57. package/dist/prompts/specialists.d.ts.map +1 -0
  58. package/dist/prompts/specialists.js +241 -0
  59. package/dist/prompts/specialists.js.map +1 -0
  60. package/dist/shell-text.d.ts +14 -0
  61. package/dist/shell-text.d.ts.map +1 -0
  62. package/dist/shell-text.js +16 -0
  63. package/dist/shell-text.js.map +1 -0
  64. package/dist/tm/args-schema.d.ts +42 -0
  65. package/dist/tm/args-schema.d.ts.map +1 -0
  66. package/dist/tm/args-schema.js +213 -0
  67. package/dist/tm/args-schema.js.map +1 -0
  68. package/dist/tm/browser.d.ts +52 -0
  69. package/dist/tm/browser.d.ts.map +1 -0
  70. package/dist/tm/browser.js +361 -0
  71. package/dist/tm/browser.js.map +1 -0
  72. package/dist/tm/client-unwrap.d.ts +38 -0
  73. package/dist/tm/client-unwrap.d.ts.map +1 -0
  74. package/dist/tm/client-unwrap.js +113 -0
  75. package/dist/tm/client-unwrap.js.map +1 -0
  76. package/dist/tm/config.d.ts +55 -19
  77. package/dist/tm/config.d.ts.map +1 -1
  78. package/dist/tm/config.js +74 -19
  79. package/dist/tm/config.js.map +1 -1
  80. package/dist/tm/guard.d.ts.map +1 -1
  81. package/dist/tm/guard.js +4 -7
  82. package/dist/tm/guard.js.map +1 -1
  83. package/dist/tm/index.d.ts +24 -7
  84. package/dist/tm/index.d.ts.map +1 -1
  85. package/dist/tm/index.js +111 -21
  86. package/dist/tm/index.js.map +1 -1
  87. package/dist/tm/memory.d.ts +88 -0
  88. package/dist/tm/memory.d.ts.map +1 -0
  89. package/dist/tm/memory.js +360 -0
  90. package/dist/tm/memory.js.map +1 -0
  91. package/dist/tm/pipelines.d.ts +58 -0
  92. package/dist/tm/pipelines.d.ts.map +1 -0
  93. package/dist/tm/pipelines.js +308 -0
  94. package/dist/tm/pipelines.js.map +1 -0
  95. package/dist/tm/preview.d.ts +6 -1
  96. package/dist/tm/preview.d.ts.map +1 -1
  97. package/dist/tm/preview.js +63 -13
  98. package/dist/tm/preview.js.map +1 -1
  99. package/dist/tm/ptc/budgets.d.ts +38 -0
  100. package/dist/tm/ptc/budgets.d.ts.map +1 -0
  101. package/dist/tm/ptc/budgets.js +59 -0
  102. package/dist/tm/ptc/budgets.js.map +1 -0
  103. package/dist/tm/ptc/contract.d.ts +131 -0
  104. package/dist/tm/ptc/contract.d.ts.map +1 -0
  105. package/dist/tm/ptc/contract.js +47 -0
  106. package/dist/tm/ptc/contract.js.map +1 -0
  107. package/dist/tm/ptc/driver.d.ts +37 -0
  108. package/dist/tm/ptc/driver.d.ts.map +1 -0
  109. package/dist/tm/ptc/driver.js +181 -0
  110. package/dist/tm/ptc/driver.js.map +1 -0
  111. package/dist/tm/ptc/engines.d.ts +32 -0
  112. package/dist/tm/ptc/engines.d.ts.map +1 -0
  113. package/dist/tm/ptc/engines.js +201 -0
  114. package/dist/tm/ptc/engines.js.map +1 -0
  115. package/dist/tm/ptc/gate.d.ts +28 -0
  116. package/dist/tm/ptc/gate.d.ts.map +1 -0
  117. package/dist/tm/ptc/gate.js +130 -0
  118. package/dist/tm/ptc/gate.js.map +1 -0
  119. package/dist/tm/ptc/index.d.ts +19 -0
  120. package/dist/tm/ptc/index.d.ts.map +1 -0
  121. package/dist/tm/ptc/index.js +15 -0
  122. package/dist/tm/ptc/index.js.map +1 -0
  123. package/dist/tm/ptc/pscan.d.ts +11 -0
  124. package/dist/tm/ptc/pscan.d.ts.map +1 -0
  125. package/dist/tm/ptc/pscan.js +27 -0
  126. package/dist/tm/ptc/pscan.js.map +1 -0
  127. package/dist/tm/ptc/summary.d.ts +17 -0
  128. package/dist/tm/ptc/summary.d.ts.map +1 -0
  129. package/dist/tm/ptc/summary.js +112 -0
  130. package/dist/tm/ptc/summary.js.map +1 -0
  131. package/dist/tm/ptc/tool.d.ts +35 -0
  132. package/dist/tm/ptc/tool.d.ts.map +1 -0
  133. package/dist/tm/ptc/tool.js +136 -0
  134. package/dist/tm/ptc/tool.js.map +1 -0
  135. package/dist/tm/ptc.d.ts +45 -26
  136. package/dist/tm/ptc.d.ts.map +1 -1
  137. package/dist/tm/ptc.js +71 -45
  138. package/dist/tm/ptc.js.map +1 -1
  139. package/dist/tm/result.d.ts +34 -0
  140. package/dist/tm/result.d.ts.map +1 -0
  141. package/dist/tm/result.js +87 -0
  142. package/dist/tm/result.js.map +1 -0
  143. package/dist/tm/search.d.ts +58 -0
  144. package/dist/tm/search.d.ts.map +1 -0
  145. package/dist/tm/search.js +229 -0
  146. package/dist/tm/search.js.map +1 -0
  147. package/dist/tm/shell-bridge.d.ts +22 -0
  148. package/dist/tm/shell-bridge.d.ts.map +1 -0
  149. package/dist/tm/shell-bridge.js +116 -0
  150. package/dist/tm/shell-bridge.js.map +1 -0
  151. package/dist/tm/store.d.ts.map +1 -1
  152. package/dist/tm/store.js +2 -1
  153. package/dist/tm/store.js.map +1 -1
  154. package/dist/tm/tools.d.ts +13 -71
  155. package/dist/tm/tools.d.ts.map +1 -1
  156. package/dist/tm/tools.js +22 -656
  157. package/dist/tm/tools.js.map +1 -1
  158. package/dist/tm/webfetch.d.ts +109 -0
  159. package/dist/tm/webfetch.d.ts.map +1 -0
  160. package/dist/tm/webfetch.js +305 -0
  161. package/dist/tm/webfetch.js.map +1 -0
  162. package/docs/installation.md +201 -0
  163. package/package.json +4 -3
package/README.md CHANGED
@@ -1,634 +1,544 @@
1
- # OpenCode TeamMode
2
-
3
- **[English](./README.md)** | **[中文](./README.zh-CN.md)**
4
-
5
- [![npm version](https://img.shields.io/npm/v/@te-river/opencode-team-mode.svg)](https://www.npmjs.com/package/@te-river/opencode-team-mode)
6
- [![npm downloads](https://img.shields.io/npm/dm/@te-river/opencode-team-mode.svg)](https://www.npmjs.com/package/@te-river/opencode-team-mode)
7
- [![license](https://img.shields.io/npm/l/@te-river/opencode-team-mode.svg)](./LICENSE)
8
-
9
- > 🤝 **Multi-agent team collaboration plugin for [OpenCode Desktop](https://opencode.ai)**
10
- >
11
- > Adds a complete team of specialized AI agents — Architect, Implementer, Reviewer, Tester, Researcher — orchestrated by a Team Lead, all accessible via simple slash commands.
12
-
13
- ---
14
-
15
- ## ✨ What is TeamMode?
16
-
17
- TeamMode transforms OpenCode Desktop from a single-agent coding assistant into a **full development team**. Each agent has a distinct role, expertise, and personality — just like a real engineering team.
18
-
19
- Instead of one agent trying to do everything, you get:
20
-
21
- | Agent | Role | When to use |
22
- |---|---|---|
23
- | 🎯 **Team Lead** | Orchestrator | Complex tasks that need planning + multi-step execution |
24
- | 🏗️ **Architect** | System designer | Design docs, module structure, API contracts |
25
- | 💻 **Implementer** | Code writer | Building features, writing production code |
26
- | 🔍 **Reviewer** | Dimension-focused auditor | Single-dimension review (completeness / correctness / impact) — the lead runs 3 in parallel |
27
- | 🧪 **Tester** | Test engineer | Unit tests, integration tests, edge-case coverage, static verification (build / typecheck / lint / API tests) |
28
- | 🔎 **Researcher** | Knowledge finder | Library evaluation, API docs, best practices |
29
-
30
- ---
31
-
32
- ## 🚀 Quick Start
33
-
34
- ### Prerequisites
35
-
36
- 1. **Install OpenCode Desktop** (if you haven't already):
37
-
38
- | Platform | Install command |
39
- |---|---|
40
- | macOS (Apple Silicon) | `brew install --cask opencode-desktop` |
41
- | macOS (Intel) | `brew install --cask opencode-desktop` |
42
- | Windows | `scoop bucket add extras && scoop install extras/opencode-desktop` |
43
- | Linux | Download from [opencode.ai/download](https://opencode.ai/download) |
44
-
45
- Or install the **CLI/TUI** version:
46
- ```bash
47
- # one-line script (all platforms)
48
- curl -fsSL https://opencode.ai/install | bash
49
-
50
- # or via npm
51
- npm install -g opencode-ai
52
- ```
53
-
54
- 2. **Node.js ≥ 18** (for npm)
55
-
56
- ### Install TeamMode
57
-
58
- **Option A — One-line installer:**
59
-
60
- macOS / Linux (bash):
61
- ```bash
62
- curl -fsSL https://ghproxy.net/https://raw.githubusercontent.com/Te-River/Opencode-TeamMode/main/scripts/install.sh | bash
63
- ```
64
-
65
- Windows (PowerShell):
66
- ```powershell
67
- irm https://ghproxy.net/https://raw.githubusercontent.com/Te-River/Opencode-TeamMode/main/scripts/install.ps1 | iex
68
- ```
69
-
70
- **Option B — Manual config:**
71
-
72
- Add the plugin to your `opencode.jsonc`:
73
-
74
- ```jsonc
75
- {
76
- "$schema": "https://opencode.ai/config.json",
77
- "plugin": [
78
- "@te-river/opencode-team-mode@latest"
79
- ]
80
- }
81
- ```
82
-
83
- OpenCode will automatically install the plugin on startup.
84
-
85
- > **Tip:** After modifying `opencode.json`, **restart OpenCode Desktop** for changes to take effect.
86
-
87
- ---
88
-
89
- ## ⚙️ Configuration
90
-
91
- The plugin automatically injects all team agents and commands when OpenCode starts. **No need to manually copy agent files or command definitions.**
92
-
93
- > ⚠️ **Model choice matters.** Every judgment in the workflow — triage,
94
- > decomposition, dispatch briefs, synthesis, review-loop verdicts — flows
95
- > through the **Team Lead**. A weak model in that seat degrades the whole
96
- > pipeline no matter how strong the specialists are. Pin your best
97
- > reasoning model to the `team` agent (recipe in
98
- > [Customization](#customization) below).
99
-
100
- ### Global install (all projects)
101
-
102
- To enable TeamMode in every project, add the plugin to your global config:
103
-
104
- ```jsonc
105
- // ~/.config/opencode/opencode.jsonc
106
- {
107
- "$schema": "https://opencode.ai/config.json",
108
- "plugin": [
109
- "@te-river/opencode-team-mode@latest"
110
- ]
111
- }
112
- ```
113
-
114
- ---
115
-
116
- ## 📖 Usage
117
-
118
- ### Slash Commands
119
-
120
- TeamMode adds six slash commands to OpenCode. Type them in the chat input:
121
-
122
- | Command | Agent | Description |
123
- |---|---|---|
124
- | `/team-plan <task>` | Architect | Create a detailed implementation plan with architecture, file manifest, and task breakdown |
125
- | `/team-implement <task>` | Implementer | Write production code for a feature or task |
126
- | `/team-review [scope]` | Reviewer | Audit code for bugs, security issues, and quality problems |
127
- | `/team-test [scope]` | Tester | Generate comprehensive tests with edge-case coverage |
128
- | `/team-research <topic>` | Researcher | Investigate libraries, APIs, or best practices |
129
- | `/team-run <task>` | Team Lead | **Full workflow** — orchestrates all agents end-to-end |
130
-
131
- #### Example workflow
132
-
133
- ```
134
- # 1. Plan the feature
135
- /team-plan Add user authentication with OAuth2 and JWT tokens
136
-
137
- # 2. Review the plan, then implement
138
- /team-implement Implement the auth module as planned
139
-
140
- # 3. Review the code
141
- /team-review src/auth/
142
-
143
- # 4. Write tests
144
- /team-test src/auth/
145
-
146
- # Or let the team lead handle everything:
147
- /team-run Add user authentication with OAuth2 and JWT tokens
148
- ```
149
-
150
- ### Agent Picker
151
-
152
- You can also invoke agents directly using the `@` mention in OpenCode Desktop:
153
-
154
- - `@team` — Orchestrate a complex task
155
- - `@architect` — Design a system or module
156
- - `@implementer` — Write code
157
- - `@reviewer` — Review code quality
158
- - `@tester` — Write tests
159
- - `@researcher` — Research a topic
160
-
161
- ### Demo
162
-
163
- A session transcript, recreated from how the flow actually looks. Team is the
164
- default agent out of the box (see Configuration to opt out), so the user just
165
- types into a fresh chat:
166
-
167
- > **User:** Add token-bucket rate limiting to our Express API — 100 requests
168
- > per minute per user, return 429 when exceeded. Don't touch anything under
169
- > `src/legacy/`.
170
-
171
- ```text
172
- team Route: product behavior change → implementer → tester → reviewer
173
- (3 dispatches → approval gate applies)
174
-
175
- Research: read README, src/app.ts, src/middleware/*
176
- Blocking questions: none — 1 assumption listed below
177
-
178
- PLAN
179
- Goal: token-bucket limiter, 100 req/min/user, 429 + Retry-After
180
- Scope: src/middleware/rateLimit.ts (new), src/app.ts (+3 lines)
181
- Pipeline: implementer → tester → reviewer (correctness)
182
- Assumption: in-memory bucket, not Redis — say the word to change
183
- Boundary: src/legacy/** untouched
184
- Approve to proceed?
185
-
186
- user approved, go
187
-
188
- team ▸ @implementer — STATUS: done
189
- CHANGES: src/middleware/rateLimit.ts (new) · src/app.ts (+3)
190
- HANDOFF: bucket {tokens, lastRefill}; refill() is a single atomic pass
191
- EVIDENCE: tsc clean (output above)
192
-
193
- ▸ @tester — STATUS: done · VERDICT: pass (14/14)
194
- FINDINGS: burst edge, window expiry, concurrent refill covered;
195
- src/legacy/** byte-identical
196
- EVIDENCE: vitest 14 passed
197
-
198
- ▸ @reviewer — STATUS: done · VERDICT: approve (correctness)
199
- FINDINGS: no Critical/Major; 1 Minor (log line noise) noted
200
-
201
- team Done.
202
- rate limiter shipped: rateLimit.ts (new) · app.ts (+3) · 14 tests green
203
- review: approve · assumption: in-memory only · src/legacy/ untouched
204
- ```
205
-
206
- The only message the user typed was the task and "approved, go". The
207
- pipeline was a routing-table lookup, execution waited for plan approval,
208
- and every handoff traveled as a structured skeleton — no file ceremony.
209
-
210
- ### Desktop-specific features
211
-
212
- In **OpenCode Desktop**, you get additional UX benefits:
213
-
214
- - 🎨 **Color-coded agents** — Each agent has a distinct color in the chat UI for easy identification.
215
- - 📋 **Agent picker** — Click the agent dropdown to switch between team agents visually.
216
- - 🔀 **Parallel sub-tasks** — The Team Lead can dispatch multiple sub-agents simultaneously, with results shown in parallel panels.
217
- - 📊 **Session history** — All team interactions are saved and searchable in the Desktop session sidebar.
218
-
219
- ---
220
-
221
- ## 🧯 Context governance (tm_* + R6 + R2) — new in v1.5.1
222
-
223
- > ⚠️ Requires `@te-river/opencode-team-mode@1.5.1` or later (released
224
- > 2026-09-08). If your config pins `@latest`, OpenCode upgrades on next start.
225
-
226
- **JIT layer-2 tools (`tm_read` / `tm_grep` / `tm_bash` / `tm_fetch`).**
227
- Large tool outputs are context cost's main driver: every step re-sends the
228
- whole window. The tm_* tools run the built-in capability under governance
229
- first: results above `TM_OFFLOAD_THRESHOLD` tokens never enter the window —
230
- they are written to a local run store and replaced by a handle with a
231
- content-aware preview (JSON keys / CSV header+shape / log ERROR×N stats /
232
- code signatures / binary metadata, hard-capped at 80 tokens). When the agent
233
- actually needs the payload it pages through it with `tm_fetch`, using an
234
- HMAC-signed, run-scoped, expiring handle. `tm_bash` only allows read-only
235
- commands (allowlist), and failures come back as structured errors instead of
236
- raw dumps.
237
-
238
- **R6 environment protection (now an approval gate).** With TeamMode active,
239
- the model cannot read environment variables silently. Env-var reads
240
- (`printenv`, `env`, `Get-ChildItem env:`, …) and env files (`.env`, shell rc
241
- files) route through OpenCode's **official confirmation dialog**: you get a
242
- native prompt to approve or deny, and an unanswered prompt is **auto-rejected
243
- after `TM_ASK_TIMEOUT_MIN` (default 10 min)** — the plugin only ever rejects
244
- on timeout, never approves on the model's behalf. Env reads that no wildcard
245
- can express (embedded `$VAR` / `${VAR}` / `$env:` inside another command,
246
- command substitution, subshell/escaped forms) and the `tm_*` wrapper channel
247
- stay a **hard block** (no dialog to slip through). tm_* wrappers route through
248
- the same checks (no backdoor via the wrappers). Audit lines record only tool
249
- name + pattern category + the verdict (`ask` / `allowed-once` /
250
- `allowed-always` / `rejected` / `timeout-rejected` / `degraded`) — never
251
- command text, paths, variable names or values.
252
-
253
- **R2 dangerous operations (same dialog).** Delete (`rm`/`del`/`Remove-Item`/
254
- `rmdir`), git publishing (`git push`/`git commit`), network fetch (`curl`/
255
- `wget`/`Invoke-WebRequest`/`Invoke-RestMethod`), package installs/publishes
256
- (`npm install`/`npm publish`/`pip install`/`winget`/`choco`), process/system
257
- (`taskkill`/`Stop-Process`/`kill`/`shutdown`/`format`) and privilege changes
258
- (`chmod`/`takeown`/`icacls`) — none are silently allowed. They pop the same
259
- official dialog and are auto-rejected if you don't answer within the timeout.
260
- The normal verification stack (`npm test`, `tsc`, `git status`/`diff`) is NOT
261
- gated, so day-to-day team work runs without interruption.
262
-
263
- > ⚠️ **When you approve a dialog, pick "once" — not "always".** Verified on
264
- > the live host, "always" records a far broader rule than the command you
265
- > saw: approving `Get-ChildItem env:PATH` with "always" stores `Get-ChildItem
266
- > *`, so every later `Get-ChildItem` runs with no dialog at all. Only the
267
- > once-verdict keeps each gated operation individually human-checked.
268
-
269
- > Deferral is per-session: env reads only route to the dialog in sessions
270
- > running TeamMode's injected agents (or after such a session has shown one
271
- > of these dialogs). In any other session (e.g. a stock `build`/`plan` chat)
272
- > TeamMode's guard keeps hard-blocking env reads, since no dialog would back
273
- > them there. Compound commands (`a; b`) are evaluated per segment by the
274
- > host and approved through one dialog; the guard blocks them outright
275
- > whenever any segment is an env read.
276
-
277
- > The permission protocol was verified against a live `opencode serve` host
278
- > (1.18.29) via SSE event capture; the Desktop dialog rendering itself is the
279
- > one leg that still needs eyeballing in a real Desktop session. Headless
280
- > `opencode run` auto-rejects an unanswered `ask` immediately (there is no
281
- > human to prompt).
282
-
283
- | Env var | Default | Purpose |
284
- |---|---|---|
285
- | `TM_ENV_PROTECT` | `strict` | R6 mode: `strict` / `standard` / `off` (off also disarms the approval timer) |
286
- | `TM_ASK_TIMEOUT_MIN` | `10` | minutes before an unanswered R6/R2 confirmation dialog is auto-rejected; minimum 3 minutes (the host's `permission.replied` reaches the plugin ~120 s late on the event bus — shorter values would auto-reject a just-approved request) |
287
- | `TM_ENV_PROTECT_EXTRA_DENY` | — | extra block patterns (regex list; always a hard block, never dialog-governed) |
288
- | `TM_OFFLOAD_THRESHOLD` | `2000` | offload threshold (tokens, chars/4 estimate) |
289
- | `TM_PREVIEW_MAX_TOKENS` | `80` | preview hard cap |
290
- | `TM_FETCH_MAX_LINES` | `2000` | tm_fetch page cap |
291
- | `TM_BLACKBOARD_DIR` | `.blackboard/` | offloaded payload store |
292
- | `TM_TRAJECTORY_DIR` | `.trajectory/` | append-only tool-call ledger |
293
- | `TM_BLACKBOARD_TTL` | `7` | store retention (days) |
294
- | `TM_BASH_READONLY_ALLOWED` | built-in table | tm_bash allowlist |
295
- | `TM_PTC_MAX_PROGRAM_CHARS` | `4000` | PTC program source length cap (chars) |
296
- | `TM_PTC_MAX_CALLS` | `20` | PTC per-run bridge-call budget (1–200) |
297
- | `TM_PTC_MAX_ERRORS` | `3` | PTC per-run error budget (1–50) |
298
- | `TM_PTC_TIMEOUT_MS` | `60000` | PTC per-run wall-clock timeout (5s–10min) |
299
- | `TM_PTC_ENGINE` | `auto` | PTC engine: `auto` (worker→inline degrade) / `worker` / `inline` |
300
-
301
- ---
302
-
303
- ## ⚡ Batch orchestration (`tm_ptc_run`) — new in v1.5.2
304
-
305
- > Shipped in **v1.5.2** (2026-09-10). Requires `@te-river/opencode-team-mode@1.5.2`
306
- > or later.
307
-
308
- `tm_ptc_run` lets a specialist agent write **one async program** that makes N
309
- governed `tm_*` calls in a single turn — zero LLM round-trips during the run,
310
- only an aggregation summary returns to context. It is designed for batch
311
- read-only tasks: multi-file reconnaissance, bulk grep + read aggregation,
312
- cross-referencing search results.
313
-
314
- ### How it works
315
-
316
- The agent writes a program body using `tm.read(args)`, `tm.grep(args)`,
317
- `tm.bash(args)`, `tm.fetch(args)` — same args as the four governed tools.
318
- Each call returns `{ok:true, data}` (governed: inline text or an offload
319
- handle) or `{ok:false, error:{tool,phase,line?,message}}`. The program
320
- `return`s a value; it is JSON-serialized into the aggregation summary.
321
-
322
- Programs containing `require`, `import`, `process`, `globalThis`, `Deno`,
323
- `Bun`, `fs`, `net`, or `child_process` are rejected before execution (static
324
- pre-scan, auxiliary guard).
325
-
326
- ### Budgets (tighten-only)
327
-
328
- The caller may tighten `max_calls`, `max_errors`, and `timeout_ms` — values
329
- above the `TM_PTC_*` ceilings are clamped down; values below the floor are
330
- clamped up. Hitting any budget stops the whole run; produced output is NOT
331
- lost.
332
-
333
- ### Engine (`TM_PTC_ENGINE`)
334
-
335
- | Mode | Behavior |
336
- |---|---|
337
- | `auto` (default) | Tries `worker_threads` first; on failure degrades to `node:vm` with a `degraded-engine` mark in the summary |
338
- | `worker` | Forces the worker engine (engine-error on failure) |
339
- | `inline` | Forces the `node:vm` engine (30s compile timeout for sync busy-loops; await-gap residual documented) |
340
-
341
- The worker engine runs the program in a dedicated thread with `env:{}`
342
- (process.env emptied), `resourceLimits`, and hard wall-clock `terminate()`.
343
- All governance (P2 path scope, P3 allowlist, R6, threshold offload, TTL)
344
- applies to every bridged call — PTC is not a bypass layer.
345
-
346
- ### Access
347
-
348
- Five specialist agents (`implementer`, `tester`, `architect`, `reviewer`,
349
- `researcher`) have `tm_ptc_run` in their whitelist. The `team` lead does
350
- not — it orchestrates, it does not run batch programs itself.
351
-
352
- ---
353
-
354
- ## 🏗️ Architecture
355
-
356
- ```
357
- opencode-team-mode/
358
- ├── package.json ← npm package definition
359
- ├── tsconfig.json ← TypeScript config
360
- ├── src/
361
- │ ├── index.ts ← Plugin entry (server(): config + R6 tool.execute.before + approval-gate event + tool segment)
362
- │ ├── agents.ts ← Agent definitions (prompts, modes, colors)
363
- │ ├── commands.ts ← Command definitions (templates, agent bindings)
364
- │ ├── blackboard.ts ← Shared blackboard + TTL auto-cleanup sweeper
365
- │ ├── envprotect.ts ← R6 env-var read protection + R2 ask-pattern sets (dialog vs hard-block)
366
- │ ├── approval-gate.ts ← Unified approval gate: host-dialog timeout auto-reject (never self-allows)
367
- │ ├── tm/ ← JIT layer-2 tools (tm_read / tm_grep / tm_bash / tm_fetch / tm_ptc_run)
368
- │ └── types.ts ← Loader-contract type definitions (1.18.x)
369
- ├── scripts/
370
- │ ├── install.sh ← One-click installer (bash)
371
- │ └── install.ps1 ← One-click installer (PowerShell)
372
- ├── pt07/ ← PT-07 baseline suite (seeded A/B token measurement)
373
- ├── LICENSE ← Apache 2.0
374
- ├── README.md ← English documentation
375
- └── README.zh-CN.md ← Chinese documentation
376
- ```
377
-
378
- ### How it works
379
-
380
- 1. OpenCode Desktop starts and loads `opencode.json(c)`.
381
- 2. It sees `"@te-river/opencode-team-mode@latest"` in the `plugin` array and loads the npm package.
382
- 3. The loader calls the plugin's `server(input, options)`, which registers a `config` hook; the hook injects 6 agents and 6 commands into the merged config. The same call installs the R6 `tool.execute.before` guard, arms the unified R6/R2 approval gate (official dialog + `TM_ASK_TIMEOUT_MIN` auto-reject, wired through an `event` hook), and registers the governed `tm_*` tools (see [Context governance](#-context-governance-tm--r6--r2--new-in-v151) below).
383
- 4. The plugin's `id: "team-mode"` is displayed as the plugin name in the Desktop UI.
384
- 5. Agents and commands are immediately available in the Desktop UI — no file copying needed. User-defined agents with the same name always win (the plugin never clobbers them).
385
-
386
- ---
387
-
388
- ## 🗂️ Coordination: structured handoffs first, files second (hybrid)
389
-
390
- Sub-agents cannot message each other live (platform limitation), so TeamMode
391
- coordinates them through a **structured reply skeleton**, with a file
392
- blackboard reserved for oversized output:
393
-
394
- - **Reply skeleton (primary channel):** every specialist's final reply starts
395
- with `STATUS: / CHANGES: / FINDINGS: / EVIDENCE: / HANDOFF:` and stays ≤50
396
- lines. Deliverables at that size travel inline — zero file I/O, nothing to
397
- fall out of sync. The lead relays `HANDOFF` verbatim into the next
398
- dispatch and machine-checks the skeleton (missing → one retry with it
399
- inline, then downgrade and note the violation).
400
- - **Board files (exception only):** when a full deliverable exceeds ~50 lines
401
- (e.g. a complete architecture doc), the dispatch names ONE file:
402
- `<repo>/.git/opencode-team/<session-key>/<task-slug>/NN-<role>-<topic>.md`
403
- — inside `.git/`, so your working tree and commits are **never polluted**
404
- (non-git workspaces fall back to the OS temp dir). Writes are frozen: a
405
- revision is a new round-suffixed file (`…-r2.md`); session folders keep a
406
- fresh conversation from touching a not-yet-swept board.
407
- - **No MANIFEST.md:** the lead's state memory is its todo list.
408
- - **Feedback loop:** Critical/Major findings and product bugs automatically
409
- become tracked fix tasks until the deliverable converges (max 2 loops,
410
- then escalate to you).
411
-
412
- ### Deterministic routing, approval gate & adaptive review (v1.4.7)
413
-
414
- - **Routing table:** the lead picks a fixed pipeline row by task shape —
415
- question → direct answer; docs-only → implementer; product behavior
416
- change → implementer → tester → reviewer; multi-module feature →
417
- architect → implementer → tester → reviewer(s); unknown external tech →
418
- researcher first. Pipelines have fixed minimums: a product change routed
419
- below 3 dispatches is a routing bug, and splitting one request into
420
- sub-2-dispatch pieces to dodge the gate is a protocol violation.
421
- - **Approval gate (count-based):** ≥2 planned dispatches → the lead
422
- researches (reading the repo itself; a researcher dispatch only for
423
- unknown external tech), presents a ≤30-line plan, and **waits for your
424
- approval** before executing anything. 0-1 dispatches run with a 1-2 line
425
- notice. A task that grows a second dispatch mid-run pauses for approval.
426
- Blocking uncertainties are batched and asked immediately — never guessed,
427
- never drip-fed.
428
- - **Adaptive review:** default is ONE reviewer dispatch (correctness);
429
- three parallel dimensions (completeness / correctness / impact) only for
430
- high-risk profiles — auth/security surface, cross-module data contracts,
431
- public APIs across ≥3 files.
432
- - **Static verification:** testers verify via build, typecheck, static
433
- analysis, and API/unit tests. Improvised browser automation (headless
434
- screenshots, DOM stubs) is banned; user-visible frontend changes end with
435
- `UI NOT VERIFIED: <what needs manual checking>` unless the project
436
- already ships real browser-test tooling.
437
- - **No-ceremony fast path:** a root cause the lead has already verified
438
- (file:line evidence) goes straight to the implementer as a fix spec —
439
- investigation dispatches serve unknowns, not ritual.
440
- - **Brevity discipline:** route selection is a table lookup; user-visible
441
- planning text stays ≤5 lines.
442
- - **Evidence standard (kept):** "done / fixed / passed" claims need
443
- verifiable evidence — command output, logs, diffs. Narratives are
444
- progress notes, not proof.
445
- - **Verbatim contracts (kept):** parallel implementers that must
446
- interoperate get the exact data contract (endpoints, field names, types)
447
- pasted verbatim into every affected dispatch.
448
- - **Docs sync (CHANGELOG + AGENTS.md):** delivered changes append a
449
- CHANGELOG.md entry when one exists, and update AGENTS.md when the change
450
- alters what it records (build/test commands, conventions, structure,
451
- agent instructions); either file is offered for creation when missing.
452
- Reading is deduplicated: the lead reads the README itself (the host does
453
- not inject it), uses the host-injected AGENTS.md/CLAUDE.md copy already
454
- in context and opens those files only when genuinely absent — and
455
- specialists never re-open these docs, since conventions arrive
456
- distilled inside their dispatches.
457
-
458
- ### Triage — questions don't become code edits
459
-
460
- The Team Lead classifies every incoming message before acting: a question or
461
- consult gets an answer (zero file changes, fixes merely proposed and awaiting
462
- your go-ahead); only explicit action requests enter the workflow. And whenever
463
- you spell out what may or may not be touched, **those boundaries outrank
464
- everything else** — the lead restates them in every single dispatch.
465
-
466
- ### Cleanup — the TTL sweeper is the only path
467
-
468
- | Who | When |
469
- |---|---|
470
- | Plugin code (in-process sweeper) | At startup + every hour: removes task directories idle **beyond the TTL** |
471
-
472
- The Team Lead never deletes task directories — finished boards stay
473
- readable so you can audit how a run went, and reclamation is pure code
474
- that never relies on the model remembering to do anything (crashes and
475
- force-kills leave nothing behind either). The sweeper prunes stale task
476
- dirs individually under a still-live session, and reclaims an entirely
477
- idle session folder in one pass. Set `ttlDays` to taste.
478
-
479
- ### Configure the TTL
480
-
481
- Default is **5 days**. To choose your own, use the tuple plugin form in
482
- `opencode.jsonc`:
483
-
484
- ```jsonc
485
- {
486
- "$schema": "https://opencode.ai/config.json",
487
- "plugin": [
488
- ["@te-river/opencode-team-mode@latest", { "ttlDays": 7 }]
489
- ]
490
- }
491
- ```
492
-
493
- `ttlDays` accepts any number of days in `(0, 365]`; invalid values silently
494
- fall back to 5.
495
-
496
- ### Default agent
497
-
498
- By default TeamMode **makes Team your default agent** — new chats open
499
- directly in the team orchestrator. One side effect comes with the default
500
- slot: the switcher pins the default agent to the **first position** and
501
- sorts everything else alphabetically, so the picker order is
502
- **team, build, plan**. (Want Team below Plan instead? That requires
503
- giving up the default slot — see the opt-out below; the two are
504
- mutually exclusive by the server's sort.)
505
-
506
- To opt out (`build` stays the default, picker order **build, plan,
507
- team**):
508
-
509
- ```jsonc
510
- {
511
- "plugin": [
512
- ["@te-river/opencode-team-mode@latest", { "defaultAgent": false }]
513
- ]
514
- }
515
- ```
516
-
517
- An explicitly configured non-`build` `default_agent` in your own config is
518
- always respected untouched — the plugin never clobbers it.
519
-
520
- **Upgrade note:** v1.4.4 briefly made this promotion opt-in; v1.4.5 restores
521
- Team-as-default as the shipped behavior. If you pinned `{ "defaultAgent":
522
- true }` during v1.4.4, you can drop that option (or switch it to `false` to
523
- opt out).
524
-
525
- ---
526
-
527
- ## 🔧 Customization
528
-
529
- ### The Team Lead's model matters most
530
-
531
- The Lead is the orchestrating brain: it classifies every message, cuts the
532
- work into packages, writes each dispatch manifest, judges reviewer/tester
533
- findings, and synthesizes the final deliverable. Quality failures there
534
- **multiply down the pipeline** — a mediocre Lead mis-decomposes, briefs the
535
- experts vaguely, and waves weak work through; no specialist can rescue an
536
- assignment it was never correctly given.
537
-
538
- So run the strongest model you can afford **in the Lead seat**. The other
539
- roles tolerate cheaper models — they work from tight briefs with scoped
540
- reading. Pin models per agent:
541
-
542
- ```jsonc
543
- {
544
- "agent": {
545
- // Team Lead — orchestration earns your best model
546
- "team": { "model": "anthropic/claude-opus-4-5" },
547
- // specialists — cheaper models are usually fine
548
- "implementer": { "model": "anthropic/claude-sonnet-4-6" }
549
- }
550
- }
551
- ```
552
-
553
- (Model IDs above are placeholders — use whatever your provider exposes.
554
- Your own `agent.team` definition always takes precedence over the plugin's.)
555
-
556
- ### Override an agent
557
-
558
- Add an agent with the same name in your `opencode.json` — your definition takes precedence:
559
-
560
- ```jsonc
561
- {
562
- "agent": {
563
- "reviewer": {
564
- "model": "anthropic/claude-sonnet-4-6",
565
- "prompt": "You are an extremely strict reviewer. Reject anything with a lint warning."
566
- }
567
- }
568
- }
569
- ```
570
-
571
- ### Add your own agents
572
-
573
- TeamMode does not prevent you from adding more agents. Define them alongside the team:
574
-
575
- ```jsonc
576
- {
577
- "agent": {
578
- "devops": {
579
- "mode": "subagent",
580
- "description": "Handles CI/CD, Docker, and deployment tasks.",
581
- "prompt": "You are the DevOps engineer..."
582
- }
583
- }
584
- }
585
- ```
586
-
587
- ### Disable an agent
588
-
589
- ```jsonc
590
- {
591
- "agent": {
592
- "researcher": { "disable": true }
593
- }
594
- }
595
- ```
596
-
597
- ---
598
-
599
- ## 📦 Publishing to npm
600
-
601
- If you want to publish your own fork:
602
-
603
- ```bash
604
- npm run build # compile TypeScript → dist/
605
- npm version patch # bump version
606
- npm publish # publish to npm registry
607
- ```
608
-
609
- ---
610
-
611
- ## 🤝 Contributing
612
-
613
- Contributions are welcome! Areas where we need help:
614
-
615
- - 🌐 **Localization** — Translate agent prompts to other languages
616
- - 🎨 **More agent roles** — DevOps, DBA, Security Specialist, UX Designer
617
- - 🔧 **Additional commands** — `/team-deploy`, `/team-docs`, `/team-refactor`
618
- - 📝 **Better prompts** — Improve agent behavior through prompt engineering
619
-
620
- ---
621
-
622
- ## 📄 License
623
-
624
- [Apache License 2.0](./LICENSE)
625
-
626
- ---
627
-
628
- ## 🔗 Links
629
-
630
- - [npm Package](https://www.npmjs.com/package/@te-river/opencode-team-mode) — `@te-river/opencode-team-mode` on npm
631
- - [OpenCode Desktop](https://opencode.ai) — Official website & download
632
- - [OpenCode Docs](https://opencode.ai/docs) — Configuration & plugin documentation
633
- - [OpenCode Plugin API](https://opencode.ai/docs/plugins) — Build your own plugins
634
- - [OpenCode GitHub](https://github.com/anomalyco/opencode) — Source code for OpenCode itself
1
+ # OpenCode TeamMode
2
+
3
+ **[English](./README.md)** | **[中文](./README.zh-CN.md)**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@te-river/opencode-team-mode.svg)](https://www.npmjs.com/package/@te-river/opencode-team-mode)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@te-river/opencode-team-mode.svg)](https://www.npmjs.com/package/@te-river/opencode-team-mode)
7
+ [![license](https://img.shields.io/npm/l/@te-river/opencode-team-mode.svg)](./LICENSE)
8
+
9
+ > 🤝 **Your OpenCode just hired a team.**
10
+ >
11
+ > Six specialized agents — a Lead, an Architect, an Implementer, a Reviewer, a Tester and a Researcher — with governed tools, structured handoffs, and a plan-first approval gate. One plugin, zero config files to copy.
12
+
13
+ > 💡 **Best for medium-to-large projects.** The governance layer (approval gate, context offload, tool allowlists) is an asset once a codebase has real surface area — and mostly overhead on tiny scripts and one-off questions. Use it where the work is.
14
+
15
+ ---
16
+
17
+ ## TL;DR — skip the docs
18
+
19
+ > **The lazy path:** paste this to any coding agent and let it do the work:
20
+ >
21
+ > ```text
22
+ > Install the OpenCode plugin @te-river/opencode-team-mode following
23
+ > https://raw.githubusercontent.com/Te-River/Opencode-TeamMode/main/docs/installation.md
24
+ > Then verify the install using the checks in that guide.
25
+ > ```
26
+ >
27
+ > **The one command to remember afterwards:** `/team-run <task>` — the Team Lead
28
+ > plans it, shows you the plan, waits for your approval, then runs the whole team.
29
+
30
+ Everything else below is detail. When you're ready for it, here's the map:
31
+
32
+ **[Why](#-why-teammode) · [The team](#-the-team) · [Install](#-install) · [Usage](#-usage) · [Tools & security](#-governed-tools--security) · [Search](#-web-search-that-actually-works-in-china) · [Config](#️-configuration) · [How it works](#-how-the-team-works) · [FAQ](#-faq) · [Uninstall](#-uninstall)**
33
+
34
+ ---
35
+
36
+ ## 🤔 Why TeamMode?
37
+
38
+ Because a single agent doing everything is how you get: a context window stuffed
39
+ with 5000-line file dumps, twenty round-trips to `bash` for what one script could
40
+ do, sub-agents that silently read `.env`, and web "research" that is really just
41
+ the model's imagination.
42
+
43
+ TeamMode's answer to each:
44
+
45
+ | Pain | TeamMode's answer |
46
+ |---|---|
47
+ | 🔥 **Context flooding** | Every governed tool output over 2000 tokens is offloaded to a local run store and replaced by an 80-token preview + an HMAC handle. The agent pages through what it needs — the window never drowns. |
48
+ | 🐌 **Round-trip overhead** | `tm_ptc_run`: the agent writes ONE program that makes N governed calls in a single turn. Zero LLM round-trips during the run. |
49
+ | 🕳️ **Silent side effects** | R6/R2 approval gate: env-var reads and dangerous ops route through OpenCode's official confirmation dialog, auto-rejected after 10 unanswered minutes. The plugin never approves on its own — it only ever rejects. |
50
+ | 🌫️ **Hallucinated research** | Web access is a two-role grant with an allowlisted, governed tool chain. A fact that couldn't be fetched is reported as a gap — never fabricated. |
51
+
52
+ And the workflow discipline underneath: deterministic routing, a ≤30-line plan
53
+ you approve before ≥2 dispatches execute, structured `STATUS/CHANGES/FINDINGS/
54
+ EVIDENCE/HANDOFF` replies between agents, and static verification (build /
55
+ typecheck / tests) instead of vibes.
56
+
57
+ That discipline is also why the recommendation is **medium-to-large
58
+ projects**: on a two-file script the team simply has less to govern.
59
+
60
+ ---
61
+
62
+ ## 👥 The team
63
+
64
+ | Agent | Role | When to use |
65
+ |---|---|---|
66
+ | 🎯 **Team Lead** (`@team`) | Orchestrator | Complex tasks that need planning + multi-step execution |
67
+ | 🏗️ **Architect** | System designer | Design docs, module structure, API contracts |
68
+ | 💻 **Implementer** | Code writer | Building features, writing production code |
69
+ | 🔍 **Reviewer** | Dimension-focused auditor | Single-dimension review by default; 3 in parallel only for high-risk changes |
70
+ | 🧪 **Tester** | Test engineer | Tests with real edge cases; static verification (build / typecheck / lint); governed UI verification via `tm_browser` |
71
+ | 🔎 **Researcher** | Knowledge finder | Local repo first, then the web — one of the two network roles (with the Lead) |
72
+
73
+ Out of the box, **Team is your default agent** — new chats open straight into the
74
+ orchestrator (opt-out in [Configuration](#-configuration)).
75
+
76
+ ---
77
+
78
+ ## 📦 Install
79
+
80
+ ### Option 1 — Let your agent do it (recommended)
81
+
82
+ Copy this into any coding agent — it will edit your config, restart-remind you, and verify:
83
+
84
+ ```text
85
+ Install the OpenCode plugin @te-river/opencode-team-mode following
86
+ https://raw.githubusercontent.com/Te-River/Opencode-TeamMode/main/docs/installation.md
87
+ Then verify the install using the checks in that guide.
88
+ ```
89
+
90
+ (The guide is the complete manual procedure — config file locations, plugin
91
+ entry, restart, verification, update and uninstall. Your agent reads it and
92
+ executes it faithfully; there is nothing else it needs.)
93
+
94
+ ### Option 2 — One-line script
95
+
96
+ macOS / Linux (bash):
97
+
98
+ ```bash
99
+ curl -fsSL https://ghproxy.net/https://raw.githubusercontent.com/Te-River/Opencode-TeamMode/main/scripts/install.sh | bash
100
+ ```
101
+
102
+ Windows (PowerShell):
103
+
104
+ ```powershell
105
+ irm https://ghproxy.net/https://raw.githubusercontent.com/Te-River/Opencode-TeamMode/main/scripts/install.ps1 | iex
106
+ ```
107
+
108
+ ### Option 3 — Manual
109
+
110
+ Add the plugin to your `opencode.jsonc`:
111
+
112
+ ```jsonc
113
+ {
114
+ "$schema": "https://opencode.ai/config.json",
115
+ "plugin": [
116
+ "@te-river/opencode-team-mode@latest"
117
+ ]
118
+ }
119
+ ```
120
+
121
+ OpenCode installs the plugin on next startup.
122
+
123
+ ### ⚠️ Read this once, save yourself an hour later
124
+
125
+ - **Restart to activate.** After touching `opencode.json`, fully quit and restart OpenCode (Desktop: quit from tray, not just the window).
126
+ - **Plugin updates: re-run the installer.** It is idempotent — a re-run re-patches the config (no-op when present), purges the stale plugin cache, and re-resolves any npm-installed copy. This exists because OpenCode caches plugins by spec string and does NOT re-resolve `@latest` when a new version publishes (upstream limitation). Manual recipe, if you prefer:
127
+
128
+ | OS | Cache location |
129
+ |---|---|
130
+ | macOS / Linux | `rm -rf ~/.cache/opencode/packages/@te_river+opencode-team-mode@latest` |
131
+ | Windows | `Remove-Item -Recurse -Force "$env:LOCALAPPDATA\opencode\cache\packages\@te_river+opencode-team-mode@latest"` |
132
+
133
+ If you also npm-installed the plugin into `~/.config/opencode`, its package-lock pins the version — run `npm install @te-river/opencode-team-mode@latest` there too. Full recipe (including an agent-driven update prompt): [installation guide, Updating](./docs/installation.md).
134
+ - **Prerequisites:** [OpenCode](https://opencode.ai) (Desktop or CLI) and Node ≥ 18.
135
+
136
+ ### Verify
137
+
138
+ Restart, open the agent picker, and look for **team, architect, implementer,
139
+ reviewer, tester, researcher**. That's it — the team is hired.
140
+
141
+ ---
142
+
143
+ ## 📖 Usage
144
+
145
+ ### Slash commands
146
+
147
+ | Command | Agent | Description |
148
+ |---|---|---|
149
+ | `/team-plan <task>` | Architect | Implementation plan with architecture, file manifest, task breakdown |
150
+ | `/team-implement <task>` | Implementer | Production code for a feature or task |
151
+ | `/team-review [scope]` | Reviewer | Audit for bugs, security issues, quality problems |
152
+ | `/team-test [scope]` | Tester | Comprehensive tests with edge-case coverage |
153
+ | `/team-research <topic>` | Researcher | Local repo first; web via the governed tools |
154
+ | `/team-run <task>` | Team Lead | **The full workflow** — plan → approval → orchestration → verification |
155
+
156
+ Or `@`-mention agents directly: `@team`, `@architect`, `@implementer`,
157
+ `@reviewer`, `@tester`, `@researcher`.
158
+
159
+ ### What a run feels like
160
+
161
+ Team is the default agent out of the box, so you just type into a fresh chat:
162
+
163
+ > **You:** Add token-bucket rate limiting to our Express API — 100 requests per minute per user, return 429 when exceeded. Don't touch anything under `src/legacy/`.
164
+
165
+ ```text
166
+ team Route: product behavior change → implementer → tester → reviewer
167
+ (3 dispatches → approval gate applies)
168
+
169
+ PLAN
170
+ Goal: token-bucket limiter, 100 req/min/user, 429 + Retry-After
171
+ Scope: src/middleware/rateLimit.ts (new), src/app.ts (+3 lines)
172
+ Pipeline: implementer → tester → reviewer (correctness)
173
+ Assumption: in-memory bucket, not Redis — say the word to change
174
+ Boundary: src/legacy/** untouched
175
+ Approve to proceed?
176
+
177
+ you approved, go
178
+
179
+ team ▸ @implementer — STATUS: done
180
+ CHANGES: src/middleware/rateLimit.ts (new) · src/app.ts (+3)
181
+ EVIDENCE: tsc clean
182
+
183
+ ▸ @tester — STATUS: done · VERDICT: pass (14/14)
184
+ FINDINGS: burst edge, window expiry, concurrent refill covered;
185
+ src/legacy/** byte-identical
186
+
187
+ ▸ @reviewer — STATUS: done · VERDICT: approve (correctness)
188
+
189
+ team Done. rateLimit.ts (new) · app.ts (+3) · 14 tests green
190
+ review: approve · assumption: in-memory only · src/legacy/ untouched
191
+ ```
192
+
193
+ You typed the task and four words. The plan was a routing-table lookup,
194
+ execution waited for your approval, and every handoff between agents traveled
195
+ as a structured skeleton — nothing landed in your repo, nothing was guessed.
196
+
197
+ ---
198
+
199
+ ## 🧰 Governed tools & security
200
+
201
+ Every tool TeamMode adds runs under ONE governance pipeline: outputs above
202
+ `TM_OFFLOAD_THRESHOLD` tokens never enter the context window — they are
203
+ offloaded to a run store and replaced by a content-aware preview plus an
204
+ HMAC-signed handle that the agent pages through with `tm_fetch` when it
205
+ genuinely needs the payload.
206
+
207
+ | Tool | What it does | Roles |
208
+ |---|---|---|
209
+ | `tm_read` / `tm_grep` / `tm_bash` / `tm_fetch` | Governed file read / regex search / read-only shell (allowlist) / paged handle retrieval | all six agents |
210
+ | `tm_memory` | Project + global memory store (Markdown + frontmatter): add / search / list / forget | all six agents |
211
+ | `tm_ptc_run` | Batch orchestration: one program, N governed calls, zero LLM round-trips | all six agents |
212
+ | `tm_search` | Multi-engine web search with extracted, deduplicated hit lists | Lead + Researcher |
213
+ | `tm_webfetch` | Single governed GET of an allowlisted page (search pages auto-extracted) | Lead + Researcher |
214
+ | `tm_browser` | Interactive browser session (headful CDP): open / navigate / read / screenshot / close | Lead + Researcher + Tester (UI verification) |
215
+
216
+ > **Fixed tool priority ladder (every task): ① TeamMode governed tools
217
+ > (`tm_*`) → ② user MCP/plugin tools → ③ the model's own reasoning.**
218
+ > It doubles as the fallback chain: when a governed tool errors (no browser
219
+ > on this host, blocked host), the agent says so and drops to the next rung.
220
+
221
+ All governed tools are **parallel-safe**: the host may run a batch of
222
+ `tm_search` / `tm_webfetch` / `tm_fetch` calls concurrently — each call gets
223
+ its own step id and its own payload, and nothing cross-contaminates
224
+ (proven by the parallel test suite).
225
+
226
+ ### Context governance: offload, handles, previews
227
+
228
+ Large tool outputs are context cost's main driver — every step re-sends the
229
+ whole window. So results above `TM_OFFLOAD_THRESHOLD` tokens are written to a
230
+ local run store (`<repo>/.git/opencode-team/`, never your working tree) and
231
+ replaced by a handle with a content-aware preview: JSON keys / CSV header +
232
+ shape / log ERROR×N stats / code signatures / binary metadata, hard-capped at
233
+ 80 tokens. When the agent actually needs the payload, it pages through with
234
+ `tm_fetch` using an HMAC-signed, run-scoped, expiring handle. `tm_bash` only
235
+ allows read-only commands (allowlist), and failures come back as structured
236
+ errors instead of raw dumps.
237
+
238
+ ### Project + global memory (tm_memory)
239
+
240
+ Durable facts — build commands, environment quirks, architecture decisions,
241
+ your conventions — live as human-editable Markdown with frontmatter:
242
+
243
+ - **`project`** (default): `<repo>/.git/opencode-team/memories/…` — per checkout, git-adjacent.
244
+ - **`global`**: `~/.opencode-team/memories/global/` (override `TM_MEMORY_GLOBAL_DIR`) — **follows you across ALL projects**.
245
+
246
+ Actions: `add` / `search` (deterministic keyword scoring) / `list` / `forget`;
247
+ 4000 chars per memory. Agents are prompted to search before assuming
248
+ conventions and to save hard-won facts for the next conversation.
249
+
250
+ ### 🌐 Web search that actually works (in China)
251
+
252
+ `tm_search` is the open-ended-lookup front: **one call, one query, clean
253
+ results**. The engine URL is built for you, fetched through the governed
254
+ pipeline, and collapsed into a numbered title+URL hit list — the agent never
255
+ sees raw SERP chrome.
256
+
257
+ | Engine | Notes |
258
+ |---|---|
259
+ | `bing` (default) | cn.bing.com; `bing-int` forces international results (`ensearch=1`) |
260
+ | `sogou` / `so` (360) | CN-native engines, good for CJK content |
261
+ | `baidu` | flakiest (anti-bot) but sometimes the only CN-specific index; failures name alternatives |
262
+ | `bilibili` | video search |
263
+ | `moegirl` | MediaWiki search API — entry titles + snippets, structured |
264
+ | `npm` | registry search → name@version + description, structured |
265
+ | `github` | repo search API → stars + description, structured |
266
+
267
+ All nine engines are reachable from mainland China **without API keys**, and
268
+ every one of them sits on the seeded domain allowlist. On an empty result
269
+ (an anti-bot shell), the error names the alternative engines instead of
270
+ leaving the agent stuck. Two more channels complete the surface:
271
+
272
+ - `tm_webfetch` — a known URL, one governed GET. Search-engine pages it
273
+ fetches are auto-extracted to hit lists too. JSON endpoints like
274
+ `registry.npmjs.org/<pkg>/latest` pass through untouched.
275
+ - `tm_browser` — JS-rendered pages: your own Chromium-family browser, headful
276
+ via CDP pipe, isolated temp profile, **domain allowlist enforced at the
277
+ network layer** per request (`Fetch.requestPaused` → non-allowlisted hosts
278
+ get `BlockedByClient`).
279
+
280
+ Seeded allowlist (both tools): `mobile.moegirl.org.cn`, `search.bilibili.com`,
281
+ `cn.bing.com`, `www.bing.com`, `www.baidu.com`, `www.sogou.com`, `www.so.com`,
282
+ `registry.npmjs.org`, `api.github.com` — extend via
283
+ `TM_WEBFETCH_ALLOWED_DOMAINS` (`"*"` opens every host). Architect /
284
+ implementer / reviewer have NO network grant — web questions come back as a
285
+ reported gap, never simulated. The tester carries `tm_browser` ONLY, for
286
+ governed UI verification of the project (local dev servers, preview routes);
287
+ open web fetching stays with the two network roles.
288
+
289
+ ### Security: the R6 + R2 approval gate
290
+
291
+ **R6 environment protection.** With TeamMode active, the model cannot read
292
+ environment variables silently. Env reads (`printenv`, `env`, `Get-ChildItem
293
+ env:`, …) and env files (`.env`, shell rc) route through OpenCode's official
294
+ confirmation dialog; unanswered prompts are **auto-rejected after
295
+ `TM_ASK_TIMEOUT_MIN` (default 10 min)**. Env reads no wildcard can express
296
+ (embedded `$VAR` / `${VAR}` / `$env:` inside another command, command
297
+ substitution) and the `tm_*` wrapper channel stay a **hard block** — no dialog
298
+ to slip through. The audit log records only tool name + pattern category +
299
+ verdict — never command text, paths, variable names or values.
300
+
301
+ **R2 dangerous operations (same dialog).** Delete, git publish, network
302
+ fetch, package install/publish, process/system, privilege changes — none are
303
+ silently allowed. The normal verification stack (`npm test`, `tsc`,
304
+ `git status`) is NOT gated, so day-to-day work runs uninterrupted.
305
+
306
+ > ⚠️ **When you approve a dialog, pick "once" — not "always".** Verified on
307
+ > the live host, "always" records a far broader rule than the command you
308
+ > saw: approving `Get-ChildItem env:PATH` with "always" stores `Get-ChildItem
309
+ > *`, so every later `Get-ChildItem` runs with no dialog at all.
310
+
311
+ > Deferral to the dialog is per-session: env reads only route to the dialog
312
+ > in sessions running TeamMode's injected agents. In any other session the
313
+ > guard keeps hard-blocking env reads. `headless opencode run` auto-rejects
314
+ > unanswered `ask`s immediately (there is no human to prompt).
315
+
316
+ ### Repo hygiene
317
+
318
+ The offload/trajectory/memory stores live under `<repo>/.git/opencode-team/`
319
+ (or the OS temp dir outside a git repo) — **never your working tree**. Every
320
+ agent is instructed to delete scratch files before reporting done and to keep
321
+ throwaway work in the OS temp dir. A TTL sweeper reclaims old task dirs at
322
+ startup + hourly; the Team Lead never deletes boards itself, so you can audit
323
+ any run.
324
+
325
+ ---
326
+
327
+ ## ⚙️ Configuration
328
+
329
+ The plugin injects everything at startup — no agent files to copy.
330
+
331
+ > **Model choice matters.** Every judgment — triage, decomposition, dispatch
332
+ > briefs, synthesis, review verdicts — flows through the Team Lead. A weak
333
+ > model in that seat degrades the whole pipeline no matter how strong the
334
+ > specialists are. Pin your best reasoning model to `team`:
335
+
336
+ ```jsonc
337
+ {
338
+ "agent": {
339
+ "team": { "model": "anthropic/claude-opus-4-5" }, // Lead earns your best model
340
+ "implementer": { "model": "anthropic/claude-sonnet-4-6" } // specialists tolerate cheaper
341
+ }
342
+ }
343
+ ```
344
+
345
+ **Global install** — put the plugin entry in `~/.config/opencode/opencode.jsonc` and every project gets the team.
346
+
347
+ **Keep Team off the default slot:**
348
+
349
+ ```jsonc
350
+ {
351
+ "plugin": [
352
+ ["@te-river/opencode-team-mode@latest", { "defaultAgent": false }]
353
+ ]
354
+ }
355
+ ```
356
+
357
+ Your own agents named `team` / `architect` / … always take precedence; the
358
+ plugin never clobbers user definitions. See [Customization](#-customization)
359
+ for overrides, extra agents and disabling roles.
360
+
361
+ ### Environment variables
362
+
363
+ | Env var | Default | Purpose |
364
+ |---|---|---|
365
+ | `TM_ENV_PROTECT` | `strict` | R6 mode: `strict` / `standard` / `off` (off also disarms the approval timer) |
366
+ | `TM_ASK_TIMEOUT_MIN` | `10` | minutes before an unanswered dialog is auto-rejected (hard floor 3 — the host's reply event reaches the plugin ~120 s late) |
367
+ | `TM_ENV_PROTECT_EXTRA_DENY` | — | extra block patterns (regex; always hard block, never dialog-governed) |
368
+ | `TM_OFFLOAD_THRESHOLD` | `2000` | offload threshold (tokens, CJK-aware estimate) |
369
+ | `TM_PREVIEW_MAX_TOKENS` | `80` | preview hard cap |
370
+ | `TM_FETCH_MAX_LINES` | `2000` | tm_fetch page cap |
371
+ | `TM_BLACKBOARD_DIR` / `TM_TRAJECTORY_DIR` | `<repo>/.git/opencode-team/…` | offload store / trajectory ledger (tmpdir fallback; explicit = absolute or project-relative) |
372
+ | `TM_BLACKBOARD_TTL` | `7` | store retention (days) |
373
+ | `TM_BASH_READONLY_ALLOWED` | built-in table | tm_bash allowlist |
374
+ | `TM_WEBFETCH_ALLOWED_DOMAINS` | the nine seeded hosts | tm_webfetch / tm_search / tm_browser allowlist (`"*"` opens all; empty = deny all) |
375
+ | `TM_BROWSER_PATH` | auto-detect | tm_browser executable override (Edge/Chrome/Chromium per OS) |
376
+ | `TM_BROWSER_HEADLESS` | `auto` | `1` headless (CI) / `0` headful / `auto` (headless only on display-less Linux) |
377
+ | `TM_MEMORY_GLOBAL_DIR` | `~/.opencode-team/memories/global/` | tm_memory GLOBAL scope store |
378
+ | `TM_PTC_MAX_PROGRAM_CHARS` | `4000` | PTC program source cap |
379
+ | `TM_PTC_MAX_CALLS` | `20` | PTC per-run bridge-call budget (1–200) |
380
+ | `TM_PTC_MAX_ERRORS` | `3` | PTC per-run error budget (1–50) |
381
+ | `TM_PTC_TIMEOUT_MS` | `60000` | PTC per-run wall-clock timeout (5s–10min) |
382
+ | `TM_PTC_ENGINE` | `auto` | `auto` (worker→inline degrade) / `worker` / `inline` |
383
+
384
+ ---
385
+
386
+ ## 🏗️ How the team works
387
+
388
+ Sub-agents can't message each other live (platform limitation), so TeamMode
389
+ coordinates them through a **structured reply skeleton** — every specialist
390
+ reply is `STATUS: / CHANGES: / FINDINGS: / EVIDENCE: / HANDOFF:`, ≤50 lines,
391
+ relayed verbatim by the Lead into the next dispatch. Files are the exception,
392
+ not the rule: a deliverable over ~50 lines goes to ONE named board file under
393
+ `<repo>/.git/opencode-team/` (round-suffixed, working tree untouched).
394
+
395
+ - **Routing table:** question → direct answer; docs-only → implementer;
396
+ product change → implementer → tester → reviewer; multi-module →
397
+ architect → implementer → tester → reviewer(s); unknown tech → researcher
398
+ first. Fixed minimums — a product change routed below 3 dispatches is a
399
+ routing bug.
400
+ - **Approval gate (count-based):** ≥2 dispatches → plan (≤30 lines) → **your
401
+ approval** → execute. Blocking questions are batched and asked immediately.
402
+ - **Adaptive review:** one reviewer by default; three parallel dimensions
403
+ only for high-risk profiles (auth/security, cross-module contracts, public APIs).
404
+ - **Static verification:** build / typecheck / lint / tests. Improvised
405
+ browser automation is banned; unverified UI work ends with
406
+ `UI NOT VERIFIED: <what to check>`.
407
+ - **Evidence standard:** "done / fixed / passed" claims need verifiable
408
+ evidence — output, logs, diffs.
409
+
410
+ ---
411
+
412
+ ## 🔧 Customization
413
+
414
+ **Override an agent** — same name in your config wins:
415
+
416
+ ```jsonc
417
+ {
418
+ "agent": {
419
+ "reviewer": {
420
+ "model": "anthropic/claude-sonnet-4-6",
421
+ "prompt": "You are an extremely strict reviewer. Reject anything with a lint warning."
422
+ }
423
+ }
424
+ }
425
+ ```
426
+
427
+ **Add your own agents** alongside the team:
428
+
429
+ ```jsonc
430
+ {
431
+ "agent": {
432
+ "devops": {
433
+ "mode": "subagent",
434
+ "description": "Handles CI/CD, Docker, and deployment tasks.",
435
+ "prompt": "You are the DevOps engineer..."
436
+ }
437
+ }
438
+ }
439
+ ```
440
+
441
+ **Disable one:** `"researcher": { "disable": true }`.
442
+
443
+ **Board retention** via the tuple form: `["@te-river/opencode-team-mode@latest", { "ttlDays": 7 }]` (valid range (0, 365], invalid values fall back to 5).
444
+
445
+ ---
446
+
447
+ ## ❓ FAQ
448
+
449
+ **Will this eat my tokens?**
450
+ The opposite is the point. Offload + 80-token previews + PTC batch programs
451
+ exist because a five-agent pipeline naively bolted onto one context window
452
+ *would* eat your tokens. The governance is the token-saver.
453
+
454
+ **Is the web access safe?**
455
+ It's the most guarded surface in the plugin: two full web roles plus a
456
+ browser-only tester grant, domain
457
+ allowlist, redirects re-checked per hop, network-layer enforcement in the
458
+ browser, env-file URL refusal, and every payload rides the same offload
459
+ governance. No allowlisted page can bounce the fetch off-site.
460
+
461
+ **Why doesn't the plugin auto-update?**
462
+ OpenCode caches plugins by spec string and never re-resolves `@latest`
463
+ (upstream limitation, not ours). **Re-run the installer — that IS the
464
+ update** (it purges the cache and re-resolves npm copies); or delete the
465
+ cache dir by hand. Recipe above and in the
466
+ [installation guide](./docs/installation.md).
467
+
468
+ **Can agents run tools in parallel?**
469
+ Yes — and they're *engineered* for it: parallel `tm_search` / `tm_webfetch` /
470
+ `tm_fetch` calls get distinct step ids and isolated payloads. A regression
471
+ here fails the test suite before it ever reaches you.
472
+
473
+ **Does it work in the CLI (TUI), or only Desktop?**
474
+ Both. Desktop adds the color-coded picker and panels; the governed tools and
475
+ the whole workflow are host-agnostic. On display-less Linux, `tm_browser`
476
+ runs headless automatically.
477
+
478
+ **What happens if I don't answer a confirmation dialog?**
479
+ It auto-rejects after `TM_ASK_TIMEOUT_MIN` (default 10). The plugin never
480
+ self-approves — the only side it can take is yours or nobody's.
481
+
482
+ ---
483
+
484
+ ## 🗑️ Uninstall
485
+
486
+ 1. Remove the entry from the `"plugin"` array in your config file.
487
+ 2. Delete the cache dir (table in [Install](#-read-this-once-save-yourself-an-hour-later)) if you want the disk space back.
488
+ 3. Restart OpenCode. The agents, commands and tools are gone; the stores under `<repo>/.git/opencode-team/` (and `~/.opencode-team/` for global memories) are plain files you can delete whenever.
489
+
490
+ No DLLs were harmed. Nothing was written to your working tree.
491
+
492
+ ---
493
+
494
+ ## 🏛️ Architecture (for the curious)
495
+
496
+ ```
497
+ opencode-team-mode/
498
+ ├── src/
499
+ │ ├── index.ts ← Plugin entry (config + R6 guard + approval gate + tool segment)
500
+ │ ├── agents.ts ← Agent structure (modes, colors, temperatures, whitelist matrix)
501
+ │ ├── prompts/ ← Agent prompts (lead / specialists / shared) — pinned by tests
502
+ │ ├── commands.ts ← Slash command definitions
503
+ │ ├── blackboard.ts ← Shared blackboard + TTL sweeper
504
+ │ ├── envprotect.ts ← R6 facade (patterns / classifiers / gate predicates / hook)
505
+ │ ├── approval-gate.ts ← Unified approval gate (dialog timeout auto-reject)
506
+ │ ├── tm/ ← Governed tools: pipelines / store / preview / guard / refs /
507
+ │ │ webfetch / search / memory / browser / shell-bridge / ptc/ (9 modules)
508
+ │ └── types.ts ← Loader-contract types (1.18.x)
509
+ ├── docs/installation.md ← The agent-consumable install guide
510
+ ├── scripts/ ← One-line installers (bash / PowerShell)
511
+ ├── pt07/ ← PT-07 baseline suite (seeded A/B token measurement)
512
+ └── README.*.md ← You are here (twice)
513
+ ```
514
+
515
+ The loader calls `server(input, options)` once: the `config` hook injects the
516
+ six agents and six commands, the same call installs the R6
517
+ `tool.execute.before` guard, arms the approval gate through an `event` hook,
518
+ and registers the `tm_*` tools. User-defined agents with the same name always
519
+ win — the plugin never clobbers.
520
+
521
+ ---
522
+
523
+ ## 🤝 Contributing
524
+
525
+ Issues and PRs welcome. Especially wanted: localization of agent prompts,
526
+ more agent roles, more command templates, and real-world reports of the
527
+ search engines' behavior (they rearrange their markup; the extractor filters
528
+ are intentionally loose but not psychic).
529
+
530
+ ---
531
+
532
+ ## 📄 License
533
+
534
+ [Apache License 2.0](./LICENSE)
535
+
536
+ ---
537
+
538
+ ## 🔗 Links
539
+
540
+ - [npm Package](https://www.npmjs.com/package/@te-river/opencode-team-mode) — `@te-river/opencode-team-mode`
541
+ - [Installation guide](./docs/installation.md) — the complete manual / agent-consumable procedure
542
+ - [OpenCode Desktop](https://opencode.ai) — Official website & download
543
+ - [OpenCode Docs](https://opencode.ai/docs) — Configuration & plugin documentation
544
+ - [OpenCode Plugin API](https://opencode.ai/docs/plugins) — Build your own plugins