dsh-memsearch-community 0.2.1 → 0.2.3

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 (3) hide show
  1. package/README.md +21 -0
  2. package/lib/index.js +40 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -12,6 +12,27 @@ computed locally with ONNX.
12
12
 
13
13
  ## Changes from upstream
14
14
 
15
+ **0.2.3 — keep reply headings out of the journal structure**
16
+
17
+ The journal uses `### HH:MM` lines as separators and `memsearch index` splits
18
+ markdown on headings. An assistant reply containing `### Something` therefore
19
+ looked like a new journal entry with a heading where the timestamp belongs,
20
+ fragmenting one exchange into several phantom entries. Captured text now escapes
21
+ leading `#` characters (`\###` renders as `###`), so only the plugin's own
22
+ timestamp lines remain headings.
23
+
24
+ **0.2.2 — capture actually runs**
25
+
26
+ DSH's `Session` class exposes its log through `snapshotEvents()`, `ownEvents()`
27
+ and `eventAt()`; it has no `events` property. The upstream capture handler
28
+ guarded on `session.events`, so the guard was always false and **no turn was ever
29
+ journaled** on current DSH releases — journals only ever contained hand-written
30
+ test entries.
31
+
32
+ The plugin now reads the log through `snapshotEvents()` with fallbacks to
33
+ `ownEvents()` and the legacy `events` array, so capture works on both current
34
+ and older builds.
35
+
15
36
  **0.2.1 — capture the real prompt**
16
37
 
17
38
  DeepSeek Harness delivers injected context as ordinary `user/message` events:
package/lib/index.js CHANGED
@@ -172,6 +172,26 @@ function messageOf(data) {
172
172
  /** Blocks the harness injects into the conversation; never a real user prompt. */
173
173
  const INJECTED_TEXT = /^\s*(<system-reminder>|Time sampled while preparing)/;
174
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
+
175
195
  /**
176
196
  * The last exchange of the session: the newest genuine user prompt plus the
177
197
  * final assistant reply that follows it.
@@ -184,7 +204,7 @@ const INJECTED_TEXT = /^\s*(<system-reminder>|Time sampled while preparing)/;
184
204
  function extractExchange(session) {
185
205
  let userText = "";
186
206
  let userSeq = -1;
187
- const events = Array.isArray(session.events) ? session.events : [];
207
+ const events = sessionEvents(session);
188
208
  for (let i = 0; i < events.length; i++) {
189
209
  const event = events[i];
190
210
  if (!event || typeof event !== "object" || event.type !== "user/message") continue;
@@ -244,6 +264,19 @@ function createStatusMessage(text) {
244
264
  };
245
265
  }
246
266
 
267
+ /**
268
+ * Neutralise markdown headings inside captured text.
269
+ *
270
+ * The journal uses `### HH:MM` lines as its own separators, and `memsearch index`
271
+ * splits markdown on headings. An assistant reply containing `### Something`
272
+ * therefore produced phantom journal entries with a heading where the timestamp
273
+ * belongs. Escaping the leading `#` keeps the text readable (`\### foo` renders
274
+ * as `### foo`) while leaving the heading structure to the journal itself.
275
+ */
276
+ function defuseHeadings(text) {
277
+ return String(text).replace(/^(#{1,6})(\s)/gm, "\\$1$2");
278
+ }
279
+
247
280
  async function captureTurn(config, memoryDir, session, state) {
248
281
  try {
249
282
  const { userText, assistantText, assistantSeq } = extractExchange(session);
@@ -252,11 +285,12 @@ async function captureTurn(config, memoryDir, session, state) {
252
285
  if (state.lastCaptured.get(session.id) === assistantSeq) return; // already captured
253
286
  state.lastCaptured.set(session.id, assistantSeq);
254
287
 
255
- let summary = `=== Final exchange, authoritative for outcome ===\n[User]: ${truncate(userText, config.maxCaptureChars)}\n[DSH]: ${truncate(assistantText || "(no text)", config.maxCaptureChars)}`;
288
+ const body = `[User]: ${truncate(userText, config.maxCaptureChars)}\n[DSH]: ${truncate(assistantText || "(no text)", config.maxCaptureChars)}`;
289
+ let summary = `=== Final exchange, authoritative for outcome ===\n${defuseHeadings(body)}`;
256
290
 
257
291
  if (config.summarizePlugin && resolveCli()) {
258
292
  const res = await runMemsearch(["summarize", "--plugin", config.summarizePlugin, "--agent-name", "DSH"], { input: summary });
259
- if (!res.err && res.stdout.trim()) summary = res.stdout.trim();
293
+ if (!res.err && res.stdout.trim()) summary = defuseHeadings(res.stdout.trim());
260
294
  }
261
295
 
262
296
  mkdirSync(memoryDir, { recursive: true });
@@ -316,8 +350,8 @@ function apply(ctx, config) {
316
350
  if (config.capture) {
317
351
  ctx.on("session/event", (session, event) => {
318
352
  try {
319
- if (!event || event.type !== "turn/end") return;
320
- if (session && session.events) captureTurn(config, memoryDir, session, state);
353
+ if (!event || event.type !== "turn/end" || !session) return;
354
+ captureTurn(config, memoryDir, session, state);
321
355
  } catch (err) {
322
356
  console.error(`[dsh-memsearch] session/event failed: ${err && err.message ? err.message : String(err)}`);
323
357
  }
@@ -325,4 +359,4 @@ function apply(ctx, config) {
325
359
  }
326
360
  }
327
361
 
328
- export { Config, apply, extractExchange, inject, name };
362
+ export { Config, apply, defuseHeadings, extractExchange, inject, name };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-memsearch-community",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
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",