Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(memory-plugin): show usage cards in the desktop app (#5694)
Zhou Wai6cd2bdd37fff
diff --git a/examples/claude-code-memory-plugin/.claude-plugin/plugin.json b/examples/claude-code-memory-plugin/.claude-plugin/plugin.jsonindex bbde0b32f..42e17957e 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.7.1",+ "version": "0.7.2","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",diff --git a/examples/claude-code-memory-plugin/README.md b/examples/claude-code-memory-plugin/README.mdindex 0e753a11f..f92d62b55 100644--- a/examples/claude-code-memory-plugin/README.md+++ b/examples/claude-code-memory-plugin/README.md@@ -453,7 +453,7 @@ On builds between the first modules release and 2.1.286 with modules switched on**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.+It keeps each answer's source URIs, scores, redacted search queries, and the transcript row id and a hash of the reply text it sits under (the desktop finds a card's reply by that hash) 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.diff --git a/examples/claude-code-memory-plugin/README_CN.md b/examples/claude-code-memory-plugin/README_CN.mdindex 0ba506bda..e180d9267 100644--- a/examples/claude-code-memory-plugin/README_CN.md+++ b/examples/claude-code-memory-plugin/README_CN.md@@ -403,7 +403,7 @@ Claude's own lookups**数据。** 模块读取本插件 `UserPromptSubmit` hook 返回的 `<openviking-context>` 块,以及 Claude 发起的 OpenViking MCP 调用和 `ov` CLI 调用。它不发网络请求,不向 OpenViking 写任何内容。-它在 Claude Code 的插件存储里保存每次回答的来源 URI、分数、脱敏后的搜索词和卡片所在的对话行 id,保留最近 20 个会话,所以 `claude --continue` 之后卡片还在。不保存 shell 命令和提示原文。卡片不会发给 Claude,不消耗 token。+它在 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` 做类型检查。diff --git a/examples/claude-code-memory-plugin/mods/usage/register.tsx b/examples/claude-code-memory-plugin/mods/usage/register.tsxindex dcd1b9afb..42189f486 100644--- a/examples/claude-code-memory-plugin/mods/usage/register.tsx+++ b/examples/claude-code-memory-plugin/mods/usage/register.tsx@@ -5,6 +5,7 @@ import {classifyCall,consulted,groupOf,+ hashText,parseRecall,summaryLine,titleOf,@@ -209,13 +210,16 @@ export const register: Register = (on) => {const res = await next(e);if (res.deny !== undefined || e.agentId || e.door !== "response") return res;await safely($, "record reply", async () => {- const hasText = (res.message.content ?? []).some(- (b) => b && typeof b === "object" && "type" in b && b.type === "text",+ const texts = (res.message.content ?? []).filter(+ (b): b is { type: "text"; text: string } =>+ !!b && typeof b === "object" && "type" in b && b.type === "text" && "text" in b,);- const turn = hasText ? await lastTurn($) : undefined;- if (turn) {+ const last = texts.at(-1);+ const turn = last ? await lastTurn($) : undefined;+ if (last && turn) {const { value: list = [] } = await $.state.get(repliesRef);- const kept = [...list.filter((r) => r.n !== turn.n), { id: res.uuid, n: turn.n }];+ const reply = { id: res.uuid, n: turn.n, text: hashText(last.text) };+ const kept = [...list.filter((r) => r.n !== turn.n), reply];await $.state.set(repliesRef, kept.slice(-MAX_TURNS));}});@@ -231,7 +235,13 @@ export const register: Register = (on) => {on("ui.render", { component: "AssistantMessage" }, async ($, e, next) => {const below = await safely($, "draw card", async () => {const { value: replies = [] } = await $.state.get(repliesRef);- const n = replies.find((r) => r.id === e.requestId)?.n;+ // The terminal names the row by its uuid; the desktop by API message id, so+ // fall back to the reply's text.+ const text = typeof e.props.text === "string" ? hashText(e.props.text) : undefined;+ const n = (+ replies.find((r) => r.id === e.requestId) ??+ (text ? replies.find((r) => r.text === text) : undefined)+ )?.n;const { value: turns = [] } = await $.state.get(turnsRef);const turn = n === undefined ? undefined : turns.find((t) => t.n === n);return turn ? await card($, e, turn) : null;diff --git a/examples/claude-code-memory-plugin/mods/usage/sources.test.ts b/examples/claude-code-memory-plugin/mods/usage/sources.test.tsindex 0cb0f38bd..48615fc23 100644--- a/examples/claude-code-memory-plugin/mods/usage/sources.test.ts+++ b/examples/claude-code-memory-plugin/mods/usage/sources.test.ts@@ -2,6 +2,7 @@ import { describe, expect, test } from "claude-code/testing";import {classifyCall,consulted,+ hashText,parseRecall,redact,summaryLine,@@ -94,3 +95,12 @@ describe("one answer", () => {);});});++describe("reply fingerprint", () => {+ test("ignores surrounding whitespace, tells different replies apart, keeps no text", () => {+ const reply = "L0 is the abstract, L1 the overview.";+ expect(hashText(`\n${reply} `)).toBe(hashText(reply));+ expect(hashText(reply)).not.toBe(hashText("L0 is the abstract, L1 the overview!"));+ expect(hashText(reply)).not.toContain("abstract");+ });+});diff --git a/examples/claude-code-memory-plugin/mods/usage/sources.ts b/examples/claude-code-memory-plugin/mods/usage/sources.tsindex 67ebc8fed..dfda61f86 100644--- a/examples/claude-code-memory-plugin/mods/usage/sources.ts+++ b/examples/claude-code-memory-plugin/mods/usage/sources.ts@@ -200,3 +200,12 @@ export function summaryLine(c: ReturnType<typeof consulted>): string {.filter(Boolean).join(" · ");}++// A short fingerprint of a reply's text, so the card can find its reply where the+// surface names rows by API message id (the desktop) without storing the text.+export function hashText(s: string): string {+ let h = 5381;+ const t = s.trim();+ for (let i = 0; i < t.length; i++) h = ((h << 5) + h + t.charCodeAt(i)) | 0;+ return `${t.length}:${(h >>> 0).toString(36)}`;+}diff --git a/examples/claude-code-memory-plugin/mods/usage/types.d.ts b/examples/claude-code-memory-plugin/mods/usage/types.d.tsindex f6f221a23..2d3cff53a 100644--- a/examples/claude-code-memory-plugin/mods/usage/types.d.ts+++ b/examples/claude-code-memory-plugin/mods/usage/types.d.ts@@ -15,8 +15,9 @@ export type Turn = {lookups: Lookup[];};-// The transcript row an answer's card is drawn under, by its row id.-export type Reply = { id: string; n: number };+// The transcript row an answer's card is drawn under: its row id (the terminal's+// requestId) and a hash of its text, since the desktop names rows by API message id.+export type Reply = { id: string; n: number; text?: string };declare module "claude-code" {interface PluginState {diff --git a/examples/claude-code-memory-plugin/package.json b/examples/claude-code-memory-plugin/package.jsonindex 9c224d0b7..237bd5a6c 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.7.1",+ "version": "0.7.2","description": "OpenViking memory plugin for Claude Code — semantic long-term memory","type": "module","scripts": {