dsh-cross-memory 0.2.3 → 0.2.4
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 +92 -94
- package/docs/DETAIL.md +75 -10
- package/docs/DETAIL.zh.md +74 -13
- package/lib/backfill.js +1 -0
- package/lib/client.js +6 -1
- package/lib/config.js +50 -18
- package/lib/extract.js +133 -25
- package/lib/index.js +194 -43
- package/lib/loops.js +9 -4
- package/lib/render.js +2 -2
- package/lib/search.js +141 -18
- package/lib/storage.js +8 -0
- package/lib/sync.js +96 -1
- package/lib/test/extract.test.js +59 -2
- package/lib/test/recall.test.js +59 -26
- package/lib/test/retrieval.test.js +46 -1
- package/lib/test/rotation.test.js +5 -2
- package/lib/test/sync.test.js +46 -1
- package/lib/tool.js +9 -1
- package/lib/types/backfill.d.ts +10 -0
- package/lib/types/config.d.ts +49 -15
- package/lib/types/extract.d.ts +95 -3
- package/lib/types/index.d.ts +52 -4
- package/lib/types/search.d.ts +68 -0
- package/lib/types/sync.d.ts +12 -0
- package/lib/types/types.d.ts +8 -0
- package/package.json +1 -1
package/lib/types/index.d.ts
CHANGED
|
@@ -96,6 +96,10 @@ export declare class MemoriesRuntime {
|
|
|
96
96
|
private consolidateSkip;
|
|
97
97
|
/** Hub-term predicates by store signature; see `hubFor`. */
|
|
98
98
|
private readonly hubCache;
|
|
99
|
+
/** Last project-slug conflict scan, with the time it ran. */
|
|
100
|
+
private conflictScan;
|
|
101
|
+
/** Whether the conflict scan has already logged its findings once. */
|
|
102
|
+
private conflictLogged;
|
|
99
103
|
/** Sessions whose conversation already carries the memory block. */
|
|
100
104
|
private readonly injected;
|
|
101
105
|
/** Recall deltas already injected into each conversation. */
|
|
@@ -217,6 +221,25 @@ export declare class MemoriesRuntime {
|
|
|
217
221
|
kinds?: readonly MemoryKind[];
|
|
218
222
|
limit?: number;
|
|
219
223
|
}): Promise<import("./types.js").MemoryHit[]>;
|
|
224
|
+
/**
|
|
225
|
+
* The vocabulary this store files memories under, for a query that found
|
|
226
|
+
* nothing.
|
|
227
|
+
*
|
|
228
|
+
* Search is lexical, so a query phrased in the user's words cannot reach a
|
|
229
|
+
* memory filed under the product's words. Returning the aliases and tags that
|
|
230
|
+
* share characters with the query is what lets the caller try again with the
|
|
231
|
+
* store's own terms instead of concluding the fact was never recorded.
|
|
232
|
+
*
|
|
233
|
+
* @param session - conversation asking.
|
|
234
|
+
* @param query - the query that returned nothing.
|
|
235
|
+
* @param limit - most terms to return.
|
|
236
|
+
* @returns shared terms first, then the most widely used ones.
|
|
237
|
+
*/
|
|
238
|
+
aliasHints(session: Session, query: string, limit?: number): Promise<{
|
|
239
|
+
term: string;
|
|
240
|
+
carriers: number;
|
|
241
|
+
matched: number;
|
|
242
|
+
}[]>;
|
|
220
243
|
/** Read one entry by scope and id, recording the hit. */
|
|
221
244
|
read(session: Session, scope: MemoryScope, id: string, record?: boolean): Promise<MemoryEntry | undefined>;
|
|
222
245
|
/**
|
|
@@ -265,10 +288,16 @@ export declare class MemoriesRuntime {
|
|
|
265
288
|
* cap. Extraction is otherwise blind to what is already known, which is how one
|
|
266
289
|
* session's lesson ended up stored twice — once in Chinese, once in English.
|
|
267
290
|
*
|
|
291
|
+
* The whole scope is returned, uncapped; the caller ranks it against the
|
|
292
|
+
* window with {@link selectKnownTitles} and only then cuts. Cutting here was
|
|
293
|
+
* the bug: on a store larger than the cap, every title past the cut was
|
|
294
|
+
* invisible to the extractor, which then re-derived those facts under new
|
|
295
|
+
* titles.
|
|
296
|
+
*
|
|
268
297
|
* @param root - the session's project root, when it has one.
|
|
269
|
-
* @returns
|
|
298
|
+
* @returns every candidate title with its write time.
|
|
270
299
|
*/
|
|
271
|
-
private
|
|
300
|
+
private knownTitleCandidates;
|
|
272
301
|
/** Delete one entry. */
|
|
273
302
|
forget(session: Session, scope: MemoryScope, id: string): Promise<boolean>;
|
|
274
303
|
/**
|
|
@@ -330,6 +359,23 @@ export declare class MemoriesRuntime {
|
|
|
330
359
|
* @returns a human-readable summary, or `undefined` when nothing is staged.
|
|
331
360
|
*/
|
|
332
361
|
applyPendingPlan(_parent: Agent): Promise<string | undefined>;
|
|
362
|
+
/**
|
|
363
|
+
* A warning when this workspace's memory directory is shared with another
|
|
364
|
+
* repository of the same name.
|
|
365
|
+
*
|
|
366
|
+
* `projectSlug` keys a project by its basename, which is what lets one
|
|
367
|
+
* repository checked out at two paths on two machines share one memory
|
|
368
|
+
* directory. The accepted cost is that two unrelated repositories called
|
|
369
|
+
* `backend` also share one — and the failure is silent and confusing: each
|
|
370
|
+
* project's memories are injected into the other's sessions, with nothing
|
|
371
|
+
* saying why. The store already records every host's git origin; two
|
|
372
|
+
* different origins for one slug is the proof. This surfaces it once per
|
|
373
|
+
* injected conversation, in the block the model actually reads.
|
|
374
|
+
*
|
|
375
|
+
* @param root - the session's project root, when it has one.
|
|
376
|
+
* @returns the warning line, or `undefined` when there is no collision.
|
|
377
|
+
*/
|
|
378
|
+
private conflictNote;
|
|
333
379
|
/**
|
|
334
380
|
* The one line this plugin wants in the summary but cannot express as a memory.
|
|
335
381
|
*
|
|
@@ -489,8 +535,8 @@ export declare class MemoriesRuntime {
|
|
|
489
535
|
* later is invisible until the model thinks to search for it. This path names
|
|
490
536
|
* only entries whose `updated` stamp is newer than the last injection, and
|
|
491
537
|
* only those the conversation has not already been shown, so it is a short
|
|
492
|
-
* paragraph rather than a second summary. Two per conversation,
|
|
493
|
-
* each: the block is a nudge, not a channel.
|
|
538
|
+
* paragraph rather than a second summary. Two per conversation, at
|
|
539
|
+
* `deltaMaxBytes` each: the block is a nudge, not a channel.
|
|
494
540
|
*
|
|
495
541
|
* @param agent - the agent whose next step is being prepared.
|
|
496
542
|
* @returns the message to append, or `undefined` when nothing new is worth it.
|
|
@@ -1200,6 +1246,7 @@ export declare const Config: import("@deepseek-ai/schemastery").default<Schemast
|
|
|
1200
1246
|
recallMinQueryChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1201
1247
|
recallMinTerms: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1202
1248
|
injectDelta: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
1249
|
+
deltaMaxBytes: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1203
1250
|
rotationEntries: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1204
1251
|
rotationEveryTurns: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1205
1252
|
maxEntriesPerScope: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
@@ -1269,6 +1316,7 @@ export declare const Config: import("@deepseek-ai/schemastery").default<Schemast
|
|
|
1269
1316
|
recallMinQueryChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1270
1317
|
recallMinTerms: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1271
1318
|
injectDelta: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
1319
|
+
deltaMaxBytes: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1272
1320
|
rotationEntries: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1273
1321
|
rotationEveryTurns: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1274
1322
|
maxEntriesPerScope: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
package/lib/types/search.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { type TimeRange } from './time.js';
|
|
|
21
21
|
export declare const FIELD_WEIGHTS: {
|
|
22
22
|
readonly title: 40;
|
|
23
23
|
readonly keys: 26;
|
|
24
|
+
readonly entities: 24;
|
|
24
25
|
readonly tags: 20;
|
|
25
26
|
readonly appliesTo: 18;
|
|
26
27
|
readonly body: 12;
|
|
@@ -35,6 +36,7 @@ export declare const FIELD_WEIGHTS: {
|
|
|
35
36
|
export declare const TERM_WEIGHTS: {
|
|
36
37
|
readonly title: 8;
|
|
37
38
|
readonly keys: 7;
|
|
39
|
+
readonly entities: 7;
|
|
38
40
|
readonly tags: 6;
|
|
39
41
|
readonly appliesTo: 5;
|
|
40
42
|
readonly body: 2;
|
|
@@ -370,6 +372,8 @@ export interface MatchCredit {
|
|
|
370
372
|
/** The structural evidence behind the score. */
|
|
371
373
|
readonly evidence: MatchEvidence;
|
|
372
374
|
}
|
|
375
|
+
/** One field a match may be scored against. */
|
|
376
|
+
export type ScoreField = 'title' | 'keys' | 'entities' | 'tags' | 'appliesTo' | 'body';
|
|
373
377
|
/** How strictly {@link matchCredit} applies its structural gate. */
|
|
374
378
|
export interface CreditOptions {
|
|
375
379
|
/**
|
|
@@ -407,6 +411,16 @@ export interface CreditOptions {
|
|
|
407
411
|
* hatch untouched — this only changes what "two terms" means.
|
|
408
412
|
*/
|
|
409
413
|
readonly hub?: (term: string) => boolean;
|
|
414
|
+
/**
|
|
415
|
+
* Which fields may produce score and evidence; omitted means every field.
|
|
416
|
+
*
|
|
417
|
+
* The alias fallback passes `['keys', 'appliesTo']` so a relaxed single-term
|
|
418
|
+
* pass cannot be carried by a body word. A body mention is the weakest claim
|
|
419
|
+
* in the store — a long memory mentions many things — while a `keys` entry is
|
|
420
|
+
* a deliberate statement that this is another name for the memory. Widening
|
|
421
|
+
* the gate for the latter must not widen it for the former.
|
|
422
|
+
*/
|
|
423
|
+
readonly fields?: readonly ScoreField[];
|
|
410
424
|
}
|
|
411
425
|
/**
|
|
412
426
|
* Whether one entry is genuinely about one turn — the single decision behind
|
|
@@ -439,6 +453,37 @@ export interface CreditOptions {
|
|
|
439
453
|
* @returns the verdict with the evidence behind it.
|
|
440
454
|
*/
|
|
441
455
|
export declare function matchCredit(entry: MemoryEntry, query: string, minScore: number, minTerms: number, options?: CreditOptions): MatchCredit;
|
|
456
|
+
/**
|
|
457
|
+
* Whether the query names one of the entry's entities.
|
|
458
|
+
*
|
|
459
|
+
* Entities are exact names, so the test is a substring match on each query term
|
|
460
|
+
* (a CJK bigram or a Latin word) against the entity list. A single shared
|
|
461
|
+
* character is not enough: 「票」 alone would make every receipt memory answer
|
|
462
|
+
* every question about tickets.
|
|
463
|
+
*
|
|
464
|
+
* @param entry - the memory whose entity list is tested.
|
|
465
|
+
* @param query - the turn.
|
|
466
|
+
* @returns true when at least one query term appears in the entity list.
|
|
467
|
+
*/
|
|
468
|
+
export declare function sharesEntity(entry: MemoryEntry, query: string): boolean;
|
|
469
|
+
/**
|
|
470
|
+
* The relevance floor an alias-only match must clear, as a share of the normal one.
|
|
471
|
+
*
|
|
472
|
+
* An alias pass scores `keys` and `appliesTo` only, so the full floor is
|
|
473
|
+
* unreachable by construction. Measured with `recallMinScore` 9 against this
|
|
474
|
+
* scorer: one CJK alias term scores 6 at most (7×0.5 in `keys` plus 5×0.5 in
|
|
475
|
+
* `appliesTo`) and one Latin word 12, while the strict gate needs 9 — so keeping
|
|
476
|
+
* the same number would have let the fallback fire for English turns and never
|
|
477
|
+
* for Chinese ones, the language most of this store is written in. That is the
|
|
478
|
+
* same "dead in practice" failure a keys-only search had, one layer down.
|
|
479
|
+
*
|
|
480
|
+
* Half the floor, and deliberately no lower: with one CJK term in `keys` alone
|
|
481
|
+
* the pass scores 3.5 and stays refused, so an alias has to be filed in two of
|
|
482
|
+
* the scored fields before it can carry a recall. The structural rule (a
|
|
483
|
+
* substantive term, meaning a CJK pair inside a shared run of three characters,
|
|
484
|
+
* or a Latin word of three) and the hub discount are unchanged.
|
|
485
|
+
*/
|
|
486
|
+
export declare const ALIAS_FLOOR_SHARE = 0.5;
|
|
442
487
|
/**
|
|
443
488
|
* Query terms too common in one scope to count as evidence.
|
|
444
489
|
*
|
|
@@ -573,6 +618,29 @@ export interface ScopeEntries {
|
|
|
573
618
|
* @returns hits ordered by descending relevance, the attention score breaking ties.
|
|
574
619
|
*/
|
|
575
620
|
export declare function searchMemories(groups: readonly ScopeEntries[], query: string, options?: SearchOptions): MemoryHit[];
|
|
621
|
+
/**
|
|
622
|
+
* The aliases and tags a store files memories under, ranked against one query.
|
|
623
|
+
*
|
|
624
|
+
* The main search is lexical, so a query written in the user's words finds
|
|
625
|
+
* nothing when the store was filed under the product's words: the model then
|
|
626
|
+
* reports "no memories match" and stops, although the memory exists under a
|
|
627
|
+
* name it did not guess. Re-running the search with different words is the
|
|
628
|
+
* only fix, and this is what makes that possible without a model call —
|
|
629
|
+
* `keys` and `tags` already hold every other name for every memory.
|
|
630
|
+
*
|
|
631
|
+
* A hint, never a result: the terms it returns are vocabulary, not claims, so
|
|
632
|
+
* a caller must not present them as matches.
|
|
633
|
+
*
|
|
634
|
+
* @param groups - per-scope entry lists.
|
|
635
|
+
* @param query - the query that found nothing.
|
|
636
|
+
* @param limit - most terms to return.
|
|
637
|
+
* @returns shared terms first, then the most widely used ones.
|
|
638
|
+
*/
|
|
639
|
+
export declare function suggestAliases(groups: readonly ScopeEntries[], query: string, limit?: number): {
|
|
640
|
+
term: string;
|
|
641
|
+
carriers: number;
|
|
642
|
+
matched: number;
|
|
643
|
+
}[];
|
|
576
644
|
/**
|
|
577
645
|
* Select entries without a text query — used by `memory_search`'s browse mode
|
|
578
646
|
* and by the injector.
|
package/lib/types/sync.d.ts
CHANGED
|
@@ -90,6 +90,18 @@ export declare function newerEntry(ours: string, theirs: string): {
|
|
|
90
90
|
export declare function isSessionNotePath(path: string): boolean;
|
|
91
91
|
/** The `at` stamp of one session note, or 0 when it cannot be parsed. */
|
|
92
92
|
export declare function sessionNoteStamp(text: string): number;
|
|
93
|
+
/** Whether one path is a persona file: prose the assistant maintains for the user. */
|
|
94
|
+
export declare function isPersonaPath(path: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Merge two versions of a persona file as a bullet union.
|
|
97
|
+
*
|
|
98
|
+
* A persona file is headings plus bullet lists; both machines append their own
|
|
99
|
+
* observations, so a line-level union keeps every rule either machine recorded.
|
|
100
|
+
* Bullets are matched on their trimmed text (duplicates are dropped), inserted
|
|
101
|
+
* after the last bullet of the same section, and a whole section that only
|
|
102
|
+
* `theirs` has is appended at the end. Non-bullet lines come from `ours`.
|
|
103
|
+
*/
|
|
104
|
+
export declare function mergePersona(ours: string, theirs: string): string;
|
|
93
105
|
/**
|
|
94
106
|
* Resolve one conflicting session note by keeping the later `at:` stamp.
|
|
95
107
|
*
|
package/lib/types/types.d.ts
CHANGED
|
@@ -73,6 +73,12 @@ export interface MemoryEntry {
|
|
|
73
73
|
* buys most of the recall a vector index would, without an index.
|
|
74
74
|
*/
|
|
75
75
|
readonly keys: readonly string[];
|
|
76
|
+
/**
|
|
77
|
+
* Named entities the memory is about: people, places, organisations, objects,
|
|
78
|
+
* dates. Used by recall to match a turn that names one of them even when it
|
|
79
|
+
* shares no other word with the memory (「北街南街」 against 「南街文具店」).
|
|
80
|
+
*/
|
|
81
|
+
readonly entities?: readonly string[];
|
|
76
82
|
/** When this memory is worth recalling, in the author's words. */
|
|
77
83
|
readonly appliesTo?: string;
|
|
78
84
|
/**
|
|
@@ -291,6 +297,8 @@ export interface MemoryDraft {
|
|
|
291
297
|
readonly derivedFrom?: readonly string[];
|
|
292
298
|
/** Extra search keys (aliases, keyphrases) that should also find this memory. */
|
|
293
299
|
readonly keys?: readonly string[];
|
|
300
|
+
/** Named entities (people, places, organisations, objects) this memory is about. */
|
|
301
|
+
readonly entities?: readonly string[];
|
|
294
302
|
}
|
|
295
303
|
/** The outcome of persisting one draft. */
|
|
296
304
|
export interface UpsertResult {
|
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.4",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|