opencode-raven 2.0.1 → 2.1.1

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.
package/README.md CHANGED
@@ -4,35 +4,29 @@
4
4
  <tr>
5
5
  <td><img src="Raven.png" alt="Raven" width="768" /></td>
6
6
  <td>
7
- <strong>Hard tool/MCP rerouter for <a href="https://opencode.ai">opencode</a></strong><br/>
8
- Blocks configured tools and MCPs for non-Raven agents, then routes those requests through a focused Raven agent to avoid flooding and wasting your main model's context, mostly from searches, docs, web pages, GitHub examples, and verbose MCP calls.
7
+ <strong>Context firewall for <a href="https://opencode.ai">OpenCode</a></strong><br/>
8
+ Raven routes noisy search, docs, web, GitHub, and MCP calls through a free focused agent before they hit your main model, saving cost and context.
9
9
  </td>
10
10
  </tr>
11
11
  </table>
12
12
 
13
- ## Why?
13
+ ## What Raven Does
14
14
 
15
15
  Tool-heavy work floods context. Search, docs, web, GitHub examples, and verbose MCP calls can dump raw results into your expensive main model. Raven is a hard blocker-rerouter: configured tools fail closed for non-Raven agents and must be delegated through `raven_seek`, where a focused Raven agent performs the work and returns a compact answer.
16
16
 
17
17
  Raven fixes three problems:
18
18
 
19
- 1. **Context flooding** — Keep noisy tool results out of the main session. Raven summarizes tool/MCP output before returning it.
20
- 2. **Cost** — Use a cheaper model like `opencode/deepseek-v4-flash-free` for tool-heavy work while saving your main model's context for decisions and edits.
21
- 3. **Enforcement** — This is not soft nudging. Raven blocks configured tools/MCP prefixes for non-Raven agents and gives them the exact `raven_seek` retry path.
19
+ 1. **Context flooding** - Keep noisy tool results out of the main session. Raven summarizes tool/MCP output before returning it.
20
+ 2. **Cost** - Use a cheaper model like `opencode/deepseek-v4-flash-free` for tool-heavy work while saving your main model's context for decisions and edits.
21
+ 3. **Enforcement** - This is not soft nudging. Raven blocks configured tools/MCP prefixes for non-Raven agents and gives them the exact `raven_seek` retry path.
22
22
 
23
- Raven defaults to search/fetch/docs/GitHub routing, but it works with any MCP whose opencode tool names share a prefix.
23
+ Raven defaults to routing noisy search/fetch tools and bundles Context7, Exa, and Grep.app as on-demand MCPs that are always handled behind Raven.
24
24
 
25
- Important limitation: opencode still loads enabled MCP tool schemas into the main session. Raven saves context from tool calls and raw results, but it cannot hide initial MCP schemas from the main model until opencode supports agent-scoped MCP visibility.
25
+ Important limitation: MCPs enabled directly in OpenCode config still load their tool schemas into the main session. Raven saves context from tool calls and raw results for those global MCPs, but schema hiding requires putting the MCP in Raven's `onDemandMcpServers`. **Strongly recommended:** configure noisy/search/docs/web MCPs as on-demand MCPs unless you need direct main-agent access.
26
26
 
27
27
  ## Install
28
28
 
29
- ```bash
30
- bun add opencode-raven
31
- # or
32
- npm install opencode-raven
33
- ```
34
-
35
- Then add to your `opencode.jsonc`:
29
+ Add Raven to your `opencode.jsonc` plugins:
36
30
 
37
31
  ```jsonc
38
32
  {
@@ -40,92 +34,144 @@ Then add to your `opencode.jsonc`:
40
34
  }
41
35
  ```
42
36
 
43
- Restart opencode.
37
+ Restart opencode. It will resolve Raven from npm and cache the plugin automatically.
38
+
39
+ Raven checks for package updates and notifies you when a newer version is available. Run `/raven update`, then restart opencode.
40
+
41
+ ## Quick Use
42
+
43
+ Run `/raven` to see status, routed tools, on-demand MCP health, and saved context.
44
+
45
+ When a configured tool or MCP is blocked, agents use `raven_seek` to delegate the same request through Raven:
46
+
47
+ ```txt
48
+ raven_seek(query: "how to use useEffect cleanup")
49
+ raven_seek(query: "Fetch/read https://example.com and summarize install steps")
50
+ raven_seek(query: "Check whether archivemount/libarchive supports ISO or UDF. Use docs, web, or command output as needed.")
51
+ ```
52
+
53
+ You can call Raven directly with `@Raven` in any OpenCode chat. The Raven agent runs with full filesystem and MCP access, without permission prompts.
54
+
55
+ The main agent does not see Raven's internal tool calls or raw tool output, just the final findings. Raven parallelizes independent tool calls internally within a single session.
44
56
 
