Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/agent-hook-plugin/hosts/codebuddy/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openviking-memory",
"version": "0.5.34",
"version": "0.5.35",
"description": "Long-term semantic memory for the CodeBuddy Code CLI, powered by OpenViking. Injects relevant context at session start and on each prompt, and captures the conversation back into OpenViking.",
"author": {
"name": "OpenViking",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
"version": "0.5.34",
"version": "0.5.35",
"clients": [
"cursor"
],
Expand Down
2 changes: 1 addition & 1 deletion examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openviking-memory",
"version": "0.5.34",
"version": "0.5.35",
"description": "Long-term semantic memory for Kimi Code CLI, powered by OpenViking.",
"author": {
"name": "OpenViking",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
"version": "0.5.34",
"version": "0.5.35",
"clients": [
"kimicode"
],
Expand Down
2 changes: 1 addition & 1 deletion examples/agent-hook-plugin/hosts/qoder/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openviking-memory",
"version": "0.5.34",
"version": "0.5.35",
"description": "Long-term semantic memory for the Qoder CLI, powered by OpenViking. Injects relevant context at session start and on each prompt, and captures the conversation back into OpenViking.",
"author": {
"name": "OpenViking",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
"version": "0.5.34",
"version": "0.5.35",
"clients": [
"trae",
"trae-cn"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
"version": "0.5.34",
"version": "0.5.35",
"clients": [
"zcode"
],
Expand Down
2 changes: 1 addition & 1 deletion examples/agent-hook-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "agent-hook-plugin",
"version": "0.5.34",
"version": "0.5.35",
"description": "Long-term semantic memory for Cursor, TRAE, TRAE CN, ZCode, Kimi Code, CodeBuddy Code, Qoder CLI and Antigravity — powered by OpenViking. Auto-recall relevant memories and capture the conversation as it happens.",
"author": {
"name": "OpenViking",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openviking-memory",
"version": "0.7.25",
"version": "0.7.26",
"description": "Long-term semantic memory for Claude Code, powered by OpenViking. Auto-recall relevant memories at session start and capture important information during conversations.",
"author": {
"name": "OpenViking",
Expand Down
2 changes: 1 addition & 1 deletion examples/claude-code-memory-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "claude-code-openviking-memory",
"version": "0.7.25",
"version": "0.7.26",
"description": "OpenViking memory plugin for Claude Code — semantic long-term memory",
"type": "module",
"scripts": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/codex-memory-plugin/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openviking-memory",
"version": "0.11.23",
"version": "0.11.24",
"description": "Long-term semantic memory for Codex, powered by OpenViking. Recall on UserPromptSubmit, incremental add_message on Stop (per turn), commit on SessionEnd (Codex >= 0.145) and on PreCompact, with an idle/ended sweep on SessionStart as the fallback for signals, crashes and older Codex builds. Includes a local stdio MCP proxy that reads OpenViking credentials from env/ovcli.conf.",
"author": {
"name": "OpenViking",
Expand Down
4 changes: 4 additions & 0 deletions examples/codex-memory-plugin/scripts/shared/config-schema.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/dsh-memory-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/dsh-memory-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openviking/dsh-memory-plugin",
"version": "0.5.38",
"version": "0.5.39",
"description": "OpenViking memory and context bundle for DeepSeek Harness",
"icon": "./icon.svg",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion examples/magpie-memory-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openviking/magpie-plugin",
"version": "0.2.2",
"version": "0.2.3",
"description": "OpenViking integration for Magpie: memory recall/capture and model switching with automatic restart.",
"author": "OpenViking",
"homepage": "https://github.com/volcengine/OpenViking/tree/main/examples/magpie-memory-plugin",
Expand Down
4 changes: 4 additions & 0 deletions examples/memory-plugin-shared/lib/config-schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export const KNOBS = [
{ name: "recallContextTimeoutMs", type: "int", default: 0, min: 0, max: 600000, env: "OPENVIKING_RECALL_CONTEXT_TIMEOUT_MS", capability: "recall" },
{ name: "logRankingDetails", type: "bool", default: false, env: "OPENVIKING_LOG_RANKING_DETAILS", capability: "recall" },
{ name: "recallLedger", type: "bool", default: true, env: "OPENVIKING_RECALL_LEDGER", capability: "recall" },
// Hosts that fetch recall alongside the send rather than before it (opencode
// v2): how long after the send the model call may wait for it. Recall that
// lands later is skipped for that turn; 0 injects only what is already there.
{ name: "recallWaitMs", type: "int", default: 5000, min: 0, max: 60000, env: "OPENVIKING_RECALL_WAIT_MS", capability: "recall" },
{ name: "recallQueryFilters", type: "list", default: [], env: "OPENVIKING_RECALL_QUERY_FILTERS", capability: "recall" },
// Subtree URIs the recall search must never return. Without this there is no
// way to keep generated directory files (viking://user/<space>/skills,
Expand Down
2 changes: 2 additions & 0 deletions examples/opencode-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ Explicit values from 1 through 5 produce an effective total quota of 6 because
each coding category keeps one retrieval slot. Use Context `quotas` directly
when exact category ceilings are required.

On OpenCode v2 the plugin does not hold the send while it fetches. The `prompt` hook only starts the session-start and recall fetches, so your message appears at once; the model call waits for them for up to `recallWaitMs` after the send (default `5000`, `OPENVIKING_RECALL_WAIT_MS`). Recall that arrives later is skipped for that turn, and late session-start context goes out with your next message instead. What was injected into each message is kept per session in OpenCode's plugin storage and sent again unchanged on every later request, so the provider's prompt cache keeps matching; `recallLedger: false` keeps it in memory only, for the life of the server.

`profileTokenBudget` covers the profile and memory indexes in the session-start block. The `<available-skills>` catalog comes from one `GET /api/v1/skills` and has its own budget, `skillCatalogTokenBudget` (default `1200`, `OPENVIKING_SKILL_CATALOG_TOKEN_BUDGET`). Your own skills are listed first, then the ones shared under `viking://agent/skills`, leaving out a shared skill that has the same name as one of yours; each description is cut to about 40 tokens. When the descriptions do not fit, the catalog lists names only (with a `... +N more` tail if even the names do not all fit), and when not even one name fits, a one-line count. The agent reads a skill's `SKILL.md` with `openviking_read` before following it. `skillCatalog: false` (`OPENVIKING_SKILL_CATALOG=0`) or a budget of `0` turns the catalog off; with no skills, or on a server without `GET /api/v1/skills`, it is left out.

API keys are resolved from environment variables or `~/.openviking/ovcli.conf` and sent as `Authorization: Bearer ...` by both hooks and the MCP proxy. Recall goes through the server-side context face (`POST /api/v1/search/search` with `mode="context"`), falling back to the deprecated `/api/v1/search/recall` on older deployments. `account` and `user` are trusted-mode identity
Expand Down
12 changes: 6 additions & 6 deletions examples/opencode-plugin/lib/memory-recall.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { isBypassed } from "./shared/session-model.mjs"
import { effectivePeerId, fetchJSON, log } from "./utils.mjs"

export function createMemoryRecall({ config, sessionManager }) {
async function buildRelevantMemories(input, parts) {
if (!isRecallEnabled(config)) return
async function buildRelevantMemories(input, parts, { signal } = {}) {
if (signal?.aborted || !isRecallEnabled(config)) return
const query = extractCurrentUserText(parts ?? [])
if (!query) return
if (query.length < config.minQueryLength) return
Expand All @@ -14,15 +14,15 @@ export function createMemoryRecall({ config, sessionManager }) {
cwd: input.directory ?? input.cwd,
})) return

const health = await fetchJSON(config, "/health", {}, { timeoutMs: 5000 })
if (!health.ok) return
const health = await fetchJSON(config, "/health", { signal }, { timeoutMs: 5000 })
if (signal?.aborted || !health.ok) return

const block = await buildRecallBlock(
// 5s is this hook's own budget for a bare retrieval; when the request
// also spends a server fuse the helper hands down a longer deadline, and
// overriding it here would abort a request the server was still inside.
(path, init = {}, options = {}) =>
fetchJSON(config, path, init, { ...options, timeoutMs: options.timeoutMs ?? 5000 }),
fetchJSON(config, path, { ...init, signal: signal ?? init.signal }, { ...options, timeoutMs: options.timeoutMs ?? 5000 }),
config,
query,
{
Expand All @@ -34,7 +34,7 @@ export function createMemoryRecall({ config, sessionManager }) {
log: (stage, data) => log("DEBUG", "recall", stage, data),
},
)
return block || undefined
return signal?.aborted ? undefined : block || undefined
}

async function injectRelevantMemories(input, output) {
Expand Down
7 changes: 4 additions & 3 deletions examples/opencode-plugin/lib/session-inject.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { effectivePeerId, fetchJSON, log } from "./utils.mjs"
export function createSessionInject({ config, sessionManager }) {
const injectedSessions = new Set()

async function buildSessionContext(input) {
if (config.noAutoInject) return false
async function buildSessionContext(input, { signal } = {}) {
if (config.noAutoInject || signal?.aborted) return false
const sessionID = input.sessionID
const messageID = input.messageID
if (!sessionID || !messageID || injectedSessions.has(sessionID)) return false
Expand All @@ -15,7 +15,7 @@ export function createSessionInject({ config, sessionManager }) {

const actorPeerId = effectivePeerId(config)
const clientFetch = (endpoint, init = {}, options = {}) =>
fetchJSON(config, endpoint, init, { ...options, actorPeerId, timeoutMs: 10000 })
signal?.aborted ? { ok: false } : fetchJSON(config, endpoint, { ...init, signal: signal ?? init.signal }, { ...options, actorPeerId, timeoutMs: 10000 })

const parts = []
const profile = await buildProfileBlock(clientFetch, config.profileTokenBudget, actorPeerId, config)
Expand All @@ -25,6 +25,7 @@ export function createSessionInject({ config, sessionManager }) {
? await fetchArchiveBlock(clientFetch, ovSessionId, config.resumeContextBudget)
: ""
if (archive) parts.push(archive)
if (signal?.aborted) return undefined

if (parts.length === 0) {
injectedSessions.add(sessionID)
Expand Down
64 changes: 18 additions & 46 deletions examples/opencode-plugin/lib/v2-plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { join } from "node:path"
import { isRecallEnabled } from "./shared/recall-core.mjs"
import { createOpenVikingV2McpConfig, openVikingSkillsDir } from "./mcp-config.mjs"
import { contextMessageEvents, normalizeV2LifecycleEvent } from "./v2-events.mjs"
import { createV2Recall } from "./v2-recall.mjs"
import { log } from "./utils.mjs"

const METADATA_KEY = "openviking"
const CURSOR_KEY_PREFIX = "capture-cursor/"
const LIFECYCLE_EVENTS = new Set([
"session.created",
Expand Down Expand Up @@ -37,6 +37,15 @@ export async function startV2Plugin(ctx, runtime, { pluginRoot }) {
return task
}
const directory = ctx?.location?.project?.directory || ctx?.location?.directory
const v2Recall = createV2Recall({
ctx,
config,
ready: runtime.ready,
recall,
sessionInject,
directory,
recallEnabled: isRecallEnabled(config),
})

if (config.mcp.enabled && ctx?.mcp?.transform) {
let registered = false
Expand Down Expand Up @@ -79,15 +88,11 @@ export async function startV2Plugin(ctx, runtime, { pluginRoot }) {
}

if (ctx?.session?.hook) {
await ctx.session.hook("prompt", async (event) => {
// The host holds the user's message until this returns, so it only
// starts the fetch; `context` waits for it right before the model call.
await ctx.session.hook("prompt", (event) => {
try {
await runtime.ready
await prepareV2Prompt(event, {
directory,
recall,
sessionInject,
recallEnabled: isRecallEnabled(config),
})
v2Recall.prefetch(event)
} catch (error) {
logHookError("session.prompt", error)
}
Expand All @@ -97,6 +102,7 @@ export async function startV2Plugin(ctx, runtime, { pluginRoot }) {
try {
await runtime.ready
injectV2Context(event, repoContext)
await v2Recall.inject(event)
} catch (error) {
logHookError("session.context", error)
}
Expand Down Expand Up @@ -145,15 +151,18 @@ export async function startV2Plugin(ctx, runtime, { pluginRoot }) {
if (event.type === "session.deleted") {
sessionOwnership.delete(sessionID)
await forgetCursor(ctx, captureCursors, sessionID)
await v2Recall.forget(sessionID)
}
})
})
}

return async () => {
const recallCleanup = v2Recall.dispose()
controller.abort()
try {
await eventTask
await recallCleanup
await sessionTask
await runtime.ready
await runtime.background
Expand Down Expand Up @@ -204,46 +213,9 @@ async function consumeEvents(ctx, signal, handle) {
}
}

export async function prepareV2Prompt(event, {
directory,
recall,
sessionInject,
recallEnabled,
}) {
const sessionID = event?.sessionID
const messageID = event?.messageID
if (!sessionID || !messageID) return
const text = event?.prompt?.text
const parts = typeof text === "string" && text.trim() ? [{ type: "text", text }] : []
const input = { sessionID, messageID, directory }
const blocks = (await Promise.all([
sessionInject.buildSessionContext(input).catch((error) => logHookError("session.prompt.profile", error)),
recallEnabled
? recall.buildRelevantMemories(input, parts).catch((error) => logHookError("session.prompt.recall", error))
: undefined,
])).filter(Boolean)
if (blocks.length === 0) return

event.metadata = event.metadata && typeof event.metadata === "object" ? event.metadata : {}
event.metadata[METADATA_KEY] = { context: blocks }
}

export function injectV2Context(event, repoContext) {
const repoPrompt = repoContext.getRepoSystemPrompt()
if (repoPrompt) pushSystem(event, repoPrompt)
if (!Array.isArray(event?.messages)) return

for (const message of event.messages) {
const blocks = message?.metadata?.[METADATA_KEY]?.context
if (message?.role !== "user" || !Array.isArray(blocks) || blocks.length === 0) continue
if (!Array.isArray(message.content)) message.content = []
if (message.content.some((part) => part?.metadata?.[METADATA_KEY] === true)) continue
message.content.unshift({
type: "text",
text: blocks.filter((block) => typeof block === "string" && block).join("\n\n"),
metadata: { [METADATA_KEY]: true },
})
}
}

// The plugin event stream carries every location served by the process, and
Expand Down
Loading