dsh-cross-memory 0.0.0-stage → 0.2.1
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 +21 -0
- package/README.md +253 -2
- package/cordis.patch.yml +27 -0
- package/docs/DETAIL.md +13 -0
- package/docs/DETAIL.zh.md +17 -0
- package/icon.svg +1 -0
- package/lib/backfill.js +273 -0
- package/lib/citations.js +305 -0
- package/lib/client.js +1660 -0
- package/lib/config.js +736 -0
- package/lib/consolidate.js +1119 -0
- package/lib/extract.js +570 -0
- package/lib/gate.js +137 -0
- package/lib/git-origin.js +224 -0
- package/lib/index.js +4482 -0
- package/lib/log.js +260 -0
- package/lib/loops.js +186 -0
- package/lib/notices.js +195 -0
- package/lib/notify.js +33 -0
- package/lib/persona.js +163 -0
- package/lib/query.js +93 -0
- package/lib/raw-recall.js +286 -0
- package/lib/reflection.js +291 -0
- package/lib/remote.js +490 -0
- package/lib/render.js +678 -0
- package/lib/retention.js +64 -0
- package/lib/schedule.js +245 -0
- package/lib/search.js +1068 -0
- package/lib/skills.js +220 -0
- package/lib/state.js +701 -0
- package/lib/storage.js +1424 -0
- package/lib/sync-runtime.js +268 -0
- package/lib/sync.js +620 -0
- package/lib/test/activity.test.js +74 -0
- package/lib/test/archive.test.js +182 -0
- package/lib/test/backfill.test.js +144 -0
- package/lib/test/citations.test.js +91 -0
- package/lib/test/client-wiring.test.js +134 -0
- package/lib/test/consolidate-job.test.js +95 -0
- package/lib/test/consolidate.test.js +430 -0
- package/lib/test/consolidation-selection.test.js +152 -0
- package/lib/test/dedupe-keys.test.js +230 -0
- package/lib/test/delta.test.js +93 -0
- package/lib/test/derived.test.js +110 -0
- package/lib/test/disputes-panel.test.js +341 -0
- package/lib/test/eval.test.js +171 -0
- package/lib/test/expand.test.js +164 -0
- package/lib/test/extract.test.js +1020 -0
- package/lib/test/git-origin.test.js +189 -0
- package/lib/test/injection.test.js +440 -0
- package/lib/test/kind-filter.test.js +49 -0
- package/lib/test/legacy-state.test.js +69 -0
- package/lib/test/log.test.js +156 -0
- package/lib/test/loops.test.js +86 -0
- package/lib/test/memory.test.js +855 -0
- package/lib/test/notices.test.js +142 -0
- package/lib/test/persona.test.js +86 -0
- package/lib/test/prefilter.test.js +73 -0
- package/lib/test/preset.test.js +77 -0
- package/lib/test/raw-recall.test.js +186 -0
- package/lib/test/recall.test.js +433 -0
- package/lib/test/reflection.test.js +64 -0
- package/lib/test/remote.test.js +238 -0
- package/lib/test/retention.test.js +117 -0
- package/lib/test/retrieval.test.js +142 -0
- package/lib/test/rotation.test.js +228 -0
- package/lib/test/schedule.test.js +112 -0
- package/lib/test/settings-card.test.js +58 -0
- package/lib/test/skills.test.js +129 -0
- package/lib/test/state.test.js +212 -0
- package/lib/test/subagent-contract.test.js +139 -0
- package/lib/test/sweep.test.js +159 -0
- package/lib/test/sync.test.js +314 -0
- package/lib/test/time.test.js +171 -0
- package/lib/time.js +303 -0
- package/lib/tool.js +330 -0
- package/lib/types/backfill.d.ts +96 -0
- package/lib/types/citations.d.ts +105 -0
- package/lib/types/config.d.ts +811 -0
- package/lib/types/consolidate.d.ts +742 -0
- package/lib/types/extract.d.ts +352 -0
- package/lib/types/gate.d.ts +83 -0
- package/lib/types/git-origin.d.ts +23 -0
- package/lib/types/index.d.ts +1316 -0
- package/lib/types/log.d.ts +144 -0
- package/lib/types/loops.d.ts +82 -0
- package/lib/types/notices.d.ts +117 -0
- package/lib/types/notify.d.ts +12 -0
- package/lib/types/persona.d.ts +76 -0
- package/lib/types/query.d.ts +45 -0
- package/lib/types/raw-recall.d.ts +84 -0
- package/lib/types/reflection.d.ts +122 -0
- package/lib/types/remote.d.ts +246 -0
- package/lib/types/render.d.ts +286 -0
- package/lib/types/retention.d.ts +66 -0
- package/lib/types/schedule.d.ts +116 -0
- package/lib/types/search.d.ts +583 -0
- package/lib/types/skills.d.ts +71 -0
- package/lib/types/state.d.ts +294 -0
- package/lib/types/storage.d.ts +458 -0
- package/lib/types/sync-runtime.d.ts +103 -0
- package/lib/types/sync.d.ts +222 -0
- package/lib/types/test/activity.test.d.ts +1 -0
- package/lib/types/test/archive.test.d.ts +1 -0
- package/lib/types/test/backfill.test.d.ts +1 -0
- package/lib/types/test/citations.test.d.ts +1 -0
- package/lib/types/test/client-wiring.test.d.ts +1 -0
- package/lib/types/test/consolidate-job.test.d.ts +1 -0
- package/lib/types/test/consolidate.test.d.ts +1 -0
- package/lib/types/test/consolidation-selection.test.d.ts +1 -0
- package/lib/types/test/dedupe-keys.test.d.ts +1 -0
- package/lib/types/test/delta.test.d.ts +1 -0
- package/lib/types/test/derived.test.d.ts +1 -0
- package/lib/types/test/disputes-panel.test.d.ts +1 -0
- package/lib/types/test/eval.test.d.ts +1 -0
- package/lib/types/test/expand.test.d.ts +1 -0
- package/lib/types/test/extract.test.d.ts +1 -0
- package/lib/types/test/git-origin.test.d.ts +1 -0
- package/lib/types/test/injection.test.d.ts +1 -0
- package/lib/types/test/kind-filter.test.d.ts +1 -0
- package/lib/types/test/legacy-state.test.d.ts +1 -0
- package/lib/types/test/log.test.d.ts +1 -0
- package/lib/types/test/loops.test.d.ts +1 -0
- package/lib/types/test/memory.test.d.ts +1 -0
- package/lib/types/test/notices.test.d.ts +1 -0
- package/lib/types/test/persona.test.d.ts +1 -0
- package/lib/types/test/prefilter.test.d.ts +1 -0
- package/lib/types/test/preset.test.d.ts +1 -0
- package/lib/types/test/raw-recall.test.d.ts +1 -0
- package/lib/types/test/recall.test.d.ts +1 -0
- package/lib/types/test/reflection.test.d.ts +1 -0
- package/lib/types/test/remote.test.d.ts +1 -0
- package/lib/types/test/retention.test.d.ts +1 -0
- package/lib/types/test/retrieval.test.d.ts +1 -0
- package/lib/types/test/rotation.test.d.ts +1 -0
- package/lib/types/test/schedule.test.d.ts +1 -0
- package/lib/types/test/settings-card.test.d.ts +1 -0
- package/lib/types/test/skills.test.d.ts +1 -0
- package/lib/types/test/state.test.d.ts +1 -0
- package/lib/types/test/subagent-contract.test.d.ts +1 -0
- package/lib/types/test/sweep.test.d.ts +1 -0
- package/lib/types/test/sync.test.d.ts +1 -0
- package/lib/types/test/time.test.d.ts +1 -0
- package/lib/types/time.d.ts +67 -0
- package/lib/types/tool.d.ts +9 -0
- package/lib/types/types.d.ts +374 -0
- package/lib/types/workspace.d.ts +20 -0
- package/lib/types.js +47 -0
- package/lib/workspace.js +65 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +126 -4
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the memory store, search, and rendering layers.
|
|
3
|
+
*
|
|
4
|
+
* @module dsh-cross-memory/test/storage.test
|
|
5
|
+
*/
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises';
|
|
8
|
+
import { tmpdir } from 'node:os';
|
|
9
|
+
import { join, resolve } from 'node:path';
|
|
10
|
+
import test from 'node:test';
|
|
11
|
+
import { createVolatile, updateVolatile } from '@deepseek-ai/cosmokit';
|
|
12
|
+
import { MemoryStore, formatEntry, parseEntry, projectSlug, slugify } from '../storage.js';
|
|
13
|
+
import { browseMemories, matchCredit, relevanceOfOne, scoreEntry, searchMemories } from '../search.js';
|
|
14
|
+
import { rankForSummary, renderMemorySummary, renderOpenLoops, selectForSummary } from '../render.js';
|
|
15
|
+
import { DEFAULT_MAX_SUMMARY_BYTES, consolidationRouteOf, normalizeSettings, readTunables, resolveConfig } from '../config.js';
|
|
16
|
+
import { name } from '../index.js';
|
|
17
|
+
import { MEMORY_SOURCE_KIND } from '../types.js';
|
|
18
|
+
import { findProjectRoot, isWithin } from '../workspace.js';
|
|
19
|
+
/** Create a temporary memories directory. */
|
|
20
|
+
async function tempStore() {
|
|
21
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-'));
|
|
22
|
+
return { store: new MemoryStore(dir), dir };
|
|
23
|
+
}
|
|
24
|
+
test('slugify produces stable ids and falls back for empty input', () => {
|
|
25
|
+
assert.equal(slugify('Use pnpm, not npm!'), 'use-pnpm-not-npm');
|
|
26
|
+
assert.equal(slugify(' '), 'memory');
|
|
27
|
+
assert.equal(slugify('中文 记忆'), '中文-记忆');
|
|
28
|
+
});
|
|
29
|
+
test('projectSlug is the project name, so one project keeps one slug on every machine', () => {
|
|
30
|
+
assert.equal(projectSlug('C:\\Code\\alpha'), 'alpha');
|
|
31
|
+
assert.equal(projectSlug('/Users/you/Documents/Code/alpha'), 'alpha', 'a different machine path resolves to the same slug');
|
|
32
|
+
assert.equal(projectSlug('/Users/you/Documents/Code/my-project/'), 'my-project');
|
|
33
|
+
assert.notEqual(projectSlug('/Code/alpha'), projectSlug('/Code/beta'));
|
|
34
|
+
});
|
|
35
|
+
test('adopting a legacy path-hashed directory merges its entries instead of dropping them', async () => {
|
|
36
|
+
const { store, dir } = await tempStore();
|
|
37
|
+
const root = '/Users/you/Documents/Code/alpha';
|
|
38
|
+
// The directory the old path-hashed scheme produced, with one entry only it has.
|
|
39
|
+
const legacy = join(dir, 'projects', 'alpha-1a2b3c4d');
|
|
40
|
+
await mkdir(join(legacy, 'entries'), { recursive: true });
|
|
41
|
+
await writeFile(join(legacy, 'project.json'), JSON.stringify({ root, name: 'alpha', slug: 'alpha-1a2b3c4d', updatedAt: 1 }));
|
|
42
|
+
await writeFile(join(legacy, 'entries', 'shared.md'), [
|
|
43
|
+
'---', 'id: shared', 'scope: project', 'kind: fact', 'title: Shared', 'tags:',
|
|
44
|
+
'created: 2026-01-01T00:00:00.000Z', 'updated: 2026-01-01T00:00:00.000Z', '---', '', 'old text', '',
|
|
45
|
+
].join('\n'));
|
|
46
|
+
await writeFile(join(legacy, 'entries', 'only-legacy.md'), [
|
|
47
|
+
'---', 'id: only-legacy', 'scope: project', 'kind: fact', 'title: Only legacy', 'tags:',
|
|
48
|
+
'created: 2026-01-01T00:00:00.000Z', 'updated: 2026-01-01T00:00:00.000Z', '---', '', 'kept', '',
|
|
49
|
+
].join('\n'));
|
|
50
|
+
// The canonical directory the current scheme derives: same id, newer revision.
|
|
51
|
+
const canonical = join(dir, 'projects', 'alpha', 'entries');
|
|
52
|
+
await mkdir(canonical, { recursive: true });
|
|
53
|
+
await writeFile(join(canonical, 'shared.md'), [
|
|
54
|
+
'---', 'id: shared', 'scope: project', 'kind: fact', 'title: Shared', 'tags:',
|
|
55
|
+
'created: 2026-01-01T00:00:00.000Z', 'updated: 2026-02-01T00:00:00.000Z', '---', '', 'new text', '',
|
|
56
|
+
].join('\n'));
|
|
57
|
+
const moved = await store.adoptMisnamedProjects();
|
|
58
|
+
assert.deepEqual(moved, [{ from: 'alpha-1a2b3c4d', to: 'alpha' }]);
|
|
59
|
+
assert.deepEqual(await store.listProjects(), ['alpha']);
|
|
60
|
+
const entries = await store.list('project', root, { fresh: true });
|
|
61
|
+
assert.deepEqual(entries.map((entry) => entry.id).sort(), ['only-legacy', 'shared']);
|
|
62
|
+
assert.equal(entries.find((entry) => entry.id === 'shared')?.body, 'new text', 'the newer revision wins');
|
|
63
|
+
});
|
|
64
|
+
test('a project directory records every machine that used it', async () => {
|
|
65
|
+
const { store, dir } = await tempStore();
|
|
66
|
+
// A POSIX path is not resolvable to itself on Windows, and the descriptor
|
|
67
|
+
// stores the RESOLVED root: use a path this platform can round-trip.
|
|
68
|
+
const root = process.platform === 'win32' ? 'C:\\Users\\you\\Documents\\Code\\alpha' : '/Users/you/Documents/Code/alpha';
|
|
69
|
+
await store.writeProjectDescriptor(root, 1000);
|
|
70
|
+
const hostsDir = join(dir, 'projects', 'alpha', 'hosts');
|
|
71
|
+
const files = (await readdir(hostsDir)).filter((name) => name.endsWith('.json'));
|
|
72
|
+
assert.equal(files.length, 1, 'one descriptor for this machine');
|
|
73
|
+
const descriptor = JSON.parse(await readFile(join(hostsDir, files[0]), 'utf8'));
|
|
74
|
+
assert.equal(descriptor.root, root);
|
|
75
|
+
assert.equal(typeof descriptor.host, 'string');
|
|
76
|
+
});
|
|
77
|
+
test('the consolidation route falls back to the extraction route, then to the session', () => {
|
|
78
|
+
const base = normalizeSettings({});
|
|
79
|
+
assert.deepEqual(consolidationRouteOf(base), {}, 'no route at all reuses the session route');
|
|
80
|
+
assert.deepEqual(consolidationRouteOf({ ...base, extractProvider: 'p', extractModel: 'm' }), { provider: 'p', model: 'm' }, 'an unset consolidation route inherits extraction');
|
|
81
|
+
assert.deepEqual(consolidationRouteOf({ ...base, extractProvider: 'p', extractModel: 'm', consolidateProvider: 'q', consolidateModel: 'n' }), { provider: 'q', model: 'n' }, 'its own route wins');
|
|
82
|
+
// A lone half is not a route, exactly like the extraction pair.
|
|
83
|
+
const half = normalizeSettings({ consolidateProvider: 'q' });
|
|
84
|
+
assert.equal(half.consolidateModel, '');
|
|
85
|
+
assert.deepEqual(consolidationRouteOf({ ...half, extractProvider: 'p', extractModel: 'm' }), { provider: 'p', model: 'm' });
|
|
86
|
+
});
|
|
87
|
+
test('the quota knobs default on and clamp to zero', () => {
|
|
88
|
+
const settings = normalizeSettings({});
|
|
89
|
+
assert.equal(settings.pauseOnQuotaError, true);
|
|
90
|
+
assert.equal(settings.quotaCooldownMinutes, 30);
|
|
91
|
+
assert.equal(settings.quotaCooldownMaxMinutes, 480);
|
|
92
|
+
assert.equal(normalizeSettings({ quotaCooldownMinutes: -5 }).quotaCooldownMinutes, 0);
|
|
93
|
+
assert.equal(normalizeSettings({ pauseOnQuotaError: false }).pauseOnQuotaError, false);
|
|
94
|
+
});
|
|
95
|
+
/** Build a complete entry from the fields a test cares about. */
|
|
96
|
+
function entry(partial) {
|
|
97
|
+
return { kind: 'fact', tags: [], keys: [], createdAt: 1, updatedAt: 1, uses: 0, lastUsedAt: 0, lastSurfacedAt: 0, source: 'tool', ...partial };
|
|
98
|
+
}
|
|
99
|
+
test('entry files round-trip through format and parse', () => {
|
|
100
|
+
const value = entry({
|
|
101
|
+
id: 'prefer-pnpm',
|
|
102
|
+
scope: 'global',
|
|
103
|
+
title: 'Prefer pnpm',
|
|
104
|
+
body: 'The user standardizes on pnpm; do not run npm install.',
|
|
105
|
+
tags: ['tooling', 'packages'],
|
|
106
|
+
createdAt: 1_700_000_000_000,
|
|
107
|
+
updatedAt: 1_700_000_100_000,
|
|
108
|
+
uses: 4,
|
|
109
|
+
lastUsedAt: 1_700_000_200_000,
|
|
110
|
+
quote: 'We never run npm install here.',
|
|
111
|
+
evidenceSeq: 12,
|
|
112
|
+
});
|
|
113
|
+
const parsed = parseEntry(formatEntry(value), 'global', 'fallback');
|
|
114
|
+
assert.deepEqual(parsed, value);
|
|
115
|
+
});
|
|
116
|
+
test('an evidence quote is kept across an unchanged rewrite and dropped when the body changes', async (t) => {
|
|
117
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-evidence-'));
|
|
118
|
+
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
119
|
+
const store = new MemoryStore(dir);
|
|
120
|
+
await store.upsert({
|
|
121
|
+
scope: 'global',
|
|
122
|
+
title: 'Ship with pnpm',
|
|
123
|
+
body: 'Run pnpm run ship.',
|
|
124
|
+
tags: [],
|
|
125
|
+
quote: 'We always ship with pnpm run ship.',
|
|
126
|
+
evidenceSeq: 7,
|
|
127
|
+
sourceSession: 'session-42',
|
|
128
|
+
}, undefined, 'auto');
|
|
129
|
+
const stored = await store.read('global', undefined, 'ship-with-pnpm');
|
|
130
|
+
assert.equal(stored?.quote, 'We always ship with pnpm run ship.');
|
|
131
|
+
assert.equal(stored?.evidenceSeq, 7);
|
|
132
|
+
assert.match(await readFile(join(dir, 'entries', 'ship-with-pnpm.md'), 'utf8'), /^quote: We always ship with pnpm run ship\.$/mu);
|
|
133
|
+
// A rewrite that leaves the body alone still restates the same claim.
|
|
134
|
+
await store.upsert({ scope: 'global', title: 'Ship with pnpm', body: 'Run pnpm run ship.', tags: [] }, undefined, 'auto');
|
|
135
|
+
assert.equal((await store.read('global', undefined, 'ship-with-pnpm'))?.quote, 'We always ship with pnpm run ship.');
|
|
136
|
+
// A rewrite that changes the body may state something the excerpt never did,
|
|
137
|
+
// so the stale quote must not survive looking like proof.
|
|
138
|
+
await store.upsert({ scope: 'global', title: 'Ship with pnpm', body: 'Ship with pnpm, not npm run ship.', tags: [] }, undefined, 'auto');
|
|
139
|
+
const rewritten = await store.read('global', undefined, 'ship-with-pnpm');
|
|
140
|
+
assert.equal(rewritten?.quote, undefined);
|
|
141
|
+
assert.equal(rewritten?.evidenceSeq, undefined);
|
|
142
|
+
});
|
|
143
|
+
test('an entry records the session it came from, and keeps it across a rewrite', async (t) => {
|
|
144
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-provenance-'));
|
|
145
|
+
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
146
|
+
const store = new MemoryStore(dir);
|
|
147
|
+
await store.upsert({ scope: 'global', title: 'Ship with pnpm', body: 'Run pnpm run ship.', tags: [], sourceSession: 'session-42' }, undefined, 'auto');
|
|
148
|
+
const stored = await store.read('global', undefined, 'ship-with-pnpm');
|
|
149
|
+
assert.equal(stored?.sourceSession, 'session-42');
|
|
150
|
+
assert.match(await readFile(join(dir, 'entries', 'ship-with-pnpm.md'), 'utf8'), /^session: session-42$/mu);
|
|
151
|
+
// A consolidation rewrites the body without naming the session; provenance is
|
|
152
|
+
// not the rewriter's to drop.
|
|
153
|
+
await store.upsert({ scope: 'global', title: 'Ship with pnpm', body: 'Always run pnpm run ship.', tags: [] }, undefined, 'auto');
|
|
154
|
+
assert.equal((await store.read('global', undefined, 'ship-with-pnpm'))?.sourceSession, 'session-42');
|
|
155
|
+
});
|
|
156
|
+
test('session evidence notes round-trip, including text a plain YAML scalar would break', async (t) => {
|
|
157
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-notes-'));
|
|
158
|
+
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
159
|
+
const store = new MemoryStore(dir);
|
|
160
|
+
const path = await store.writeSessionNote({
|
|
161
|
+
session: 'session-1',
|
|
162
|
+
at: 1_700_000_000_000,
|
|
163
|
+
project: 'project:demo',
|
|
164
|
+
summary: 'The user wrote: ship with pnpm run ship.',
|
|
165
|
+
memories: ['ship-with-pnpm', 'prefer-pnpm'],
|
|
166
|
+
});
|
|
167
|
+
assert.equal(path, join(dir, 'sessions', 'session-1.md'));
|
|
168
|
+
const note = await store.readSessionNote('session-1');
|
|
169
|
+
assert.equal(note?.session, 'session-1');
|
|
170
|
+
assert.equal(note?.project, 'project:demo');
|
|
171
|
+
assert.equal(note?.summary, 'The user wrote: ship with pnpm run ship.');
|
|
172
|
+
assert.deepEqual(note?.memories, ['ship-with-pnpm', 'prefer-pnpm']);
|
|
173
|
+
assert.equal(note?.at, 1_700_000_000_000);
|
|
174
|
+
assert.deepEqual(await store.listSessionNotes(), ['session-1']);
|
|
175
|
+
assert.equal(await store.readSessionNote('never-mined'), undefined);
|
|
176
|
+
});
|
|
177
|
+
test('an entry with no recorded use round-trips its zero counters', () => {
|
|
178
|
+
const value = entry({ id: 'fresh', scope: 'global', title: 'Fresh', body: 'Never read yet.' });
|
|
179
|
+
const parsed = parseEntry(formatEntry(value), 'global', 'fallback');
|
|
180
|
+
assert.equal(parsed?.uses, 0);
|
|
181
|
+
assert.equal(parsed?.lastUsedAt, 0);
|
|
182
|
+
});
|
|
183
|
+
test('kind and appliesTo round-trip, and an entry without them defaults to a fact', () => {
|
|
184
|
+
const value = entry({
|
|
185
|
+
id: 'never-force-push',
|
|
186
|
+
scope: 'global',
|
|
187
|
+
kind: 'preference',
|
|
188
|
+
title: 'Never force-push',
|
|
189
|
+
body: 'Ask before any force-push.',
|
|
190
|
+
appliesTo: 'before running any git push',
|
|
191
|
+
});
|
|
192
|
+
assert.deepEqual(parseEntry(formatEntry(value), 'global', 'fallback'), value);
|
|
193
|
+
// A file written before kinds existed has no `kind:` line: it must parse as a
|
|
194
|
+
// fact rather than being rejected or losing the entry.
|
|
195
|
+
const legacy = [
|
|
196
|
+
'---',
|
|
197
|
+
'id: legacy',
|
|
198
|
+
'scope: global',
|
|
199
|
+
'title: Legacy entry',
|
|
200
|
+
'tags:',
|
|
201
|
+
'created: 2026-01-01T00:00:00.000Z',
|
|
202
|
+
'updated: 2026-01-01T00:00:00.000Z',
|
|
203
|
+
'source: tool',
|
|
204
|
+
'uses: 0',
|
|
205
|
+
'lastUsed: never',
|
|
206
|
+
'---',
|
|
207
|
+
'',
|
|
208
|
+
'Written before kinds existed.',
|
|
209
|
+
].join('\n');
|
|
210
|
+
const parsed = parseEntry(legacy, 'global', 'legacy');
|
|
211
|
+
assert.equal(parsed?.kind, 'fact');
|
|
212
|
+
assert.equal(parsed?.appliesTo, undefined);
|
|
213
|
+
assert.equal(parsed?.supersedes, undefined);
|
|
214
|
+
});
|
|
215
|
+
test('an unknown kind value degrades to a fact instead of failing the entry', () => {
|
|
216
|
+
const parsed = parseEntry(formatEntry(entry({ id: 'x', scope: 'global', title: 'X', body: 'y' })).replace('kind: fact', 'kind: nonsense'), 'global', 'x');
|
|
217
|
+
assert.equal(parsed?.kind, 'fact');
|
|
218
|
+
});
|
|
219
|
+
test('a rewrite that omits the kind keeps the stored one', async () => {
|
|
220
|
+
const { store, dir } = await tempStore();
|
|
221
|
+
try {
|
|
222
|
+
await store.upsert({ scope: 'global', kind: 'preference', title: 'Use pnpm', body: 'Use pnpm.', tags: [] }, undefined, 'tool', 1_000);
|
|
223
|
+
const updated = await store.upsert({ scope: 'global', title: 'Use pnpm', body: 'Use pnpm everywhere.', tags: [] }, undefined, 'auto', 2_000);
|
|
224
|
+
assert.equal(updated.entry.kind, 'preference');
|
|
225
|
+
}
|
|
226
|
+
finally {
|
|
227
|
+
await rm(dir, { recursive: true, force: true });
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
test('supersedes retires the entry it replaces', async () => {
|
|
231
|
+
const { store, dir } = await tempStore();
|
|
232
|
+
try {
|
|
233
|
+
await store.upsert({ scope: 'global', title: 'Use npm', body: 'Run npm install.', tags: [] }, undefined, 'tool', 1_000);
|
|
234
|
+
const replacement = await store.upsert({
|
|
235
|
+
scope: 'global',
|
|
236
|
+
title: 'Use pnpm',
|
|
237
|
+
body: 'Run pnpm install.',
|
|
238
|
+
tags: [],
|
|
239
|
+
supersedes: 'use-npm',
|
|
240
|
+
}, undefined, 'auto', 2_000);
|
|
241
|
+
assert.equal(replacement.entry.supersedes, 'use-npm');
|
|
242
|
+
const listed = await store.list('global', undefined, { fresh: true });
|
|
243
|
+
assert.deepEqual(listed.map((item) => item.id), ['use-pnpm'], 'the superseded entry is gone');
|
|
244
|
+
assert.equal(await store.read('global', undefined, 'use-npm'), undefined);
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
await rm(dir, { recursive: true, force: true });
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
test('supersedes never deletes the entry that carries it, and is scope-local', async () => {
|
|
251
|
+
const { store, dir } = await tempStore();
|
|
252
|
+
try {
|
|
253
|
+
// A self-reference must be a no-op rather than a self-delete.
|
|
254
|
+
const self = await store.upsert({ scope: 'global', title: 'Self', body: 'x', tags: [], supersedes: 'self' }, undefined, 'tool', 1_000);
|
|
255
|
+
assert.equal(self.entry.supersedes, 'self');
|
|
256
|
+
assert.ok(await store.read('global', undefined, 'self') !== undefined);
|
|
257
|
+
// A project entry cannot retire a global one that happens to share an id.
|
|
258
|
+
await store.upsert({ scope: 'global', title: 'Shared', body: 'global', tags: [] }, undefined, 'tool', 2_000);
|
|
259
|
+
await store.upsert({ scope: 'project', title: 'Other', body: 'project', tags: [], supersedes: 'shared' }, dir, 'tool', 3_000);
|
|
260
|
+
assert.ok(await store.read('global', undefined, 'shared') !== undefined, 'the global entry survives');
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
await rm(dir, { recursive: true, force: true });
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
test('parseEntry rejects a non-entry file instead of throwing', () => {
|
|
267
|
+
assert.equal(parseEntry('just prose', 'global', 'x'), undefined);
|
|
268
|
+
assert.equal(parseEntry('---\nscope: global\n---\n\nbody', 'global', 'x'), undefined);
|
|
269
|
+
});
|
|
270
|
+
test('upsert creates, then updates in place on the same title', async () => {
|
|
271
|
+
const { store, dir } = await tempStore();
|
|
272
|
+
try {
|
|
273
|
+
const first = await store.upsert({ scope: 'global', title: 'Build with pnpm', body: 'Use pnpm build.', tags: ['build'] }, undefined, 'tool', 1_000);
|
|
274
|
+
assert.equal(first.action, 'created');
|
|
275
|
+
const second = await store.upsert({ scope: 'global', title: 'Build with pnpm', body: 'Use pnpm run build.', tags: ['build', 'tooling'] }, undefined, 'auto', 2_000);
|
|
276
|
+
assert.equal(second.action, 'updated');
|
|
277
|
+
assert.equal(second.entry.createdAt, 1_000);
|
|
278
|
+
assert.equal(second.entry.updatedAt, 2_000);
|
|
279
|
+
const listed = await store.list('global', undefined, { fresh: true });
|
|
280
|
+
assert.equal(listed.length, 1);
|
|
281
|
+
assert.equal(listed[0]?.body, 'Use pnpm run build.');
|
|
282
|
+
assert.deepEqual([...listed[0].tags], ['build', 'tooling']);
|
|
283
|
+
}
|
|
284
|
+
finally {
|
|
285
|
+
await rm(dir, { recursive: true, force: true });
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
test('project and global scopes stay isolated and both survive a restart', async () => {
|
|
289
|
+
const { store, dir } = await tempStore();
|
|
290
|
+
try {
|
|
291
|
+
// The store resolves a project root to an absolute path, so the root here
|
|
292
|
+
// has to be the resolved one: on Windows the literal already is absolute,
|
|
293
|
+
// on POSIX it is resolved against the working directory.
|
|
294
|
+
const root = resolve('C:\\Code\\alpha');
|
|
295
|
+
await store.upsert({ scope: 'global', title: 'Global fact', body: 'Applies everywhere.', tags: [] }, undefined, 'tool', 1);
|
|
296
|
+
await store.upsert({ scope: 'project', title: 'Project fact', body: 'Only for alpha.', tags: [] }, root, 'tool', 2);
|
|
297
|
+
const reopened = new MemoryStore(dir);
|
|
298
|
+
assert.deepEqual((await reopened.list('global', undefined, { fresh: true })).map((entry) => entry.title), ['Global fact']);
|
|
299
|
+
assert.deepEqual((await reopened.list('project', root, { fresh: true })).map((entry) => entry.title), ['Project fact']);
|
|
300
|
+
assert.deepEqual(await reopened.list('project', resolve('C:\\Code\\beta'), { fresh: true }), []);
|
|
301
|
+
const descriptor = await reopened.readProjectDescriptor(projectSlug(root));
|
|
302
|
+
assert.equal(descriptor?.root, root);
|
|
303
|
+
}
|
|
304
|
+
finally {
|
|
305
|
+
await rm(dir, { recursive: true, force: true });
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
test('a corrupted entry file does not break the scope', async () => {
|
|
309
|
+
const { store, dir } = await tempStore();
|
|
310
|
+
try {
|
|
311
|
+
await store.upsert({ scope: 'global', title: 'Good', body: 'ok', tags: [] }, undefined, 'tool', 1);
|
|
312
|
+
await writeFile(join(dir, 'entries', 'broken.md'), 'not an entry\n', 'utf8');
|
|
313
|
+
const listed = await store.list('global', undefined, { fresh: true });
|
|
314
|
+
assert.deepEqual(listed.map((entry) => entry.title), ['Good']);
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
await rm(dir, { recursive: true, force: true });
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
test('the index file is rewritten and stays readable', async () => {
|
|
321
|
+
const { store, dir } = await tempStore();
|
|
322
|
+
try {
|
|
323
|
+
await store.upsert({ scope: 'global', title: 'Indexed', body: 'body', tags: ['x'] }, undefined, 'tool', 5);
|
|
324
|
+
const index = JSON.parse(await readFile(join(dir, 'index.json'), 'utf8'));
|
|
325
|
+
assert.equal(index.count, 1);
|
|
326
|
+
assert.equal(index.entries[0]?.title, 'Indexed');
|
|
327
|
+
}
|
|
328
|
+
finally {
|
|
329
|
+
await rm(dir, { recursive: true, force: true });
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
test('the same memory under a different title collapses instead of duplicating', async () => {
|
|
333
|
+
const { store, dir } = await tempStore();
|
|
334
|
+
try {
|
|
335
|
+
const first = await store.upsert({ scope: 'global', title: 'Prefer pnpm', body: 'Use pnpm, not npm.', tags: [] }, undefined, 'tool', 1_000);
|
|
336
|
+
// A re-worded title that contains the original one, same body: the older
|
|
337
|
+
// entry is retired on the next load.
|
|
338
|
+
const second = await store.upsert({ scope: 'global', title: 'Prefer pnpm in this repo', body: 'Use pnpm, not npm.', tags: [] }, undefined, 'auto', 2_000);
|
|
339
|
+
assert.notEqual(first.entry.id, second.entry.id);
|
|
340
|
+
const listed = await store.list('global', undefined, { fresh: true });
|
|
341
|
+
assert.equal(listed.length, 1);
|
|
342
|
+
assert.equal(listed[0]?.id, second.entry.id);
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
await rm(dir, { recursive: true, force: true });
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
test('genuinely distinct memories that share a body are both kept', async () => {
|
|
349
|
+
const { store, dir } = await tempStore();
|
|
350
|
+
try {
|
|
351
|
+
await store.upsert({ scope: 'global', title: 'Alpha rule', body: 'same words', tags: [] }, undefined, 'tool', 1_000);
|
|
352
|
+
await store.upsert({ scope: 'global', title: 'Beta rule', body: 'same words', tags: [] }, undefined, 'tool', 2_000);
|
|
353
|
+
const listed = await store.list('global', undefined, { fresh: true });
|
|
354
|
+
assert.deepEqual(listed.map((entry) => entry.title).sort(), ['Alpha rule', 'Beta rule']);
|
|
355
|
+
}
|
|
356
|
+
finally {
|
|
357
|
+
await rm(dir, { recursive: true, force: true });
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
test('remove deletes one entry and reports the truth', async () => {
|
|
361
|
+
const { store, dir } = await tempStore();
|
|
362
|
+
try {
|
|
363
|
+
await store.upsert({ scope: 'global', title: 'Temporary', body: 'x', tags: [] }, undefined, 'tool', 1);
|
|
364
|
+
assert.equal(await store.remove('global', undefined, 'temporary'), true);
|
|
365
|
+
assert.equal(await store.remove('global', undefined, 'temporary'), false);
|
|
366
|
+
assert.deepEqual(await store.list('global', undefined, { fresh: true }), []);
|
|
367
|
+
}
|
|
368
|
+
finally {
|
|
369
|
+
await rm(dir, { recursive: true, force: true });
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
test('the per-scope cap evicts the least recently updated entries', async () => {
|
|
373
|
+
const { store, dir } = await tempStore();
|
|
374
|
+
try {
|
|
375
|
+
store.entryLimit = () => 2;
|
|
376
|
+
for (let index = 0; index < 4; index += 1) {
|
|
377
|
+
await store.upsert({ scope: 'global', title: `Entry ${index}`, body: 'x', tags: [] }, undefined, 'tool', index + 1);
|
|
378
|
+
}
|
|
379
|
+
const listed = await store.list('global', undefined, { fresh: true });
|
|
380
|
+
assert.deepEqual(listed.map((entry) => entry.title), ['Entry 3', 'Entry 2']);
|
|
381
|
+
}
|
|
382
|
+
finally {
|
|
383
|
+
await rm(dir, { recursive: true, force: true });
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
test('a memory the turn is about outranks one that is merely well read', () => {
|
|
387
|
+
const now = 1_000_000_000_000;
|
|
388
|
+
// The incumbent has everything the weight rewards and nothing the turn names.
|
|
389
|
+
const incumbent = entry({
|
|
390
|
+
id: 'incumbent', scope: 'global', title: 'Sidebar adapter', body: 'unrelated to the question',
|
|
391
|
+
updatedAt: now, lastUsedAt: now, uses: 30,
|
|
392
|
+
});
|
|
393
|
+
// The turn names this one twice over, and it has never been read.
|
|
394
|
+
const named = entry({
|
|
395
|
+
id: 'named', scope: 'global', title: '注入摘要的排序公式', body: '注入摘要按相关性分层排序',
|
|
396
|
+
keys: ['排序', '注入'], updatedAt: now - 400 * 86_400_000, source: 'auto', uses: 0,
|
|
397
|
+
});
|
|
398
|
+
const query = '注入摘要的排序是怎么算的';
|
|
399
|
+
const blind = rankForSummary([incumbent, named], now);
|
|
400
|
+
assert.equal(blind[0]?.id, 'incumbent', 'without a topic signal the ranking is history, as before');
|
|
401
|
+
const topical = rankForSummary([incumbent, named], now, query);
|
|
402
|
+
assert.equal(topical[0]?.id, 'named', 'a named memory outranks thirty reads');
|
|
403
|
+
assert.equal(topical.indexOf(incumbent), 1, 'and history still orders everything below the tier');
|
|
404
|
+
});
|
|
405
|
+
test('inside the topical tier the better match comes first, not the better read', () => {
|
|
406
|
+
const now = 1_000_000_000_000;
|
|
407
|
+
// Both are about the turn, so the tier cannot separate them — and a saturating
|
|
408
|
+
// multiplier could not either, which is how a relevance-62 memory stayed
|
|
409
|
+
// unlisted while relevance-30 ones were shown.
|
|
410
|
+
const stronger = entry({
|
|
411
|
+
id: 'stronger', scope: 'global', title: '注入摘要是按相关性分层排序的', body: '相关性 注入 排序 分层',
|
|
412
|
+
keys: ['注入', '排序', '分层', '相关性'], updatedAt: now - 400 * 86_400_000, uses: 0,
|
|
413
|
+
});
|
|
414
|
+
const weaker = entry({
|
|
415
|
+
id: 'weaker', scope: 'global', title: '重启 dsh web 的 restart 端点', body: '注入 排序 之外的话题',
|
|
416
|
+
keys: ['注入', '排序'], updatedAt: now, lastUsedAt: now, uses: 30,
|
|
417
|
+
});
|
|
418
|
+
const ranked = rankForSummary([weaker, stronger], now, '注入摘要的排序是怎么算的');
|
|
419
|
+
const relevance = (id) => relevanceOfOne(ranked.find((value) => value.id === id), '注入摘要的排序是怎么算的');
|
|
420
|
+
assert.ok(relevance('stronger') > relevance('weaker'), 'the fixture really does separate the two');
|
|
421
|
+
assert.equal(ranked[0]?.id, 'stronger', 'and the stronger match is listed first despite never being read');
|
|
422
|
+
});
|
|
423
|
+
test('the topical tier is not reachable on one shared word', () => {
|
|
424
|
+
const now = 1_000_000_000_000;
|
|
425
|
+
// One strong term, and a score high enough to clear the recall escape hatch's
|
|
426
|
+
// 2× floor. A Latin word is used because a single CJK bigram cannot reach that
|
|
427
|
+
// score on its own — which is itself why the escape hatch is safe for recall.
|
|
428
|
+
const brush = entry({
|
|
429
|
+
id: 'brush', scope: 'global', title: 'Telemetry counters', body: 'telemetry counters are reset per session, telemetry again',
|
|
430
|
+
keys: ['telemetry'], updatedAt: now, lastUsedAt: now, uses: 20,
|
|
431
|
+
});
|
|
432
|
+
const query = 'telemetry 的计数口径是什么';
|
|
433
|
+
const recall = matchCredit(brush, query, 9, 2, { now });
|
|
434
|
+
assert.equal(recall.evidence.strongTerms, 1, 'the fixture really does rest on a single strong term');
|
|
435
|
+
assert.ok(recall.relevance >= 18, 'and on a decisive score, so the escape hatch applies');
|
|
436
|
+
assert.equal(recall.about, true, 'recall still credits a single decisive term — that is its job');
|
|
437
|
+
assert.equal(matchCredit(brush, query, 9, 2, { now, singleTerm: false }).about, false, 'the summary tier demands the full term count');
|
|
438
|
+
});
|
|
439
|
+
test('the byte budget admits by rank, so a relevant fact is not cut for an irrelevant preference', () => {
|
|
440
|
+
// The renderer receives entries in the order `selectForSummary` protected them,
|
|
441
|
+
// which is rank order — so these two `fact`s come first even though their kind
|
|
442
|
+
// renders last.
|
|
443
|
+
//
|
|
444
|
+
// Admitting kind by kind instead (preferences laid out first, budget dropped
|
|
445
|
+
// from the end of each group) made the byte budget a statement about `kind`
|
|
446
|
+
// rather than about relevance. At this budget the old code listed BOTH
|
|
447
|
+
// preferences and dropped BOTH facts, and on the real store it cut a memory at
|
|
448
|
+
// relevance 52 while keeping one at 20.
|
|
449
|
+
const scopes = [{
|
|
450
|
+
label: 'global',
|
|
451
|
+
heading: 'Global memories',
|
|
452
|
+
total: 4,
|
|
453
|
+
maxEntries: 4,
|
|
454
|
+
maxBytes: 340,
|
|
455
|
+
entries: [
|
|
456
|
+
entry({ id: 'f1', scope: 'global', kind: 'fact', title: '注入排序按相关性分层', body: '注入摘要是按相关性分层的,不按历史。' }),
|
|
457
|
+
entry({ id: 'f2', scope: 'global', kind: 'fact', title: '字节预算从尾部丢弃', body: '预算按字节预留,中文条目约三字节一字符。' }),
|
|
458
|
+
entry({ id: 'p1', scope: 'global', kind: 'preference', title: '偏好 p1', body: '与本轮无关的一条偏好。'.repeat(6) }),
|
|
459
|
+
entry({ id: 'p2', scope: 'global', kind: 'preference', title: '偏好 p2', body: '与本轮无关的一条偏好。'.repeat(6) }),
|
|
460
|
+
],
|
|
461
|
+
}];
|
|
462
|
+
const text = renderMemorySummary(scopes, { maxBytes: 4_096, maxEntriesPerScope: 12 });
|
|
463
|
+
assert.ok(text !== undefined);
|
|
464
|
+
assert.match(text, /注入排序按相关性分层/u, 'the top-ranked entry is listed');
|
|
465
|
+
assert.match(text, /字节预算从尾部丢弃/u, 'and so is the one behind it');
|
|
466
|
+
assert.doesNotMatch(text, /偏好 p1/u, 'the budget went to rank, not to the kind that renders first');
|
|
467
|
+
assert.doesNotMatch(text, /偏好 p2/u);
|
|
468
|
+
});
|
|
469
|
+
test('matchCredit reports the evidence behind a refusal as well as a credit', () => {
|
|
470
|
+
const now = 1_000_000_000_000;
|
|
471
|
+
const onTopic = entry({
|
|
472
|
+
id: 'on', scope: 'global', title: '前缀缓存只能追加', body: '不要改写已有消息',
|
|
473
|
+
keys: ['前缀缓存', '追加'], updatedAt: now,
|
|
474
|
+
});
|
|
475
|
+
const offTopic = entry({
|
|
476
|
+
id: 'off', scope: 'global', title: 'Sidebar adapter', body: 'nothing to do with caches',
|
|
477
|
+
updatedAt: now,
|
|
478
|
+
});
|
|
479
|
+
const query = '改注入预算会不会破坏前缀缓存';
|
|
480
|
+
const yes = matchCredit(onTopic, query, 9, 2, { now });
|
|
481
|
+
assert.equal(yes.about, true);
|
|
482
|
+
assert.ok(yes.evidence.strongTerms >= 2, 'and it can say why');
|
|
483
|
+
assert.ok(yes.best.length > 0, 'the sentence that matched is reported for the log');
|
|
484
|
+
assert.ok(yes.score >= yes.relevance, 'the decayed score is at least the raw relevance');
|
|
485
|
+
const no = matchCredit(offTopic, query, 9, 2, { now });
|
|
486
|
+
assert.equal(no.about, false);
|
|
487
|
+
assert.equal(no.credited, false);
|
|
488
|
+
assert.equal(no.relevance, 0, 'and an unrelated entry says so plainly');
|
|
489
|
+
});
|
|
490
|
+
test('the never-surfaced reservation is bounded by the slots the scope really renders', () => {
|
|
491
|
+
const now = 1_000_000_000_000;
|
|
492
|
+
const backlog = Array.from({ length: 8 }, (_, index) => entry({
|
|
493
|
+
id: `fresh-${index}`, scope: 'global', title: `Fresh ${index}`, body: 'never surfaced',
|
|
494
|
+
updatedAt: now - index, lastSurfacedAt: 0, source: 'auto',
|
|
495
|
+
}));
|
|
496
|
+
const established = Array.from({ length: 20 }, (_, index) => entry({
|
|
497
|
+
id: `old-${index}`, scope: 'global', title: `Old ${index}`, body: 'already listed',
|
|
498
|
+
updatedAt: now, lastUsedAt: now, lastSurfacedAt: now, uses: 6,
|
|
499
|
+
}));
|
|
500
|
+
const count = (list) => list.filter((value) => value.lastSurfacedAt <= 0).length;
|
|
501
|
+
// A 12-slot scope at the shipped default of 3 is unchanged.
|
|
502
|
+
assert.equal(count(selectForSummary([...established, ...backlog], 12, { freshSlots: 3, now })), 3);
|
|
503
|
+
// A 4-slot scope is where the untruncated reservation took over: it is the
|
|
504
|
+
// global half, and every session in every workspace pays for it.
|
|
505
|
+
assert.equal(count(selectForSummary([...established, ...backlog], 4, { freshSlots: 3, now })), 1);
|
|
506
|
+
// One slot has no room to give, and two take one.
|
|
507
|
+
assert.equal(count(selectForSummary([...established, ...backlog], 1, { freshSlots: 3, now })), 0);
|
|
508
|
+
assert.equal(count(selectForSummary([...established, ...backlog], 2, { freshSlots: 3, now })), 1);
|
|
509
|
+
});
|
|
510
|
+
test('a saturated scope of pins still shows what the turn is about', () => {
|
|
511
|
+
const now = 1_000_000_000_000;
|
|
512
|
+
// Five pins in a twelve-slot scope, plus a three-slot reservation: eight
|
|
513
|
+
// slots spoken for before the ranking is consulted. The renderer then cuts the
|
|
514
|
+
// section to about six by bytes, so whatever leads the protection order is
|
|
515
|
+
// what survives — and pins leading means the ranking contributes one bullet.
|
|
516
|
+
// Measured on the real store: the entry at relevance 116, top of 150 for that
|
|
517
|
+
// turn, never appeared at all.
|
|
518
|
+
const pins = Array.from({ length: 5 }, (_, index) => entry({
|
|
519
|
+
id: `pin-${index}`, scope: 'project', kind: 'fact', title: `部署事实 ${index}`,
|
|
520
|
+
body: '与本轮完全无关的一条部署事实。', pinned: true, updatedAt: now - index,
|
|
521
|
+
}));
|
|
522
|
+
const fresh = Array.from({ length: 3 }, (_, index) => entry({
|
|
523
|
+
id: `fresh-${index}`, scope: 'project', kind: 'fact', title: `新写入 ${index}`,
|
|
524
|
+
body: '刚写下、从未露面的新条目。', updatedAt: now - index, lastSurfacedAt: 0, source: 'auto',
|
|
525
|
+
}));
|
|
526
|
+
const about = entry({
|
|
527
|
+
id: 'about', scope: 'project', kind: 'knowledge', title: '异常与通知文案是写死的中文',
|
|
528
|
+
body: '异常中心 通知中心 的文案无法跟随语言切换。',
|
|
529
|
+
keys: ['异常中心', '通知中心', '文案', '语言切换'], updatedAt: now - 400 * 86_400_000, uses: 0,
|
|
530
|
+
});
|
|
531
|
+
const filler = Array.from({ length: 20 }, (_, index) => entry({
|
|
532
|
+
id: `old-${index}`, scope: 'project', kind: 'fact', title: `旧条目 ${index}`,
|
|
533
|
+
body: '历史条目。', updatedAt: now, lastUsedAt: now, lastSurfacedAt: now, uses: 6,
|
|
534
|
+
}));
|
|
535
|
+
const query = '评估异常中心、通知中心文案时';
|
|
536
|
+
const selected = selectForSummary([...pins, ...fresh, ...filler, about], 12, { freshSlots: 3, now, query });
|
|
537
|
+
assert.equal(selected[0]?.id, 'about', 'the topical floor leads, ahead of the pins');
|
|
538
|
+
// The promises still hold: no pin is evicted, and the reservation still runs.
|
|
539
|
+
assert.equal(selected.filter((value) => value.pinned === true).length, 5, 'every pin is still selected');
|
|
540
|
+
assert.ok(selected.some((value) => value.id === 'fresh-0'), 'and the fresh reservation still gets a slot');
|
|
541
|
+
// And the consequence that matters: the byte budget keeps the head of this
|
|
542
|
+
// array, so the memory the turn is about is actually rendered.
|
|
543
|
+
const text = renderMemorySummary([{
|
|
544
|
+
label: 'project', heading: 'Project memories', total: 25, entries: selected,
|
|
545
|
+
}], { maxBytes: 1_500, maxEntriesPerScope: 12 });
|
|
546
|
+
assert.ok(text !== undefined);
|
|
547
|
+
assert.match(text, /异常与通知文案是写死的中文/u, 'the best match survives a section full of pins');
|
|
548
|
+
});
|
|
549
|
+
test('the summary groups a scope by kind, actionable kinds first', () => {
|
|
550
|
+
const scopes = [{
|
|
551
|
+
label: 'global',
|
|
552
|
+
heading: 'Global memories',
|
|
553
|
+
total: 3,
|
|
554
|
+
entries: [
|
|
555
|
+
entry({ id: 'f', scope: 'global', kind: 'fact', title: 'A fact', body: 'background' }),
|
|
556
|
+
entry({ id: 'p', scope: 'global', kind: 'preference', title: 'A preference', body: 'follow this' }),
|
|
557
|
+
entry({ id: 'x', scope: 'global', kind: 'failure', title: 'A failure', body: 'avoid this' }),
|
|
558
|
+
],
|
|
559
|
+
}];
|
|
560
|
+
const text = renderMemorySummary(scopes, { maxBytes: 4_000, maxEntriesPerScope: 10 });
|
|
561
|
+
assert.ok(text !== undefined);
|
|
562
|
+
const preferenceAt = text.indexOf('### Preferences');
|
|
563
|
+
const failureAt = text.indexOf('### Failures to avoid');
|
|
564
|
+
const factAt = text.indexOf('### Facts');
|
|
565
|
+
assert.ok(preferenceAt > 0 && failureAt > 0 && factAt > 0, 'every populated kind gets a heading');
|
|
566
|
+
assert.ok(preferenceAt < failureAt && failureAt < factAt, 'actionable kinds render before plain facts');
|
|
567
|
+
});
|
|
568
|
+
test('search ranks a title hit above a body hit and honours filters', () => {
|
|
569
|
+
const groups = [{
|
|
570
|
+
scope: 'global',
|
|
571
|
+
label: 'global',
|
|
572
|
+
entries: [
|
|
573
|
+
entry({ id: 'a', scope: 'global', title: 'Use pnpm', body: 'package manager', tags: ['tooling'] }),
|
|
574
|
+
entry({ id: 'b', scope: 'global', title: 'Deployment notes', body: 'we use pnpm to deploy' }),
|
|
575
|
+
],
|
|
576
|
+
}];
|
|
577
|
+
const hits = searchMemories(groups, 'pnpm');
|
|
578
|
+
assert.equal(hits[0]?.entry.id, 'a');
|
|
579
|
+
assert.ok(scoreEntry(groups[0].entries[0], 'pnpm') > scoreEntry(groups[0].entries[1], 'pnpm'));
|
|
580
|
+
assert.equal(searchMemories(groups, 'pnpm', { tags: ['nope'] }).length, 0);
|
|
581
|
+
assert.equal(searchMemories(groups, '').length, 0);
|
|
582
|
+
assert.equal(browseMemories(groups).length, 2);
|
|
583
|
+
});
|
|
584
|
+
test('summary ranks a frequently used entry above a stale one', () => {
|
|
585
|
+
const now = 1_000_000_000_000;
|
|
586
|
+
const stale = entry({ id: 'stale', scope: 'global', title: 'Stale', body: 'old', updatedAt: now - 86_400_000 * 400 });
|
|
587
|
+
const used = entry({ id: 'used', scope: 'global', title: 'Used', body: 'hot', updatedAt: now - 86_400_000 * 400, uses: 6, lastUsedAt: now });
|
|
588
|
+
assert.deepEqual(rankForSummary([stale, used], now).map((value) => value.id), ['used', 'stale']);
|
|
589
|
+
});
|
|
590
|
+
test('being listed in the summary does not renew an entry against a newer one', () => {
|
|
591
|
+
const now = 1_000_000_000_000;
|
|
592
|
+
const DAY_MS = 86_400_000;
|
|
593
|
+
// The incumbent was read twice and is being listed right now, but nobody has
|
|
594
|
+
// touched it in 200 days. Counting the listing as attention would pin its
|
|
595
|
+
// recency at "now" and keep it ahead of everything written afterwards.
|
|
596
|
+
const listed = entry({
|
|
597
|
+
id: 'listed', scope: 'global', title: 'Listed', body: 'long-standing',
|
|
598
|
+
updatedAt: now - 200 * DAY_MS, lastUsedAt: now - 200 * DAY_MS, lastSurfacedAt: now, uses: 2,
|
|
599
|
+
});
|
|
600
|
+
const fresh = entry({ id: 'fresh', scope: 'global', title: 'Fresh', body: 'written just now', updatedAt: now });
|
|
601
|
+
assert.deepEqual(rankForSummary([listed, fresh], now).map((value) => value.id), ['fresh', 'listed']);
|
|
602
|
+
});
|
|
603
|
+
test('a saturated scope still lists a never-surfaced entry that ranking would drop', () => {
|
|
604
|
+
const now = 1_000_000_000_000;
|
|
605
|
+
const incumbents = Array.from({ length: 20 }, (_, index) => entry({
|
|
606
|
+
id: `old-${index}`, scope: 'global', title: `Old ${index}`, body: 'been here a while',
|
|
607
|
+
updatedAt: now - 86_400_000, lastUsedAt: now, lastSurfacedAt: now, uses: 6,
|
|
608
|
+
}));
|
|
609
|
+
const correction = entry({
|
|
610
|
+
id: 'correction', scope: 'global', title: 'The correction', body: 'this replaces one of them',
|
|
611
|
+
updatedAt: now, source: 'tool',
|
|
612
|
+
});
|
|
613
|
+
const entries = [...incumbents, correction];
|
|
614
|
+
const ranked = rankForSummary(entries, now);
|
|
615
|
+
assert.ok(!ranked.slice(0, 12).some((value) => value.id === 'correction'), 'the ranking alone keeps the correction out, which is the failure being fixed');
|
|
616
|
+
assert.ok(ranked.findIndex((value) => value.id === 'correction') >= 12, 'and it sits below the cut');
|
|
617
|
+
const selected = selectForSummary(entries, 12, { freshSlots: 2, now });
|
|
618
|
+
assert.equal(selected.length, 12);
|
|
619
|
+
assert.equal(selected[0]?.id, 'correction', 'a reserved entry comes first so byte pressure cannot drop it');
|
|
620
|
+
assert.ok(selected.some((value) => value.id === 'correction'), 'the reserved slot lets it in exactly once');
|
|
621
|
+
// Zero slots restores pure ranking, so the knob is what does the work.
|
|
622
|
+
assert.ok(!selectForSummary(entries, 12, { freshSlots: 0, now }).some((value) => value.id === 'correction'));
|
|
623
|
+
});
|
|
624
|
+
test('reserved slots prefer an explicit write and never take the whole list', () => {
|
|
625
|
+
const now = 1_000_000_000_000;
|
|
626
|
+
const unseen = Array.from({ length: 15 }, (_, index) => entry({
|
|
627
|
+
id: `auto-${index}`, scope: 'global', title: `Extracted ${index}`, body: 'guessed',
|
|
628
|
+
updatedAt: now - index * 1_000, source: 'auto',
|
|
629
|
+
}));
|
|
630
|
+
const explicit = entry({
|
|
631
|
+
id: 'explicit', scope: 'global', title: 'A person said so', body: 'authoritative',
|
|
632
|
+
updatedAt: now - 86_400_000, source: 'user',
|
|
633
|
+
});
|
|
634
|
+
const incumbents = Array.from({ length: 20 }, (_, index) => entry({
|
|
635
|
+
id: `old-${index}`, scope: 'global', title: `Old ${index}`, body: 'been here a while',
|
|
636
|
+
updatedAt: now, lastUsedAt: now, lastSurfacedAt: now, uses: 6,
|
|
637
|
+
}));
|
|
638
|
+
const selected = selectForSummary([...incumbents, ...unseen, explicit], 12, { freshSlots: 2, now });
|
|
639
|
+
assert.equal(selected.length, 12);
|
|
640
|
+
assert.ok(selected.some((value) => value.id === 'explicit'), 'the explicit write wins the reservation');
|
|
641
|
+
assert.ok(selected.some((value) => value.id === 'auto-0'), 'the second slot goes to the newest extracted entry');
|
|
642
|
+
assert.ok(selected.filter((value) => value.uses === 0).length < 12, 'the reservation does not take the whole list');
|
|
643
|
+
});
|
|
644
|
+
test('a reserved slot prefers a never-surfaced entry this conversation names', () => {
|
|
645
|
+
const now = 1_000_000_000_000;
|
|
646
|
+
const incumbents = Array.from({ length: 20 }, (_, index) => entry({
|
|
647
|
+
id: `old-${index}`, scope: 'global', title: `Old ${index}`, body: 'generic history',
|
|
648
|
+
updatedAt: now, lastUsedAt: now, lastSurfacedAt: now, uses: 6,
|
|
649
|
+
}));
|
|
650
|
+
// The newest unseen entry shares nothing with the turn; an older one is about it.
|
|
651
|
+
const newest = entry({
|
|
652
|
+
id: 'newest', scope: 'global', title: 'Unrelated fresh note', body: 'nothing to do with it',
|
|
653
|
+
updatedAt: now, source: 'auto',
|
|
654
|
+
});
|
|
655
|
+
const relevant = entry({
|
|
656
|
+
id: 'relevant', scope: 'global', title: '发票 OCR 手写字段补摘', body: '按版面语义抽字段,不要用首个正则命中',
|
|
657
|
+
updatedAt: now - 86_400_000, source: 'auto',
|
|
658
|
+
});
|
|
659
|
+
// Without the topical step the reserved slot went to the newest entry, which is
|
|
660
|
+
// how every measured scope spent one of four global slots on something the
|
|
661
|
+
// session could not use.
|
|
662
|
+
const blind = selectForSummary([...incumbents, newest, relevant], 5, { freshSlots: 1, now });
|
|
663
|
+
assert.ok(blind.some((value) => value.id === 'newest'), 'newest wins when there is no topic signal');
|
|
664
|
+
const topical = selectForSummary([...incumbents, newest, relevant], 5, { freshSlots: 1, now, query: '发票手写字段怎么补摘' });
|
|
665
|
+
assert.ok(topical.some((value) => value.id === 'relevant'), 'the named entry takes the reserved slot');
|
|
666
|
+
});
|
|
667
|
+
test('every entry is listed when a scope fits, and nothing is listed at zero', () => {
|
|
668
|
+
const now = 1_000_000_000_000;
|
|
669
|
+
const entries = [
|
|
670
|
+
entry({ id: 'a', scope: 'global', title: 'A', body: 'x', updatedAt: now }),
|
|
671
|
+
entry({ id: 'b', scope: 'global', title: 'B', body: 'y', updatedAt: now - 1 }),
|
|
672
|
+
];
|
|
673
|
+
assert.deepEqual(selectForSummary(entries, 5, { freshSlots: 2, now }).map((value) => value.id), ['a', 'b']);
|
|
674
|
+
assert.deepEqual(selectForSummary(entries, 0, { freshSlots: 2, now }), []);
|
|
675
|
+
});
|
|
676
|
+
test('a pinned memory is listed even when the ranking would leave it out', () => {
|
|
677
|
+
const now = 1_000_000_000_000;
|
|
678
|
+
const incumbents = Array.from({ length: 20 }, (_, index) => entry({
|
|
679
|
+
id: `old-${index}`, scope: 'global', title: `Old ${index}`, body: 'well read history',
|
|
680
|
+
updatedAt: now, lastUsedAt: now, lastSurfacedAt: now, uses: 6,
|
|
681
|
+
}));
|
|
682
|
+
const rule = entry({
|
|
683
|
+
id: 'the-rule', scope: 'global', title: 'Never break the prompt cache', body: 'only append',
|
|
684
|
+
updatedAt: now - 400 * 86_400_000, pinned: true, uses: 0,
|
|
685
|
+
});
|
|
686
|
+
const ranked = rankForSummary([...incumbents, rule], now);
|
|
687
|
+
assert.ok(ranked.findIndex((value) => value.id === 'the-rule') >= 5, 'the ranking alone keeps it out');
|
|
688
|
+
const selected = selectForSummary([...incumbents, rule], 5, { freshSlots: 0, now });
|
|
689
|
+
assert.equal(selected[0]?.id, 'the-rule', 'a pin is chosen before the ranking and before the fresh slots');
|
|
690
|
+
});
|
|
691
|
+
test('pins compete only with each other, so they cannot take the whole list', () => {
|
|
692
|
+
const now = 1_000_000_000_000;
|
|
693
|
+
const pinned = Array.from({ length: 9 }, (_, index) => entry({
|
|
694
|
+
id: `pin-${index}`, scope: 'global', title: `Pin ${index}`, body: 'pinned', updatedAt: now - index * 1_000, pinned: true,
|
|
695
|
+
}));
|
|
696
|
+
const selected = selectForSummary(pinned, 4, { freshSlots: 1, now });
|
|
697
|
+
assert.equal(selected.length, 4, 'the cap still bounds the section');
|
|
698
|
+
assert.ok(selected.every((value) => value.pinned === true));
|
|
699
|
+
});
|
|
700
|
+
test('a pinned entry survives the kind grouping, which would otherwise drop it', () => {
|
|
701
|
+
const now = 1_000_000_000_000;
|
|
702
|
+
const overview = entry({
|
|
703
|
+
id: 'overview', scope: 'project', kind: 'fact', title: '项目概览:本仓库',
|
|
704
|
+
body: '这是一个很长的概览正文,用来把预算吃掉一部分。'.repeat(6), pinned: true, updatedAt: now,
|
|
705
|
+
});
|
|
706
|
+
const others = Array.from({ length: 12 }, (_, index) => entry({
|
|
707
|
+
id: `pref-${index}`, scope: 'project', kind: 'preference', title: `约定 ${index}`,
|
|
708
|
+
body: '一条偏好。'.repeat(20), updatedAt: now - index,
|
|
709
|
+
}));
|
|
710
|
+
const text = renderMemorySummary([{
|
|
711
|
+
label: 'project',
|
|
712
|
+
heading: 'Project memories',
|
|
713
|
+
entries: selectForSummary([...others, overview], 12, { freshSlots: 0, now }),
|
|
714
|
+
total: others.length + 1,
|
|
715
|
+
}], { maxBytes: 1_400, maxEntriesPerScope: 12 });
|
|
716
|
+
assert.ok(text !== undefined);
|
|
717
|
+
// Facts render last and the budget drops from the end: before the fix the
|
|
718
|
+
// pinned overview was exactly the bullet that disappeared.
|
|
719
|
+
assert.match(text, /📌 项目概览:本仓库/u, 'a pinned bullet is rendered first and cannot be cut');
|
|
720
|
+
});
|
|
721
|
+
test('a summary note is carried inside the byte budget', () => {
|
|
722
|
+
const scopes = [{
|
|
723
|
+
label: 'global',
|
|
724
|
+
heading: 'Global memories',
|
|
725
|
+
total: 2,
|
|
726
|
+
entries: [
|
|
727
|
+
entry({ id: 'a', scope: 'global', title: 'A', body: 'x' }),
|
|
728
|
+
entry({ id: 'b', scope: 'global', title: 'B', body: 'y' }),
|
|
729
|
+
],
|
|
730
|
+
}];
|
|
731
|
+
const note = 'Pending skill drafts (2): promote-me, discard-me — promote with /memories promote <name>.';
|
|
732
|
+
const text = renderMemorySummary(scopes, { maxBytes: 4_000, maxEntriesPerScope: 10, note });
|
|
733
|
+
assert.ok(text !== undefined);
|
|
734
|
+
assert.match(text, /Pending skill drafts \(2\)/u);
|
|
735
|
+
assert.ok(Buffer.byteLength(text, 'utf8') <= 4_000);
|
|
736
|
+
// Even a budget that suits only the frame keeps the note inside it.
|
|
737
|
+
const tight = renderMemorySummary(scopes, { maxBytes: 700, maxEntriesPerScope: 10, note });
|
|
738
|
+
assert.ok(tight !== undefined);
|
|
739
|
+
assert.ok(Buffer.byteLength(tight, 'utf8') <= 700);
|
|
740
|
+
});
|
|
741
|
+
test('isWithin treats a directory as inside itself and ignores case on Windows', () => {
|
|
742
|
+
const parent = process.platform === 'win32' ? 'C:\\Code\\Alpha' : '/code/alpha';
|
|
743
|
+
const child = join(parent, 'sub', 'deep');
|
|
744
|
+
assert.equal(isWithin(parent, parent), true);
|
|
745
|
+
assert.equal(isWithin(parent, child), true);
|
|
746
|
+
assert.equal(isWithin(child, parent), false);
|
|
747
|
+
const sibling = process.platform === 'win32' ? 'C:\\Code\\Alphabet' : '/code/alphabet';
|
|
748
|
+
assert.equal(isWithin(parent, sibling), false, 'a shared prefix is not containment');
|
|
749
|
+
if (process.platform === 'win32')
|
|
750
|
+
assert.equal(isWithin(parent, 'c:\\code\\alpha\\sub'), true);
|
|
751
|
+
});
|
|
752
|
+
test('summary renders both scopes and stays inside its byte budget', () => {
|
|
753
|
+
const scopes = [
|
|
754
|
+
{
|
|
755
|
+
label: 'global',
|
|
756
|
+
heading: 'Global memories',
|
|
757
|
+
total: 2,
|
|
758
|
+
entries: [
|
|
759
|
+
entry({ id: 'g1', scope: 'global', title: 'Prefer pnpm', body: 'x'.repeat(400) }),
|
|
760
|
+
entry({ id: 'g2', scope: 'global', title: 'Answer in Chinese', body: 'y'.repeat(400) }),
|
|
761
|
+
],
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
label: 'project:alpha',
|
|
765
|
+
heading: 'Project memories (project:alpha)',
|
|
766
|
+
total: 1,
|
|
767
|
+
entries: [
|
|
768
|
+
entry({ id: 'p1', scope: 'project', title: 'Windows only', body: 'z'.repeat(400) }),
|
|
769
|
+
],
|
|
770
|
+
},
|
|
771
|
+
];
|
|
772
|
+
const text = renderMemorySummary(scopes, { maxBytes: 900, maxEntriesPerScope: 12 });
|
|
773
|
+
assert.ok(text !== undefined);
|
|
774
|
+
assert.ok(Buffer.byteLength(text, 'utf8') <= 900);
|
|
775
|
+
assert.match(text, /<memory-context>/u);
|
|
776
|
+
assert.match(text, /Global memories/u);
|
|
777
|
+
assert.match(text, /Project memories/u);
|
|
778
|
+
assert.equal(renderMemorySummary([], { maxBytes: 100, maxEntriesPerScope: 5 }), undefined);
|
|
779
|
+
});
|
|
780
|
+
test('open loops render in deadline order, and closed ones stay out', () => {
|
|
781
|
+
const now = Date.parse('2026-11-05T00:00:00Z');
|
|
782
|
+
const text = renderOpenLoops([
|
|
783
|
+
{ id: 'open-a', text: '把登录页的截图补齐', openedAt: 1, state: 'open' },
|
|
784
|
+
{ id: 'open-b', text: '周五前把报价发出去', openedAt: 2, dueAt: now - 86_400_000, state: 'open' },
|
|
785
|
+
{ id: 'done-c', text: '已经做完的事', openedAt: 3, state: 'done' },
|
|
786
|
+
], { now });
|
|
787
|
+
assert.ok(text !== undefined);
|
|
788
|
+
assert.match(text, /overdue · 周五前把报价发出去/u);
|
|
789
|
+
assert.match(text, /no date · 把登录页的截图补齐/u);
|
|
790
|
+
// A closed loop is history, not something the model should be told about.
|
|
791
|
+
assert.doesNotMatch(text, /已经做完的事/u);
|
|
792
|
+
// Overdue comes first: it is the one that needs acting on.
|
|
793
|
+
assert.ok(text.indexOf('周五前把报价发出去') < text.indexOf('把登录页的截图补齐'));
|
|
794
|
+
assert.equal(renderOpenLoops([{ id: 'expired-d', text: 't', openedAt: 1, state: 'expired' }], { now }), undefined);
|
|
795
|
+
});
|
|
796
|
+
test('entry config resolves paths, clamps tunables, and reads live references', () => {
|
|
797
|
+
// A Windows home on Windows and a POSIX home elsewhere: the plugin resolves
|
|
798
|
+
// the home against the platform, so the expectation has to as well.
|
|
799
|
+
const home = process.platform === 'win32' ? 'C:\\home' : '/home';
|
|
800
|
+
const resolved = resolveConfig({ dshHome: home, maxSummaryBytes: -5, autoExtractIdleMs: 10, extractProvider: 'p', extractModel: 'm' });
|
|
801
|
+
assert.equal(resolved.memoriesDir, `${home}/memories`);
|
|
802
|
+
assert.equal(resolved.tunables.maxSummaryBytes, 0);
|
|
803
|
+
assert.equal(resolved.tunables.autoExtractIdleMs, 1000);
|
|
804
|
+
assert.equal(resolved.tunables.extractProvider, 'p');
|
|
805
|
+
// A lone provider is not a route: both halves are required.
|
|
806
|
+
assert.equal(resolveConfig({ extractProvider: 'p' }).tunables.extractModel, '');
|
|
807
|
+
// A mounted row hands the tunables over as live references, not values; the
|
|
808
|
+
// same resolution has to see straight through them.
|
|
809
|
+
const mounted = resolveConfig({ maxSummaryBytes: createVolatile(8192), autoExtract: createVolatile(false) });
|
|
810
|
+
assert.equal(mounted.tunables.maxSummaryBytes, 8192);
|
|
811
|
+
assert.equal(mounted.tunables.autoExtract, false);
|
|
812
|
+
// And re-reading follows the reference, which is what makes a settings write
|
|
813
|
+
// take effect without a restart.
|
|
814
|
+
const reference = createVolatile(8192);
|
|
815
|
+
const live = { maxSummaryBytes: reference };
|
|
816
|
+
assert.equal(readTunables(live).maxSummaryBytes, 8192);
|
|
817
|
+
updateVolatile(reference, createVolatile(1024));
|
|
818
|
+
assert.equal(readTunables(live).maxSummaryBytes, 1024);
|
|
819
|
+
});
|
|
820
|
+
test('normalizeSettings fills every field and clamps nonsense', () => {
|
|
821
|
+
const settings = normalizeSettings({ autoExtract: false, maxSummaryEntries: -3 });
|
|
822
|
+
assert.equal(settings.autoExtract, false);
|
|
823
|
+
assert.equal(settings.maxSummaryEntries, 1);
|
|
824
|
+
assert.equal(settings.enableTool, true);
|
|
825
|
+
assert.equal(settings.maxSummaryBytes, DEFAULT_MAX_SUMMARY_BYTES);
|
|
826
|
+
});
|
|
827
|
+
test('findProjectRoot walks up to the marker and falls back to cwd', async () => {
|
|
828
|
+
const root = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-root-'));
|
|
829
|
+
try {
|
|
830
|
+
await writeFile(join(root, '.git'), 'gitdir: elsewhere\n', 'utf8');
|
|
831
|
+
const nested = join(root, 'packages', 'app', 'src');
|
|
832
|
+
await mkdir(nested, { recursive: true });
|
|
833
|
+
assert.equal(await findProjectRoot(nested, ['.git']), root);
|
|
834
|
+
const orphan = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-orphan-'));
|
|
835
|
+
try {
|
|
836
|
+
assert.equal(await findProjectRoot(orphan, ['.git']), orphan);
|
|
837
|
+
}
|
|
838
|
+
finally {
|
|
839
|
+
await rm(orphan, { recursive: true, force: true });
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
finally {
|
|
843
|
+
await rm(root, { recursive: true, force: true });
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
test('injected context carries a producer-owned source kind', () => {
|
|
847
|
+
// Durable session format v4 refuses the retired `{ kind: 'plugin', plugin }`
|
|
848
|
+
// wrapper on write, so every message this plugin injects has to name its
|
|
849
|
+
// producer. The platform's own v3→v4 migration derives `plugin:<name>` from
|
|
850
|
+
// that wrapper, which is why the two spellings must agree: a session resumed
|
|
851
|
+
// from an older log has to recognise the block it already carries, or the
|
|
852
|
+
// summary is injected a second time.
|
|
853
|
+
assert.equal(MEMORY_SOURCE_KIND, `plugin:${name}`);
|
|
854
|
+
assert.notEqual(MEMORY_SOURCE_KIND, 'plugin');
|
|
855
|
+
});
|