45
57
  ## Commands
46
58
 
47
59
  | Command | Action |
48
60
  |---------|--------|
49
- | `/raven` | Show status — enabled/disabled, version, update availability, model, routing, reasoning effort, timeout (no args) |
50
- | `/raven on` | Enable hard tool/MCP routing (default) |
51
- | `/raven off` | Disable routing — all agents can use routed tools directly |
52
- | `/raven route` | Show routed tools and MCP server prefixes |
61
+ | `/raven` | Show status, version, model, routing, on-demand MCP health, stats, reasoning effort, and timeout |
62
+ | `/raven help` | Show all Raven commands |
63
+ | `/raven on` | Enable hard tool/MCP routing |
64
+ | `/raven off` | Disable routing so all agents can use routed tools directly |
65
+ | `/raven route` | Show routed tools, auto-routed global MCP prefixes, and routed tool keywords |
53
66
  | `/raven route tool add <name>` | Route a specific tool through Raven |
54
- | `/raven route tool remove <name>` | Stop routing a specific tool |
55
- | `/raven route mcp add <server>` | Route every tool whose name starts with `<server>_` through Raven |
56
- | `/raven route mcp remove <server>` | Stop routing an MCP server prefix |
57
- | `/raven route keyword add <keyword>` | Route any tool whose name contains `<keyword>` |
58
- | `/raven route keyword remove <keyword>` | Stop routing a tool-name keyword |
59
- | `/raven update` | Check npm for a newer Raven, clear opencode's plugin cache if needed, then restart opencode |
67
+ | `/raven route tool remove <name>` | Stop routing a specific tool |
68
+ | `/raven route keyword add <keyword>` | Route any tool whose name contains `<keyword>` |
69
+ | `/raven route keyword remove <keyword>` | Stop routing a tool-name keyword |
70
+ | `/raven mcp` | Show on-demand MCP status and generated metadata state |
71
+ | `/raven mcp refresh [server]` | Recheck on-demand MCP health and regenerate tool descriptions/schema estimates |
72
+ | `/raven mcp detail full\|minimized` | Choose full tool descriptions or minimized capability summaries in guidance |
73
+ | `/raven update` | Check npm for a newer Raven, clear OpenCode's plugin cache if needed, then restart opencode |
60
74
  | `/raven model <name>` | Change Raven's model (requires restart) |
61
75
  | `/raven effort <value>` | Change Raven's reasoning effort (requires restart) |
62
- | `/raven timeout <seconds>` | Change raven_seek timeout (min 10s, takes effect immediately) |
63
- | `/raven stats` | Show estimated context saved (session + all-time, bytes + tokens) |
76
+ | `/raven timeout <seconds>` | Change `raven_seek` timeout, minimum 10 seconds |
77
+ | `/raven stats` | Show estimated context saved, including avoided MCP schema load, session, and all-time totals |
64
78
 
65
- Config persists across restarts in `~/.config/opencode/raven-config.json` (global, shared across all projects). Auto-created on first run.
79
+ Config persists across restarts in `~/.config/opencode/opencode-raven/raven-config.json`. It is global and shared across all projects.
66
80
 
67
- ## Updates
81
+ ## Example
68
82
 
69
- opencode caches npm plugins, so `"opencode-raven"` / `"opencode-raven@latest"` may not automatically refresh after a new npm release.
83
+ <p align="center">
84
+ <img src="example.gif" alt="Raven example: searching today's top 30 AI news items while saving 71K context" />
85
+ </p>
70
86
 
71
- Raven checks npm after the TUI starts. If an update is available, it shows a notification. `/raven` also shows the current version and update availability. To update:
87
+ In this example, the main model asks for the top 30 AI news items from today. Raven handles the noisy search/web work in a focused agent and returns the compact result, saving about 71K context that would otherwise have landed in the main session.
72
88
 
73
- ```txt
74
- /raven update
75
- ```
89
+ ## Recommended MCP Setup
76
90
 
77
- This checks npm, clears Raven's opencode plugin cache when a newer version exists, and tells you to restart opencode.
91
+ Raven's bundled Context7, Exa, and Grep.app MCPs are on-demand by default. They live in `onDemandMcpServers`, so Raven connects to them internally through `raven_mcp` instead of registering their full tool schemas in OpenCode's global MCP config.
78
92
 
