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(plugins)!: apply captureFilters substitutions to tool call inputs and outputs (#5937)
t0saki621b1ddd9945
diff --git a/examples/agent-hook-plugin/hosts/cursor/openviking.integration.json b/examples/agent-hook-plugin/hosts/cursor/openviking.integration.jsonindex 634935081..fafb4a819 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.20",+ "version": "0.5.21","clients": ["cursor"],diff --git a/examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.json b/examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.jsonindex cc896ca54..51dd05c72 100644--- a/examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.json+++ b/examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.json@@ -1,6 +1,6 @@{"name": "openviking-memory",- "version": "0.5.20",+ "version": "0.5.21","description": "Long-term semantic memory for Kimi Code CLI, powered by OpenViking.","author": {"name": "OpenViking",diff --git a/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json b/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.jsonindex 2d5a2ba67..1f64e3255 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.20",+ "version": "0.5.21","clients": ["kimicode"],diff --git a/examples/agent-hook-plugin/hosts/trae/openviking.integration.json b/examples/agent-hook-plugin/hosts/trae/openviking.integration.jsonindex accf10f34..e7685b2b2 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.20",+ "version": "0.5.21","clients": ["trae","trae-cn"diff --git a/examples/agent-hook-plugin/hosts/zcode/openviking.integration.json b/examples/agent-hook-plugin/hosts/zcode/openviking.integration.jsonindex cb80b8ad5..5e1609b52 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.20",+ "version": "0.5.21","clients": ["zcode"],diff --git a/examples/agent-hook-plugin/plugin.json b/examples/agent-hook-plugin/plugin.jsonindex 71609170a..3f4167a8e 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.20",+ "version": "0.5.21","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/claude-code-memory-plugin/.claude-plugin/plugin.json b/examples/claude-code-memory-plugin/.claude-plugin/plugin.jsonindex c839bd3b2..5d6817b5a 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.11",+ "version": "0.7.12","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 da83d209c..296a50ba2 100644--- a/examples/claude-code-memory-plugin/README.md+++ b/examples/claude-code-memory-plugin/README.md@@ -323,6 +323,7 @@ In `ovcli.conf` the rules are a JSON array, so backslashes are doubled:- **The env vars are comma-separated lists**, split before parsing, so a rule that needs a literal comma — a bounded `{10,}`, say — belongs in the array above. (`\x2c` covers a literal comma elsewhere in a pattern, but it is not quantifier syntax.)- **Order matters and drops win.** The first `d` that matches, or `k` that does not, ends the decision. Filters run before `OPENVIKING_MIN_QUERY_LENGTH` and before the built-in ack / slash-command heuristics, so a prefix stripped down to `ok` is discarded as an ack. Text a substitution empties is not a drop — an emptied query is simply too short to recall on.- **Filters shape what is sent, not what is stored.** Adding a `d`/`k` rule mid-session also shortens the turn list the capture cursor counts, which reads as a transcript rewrite and replays from the last user turn — the same thing toggling `OPENVIKING_CAPTURE_ASSISTANT_TURNS` does.+- **Substitutions reach tool calls, verdicts do not.** On the capture path an `s` rule also rewrites every string value in a tool call's input and a tool result's output, so a redaction rule covers a secret that reached a command or its output. `d`/`k` rules look only at the turn's text.- **A bad rule is skipped, never fatal.** `ov-memory-doctor` lists the active rules and reports the exact parse or RegExp error for the ones it could not compile.### Plugin settings in `ovcli.conf`diff --git a/examples/claude-code-memory-plugin/README_CN.md b/examples/claude-code-memory-plugin/README_CN.mdindex 9d71311b6..6ecc5cfac 100644--- a/examples/claude-code-memory-plugin/README_CN.md+++ b/examples/claude-code-memory-plugin/README_CN.md@@ -291,6 +291,7 @@ bypass 命中时所有 hook 直接放行,不联系 OpenViking。- **环境变量是逗号分隔的列表**,先按逗号切分再解析,所以需要字面逗号的规则(比如带下界的 `{10,}`)只能写进上面的数组。(`\x2c` 能表示模式里其它位置的字面逗号,但它不是量词语法。)- **顺序有意义,丢弃优先。** 第一条命中的 `d`(或未命中的 `k`)就决定了结果。过滤发生在 `OPENVIKING_MIN_QUERY_LENGTH` 和内置的应答语/slash 命令启发式之前,所以剥掉前缀后只剩「好的」的文本会按应答语丢弃。被替换成空串不算丢弃 —— query 空了只是长度不够。- **过滤只管送出去的内容,管不到已经存下的。** 会话中途新增 `d`/`k` 规则还会让捕获游标计数的回合列表变短,这会被当成 transcript 被改写、从最后一个用户回合重放 —— 和切换 `OPENVIKING_CAPTURE_ASSISTANT_TURNS` 是同一个现象。+- **替换会作用到工具调用,取舍判断不会。** 在写路径上,`s` 规则也会改写工具调用输入里的每个字符串值和工具结果的输出,所以脱敏规则同样能盖住出现在命令或命令输出里的密钥;`d`/`k` 规则只看回合的文本。- **坏规则只会被跳过,不会让 hook 挂掉。** `ov-memory-doctor` 会列出生效的规则,并对编译失败的那条给出确切的解析或 RegExp 报错。### 插件配置放在 `ovcli.conf`diff --git a/examples/claude-code-memory-plugin/package.json b/examples/claude-code-memory-plugin/package.jsonindex 52205300a..af5649581 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.11",+ "version": "0.7.12","description": "OpenViking memory plugin for Claude Code — semantic long-term memory","type": "module","scripts": {diff --git a/examples/claude-code-memory-plugin/scripts/shared/capture-utils.mjs b/examples/claude-code-memory-plugin/scripts/shared/capture-utils.mjsindex c6bf25eae..97884e315 100644--- a/examples/claude-code-memory-plugin/scripts/shared/capture-utils.mjs+++ b/examples/claude-code-memory-plugin/scripts/shared/capture-utils.mjs@@ -362,14 +362,41 @@ export function extractPartsFromPayload(payload, options = {}) {return parts;}+function substituteValue(value, rules, role) {+ if (typeof value === "string") {+ let current = value;+ for (const rule of rules) {+ if (rule.op !== "s" || (rule.scope && rule.scope !== role)) continue;+ current = current.replace(rule.re, rule.replacement);+ }+ return current;+ }+ if (Array.isArray(value)) return value.map((item) => substituteValue(item, rules, role));+ if (value && typeof value === "object") {+ return Object.fromEntries(+ Object.entries(value).map(([key, item]) => [key, substituteValue(item, rules, role)]),+ );+ }+ return value;+}++function substituteToolPart(part, rules, role) {+ if (part.type !== "tool") return part;+ const out = { ...part };+ if (part.tool_input !== undefined) out.tool_input = substituteValue(part.tool_input, rules, role);+ if (part.tool_output !== undefined) out.tool_output = substituteValue(part.tool_output, rules, role);+ return out;+}+/*** Prune blank text parts and run `cfg.captureFilters` over the ones that remain.** One drop verdict is taken per turn, on the aggregate of its text parts; the* individual parts are then rewritten with the substitutions only, so a rule can- * never both keep and drop the same turn. Tool call/result parts are carried- * through untouched — filters match conversation text, not tool payloads — but a- * turn dropped on its text takes its tool parts with it.+ * never both keep and drop the same turn. Tool call/result parts get the+ * substitutions too, on their input values and output, so a redaction rule also+ * covers a secret that reached a command or its output; only text parts decide+ * the drop verdict, and a turn dropped on its text takes its tool parts with it.*/export function filterCaptureParts(parts, role, cfg = {}) {const kept = [];@@ -389,7 +416,9 @@ export function filterCaptureParts(parts, role, cfg = {}) {if (!compiled.rules.length || kept.length === 0) return blank;const textParts = kept.filter((part) => part.type === "text");- if (textParts.length === 0) return blank;+ if (textParts.length === 0) {+ return { parts: kept.map((part) => substituteToolPart(part, compiled.rules, role)), dropped: false };+ }const verdict = applyInputFilters(textParts.map((part) => part.text).join("\n\n"), compiled.rules, {role,@@ -399,7 +428,7 @@ export function filterCaptureParts(parts, role, cfg = {}) {const out = [];for (const part of kept) {if (part.type !== "text") {- out.push(part);+ out.push(substituteToolPart(part, compiled.rules, role));continue;}const shaped = applyInputFilters(part.text, compiled.rules, { role, substituteOnly: true });@@ -431,7 +460,7 @@ function faithfulCaptureDecision(text, cfg) {/*** Shape one host message before an adapter builds its session payload.* Sanitize injected context before evaluating keep/drop rules, so text that- * will not be sent cannot satisfy a keep rule. Tool parts are never filtered.+ * will not be sent cannot satisfy a keep rule. Tool parts never decide keep or drop.*/export function shapeCapturePayload(payload, role, cfg = {}, { toolNameById = {}, faithful = false } = {}) {const options = { toolMaxChars: cfg.captureToolMaxChars, toolNameById };diff --git a/examples/codex-memory-plugin/.codex-plugin/plugin.json b/examples/codex-memory-plugin/.codex-plugin/plugin.jsonindex 4870aa30a..6be7f2873 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.11.10",+ "version": "0.11.11","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/README.md b/examples/codex-memory-plugin/README.mdindex eef76cb3c..91ca14d7f 100644--- a/examples/codex-memory-plugin/README.md+++ b/examples/codex-memory-plugin/README.md@@ -206,7 +206,7 @@ The env vars are comma-separated lists, split before parsing, so a rule needing}```-Rules run top to bottom and the first `d` that matches (or `k` that does not) ends the decision; text a substitution empties is not a drop, just too short to recall on. Filters run before `OPENVIKING_MIN_QUERY_LENGTH` and before the built-in ack / slash-command heuristics. A capture rule shapes what is sent, not what is already stored, and anything already in the pending queue carries the rules that were in effect when it was enqueued; adding a `d`/`k` rule mid-session also shortens the turn list the cursor counts, which reads as a transcript rewrite and replays from the last user turn. A rule that fails to compile is skipped, never fatal — `ov-memory-doctor` lists the active rules and reports the exact error for the ones it could not parse.+Rules run top to bottom and the first `d` that matches (or `k` that does not) ends the decision; text a substitution empties is not a drop, just too short to recall on. Filters run before `OPENVIKING_MIN_QUERY_LENGTH` and before the built-in ack / slash-command heuristics. A capture rule shapes what is sent, not what is already stored, and anything already in the pending queue carries the rules that were in effect when it was enqueued; adding a `d`/`k` rule mid-session also shortens the turn list the cursor counts, which reads as a transcript rewrite and replays from the last user turn. On the capture path an `s` rule also rewrites every string value in a tool call's input and a tool result's output, so a redaction rule covers a secret that reached a command or its output; `d`/`k` rules look only at the turn's text. A rule that fails to compile is skipped, never fatal — `ov-memory-doctor` lists the active rules and reports the exact error for the ones it could not parse.#### Workspace configuration filesdiff --git a/examples/codex-memory-plugin/scripts/shared/capture-utils.mjs b/examples/codex-memory-plugin/scripts/shared/capture-utils.mjsindex c6bf25eae..97884e315 100644--- a/examples/codex-memory-plugin/scripts/shared/capture-utils.mjs+++ b/examples/codex-memory-plugin/scripts/shared/capture-utils.mjs@@ -362,14 +362,41 @@ export function extractPartsFromPayload(payload, options = {}) {return parts;}+function substituteValue(value, rules, role) {+ if (typeof value === "string") {+ let current = value;+ for (const rule of rules) {+ if (rule.op !== "s" || (rule.scope && rule.scope !== role)) continue;+ current = current.replace(rule.re, rule.replacement);+ }+ return current;+ }+ if (Array.isArray(value)) return value.map((item) => substituteValue(item, rules, role));+ if (value && typeof value === "object") {+ return Object.fromEntries(+ Object.entries(value).map(([key, item]) => [key, substituteValue(item, rules, role)]),+ );+ }+ return value;+}++function substituteToolPart(part, rules, role) {+ if (part.type !== "tool") return part;+ const out = { ...part };+ if (part.tool_input !== undefined) out.tool_input = substituteValue(part.tool_input, rules, role);+ if (part.tool_output !== undefined) out.tool_output = substituteValue(part.tool_output, rules, role);+ return out;+}+/*** Prune blank text parts and run `cfg.captureFilters` over the ones that remain.** One drop verdict is taken per turn, on the aggregate of its text parts; the* individual parts are then rewritten with the substitutions only, so a rule can- * never both keep and drop the same turn. Tool call/result parts are carried- * through untouched — filters match conversation text, not tool payloads — but a- * turn dropped on its text takes its tool parts with it.+ * never both keep and drop the same turn. Tool call/result parts get the+ * substitutions too, on their input values and output, so a redaction rule also+ * covers a secret that reached a command or its output; only text parts decide+ * the drop verdict, and a turn dropped on its text takes its tool parts with it.*/export function filterCaptureParts(parts, role, cfg = {}) {const kept = [];@@ -389,7 +416,9 @@ export function filterCaptureParts(parts, role, cfg = {}) {if (!compiled.rules.length || kept.length === 0) return blank;const textParts = kept.filter((part) => part.type === "text");- if (textParts.length === 0) return blank;+ if (textParts.length === 0) {+ return { parts: kept.map((part) => substituteToolPart(part, compiled.rules, role)), dropped: false };+ }const verdict = applyInputFilters(textParts.map((part) => part.text).join("\n\n"), compiled.rules, {role,@@ -399,7 +428,7 @@ export function filterCaptureParts(parts, role, cfg = {}) {const out = [];for (const part of kept) {if (part.type !== "text") {- out.push(part);+ out.push(substituteToolPart(part, compiled.rules, role));continue;}const shaped = applyInputFilters(part.text, compiled.rules, { role, substituteOnly: true });@@ -431,7 +460,7 @@ function faithfulCaptureDecision(text, cfg) {/*** Shape one host message before an adapter builds its session payload.* Sanitize injected context before evaluating keep/drop rules, so text that- * will not be sent cannot satisfy a keep rule. Tool parts are never filtered.+ * will not be sent cannot satisfy a keep rule. Tool parts never decide keep or drop.*/export function shapeCapturePayload(payload, role, cfg = {}, { toolNameById = {}, faithful = false } = {}) {const options = { toolMaxChars: cfg.captureToolMaxChars, toolNameById };diff --git a/examples/dsh-memory-plugin/config.mjs b/examples/dsh-memory-plugin/config.mjsindex e9625bf3d..da778a7bf 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.25";+export const PLUGIN_VERSION = "0.5.26";/*** Namespace for the bridged OpenViking MCP tools. DSH publishes every MCP tooldiff --git a/examples/dsh-memory-plugin/package-lock.json b/examples/dsh-memory-plugin/package-lock.jsonindex be21e740c..a1b38dee3 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.25",+ "version": "0.5.26","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@openviking/dsh-memory-plugin",- "version": "0.5.25",+ "version": "0.5.26","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.jsonindex e4ba72a18..699aa5255 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.25",+ "version": "0.5.26","description": "OpenViking memory and context bundle for DeepSeek Harness","icon": "./icon.svg","type": "module",diff --git a/examples/memory-plugin-shared/capture-utils.test.mjs b/examples/memory-plugin-shared/capture-utils.test.mjsindex 62d6ccd16..6b86f4d11 100644--- a/examples/memory-plugin-shared/capture-utils.test.mjs+++ b/examples/memory-plugin-shared/capture-utils.test.mjs@@ -227,7 +227,7 @@ test("filterCaptureParts prunes blank text parts even with no rules configured",assert.deepEqual(shaped.parts, [{ type: "text", text: "kept" }, TOOL_PART])})-test("filterCaptureParts substitutes in every text part and leaves tool parts alone", () => {+test("filterCaptureParts substitutes in every text part", () => {const shaped = filterCaptureParts([{ type: "text", text: "token sk_ABCDEF here" }, TOOL_PART, { type: "text", text: "and sk_ZZZ" }],"user",@@ -241,6 +241,33 @@ test("filterCaptureParts substitutes in every text part and leaves tool parts al])})+test("filterCaptureParts redacts tool inputs and outputs, with or without text parts", () => {+ const cfg = { captureFilters: ["s/sk_[A-Za-z0-9]+/[redacted]/g"] }+ const call = {+ type: "tool",+ tool_name: "bash",+ tool_input: { command: "curl -H 'Authorization: sk_ABCDEF'", env: ["KEY=sk_XYZ"], timeout: 30 },+ }+ const result = { type: "tool", tool_name: "bash", tool_output: "echoed sk_ABCDEF" }++ const toolOnly = filterCaptureParts([call, result], "user", cfg)+ assert.equal(toolOnly.dropped, false)+ assert.deepEqual(toolOnly.parts, [+ {+ ...call,+ tool_input: { command: "curl -H 'Authorization: [redacted]'", env: ["KEY=[redacted]"], timeout: 30 },+ },+ { ...result, tool_output: "echoed [redacted]" },+ ])++ const mixed = filterCaptureParts([{ type: "text", text: "run it" }, call], "assistant", cfg)+ assert.equal(mixed.parts[1].tool_input.command, "curl -H 'Authorization: [redacted]'")+ assert.equal(call.tool_input.command.includes("sk_ABCDEF"), true)++ const scoped = filterCaptureParts([result], "user", { captureFilters: ["assistant:s/sk_[A-Za-z0-9]+/x/g"] })+ assert.equal(scoped.parts[0].tool_output, "echoed sk_ABCDEF")+})+test("filterCaptureParts takes one drop verdict on the aggregate, tool parts included", () => {const cfg = { captureFilters: ["d/^internal notes/"] }const shaped = filterCaptureParts(diff --git a/examples/memory-plugin-shared/lib/capture-utils.mjs b/examples/memory-plugin-shared/lib/capture-utils.mjsindex 75ff03255..5ac6031fa 100644--- a/examples/memory-plugin-shared/lib/capture-utils.mjs+++ b/examples/memory-plugin-shared/lib/capture-utils.mjs@@ -361,14 +361,41 @@ export function extractPartsFromPayload(payload, options = {}) {return parts;}+function substituteValue(value, rules, role) {+ if (typeof value === "string") {+ let current = value;+ for (const rule of rules) {+ if (rule.op !== "s" || (rule.scope && rule.scope !== role)) continue;+ current = current.replace(rule.re, rule.replacement);+ }+ return current;+ }+ if (Array.isArray(value)) return value.map((item) => substituteValue(item, rules, role));+ if (value && typeof value === "object") {+ return Object.fromEntries(+ Object.entries(value).map(([key, item]) => [key, substituteValue(item, rules, role)]),+ );+ }+ return value;+}++function substituteToolPart(part, rules, role) {+ if (part.type !== "tool") return part;+ const out = { ...part };+ if (part.tool_input !== undefined) out.tool_input = substituteValue(part.tool_input, rules, role);+ if (part.tool_output !== undefined) out.tool_output = substituteValue(part.tool_output, rules, role);+ return out;+}+/*** Prune blank text parts and run `cfg.captureFilters` over the ones that remain.** One drop verdict is taken per turn, on the aggregate of its text parts; the* individual parts are then rewritten with the substitutions only, so a rule can- * never both keep and drop the same turn. Tool call/result parts are carried- * through untouched — filters match conversation text, not tool payloads — but a- * turn dropped on its text takes its tool parts with it.+ * never both keep and drop the same turn. Tool call/result parts get the+ * substitutions too, on their input values and output, so a redaction rule also+ * covers a secret that reached a command or its output; only text parts decide+ * the drop verdict, and a turn dropped on its text takes its tool parts with it.*/export function filterCaptureParts(parts, role, cfg = {}) {const kept = [];@@ -388,7 +415,9 @@ export function filterCaptureParts(parts, role, cfg = {}) {if (!compiled.rules.length || kept.length === 0) return blank;const textParts = kept.filter((part) => part.type === "text");- if (textParts.length === 0) return blank;+ if (textParts.length === 0) {+ return { parts: kept.map((part) => substituteToolPart(part, compiled.rules, role)), dropped: false };+ }const verdict = applyInputFilters(textParts.map((part) => part.text).join("\n\n"), compiled.rules, {role,@@ -398,7 +427,7 @@ export function filterCaptureParts(parts, role, cfg = {}) {const out = [];for (const part of kept) {if (part.type !== "text") {- out.push(part);+ out.push(substituteToolPart(part, compiled.rules, role));continue;}const shaped = applyInputFilters(part.text, compiled.rules, { role, substituteOnly: true });@@ -430,7 +459,7 @@ function faithfulCaptureDecision(text, cfg) {/*** Shape one host message before an adapter builds its session payload.* Sanitize injected context before evaluating keep/drop rules, so text that- * will not be sent cannot satisfy a keep rule. Tool parts are never filtered.+ * will not be sent cannot satisfy a keep rule. Tool parts never decide keep or drop.*/export function shapeCapturePayload(payload, role, cfg = {}, { toolNameById = {}, faithful = false } = {}) {const options = { toolMaxChars: cfg.captureToolMaxChars, toolNameById };diff --git a/examples/opencode-plugin/package.json b/examples/opencode-plugin/package.jsonindex f71276c08..a2a9f96b3 100644--- a/examples/opencode-plugin/package.json+++ b/examples/opencode-plugin/package.json@@ -1,6 +1,6 @@{"name": "@openviking/opencode-plugin",- "version": "0.5.16",+ "version": "0.5.17","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.jsonindex c624f39a5..ab36959e2 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.19",+ "version": "0.4.20","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "openviking-pi-extension",- "version": "0.4.19",+ "version": "0.4.20","dependencies": {"@modelcontextprotocol/client": "2.0.0"},diff --git a/examples/pi-coding-agent-extension/package.json b/examples/pi-coding-agent-extension/package.jsonindex e9fba4696..67c307f4f 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.19",+ "version": "0.4.20","description": "OpenViking memory and context extension for the pi coding agent","private": true,"type": "module",diff --git a/examples/pi-coding-agent-extension/tests/capture-adapter.test.mjs b/examples/pi-coding-agent-extension/tests/capture-adapter.test.mjsindex b6227b867..566a020ef 100644--- a/examples/pi-coding-agent-extension/tests/capture-adapter.test.mjs+++ b/examples/pi-coding-agent-extension/tests/capture-adapter.test.mjs@@ -183,17 +183,17 @@ for (const [mode, modeConfig] of [}const toolCall = { type: "toolCall", id: "call-filter", name: "lookup", arguments: { value: "secret" } };- const toolPart = {+ const toolPart = (value = "secret") => ({type: "tool", tool_id: "call-filter", tool_name: "lookup",- tool_status: "running", tool_input: { value: "secret" },- };- for (const [name, rules, texts, expected] of [+ tool_status: "running", tool_input: { value },+ });+ for (const [name, rules, texts, expected, toolValue] of [["whole-turn drop", ["d/secret/"], ["Remember secret for later."], null],["whole-turn keep miss", ["k/approved/"], ["Remember other settings."], null],- ["conversation-only matching", ["d/secret/"], ["Remember safe settings."], "Remember safe settings."],- ["conversation-only substitution", ["s/secret/secret-safe/"], ["Remember secret for later."], "Remember secret-safe for later."],+ ["text-only matching", ["d/secret/"], ["Remember safe settings."], "Remember safe settings."],+ ["substitution", ["s/secret/secret-safe/"], ["Remember secret for later."], "Remember secret-safe for later.", "secret-safe"],["aggregate keep", ["k/approved/"], ["Remember approved settings.", "Keep this detail too."], "Remember approved settings.\n\nKeep this detail too."],- ["empty text removal", ["s/^.*$//s"], ["Remember secret for later."], ""],+ ["empty text removal", ["s/^.*$//s"], ["Remember secret for later."], "", ""],]) {test(`${mode} capture uses ${name} for mixed text and tools`, () => {const branch = [{ role: "assistant", content: [@@ -203,13 +203,13 @@ for (const [mode, modeConfig] of [const { payloads } = extractBranchCapturePayloads(branch, 0, { ...modeConfig, captureFilters: rules });assert.deepEqual(payloads, expected === null ? [] : [{role: "assistant",- parts: [...(expected ? [{ type: "text", text: expected }] : []), toolPart],+ parts: [...(expected ? [{ type: "text", text: expected }] : []), toolPart(toolValue)],}]);assert.deepEqual(branch, original);});}- test(`${mode} capture preserves tool-only input and output with conversation rules`, () => {+ test(`${mode} capture substitutes in tool-only input and output without judging them`, () => {const branch = [{ role: "assistant", content: [toolCall] },{ role: "toolResult", toolCallId: "call-filter", toolName: "lookup", content: "secret" },@@ -218,10 +218,10 @@ for (const [mode, modeConfig] of [...modeConfig, captureFilters: ["s/secret/[removed]/", "d/secret/", "k/approved/"],});assert.deepEqual(payloads, [- { role: "assistant", parts: [toolPart] },+ { role: "assistant", parts: [toolPart("[removed]")] },{ role: "user", parts: [{type: "tool", tool_id: "call-filter", tool_name: "lookup",- tool_status: "completed", tool_output: "secret",+ tool_status: "completed", tool_output: "[removed]",}] },]);});