dsh-memsearch-community 0.5.0 → 0.5.1

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 CHANGED
@@ -15,6 +15,15 @@ computed locally with ONNX.
15
15
 
16
16
  ## Changes from upstream
17
17
 
18
+ **0.5.1 — existing archives are renumbered automatically**
19
+
20
+ Archives written before 0.5.0 named every day's file after the title, so a
21
+ session spanning three days had three identical names. On first start the plugin
22
+ now discovers the days of each recorded session, renames the files to the
23
+ day-numbered scheme (`标题`, `标题(2)`, `标题(3)`), and adds the retrieval hint
24
+ to the continuations. It runs once, never overwrites an existing file, and is a
25
+ no-op afterwards.
26
+
18
27
  **0.5.0 — day numbering, overflow volumes and retrieval hints**
19
28
 
20
29
  A session that spans several days keeps counting instead of restarting:
package/lib/index.js CHANGED
@@ -465,10 +465,13 @@ function apply(ctx, config) {
465
465
  const log = (message) => console.error(message);
466
466
 
467
467
  // Upgrading from the flat layout (`<day>/<title>.txt`) moves those files into
468
- // their session folder once; later starts are no-ops.
468
+ // their session folder once; later starts are no-ops. The second call renumbers
469
+ // archives written before the day/volume scheme existed.
469
470
  try {
470
471
  const moved = archive.migrateLayout();
471
472
  if (moved) log(`[memsearch] 归档结构迁移: ${moved} 个文件移入会话文件夹`);
473
+ const renumbered = archive.migrateDayNaming();
474
+ if (renumbered) log(`[memsearch] 归档编号迁移: ${renumbered} 个文件按天数重新编号`);
472
475
  } catch (err) {
473
476
  log(`[memsearch] 归档迁移失败: ${err && err.message ? err.message : String(err)}`);
474
477
  }
package/lib/tree.js CHANGED
@@ -367,6 +367,84 @@ export class Archive {
367
367
  return currentPath;
368
368
  }
369
369
 
370
+ /**
371
+ * Bring archives written before 0.5.0 up to the day-numbering scheme.
372
+ *
373
+ * Sessions recorded by older versions have no `days` map, so the day folders
374
+ * are discovered by title: every day that holds a folder with that name is one
375
+ * day of the session, in date order. Files already named for a later day are
376
+ * left alone, and nothing is overwritten.
377
+ */
378
+ migrateDayNaming() {
379
+ if (this.countsAsFlag("dayNamingMigrated")) return 0;
380
+ const days = this.listDays();
381
+ let changed = 0;
382
+
383
+ for (const [sessionId, record] of Object.entries(this.state.sessions)) {
384
+ const base = record.title || (record.folder ? basename(record.folder) : null);
385
+ if (!base) continue;
386
+ const present = days.filter((day) => existsSync(join(this.root, day, base)));
387
+ if (!present.length) continue;
388
+
389
+ present.forEach((day, index) => {
390
+ const dayIndex = index + 1;
391
+ const dir = join(this.root, day, base);
392
+ let names;
393
+ try {
394
+ names = readdirSync(dir);
395
+ } catch {
396
+ return;
397
+ }
398
+ for (const name of names) {
399
+ const slot = parseVolume(name, base);
400
+ if (!slot) continue;
401
+ const target = join(dir, volumeName(base, dayIndex, slot.volume));
402
+ if (target === join(dir, name)) {
403
+ // already correct; only make sure a continuation carries its hint
404
+ if (dayIndex > 1 || slot.volume > 0) this.#ensureHint(target, dayIndex, slot.volume);
405
+ continue;
406
+ }
407
+ if (existsSync(target)) continue;
408
+ try {
409
+ renameSync(join(dir, name), target);
410
+ changed++;
411
+ if (dayIndex > 1 || slot.volume > 0) this.#ensureHint(target, dayIndex, slot.volume);
412
+ } catch {
413
+ /* leave it in place */
414
+ }
415
+ }
416
+ });
417
+
418
+ const folders = {};
419
+ for (const day of present) folders[day] = join(this.root, day, base);
420
+ const lastDay = present[present.length - 1];
421
+ const volumes = this.volumes(lastDay, base);
422
+ this.state.sessions[sessionId] = {
423
+ ...record,
424
+ title: base,
425
+ day: lastDay,
426
+ days: present,
427
+ folder: folders[lastDay],
428
+ path: volumes.length ? volumes[volumes.length - 1] : join(folders[lastDay], volumeName(base, present.length, 0)),
429
+ folders,
430
+ };
431
+ }
432
+
433
+ this.setFlag("dayNamingMigrated", true);
434
+ this.save();
435
+ return changed;
436
+ }
437
+
438
+ #ensureHint(file, dayIndex, volume) {
439
+ try {
440
+ const text = readFileSync(file, "utf8");
441
+ if (text.startsWith("【检索指引】")) return;
442
+ writeFileSync(file, continuationHint(dayIndex, volume) + text, "utf8");
443
+ } catch {
444
+ /* best effort */
445
+ }
446
+ }
447
+
370
448
  /** Move files written by the flat layout into the folder layout. */
371
449
  migrateLayout() {
372
450
  if (this.countsAsFlag("layoutMigrated")) return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-memsearch-community",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Automatic local memory for DeepSeek Harness: per-day, per-session conversation archive with numbered volumes, semantic search index, first-run setup prompts, optional history import.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",