dsh-memsearch-community 0.3.1 → 0.3.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.
- package/README.md +22 -0
- package/lib/dialogs.js +30 -9
- package/lib/index.js +29 -12
- package/lib/tree.js +7 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,28 @@ computed locally with ONNX.
|
|
|
12
12
|
|
|
13
13
|
## Changes from upstream
|
|
14
14
|
|
|
15
|
+
**0.3.3 — no duplicate rows from continuation turns**
|
|
16
|
+
|
|
17
|
+
A continuation turn (goal round, steered re-run) ends without a new user
|
|
18
|
+
message, but the assistant reply has a fresh event sequence. The old guard only
|
|
19
|
+
compared that sequence, so every continuation journaled the *same* prompt again.
|
|
20
|
+
Capture now tracks the user-message sequence too and skips a turn whose prompt
|
|
21
|
+
has not changed.
|
|
22
|
+
|
|
23
|
+
Also: a missing CLI is re-checked once a minute instead of staying cached until
|
|
24
|
+
the process restarts, and opening the archive folder no longer reports a false
|
|
25
|
+
failure on Windows.
|
|
26
|
+
|
|
27
|
+
**0.3.2 — edge cases found in review**
|
|
28
|
+
|
|
29
|
+
- A state file that is valid JSON but lacks `flags`/`sessions` crashed plugin
|
|
30
|
+
startup (`state.flags.dataRootAsked` on undefined). The state is normalised on
|
|
31
|
+
load, so hand-edited or older files no longer break activation.
|
|
32
|
+
- Windows dialogs now run from a BOM-prefixed `.ps1` instead of `-Command`, so
|
|
33
|
+
Chinese text reaches the native message box intact.
|
|
34
|
+
- Installing the CLI no longer blocks the first turn: `pip install` runs in the
|
|
35
|
+
background and the result is logged.
|
|
36
|
+
|
|
15
37
|
**0.3.1 — robust home directory and CLI detection**
|
|
16
38
|
|
|
17
39
|
- 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
|
@@ -151,8 +151,16 @@ function cliDirs() {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
let cliCache;
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
let cliCheckedAt = 0;
|
|
155
|
+
|
|
156
|
+
function resolveCli(force = false) {
|
|
157
|
+
// A missing CLI is re-checked at most once a minute: installing it outside the
|
|
158
|
+
// plugin must not require restarting the whole Harness.
|
|
159
|
+
if (!force && cliCache !== undefined) {
|
|
160
|
+
if (cliCache) return cliCache;
|
|
161
|
+
if (Date.now() - cliCheckedAt < 60000) return null;
|
|
162
|
+
}
|
|
163
|
+
cliCheckedAt = Date.now();
|
|
156
164
|
const candidates = ["memsearch", "memsearch.exe", "memsearch.cmd", "memsearch.bat"];
|
|
157
165
|
for (const dir of cliDirs()) {
|
|
158
166
|
for (const cand of candidates) {
|
|
@@ -287,7 +295,7 @@ function extractExchange(session) {
|
|
|
287
295
|
assistantSeq = event.seq;
|
|
288
296
|
break;
|
|
289
297
|
}
|
|
290
|
-
return { userText, assistantText, assistantSeq };
|
|
298
|
+
return { userText, assistantText, assistantSeq, userSeq };
|
|
291
299
|
}
|
|
292
300
|
|
|
293
301
|
/** Escape markdown headings so a reply cannot split the journal structure. */
|
|
@@ -356,17 +364,21 @@ async function runSetup(config, archive, log) {
|
|
|
356
364
|
}
|
|
357
365
|
|
|
358
366
|
if (!archive.countsAsFlag("cliOffered") && !resolveCli()) {
|
|
367
|
+
// Never block the session on a package install: kick it off and report later.
|
|
368
|
+
const startInstall = () => {
|
|
369
|
+
installCli().then((res) => {
|
|
370
|
+
log(res.ok ? `[memsearch] CLI 已安装: ${res.cli}` : `[memsearch] CLI 安装失败: ${res.reason}`);
|
|
371
|
+
});
|
|
372
|
+
};
|
|
359
373
|
if (config.autoInstallCli) {
|
|
360
|
-
|
|
361
|
-
log(res.ok ? `[memsearch] CLI 已安装: ${res.cli}` : `[memsearch] CLI 安装失败: ${res.reason}`);
|
|
374
|
+
startInstall();
|
|
362
375
|
} else if (config.offerCliInstall) {
|
|
363
376
|
const answer = await askYesNo({
|
|
364
377
|
title: "是否安装检索命令行工具?",
|
|
365
|
-
message: "memsearch CLI 负责把记录变成可语义检索的索引。\n不装也能用:对话仍会按日期归档成 txt。\n装好后可以用「上次我们聊的…」这类提问翻旧账。\n\n现在安装吗?(约需 Python 3.10
|
|
378
|
+
message: "memsearch CLI 负责把记录变成可语义检索的索引。\n不装也能用:对话仍会按日期归档成 txt。\n装好后可以用「上次我们聊的…」这类提问翻旧账。\n\n现在安装吗?(约需 Python 3.10+,后台进行)",
|
|
366
379
|
});
|
|
367
380
|
if (answer.ok && answer.answer) {
|
|
368
|
-
|
|
369
|
-
log(res.ok ? `[memsearch] CLI 已安装: ${res.cli}` : `[memsearch] CLI 安装失败: ${res.reason}`);
|
|
381
|
+
startInstall();
|
|
370
382
|
} else {
|
|
371
383
|
log("[memsearch] 用户暂不安装 CLI");
|
|
372
384
|
archive.setFlag("cliDeclined", true);
|
|
@@ -415,7 +427,9 @@ async function checkRetention(config, archive, log) {
|
|
|
415
427
|
});
|
|
416
428
|
if (answer.ok && answer.answer) {
|
|
417
429
|
const res = await openFolder(archive.root);
|
|
418
|
-
|
|
430
|
+
// explorer.exe returns a non-zero status even when it opens the folder.
|
|
431
|
+
const failed = res && res.err && process.platform !== "win32";
|
|
432
|
+
log(`[memsearch] 已打开归档目录: ${archive.root}${failed ? " (打开失败)" : ""}`);
|
|
419
433
|
}
|
|
420
434
|
}
|
|
421
435
|
|
|
@@ -500,12 +514,15 @@ function apply(ctx, config) {
|
|
|
500
514
|
}
|
|
501
515
|
|
|
502
516
|
async function captureTurn() {
|
|
503
|
-
const { userText, assistantText, assistantSeq } = extractExchange(session);
|
|
517
|
+
const { userText, assistantText, assistantSeq, userSeq } = extractExchange(session);
|
|
504
518
|
if (!userText || userText.length < config.captureMinPromptLength) return;
|
|
505
519
|
if (assistantSeq === undefined) return;
|
|
506
520
|
const sessionId = session.id || (session.header && session.header.id) || "session";
|
|
507
|
-
|
|
508
|
-
|
|
521
|
+
// A continuation turn (goal round, steered re-run) ends without a new user
|
|
522
|
+
// message; capturing it again would duplicate the same prompt.
|
|
523
|
+
const last = state.lastCaptured.get(sessionId);
|
|
524
|
+
if (last && (last.assistantSeq === assistantSeq || last.userSeq === userSeq)) return;
|
|
525
|
+
state.lastCaptured.set(sessionId, { assistantSeq, userSeq });
|
|
509
526
|
|
|
510
527
|
const title = sessionTitle(session);
|
|
511
528
|
const now = new Date();
|
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.3",
|
|
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",
|