@kangyishuai/dsh-next-step 0.1.0 → 0.1.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 +1 -1
- package/README.zh-CN.md +1 -1
- package/lib/build-info.js +117 -0
- package/lib/client.js +6 -0
- package/lib/service.js +7 -0
- package/locale/en.json +2 -1
- package/locale/zh.json +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ Settings → **General** → “Next-step suggestions” is one row with everyth
|
|
|
72
72
|
- **Decision card under the answer** / **Ghost hint in the composer** — one switch per face.
|
|
73
73
|
- **Cadence** — “Pause for 1 hour” / “Resume”.
|
|
74
74
|
- **Per session, at most N cards** — the budget (`maxCardsPerSession`, clamped to 0–1000).
|
|
75
|
-
- **Diagnostics** — generated / failed / skipped / in-flight counters, the last error, and a Refresh button.
|
|
75
|
+
- **Diagnostics** — generated / failed / skipped / in-flight counters, the last error, the runtime **version + build hash**, and a Refresh button. `nextStep/diagnostics` returns the same `version` / `buildHash` / `buildFiles` / `packagePath`, so a running build can be matched against `dsh plugin list` or the npm tarball without digging through startup logs.
|
|
76
76
|
|
|
77
77
|
The row writes the same `$DSH_HOME/next-step.settings.json` that the host re-reads (1 s cache) before every generation, so a change applies on the next turn — no restart. If the row is missing because a host seam moved, editing the file still works.
|
|
78
78
|
|
package/README.zh-CN.md
CHANGED
|
@@ -72,7 +72,7 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-next-step-*.tgz
|
|
|
72
72
|
- **回答下方的决策卡** / **输入框里的幽灵提示** —— 每个面一个开关。
|
|
73
73
|
- **生成节奏** —— 「暂停 1 小时」/「恢复生成」。
|
|
74
74
|
- **每会话最多 N 张卡** —— 预算(`maxCardsPerSession`,夹在 0–1000)。
|
|
75
|
-
- **诊断** —— 已生成 / 失败 / 跳过 /
|
|
75
|
+
- **诊断** —— 已生成 / 失败 / 跳过 / 在途计数、最近错误、**运行时版本 + 构建哈希**、刷新按钮。`nextStep/diagnostics` 同样返回 `version` / `buildHash` / `buildFiles` / `packagePath`,所以运行中的构建可以和 `dsh plugin list` 或 npm 上的 tarball 对照,不需要翻启动日志。
|
|
76
76
|
|
|
77
77
|
这一行写入的就是宿主每次生成前重读(1s 缓存)的 `$DSH_HOME/next-step.settings.json`,所以改完下一轮就生效、不用重启;万一宿主 seam 变了导致这一行不显示,直接改文件同样有效。
|
|
78
78
|
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// 运行时自证的构建身份:版本号 + 构建哈希。
|
|
3
|
+
//
|
|
4
|
+
// 为什么需要它:插件装没装、装的是哪个版本,过去只能靠 `dsh plugin list`、profile 的 lock 文件、
|
|
5
|
+
// 或者启动日志去侧面推断。这里让插件自己报出来——`diagnostics` RPC 会带上 `version` 与
|
|
6
|
+
// `buildHash`,和 `dsh plugin list` / npm 上的 tarball 一比就能确认「现在跑的是不是那份代码」。
|
|
7
|
+
//
|
|
8
|
+
// 只依赖 Node 内置模块,不进宿主包,因此可以用 `node --test` 直接测。
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
11
|
+
import { join, relative, sep } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
|
|
14
|
+
/** 插件包根目录(本文件在 <root>/lib/ 下)。 */
|
|
15
|
+
export const PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 参与构建哈希的条目(相对包根)。刻意不含 README / LICENSE:
|
|
19
|
+
* 它们不影响行为,改文档不该让用户看到「构建变了」。
|
|
20
|
+
*/
|
|
21
|
+
const HASHED_ENTRIES = ["package.json", "cordis.patch.yml", "lib", "locale"];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 递归收集普通文件(不跟随符号链接)。
|
|
25
|
+
* @param {string} absolute 绝对路径
|
|
26
|
+
* @param {string[]} out 收集结果
|
|
27
|
+
* @returns {Promise<void>}
|
|
28
|
+
*/
|
|
29
|
+
async function collect(absolute, out) {
|
|
30
|
+
let entries;
|
|
31
|
+
try {
|
|
32
|
+
entries = await readdir(absolute, { withFileTypes: true });
|
|
33
|
+
} catch (_error) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
const child = join(absolute, entry.name);
|
|
38
|
+
if (entry.isDirectory()) await collect(child, out);
|
|
39
|
+
else if (entry.isFile()) out.push(child);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 归一化相对路径:统一用 `/`,保证 macOS / Linux / Windows 上哈希一致。
|
|
45
|
+
* @param {string} absolute
|
|
46
|
+
* @returns {string}
|
|
47
|
+
*/
|
|
48
|
+
function relativeKey(absolute) {
|
|
49
|
+
return relative(PACKAGE_ROOT, absolute).split(sep).join("/");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 计算一次构建身份:读 package.json 的 version,并对参与构建的文件做 sha256。
|
|
54
|
+
* @returns {Promise<{ version: string, buildHash: string, buildFiles: number, packagePath: string }>}
|
|
55
|
+
*/
|
|
56
|
+
export async function computeBuildIdentity() {
|
|
57
|
+
const pkgText = await readFile(join(PACKAGE_ROOT, "package.json"), "utf8");
|
|
58
|
+
/** @type {{ version?: unknown }} */
|
|
59
|
+
const pkg = JSON.parse(pkgText);
|
|
60
|
+
const version = typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
61
|
+
|
|
62
|
+
/** @type {string[]} */
|
|
63
|
+
const absoluteFiles = [];
|
|
64
|
+
for (const entry of HASHED_ENTRIES) {
|
|
65
|
+
const absolute = join(PACKAGE_ROOT, entry);
|
|
66
|
+
try {
|
|
67
|
+
const stats = await readdir(absolute, { withFileTypes: true });
|
|
68
|
+
if (Array.isArray(stats)) await collect(absolute, absoluteFiles);
|
|
69
|
+
} catch (_error) {
|
|
70
|
+
// 不是目录:当作单文件处理(package.json / cordis.patch.yml)
|
|
71
|
+
absoluteFiles.push(absolute);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** @type {{ key: string, path: string }[]} */
|
|
76
|
+
const files = absoluteFiles
|
|
77
|
+
.map((path) => ({ key: relativeKey(path), path }))
|
|
78
|
+
.sort((left, right) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0));
|
|
79
|
+
|
|
80
|
+
const hash = createHash("sha256");
|
|
81
|
+
for (const file of files) {
|
|
82
|
+
const content = await readFile(file.path);
|
|
83
|
+
hash.update(file.key);
|
|
84
|
+
hash.update("\u0000");
|
|
85
|
+
hash.update(String(content.length));
|
|
86
|
+
hash.update("\u0000");
|
|
87
|
+
hash.update(content);
|
|
88
|
+
hash.update("\u0000");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
version,
|
|
93
|
+
buildHash: hash.digest("hex"),
|
|
94
|
+
buildFiles: files.length,
|
|
95
|
+
packagePath: PACKAGE_ROOT,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** @type {Promise<{ version: string, buildHash: string, buildFiles: number, packagePath: string }> | null} */
|
|
100
|
+
let cached = null;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 缓存的构建身份(第一次调用后不再读盘;插件进程内版本不会变)。
|
|
104
|
+
* @returns {Promise<{ version: string, buildHash: string, buildFiles: number, packagePath: string }>}
|
|
105
|
+
*/
|
|
106
|
+
export function buildIdentity() {
|
|
107
|
+
if (cached === null) cached = computeBuildIdentity();
|
|
108
|
+
return cached;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 只清缓存,给测试用(运行时不会调用)。
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
115
|
+
export function resetBuildIdentityCache() {
|
|
116
|
+
cached = null;
|
|
117
|
+
}
|
package/lib/client.js
CHANGED
|
@@ -67,6 +67,7 @@ window.__ModuleLoader__.load({
|
|
|
67
67
|
"settings.noError": "无错误",
|
|
68
68
|
"settings.paused": "已暂停,约 {time} 后恢复",
|
|
69
69
|
"settings.updateFailed": "保存失败",
|
|
70
|
+
"settings.version": "版本 {version} · 构建 {hash}",
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
/**
|
|
@@ -106,6 +107,7 @@ window.__ModuleLoader__.load({
|
|
|
106
107
|
"settings.noError": "No errors",
|
|
107
108
|
"settings.paused": "Paused; resumes in about {time}",
|
|
108
109
|
"settings.updateFailed": "Could not save",
|
|
110
|
+
"settings.version": "Version {version} · build {hash}",
|
|
109
111
|
};
|
|
110
112
|
|
|
111
113
|
/**
|
|
@@ -1097,6 +1099,10 @@ window.__ModuleLoader__.load({
|
|
|
1097
1099
|
(lastError === ""
|
|
1098
1100
|
? t("settings.noError")
|
|
1099
1101
|
: t("settings.lastError", { message: lastError }));
|
|
1102
|
+
if (typeof stats.version === "string" && stats.version !== "") {
|
|
1103
|
+
let buildHash = typeof stats.buildHash === "string" ? stats.buildHash.slice(0, 8) : "";
|
|
1104
|
+
diagText += "\n" + t("settings.version", { version: stats.version, hash: buildHash });
|
|
1105
|
+
}
|
|
1100
1106
|
}
|
|
1101
1107
|
|
|
1102
1108
|
return h("div", { className: "ns_settings", "data-next-step-settings": "" }, [
|
package/lib/service.js
CHANGED
|
@@ -11,6 +11,7 @@ import { join } from "node:path";
|
|
|
11
11
|
import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
12
12
|
import { appendPluginRecord, pluginRecordOf } from "@deepseek-ai/dsh-session";
|
|
13
13
|
import { Remote, RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
14
|
+
import { buildIdentity } from "./build-info.js";
|
|
14
15
|
import {
|
|
15
16
|
CARD_RECORD,
|
|
16
17
|
DECISION_RECORD,
|
|
@@ -524,6 +525,7 @@ export class NextStepService extends TypertRemoteService {
|
|
|
524
525
|
*/
|
|
525
526
|
async diagnostics() {
|
|
526
527
|
try {
|
|
528
|
+
const identity = await buildIdentity();
|
|
527
529
|
return {
|
|
528
530
|
ok: true,
|
|
529
531
|
stats: {
|
|
@@ -532,6 +534,11 @@ export class NextStepService extends TypertRemoteService {
|
|
|
532
534
|
lastError: this.lastError,
|
|
533
535
|
dataRoot: this.dataRoot,
|
|
534
536
|
settings: await this.currentSettings(),
|
|
537
|
+
// 运行时自证:与 `dsh plugin list` / npm tarball 对照用。
|
|
538
|
+
version: identity.version,
|
|
539
|
+
buildHash: identity.buildHash,
|
|
540
|
+
buildFiles: identity.buildFiles,
|
|
541
|
+
packagePath: identity.packagePath,
|
|
535
542
|
},
|
|
536
543
|
};
|
|
537
544
|
} catch (error) {
|
package/locale/en.json
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"settings.lastError": "Last error: {message}",
|
|
30
30
|
"settings.noError": "No errors",
|
|
31
31
|
"settings.paused": "Paused; resumes in about {time}",
|
|
32
|
-
"settings.updateFailed": "Could not save"
|
|
32
|
+
"settings.updateFailed": "Could not save",
|
|
33
|
+
"settings.version": "Version {version} · build {hash}"
|
|
33
34
|
}
|
|
34
35
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED