dsh-cross-memory 0.2.6 → 0.2.9
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/backfill.js +3 -1
- package/lib/bm25.js +100 -0
- package/lib/cards.js +188 -0
- package/lib/client.js +229 -1
- package/lib/config.js +60 -4
- package/lib/extract.js +232 -13
- package/lib/index.js +171 -45
- package/lib/raw-recall.js +149 -0
- package/lib/render.js +71 -18
- package/lib/search.js +33 -53
- package/lib/test/extract.test.js +33 -3
- package/lib/test/injection.test.js +18 -2
- package/lib/test/proposal-card.test.js +353 -0
- package/lib/test/recall.test.js +4 -2
- 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 +64 -4
- package/lib/types/extract.d.ts +54 -0
- package/lib/types/index.d.ts +37 -8
- package/lib/types/raw-recall.d.ts +28 -0
- package/lib/types/render.d.ts +1 -0
- package/lib/types/search.d.ts +1 -21
- package/lib/types/test/proposal-card.test.d.ts +1 -0
- package/lib/types/tokenize.d.ts +39 -0
- package/package.json +8 -4
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `resolve_memory_proposal` action card: a staged consolidation proposal
|
|
3
|
+
* offered in the answer, decided by a click.
|
|
4
|
+
*
|
|
5
|
+
* Before 0.2.9 a staged proposal could only wait for `/memories plan` +
|
|
6
|
+
* `/memories apply|reject` or the settings page, and the notification pump that
|
|
7
|
+
* pointed at it is unusable on macOS in this deployment (no osascript channel).
|
|
8
|
+
* A card is the same question where the user already is: the model loads a
|
|
9
|
+
* skill, ends its answer with an `action-card` block, and the buttons apply or
|
|
10
|
+
* discard the whole waiting batch.
|
|
11
|
+
*
|
|
12
|
+
* The kind owns no state of its own: every action reads the real pending file
|
|
13
|
+
* through {@link ProposalCardRuntime}, so a card can never apply a proposal the
|
|
14
|
+
* store no longer has, and the same pending batch stays actionable from the
|
|
15
|
+
* command and the settings panel.
|
|
16
|
+
*
|
|
17
|
+
* The Host services are described by the small structural interfaces below
|
|
18
|
+
* instead of importing `@deepseek-ai/dsh-action-cards` / `dsh-skill` types. Two
|
|
19
|
+
* reasons: the card mechanism is an optional capability (an older Host has no
|
|
20
|
+
* `skillProvider` and this plugin must still compose), and both packages ship
|
|
21
|
+
* their own `schemastery` copy, whose duplicate type identity made this
|
|
22
|
+
* package's `Config` declaration non-portable.
|
|
23
|
+
*
|
|
24
|
+
* @module dsh-cross-memory/cards
|
|
25
|
+
*/
|
|
26
|
+
import { z } from 'zod';
|
|
27
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
28
|
+
import type { Session } from '@deepseek-ai/dsh-session';
|
|
29
|
+
/** Value of the card's `action` field; also what the skill's block names. */
|
|
30
|
+
export declare const PROPOSAL_ACTION = "resolve_memory_proposal";
|
|
31
|
+
/** Skill name that tells the model when to offer the card. */
|
|
32
|
+
export declare const PROPOSAL_SKILL = "memory-proposal";
|
|
33
|
+
/** Fields the model writes into the answer block; validated on both sides. */
|
|
34
|
+
export interface ProposalDetails {
|
|
35
|
+
/** Scope label of the waiting proposal, as the store wrote it. */
|
|
36
|
+
readonly label: string;
|
|
37
|
+
/** Number of decisions waiting for the user. */
|
|
38
|
+
readonly count: number;
|
|
39
|
+
/** Epoch milliseconds when the pass staged the proposal. */
|
|
40
|
+
readonly stagedAt: number;
|
|
41
|
+
}
|
|
42
|
+
/** Host validation for one card's `details`. */
|
|
43
|
+
export declare const PROPOSAL_DETAILS: z.ZodObject<{
|
|
44
|
+
label: z.ZodString;
|
|
45
|
+
count: z.ZodNumber;
|
|
46
|
+
stagedAt: z.ZodNumber;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
/** The staged proposal as the card reads it; identical to the injected note's fields. */
|
|
49
|
+
export interface PendingProposal {
|
|
50
|
+
readonly label: string;
|
|
51
|
+
readonly count: number;
|
|
52
|
+
readonly stagedAt: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* What the card needs from the memory runtime.
|
|
56
|
+
*
|
|
57
|
+
* A seam rather than the runtime itself: the kind is testable with three tiny
|
|
58
|
+
* functions, and it cannot reach the store, the model or the session directly.
|
|
59
|
+
*/
|
|
60
|
+
export interface ProposalCardRuntime {
|
|
61
|
+
/** The proposal waiting right now, or `undefined` when nothing is staged. */
|
|
62
|
+
pending(): Promise<PendingProposal | undefined>;
|
|
63
|
+
/**
|
|
64
|
+
* Apply every waiting decision.
|
|
65
|
+
* @param agent - live root of the card's Session, as the Host resolved it.
|
|
66
|
+
* @returns the written/retired counts, or `undefined` when nothing was staged.
|
|
67
|
+
*/
|
|
68
|
+
apply(agent: Agent): Promise<{
|
|
69
|
+
readonly written: number;
|
|
70
|
+
readonly retired: number;
|
|
71
|
+
} | undefined>;
|
|
72
|
+
/** Discard every waiting decision, returning how many were dropped. */
|
|
73
|
+
reject(): Promise<number | undefined>;
|
|
74
|
+
}
|
|
75
|
+
/** One decision recorded for a card, as the Host stores it. */
|
|
76
|
+
export interface ProposalDecision {
|
|
77
|
+
readonly cardId: string;
|
|
78
|
+
readonly action: string;
|
|
79
|
+
readonly phase: string;
|
|
80
|
+
readonly data?: Readonly<Record<string, unknown>>;
|
|
81
|
+
}
|
|
82
|
+
/** One card as the Host hands it to `reconcile` and `act`. */
|
|
83
|
+
export interface ProposalRef {
|
|
84
|
+
readonly cardId: string;
|
|
85
|
+
readonly action: string;
|
|
86
|
+
readonly title: string;
|
|
87
|
+
readonly brief: string;
|
|
88
|
+
readonly details: ProposalDetails;
|
|
89
|
+
}
|
|
90
|
+
/** What a card action returns to the browser. */
|
|
91
|
+
export type ProposalResult = {
|
|
92
|
+
readonly status: 'accepted';
|
|
93
|
+
} | {
|
|
94
|
+
readonly status: 'settled';
|
|
95
|
+
readonly decision: ProposalDecision;
|
|
96
|
+
} | {
|
|
97
|
+
readonly status: 'refused';
|
|
98
|
+
readonly reason: string;
|
|
99
|
+
} | {
|
|
100
|
+
readonly status: 'unconfirmed';
|
|
101
|
+
readonly reason: string;
|
|
102
|
+
};
|
|
103
|
+
/** The zod-like field validator the Host calls before every action. */
|
|
104
|
+
export interface ProposalDetailsSchema {
|
|
105
|
+
safeParse(value: unknown): {
|
|
106
|
+
readonly success: true;
|
|
107
|
+
readonly data: ProposalDetails;
|
|
108
|
+
} | {
|
|
109
|
+
readonly success: false;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** One Host action kind, narrowed to the fields this plugin sets. */
|
|
113
|
+
export interface ProposalKind {
|
|
114
|
+
readonly action: string;
|
|
115
|
+
readonly details: ProposalDetailsSchema;
|
|
116
|
+
readonly verbs: Readonly<Record<string, {
|
|
117
|
+
readonly writes?: true;
|
|
118
|
+
readonly global?: true;
|
|
119
|
+
}>>;
|
|
120
|
+
readonly openPhases?: readonly string[];
|
|
121
|
+
readonly statusGuidance?: string;
|
|
122
|
+
readonly statusFields?: readonly string[];
|
|
123
|
+
reconcile?(agent: Agent, proposal: ProposalRef): Promise<void>;
|
|
124
|
+
act(agent: Agent, proposal: ProposalRef, verb: string, payload: Readonly<Record<string, unknown>> | undefined): Promise<ProposalResult>;
|
|
125
|
+
}
|
|
126
|
+
/** One skill catalog entry, as `ctx.skills` takes it. */
|
|
127
|
+
export interface ProposalSkillCandidate {
|
|
128
|
+
readonly name: string;
|
|
129
|
+
readonly description: string;
|
|
130
|
+
readonly invocation: {
|
|
131
|
+
readonly modelInvocable: boolean;
|
|
132
|
+
readonly userInvocable: boolean;
|
|
133
|
+
};
|
|
134
|
+
readonly source: string;
|
|
135
|
+
readonly provider: string;
|
|
136
|
+
readonly rank: number;
|
|
137
|
+
readonly locator: unknown;
|
|
138
|
+
}
|
|
139
|
+
/** One loaded skill definition. */
|
|
140
|
+
export type ProposalSkillDefinition = Omit<ProposalSkillCandidate, 'rank' | 'locator'> & {
|
|
141
|
+
readonly content: string;
|
|
142
|
+
};
|
|
143
|
+
/** Options a provider receives when listing or loading a skill. */
|
|
144
|
+
export interface ProposalSkillOptions {
|
|
145
|
+
readonly signal?: AbortSignal;
|
|
146
|
+
}
|
|
147
|
+
/** What a provider receives when the registry binds it. */
|
|
148
|
+
export interface ProposalSkillControl {
|
|
149
|
+
readonly signal: AbortSignal;
|
|
150
|
+
readonly invalidate: () => void;
|
|
151
|
+
}
|
|
152
|
+
/** One skill provider, narrowed to what this plugin implements. */
|
|
153
|
+
export interface ProposalSkillProvider {
|
|
154
|
+
readonly name: string;
|
|
155
|
+
readonly list: (options: ProposalSkillOptions) => Promise<readonly ProposalSkillCandidate[]>;
|
|
156
|
+
readonly get: (candidate: ProposalSkillCandidate, options: ProposalSkillOptions) => Promise<ProposalSkillDefinition | undefined>;
|
|
157
|
+
}
|
|
158
|
+
/** The Host action-card service, narrowed to what this kind uses. */
|
|
159
|
+
export interface ProposalCards {
|
|
160
|
+
view(session: Session): {
|
|
161
|
+
readonly decisions: Readonly<Record<string, ProposalDecision>>;
|
|
162
|
+
};
|
|
163
|
+
register(kind: ProposalKind): () => void;
|
|
164
|
+
record(agent: Agent, decision: ProposalDecision): void;
|
|
165
|
+
/** Present only from 0.2.3-alpha.2; the composition checks it before calling. */
|
|
166
|
+
skillProvider(candidate: ProposalSkillCandidate, get: ProposalSkillProvider['get']): (control: ProposalSkillControl) => ProposalSkillProvider;
|
|
167
|
+
}
|
|
168
|
+
/** The Host skill registry, narrowed to provider registration. */
|
|
169
|
+
export interface ProposalSkills {
|
|
170
|
+
registerProvider(create: (control: ProposalSkillControl) => ProposalSkillProvider): () => void;
|
|
171
|
+
}
|
|
172
|
+
/** What the model is told when it loads the skill. */
|
|
173
|
+
export declare const PROPOSAL_SKILL_CONTENT: string;
|
|
174
|
+
/**
|
|
175
|
+
* Register the card kind and the skill that offers it for the caller's lifetime.
|
|
176
|
+
*
|
|
177
|
+
* The caller must run this inside `ctx.inject(['actionCards', 'skills'], …)` and
|
|
178
|
+
* hold the returned disposer in `ctx.effect`; disposing removes both, so an
|
|
179
|
+
* unloaded plugin leaves no half-registered card behind.
|
|
180
|
+
*
|
|
181
|
+
* @param cards - the Host action-card service.
|
|
182
|
+
* @param skills - the Host skill registry.
|
|
183
|
+
* @param runtime - the store seam described by {@link ProposalCardRuntime}.
|
|
184
|
+
* @returns disposer removing the kind and the skill provider.
|
|
185
|
+
*/
|
|
186
|
+
export declare function registerProposalCard(cards: ProposalCards, skills: ProposalSkills, runtime: ProposalCardRuntime): () => void;
|
package/lib/types/config.d.ts
CHANGED
|
@@ -209,6 +209,11 @@ export declare const DEFAULT_RAW_RECALL = false;
|
|
|
209
209
|
export declare const DEFAULT_RAW_RECALL_BYTES = 2400;
|
|
210
210
|
/** Most raw excerpts one recall block may carry. */
|
|
211
211
|
export declare const DEFAULT_RAW_RECALL_EXCERPTS = 3;
|
|
212
|
+
export declare const DEFAULT_RAG_RECALL = true;
|
|
213
|
+
export declare const DEFAULT_RAG_RECALL_BYTES = 12000;
|
|
214
|
+
export declare const DEFAULT_RAG_RECALL_EXCERPTS = 6;
|
|
215
|
+
export declare const DEFAULT_RAG_RECALL_SESSIONS = 0;
|
|
216
|
+
export declare const DEFAULT_RAG_RECALL_CHARS = 2000;
|
|
212
217
|
/**
|
|
213
218
|
* Default number of distinct strong-field terms a recall needs.
|
|
214
219
|
*
|
|
@@ -276,13 +281,31 @@ export declare const DEFAULT_EXTRACT_TIMEOUT_MS = 120000;
|
|
|
276
281
|
/**
|
|
277
282
|
* Default max drafts one extraction may produce.
|
|
278
283
|
*
|
|
279
|
-
*
|
|
284
|
+
* 12 rather than 5, then 8: on a real production session, an audit of 50 Mubea
|
|
280
285
|
* Invoice-Insight conversations found 247 durable facts, and the cap of 5 was
|
|
281
286
|
* the single biggest cause of missed material on long sessions (one audit
|
|
282
|
-
* session held 16 facts and kept 5).
|
|
283
|
-
*
|
|
287
|
+
* session held 16 facts and kept 5). The real-session bench then measured a
|
|
288
|
+
* clean dose-response on one fixed corpus: 5 → 19/33, 10 → 22/33, 20 → 24/33,
|
|
289
|
+
* so the curve is still rising at 20 but flattening. Twelve is where the next
|
|
290
|
+
* step buys about one more answered question per extra pass, before the entry
|
|
291
|
+
* count (and the consolidation load it creates) starts to dominate.
|
|
284
292
|
*/
|
|
285
|
-
export declare const DEFAULT_EXTRACT_MAX_MEMORIES =
|
|
293
|
+
export declare const DEFAULT_EXTRACT_MAX_MEMORIES = 12;
|
|
294
|
+
/**
|
|
295
|
+
* What the extractor is allowed to keep, by default.
|
|
296
|
+
*
|
|
297
|
+
* `work` (the default) keeps the material a working session actually needs —
|
|
298
|
+
* project architecture and conventions, commands, gotchas, decisions and their
|
|
299
|
+
* reasons, and pre-sales material (quotes, proposals, customer terms, effort
|
|
300
|
+
* estimates, contracts, bids) — and leaves personal life alone unless the user
|
|
301
|
+
* asked for it. `both` also keeps personal background, relationships, habits and
|
|
302
|
+
* creative collaborations.
|
|
303
|
+
*
|
|
304
|
+
* Measured on this machine's own store: 90% of entries were work/toolchain and
|
|
305
|
+
* project material, and a benchmark-driven push toward personal memory added
|
|
306
|
+
* nothing the user's real sessions needed.
|
|
307
|
+
*/
|
|
308
|
+
export declare const DEFAULT_RECORD_SCOPE: 'both';
|
|
286
309
|
/** Default idle hours a session must accumulate before it is mined. */
|
|
287
310
|
export declare const DEFAULT_MIN_IDLE_HOURS = 6;
|
|
288
311
|
/** Default age limit: sessions idle longer than this are never mined. */
|
|
@@ -385,6 +408,20 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
385
408
|
rawRecall: z<boolean, boolean, "volatile-defined">;
|
|
386
409
|
rawRecallBytes: z<number, number, "volatile-defined">;
|
|
387
410
|
rawRecallExcerpts: z<number, number, "volatile-defined">;
|
|
411
|
+
/**
|
|
412
|
+
* Read the raw channel across the whole history, not just the sessions the
|
|
413
|
+
* recalled memories came from.
|
|
414
|
+
*
|
|
415
|
+
* The anchored version only sees a conversation the extraction already picked
|
|
416
|
+
* a memory from, so anything the extraction dropped is unreachable. This one
|
|
417
|
+
* scores every persisted session's prose against the query — a real retrieval
|
|
418
|
+
* path, at the cost of opening more logs.
|
|
419
|
+
*/
|
|
420
|
+
ragRecall: z<boolean, boolean, "volatile-defined">;
|
|
421
|
+
ragRecallBytes: z<number, number, "volatile-defined">;
|
|
422
|
+
ragRecallExcerpts: z<number, number, "volatile-defined">;
|
|
423
|
+
ragRecallSessions: z<number, number, "volatile-defined">;
|
|
424
|
+
ragRecallChars: z<number, number, "volatile-defined">;
|
|
388
425
|
/** Shortest user turn worth a recall decision. */
|
|
389
426
|
recallMinQueryChars: z<number, number, "volatile-defined">;
|
|
390
427
|
/** Distinct strong-field terms a recall needs before it is credited. */
|
|
@@ -440,6 +477,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
440
477
|
extractTimeoutMs: z<number, number, "volatile-defined">;
|
|
441
478
|
/** Max drafts one extraction may produce. */
|
|
442
479
|
extractMaxMemories: z<number, number, "volatile-defined">;
|
|
480
|
+
recordScope: z<"both" | "work", "both" | "work", "volatile-defined">;
|
|
443
481
|
/** Minutes between periodic extraction checks over every open session. */
|
|
444
482
|
extractIntervalMinutes: z<number, number, "volatile-defined">;
|
|
445
483
|
/** A session must have been idle this long before it is mined. */
|
|
@@ -540,6 +578,20 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
540
578
|
rawRecall: z<boolean, boolean, "volatile-defined">;
|
|
541
579
|
rawRecallBytes: z<number, number, "volatile-defined">;
|
|
542
580
|
rawRecallExcerpts: z<number, number, "volatile-defined">;
|
|
581
|
+
/**
|
|
582
|
+
* Read the raw channel across the whole history, not just the sessions the
|
|
583
|
+
* recalled memories came from.
|
|
584
|
+
*
|
|
585
|
+
* The anchored version only sees a conversation the extraction already picked
|
|
586
|
+
* a memory from, so anything the extraction dropped is unreachable. This one
|
|
587
|
+
* scores every persisted session's prose against the query — a real retrieval
|
|
588
|
+
* path, at the cost of opening more logs.
|
|
589
|
+
*/
|
|
590
|
+
ragRecall: z<boolean, boolean, "volatile-defined">;
|
|
591
|
+
ragRecallBytes: z<number, number, "volatile-defined">;
|
|
592
|
+
ragRecallExcerpts: z<number, number, "volatile-defined">;
|
|
593
|
+
ragRecallSessions: z<number, number, "volatile-defined">;
|
|
594
|
+
ragRecallChars: z<number, number, "volatile-defined">;
|
|
543
595
|
/** Shortest user turn worth a recall decision. */
|
|
544
596
|
recallMinQueryChars: z<number, number, "volatile-defined">;
|
|
545
597
|
/** Distinct strong-field terms a recall needs before it is credited. */
|
|
@@ -595,6 +647,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
595
647
|
extractTimeoutMs: z<number, number, "volatile-defined">;
|
|
596
648
|
/** Max drafts one extraction may produce. */
|
|
597
649
|
extractMaxMemories: z<number, number, "volatile-defined">;
|
|
650
|
+
recordScope: z<"both" | "work", "both" | "work", "volatile-defined">;
|
|
598
651
|
/** Minutes between periodic extraction checks over every open session. */
|
|
599
652
|
extractIntervalMinutes: z<number, number, "volatile-defined">;
|
|
600
653
|
/** A session must have been idle this long before it is mined. */
|
|
@@ -680,6 +733,11 @@ export interface MemoriesSettings {
|
|
|
680
733
|
rawRecall: boolean;
|
|
681
734
|
rawRecallBytes: number;
|
|
682
735
|
rawRecallExcerpts: number;
|
|
736
|
+
ragRecall: boolean;
|
|
737
|
+
ragRecallBytes: number;
|
|
738
|
+
ragRecallExcerpts: number;
|
|
739
|
+
ragRecallSessions: number;
|
|
740
|
+
ragRecallChars: number;
|
|
683
741
|
recallMinQueryChars: number;
|
|
684
742
|
recallMinTerms: number;
|
|
685
743
|
/** Whether memories written after the summary are announced as a delta. */
|
|
@@ -704,6 +762,8 @@ export interface MemoriesSettings {
|
|
|
704
762
|
extractMaxOutputTokens: number;
|
|
705
763
|
extractTimeoutMs: number;
|
|
706
764
|
extractMaxMemories: number;
|
|
765
|
+
/** What the extractor may keep: `work` (default) or `both`. */
|
|
766
|
+
recordScope: 'work' | 'both';
|
|
707
767
|
extractIntervalMinutes: number;
|
|
708
768
|
minIdleHours: number;
|
|
709
769
|
maxAgeDays: number;
|
package/lib/types/extract.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface ExtractWindow {
|
|
|
21
21
|
readonly sources: readonly {
|
|
22
22
|
readonly seq: number;
|
|
23
23
|
readonly text: string;
|
|
24
|
+
readonly time?: number | undefined;
|
|
24
25
|
}[];
|
|
25
26
|
/**
|
|
26
27
|
* Unmined prose messages this window left out.
|
|
@@ -301,6 +302,38 @@ export declare function bindEvidence(drafts: readonly MemoryDraft[], sources: re
|
|
|
301
302
|
readonly seq: number;
|
|
302
303
|
readonly text: string;
|
|
303
304
|
}[]): EvidenceBinding;
|
|
305
|
+
/**
|
|
306
|
+
* Pick the turns an extractor is most likely to skip, as a must-cover list.
|
|
307
|
+
*
|
|
308
|
+
* The extractor sees the whole window and still drops material: measured on 50
|
|
309
|
+
* real sessions, the misses were new people, changed names, one-line agreements
|
|
310
|
+
* and interface traps — exactly the turns that score high here. Handing the list
|
|
311
|
+
* to the model turns "silently skipped" into "write it, or say why not".
|
|
312
|
+
*
|
|
313
|
+
* @param sources - the transcript lines, with their surface seq.
|
|
314
|
+
* @param max - how many candidates to return.
|
|
315
|
+
* @returns candidates, most salient first, each with a short snippet.
|
|
316
|
+
*/
|
|
317
|
+
export declare function mustCoverCandidates(sources: readonly {
|
|
318
|
+
readonly seq: number;
|
|
319
|
+
readonly text: string;
|
|
320
|
+
}[], max?: number): {
|
|
321
|
+
seq: number;
|
|
322
|
+
score: number;
|
|
323
|
+
snippet: string;
|
|
324
|
+
}[];
|
|
325
|
+
/**
|
|
326
|
+
* Render the must-cover list for the prompt, or undefined when nothing qualifies.
|
|
327
|
+
*
|
|
328
|
+
* @param candidates - from {@link mustCoverCandidates}.
|
|
329
|
+
* @returns the prompt lines, ready to append.
|
|
330
|
+
*/
|
|
331
|
+
export declare function renderMustCover(candidates: readonly {
|
|
332
|
+
readonly seq: number;
|
|
333
|
+
readonly score: number;
|
|
334
|
+
readonly snippet: string;
|
|
335
|
+
}[]): string | undefined;
|
|
336
|
+
export declare function resolveRelativeTimes(text: string, base: Date): string;
|
|
304
337
|
/** Everything one extraction call needs. */
|
|
305
338
|
export interface ExtractionRequest {
|
|
306
339
|
/** Session being mined. */
|
|
@@ -331,6 +364,14 @@ export interface ExtractionRequest {
|
|
|
331
364
|
readonly maxOutputTokens: number;
|
|
332
365
|
readonly maxMemories: number;
|
|
333
366
|
readonly timeoutMs: number;
|
|
367
|
+
/**
|
|
368
|
+
* What this pass may keep.
|
|
369
|
+
*
|
|
370
|
+
* `work` (the default) leaves personal life out of the store unless the user
|
|
371
|
+
* asked for it; `both` keeps personal background, relationships, habits and
|
|
372
|
+
* creative work too.
|
|
373
|
+
*/
|
|
374
|
+
readonly recordScope?: 'work' | 'both';
|
|
334
375
|
/** Cancellation. */
|
|
335
376
|
readonly signal: AbortSignal;
|
|
336
377
|
}
|
|
@@ -427,6 +468,19 @@ export type ExtractionOutcome = {
|
|
|
427
468
|
* @param request - session, window, route, and budget.
|
|
428
469
|
* @returns the parsed drafts, or a reason there are none.
|
|
429
470
|
*/
|
|
471
|
+
/**
|
|
472
|
+
* How many memories one pass should ask for, given the window size.
|
|
473
|
+
*
|
|
474
|
+
* The cap exists to keep a short session from padding itself, but a long session
|
|
475
|
+
* with 16 durable facts was being cut at 8 — measured on 50 real sessions, the
|
|
476
|
+
* misses concentrated in the biggest ones. Scale with the window, bounded so a
|
|
477
|
+
* short session is still asked for few.
|
|
478
|
+
*
|
|
479
|
+
* @param requested - the configured cap.
|
|
480
|
+
* @param messages - how many messages the window holds.
|
|
481
|
+
* @returns the cap to actually use.
|
|
482
|
+
*/
|
|
483
|
+
export declare function effectiveMaxMemories(requested: number, messages: number): number;
|
|
430
484
|
export declare function runExtraction(llm: LlmRuntime, request: ExtractionRequest): Promise<ExtractionOutcome>;
|
|
431
485
|
/**
|
|
432
486
|
* Close a JSON reply the output cap cut in half.
|
package/lib/types/index.d.ts
CHANGED
|
@@ -356,9 +356,20 @@ export declare class MemoriesRuntime {
|
|
|
356
356
|
* Apply every waiting decision.
|
|
357
357
|
*
|
|
358
358
|
* @param _parent - the agent asking; the stored rows carry their own scope.
|
|
359
|
-
* @returns
|
|
359
|
+
* @returns the command's report plus the counts the action-card decision
|
|
360
|
+
* records, or `undefined` when nothing is staged.
|
|
360
361
|
*/
|
|
361
|
-
applyPendingPlan(_parent: Agent): Promise<
|
|
362
|
+
applyPendingPlan(_parent: Agent): Promise<{
|
|
363
|
+
text: string;
|
|
364
|
+
written: number;
|
|
365
|
+
retired: number;
|
|
366
|
+
} | undefined>;
|
|
367
|
+
/**
|
|
368
|
+
* Discard every waiting decision, leaving the store untouched.
|
|
369
|
+
*
|
|
370
|
+
* @returns how many decisions were dropped, or `undefined` when nothing was staged.
|
|
371
|
+
*/
|
|
372
|
+
rejectPendingPlan(): Promise<number | undefined>;
|
|
362
373
|
/**
|
|
363
374
|
* A warning when this workspace's memory directory is shared with another
|
|
364
375
|
* repository of the same name.
|
|
@@ -516,6 +527,7 @@ export declare class MemoriesRuntime {
|
|
|
516
527
|
* @param query - the current user turn.
|
|
517
528
|
* @returns scrubbed excerpts, empty when disabled or unavailable.
|
|
518
529
|
*/
|
|
530
|
+
private ragExcerpts;
|
|
519
531
|
private rawExcerpts;
|
|
520
532
|
/**
|
|
521
533
|
* Extend the conversation's "already shown" record.
|
|
@@ -926,12 +938,17 @@ export declare class MemoriesRuntime {
|
|
|
926
938
|
/**
|
|
927
939
|
* Speak without being asked, when there is something to say.
|
|
928
940
|
*
|
|
929
|
-
* Two deterministic triggers
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
941
|
+
* Two deterministic triggers: a daily line about what the plugin maintained,
|
|
942
|
+
* and a promise whose deadline has passed. Both are judgements a rule can
|
|
943
|
+
* make, which is why they are the ones allowed to interrupt. Everything
|
|
944
|
+
* smarter (reflections) enters here later through the same queue, and the
|
|
945
|
+
* same rules apply: evidence or silence, and never the same subject twice.
|
|
946
|
+
*
|
|
947
|
+
* A staged consolidation proposal no longer comes through this pump: its
|
|
948
|
+
* backlog branch could not reach the user in this deployment (macOS
|
|
949
|
+
* `osascript` is unavailable, so every delivery logged `no channel for notice
|
|
950
|
+
* backlog`), and the answer card plus the injected draft note are the
|
|
951
|
+
* confirmation path now.
|
|
935
952
|
*
|
|
936
953
|
* Called from the once-per-conversation hook and from the maintenance sweep. A
|
|
937
954
|
* failure is logged and swallowed: speaking is never allowed to break a turn.
|
|
@@ -1243,6 +1260,11 @@ export declare const Config: import("@deepseek-ai/schemastery").default<Schemast
|
|
|
1243
1260
|
rawRecall: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
1244
1261
|
rawRecallBytes: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1245
1262
|
rawRecallExcerpts: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1263
|
+
ragRecall: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
1264
|
+
ragRecallBytes: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1265
|
+
ragRecallExcerpts: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1266
|
+
ragRecallSessions: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1267
|
+
ragRecallChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1246
1268
|
recallMinQueryChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1247
1269
|
recallMinTerms: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1248
1270
|
injectDelta: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
@@ -1261,6 +1283,7 @@ export declare const Config: import("@deepseek-ai/schemastery").default<Schemast
|
|
|
1261
1283
|
extractMaxOutputTokens: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1262
1284
|
extractTimeoutMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1263
1285
|
extractMaxMemories: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1286
|
+
recordScope: import("@deepseek-ai/schemastery").default<"both" | "work", "both" | "work", "volatile-defined">;
|
|
1264
1287
|
extractIntervalMinutes: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1265
1288
|
minIdleHours: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1266
1289
|
maxAgeDays: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
@@ -1313,6 +1336,11 @@ export declare const Config: import("@deepseek-ai/schemastery").default<Schemast
|
|
|
1313
1336
|
rawRecall: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
1314
1337
|
rawRecallBytes: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1315
1338
|
rawRecallExcerpts: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1339
|
+
ragRecall: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
1340
|
+
ragRecallBytes: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1341
|
+
ragRecallExcerpts: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1342
|
+
ragRecallSessions: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1343
|
+
ragRecallChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1316
1344
|
recallMinQueryChars: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1317
1345
|
recallMinTerms: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1318
1346
|
injectDelta: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
|
|
@@ -1331,6 +1359,7 @@ export declare const Config: import("@deepseek-ai/schemastery").default<Schemast
|
|
|
1331
1359
|
extractMaxOutputTokens: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1332
1360
|
extractTimeoutMs: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1333
1361
|
extractMaxMemories: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1362
|
+
recordScope: import("@deepseek-ai/schemastery").default<"both" | "work", "both" | "work", "volatile-defined">;
|
|
1334
1363
|
extractIntervalMinutes: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1335
1364
|
minIdleHours: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
1336
1365
|
maxAgeDays: import("@deepseek-ai/schemastery").default<number, number, "volatile-defined">;
|
|
@@ -76,6 +76,34 @@ export declare function readTranscript(sessionsDir: string, sessionId: string, n
|
|
|
76
76
|
* @param limits - count/character/byte caps (byte cap applies across sessions).
|
|
77
77
|
* @returns excerpts with their session id filled in.
|
|
78
78
|
*/
|
|
79
|
+
/**
|
|
80
|
+
* Full-history RAG selection.
|
|
81
|
+
*
|
|
82
|
+
* `collectExcerpts` only reads the sessions a recalled memory came from, so it
|
|
83
|
+
* is anchored to the extraction. This one reads EVERY persisted session on this
|
|
84
|
+
* machine and picks the excerpts that lexically match the query best, which is
|
|
85
|
+
* what makes the raw channel a real retrieval path rather than a footnote.
|
|
86
|
+
*
|
|
87
|
+
* Zero model calls: the same tokenizer and scorer as `selectExcerpts`, so the
|
|
88
|
+
* cost is reading the logs (cached) and the text it injects.
|
|
89
|
+
*
|
|
90
|
+
* @param sessionsDir - `<dshHome>/sessions`.
|
|
91
|
+
* @param query - the current user turn.
|
|
92
|
+
* @param limits - same knobs as `selectExcerpts`, plus `maxSessions` to bound the
|
|
93
|
+
* number of logs opened.
|
|
94
|
+
* @returns the best matching excerpts across all sessions, empty when none match.
|
|
95
|
+
*/
|
|
96
|
+
export declare function collectRagExcerpts(sessionsDir: string, query: string, limits?: RawRecallLimits & {
|
|
97
|
+
readonly maxSessions?: number;
|
|
98
|
+
readonly excludeSessionId?: string;
|
|
99
|
+
}): Promise<RawExcerpt[]>;
|
|
100
|
+
/** One user turn and the assistant turns that answered it. */
|
|
101
|
+
export interface TurnChunk {
|
|
102
|
+
readonly seq: number;
|
|
103
|
+
readonly text: string;
|
|
104
|
+
}
|
|
105
|
+
/** Group a transcript into user→assistant turns, dropping turns with no prose. */
|
|
106
|
+
export declare function turnChunks(messages: readonly BackfillMessage[]): TurnChunk[];
|
|
79
107
|
export declare function collectExcerpts(sessionsDir: string, sources: readonly {
|
|
80
108
|
readonly sessionId: string;
|
|
81
109
|
readonly quote?: string;
|
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,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.9",
|
|
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
|
}
|