@kangyishuai/dsh-next-step 0.1.0 → 0.1.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 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
 
@@ -93,6 +93,7 @@ The row writes the same `$DSH_HOME/next-step.settings.json` that the host re-rea
93
93
  ## Known limitations
94
94
 
95
95
  - **The card is attached to the composer area**, not to the transcript. It renders in the composer's overlay layer so it is visible without scrolling; the trade-off is that it reads as part of the input box rather than as a block inside the conversation (ADR 0009 §4).
96
+ - **No card while messages are queued.** If you already have 2+ messages waiting to be sent, the plugin skips generation for that turn (the official action cards use the same limit); nothing is queued or sent by the plugin itself.
96
97
  - **Exactly two proposals.** Every card has two options that must point in different (mutually exclusive) directions.
97
98
  - **The `⌘↵` / `Ctrl+↵` keycap on the primary pill is decorative.** v1 does not bind the shortcut; it is a visual hint only.
98
99
  - **No cross-device sync.** Cards and decisions live in the local session log of the machine that generated them.
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
 
@@ -93,6 +93,7 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-next-step-*.tgz
93
93
  ## 已知限制
94
94
 
95
95
  - **卡片贴在输入区上方**(composer 的覆盖层),不排在对话流里。好处是永远不用滚动就能看到建议;代价是它视觉上属于输入框,不是对话正文里的一块(取舍见 ADR 0009 §4)。
96
+ - **有排队消息时不出卡。** 如果你已经排了 2 条以上待发送消息,这一轮就跳过生成(官方 action cards 用同一条规则);插件本身不会排队或代发任何东西。
96
97
  - **固定两条建议。** 每张卡都是两条方向互斥的选项。
97
98
  - **primary 胶囊上的 `⌘↵` / `Ctrl+↵` 键帽只是视觉提示。** v1 不绑定这个快捷键。
98
99
  - **不做跨设备同步。** 卡片和决策只存在生成它的那台机器的本地会话日志里。
@@ -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
  /**
@@ -938,7 +940,7 @@ window.__ModuleLoader__.load({
938
940
  else if (clearedKey === promptKey) reason = "cleared";
939
941
  else if (suppressed) reason = "suppressed";
940
942
  else if (draft !== "") reason = "draft";
941
- else if (phase !== "plain") reason = "phase:" + phase;
943
+ else if (phase !== "plain") reason = `phase:${phase}`;
942
944
  else if (hasClaim) reason = "claim";
943
945
  else if (menuOpen) reason = "menu";
944
946
  else if (attachmentCount !== 0) reason = "attachments";
@@ -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": "" }, [
@@ -0,0 +1,21 @@
1
+ // @ts-check
2
+ // 「用户已经在排队,就别再塞建议」的闸——纯函数,方便单测。
3
+ //
4
+ // 依据:官方 `dsh-action-cards` 的 `queuedMessageLimit = 2`(用户已排 ≥2 条消息时不再出卡),
5
+ // 避免「你已经排了两条,它还弹一张卡让你再点一条」这种噪音。宿主的排队消息可读面是
6
+ // `agent.inbox.nextStep` / `agent.inbox.nextTurn`(见 docs/runtime/0.2.2-rc.1.md §9.6)。
7
+
8
+ /** 用户已排队多少条消息时就不再出卡(0 = 关闭该闸)。 */
9
+ export const QUEUED_MESSAGE_LIMIT = 2;
10
+
11
+ /**
12
+ * 该不该因为「用户已在排队」而跳过生成。
13
+ * @param {number} queued 当前排队(next-turn + next-step)的消息条数
14
+ * @param {number} [limit] 闸值;0 表示不启用
15
+ * @returns {boolean} true = 跳过
16
+ */
17
+ export function shouldSkipForQueue(queued, limit = QUEUED_MESSAGE_LIMIT) {
18
+ if (!Number.isFinite(limit) || limit <= 0) return false;
19
+ if (!Number.isFinite(queued) || queued <= 0) return false;
20
+ return queued >= limit;
21
+ }
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,
@@ -19,6 +20,7 @@ import {
19
20
  nextStepProjection,
20
21
  } from "./projection.js";
