@kangyishuai/dsh-next-step 0.1.1 → 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
@@ -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
@@ -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
  - **不做跨设备同步。** 卡片和决策只存在生成它的那台机器的本地会话日志里。
package/lib/client.js CHANGED
@@ -940,7 +940,7 @@ window.__ModuleLoader__.load({
940
940
  else if (clearedKey === promptKey) reason = "cleared";
941
941
  else if (suppressed) reason = "suppressed";
942
942
  else if (draft !== "") reason = "draft";
943
- else if (phase !== "plain") reason = "phase:" + phase;
943
+ else if (phase !== "plain") reason = `phase:${phase}`;
944
944
  else if (hasClaim) reason = "claim";
945
945
  else if (menuOpen) reason = "menu";
946
946
  else if (attachmentCount !== 0) reason = "attachments";
@@ -1101,7 +1101,7 @@ window.__ModuleLoader__.load({
1101
1101
  : t("settings.lastError", { message: lastError }));
1102
1102
  if (typeof stats.version === "string" && stats.version !== "") {
1103
1103
  let buildHash = typeof stats.buildHash === "string" ? stats.buildHash.slice(0, 8) : "";
1104
- diagText += "\n" + t("settings.version", { version: stats.version, hash: buildHash });
1104
+ diagText += `\n${t("settings.version", { version: stats.version, hash: buildHash })}`;
1105
1105
  }
1106
1106
  }
1107
1107
 
@@ -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
@@ -20,6 +20,7 @@ import {
20
20
  nextStepProjection,
21
21
  } from "./projection.js";
22
22
  import { buildMessages, buildSystemPrompt, parseSuggestion, renderTranscript } from "./prompt.js";
23
+ import { shouldSkipForQueue } from "./queue-gate.js";
23
24
  import { DEFAULT_SETTINGS, loadSettings, saveSettings } from "./settings.js";
24
25
 
25
26
  /**
@@ -99,6 +100,28 @@ function isSubagentSession(session) {
99
100
  );
100
101
  }
101
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
+
102
125
  /**
103
126
  * 读会话日志里的卡片与决策(全量,用于预算与去重;渲染走投影,不读这里)。
104
127
  * @param {any} session
@@ -210,6 +233,11 @@ export class NextStepService extends TypertRemoteService {
210
233
  if (!settings.enabled || !settings.card) return;
211
234
  if (settings.pauseUntil > Date.now()) return;
212
235
  const sessionId = session.id;
236
+ // 用户已经排了 ≥2 条消息就不再出卡(官方 action-cards 的同一条规则)。
237
+ if (shouldSkipForQueue(queuedCountOf(this.ctx, sessionId))) {
238
+ this.counters.skipped += 1;
239
+ return;
240
+ }
213
241
  const { cards } = scanSession(session);
214
242
  if (cards.has(turn)) return;
215
243
  if (cards.size >= settings.maxCardsPerSession) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kangyishuai/dsh-next-step",
3
- "version": "0.1.1",
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",