dsh-memsearch-community 0.3.4 → 0.3.5

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 +14 -0
  2. package/lib/tree.js +58 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -12,6 +12,20 @@ computed locally with ONNX.
12
12
 
13
13
  ## Changes from upstream
14
14
 
15
+ **0.3.5 — one file per session, and renames never overwrite**
16
+
17
+ Two sessions can share a title on the same day. They used to append into a
18
+ single file, and a rename could even replace another session's file — on Windows
19
+ `rename` overwrites silently, which destroyed data. Names are now claimed per
20
+ session (`周报.txt`, `周报 (2).txt`), a rename picks a free name, and an existing
21
+ target aborts the rename instead of clobbering it.
22
+
23
+ **0.3.4 — escape timestamp-like lines in archived text**
24
+
25
+ A reply that quoted a line such as `[2026.12.04 09:00]` looked like a turn
26
+ boundary and split one exchange into several when the archive was parsed.
27
+ Captured text now escapes a leading timestamp.
28
+
15
29
  **0.3.3 — no duplicate rows from continuation turns**
16
30
 
17
31
  A continuation turn (goal round, steered re-run) ends without a new user
package/lib/tree.js CHANGED
@@ -118,6 +118,29 @@ export class Archive {
118
118
  }
119
119
  }
120
120
 
121
+ /**
122
+ * Pick the file a session owns inside `dir` for `base`.
123
+ *
124
+ * One file per session per day: when another session already claimed the name,
125
+ * fall back to `base (2).txt`, `base (3).txt`, and so on instead of appending
126
+ * two conversations into one file. `selfPath` is the caller's current file: it
127
+ * counts as free because the caller is about to move away from it.
128
+ */
129
+ #claimName(dir, base, sessionId, selfPath) {
130
+ const owner = new Map();
131
+ for (const [id, record] of Object.entries(this.state.sessions)) {
132
+ if (record && record.path) owner.set(record.path, id);
133
+ }
134
+ for (let n = 1; n < 1000; n++) {
135
+ const candidate = join(dir, n === 1 ? `${base}.txt` : `${base} (${n}).txt`);
136
+ if (candidate === selfPath) return candidate;
137
+ if (!existsSync(candidate)) return candidate;
138
+ const holder = owner.get(candidate);
139
+ if (holder === undefined || holder === sessionId) return candidate;
140
+ }
141
+ return join(dir, `${base} (${Date.now()}).txt`);
142
+ }
143
+
121
144
  /**
122
145
  * Append one exchange. Returns the file path, renaming an existing file when
123
146
  * the session title changed since the last write.
@@ -127,15 +150,27 @@ export class Archive {
127
150
  const day = dayName(date);
128
151
  const dir = this.dayDir(day);
129
152
  const base = safeFileBase(title, `会话-${String(sessionId).slice(-6)}`);
130
- const target = join(dir, `${base}.txt`);
131
153
 
132
154
  const record = this.state.sessions[sessionId];
133
- if (record && record.path !== target && existsSync(record.path) && !existsSync(target)) {
134
- try {
135
- renameSync(record.path, target);
136
- this.#pruneEmpty(record.path);
137
- } catch {
138
- /* leave the old file in place */
155
+ let target = this.#claimName(dir, base, sessionId);
156
+
157
+ // The session already owns a file from earlier today; keep appending to it,
158
+ // renaming only when the title changed.
159
+ if (record && record.day === day && existsSync(record.path)) {
160
+ const desired = target;
161
+ if (record.path !== desired) {
162
+ try {
163
+ if (!existsSync(desired)) {
164
+ renameSync(record.path, desired);
165
+ target = desired;
166
+ } else {
167
+ target = record.path;
168
+ }
169
+ } catch {
170
+ target = record.path;
171
+ }
172
+ } else {
173
+ target = record.path;
139
174
  }
140
175
  }
141
176
 
@@ -156,18 +191,25 @@ export class Archive {
156
191
  const record = this.state.sessions[sessionId];
157
192
  if (!record || !existsSync(record.path)) return null;
158
193
  const dir = join(this.root, record.day);
159
- const target = join(dir, `${safeFileBase(title, `会话-${String(sessionId).slice(-6)}`)}.txt`);
160
- if (target === record.path) return record.path;
161
- try {
162
- if (existsSync(target)) return record.path; // keep both rather than overwrite
163
- renameSync(record.path, target);
164
- record.path = target;
165
- record.title = title;
194
+ const base = safeFileBase(title, `会话-${String(sessionId).slice(-6)}`);
195
+ const previous = record.path;
196
+ const target = this.#claimName(dir, base, sessionId, previous);
197
+ if (target === previous) {
198
+ record.title = base;
166
199
  this.save();
167
- return target;
200
+ return previous;
201
+ }
202
+ // Never let a rename replace another session's file: Windows overwrites.
203
+ if (existsSync(target)) return previous;
204
+ try {
205
+ renameSync(previous, target);
168
206
  } catch {
169
- return record.path;
207
+ return previous;
170
208
  }
209
+ record.path = target;
210
+ record.title = base;
211
+ this.save();
212
+ return target;
171
213
  }
172
214
 
173
215
  #pruneEmpty(oldPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-memsearch-community",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Automatic local memory for DeepSeek Harness: per-day conversation archive by session title, semantic search index, first-run setup prompts, optional history import.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",