Skip to content

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

fix(plugins): forward recall exclusions through agent hooks (#5616)

LI35fd8c8b9b86
diff --git a/examples/agent-hook-plugin/tests/zcode.test.mjs b/examples/agent-hook-plugin/tests/zcode.test.mjs
index 2111a4566..eb40cec4f 100644
--- a/examples/agent-hook-plugin/tests/zcode.test.mjs
+++ b/examples/agent-hook-plugin/tests/zcode.test.mjs
@@ -1,12 +1,107 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
+import { rm } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import test from "node:test";
import { evaluateHostUriGuard } from "../scripts/uri-guard.mjs";
+import {
+ expectExit,
+ readRequestBody,
+ runHookScript,
+ scrubOpenVikingEnv,
+ withMockOpenViking,
+ writeCredentialFiles,
+ writeJson,
+} from "../../memory-plugin-shared/testing/support.mjs";
const PLUGIN_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
+const RECALL_DOCUMENTS = [
+ { uri: "viking://agent/skills/noisy/SKILL.md", category: "skills", text: "EXCLUDED_SKILL_DOCUMENT" },
+ { uri: "viking://user/resources/project/README.md", category: "resources", text: "NORMAL_PROJECT_DOCUMENT" },
+];
+
+for (const scenario of [
+ { name: "no recall exclusion configured", excludeUris: undefined },
+ { name: "an empty recall exclusion list", excludeUris: [] },
+ { name: "an exact skill URI excluded", excludeUris: [RECALL_DOCUMENTS[0].uri] },
+ { name: "the exclusion retargeted to the ordinary document", excludeUris: [RECALL_DOCUMENTS[1].uri] },
+]) {
+ test(`ZCode prompt recall injects the configured documents with ${scenario.name}`, async () => {
+ const restoreEnv = scrubOpenVikingEnv();
+ const requestBodies = [];
+ try {
+ await withMockOpenViking(async (req, res) => {
+ assert.equal(req.method, "POST");
+ assert.equal(req.url, "/api/v1/search/search");
+ const body = await readRequestBody(req);
+ requestBodies.push(body);
+ assert.equal(body.mode, "context");
+ assert.equal(body.query, "What project setting should I use?");
+ assert.equal(body.session_id, "zc-recall-exclusion-session");
+ assert.equal(body.peer_scope, "actor");
+ // This fixture implements only exact URI membership, not subtree filtering.
+ const entries = RECALL_DOCUMENTS.filter((entry) => !body.exclude_uris?.includes(entry.uri));
+ writeJson(res, {
+ status: "ok",
+ result: { rendered: entries.map((entry) => entry.text).join("\n"), entries, stats: { used_tokens: 20 } },
+ });
+ }, async (baseUrl, requests) => {
+ const settings = {
+ recallPeerScope: "actor",
+ recallCompress: "off",
+ recallQueryExpansion: "off",
+ recallDedupTurns: 0,
+ };
+ if (scenario.excludeUris !== undefined) settings.recallExcludeUris = scenario.excludeUris;
+ const files = await writeCredentialFiles("ov-zcode-recall-exclude-", {
+ ovcli: { url: baseUrl, api_key: "", plugin: { zcode: settings } },
+ ov: {},
+ });
+ try {
+ const result = expectExit(await runHookScript(join(PLUGIN_ROOT, "scripts", "hook.mjs"), {
+ argv: ["user-prompt-submit", "zcode"],
+ input: {
+ prompt: "What project setting should I use?",
+ sessionId: "recall-exclusion-session",
+ request_id: "recall-exclusion-prompt",
+ cwd: files.dir,
+ },
+ cwd: files.dir,
+ env: {
+ ...files.env,
+ OPENVIKING_PEER_ID: "fixture-peer",
+ OPENVIKING_HOOK_STATE_DIR: join(files.dir, "hook-state"),
+ OPENVIKING_STATE_DIR: join(files.dir, "state"),
+ },
+ }));
+ assert.equal(requests.length, 1, "a successful context response must not use retrieval fallbacks");
+ const output = JSON.parse(result.stdout);
+ assert.equal(output.hookSpecificOutput.hookEventName, "UserPromptSubmit");
+ const block = output.hookSpecificOutput.additionalContext;
+ for (const entry of RECALL_DOCUMENTS) {
+ assert.equal(
+ block.includes(entry.text),
+ !scenario.excludeUris?.includes(entry.uri),
+ `injected context should respect the exact exclusion for ${entry.uri}`,
+ );
+ }
+ assert.deepEqual(
+ requestBodies[0].exclude_uris,
+ scenario.excludeUris?.length ? scenario.excludeUris : undefined,
+ "the configured exact URI must reach the context-mode HTTP request",
+ );
+ } finally {
+ await rm(files.dir, { recursive: true, force: true });
+ }
+ });
+ } finally {
+ restoreEnv();
+ }
+ });
+}
+
// ---------------------------------------------------------------------------
// URI Guard output schema (the #1 silent-failure mode in the adversarial review)
// ZCode's strict JSON schema rejects any unrecognized key. These tests assert
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 6ba24c4bb..2e1d04421 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
@@ -278,6 +278,7 @@ export async function recallForPrompt(fetchJSON, cfg, prompt, cwd, log = () => {
// Passing the OV session id is what turns on server-side query expansion
// and the cross-turn dedup ledger for these thin harnesses.
sessionId: options.sessionId || "",
+ excludeUris: cfg.recallExcludeUris,
log,
});
}
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 6ba24c4bb..2e1d04421 100644
--- a/examples/codex-memory-plugin/scripts/shared/agent-hook-runtime.mjs
+++ b/examples/codex-memory-plugin/scripts/shared/agent-hook-runtime.mjs
@@ -278,6 +278,7 @@ export async function recallForPrompt(fetchJSON, cfg, prompt, cwd, log = () => {
// Passing the OV session id is what turns on server-side query expansion
// and the cross-turn dedup ledger for these thin harnesses.
sessionId: options.sessionId || "",
+ excludeUris: cfg.recallExcludeUris,
log,
});
}
diff --git a/examples/memory-plugin-shared/lib/agent-hook-runtime.mjs b/examples/memory-plugin-shared/lib/agent-hook-runtime.mjs
index d5242edd4..ad6471951 100644
--- a/examples/memory-plugin-shared/lib/agent-hook-runtime.mjs
+++ b/examples/memory-plugin-shared/lib/agent-hook-runtime.mjs
@@ -277,6 +277,7 @@ export async function recallForPrompt(fetchJSON, cfg, prompt, cwd, log = () => {
// Passing the OV session id is what turns on server-side query expansion
// and the cross-turn dedup ledger for these thin harnesses.
sessionId: options.sessionId || "",
+ excludeUris: cfg.recallExcludeUris,
log,
});
}