@openviking/opencode-plugin 0.1.5 → 0.2.0
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/INSTALL-ZH.md +50 -49
- package/INSTALL.md +50 -49
- package/README.md +40 -123
- package/index.mjs +20 -12
- package/lib/config.mjs +272 -0
- package/lib/mcp-config.mjs +21 -0
- package/lib/memory-recall.mjs +21 -172
- package/lib/memory-session.mjs +301 -478
- package/lib/repo-context.mjs +5 -5
- package/lib/session-inject.mjs +71 -0
- package/lib/shared/capture-utils.mjs +500 -0
- package/lib/shared/credentials.mjs +207 -0
- package/lib/shared/debug-log.mjs +58 -0
- package/lib/shared/mcp-proxy-core.mjs +451 -0
- package/lib/shared/pending-queue.mjs +439 -0
- package/lib/shared/profile-inject.mjs +294 -0
- package/lib/shared/recall-core.mjs +282 -0
- package/lib/shared/session-model.mjs +57 -0
- package/lib/shared/setup-wizard.mjs +111 -0
- package/lib/shared/uri-guard.mjs +56 -0
- package/lib/utils.mjs +33 -116
- package/lib/viking-uri-guard.mjs +9 -24
- package/package.json +13 -8
- package/scripts/setup.mjs +8 -0
- package/servers/mcp-proxy.mjs +67 -0
- package/servers/mcp-proxy.test.mjs +100 -0
- package/lib/code-tools.mjs +0 -134
- package/lib/memadd-local.mjs +0 -118
- package/lib/memory-tools.mjs +0 -410
package/INSTALL-ZH.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
这个插件新增了一个面向 OpenCode 的统一 OpenViking 插件:
|
|
4
4
|
|
|
5
|
-
-
|
|
5
|
+
- 面向 memory、resources 和 code context 的 OpenViking MCP 工具
|
|
6
6
|
- 长期记忆、session 同步、生命周期边界 commit、自动 recall
|
|
7
7
|
|
|
8
|
-
这是仓库中唯一继续维护的 OpenCode 插件示例。这个插件不再安装 `skills/openviking/SKILL.md`,也不要求 agent 使用 `ov`
|
|
8
|
+
这是仓库中唯一继续维护的 OpenCode 插件示例。这个插件不再安装 `skills/openviking/SKILL.md`,也不要求 agent 使用 `ov` 命令。模型工具由 Claude Code 和 Codex 记忆插件同款的 stdio MCP proxy 提供。
|
|
9
9
|
|
|
10
10
|
## 前置条件
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
- OpenCode
|
|
15
15
|
- OpenViking HTTP Server
|
|
16
|
-
- Node.js
|
|
16
|
+
- Node.js 18+
|
|
17
17
|
- 如果服务端启用了认证,需要可用的 OpenViking API Key
|
|
18
18
|
|
|
19
19
|
建议先启动 OpenViking:
|
|
@@ -53,8 +53,7 @@ mkdir -p ~/.config/opencode/plugins/openviking
|
|
|
53
53
|
cp examples/opencode-plugin/wrappers/openviking.js ~/.config/opencode/plugins/openviking.js
|
|
54
54
|
cp examples/opencode-plugin/index.mjs examples/opencode-plugin/package.json ~/.config/opencode/plugins/openviking/
|
|
55
55
|
cp -r examples/opencode-plugin/lib ~/.config/opencode/plugins/openviking/
|
|
56
|
-
|
|
57
|
-
npm install
|
|
56
|
+
cp -r examples/opencode-plugin/servers ~/.config/opencode/plugins/openviking/
|
|
58
57
|
```
|
|
59
58
|
|
|
60
59
|
安装后结构应类似:
|
|
@@ -66,7 +65,7 @@ npm install
|
|
|
66
65
|
├── index.mjs
|
|
67
66
|
├── package.json
|
|
68
67
|
├── lib/
|
|
69
|
-
└──
|
|
68
|
+
└── servers/
|
|
70
69
|
```
|
|
71
70
|
|
|
72
71
|
顶层 `openviking.js` 只负责把 OpenCode 能发现的一级 `.js` 入口转发到插件目录:
|
|
@@ -92,22 +91,22 @@ export { OpenVikingPlugin, default } from "./openviking/index.mjs"
|
|
|
92
91
|
|
|
93
92
|
```json
|
|
94
93
|
{
|
|
95
|
-
"endpoint": "http://localhost:1933",
|
|
96
|
-
"apiKey": "",
|
|
97
|
-
"account": "",
|
|
98
|
-
"user": "",
|
|
99
|
-
"peerId": "",
|
|
100
94
|
"enabled": true,
|
|
101
95
|
"timeoutMs": 30000,
|
|
102
96
|
"repoContext": { "enabled": true, "cacheTtlMs": 60000 },
|
|
103
97
|
"autoRecall": {
|
|
104
98
|
"enabled": true,
|
|
105
99
|
"limit": 6,
|
|
106
|
-
"scoreThreshold": 0.
|
|
100
|
+
"scoreThreshold": 0.35,
|
|
107
101
|
"maxContentChars": 500,
|
|
108
102
|
"preferAbstract": true,
|
|
109
|
-
"tokenBudget": 2000
|
|
110
|
-
|
|
103
|
+
"tokenBudget": 2000,
|
|
104
|
+
"minQueryLength": 3
|
|
105
|
+
},
|
|
106
|
+
"commitTokenThreshold": 20000,
|
|
107
|
+
"commitKeepRecentCount": 10,
|
|
108
|
+
"profileTokenBudget": 10000,
|
|
109
|
+
"resumeContextBudget": 32000
|
|
111
110
|
}
|
|
112
111
|
```
|
|
113
112
|
|
|
@@ -117,7 +116,7 @@ export { OpenVikingPlugin, default } from "./openviking/index.mjs"
|
|
|
117
116
|
export OPENVIKING_API_KEY="your-api-key-here"
|
|
118
117
|
```
|
|
119
118
|
|
|
120
|
-
`
|
|
119
|
+
API key 会从环境变量或 `~/.openviking/ovcli.conf` 读取,并由 hooks 和 MCP proxy 作为 `Authorization: Bearer ...` 发送。`account` 和 `user` 是 trusted mode
|
|
121
120
|
身份头,会作为 `X-OpenViking-Account`、`X-OpenViking-User` 发送;使用
|
|
122
121
|
user/admin API key 的 API_KEY mode 时应留空。
|
|
123
122
|
`peerId` 会作为 `X-OpenViking-Actor-Peer` 用于数据面的 memory/resource 请求;捕获 session message 时仍写入 body `peer_id`。需要 peer 维度路由时请显式配置。
|
|
@@ -132,13 +131,13 @@ user/admin API key 的 API_KEY mode 时应留空。
|
|
|
132
131
|
|
|
133
132
|
修改插件或 OpenViking 配置后,需要重启 OpenCode。
|
|
134
133
|
|
|
135
|
-
进入新的 OpenCode session 后,可以让 agent 浏览 OpenViking memory
|
|
134
|
+
进入新的 OpenCode session 后,可以让 agent 浏览 OpenViking memory,或搜索一个已索引的资源。插件应暴露 OpenViking MCP server,OpenCode 中的工具名会带 `openviking_` 前缀:
|
|
136
135
|
|
|
137
|
-
- `
|
|
138
|
-
- `
|
|
139
|
-
- `
|
|
140
|
-
- `
|
|
141
|
-
- `
|
|
136
|
+
- `openviking_recall`、`openviking_search`、`openviking_find`
|
|
137
|
+
- `openviking_read`、`openviking_list`、`openviking_grep`、`openviking_glob`
|
|
138
|
+
- `openviking_remember`、`openviking_add_resource`、`openviking_forget`、`openviking_health`
|
|
139
|
+
- `openviking_list_watches`、`openviking_cancel_watch`
|
|
140
|
+
- `openviking_code_search`、`openviking_code_outline`、`openviking_code_expand`
|
|
142
141
|
|
|
143
142
|
如果行为异常,先查看运行时文件:
|
|
144
143
|
|
|
@@ -153,35 +152,37 @@ tail -n 100 ~/.config/opencode/openviking/openviking-memory.log
|
|
|
153
152
|
curl http://localhost:1933/health
|
|
154
153
|
```
|
|
155
154
|
|
|
156
|
-
##
|
|
155
|
+
## 可用 MCP 工具
|
|
157
156
|
|
|
158
|
-
插件会通过 OpenCode `
|
|
157
|
+
插件会通过 OpenCode config 注册 OpenViking stdio MCP proxy。服务端实际返回的 `tools/list` 是最终工具清单;当前 OpenViking server 暴露:
|
|
159
158
|
|
|
160
|
-
- `
|
|
161
|
-
- `
|
|
162
|
-
- `
|
|
163
|
-
- `
|
|
164
|
-
- `
|
|
165
|
-
- `
|
|
166
|
-
- `
|
|
167
|
-
- `
|
|
168
|
-
- `
|
|
169
|
-
- `
|
|
159
|
+
- `openviking_recall`:面向当前任务的平衡召回
|
|
160
|
+
- `openviking_search`:跨 memories/resources/skills 的深度语义检索
|
|
161
|
+
- `openviking_find`:快速语义检索
|
|
162
|
+
- `openviking_remember`:存储重要事实或决策,供记忆提取
|
|
163
|
+
- `openviking_read`:读取一个或多个 `viking://` 文件
|
|
164
|
+
- `openviking_list`:列出 `viking://` 目录
|
|
165
|
+
- `openviking_grep`:精确文本或正则搜索
|
|
166
|
+
- `openviking_glob`:glob 文件匹配
|
|
167
|
+
- `openviking_add_resource`:添加 URL、本地文件、sitemap 或 feed
|
|
168
|
+
- `openviking_forget`:在用户明确确认后删除 `viking://` URI
|
|
169
|
+
- `openviking_list_watches` / `openviking_cancel_watch`:查看或取消资源 watch
|
|
170
|
+
- `openviking_code_search`、`openviking_code_outline`、`openviking_code_expand`:查看已索引代码符号
|
|
171
|
+
- `openviking_health`:检查 OpenViking server 健康状态
|
|
170
172
|
|
|
171
173
|
使用建议:
|
|
172
174
|
|
|
173
|
-
- 概念性问题用 `
|
|
174
|
-
- 精确符号、函数名、类名、报错字符串用 `
|
|
175
|
-
- 枚举文件用 `
|
|
176
|
-
- 读取内容用 `
|
|
177
|
-
- 探索目录结构用 `
|
|
178
|
-
-
|
|
179
|
-
-
|
|
180
|
-
- 如果 agent 误用 OpenCode 本地 `read`、`glob`、`grep` 工具访问 `viking://` URI,插件会阻止这次本地文件系统调用,并提示改用 `memread`、`membrowse` 或 `memsearch`。
|
|
175
|
+
- 概念性问题用 `openviking_search`
|
|
176
|
+
- 精确符号、函数名、类名、报错字符串用 `openviking_grep`
|
|
177
|
+
- 枚举文件用 `openviking_glob`
|
|
178
|
+
- 读取内容用 `openviking_read`
|
|
179
|
+
- 探索目录结构用 `openviking_list`
|
|
180
|
+
- 删除前必须先获得用户明确确认,再调用 `openviking_forget`
|
|
181
|
+
- 如果 agent 误用 OpenCode 本地 `read`、`glob`、`grep` 工具访问 `viking://` URI,插件会阻止这次本地文件系统调用,并提示改用 MCP 工具。
|
|
181
182
|
|
|
182
|
-
## `
|
|
183
|
+
## `openviking_add_resource` 本地文件
|
|
183
184
|
|
|
184
|
-
`
|
|
185
|
+
`openviking_add_resource` 支持三类输入:
|
|
185
186
|
|
|
186
187
|
- 远端 `http(s)` URL:直接调用 `/api/v1/resources`
|
|
187
188
|
- 本地文件路径:先调用 `/api/v1/resources/temp_upload`,再用返回的 `temp_file_id` 添加资源
|
|
@@ -190,9 +191,9 @@ curl http://localhost:1933/health
|
|
|
190
191
|
相对路径会按 OpenCode 当前项目目录解析。示例:
|
|
191
192
|
|
|
192
193
|
```text
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
openviking_add_resource(path="https://example.com/spec.md", to="viking://resources/spec")
|
|
195
|
+
openviking_add_resource(path="./docs/notes.md", to="viking://resources/notes.md")
|
|
196
|
+
openviking_add_resource(path="file:///home/alice/project/notes.md", description="project notes")
|
|
196
197
|
```
|
|
197
198
|
|
|
198
199
|
当前仍不支持本地目录自动打 zip 上传;传入目录时会返回明确错误。
|
|
@@ -208,7 +209,7 @@ memadd path="file:///home/alice/project/notes.md" reason="project notes"
|
|
|
208
209
|
可能包含:
|
|
209
210
|
|
|
210
211
|
- `openviking-memory.log`
|
|
211
|
-
- `openviking-session-
|
|
212
|
+
- `openviking-session-state.json`
|
|
212
213
|
|
|
213
214
|
可以通过配置里的 `runtime.dataDir` 修改这个目录。
|
|
214
215
|
|
|
@@ -219,7 +220,7 @@ memadd path="file:///home/alice/project/notes.md" reason="project notes"
|
|
|
219
220
|
| 问题 | 排查方向 |
|
|
220
221
|
|------|----------|
|
|
221
222
|
| 插件没有加载 | package 安装检查 `~/.config/opencode/opencode.json` 是否包含 `@openviking/opencode-plugin`;源码安装检查 `~/.config/opencode/plugins/openviking.js` 是否存在 |
|
|
222
|
-
|
|
|
223
|
+
| MCP tools 连到了错误的 server | 检查 `~/.openviking/ovcli.conf`,或用 `OPENVIKING_*` 环境变量 / `OPENVIKING_PLUGIN_CONFIG` 指向正确配置 |
|
|
223
224
|
| OpenViking 返回 401 / 403 | 检查 `OPENVIKING_API_KEY`;trusted-mode 部署还要检查 `OPENVIKING_ACCOUNT` 和 `OPENVIKING_USER` |
|
|
224
225
|
| recall 为空 | 确认 OpenViking 中已有 memories/resources,并且 `autoRecall.enabled` 为 `true` |
|
|
225
|
-
| 本地 `
|
|
226
|
+
| 本地 `openviking_add_resource` 失败 | 传入文件路径而不是目录;目前还不支持自动上传本地目录 |
|
package/INSTALL.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This plugin adds one unified OpenViking plugin for OpenCode:
|
|
4
4
|
|
|
5
|
-
-
|
|
5
|
+
- OpenViking MCP tools for memory, resources, and code context
|
|
6
6
|
- Long-term memory, session synchronization, lifecycle commit, and automatic recall
|
|
7
7
|
|
|
8
|
-
This is the only OpenCode plugin example maintained in this repository. It does not install `skills/openviking/SKILL.md`, and it does not require the agent to use the `ov` command.
|
|
8
|
+
This is the only OpenCode plugin example maintained in this repository. It does not install `skills/openviking/SKILL.md`, and it does not require the agent to use the `ov` command. Model tools are provided by the same stdio MCP proxy used by the Claude Code and Codex memory plugins.
|
|
9
9
|
|
|
10
10
|
## Prerequisites
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@ Prepare the following first:
|
|
|
13
13
|
|
|
14
14
|
- OpenCode
|
|
15
15
|
- OpenViking HTTP Server
|
|
16
|
-
- Node.js
|
|
16
|
+
- Node.js 18+
|
|
17
17
|
- A valid OpenViking API key if authentication is enabled on the server
|
|
18
18
|
|
|
19
19
|
Start OpenViking first:
|
|
@@ -53,8 +53,7 @@ mkdir -p ~/.config/opencode/plugins/openviking
|
|
|
53
53
|
cp examples/opencode-plugin/wrappers/openviking.js ~/.config/opencode/plugins/openviking.js
|
|
54
54
|
cp examples/opencode-plugin/index.mjs examples/opencode-plugin/package.json ~/.config/opencode/plugins/openviking/
|
|
55
55
|
cp -r examples/opencode-plugin/lib ~/.config/opencode/plugins/openviking/
|
|
56
|
-
|
|
57
|
-
npm install
|
|
56
|
+
cp -r examples/opencode-plugin/servers ~/.config/opencode/plugins/openviking/
|
|
58
57
|
```
|
|
59
58
|
|
|
60
59
|
After installation, the layout should look like this:
|
|
@@ -66,7 +65,7 @@ After installation, the layout should look like this:
|
|
|
66
65
|
├── index.mjs
|
|
67
66
|
├── package.json
|
|
68
67
|
├── lib/
|
|
69
|
-
└──
|
|
68
|
+
└── servers/
|
|
70
69
|
```
|
|
71
70
|
|
|
72
71
|
The top-level `openviking.js` forwards the first-level `.js` entry that OpenCode can discover to the actual plugin directory:
|
|
@@ -92,22 +91,22 @@ Example configuration:
|
|
|
92
91
|
|
|
93
92
|
```json
|
|
94
93
|
{
|
|
95
|
-
"endpoint": "http://localhost:1933",
|
|
96
|
-
"apiKey": "",
|
|
97
|
-
"account": "",
|
|
98
|
-
"user": "",
|
|
99
|
-
"peerId": "",
|
|
100
94
|
"enabled": true,
|
|
101
95
|
"timeoutMs": 30000,
|
|
102
96
|
"repoContext": { "enabled": true, "cacheTtlMs": 60000 },
|
|
103
97
|
"autoRecall": {
|
|
104
98
|
"enabled": true,
|
|
105
99
|
"limit": 6,
|
|
106
|
-
"scoreThreshold": 0.
|
|
100
|
+
"scoreThreshold": 0.35,
|
|
107
101
|
"maxContentChars": 500,
|
|
108
102
|
"preferAbstract": true,
|
|
109
|
-
"tokenBudget": 2000
|
|
110
|
-
|
|
103
|
+
"tokenBudget": 2000,
|
|
104
|
+
"minQueryLength": 3
|
|
105
|
+
},
|
|
106
|
+
"commitTokenThreshold": 20000,
|
|
107
|
+
"commitKeepRecentCount": 10,
|
|
108
|
+
"profileTokenBudget": 10000,
|
|
109
|
+
"resumeContextBudget": 32000
|
|
111
110
|
}
|
|
112
111
|
```
|
|
113
112
|
|
|
@@ -117,7 +116,7 @@ It is recommended to provide the API key through an environment variable instead
|
|
|
117
116
|
export OPENVIKING_API_KEY="your-api-key-here"
|
|
118
117
|
```
|
|
119
118
|
|
|
120
|
-
`
|
|
119
|
+
API keys are resolved from environment variables or `~/.openviking/ovcli.conf` and sent as `Authorization: Bearer ...` by both hooks and the MCP proxy. `account` and `user` are trusted-mode identity headers sent as `X-OpenViking-Account` and `X-OpenViking-User`; leave them empty when using API-key mode with user/admin API keys. `peerId` is sent as `X-OpenViking-Actor-Peer` on data-plane memory/resource requests; captured session messages store it as body `peer_id`.
|
|
121
120
|
|
|
122
121
|
`OPENVIKING_API_KEY`, `OPENVIKING_ACCOUNT`, `OPENVIKING_USER`, and `OPENVIKING_PEER_ID` take precedence over the corresponding values in `openviking-config.json`.
|
|
123
122
|
|
|
@@ -127,13 +126,13 @@ For advanced setups, use `OPENVIKING_PLUGIN_CONFIG` to point to another configur
|
|
|
127
126
|
|
|
128
127
|
Restart OpenCode after changing plugin or OpenViking configuration.
|
|
129
128
|
|
|
130
|
-
In a new OpenCode session, ask the agent to browse OpenViking memory or search for a known indexed resource. The plugin should expose
|
|
129
|
+
In a new OpenCode session, ask the agent to browse OpenViking memory or search for a known indexed resource. The plugin should expose the OpenViking MCP server, with tools namespaced by OpenCode as `openviking_*`:
|
|
131
130
|
|
|
132
|
-
- `
|
|
133
|
-
- `
|
|
134
|
-
- `
|
|
135
|
-
- `
|
|
136
|
-
- `
|
|
131
|
+
- `openviking_recall`, `openviking_search`, `openviking_find`
|
|
132
|
+
- `openviking_read`, `openviking_list`, `openviking_grep`, `openviking_glob`
|
|
133
|
+
- `openviking_remember`, `openviking_add_resource`, `openviking_forget`, `openviking_health`
|
|
134
|
+
- `openviking_list_watches`, `openviking_cancel_watch`
|
|
135
|
+
- `openviking_code_search`, `openviking_code_outline`, `openviking_code_expand`
|
|
137
136
|
|
|
138
137
|
If anything looks wrong, check the runtime files:
|
|
139
138
|
|
|
@@ -148,35 +147,37 @@ For a local server, also confirm OpenViking is reachable:
|
|
|
148
147
|
curl http://localhost:1933/health
|
|
149
148
|
```
|
|
150
149
|
|
|
151
|
-
## Available Tools
|
|
150
|
+
## Available MCP Tools
|
|
152
151
|
|
|
153
|
-
The plugin
|
|
152
|
+
The plugin registers OpenViking's stdio MCP proxy through OpenCode config. The server's real `tools/list` response is the source of truth; current OpenViking servers expose:
|
|
154
153
|
|
|
155
|
-
- `
|
|
156
|
-
- `
|
|
157
|
-
- `
|
|
158
|
-
- `
|
|
159
|
-
- `
|
|
160
|
-
- `
|
|
161
|
-
- `
|
|
162
|
-
- `
|
|
163
|
-
- `
|
|
164
|
-
- `
|
|
154
|
+
- `openviking_recall`: balanced current-task recall.
|
|
155
|
+
- `openviking_search`: deep semantic retrieval across memories, resources, and skills.
|
|
156
|
+
- `openviking_find`: fast semantic retrieval.
|
|
157
|
+
- `openviking_remember`: store important facts or decisions for memory extraction.
|
|
158
|
+
- `openviking_read`: read one or more `viking://` files.
|
|
159
|
+
- `openviking_list`: list a `viking://` directory.
|
|
160
|
+
- `openviking_grep`: exact text or regex search.
|
|
161
|
+
- `openviking_glob`: glob file matching.
|
|
162
|
+
- `openviking_add_resource`: add a URL, local file, sitemap, or feed.
|
|
163
|
+
- `openviking_forget`: delete a `viking://` URI after explicit user confirmation.
|
|
164
|
+
- `openviking_list_watches` / `openviking_cancel_watch`: inspect or cancel resource watches.
|
|
165
|
+
- `openviking_code_search`, `openviking_code_outline`, `openviking_code_expand`: inspect indexed code symbols.
|
|
166
|
+
- `openviking_health`: check OpenViking server health.
|
|
165
167
|
|
|
166
168
|
Usage guidance:
|
|
167
169
|
|
|
168
|
-
- Use `
|
|
169
|
-
- Use `
|
|
170
|
-
- Use `
|
|
171
|
-
- Use `
|
|
172
|
-
- Use `
|
|
173
|
-
-
|
|
174
|
-
-
|
|
175
|
-
- If an agent tries to use OpenCode's local `read`, `glob`, or `grep` tools on a `viking://` URI, the plugin blocks that call and points it to `memread`, `membrowse`, or `memsearch`.
|
|
170
|
+
- Use `openviking_search` for conceptual questions.
|
|
171
|
+
- Use `openviking_grep` for exact symbols, function names, class names, or error strings.
|
|
172
|
+
- Use `openviking_glob` to enumerate files.
|
|
173
|
+
- Use `openviking_read` to read content.
|
|
174
|
+
- Use `openviking_list` to explore directory structure.
|
|
175
|
+
- Before deleting anything, obtain explicit user confirmation first; then call `openviking_forget`.
|
|
176
|
+
- If an agent tries to use OpenCode's local `read`, `glob`, or `grep` tools on a `viking://` URI, the plugin blocks that call and points it to the MCP tools.
|
|
176
177
|
|
|
177
|
-
## Local Files with `
|
|
178
|
+
## Local Files with `openviking_add_resource`
|
|
178
179
|
|
|
179
|
-
`
|
|
180
|
+
`openviking_add_resource` supports three input types:
|
|
180
181
|
|
|
181
182
|
- Remote `http(s)` URL: directly calls `/api/v1/resources`
|
|
182
183
|
- Local file path: first calls `/api/v1/resources/temp_upload`, then adds the resource using the returned `temp_file_id`
|
|
@@ -185,9 +186,9 @@ Usage guidance:
|
|
|
185
186
|
Relative paths are resolved against the current OpenCode project directory. Examples:
|
|
186
187
|
|
|
187
188
|
```text
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
openviking_add_resource(path="https://example.com/spec.md", to="viking://resources/spec")
|
|
190
|
+
openviking_add_resource(path="./docs/notes.md", to="viking://resources/notes.md")
|
|
191
|
+
openviking_add_resource(path="file:///home/alice/project/notes.md", description="project notes")
|
|
191
192
|
```
|
|
192
193
|
|
|
193
194
|
Automatic zip upload for local directories is not supported yet. Passing a directory will return a clear error.
|
|
@@ -203,7 +204,7 @@ By default, the plugin writes runtime files to:
|
|
|
203
204
|
Possible files include:
|
|
204
205
|
|
|
205
206
|
- `openviking-memory.log`
|
|
206
|
-
- `openviking-session-
|
|
207
|
+
- `openviking-session-state.json`
|
|
207
208
|
|
|
208
209
|
You can change this directory with `runtime.dataDir` in the configuration.
|
|
209
210
|
|
|
@@ -214,7 +215,7 @@ These are local runtime files and should not be committed to the repository.
|
|
|
214
215
|
| Issue | What to check |
|
|
215
216
|
|-------|---------------|
|
|
216
217
|
| Plugin does not load | For package installs, confirm `~/.config/opencode/opencode.json` contains `@openviking/opencode-plugin`; for source installs, confirm `~/.config/opencode/plugins/openviking.js` exists |
|
|
217
|
-
|
|
|
218
|
+
| MCP tools call the wrong server | Check `~/.openviking/ovcli.conf`, or set `OPENVIKING_*` env vars / `OPENVIKING_PLUGIN_CONFIG` to the intended config path |
|
|
218
219
|
| 401 / 403 from OpenViking | Verify `OPENVIKING_API_KEY`; for trusted-mode deployments, also verify `OPENVIKING_ACCOUNT` and `OPENVIKING_USER` |
|
|
219
220
|
| Recall is empty | Confirm OpenViking has indexed memories/resources and `autoRecall.enabled` is `true` |
|
|
220
|
-
| Local `
|
|
221
|
+
| Local `openviking_add_resource` fails | Pass a file path, not a directory; local directories are not uploaded automatically yet |
|
package/README.md
CHANGED
|
@@ -4,17 +4,17 @@ A unified OpenCode plugin for OpenViking repository retrieval and long-term memo
|
|
|
4
4
|
|
|
5
5
|
This is the only OpenCode plugin example maintained in this repository. It supersedes the former split examples for indexed repository prompt injection and long-term memory.
|
|
6
6
|
|
|
7
|
-
The
|
|
7
|
+
The plugin uses OpenCode hooks for lifecycle behavior and registers OpenViking's standard stdio MCP proxy for model tools. It does not install or require an OpenCode skill, and agents do not need to run `ov` shell commands.
|
|
8
8
|
|
|
9
9
|
## What It Does
|
|
10
10
|
|
|
11
11
|
- Injects indexed `viking://resources/` repositories into the system prompt.
|
|
12
|
-
- Exposes
|
|
12
|
+
- Exposes the same OpenViking MCP tools used by the Claude Code and Codex memory plugins.
|
|
13
13
|
- Maps each OpenCode session to an OpenViking session.
|
|
14
14
|
- Captures user and assistant text messages into OpenViking.
|
|
15
15
|
- Commits sessions at lifecycle boundaries for memory extraction.
|
|
16
16
|
- Automatically recalls relevant memories and injects them as hidden synthetic context for the current user message.
|
|
17
|
-
- Blocks accidental local filesystem reads of `viking://` URIs and points the agent back to `
|
|
17
|
+
- Blocks accidental local filesystem reads of `viking://` URIs and points the agent back to `openviking_read`, `openviking_glob`, or `openviking_search`.
|
|
18
18
|
|
|
19
19
|
## Files
|
|
20
20
|
|
|
@@ -25,26 +25,29 @@ examples/opencode-plugin/
|
|
|
25
25
|
├── README.md
|
|
26
26
|
├── INSTALL-ZH.md
|
|
27
27
|
├── lib/
|
|
28
|
+
│ ├── config.mjs
|
|
29
|
+
│ ├── mcp-config.mjs
|
|
28
30
|
│ ├── runtime.mjs
|
|
29
31
|
│ ├── repo-context.mjs
|
|
30
32
|
│ ├── memory-session.mjs
|
|
31
|
-
│ ├── memadd-local.mjs
|
|
32
|
-
│ ├── memory-tools.mjs
|
|
33
33
|
│ ├── memory-recall.mjs
|
|
34
|
+
│ ├── session-inject.mjs
|
|
34
35
|
│ ├── viking-uri-guard.mjs
|
|
35
36
|
│ └── utils.mjs
|
|
37
|
+
├── servers/
|
|
38
|
+
│ └── mcp-proxy.mjs
|
|
36
39
|
├── tests/
|
|
37
40
|
└── wrappers/
|
|
38
41
|
└── openviking.js
|
|
39
42
|
```
|
|
40
43
|
|
|
41
|
-
There is intentionally no `skills/openviking/SKILL.md`. The
|
|
44
|
+
There is intentionally no `skills/openviking/SKILL.md`. The tool surface comes from OpenViking's MCP endpoint.
|
|
42
45
|
|
|
43
46
|
## Requirements
|
|
44
47
|
|
|
45
48
|
- OpenCode
|
|
46
49
|
- OpenViking HTTP server
|
|
47
|
-
- Node.js
|
|
50
|
+
- Node.js 18+
|
|
48
51
|
- An OpenViking API key if your server requires authentication
|
|
49
52
|
|
|
50
53
|
Start OpenViking first:
|
|
@@ -80,8 +83,7 @@ mkdir -p ~/.config/opencode/plugins/openviking
|
|
|
80
83
|
cp examples/opencode-plugin/wrappers/openviking.js ~/.config/opencode/plugins/openviking.js
|
|
81
84
|
cp examples/opencode-plugin/index.mjs examples/opencode-plugin/package.json ~/.config/opencode/plugins/openviking/
|
|
82
85
|
cp -r examples/opencode-plugin/lib ~/.config/opencode/plugins/openviking/
|
|
83
|
-
|
|
84
|
-
npm install
|
|
86
|
+
cp -r examples/opencode-plugin/servers ~/.config/opencode/plugins/openviking/
|
|
85
87
|
```
|
|
86
88
|
|
|
87
89
|
This creates a stable OpenCode plugin layout:
|
|
@@ -93,7 +95,7 @@ This creates a stable OpenCode plugin layout:
|
|
|
93
95
|
├── index.mjs
|
|
94
96
|
├── package.json
|
|
95
97
|
├── lib/
|
|
96
|
-
└──
|
|
98
|
+
└── servers/
|
|
97
99
|
```
|
|
98
100
|
|
|
99
101
|
The top-level `openviking.js` is only a wrapper:
|
|
@@ -111,26 +113,26 @@ Create `~/.config/opencode/openviking-config.json`:
|
|
|
111
113
|
|
|
112
114
|
```json
|
|
113
115
|
{
|
|
114
|
-
"endpoint": "http://localhost:1933",
|
|
115
|
-
"apiKey": "",
|
|
116
|
-
"account": "",
|
|
117
|
-
"user": "",
|
|
118
|
-
"peerId": "",
|
|
119
116
|
"enabled": true,
|
|
120
117
|
"timeoutMs": 30000,
|
|
121
118
|
"repoContext": { "enabled": true, "cacheTtlMs": 60000 },
|
|
122
119
|
"autoRecall": {
|
|
123
120
|
"enabled": true,
|
|
124
121
|
"limit": 6,
|
|
125
|
-
"scoreThreshold": 0.
|
|
122
|
+
"scoreThreshold": 0.35,
|
|
126
123
|
"maxContentChars": 500,
|
|
127
124
|
"preferAbstract": true,
|
|
128
|
-
"tokenBudget": 2000
|
|
129
|
-
|
|
125
|
+
"tokenBudget": 2000,
|
|
126
|
+
"minQueryLength": 3
|
|
127
|
+
},
|
|
128
|
+
"commitTokenThreshold": 20000,
|
|
129
|
+
"commitKeepRecentCount": 10,
|
|
130
|
+
"profileTokenBudget": 10000,
|
|
131
|
+
"resumeContextBudget": 32000
|
|
130
132
|
}
|
|
131
133
|
```
|
|
132
134
|
|
|
133
|
-
`
|
|
135
|
+
API keys are resolved from environment variables or `~/.openviking/ovcli.conf` and sent as `Authorization: Bearer ...` by both hooks and the MCP proxy. `account` and `user` are trusted-mode identity
|
|
134
136
|
headers sent as `X-OpenViking-Account` and `X-OpenViking-User`; leave them empty
|
|
135
137
|
when using API-key mode with user/admin API keys.
|
|
136
138
|
`peerId` is sent as `X-OpenViking-Actor-Peer` on data-plane memory/resource
|
|
@@ -138,124 +140,39 @@ requests; captured session messages store it as body `peer_id`. Configure
|
|
|
138
140
|
`peerId` explicitly when peer-scoped memory routing is needed.
|
|
139
141
|
|
|
140
142
|
`OPENVIKING_API_KEY`, `OPENVIKING_ACCOUNT`, `OPENVIKING_USER`,
|
|
141
|
-
and `OPENVIKING_PEER_ID` take
|
|
142
|
-
precedence over values in this file.
|
|
143
|
+
and `OPENVIKING_PEER_ID` take precedence over values in this file.
|
|
143
144
|
|
|
144
145
|
For advanced setups, `OPENVIKING_PLUGIN_CONFIG` can point to another config file path.
|
|
145
146
|
|
|
146
147
|
OpenCode's local `read`, `glob`, and `grep` tools cannot read `viking://` URIs.
|
|
147
148
|
When the agent accidentally tries that, the plugin blocks the filesystem tool
|
|
148
|
-
call and points it to
|
|
149
|
+
call and points it to the OpenViking MCP tools.
|
|
149
150
|
|
|
150
|
-
## Tools
|
|
151
|
+
## MCP Tools
|
|
151
152
|
|
|
152
|
-
|
|
153
|
+
OpenCode sees the OpenViking MCP server as `openviking`, so tool names are namespaced with `openviking_`.
|
|
153
154
|
|
|
154
|
-
|
|
155
|
+
- `openviking_recall`: balanced current-task recall using OpenViking's `/recall` endpoint.
|
|
156
|
+
- `openviking_search`: deep semantic retrieval across memories, resources, and skills.
|
|
157
|
+
- `openviking_find`: fast semantic retrieval.
|
|
158
|
+
- `openviking_remember`: store important facts or decisions for memory extraction.
|
|
159
|
+
- `openviking_read`: read one or more `viking://` files.
|
|
160
|
+
- `openviking_list`: list a `viking://` directory.
|
|
161
|
+
- `openviking_grep`: exact text or regex search.
|
|
162
|
+
- `openviking_glob`: glob file matching.
|
|
163
|
+
- `openviking_add_resource`: add a URL, local file, sitemap, or feed.
|
|
164
|
+
- `openviking_forget`: delete a `viking://` URI after explicit user confirmation.
|
|
165
|
+
- `openviking_list_watches` / `openviking_cancel_watch`: inspect or cancel resource watches.
|
|
166
|
+
- `openviking_code_search`, `openviking_code_outline`, `openviking_code_expand`: inspect indexed code symbols.
|
|
167
|
+
- `openviking_health`: check OpenViking server health.
|
|
155
168
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
### `memread`
|
|
159
|
-
|
|
160
|
-
Read a specific `viking://` URI using `abstract`, `overview`, `read`, or `auto`.
|
|
161
|
-
|
|
162
|
-
Use after `memsearch`, `memgrep`, `memglob`, or `membrowse` returns a URI.
|
|
163
|
-
|
|
164
|
-
### `membrowse`
|
|
165
|
-
|
|
166
|
-
Browse OpenViking filesystem structure with `list`, `tree`, or `stat`.
|
|
167
|
-
|
|
168
|
-
Use to discover exact URIs before reading content.
|
|
169
|
-
|
|
170
|
-
### `memcommit`
|
|
171
|
-
|
|
172
|
-
Commit the current OpenCode session to OpenViking and trigger memory extraction.
|
|
173
|
-
|
|
174
|
-
The plugin also commits at session deletion, session error, compaction, and plugin shutdown boundaries.
|
|
175
|
-
|
|
176
|
-
### `memgrep`
|
|
177
|
-
|
|
178
|
-
Pattern search through OpenViking content.
|
|
179
|
-
|
|
180
|
-
Use for exact symbols, class names, function names, error strings, or known keywords.
|
|
181
|
-
|
|
182
|
-
### `memglob`
|
|
183
|
-
|
|
184
|
-
Glob file matching through OpenViking content.
|
|
185
|
-
|
|
186
|
-
Use to enumerate files such as `**/*.py`, `**/test_*.ts`, or `**/*.md`.
|
|
187
|
-
|
|
188
|
-
### `memadd`
|
|
189
|
-
|
|
190
|
-
Add a remote URL or local file resource to OpenViking.
|
|
191
|
-
|
|
192
|
-
Remote `http(s)` URLs go directly through `POST /api/v1/resources`.
|
|
193
|
-
Local files use the safer two-step server flow: upload the file to
|
|
194
|
-
`POST /api/v1/resources/temp_upload`, then add it through
|
|
195
|
-
`POST /api/v1/resources` with the returned `temp_file_id`.
|
|
196
|
-
|
|
197
|
-
Local paths may be absolute, relative to the OpenCode project directory, or
|
|
198
|
-
`file://` URLs. Local directory upload is not supported yet.
|
|
199
|
-
|
|
200
|
-
Examples:
|
|
201
|
-
|
|
202
|
-
```text
|
|
203
|
-
memadd path="https://example.com/spec.md" to="viking://resources/spec"
|
|
204
|
-
memadd path="./docs/notes.md" parent="viking://resources/"
|
|
205
|
-
memadd path="file:///home/alice/project/notes.md" reason="project notes"
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
After adding a resource, the tool also returns `GET /api/v1/observer/queue` status.
|
|
209
|
-
|
|
210
|
-
### `memwrite`
|
|
211
|
-
|
|
212
|
-
Write text content to a `viking://` file through `POST /api/v1/content/write`.
|
|
213
|
-
|
|
214
|
-
Use this for durable notes, small project memory files, or resource text that
|
|
215
|
-
should be updated directly. The default mode is `create` to avoid accidental
|
|
216
|
-
overwrites. Use `append` to extend an existing file and `replace` only when the
|
|
217
|
-
user explicitly wants to overwrite the file.
|
|
218
|
-
|
|
219
|
-
Examples:
|
|
220
|
-
|
|
221
|
-
```text
|
|
222
|
-
memwrite uri="viking://user/memories/project-notes.md" content="# Decision\n\nUse PostgreSQL." wait=true
|
|
223
|
-
memwrite uri="viking://resources/docs/api.md" content="\n\n## New endpoint" mode="append"
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
### `memremove`
|
|
227
|
-
|
|
228
|
-
Remove a `viking://` URI through `DELETE /api/v1/fs`.
|
|
229
|
-
|
|
230
|
-
This tool requires `confirm: true`. The user must explicitly confirm deletion before the agent calls it.
|
|
231
|
-
|
|
232
|
-
### `memqueue`
|
|
233
|
-
|
|
234
|
-
Return OpenViking observer queue status for embedding and semantic processing.
|
|
235
|
-
|
|
236
|
-
### `codesearch`
|
|
237
|
-
|
|
238
|
-
Search AST-supported symbol names across a confirmed ingested code repository or source subtree.
|
|
239
|
-
|
|
240
|
-
Use this after you have evidence that a `viking://` URI contains supported source files.
|
|
241
|
-
|
|
242
|
-
### `codeoutline`
|
|
243
|
-
|
|
244
|
-
Show symbol structure for a confirmed `viking://` source file.
|
|
245
|
-
|
|
246
|
-
Use this after `memglob`, `membrowse`, or `codesearch` finds an exact source file URI.
|
|
247
|
-
|
|
248
|
-
### `codeexpand`
|
|
249
|
-
|
|
250
|
-
Return the full source for one named symbol from a confirmed `viking://` source file.
|
|
251
|
-
|
|
252
|
-
Use this after `codeoutline` or other evidence shows the symbol exists in that file.
|
|
169
|
+
The proxy forwards the server's real `tools/list` response; the plugin does not maintain a separate native tool list.
|
|
253
170
|
|
|
254
171
|
## Runtime Files
|
|
255
172
|
|
|
256
173
|
The plugin writes runtime files to `~/.config/opencode/openviking/` by default:
|
|
257
174
|
|
|
258
175
|
- `openviking-memory.log`
|
|
259
|
-
- `openviking-session-
|
|
176
|
+
- `openviking-session-state.json`
|
|
260
177
|
|
|
261
178
|
Set `runtime.dataDir` in config to override this directory.
|