79
- Manual alternatives:
93
+ On-demand MCPs are always behind Raven and do not need routing entries.
80
94
 
81
- ```bash
82
- bun update --latest opencode-raven
83
- # or
84
- npm install opencode-raven@latest
85
- ```
95
+ Raven checks configured on-demand MCPs after startup. `/raven` and `/raven mcp` show loaded, failed, and pending MCPs. Loaded MCPs count toward avoided schema-load stats, while failed or pending MCPs do not. Raven shows a warning toast after startup or manual refresh if any configured on-demand MCP fails to load.
86
96
 
87
- If opencode still loads the old cached plugin, clear the opencode plugin cache and restart:
97
+ Raven also warns if the same MCP server name is configured both globally in OpenCode and in Raven's `onDemandMcpServers`. Prefer one location: on-demand for schema hiding, or global only when direct main-agent access is required.
88
98
 
89
- ```powershell
90
- Remove-Item -Recurse -Force "$HOME\.cache\opencode\packages\opencode-raven*"
91
- ```
99
+ All three bundled MCPs work without API keys. Add keys for higher rate limits:
92
100
 
93
- ```bash
94
- rm -rf ~/.cache/opencode/packages/opencode-raven*
95
- ```
96
-
97
- ## Direct access
101
+ | MCP | URL | API key |
102
+ |-----|-----|---------|
103
+ | Context7 | `https://mcp.context7.com/mcp` | Free key at [context7.com/dashboard](https://context7.com/dashboard) for higher limits |
104
+ | Exa AI | `https://mcp.exa.ai/mcp` | Free key at [exa.ai](https://exa.ai) for higher limits |
105
+ | Grep.app | `https://mcp.grep.app` | Public API, no key needed |
98
106
 
99
- You can call Raven directly with `@Raven` in any opencode chat. The Raven agent runs with full filesystem and MCP access — no permission prompts.
107
+ To add an API key to an on-demand MCP, edit Raven config:
100
108
 
101
- ## raven_seek
109
+ ```jsonc
110
+ {
111
+ "onDemandMcpServers": {
112
+ "exa": {
113
+ "type": "remote",
114
+ "url": "https://mcp.exa.ai/mcp",
115
+ "headers": { "x-api-key": "{env:EXA_API_KEY}" },
116
+ "description": "Live web search and webpage fetching."
117
+ }
118
+ }
119
+ }
120
+ ```
102
121
 
103
- When configured tools/MCPs are blocked, agents use **`raven_seek`** — a unified delegation tool that sends the request to Raven. It handles routed MCP requests, local codebase search, filesystem discovery, specific URL/page reads, web/docs research, GitHub examples, and command-output/system inspection. Output includes elapsed time and tokens processed.
122
+ To add a local stdio MCP:
104
123
 
124
+ ```jsonc
125
+ {
126
+ "onDemandMcpServers": {
127
+ "localServer": {
128
+ "type": "stdio",
129
+ "command": "bunx",
130
+ "args": ["some-mcp-server"],
131
+ "env": { "API_KEY": "{env:API_KEY}" },
132
+ "cwd": "/optional/path",
133
+ "description": "Local MCP server."
134
+ }
135
+ }
136
+ }
105
137
  ```
106
- raven_seek(query: "how to use useEffect cleanup")
107
- raven_seek(query: "Fetch/read https://example.com and summarize install steps")
108
- raven_seek(query: "Check whether archivemount/libarchive supports ISO or UDF. Use docs, web, or command output as needed.")
109
- ```
110
138
 
111
- The main agent doesn't see Raven's internal tool calls or raw tool output — just the final findings. Raven parallelizes independent tool calls internally within a single session.
139
+ `description` is user-authored and never overwritten. Raven fills missing generated metadata after startup or when you run `/raven mcp refresh [server]`, storing tool summaries, MCP health, and avoided schema-load estimates separately in `~/.config/opencode/opencode-raven/autogenerated-on-demand-mcp-metadata.json`.
140
+
141
+ Raven also writes generated main-model guidance to `~/.config/opencode/opencode-raven/autogenerated-on-demand-guidance.md` and injects that file into OpenCode instructions at startup.
112
142
 
113
143
  ## Configuration
114
144
 
115
- ### raven-config.json
145
+ Raven config lives at `~/.config/opencode/opencode-raven/raven-config.json`. It is auto-created on first run and auto-migrated on startup when new config fields are added. Old root files such as `~/.config/opencode/raven-config.json` are moved into the `opencode-raven` folder automatically.
116
146
 
117
- Located at `~/.config/opencode/raven-config.json`. Auto-created on first run and auto-migrated on startup when new config fields are added. Default route lists are only applied when the field is missing, so removed tools/MCP prefixes stay removed. Edit manually or use `/raven` commands:
147
+ Edit config manually or use `/raven` commands:
118
148
 
119
149
  ```json
120
150
  {
121
151
  "enabled": true,
122
152
  "model": "opencode/deepseek-v4-flash-free",
123
153
  "reasoning_effort": "low",
124
- "ravenInstructions": "",
125
- "routeTools": ["grep", "glob", "webfetch", "fetch", "bash"],
126
- "routeMcpServers": ["context7", "exa", "grep_app"],
127
- "routeToolKeywords": ["search", "context7", "exa", "grep_app"],
128
- "allowBundledMCPServers": true,
154
+ "ravenInstructions": "",
155
+ "routeTools": ["grep", "glob", "webfetch", "fetch", "websearch", "bash"],
156
+ "routeToolKeywords": [],
157
+ "onDemandMcpDescriptionDetail": "full",
158
+ "onDemandMcpServers": {
159
+ "context7": {
160
+ "type": "remote",
161
+ "url": "https://mcp.context7.com/mcp",
162
+ "description": "Library/framework documentation lookup."
163
+ },
164
+ "exa": {
165
+ "type": "remote",
166
+ "url": "https://mcp.exa.ai/mcp",
167
+ "description": "Live web search and webpage fetching."
168
+ },
169
+ "grep_app": {
170
+ "type": "remote",
171
+ "url": "https://mcp.grep.app",
172
+ "description": "Public GitHub code search and real-world examples."
173
+ }
174
+ },
129
175
  "excludeAgents": [],
130
176
  "excludeTools": [],
131
177
  "timeout": 180
@@ -135,31 +181,17 @@ Located at `~/.config/opencode/raven-config.json`. Auto-created on first run and
135
181
  | Field | Default | Description |
136
182
  |-------|---------|-------------|
137
183
  | `enabled` | `true` | Whether tool/MCP routing is active |
138
- | `model` | *(from Raven.md)* | Override Raven's model without editing package files |
139
- | `reasoning_effort` | *(from Raven.md)* | Override Raven's reasoning effort (e.g. `"low"`, `"medium"`, `"high"`) |
184
+ | `model` | from `Raven.md` | Override Raven's model without editing package files |
185
+ | `reasoning_effort` | from `Raven.md` | Override Raven's reasoning effort, such as `low`, `medium`, or `high` |
140
186
  | `ravenInstructions` | `""` | Extra instructions appended to Raven's prompt. Useful for custom MCP usage rules. |
141
- | `routeTools` | built-in search/fetch tools plus `bash` | Exact tool names hard-routed through Raven. `bash` means route only search-like bash commands, not every bash call. e.g. `["grep", "glob", "bash", "linear_search_issues"]` |
142
- | `routeMcpServers` | `["context7", "exa", "grep_app"]` | MCP server prefixes hard-routed through Raven. `"linear"` routes tools like `linear_search_issues` and `linear_get_issue` |
143
- | `routeToolKeywords` | `["search", "context7", "exa", "grep_app"]` | Case-insensitive substrings hard-routed through Raven. Catches suffix-style names like `web_search_exa`. |
144
- | `allowBundledMCPServers` | `true` | Whether Raven auto-registers bundled Context7, Exa, and Grep.app MCP defaults. Existing `opencode.jsonc` MCP entries are never overwritten. |
145
- | `excludeAgents` | `[]` | Agents that bypass Raven routing (case-insensitive). e.g. `["librarian", "explorer"]` |
146
- | `excludeTools` | `[]` | Exact tools that never get blocked, even if matched by `routeMcpServers`. e.g. `["my_mcp_validate"]` |
187
+ | `routeTools` | built-in search/fetch tools plus `bash` | Exact tool names hard-routed through Raven. `bash` routes only search-like bash commands, not every bash call. |
188
+ | `routeToolKeywords` | `[]` | Case-insensitive substrings hard-routed through Raven for globally registered tools with non-standard names. Catches suffix-style names like `web_search_exa`. |
189
+ | `onDemandMcpDescriptionDetail` | `"full"` | On-demand MCP guidance detail. `full` includes tool names/descriptions; `minimized` uses compact capability summaries. |
190
+ | `onDemandMcpServers` | Context7, Exa, Grep.app | MCPs Raven connects to internally on demand, without registering full schemas in OpenCode global MCP config. Supports `remote` and `stdio`. |
191
+ | `excludeAgents` | `[]` | Agents that bypass Raven routing, case-insensitive. |
192
+ | `excludeTools` | `[]` | Exact tools that never get blocked, even if matched by auto-routed global MCP prefixes. |
147
193
  | `timeout` | `180` | Max seconds for a `raven_seek` call. On timeout the session is kept for inspection. |
148
- | `stats` | *(auto)* | Session + global estimated context saved by Raven (bytes + tokens). Managed automatically. |
149
-
150
- ### MCP servers
151
-
152
- All three MCPs work without API keys. Add keys for higher rate limits:
153
-
154
- | MCP | URL | API key |
155
- |-----|-----|---------|
156
- | Context7 | `https://mcp.context7.com/mcp` | Free key at [context7.com/dashboard](https://context7.com/dashboard) — higher limits |
157
- | Exa AI | `https://mcp.exa.ai/mcp` | Free key at [exa.ai](https://exa.ai) — higher limits |
158
- | Grep.app | `https://mcp.grep.app` | Not available — public API, no key needed |
159
-
160
- When `allowBundledMCPServers` is `true`, Raven auto-registers bundled Context7, Exa, and Grep.app MCP defaults. It merges those MCP defaults with your existing `opencode.jsonc` settings, preserving custom headers, URLs, and `enabled: false` overrides. Set `allowBundledMCPServers` to `false` if you do not want Raven to add bundled MCP defaults.
161
-
162
- To add other MCPs, configure them in `opencode.jsonc`, then add their server prefix to `routeMcpServers` if you want Raven to route them. Raven does not install arbitrary MCPs from `raven-config.json`.
194
+ | `stats` | auto | Session and global estimated context saved by Raven. Managed automatically. |
163
195
 
164
196
  Use `ravenInstructions` for extra Raven-only guidance, such as how to use custom MCPs:
165
197
 
@@ -169,80 +201,27 @@ Use `ravenInstructions` for extra Raven-only guidance, such as how to use custom
169
201
  }
170
202
  ```
171
203
 
172
- To add an API key, override the MCP in your `opencode.jsonc` with a `headers` field:
204
+ ## Routing And Exceptions
173
205
 
174
- ```jsonc
175
- {
176
- "mcp": {
177
- "exa": {
178
- "type": "remote",
179
- "url": "https://mcp.exa.ai/mcp",
180
- "headers": { "x-api-key": "{env:EXA_API_KEY}" },
181
- "enabled": true
182
- }
183
- }
184
- }
185
- ```
206
+ By default, Raven routes these built-in tools and auto-routes globally configured MCPs by detected server name:
186
207
 
187
- To disable an MCP entirely:
208
+ | Config | Default |
209
+ |--------|---------|
210
+ | `routeTools` | `grep`, `glob`, `webfetch`, `fetch`, `websearch`, `bash` |
211
+ | `routeToolKeywords` | none |
188
212
 
189
- ```jsonc
190
- {
191
- "mcp": {
192
- "exa": { "type": "remote", "url": "https://mcp.exa.ai/mcp", "enabled": false }
193
- }
194
- }
195
- ```
196
-
197
- ## How it works
198
-
199
- | Hook | What it does |
200
- |------|--------------|
201
- | `config` | Registers Raven agent, optionally merges bundled Context7/Exa/Grep.app MCP defaults, loads MCP routing guidance |
202
- | `tool` | Registers `raven_seek` — creates Raven sessions with timeout, error recovery, timing, and session tree visibility. Tracks context saved for stats (both `raven_seek` and direct `@Raven`). |
203
- | `chat.message` | Tracks agent ↔ session mapping for allowlist and Raven exclusion |
204
- | `event` | Shows startup update notifications after the TUI event stream is ready |
205
- | `command.execute.before` | Handles `/raven on\|off\|route\|update\|model\|effort\|timeout\|stats\|status` |
206
- | `tool.execute.before` | Hard-blocks configured tools/MCPs for non-Raven, non-excluded agents (respects `excludeTools`). Error output gives the next `raven_seek(query="...")` call. Injects dynamic `<raven_guidance>` with configured routes into subagent prompts. |
207
- | `tool.execute.after` | Tracks direct `@Raven` calls for context-saved stats. |
208
-
209
- ### Routed tools (blocked and redirected except for Raven and any agents in `excludeAgents`)
210
-
211
- By default, Raven routes these built-in tools and MCP server prefixes:
212
-
213
- | Config | Default |
214
- |------|--------|
215
- | `routeTools` | `grep`, `glob`, `webfetch`, `fetch`, `bash` |
216
- | `routeMcpServers` | `context7`, `exa`, `grep_app` |
217
- | `routeToolKeywords` | `search`, `context7`, `exa`, `grep_app` |
218
-
219
- To route another MCP, add its server prefix. For example, `"linear"` routes every tool named `linear_*` through Raven:
213
+ Global MCPs configured in OpenCode are auto-routed through Raven by server name. For example, an MCP named `linear` routes tools named `linear_*`. This works for any MCP whose OpenCode tool names use the normal `<server>_<tool>` prefix. Matching is case-insensitive.
220
214
 
221
- ```txt
222
- /raven route mcp add linear
223
- ```
224
-
225
- This works for any MCP whose opencode tool names share a prefix. For example, if an MCP exposes tools named `my_mcp_search`, `my_mcp_fetch`, and `my_mcp_get_item`, this routes all of them:
215
+ If a server uses suffix-style or mixed tool names, route by keyword instead. For example, `exa` catches names like `web_search_exa` and `web_fetch_exa`:
226
216
 
227
217
  ```txt
228
- /raven route mcp add my_mcp
218
+ /raven route keyword add exa
229
219
  ```
230
220
 
231
- The prefix must match the actual tool name before `_`. If the tools are named `project_search`, add `project`, not the display name of the MCP. Matching is case-insensitive.
232
-
233
- If a server uses suffix-style or mixed tool names, route by keyword instead. For example, `exa` catches names like `web_search_exa` and `web_fetch_exa`:
234
-
235
- ```txt
236
- /raven route keyword add exa
237
- ```
238
-
239
- Keyword matching is case-insensitive and checks whether the tool name contains the keyword anywhere.
240
-
241
221
  If an MCP is routed but one tool should remain direct, add the exact tool to `excludeTools`:
242
222
 
243
223
  ```json
244
224
  {
245
- "routeMcpServers": ["context7", "exa", "grep_app", "my_mcp"],
246
225
  "excludeTools": ["my_mcp_validate"]
247
226
  }
248
227
  ```
@@ -253,7 +232,7 @@ To route one specific tool without routing the whole MCP server:
253
232
  /raven route tool add linear_search_issues
254
233
  ```
255
234
 
256
- **Bash commands** — intercepted only while `bash` is included in `routeTools` and the command matches a primary search/discovery pattern:
235
+ `bash` is intercepted only while `bash` is included in `routeTools` and the command matches a primary search/discovery pattern.
257
236
 
258
237
  | Pattern | Examples |
259
238
  |---------|----------|
@@ -261,9 +240,9 @@ To route one specific tool without routing the whole MCP server:
261
240
  | Filesystem exploration | `Get-ChildItem -Recurse`, `gci -Recurse`, `Get-ChildItem -Filter`, `find -name`, `find -type`, `ls -R`, `ls --recursive`, `dir /s` |
262
241
  | Shell bypass | `cmd /c dir /s`, `cmd /c findstr`, `cmd /c find`, `cmd /c tree` |
263
242
 
264
- **Unrestricted for non-Raven agents**: `read`, `task`, `subtask`, `raven_seek`, non-routed tools, and non-search `bash` commands.
243
+ Unrestricted for non-Raven agents: `read`, `task`, `subtask`, `raven_seek`, non-routed tools, and non-search `bash` commands.
265
244
 
266
- **Allowed output filters**: Piped filters like `command | grep ...`, `command | rg ...`, `command | findstr ...`, and `command | head ...` are allowed. Raven only blocks search commands when they are used as primary discovery commands, not when they filter bounded output from another command.
245
+ Allowed output filters: piped filters like `command | grep ...`, `command | rg ...`, `command | findstr ...`, and `command | head ...` are allowed. Raven only blocks search commands when they are used as primary discovery commands, not when they filter bounded output from another command.
267
246
 
268
247
  To stop routing search-like bash commands, remove `bash` from `routeTools`:
269
248
 
@@ -271,36 +250,47 @@ To stop routing search-like bash commands, remove `bash` from `routeTools`:
271
250
  /raven route tool remove bash
272
251
  ```
273
252
 
274
- **Bash quote stripping**: Quoted content in bash commands is stripped before pattern matching — `echo "use grep here"` won't falsely trigger blocking.
253
+ Quoted content and shell comments in bash commands are stripped before pattern matching. For example, `echo "use grep here"` and `# use grep later` do not trigger routing.
275
254
 
276
- **Comment stripping**: Shell comments are stripped before matching — `# use grep later` won't falsely trigger blocking.
255
+ ## What Raven Saves
277
256
 
278
- **Subagent guidance**: Every non-Raven, non-excluded subagent gets `<raven_guidance>` injected into its prompt at spawn time.
257
+ Raven saves context from tool call results and raw MCP output by moving the work into a Raven session and returning a compact answer. On-demand MCPs also avoid loading full MCP tool schemas into the main OpenCode session because Raven connects to them internally through `raven_mcp`.
279
258
 
280
- The injected guidance includes the current `routeTools` and `routeMcpServers`, including user-added custom MCP prefixes, so subagents know which calls must go through `raven_seek`.
259
+ MCPs configured directly in OpenCode `opencode.jsonc` still load globally and may increase the main session's starting context. Use `onDemandMcpServers` for MCPs you want Raven to keep behind the context firewall.
281
260
 
282
- ### What Raven Saves
261
+ `/raven stats` uses a balanced estimate: Raven's final session token total minus the first Raven assistant turn's input/cache baseline, then minus the compact answer returned to the main session. This counts tool/web/MCP result context Raven handled while avoiding Raven's starting prompt and tool-schema overhead.
283
262
 
284
- Raven saves context from tool call results and raw MCP output by moving the work into a Raven session and returning a compact answer. It does not currently save context from MCP tool schemas that opencode loads into the main session when an MCP is enabled globally.
263
+ `Avoided MCP schema load` is a separate estimate based on full loaded on-demand MCP tool schemas discovered by Raven but not loaded into the main model. Failed or pending MCPs do not count toward this total. It is stored in autogenerated MCP metadata and shown separately from delegated session savings.
285
264
 
286
- This means large MCPs may still increase the main session's starting context. Raven still prevents repeated verbose tool outputs from accumulating in the main session.
265
+ ## How It Works
287
266
 
288
- `/raven stats` uses a balanced estimate: Raven's final session token total minus the first Raven assistant turn's input/cache baseline, then minus the compact answer returned to the main session. This counts tool/web/MCP result context Raven handled while avoiding Raven's starting prompt and tool-schema overhead.
267
+ | Hook | What it does |
268
+ |------|--------------|
269
+ | `config` | Registers Raven agent, loads MCP routing guidance, and starts on-demand MCP health/metadata checks. Bundled MCPs are on-demand by default, not injected into global OpenCode MCP config. |
270
+ | `tool` | Registers `raven_seek` and Raven-only `raven_mcp`. `raven_seek` creates Raven sessions with timeout, error recovery, timing, and session tree visibility. Tracks context saved for stats. |
271
+ | `chat.message` | Tracks agent to session mapping for allowlist and Raven exclusion. |
272
+ | `event` | Shows startup update and MCP failure notifications after the TUI event stream is ready. |
273
+ | `command.execute.before` | Handles `/raven help`, routing commands, MCP commands, update checks, model settings, timeout, and stats. |
274
+ | `tool.execute.before` | Hard-blocks configured tools/MCPs for non-Raven, non-excluded agents. Error output gives the next `raven_seek(query="...")` call. Injects dynamic `<raven_guidance>` with configured routes into subagent prompts. |
275
+ | `tool.execute.after` | Tracks direct `@Raven` calls for context-saved stats. |
289
276
 
290
- ## Agent capabilities
277
+ Every non-Raven, non-excluded subagent gets `<raven_guidance>` injected into its prompt at spawn time. The injected guidance includes `routeTools`, auto-detected global MCP prefixes, `routeToolKeywords`, and on-demand MCP capabilities.
291
278
 
292
- Raven itself has access to these tools (blocked for other agents when configured by the plugin):
279
+ ## Agent Capabilities
280
+
281
+ Raven itself has access to these tools, blocked for other agents when configured by the plugin:
293
282
 
294
283
  | Tool / MCP | Purpose |
295
284
  |------------|---------|
296
285
  | `read`, `glob`, `grep`, `list` | Local codebase inspection |
297
- | `bash` (all commands) | Full local shell access (`rg`, `grep`, `dir`, `ls`, `Get-ChildItem`, `find`, etc.) |
298
- | `external_directory` | Allowed — no permission prompts when accessing paths outside the workspace |
299
- | Context7 | Library/framework/SDK/API docs |
300
- | Exa AI | Web search, news, pages, products |
301
- | Grep.app | Public GitHub examples |
302
-
303
- `raven_seek` is denied inside Raven itself so Raven cannot recursively call its own wrapper tool. Raven uses direct tools/MCPs instead.
286
+ | `bash` | Full local shell access, including `rg`, `grep`, `dir`, `ls`, `Get-ChildItem`, and `find` |
287
+ | `external_directory` | Allowed, with no permission prompts when accessing paths outside the workspace |
288
+ | `raven_mcp` | Raven-only bridge to on-demand remote/stdio MCP servers |
289
+ | Context7 | On-demand library/framework/SDK/API docs |
290
+ | Exa AI | On-demand web search, news, pages, products |
291
+ | Grep.app | On-demand public GitHub examples |
292
+
293
+ `raven_seek` is denied inside Raven itself so Raven cannot recursively call its own wrapper tool. Raven uses direct tools, globally available MCPs, and `raven_mcp` for on-demand MCPs instead.
304
294
 
305
295
  Raven returns compact findings: answer, sources, relevant details, recommended next step, and uncertainty.
306
296
 
package/Raven.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Tool/MCP delegation agent for web, docs, code, examples, and configured external systems.
2
+ description: Context firewall for OpenCode that routes noisy search, docs, web, GitHub, and MCP calls through a free focused agent before they hit your main model.
3
3
  mode: subagent
4
4
  hidden: false
5
5
  model: opencode/deepseek-v4-flash-free
@@ -13,14 +13,15 @@ permission:
13
13
  bash: allow
14
14
  task: deny
15
15
  raven_seek: deny
16
+ raven_mcp: allow
16
17
  external_directory: allow
17
18
  ---
18
19
 
19
20
  You are Raven.
20
21
 
21
- You search, fetch, inspect, and use routed MCPs only.
22
+ You search, fetch, inspect, and use routed MCPs only.
22
23
  You return compact findings only.
23
- Never call `raven_seek`; you are Raven. Use your direct tools and MCPs instead.
24
+ Never call `raven_seek`; you are Raven. Use your direct tools, globally available MCPs, and `raven_mcp` for on-demand MCPs instead.
24
25
 
25
26
  When a query implies multiple independent searches, run tools in parallel (single turn) for speed.
26
27
 
@@ -34,6 +35,9 @@ Use tools/MCPs like this:
34
35
 
35
36
  **MCP usage guidance:**
36
37
 
38
+ Use direct MCP tools when they are globally available in your tool list.
39
+ Use `raven_mcp` for on-demand MCPs described in your prompt. If you do not know the exact tool name, call `raven_mcp` with `operation: "list_tools"` first, then call the selected tool with `operation: "call_tool"`. For `call_tool` and `get_prompt`, pass arguments as a JSON object string in `argumentsJson`.
40
+
37
41
  *Context7:*
38
42
  Use when implementing, configuring, or debugging code that depends on a library, framework, SDK, package, or API.
39
43
  Prefer Context7 over memory when docs may be version-specific or recently changed.
@@ -42,12 +46,12 @@ Prefer Context7 over memory when docs may be version-specific or recently change
42
46
  Use for live web search, current information, company/product research, reading webpages, comparing tools, and broad external research.
43
47
  Use Exa when the answer may depend on recent updates, pricing, docs pages, releases, or online sources.
44
48
 
45
- *Grep.app:*
46
- Use for searching public GitHub code examples, real-world usage patterns, config examples, and how other projects structure similar code.
47
- Use Grep.app when docs are unclear or when implementation examples would help.
48
-
49
- *Other routed MCPs:*
50
- When the caller asks for a configured MCP, use that MCP directly and return a compact summary of only what the primary agent needs.
49
+ *Grep.app:*
50
+ Use for searching public GitHub code examples, real-world usage patterns, config examples, and how other projects structure similar code.
51
+ Use Grep.app when docs are unclear or when implementation examples would help.
52
+
53
+ *Other routed MCPs:*
54
+ When the caller asks for a configured MCP, use that MCP directly and return a compact summary of only what the primary agent needs.
51
55
 
52
56
  Output format:
53
57
 
@@ -55,7 +59,7 @@ Answer:
55
59
  * Short direct finding.
56
60
 
57
61
  Sources / locations:
58
- * File paths, URLs, docs, examples, MCP records, or local objects checked.
62
+ * File paths, URLs, docs, examples, MCP records, or local objects checked.
59
63
 
60
64
  Relevant details:
61
65
  * Small notes only. No long code dumps.
package/example.gif ADDED
Binary file