dsh-memsearch-community 0.2.0 → 0.2.2
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 +34 -0
- package/lib/index.js +56 -18
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,6 +10,40 @@ computed locally with ONNX.
|
|
|
10
10
|
> This is an **unofficial community fork** of `dsh-memsearch` (upstream 0.1.7,
|
|
11
11
|
> MIT). It is not affiliated with the upstream author or with DeepSeek.
|
|
12
12
|
|
|
13
|
+
## Changes from upstream
|
|
14
|
+
|
|
15
|
+
**0.2.2 — capture actually runs**
|
|
16
|
+
|
|
17
|
+
DSH's `Session` class exposes its log through `snapshotEvents()`, `ownEvents()`
|
|
18
|
+
and `eventAt()`; it has no `events` property. The upstream capture handler
|
|
19
|
+
guarded on `session.events`, so the guard was always false and **no turn was ever
|
|
20
|
+
journaled** on current DSH releases — journals only ever contained hand-written
|
|
21
|
+
test entries.
|
|
22
|
+
|
|
23
|
+
The plugin now reads the log through `snapshotEvents()` with fallbacks to
|
|
24
|
+
`ownEvents()` and the legacy `events` array, so capture works on both current
|
|
25
|
+
and older builds.
|
|
26
|
+
|
|
27
|
+
**0.2.1 — capture the real prompt**
|
|
28
|
+
|
|
29
|
+
DeepSeek Harness delivers injected context as ordinary `user/message` events:
|
|
30
|
+
`runtime-context`, `time-context`, `skill-catalog`, `model-selection` and the
|
|
31
|
+
plugin's own status line. Upstream skipped only `source.kind === "plugin"`, so
|
|
32
|
+
every journal entry began with harness boilerplate such as
|
|
33
|
+
`Time sampled while preparing turn 3, step 1: …` instead of what the user
|
|
34
|
+
actually asked.
|
|
35
|
+
|
|
36
|
+
The extractor now accepts only `source.kind === "user"` (plus messages that
|
|
37
|
+
carry no source at all), rejects text that still looks like an injected block,
|
|
38
|
+
and pairs the prompt with the final assistant reply that follows it.
|
|
39
|
+
|
|
40
|
+
**0.2.0 — installable bundle**
|
|
41
|
+
|
|
42
|
+
Packaged as a DSH bundle: `dsh.bundle.patch`, locale metadata, an icon, and a
|
|
43
|
+
detail document, so the plugin installs by package name instead of a hand-edited
|
|
44
|
+
profile patch. Also: Windows `PATH` handling, and graceful degradation when the
|
|
45
|
+
`memsearch` CLI is missing.
|
|
46
|
+
|
|
13
47
|
## What it does
|
|
14
48
|
|
|
15
49
|
| Behaviour | Detail |
|
package/lib/index.js
CHANGED
|
@@ -169,27 +169,65 @@ function messageOf(data) {
|
|
|
169
169
|
return data;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
/**
|
|
172
|
+
/** Blocks the harness injects into the conversation; never a real user prompt. */
|
|
173
|
+
const INJECTED_TEXT = /^\s*(<system-reminder>|Time sampled while preparing)/;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Committed events of a session.
|
|
177
|
+
*
|
|
178
|
+
* DSH exposes the log through `snapshotEvents()`; older builds also carried a
|
|
179
|
+
* plain `events` array. Reading only `session.events` silently disabled capture
|
|
180
|
+
* on current releases, because that property no longer exists.
|
|
181
|
+
*/
|
|
182
|
+
function sessionEvents(session) {
|
|
183
|
+
if (!session) return [];
|
|
184
|
+
if (typeof session.snapshotEvents === "function") {
|
|
185
|
+
const events = session.snapshotEvents();
|
|
186
|
+
return Array.isArray(events) ? events : [];
|
|
187
|
+
}
|
|
188
|
+
if (typeof session.ownEvents === "function") {
|
|
189
|
+
const events = session.ownEvents();
|
|
190
|
+
return Array.isArray(events) ? events : [];
|
|
191
|
+
}
|
|
192
|
+
return Array.isArray(session.events) ? session.events : [];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The last exchange of the session: the newest genuine user prompt plus the
|
|
197
|
+
* final assistant reply that follows it.
|
|
198
|
+
*
|
|
199
|
+
* Injected context reaches the session as ordinary `user/message` events, so
|
|
200
|
+
* `source.kind` decides what counts: only `kind: "user"` (and a message with no
|
|
201
|
+
* source at all) is a real prompt. Everything else — `plugin`, `runtime-context`,
|
|
202
|
+
* `time-context`, `skill-catalog`, `model-selection` — is skipped.
|
|
203
|
+
*/
|
|
173
204
|
function extractExchange(session) {
|
|
174
205
|
let userText = "";
|
|
206
|
+
let userSeq = -1;
|
|
207
|
+
const events = sessionEvents(session);
|
|
208
|
+
for (let i = 0; i < events.length; i++) {
|
|
209
|
+
const event = events[i];
|
|
210
|
+
if (!event || typeof event !== "object" || event.type !== "user/message") continue;
|
|
211
|
+
const source = event.data && event.data.source;
|
|
212
|
+
if (source && source.kind !== "user") continue; // injected context or our own status line
|
|
213
|
+
const text = textOf(messageOf(event.data));
|
|
214
|
+
if (!text || INJECTED_TEXT.test(text)) continue;
|
|
215
|
+
userText = text;
|
|
216
|
+
userSeq = typeof event.seq === "number" ? event.seq : i;
|
|
217
|
+
}
|
|
218
|
+
if (!userText) return { userText: "", assistantText: "", assistantSeq: undefined };
|
|
219
|
+
|
|
175
220
|
let assistantText = "";
|
|
176
221
|
let assistantSeq;
|
|
177
|
-
const events = Array.isArray(session.events) ? session.events : [];
|
|
178
222
|
for (let i = events.length - 1; i >= 0; i--) {
|
|
179
223
|
const event = events[i];
|
|
180
|
-
if (!event || typeof event !== "object") continue;
|
|
181
|
-
if (event.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (text) {
|
|
188
|
-
assistantText = text;
|
|
189
|
-
assistantSeq = event.seq;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (userText && assistantSeq !== undefined) break;
|
|
224
|
+
if (!event || typeof event !== "object" || event.type !== "assistant/message") continue;
|
|
225
|
+
if (typeof event.seq === "number" && typeof userSeq === "number" && event.seq < userSeq) continue;
|
|
226
|
+
const text = textOf(messageOf(event.data));
|
|
227
|
+
if (!text) continue;
|
|
228
|
+
assistantText = text;
|
|
229
|
+
assistantSeq = event.seq;
|
|
230
|
+
break;
|
|
193
231
|
}
|
|
194
232
|
return { userText, assistantText, assistantSeq };
|
|
195
233
|
}
|
|
@@ -298,8 +336,8 @@ function apply(ctx, config) {
|
|
|
298
336
|
if (config.capture) {
|
|
299
337
|
ctx.on("session/event", (session, event) => {
|
|
300
338
|
try {
|
|
301
|
-
if (!event || event.type !== "turn/end") return;
|
|
302
|
-
|
|
339
|
+
if (!event || event.type !== "turn/end" || !session) return;
|
|
340
|
+
captureTurn(config, memoryDir, session, state);
|
|
303
341
|
} catch (err) {
|
|
304
342
|
console.error(`[dsh-memsearch] session/event failed: ${err && err.message ? err.message : String(err)}`);
|
|
305
343
|
}
|
|
@@ -307,4 +345,4 @@ function apply(ctx, config) {
|
|
|
307
345
|
}
|
|
308
346
|
}
|
|
309
347
|
|
|
310
|
-
export { Config, apply, inject, name };
|
|
348
|
+
export { Config, apply, extractExchange, inject, name };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-memsearch-community",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Automatic local semantic memory for DeepSeek Harness: journals every turn, indexes it with memsearch, and lets the agent recall earlier sessions. Community fork
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Automatic local semantic memory for DeepSeek Harness: journals every turn, indexes it with memsearch, and lets the agent recall earlier sessions. Community fork that captures only genuine user prompts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|