examples/opencode-plugin/README.md
A unified OpenCode plugin for OpenViking repository retrieval and long-term memory.
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.
The new plugin exposes everything through OpenCode tool hooks and talks to OpenViking through HTTP APIs. It does not install or require an OpenCode skill, and agents do not need to run ov shell commands.
viking://resources/ repositories into the system prompt.viking:// URIs and points the agent back to memread, membrowse, or memsearch.examples/opencode-plugin/
├── index.mjs
├── package.json
├── README.md
├── INSTALL-ZH.md
├── lib/
│ ├── runtime.mjs
│ ├── repo-context.mjs
│ ├── memory-session.mjs
│ ├── memadd-local.mjs
│ ├── memory-tools.mjs
│ ├── memory-recall.mjs
│ ├── viking-uri-guard.mjs
│ └── utils.mjs
├── tests/
└── wrappers/
└── openviking.mjs
There is intentionally no skills/openviking/SKILL.md. The former skill behavior is implemented as tools.
Start OpenViking first:
openviking-server --config ~/.openviking/ov.conf
Normal users should enable it through OpenCode's package plugin mechanism:
{
"plugin": ["openviking-opencode-plugin"]
}
For development or PR testing, copy the package into OpenCode's plugin directory with a top-level wrapper:
mkdir -p ~/.config/opencode/plugins/openviking
cp examples/opencode-plugin/wrappers/openviking.mjs ~/.config/opencode/plugins/openviking.mjs
cp examples/opencode-plugin/index.mjs examples/opencode-plugin/package.json ~/.config/opencode/plugins/openviking/
cp -r examples/opencode-plugin/lib ~/.config/opencode/plugins/openviking/
cd ~/.config/opencode/plugins/openviking
npm install
This creates a stable OpenCode plugin layout:
~/.config/opencode/plugins/
├── openviking.mjs
└── openviking/
├── index.mjs
├── package.json
├── lib/
└── node_modules/
The top-level openviking.mjs is only a wrapper:
export { OpenVikingPlugin, default } from "./openviking/index.mjs"
This wrapper is only for source installs with the directory layout shown above. npm package installs load index.mjs directly through package.json.
Create ~/.config/opencode/openviking-config.json:
{
"endpoint": "http://localhost:1933",
"apiKey": "",
"account": "",
"user": "",
"peerId": "",
"enabled": true,
"timeoutMs": 30000,
"repoContext": { "enabled": true, "cacheTtlMs": 60000 },
"autoRecall": {
"enabled": true,
"limit": 6,
"scoreThreshold": 0.15,
"maxContentChars": 500,
"preferAbstract": true,
"tokenBudget": 2000
}
}
apiKey is sent as X-API-Key. 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. Configure
peerId explicitly when peer-scoped memory routing is needed.
OPENVIKING_API_KEY, OPENVIKING_ACCOUNT, OPENVIKING_USER,
and OPENVIKING_PEER_ID take
precedence over values in this file.
For advanced setups, OPENVIKING_PLUGIN_CONFIG can point to another config file path.
OpenCode's local read, glob, and grep tools cannot read viking:// URIs.
When the agent accidentally tries that, the plugin blocks the filesystem tool
call and points it to memread, membrowse, or memsearch.
memsearchSemantic search across memories, resources, and skills.
Use for conceptual questions, repository internals, user preferences, and context-aware retrieval. Use target_uri to narrow scope, for example viking://resources/fastapi/.
memreadRead a specific viking:// URI using abstract, overview, read, or auto.
Use after memsearch, memgrep, memglob, or membrowse returns a URI.
membrowseBrowse OpenViking filesystem structure with list, tree, or stat.
Use to discover exact URIs before reading content.
memcommitCommit the current OpenCode session to OpenViking and trigger memory extraction.
The plugin also commits at session deletion, session error, compaction, and plugin shutdown boundaries.
memgrepPattern search through OpenViking content.
Use for exact symbols, class names, function names, error strings, or known keywords.
memglobGlob file matching through OpenViking content.
Use to enumerate files such as **/*.py, **/test_*.ts, or **/*.md.
memaddAdd a remote URL or local file resource to OpenViking.
Remote http(s) URLs go directly through POST /api/v1/resources.
Local files use the safer two-step server flow: upload the file to
POST /api/v1/resources/temp_upload, then add it through
POST /api/v1/resources with the returned temp_file_id.
Local paths may be absolute, relative to the OpenCode project directory, or
file:// URLs. Local directory upload is not supported yet.
Examples:
memadd path="https://example.com/spec.md" to="viking://resources/spec"
memadd path="./docs/notes.md" parent="viking://resources/"
memadd path="file:///home/alice/project/notes.md" reason="project notes"
After adding a resource, the tool also returns GET /api/v1/observer/queue status.
memwriteWrite text content to a viking:// file through POST /api/v1/content/write.
Use this for durable notes, small project memory files, or resource text that
should be updated directly. The default mode is create to avoid accidental
overwrites. Use append to extend an existing file and replace only when the
user explicitly wants to overwrite the file.
Examples:
memwrite uri="viking://user/memories/project-notes.md" content="# Decision\n\nUse PostgreSQL." wait=true
memwrite uri="viking://resources/docs/api.md" content="\n\n## New endpoint" mode="append"
memremoveRemove a viking:// URI through DELETE /api/v1/fs.
This tool requires confirm: true. The user must explicitly confirm deletion before the agent calls it.
memqueueReturn OpenViking observer queue status for embedding and semantic processing.
The plugin writes runtime files to ~/.config/opencode/openviking/ by default:
openviking-memory.logopenviking-session-map.jsonSet runtime.dataDir in config to override this directory.