dsh-memsearch-community 0.3.0 → 0.3.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
@@ -12,6 +12,16 @@ computed locally with ONNX.
12
12
 
13
13
  ## Changes from upstream
14
14
 
15
+ **0.3.1 — robust home directory and CLI detection**
16
+
17
+ - Launchers can hand the process a mojibake `USERPROFILE`, which pointed the
18
+ archive at a path like `C:\Users\??\Documents\...` that does not exist. The
19
+ plugin now prefers the first home candidate that is a real directory, and a
20
+ folder chosen in the picker is persisted and reused on the next start.
21
+ - CLI detection also scans known install locations (`pip install --user`
22
+ Scripts, `%APPDATA%\Python\Python3xx\Scripts`, DSH's bundled runtime) instead
23
+ of relying on the inherited `PATH`, which did not always contain them.
24
+
15
25
  **0.3.0 — first-run setup, per-day archive, history import**
16
26
 
17
27
  - **Setup prompts.** On first run the plugin asks three things with native
package/lib/dialogs.js CHANGED
@@ -9,7 +9,9 @@
9
9
  * back to configuration or a session message.
10
10
  */
11
11
  import { execFile } from "node:child_process";
12
+ import { existsSync } from "node:fs";
12
13
  import os from "node:os";
14
+ import { join } from "node:path";
13
15
 
14
16
  const DIALOG_TIMEOUT = 180000;
15
17
 
@@ -83,5 +85,24 @@ export async function openFolder(path) {
83
85
  }
84
86
 
85
87
  export function defaultDataRoot() {
86
- return `${os.homedir()}\\Documents\\DSH对话数据`.replace(/\\/g, process.platform === "win32" ? "\\" : "/");
88
+ return join(realHome(), "Documents", "DSH对话数据");
89
+ }
90
+
91
+ /**
92
+ * Home directory that actually exists on disk.
93
+ *
94
+ * Launchers can hand the process a mojibake `USERPROFILE`; `os.homedir()` then
95
+ * points at a path like `C:\Users\??\...` that was never created.
96
+ */
97
+ export function realHome() {
98
+ const candidates = [process.env.USERPROFILE, process.env.HOME, os.homedir()].filter(Boolean);
99
+ for (const candidate of candidates) {
100
+ if (/[\uFFFD]/.test(candidate)) continue;
101
+ try {
102
+ if (existsSync(candidate)) return candidate;
103
+ } catch {
104
+ /* keep looking */
105
+ }
106
+ }
107
+ return os.homedir();
87
108
  }
package/lib/index.js CHANGED
@@ -55,6 +55,18 @@ const MS_STATUS_TIMEOUT = 15000;
55
55
  const MAX_BUFFER = 8 * 1024 * 1024;
56
56
 
57
57
  function home() {
58
+ // Some launchers hand the process a mojibake USERPROFILE (CP936 bytes decoded
59
+ // as UTF-8), which produces paths like `C:\Users\??\...` that do not exist.
60
+ // Prefer the first candidate that is a real directory.
61
+ const candidates = [process.env.USERPROFILE, process.env.HOME, os.homedir()].filter(Boolean);
62
+ for (const candidate of candidates) {
63
+ if (/[\uFFFD]/.test(candidate)) continue;
64
+ try {
65
+ if (existsSync(candidate)) return candidate;
66
+ } catch {
67
+ /* keep looking */
68
+ }
69
+ }
58
70
  return os.homedir();
59
71
  }
60
72
 
@@ -83,12 +95,66 @@ function memsearchEnv() {
83
95
  return env;
84
96
  }
85
97
 
98
+ /**
99
+ * Directories worth scanning for the CLI, beyond the inherited PATH.
100
+ *
101
+ * DSH's own bundled Python installs console scripts into a directory that is not
102
+ * always on the process PATH, and `pip install --user` lands in a per-user
103
+ * Scripts folder. Scanning these explicitly keeps detection working whichever
104
+ * way the CLI was installed.
105
+ */
106
+ function cliDirs() {
107
+ const dirs = [];
108
+ const push = (dir) => {
109
+ if (!dir) return;
110
+ try {
111
+ if (existsSync(dir)) dirs.push(dir);
112
+ } catch {
113
+ /* ignore */
114
+ }
115
+ };
116
+
117
+ for (const dir of (memsearchEnv().PATH || "").split(pathSep())) push(dir);
118
+
119
+ const appData = process.env.APPDATA;
120
+ const localAppData = process.env.LOCALAPPDATA;
121
+ const base = home();
122
+ push(path.join(base, ".local", "bin"));
123
+ push(path.join(base, ".cargo", "bin"));
124
+ push(path.join(localAppData || "", "Programs", "Python", "Launcher"));
125
+
126
+ // %APPDATA%\Python\Python3xx\Scripts
127
+ for (const root of [appData, localAppData].filter(Boolean)) {
128
+ const pythonRoot = path.join(root, "Python");
129
+ try {
130
+ for (const entry of readdirSync(pythonRoot)) {
131
+ if (/^Python3/i.test(entry)) push(path.join(pythonRoot, entry, "Scripts"));
132
+ }
133
+ } catch {
134
+ /* no python root */
135
+ }
136
+ const programs = path.join(root, "Programs", "Python");
137
+ try {
138
+ for (const entry of readdirSync(programs)) push(path.join(programs, entry, "Scripts"));
139
+ } catch {
140
+ /* not installed there */
141
+ }
142
+ }
143
+
144
+ // DSH's bundled runtime
145
+ const harness = path.join(localAppData || "", "Programs", "DeepSeek Harness", "resources", "runtime");
146
+ for (const sub of ["primary-runtime", "cli"]) {
147
+ push(path.join(harness, sub, "dependencies", "python", "Scripts"));
148
+ }
149
+
150
+ return [...new Set(dirs)];
151
+ }
152
+
86
153
  let cliCache;
87
154
  function resolveCli() {
88
155
  if (cliCache !== undefined) return cliCache;
89
- const env = memsearchEnv();
90
156
  const candidates = ["memsearch", "memsearch.exe", "memsearch.cmd", "memsearch.bat"];
91
- for (const dir of (env.PATH || "").split(pathSep()).filter(Boolean)) {
157
+ for (const dir of cliDirs()) {
92
158
  for (const cand of candidates) {
93
159
  const full = path.join(dir, cand);
94
160
  if (existsSync(full)) {
@@ -284,10 +350,8 @@ async function runSetup(config, archive, log) {
284
350
  const picked = await pickFolder({ title: "选择 DSH 对话数据的保存位置", initial: path.dirname(archive.root) });
285
351
  archive.setFlag("dataRootAsked");
286
352
  if (picked.ok && picked.path) {
287
- archive.root = picked.path;
288
- archive.statePath = path.join(picked.path, ".dsh-memsearch-state.json");
289
- archive.ensureRoot();
290
- archive.setFlag("dataRootAsked");
353
+ archive.relocate(picked.path);
354
+ archive.setFlag("dataRoot", picked.path);
291
355
  }
292
356
  }
293
357
 
@@ -358,6 +422,12 @@ async function checkRetention(config, archive, log) {
358
422
  function archiveFor(config) {
359
423
  const root = config.dataRoot ? expandPath(config.dataRoot) : defaultDataRoot();
360
424
  const archive = new Archive(root);
425
+ // A folder picked in a previous run wins over the computed default, which can
426
+ // be wrong when the launcher hands the process a mojibake home directory.
427
+ const saved = archive.state && archive.state.flags && archive.state.flags.dataRoot;
428
+ if (!config.dataRoot && saved && saved !== root) {
429
+ archive.relocate(saved);
430
+ }
361
431
  if (config.dataRoot && !archive.state.flags.dataRootAsked) {
362
432
  archive.setFlag("dataRootAsked");
363
433
  }
@@ -478,4 +548,4 @@ function apply(ctx, config) {
478
548
  });
479
549
  }
480
550
 
481
- export { Config, Archive, apply, defuseHeadings, extractExchange, importHistory, name, sessionEvents, sessionTitle };
551
+ export { Config, Archive, apply, defuseHeadings, extractExchange, importHistory, name, resolveCli, sessionEvents, sessionTitle };
package/lib/tree.js CHANGED
@@ -55,6 +55,20 @@ export class Archive {
55
55
  }
56
56
  }
57
57
 
58
+ /** Point the archive at another root, keeping the flags already recorded. */
59
+ relocate(root) {
60
+ const previous = this.state;
61
+ this.root = root;
62
+ this.statePath = join(root, ".dsh-memsearch-state.json");
63
+ this.state = this.#load();
64
+ if (previous && previous.flags) {
65
+ this.state.flags = { ...previous.flags, ...(this.state.flags || {}) };
66
+ }
67
+ this.ensureRoot();
68
+ this.save();
69
+ return this.root;
70
+ }
71
+
58
72
  ensureRoot() {
59
73
  mkdirSync(this.root, { recursive: true });
60
74
  return this.root;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-memsearch-community",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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",