@tangjs/dsh-memory 0.0.0-stage → 1.0.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/CHANGELOG.md +154 -0
- package/LICENSE +201 -0
- package/README.en.md +268 -0
- package/README.md +268 -2
- package/client/client.js +1607 -0
- package/cordis.patch.yml +7 -0
- package/docs/ACCEPTANCE.md +341 -0
- package/docs/DESIGN.md +87 -0
- package/docs/DETAIL.md +48 -0
- package/docs/SPIKE.md +20 -0
- package/docs/diagrams/memory-flow.html +1227 -0
- package/icon.svg +8 -0
- package/index.js +582 -0
- package/locale/en.json +50 -0
- package/locale/zh.json +50 -0
- package/package.json +77 -4
- package/screenshots/global-space.png +0 -0
- package/screenshots/guide.png +0 -0
- package/screenshots/memory-detail.png +0 -0
- package/screenshots/memory-flow.png +0 -0
- package/screenshots/memory-page.png +0 -0
- package/src/host/api.mjs +234 -0
- package/src/host/autoDream.mjs +946 -0
- package/src/host/config.mjs +131 -0
- package/src/host/digest.mjs +121 -0
- package/src/host/dream.mjs +385 -0
- package/src/host/dreamAgent.mjs +619 -0
- package/src/host/extract.mjs +813 -0
- package/src/host/memoryIndex.mjs +137 -0
- package/src/host/prompt.mjs +65 -0
- package/src/host/recall.mjs +456 -0
- package/src/host/score.mjs +76 -0
- package/src/host/store.mjs +498 -0
- package/src/host/tool.mjs +144 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [1.0.0] — 2026-11-30
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- **Renamed to `@tangjs/dsh-memory`** for the first npm release. The old
|
|
12
|
+
`@tangzhicheng/dsh-memory` name never shipped to the registry; `dsh-memory`
|
|
13
|
+
without a scope belongs to an unrelated package, so a scoped name is what
|
|
14
|
+
makes this installable. Upgrading means updating the dependency key, the
|
|
15
|
+
bundle list, and the `dsh-memory` patch row's `name:` to the new package.
|
|
16
|
+
- `1.0.0` marks the first public release: the tools, the note format, and the
|
|
17
|
+
configuration schema are what third parties can now depend on.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- `publishConfig.access: "public"` so a scoped first publish is not rejected as
|
|
22
|
+
private.
|
|
23
|
+
- `screenshots/` ships with the package, so the README images resolve on npm
|
|
24
|
+
instead of 404ing.
|
|
25
|
+
|
|
26
|
+
## [0.5.0] — 2026-11-29
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- **Evidence-based automatic consolidation.** Auto-dream can now run as a
|
|
31
|
+
tool-capable subagent (`dream.agent`, default on) instead of a single model
|
|
32
|
+
call. The child gets the notes manifest, the memory directory, and the
|
|
33
|
+
workspace directory; it reads notes, greps the codebase, and checks `git log`
|
|
34
|
+
before deciding what is stale. It returns a JSON plan — it never writes —
|
|
35
|
+
and the plugin applies it through `store`.
|
|
36
|
+
- `conflicts` in the plan: when two notes disagree and the evidence does not
|
|
37
|
+
settle which is right, the pass reports the conflict instead of picking one.
|
|
38
|
+
Conflicts are logged; they are never auto-resolved.
|
|
39
|
+
- Shrink guard: a rewrite that drops more than half of a long note (and at least
|
|
40
|
+
400 characters) is rejected, because that usually means the child rewrote a
|
|
41
|
+
file it never read.
|
|
42
|
+
- Snapshot guard: the memory directory is snapshotted before the child starts and
|
|
43
|
+
restored afterwards, so a child that ignores the read-only rule cannot leave
|
|
44
|
+
writes behind.
|
|
45
|
+
- Failure backoff (`dream.backoffMinutes`, default 60): `lastAttemptAt` is now
|
|
46
|
+
persisted, so a failed pass no longer re-fires on every `turn/end`.
|
|
47
|
+
- Config: `dream.agent`, `dream.provider`, `dream.agentModel`,
|
|
48
|
+
`dream.agentTimeoutMs`, `dream.backoffMinutes`.
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- The agent path hands the child a manifest (file, type, name, description,
|
|
53
|
+
`updated`, size) instead of note bodies; the child reads what it needs. The
|
|
54
|
+
single-call path and its 32KB byte budget are unchanged and still serve as the
|
|
55
|
+
fallback whenever no subagent service is available.
|
|
56
|
+
- Note selection now carries `updated` and body length, which the shrink guard
|
|
57
|
+
and the manifest both use.
|
|
58
|
+
|
|
59
|
+
## [0.1.0] — 2026-11-28
|
|
60
|
+
|
|
61
|
+
### Added
|
|
62
|
+
|
|
63
|
+
- File-based, workspace-scoped memory notes under `$DSH_HOME/dsh-memory/spaces/`.
|
|
64
|
+
- `memory_note` and `memory_search` model tools.
|
|
65
|
+
- End-of-turn extraction: bounded conversation digest, one model call per turn,
|
|
66
|
+
JSON upserts/deletes with a strict parser.
|
|
67
|
+
- Lexical recall (Latin words + CJK bigrams) injected before the first step of
|
|
68
|
+
each turn, with per-note and per-session byte budgets.
|
|
69
|
+
- Right-sidebar **Memory** page: space list, note timeline, Markdown detail view.
|
|
70
|
+
- Read-only JSON API under `/plugin/dsh-memory/api`.
|
|
71
|
+
- Configuration for storage, extraction, recall, and the reserved global space.
|
|
72
|
+
|
|
73
|
+
## [0.2.0] — 2026-11-28
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
|
|
77
|
+
- `/dream`: a manual consolidation pass (Orient → Gather → Consolidate → Prune)
|
|
78
|
+
that merges duplicates, corrects stale facts, absolutizes dates, and prunes.
|
|
79
|
+
- Optional global memory space: `spaces.global: true` makes `_global` writable
|
|
80
|
+
and readable; recall merges workspace and global notes and marks global hits.
|
|
81
|
+
- `memory_note` / `memory_forget` accept `scope: "global"` when the global space
|
|
82
|
+
is enabled.
|
|
83
|
+
- Memory page pins the global row last and localizes its label.
|
|
84
|
+
|
|
85
|
+
### Changed
|
|
86
|
+
|
|
87
|
+
- Extraction is now incremental: only the conversation since the last
|
|
88
|
+
extraction cursor is sent, capped at ~8K characters.
|
|
89
|
+
- Extraction output may name an existing `file`; the writer merges by file,
|
|
90
|
+
exact name, or name/description similarity (Jaccard ≥ 0.45) so one topic keeps
|
|
91
|
+
one file, preserving `created`.
|
|
92
|
+
- Manifest entries in the extraction prompt are explicitly metadata: model
|
|
93
|
+
output has `[type]`, timestamps, and `.md` names stripped before writing.
|
|
94
|
+
- `store.listSpaces()` now reports the real `_global` row; the API sorts it last.
|
|
95
|
+
|
|
96
|
+
### Fixed
|
|
97
|
+
|
|
98
|
+
- `/notes` and `/note` accept `refresh=1` to invalidate the per-space cache after
|
|
99
|
+
hand-editing Markdown.
|
|
100
|
+
- Client space sorting no longer floats the global row up by recency.
|
|
101
|
+
|
|
102
|
+
## [0.3.0] — 2026-11-28
|
|
103
|
+
|
|
104
|
+
### Added
|
|
105
|
+
|
|
106
|
+
- **Automatic consolidation**: after 24h and 5 distinct sessions, a background
|
|
107
|
+
pass merges duplicates, rewrites stale notes, and prunes. Hard safety rails:
|
|
108
|
+
never empties a space, never deletes more than `dream.maxDeletes`, never
|
|
109
|
+
rewrites a truncated note, ignores files outside the prompt, and never throws
|
|
110
|
+
into the turn.
|
|
111
|
+
- **LLM recall strategy** (`recall.strategy: "llm"`): the session model picks the
|
|
112
|
+
notes to inject; invalid output, timeouts, or missing routes silently fall
|
|
113
|
+
back to the lexical ranker.
|
|
114
|
+
- `recall.llmTimeoutMs` and `dream.*` configuration (enabled, minHours,
|
|
115
|
+
minSessions, maxNotes, maxDeletes, model).
|
|
116
|
+
|
|
117
|
+
### Changed
|
|
118
|
+
|
|
119
|
+
- Recall routes are captured per turn so the selector uses the live session
|
|
120
|
+
model; the outer recall deadline now accounts for the LLM budget.
|
|
121
|
+
|
|
122
|
+
## [0.4.0] — 2026-11-28
|
|
123
|
+
|
|
124
|
+
### Added
|
|
125
|
+
|
|
126
|
+
- **Generated `MEMORY.md` index** in every space: one line per note
|
|
127
|
+
(type / name / description / file / date), rebuilt atomically after every
|
|
128
|
+
write or delete, lazily repaired if missing, and removed when the space is
|
|
129
|
+
empty.
|
|
130
|
+
- The index is injected **once per session** as a bounded `<memory-index>`
|
|
131
|
+
notice: default ≤20 entries and ≤2000 characters, subtracted from the same
|
|
132
|
+
40 KB session budget as recall. Full bodies still come from recall or tools.
|
|
133
|
+
- `memoryMd.*` configuration (enabled, maxEntries, maxLineChars, maxChars,
|
|
134
|
+
inject, injectMaxEntries, injectMaxChars).
|
|
135
|
+
- Index lines collapse newlines and truncate per line, so a hostile note name
|
|
136
|
+
or description cannot grow the file or the prompt without bound.
|
|
137
|
+
|
|
138
|
+
### Changed
|
|
139
|
+
|
|
140
|
+
- Store writes now also refresh the index; the index file is excluded from the
|
|
141
|
+
note list and the note cap.
|
|
142
|
+
|
|
143
|
+
## [0.4.1] — 2026-11-28
|
|
144
|
+
|
|
145
|
+
### Added
|
|
146
|
+
|
|
147
|
+
- The memory page now shows a pinned **MEMORY.md** row above the note timeline,
|
|
148
|
+
with its entry count; opening it renders the generated index (read-only) and
|
|
149
|
+
the on-disk path. New `GET /plugin/dsh-memory/api/index?space=…` route backs
|
|
150
|
+
it, and `notes` responses carry a small `index` summary.
|
|
151
|
+
|
|
152
|
+
### Fixed
|
|
153
|
+
|
|
154
|
+
- The index's generator comment is hidden in the rendered view.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 PerryLink
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# dsh-memory
|
|
2
|
+
|
|
3
|
+
English | [中文](README.md)
|
|
4
|
+
|
|
5
|
+
A **memory-notes** plugin for [DeepSeek Harness](https://github.com/deepseek-ai), scoped per workspace directory: it gives the agent a way to remember what matters across sessions, plus a sidebar page for browsing the memory itself.
|
|
6
|
+
|
|
7
|
+
> The design borrows from Claude Code's auto-memory: notes are self-describing Markdown files, recall injects only the few relevant ones, and the injected layer stays small on purpose.
|
|
8
|
+
|
|
9
|
+
## What it does
|
|
10
|
+
|
|
11
|
+
| Capability | What happens |
|
|
12
|
+
|---|---|
|
|
13
|
+
| Explicit save | The model calls `memory_note` to write one durable note (user preference, feedback, project context, external pointer); writing the same name updates it in place |
|
|
14
|
+
| Explicit forget | `memory_forget` deletes one note by file name (used when the user says "forget …") |
|
|
15
|
+
| End-of-turn extraction | After each turn, a background pass turns what is worth keeping in that turn into notes (can be disabled) |
|
|
16
|
+
| MEMORY.md index | Rebuilt on every write; injected once per session, ≤20 lines / ≤2000 characters |
|
|
17
|
+
| On-demand recall | Before answering, one matching pass (local lexical by default, optionally an LLM selector) injects at most 3 of the most relevant notes |
|
|
18
|
+
| Memory page | Right sidebar: browse note timelines per workspace space, open one for its Markdown detail |
|
|
19
|
+
| Consolidation | `/dream [focus]` on demand; automatic consolidation also runs in the background once 24h **and** 5 sessions have passed |
|
|
20
|
+
| Workspace isolation | One memory space per working directory; the model only reads its own space by default |
|
|
21
|
+
| Global space | Opt-in: cross-project facts live in `_global` and are recalled alongside workspace notes |
|
|
22
|
+
|
|
23
|
+
Naming follows a four-type taxonomy (`user` / `feedback` / `project` / `reference`), and the guidance explicitly lists **what not to save** (code patterns, git history, debugging recipes, anything already in AGENTS.md).
|
|
24
|
+
|
|
25
|
+
## Flow diagram
|
|
26
|
+
|
|
27
|
+
[Memory capture and consumption](docs/diagrams/memory-flow.html): a single offline-openable HTML file; ten steps explain how memory is extracted, recalled, and consolidated across working directories and sessions, with toggles for the global space and the recall strategy.
|
|
28
|
+
|
|
29
|
+
[](docs/diagrams/memory-flow.html)
|
|
30
|
+
|
|
31
|
+
## Interface
|
|
32
|
+
|
|
33
|
+
Right sidebar → the **Memory** card in guide:
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
Opening any note goes to its detail view (breadcrumb, type/origin badges, Markdown body, file path):
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
Requires DeepSeek Harness `>=0.2.2-0 <0.3.0`.
|
|
44
|
+
|
|
45
|
+
**Local directory** (development): clone this repository, then **Plugins → Add plugin** and pick the directory.
|
|
46
|
+
|
|
47
|
+
**GitHub channel** (after publishing):
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
dsh plugin --profile desktop add github:zixingtangmouren/dsh-memory
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**npm** (once published to npm):
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
dsh plugin --profile desktop add @tangjs/dsh-memory
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
After installing, open a new session; the **Memory** page should appear among the guide cards in the right sidebar.
|
|
60
|
+
|
|
61
|
+
### Which profile to install into (the easy mistake)
|
|
62
|
+
|
|
63
|
+
Plugins are isolated **per profile**: installing into `desktop` only affects desktop GUI sessions and does **not** make the plugin available in `sdk`, `web`, or `feishu-guest` sessions. The memory files themselves are shared on disk (one `$DSH_HOME/dsh-memory`); what differs is whether that profile has the plugin assembled.
|
|
64
|
+
|
|
65
|
+
| Entry point | Profile used | Installed by default |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| Desktop GUI | `desktop` | Install with the command above |
|
|
68
|
+
| `dsh` CLI / SDK | whichever profile you pass (e.g. `sdk`) | Install separately |
|
|
69
|
+
| Feishu bridge (feishu-bridge) | `sdk` by default; group members use `feishu-guest` | Install separately into `sdk` |
|
|
70
|
+
| `dsh web` | `web` | Install separately |
|
|
71
|
+
|
|
72
|
+
Installing into another profile (the CLI forwards to pnpm; also add the bundle to the list, or use that profile's plugin manager):
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
dsh plugin --profile sdk add @tangjs/dsh-memory
|
|
76
|
+
# then add "@tangjs/dsh-memory" to dsh.profile.bundles in ~/.dsh/profiles/sdk/package.json
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`feishu-guest` is a guest profile that is **shell-less and read-only by design**: do not install there, because plugin writes would bypass its read-only sandbox; read-only recall for guests is future work.
|
|
80
|
+
|
|
81
|
+
## Configuration
|
|
82
|
+
|
|
83
|
+
Override in the profile's patch layer (for example `$DSH_HOME/profiles/<name>/cordis.patch.yml`):
|
|
84
|
+
|
|
85
|
+
```yaml
|
|
86
|
+
- id: dsh-memory
|
|
87
|
+
name: '@tangjs/dsh-memory'
|
|
88
|
+
config:
|
|
89
|
+
storage:
|
|
90
|
+
root: '' # default $DSH_HOME/dsh-memory
|
|
91
|
+
maxNoteBytes: 8192 # cap for one note
|
|
92
|
+
maxNotes: 200 # cap for one space
|
|
93
|
+
extract:
|
|
94
|
+
enabled: true
|
|
95
|
+
minNewChars: 1500 # skip extraction when the new conversation is shorter than this
|
|
96
|
+
model: '' # default: the current session's model
|
|
97
|
+
maxPerTurn: 3
|
|
98
|
+
recall:
|
|
99
|
+
enabled: true
|
|
100
|
+
strategy: lexical # lexical (default) | llm (model selects; falls back silently)
|
|
101
|
+
topK: 3
|
|
102
|
+
maxNoteBytes: 4096
|
|
103
|
+
sessionBudgetBytes: 40960
|
|
104
|
+
timeoutMs: 400 # lexical budget
|
|
105
|
+
llmTimeoutMs: 2000 # LLM selector budget
|
|
106
|
+
dream:
|
|
107
|
+
enabled: true # master switch for automatic consolidation
|
|
108
|
+
minHours: 24
|
|
109
|
+
minSessions: 5
|
|
110
|
+
maxNotes: 60 # notes considered by one pass
|
|
111
|
+
maxDeletes: 5 # deletions allowed in one pass
|
|
112
|
+
model: '' # model for the single-call path; default current session model
|
|
113
|
+
agent: true # consolidate through a tool-capable subagent (can verify against code)
|
|
114
|
+
provider: spawn # subagent backend: spawn (default) or fork
|
|
115
|
+
agentModel: '' # subagent model; empty inherits the parent session
|
|
116
|
+
agentTimeoutMs: 180000
|
|
117
|
+
backoffMinutes: 60 # how long to wait after a failed pass
|
|
118
|
+
memoryMd:
|
|
119
|
+
enabled: true # rebuild the MEMORY.md index after every write
|
|
120
|
+
maxEntries: 100 # most entries in the index file
|
|
121
|
+
maxLineChars: 240 # per-line cap
|
|
122
|
+
maxChars: 12000 # total cap for the index file
|
|
123
|
+
inject: true # inject the index once per session
|
|
124
|
+
injectMaxEntries: 20 # most entries in the injected copy
|
|
125
|
+
injectMaxChars: 2000 # total characters in the injected copy (~1–1.5k tokens)
|
|
126
|
+
spaces:
|
|
127
|
+
global: false # global space (off by default; see below to enable)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Where the data lives
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
$DSH_HOME/dsh-memory/spaces/<workspace>-<hash>/
|
|
134
|
+
├── user_role.md
|
|
135
|
+
├── feedback_testing.md
|
|
136
|
+
└── project_release.md
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
A note looks like this:
|
|
140
|
+
|
|
141
|
+
```markdown
|
|
142
|
+
---
|
|
143
|
+
name: Do not mock the database in tests
|
|
144
|
+
description: Integration tests must hit a real PG; a mock hides migration syntax errors
|
|
145
|
+
type: feedback
|
|
146
|
+
origin: extract
|
|
147
|
+
created: 2026-11-28T00:12:00.000Z
|
|
148
|
+
updated: 2026-11-28T00:12:00.000Z
|
|
149
|
+
source_session: 6f3a9c1e-...
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
Do not mock the database connection in tests.
|
|
153
|
+
|
|
154
|
+
**Why:** A migration that passed under a mock was invalid on real PG — CI was green and production broke.
|
|
155
|
+
**How to apply:** Start a throwaway database with docker, or reuse TEST_DATABASE_URL.
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- `description` is the retrieval key used at recall time, so make it specific.
|
|
159
|
+
- Extraction is **incremental**: each turn only sends the conversation since the last extraction cursor, and one topic merges into the existing file instead of piling up near-duplicates.
|
|
160
|
+
- File names are ASCII slugs derived from `name`; a CJK-only name degrades to `note-<hash>.md`.
|
|
161
|
+
- These files are the authority: delete the cache or copy the directory to another machine and it still works.
|
|
162
|
+
|
|
163
|
+
**Privacy**: everything stays on this machine; the plugin makes no network requests. The only external call reuses DSH's own model route for extraction.
|
|
164
|
+
|
|
165
|
+
## Consolidating memory (`/dream`)
|
|
166
|
+
|
|
167
|
+
Type `/dream`, or narrow the scope with `/dream only the deployment notes`. It feeds a four-phase prompt (Orient → Gather → Consolidate → Prune) into the current session, and the model consolidates with the same tools it normally uses:
|
|
168
|
+
|
|
169
|
+
- Merge several files about one topic; correct facts that reality has overturned; convert relative dates to absolute ones;
|
|
170
|
+
- Delete one-off task details and obsolete entries; hold one space at ≤200 notes and each note at ≤8 KB;
|
|
171
|
+
- Finish with a one-line report (what was written, what was deleted).
|
|
172
|
+
|
|
173
|
+
## Automatic consolidation (auto-dream)
|
|
174
|
+
|
|
175
|
+
On by default. After **≥24 hours since the last pass** and **≥5 distinct sessions in between**, the plugin runs one consolidation in the background at the end of a turn:
|
|
176
|
+
|
|
177
|
+
- It only merges / rewrites / deletes; it never adds notes;
|
|
178
|
+
- It looks at ≤60 notes and deletes ≤5, and **never empties a space**;
|
|
179
|
+
- Files written in the same turn are never deleted;
|
|
180
|
+
- On failure or invalid model output it changes nothing and does not interrupt the conversation; a failed pass waits `backoffMinutes` (60 by default) before trying again, instead of retrying at every turn end;
|
|
181
|
+
- Both the gates and the caps live in the `dream` config; turn it off with `dream.enabled: false`.
|
|
182
|
+
|
|
183
|
+
### Evidence-based consolidation (the default path)
|
|
184
|
+
|
|
185
|
+
Notes alone cannot tell you what is stale: they can reveal that two notes disagree, but never that a note no longer matches the code. So the default path **starts a tool-capable subagent** (`dream.agent: true`):
|
|
186
|
+
|
|
187
|
+
1. It receives the memory directory, the workspace directory, and a manifest (file / type / name / description / `updated` / size) — **not the note bodies**;
|
|
188
|
+
2. It reads the notes, greps the codebase, and consults `git log` to check whether the files, functions, flags, and commands a note names still exist;
|
|
189
|
+
3. It returns a JSON plan and **never writes a file**; the plugin applies the plan through the store.
|
|
190
|
+
|
|
191
|
+
That lets it do what a single call cannot: catch drift such as "the code changed but the note did not", and attach the evidence it checked.
|
|
192
|
+
|
|
193
|
+
The safety rails are in code, not just in the prompt:
|
|
194
|
+
|
|
195
|
+
- **Change, never add**: every `merge` must point at a file already in the manifest;
|
|
196
|
+
- **Unseen notes stay untouched**: files dropped by `maxNotes` are not on the whitelist;
|
|
197
|
+
- **Shrink guard**: a rewrite that keeps less than half of a long note *and* drops ≥400 characters is refused — that usually means it was rewritten without being read;
|
|
198
|
+
- **Conflicts are not guessed**: when two notes disagree and the evidence does not settle it, the pass returns `conflicts` (the two files plus one question for a human); the plugin only logs them and **never picks a side**;
|
|
199
|
+
- **Snapshot guard**: the memory directory is snapshotted before the child starts and restored afterwards, reverting any writes it made anyway;
|
|
200
|
+
- **Timeout**: the run is aborted at `agentTimeoutMs` instead of hanging in the background.
|
|
201
|
+
|
|
202
|
+
When no subagent service is available (or with `dream.agent: false`), it falls back to the original single model call: note bodies are truncated into the prompt and the model returns the same JSON plan. Both paths share the same apply-time checks.
|
|
203
|
+
|
|
204
|
+
Whether the subagent can read session transcripts depends on the tools it inherits: a profile with session search can query earlier sessions narrowly; without it, the child relies on the notes, the codebase, and `git log`.
|
|
205
|
+
|
|
206
|
+
You can still run a pass immediately with `/dream`.
|
|
207
|
+
|
|
208
|
+
## The MEMORY.md index
|
|
209
|
+
|
|
210
|
+
Each space keeps a **generated index** at `spaces/<key>/MEMORY.md`: one line per note (type / name / description / file / date), newest `updated` first.
|
|
211
|
+
|
|
212
|
+
- Rebuilt automatically: atomically rewritten after any write or delete, and recreated on the next read if it went missing.
|
|
213
|
+
- It is not the whole injection: the index is for overview and discovery; bodies still come from recall, ranked by relevance.
|
|
214
|
+
- Injection is hard-capped: once per session at the first pre-step, **≤20 lines / ≤2000 characters** (`memoryMd.injectMax*`), counted against the 40 KB session budget; anything beyond that becomes one line saying "N more notes, use memory_search".
|
|
215
|
+
- The index file itself is capped too (≤100 entries / ≤12000 characters by default), so a large space cannot grow without bound.
|
|
216
|
+
|
|
217
|
+
Tokens are therefore bounded by two gates together: **at most 2 KB of index once, and at most 3 notes / 4 KB per note / 40 KB per session from recall**.
|
|
218
|
+
|
|
219
|
+
## Recall strategy
|
|
220
|
+
|
|
221
|
+
The default is `lexical`: local lexical ranking, zero extra calls, deterministic. With `strategy: llm` the current model picks from the candidates (up to `topK`), and a timeout or invalid output **falls back to lexical silently**, so a turn never loses recall.
|
|
222
|
+
|
|
223
|
+
## Global memory space (optional)
|
|
224
|
+
|
|
225
|
+
Off by default: a workspace only sees its own notes. Set `spaces.global` to `true`:
|
|
226
|
+
|
|
227
|
+
```yaml
|
|
228
|
+
- id: dsh-memory
|
|
229
|
+
name: '@tangjs/dsh-memory'
|
|
230
|
+
config:
|
|
231
|
+
spaces:
|
|
232
|
+
global: true
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
- The **Global** row in the Memory page becomes usable and shows the notes in `_global`;
|
|
236
|
+
- The model can write cross-project facts with `memory_note` and `scope: "global"` (the default is still the current workspace);
|
|
237
|
+
- Recall ranks workspace and global notes together and marks global hits.
|
|
238
|
+
|
|
239
|
+
With it enabled, the Global row in the Memory page lets you browse `_global` directly:
|
|
240
|
+
|
|
241
|
+

|
|
242
|
+
|
|
243
|
+
## Development
|
|
244
|
+
|
|
245
|
+
Zero dependencies, zero build step: the published artifact is the source.
|
|
246
|
+
|
|
247
|
+
```sh
|
|
248
|
+
npm run check # node --check
|
|
249
|
+
npm test # node --test (runs without DSH installed)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`src/host/*.mjs` must not import any `@deepseek-ai/*`, so CI does not need the harness; all DSH assembly lives in `index.js`.
|
|
253
|
+
|
|
254
|
+
## Roadmap
|
|
255
|
+
|
|
256
|
+
- [x] Note storage, the two tools, and the system-prompt section
|
|
257
|
+
- [x] End-of-turn extraction and on-demand recall
|
|
258
|
+
- [x] Right-sidebar Memory page (spaces / timeline / detail)
|
|
259
|
+
- [x] `/dream` cross-session consolidation (merge, correct, prune)
|
|
260
|
+
- [x] Global memory space (shared by all workspaces, off by default)
|
|
261
|
+
- [x] Automatic dream (24h / 5-session gates, safe merges)
|
|
262
|
+
- [x] Optional LLM recall (falls back to lexical)
|
|
263
|
+
- [x] Consolidation through a tool-capable subagent (checks code, surfaces conflicts, snapshots and rolls back writes)
|
|
264
|
+
- [ ] Jump from a note to its source session (the host has no public client API for selecting a session yet)
|
|
265
|
+
|
|
266
|
+
## License
|
|
267
|
+
|
|
268
|
+
Apache-2.0
|