@zhangfeiyue/dsh-long-term-memory 0.0.0-stage → 1.1.0

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/docs/DETAIL.md ADDED
@@ -0,0 +1,226 @@
1
+ # Long-term memory
2
+
3
+ This plugin gives DeepSeek Harness a memory that outlives the conversation. It is
4
+ installed in the profile, so it applies to every session in every workspace, and
5
+ its records are stored outside all workspaces.
6
+
7
+ ## Why it exists
8
+
9
+ Every new session starts blank. Project conventions, decisions taken last week,
10
+ the reason a workaround exists, and the task that was half finished are all
11
+ re-derived or forgotten. Session logs already contain that knowledge, but nothing
12
+ brings the relevant part back at the moment it matters.
13
+
14
+ This plugin closes that gap with three movements: capture durable knowledge,
15
+ recall it when it is relevant, and keep the store from rotting.
16
+
17
+ ## Profiles: who, and how
18
+
19
+ A record store answers "what did we decide about X". It cannot answer "how should
20
+ I talk to this person" or "how is development done here", because those need a
21
+ consolidated, stable, bounded description rather than a ranked list.
22
+
23
+ So memory has two representations. **Evidence** is the record store — durable,
24
+ searchable, correctable one line at a time. **Profiles** are computed from it:
25
+
26
+ | Layer | Holds | Scope |
27
+ |---|---|---|
28
+ | `persona` | Identity, communication, values, hard constraints, goals, working style | One, global |
29
+ | `work` | Stack, conventions, quality bar, workflow, pitfalls, decisions | One per domain |
30
+ | `project` | Facts about this workspace | Per workspace |
31
+ | `episodic` | Tasks in flight | Per workspace/session |
32
+
33
+ Domains are coarse on purpose: `development`, `data`, `ops-ci`, `design`,
34
+ `product`, `writing`, `general`. A profile holding four items is useful; one
35
+ holding one item per sub-speciality is noise.
36
+
37
+ A **facet** says which aspect a memory describes — `communication` for "reply in
38
+ Chinese", `constraints` for "never push to main". Facets are what make the profile
39
+ read as sections rather than a heap.
40
+
41
+ **Admission** keeps the persona honest. A record enters a profile only when it is
42
+ pinned with `memory_profile`, confirmed twice (restating a memory merges into it
43
+ and increments a counter), or important enough (persona ≥ 4, work ≥ 3). A single
44
+ passing remark stays evidence — searchable, correctable — without becoming part of
45
+ "who this person is".
46
+
47
+ **Synthesis** is deterministic and extractive: select, group by facet, order,
48
+ drop lines more than 90% contained in one already kept, cap per facet and by
49
+ budget. No model call sits in the request path, so the same store always yields
50
+ the same profile, and every line cites the record id it came from. The trade is
51
+ readability: a profile reads as cleaned-up statements, not as prose written by a
52
+ model.
53
+
54
+ ## The memory board
55
+
56
+ The bundle ships a browser half. **Settings → Plugins → Long-term memory** shows
57
+ the whole store at a glance: the personal profile, each work profile with its
58
+ entry count, unfinished tasks, and a feed of recent changes.
59
+
60
+ It is live. A server-sent event stream pushes a snapshot whenever the store
61
+ changes, so a write from any session appears while you watch, and rows whose
62
+ timestamp moved are highlighted. If the stream cannot connect the board falls back
63
+ to polling and says so in the status chip.
64
+
65
+ You can pin, edit and delete an entry from the board, and change a task's status
66
+ inline. Three rules keep that safe:
67
+
68
+ - **Versioned writes.** Each write carries the version the board last saw; a
69
+ memory changed in the meantime answers `409` and the board reloads instead of
70
+ overwriting it.
71
+ - **Exact text.** The stream carries truncated text to stay small, so the editor
72
+ loads the full stored record before you type — saving cannot quietly drop the
73
+ tail of a memory.
74
+ - **Audit.** Board writes are stamped `source: { kind: 'board', at }`, so the
75
+ append-only log still says who changed what.
76
+
77
+ ## How recall works
78
+
79
+ The plugin extends the harness only at documented seams.
80
+
81
+ - It registers six model-facing tools on `ctx.tools`, so the model can read and
82
+ write memory deliberately.
83
+ - It listens for `agent/created` and installs a per-agent dynamic context
84
+ through `agent.ctx.systemPrompt.context`. The provider is evaluated during
85
+ prompt assembly, returns a bounded block, and is removed with the agent.
86
+ - It listens on `session/event` and reads the durable log. It never appends
87
+ events, so replay, fork and resume remain entirely the harness's business.
88
+
89
+ Before a request, the plugin takes the latest real user message as the retrieval
90
+ query. It ranks memories lexically — word tokens for space-delimited scripts,
91
+ character bigrams for Chinese and Japanese, inverse-document-frequency weighting,
92
+ plus boosts for workspace match, kind, importance, recency and reuse — and
93
+ assembles one block from five sections, each with its own character budget:
94
+ personal profile, work profile for the active domain, project knowledge,
95
+ unfinished tasks, and finally whatever budget remains for entries related to the
96
+ current request. An empty store contributes no text at all, so the plugin costs
97
+ nothing until it has learned something.
98
+
99
+ Because profile cost is capped per section, injected cost stays constant as the
100
+ store grows — which is the point of profiles rather than injecting more facts.
101
+
102
+ The rendered block is cached per session until the latest user message changes,
103
+ which keeps the request prefix stable for provider cache reuse.
104
+
105
+ ## What is captured, and what is not
106
+
107
+ Capture is deliberately narrow, because every captured memory is later injected
108
+ into prompts.
109
+
110
+ **Captured automatically**
111
+
112
+ - A user sentence that explicitly asks the agent to remember something, in
113
+ English or Chinese. Questions and ordinary requests are ignored.
114
+ - Open and in-progress items from every `todo/write` snapshot, recorded as task
115
+ memories partitioned by workspace and session. This is what makes unfinished
116
+ work resumable after a restart. Items that disappear from a later snapshot are
117
+ marked dropped rather than silently forgotten.
118
+
119
+ **Captured on request**
120
+
121
+ Everything else, through `memory_save`. The plugin does not mine conversation
122
+ transcripts for facts, because unverified inference silently becomes
123
+ authoritative context later.
124
+
125
+ **Never captured**
126
+
127
+ Secrets and credentials, transient state, and long code blocks. Storing those
128
+ would leak them into every future prompt.
129
+
130
+ ## Scope
131
+
132
+ - `preference`, `capability`, `fact` and `decision` records default to global,
133
+ visible from every workspace.
134
+ - `project`, `solution` and `task` records default to the workspace they were
135
+ created in. Retrieval excludes other workspaces unless cross-workspace search
136
+ is explicitly requested, so project knowledge never leaks between projects.
137
+
138
+ ## Consolidation
139
+
140
+ A background pass runs every six hours and after a burst of log growth:
141
+
142
+ 1. Near-identical records of the same kind and scope are merged; the survivor
143
+ keeps the longer text and the union of the tags, and the other is marked
144
+ superseded rather than deleted.
145
+ 2. For preferences and decisions, a newer statement that nearly restates an older
146
+ one supersedes it, so a revised decision wins while its history stays
147
+ searchable.
148
+ 3. Old, never-used, low-importance notes and facts are archived.
149
+ 4. When the store exceeds `maxRecords`, the lowest-value records are archived
150
+ first.
151
+
152
+ Archived and superseded records remain recallable through `memory_search` with an
153
+ explicit status filter. Estimated through containment rather than Jaccard
154
+ similarity, because a restated memory that adds one qualifier is still the same
155
+ memory.
156
+
157
+ ## Storage and recovery
158
+
159
+ The store is an append-only JSON-lines log folded into memory at load. An append
160
+ is one small write, so a crash costs at most the record being written. A torn
161
+ trailing line is skipped, not fatal. Compaction rewrites only live records and
162
+ leaves dated copies in `backup/`, keeping the five most recent.
163
+
164
+ Default location: `~/.dsh/long-term-memory/`
165
+
166
+ | Path | Contents |
167
+ |---|---|
168
+ | `records.jsonl` | Append-only record log |
169
+ | `backup/` | Dated pre-compaction copies |
170
+ | `logs/plugin.log` | Diagnostics, rotated at 1 MiB |
171
+ | `config.json` | Optional user overrides |
172
+ | `effective-config.json` | Resolved settings, rewritten at mount |
173
+
174
+ Deleting the directory resets memory. Restoring a backup file over
175
+ `records.jsonl` restores the store as of that copy.
176
+
177
+ ## Configuration
178
+
179
+ The composition row carries no configuration, so the row survives upgrades
180
+ unchanged. Override settings in `~/.dsh/long-term-memory/config.json`; a value in
181
+ the row still wins.
182
+
183
+ | Key | Default | Meaning |
184
+ |---|---|---|
185
+ | `storeDir` | `~/.dsh/long-term-memory` | Store location |
186
+ | `maxRecords` | 5000 | Cap before consolidation archives the weakest |
187
+ | `maxInjectChars` | 2400 | Character budget of one injected block |
188
+ | `injectLimit` | 12 | Retrieval candidates considered for injection |
189
+ | `searchLimit` | 20 | Maximum `memory_search` results |
190
+ | `injectRefreshMs` | 300000 | Minimum time between block refreshes per session |
191
+ | `consolidateIntervalMs` | 21600000 | Background consolidation period |
192
+ | `staleDays` | 180 | Age after which unused trivia is archived |
193
+ | `autoExtract` | true | Capture explicit "remember this" instructions |
194
+ | `taskCapture` | true | Capture `todo/write` items as resumable tasks |
195
+ | `personaMinImportance` | 4 | Importance floor for entering the personal profile |
196
+ | `workMinImportance` | 3 | Importance floor for entering a work profile |
197
+ | `profileBudgets` | 400/500/520/400 | Per-section caps for persona, work, project, tasks |
198
+ | `domains` | `[]` | Workspace path patterns mapped to a work domain |
199
+
200
+ ## Limitations
201
+
202
+ - **Profiles are extractive, not abstractive.** A profile line is a cleaned-up
203
+ evidence record, not prose written by a model. It is free, reproducible and
204
+ traceable, but reads as a list of statements.
205
+ - **Domain detection is heuristic.** A repository whose directory name says
206
+ nothing about its field lands in `general` unless configured.
207
+ - **Lexical retrieval, not semantic.** Recall depends on shared vocabulary. A
208
+ memory phrased very differently from the question may not surface; ask for it
209
+ with `memory_search` in that case.
210
+ - **Capture needs an explicit signal.** The automatic path handles remembered
211
+ instructions and todo items only. The agent is responsible for saving decisions
212
+ and solutions as they happen.
213
+ - **Consolidation is conservative.** Distinct preferences that share most
214
+ vocabulary are not superseded automatically; correct them with
215
+ `memory_update`.
216
+ - **The store is single-writer.** Writes are serialized inside one host process.
217
+ Concurrent processes sharing one store directory can interleave appends; a torn
218
+ line is skipped at load, but the surviving record set may differ by one write.
219
+ - **Memory is advisory.** Recalled entries can be stale. The injected block says
220
+ so, and the model is expected to verify anything that may have changed.
221
+
222
+ ## Failure behaviour
223
+
224
+ Every listener, context provider and tool catches its own errors and degrades to
225
+ "no memory". A damaged, read-only or deleted store never prevents a session from
226
+ starting, and no failure path in this plugin can prevent a model request.
package/icon.svg ADDED
@@ -0,0 +1,18 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Long-term memory">
2
+ <defs>
3
+ <linearGradient id="ltm-bg" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0" stop-color="#2b5bd7"/>
5
+ <stop offset="1" stop-color="#6f3bd6"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <rect x="4" y="4" width="56" height="56" rx="14" fill="url(#ltm-bg)"/>
9
+ <!-- stacked memory layers -->
10
+ <g fill="none" stroke="#ffffff" stroke-width="3.2" stroke-linecap="round" stroke-linejoin="round">
11
+ <path d="M18 26 L32 19 L46 26 L32 33 Z"/>
12
+ <path d="M18 34 L32 41 L46 34" opacity="0.85"/>
13
+ <path d="M18 42 L32 49 L46 42" opacity="0.6"/>
14
+ </g>
15
+ <!-- recall node -->
16
+ <circle cx="32" cy="26" r="3.1" fill="#ffffff"/>
17
+ <circle cx="32" cy="26" r="7.2" fill="none" stroke="#ffffff" stroke-width="1.6" opacity="0.55"/>
18
+ </svg>