dsh-cross-memory 0.2.8 → 0.2.10
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 +12 -2
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/lib/bm25.js +100 -0
- package/lib/cards.js +188 -0
- package/lib/client.js +200 -1
- package/lib/config.js +16 -4
- package/lib/dense.js +180 -0
- package/lib/index.js +174 -44
- package/lib/render.js +71 -18
- package/lib/search.js +33 -53
- package/lib/test/bm25.test.js +108 -0
- package/lib/test/dense.test.js +49 -0
- package/lib/test/injection.test.js +18 -2
- package/lib/test/proposal-card.test.js +353 -0
- package/lib/tokenize.js +68 -0
- package/lib/types/bm25.d.ts +66 -0
- package/lib/types/cards.d.ts +186 -0
- package/lib/types/config.d.ts +16 -4
- package/lib/types/dense.d.ts +53 -0
- package/lib/types/index.d.ts +30 -8
- package/lib/types/render.d.ts +1 -0
- package/lib/types/search.d.ts +1 -21
- package/lib/types/test/bm25.test.d.ts +1 -0
- package/lib/types/test/dense.test.d.ts +1 -0
- package/lib/types/test/proposal-card.test.d.ts +1 -0
- package/lib/types/tokenize.d.ts +39 -0
- package/package.json +8 -4
package/lib/types/config.d.ts
CHANGED
|
@@ -214,6 +214,12 @@ export declare const DEFAULT_RAG_RECALL_BYTES = 12000;
|
|
|
214
214
|
export declare const DEFAULT_RAG_RECALL_EXCERPTS = 6;
|
|
215
215
|
export declare const DEFAULT_RAG_RECALL_SESSIONS = 0;
|
|
216
216
|
export declare const DEFAULT_RAG_RECALL_CHARS = 2000;
|
|
217
|
+
/** Dense ranking is opt-in: it needs a local embedding service on every machine that recalls. */
|
|
218
|
+
export declare const DEFAULT_DENSE_ENABLED = false;
|
|
219
|
+
/** Ollama's default endpoint; the plugin never calls outside the machine unless this is changed. */
|
|
220
|
+
export declare const DEFAULT_DENSE_URL = "http://127.0.0.1:11434";
|
|
221
|
+
/** The model the bench measured (1024 dimensions). */
|
|
222
|
+
export declare const DEFAULT_DENSE_MODEL = "qwen3-embedding:0.6b";
|
|
217
223
|
/**
|
|
218
224
|
* Default number of distinct strong-field terms a recall needs.
|
|
219
225
|
*
|
|
@@ -281,13 +287,16 @@ export declare const DEFAULT_EXTRACT_TIMEOUT_MS = 120000;
|
|
|
281
287
|
/**
|
|
282
288
|
* Default max drafts one extraction may produce.
|
|
283
289
|
*
|
|
284
|
-
*
|
|
290
|
+
* 12 rather than 5, then 8: on a real production session, an audit of 50 Mubea
|
|
285
291
|
* Invoice-Insight conversations found 247 durable facts, and the cap of 5 was
|
|
286
292
|
* the single biggest cause of missed material on long sessions (one audit
|
|
287
|
-
* session held 16 facts and kept 5).
|
|
288
|
-
*
|
|
293
|
+
* session held 16 facts and kept 5). The real-session bench then measured a
|
|
294
|
+
* clean dose-response on one fixed corpus: 5 → 19/33, 10 → 22/33, 20 → 24/33,
|
|
295
|
+
* so the curve is still rising at 20 but flattening. Twelve is where the next
|
|
296
|
+
* step buys about one more answered question per extra pass, before the entry
|
|
297
|
+
* count (and the consolidation load it creates) starts to dominate.
|
|
289
298
|
*/
|
|
290
|
-
export declare const DEFAULT_EXTRACT_MAX_MEMORIES =
|
|
299
|
+
export declare const DEFAULT_EXTRACT_MAX_MEMORIES = 12;
|
|
291
300
|
/**
|
|
292
301
|
* What the extractor is allowed to keep, by default.
|
|
293
302
|
*
|
|
@@ -419,6 +428,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
419
428
|
ragRecallExcerpts: z<number, number, "volatile-defined">;
|
|
420
429
|
ragRecallSessions: z<number, number, "volatile-defined">;
|
|
421
430
|
ragRecallChars: z<number, number, "volatile-defined">;
|
|
431
|
+
denseEnabled: z<boolean, boolean, "volatile-defined">;
|
|
422
432
|
/** Shortest user turn worth a recall decision. */
|
|
423
433
|
recallMinQueryChars: z<number, number, "volatile-defined">;
|
|
424
434
|
/** Distinct strong-field terms a recall needs before it is credited. */
|
|
@@ -589,6 +599,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
589
599
|
ragRecallExcerpts: z<number, number, "volatile-defined">;
|
|
590
600
|
ragRecallSessions: z<number, number, "volatile-defined">;
|
|
591
601
|
ragRecallChars: z<number, number, "volatile-defined">;
|
|
602
|
+
denseEnabled: z<boolean, boolean, "volatile-defined">;
|
|
592
603
|
/** Shortest user turn worth a recall decision. */
|
|
593
604
|
recallMinQueryChars: z<number, number, "volatile-defined">;
|
|
594
605
|
/** Distinct strong-field terms a recall needs before it is credited. */
|
|
@@ -735,6 +746,7 @@ export interface MemoriesSettings {
|
|
|
735
746
|
ragRecallExcerpts: number;
|
|
736
747
|
ragRecallSessions: number;
|
|
737
748
|
ragRecallChars: number;
|
|
749
|
+
denseEnabled: boolean;
|
|
738
750
|
recallMinQueryChars: number;
|
|
739
751
|
recallMinTerms: number;
|
|
740
752
|
/** Whether memories written after the summary are announced as a delta. */
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { MemoryEntry } from './types.js';
|
|
2
|
+
/** Where the embedding service is reached; the harness never calls outside the machine by default. */
|
|
3
|
+
export declare const DEFAULT_DENSE_URL = "http://127.0.0.1:11434";
|
|
4
|
+
/** The model the bench measured. Any embedding model works; the cache is keyed by name. */
|
|
5
|
+
export declare const DEFAULT_DENSE_MODEL = "qwen3-embedding:0.6b";
|
|
6
|
+
/** Settings for one dense pass. */
|
|
7
|
+
export interface DenseOptions {
|
|
8
|
+
/** Base URL of the embedding service, e.g. `http://127.0.0.1:11434`. */
|
|
9
|
+
readonly url: string;
|
|
10
|
+
/** Model name. */
|
|
11
|
+
readonly model: string;
|
|
12
|
+
/** Directory holding the JSON vector cache. */
|
|
13
|
+
readonly cacheDir: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Embed texts, reusing the on-disk cache.
|
|
17
|
+
*
|
|
18
|
+
* Failures propagate: the caller decides whether to fall back. The cache is
|
|
19
|
+
* written only after every batch succeeded, so a partial run never poisons it.
|
|
20
|
+
*
|
|
21
|
+
* @param texts - texts to embed, in order.
|
|
22
|
+
* @param options - service location, model, and cache directory.
|
|
23
|
+
* @returns one unit vector per text.
|
|
24
|
+
*/
|
|
25
|
+
export declare function embed(texts: readonly string[], options: DenseOptions): Promise<Float32Array[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Cosine similarity of two unit vectors (a dot product).
|
|
28
|
+
* @param left - one vector.
|
|
29
|
+
* @param right - the other.
|
|
30
|
+
* @returns similarity in `[-1, 1]`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function cosine(left: Float32Array, right: Float32Array): number;
|
|
33
|
+
/**
|
|
34
|
+
* Score every entry against one query by embedding.
|
|
35
|
+
*
|
|
36
|
+
* @param entries - the entries to score.
|
|
37
|
+
* @param query - the turn.
|
|
38
|
+
* @param options - service location, model, and cache directory.
|
|
39
|
+
* @returns id → cosine similarity; empty when the service is unavailable.
|
|
40
|
+
*/
|
|
41
|
+
export declare function denseScores(entries: readonly MemoryEntry[], query: string, options: DenseOptions): Promise<Map<string, number>>;
|
|
42
|
+
/**
|
|
43
|
+
* Reciprocal rank fusion.
|
|
44
|
+
*
|
|
45
|
+
* The two channels disagree about scale, not about order, so their ranks are
|
|
46
|
+
* fused instead of their scores: each list contributes `1 / (k + rank)`, and
|
|
47
|
+
* the constant keeps a first place worth about twice a tenth.
|
|
48
|
+
*
|
|
49
|
+
* @param lists - ranked id lists, best first.
|
|
50
|
+
* @param k - fusion constant; 60 is the usual value.
|
|
51
|
+
* @returns id → fused score, descending.
|
|
52
|
+
*/
|
|
53
|
+
export declare function rrf(lists: readonly (readonly string[])[], k?: number): Map<string, number>;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -142,6 +142,8 @@ export declare class MemoriesRuntime {
|
|
|
142
142
|
*/
|
|
143
143
|
logSinkError: string | undefined;
|
|
144
144
|
constructor(ctx: Context, config: MemoriesConfig, settings?: () => MemoriesSettings);
|
|
145
|
+
/** Embed the store once in the background so the first recall is not the slow one. */
|
|
146
|
+
private warmDense;
|
|
145
147
|
/**
|
|
146
148
|
* The LLM runtime to use right now.
|
|
147
149
|
*
|
|
@@ -356,9 +358,20 @@ export declare class MemoriesRuntime {
|
|
|
356
358
|
* Apply every waiting decision.
|
|
357
359
|
*
|
|
358
360
|
* @param _parent - the agent asking; the stored rows carry their own scope.
|
|
359
|
-
* @returns
|
|
361
|
+
* @returns the command's report plus the counts the action-card decision
|
|
362
|
+
* records, or `undefined` when nothing is staged.
|
|
360
363
|
*/
|
|
361
|
-
applyPendingPlan(_parent: Agent): Promise<
|
|
364
|
+
applyPendingPlan(_parent: Agent): Promise<{
|
|
365
|
+
text: string;
|
|
366
|
+
written: number;
|
|
367
|
+
retired: number;
|
|
368
|
+
} | undefined>;
|
|
369
|
+
/**
|
|
370
|
+
* Discard every waiting decision, leaving the store untouched.
|
|
371
|
+
*
|
|
372
|
+
* @returns how many decisions were dropped, or `undefined` when nothing was staged.
|
|
373
|
+
*/
|
|
374
|
+
rejectPendingPlan(): Promise<number | undefined>;
|
|
362
375
|
/**
|
|
363
376
|
* A warning when this workspace's memory directory is shared with another
|
|
364
377
|
* repository of the same name.
|
|
@@ -489,6 +502,8 @@ export declare class MemoriesRuntime {
|
|
|
489
502
|
* @returns the predicate, or `undefined` when the discount is off.
|
|
490
503
|
*/
|
|
491
504
|
private hubFor;
|
|
505
|
+
/** Where the dense vector cache lives: `<dshHome>/cache/dsh-cross-memory`. */
|
|
506
|
+
private denseCacheDir;
|
|
492
507
|
/**
|
|
493
508
|
* The on-demand recall delta for this step, or `undefined` when nothing is
|
|
494
509
|
* worth adding.
|
|
@@ -927,12 +942,17 @@ export declare class MemoriesRuntime {
|
|
|
927
942
|
/**
|
|
928
943
|
* Speak without being asked, when there is something to say.
|
|
929
944
|
*
|
|
930
|
-
* Two deterministic triggers
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
*
|
|
945
|
+
* Two deterministic triggers: a daily line about what the plugin maintained,
|
|
946
|
+
* and a promise whose deadline has passed. Both are judgements a rule can
|
|
947
|
+
* make, which is why they are the ones allowed to interrupt. Everything
|
|
948
|
+
* smarter (reflections) enters here later through the same queue, and the
|
|
949
|
+
* same rules apply: evidence or silence, and never the same subject twice.
|
|
950
|
+
*
|
|
951
|
+
* A staged consolidation proposal no longer comes through this pump: its
|
|
952
|
+
* backlog branch could not reach the user in this deployment (macOS
|
|
953
|
+
* `osascript` is unavailable, so every delivery logged `no channel for notice
|
|
954
|
+
* backlog`), and the answer card plus the injected draft note are the
|
|
955
|
+
* confirmation path now.
|
|
936
956
|
*
|
|
937
957
|
* Called from the once-per-conversation hook and from the maintenance sweep. A
|
|
938
958
|
* failure is logged and swallowed: speaking is never allowed to break a turn.
|
|
@@ -1249,6 +1269,7 @@ export declare const Config: import("@deepseek-ai/schemastery").default<Schemast
|
|
|
1249
1269
|
ragRecallExcerpts: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1250
1270
|
ragRecallSessions: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1251
1271
|
ragRecallChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1272
|
+
denseEnabled: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
1252
1273
|
recallMinQueryChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1253
1274
|
recallMinTerms: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1254
1275
|
injectDelta: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
@@ -1325,6 +1346,7 @@ export declare const Config: import("@deepseek-ai/schemastery").default<Schemast
|
|
|
1325
1346
|
ragRecallExcerpts: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1326
1347
|
ragRecallSessions: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1327
1348
|
ragRecallChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1349
|
+
denseEnabled: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
1328
1350
|
recallMinQueryChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1329
1351
|
recallMinTerms: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1330
1352
|
injectDelta: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
package/lib/types/render.d.ts
CHANGED
|
@@ -137,6 +137,7 @@ export declare function selectForSummary(entries: readonly MemoryEntry[], perSco
|
|
|
137
137
|
freshSlots?: number;
|
|
138
138
|
now?: number;
|
|
139
139
|
query?: string;
|
|
140
|
+
ranked?: readonly MemoryEntry[];
|
|
140
141
|
}): MemoryEntry[];
|
|
141
142
|
/** One scope's contribution to the injected summary. */
|
|
142
143
|
export interface SummaryScope {
|
package/lib/types/search.d.ts
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import type { MemoryEntry, MemoryHit, MemoryKind, MemoryScope } from './types.js';
|
|
19
19
|
import { type TimeRange } from './time.js';
|
|
20
|
+
export { tokenize, termWeight } from './tokenize.js';
|
|
20
21
|
/** Score added when the whole query appears verbatim in one field. */
|
|
21
22
|
export declare const FIELD_WEIGHTS: {
|
|
22
23
|
readonly title: 40;
|
|
@@ -75,27 +76,6 @@ export interface MatchEvidence {
|
|
|
75
76
|
}
|
|
76
77
|
/** Most body occurrences of one term that still earn score. */
|
|
77
78
|
export declare const BODY_TERM_CAP = 4;
|
|
78
|
-
/** Split text into searchable terms: ASCII words and CJK character bigrams.
|
|
79
|
-
*
|
|
80
|
-
* A CJK run also contributes bigrams of its neighbours, so "该插件是否有日志"
|
|
81
|
-
* yields "该插","插件","件是","是否","否有","有日","日志". A one-character run
|
|
82
|
-
* contributes itself, since a lone ideograph has no bigram.
|
|
83
|
-
*
|
|
84
|
-
* @param text - raw text.
|
|
85
|
-
* @returns lowercase terms; a run that yields nothing contributes nothing.
|
|
86
|
-
*/
|
|
87
|
-
export declare function tokenize(text: string): string[];
|
|
88
|
-
/**
|
|
89
|
-
* A term's weight for scoring purposes.
|
|
90
|
-
*
|
|
91
|
-
* One CJK bigram is a much weaker claim than one Latin word — "日志" occurs in
|
|
92
|
-
* countless texts where "logging" does not — so a bigram earns less. Without
|
|
93
|
-
* this every Chinese question would clear the recall gate on noise alone.
|
|
94
|
-
*
|
|
95
|
-
* @param term - one term from {@link tokenize}.
|
|
96
|
-
* @returns a multiplier in `(0, 1]`.
|
|
97
|
-
*/
|
|
98
|
-
export declare function termWeight(term: string): number;
|
|
99
79
|
/**
|
|
100
80
|
* Build (or reuse) the term index for one entry array.
|
|
101
81
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tokenizer shared by every lexical path in the plugin.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `search.ts` so the BM25 ranker can use the exact same terms as
|
|
5
|
+
* the hand-weighted scorer without a circular import: the two rankers are
|
|
6
|
+
* supposed to agree on what a "term" is, and a copy of this file would be the
|
|
7
|
+
* first thing to drift.
|
|
8
|
+
*
|
|
9
|
+
* Chinese is the reason this module exists. A query with no spaces
|
|
10
|
+
* ("该插件是否有日志") tokenizes to one indivisible run under any whitespace
|
|
11
|
+
* splitter, so a whole-run substring test is the only thing that could match —
|
|
12
|
+
* and a memory almost never contains a whole question verbatim. Every
|
|
13
|
+
* comparison therefore runs over CJK character bigrams as well.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-cross-memory/tokenize
|
|
16
|
+
*/
|
|
17
|
+
/** Split text into searchable terms: ASCII words and CJK character bigrams.
|
|
18
|
+
*
|
|
19
|
+
* A CJK run also contributes bigrams of its neighbours, so "该插件是否有日志"
|
|
20
|
+
* yields "该插","插件","件是","是否","否有","有日","日志". A one-character run
|
|
21
|
+
* contributes itself, since a lone ideograph has no bigram.
|
|
22
|
+
*
|
|
23
|
+
* @param text - raw text.
|
|
24
|
+
* @returns lowercase terms; a run that yields nothing contributes nothing.
|
|
25
|
+
*/
|
|
26
|
+
export declare function tokenize(text: string): string[];
|
|
27
|
+
/**
|
|
28
|
+
* A term's weight for scoring purposes.
|
|
29
|
+
*
|
|
30
|
+
* One CJK bigram is a much weaker claim than one Latin word — "日志" occurs in
|
|
31
|
+
* countless texts where "logging" does not — so a bigram earns less. Without
|
|
32
|
+
* this every Chinese question would clear the recall gate on noise alone.
|
|
33
|
+
*
|
|
34
|
+
* @param term - one term from {@link tokenize}.
|
|
35
|
+
* @returns a multiplier in `(0, 1]`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function termWeight(term: string): number;
|
|
38
|
+
/** A short token carries little signal and is skipped as a query term. */
|
|
39
|
+
export declare function isNoise(token: string): boolean;
|
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.10",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=24",
|
|
57
|
-
"dsh": "^0.2.1-rc.2 || ^0.2.2-alpha.2"
|
|
57
|
+
"dsh": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1"
|
|
58
58
|
},
|
|
59
59
|
"dsh": {
|
|
60
60
|
"manifestVersion": 1,
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"client": {
|
|
65
65
|
"inject": [
|
|
66
66
|
"@deepseek-ai/dsh-client-ui-settings",
|
|
67
|
-
"@deepseek-ai/dsh-client-ui-slots"
|
|
67
|
+
"@deepseek-ai/dsh-client-ui-slots",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-action-cards"
|
|
68
69
|
],
|
|
69
70
|
"external": [
|
|
70
71
|
"@deepseek-ai/dsh-client-ui-settings/client"
|
|
@@ -105,6 +106,7 @@
|
|
|
105
106
|
"devDependencies": {
|
|
106
107
|
"@deepseek-ai/cordis": "4.1.0",
|
|
107
108
|
"@deepseek-ai/cordis-plugin-loader": "^1.1.0",
|
|
109
|
+
"@deepseek-ai/dsh-action-cards": "0.2.3-alpha.2",
|
|
108
110
|
"@deepseek-ai/dsh-agent": "0.2.2-rc.1",
|
|
109
111
|
"@deepseek-ai/dsh-attachment": "0.2.2-rc.1",
|
|
110
112
|
"@deepseek-ai/dsh-commands": "0.2.2-rc.1",
|
|
@@ -113,6 +115,7 @@
|
|
|
113
115
|
"@deepseek-ai/dsh-scope": "0.2.2-rc.1",
|
|
114
116
|
"@deepseek-ai/dsh-session": "0.2.2-rc.1",
|
|
115
117
|
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
|
|
118
|
+
"@deepseek-ai/dsh-skill": "0.2.3-alpha.2",
|
|
116
119
|
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
|
|
117
120
|
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
118
121
|
"@deepseek-ai/dsh-user-approval": "0.2.2-rc.1",
|
|
@@ -122,7 +125,8 @@
|
|
|
122
125
|
"typescript": "^7.0.2"
|
|
123
126
|
},
|
|
124
127
|
"dependencies": {
|
|
125
|
-
"@deepseek-ai/cosmokit": "^1.9.0"
|
|
128
|
+
"@deepseek-ai/cosmokit": "^1.9.0",
|
|
129
|
+
"zod": "^4.6.7"
|
|
126
130
|
},
|
|
127
131
|
"icon": "./icon.svg"
|
|
128
132
|
}
|