Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

feat(claude-code-memory-plugin): show OpenViking source cards under answers (#5663)

Zayn Jarvis930173ac3c08
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json
index 351d59855..ed9ae6c1c 100644
--- a/.claude-plugin/marketplace.json
+++ b/.claude-plugin/marketplace.json
@@ -15,17 +15,6 @@
"ref": "main"
},
"category": "productivity"
- },
- {
- "name": "ov-usage",
- "description": "Shows which OpenViking sources each Claude Code answer consulted, as a card under the answer",
- "source": {
- "source": "git-subdir",
- "url": "https://github.com/volcengine/OpenViking.git",
- "path": "examples/claude-code-usage-plugin",
- "ref": "main"
- },
- "category": "productivity"
}
]
}
diff --git a/.github/scripts/check-marketplace-archive.mjs b/.github/scripts/check-marketplace-archive.mjs
index 341702d90..d3b0a7108 100644
--- a/.github/scripts/check-marketplace-archive.mjs
+++ b/.github/scripts/check-marketplace-archive.mjs
@@ -29,7 +29,12 @@ const PACKAGE_MANIFESTS = ["plugin.json"];
// Directories a host loads whole; what is inside them is named nowhere.
const CONTENT_DIRS = ["skills", "rules", "commands"];
-const SCRIPT_RE = /[^\s"'`]+\.(?:mjs|cjs|js)\b/g;
+// Command hooks name .mjs/.cjs/.js scripts; a Claude Code hooks module (`modules`
+// in hooks.json) names a .ts/.tsx file.
+const SCRIPT_RE = /[^\s"'`]+\.(?:mjs|cjs|js|tsx?)\b/g;
+
+// TypeScript imports leave the extension off: "./sources" is sources.ts.
+const TS_EXTENSIONS = ["", ".ts", ".tsx", ".d.ts"];
async function isFile(path) {
return stat(path)
@@ -92,8 +97,15 @@ async function importClosure(entries) {
const reached = new Set();
const pending = [...entries];
while (pending.length) {
- const file = pending.pop();
- if (reached.has(file) || !(await isFile(file))) continue;
+ const spec = pending.pop();
+ let file = null;
+ for (const ext of TS_EXTENSIONS) {
+ if (await isFile(spec + ext)) {
+ file = spec + ext;
+ break;
+ }
+ }
+ if (!file || reached.has(file)) continue;
reached.add(file);
const source = await readFile(file, "utf-8");
for (const spec of importSpecifiers(source)) {
diff --git a/.github/scripts/check-plugin-version-bumps.sh b/.github/scripts/check-plugin-version-bumps.sh
index 6b60d129e..f2a62728b 100755
--- a/.github/scripts/check-plugin-version-bumps.sh
+++ b/.github/scripts/check-plugin-version-bumps.sh
@@ -22,7 +22,6 @@ cd "$ROOT"
# <plugin directory>:<manifest holding the version>
PLUGINS=(
"examples/claude-code-memory-plugin:examples/claude-code-memory-plugin/.claude-plugin/plugin.json"
- "examples/claude-code-usage-plugin:examples/claude-code-usage-plugin/.claude-plugin/plugin.json"
"examples/codex-memory-plugin:examples/codex-memory-plugin/.codex-plugin/plugin.json"
"examples/agent-hook-plugin:examples/agent-hook-plugin/plugin.json"
"examples/opencode-plugin:examples/opencode-plugin/package.json"
diff --git a/docs/en/agent-integrations/02-claude-code.md b/docs/en/agent-integrations/02-claude-code.md
index f075912c6..17b399bde 100644
--- a/docs/en/agent-integrations/02-claude-code.md
+++ b/docs/en/agent-integrations/02-claude-code.md
@@ -111,15 +111,11 @@ Change it with `OPENVIKING_PEER_SOURCE`, with `plugin.peerSource` in `ovcli.conf
The plugin renders an OpenViking status indicator beneath your Claude Code input box, allowing you to check connection health, recall count, capture progress, and session state at a glance. See [STATUSLINE.md](https://github.com/volcengine/OpenViking/blob/main/examples/claude-code-memory-plugin/STATUSLINE.md) for a complete glossary of segments and personalization recipes.
-## Optional: see what OpenViking contributed (OV-Usage)
+## Source cards
-OV-Usage is a separate, opt-in plugin. It adds a card under each answer listing the OpenViking sources the answer used: what auto-recall added, and what Claude searched for and read on its own. The card is one line by default and expands to the full list. It needs Claude Code 2.1.286 or newer, and openviking-memory installed.
+Under each answer, the plugin adds a one-line card listing the OpenViking sources that answer drew on: what auto-recall added to the prompt, and what Claude searched for and read on its own. For example: `OV · 8 sources · 4 past events · 3 work memories · 1 team doc · 1 read in full [Expand]`. Expand a card with its button, or expand and collapse every card with `/openviking-usage expand` and `/openviking-usage collapse`. Cards are collapsed by default.
-```bash
-claude plugin install ov-usage@openviking
-```
-
-See the [OV-Usage README](https://github.com/volcengine/OpenViking/blob/main/examples/claude-code-usage-plugin/README.md) for details.
+The cards need Claude Code 2.1.286 or newer with plugin hooks modules enabled. On older versions, or with modules off, no cards are shown, and recall, capture and the other hooks work as before. See [Source cards](https://github.com/volcengine/OpenViking/blob/main/examples/claude-code-memory-plugin/README.md#source-cards) in the plugin README.
## Troubleshooting
diff --git a/docs/zh/agent-integrations/02-claude-code.md b/docs/zh/agent-integrations/02-claude-code.md
index ecf68498a..5743c4236 100644
--- a/docs/zh/agent-integrations/02-claude-code.md
+++ b/docs/zh/agent-integrations/02-claude-code.md
@@ -111,15 +111,11 @@ skill 清单就是 `<available-skills>` 块,列出存放在 OpenViking 中的
插件会在 Claude Code 的输入框下方显示一行 OpenViking 状态栏,用于指示:连接状态、召回条数、捕获进度以及当前会话状态。关于状态栏各部分的详细含义与自定义配置方法,请参阅 [STATUSLINE.md](https://github.com/volcengine/OpenViking/blob/main/examples/claude-code-memory-plugin/STATUSLINE.md)。
-## 可选:查看 OpenViking 的贡献(OV-Usage)
+## 来源卡片
-OV-Usage 是一个独立的可选插件,在每次回答下方加一张卡片,列出这次回答用到的 OpenViking 来源:自动召回加入了什么,Claude 自己搜索、读取了什么。卡片默认只占一行,展开后显示完整列表。需要 Claude Code 2.1.286 或更高版本,并已安装 openviking-memory。
+插件会在每次回答下方加一行卡片,列出这次回答用到的 OpenViking 来源:自动召回加进提示的内容,以及 Claude 自己搜索、读取的内容。例如 `OV · 8 sources · 4 past events · 3 work memories · 1 team doc · 1 read in full [Expand]`。用卡片上的按钮展开单张卡片,或用 `/openviking-usage expand`、`/openviking-usage collapse` 展开或折叠全部卡片。卡片默认折叠。
-```bash
-claude plugin install ov-usage@openviking
-```
-
-详见 [OV-Usage README](https://github.com/volcengine/OpenViking/blob/main/examples/claude-code-usage-plugin/README_CN.md)。
+卡片需要 Claude Code 2.1.286 或更高版本,并启用插件 hooks 模块。版本更早或模块未启用时不显示卡片,召回、捕获等 hook 照常工作。详见插件 README 的[来源卡片](https://github.com/volcengine/OpenViking/blob/main/examples/claude-code-memory-plugin/README_CN.md#来源卡片)。
## 故障排查
diff --git a/examples/claude-code-memory-plugin/.claude-plugin/plugin.json b/examples/claude-code-memory-plugin/.claude-plugin/plugin.json
index 845ebc0f7..adceef067 100644
--- a/examples/claude-code-memory-plugin/.claude-plugin/plugin.json
+++ b/examples/claude-code-memory-plugin/.claude-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "openviking-memory",
- "version": "0.6.9",
+ "version": "0.7.0",
"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",
@@ -15,5 +15,6 @@
"long-term-memory",
"context-engine"
],
- "mcpServers": "./.mcp.json"
+ "mcpServers": "./.mcp.json",
+ "types": "./mods/usage/types.d.ts"
}
diff --git a/examples/claude-code-memory-plugin/.gitignore b/examples/claude-code-memory-plugin/.gitignore
index 72b98d5e1..24414b475 100644
--- a/examples/claude-code-memory-plugin/.gitignore
+++ b/examples/claude-code-memory-plugin/.gitignore
@@ -3,3 +3,7 @@ node_modules/
# Top-level .gitignore excludes lib/ (Python setuptools convention); the
# plugin's scripts/lib/ is a JS module directory and must be tracked.
!scripts/lib/
+# Written by Claude Code when it loads this directory with --plugin-dir: the
+# hooks-module API types and a tsconfig that points at them.
+.claude-plugin/types/
+/tsconfig.json
diff --git a/examples/claude-code-memory-plugin/README.md b/examples/claude-code-memory-plugin/README.md
index 9596ed3ed..0e753a11f 100644
--- a/examples/claude-code-memory-plugin/README.md
+++ b/examples/claude-code-memory-plugin/README.md
@@ -419,6 +419,44 @@ Disable / customize:
- Remove entirely: `jq 'del(.statusLine)' ~/.claude/settings.json > t && mv t ~/.claude/settings.json`.
- Already had a custom statusline? The installer prompts replace / skip / manual-compose.
+## Source cards
+
+Under each answer, the plugin adds a card listing the OpenViking sources that answer drew on: what auto-recall added to the prompt, and what Claude searched for and read on its own. The card is collapsed by default to one line:
+
+```
+OV · 14 sources · 6 past events · 5 work memories · 2 team docs · 1 skill · 1 read in full [Expand]
+```
+
+Expanded, it lists every source and Claude's own lookups:
+
+```
+OV · 14 sources · … · 1 read in full [Collapse]
+ ◷ 10/3 发版检查清单补充 · found by Claude · read in full
+ ⚙ openviking-release · auto-recalled
+ …
+Claude's own lookups
+ ⌕ Searched “lark-daemon release” · 6 results
+ ▤ Read 10/3 发版检查清单补充
+```
+
+- Groups: ★ preferences, ◷ past events, ◆ work memories (notes, lessons, your agents' memories), ▤ team docs, ⚙ skills.
+- **read in full**: Claude opened the file with `read`, through the MCP tool or `ov read`/`cat`/`abstract`/`overview`. A search hit doesn't count.
+- An answer that used nothing from OpenViking gets no card.
+- Expand or collapse one card with its button. Expand or collapse every card with `/openviking-usage expand` or `/openviking-usage collapse`.
+
+**Requirements.** Cards are a Claude Code hooks module (`modules` in `hooks/hooks.json`, code in `mods/usage/`). They need Claude Code 2.1.286 or newer with hooks modules enabled. Claude Code ignores the module and runs the command hooks as before in these cases:
+
+- On versions without modules.
+- When modules are switched off, for example with `CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=0` or by the rollout flag.
+
+On builds between the first modules release and 2.1.286 with modules switched on, the module fails to load because it uses `session.append`. Claude Code logs that failure and still registers the command hooks.
+
+**Data.** The module reads the `<openviking-context>` block this plugin's `UserPromptSubmit` hook returns, and the OpenViking MCP and `ov` CLI calls Claude makes. It makes no network calls and writes nothing to OpenViking.
+
+It keeps each answer's source URIs, scores, redacted search queries and the transcript row id of its card in Claude Code's plugin store, for the last 20 sessions, so cards survive `claude --continue`. Shell commands and prompt text are not stored. The card isn't sent to Claude, so it costs no tokens.
+
+**Development.** `claude plugin test examples/claude-code-memory-plugin` runs `mods/usage/sources.test.ts`. After `claude --plugin-dir examples/claude-code-memory-plugin` has generated `.claude-plugin/types/`, run `tsc -p examples/claude-code-memory-plugin/mods/usage` to type-check the module.
+
## Debug logging
Set `claude_code.debug: true` in `ov.conf` or `OPENVIKING_DEBUG=1` to write hook logs to `~/.openviking/logs/cc-hooks.log`.
@@ -486,7 +524,7 @@ Claude Code has a built-in `MEMORY.md` file system. This plugin **complements**
context inject └──────────────┘
```
-There is no TypeScript build step and no runtime npm bootstrap. Hooks are plain `.mjs` files that talk to OpenViking over HTTP; MCP uses `servers/mcp-proxy.mjs` as a zero-dependency stdio bridge to the OpenViking server's `/mcp` endpoint.
+There is no TypeScript build step and no runtime npm bootstrap. Hooks are plain `.mjs` files that talk to OpenViking over HTTP; MCP uses `servers/mcp-proxy.mjs` as a zero-dependency stdio bridge to the OpenViking server's `/mcp` endpoint. The source-card module in `mods/usage/` is TypeScript that Claude Code compiles itself.
A persistent OpenViking session is created on first contact and reused for the entire Claude Code session. The OV session ID is `cc-<cc_session_id>` (the CC session_id verbatim, no hashing), so resume / compact / multi-hook events all target the same session. Archival + memory extraction is triggered client-side: the `Stop` hook commits when server-reported pending tokens cross `commitTokenThreshold` (default 20000), and `PreCompact` / `SessionEnd` / `SubagentStop` commit unconditionally.
diff --git a/examples/claude-code-memory-plugin/README_CN.md b/examples/claude-code-memory-plugin/README_CN.md
index ed9dcd2fc..0ba506bda 100644
--- a/examples/claude-code-memory-plugin/README_CN.md
+++ b/examples/claude-code-memory-plugin/README_CN.md
@@ -369,6 +369,44 @@ OV ✓ │ 🔗 resumed │ +3 today session 已恢复上下文;
- 彻底卸载:`jq 'del(.statusLine)' ~/.claude/settings.json > t && mv t ~/.claude/settings.json`。
- 已有自定义 statusline?安装时会询问替换 / 跳过 / 稍后手动 compose。
+## 来源卡片
+
+插件会在每次回答下方加一张卡片,列出这次回答用到的 OpenViking 来源:自动召回加进提示的内容,以及 Claude 自己搜索、读取的内容。卡片默认折叠成一行:
+
+```
+OV · 14 sources · 6 past events · 5 work memories · 2 team docs · 1 skill · 1 read in full [Expand]
+```
+
+展开后列出全部来源和 Claude 自己的查询:
+
+```
+OV · 14 sources · … · 1 read in full [Collapse]
+ ◷ 10/3 发版检查清单补充 · found by Claude · read in full
+ ⚙ openviking-release · auto-recalled
+ …
+Claude's own lookups
+ ⌕ Searched “lark-daemon release” · 6 results
+ ▤ Read 10/3 发版检查清单补充
+```
+
+- 分组:★ 偏好,◷ 过往事件,◆ 工作记忆(笔记、经验、你的 agent 的记忆),▤ 团队文档,⚙ Skill。
+- **read in full**:Claude 用 `read`(MCP 工具,或 `ov read`/`cat`/`abstract`/`overview`)打开了这个文件。只出现在搜索结果里的不算。
+- 没用到任何 OpenViking 内容的回答不显示卡片。
+- 用卡片上的按钮展开或折叠单张卡片;用 `/openviking-usage expand` 或 `/openviking-usage collapse` 展开或折叠全部卡片。界面文字只有英文。
+
+**前提。** 卡片是一个 Claude Code hooks 模块(`hooks/hooks.json` 里的 `modules`,代码在 `mods/usage/`),需要 Claude Code 2.1.286 或更高版本,并启用 hooks 模块。下面这些情况下,Claude Code 会忽略这个模块,命令 hook 照常运行:
+
+- 版本不支持模块。
+- 模块被关闭,例如设置了 `CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=0`,或被灰度开关关闭。
+
+在支持模块、但早于 2.1.286 的版本上,如果开启了模块,这个模块会因为用到 `session.append` 而加载失败。Claude Code 会记录这条错误,命令 hook 仍然照常注册。
+
+**数据。** 模块读取本插件 `UserPromptSubmit` hook 返回的 `<openviking-context>` 块,以及 Claude 发起的 OpenViking MCP 调用和 `ov` CLI 调用。它不发网络请求,不向 OpenViking 写任何内容。
+
+它在 Claude Code 的插件存储里保存每次回答的来源 URI、分数、脱敏后的搜索词和卡片所在的对话行 id,保留最近 20 个会话,所以 `claude --continue` 之后卡片还在。不保存 shell 命令和提示原文。卡片不会发给 Claude,不消耗 token。
+
+**开发。** `claude plugin test examples/claude-code-memory-plugin` 会运行 `mods/usage/sources.test.ts`。用 `claude --plugin-dir examples/claude-code-memory-plugin` 启动一次、生成 `.claude-plugin/types/` 后,可以用 `tsc -p examples/claude-code-memory-plugin/mods/usage` 做类型检查。
+
## 调试日志
设置 `claude_code.debug: true` 或 `OPENVIKING_DEBUG=1`,hook 日志写到 `~/.openviking/logs/cc-hooks.log`。
@@ -478,7 +516,7 @@ claude-code-memory-plugin/
├── .claude-plugin/
│ └── plugin.json # plugin manifest
├── hooks/
-│ └── hooks.json # 9 个 hook 注册
+│ └── hooks.json # 9 个 hook 注册 + 来源卡片模块
├── commands/
│ └── ov.md # /ov 状态命令
├── skills/
@@ -486,6 +524,8 @@ claude-code-memory-plugin/
│ ├── openviking-skills/ # 查找、添加、共享和迁移 OpenViking skill
│ ├── ov-experience-memory/
│ └── ov-memory-doctor/ # 安装 / 配置 / 连接 / 本机 server 排障
+├── mods/
+│ └── usage/ # 来源卡片(Claude Code hooks 模块)
├── servers/
│ └── mcp-proxy.mjs # stdio -> OpenViking /mcp 桥接
├── scripts/
diff --git a/examples/claude-code-memory-plugin/hooks/hooks.json b/examples/claude-code-memory-plugin/hooks/hooks.json
index c9402f608..4b253e7c0 100644
--- a/examples/claude-code-memory-plugin/hooks/hooks.json
+++ b/examples/claude-code-memory-plugin/hooks/hooks.json
@@ -1,4 +1,7 @@
{
+ "modules": [
+ "../mods/usage/register.tsx"
+ ],
"hooks": {
"SessionStart": [
{
diff --git a/examples/claude-code-usage-plugin/hooks/register.tsx b/examples/claude-code-memory-plugin/mods/usage/register.tsx
similarity index 92%
rename from examples/claude-code-usage-plugin/hooks/register.tsx
rename to examples/claude-code-memory-plugin/mods/usage/register.tsx
index 74ec8ac57..cdb90c80d 100644
--- a/examples/claude-code-usage-plugin/hooks/register.tsx
+++ b/examples/claude-code-memory-plugin/mods/usage/register.tsx
@@ -1,5 +1,5 @@
import type { EngineInterface, Register, ResolveInput } from "claude-code";
-import type { Lookup, Turn } from "../types";
+import type { Lookup, Turn } from "./types";
import {
ICON,
classifyCall,
@@ -11,9 +11,9 @@ import {
urisIn,
} from "./sources";
-const turnsRef = { plugin: "ov-usage", key: "turns" } as const;
-const repliesRef = { plugin: "ov-usage", key: "replies" } as const;
-const expandedRef = { plugin: "ov-usage", key: "expanded" } as const;
+const turnsRef = { plugin: "openviking-memory", key: "turns" } as const;
+const repliesRef = { plugin: "openviking-memory", key: "replies" } as const;
+const expandedRef = { plugin: "openviking-memory", key: "expanded" } as const;
const MAX_TURNS = 50;
const MAX_SESSIONS = 20;
@@ -40,22 +40,22 @@ async function lastTurn($: EngineInterface): Promise<Turn | undefined> {
async function save($: EngineInterface) {
const id = await $.session.id();
if (!id) return;
- await $.store.set(`session:${id}`, {
+ await $.store.set(`usage:session:${id}`, {
turns: (await $.state.get(turnsRef)).value ?? [],
replies: (await $.state.get(repliesRef)).value ?? [],
expanded: (await $.state.get(expandedRef)).value ?? [],
});
- const index = ((await $.store.get("sessions")) as string[] | undefined) ?? [];
+ const index = ((await $.store.get("usage:sessions")) as string[] | undefined) ?? [];
const next = [...index.filter((k) => k !== id), id];
- for (const old of next.slice(0, -MAX_SESSIONS)) await $.store.delete(`session:${old}`);
- await $.store.set("sessions", next.slice(-MAX_SESSIONS));
+ for (const old of next.slice(0, -MAX_SESSIONS)) await $.store.delete(`usage:session:${old}`);
+ await $.store.set("usage:sessions", next.slice(-MAX_SESSIONS));
}
async function restore($: EngineInterface) {
if ((await $.state.get(turnsRef)).value?.length) return; // a hot reload keeps $.state
const id = await $.session.id();
const snap = id
- ? ((await $.store.get(`session:${id}`)) as Record<string, never> | undefined)
+ ? ((await $.store.get(`usage:session:${id}`)) as Record<string, never> | undefined)
: undefined;
if (!snap) return;
await $.state.set(turnsRef, snap.turns ?? []);
diff --git a/examples/claude-code-usage-plugin/tests/sources.test.ts b/examples/claude-code-memory-plugin/mods/usage/sources.test.ts
similarity index 93%
rename from examples/claude-code-usage-plugin/tests/sources.test.ts
rename to examples/claude-code-memory-plugin/mods/usage/sources.test.ts
index ca005dd32..0cb0f38bd 100644
--- a/examples/claude-code-usage-plugin/tests/sources.test.ts
+++ b/examples/claude-code-memory-plugin/mods/usage/sources.test.ts
@@ -7,7 +7,7 @@ import {
summaryLine,
titleOf,
urisIn,
-} from "../hooks/sources";
+} from "./sources";
const EVENT = "viking://user/t/memories/events/2026/10/03/web版本未更新排查请求.md";
const PREF = "viking://user/t/memories/preferences/me/按钮状态.md";
@@ -83,6 +83,11 @@ describe("one answer", () => {
expect(titleOf(EVENT)).toBe("10/3 web版本未更新排查请求");
});
+ test("a title with a literal % does not throw", () => {
+ expect(titleOf("viking://resources/docs/50% off.md")).toBe("50% off");
+ expect(titleOf("viking://resources/docs/a%20b.md")).toBe("a b");
+ });
+
test("secrets are redacted", () => {
expect(redact("Bearer abcdefghijklmnopqrstuvwxyz sk-abcdefghijklmnopqrstuvwx")).toBe(
"Bearer [REDACTED] [REDACTED]",
diff --git a/examples/claude-code-usage-plugin/hooks/sources.ts b/examples/claude-code-memory-plugin/mods/usage/sources.ts
similarity index 96%
rename from examples/claude-code-usage-plugin/hooks/sources.ts
rename to examples/claude-code-memory-plugin/mods/usage/sources.ts
index 255675f6c..67ebc8fed 100644
--- a/examples/claude-code-usage-plugin/hooks/sources.ts
+++ b/examples/claude-code-memory-plugin/mods/usage/sources.ts
@@ -1,7 +1,7 @@
// Pure helpers: which viking:// URIs a recall block or a tool call names, which
// tool calls are OpenViking lookups, and what one answer consulted.
-import type { Lookup, Turn } from "../types";
+import type { Lookup, Turn } from "./types";
// A viking:// URI stops at whitespace, quotes, brackets or CJK punctuation.
const URI = /viking:\/\/(?:~|[A-Za-z][\w.-]*)(?:\/[^\s"'<>)\]`,,。;:!?、()《》“”]*)?/g;
@@ -144,9 +144,18 @@ const NOUN: Record<Group, [string, string]> = {
const plural = (n: number, [one, many]: [string, string]) => `${n} ${n === 1 ? one : many}`;
+// URIs can hold a literal "%" (a title like "50% off"), which decodeURIComponent rejects.
+function decodeUri(uri: string): string {
+ try {
+ return decodeURIComponent(uri);
+ } catch {
+ return uri;
+ }
+}
+
// A short name for a source: its file name, with the date of a dated event.
export function titleOf(uri: string): string {
- const parts = decodeURIComponent(uri).split("/").filter(Boolean);
+ const parts = decodeUri(uri).split("/").filter(Boolean);
let name = (parts.at(-1) ?? uri).replace(/\.md$/, "");
if (/^(\.|summary$|index$|prompts$)/i.test(name)) name = `${parts.at(-2) ?? ""}/${name}`;
const d = /\/(\d{4})\/(\d{2})\/(\d{2})\//.exec(uri);
diff --git a/examples/claude-code-memory-plugin/mods/usage/tsconfig.json b/examples/claude-code-memory-plugin/mods/usage/tsconfig.json
new file mode 100644
index 000000000..f7c64afd7
--- /dev/null
+++ b/examples/claude-code-memory-plugin/mods/usage/tsconfig.json
@@ -0,0 +1,4 @@
+{
+ "extends": "../../.claude-plugin/types/tsconfig.json",
+ "include": ["."]
+}
diff --git a/examples/claude-code-usage-plugin/types/index.d.ts b/examples/claude-code-memory-plugin/mods/usage/types.d.ts
similarity index 96%
rename from examples/claude-code-usage-plugin/types/index.d.ts
rename to examples/claude-code-memory-plugin/mods/usage/types.d.ts
index ecefaa8c0..f6f221a23 100644
--- a/examples/claude-code-usage-plugin/types/index.d.ts
+++ b/examples/claude-code-memory-plugin/mods/usage/types.d.ts
@@ -20,7 +20,7 @@ export type Reply = { id: string; n: number };
declare module "claude-code" {
interface PluginState {
- "ov-usage": {
+ "openviking-memory": {
// this session's answers, oldest first (last 50)
turns: Turn[];
replies: Reply[];
diff --git a/examples/claude-code-memory-plugin/package.json b/examples/claude-code-memory-plugin/package.json
index f85f6003e..d361bbbef 100644
--- a/examples/claude-code-memory-plugin/package.json
+++ b/examples/claude-code-memory-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "claude-code-openviking-memory",
- "version": "0.6.9",
+ "version": "0.7.0",
"description": "OpenViking memory plugin for Claude Code — semantic long-term memory",
"type": "module",
"scripts": {
diff --git a/examples/claude-code-usage-plugin/.claude-plugin/plugin.json b/examples/claude-code-usage-plugin/.claude-plugin/plugin.json
deleted file mode 100644
index fdc278a80..000000000
--- a/examples/claude-code-usage-plugin/.claude-plugin/plugin.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "name": "ov-usage",
- "version": "0.1.0",
- "description": "Shows which OpenViking sources each Claude Code answer consulted, as a card under the answer",
- "types": "./types/index.d.ts",
- "author": {
- "name": "OpenViking",
- "url": "https://github.com/volcengine/OpenViking"
- },
- "repository": "https://github.com/volcengine/OpenViking",
- "license": "Apache-2.0",
- "keywords": ["openviking", "memory", "observability", "context-engine"]
-}
diff --git a/examples/claude-code-usage-plugin/.gitignore b/examples/claude-code-usage-plugin/.gitignore
deleted file mode 100644
index 6ba649ab4..000000000
--- a/examples/claude-code-usage-plugin/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# Generated by Claude Code when it loads the plugin
-.claude-plugin/types/
diff --git a/examples/claude-code-usage-plugin/README.md b/examples/claude-code-usage-plugin/README.md
deleted file mode 100644
index aa7590441..000000000
--- a/examples/claude-code-usage-plugin/README.md
+++ /dev/null
@@ -1,61 +0,0 @@
-# OV-Usage
-
-English / [中文](./README_CN.md)
-
-OV-Usage adds a card under each Claude Code answer that lists the OpenViking sources the answer used. That covers what auto-recall added to the prompt, plus what Claude searched for and read on its own.
-
-The card is collapsed by default, so it takes one line:
-
-```
-OV · 14 sources · 6 past events · 5 work memories · 2 team docs · 1 skill · 1 read in full [Expand]
-```
-
-Expand it to see every source and Claude's own lookups:
-
-```
-OV · 14 sources · … · 1 read in full [Collapse]
- ◷ 10/3 发版检查清单补充 · found by Claude · read in full
- ⚙ openviking-release · auto-recalled
- ▤ lark-daemon · auto-recalled
- …
-Claude's own lookups
- ⌕ Searched “lark-daemon release” · 6 results
- ▤ Read 10/3 发版检查清单补充
-```
-
-- Groups: ★ preferences, ◷ past events, ◆ work memories (notes, lessons, your agents' memories), ▤ team docs, ⚙ skills.
-- **read in full**: Claude opened the file with `read`, either through the MCP tool or `ov read`. A search hit doesn't count.
-- An answer that used nothing from OpenViking gets no card.
-
-Expand or collapse a card with its `[Expand]` / `[Collapse]` button. You can also expand or collapse every card with `/openviking-usage expand` or `/openviking-usage collapse`.
-
-Labels are in English only.
-
-## Requirements
-
-- Claude Code 2.1.286 or newer. The plugin uses Claude Code's plugin hooks (`hooks.json` with `modules`), which are still early access. Without them, the plugin installs but shows nothing.
-- The OpenViking memory plugin (`openviking-memory@openviking`).
-
-## Install
-
-```bash
-claude plugin marketplace add https://raw.githubusercontent.com/volcengine/OpenViking/main/.claude-plugin/marketplace.json
-claude plugin install ov-usage@openviking
-```
-
-If you already added the marketplace, run `claude plugin marketplace update openviking` first. Then start a new session.
-
-## What it reads and stores
-
-- **Auto-recall**: the `<openviking-context>` block that openviking-memory's `UserPromptSubmit` hook adds to the prompt. OV-Usage reads the `uri` and `score` of each `<memory>` item, or the `viking://` URI on each line of the digest form. It reads no openviking-memory files or config. If openviking-memory changes this block's format, auto-recalled items stop showing.
-- **Claude's lookups**: OpenViking MCP tool calls (`read`, `search`, `find`, `grep`, `glob`, `list`, `tree`) and `ov` CLI calls through Bash (`read`, `cat`, `abstract`, `overview`, `find`, `search`, `grep`, `glob`, `ls`, `tree`). Writes and other commands are ignored.
-- **Stored** in Claude Code's plugin store, for the last 20 sessions: each answer's source URIs and scores, search queries (redacted, first 80 characters), and the transcript row id each card belongs to. That keeps cards in place after `claude --continue`. Shell commands and prompt text are not stored.
-
-The plugin makes no network calls and writes nothing to OpenViking. The card isn't sent to Claude, so it costs no tokens.
-
-## Development
-
-- `hooks/register.tsx`: the hooks and the card.
-- `hooks/sources.ts`: pure parsing: recall blocks, URIs in tool output, which tool calls are lookups, and what an answer consulted.
-- `tests/`: `claude plugin test examples/claude-code-usage-plugin`. These run on Claude Code's plugin test runner, not in the repository's Node CI.
-- `claude plugin validate examples/claude-code-usage-plugin` checks the plugin. After `claude --plugin-dir examples/claude-code-usage-plugin` has generated `.claude-plugin/types/`, `tsc -p examples/claude-code-usage-plugin` type-checks it.
diff --git a/examples/claude-code-usage-plugin/README_CN.md b/examples/claude-code-usage-plugin/README_CN.md
deleted file mode 100644
index e01ade8a4..000000000
--- a/examples/claude-code-usage-plugin/README_CN.md
+++ /dev/null
@@ -1,61 +0,0 @@
-# OV-Usage
-
-[English](./README.md) / 中文
-
-OV-Usage 在 Claude Code 每次回答下方加一张卡片,列出这次回答用到的 OpenViking 来源,包括自动召回加进提示的内容,以及 Claude 自己搜索、读取的内容。
-
-卡片默认折叠,只占一行:
-
-```
-OV · 14 sources · 6 past events · 5 work memories · 2 team docs · 1 skill · 1 read in full [Expand]
-```
-
-展开后列出全部来源和 Claude 自己的查询:
-
-```
-OV · 14 sources · … · 1 read in full [Collapse]
- ◷ 10/3 发版检查清单补充 · found by Claude · read in full
- ⚙ openviking-release · auto-recalled
- ▤ lark-daemon · auto-recalled
- …
-Claude's own lookups
- ⌕ Searched “lark-daemon release” · 6 results
- ▤ Read 10/3 发版检查清单补充
-```
-
-- 分组:★ 偏好,◷ 过往事件,◆ 工作记忆(笔记、经验、你的 agent 的记忆),▤ 团队文档,⚙ Skill。
-- **read in full**:Claude 用 `read`(MCP 工具或 `ov read`)打开了这个文件。只出现在搜索结果里的不算。
-- 没用到任何 OpenViking 内容的回答不显示卡片。
-
-用卡片上的 `[Expand]` / `[Collapse]` 按钮展开或折叠单张卡片;也可以用 `/openviking-usage expand` 或 `/openviking-usage collapse` 一次展开或折叠全部卡片。
-
-界面文字只有英文。
-
-## 前提
-
-- Claude Code 2.1.286 或更高版本。插件依赖 Claude Code 的插件 hooks(`hooks.json` 里的 `modules`),目前仍是 early access。没有这个能力时,插件能装上,但不显示任何内容。
-- 已安装 OpenViking 记忆插件(`openviking-memory@openviking`)。
-
-## 安装
-
-```bash
-claude plugin marketplace add https://raw.githubusercontent.com/volcengine/OpenViking/main/.claude-plugin/marketplace.json
-claude plugin install ov-usage@openviking
-```
-
-如果之前已经添加过这个 marketplace,先运行 `claude plugin marketplace update openviking`。装好后开一个新会话。
-
-## 读取和保存的内容
-
-- **自动召回**:openviking-memory 的 `UserPromptSubmit` hook 加进提示的 `<openviking-context>` 块。读取每个 `<memory>` 的 `uri` 和 `score`;digest 格式则读取每行里的 `viking://` URI。不读 openviking-memory 的任何文件或配置。如果 openviking-memory 改了这个块的格式,自动召回的条目就不会再显示。
-- **Claude 的查询**:OpenViking MCP 工具调用(`read`、`search`、`find`、`grep`、`glob`、`list`、`tree`),以及通过 Bash 调用的 `ov` CLI(`read`、`cat`、`abstract`、`overview`、`find`、`search`、`grep`、`glob`、`ls`、`tree`)。写入和其他命令不计入。
-- **保存**在 Claude Code 的插件存储里,保留最近 20 个会话:每次回答的来源 URI 和分数、搜索词(已脱敏,最多 80 字符)、卡片所在的对话行 id,这样 `claude --continue` 之后卡片还在原位。不保存 shell 命令和提示原文。
-
-插件不发网络请求,不向 OpenViking 写任何内容。卡片不会发给 Claude,不消耗 token。
-
-## 开发
-
-- `hooks/register.tsx`:hooks 和卡片。
-- `hooks/sources.ts`:纯解析逻辑,包括召回块、工具输出里的 URI、哪些工具调用算查询,以及一次回答用到了什么。
-- `tests/`:`claude plugin test examples/claude-code-usage-plugin`。这些测试跑在 Claude Code 的插件测试器上,不在仓库的 Node CI 里。
-- `claude plugin validate examples/claude-code-usage-plugin` 校验插件。用 `claude --plugin-dir examples/claude-code-usage-plugin` 启动一次、生成 `.claude-plugin/types/` 后,可以用 `tsc -p examples/claude-code-usage-plugin` 做类型检查。
diff --git a/examples/claude-code-usage-plugin/hooks/hooks.json b/examples/claude-code-usage-plugin/hooks/hooks.json
deleted file mode 100644
index 5a63f6495..000000000
--- a/examples/claude-code-usage-plugin/hooks/hooks.json
+++ /dev/null
@@ -1 +0,0 @@
-{ "modules": ["./register.tsx"] }
diff --git a/examples/claude-code-usage-plugin/package.json b/examples/claude-code-usage-plugin/package.json
deleted file mode 100644
index 66f8f0e98..000000000
--- a/examples/claude-code-usage-plugin/package.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "name": "ov-usage",
- "private": true,
- "description": "Opt-in Claude Code plugin showing which OpenViking sources each answer consulted",
- "license": "Apache-2.0",
- "scripts": {
- "check": "claude plugin validate . && tsc -p .",
- "format": "prettier --no-config --print-width 100 --write \"hooks/*.ts\" \"hooks/*.tsx\" \"tests/*.ts\" \"types/*.ts\"",
- "test": "claude plugin test ."
- }
-}
diff --git a/examples/claude-code-usage-plugin/tsconfig.json b/examples/claude-code-usage-plugin/tsconfig.json
deleted file mode 100644
index 8681ec01d..000000000
--- a/examples/claude-code-usage-plugin/tsconfig.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "extends": "./.claude-plugin/types/tsconfig.json"
-}
diff --git a/examples/memory-plugin-shared/sync.mjs b/examples/memory-plugin-shared/sync.mjs
index a09615ffa..58ac1a31e 100644
--- a/examples/memory-plugin-shared/sync.mjs
+++ b/examples/memory-plugin-shared/sync.mjs
@@ -310,6 +310,21 @@ export async function assembledClosure() {
return sharedClosure([...seeds]);
}
+/**
+ * Whether TypeScript in the plugin imports the shared copies, so they need
+ * their `.d.mts` declarations. TypeScript that imports none of them (a Claude
+ * Code hooks module beside plain `.mjs` hooks) does not make the target typed.
+ */
+async function importsFromTypeScript(files, dir) {
+ for (const file of files) {
+ if (!file.endsWith(".ts") && !file.endsWith(".mts") && !file.endsWith(".tsx")) continue;
+ for (const spec of importSpecifiers(await readFile(file, "utf-8"))) {
+ if (spec.startsWith(".") && resolvePath(dirname(file), spec).startsWith(dir + sep)) return true;
+ }
+ }
+ return false;
+}
+
/** Every target with the file set its own imports resolve to. */
export async function resolveTargets() {
const resolved = [];
@@ -323,7 +338,7 @@ export async function resolveTargets() {
resolved.push({
...target,
files: await sharedClosure(seeds),
- typed: own.some((file) => file.endsWith(".ts") || file.endsWith(".mts")),
+ typed: await importsFromTypeScript(own, target.dir),
});
}
return resolved;