21
22
  import { buildMessages, buildSystemPrompt, parseSuggestion, renderTranscript } from "./prompt.js";
23
+ import { shouldSkipForQueue } from "./queue-gate.js";
22
24
  import { DEFAULT_SETTINGS, loadSettings, saveSettings } from "./settings.js";
23
25
 
24
26
  /**
@@ -98,6 +100,28 @@ function isSubagentSession(session) {
98
100
  );
99
101
  }
100
102
 
103
+ /**
104
+ * 读「用户已排队」的消息条数:next-turn + next-step。
105
+ * 读不到就返回 0(宁可不拦,也不因为宿主形状变化误杀)。
106
+ * @param {any} ctx
107
+ * @param {string} sessionId
108
+ * @returns {number}
109
+ */
110
+ function queuedCountOf(ctx, sessionId) {
111
+ const inbox = serviceOf(ctx, "agents")?.get?.(sessionId)?.inbox;
112
+ if (inbox === undefined || inbox === null) return 0;
113
+ let count = 0;
114
+ try {
115
+ const nextStep = inbox.nextStep;
116
+ const nextTurn = inbox.nextTurn;
117
+ if (Array.isArray(nextStep)) count += nextStep.length;
118
+ if (Array.isArray(nextTurn)) count += nextTurn.length;
119
+ } catch (_error) {
120
+ return 0;
121
+ }
122
+ return count;
123
+ }
124
+
101
125
  /**
102
126
  * 读会话日志里的卡片与决策(全量,用于预算与去重;渲染走投影,不读这里)。
103
127
  * @param {any} session
@@ -209,6 +233,11 @@ export class NextStepService extends TypertRemoteService {
209
233
  if (!settings.enabled || !settings.card) return;
210
234
  if (settings.pauseUntil > Date.now()) return;
211
235
  const sessionId = session.id;
236
+ // 用户已经排了 ≥2 条消息就不再出卡(官方 action-cards 的同一条规则)。
237
+ if (shouldSkipForQueue(queuedCountOf(this.ctx, sessionId))) {
238
+ this.counters.skipped += 1;
239
+ return;
240
+ }
212
241
  const { cards } = scanSession(session);
213
242
  if (cards.has(turn)) return;
214
243
  if (cards.size >= settings.maxCardsPerSession) {
@@ -524,6 +553,7 @@ export class NextStepService extends TypertRemoteService {
524
553
  */
525
554
  async diagnostics() {
526
555
  try {
556
+ const identity = await buildIdentity();
527
557
  return {
528
558
  ok: true,
529
559
  stats: {
@@ -532,6 +562,11 @@ export class NextStepService extends TypertRemoteService {
532
562
  lastError: this.lastError,
533
563
  dataRoot: this.dataRoot,
534
564
  settings: await this.currentSettings(),
565
+ // 运行时自证:与 `dsh plugin list` / npm tarball 对照用。
566
+ version: identity.version,
567
+ buildHash: identity.buildHash,
568
+ buildFiles: identity.buildFiles,
569
+ packagePath: identity.packagePath,
535
570
  },
536
571
  };
537
572
  } 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
@@ -29,6 +29,7 @@
29
29
  "settings.lastError": "最近错误:{message}",
30
30
  "settings.noError": "无错误",
31
31
  "settings.paused": "已暂停,约 {time} 后恢复",
32
- "settings.updateFailed": "保存失败"
32
+ "settings.updateFailed": "保存失败",
33
+ "settings.version": "版本 {version} · 构建 {hash}"
33
34
  }
34
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kangyishuai/dsh-next-step",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Next-step decision card under each completed answer, plus an optional greyed-out next-prompt hint in the composer",
5
5
  "keywords": [
6
6
  "dsh",