Skip to content

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

fix(agent-hook): stamp the effective peer into captured messages (#5343)

Zayn Jarvis20a97022d522
diff --git a/examples/agent-hook-plugin/hosts/cursor.mjs b/examples/agent-hook-plugin/hosts/cursor.mjs
index 33a4aefc3..d21470c67 100644
--- a/examples/agent-hook-plugin/hosts/cursor.mjs
+++ b/examples/agent-hook-plugin/hosts/cursor.mjs
@@ -33,7 +33,7 @@ async function captureTranscript(ctx, state) {
}
toSend.push({ hash, turn: kept[0] });
}
- const result = await addAgentMessages(ctx.fetchJSON, ctx.sessionId, toSend.map((item) => item.turn));
+ const result = await addAgentMessages(ctx.fetchJSON, ctx.sessionId, toSend.map((item) => item.turn), ctx.peerId);
const captured = result.sent + result.queued;
for (const item of toSend.slice(0, captured)) capturedHashes.add(item.hash);
return {
diff --git a/examples/agent-hook-plugin/hosts/cursor/openviking.integration.json b/examples/agent-hook-plugin/hosts/cursor/openviking.integration.json
index feb27ace6..3771a413b 100644
--- a/examples/agent-hook-plugin/hosts/cursor/openviking.integration.json
+++ b/examples/agent-hook-plugin/hosts/cursor/openviking.integration.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
- "version": "0.5.0",
+ "version": "0.5.1",
"clients": [
"cursor"
],
diff --git a/examples/agent-hook-plugin/hosts/kimicode.mjs b/examples/agent-hook-plugin/hosts/kimicode.mjs
index e3523dbcf..3402c65c0 100644
--- a/examples/agent-hook-plugin/hosts/kimicode.mjs
+++ b/examples/agent-hook-plugin/hosts/kimicode.mjs
@@ -65,7 +65,7 @@ export const kimicode = {
const plan = buildIncrementalCapturePlan(transcript.turns, state, ctx.cfg);
if (plan.toSend.length === 0) return null;
- const result = await addAgentMessages(ctx.fetchJSON, ctx.sessionId, plan.payloads);
+ const result = await addAgentMessages(ctx.fetchJSON, ctx.sessionId, plan.payloads, ctx.peerId);
const next = applyIncrementalCaptureResult(state, plan, result, cleanKimicodeText);
let capturedSinceCommit = Number(state.capturedSinceCommit || 0) + next.captured;
if (shouldCommitKimicodeCapture(event, ctx.cfg, state.capturedSinceCommit, next.captured)) {
diff --git a/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json b/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json
index ba53fa7bc..04ff3ac14 100644
--- a/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json
+++ b/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
- "version": "0.5.0",
+ "version": "0.5.1",
"clients": [
"kimicode"
],
diff --git a/examples/agent-hook-plugin/hosts/trae.mjs b/examples/agent-hook-plugin/hosts/trae.mjs
index 292952336..521e4de7b 100644
--- a/examples/agent-hook-plugin/hosts/trae.mjs
+++ b/examples/agent-hook-plugin/hosts/trae.mjs
@@ -42,7 +42,7 @@ export const trae = {
}
toSend.push({ hash, turn: kept[0] });
}
- const result = await addAgentMessages(ctx.fetchJSON, ctx.sessionId, toSend.map((item) => item.turn));
+ const result = await addAgentMessages(ctx.fetchJSON, ctx.sessionId, toSend.map((item) => item.turn), ctx.peerId);
const captured = result.sent + result.queued;
for (const item of toSend.slice(0, captured)) hashes.add(item.hash);
let nextCount = Number(state.capturedSinceCommit || 0) + captured;
diff --git a/examples/agent-hook-plugin/hosts/trae/openviking.integration.json b/examples/agent-hook-plugin/hosts/trae/openviking.integration.json
index d7b86edaf..ff3c4d762 100644
--- a/examples/agent-hook-plugin/hosts/trae/openviking.integration.json
+++ b/examples/agent-hook-plugin/hosts/trae/openviking.integration.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
- "version": "0.5.0",
+ "version": "0.5.1",
"clients": [
"trae",
"trae-cn"
diff --git a/examples/agent-hook-plugin/hosts/zcode.mjs b/examples/agent-hook-plugin/hosts/zcode.mjs
index d493787f2..86554d420 100644
--- a/examples/agent-hook-plugin/hosts/zcode.mjs
+++ b/examples/agent-hook-plugin/hosts/zcode.mjs
@@ -45,7 +45,7 @@ export const zcode = {
// could be a Stop with no new content, or a race with UserPromptSubmit).
if (plan.toSend.length === 0) return null;
- const result = await addAgentMessages(ctx.fetchJSON, ctx.sessionId, plan.payloads);
+ const result = await addAgentMessages(ctx.fetchJSON, ctx.sessionId, plan.payloads, ctx.peerId);
const { captured, ...nextState } = applyZcodeCaptureResult(state, plan, result);
let nextCount = Number(state.capturedSinceCommit || 0) + captured;
if (captured > 0) {
diff --git a/examples/agent-hook-plugin/hosts/zcode/openviking.integration.json b/examples/agent-hook-plugin/hosts/zcode/openviking.integration.json
index c44fbac85..8b43f5570 100644
--- a/examples/agent-hook-plugin/hosts/zcode/openviking.integration.json
+++ b/examples/agent-hook-plugin/hosts/zcode/openviking.integration.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
- "version": "0.5.0",
+ "version": "0.5.1",
"clients": [
"zcode"
],
diff --git a/examples/agent-hook-plugin/plugin.json b/examples/agent-hook-plugin/plugin.json
index 7e778e8be..885b00edf 100644
--- a/examples/agent-hook-plugin/plugin.json
+++ b/examples/agent-hook-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "agent-hook-plugin",
- "version": "0.5.0",
+ "version": "0.5.1",
"description": "Long-term semantic memory for Cursor, TRAE, TRAE CN, ZCode and Kimi Code — powered by OpenViking. Auto-recall relevant memories and capture the conversation as it happens.",
"author": {
"name": "OpenViking",
diff --git a/examples/agent-hook-plugin/scripts/hook.mjs b/examples/agent-hook-plugin/scripts/hook.mjs
index 8cb393549..baf0a3796 100644
--- a/examples/agent-hook-plugin/scripts/hook.mjs
+++ b/examples/agent-hook-plugin/scripts/hook.mjs
@@ -172,7 +172,8 @@ async function main() {
cfg = resolved;
const payload = normalize(input);
if (!stageName) return "";
- const baseFetchJSON = makeAgentFetchJSON(cfg, cwd).fetchJSON;
+ const agent = makeAgentFetchJSON(cfg, cwd);
+ const baseFetchJSON = agent.fetchJSON;
const ctx = {
cfg,
cwd,
@@ -180,6 +181,9 @@ async function main() {
nativeSessionId: resolveNativeSessionId(payload),
sessionId: deriveAgentSessionId(host.prefix, payload),
fetchJSON: withRequestBudget(baseFetchJSON, host.requestBudgets?.[event]),
+ // The peer the actor-peer header already carries, stamped into captured
+ // messages because session writes read it from the body only.
+ get peerId() { return agent.effectivePeer.peerId; },
log,
logError,
};
diff --git a/examples/agent-hook-plugin/tests/cursor.test.mjs b/examples/agent-hook-plugin/tests/cursor.test.mjs
index 033c78501..6d40c0b90 100644
--- a/examples/agent-hook-plugin/tests/cursor.test.mjs
+++ b/examples/agent-hook-plugin/tests/cursor.test.mjs
@@ -134,9 +134,10 @@ test("Cursor injects recall before the request and Stop captures transcript delt
runHook("stop", { ...base, transcript_path: transcript }, env),
runHook("stop", { ...base, transcript_path: transcript }, env),
]);
+ // Session writes ignore the actor-peer header, so the peer rides in the body.
assert.deepEqual(messages, [
- { role: "user", content: "question" },
- { role: "assistant", content: "answer" },
+ { role: "user", content: "question", peer_id: "github.com-acme-cursor-project" },
+ { role: "assistant", content: "answer", peer_id: "github.com-acme-cursor-project" },
]);
} finally {
server.close();
diff --git a/examples/claude-code-memory-plugin/.claude-plugin/plugin.json b/examples/claude-code-memory-plugin/.claude-plugin/plugin.json
index bb849192b..ef22bbe69 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.1",
+ "version": "0.6.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/package.json b/examples/claude-code-memory-plugin/package.json
index aee029ef6..91336b804 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.1",
+ "version": "0.6.2",
"description": "OpenViking memory plugin for Claude Code — semantic long-term memory",
"type": "module",
"scripts": {
diff --git a/examples/claude-code-memory-plugin/scripts/shared/agent-hook-runtime.mjs b/examples/claude-code-memory-plugin/scripts/shared/agent-hook-runtime.mjs
index 1fc615672..6ba24c4bb 100644
--- a/examples/claude-code-memory-plugin/scripts/shared/agent-hook-runtime.mjs
+++ b/examples/claude-code-memory-plugin/scripts/shared/agent-hook-runtime.mjs
@@ -220,8 +220,16 @@ export async function addAgentMessage(fetchJSON, sessionId, payload) {
return notePendingWrite("addMessage", sessionId, payload, result);
}
-export async function addAgentMessages(fetchJSON, sessionId, payloads) {
- return sendSessionMessages(fetchJSON, sessionId, payloads, { enqueueOnRetryable: true });
+/**
+ * Session routes attribute a message by its body `peer_id` alone: the
+ * actor-peer header scopes reads, not session writes. A payload that already
+ * names its peer keeps it; an empty `peerId` (peer mode off) stamps nothing.
+ */
+export async function addAgentMessages(fetchJSON, sessionId, payloads, peerId = "") {
+ const stamped = peerId
+ ? payloads.map((payload) => (payload.peer_id ? payload : { ...payload, peer_id: peerId }))
+ : payloads;
+ return sendSessionMessages(fetchJSON, sessionId, stamped, { enqueueOnRetryable: true });
}
export async function commitAgentSession(fetchJSON, sessionId, log = () => {}, payload = {}) {
diff --git a/examples/codex-memory-plugin/.codex-plugin/plugin.json b/examples/codex-memory-plugin/.codex-plugin/plugin.json
index 3b0979f44..dcdf8e13b 100644
--- a/examples/codex-memory-plugin/.codex-plugin/plugin.json
+++ b/examples/codex-memory-plugin/.codex-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "openviking-memory",
- "version": "0.10.1",
+ "version": "0.10.2",
"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",
diff --git a/examples/codex-memory-plugin/scripts/shared/agent-hook-runtime.mjs b/examples/codex-memory-plugin/scripts/shared/agent-hook-runtime.mjs
index 1fc615672..6ba24c4bb 100644
--- a/examples/codex-memory-plugin/scripts/shared/agent-hook-runtime.mjs
+++ b/examples/codex-memory-plugin/scripts/shared/agent-hook-runtime.mjs
@@ -220,8 +220,16 @@ export async function addAgentMessage(fetchJSON, sessionId, payload) {
return notePendingWrite("addMessage", sessionId, payload, result);
}
-export async function addAgentMessages(fetchJSON, sessionId, payloads) {
- return sendSessionMessages(fetchJSON, sessionId, payloads, { enqueueOnRetryable: true });
+/**
+ * Session routes attribute a message by its body `peer_id` alone: the
+ * actor-peer header scopes reads, not session writes. A payload that already
+ * names its peer keeps it; an empty `peerId` (peer mode off) stamps nothing.
+ */
+export async function addAgentMessages(fetchJSON, sessionId, payloads, peerId = "") {
+ const stamped = peerId
+ ? payloads.map((payload) => (payload.peer_id ? payload : { ...payload, peer_id: peerId }))
+ : payloads;
+ return sendSessionMessages(fetchJSON, sessionId, stamped, { enqueueOnRetryable: true });
}
export async function commitAgentSession(fetchJSON, sessionId, log = () => {}, payload = {}) {
diff --git a/examples/dsh-memory-plugin/config.mjs b/examples/dsh-memory-plugin/config.mjs
index bcd071309..852211c32 100644
--- a/examples/dsh-memory-plugin/config.mjs
+++ b/examples/dsh-memory-plugin/config.mjs
@@ -1,7 +1,7 @@
import { buildPluginConfig } from "./shared/plugin-config.mjs";
import { loadCredentialFiles } from "./shared/credentials.mjs";
-export const PLUGIN_VERSION = "0.5.2";
+export const PLUGIN_VERSION = "0.5.3";
/**
* Namespace for the bridged OpenViking MCP tools. DSH publishes every MCP tool
diff --git a/examples/dsh-memory-plugin/package-lock.json b/examples/dsh-memory-plugin/package-lock.json
index 672d68960..79d6131ca 100644
--- a/examples/dsh-memory-plugin/package-lock.json
+++ b/examples/dsh-memory-plugin/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@openviking/dsh-memory-plugin",
- "version": "0.5.2",
+ "version": "0.5.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@openviking/dsh-memory-plugin",
- "version": "0.5.2",
+ "version": "0.5.3",
"license": "Apache-2.0",
"devDependencies": {
"@deepseek-ai/dsh-llm": "0.1.0-rc.6",
diff --git a/examples/dsh-memory-plugin/package.json b/examples/dsh-memory-plugin/package.json
index a4681f2fe..f5ecea7b5 100644
--- a/examples/dsh-memory-plugin/package.json
+++ b/examples/dsh-memory-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@openviking/dsh-memory-plugin",
- "version": "0.5.2",
+ "version": "0.5.3",
"description": "OpenViking memory and context bundle for DeepSeek Harness",
"type": "module",
"main": "index.mjs",
diff --git a/examples/memory-plugin-shared/agent-hook-runtime.test.mjs b/examples/memory-plugin-shared/agent-hook-runtime.test.mjs
index e1bae1338..c20be6e47 100644
--- a/examples/memory-plugin-shared/agent-hook-runtime.test.mjs
+++ b/examples/memory-plugin-shared/agent-hook-runtime.test.mjs
@@ -9,6 +9,7 @@ import { filterCaptureTurns } from "./lib/capture-utils.mjs";
import { expectExit, runHookScript, withMockOpenViking, writeJson } from "./testing/support.mjs";
import {
+ addAgentMessages,
commitAgentSession,
loadAgentHookConfig,
makeAgentFetchJSON,
@@ -433,3 +434,23 @@ test("the envelope is written once when the callback answers early", async () =>
assert.deepEqual(seen.envelopes, ["detached"]);
});
+
+test("captured messages carry the effective peer in the body, and none when peer mode is off", async () => {
+ const sent = [];
+ const fetchJSON = async (_path, init) => {
+ sent.push(JSON.parse(init.body).messages);
+ return { ok: true, status: 200, result: { added: -1 } };
+ };
+ await addAgentMessages(fetchJSON, "s1", [
+ { role: "user", content: "a" },
+ { role: "assistant", content: "b", peer_id: "explicit" },
+ ], "workspace-peer");
+ await addAgentMessages(fetchJSON, "s1", [{ role: "user", content: "c" }], "");
+ assert.deepEqual(sent, [
+ [
+ { role: "user", content: "a", peer_id: "workspace-peer" },
+ { role: "assistant", content: "b", peer_id: "explicit" },
+ ],
+ [{ role: "user", content: "c" }],
+ ]);
+});
diff --git a/examples/memory-plugin-shared/lib/agent-hook-runtime.mjs b/examples/memory-plugin-shared/lib/agent-hook-runtime.mjs
index 94acb0584..d5242edd4 100644
--- a/examples/memory-plugin-shared/lib/agent-hook-runtime.mjs
+++ b/examples/memory-plugin-shared/lib/agent-hook-runtime.mjs
@@ -219,8 +219,16 @@ export async function addAgentMessage(fetchJSON, sessionId, payload) {
return notePendingWrite("addMessage", sessionId, payload, result);
}
-export async function addAgentMessages(fetchJSON, sessionId, payloads) {
- return sendSessionMessages(fetchJSON, sessionId, payloads, { enqueueOnRetryable: true });
+/**
+ * Session routes attribute a message by its body `peer_id` alone: the
+ * actor-peer header scopes reads, not session writes. A payload that already
+ * names its peer keeps it; an empty `peerId` (peer mode off) stamps nothing.
+ */
+export async function addAgentMessages(fetchJSON, sessionId, payloads, peerId = "") {
+ const stamped = peerId
+ ? payloads.map((payload) => (payload.peer_id ? payload : { ...payload, peer_id: peerId }))
+ : payloads;
+ return sendSessionMessages(fetchJSON, sessionId, stamped, { enqueueOnRetryable: true });
}
export async function commitAgentSession(fetchJSON, sessionId, log = () => {}, payload = {}) {
diff --git a/examples/opencode-plugin/package.json b/examples/opencode-plugin/package.json
index 670a6728b..9f7c84166 100644
--- a/examples/opencode-plugin/package.json
+++ b/examples/opencode-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@openviking/opencode-plugin",
- "version": "0.4.1",
+ "version": "0.4.2",
"author": "@openviking",
"description": "Unified OpenCode plugin for OpenViking repository retrieval and long-term memory",
"type": "module",
diff --git a/examples/pi-coding-agent-extension/package-lock.json b/examples/pi-coding-agent-extension/package-lock.json
index 8ecdab663..56f992790 100644
--- a/examples/pi-coding-agent-extension/package-lock.json
+++ b/examples/pi-coding-agent-extension/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "openviking-pi-extension",
- "version": "0.4.2",
+ "version": "0.4.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openviking-pi-extension",
- "version": "0.4.2",
+ "version": "0.4.3",
"dependencies": {
"@modelcontextprotocol/client": "2.0.0"
},
diff --git a/examples/pi-coding-agent-extension/package.json b/examples/pi-coding-agent-extension/package.json
index 519dbf02b..67cd32a82 100644
--- a/examples/pi-coding-agent-extension/package.json
+++ b/examples/pi-coding-agent-extension/package.json
@@ -1,6 +1,6 @@
{
"name": "openviking-pi-extension",
- "version": "0.4.2",
+ "version": "0.4.3",
"description": "OpenViking memory and context extension for the pi coding agent",
"private": true,
"type": "module",