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(dsh): normalize session ids for portable storage (#5522)
Zayn Jarvis5dd5b2db19ad
diff --git a/examples/dsh-memory-plugin/README.md b/examples/dsh-memory-plugin/README.mdindex 14f20378c..c3224dee7 100644--- a/examples/dsh-memory-plugin/README.md+++ b/examples/dsh-memory-plugin/README.md@@ -228,7 +228,7 @@ The older size settings apply to fallback recall, not the primary context reques- `tools/pre-execute` denies a DSH filesystem tool (`read`, `glob`, `grep`, `edit`, `write`, `str_replace_editor`) whose path argument is a `viking://` URI, pointing the model at the bridged `mcp__openviking__*` tools instead. A `write` or `edit` under a skill directory (`viking://~/skills/...`, `viking://user/<id>/skills/...`, `viking://agent/skills/...`) points at `mcp__openviking__add_skill` instead, which creates or replaces a whole skill from its `SKILL.md` text. A `grep` whose pattern is `viking://` text still runs.- `tools/post-execute` lets a `bash` command that carries a `viking://` URI run unchanged and attaches a notice for the model: use the bridged tools if it meant OpenViking content, or ignore the notice when the URI is intentional data such as an `ov` argument or an HTTP payload.-Each DSH session maps to `dsh-<session-id>` in OpenViking. Workspace-derived actor peers are resolved per session and sent on every session-specific request: the peer is the git identity of the session's workspace — the normalized `origin` URL (`[email protected]:volcengine/OpenViking.git` becomes `github.com-volcengine-openviking`), else the repository root path, that fallback keeping the older rule where every non-letter-or-digit character becomes `-`. With the default peer settings, no peer is sent outside a git repository, and what is remembered there goes to the user-level space `viking://user/<you>/memories`. One repository therefore keeps one peer across subdirectories, worktrees, clones and machines, while a fork's different origin keeps it separate. Memories written under the older path-derived peer stay reachable: the default `recallPeerScope: all` sweeps every peer under the user.+Each DSH session maps to `dsh-<session-id>` in OpenViking. IDs that contain Windows-invalid path characters are normalized to a readable underscore form plus a stable hash, so two native IDs cannot collapse onto the same OpenViking session; already-portable IDs keep their existing mapping. Existing sessions whose native IDs require normalization start a new OpenViking session after this upgrade. Workspace-derived actor peers are resolved per session and sent on every session-specific request: the peer is the git identity of the session's workspace — the normalized `origin` URL (`[email protected]:volcengine/OpenViking.git` becomes `github.com-volcengine-openviking`), else the repository root path, that fallback keeping the older rule where every non-letter-or-digit character becomes `-`. With the default peer settings, no peer is sent outside a git repository, and what is remembered there goes to the user-level space `viking://user/<you>/memories`. One repository therefore keeps one peer across subdirectories, worktrees, clones and machines, while a fork's different origin keeps it separate. Memories written under the older path-derived peer stay reachable: the default `recallPeerScope: all` sweeps every peer under the user.Workspace peer settings are loaded from `session.header.cwd` when the session first uses memory. A workspace can set `peer.id` to name its project explicitly, or `peer.source` to choose a preset or template chain. For example, `<root>/.openviking/config.json` can contain:diff --git a/examples/dsh-memory-plugin/config.mjs b/examples/dsh-memory-plugin/config.mjsindex d099f626c..994283c72 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.13";+export const PLUGIN_VERSION = "0.5.14";/*** 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 dfd9928a5..bbb670bc0 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.13",+ "version": "0.5.14","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@openviking/dsh-memory-plugin",- "version": "0.5.13",+ "version": "0.5.14","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 0b09e10aa..a28efb531 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.13",+ "version": "0.5.14","description": "OpenViking memory and context bundle for DeepSeek Harness","icon": "./icon.svg","type": "module",@@ -20,6 +20,7 @@"mcp.mjs","mcp-env.mjs","runtime.mjs",+ "session-id.mjs","skills.mjs","uri-guard.mjs","servers/",diff --git a/examples/dsh-memory-plugin/runtime.mjs b/examples/dsh-memory-plugin/runtime.mjsindex 03955e984..b09120bd8 100644--- a/examples/dsh-memory-plugin/runtime.mjs+++ b/examples/dsh-memory-plugin/runtime.mjs@@ -1,7 +1,6 @@import { isCaptureEnabled } from "./shared/capture-utils.mjs";import { buildProfileBlock } from "./shared/profile-inject.mjs";import { buildRecallBlock, isRecallEnabled } from "./shared/recall-core.mjs";-import { deriveHarnessSessionId } from "./shared/session-model.mjs";import {dequeue,enqueue,@@ -16,6 +15,7 @@ import {pluginMessage,promptText,} from "./capture.mjs";+import { deriveDshSessionId } from "./session-id.mjs";export class OpenVikingRuntime {constructor(client, config, logger = console, resolveSessionPeer = null) {@@ -45,7 +45,7 @@ export class OpenVikingRuntime {});state = {dshSessionId: String(session.id),- ovSessionId: deriveHarnessSessionId("dsh-", String(session.id)),+ ovSessionId: deriveDshSessionId(session.id),config: { ...this.config, peerId: peer.peerId, legacyPeerId: peer.legacyPeerId },ready: false,profileBlock: "",diff --git a/examples/dsh-memory-plugin/runtime.test.mjs b/examples/dsh-memory-plugin/runtime.test.mjsindex 05f8278e5..e3f7c28a3 100644--- a/examples/dsh-memory-plugin/runtime.test.mjs+++ b/examples/dsh-memory-plugin/runtime.test.mjs@@ -21,6 +21,19 @@ afterEach(async () => {await Promise.all(tempDirs.splice(0).map(dir => rm(dir, { recursive: true, force: true })));});+test("runtime uses a portable OpenViking id for DSH IM sessions", () => {+ const runtime = new OpenVikingRuntime({}, config(), { debug() {} });+ const state = runtime.stateFor({+ id: "im:weixin_fixture:dm:1790750070550:[email protected]",+ header: { cwd: "/workspace" },+ });++ assert.equal(+ state.ovSessionId,+ "[email protected]__eb8b3dae7d74",+ );+});+test("capture queues retryable failures but drops permanent client errors", async () => {for (const [status, expectedPending] of [[400, 0], [503, 1]]) {const pendingDir = await mkdtemp(join(tmpdir(), `dsh-memory-${status}-`));diff --git a/examples/dsh-memory-plugin/session-id.mjs b/examples/dsh-memory-plugin/session-id.mjsnew file mode 100644index 000000000..8715319dc--- /dev/null+++ b/examples/dsh-memory-plugin/session-id.mjs@@ -0,0 +1,21 @@+import { createHash } from "node:crypto";+import { deriveHarnessSessionId } from "./shared/session-model.mjs";++// Keep identifiers valid as a single path component on Windows. The `dsh-`+// prefix also prevents reserved device names such as CON and NUL from matching+// the whole component.+const WINDOWS_UNSAFE = /[<>:"/\\|?*\u0000-\u001F]/g;+const WINDOWS_UNSAFE_TRAILING = /[. ]+$/g;++export function deriveDshSessionId(sessionId) {+ const original = deriveHarnessSessionId("dsh-", String(sessionId));+ const portable = original+ .replace(WINDOWS_UNSAFE, "_")+ .replace(WINDOWS_UNSAFE_TRAILING, match => "_".repeat(match.length));+ if (portable === original) return original;++ // Replacement alone is lossy (`im:a` and `im?a` both become `im_a`). Keep a+ // readable stem and add a stable digest whenever normalization was needed.+ const digest = createHash("sha256").update(original).digest("hex").slice(0, 12);+ return `${portable}__${digest}`;+}diff --git a/examples/dsh-memory-plugin/session-id.test.mjs b/examples/dsh-memory-plugin/session-id.test.mjsnew file mode 100644index 000000000..2e4b472c0--- /dev/null+++ b/examples/dsh-memory-plugin/session-id.test.mjs@@ -0,0 +1,30 @@+import assert from "node:assert/strict";+import { test } from "node:test";+import { deriveDshSessionId } from "./session-id.mjs";++test("safe DSH session ids keep their existing OpenViking identity", () => {+ assert.equal(deriveDshSessionId("web-session_01"), "dsh-web-session_01");+});++test("Windows-unsafe IM session ids become portable and deterministic", () => {+ const native = "im:weixin_fixture:dm:1790750070550:[email protected]";+ const expected = "[email protected]__eb8b3dae7d74";++ assert.equal(deriveDshSessionId(native), expected);+ assert.equal(deriveDshSessionId(native), expected);+ assert.doesNotMatch(expected, /[<>:"/\\|?*\u0000-\u001F]/);+});++test("normalization cannot merge distinct native session ids", () => {+ const colon = deriveDshSessionId("im:a");+ const question = deriveDshSessionId("im?a");++ assert.equal(colon, "dsh-im_a__2ffb1edac2e4");+ assert.equal(question, "dsh-im_a__c0def8231117");+ assert.notEqual(colon, question);+});++test("trailing dots and spaces are removed from the path component", () => {+ assert.equal(deriveDshSessionId("name."), "dsh-name___c39208ad84ba");+ assert.doesNotMatch(deriveDshSessionId("name "), /[. ]$/);+});