dsh-dejavu-memory 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alexandre@AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ <p align="center">
2
+ <img src="assets/readme/hero.svg" alt="dsh-dejavu-memory — long-term memory for DeepSeek Harness" width="100%">
3
+ </p>
4
+
5
+ # dsh-dejavu-memory
6
+
7
+ > **Renamed:** former npm/GitHub package `dsh-noc-memory` → **`dsh-dejavu-memory`**. Prefer this package; deprecate the old name when publishing.
8
+
9
+
10
+ Connects DeepSeek Harness to **DejaVu**: session-start boot + daily briefing, plus memory read / search / create / update / delete, backed by your own DejaVu MCP server on Cloudflare.
11
+
12
+ > Port of [pi-dejavu-memory](https://github.com/RealAlexandreAI/pi-dejavu-memory) — same protocol, same tool names.
13
+
14
+ [English](README.md) · [中文](README.zh.md)
15
+
16
+ ## Tools
17
+
18
+ | tool | what it does |
19
+ |---|---|
20
+ | `noc_boot` | load at session start: `system://boot`, `system://recent/5`, `system://triggers`, then best-effort `system://briefing`; afterward read `system://focus` (recent is a briefing subset — no need to re-read it after boot) |
21
+ | `noc_read` | read a memory by URI (`system://…`, `noc://agent`, …) |
22
+ | `noc_search` | search memories (semantic + keyword / trigger recall via `search_memory`) |
23
+ | `noc_create` | create a memory node (`[Baseline]`/`[Deviation]`/`[Result]`/`[Reusable judgment]`) |
24
+ | `noc_update` | full replace, patch (old_string/new_string), or append; optional `relation` |
25
+ | `noc_delete` | delete a memory by URI (`delete_memory`) |
26
+
27
+ ## Quick start
28
+
29
+ ```sh
30
+ dsh plugin --profile web add dsh-dejavu-memory
31
+ ```
32
+
33
+ Requires your own DejaVu server — deploy it to Cloudflare in minutes: [DejaVu](https://github.com/RealAlexandreAI/DejaVu).
34
+
35
+ ```yaml
36
+ - id: dejavu
37
+ name: dsh-dejavu-memory
38
+ config:
39
+ mcp_url: https://dejavu.example.com/mcp
40
+ mcp_auth: "" # prefer mcp_headers for Access service token
41
+ ```
42
+
43
+ For a server behind Cloudflare Access (e.g. dejavu.example.com), use the **service token** headers instead of `mcp_auth`:
44
+
45
+ ```yaml
46
+ - id: dejavu
47
+ name: dsh-dejavu-memory
48
+ config:
49
+ mcp_url: https://dejavu.example.com/mcp
50
+ mcp_headers:
51
+ CF-Access-Client-Id: <your client id>
52
+ CF-Access-Client-Secret: <your client secret>
53
+ ```
54
+
55
+ | key | required | meaning |
56
+ |---|---|---|
57
+ | `mcp_url` | yes | your DejaVu MCP endpoint (Streamable HTTP) |
58
+ | `mcp_auth` | no | legacy; prefer `mcp_headers` for Cloudflare Access service token |
59
+ | `mcp_headers` | no | extra headers merged into every MCP request (e.g. Cloudflare Access service token) |
60
+
61
+ > **Upgrading from dsh-noc-memory:** package renamed to `dsh-dejavu-memory`. Remove the old plugin and re-add; point config `id` at `dejavu`.
62
+
63
+ ## Why noc_* (not DejaVu_*)?
64
+
65
+ Some agents probe `read_mcp_resource` before reaching for a memory tool, wasting a round trip ([upstream issue #32](https://github.com/Dataojitori/DejaVu_memory/issues/32)). Explicit `noc_boot` / `noc_read` naming in the tool list and boot-protocol prompt steers models straight to the right tool — no resource shim required.
66
+
67
+ ## License
68
+
69
+ MIT
70
+
71
+ ## Related
72
+
73
+ - [DejaVu](https://github.com/RealAlexandreAI/DejaVu) — the Cloudflare MCP memory server this plugin talks to
74
+ - [pi-dejavu-memory](https://github.com/RealAlexandreAI/pi-dejavu-memory) — same memory tools for Pi
75
+ - [DejaVu_memory](https://github.com/Dataojitori/DejaVu_memory) — upstream project
package/README.zh.md ADDED
@@ -0,0 +1,71 @@
1
+ <p align="center">
2
+ <img src="assets/readme/hero.zh.svg" alt="dsh-dejavu-memory —— 给 DeepSeek Harness 接上长期记忆" width="100%">
3
+ </p>
4
+
5
+ # dsh-dejavu-memory
6
+
7
+ 给 DeepSeek Harness 接上 **DejaVu** 长期记忆:会话开始 boot + 每日简报,记忆读写/搜索/更新/删除,后端是部署在 Cloudflare 上的 DejaVu MCP 服务器。
8
+
9
+ > 由 [pi-dejavu-memory](https://github.com/RealAlexandreAI/pi-dejavu-memory) 移植,协议与工具名完全一致。
10
+
11
+ [English](README.md) · [中文](README.zh.md)
12
+
13
+ ## 工具
14
+
15
+ | 工具 | 说明 |
16
+ |---|---|
17
+ | `noc_boot` | 会话开始加载:`system://boot`、`system://recent/5`、`system://triggers`,再 best-effort 读 `system://briefing`;随后读 `system://focus`(`recent` 是 briefing 子集——boot 之后不必再单独读) |
18
+ | `noc_read` | 按 URI 读记忆(`system://…`、`noc://agent`…) |
19
+ | `noc_search` | 搜记忆(语义 + 关键词 / 触发词召回,服务端 `search_memory`) |
20
+ | `noc_create` | 新建记忆节点(支持 `[Baseline]`/`[Deviation]`/`[Result]`/`[Reusable judgment]`) |
21
+ | `noc_update` | 全文替换、patch(old_string/new_string)或 append;可选 `relation` |
22
+ | `noc_delete` | 按 URI 删除记忆(`delete_memory`) |
23
+
24
+ ## 快速开始
25
+
26
+ ```sh
27
+ dsh plugin --profile web add dsh-dejavu-memory
28
+ ```
29
+
30
+ 需要你能连到自己的 DejaVu(DejaVu)服务器——几分钟部署到 Cloudflare:[DejaVu](https://github.com/RealAlexandreAI/DejaVu)。
31
+
32
+ ```yaml
33
+ - id: dejavu
34
+ name: dsh-dejavu-memory
35
+ config:
36
+ mcp_url: https://dejavu.example.com/mcp
37
+ mcp_auth: "" # 优先用 mcp_headers 传 Access service token
38
+ ```
39
+
40
+ 若服务器在 Cloudflare Access 后(例如 `dejavu.example.com`),用 **service token** 头替代 `mcp_auth`:
41
+
42
+ ```yaml
43
+ - id: dejavu
44
+ name: dsh-dejavu-memory
45
+ config:
46
+ mcp_url: https://dejavu.example.com/mcp
47
+ mcp_headers:
48
+ CF-Access-Client-Id: <your client id>
49
+ CF-Access-Client-Secret: <your client secret>
50
+ ```
51
+
52
+ | 键 | 必填 | 含义 |
53
+ |---|---|---|
54
+ | `mcp_url` | 是 | 你的 DejaVu MCP 端点(Streamable HTTP) |
55
+ | `mcp_auth` | 否 | 遗留字段;优先用 `mcp_headers` 传 Cloudflare Access service token |
56
+
57
+ > **从 dsh-DejaVu-memory(≤0.1.x)升级:** 已改名为 `dsh-dejavu-memory`,工具名 `DejaVu_*` → `noc_*`。删除旧插件后重新添加新包;更新提示词里所有 `DejaVu_*` 工具引用。
58
+
59
+ ## 为什么叫 noc_*(不叫 DejaVu_*)?
60
+
61
+ 部分模型会先探测 `read_mcp_resource` 再调用记忆工具,浪费一次往返([上游 issue #32](https://github.com/Dataojitori/DejaVu_memory/issues/32))。工具列表与 boot 协议提示词里显式的 `noc_boot` / `noc_read` 命名,能把模型直接引导到正确工具——无需 resource 兼容层。
62
+
63
+ ## License
64
+
65
+ MIT
66
+
67
+ ## 相关
68
+
69
+ - [DejaVu](https://github.com/RealAlexandreAI/DejaVu) — 本插件连接的 Cloudflare MCP 记忆服务器
70
+ - [pi-dejavu-memory](https://github.com/RealAlexandreAI/pi-dejavu-memory) — 面向 Pi 的同一套记忆工具
71
+ - [DejaVu_memory](https://github.com/Dataojitori/DejaVu_memory) — 上游项目
@@ -0,0 +1,12 @@
1
+ # Plugin bundle for dsh-dejavu-memory.
2
+ # Registers the DejaVu memory tools (noc_boot / read / search /
3
+ # create / update / delete). Configure your own DejaVu MCP server:
4
+ #
5
+ # - id: dejavu
6
+ # name: 'dsh-dejavu-memory'
7
+ # config:
8
+ # mcp_url: http://localhost:PORT/mcp
9
+ # mcp_auth: Bearer <your token>
10
+ - insert:
11
+ - id: dejavu
12
+ name: 'dsh-dejavu-memory'
@@ -0,0 +1,32 @@
1
+ import { Context } from '@deepseek-ai/cordis';
2
+ import z from '@deepseek-ai/schemastery';
3
+ export declare const name = "noc-memory";
4
+ export declare const inject: string[];
5
+ export interface Config {
6
+ /** Noc MCP server URL, e.g. http://localhost:PORT/mcp. Optional at load
7
+ * time — a missing server surfaces as a setup hint on tool calls so the
8
+ * plugin still loads in a bare profile. */
9
+ mcp_url?: string;
10
+ /** MCP auth token (Authorization header value, e.g. "Bearer xxx"). */
11
+ mcp_auth?: string;
12
+ /** Extra headers merged into every MCP request — e.g. a Cloudflare Access
13
+ * service token ("CF-Access-Client-Id" / "CF-Access-Client-Secret"). */
14
+ mcp_headers?: Record<string, string>;
15
+ /** MCP protocol version. */
16
+ protocol_version?: string;
17
+ }
18
+ export declare const Config: z<Config>;
19
+ /** Parse an SSE body into the first JSON-RPC result/error object. Pure logic. */
20
+ export declare function parseStreamResponse(text: string): any;
21
+ export declare function extractText(data: any): string;
22
+ /** Boot resources read via read_memory (boot + recent + triggers). */
23
+ export declare const BOOT_URIS: readonly ["system://boot", "system://recent/5", "system://triggers"];
24
+ /** MCP tool names as exposed by cf-noc-mem (must stay in sync with the server). */
25
+ export declare const MCP_TOOLS: {
26
+ readonly read: "read_memory";
27
+ readonly search: "search_memory";
28
+ readonly create: "create_memory";
29
+ readonly update: "update_memory";
30
+ readonly delete: "delete_memory";
31
+ };
32
+ export declare function apply(ctx: Context, config: Config): void;
package/dist/index.js ADDED
@@ -0,0 +1,412 @@
1
+ // dsh-memory — DeepSeek Harness (Cordis) plugin.
2
+ //
3
+ // Noc Memory client: automated long-term memory for the agent,
4
+ // backed by YOUR OWN Noc MCP server (mcp_url). Ported from
5
+ // pi-dejavu-memory — same MCP protocol, same boot protocol, same tools.
6
+ //
7
+ // Tools: noc_boot (session-start memory load), noc_read,
8
+ // noc_search, noc_create, noc_update, noc_delete.
9
+ //
10
+ // Privacy: memories live on your own MCP server; the plugin is a thin
11
+ // client. The auth token comes from the plugin config (mcp_auth) — never logged.
12
+ import z from '@deepseek-ai/schemastery';
13
+ import { defineTool } from '@deepseek-ai/dsh-tools';
14
+ export const name = 'noc-memory';
15
+ export const inject = ['tools', 'systemPrompt'];
16
+ export const Config = z.object({
17
+ mcp_url: z.string().description('Noc MCP server URL, e.g. http://localhost:PORT/mcp'),
18
+ mcp_auth: z.string().description('MCP auth token (Authorization header value, e.g. "Bearer xxx")'),
19
+ mcp_headers: z.dict(z.string()).description('Extra headers merged into every MCP request (e.g. Cloudflare Access service token)'),
20
+ protocol_version: z.string().description('MCP protocol version (default 2024-11-05)'),
21
+ });
22
+ /** Parse an SSE body into the first JSON-RPC result/error object. Pure logic. */
23
+ export function parseStreamResponse(text) {
24
+ const lines = text.split(/\r?\n/);
25
+ let currentData = '';
26
+ for (const line of lines) {
27
+ const trimmed = line.trim();
28
+ if (trimmed.startsWith('data: ')) {
29
+ currentData = trimmed.slice(6);
30
+ }
31
+ else if (trimmed === '' && currentData) {
32
+ try {
33
+ const parsed = JSON.parse(currentData);
34
+ if (parsed.result || parsed.error)
35
+ return parsed;
36
+ }
37
+ catch {
38
+ // continue
39
+ }
40
+ currentData = '';
41
+ }
42
+ }
43
+ if (currentData) {
44
+ try {
45
+ return JSON.parse(currentData);
46
+ }
47
+ catch {
48
+ // ignore
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ export function extractText(data) {
54
+ if (data?.error)
55
+ return `Error: ${data.error.message ?? JSON.stringify(data.error)}`;
56
+ return data?.result?.content?.[0]?.text ?? '';
57
+ }
58
+ const REQUEST_TIMEOUT_MS = 30_000;
59
+ /** Boot resources read via read_memory (boot + recent + triggers). */
60
+ export const BOOT_URIS = ['system://boot', 'system://recent/5', 'system://triggers'];
61
+ /** MCP tool names as exposed by cf-noc-mem (must stay in sync with the server). */
62
+ export const MCP_TOOLS = {
63
+ read: 'read_memory',
64
+ search: 'search_memory', // not search_memories
65
+ create: 'create_memory',
66
+ update: 'update_memory',
67
+ delete: 'delete_memory',
68
+ };
69
+ // UI presentation helpers — dsh web UI renders pending/settled tool calls as
70
+ // cards; declaring them gives memory ops readable titles instead of raw args.
71
+ function presentCallFor(label, pick) {
72
+ return (args) => {
73
+ const what = String(pick(args) ?? '').trim();
74
+ return { card: 'generic', title: what ? `${label} ${what}` : label, rawInput: what || undefined };
75
+ };
76
+ }
77
+ function presentResultFor(label) {
78
+ return (_args, result) => {
79
+ const text = result.content.map((b) => (b.type === 'text' && b.text) || '').join('').trim();
80
+ if (result.isError) {
81
+ return { card: 'generic', title: `${label} failed`, content: [{ type: 'text', text: text || 'unknown error' }] };
82
+ }
83
+ return { card: 'generic', title: `${label} ok`, content: text ? [{ type: 'text', text }] : undefined };
84
+ };
85
+ }
86
+ /** MCP 2.0 (2026-07-28) is stateless: no initialize handshake, no session. */
87
+ function isMissingSession(parsed) {
88
+ const code = parsed?.error?.code;
89
+ const message = String(parsed?.error?.message ?? '').toLowerCase();
90
+ return code === -32600 || message.includes('session');
91
+ }
92
+ class NocClient {
93
+ url;
94
+ auth;
95
+ protocolVersion;
96
+ extraHeaders;
97
+ sessionId = null;
98
+ initPromise = null;
99
+ // Probe once: MCP 2.0 servers answer without a session; legacy servers
100
+ // (2025-era) demand initialize + Mcp-Session-Id. Never assume which.
101
+ mode = 'unknown';
102
+ constructor(url, auth, protocolVersion, extraHeaders = {}) {
103
+ this.url = url;
104
+ this.auth = auth;
105
+ this.protocolVersion = protocolVersion;
106
+ this.extraHeaders = extraHeaders;
107
+ }
108
+ async fetchRaw(method, params, sessionId) {
109
+ const headers = {
110
+ 'Content-Type': 'application/json',
111
+ Accept: 'application/json, text/event-stream',
112
+ Authorization: this.auth,
113
+ ...this.extraHeaders,
114
+ };
115
+ if (sessionId)
116
+ headers['Mcp-Session-Id'] = sessionId;
117
+ return fetch(this.url, {
118
+ method: 'POST',
119
+ headers,
120
+ body: JSON.stringify({ jsonrpc: '2.0', id: method + Date.now(), method, params }),
121
+ // A dead MCP server must not stall a dsh turn forever.
122
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
123
+ });
124
+ }
125
+ async initialize() {
126
+ // Concurrent first calls share one handshake instead of racing sessions.
127
+ if (this.initPromise)
128
+ return this.initPromise;
129
+ this.initPromise = (async () => {
130
+ const resp = await this.fetchRaw('initialize', {
131
+ protocolVersion: this.protocolVersion,
132
+ capabilities: {},
133
+ clientInfo: { name: 'dsh-memory', version: '0.1.0' },
134
+ });
135
+ if (!resp.ok)
136
+ return null;
137
+ return resp.headers.get('mcp-session-id');
138
+ })();
139
+ return this.initPromise;
140
+ }
141
+ async call(method, params) {
142
+ // MCP 2.0 stateless path: try without a session first (no initialize).
143
+ if (this.mode !== 'legacy') {
144
+ const resp = await this.fetchRaw(method, params);
145
+ if (resp.ok) {
146
+ const parsed = parseStreamResponse(await resp.text());
147
+ if (!isMissingSession(parsed)) {
148
+ this.mode = 'stateless';
149
+ const newSid = resp.headers.get('mcp-session-id');
150
+ if (newSid)
151
+ this.sessionId = newSid;
152
+ return parsed;
153
+ }
154
+ // Legacy server demands a session — fall through to handshake.
155
+ }
156
+ }
157
+ this.mode = 'legacy';
158
+ if (!this.sessionId) {
159
+ this.sessionId = await this.initialize();
160
+ if (!this.sessionId)
161
+ return { error: { code: -1, message: 'Failed to initialize MCP session' } };
162
+ }
163
+ const resp = await this.fetchRaw(method, params, this.sessionId);
164
+ if (!resp.ok) {
165
+ const body = await resp.text().catch(() => '<unreadable>');
166
+ return { error: { code: resp.status, message: `HTTP ${resp.status}: ${body.slice(0, 200)}` } };
167
+ }
168
+ const newSid = resp.headers.get('mcp-session-id');
169
+ if (newSid)
170
+ this.sessionId = newSid;
171
+ return parseStreamResponse(await resp.text());
172
+ }
173
+ }
174
+ export function apply(ctx, config) {
175
+ ctx.systemPrompt.section({
176
+ name: 'tool:noc-memory',
177
+ order: 2960,
178
+ text: 'You have long-term memory via the Noc MCP server. At the start of ' +
179
+ 'substantial work call noc_boot to load system://boot, system://recent/5, ' +
180
+ 'system://triggers, and best-effort system://briefing; then ' +
181
+ 'read system://focus to resume active working trees (recent is a briefing ' +
182
+ 'subset — no need to re-read it after boot); use noc_search before ' +
183
+ 'answering from memory — describe what you need in natural language, not ' +
184
+ 'just keywords (semantic recall finds memories with no shared words); ' +
185
+ 'persist valuable outcomes with noc_create; revise with noc_update; remove ' +
186
+ 'dead nodes with noc_delete. ' +
187
+ 'Periodically (after many new memories or when you repeat a mistake) ' +
188
+ 'run a memory audit: noc_read system://diagnostic/noc, then fix what it ' +
189
+ 'flags — never-reaccessed high-priority memories (disclosure/placement), ' +
190
+ 'stale or cold candidates (noc_delete if dead, demote if niche), crowded ' +
191
+ 'parents (regroup), contradictions (merge via noc_update). Always ' +
192
+ 'noc_read a node in full before changing it.',
193
+ });
194
+ const resolveAuth = async () => config.mcp_auth ?? '';
195
+ // One client per plugin instance: the MCP session (initialize handshake +
196
+ // session id) is reused across tool calls instead of re-handshaking on every
197
+ // call.
198
+ let cachedClient = null;
199
+ const client = () => {
200
+ if (!cachedClient) {
201
+ cachedClient = (async () => {
202
+ if (!config.mcp_url) {
203
+ throw new Error('Noc MCP server not configured — set mcp_url in the plugin config (e.g. http://localhost:PORT/mcp)');
204
+ }
205
+ return new NocClient(config.mcp_url, await resolveAuth(), config.protocol_version ?? '2024-11-05', config.mcp_headers ?? {});
206
+ })();
207
+ }
208
+ return cachedClient;
209
+ };
210
+ const register = (tool) => {
211
+ ctx.tools.register(defineTool(tool));
212
+ };
213
+ register({
214
+ name: 'noc_boot',
215
+ description: 'Call at session start. Loads core memories, recent context, triggers ' +
216
+ '(system://triggers), and today\'s working-memory briefing. Self-discipline startup protocol.',
217
+ parameters: {},
218
+ output: {
219
+ schema: { type: 'string' },
220
+ render: (_a, v) => [{ type: 'text', text: String(v) }],
221
+ presentationMeta: () => ({ action: 'boot' }),
222
+ },
223
+ isConcurrencySafe: () => true,
224
+ presentCall: presentCallFor('noc_boot', () => 'load core + recent + triggers + briefing'),
225
+ presentResult: presentResultFor('noc_boot'),
226
+ async execute(_args, _exec) {
227
+ const c = await client();
228
+ const out = [];
229
+ for (const uri of BOOT_URIS) {
230
+ const data = await c.call('tools/call', { name: MCP_TOOLS.read, arguments: { uri } });
231
+ const text = extractText(data);
232
+ if (!text)
233
+ continue;
234
+ out.push(`[${uri}]\n${text}`);
235
+ }
236
+ // Daily briefing: best-effort — boot still succeeds if server lacks it.
237
+ try {
238
+ const data = await c.call('tools/call', { name: MCP_TOOLS.read, arguments: { uri: 'system://briefing' } });
239
+ const text = extractText(data);
240
+ if (text && !/^Unknown system URI/i.test(text.trim()) && !text.startsWith('Error:')) {
241
+ out.push(`[system://briefing]\n${text}`);
242
+ }
243
+ }
244
+ catch {
245
+ // ignore
246
+ }
247
+ return out.join('\n\n');
248
+ },
249
+ });
250
+ register({
251
+ name: 'noc_read',
252
+ description: 'Read a memory by URI. Use system:// URIs or memory paths like core://agent.',
253
+ parameters: {
254
+ uri: { type: 'string', required: true, description: 'Memory URI (e.g., core://agent, system://boot)' },
255
+ },
256
+ output: {
257
+ schema: { type: 'string' },
258
+ render: (_a, v) => [{ type: 'text', text: String(v) }],
259
+ presentationMeta: (args) => ({ action: 'read', uri: args.uri ?? '' }),
260
+ },
261
+ isConcurrencySafe: () => true,
262
+ presentCall: presentCallFor('noc_read', (args) => args.uri),
263
+ presentResult: presentResultFor('noc_read'),
264
+ async execute(args, _exec) {
265
+ const c = await client();
266
+ const data = await c.call('tools/call', { name: MCP_TOOLS.read, arguments: { uri: args.uri } });
267
+ return extractText(data);
268
+ },
269
+ });
270
+ register({
271
+ name: 'noc_search',
272
+ description: 'Search memories with semantic + keyword recall (multilingual, CJK-capable). ' +
273
+ 'Describe what you are looking for in natural language — semantic search finds ' +
274
+ 'memories that share no keywords (e.g. query "部署失败" recalls a note about a broken release pipeline).',
275
+ parameters: {
276
+ query: { type: 'string', required: true, description: 'Concept or keywords to search for' },
277
+ limit: { type: 'number', description: 'Max results (1-50, default 20)' },
278
+ domain: { type: 'string', description: 'Domain filter (e.g., core, writer); ignored by current cf-noc-mem' },
279
+ },
280
+ output: {
281
+ schema: { type: 'string' },
282
+ render: (_a, v) => [{ type: 'text', text: String(v) }],
283
+ presentationMeta: (args) => ({ action: 'search', query: args.query ?? '' }),
284
+ },
285
+ isConcurrencySafe: () => true,
286
+ presentCall: presentCallFor('noc_search', (args) => args.query),
287
+ presentResult: presentResultFor('noc_search'),
288
+ async execute(args, _exec) {
289
+ const c = await client();
290
+ const arguments_ = { query: args.query };
291
+ if (args.limit !== undefined)
292
+ arguments_.limit = args.limit;
293
+ if (args.domain)
294
+ arguments_.domain = args.domain;
295
+ const data = await c.call('tools/call', {
296
+ name: MCP_TOOLS.search,
297
+ arguments: arguments_,
298
+ });
299
+ return extractText(data);
300
+ },
301
+ });
302
+ register({
303
+ name: 'noc_create',
304
+ description: 'Create a new memory node. Include [Baseline], [Deviation], [Result], [Reusable judgment] for behavior records.',
305
+ parameters: {
306
+ parent_uri: { type: 'string', required: true, description: 'Parent URI (e.g., core://)' },
307
+ content: { type: 'string', required: true, description: 'Memory content (Markdown supported)' },
308
+ priority: { type: 'number', description: 'Priority (0=highest, default 2)' },
309
+ disclosure: { type: 'string', required: true, description: "When to recall this memory (e.g., 'When discussing X')" },
310
+ title: { type: 'string', description: 'Path name (a-z, 0-9, _, -)' },
311
+ },
312
+ output: {
313
+ schema: { type: 'string' },
314
+ render: (_a, v) => [{ type: 'text', text: String(v) }],
315
+ presentationMeta: (args) => ({ action: 'create', parent_uri: args.parent_uri ?? '', title: args.title ?? '' }),
316
+ },
317
+ isConcurrencySafe: () => true,
318
+ presentCall: presentCallFor('noc_create', (args) => args.title ?? args.parent_uri),
319
+ presentResult: presentResultFor('noc_create'),
320
+ async execute(args, _exec) {
321
+ const c = await client();
322
+ const data = await c.call('tools/call', {
323
+ name: MCP_TOOLS.create,
324
+ arguments: {
325
+ parent_uri: args.parent_uri,
326
+ content: args.content,
327
+ priority: args.priority ?? 2,
328
+ disclosure: args.disclosure,
329
+ title: args.title ?? undefined,
330
+ },
331
+ });
332
+ return extractText(data);
333
+ },
334
+ });
335
+ register({
336
+ name: 'noc_update',
337
+ description: 'Update existing memory. Supports full content replace, old_string/new_string patch, or append. ' +
338
+ 'Must noc_read the URI first. Optional relation marks knowledge evolution: replace|enrich|confirm|challenge.',
339
+ parameters: {
340
+ uri: { type: 'string', required: true, description: 'Memory URI to update' },
341
+ content: { type: 'string', description: 'Full replacement content' },
342
+ old_string: { type: 'string', description: 'Exact text to replace (patch)' },
343
+ new_string: { type: 'string', description: 'Replacement text (patch)' },
344
+ append: { type: 'string', description: 'Text to append' },
345
+ priority: { type: 'number', description: 'New priority (lower = more important)' },
346
+ disclosure: { type: 'string', description: 'New disclosure condition' },
347
+ expires_at: { type: 'string', description: 'ISO datetime to expire, or "" to clear' },
348
+ relation: {
349
+ type: 'string',
350
+ enum: ['replace', 'enrich', 'confirm', 'challenge'],
351
+ description: 'Knowledge-evolution relation to previous version',
352
+ },
353
+ },
354
+ output: {
355
+ schema: { type: 'string' },
356
+ render: (_a, v) => [{ type: 'text', text: String(v) }],
357
+ presentationMeta: (args) => ({ action: 'update', uri: args.uri ?? '' }),
358
+ },
359
+ isConcurrencySafe: () => true,
360
+ presentCall: presentCallFor('noc_update', (args) => args.uri),
361
+ presentResult: presentResultFor('noc_update'),
362
+ async execute(args, _exec) {
363
+ const c = await client();
364
+ const arguments_ = { uri: args.uri };
365
+ if (args.content !== undefined)
366
+ arguments_.content = args.content;
367
+ if (args.old_string)
368
+ arguments_.old_string = args.old_string;
369
+ if (args.new_string !== undefined)
370
+ arguments_.new_string = args.new_string;
371
+ if (args.append)
372
+ arguments_.append = args.append;
373
+ if (args.priority !== undefined)
374
+ arguments_.priority = args.priority;
375
+ if (args.disclosure)
376
+ arguments_.disclosure = args.disclosure;
377
+ if (args.expires_at !== undefined)
378
+ arguments_.expires_at = args.expires_at;
379
+ if (args.relation)
380
+ arguments_.relation = args.relation;
381
+ const data = await c.call('tools/call', {
382
+ name: MCP_TOOLS.update,
383
+ arguments: arguments_,
384
+ });
385
+ return extractText(data);
386
+ },
387
+ });
388
+ register({
389
+ name: 'noc_delete',
390
+ description: 'Delete a memory by URI (cuts its path). Always noc_read the full node first. ' +
391
+ 'If the node has children, the server may return orphans to handle first.',
392
+ parameters: {
393
+ uri: { type: 'string', required: true, description: 'Memory URI to delete' },
394
+ },
395
+ output: {
396
+ schema: { type: 'string' },
397
+ render: (_a, v) => [{ type: 'text', text: String(v) }],
398
+ presentationMeta: (args) => ({ action: 'delete', uri: args.uri ?? '' }),
399
+ },
400
+ isConcurrencySafe: () => true,
401
+ presentCall: presentCallFor('noc_delete', (args) => args.uri),
402
+ presentResult: presentResultFor('noc_delete'),
403
+ async execute(args, _exec) {
404
+ const c = await client();
405
+ const data = await c.call('tools/call', {
406
+ name: MCP_TOOLS.delete,
407
+ arguments: { uri: args.uri },
408
+ });
409
+ return extractText(data);
410
+ },
411
+ });
412
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "dsh-dejavu-memory",
3
+ "version": "0.4.0",
4
+ "description": "DeepSeek Harness plugin: DejaVu memory client \u2014 automated long-term memory (boot/read/search/create/update/delete) backed by your own DejaVu MCP server.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "exports": {
8
+ ".": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "cordis.patch.yml",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "test": "node --import tsx --test tests/*.mjs",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "keywords": [
22
+ "dsh",
23
+ "dsh-plugin",
24
+ "deepseek-harness",
25
+ "cordis",
26
+ "memory",
27
+ "dejavu"
28
+ ],
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "@deepseek-ai/cordis": "^4.0.2",
32
+ "@deepseek-ai/dsh-tools": "^0.1.5-rc.2",
33
+ "@deepseek-ai/schemastery": "^3.18.2"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^22.0.0",
37
+ "tsx": "^4.19.0",
38
+ "typescript": "^5.5.0"
39
+ },
40
+ "dsh": {
41
+ "manifestVersion": 1,
42
+ "bundle": {
43
+ "patch": "./cordis.patch.yml"
44
+ }
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/RealAlexandreAI/dsh-dejavu-memory"
49
+ },
50
+ "engines": {
51
+ "node": ">=20.0.0"
52
+ }
53
+ }