dsh-cross-memory 0.2.13 → 0.2.14
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/README.md +55 -16
- package/docs/DETAIL.md +10 -7
- package/docs/DETAIL.zh.md +10 -7
- package/lib/backfill.js +32 -1
- package/lib/client.js +3 -3
- package/lib/dense.js +47 -15
- package/lib/index.js +144 -83
- package/lib/mcp.js +7 -5
- package/lib/notify.js +10 -5
- package/lib/raw-recall.js +18 -7
- package/lib/state.js +19 -7
- package/lib/sync.js +12 -1
- package/lib/test/mcp.test.js +6 -1
- package/lib/test/recall.test.js +54 -1
- package/lib/test/sync.test.js +4 -0
- package/lib/types/backfill.d.ts +5 -0
- package/lib/types/dense.d.ts +7 -2
- package/lib/types/index.d.ts +10 -0
- package/lib/types/mcp.d.ts +1 -0
- package/lib/types/notify.d.ts +3 -2
- package/lib/types/raw-recall.d.ts +1 -0
- package/lib/types/sync.d.ts +1 -0
- package/package.json +7 -7
package/lib/mcp.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @module dsh-cross-memory/mcp
|
|
13
13
|
*/
|
|
14
14
|
import { homedir } from 'node:os';
|
|
15
|
-
import { join, resolve } from 'node:path';
|
|
15
|
+
import { dirname, join, resolve } from 'node:path';
|
|
16
16
|
import { createInterface } from 'node:readline';
|
|
17
17
|
import { fileURLToPath } from 'node:url';
|
|
18
18
|
import { DEFAULT_DENSE_MODEL, DEFAULT_DENSE_URL, denseScores, rrf } from './dense.js';
|
|
@@ -104,11 +104,12 @@ export const MCP_TOOLS = [
|
|
|
104
104
|
export function defaultMcpOptions(env = process.env) {
|
|
105
105
|
const dshHome = env['DSH_HOME']?.trim() || join(homedir(), '.dsh');
|
|
106
106
|
const memoriesDir = resolve(env['DSH_MEMORIES_DIR']?.trim() || join(dshHome, 'memories'));
|
|
107
|
+
const cacheDir = resolve(env['DSH_MEMORY_CACHE_DIR']?.trim() || join(dshHome, 'cache', 'dsh-cross-memory'));
|
|
107
108
|
const denseEnv = env['DSH_MEMORY_DENSE']?.trim().toLowerCase();
|
|
108
109
|
const denseEnabled = denseEnv === undefined ? true : !(denseEnv === '0' || denseEnv === 'false' || denseEnv === 'off');
|
|
109
110
|
const denseUrl = env['DSH_MEMORY_DENSE_URL']?.trim() || DEFAULT_DENSE_URL;
|
|
110
111
|
const denseModel = env['DSH_MEMORY_DENSE_MODEL']?.trim() || DEFAULT_DENSE_MODEL;
|
|
111
|
-
return { memoriesDir, denseEnabled, denseUrl, denseModel };
|
|
112
|
+
return { memoriesDir, cacheDir, denseEnabled, denseUrl, denseModel };
|
|
112
113
|
}
|
|
113
114
|
/** Resolve a workspace root argument from either `projectRoot` or `projectSlug`. */
|
|
114
115
|
async function resolveProjectRoot(store, projectRootArg, projectSlugArg) {
|
|
@@ -118,7 +119,7 @@ async function resolveProjectRoot(store, projectRootArg, projectSlugArg) {
|
|
|
118
119
|
if (typeof projectSlugArg === 'string' && projectSlugArg.trim().length > 0) {
|
|
119
120
|
const slug = projectSlugArg.trim();
|
|
120
121
|
const descriptor = await store.readProjectDescriptor(slug);
|
|
121
|
-
return descriptor?.root
|
|
122
|
+
return descriptor?.root;
|
|
122
123
|
}
|
|
123
124
|
return undefined;
|
|
124
125
|
}
|
|
@@ -131,7 +132,8 @@ async function maybeDenseRerank(hits, query, options, limit) {
|
|
|
131
132
|
if (!options.denseEnabled || hits.length <= 1 || query.trim().length === 0)
|
|
132
133
|
return hits.slice(0, limit);
|
|
133
134
|
const pool = hits.slice(0, Math.min(hits.length, 32));
|
|
134
|
-
const
|
|
135
|
+
const cacheDir = options.cacheDir ?? join(dirname(options.memoriesDir), 'cache', 'dsh-cross-memory');
|
|
136
|
+
const scores = await denseScores(pool.map((hit) => hit.entry), query, { url: options.denseUrl, model: options.denseModel, cacheDir });
|
|
135
137
|
if (scores.size === 0)
|
|
136
138
|
return hits.slice(0, limit);
|
|
137
139
|
const lexical = pool.map((hit) => hit.entry.id);
|
|
@@ -273,7 +275,7 @@ export async function handleMcpRequest(request, options, store = new MemoryStore
|
|
|
273
275
|
return ok({
|
|
274
276
|
protocolVersion: requested,
|
|
275
277
|
capabilities: { tools: {} },
|
|
276
|
-
serverInfo: { name: 'dsh-cross-memory', version: '0.2.
|
|
278
|
+
serverInfo: { name: 'dsh-cross-memory', version: '0.2.14' },
|
|
277
279
|
});
|
|
278
280
|
}
|
|
279
281
|
case 'notifications/initialized':
|
package/lib/notify.js
CHANGED
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @module dsh-cross-memory/notify
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import { execFile } from 'node:child_process';
|
|
13
|
+
import { promisify } from 'node:util';
|
|
14
|
+
const execFileAsync = promisify(execFile);
|
|
13
15
|
/**
|
|
14
|
-
* Post a macOS notification
|
|
16
|
+
* Post a macOS notification asynchronously so the Host event loop is never
|
|
17
|
+
* blocked waiting on AppleScript.
|
|
15
18
|
*
|
|
16
19
|
* Deliberately the quiet kind: no sound, no focus steal. The point is that a
|
|
17
20
|
* notice is not lost, not that it interrupts. Never throws — a notification
|
|
@@ -21,11 +24,13 @@ import { spawnSync } from 'node:child_process';
|
|
|
21
24
|
* @param message - notification body.
|
|
22
25
|
* @returns whether `osascript` accepted it.
|
|
23
26
|
*/
|
|
24
|
-
export function systemNotification(title, message) {
|
|
27
|
+
export async function systemNotification(title, message) {
|
|
28
|
+
if (process.platform !== 'darwin')
|
|
29
|
+
return false;
|
|
25
30
|
const script = `display notification "${message.replace(/["\\]/gu, '')}" with title "${title.replace(/["\\]/gu, '')}"`;
|
|
26
31
|
try {
|
|
27
|
-
|
|
28
|
-
return
|
|
32
|
+
await execFileAsync('osascript', ['-e', script], { timeout: 3_000 });
|
|
33
|
+
return true;
|
|
29
34
|
}
|
|
30
35
|
catch {
|
|
31
36
|
return false;
|
package/lib/raw-recall.js
CHANGED
|
@@ -167,8 +167,20 @@ export function windowAroundQuote(messages, quote, maxChars = 600) {
|
|
|
167
167
|
/** Cache of parsed transcripts, keyed by sessions dir + session id. */
|
|
168
168
|
const transcriptCache = new Map();
|
|
169
169
|
const CACHE_TTL_MS = 10 * 60_000;
|
|
170
|
+
const MAX_TRANSCRIPT_CACHE = 128;
|
|
170
171
|
const INDEX_TTL_MS = 60_000;
|
|
171
172
|
const indexCache = new Map();
|
|
173
|
+
function setTranscriptCache(key, entry) {
|
|
174
|
+
if (transcriptCache.has(key))
|
|
175
|
+
transcriptCache.delete(key);
|
|
176
|
+
transcriptCache.set(key, entry);
|
|
177
|
+
while (transcriptCache.size > MAX_TRANSCRIPT_CACHE) {
|
|
178
|
+
const oldest = transcriptCache.keys().next().value;
|
|
179
|
+
if (oldest === undefined)
|
|
180
|
+
break;
|
|
181
|
+
transcriptCache.delete(oldest);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
172
184
|
/** Normalize a log directory name and a session id to the same form. */
|
|
173
185
|
function normalizeSession(id) {
|
|
174
186
|
return id.replace(/^session-/u, '');
|
|
@@ -206,15 +218,15 @@ export async function readTranscript(sessionsDir, sessionId, now = Date.now()) {
|
|
|
206
218
|
try {
|
|
207
219
|
const log = (await logIndex(sessionsDir, now)).get(normalizeSession(sessionId));
|
|
208
220
|
if (log === undefined) {
|
|
209
|
-
|
|
221
|
+
setTranscriptCache(key, { at: now, messages: undefined });
|
|
210
222
|
return undefined;
|
|
211
223
|
}
|
|
212
224
|
const parsed = await readSessionLog(log.file, log.modifiedAt);
|
|
213
|
-
|
|
225
|
+
setTranscriptCache(key, { at: now, messages: parsed?.messages });
|
|
214
226
|
return parsed?.messages;
|
|
215
227
|
}
|
|
216
228
|
catch {
|
|
217
|
-
|
|
229
|
+
setTranscriptCache(key, { at: now, messages: undefined });
|
|
218
230
|
return undefined;
|
|
219
231
|
}
|
|
220
232
|
}
|
|
@@ -279,7 +291,7 @@ export async function collectRagExcerpts(sessionsDir, query, limits = {}) {
|
|
|
279
291
|
if (messages === undefined)
|
|
280
292
|
continue;
|
|
281
293
|
for (const chunk of turnChunks(messages))
|
|
282
|
-
turns.push({ sessionId, chunk });
|
|
294
|
+
turns.push({ sessionId, chunk: { ...chunk, sessionId } });
|
|
283
295
|
}
|
|
284
296
|
// Document frequency across every turn in this history, so the scorer can tell
|
|
285
297
|
// a word that appears everywhere from a word that names the thing.
|
|
@@ -290,8 +302,7 @@ export async function collectRagExcerpts(sessionsDir, query, limits = {}) {
|
|
|
290
302
|
}
|
|
291
303
|
const candidates = [];
|
|
292
304
|
for (const item of selectTurnExcerpts(turns.map((turn) => turn.chunk), query, df, { maxExcerpts, maxChars, maxBytes })) {
|
|
293
|
-
|
|
294
|
-
candidates.push({ excerpt: { ...item.excerpt, sessionId: turn?.sessionId ?? '' }, score: item.score });
|
|
305
|
+
candidates.push({ excerpt: item.excerpt, score: item.score });
|
|
295
306
|
}
|
|
296
307
|
// Merge across sessions by score: one conversation that happens to hold several
|
|
297
308
|
// matching turns must not crowd out the conversation that holds the answer.
|
|
@@ -378,7 +389,7 @@ function selectTurnExcerpts(turns, query, df, limits = {}) {
|
|
|
378
389
|
return scored.map((item) => {
|
|
379
390
|
const window = bestWindow(item.turn.text.trim(), queryTokens, maxChars);
|
|
380
391
|
const text = redactSecrets(window.text.trim()).replace(/\s+/gu, ' ').slice(0, maxChars);
|
|
381
|
-
return { excerpt: { sessionId: '', seq: item.turn.seq, role: 'assistant', text }, score: item.score };
|
|
392
|
+
return { excerpt: { sessionId: item.turn.sessionId ?? '', seq: item.turn.seq, role: 'assistant', text }, score: item.score };
|
|
382
393
|
}).filter((item) => item.excerpt.text.length >= 24);
|
|
383
394
|
}
|
|
384
395
|
export async function collectExcerpts(sessionsDir, sources, query, limits = {}) {
|
package/lib/state.js
CHANGED
|
@@ -500,8 +500,10 @@ export class StateStore {
|
|
|
500
500
|
* @param now - clock to record.
|
|
501
501
|
*/
|
|
502
502
|
markConsolidated(refs, now = Date.now()) {
|
|
503
|
-
|
|
504
|
-
|
|
503
|
+
if (refs.length === 0)
|
|
504
|
+
return;
|
|
505
|
+
if (this.db === undefined) {
|
|
506
|
+
for (const ref of refs) {
|
|
505
507
|
const key = `${ref.scope}\u0000${ref.id}`;
|
|
506
508
|
const previous = this.usage.get(key);
|
|
507
509
|
this.usage.set(key, {
|
|
@@ -510,12 +512,22 @@ export class StateStore {
|
|
|
510
512
|
surfacedAt: previous?.surfacedAt ?? 0,
|
|
511
513
|
consolidatedAt: now,
|
|
512
514
|
});
|
|
513
|
-
continue;
|
|
514
515
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const stmt = this.db.prepare(`
|
|
519
|
+
INSERT INTO usage (scope, id, uses, last_used_at, consolidated_at) VALUES (?, ?, 0, 0, ?)
|
|
520
|
+
ON CONFLICT(scope, id) DO UPDATE SET consolidated_at = excluded.consolidated_at
|
|
521
|
+
`);
|
|
522
|
+
this.db.exec('BEGIN');
|
|
523
|
+
try {
|
|
524
|
+
for (const ref of refs)
|
|
525
|
+
stmt.run(ref.scope, ref.id, now);
|
|
526
|
+
this.db.exec('COMMIT');
|
|
527
|
+
}
|
|
528
|
+
catch (error) {
|
|
529
|
+
this.db.exec('ROLLBACK');
|
|
530
|
+
throw error;
|
|
519
531
|
}
|
|
520
532
|
}
|
|
521
533
|
/** Every usage row with all four timestamps, for the retention pass. */
|
package/lib/sync.js
CHANGED
|
@@ -47,6 +47,7 @@ export const STORE_GITIGNORE = [
|
|
|
47
47
|
'**/index.json',
|
|
48
48
|
'# a project descriptor records THIS machine\'s checkout path',
|
|
49
49
|
'**/project.json',
|
|
50
|
+
'cache/',
|
|
50
51
|
'pending/',
|
|
51
52
|
'*.log',
|
|
52
53
|
'.DS_Store',
|
|
@@ -418,6 +419,7 @@ export class MemorySync {
|
|
|
418
419
|
debounce;
|
|
419
420
|
pushing = false;
|
|
420
421
|
inflight;
|
|
422
|
+
dirtyWhileInflight = false;
|
|
421
423
|
lastOutcome;
|
|
422
424
|
constructor(options) {
|
|
423
425
|
this.options = options;
|
|
@@ -514,6 +516,8 @@ export class MemorySync {
|
|
|
514
516
|
* commit and the network happen later, on the debounce timer.
|
|
515
517
|
*/
|
|
516
518
|
queueCommit() {
|
|
519
|
+
if (this.inflight !== undefined)
|
|
520
|
+
this.dirtyWhileInflight = true;
|
|
517
521
|
if (this.debounce !== undefined)
|
|
518
522
|
return;
|
|
519
523
|
this.debounce = setTimeout(() => {
|
|
@@ -536,9 +540,14 @@ export class MemorySync {
|
|
|
536
540
|
async run(reason) {
|
|
537
541
|
if (this.inflight !== undefined)
|
|
538
542
|
return await this.inflight;
|
|
543
|
+
this.dirtyWhileInflight = false;
|
|
539
544
|
this.inflight = this.flush(reason).finally(() => { this.inflight = undefined; });
|
|
540
545
|
const outcome = await this.inflight;
|
|
541
546
|
this.lastOutcome = outcome;
|
|
547
|
+
if (this.dirtyWhileInflight && this.debounce === undefined) {
|
|
548
|
+
this.dirtyWhileInflight = false;
|
|
549
|
+
this.queueCommit();
|
|
550
|
+
}
|
|
542
551
|
return outcome;
|
|
543
552
|
}
|
|
544
553
|
/** The body of one run; see {@link run}. */
|
|
@@ -559,7 +568,9 @@ export class MemorySync {
|
|
|
559
568
|
resolvedByTime = pull.resolvedByTime;
|
|
560
569
|
mergedByStructure = pull.mergedByStructure;
|
|
561
570
|
stoppedBy = pull.stoppedBy;
|
|
562
|
-
|
|
571
|
+
if (stoppedBy !== 'rebase-not-started') {
|
|
572
|
+
pushed = await this.push();
|
|
573
|
+
}
|
|
563
574
|
}
|
|
564
575
|
if (committed > 0 || pulled > 0 || conflicts > 0 || pushed || stoppedBy !== undefined) {
|
|
565
576
|
this.options.log.info('dsh-cross-memory: 记忆库同步(%s):提交 %d、拉取 %d、推送 %s、冲突 %d(AI %d / 时间 %d / 结构 %d)%s', reason, committed, pulled, pushed ? '是' : '否', conflicts, resolvedByResolver, resolvedByTime, mergedByStructure, stoppedBy === undefined ? '' : ',止于 ' + stoppedBy);
|
package/lib/test/mcp.test.js
CHANGED
|
@@ -8,7 +8,7 @@ import { mkdtemp, rm } from 'node:fs/promises';
|
|
|
8
8
|
import { tmpdir } from 'node:os';
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
import test from 'node:test';
|
|
11
|
-
import { handleMcpRequest } from '../mcp.js';
|
|
11
|
+
import { handleMcpRequest, defaultMcpOptions } from '../mcp.js';
|
|
12
12
|
import { writePersona } from '../persona.js';
|
|
13
13
|
test('MCP server supports initialize, tools/list, persona, write (with redaction), search, read, and projects', async (t) => {
|
|
14
14
|
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-mcp-'));
|
|
@@ -96,3 +96,8 @@ test('MCP server supports initialize, tools/list, persona, write (with redaction
|
|
|
96
96
|
const projectsText = (projectsRes?.result).content[0].text;
|
|
97
97
|
assert.match(projectsText, /fake-repo \(1 entries\)/u);
|
|
98
98
|
});
|
|
99
|
+
test('defaultMcpOptions keeps dense cache outside memoriesDir', () => {
|
|
100
|
+
const opts = defaultMcpOptions({ DSH_HOME: '/tmp/fake-dsh' });
|
|
101
|
+
assert.equal(opts.memoriesDir, '/tmp/fake-dsh/memories');
|
|
102
|
+
assert.equal(opts.cacheDir, '/tmp/fake-dsh/cache/dsh-cross-memory');
|
|
103
|
+
});
|
package/lib/test/recall.test.js
CHANGED
|
@@ -14,7 +14,7 @@ import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
|
14
14
|
import { tmpdir } from 'node:os';
|
|
15
15
|
import { join } from 'node:path';
|
|
16
16
|
import test from 'node:test';
|
|
17
|
-
import { MemoriesRuntime } from '../index.js';
|
|
17
|
+
import { MemoriesRuntime, isSubagentSession } from '../index.js';
|
|
18
18
|
import { renderRecall } from '../render.js';
|
|
19
19
|
import { hubTerms, matchCredit } from '../search.js';
|
|
20
20
|
import { Logger } from '@deepseek-ai/cordis';
|
|
@@ -466,3 +466,56 @@ test('the stronger lexical match is listed first, even when a weaker one is fres
|
|
|
466
466
|
assert.ok(weaker >= 0, `the weaker match is still worth a slot, got: ${text}`);
|
|
467
467
|
assert.ok(exact < weaker, `the memory the turn is about comes first, got: ${text}`);
|
|
468
468
|
});
|
|
469
|
+
test('recallFor deduplicates repeated steps within the same human user turn and continuation turns', async (t) => {
|
|
470
|
+
const { dir, runtime } = await fixture(t, { ragRecall: true });
|
|
471
|
+
const entries = join(dir, 'entries');
|
|
472
|
+
await mkdir(entries, { recursive: true });
|
|
473
|
+
await writeFile(join(entries, 'alpha.md'), [
|
|
474
|
+
'---',
|
|
475
|
+
'id: alpha',
|
|
476
|
+
'scope: global',
|
|
477
|
+
'kind: fact',
|
|
478
|
+
'title: 阿尔法构建规矩',
|
|
479
|
+
'tags: build',
|
|
480
|
+
'keys: alpha, build',
|
|
481
|
+
'created: 2026-01-01T00:00:00.000Z',
|
|
482
|
+
'updated: 2026-01-01T00:00:00.000Z',
|
|
483
|
+
'source: auto',
|
|
484
|
+
'---',
|
|
485
|
+
'',
|
|
486
|
+
'阿尔法仓库必须先跑 build 再跑 test。',
|
|
487
|
+
].join('\n'));
|
|
488
|
+
let messages = [
|
|
489
|
+
{ id: 'u1', role: 'user', source: { kind: 'user' }, content: [{ type: 'text', text: '阿尔法仓库 build 规矩是什么' }] },
|
|
490
|
+
];
|
|
491
|
+
const session = {
|
|
492
|
+
id: 'dedup-turn-session',
|
|
493
|
+
header: { version: 0, id: 'dedup-turn-session', createdAt: 0, cwd: dir, isSeeded: false },
|
|
494
|
+
seq: 1,
|
|
495
|
+
requestHeader: () => undefined,
|
|
496
|
+
deriveMessages: () => messages,
|
|
497
|
+
};
|
|
498
|
+
const agent = stubAgent(session);
|
|
499
|
+
// Simulate RAG excerpts on the first step; second step and continuation turn must not duplicate them.
|
|
500
|
+
let ragCalls = 0;
|
|
501
|
+
runtime.ragExcerpts = async () => {
|
|
502
|
+
ragCalls += 1;
|
|
503
|
+
return [{ sessionId: 'other-session', seq: 1, role: 'assistant', text: '阿尔法仓库 build 规矩:先 build 再 test,这是一段历史对话原文片段。' }];
|
|
504
|
+
};
|
|
505
|
+
const first = await runtime.recallFor(agent);
|
|
506
|
+
assert.ok(first !== undefined, 'first step recalls');
|
|
507
|
+
assert.equal(ragCalls, 1);
|
|
508
|
+
// Simulate tool-call step 2 AND a refusal-guard continuation message on the same user turn.
|
|
509
|
+
messages = [
|
|
510
|
+
...messages,
|
|
511
|
+
{ id: 'c1', role: 'user', source: { kind: 'cordis-host-runner' }, content: [{ type: 'text', text: '继续' }] },
|
|
512
|
+
];
|
|
513
|
+
const second = await runtime.recallFor(agent);
|
|
514
|
+
assert.equal(second, undefined, 'same user turn must not trigger duplicate RAG or recall');
|
|
515
|
+
assert.equal(ragCalls, 1, 'ragExcerpts must not re-run for the same user turn');
|
|
516
|
+
});
|
|
517
|
+
test('isSubagentSession detects subagent origin and delegationDepth', () => {
|
|
518
|
+
assert.equal(isSubagentSession({ header: { origin: 'subagent' } }), true);
|
|
519
|
+
assert.equal(isSubagentSession({ header: { delegationDepth: 1 } }), true);
|
|
520
|
+
assert.equal(isSubagentSession({ header: { origin: 'interactive', delegationDepth: 0 } }), false);
|
|
521
|
+
});
|
package/lib/test/sync.test.js
CHANGED
|
@@ -76,6 +76,8 @@ test('machine state is kept out of the repository', async () => {
|
|
|
76
76
|
await mkdir(join(base, 'entries'), { recursive: true });
|
|
77
77
|
await writeFile(join(base, 'state.db'), 'binary');
|
|
78
78
|
await writeFile(join(base, 'index.json'), '{}');
|
|
79
|
+
await mkdir(join(base, 'cache'), { recursive: true });
|
|
80
|
+
await writeFile(join(base, 'cache', 'dense-test.json'), '{}');
|
|
79
81
|
await writeFile(join(base, 'entries', 'one.md'), entryText('one', 'kept', '2026-02-01T00:00:00.000Z'));
|
|
80
82
|
const sync = new MemorySync({ memoriesDir: base, remote: '', intervalMs: 0, debounceMs: 0, gitTimeoutMs: 20_000, networkTimeoutMs: 20_000, log: quietLog, host: 'test' });
|
|
81
83
|
await sync.init();
|
|
@@ -83,6 +85,8 @@ test('machine state is kept out of the repository', async () => {
|
|
|
83
85
|
assert.ok(tracked.includes('entries/one.md'), 'an entry is tracked');
|
|
84
86
|
assert.ok(!tracked.includes('state.db'), 'the database is not tracked');
|
|
85
87
|
assert.ok(!tracked.includes('index.json'), 'the index cache is not tracked');
|
|
88
|
+
assert.ok(!tracked.includes('cache/dense-test.json'), 'the dense cache is not tracked');
|
|
89
|
+
assert.ok(STORE_GITIGNORE.includes('cache/'));
|
|
86
90
|
assert.equal(await readFile(join(base, '.gitignore'), 'utf8'), STORE_GITIGNORE);
|
|
87
91
|
});
|
|
88
92
|
test('only entry paths are auto-resolved, and the newer revision wins without a resolver', () => {
|
package/lib/types/backfill.d.ts
CHANGED
|
@@ -59,6 +59,11 @@ export declare function zstdAvailable(): boolean;
|
|
|
59
59
|
* @throws when the Node build has no zstd support.
|
|
60
60
|
*/
|
|
61
61
|
export declare function decodeSessionLog(buffer: Buffer): string;
|
|
62
|
+
/**
|
|
63
|
+
* Async variant of {@link decodeSessionLog}: decompresses frames on libuv's
|
|
64
|
+
* worker pool so large persisted logs never stall the Host event loop.
|
|
65
|
+
*/
|
|
66
|
+
export declare function decodeSessionLogAsync(buffer: Buffer): Promise<string>;
|
|
62
67
|
/**
|
|
63
68
|
* Parse one decoded session log.
|
|
64
69
|
*
|
package/lib/types/dense.d.ts
CHANGED
|
@@ -11,18 +11,23 @@ export interface DenseOptions {
|
|
|
11
11
|
readonly model: string;
|
|
12
12
|
/** Directory holding the JSON vector cache. */
|
|
13
13
|
readonly cacheDir: string;
|
|
14
|
+
/** Optional HTTP request timeout in milliseconds (default 5000). */
|
|
15
|
+
readonly timeoutMs?: number;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* Embed texts, reusing the on-disk cache.
|
|
17
19
|
*
|
|
18
20
|
* Failures propagate: the caller decides whether to fall back. The cache is
|
|
19
|
-
* written only after every batch succeeded, so a partial run never
|
|
21
|
+
* written atomically only after every batch succeeded, so a partial run never
|
|
22
|
+
* poisons it. Ephemeral texts (like one-off queries) can pass `persistCount`
|
|
23
|
+
* to avoid bloating the on-disk cache with unshared query vectors.
|
|
20
24
|
*
|
|
21
25
|
* @param texts - texts to embed, in order.
|
|
22
26
|
* @param options - service location, model, and cache directory.
|
|
27
|
+
* @param persistCount - how many leading items belong in the persistent cache (defaults to all).
|
|
23
28
|
* @returns one unit vector per text.
|
|
24
29
|
*/
|
|
25
|
-
export declare function embed(texts: readonly string[], options: DenseOptions): Promise<Float32Array[]>;
|
|
30
|
+
export declare function embed(texts: readonly string[], options: DenseOptions, persistCount?: number): Promise<Float32Array[]>;
|
|
26
31
|
/**
|
|
27
32
|
* Cosine similarity of two unit vectors (a dot product).
|
|
28
33
|
* @param left - one vector.
|
package/lib/types/index.d.ts
CHANGED
|
@@ -49,6 +49,8 @@ interface ScopeState {
|
|
|
49
49
|
readonly heading: string;
|
|
50
50
|
readonly entries: readonly MemoryEntry[];
|
|
51
51
|
}
|
|
52
|
+
/** Whether a session is a subagent rather than an interactive top-level session. */
|
|
53
|
+
export declare function isSubagentSession(session: Session): boolean;
|
|
52
54
|
/**
|
|
53
55
|
* The memory runtime: one instance per plugin mount, shared by the tool, the
|
|
54
56
|
* injector, the extractor, and the command handler.
|
|
@@ -104,6 +106,8 @@ export declare class MemoriesRuntime {
|
|
|
104
106
|
private readonly injected;
|
|
105
107
|
/** Recall deltas already injected into each conversation. */
|
|
106
108
|
private readonly recallCounts;
|
|
109
|
+
/** Latest human user turn id/seq whose full-history RAG excerpts were already injected. */
|
|
110
|
+
private readonly lastRagTurn;
|
|
107
111
|
/** Late memory blocks already injected into each conversation. */
|
|
108
112
|
private readonly deltaCounts;
|
|
109
113
|
/** The user-turn number at which each conversation last emitted a rotation block. */
|
|
@@ -603,7 +607,10 @@ export declare class MemoriesRuntime {
|
|
|
603
607
|
* @param session - session to read.
|
|
604
608
|
* @returns the text, or `undefined` when no user message is on the surface.
|
|
605
609
|
*/
|
|
610
|
+
private latestUserTurn;
|
|
606
611
|
private latestUserText;
|
|
612
|
+
/** Clean up per-session maps when an agent disposes. */
|
|
613
|
+
forgetSession(sessionId: string): void;
|
|
607
614
|
/** Whether memory is switched off for one session. */
|
|
608
615
|
private sessionOff;
|
|
609
616
|
/** Entry ids already shown to one conversation, created on first use. */
|
|
@@ -698,6 +705,8 @@ export declare class MemoriesRuntime {
|
|
|
698
705
|
stopPeriodicSync(): void;
|
|
699
706
|
/** Record that a memory changed; the commit and the network happen later. */
|
|
700
707
|
private markStoreChanged;
|
|
708
|
+
/** The boot notice check's timer, when one is armed. */
|
|
709
|
+
private bootNoticeTimer;
|
|
701
710
|
/** The periodic check's timer, when one is armed. */
|
|
702
711
|
private periodicTimer;
|
|
703
712
|
/** The store's git transport; see {@link StoreSyncService}. */
|
|
@@ -779,6 +788,7 @@ export declare class MemoriesRuntime {
|
|
|
779
788
|
/** Cancel a pending extraction timer. */
|
|
780
789
|
cancelExtraction(agent: Agent): void;
|
|
781
790
|
/** Remember an agent so a process exit can still mine it. */
|
|
791
|
+
private readonly trackedAgents;
|
|
782
792
|
private track;
|
|
783
793
|
/**
|
|
784
794
|
* Mine every tracked agent once, right now.
|
package/lib/types/mcp.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { MemoryStore } from './storage.js';
|
|
|
3
3
|
/** Runtime options for the MCP server. */
|
|
4
4
|
export interface McpServerOptions {
|
|
5
5
|
readonly memoriesDir: string;
|
|
6
|
+
readonly cacheDir?: string;
|
|
6
7
|
readonly denseEnabled: boolean;
|
|
7
8
|
readonly denseUrl: string;
|
|
8
9
|
readonly denseModel: string;
|
package/lib/types/notify.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Post a macOS notification
|
|
2
|
+
* Post a macOS notification asynchronously so the Host event loop is never
|
|
3
|
+
* blocked waiting on AppleScript.
|
|
3
4
|
*
|
|
4
5
|
* Deliberately the quiet kind: no sound, no focus steal. The point is that a
|
|
5
6
|
* notice is not lost, not that it interrupts. Never throws — a notification
|
|
@@ -9,4 +10,4 @@
|
|
|
9
10
|
* @param message - notification body.
|
|
10
11
|
* @returns whether `osascript` accepted it.
|
|
11
12
|
*/
|
|
12
|
-
export declare function systemNotification(title: string, message: string): boolean
|
|
13
|
+
export declare function systemNotification(title: string, message: string): Promise<boolean>;
|
|
@@ -99,6 +99,7 @@ export declare function collectRagExcerpts(sessionsDir: string, query: string, l
|
|
|
99
99
|
}): Promise<RawExcerpt[]>;
|
|
100
100
|
/** One user turn and the assistant turns that answered it. */
|
|
101
101
|
export interface TurnChunk {
|
|
102
|
+
readonly sessionId?: string;
|
|
102
103
|
readonly seq: number;
|
|
103
104
|
readonly text: string;
|
|
104
105
|
}
|
package/lib/types/sync.d.ts
CHANGED
|
@@ -174,6 +174,7 @@ export declare class MemorySync {
|
|
|
174
174
|
private debounce;
|
|
175
175
|
private pushing;
|
|
176
176
|
private inflight;
|
|
177
|
+
private dirtyWhileInflight;
|
|
177
178
|
private lastOutcome;
|
|
178
179
|
constructor(options: MemorySyncOptions);
|
|
179
180
|
/** The outcome of the last completed run, when there was one. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cross-memory",
|
|
3
3
|
"description": "Cross-session memory for the DeepSeek Harness: project-scoped and global memories with an explicit memory tool, idle-time background extraction, consolidation, and layered summary injection",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.14",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -102,12 +102,12 @@
|
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"@deepseek-ai/cordis": "^4.0.5 || ^4.0.6-alpha.1",
|
|
105
|
-
"@deepseek-ai/dsh-agent": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
|
|
106
|
-
"@deepseek-ai/dsh-commands": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
|
|
107
|
-
"@deepseek-ai/dsh-home-paths": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
|
|
108
|
-
"@deepseek-ai/dsh-llm": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
|
|
109
|
-
"@deepseek-ai/dsh-session": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
|
|
110
|
-
"@deepseek-ai/dsh-tools": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
|
|
105
|
+
"@deepseek-ai/dsh-agent": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1",
|
|
106
|
+
"@deepseek-ai/dsh-commands": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1",
|
|
107
|
+
"@deepseek-ai/dsh-home-paths": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1",
|
|
108
|
+
"@deepseek-ai/dsh-llm": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1",
|
|
109
|
+
"@deepseek-ai/dsh-session": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1",
|
|
110
|
+
"@deepseek-ai/dsh-tools": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1",
|
|
111
111
|
"@deepseek-ai/schemastery": "^3.18.5 || ^3.18.6-alpha.1"
|
|
112
112
|
},
|
|
113
113
|
"devDependencies": {
|