@kangyishuai/dsh-next-step 0.2.0 → 0.3.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > A next-step decision card for DeepSeek Harness: after every completed answer, a compact card under it shows where the conversation stands, the question you need to settle, and two mutually exclusive proposals. Click one and that pill's text — exactly as written on it — is sent as your user message. Optionally — off by default — a grey ghost hint in the empty composer offers the next prompt, accepted with `Tab` or `→`.
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-next-step?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-next-step) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.1-4b6bfb)](#compatibility) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
5
+ [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-next-step?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-next-step) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.3-4b6bfb)](#compatibility) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
6
6
 
7
7
  [中文](./README.zh-CN.md)
8
8
 
@@ -14,10 +14,10 @@ Unofficial plugin for [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/de
14
14
 
15
15
  ## What it does
16
16
 
17
- - **A card only when there is something to continue.** When a turn ends normally, the plugin makes one extra model call that first asks the model whether the turn is genuinely worth continuing. If not, the model returns a one-line reason and no card is written (the reason shows up in diagnostics). If it is worth continuing, a decision card is appended below the answer: a one-to-three sentence **summary** of the conversation state (folded to two lines, with an expand/collapse control when it is longer), one **question** that names the decision you have to make, and **two pills** for two mutually exclusive directions. Each pill carries the exact sentence that will be sent when you click it (up to 60 characters, verb-first and self-contained).
17
+ - **A card only when there is something to continue.** When a turn ends normally, the plugin makes one extra model call that first asks the model whether the turn is genuinely worth continuing. If not, the model returns a one-line reason and no card is written (the reason shows up in diagnostics). If it is worth continuing, a decision card is appended below the answer: a one-to-three sentence **summary** of the conversation state (folded to two lines, with an expand/collapse control when it is longer), one **question** that names the decision you have to make, and **1–2 pills** for mutually exclusive directions (one is fine when the next step is obvious — no padding). Each pill carries the exact sentence that will be sent when you click it: **2–20 characters, verb-first, and it must name a concrete object from the conversation** (file, command, flag, version, PR number). Generic pills like “check whether the definition is accurate” are dropped — if none survive, no card is shown at all.
18
18
  - **One click is one user message.** Clicking a pill puts that pill's own text into the composer and submits it through the same path as pressing Enter yourself — not by faking a session event. An idle session sends immediately; if a turn is already running, the text is queued exactly like a typed message.
19
19
  - **It stays.** Cards and decisions are appended to the session log as plugin records and folded by a session projection, which is the only source of truth. A page reload, a session switch or an app restart brings them back; the client keeps no separate state.
20
- - **Resolved, not removed.** After you click, the card stays in the transcript but becomes read-only: summary and question remain, the two pills are replaced by the one you picked in a selected state (✓ plus its text), followed by a grey “sent” line. Cards from earlier turns are always read-only, so at most one card is interactive at a time. The ✕ in a card's corner dismisses it without sending anything.
20
+ - **Resolved, not removed.** After you click, the card stays in the transcript but becomes read-only: summary and question remain, the pills are replaced by the one you picked in a selected state (✓ plus its text), followed by a grey “sent” line. Cards from earlier turns are always read-only, so at most one card is interactive at a time. The ✕ in a card's corner dismisses it without sending anything.
21
21
  - **Ghost hint in the composer (off by default).** The same model call also produces one next prompt. With the ghost face enabled, an empty idle composer shows it as grey, placeholder-style text. `Tab` or `→` accepts it into the draft (undoable with `Ctrl+Z`), `Esc` clears the current suggestion, typing makes it disappear, and it stays hidden while the composer holds a draft, an attachment, an `@` reference or a slash command. The ghost is not draft content, so pressing Enter on an otherwise empty composer sends nothing.
22
22
  - **Two faces, one call.** Card and ghost are produced together by a single model call — turning the ghost on costs no additional requests.
23
23
  - **Switches that actually stop requests.** `card` (default on) and `ghost` (default off) are separate switches; the global `enabled` switch off means no generation request at all, not just a hidden UI. A pause and a per-session card budget (`maxCardsPerSession`) stop new cards too. Cards already in the log stay readable.
@@ -25,7 +25,7 @@ Unofficial plugin for [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/de
25
25
  ## Cost & model calls
26
26
 
27
27
  - One extra model call per trigger, on the model the session's agent is currently using (falling back to the default model selection), billed to your own provider quota.
28
- - The call times out after 20 s. Failures, rate limits and malformed JSON are silent: no card, no dialog — only a counter in the plugin's diagnostics. Malformed output is dropped without writing a record.
28
+ - The call times out after 20 s. Other failures, rate limits and malformed JSON are silent: no card, no dialog — only a counter in the plugin's diagnostics. A **timeout or cancellation** is counted separately (the `aborted` counter plus a "Last skipped" reason such as `generation timeout after 20s`), and the generate button then says the generation timed out or was cancelled — so this class stays diagnosable afterwards. Malformed output is dropped without writing a record.
29
29
  - When the model decides the turn is not worth continuing, no card is written — but **the call still happens**: this saves UI noise, not tokens. The model's reason is kept in the settings row's “Last skipped” line.
30
30
  - No other network access, no telemetry.
31
31
 
@@ -37,7 +37,7 @@ Unofficial plugin for [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/de
37
37
  - **What is sent is a normal user message.** It enters the model context and is visible in the transcript exactly as if you had typed it.
38
38
  - **Private host seams.** The card renders through `conversation.chat.turnTail`; state comes from a host session projection read via `useProjection`; click-to-send uses the composer shell (`setDraft` / `submit`, waiting for the draft to settle before submitting); the ghost uses `conversation.input.overlay` and the host's placeholder DOM. These are internal, untyped and unversioned: a DSH upgrade can make the card, the send path or the ghost stop working **silently**. The plugin degrades instead of breaking a session, but after an upgrade run `pnpm probe:runtime` and the smoke suites, and check diagnostics.
39
39
  - **The ghost is coupled to the host placeholder DOM**, which is why it ships off by default; if that DOM changes, the hint can simply disappear.
40
- - **Silent failure is by design.** “No card appeared” is not an error dialog; look at the diagnostics counters before filing a bug.
40
+ - **Silent failure is by design.** “No card appeared” is not an error dialog; look at the diagnostics counters before filing a bug. Timeouts and cancellations are the one exception worth knowing: they are labelled rather than lumped into a generic failure, because an unlabelled abort is what made one “no card” incident undiagnosable.
41
41
  - **No plugin data directory and no workspace files.** Everything lives in the existing session log; nothing is written under `DSH_HOME` besides the session itself.
42
42
  - **Subagent sessions never get cards**, and only normally completed turns are eligible.
43
43
 
@@ -71,13 +71,13 @@ Re-run `pnpm pack` + `add` after changing the code. The plugin has a host half,
71
71
 
72
72
  ## Settings & diagnostics
73
73
 
74
- Settings → **General** → “Next-step suggestions” is one row with everything you need to control it:
74
+ Settings → **Next-step suggestions** (its own section now, no longer a row buried in General) has everything you need to control it:
75
75
 
76
76
  - **Enable the plugin** — the global switch. Off means **no generation request at all**, not a hidden UI.
77
77
  - **Decision card under the answer** / **Ghost hint in the composer** — one switch per face.
78
78
  - **Cadence** — “Pause for 1 hour” / “Resume”.
79
79
  - **Per session, at most N cards** — the budget (`maxCardsPerSession`, clamped to 0–1000).
80
- - **Diagnostics** — generated / failed / skipped / in-flight counters, the **reason the last card was skipped** (model judged unnecessary / queued / paused / budget / failure, with the model's own sentence), 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.
80
+ - **Diagnostics** — generated / failed / aborted / skipped / in-flight counters, the **reason the last card was skipped** (model judged unnecessary / queued / paused / budget / failure / timeout / cancelled, with the model's own sentence), 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.
81
81
 
82
82
  Turning the global switch off **hides every dependent row** (card / ghost / pause / budget / diagnostics) and leaves just the switch plus one line of explanation — off means off, nothing looks like it still runs, and re-enabling restores the previous switch values.
83
83
 
@@ -85,18 +85,19 @@ The row writes the same `$DSH_HOME/next-step.settings.json` that the host re-rea
85
85
 
86
86
  ## When no card appears
87
87
 
88
- | Situation | What happens |
89
- | ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
90
- | The turn was stopped, errored, or produced no text | No card: only normally completed turns are eligible. |
91
- | Subagent session | No card, by design. |
92
- | Global switch off | No request is made at all; existing cards remain in the transcript. |
93
- | Paused, or the session's card budget (`maxCardsPerSession`) used up | No new card; existing cards stay. |
94
- | A card or a decision already exists for that turn | One card per turn; no duplicates. |
95
- | The model judges the turn not worth continuing (`needed=false`) | No card; “Last skipped” in diagnostics shows the model's reason. |
96
- | Model call failed, timed out (20 s), was rate-limited, bad JSON | Silent; only a diagnostics counter goes up. |
97
- | The reply is still streaming | Nothing is rendered for the turn until it ends. |
98
- | The composer already has a draft | The card is visible but the pills are disabled until the draft is cleared. |
99
- | Ghost face on, but the composer is not plain (draft, attachment, `@`, `/`, or a non-idle session) | The hint stays hidden. |
88
+ | Situation | What happens |
89
+ | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
90
+ | The turn was stopped, errored, or produced no text | No card: only normally completed turns are eligible. |
91
+ | Subagent session | No card, by design. |
92
+ | Global switch off | No request is made at all; existing cards remain in the transcript. |
93
+ | Paused, or the session's card budget (`maxCardsPerSession`) used up | No new card; existing cards stay. |
94
+ | A card or a decision already exists for that turn | One card per turn; no duplicates. |
95
+ | The model judges the turn not worth continuing (`needed=false`) | No card; “Last skipped” in diagnostics shows the model's reason. |
96
+ | Model call failed, was rate-limited, bad JSON | Silent; only a diagnostics counter goes up. |
97
+ | The generation **timed out (20 s) or was cancelled** | Counted in `aborted`; “Last skipped” says which, and the generate button reports it. No dialog. |
98
+ | The reply is still streaming | Nothing is rendered for the turn until it ends. |
99
+ | The composer already has a draft | The card is visible but the pills are disabled until the draft is cleared. |
100
+ | Ghost face on, but the composer is not plain (draft, attachment, `@`, `/`, or a non-idle session) | The hint stays hidden. |
100
101
 
101
102
  ## Known limitations
102
103
 
@@ -114,9 +115,11 @@ The row writes the same `$DSH_HOME/next-step.settings.json` that the host re-rea
114
115
 
115
116
  ## Compatibility
116
117
 
117
- | DSH version | Status |
118
- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
119
- | 0.2.2-rc.1 | Web composition verified end-to-end on 2026-11-11 (`pnpm smoke:next-step`: 59 assertions passing, 0 skipped; real host + real model calls, covering WYSIWYG sending, the picked-option echo, the `needed` gate and the force-generate button, and the progressive settings); 83 unit tests; runtime probe 60/60. The desktop real-machine regression was not re-run on this machine (it needs the new tarball installed into the running desktop profile and a host restart, which would terminate the current session); re-check with `pnpm smoke:next-step-desktop --require --deep` before releasing. Other DSH versions are not verified. |
118
+ | DSH version | Status |
119
+ | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120
+ | 0.2.2-rc.3 | **0.3.0** (2026-11-14): no code change needed for this DSH build. Verified: 99 unit tests + `pnpm probe:runtime` 72/72 + web `pnpm smoke:next-step` **59/59** (real host + real model call) + desktop read-only regression **10 PASS + 2 SKIP**. The first web run reported 2 transient failures while three desktop regressions ran concurrently (the card's extra completion call failed); a solo re-run was 59/59 — see [runtime 0.2.2-rc.3 §7](../../docs/runtime/0.2.2-rc.3.md). |
121
+ | 0.2.2-rc.2 | **0.3.0** (2026-11-14): pill labels tightened to 2–20 characters and must name a concrete object (generic pills are dropped), 1–2 options instead of exactly 2, summaries must state checkable facts, two new cheap gates (previous turn errored / answer under 80 characters), ghost hint capped at 150 characters and degraded when it disagrees with the recommended pill; settings moved to their own "Settings → Next-step suggestions" section. Verified: 58 unit tests (50 prompt + 8 gates) + `pnpm probe:runtime` 72/72 + web `pnpm smoke:next-step` **59/59** (real host, real model call). The settings section was also checked on a live desktop build via read-only CDP; the desktop read-only regression reports **10 PASS + 2 SKIP** (the SKIPs are "no card in this session" and "read-only mode does not create cards"); `--deep` card interaction reports **23 PASS + 2 SKIP** (real model call — the one-sentence fixture is blocked by the new "answer under 80 characters" gate, so the run exercises the generate-now fallback, which also verifies that gate). |
122
+ | 0.2.2-rc.1 | Full regression green on 2026-11-11: web composition end-to-end (`pnpm smoke:next-step`: 59 assertions passing, 0 skipped; real host + real model calls, covering WYSIWYG sending, the picked-option echo, the `needed` gate and the force-generate button, and the progressive settings), desktop real-machine `pnpm smoke:next-step-desktop --require --deep` (32 passing + 3 skipped + 0 failing on the pre-release tarball, build `1ba08e8b`; the published 0.2.0 self-reports `version 0.2.0, build ce72c9dd` — the hash covers `package.json`, so the version bump changes it; every skip is a data-dependent branch), 83 unit tests, runtime probe 60/60, and `pnpm gate next-step` green across all four steps. Other DSH versions are not verified. |
120
123
 
121
124
  The plugin declares no `engines.dsh` and no `@deepseek-ai/*` peer range: DSH is pre-release and semver ranges over prereleases are unreliable (see [ADR 0005](../../docs/adr/0005-dsh-version-compatibility.md)). Treat the table as the compatibility statement. After a DSH upgrade run `pnpm probe:runtime`, `pnpm smoke:next-step` and `pnpm smoke:next-step-desktop`, then check the plugin's diagnostics.
122
125
 
package/README.zh-CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > DeepSeek Harness 的「下一步决策卡」:每条完整回答下方给一张小卡片,写清对话现状、需要你拍板的问题,以及两条互斥的下一步建议;点哪一句,就把那句**原样**作为用户消息发出(所见即所发)。模型判断这一轮不值得继续时不出卡。可选(默认关)在空输入框里给一条灰色幽灵提示,`Tab` / `→` 接受。
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-next-step?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-next-step) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.1-4b6bfb)](#兼容性) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
5
+ [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-next-step?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-next-step) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.3-4b6bfb)](#兼容性) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
6
6
 
7
7
  [English](./README.md)
8
8
 
@@ -14,7 +14,7 @@
14
14
 
15
15
  ## 它做什么
16
16
 
17
- - **需要继续时才出卡。** 一轮正常结束后,插件额外调用一次模型:先让模型判断「这一轮结束后用户是否真的值得继续」,不值得就给一句理由、不写卡(理由进诊断);值得才在回答下方追加一张决策卡——一到三句**现状摘要**(超过两行折叠,带「展开 / 收起」小按钮)、一句点名要你拍板的**提问**,以及**两粒互斥方向**的胶囊。胶囊上就是点击后**原样发出**的那句话(不超过 60 字,动词开头、单独发出去就能干活)。
17
+ - **需要继续时才出卡。** 一轮正常结束后,插件额外调用一次模型:先让模型判断「这一轮结束后用户是否真的值得继续」,不值得就给一句理由、不写卡(理由进诊断);值得才在回答下方追加一张决策卡——一到三句**现状摘要**(超过两行折叠,带「展开 / 收起」小按钮)、一句点名要你拍板的**提问**,以及 **1–2 粒互斥方向**的胶囊(下一步很明确时就只给一粒,不凑数)。胶囊上就是点击后**原样发出**的那句话:**2–20 字、动词开头、必须含对话里的具体对象**(文件名 / 命令 / 参数 / 版本号 / PR 号)——「检查定义是否准确」这类放到哪一轮都成立的按钮会被直接丢掉,一条都不剩就整卡不出。
18
18
  - **点一下就是一条用户消息。** 点胶囊会把它自己那行文本填入输入框,并走和手动回车**同一条提交链**发出——不是伪造会话事件。空闲会话立即发送;如果已有回合在跑,就和你打字一样排进队列。
19
19
  - **刷新也不丢。** 卡片和决策以插件记录的形式追加进会话日志,由宿主的 session projection 折叠,这是唯一的数据来源。刷新页面、切换会话、重开应用都还在;客户端不另存状态。
20
20
  - **只读保留,不是消失。** 点过之后卡片仍留在对话里,但变成只读:摘要和提问保留,两粒胶囊换成**你点的那一粒的选中态**(✓ + 那句话),后面跟一行灰字「已发出」。更早轮次的卡一律只读,所以任何时刻最多一张卡可交互。卡片右上角的 ✕ 可以收掉这张卡,不发送任何东西。
@@ -25,7 +25,7 @@
25
25
  ## 成本
26
26
 
27
27
  - 每次触发多一次模型调用,用会话所在智能体当前的模型(取不到时回退到默认模型选择),**占用你自己的 provider 额度**。
28
- - 这次调用 20 秒超时。失败、限流、JSON 不合法都**静默**:不出卡、不弹框,只在插件诊断里加计数。不合法输出直接丢弃,不写记录。
28
+ - 这次调用 20 秒超时。其它失败、限流、JSON 不合法都**静默**:不出卡、不弹框,只在插件诊断里加计数。**超时 / 被取消**单独计数(`aborted`,并在「最近跳过」写明 `generation timeout after 20s`),补生成按钮也会显示「生成超时或被取消」,所以这一类事后可诊断。不合法输出直接丢弃,不写记录。
29
29
  - 模型判断「不需要继续」时也不出卡,但**这次调用已经发生**:省的是界面噪音,不是 token。想看模型给出的理由,去设置页诊断里的「最近跳过」。
30
30
  - 除此之外不联网,不上报。
31
31
 
@@ -37,7 +37,7 @@
37
37
  - **发出去的就是普通用户消息。** 它进入模型上下文、出现在对话里,和你自己打字完全一样。
38
38
  - **依赖宿主私有 seam。** 卡片渲染走 `conversation.chat.turnTail`;状态来自宿主 session projection(客户端用 `useProjection` 读);点击发送走 composer shell 的 `setDraft` / `submit`(提交前等草稿落定);幽灵提示走 `conversation.input.overlay` 和宿主 placeholder 的 DOM。这些都没有类型、没有版本契约:DSH 升级可能让卡片、发送链或幽灵提示**静默失效**。插件会降级而不是弄坏会话,但升级后请跑 `pnpm probe:runtime`、两个冒烟套件,并看诊断。
39
39
  - **幽灵提示和宿主 placeholder DOM 绑在一起**,这也是它默认关的原因;宿主改了那块 DOM,它就只是不显示了。
40
- - **失败静默是设计。**「没出卡」不是错误弹窗;先看诊断计数再判断是不是 bug。
40
+ - **失败静默是设计。**「没出卡」不是错误弹窗;先看诊断计数再判断是不是 bug。超时与取消是唯一值得单独知道的例外:它们会被标成自己的原因,而不是混进笼统的失败——之前正因为中止无痕,一次「没出卡」完全没法定位。
41
41
  - **没有插件数据目录,也不碰工作区文件。** 所有东西都在已有的会话日志里,`DSH_HOME` 下不额外写数据。
42
42
  - **子代理会话不出卡**,被停止、报错或没有文本的回合同样不出卡。
43
43
 
@@ -65,19 +65,19 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-next-step-*.tgz
65
65
 
66
66
  **没出卡怎么办。** 如果这一轮没有自动出卡(模型判断不需要、暂停中、有排队消息、或在预算之外),最新回答下方会出现一行「生成下一步建议」:点它就会**强制**生成一张卡(模型判断不需要也照出)。所以「我觉得该出卡却没出」时:先看设置页诊断的「最近跳过」;想立刻要一张,直接点那个按钮。
67
67
 
68
- **幽灵提示。** 在插件设置里打开 ghost 面。输入框空且空闲时,最新一张卡的「下一句提示」以灰色出现,和宿主 placeholder 对齐。`Tab` 或 `→` 接受——文本进入草稿,仍可撤销。`Esc` 清除本次建议,输入第一个字符也会让它消失。它只改草稿:不发送,也不抢 Enter。
68
+ **幽灵提示。** 在 设置 → **下一步建议** 里打开 ghost 面。输入框空且空闲时,最新一张卡的「下一句提示」以灰色出现,和宿主 placeholder 对齐。`Tab` 或 `→` 接受——文本进入草稿,仍可撤销。`Esc` 清除本次建议,输入第一个字符也会让它消失。它只改草稿:不发送,也不抢 Enter。
69
69
 
70
- **开关在哪。** 插件设置里有 card / ghost 两个面、全局开关、暂停,以及每会话预算。全局开关关闭后连请求都不发,不只是不显示。
70
+ **开关在哪。** 设置 → **下一步建议**(独立分节)里有 card / ghost 两个面、全局开关、暂停,以及每会话预算。全局开关关闭后连请求都不发,不只是不显示。
71
71
 
72
72
  ## 设置与诊断
73
73
 
74
- 设置 → **通用** → 「下一步建议」是一行完整控制项:
74
+ 设置 → **下一步建议**(独立分节)就是一整页控制项:
75
75
 
76
76
  - **启用插件** —— 总开关。关掉之后**完全不发请求**,不是把界面藏起来。
77
77
  - **回答下方的决策卡** / **输入框里的幽灵提示** —— 每个面一个开关。
78
78
  - **生成节奏** —— 「暂停 1 小时」/「恢复生成」。
79
79
  - **每会话最多 N 张卡** —— 预算(`maxCardsPerSession`,夹在 0–1000)。
80
- - **诊断** —— 已生成 / 失败 / 跳过 / 在途计数、**最近一次没出卡的原因**(模型判断不需要 / 排队 / 暂停 / 预算 / 失败,附模型给的理由)、最近错误、**运行时版本 + 构建哈希**、刷新按钮。`nextStep/diagnostics` 同样返回 `version` / `buildHash` / `buildFiles` / `packagePath` 与 `lastSkip`,所以运行中的构建可以和 `dsh plugin list` 或 npm 上的 tarball 对照,不需要翻启动日志。
80
+ - **诊断** —— 已生成 / 失败 / 已中止 / 跳过 / 在途计数、**最近一次没出卡的原因**(模型判断不需要 / 排队 / 暂停 / 预算 / 失败 / 超时 / 取消,附模型给的理由)、最近错误、**运行时版本 + 构建哈希**、刷新按钮。`nextStep/diagnostics` 同样返回 `version` / `buildHash` / `buildFiles` / `packagePath` 与 `lastSkip`,所以运行中的构建可以和 `dsh plugin list` 或 npm 上的 tarball 对照,不需要翻启动日志。
81
81
 
82
82
  关闭总开关后,卡片 / 幽灵 / 暂停 / 预算 / 诊断这些依赖项会**整段隐藏**,只留总开关和一行说明——关掉就是关掉,不会让人以为还有东西在跑;重新启用时这些开关的取值都还在。
83
83
 
@@ -85,18 +85,19 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-next-step-*.tgz
85
85
 
86
86
  ## 什么情况下不出卡
87
87
 
88
- | 情况 | 表现 |
89
- | ------------------------------------------------------- | ---------------------------------------- |
90
- | 回合被停止、报错,或没有文本 | 不出卡:只有正常结束的回合才有资格。 |
91
- | 子代理会话 | 按设计不出卡。 |
92
- | 全局开关关闭 | 完全不发请求;已有卡片仍然留在对话里。 |
93
- | 已暂停,或用完该会话的卡片预算(`maxCardsPerSession`) | 不出新卡;已有卡片保留。 |
94
- | 该轮已经有 card 或 decision 记录 | 一轮最多一张卡,不重复。 |
95
- | 模型判断这一轮不需要继续(`needed=false`) | 不出卡;诊断里「最近跳过」写明理由。 |
96
- | 模型调用失败、20 秒超时、限流、JSON 不合法 | 静默;只有诊断计数增加。 |
97
- | 回答还在流式输出 | 该轮结束前槽位不渲染。 |
98
- | 输入框里已有草稿 | 卡片照常显示,但胶囊禁用,直到清空草稿。 |
99
- | ghost 开着,但草稿、附件、`@`、`/` 或输入状态不满足条件 | 提示隐藏。 |
88
+ | 情况 | 表现 |
89
+ | ------------------------------------------------------- | ---------------------------------------------------------------------- |
90
+ | 回合被停止、报错,或没有文本 | 不出卡:只有正常结束的回合才有资格。 |
91
+ | 子代理会话 | 按设计不出卡。 |
92
+ | 全局开关关闭 | 完全不发请求;已有卡片仍然留在对话里。 |
93
+ | 已暂停,或用完该会话的卡片预算(`maxCardsPerSession`) | 不出新卡;已有卡片保留。 |
94
+ | 该轮已经有 card 或 decision 记录 | 一轮最多一张卡,不重复。 |
95
+ | 模型判断这一轮不需要继续(`needed=false`) | 不出卡;诊断里「最近跳过」写明理由。 |
96
+ | 模型调用失败、限流、JSON 不合法 | 静默;只有诊断计数增加。 |
97
+ | 生成**超时(20 秒)或被取消** | 计入 `aborted`;「最近跳过」写明是哪一种,补生成按钮也会显示。不弹框。 |
98
+ | 回答还在流式输出 | 该轮结束前槽位不渲染。 |
99
+ | 输入框里已有草稿 | 卡片照常显示,但胶囊禁用,直到清空草稿。 |
100
+ | ghost 开着,但草稿、附件、`@`、`/` 或输入状态不满足条件 | 提示隐藏。 |
100
101
 
101
102
  ## 已知限制
102
103
 
@@ -114,9 +115,11 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-next-step-*.tgz
114
115
 
115
116
  ## 兼容性
116
117
 
117
- | DSH 版本 | 状态 |
118
- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
119
- | 0.2.2-rc.1 | 2026-11-11 用 web 组合端到端验证通过(`pnpm smoke:next-step`:59 项断言全部通过 + 0 SKIP;真实宿主 + 真实模型调用,覆盖 WYSIWYG 发送、点后回显、`needed` 门控与补生成按钮、设置渐进披露)、单测 83 项、宿主探针 60/60。桌面真机回归本机未重跑(需把新版装进正在运行的 desktop profile 并重启宿主,会中断当前会话);发版前用 `pnpm smoke:next-step-desktop --require --deep` 复核。其他 DSH 版本未验证。 |
118
+ | DSH 版本 | 状态 |
119
+ | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120
+ | 0.2.2-rc.3 | **0.3.0**(2026-11-14):这一版 DSH 不需要改代码。已验证:99 项单测 + `pnpm probe:runtime` 72/72 + web `pnpm smoke:next-step` **59/59**(真实宿主 + 真实模型调用)+ 桌面只读回归 **10 PASS + 2 SKIP**。首跑有 2 项瞬时失败(与三条桌面回归并发时卡片的补生成调用失败),单独重跑 59/59——见 [runtime 0.2.2-rc.3 §7](../../docs/runtime/0.2.2-rc.3.md)。 |
121
+ | 0.2.2-rc.2 | **0.3.0**(2026-11-14):胶囊文案收紧到 2–20 字且必须含具体对象(泛化按钮直接丢弃)、选项 1–2 条、摘要要求写事实、新增「上轮报错 / 回答 < 80 字」两道便宜闸、幽灵提示 150 字上限 + 与推荐项一致性退化;设置搬到「设置 → 下一步建议」分节。已验证:单测 58(prompt 50 + gates 8)+ `pnpm probe:runtime` 72/72 + web `pnpm smoke:next-step` **59/59**(真实宿主 + 真实模型调用)。设置分节另有真机只读 CDP 核验;桌面只读回归 **10 PASS + 2 SKIP**(SKIP 是「当前会话没有决策卡」与「只读模式不造卡」);`--deep` 造卡交互 **23 PASS + 2 SKIP**(真实模型调用;一句话提示词会被「回答 < 80 字」闸挡住,走的是补生成按钮那条兜底,顺带验证了闸)。 |
122
+ | 0.2.2-rc.1 | 2026-11-11 全量回归通过:web 组合端到端(`pnpm smoke:next-step`:59 项断言全部通过 + 0 SKIP;真实宿主 + 真实模型调用,覆盖 WYSIWYG 发送、点后回显、`needed` 门控与补生成按钮、设置渐进披露)、桌面真机 `pnpm smoke:next-step-desktop --require --deep`(32 PASS + 3 SKIP + 0 FAIL,发版前 tarball 构建 `1ba08e8b`;发布后 0.2.0 只读自证 20 PASS + 2 SKIP,诊断 `版本 0.2.0 · 构建 ce72c9dd`,哈希含 `package.json` 版本故与发版前不同)、单测 83 项、宿主探针 60/60、`pnpm gate next-step` 四步全绿。其他 DSH 版本未验证。 |
120
123
 
121
124
  插件不声明 `engines.dsh`,也不声明 `@deepseek-ai/*` 的 peer 范围:DSH 还在预发布阶段,预发布版本的 semver 范围不可靠(见 [ADR 0005](../../docs/adr/0005-dsh-version-compatibility.md))。以这张表为准。DSH 升级后跑 `pnpm probe:runtime`、`pnpm smoke:next-step`、`pnpm smoke:next-step-desktop`,并看插件诊断。
122
125
 
@@ -0,0 +1,47 @@
1
+ // @ts-check
2
+ // 「卡片生成被中止」的原因细分:**超时**(插件自己的 timeout 定时器)与**取消**
3
+ // (用户取消 / 同一会话又起了新的生成)是两件事。
4
+ //
5
+ // 为什么单独一个纯函数模块:中止既不写会话日志、也不计数时,诊断面板里完全看不到
6
+ // 痕迹——2026-11-14 排查那次「卡片没出来」就卡在这里。把判据抽出来才能单测,
7
+ // 让 `writeCardFor` 与诊断行共用同一套结论。
8
+
9
+ /** 超时定时器塞进 `AbortController.abort()` 的 Error message。 */
10
+ export const TIMEOUT_MESSAGE = "next-step timeout";
11
+
12
+ /**
13
+ * 从 `AbortController.signal.reason` 判出中止原因。
14
+ * @param {unknown} reason
15
+ * @returns {"timeout" | "cancelled"}
16
+ */
17
+ export function abortReasonOf(reason) {
18
+ const message =
19
+ reason instanceof Error
20
+ ? reason.message
21
+ : typeof reason === "string"
22
+ ? reason
23
+ : typeof (/** @type {any} */ (reason)?.message) === "string"
24
+ ? String(/** @type {any} */ (reason).message)
25
+ : "";
26
+ return /timeout|timed\s*out/iu.test(message) ? "timeout" : "cancelled";
27
+ }
28
+
29
+ /**
30
+ * 诊断行里「最近一次没出卡」的 kind。用户能看懂,也便于冒烟断言。
31
+ * @param {"timeout" | "cancelled"} kind
32
+ */
33
+ export function abortSkipKind(kind) {
34
+ return kind === "timeout" ? "timeout" : "cancelled";
35
+ }
36
+
37
+ /**
38
+ * 给诊断用的英文原因 token(与其它 lastSkip.reason 风格一致:机器可读、不翻译)。
39
+ * @param {"timeout" | "cancelled"} kind
40
+ * @param {number} [timeoutMs]
41
+ */
42
+ export function abortReasonText(kind, timeoutMs) {
43
+ if (kind !== "timeout") return "cancelled";
44
+ const seconds =
45
+ Number.isFinite(timeoutMs) && Number(timeoutMs) > 0 ? Math.round(Number(timeoutMs) / 1000) : 0;
46
+ return seconds > 0 ? `generation timeout after ${seconds}s` : "generation timeout";
47
+ }
package/lib/client.js CHANGED
@@ -52,6 +52,7 @@ window.__ModuleLoader__.load({
52
52
  "error.missing": "找不到这条建议",
53
53
  "error.disabled": "插件已停用",
54
54
  "error.failed": "操作失败,请重试",
55
+ "error.aborted": "生成超时或被取消,请重试",
55
56
  "error.send": "没能把建议写进输入框",
56
57
  "error.budget": "本会话的卡片预算已用完",
57
58
  "error.exists": "这一轮已经有卡片了",
@@ -60,8 +61,9 @@ window.__ModuleLoader__.load({
60
61
  "retry.generate": "生成下一步建议",
61
62
  "retry.generating": "正在生成…",
62
63
  "settings.title": "下一步建议",
64
+ "settings.nav": "下一步建议",
63
65
  "settings.desc":
64
- "答完后判断是否值得继续;需要时生成一张含摘要与两个方向建议的决策卡(一次额外模型调用)。",
66
+ "答完后判断是否值得继续;需要时生成一张含摘要、提问与 1–2 条具体建议的决策卡(一次额外模型调用)。",
65
67
  "settings.enabled": "启用插件",
66
68
  "settings.card": "回答下方的决策卡",
67
69
  "settings.ghost": "输入框里的幽灵提示",
@@ -72,7 +74,8 @@ window.__ModuleLoader__.load({
72
74
  "settings.budgetUnit": "张卡",
73
75
  "settings.diagnostics": "诊断",
74
76
  "settings.refresh": "刷新",
75
- "settings.stats": "已生成 {generated} · 失败 {failed} · 跳过 {skipped} · 在途 {inflight}",
77
+ "settings.stats":
78
+ "已生成 {generated} · 失败 {failed} · 已中止 {aborted} · 跳过 {skipped} · 在途 {inflight}",
76
79
  "settings.lastError": "最近错误:{message}",
77
80
  "settings.noError": "无错误",
78
81
  "settings.paused": "已暂停,约 {time} 后恢复",
@@ -102,6 +105,7 @@ window.__ModuleLoader__.load({
102
105
  "error.missing": "That suggestion is no longer available",
103
106
  "error.disabled": "The plugin is disabled",
104
107
  "error.failed": "Something went wrong. Try again.",
108
+ "error.aborted": "Generation timed out or was cancelled. Try again.",
105
109
  "error.send": "Could not fill the composer",
106
110
  "error.budget": "This session has used up its card budget",
107
111
  "error.exists": "This turn already has a card",
@@ -110,8 +114,9 @@ window.__ModuleLoader__.load({
110
114
  "retry.generate": "Generate a next-step card",
111
115
  "retry.generating": "Generating…",
112
116
  "settings.title": "Next-step suggestions",
117
+ "settings.nav": "Next-step suggestions",
113
118
  "settings.desc":
114
- "Judges whether a turn is worth continuing; when it is, adds a status summary and two directions (one extra model call).",
119
+ "Judges whether a turn is worth continuing; when it is, adds a status summary, a question and 1–2 concrete next steps (one extra model call).",
115
120
  "settings.enabled": "Enable the plugin",
116
121
  "settings.card": "Decision card under the answer",
117
122
  "settings.ghost": "Ghost hint in the composer",
@@ -123,7 +128,7 @@ window.__ModuleLoader__.load({
123
128
  "settings.diagnostics": "Diagnostics",
124
129
  "settings.refresh": "Refresh",
125
130
  "settings.stats":
126
- "Generated {generated} · failed {failed} · skipped {skipped} · in flight {inflight}",
131
+ "Generated {generated} · failed {failed} · aborted {aborted} · skipped {skipped} · in flight {inflight}",
127
132
  "settings.lastError": "Last error: {message}",
128
133
  "settings.noError": "No errors",
129
134
  "settings.paused": "Paused; resumes in about {time}",
@@ -155,7 +160,7 @@ window.__ModuleLoader__.load({
155
160
  "no-turn": "error.noTurn",
156
161
  failed: "error.failed",
157
162
  schema: "error.failed",
158
- aborted: "error.failed",
163
+ aborted: "error.aborted",
159
164
  "not-needed": "error.failed",
160
165
  };
161
166
 
@@ -1365,6 +1370,7 @@ window.__ModuleLoader__.load({
1365
1370
  diagText = t("settings.stats", {
1366
1371
  generated: String(stats.generated || 0),
1367
1372
  failed: String(stats.failed || 0),
1373
+ aborted: String(stats.aborted || 0),
1368
1374
  skipped: String(stats.skipped || 0),
1369
1375
  inflight: String(stats.inflight || 0),
1370
1376
  });
@@ -1499,6 +1505,8 @@ window.__ModuleLoader__.load({
1499
1505
  /** @param {any} ctx */
1500
1506
  exports.apply = function apply(ctx) {
1501
1507
  ctx.effect(() => ctx.locale.register(NS, { zh: zh, en: en }), "next-step: dictionaries");
1508
+ // settings.section 的 label 是惰性求值的,需要一个绑定到本插件的翻译函数。
1509
+ const tr = ctx.locale.bind(NS);
1502
1510
 
1503
1511
  // 只注入一份样式;判重让 HMR / 重复挂载不会插第二份。
1504
1512
  ctx.effect(() => {
@@ -1702,15 +1710,16 @@ window.__ModuleLoader__.load({
1702
1710
  "next-step: ghost",
1703
1711
  );
1704
1712
 
1705
- // 设置页 → 通用:总开关、两个面、暂停、预算与诊断。
1713
+ // 设置 → 下一步建议(独立分节;原来挤在「通用设置」里)。
1706
1714
  ctx.effect(
1707
1715
  () =>
1708
- ctx.slots.inject("settings.general.item", () =>
1716
+ ctx.slots.inject("settings.section", () =>
1709
1717
  ctx.slots.register(
1710
1718
  {
1711
- name: "settings.general.item",
1719
+ name: "settings.section",
1712
1720
  id: "next-step",
1713
- order: 900,
1721
+ order: 93,
1722
+ label: () => tr("settings.nav"),
1714
1723
  locale: NS,
1715
1724
  inject: () => ({ api: api }),
1716
1725
  },
package/lib/gates.js ADDED
@@ -0,0 +1,39 @@
1
+ // @ts-check
2
+ // 便宜闸:在做那次模型调用**之前**就能判断出「这一轮不该出卡」的条件。
3
+ // 每一条都对应一种「此刻打扰是负价值」的场景,参考 Claude 的建议生成门控:
4
+ // 出错的时候不要打扰用户、回答太短没有上下文可依、用户已经在排队等回复。
5
+ //
6
+ // 抽成纯函数是为了能单测:service.js 依赖 @deepseek-ai/*,在单测环境里导入不了。
7
+
8
+ /** 回答短于这个字符数就不出卡:没有足够上下文,生成的建议必然是空话。 */
9
+ export const MIN_ANSWER_CHARS = 80;
10
+
11
+ /**
12
+ * 判定这一轮是否应当跳过(不调用模型)。
13
+ * @param {{
14
+ * enabled: boolean, cardEnabled: boolean, pauseUntil: number, now: number,
15
+ * queued: number, cardsForTurn: boolean, cardsInSession: number, maxCards: number,
16
+ * endKind?: string, answerChars?: number,
17
+ * }} input
18
+ * @returns {{ reason: string, detail: string } | null} 需要跳过时返回原因,否则 null
19
+ */
20
+ export function cheapSkipReason(input) {
21
+ if (!input.enabled) return { reason: "disabled", detail: "card generation is off" };
22
+ if (!input.cardEnabled) return { reason: "disabled", detail: "cards are turned off" };
23
+ if (input.pauseUntil > input.now) return { reason: "paused", detail: "generation is paused" };
24
+ // 用户已经排了 ≥2 条消息:他马上要说的话比任何建议都准。
25
+ if (input.queued >= 2)
26
+ return { reason: "queued", detail: "the user already has queued messages" };
27
+ if (input.cardsForTurn) return { reason: "duplicate", detail: "this turn already has a card" };
28
+ if (input.cardsInSession >= input.maxCards) {
29
+ return { reason: "budget", detail: "per-session card budget reached" };
30
+ }
31
+ // 上一轮报错/被中断:先让用户看错误、决定怎么修,别在错误旁边推销下一步。
32
+ if (typeof input.endKind === "string" && input.endKind !== "completed") {
33
+ return { reason: "turn-error", detail: `turn ended as ${input.endKind}` };
34
+ }
35
+ if (typeof input.answerChars === "number" && input.answerChars < MIN_ANSWER_CHARS) {
36
+ return { reason: "short-answer", detail: `answer has ${input.answerChars} chars` };
37
+ }
38
+ return null;
39
+ }
package/lib/projection.js CHANGED
@@ -42,9 +42,11 @@ export function isCardData(data) {
42
42
  typeof data.question === "string" &&
43
43
  data.question.trim() !== "" &&
44
44
  Array.isArray(data.options) &&
45
- data.options.length === 2 &&
45
+ // 1–2 条:只给 1 条表示「下一步很明确」,不是残缺;3 条以上徒增选择成本。
46
+ data.options.length >= 1 &&
47
+ data.options.length <= 2 &&
46
48
  data.options.every(isOption) &&
47
- data.options[0].stance !== data.options[1].stance &&
49
+ (data.options.length === 1 || data.options[0].stance !== data.options[1].stance) &&
48
50
  (data.nextPrompt === undefined || typeof data.nextPrompt === "string")
49
51
  );
50
52
  }
package/lib/prompt.js CHANGED
@@ -12,14 +12,22 @@
12
12
  export const SUMMARY_MAX = 400;
13
13
  /** 提问最大字符数。 */
14
14
  export const QUESTION_MAX = 200;
15
- /** 按钮文案最大字符数(它同时是要发送的消息,允许两行)。 */
16
- export const LABEL_MAX = 60;
15
+ /**
16
+ * 按钮文案最大字符数。参照 Claude 桌面端的建议卡:chip 都是「动词 + 具体对象」的短语
17
+ * (「改成 %5」「写 v1.3」「出 v1.5 和 E2E-01c」都在 13 字以内),长到一整句就点不动了。
18
+ */
19
+ export const LABEL_MAX = 20;
17
20
  /** 按钮文案最少字符数(太短多半是「继续」这种悬空指令)。 */
18
- export const LABEL_MIN = 4;
21
+ export const LABEL_MIN = 2;
19
22
  /** 判断依据最大字符数(会显示在诊断里)。 */
20
23
  export const REASON_MAX = 160;
21
- /** 幽灵提示最大字符数。 */
22
- export const NEXT_PROMPT_MAX = 120;
24
+ /**
25
+ * 幽灵提示最大字符数。输入框里是一整行灰字,比 chip 能承载更长的句子;
26
+ * 但超过一屏宽度只会被省略号截断,所以仍然给上限,并要求关键信息前置。
27
+ */
28
+ export const NEXT_PROMPT_MAX = 150;
29
+ /** 幽灵提示里「关键信息必须出现」的前缀长度。 */
30
+ export const NEXT_PROMPT_HEAD = 60;
23
31
  /** stance 最大字符数。 */
24
32
  export const STANCE_MAX = 40;
25
33
 
@@ -59,6 +67,80 @@ export function renderTranscript(messages, options = {}) {
59
67
  return kept.slice(-Math.max(1, limit)).join("\n\n");
60
68
  }
61
69
 
70
+ /**
71
+ * 从一段文字里抽「具体对象」:版本号、文件名/路径、命令、带数字或下划线的标识符、
72
+ * 英文单词与中文里成串的名词片段。用途只有一个——机械校验按钮文案/幽灵提示里
73
+ * 到底有没有对话里的东西,而不是又一句可以套在任何一轮上的空话。
74
+ * @param {string} text
75
+ * @returns {Set<string>}
76
+ */
77
+ export function concreteTokens(text) {
78
+ const found = new Set();
79
+ const source = typeof text === "string" ? text : "";
80
+ // 带扩展名的文件、路径、命令、版本号、PR/issue 号、下划线标识符
81
+ for (const match of source.matchAll(
82
+ /[A-Za-z0-9_./-]*(?:\.[A-Za-z]{1,5}|\/[A-Za-z0-9_.-]+|#[0-9]+|v?\d+(?:\.\d+)+|[a-z]+_[a-z0-9_]+)/gu,
83
+ )) {
84
+ const token = match[0].replace(/^[./-]+|[./-]+$/gu, "");
85
+ if (token.length >= 3) found.add(token.toLowerCase());
86
+ }
87
+ // 中文片段:2 字以上的连续汉字(去掉「继续」「下一步」这类无信息量的词)
88
+ const stop = new Set(["继续", "下一步", "建议", "可以", "需要", "是否", "现在", "然后", "一下"]);
89
+ for (const match of source.matchAll(/[\u4e00-\u9fa5]{2,8}/gu)) {
90
+ const token = match[0];
91
+ if (!stop.has(token)) found.add(token);
92
+ }
93
+ return found;
94
+ }
95
+
96
+ /** 只有空话动词、没有具体对象的按钮文案:一律不要(宁可这一轮不出卡)。 */
97
+ const GENERIC_VERBS =
98
+ /^(?:检查|看看|确认|继续|优化|扩展|扩充|补充|完善|调整|处理|评估|梳理|整理|深入|展开|review|check|continue|expand|improve)/iu;
99
+
100
+ /**
101
+ * 按钮文案是不是「套在任何一轮都成立」的空话。
102
+ * 判据:以泛化动词开头,且不含任何具体对象(版本号/文件/命令/数字/英文标识符)。
103
+ * @param {string} label
104
+ * @returns {boolean}
105
+ */
106
+ export function isGenericLabel(label) {
107
+ const text = typeof label === "string" ? label.trim() : "";
108
+ if (text === "") return true;
109
+ if (!GENERIC_VERBS.test(text)) return false;
110
+ const tokens = concreteTokens(text);
111
+ // 只剩「定义」「实现细节」这类抽象名词时 tokens 可能非空,所以这里再要求
112
+ // 出现过至少一个「像标识符/数字/路径」的 token 才算具体。
113
+ for (const token of tokens) {
114
+ if (/^[a-z0-9_./#-]+$/iu.test(token) || /\d/u.test(token)) return false;
115
+ }
116
+ return true;
117
+ }
118
+
119
+ /**
120
+ * 幽灵提示与推荐按钮文案是否在说同一件事:至少共享一个具体对象。
121
+ * 不共享时返回 false,调用方会把幽灵提示退化成按钮文案本身(宁可短,也不打脸)。
122
+ * @param {string} ghost
123
+ * @param {string} label
124
+ * @returns {boolean}
125
+ */
126
+ export function ghostAgreesWithLabel(ghost, label) {
127
+ const ghostText = typeof ghost === "string" ? ghost : "";
128
+ const labelText = typeof label === "string" ? label : "";
129
+ const right = concreteTokens(labelText);
130
+ if (right.size === 0) return true;
131
+ const haystack = ghostText.toLowerCase();
132
+ for (const token of right) {
133
+ // 中文按「连续汉字串」切分时,包含关系比完全相同更可靠:
134
+ // 「冒烟」与「冒烟和桌面回归」说的是同一件事。
135
+ if (haystack.includes(token)) return true;
136
+ }
137
+ const left = concreteTokens(ghostText);
138
+ for (const token of left) {
139
+ if (labelText.toLowerCase().includes(token)) return true;
140
+ }
141
+ return false;
142
+ }
143
+
62
144
  /**
63
145
  * 系统提示词:只做一件事——判断这一轮是否值得继续,并把对话压成一张决策卡,严格 JSON。
64
146
  * @param {{ locale?: string }} [options]
@@ -79,16 +161,26 @@ export function buildSystemPrompt(options = {}) {
79
161
  " - false:任务已完整收尾、没有自然的下一步;最后的回答已经向用户提出了明确的问题或请求;用户已表示结束(如「不用了」「谢谢」);继续只会重复劳动。",
80
162
  " - true:存在需要用户拍板的方向,或存在明显值得继续做下去的下一步。",
81
163
  `2. reason:一句话说明 needed 的判断依据,${REASON_MAX} 字以内,直接说事实,不要客套。`,
82
- "3. summary:1–3 句客观陈述当前状态(做到哪、卡在哪、还差什么),不评价、不客套。",
83
- "4. question:一句向用户确认方向的问题,必须以问号结尾。",
84
- `5. options:恰好 2 条,方向互斥(例如「按方案 A 改」vs「先补测试」),不能是同一件事的两种说法。`,
85
- " - stance:英文小写短语标识立场,两条必须不同(如 verify / proceed / harder / alternative)。",
86
- ` - label:按钮文案,也就是用户点一下后**原样发送**给助手的用户消息;${LABEL_MIN}–${LABEL_MAX} 字,动词开头,单独发出去就能干活。`,
164
+ "3. summary:写**这一轮实际发生了什么**的可核查事实,不许写「用户要求……助手已经……」这种旁白。",
165
+ " 好例子:「改了 importer/csv.ts 的流式读取,内存峰值 1.8 GB → 90 MB;parseRow 补了 3 个边界用例。」",
166
+ " 坏例子:「用户要求改导入脚本,助手已完成修改,无需补充信息。」",
167
+ " 1–3 句,不评价、不客套;没有具体事实(文件名、命令、数值、PR 号、测试结果)就说明这轮不值得出卡。",
168
+ "4. question:一句向用户确认方向的问题,必须以问号结尾,且要能从上一条 summary 里读懂。",
169
+ `5. options:1–2 条,方向互斥(例如「按方案 A 改」vs「先补测试」),不能是同一件事的两种说法。`,
170
+ " - 只给 1 条也可以:当下一步非常明确、没有第二条像样的路时,宁可不凑数。",
171
+ " - 两件事都要做、而且顺序固定时,把它们合并成**一条** label(如「出 v1.5 和 E2E-01c」),不要拆成两条。",
172
+ " - stance:英文小写短语标识立场,多条时必须互不相同(如 verify / proceed / harder / alternative)。",
173
+ ` - label:按钮文案,也就是用户点一下后**原样发送**给助手的用户消息;${LABEL_MIN}–${LABEL_MAX} 字。`,
174
+ " 必须是「动词 + 具体对象」:对象要来自这段对话(文件名、命令、参数值、版本号、PR/issue 号)。",
175
+ " 反例:「检查定义是否准确」「扩展到实现细节」——没有具体对象,换成任何一轮都成立,一律不要。",
87
176
  " 不要用「继续」「好的」这类悬空短语,不要写成问句,不要把解释塞进 label。",
88
- `6. nextPrompt:一句用户口吻的下一句输入建议,${NEXT_PROMPT_MAX} 字以内;关键信息放前 40 字内。`,
177
+ `6. nextPrompt:输入框里的幽灵提示,一句用户口吻的下一句输入,${NEXT_PROMPT_MAX} 字以内;`,
178
+ ` 关键信息(对象或动作)放前 ${NEXT_PROMPT_HEAD} 字内,超出会被省略号截断。`,
179
+ " 它和 options 必须是**同一个建议**的两种说法(可以更长、更口语),不许各说一件事。",
89
180
  `7. 语言:跟随对话中用户使用的语言(当前界面语言 ${locale},仅供参考)。`,
90
181
  "8. needed 为 false 时也要按上面的结构给出 summary / question / options —— 用户可能手动请求这张卡。",
91
182
  "9. 信息不足时,两个方向应当是「先补信息」与「按现有信息推进」,不要编造事实。",
183
+ "10. 拿不准就不要编:任何一条 label 找不到对话里的具体对象时,直接减少 options 数量(最少 1 条)。",
92
184
  ].join("\n");
93
185
  }
94
186
 
@@ -146,7 +238,8 @@ export function parseSuggestion(raw) {
146
238
  if (question === "" || question.length > QUESTION_MAX) return null;
147
239
 
148
240
  const rawOptions = Array.isArray(parsed.options) ? parsed.options : [];
149
- if (rawOptions.length !== 2) return null;
241
+ // 1–2 条:只给 1 条是「下一步很明确」,不是残缺;3 条以上是选择成本,不要。
242
+ if (rawOptions.length < 1 || rawOptions.length > 2) return null;
150
243
  /** @type {{ stance: string, label: string }[]} */
151
244
  const options = [];
152
245
  for (const option of rawOptions) {
@@ -157,13 +250,27 @@ export function parseSuggestion(raw) {
157
250
  if (label.length < LABEL_MIN || label.length > LABEL_MAX) return null;
158
251
  options.push({ stance, label });
159
252
  }
160
- if (options[0].stance === options[1].stance) return null;
253
+ if (options.length === 2 && options[0].stance === options[1].stance) return null;
254
+ // 泛化按钮:找不到对话里的具体对象、又只由空话动词构成的,直接丢掉这条。
255
+ // 一条都不剩就整卡不出——「检查定义是否准确」这种套在任何一轮都成立的按钮,
256
+ // 正是点击率低的直接原因。
257
+ const kept = options.filter((option) => !isGenericLabel(option.label));
258
+ if (kept.length === 0) return null;
259
+
260
+ options.length = 0;
261
+ options.push(...kept);
161
262
 
162
263
  /** @type {{ needed: boolean, reason: string, summary: string, question: string, options: { stance: string, label: string }[], nextPrompt?: string }} */
163
264
  const result = { needed, reason, summary, question, options };
164
265
  if (parsed.nextPrompt !== undefined) {
165
- const nextPrompt = typeof parsed.nextPrompt === "string" ? parsed.nextPrompt.trim() : "";
166
- if (nextPrompt.length > NEXT_PROMPT_MAX) return null;
266
+ let nextPrompt = typeof parsed.nextPrompt === "string" ? parsed.nextPrompt.trim() : "";
267
+ // 超长只截断,不丢整张卡:前半段本来就要求放关键信息。
268
+ if (nextPrompt.length > NEXT_PROMPT_MAX)
269
+ nextPrompt = nextPrompt.slice(0, NEXT_PROMPT_MAX).trim();
270
+ // 与推荐项不一致 → 退化成该按钮文案,保证「同一个建议的两种入口」。
271
+ if (nextPrompt !== "" && !ghostAgreesWithLabel(nextPrompt, options[0].label)) {
272
+ nextPrompt = options[0].label;
273
+ }
167
274
  if (nextPrompt !== "") result.nextPrompt = nextPrompt;
168
275
  }
169
276
  return result;
package/lib/service.js CHANGED
@@ -11,7 +11,9 @@ 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 { abortReasonOf, abortReasonText, abortSkipKind, TIMEOUT_MESSAGE } from "./abort-reason.js";
14
15
  import { buildIdentity } from "./build-info.js";
16
+ import { cheapSkipReason } from "./gates.js";
15
17
  import {
16
18
  CARD_RECORD,
17
19
  DECISION_RECORD,
@@ -19,7 +21,13 @@ import {
19
21
  isDecisionData,
20
22
  nextStepProjection,
21
23
  } from "./projection.js";
22
- import { buildMessages, buildSystemPrompt, parseSuggestion, renderTranscript } from "./prompt.js";
24
+ import {
25
+ buildMessages,
26
+ buildSystemPrompt,
27
+ parseSuggestion,
28
+ renderTranscript,
29
+ textOf,
30
+ } from "./prompt.js";
23
31
  import { shouldSkipForQueue } from "./queue-gate.js";
24
32
  import { DEFAULT_SETTINGS, loadSettings, saveSettings } from "./settings.js";
25
33
 
@@ -181,10 +189,13 @@ export class NextStepService extends TypertRemoteService {
181
189
  this.config = config ?? {};
182
190
  this.logger = ctx?.logger ?? console;
183
191
  this.dataRoot = resolveDataRoot(this.config);
184
- /** @type {{ generated: number, failed: number, skipped: number, skippedByModel: number, acted: number, dismissed: number }} */
192
+ /** @type {{ generated: number, failed: number, aborted: number, skipped: number, skippedByModel: number, acted: number, dismissed: number }} */
185
193
  this.counters = {
186
194
  generated: 0,
187
195
  failed: 0,
196
+ // 生成被中止(超时/取消)。单独计数:中止既不写会话日志、原来也不计数,
197
+ // 导致「卡片没出来」在诊断里完全无痕(见 abort-reason.js 的说明)。
198
+ aborted: 0,
188
199
  skipped: 0,
189
200
  skippedByModel: 0,
190
201
  acted: 0,
@@ -269,19 +280,33 @@ export class NextStepService extends TypertRemoteService {
269
280
  const settings = await this.currentSettings();
270
281
  if (!settings.enabled || !settings.card) return;
271
282
  const sessionId = session.id;
272
- if (settings.pauseUntil > Date.now()) {
273
- this.markSkip("paused", "generation is paused");
274
- return;
275
- }
276
- // 用户已经排了 ≥2 条消息就不再出卡(官方 action-cards 的同一条规则)。
277
- if (shouldSkipForQueue(queuedCountOf(this.ctx, sessionId))) {
278
- this.markSkip("queued", "the user already has queued messages");
279
- return;
280
- }
281
283
  const { cards } = scanSession(session);
282
- if (cards.has(turn)) return;
283
- if (cards.size >= settings.maxCardsPerSession) {
284
- this.markSkip("budget", "per-session card budget reached");
284
+
285
+ // 便宜闸统一在 gates.js:不通过就不发那次模型调用。
286
+ // 「上一轮报错/被中断」和「回答太短」是新加的两条——前者不该在旁边推销下一步,
287
+ // 后者没有足够上下文,生成出来必然是套话。
288
+ const messages = typeof session.deriveMessages === "function" ? session.deriveMessages() : [];
289
+ let lastAnswerChars = 0;
290
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
291
+ if (messages[index]?.role === "assistant") {
292
+ lastAnswerChars = textOf(messages[index]).length;
293
+ break;
294
+ }
295
+ }
296
+ const skip = cheapSkipReason({
297
+ enabled: settings.enabled,
298
+ cardEnabled: settings.card,
299
+ pauseUntil: settings.pauseUntil,
300
+ now: Date.now(),
301
+ queued: shouldSkipForQueue(queuedCountOf(this.ctx, sessionId)) ? 2 : 0,
302
+ cardsForTurn: cards.has(turn),
303
+ cardsInSession: cards.size,
304
+ maxCards: settings.maxCardsPerSession,
305
+ endKind: event?.data?.reason?.kind,
306
+ answerChars: lastAnswerChars,
307
+ });
308
+ if (skip !== null) {
309
+ if (skip.reason !== "disabled") this.markSkip(skip.reason, skip.detail);
285
310
  return;
286
311
  }
287
312
  await this.writeCardFor(session, settings, {
@@ -305,13 +330,20 @@ export class NextStepService extends TypertRemoteService {
305
330
  const controller = new AbortController();
306
331
  this.inflight.set(sessionId, controller);
307
332
  const timer = setTimeout(
308
- () => controller.abort(new Error("next-step timeout")),
333
+ () => controller.abort(new Error(TIMEOUT_MESSAGE)),
309
334
  settings.timeoutMs,
310
335
  );
311
336
  try {
312
337
  const result = await this.generate(session, settings, controller.signal);
313
- if (controller.signal.aborted) return { ok: false, reason: "aborted" };
314
- if (this.inflight.get(sessionId) !== controller) return { ok: false, reason: "aborted" };
338
+ if (controller.signal.aborted) {
339
+ this.markAbort(controller.signal.reason, settings.timeoutMs);
340
+ return { ok: false, reason: "aborted" };
341
+ }
342
+ // 同一会话又起了新的一次生成:这次被后来者取代,算取消而不是超时。
343
+ if (this.inflight.get(sessionId) !== controller) {
344
+ this.markAbort(undefined, settings.timeoutMs);
345
+ return { ok: false, reason: "aborted" };
346
+ }
315
347
  if (result === null) {
316
348
  this.counters.failed += 1;
317
349
  this.lastError = "model output did not match the card schema";
@@ -347,12 +379,21 @@ export class NextStepService extends TypertRemoteService {
347
379
  this.lastError = "";
348
380
  return { ok: true, card };
349
381
  } catch (error) {
350
- if (!controller.signal.aborted) {
351
- this.counters.failed += 1;
352
- this.lastError = error instanceof Error ? error.message : String(error);
353
- this.markFailure(this.lastError);
354
- this.warn("card generation failed", error);
382
+ // 超时/取消会让 generate() 以抛错收场(不是返回 null):这种中止原来完全无痕,
383
+ // 既不计 failed 也不写 lastSkip,诊断里看不到——所以先单独归类。
384
+ if (controller.signal.aborted) {
385
+ this.markAbort(controller.signal.reason, settings.timeoutMs);
386
+ return { ok: false, reason: "aborted" };
387
+ }
388
+ // 宿主自己抛的错误里也可能写着超时(定时器还没触发):同样按中止记,不记成 failed。
389
+ if (abortReasonOf(error) === "timeout") {
390
+ this.markAbort(error, settings.timeoutMs);
391
+ return { ok: false, reason: "aborted" };
355
392
  }
393
+ this.counters.failed += 1;
394
+ this.lastError = error instanceof Error ? error.message : String(error);
395
+ this.markFailure(this.lastError);
396
+ this.warn("card generation failed", error);
356
397
  return { ok: false, reason: "failed" };
357
398
  } finally {
358
399
  clearTimeout(timer);
@@ -386,6 +427,22 @@ export class NextStepService extends TypertRemoteService {
386
427
  };
387
428
  }
388
429
 
430
+ /**
431
+ * 记录一次「生成被中止」:计入 aborted 并写 lastSkip,让诊断行显示得出来。
432
+ * 不碰 failed(中止不是失败,也不该把 lastError 写成中止原因)。
433
+ * @param {unknown} reason AbortController 的 reason(超时时是本插件的 timeout Error)
434
+ * @param {number} [timeoutMs]
435
+ */
436
+ markAbort(reason, timeoutMs) {
437
+ const kind = abortReasonOf(reason);
438
+ this.counters.aborted += 1;
439
+ this.lastSkip = {
440
+ kind: abortSkipKind(kind),
441
+ reason: abortReasonText(kind, timeoutMs),
442
+ at: Date.now(),
443
+ };
444
+ }
445
+
389
446
  /**
390
447
  * 一次额外补全:prepareCall + stream,产出已校验的建议。
391
448
  * @param {any} session
package/locale/en.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "error.failed": "Something went wrong. Try again.",
15
15
  "error.send": "Could not fill the composer",
16
16
  "settings.title": "Next-step suggestions",
17
- "settings.desc": "Judges whether a turn is worth continuing; when it is, adds a status summary and two directions (one extra model call).",
17
+ "settings.desc": "Judges whether a turn is worth continuing; when it is, adds a status summary, a question and 1–2 concrete next steps (one extra model call).",
18
18
  "settings.enabled": "Enable the plugin",
19
19
  "settings.card": "Decision card under the answer",
20
20
  "settings.ghost": "Ghost hint in the composer",
@@ -40,6 +40,7 @@
40
40
  "error.inflight": "Already generating; try again in a moment",
41
41
  "error.noTurn": "No completed turn to generate a card for",
42
42
  "retry.generate": "Generate a next-step card",
43
- "retry.generating": "Generating…"
43
+ "retry.generating": "Generating…",
44
+ "settings.nav": "Next-step suggestions"
44
45
  }
45
46
  }
package/locale/zh.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "error.failed": "操作失败,请重试",
15
15
  "error.send": "没能把建议写进输入框",
16
16
  "settings.title": "下一步建议",
17
- "settings.desc": "答完后判断是否值得继续;需要时生成一张含摘要与两个方向建议的决策卡(一次额外模型调用)。",
17
+ "settings.desc": "答完后判断是否值得继续;需要时生成一张含摘要、提问与 1–2 条具体建议的决策卡(一次额外模型调用)。",
18
18
  "settings.enabled": "启用插件",
19
19
  "settings.card": "回答下方的决策卡",
20
20
  "settings.ghost": "输入框里的幽灵提示",
@@ -40,6 +40,7 @@
40
40
  "error.inflight": "正在生成,请稍候",
41
41
  "error.noTurn": "没有可生成建议的回合",
42
42
  "retry.generate": "生成下一步建议",
43
- "retry.generating": "正在生成…"
43
+ "retry.generating": "正在生成…",
44
+ "settings.nav": "下一步建议"
44
45
  }
45
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kangyishuai/dsh-next-step",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
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",