dsh-cross-memory 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +253 -2
  3. package/cordis.patch.yml +27 -0
  4. package/docs/DETAIL.md +13 -0
  5. package/docs/DETAIL.zh.md +17 -0
  6. package/icon.svg +1 -0
  7. package/lib/backfill.js +273 -0
  8. package/lib/citations.js +305 -0
  9. package/lib/client.js +1660 -0
  10. package/lib/config.js +736 -0
  11. package/lib/consolidate.js +1119 -0
  12. package/lib/extract.js +570 -0
  13. package/lib/gate.js +137 -0
  14. package/lib/git-origin.js +224 -0
  15. package/lib/index.js +4482 -0
  16. package/lib/log.js +260 -0
  17. package/lib/loops.js +186 -0
  18. package/lib/notices.js +195 -0
  19. package/lib/notify.js +33 -0
  20. package/lib/persona.js +163 -0
  21. package/lib/query.js +93 -0
  22. package/lib/raw-recall.js +286 -0
  23. package/lib/reflection.js +291 -0
  24. package/lib/remote.js +490 -0
  25. package/lib/render.js +678 -0
  26. package/lib/retention.js +64 -0
  27. package/lib/schedule.js +245 -0
  28. package/lib/search.js +1068 -0
  29. package/lib/skills.js +220 -0
  30. package/lib/state.js +701 -0
  31. package/lib/storage.js +1424 -0
  32. package/lib/sync-runtime.js +268 -0
  33. package/lib/sync.js +620 -0
  34. package/lib/test/activity.test.js +74 -0
  35. package/lib/test/archive.test.js +182 -0
  36. package/lib/test/backfill.test.js +144 -0
  37. package/lib/test/citations.test.js +91 -0
  38. package/lib/test/client-wiring.test.js +134 -0
  39. package/lib/test/consolidate-job.test.js +95 -0
  40. package/lib/test/consolidate.test.js +430 -0
  41. package/lib/test/consolidation-selection.test.js +152 -0
  42. package/lib/test/dedupe-keys.test.js +230 -0
  43. package/lib/test/delta.test.js +93 -0
  44. package/lib/test/derived.test.js +110 -0
  45. package/lib/test/disputes-panel.test.js +341 -0
  46. package/lib/test/eval.test.js +171 -0
  47. package/lib/test/expand.test.js +164 -0
  48. package/lib/test/extract.test.js +1020 -0
  49. package/lib/test/git-origin.test.js +189 -0
  50. package/lib/test/injection.test.js +440 -0
  51. package/lib/test/kind-filter.test.js +49 -0
  52. package/lib/test/legacy-state.test.js +69 -0
  53. package/lib/test/log.test.js +156 -0
  54. package/lib/test/loops.test.js +86 -0
  55. package/lib/test/memory.test.js +855 -0
  56. package/lib/test/notices.test.js +142 -0
  57. package/lib/test/persona.test.js +86 -0
  58. package/lib/test/prefilter.test.js +73 -0
  59. package/lib/test/preset.test.js +77 -0
  60. package/lib/test/raw-recall.test.js +186 -0
  61. package/lib/test/recall.test.js +433 -0
  62. package/lib/test/reflection.test.js +64 -0
  63. package/lib/test/remote.test.js +238 -0
  64. package/lib/test/retention.test.js +117 -0
  65. package/lib/test/retrieval.test.js +142 -0
  66. package/lib/test/rotation.test.js +228 -0
  67. package/lib/test/schedule.test.js +112 -0
  68. package/lib/test/settings-card.test.js +58 -0
  69. package/lib/test/skills.test.js +129 -0
  70. package/lib/test/state.test.js +212 -0
  71. package/lib/test/subagent-contract.test.js +139 -0
  72. package/lib/test/sweep.test.js +159 -0
  73. package/lib/test/sync.test.js +314 -0
  74. package/lib/test/time.test.js +171 -0
  75. package/lib/time.js +303 -0
  76. package/lib/tool.js +330 -0
  77. package/lib/types/backfill.d.ts +96 -0
  78. package/lib/types/citations.d.ts +105 -0
  79. package/lib/types/config.d.ts +811 -0
  80. package/lib/types/consolidate.d.ts +742 -0
  81. package/lib/types/extract.d.ts +352 -0
  82. package/lib/types/gate.d.ts +83 -0
  83. package/lib/types/git-origin.d.ts +23 -0
  84. package/lib/types/index.d.ts +1316 -0
  85. package/lib/types/log.d.ts +144 -0
  86. package/lib/types/loops.d.ts +82 -0
  87. package/lib/types/notices.d.ts +117 -0
  88. package/lib/types/notify.d.ts +12 -0
  89. package/lib/types/persona.d.ts +76 -0
  90. package/lib/types/query.d.ts +45 -0
  91. package/lib/types/raw-recall.d.ts +84 -0
  92. package/lib/types/reflection.d.ts +122 -0
  93. package/lib/types/remote.d.ts +246 -0
  94. package/lib/types/render.d.ts +286 -0
  95. package/lib/types/retention.d.ts +66 -0
  96. package/lib/types/schedule.d.ts +116 -0
  97. package/lib/types/search.d.ts +583 -0
  98. package/lib/types/skills.d.ts +71 -0
  99. package/lib/types/state.d.ts +294 -0
  100. package/lib/types/storage.d.ts +458 -0
  101. package/lib/types/sync-runtime.d.ts +103 -0
  102. package/lib/types/sync.d.ts +222 -0
  103. package/lib/types/test/activity.test.d.ts +1 -0
  104. package/lib/types/test/archive.test.d.ts +1 -0
  105. package/lib/types/test/backfill.test.d.ts +1 -0
  106. package/lib/types/test/citations.test.d.ts +1 -0
  107. package/lib/types/test/client-wiring.test.d.ts +1 -0
  108. package/lib/types/test/consolidate-job.test.d.ts +1 -0
  109. package/lib/types/test/consolidate.test.d.ts +1 -0
  110. package/lib/types/test/consolidation-selection.test.d.ts +1 -0
  111. package/lib/types/test/dedupe-keys.test.d.ts +1 -0
  112. package/lib/types/test/delta.test.d.ts +1 -0
  113. package/lib/types/test/derived.test.d.ts +1 -0
  114. package/lib/types/test/disputes-panel.test.d.ts +1 -0
  115. package/lib/types/test/eval.test.d.ts +1 -0
  116. package/lib/types/test/expand.test.d.ts +1 -0
  117. package/lib/types/test/extract.test.d.ts +1 -0
  118. package/lib/types/test/git-origin.test.d.ts +1 -0
  119. package/lib/types/test/injection.test.d.ts +1 -0
  120. package/lib/types/test/kind-filter.test.d.ts +1 -0
  121. package/lib/types/test/legacy-state.test.d.ts +1 -0
  122. package/lib/types/test/log.test.d.ts +1 -0
  123. package/lib/types/test/loops.test.d.ts +1 -0
  124. package/lib/types/test/memory.test.d.ts +1 -0
  125. package/lib/types/test/notices.test.d.ts +1 -0
  126. package/lib/types/test/persona.test.d.ts +1 -0
  127. package/lib/types/test/prefilter.test.d.ts +1 -0
  128. package/lib/types/test/preset.test.d.ts +1 -0
  129. package/lib/types/test/raw-recall.test.d.ts +1 -0
  130. package/lib/types/test/recall.test.d.ts +1 -0
  131. package/lib/types/test/reflection.test.d.ts +1 -0
  132. package/lib/types/test/remote.test.d.ts +1 -0
  133. package/lib/types/test/retention.test.d.ts +1 -0
  134. package/lib/types/test/retrieval.test.d.ts +1 -0
  135. package/lib/types/test/rotation.test.d.ts +1 -0
  136. package/lib/types/test/schedule.test.d.ts +1 -0
  137. package/lib/types/test/settings-card.test.d.ts +1 -0
  138. package/lib/types/test/skills.test.d.ts +1 -0
  139. package/lib/types/test/state.test.d.ts +1 -0
  140. package/lib/types/test/subagent-contract.test.d.ts +1 -0
  141. package/lib/types/test/sweep.test.d.ts +1 -0
  142. package/lib/types/test/sync.test.d.ts +1 -0
  143. package/lib/types/test/time.test.d.ts +1 -0
  144. package/lib/types/time.d.ts +67 -0
  145. package/lib/types/tool.d.ts +9 -0
  146. package/lib/types/types.d.ts +374 -0
  147. package/lib/types/workspace.d.ts +20 -0
  148. package/lib/types.js +47 -0
  149. package/lib/workspace.js +65 -0
  150. package/locale/en.json +7 -0
  151. package/locale/zh.json +7 -0
  152. package/package.json +126 -4
