dsh-memsearch-community 0.3.1 → 0.3.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 +10 -0
- package/lib/dialogs.js +30 -9
- package/lib/index.js +9 -5
- package/lib/tree.js +7 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,16 @@ computed locally with ONNX.
|
|
|
12
12
|
|
|
13
13
|
## Changes from upstream
|
|
14
14
|
|
|
15
|
+
**0.3.2 — edge cases found in review**
|
|
16
|
+
|
|
17
|
+
- A state file that is valid JSON but lacks `flags`/`sessions` crashed plugin
|
|
18
|
+
startup (`state.flags.dataRootAsked` on undefined). The state is normalised on
|
|
19
|
+
load, so hand-edited or older files no longer break activation.
|
|
20
|
+
- Windows dialogs now run from a BOM-prefixed `.ps1` instead of `-Command`, so
|
|
21
|
+
Chinese text reaches the native message box intact.
|
|
22
|
+
- Installing the CLI no longer blocks the first turn: `pip install` runs in the
|
|
23
|
+
background and the result is logged.
|
|
24
|
+
|
|
15
25
|
**0.3.1 — robust home directory and CLI detection**
|
|
16
26
|
|
|
17
27
|
- Launchers can hand the process a mojibake `USERPROFILE`, which pointed the
|
package/lib/dialogs.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
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
|
+
import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
13
13
|
import os from "node:os";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
|
|
@@ -25,15 +25,36 @@ function run(command, args) {
|
|
|
25
25
|
|
|
26
26
|
const psQuote = (value) => `'${String(value).replace(/'/g, "''")}'`;
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Run a PowerShell script from a UTF-8 file.
|
|
30
|
+
*
|
|
31
|
+
* Passing Chinese through `-Command` depends on the console code page and can
|
|
32
|
+
* arrive mojibake; a BOM-prefixed `.ps1` hands the text to PowerShell as UTF-8.
|
|
33
|
+
*/
|
|
34
|
+
async function runPowerShell(script) {
|
|
35
|
+
const dir = mkdtempSync(join(os.tmpdir(), "dsh-memsearch-dialog-"));
|
|
36
|
+
const file = join(dir, "dialog.ps1");
|
|
37
|
+
try {
|
|
38
|
+
writeFileSync(file, "\uFEFF" + script, "utf8");
|
|
39
|
+
return await run("powershell.exe", ["-NoProfile", "-STA", "-ExecutionPolicy", "Bypass", "-File", file]);
|
|
40
|
+
} finally {
|
|
41
|
+
try {
|
|
42
|
+
rmSync(dir, { recursive: true, force: true });
|
|
43
|
+
} catch {
|
|
44
|
+
/* temp dir cleanup is best effort */
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
28
49
|
/** Yes/No message box. Resolves { ok, answer: true|false } or { ok: false, reason }. */
|
|
29
50
|
export async function askYesNo({ title, message, yes = "是", no = "否" }) {
|
|
30
51
|
if (process.platform === "win32") {
|
|
31
52
|
const script = [
|
|
32
53
|
"Add-Type -AssemblyName System.Windows.Forms | Out-Null",
|
|
33
|
-
`$r = [System.Windows.Forms.MessageBox]::Show(${psQuote(message)}, ${psQuote(title)}, 'YesNo', 'Question', 'Button1'
|
|
34
|
-
"if ($r -eq 'Yes') { 'YES' } else { 'NO' }",
|
|
35
|
-
].join("
|
|
36
|
-
const res = await
|
|
54
|
+
`$r = [System.Windows.Forms.MessageBox]::Show(${psQuote(message)}, ${psQuote(title)}, 'YesNo', 'Question', 'Button1')`,
|
|
55
|
+
"if ($r -eq 'Yes') { Write-Output 'YES' } else { Write-Output 'NO' }",
|
|
56
|
+
].join("\n");
|
|
57
|
+
const res = await runPowerShell(script);
|
|
37
58
|
if (res.err) return { ok: false, reason: res.err.message };
|
|
38
59
|
const out = res.stdout.trim();
|
|
39
60
|
if (out === "YES") return { ok: true, answer: true };
|
|
@@ -59,10 +80,10 @@ export async function pickFolder({ title, initial }) {
|
|
|
59
80
|
"$d = New-Object System.Windows.Forms.FolderBrowserDialog",
|
|
60
81
|
`$d.Description = ${psQuote(title)}`,
|
|
61
82
|
"$d.ShowNewFolderButton = $true",
|
|
62
|
-
initial ?
|
|
63
|
-
"if ($d.ShowDialog() -eq 'OK') { $d.SelectedPath }
|
|
64
|
-
].filter(Boolean).join("
|
|
65
|
-
const res = await
|
|
83
|
+
initial ? `if (Test-Path ${psQuote(initial)}) { $d.SelectedPath = ${psQuote(initial)} }` : "",
|
|
84
|
+
"if ($d.ShowDialog() -eq 'OK') { Write-Output $d.SelectedPath }",
|
|
85
|
+
].filter(Boolean).join("\n");
|
|
86
|
+
const res = await runPowerShell(script);
|
|
66
87
|
if (res.err) return { ok: false, reason: res.err.message };
|
|
67
88
|
const picked = res.stdout.trim();
|
|
68
89
|
return picked ? { ok: true, path: picked } : { ok: false, reason: "cancelled" };
|
package/lib/index.js
CHANGED
|
@@ -356,17 +356,21 @@ async function runSetup(config, archive, log) {
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
if (!archive.countsAsFlag("cliOffered") && !resolveCli()) {
|
|
359
|
+
// Never block the session on a package install: kick it off and report later.
|
|
360
|
+
const startInstall = () => {
|
|
361
|
+
installCli().then((res) => {
|
|
362
|
+
log(res.ok ? `[memsearch] CLI 已安装: ${res.cli}` : `[memsearch] CLI 安装失败: ${res.reason}`);
|
|
363
|
+
});
|
|
364
|
+
};
|
|
359
365
|
if (config.autoInstallCli) {
|
|
360
|
-
|
|
361
|
-
log(res.ok ? `[memsearch] CLI 已安装: ${res.cli}` : `[memsearch] CLI 安装失败: ${res.reason}`);
|
|
366
|
+
startInstall();
|
|
362
367
|
} else if (config.offerCliInstall) {
|
|
363
368
|
const answer = await askYesNo({
|
|
364
369
|
title: "是否安装检索命令行工具?",
|
|
365
|
-
message: "memsearch CLI 负责把记录变成可语义检索的索引。\n不装也能用:对话仍会按日期归档成 txt。\n装好后可以用「上次我们聊的…」这类提问翻旧账。\n\n现在安装吗?(约需 Python 3.10
|
|
370
|
+
message: "memsearch CLI 负责把记录变成可语义检索的索引。\n不装也能用:对话仍会按日期归档成 txt。\n装好后可以用「上次我们聊的…」这类提问翻旧账。\n\n现在安装吗?(约需 Python 3.10+,后台进行)",
|
|
366
371
|
});
|
|
367
372
|
if (answer.ok && answer.answer) {
|
|
368
|
-
|
|
369
|
-
log(res.ok ? `[memsearch] CLI 已安装: ${res.cli}` : `[memsearch] CLI 安装失败: ${res.reason}`);
|
|
373
|
+
startInstall();
|
|
370
374
|
} else {
|
|
371
375
|
log("[memsearch] 用户暂不安装 CLI");
|
|
372
376
|
archive.setFlag("cliDeclined", true);
|
package/lib/tree.js
CHANGED
|
@@ -40,7 +40,13 @@ export class Archive {
|
|
|
40
40
|
|
|
41
41
|
#load() {
|
|
42
42
|
try {
|
|
43
|
-
|
|
43
|
+
const parsed = JSON.parse(readFileSync(this.statePath, "utf8"));
|
|
44
|
+
const state = parsed && typeof parsed === "object" ? parsed : {};
|
|
45
|
+
// A hand-edited or older state file may lack either container; normalise
|
|
46
|
+
// so callers can index into `sessions` and `flags` without guarding.
|
|
47
|
+
if (!state.sessions || typeof state.sessions !== "object") state.sessions = {};
|
|
48
|
+
if (!state.flags || typeof state.flags !== "object") state.flags = {};
|
|
49
|
+
return state;
|
|
44
50
|
} catch {
|
|
45
51
|
return { sessions: {}, flags: {} };
|
|
46
52
|
}
|
|
@@ -152,19 +158,6 @@ export class Archive {
|
|
|
152
158
|
}
|
|
153
159
|
}
|
|
154
160
|
|
|
155
|
-
/** Delete a day folder. */
|
|
156
|
-
removeDay(day) {
|
|
157
|
-
const dir = join(this.root, day);
|
|
158
|
-
try {
|
|
159
|
-
for (const f of readdirSync(dir)) {
|
|
160
|
-
try { renameSync(join(dir, f), join(dir, f)); } catch {}
|
|
161
|
-
}
|
|
162
|
-
return dir;
|
|
163
|
-
} catch {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
161
|
#pruneEmpty(oldPath) {
|
|
169
162
|
try {
|
|
170
163
|
const dir = oldPath.slice(0, oldPath.lastIndexOf("\\") >= 0 ? oldPath.lastIndexOf("\\") : oldPath.lastIndexOf("/"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-memsearch-community",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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",
|