dsh-cross-memory 0.2.0 → 0.2.2
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 +9 -3
- package/lib/client.js +1424 -1316
- package/lib/config.js +3 -3
- package/lib/index.js +18 -5
- package/lib/persona.js +52 -1
- package/lib/remote.js +35 -0
- package/lib/test/client-wiring.test.js +8 -7
- package/lib/test/consolidate-job.test.js +13 -0
- package/lib/test/disputes-panel.test.js +29 -2
- package/lib/test/notices.test.js +4 -2
- package/lib/test/persona.test.js +14 -1
- package/lib/test/remote.test.js +11 -0
- package/lib/test/settings-card.test.js +1 -1
- package/lib/test/sync.test.js +1 -1
- package/lib/types/persona.d.ts +33 -0
- package/lib/types/remote.d.ts +13 -0
- package/package.json +17 -17
package/lib/config.js
CHANGED
|
@@ -454,7 +454,7 @@ export const Config = z.object({
|
|
|
454
454
|
/** Whether a model decides if a judgement-based notice is worth an interruption. */
|
|
455
455
|
noticeGate: z.boolean().default(true).description('Before raising a notice that has no rule behind it (an undated promise that has been sitting for days), ask a model whether it is worth interrupting for. The default answer is silence: a gate that cannot run, or that fails, suppresses the notice. Rule-based notices (daily digest, backlog warning, a promise whose deadline passed) are never gated.').volatile(),
|
|
456
456
|
/** Byte budget for the persona block injected ahead of the memory summary. */
|
|
457
|
-
personaMaxBytes: z.number().default(
|
|
457
|
+
personaMaxBytes: z.number().default(12000).description('Byte budget for the persona block (who the user is, in their own words) injected once per conversation ahead of the memory summary. 0 disables the block. The profile is edited in Settings → Memories → Persona; locking it there stops the consolidation pass from rewriting it. Kept separate from the summary budget because the profile is context for the whole turn, not one of the memories being listed.').volatile(),
|
|
458
458
|
/** Share of a scope above which a query term stops counting as recall evidence. */
|
|
459
459
|
evidenceMaxDf: z.number().default(DEFAULT_EVIDENCE_MAX_DF).description('A query term that appears in more than this share of one scope does not count towards the recall gate\'s evidence requirement. 0.15 is measured on a real 200-entry store: it catches exactly one term (dsh, 22% of entries) and cuts false admissions by three quarters without changing any of ten labelled probes. 0 disables the discount and restores the pre-2026-10-23 behaviour.').volatile(),
|
|
460
460
|
/** Local-time windows whose tokens are the expensive ones. */
|
|
@@ -515,7 +515,7 @@ export const MEMORIES_SETTINGS_DEFAULTS = {
|
|
|
515
515
|
consolidateTimeoutMs: DEFAULT_CONSOLIDATE_TIMEOUT_MS,
|
|
516
516
|
autoDecide: true,
|
|
517
517
|
autoDecideMinConfidence: 0.7,
|
|
518
|
-
personaMaxBytes:
|
|
518
|
+
personaMaxBytes: 12000,
|
|
519
519
|
noticeGate: true,
|
|
520
520
|
reflectionEnabled: true,
|
|
521
521
|
noticesEnabled: true,
|
|
@@ -621,7 +621,7 @@ export function normalizeSettings(input) {
|
|
|
621
621
|
consolidateTimeoutMs: positive(value.consolidateTimeoutMs, DEFAULT_CONSOLIDATE_TIMEOUT_MS),
|
|
622
622
|
autoDecide: value.autoDecide ?? true,
|
|
623
623
|
autoDecideMinConfidence: clampUnit(value.autoDecideMinConfidence, 0.7),
|
|
624
|
-
personaMaxBytes: positive(value.personaMaxBytes,
|
|
624
|
+
personaMaxBytes: positive(value.personaMaxBytes, 12000, 0),
|
|
625
625
|
noticeGate: value.noticeGate ?? true,
|
|
626
626
|
reflectionEnabled: value.reflectionEnabled ?? true,
|
|
627
627
|
noticesEnabled: value.noticesEnabled ?? true,
|
package/lib/index.js
CHANGED
|
@@ -29,7 +29,7 @@ import { MemoryStore, slugify } from './storage.js';
|
|
|
29
29
|
import { StateStore, importLegacyState, statePath } from './state.js';
|
|
30
30
|
import { browseMemories, EXPAND_SEEDS, hubTerms, matchCredit, prefilterEntries, QUALIFIED_SCORE_FACTOR, relatedHits, searchMemories } from './search.js';
|
|
31
31
|
import { readFile } from 'node:fs/promises';
|
|
32
|
-
import { readPersona, renderPersonaBlock, writePersona } from './persona.js';
|
|
32
|
+
import { isPersonaLocked, readPersona, renderPersonaBlock, writePersona } from './persona.js';
|
|
33
33
|
import { StoreSyncService } from './sync-runtime.js';
|
|
34
34
|
import { ackNotice, admitNotice, dueNotices, pruneNotices, readNotices, withNotice, writeNotices } from './notices.js';
|
|
35
35
|
import { systemNotification } from './notify.js';
|
|
@@ -2672,12 +2672,18 @@ export class MemoriesRuntime {
|
|
|
2672
2672
|
enqueueConsolidation(now = Date.now(), readyNow = false, root) {
|
|
2673
2673
|
if (!this.settings.consolidate)
|
|
2674
2674
|
return;
|
|
2675
|
-
const notBefore = readyNow ? now : now + this.settings.consolidateCooldownHours * 3_600_000;
|
|
2676
2675
|
const existing = this.state.getJob(CONSOLIDATE_JOB);
|
|
2677
2676
|
if (existing !== undefined) {
|
|
2677
|
+
// A fresh extraction must NOT push the due time back. Doing so meant an
|
|
2678
|
+
// active store — one that keeps producing memories more often than the
|
|
2679
|
+
// cooldown — never became due at all, so the profile and the merge pass
|
|
2680
|
+
// silently starved. Keep the earliest due time; only a manual enqueue
|
|
2681
|
+
// (`/memories consolidate`) resets it to "now".
|
|
2682
|
+
const notBefore = readyNow ? now : existing.notBefore;
|
|
2678
2683
|
this.state.putJob({ ...existing, enqueuedAt: now, notBefore, ...root === undefined ? {} : { root } });
|
|
2679
2684
|
return;
|
|
2680
2685
|
}
|
|
2686
|
+
const notBefore = readyNow ? now : now + this.settings.consolidateCooldownHours * 3_600_000;
|
|
2681
2687
|
this.state.putJob({ key: CONSOLIDATE_JOB, enqueuedAt: now, notBefore, retries: 0, ...root === undefined ? {} : { root } });
|
|
2682
2688
|
}
|
|
2683
2689
|
/**
|
|
@@ -2799,9 +2805,16 @@ export class MemoriesRuntime {
|
|
|
2799
2805
|
// The profile is a document, not a memory: it is injected as its own block
|
|
2800
2806
|
// at a known budget, so it is written beside the store rather than into it.
|
|
2801
2807
|
if (plan.persona !== undefined && plan.persona.trim().length > 0) {
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2808
|
+
// A locked profile is the user's document: the pass may still propose a
|
|
2809
|
+
// rewrite, but it must not land one behind their back.
|
|
2810
|
+
if (await isPersonaLocked(this.store.memoriesDir).catch(() => false)) {
|
|
2811
|
+
this.log.info('dsh-cross-memory: persona is locked; the automatic profile update was skipped');
|
|
2812
|
+
}
|
|
2813
|
+
else {
|
|
2814
|
+
await writePersona(this.store.memoriesDir, plan.persona).catch((error) => {
|
|
2815
|
+
this.log.warn('dsh-cross-memory: could not write the persona profile: %s', error instanceof Error ? error.message : String(error));
|
|
2816
|
+
});
|
|
2817
|
+
}
|
|
2805
2818
|
}
|
|
2806
2819
|
// Skill drafts are staged, not installed: a background pass must not
|
|
2807
2820
|
// silently grow the model's skill catalog.
|
package/lib/persona.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* @module dsh-cross-memory/persona
|
|
19
19
|
*/
|
|
20
|
-
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
20
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
21
21
|
import { dirname, join } from 'node:path';
|
|
22
22
|
/** Directory holding the profile, inside the memory store. */
|
|
23
23
|
export const PERSONA_DIR = 'persona';
|
|
@@ -29,6 +29,12 @@ export const PERSONA_MAX_SOURCE_CHARS = 6000;
|
|
|
29
29
|
export function personaPath(memoriesDir) {
|
|
30
30
|
return join(memoriesDir, PERSONA_DIR, 'human.md');
|
|
31
31
|
}
|
|
32
|
+
/** Marker file that stops the consolidation pass rewriting the profile. */
|
|
33
|
+
export const PERSONA_LOCK_FILE = 'human.lock';
|
|
34
|
+
/** Path of the manual-edit lock marker. */
|
|
35
|
+
export function personaLockPath(memoriesDir) {
|
|
36
|
+
return join(memoriesDir, PERSONA_DIR, PERSONA_LOCK_FILE);
|
|
37
|
+
}
|
|
32
38
|
/**
|
|
33
39
|
* Read the profile.
|
|
34
40
|
*
|
|
@@ -110,3 +116,48 @@ export function renderPersonaBlock(body, maxBytes, now = Date.now()) {
|
|
|
110
116
|
function byteLength(text) {
|
|
111
117
|
return Buffer.byteLength(text, 'utf8');
|
|
112
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Whether the user locked the profile against automatic rewrites.
|
|
121
|
+
*
|
|
122
|
+
* The lock is an opt-in marker beside the profile: a missing or empty file
|
|
123
|
+
* means unlocked, so upgrading a store never silently changes the behaviour.
|
|
124
|
+
*
|
|
125
|
+
* @param memoriesDir - the memory store root.
|
|
126
|
+
* @returns whether the consolidation pass must leave the profile alone.
|
|
127
|
+
*/
|
|
128
|
+
export async function isPersonaLocked(memoriesDir) {
|
|
129
|
+
const marker = await readFile(personaLockPath(memoriesDir), 'utf8').catch(() => undefined);
|
|
130
|
+
return marker !== undefined && marker.trim().length > 0;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Set or clear the manual-edit lock.
|
|
134
|
+
*
|
|
135
|
+
* The marker carries a timestamp rather than the word "true": it is read as a
|
|
136
|
+
* boolean by {@link isPersonaLocked}, and the timestamp is what a person sees
|
|
137
|
+
* when they open the file to ask when it was locked. The write is atomic for the
|
|
138
|
+
* same reason the profile is.
|
|
139
|
+
*
|
|
140
|
+
* @param memoriesDir - the memory store root.
|
|
141
|
+
* @param locked - whether automatic rewrites are forbidden.
|
|
142
|
+
*/
|
|
143
|
+
export async function setPersonaLocked(memoriesDir, locked) {
|
|
144
|
+
const target = personaLockPath(memoriesDir);
|
|
145
|
+
if (!locked) {
|
|
146
|
+
await rm(target, { force: true });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
await mkdir(dirname(target), { recursive: true });
|
|
150
|
+
const temp = `${target}.${process.pid}.${Date.now().toString(36)}.tmp`;
|
|
151
|
+
await writeFile(temp, `${new Date().toISOString()}\n`, 'utf8');
|
|
152
|
+
await rename(temp, target);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Remove the profile, including the legacy single file, so the next read finds
|
|
156
|
+
* nothing to inject. Used when the editor saves an empty document.
|
|
157
|
+
*
|
|
158
|
+
* @param memoriesDir - the memory store root.
|
|
159
|
+
*/
|
|
160
|
+
export async function clearPersona(memoriesDir) {
|
|
161
|
+
await rm(personaPath(memoriesDir), { force: true });
|
|
162
|
+
await rm(join(memoriesDir, LEGACY_PERSONA_FILE), { force: true });
|
|
163
|
+
}
|
package/lib/remote.js
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
import { existsSync } from 'node:fs';
|
|
30
30
|
import { join } from 'node:path';
|
|
31
31
|
import { browseMemories, searchMemories } from './search.js';
|
|
32
|
+
import { clearPersona, isPersonaLocked, readPersona, setPersonaLocked, writePersona } from './persona.js';
|
|
32
33
|
import { discardDraft, listDrafts, promote } from './skills.js';
|
|
33
34
|
import { MEMORY_KINDS, toMemoryKind } from './types.js';
|
|
34
35
|
/** npm package owning the Remote methods. */
|
|
@@ -92,6 +93,19 @@ export const REMOTE_INVOCATION_DATA = [
|
|
|
92
93
|
parameters: [{ name: 'name', wire: 'name', shape: 'text' }],
|
|
93
94
|
result: 'discard',
|
|
94
95
|
},
|
|
96
|
+
{
|
|
97
|
+
method: 'persona',
|
|
98
|
+
parameters: [],
|
|
99
|
+
result: 'persona',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
method: 'savePersona',
|
|
103
|
+
parameters: [
|
|
104
|
+
{ name: 'text', wire: 'text', shape: 'text' },
|
|
105
|
+
{ name: 'locked', wire: 'locked', shape: 'flag' },
|
|
106
|
+
],
|
|
107
|
+
result: 'persona',
|
|
108
|
+
},
|
|
95
109
|
{
|
|
96
110
|
method: 'disputes',
|
|
97
111
|
parameters: [],
|
|
@@ -220,10 +234,16 @@ function hostCodec(shape) {
|
|
|
220
234
|
const view = asRecord(value, 'skill');
|
|
221
235
|
return { name: asText(view.name, 'skill.name'), path: asText(view.path, 'skill.path') };
|
|
222
236
|
}
|
|
237
|
+
case 'flag':
|
|
238
|
+
return asFlag(value, 'argument');
|
|
223
239
|
case 'discard': {
|
|
224
240
|
const view = asRecord(value, 'discard');
|
|
225
241
|
return { name: asText(view.name, 'discard.name'), removed: asFlag(view.removed, 'discard.removed') };
|
|
226
242
|
}
|
|
243
|
+
case 'persona': {
|
|
244
|
+
const view = asRecord(value, 'persona');
|
|
245
|
+
return { text: asText(view.text, 'persona.text'), locked: asFlag(view.locked, 'persona.locked') };
|
|
246
|
+
}
|
|
227
247
|
case 'disputes': {
|
|
228
248
|
const view = asRecord(value, 'disputes');
|
|
229
249
|
return {
|
|
@@ -417,6 +437,21 @@ export function createRemoteService(host) {
|
|
|
417
437
|
const wanted = (name ?? '').trim();
|
|
418
438
|
return { name: wanted, removed: await discardDraft(store.memoriesDir, wanted) };
|
|
419
439
|
},
|
|
440
|
+
async persona() {
|
|
441
|
+
return {
|
|
442
|
+
text: (await readPersona(store.memoriesDir)) ?? '',
|
|
443
|
+
locked: await isPersonaLocked(store.memoriesDir),
|
|
444
|
+
};
|
|
445
|
+
},
|
|
446
|
+
async savePersona(text, locked) {
|
|
447
|
+
const body = (text ?? '').trim();
|
|
448
|
+
if (body.length > 0)
|
|
449
|
+
await writePersona(store.memoriesDir, body);
|
|
450
|
+
else
|
|
451
|
+
await clearPersona(store.memoriesDir);
|
|
452
|
+
await setPersonaLocked(store.memoriesDir, locked === true);
|
|
453
|
+
return { text: body, locked: locked === true };
|
|
454
|
+
},
|
|
420
455
|
async disputes() {
|
|
421
456
|
if (host.disputes === undefined)
|
|
422
457
|
return { disputes: [] };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wiring guard for the browser half's two surfaces.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The compiled browser half (`.client-build/index.js`) is a plain CJS
|
|
5
|
+
* script that the bundle wrapper turns into a DSH client bundle, so there is
|
|
6
|
+
* no module to import: the parts are
|
|
7
|
+
* concatenated here exactly the way `scripts/build-client.mts` concatenates
|
|
7
8
|
* them, and the factory is called for real. What this pins is the registration
|
|
8
9
|
* contract, because nothing else in the suite covers it:
|
|
9
10
|
*
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
* wrong key silently means "no card in the GUI";
|
|
17
18
|
* - both registrations hand the same shared form (`scope` + `useSnapshot`) to
|
|
18
19
|
* their component, so the two editors cannot disagree;
|
|
19
|
-
* - `PACKAGE` is the package name, and `scripts/build-client.
|
|
20
|
+
* - `PACKAGE` is the package name, and `scripts/build-client.mts` uses that
|
|
20
21
|
* same value as the bundle id.
|
|
21
22
|
*
|
|
22
23
|
* @module dsh-cross-memory/test/client-wiring.test
|
|
@@ -25,9 +26,9 @@ import assert from 'node:assert/strict';
|
|
|
25
26
|
import { readFile, readdir } from 'node:fs/promises';
|
|
26
27
|
import test from 'node:test';
|
|
27
28
|
import { REMOTE_INVOCATION_DATA } from '../remote.js';
|
|
28
|
-
/** Where the
|
|
29
|
-
const PARTS = new URL('
|
|
30
|
-
const INDEX = new URL('
|
|
29
|
+
/** Where the compiled browser half lives (emitted from `client/*.ts`). */
|
|
30
|
+
const PARTS = new URL('../../.client-build/parts/', import.meta.url);
|
|
31
|
+
const INDEX = new URL('../../.client-build/index.js', import.meta.url);
|
|
31
32
|
const MANIFEST = new URL('../../package.json', import.meta.url);
|
|
32
33
|
/**
|
|
33
34
|
* Concatenate the browser half the way the bundle script does.
|
|
@@ -60,6 +60,19 @@ test('a later enqueue updates the root so the newest workspace wins', async (t)
|
|
|
60
60
|
runtime.enqueueConsolidation(2_000, false, 'C:\\work\\beta');
|
|
61
61
|
assert.equal(runtime.state.getJob('global')?.root, 'C:\\work\\beta');
|
|
62
62
|
});
|
|
63
|
+
test('a later extraction does not push the due time back', async (t) => {
|
|
64
|
+
const { runtime } = await fixture(t);
|
|
65
|
+
runtime.enqueueConsolidation(1_000, false, 'C:\\work\\alpha');
|
|
66
|
+
const first = runtime.state.getJob('global');
|
|
67
|
+
assert.ok(first !== undefined);
|
|
68
|
+
// An active store keeps producing memories; the second enqueue must not
|
|
69
|
+
// re-arm the cooldown forever (the starvation the profile hit).
|
|
70
|
+
runtime.enqueueConsolidation(1_000 + 3_600_000, false, 'C:\\work\\beta');
|
|
71
|
+
const later = runtime.state.getJob('global');
|
|
72
|
+
assert.equal(later?.notBefore, first.notBefore, 'the due time stays the first one');
|
|
73
|
+
assert.equal(later?.enqueuedAt, first.enqueuedAt + 3_600_000, 'the activity time moves');
|
|
74
|
+
assert.equal(later?.root, 'C:\\work\\beta', 'the newest workspace still wins');
|
|
75
|
+
});
|
|
63
76
|
test('an enqueue without a root keeps the recorded one', async (t) => {
|
|
64
77
|
const { runtime } = await fixture(t);
|
|
65
78
|
runtime.enqueueConsolidation(1_000, false, 'C:\\work\\alpha');
|
|
@@ -30,8 +30,8 @@ const DISPUTES = [{
|
|
|
30
30
|
after: 'what the pass wants instead',
|
|
31
31
|
}];
|
|
32
32
|
/** The browser half, resolved from the compiled test's own location. */
|
|
33
|
-
const SECTION = new URL('
|
|
34
|
-
const REMOTE = new URL('
|
|
33
|
+
const SECTION = new URL('../../.client-build/parts/section.js', import.meta.url);
|
|
34
|
+
const REMOTE = new URL('../../.client-build/parts/remote.js', import.meta.url);
|
|
35
35
|
/** Load the section factory the bundle concatenates. */
|
|
36
36
|
async function loadSection() {
|
|
37
37
|
const source = await readFile(SECTION, 'utf8');
|
|
@@ -167,6 +167,11 @@ function fakeApi(calls, rows = DISPUTES) {
|
|
|
167
167
|
calls.push(args);
|
|
168
168
|
return Promise.resolve('Applied.');
|
|
169
169
|
},
|
|
170
|
+
persona: () => Promise.resolve({ text: '他先确认再改代码。', locked: false }),
|
|
171
|
+
savePersona: (args) => {
|
|
172
|
+
calls.push(args);
|
|
173
|
+
return Promise.resolve({ text: args.text, locked: args.locked });
|
|
174
|
+
},
|
|
170
175
|
};
|
|
171
176
|
}
|
|
172
177
|
test('the disputes panel accepts and rejects through the Remote API', async () => {
|
|
@@ -312,3 +317,25 @@ test('a retirement strikes the body and renders no replacement', async () => {
|
|
|
312
317
|
assert.equal(findClass(panel, 'dshm-ins'), undefined, 'nothing replaces a retirement');
|
|
313
318
|
assert.equal(findClass(panel, 'dshm-del'), undefined);
|
|
314
319
|
});
|
|
320
|
+
test('the persona tab loads the profile and saves text plus the lock flag', async () => {
|
|
321
|
+
const calls = [];
|
|
322
|
+
const module = await loadSection();
|
|
323
|
+
const { render } = await mountSection(fakeApi(calls), module.SECTION_COPY.zh);
|
|
324
|
+
const memories = await render();
|
|
325
|
+
click(findByText(memories, 'button', '画像'));
|
|
326
|
+
const panel = await render();
|
|
327
|
+
const area = [...walk(panel)].find((element) => element.type === 'textarea');
|
|
328
|
+
assert.equal(area?.props.value, '他先确认再改代码。', 'the stored profile is in the editor');
|
|
329
|
+
(area?.props.onChange)({ target: { value: '新的画像' } });
|
|
330
|
+
const edited = await render();
|
|
331
|
+
const lock = [...walk(edited)].find((element) => element.type === 'input' && element.props.type === 'checkbox');
|
|
332
|
+
assert.equal(lock?.props.checked, false, 'the lock starts from the stored flag');
|
|
333
|
+
(lock?.props.onChange)({ target: { checked: true } });
|
|
334
|
+
const locked = await render();
|
|
335
|
+
assert.equal([...walk(locked)].find((element) => element.type === 'input' && element.props.type === 'checkbox')?.props.checked, true);
|
|
336
|
+
click(findByText(locked, 'button', '保存画像'));
|
|
337
|
+
await new Promise((resolve) => { setTimeout(resolve, 20); });
|
|
338
|
+
assert.deepEqual(calls.at(-1), { text: '新的画像', locked: true }, 'one object with both wire fields');
|
|
339
|
+
const after = await render();
|
|
340
|
+
assert.match(textOf(after), /画像已保存。/u, 'the save is reported');
|
|
341
|
+
});
|
package/lib/test/notices.test.js
CHANGED
|
@@ -62,11 +62,13 @@ test('the daily cap is a guard rail against a runaway trigger', () => {
|
|
|
62
62
|
assert.match(verdict.ok === false ? verdict.reason : '', /guard rail/u);
|
|
63
63
|
});
|
|
64
64
|
test('quiet hours defer a notice instead of dropping it', () => {
|
|
65
|
-
|
|
65
|
+
// Local-time constructors: quiet hours use the host clock, so an absolute UTC
|
|
66
|
+
// timestamp would only test the machine's timezone (and fail on UTC CI).
|
|
67
|
+
const at22 = new Date(2026, 9, 23, 22, 0, 0).getTime();
|
|
66
68
|
const due = quietHoursEnd(at22, '22:00-08:00');
|
|
67
69
|
assert.ok(due > at22, 'held until the window ends');
|
|
68
70
|
assert.equal(quietHoursEnd(at22, ''), at22, 'no window means no delay');
|
|
69
|
-
const daytime = Date
|
|
71
|
+
const daytime = new Date(2026, 9, 23, 10, 0, 0).getTime();
|
|
70
72
|
assert.equal(quietHoursEnd(daytime, '22:00-08:00'), daytime, 'outside the window it fires now');
|
|
71
73
|
});
|
|
72
74
|
test('the queue round-trips, delivers once, and expires', async (t) => {
|
package/lib/test/persona.test.js
CHANGED
|
@@ -14,7 +14,7 @@ import { mkdtemp, readFile, 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 { personaPath, readPersona, renderPersonaBlock, writePersona } from '../persona.js';
|
|
17
|
+
import { clearPersona, isPersonaLocked, personaLockPath, personaPath, readPersona, renderPersonaBlock, setPersonaLocked, writePersona } from '../persona.js';
|
|
18
18
|
import { MemoryStore } from '../storage.js';
|
|
19
19
|
import { parsePlan } from '../consolidate.js';
|
|
20
20
|
test('a profile round-trips through the store directory', async (t) => {
|
|
@@ -71,3 +71,16 @@ test('a legacy single-file profile is still read as the human block', async (t)
|
|
|
71
71
|
await writeFile(join(dir, 'persona.md'), '旧的单文件画像\n', 'utf8');
|
|
72
72
|
assert.equal(await readPersona(dir), '旧的单文件画像', 'upgrading does not lose the profile');
|
|
73
73
|
});
|
|
74
|
+
test('the manual-edit lock is a timestamped marker, and clearing removes the profile', async (t) => {
|
|
75
|
+
const dir = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-lock-'));
|
|
76
|
+
t.after(() => rm(dir, { recursive: true, force: true }));
|
|
77
|
+
assert.equal(await isPersonaLocked(dir), false, 'an untouched store is unlocked');
|
|
78
|
+
await writePersona(dir, '他先确认再改代码。');
|
|
79
|
+
await setPersonaLocked(dir, true);
|
|
80
|
+
assert.equal(await isPersonaLocked(dir), true, 'the marker locks the profile');
|
|
81
|
+
assert.match(await readFile(personaLockPath(dir), 'utf8'), /\d{4}-\d{2}-\d{2}T/u, 'the marker records when it was locked');
|
|
82
|
+
await clearPersona(dir);
|
|
83
|
+
assert.equal(await readPersona(dir), undefined, 'clearing removes the profile the injector reads');
|
|
84
|
+
await setPersonaLocked(dir, false);
|
|
85
|
+
assert.equal(await isPersonaLocked(dir), false, 'unlocking removes the marker');
|
|
86
|
+
});
|
package/lib/test/remote.test.js
CHANGED
|
@@ -86,6 +86,7 @@ test('the wire table and the expanded descriptors agree', () => {
|
|
|
86
86
|
// Every shape the browser renders is covered by a codec factory call.
|
|
87
87
|
assert.ok(seen.has('overview') && seen.has('entries') && seen.has('entry') && seen.has('removed'));
|
|
88
88
|
assert.ok(seen.has('skill') && seen.has('discard') && seen.has('text') && seen.has('number'));
|
|
89
|
+
assert.ok(seen.has('persona') && seen.has('flag'));
|
|
89
90
|
});
|
|
90
91
|
test('the host codecs validate instead of passing values through', () => {
|
|
91
92
|
const byMethod = new Map(REMOTE_CONTRIBUTION.invocations.map((descriptor) => [descriptor.method, descriptor]));
|
|
@@ -102,6 +103,16 @@ test('the host codecs validate instead of passing values through', () => {
|
|
|
102
103
|
assert.equal(numberCodec?.create().parse(10), 10);
|
|
103
104
|
assert.throws(() => numberCodec?.create().parse('10'), /must be a number/u);
|
|
104
105
|
});
|
|
106
|
+
test('the settings page can read, save and lock the persona profile', async (t) => {
|
|
107
|
+
const { store, dshHome } = await roots(t);
|
|
108
|
+
const service = createRemoteService({ store, dshHome });
|
|
109
|
+
assert.deepEqual(await service.persona(), { text: '', locked: false }, 'an empty store has no profile');
|
|
110
|
+
const saved = await service.savePersona('他先确认再改代码。', true);
|
|
111
|
+
assert.deepEqual(saved, { text: '他先确认再改代码。', locked: true });
|
|
112
|
+
assert.deepEqual(await service.persona(), saved, 'the saved document and its lock are read back');
|
|
113
|
+
await service.savePersona('', false);
|
|
114
|
+
assert.deepEqual(await service.persona(), { text: '', locked: false }, 'saving an empty document clears it');
|
|
115
|
+
});
|
|
105
116
|
test('the settings page can list and resolve the decisions waiting for a person', async (t) => {
|
|
106
117
|
const { store, dshHome } = await roots(t);
|
|
107
118
|
const seen = [];
|
|
@@ -15,7 +15,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
15
15
|
import test from 'node:test';
|
|
16
16
|
import { MEMORIES_SETTINGS_DEFAULTS, Config } from '../config.js';
|
|
17
17
|
/** The browser half, resolved from the compiled test's own location. */
|
|
18
|
-
const CARD = new URL('
|
|
18
|
+
const CARD = new URL('../../.client-build/parts/card.js', import.meta.url);
|
|
19
19
|
test('the settings card covers exactly the schema, with bilingual copy', async () => {
|
|
20
20
|
const text = await readFile(CARD, 'utf8');
|
|
21
21
|
const fields = [...text.matchAll(/field: '([A-Za-z][A-Za-z0-9]*)'/gu)].map((match) => match[1]);
|
package/lib/test/sync.test.js
CHANGED
|
@@ -53,7 +53,7 @@ function entryText(id, body, updated) {
|
|
|
53
53
|
async function twoWayFixture() {
|
|
54
54
|
const base = await mkdtemp(join(tmpdir(), 'dsh-cross-memory-sync-'));
|
|
55
55
|
const remote = join(base, 'remote.git');
|
|
56
|
-
execFileSync('git', ['init', '--bare', '--quiet', remote]);
|
|
56
|
+
execFileSync('git', ['init', '--bare', '--quiet', '-b', 'main', remote]);
|
|
57
57
|
const left = join(base, 'left');
|
|
58
58
|
const right = join(base, 'right');
|
|
59
59
|
await mkdir(join(left, 'entries'), { recursive: true });
|
package/lib/types/persona.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export declare const LEGACY_PERSONA_FILE = "persona.md";
|
|
|
6
6
|
export declare const PERSONA_MAX_SOURCE_CHARS = 6000;
|
|
7
7
|
/** Path of the profile. */
|
|
8
8
|
export declare function personaPath(memoriesDir: string): string;
|
|
9
|
+
/** Marker file that stops the consolidation pass rewriting the profile. */
|
|
10
|
+
export declare const PERSONA_LOCK_FILE = "human.lock";
|
|
11
|
+
/** Path of the manual-edit lock marker. */
|
|
12
|
+
export declare function personaLockPath(memoriesDir: string): string;
|
|
9
13
|
/**
|
|
10
14
|
* Read the profile.
|
|
11
15
|
*
|
|
@@ -41,3 +45,32 @@ export declare function writePersona(memoriesDir: string, body: string): Promise
|
|
|
41
45
|
* @returns the framed block, or `undefined` when there is nothing to show.
|
|
42
46
|
*/
|
|
43
47
|
export declare function renderPersonaBlock(body: string | undefined, maxBytes: number, now?: number): string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the user locked the profile against automatic rewrites.
|
|
50
|
+
*
|
|
51
|
+
* The lock is an opt-in marker beside the profile: a missing or empty file
|
|
52
|
+
* means unlocked, so upgrading a store never silently changes the behaviour.
|
|
53
|
+
*
|
|
54
|
+
* @param memoriesDir - the memory store root.
|
|
55
|
+
* @returns whether the consolidation pass must leave the profile alone.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isPersonaLocked(memoriesDir: string): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Set or clear the manual-edit lock.
|
|
60
|
+
*
|
|
61
|
+
* The marker carries a timestamp rather than the word "true": it is read as a
|
|
62
|
+
* boolean by {@link isPersonaLocked}, and the timestamp is what a person sees
|
|
63
|
+
* when they open the file to ask when it was locked. The write is atomic for the
|
|
64
|
+
* same reason the profile is.
|
|
65
|
+
*
|
|
66
|
+
* @param memoriesDir - the memory store root.
|
|
67
|
+
* @param locked - whether automatic rewrites are forbidden.
|
|
68
|
+
*/
|
|
69
|
+
export declare function setPersonaLocked(memoriesDir: string, locked: boolean): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Remove the profile, including the legacy single file, so the next read finds
|
|
72
|
+
* nothing to inject. Used when the editor saves an empty document.
|
|
73
|
+
*
|
|
74
|
+
* @param memoriesDir - the memory store root.
|
|
75
|
+
*/
|
|
76
|
+
export declare function clearPersona(memoriesDir: string): Promise<void>;
|
package/lib/types/remote.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export type WireShape =
|
|
|
11
11
|
'text'
|
|
12
12
|
/** A numeric parameter. */
|
|
13
13
|
| 'number'
|
|
14
|
+
/** A boolean flag parameter. */
|
|
15
|
+
| 'flag'
|
|
16
|
+
/** The persona profile plus whether it is locked against automatic rewrites. */
|
|
17
|
+
| 'persona'
|
|
14
18
|
/** Store home, per-project counts, staged skill drafts. */
|
|
15
19
|
| 'overview'
|
|
16
20
|
/** A ranked entry page plus the total before paging. */
|
|
@@ -199,11 +203,20 @@ export interface MemoriesRemote {
|
|
|
199
203
|
readonly name: string;
|
|
200
204
|
readonly removed: boolean;
|
|
201
205
|
}>;
|
|
206
|
+
persona(): Promise<PersonaView>;
|
|
207
|
+
savePersona(text?: string, locked?: boolean): Promise<PersonaView>;
|
|
202
208
|
disputes(): Promise<{
|
|
203
209
|
readonly disputes: readonly DisputeView[];
|
|
204
210
|
}>;
|
|
205
211
|
resolveDispute(id?: string, decision?: string): Promise<string>;
|
|
206
212
|
}
|
|
213
|
+
/** The persona profile as the settings page edits it. */
|
|
214
|
+
export interface PersonaView {
|
|
215
|
+
/** Stored markdown, empty when no profile exists yet. */
|
|
216
|
+
readonly text: string;
|
|
217
|
+
/** Whether automatic consolidation must leave the profile alone. */
|
|
218
|
+
readonly locked: boolean;
|
|
219
|
+
}
|
|
207
220
|
/** One consolidation decision, as the settings page renders it. */
|
|
208
221
|
export interface DisputeView {
|
|
209
222
|
readonly id: string;
|
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.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -73,24 +73,24 @@
|
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
|
-
"build": "tsc -p tsconfig.json && node scripts/build-client.
|
|
76
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && node scripts/build-client.mts",
|
|
77
77
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
78
|
-
"test": "tsc -p tsconfig.json && node scripts/build-client.
|
|
79
|
-
"smoke": "node scripts/activation-smoke.
|
|
80
|
-
"seed": "node scripts/seed.
|
|
81
|
-
"eval": "node scripts/eval-extract.
|
|
82
|
-
"eval:retrieval": "node scripts/eval-retrieval.
|
|
83
|
-
"eval:backfill": "node scripts/eval-backfill.
|
|
84
|
-
"eval:rotation": "node scripts/eval-rotation.
|
|
85
|
-
"eval:coverage-projection": "node scripts/eval-coverage-projection.
|
|
86
|
-
"eval:acceptance": "node scripts/eval-acceptance.
|
|
87
|
-
"eval:recall-log": "node scripts/eval-recall-log.
|
|
88
|
-
"report": "node scripts/report.
|
|
78
|
+
"test": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && node scripts/build-client.mts && node --test lib/test/*.test.js",
|
|
79
|
+
"smoke": "node scripts/activation-smoke.mts .",
|
|
80
|
+
"seed": "node scripts/seed.mts",
|
|
81
|
+
"eval": "node scripts/eval-extract.mts",
|
|
82
|
+
"eval:retrieval": "node scripts/eval-retrieval.mts",
|
|
83
|
+
"eval:backfill": "node scripts/eval-backfill.mts",
|
|
84
|
+
"eval:rotation": "node scripts/eval-rotation.mts",
|
|
85
|
+
"eval:coverage-projection": "node scripts/eval-coverage-projection.mts",
|
|
86
|
+
"eval:acceptance": "node scripts/eval-acceptance.mts",
|
|
87
|
+
"eval:recall-log": "node scripts/eval-recall-log.mts",
|
|
88
|
+
"report": "node scripts/report.mts",
|
|
89
89
|
"prepare": "npm run build",
|
|
90
|
-
"eval:e2e": "node bench/e2e/run.
|
|
91
|
-
"eval:real": "node bench/real/run.
|
|
92
|
-
"eval:real:sample": "node bench/real/sample.
|
|
93
|
-
"eval:real:author": "node bench/real/author.
|
|
90
|
+
"eval:e2e": "node bench/e2e/run.mts",
|
|
91
|
+
"eval:real": "node bench/real/run.mts",
|
|
92
|
+
"eval:real:sample": "node bench/real/sample.mts",
|
|
93
|
+
"eval:real:author": "node bench/real/author.mts"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|
|
96
96
|
"@deepseek-ai/cordis": "^4.0.5 || ^4.0.6-alpha.1",
|