@@ -0,0 +1,374 @@
1
+ /**
2
+ * Shared memory vocabulary for `dsh-cross-memory`.
3
+ *
4
+ * Two scopes exist, mirroring the Codex memories split:
5
+ * `global` remembers facts that hold across every project (how the user likes to
6
+ * work, durable preferences, machine/tooling facts), while `project` remembers
7
+ * facts tied to one workspace (architecture decisions, build commands, gotchas)
8
+ * and is shared by every session opened in that workspace.
9
+ *
10
+ * @module dsh-cross-memory/types
11
+ */
12
+ import type { ContextFormed } from '@deepseek-ai/dsh-llm';
13
+ /**
14
+ * Since 0.2.2-rc.1 `GenerateOptions.purpose` is `LlmRequestPurpose`, derived
15
+ * from `LlmRequestPurposeMap`, which the kernel ships empty for producer
16
+ * packages to augment (its own `dsh-compaction-basic` passes the runtime string
17
+ * from plain JS). Memory's auxiliary calls have been tagged `'compaction'`
18
+ * since 0.1.x — the DeepSeek adapter maps that to
19
+ * `x-deepseek-harness-compact: 1` — so declare the key here rather than drop
20
+ * the tag the requests have always carried.
21
+ */
22
+ declare module '@deepseek-ai/dsh-llm' {
23
+ interface LlmRequestPurposeMap {
24
+ compaction: true;
25
+ }
26
+ }
27
+ /** A memory scope: cross-project (`global`) or workspace-bound (`project`). */
28
+ export type MemoryScope = 'global' | 'project';
29
+ /**
30
+ * Who produced the content this plugin injects into a conversation.
31
+ *
32
+ * `MessageSource.kind` answers *who*, and durable session format v4 admits only
33
+ * a producer-owned kind: the retired `{ kind: 'plugin', plugin: … }` wrapper is
34
+ * refused outright on write (`format v4 message requires a producer-owned
35
+ * source kind`), which is what made every injection fail on 0.1.7. The platform's
36
+ * own v3→v4 migration derives exactly this spelling from that wrapper, so older
37
+ * logs and new writes carry the same kind — which is what lets a session resumed
38
+ * from an older log still recognise the block it already has.
39
+ *
40
+ * Spelled out rather than derived from the plugin name because the name lives in
41
+ * the plugin entry, which imports this module; a test holds the two together.
42
+ */
43
+ export declare const MEMORY_SOURCE_KIND = "plugin:memories";
44
+ /** Every valid scope, in injection order (broadest first). */
45
+ export declare const MEMORY_SCOPES: readonly MemoryScope[];
46
+ /**
47
+ * One durable memory entry.
48
+ *
49
+ * `id` is stable and derived from the title, so re-writing the same lesson
50
+ * updates the existing entry instead of growing the store.
51
+ */
52
+ export interface MemoryEntry {
53
+ /** Stable slug id, unique within its scope directory. */
54
+ readonly id: string;
55
+ /** Owning scope. */
56
+ readonly scope: MemoryScope;
57
+ /** What kind of thing this memory is; drives summary grouping and recall order. */
58
+ readonly kind: MemoryKind;
59
+ /** Short imperative heading shown in the injected summary. */
60
+ readonly title: string;
61
+ /** The remembered fact, 1-4 sentences. */
62
+ readonly body: string;
63
+ /** Lowercase keyword tags used by search ranking. */
64
+ readonly tags: readonly string[];
65
+ /** Whose words this memory preserves; see {@link MemoryVoice}. */
66
+ readonly voice?: MemoryVoice;
67
+ /**
68
+ * Extra search keys: aliases and keyphrases that should also find this
69
+ * memory.
70
+ *
71
+ * This is the cheap half of what the literature calls key expansion — a
72
+ * memory about "pnpm workspaces" should be found by "monorepo" too — and it
73
+ * buys most of the recall a vector index would, without an index.
74
+ */
75
+ readonly keys: readonly string[];
76
+ /** When this memory is worth recalling, in the author's words. */
77
+ readonly appliesTo?: string;
78
+ /**
79
+ * How long the memory stays true.
80
+ *
81
+ * `durable` (the default) is a fact that does not move: a convention, a
82
+ * command, a design constraint. `snapshot` is a reading taken at one moment —
83
+ * a count, a pass rate, a state of the world — and is rendered with the date it
84
+ * was taken and archived once it is old enough, because a stale number is worse
85
+ * than no number: measured on a real store, 43% of entries carried one.
86
+ */
87
+ readonly durability?: MemoryDurability;
88
+ /** When a `snapshot` was measured; ignored for `durable`. */
89
+ readonly asOf?: number;
90
+ /**
91
+ * Never retire this memory on its own.
92
+ *
93
+ * Deliberately separate from `pinned`: a pin answers "show this in every
94
+ * session", which costs one of the summary's few slots, while permanence
95
+ * answers "do not lose this", which costs nothing. Fusing the two meant a rule
96
+ * could only be safe by also being always-injected — and three such rules were
97
+ * enough to squeeze the global summary down to one free slot.
98
+ *
99
+ * Permanent entries are skipped by retention, by the per-scope cap, and by
100
+ * unattended consolidation (a plan that would rewrite or retire one becomes a
101
+ * question for a person instead). Only `/memories forget` removes one, and the
102
+ * title-identity rule still lets the same title be rewritten in place — which
103
+ * is how a changed mind is meant to be expressed.
104
+ */
105
+ readonly permanent?: boolean;
106
+ /**
107
+ * Keep this memory in the injected summary whenever it fits.
108
+ *
109
+ * The summary lists a handful of entries out of hundreds, so which ones appear
110
+ * is normally the ranking's decision. A pin is the user's decision instead: it
111
+ * is chosen before the fresh slots and before the ranking. Pins compete with
112
+ * each other only, so a scope cannot be flooded by them.
113
+ */
114
+ readonly pinned?: boolean;
115
+ /** Id of the memory this one replaces, when it supersedes one. */
116
+ readonly supersedes?: string;
117
+ /**
118
+ * Session this memory was learned in.
119
+ *
120
+ * The evidence behind a memory: `memories/sessions/<id>.md` records what that
121
+ * conversation was about, which is what a reader needs when a memory's wording
122
+ * or chronology could change the answer. Codex keeps the same pointer as a
123
+ * rollout summary its read path can open.
124
+ */
125
+ readonly sourceSession?: string;
126
+ /**
127
+ * Verbatim excerpt of the transcript message this memory was extracted from.
128
+ *
129
+ * `sourceSession` says which conversation a memory came from, but not what in
130
+ * that conversation supports it: a session note is the model's own summary, so
131
+ * a memory could paraphrase, misattribute or invent a detail and still point at
132
+ * a real note. `quote` is copied from the transcript and checked as a substring
133
+ * before the entry is written, so a memory whose wording the source does not
134
+ * actually support cannot claim one. Deliberately absent on entries a person
135
+ * wrote with the tool (there is no transcript to quote) and cleared when a
136
+ * rewrite changes the body, because the old excerpt no longer supports the new
137
+ * claim.
138
+ */
139
+ readonly quote?: string;
140
+ /** Surface seq of the message `quote` was copied from; see {@link MemoryEntry.quote}. */
141
+ readonly evidenceSeq?: number;
142
+ /**
143
+ * Ids of the memories this one was built from, when it was merged from others.
144
+ *
145
+ * The answer to "why does it say that": `sourceSession` names the conversation
146
+ * a memory was learned in, this names the *entries* a consolidation folded
147
+ * into it. Without it a merge is a one-way door — the sources are archived and
148
+ * the surviving entry gives no sign that three memories became one, so the
149
+ * claim it now makes cannot be checked against what it replaced. Only ids the
150
+ * store could still resolve at write time are kept.
151
+ */
152
+ readonly derivedFrom?: readonly string[];
153
+ /** Unix epoch milliseconds when the entry was first written. */
154
+ readonly createdAt: number;
155
+ /** Unix epoch milliseconds of the most recent write. */
156
+ readonly updatedAt: number;
157
+ /** How many times the entry was read or returned by search. */
158
+ readonly uses: number;
159
+ /** Unix epoch milliseconds of the last read/search hit, or 0 when never used. */
160
+ readonly lastUsedAt: number;
161
+ /** Unix epoch milliseconds the entry was last listed in an injected block, or 0. */
162
+ readonly lastSurfacedAt: number;
163
+ /** How the entry entered the store. */
164
+ readonly source: MemorySource;
165
+ }
166
+ /**
167
+ * What kind of memory one entry is.
168
+ *
169
+ * The split follows Codex's `MEMORY.md` sections, which exist because the four
170
+ * kinds are recalled differently: a preference applies whenever the situation
171
+ * matches, a failure applies when the same mistake is about to be repeated, a
172
+ * procedure is executed, and a plain fact is just background. Grouping them in
173
+ * the injected summary lets the model see the actionable ones first.
174
+ */
175
+ export type MemoryKind =
176
+ /** Durable background: how something works, what a system contains. */
177
+ 'fact'
178
+ /** How the user wants work done, or a correction they issued. */
179
+ | 'preference'
180
+ /** A non-obvious technique worth reusing. */
181
+ | 'knowledge'
182
+ /** Something that went wrong and how to avoid repeating it. */
183
+ | 'failure'
184
+ /** An ordered recipe for a recurring task. */
185
+ | 'procedure';
186
+ /** Every kind, in summary render order (actionable first). */
187
+ export declare const MEMORY_KINDS: readonly MemoryKind[];
188
+ /**
189
+ * Whose words a memory is built from.
190
+ *
191
+ * The store used to record only what the assistant concluded, which makes every
192
+ * memory sound like the agent's opinion: on a real store that read as 163 `auto`
193
+ * and 37 `tool` entries and ZERO that preserved something the user actually said.
194
+ * A profile of the person cannot be rebuilt from the assistant's summary of them,
195
+ * so the extractor now marks the entries that quote or rephrase the user's own
196
+ * statements about how they work — and only those.
197
+ *
198
+ * `voice` is NOT a durability flag: it ranks and it feeds the profile, while
199
+ * retention and adjudication keep reading `source`/`pinned`/`permanent`.
200
+ */
201
+ export type MemoryVoice =
202
+ /** The user's own words: a preference, a correction, a way of working. */
203
+ 'user'
204
+ /** The assistant's own conclusion or observation. */
205
+ | 'assistant';
206
+ /**
207
+ * How long a memory stays true.
208
+ *
209
+ * The distinction exists because a number that was correct when written is the
210
+ * most dangerous kind of memory: it is specific, it is checkable, and it goes
211
+ * wrong on its own. A `snapshot` therefore carries the date it was measured and
212
+ * expires, instead of being repeated forever as though it were a rule.
213
+ */
214
+ export type MemoryDurability =
215
+ /** A fact that does not move: a convention, a command, a constraint. */
216
+ 'durable'
217
+ /** A reading taken at one moment: a count, a pass rate, a current state. */
218
+ | 'snapshot';
219
+ /** Every durability value, for validation at the storage seam. */
220
+ export declare const MEMORY_DURABILITIES: readonly MemoryDurability[];
221
+ /**
222
+ * Normalize a raw durability value.
223
+ *
224
+ * An absent value is `durable`, so every memory written before this field
225
+ * existed keeps its old meaning without a migration.
226
+ *
227
+ * @param value - the raw text, or `undefined`.
228
+ * @returns the durability.
229
+ */
230
+ export declare function toMemoryDurability(value: string | undefined): MemoryDurability;
231
+ /** Heading text for each kind in the injected summary. */
232
+ export declare const MEMORY_KIND_HEADINGS: Record<MemoryKind, string>;
233
+ /** Narrow an unknown value to a kind, defaulting to `fact`. */
234
+ export declare function toMemoryKind(value: unknown): MemoryKind;
235
+ /** Provenance of one entry. */
236
+ export type MemorySource =
237
+ /** Written by the model through the `memory` tool. */
238
+ 'tool'
239
+ /** Written by the user through a `/memories` command. */
240
+ | 'user'
241
+ /** Produced by the idle-time background extractor. */
242
+ | 'auto'
243
+ /** Written by the plugin itself (e.g. a scope migration). */
244
+ | 'system';
245
+ /** One scope plus the resolved store directories for it. */
246
+ export interface ScopeTarget {
247
+ /** The scope this target addresses. */
248
+ readonly scope: MemoryScope;
249
+ /** Absolute directory holding this scope's entry files and `index.json`. */
250
+ readonly dir: string;
251
+ /** Model-facing label for the scope, e.g. `global` or `project:dsh-cross-memory`. */
252
+ readonly label: string;
253
+ }
254
+ /** A candidate memory as proposed by the model or the extractor, before persistence. */
255
+ export interface MemoryDraft {
256
+ /** Target scope. */
257
+ readonly scope: MemoryScope;
258
+ /** Short imperative heading. */
259
+ readonly title: string;
260
+ /** The remembered fact. */
261
+ readonly body: string;
262
+ /** Optional keyword tags. */
263
+ readonly tags: readonly string[];
264
+ /** Whose words this draft preserves; see {@link MemoryVoice}. */
265
+ readonly voice?: MemoryVoice;
266
+ /** What kind of memory this is; defaults to `fact`. */
267
+ readonly kind?: MemoryKind;
268
+ /** When this memory is worth recalling. */
269
+ readonly appliesTo?: string;
270
+ /** How long the memory stays true; see {@link MemoryEntry.durability}. */
271
+ readonly durability?: MemoryDurability;
272
+ /** When a `snapshot` was measured. */
273
+ readonly asOf?: number;
274
+ /** Whether the injected summary must list this memory whenever it fits. */
275
+ readonly pinned?: boolean;
276
+ /** Whether this memory is kept until a person decides otherwise; see {@link MemoryEntry.permanent}. */
277
+ readonly permanent?: boolean;
278
+ /** Id of a memory this one replaces. */
279
+ readonly supersedes?: string;
280
+ /** Session the draft came from, recorded as {@link MemoryEntry.sourceSession}. */
281
+ readonly sourceSession?: string;
282
+ /**
283
+ * Verbatim excerpt the extractor copied from the transcript, recorded as
284
+ * {@link MemoryEntry.quote}. Only the extraction path produces it; a rewrite
285
+ * that changes the body drops it.
286
+ */
287
+ readonly quote?: string;
288
+ /** Surface seq of the message `quote` was copied from; filled by the extractor. */
289
+ readonly evidenceSeq?: number;
290
+ /** Entries this draft was merged from, recorded as {@link MemoryEntry.derivedFrom}. */
291
+ readonly derivedFrom?: readonly string[];
292
+ /** Extra search keys (aliases, keyphrases) that should also find this memory. */
293
+ readonly keys?: readonly string[];
294
+ }
295
+ /** The outcome of persisting one draft. */
296
+ export interface UpsertResult {
297
+ /** The stored entry. */
298
+ readonly entry: MemoryEntry;
299
+ /** `created` for a new entry, `updated` when an existing id was replaced. */
300
+ readonly action: 'created' | 'updated';
301
+ }
302
+ /**
303
+ * Per-session memory switch.
304
+ *
305
+ * `off` suspends injection and extraction for one session without touching the
306
+ * workspace it runs in: a repository full of credentials can be worked in
307
+ * without turning memory off everywhere.
308
+ */
309
+ export type SessionMode = 'on' | 'off';
310
+ /**
311
+ * What one memory's usage says about whether it still earns its place.
312
+ *
313
+ * These counters live in the state database rather than in the entry file,
314
+ * because every session in the process updates them concurrently; `surfacedAt`
315
+ * is the weaker signal that keeps a memory good enough to be read straight out
316
+ * of the injected summary from looking unused.
317
+ */
318
+ export interface RetentionRow {
319
+ /** Owning scope. */
320
+ readonly scope: string;
321
+ /** Entry id within that scope. */
322
+ readonly id: string;
323
+ /** How many times the entry was read or returned by search. */
324
+ readonly uses: number;
325
+ /** Unix epoch milliseconds of the last read/search hit, or 0. */
326
+ readonly lastUsedAt: number;
327
+ /** Unix epoch milliseconds the entry was last listed in an injected block, or 0. */
328
+ readonly surfacedAt: number;
329
+ /** Unix epoch milliseconds a consolidation pass last reviewed it, or 0. */
330
+ readonly consolidatedAt: number;
331
+ }
332
+ /** One ranked search hit. */
333
+ export interface MemoryHit {
334
+ /** The matching entry. */
335
+ readonly entry: MemoryEntry;
336
+ /** Relevance score; higher is better. */
337
+ readonly score: number;
338
+ /**
339
+ * The entry this one was reached from, when it did not match the query itself.
340
+ *
341
+ * Set only by the one-hop expansion: the hit shares the seed's `keys`/`tags`
342
+ * rather than its words. Renderers say so out loud, because a result the query
343
+ * does not match must never be presented as one that does.
344
+ */
345
+ readonly via?: string;
346
+ /**
347
+ * The lexical half of the number: how well the words match, before the
348
+ * attention model.
349
+ *
350
+ * `score` is the other half — relevance weighted by importance and recency —
351
+ * and the two surfaces order by different halves on purpose: a search answers
352
+ * a question and ranks by this one, the injector volunteers memories nobody
353
+ * asked for and ranks by `score`. Set by `searchMemories`; absent on hits from
354
+ * `browseMemories`, where the query is empty and neither number means anything.
355
+ */
356
+ readonly relevance?: number;
357
+ }
358
+ /** The source this plugin stamps on every message it injects. */
359
+ export type MemoryMessageSource = {
360
+ kind: typeof MEMORY_SOURCE_KIND;
361
+ } & ContextFormed;
362
+ /**
363
+ * Add this plugin's producer kind to the shared source vocabulary.
364
+ *
365
+ * The augmentation names `@deepseek-ai/dsh-llm/message` — the module that
366
+ * declares the map — rather than the package root, which only re-exports it: a
367
+ * re-export carries the type but not the merge point.
368
+ */
369
+ declare module '@deepseek-ai/dsh-llm/message' {
370
+ interface MessageSourceMap {
371
+ /** Injected memory context: the summary block or an on-demand recall delta. */
372
+ memories: MemoryMessageSource;
373
+ }
374
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Whether one path is another, or lives underneath it.
3
+ *
4
+ * Case-insensitive on Windows, because two spellings of one directory are one
5
+ * directory there and the comparison decides whether a directory counts as the
6
+ * harness home.
7
+ *
8
+ * @param parent - the containing directory.
9
+ * @param path - the path to test.
10
+ * @returns true when `path` is `parent` or inside it.
11
+ */
12
+ export declare function isWithin(parent: string, path: string): boolean;
13
+ /**
14
+ * Walk upward from `cwd` to the first directory containing a configured root
15
+ * marker, so every session opened in a subdirectory shares one project scope.
16
+ * @param cwd - absolute session working directory.
17
+ * @param markers - child names that identify a workspace root.
18
+ * @returns the discovered root, or the resolved `cwd` when no marker exists.
19
+ */
20
+ export declare function findProjectRoot(cwd: string, markers: readonly string[]): Promise<string>;
package/lib/types.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Who produced the content this plugin injects into a conversation.
3
+ *
4
+ * `MessageSource.kind` answers *who*, and durable session format v4 admits only
5
+ * a producer-owned kind: the retired `{ kind: 'plugin', plugin: … }` wrapper is
6
+ * refused outright on write (`format v4 message requires a producer-owned
7
+ * source kind`), which is what made every injection fail on 0.1.7. The platform's
8
+ * own v3→v4 migration derives exactly this spelling from that wrapper, so older
9
+ * logs and new writes carry the same kind — which is what lets a session resumed
10
+ * from an older log still recognise the block it already has.
11
+ *
12
+ * Spelled out rather than derived from the plugin name because the name lives in
13
+ * the plugin entry, which imports this module; a test holds the two together.
14
+ */
15
+ export const MEMORY_SOURCE_KIND = 'plugin:memories';
16
+ /** Every valid scope, in injection order (broadest first). */
17
+ export const MEMORY_SCOPES = ['global', 'project'];
18
+ /** Every kind, in summary render order (actionable first). */
19
+ export const MEMORY_KINDS = ['preference', 'failure', 'procedure', 'knowledge', 'fact'];
20
+ /** Every durability value, for validation at the storage seam. */
21
+ export const MEMORY_DURABILITIES = ['durable', 'snapshot'];
22
+ /**
23
+ * Normalize a raw durability value.
24
+ *
25
+ * An absent value is `durable`, so every memory written before this field
26
+ * existed keeps its old meaning without a migration.
27
+ *
28
+ * @param value - the raw text, or `undefined`.
29
+ * @returns the durability.
30
+ */
31
+ export function toMemoryDurability(value) {
32
+ return value === 'snapshot' ? 'snapshot' : 'durable';
33
+ }
34
+ /** Heading text for each kind in the injected summary. */
35
+ export const MEMORY_KIND_HEADINGS = {
36
+ preference: 'Preferences',
37
+ failure: 'Failures to avoid',
38
+ procedure: 'Procedures',
39
+ knowledge: 'Reusable knowledge',
40
+ fact: 'Facts',
41
+ };
42
+ /** Narrow an unknown value to a kind, defaulting to `fact`. */
43
+ export function toMemoryKind(value) {
44
+ return value === 'preference' || value === 'failure' || value === 'procedure' || value === 'knowledge'
45
+ ? value
46
+ : 'fact';
47
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Workspace root discovery, shared by the project scope and the injector.
3
+ *
4
+ * @module dsh-cross-memory/workspace
5
+ */
6
+ import { dirname, resolve, sep } from 'node:path';
7
+ import { stat } from 'node:fs/promises';
8
+ /**
9
+ * Whether one path is another, or lives underneath it.
10
+ *
11
+ * Case-insensitive on Windows, because two spellings of one directory are one
12
+ * directory there and the comparison decides whether a directory counts as the
13
+ * harness home.
14
+ *
15
+ * @param parent - the containing directory.
16
+ * @param path - the path to test.
17
+ * @returns true when `path` is `parent` or inside it.
18
+ */
19
+ export function isWithin(parent, path) {
20
+ const base = resolve(parent);
21
+ const target = resolve(path);
22
+ if (target === base)
23
+ return true;
24
+ const prefix = base.endsWith(sep) ? base : `${base}${sep}`;
25
+ return process.platform === 'win32'
26
+ ? target.toLowerCase().startsWith(prefix.toLowerCase())
27
+ : target.startsWith(prefix);
28
+ }
29
+ /** Whether a filesystem error means "absent". */
30
+ function isMissing(error) {
31
+ return typeof error === 'object' && error !== null && 'code' in error
32
+ && (error.code === 'ENOENT' || error.code === 'ENOTDIR');
33
+ }
34
+ /** Whether one path exists, whatever its type. */
35
+ async function exists(path) {
36
+ try {
37
+ await stat(path);
38
+ return true;
39
+ }
40
+ catch (error) {
41
+ if (isMissing(error))
42
+ return false;
43
+ return false;
44
+ }
45
+ }
46
+ /**
47
+ * Walk upward from `cwd` to the first directory containing a configured root
48
+ * marker, so every session opened in a subdirectory shares one project scope.
49
+ * @param cwd - absolute session working directory.
50
+ * @param markers - child names that identify a workspace root.
51
+ * @returns the discovered root, or the resolved `cwd` when no marker exists.
52
+ */
53
+ export async function findProjectRoot(cwd, markers) {
54
+ let current = resolve(cwd);
55
+ for (;;) {
56
+ for (const marker of markers) {
57
+ if (await exists(resolve(current, marker)))
58
+ return current;
59
+ }
60
+ const parent = dirname(current);
61
+ if (parent === current)
62
+ return resolve(cwd);
63
+ current = parent;
64
+ }
65
+ }
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Cross-memory",
4
+ "description": "Keeps durable preferences, decisions and pitfalls as a memory library injected and recalled in later sessions.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "跨记忆",
4
+ "description": "把值得留下的偏好、决定与踩坑整理成记忆库,在后续会话里按需注入和召回。",
5
+ "detail": "docs/DETAIL.zh.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,128 @@
1
1
  {
2
2
  "name": "dsh-cross-memory",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
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.1",
5
+ "private": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "type": "module",
10
+ "main": "lib/index.js",
11
+ "types": "lib/types/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./lib/types/index.d.ts",
15
+ "default": "./lib/index.js"
16
+ },
17
+ "./client": {
18
+ "default": "./lib/client.js"
19
+ },
20
+ "./cordis.patch.yml": "./cordis.patch.yml",
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "lib/**/*.js",
25
+ "lib/types/**/*.d.ts",
26
+ "cordis.patch.yml",
27
+ "README.md",
28
+ "LICENSE",
29
+ "icon.svg",
30
+ "locale",
31
+ "docs"
32
+ ],
33
+ "license": "MIT",
34
+ "keywords": [
35
+ "dsh-plugin",
36
+ "dsh",
37
+ "deepseek-harness",
38
+ "cordis-plugin",
39
+ "cordis",
40
+ "memory",
41
+ "memories",
42
+ "cross-session",
43
+ "agent-memory",
44
+ "persistent-memory"
45
+ ],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/CooperZhuang/dsh-plugins-cooper-custom.git",
49
+ "directory": "packages/dsh-cross-memory"
50
+ },
51
+ "homepage": "https://github.com/CooperZhuang/dsh-plugins-cooper-custom/tree/main/packages/dsh-cross-memory#readme",
52
+ "bugs": {
53
+ "url": "https://github.com/CooperZhuang/dsh-plugins-cooper-custom/issues"
54
+ },
55
+ "engines": {
56
+ "node": ">=24",
57
+ "dsh": "^0.2.1-rc.2 || ^0.2.2-alpha.2"
58
+ },
59
+ "dsh": {
60
+ "manifestVersion": 1,
61
+ "bundle": {
62
+ "patch": "./cordis.patch.yml"
63
+ },
64
+ "client": {
65
+ "inject": [
66
+ "@deepseek-ai/dsh-client-ui-settings",
67
+ "@deepseek-ai/dsh-client-ui-slots"
68
+ ],
69
+ "external": [
70
+ "@deepseek-ai/dsh-client-ui-settings/client"
71
+ ],
72
+ "platform": "web"
73
+ }
74
+ },
75
+ "scripts": {
76
+ "build": "tsc -p tsconfig.json && node scripts/build-client.mjs",
77
+ "typecheck": "tsc -p tsconfig.json --noEmit",
78
+ "test": "tsc -p tsconfig.json && node scripts/build-client.mjs && node --test lib/test/*.test.js",
79
+ "smoke": "node scripts/activation-smoke.mjs .",
80
+ "seed": "node scripts/seed.mjs",
81
+ "eval": "node scripts/eval-extract.mjs",
82
+ "eval:retrieval": "node scripts/eval-retrieval.mjs",
83
+ "eval:backfill": "node scripts/eval-backfill.mjs",
84
+ "eval:rotation": "node scripts/eval-rotation.mjs",
85
+ "eval:coverage-projection": "node scripts/eval-coverage-projection.mjs",
86
+ "eval:acceptance": "node scripts/eval-acceptance.mjs",
87
+ "eval:recall-log": "node scripts/eval-recall-log.mjs",
88
+ "report": "node scripts/report.mjs",
89
+ "prepare": "npm run build",
90
+ "eval:e2e": "node bench/e2e/run.mjs",
91
+ "eval:real": "node bench/real/run.mjs",
92
+ "eval:real:sample": "node bench/real/sample.mjs",
93
+ "eval:real:author": "node bench/real/author.mjs"
94
+ },
95
+ "peerDependencies": {
96
+ "@deepseek-ai/cordis": "^4.0.5 || ^4.0.6-alpha.1",
97
+ "@deepseek-ai/dsh-agent": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
98
+ "@deepseek-ai/dsh-commands": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
99
+ "@deepseek-ai/dsh-home-paths": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
100
+ "@deepseek-ai/dsh-llm": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
101
+ "@deepseek-ai/dsh-session": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
102
+ "@deepseek-ai/dsh-tools": "^0.2.1-rc.2 || ^0.2.2-alpha.2",
103
+ "@deepseek-ai/schemastery": "^3.18.5 || ^3.18.6-alpha.1"
104
+ },
105
+ "devDependencies": {
106
+ "@deepseek-ai/cordis": "4.1.0",
107
+ "@deepseek-ai/cordis-plugin-loader": "^1.1.0",
108
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
109
+ "@deepseek-ai/dsh-attachment": "0.2.2-rc.1",
110
+ "@deepseek-ai/dsh-commands": "0.2.2-rc.1",
111
+ "@deepseek-ai/dsh-home-paths": "0.2.2-rc.1",
112
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
113
+ "@deepseek-ai/dsh-scope": "0.2.2-rc.1",
114
+ "@deepseek-ai/dsh-session": "0.2.2-rc.1",
115
+ "@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
116
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
117
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
118
+ "@deepseek-ai/dsh-user-approval": "0.2.2-rc.1",
119
+ "@deepseek-ai/dsh-workspace": "0.2.2-rc.1",
120
+ "@deepseek-ai/schemastery": "3.19.0",
121
+ "@types/node": "^26.6.5",
122
+ "typescript": "^7.0.2"
123
+ },
124
+ "dependencies": {
125
+ "@deepseek-ai/cosmokit": "^1.9.0"
126
+ },
127
+ "icon": "./icon.svg"
128
+ }