@kangyishuai/dsh-next-step 0.4.1 → 0.4.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 +12 -8
- package/README.zh-CN.md +20 -16
- package/lib/client.js +9 -1
- package/lib/events.js +1 -1
- package/lib/gates.js +14 -1
- package/lib/prompt.js +268 -9
- package/lib/report.js +12 -1
- package/lib/scheme.js +1 -1
- package/lib/service.js +126 -24
- package/locale/en.json +2 -0
- package/locale/zh.json +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Unofficial plugin for [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/de
|
|
|
27
27
|
## Cost & model calls
|
|
28
28
|
|
|
29
29
|
- 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.
|
|
30
|
-
- 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.
|
|
30
|
+
- 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. **One recovery attempt is allowed, and it always carries the same conversation**: if the model returns an _empty_ answer the request is simply resent (an empty string is not a formatting problem — asking the model to "repair" nothing is how content-free cards used to get written); if it returns something malformed but non-empty, the repair request repeats the transcript and asks only for the format. A card that cannot point at anything in the conversation is dropped and counted as `ungrounded`. 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.
|
|
31
31
|
- When the model grades the turn `no` (or `could`, and your tier is Strict), the candidate is stored but not shown — **the call still happens**: the tier saves UI noise, not tokens. Revealing a withheld candidate later costs nothing (no second call).
|
|
32
32
|
- The review log is a local append-only file that rotates at 2 MB (`events.jsonl` + one `.1` history). It contains no message text; it is on by default and can be switched off in the settings ("Local usage data").
|
|
33
33
|
- No other network access, no telemetry.
|
|
@@ -99,7 +99,8 @@ The row writes the same `$DSH_HOME/next-step.settings.json` that the host re-rea
|
|
|
99
99
|
| Paused, or the session's card budget (`maxCardsPerSession`) used up | No new card; existing cards stay. |
|
|
100
100
|
| A card or a decision already exists for that turn | One card per turn; no duplicates. |
|
|
101
101
|
| The model grades the turn `no`, or grades it `could` while your tier is Strict (`shown: false`) | The candidate is stored but hidden; the generate button **reveals it for free**. “Last skipped” shows the model's reason. |
|
|
102
|
-
| Model call failed, was rate-limited, bad JSON
|
|
102
|
+
| Model call failed, was rate-limited, bad JSON, or the card did not refer to this conversation | Silent; only a diagnostics counter goes up (`schema` / `ungrounded`). The generate button says the card was dropped. |
|
|
103
|
+
| No conversation content to work from (host seam moved / empty session) | No request at all: `no-context` in “Last skipped”. A card from nothing would be a card about nothing. |
|
|
103
104
|
| The generation **timed out (20 s) or was cancelled** | Counted in `aborted`; “Last skipped” says which, and the generate button reports it. No dialog. |
|
|
104
105
|
| The reply is still streaming | Nothing is rendered for the turn until it ends. |
|
|
105
106
|
| The composer already has a draft | The card is visible but the pills are disabled until the draft is cleared. |
|
|
@@ -114,6 +115,7 @@ The row writes the same `$DSH_HOME/next-step.settings.json` that the host re-rea
|
|
|
114
115
|
- **No cross-device sync.** Cards and decisions live in the local session log of the machine that generated them.
|
|
115
116
|
- **No cards in subagent sessions**, and none for interrupted or empty turns.
|
|
116
117
|
- **The ghost only offers the latest card's next prompt**, and only when the composer is empty and idle.
|
|
118
|
+
- **A card must be anchored in the conversation.** Besides the shape checks, the plugin mechanically verifies that the card is _about_ the material the model was given — either it names a concrete object that appears verbatim (file, command, version, PR number, identifier), or it shares at least two four-character Chinese phrases with it (so a paraphrasing card on a one-sentence answer still counts). Otherwise the card is discarded. Known gap: text that only ever appeared inside a tool result is not counted, because the check reads user/assistant text. See [ADR 0023](../../docs/adr/0023-next-step-grounded-cards.md).
|
|
117
119
|
- **The card text is model output.** The plugin validates the shape (1–2 options, distinct stances, a 2–20 character label that names a concrete object from the conversation) and drops only the individual options that fail; it never rewrites the wording.
|
|
118
120
|
- **A click sends exactly the pill's text** — there is no hidden “short label, long instruction behind it” layer. A `text` field left over in card records written by older versions is ignored.
|
|
119
121
|
|
|
@@ -121,12 +123,14 @@ The row writes the same `$DSH_HOME/next-step.settings.json` that the host re-rea
|
|
|
121
123
|
|
|
122
124
|
## Compatibility
|
|
123
125
|
|
|
124
|
-
| DSH version | Status
|
|
125
|
-
|
|
|
126
|
-
|
|
|
127
|
-
| 0.2.2-rc.3
|
|
128
|
-
| 0.2.2-rc.
|
|
129
|
-
| 0.2.2-rc.
|
|
126
|
+
| DSH version | Status |
|
|
127
|
+
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
128
|
+
| 0.2.2-rc.5 | **0.4.2** (2026-11-19): no code change needed for this DSH build. Verified: unit tests + `pnpm probe:runtime` 72/72 + web `pnpm smoke:next-step` **73/73** (real host, real model call; now includes the ✕-dismiss write path) + desktop read-only regression **21 PASS + 1 SKIP** (22 assertions; the SKIP is a data-dependent branch — that card has no expand button; the read-only pass no longer clicks ✕ because a decision is a permanent write, and it accepts the plugin's 1–2 pill contract). The new host surfaces this release (`CONTENT_REFUSED`, search-provider default routing) are not used here ([runtime rc.5](../../docs/runtime/0.2.2-rc.5.md)). |
|
|
129
|
+
| 0.2.2-rc.3 | **0.4.1** (2026-11-14): fixes a silent failure. The card is **delivered late by the projection** (the turn tail mounts and `status` becomes `interactive` first, the card arrives a moment later), while the effect that registers `⌘↵` only depended on `[sessionId, status]` — so a late card was never registered: it looked clickable and clicking the pill still worked, but `⌘↵` did nothing (it only worked when the tail remounted with the card already in the projection, hence "sometimes"). Fixed by adding card visibility / option count to the effect deps. Verified by `test/client-card-shortcut.test.js` (a mini hook runtime driving the real client source: late card, one/two pills, non-empty draft, unrevealed candidate, already decided; it fails without the fix) and on the real host: a late (≈2.3 s) two-pill card sent its primary pill with `⌘↵` and turned `sent`, while on 0.4.0 a late **one-pill** card also did nothing. Also fixes the header/delimiter order of the compatibility table in both READMEs. |
|
|
130
|
+
| 0.2.2-rc.3 | **0.4.0** (2026-11-14): the card face becomes tunable and measurable. The model grades a turn on three levels (`must` / `could` / `no`) instead of a boolean, and a setting picks which levels are shown (**strict / balanced (default) / eager**). A withheld card still stores its candidate and one click **reveals** it — no second model call; only a turn without any candidate regenerates. Parsing is tolerant (over-long text is clipped, a bad single option is dropped) with one repair call, so one over-long field can no longer delete a whole card. Every eligible turn appends one line to `<dataRoot>/next-step/events.jsonl` (gate, grade, latency, usage, what you did with the card, whether it entered the viewport; never your message text, local only, can be switched off), and the settings section writes a Markdown report with Wilson 95% intervals that refuses to give verdicts below 80 turns / 25 cards. Three deterministic losses are gone: the budget (30 → 120) only counts _shown_ cards, the short-answer gate now requires "few chars **and** no tool calls", and a bad field no longer voids the card. Settings moved to a 3-row first screen plus a "More settings" disclosure; the settings file is v2 (`schemaVersion` / `cardThreshold` / `telemetry`) and only migrates values equal to the old default. Verified: 170 unit tests + `pnpm probe:runtime` + web `pnpm smoke:next-step` **71/71** (real host, real model calls, including the withheld→reveal path and the event log) + desktop read-only regression. |
|
|
131
|
+
| 0.2.2-rc.3 | **0.3.1** (2026-11-14): makes an aborted generation diagnosable. A 20 s timeout or a cancellation used to leave **no trace at all** — no counter, no “Last skipped” entry, no session record — so a “no card appeared” incident was impossible to attribute after the fact. Now aborts increment a separate `aborted` counter (shown in the settings row as “已中止 N”), write a labelled “Last skipped” reason (`generation timeout after 20s` / `cancelled`), stay out of `failed` / `lastError`, and the generate button says “生成超时或被取消,请重试” instead of the generic failure text. Verified: 103 unit tests (4 new) + `pnpm probe:runtime` 72/72 + web `pnpm smoke:next-step` **59/59** (real host + real model call, re-run after the change) + desktop read-only regression **10 PASS + 2 SKIP**; `smoke:next-step` also gained the ability to print the plugin-reported reason and to keep its throwaway `DSH_HOME` when an assertion fails. |
|
|
132
|
+
| 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). |
|
|
133
|
+
| 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. |
|
|
130
134
|
|
|
131
135
|
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.
|
|
132
136
|
|
package/README.zh-CN.md
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
## 成本
|
|
28
28
|
|
|
29
29
|
- 每次触发多一次模型调用,用会话所在智能体当前的模型(取不到时回退到默认模型选择),**占用你自己的 provider 额度**。
|
|
30
|
-
- 这次调用 20 秒超时。其它失败、限流、JSON
|
|
30
|
+
- 这次调用 20 秒超时。其它失败、限流、JSON 不合法都**静默**:不出卡、不弹框,只在插件诊断里加计数。**恢复只允许一次,而且一定带着同一段对话**:模型返回**空**输出时,把同一个请求原样再发一次(空字符串不是格式问题——拿「空」去修格式,正是「没有对话内容的空卡」被写出来的机制);有内容但格式不对时,修复请求会重贴这段对话,只要求修格式。卡片里找不到任何对话中的对象时直接丢弃,计 `ungrounded`。**超时 / 被取消**单独计数(`aborted`,并在「最近跳过」写明 `generation timeout after 20s`),补生成按钮也会显示「生成超时或被取消」,所以这一类事后可诊断。不合法输出直接丢弃,不写记录。
|
|
31
31
|
- 模型判成 `no`(或判 `could` 而你选的是严格档)时不显示卡,但**这次调用已经发生**:档位省的是界面噪音,不是 token。事后揭示也不会再花一次调用。想看模型给出的理由,去设置页诊断里的「最近跳过」。
|
|
32
32
|
- 复盘日志是本机 append-only 文件,2 MB 滚动(`events.jsonl` + 一份 `.1` 历史)。里面没有消息原文;默认开启,可在设置里关掉(「本地采集与复盘数据」)。
|
|
33
33
|
- 除此之外不联网,不上报。
|
|
@@ -91,19 +91,20 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-next-step-*.tgz
|
|
|
91
91
|
|
|
92
92
|
## 什么情况下不出卡
|
|
93
93
|
|
|
94
|
-
| 情况 | 表现
|
|
95
|
-
| ------------------------------------------------------------ |
|
|
96
|
-
| 回合被停止、报错,或没有文本 | 不出卡:只有正常结束的回合才有资格。
|
|
97
|
-
| 子代理会话 | 按设计不出卡。
|
|
98
|
-
| 全局开关关闭 | 完全不发请求;已有卡片仍然留在对话里。
|
|
99
|
-
| 已暂停,或用完该会话的卡片预算(`maxCardsPerSession`) | 不出新卡;已有卡片保留。
|
|
100
|
-
| 该轮已经有 card 或 decision 记录 | 一轮最多一张卡,不重复。
|
|
101
|
-
| 模型判 `no`,或判 `could` 而你选的是严格档(`shown: false`) | 候选已落库但不显示;点补生成按钮**免费揭示**。诊断里「最近跳过」写明理由。
|
|
102
|
-
| 模型调用失败、限流、JSON
|
|
103
|
-
|
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
|
|
|
94
|
+
| 情况 | 表现 |
|
|
95
|
+
| ------------------------------------------------------------ | --------------------------------------------------------------------------------- |
|
|
96
|
+
| 回合被停止、报错,或没有文本 | 不出卡:只有正常结束的回合才有资格。 |
|
|
97
|
+
| 子代理会话 | 按设计不出卡。 |
|
|
98
|
+
| 全局开关关闭 | 完全不发请求;已有卡片仍然留在对话里。 |
|
|
99
|
+
| 已暂停,或用完该会话的卡片预算(`maxCardsPerSession`) | 不出新卡;已有卡片保留。 |
|
|
100
|
+
| 该轮已经有 card 或 decision 记录 | 一轮最多一张卡,不重复。 |
|
|
101
|
+
| 模型判 `no`,或判 `could` 而你选的是严格档(`shown: false`) | 候选已落库但不显示;点补生成按钮**免费揭示**。诊断里「最近跳过」写明理由。 |
|
|
102
|
+
| 模型调用失败、限流、JSON 不合法,或卡片没讲到这段对话 | 静默;只有诊断计数增加(`schema` / `ungrounded`),补生成按钮会说明卡片被丢弃。 |
|
|
103
|
+
| 拿不到任何对话内容(宿主 seam 变了 / 空会话) | **完全不发请求**:诊断「最近跳过」显示 `no-context`。没有原料的卡只会是一张空卡。 |
|
|
104
|
+
| 生成**超时(20 秒)或被取消** | 计入 `aborted`;「最近跳过」写明是哪一种,补生成按钮也会显示。不弹框。 |
|
|
105
|
+
| 回答还在流式输出 | 该轮结束前槽位不渲染。 |
|
|
106
|
+
| 输入框里已有草稿 | 卡片照常显示,但胶囊禁用,直到清空草稿。 |
|
|
107
|
+
| ghost 开着,但草稿、附件、`@`、`/` 或输入状态不满足条件 | 提示隐藏。 |
|
|
107
108
|
|
|
108
109
|
## 已知限制
|
|
109
110
|
|
|
@@ -114,6 +115,7 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-next-step-*.tgz
|
|
|
114
115
|
- **不做跨设备同步。** 卡片和决策只存在生成它的那台机器的本地会话日志里。
|
|
115
116
|
- **子代理会话不出卡**,被中断或没有文本的回合也不出。
|
|
116
117
|
- **幽灵提示只给最新一张卡的下一句**,且只在输入框为空、会话空闲时出现。
|
|
118
|
+
- **卡片必须落在对话上。** 除了形状校验,插件还会机械核对卡片是不是在讲**模型看到的那段对话**:要么它引用的某个具体对象(文件、命令、版本号、PR 号、标识符)在对话里原样出现,要么它与对话共享至少 2 条中文 4 字片段(一句话回答里「改写说法」的卡片也算数),否则丢弃。已知缺口:只出现在工具结果里的内容不计入判据(校验只读 user / assistant 文本)。见 [ADR 0023](../../docs/adr/0023-next-step-grounded-cards.md)。
|
|
117
119
|
- **卡片文字来自模型。** 插件会校验形状(1–2 条选项、方向互斥、label 2–20 字且含具体对象),超长/空话的单条会被丢掉(必要时先让模型修一次格式),但不改写措辞。
|
|
118
120
|
- **复盘要等样本。** 少于 80 个合格回合或 25 张卡时,报告只列计数并明写「样本不足」——一两天几十条数据得出的结论只会是噪声。
|
|
119
121
|
- **点击发出去的就是按钮文本**,不再有「按钮短、背后另有一段长指令」的隐藏层:旧版本卡片记录里残留的 `text` 字段会被忽略。
|
|
@@ -122,9 +124,11 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-next-step-*.tgz
|
|
|
122
124
|
|
|
123
125
|
## 兼容性
|
|
124
126
|
|
|
125
|
-
| DSH 版本
|
|
126
|
-
| 0.2.2-rc.3 | **0.4.0**(2026-11-14):卡片这一面变成**可调**且**可度量**。模型不再用一个 boolean,而是把回合打成三档(`must` / `could` / `no`),设置里选出卡频率(**严格 / 平衡(默认)/ 积极**)。被档位拦下的卡仍会存下候选,点一下**揭示**它——不再第二次调模型;只有压根没有候选的回合才真的重新生成。解析变宽容(超长文本截断、单条不合格只丢这一条)+ 一次修复调用,一个字段超长不再让整张卡消失。每个合格回合往 `<dataRoot>/next-step/events.jsonl` 追加一行(闸门、三档判定、耗时、token、你后来对卡做了什么、有没有进过视口;不写消息原文、只在本机、可关),设置页还能生成带 Wilson 95% 区间的 Markdown 报告,样本少于 80 回合 / 25 张卡时拒绝给判读。三处确定性丢失也修了:预算(30 → 120)只统计**出过**的卡、短答闸改成「字数少**且**没有工具调用」、单个字段超长不再废掉整张卡。设置页收敛成首屏 3 行 +「更多设置」折叠;设置文件升级到 v2(`schemaVersion` / `cardThreshold` / `telemetry`),只迁移等于旧默认值的字段。验证:单测 170 项 + `pnpm probe:runtime` + web `pnpm smoke:next-step` **71/71**(真实宿主、真实模型调用,含「抑制 → 揭示」链路与事件文件)+ 桌面只读回归。 |
|
|
127
|
+
| DSH 版本 | 状态 |
|
|
127
128
|
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
129
|
+
| 0.2.2-rc.5 | **0.4.2**(2026-11-19):这一版 DSH 不需要改代码。已验证:单测 + `pnpm probe:runtime` 72/72 + web `pnpm smoke:next-step` **73/73**(真实宿主 + 真实模型调用,含点 ✕ 的写路径)+ 桌面只读回归 **21 PASS + 1 SKIP**(22 项;SKIP 是数据相关分支「该卡没有展开按钮」;只读回归不再点 ✕——decision 是永久写入,且胶囊按插件契约 1–2 粒断言)。本版宿主新增的 `CONTENT_REFUSED` 与搜索提供方默认路由都与本插件无关([runtime rc.5](../../docs/runtime/0.2.2-rc.5.md))。 |
|
|
130
|
+
| 0.2.2-rc.3 | **0.4.1**(2026-11-14):修一个静默失效。卡片是**投影晚到**的(回合尾部先挂载、`status` 先变 `interactive`,卡片随后才从投影进来),而登记 `⌘↵` 的 effect 只依赖 `[sessionId, status]`,于是晚到的卡片永远登记不上:卡片看着可点、点胶囊也正常,`⌘↵` 却什么都不做(只在「重挂载那一刻卡片已在投影里」时能用,所以时灵时不灵)。修法是把「卡片可见 / 有候选」纳入 effect 依赖。验证:新增 `test/client-card-shortcut.test.js`(迷你 hooks 运行时驱动真实 client 源码,覆盖晚到卡、一粒 / 两粒、草稿非空、未揭示、已决策),去掉修复即红;真机上「晚到约 2.3s 的两粒卡」按 `⌘↵` 成功发出 primary 胶囊并转 `sent`;0.4.0 上同样条件下晚到的**一粒**卡同样不接管。顺带修了两份 README 兼容性表的表头/分隔行错位。 |
|
|
131
|
+
| 0.2.2-rc.3 | **0.4.0**(2026-11-14):卡片这一面变成**可调**且**可度量**。模型不再用一个 boolean,而是把回合打成三档(`must` / `could` / `no`),设置里选出卡频率(**严格 / 平衡(默认)/ 积极**)。被档位拦下的卡仍会存下候选,点一下**揭示**它——不再第二次调模型;只有压根没有候选的回合才真的重新生成。解析变宽容(超长文本截断、单条不合格只丢这一条)+ 一次修复调用,一个字段超长不再让整张卡消失。每个合格回合往 `<dataRoot>/next-step/events.jsonl` 追加一行(闸门、三档判定、耗时、token、你后来对卡做了什么、有没有进过视口;不写消息原文、只在本机、可关),设置页还能生成带 Wilson 95% 区间的 Markdown 报告,样本少于 80 回合 / 25 张卡时拒绝给判读。三处确定性丢失也修了:预算(30 → 120)只统计**出过**的卡、短答闸改成「字数少**且**没有工具调用」、单个字段超长不再废掉整张卡。设置页收敛成首屏 3 行 +「更多设置」折叠;设置文件升级到 v2(`schemaVersion` / `cardThreshold` / `telemetry`),只迁移等于旧默认值的字段。验证:单测 170 项 + `pnpm probe:runtime` + web `pnpm smoke:next-step` **71/71**(真实宿主、真实模型调用,含「抑制 → 揭示」链路与事件文件)+ 桌面只读回归。 |
|
|
128
132
|
| 0.2.2-rc.3 | **0.3.1**(2026-11-14):让被中止的生成可诊断。此前 20 秒超时或被取消**完全无痕**——不计数、不写「最近跳过」、也不落会话日志——所以一次「卡片没出来」事后无法归因。现在中止会计入独立的 `aborted` 计数(设置页显示「已中止 N」)、写带标签的「最近跳过」原因(`generation timeout after 20s` / `cancelled`)、不再混进 `failed` / `lastError`,补生成按钮的文案也从笼统的失败文案改为「生成超时或被取消,请重试」。已验证:103 项单测(新增 4)+ `pnpm probe:runtime` 72/72 + web `pnpm smoke:next-step` **59/59**(真实宿主 + 真实模型调用,改动后重跑)+ 桌面只读回归 **10 PASS + 2 SKIP**;`smoke:next-step` 同时补了「打印插件自报原因」与「断言失败自动保留临时 `DSH_HOME`」。 |
|
|
129
133
|
| 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 字」闸挡住,走的是补生成按钮那条兜底,顺带验证了闸)。 |
|
|
130
134
|
| 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 版本未验证。 |
|
package/lib/client.js
CHANGED
|
@@ -58,6 +58,8 @@ window.__ModuleLoader__.load({
|
|
|
58
58
|
"error.exists": "这一轮已经有卡片了",
|
|
59
59
|
"error.inflight": "正在生成,请稍候",
|
|
60
60
|
"error.noTurn": "没有可生成建议的回合",
|
|
61
|
+
"error.ungrounded": "生成的卡片与这段对话无关,已丢弃",
|
|
62
|
+
"error.noContext": "没有可用的对话内容,未生成卡片",
|
|
61
63
|
"retry.generate": "生成下一步建议",
|
|
62
64
|
"retry.generating": "正在生成…",
|
|
63
65
|
"settings.title": "下一步建议",
|
|
@@ -132,6 +134,8 @@ window.__ModuleLoader__.load({
|
|
|
132
134
|
"error.exists": "This turn already has a card",
|
|
133
135
|
"error.inflight": "Already generating; try again in a moment",
|
|
134
136
|
"error.noTurn": "No completed turn to generate a card for",
|
|
137
|
+
"error.ungrounded": "The generated card did not refer to this conversation; discarded",
|
|
138
|
+
"error.noContext": "No conversation content to generate a card from",
|
|
135
139
|
"retry.generate": "Generate a next-step card",
|
|
136
140
|
"retry.generating": "Generating…",
|
|
137
141
|
"settings.title": "Next-step suggestions",
|
|
@@ -203,6 +207,8 @@ window.__ModuleLoader__.load({
|
|
|
203
207
|
"no-turn": "error.noTurn",
|
|
204
208
|
failed: "error.failed",
|
|
205
209
|
schema: "error.failed",
|
|
210
|
+
ungrounded: "error.ungrounded",
|
|
211
|
+
"no-context": "error.noContext",
|
|
206
212
|
aborted: "error.aborted",
|
|
207
213
|
"not-needed": "error.failed",
|
|
208
214
|
};
|
|
@@ -606,12 +612,14 @@ window.__ModuleLoader__.load({
|
|
|
606
612
|
|
|
607
613
|
let code = typeof gesture.code === "string" ? gesture.code : "";
|
|
608
614
|
let primaryModifier = gesture.meta === true || gesture.control === true;
|
|
615
|
+
// 小键盘回车是 `NumpadEnter`,语义与 `Enter` 相同;只认 `Enter` 会让外接键盘上的 ⌘↵ 静默失效。
|
|
616
|
+
let enterLike = code === "Enter" || code === "NumpadEnter";
|
|
609
617
|
|
|
610
618
|
// 卡片快捷键:宿主的同一个手势是「Queue/Steer 互补发送」,但空草稿时它是 no-op
|
|
611
619
|
// (dsh-client-ui-conversation 的 empty-draft no-op),所以只在「输入干净 + 空闲 +
|
|
612
620
|
// 本会话有可交互卡」时接管;其余情况完全透传,绝不抢排队/插话的语义。
|
|
613
621
|
if (
|
|
614
|
-
|
|
622
|
+
enterLike &&
|
|
615
623
|
primaryModifier &&
|
|
616
624
|
!(gesture.meta === true && gesture.control === true) &&
|
|
617
625
|
!gesture.alt &&
|
package/lib/events.js
CHANGED
|
@@ -140,7 +140,7 @@ export function promoteEvent(input) {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
|
-
* @param {{ at: number, sid: string, turn: number, kind: "schema" | "timeout" | "cancelled" | "llm" | "route", detail?: string }} input
|
|
143
|
+
* @param {{ at: number, sid: string, turn: number, kind: "schema" | "ungrounded" | "timeout" | "cancelled" | "llm" | "route", detail?: string }} input
|
|
144
144
|
* @returns {any}
|
|
145
145
|
*/
|
|
146
146
|
export function errorEvent(input) {
|
package/lib/gates.js
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
// 被档位抑制的候选不占预算,否则严格档会把预算永远用不完、放松档位时又突然没了额度。
|
|
11
11
|
// - 短答闸不再只看最后一个回答的字数:工具密集型回合的收尾回答常常只有一句(「改好了」),
|
|
12
12
|
// 但上下文一点都不缺。判据改成「本轮回答总字数 < 80 **且** 本轮没有工具调用」。
|
|
13
|
+
//
|
|
14
|
+
// v0.5 补一条**接线闸**(见 docs/adr/0023):`deriveMessages()` 拿不到对话时 transcript 为空,
|
|
15
|
+
// 这时调模型必然产出「没有对话内容,请贴回来」的空卡。对话是空的就不要发请求。
|
|
16
|
+
|
|
17
|
+
import { MIN_CONTEXT_CHARS } from "./prompt.js";
|
|
13
18
|
|
|
14
19
|
/** 回答短于这个字符数、且本轮没有任何工具调用,就不出卡:没有足够上下文,生成的建议必然是空话。 */
|
|
15
20
|
export const MIN_ANSWER_CHARS = 80;
|
|
@@ -19,7 +24,7 @@ export const MIN_ANSWER_CHARS = 80;
|
|
|
19
24
|
* @param {{
|
|
20
25
|
* enabled: boolean, cardEnabled: boolean, pauseUntil: number, now: number,
|
|
21
26
|
* queued: number, cardsForTurn: boolean, shownCardsInSession: number, maxCards: number,
|
|
22
|
-
* endKind?: string, answerChars?: number, toolCalls?: number,
|
|
27
|
+
* endKind?: string, answerChars?: number, toolCalls?: number, contextChars?: number,
|
|
23
28
|
* }} input
|
|
24
29
|
* @returns {{ reason: string, detail: string } | null} 需要跳过时返回原因,否则 null
|
|
25
30
|
*/
|
|
@@ -27,6 +32,14 @@ export function cheapSkipReason(input) {
|
|
|
27
32
|
if (!input.enabled) return { reason: "disabled", detail: "card generation is off" };
|
|
28
33
|
if (!input.cardEnabled) return { reason: "disabled", detail: "cards are turned off" };
|
|
29
34
|
if (input.pauseUntil > input.now) return { reason: "paused", detail: "generation is paused" };
|
|
35
|
+
// 对话本身是空的(宿主没给 message / deriveMessages 被改名):模型再强也只能编。
|
|
36
|
+
// 这条闸不是质量阈值,而是**接线检查**——它的存在让「没接上」看起来像「没接上」。
|
|
37
|
+
if (input.contextChars !== undefined && input.contextChars < MIN_CONTEXT_CHARS) {
|
|
38
|
+
return {
|
|
39
|
+
reason: "no-context",
|
|
40
|
+
detail: `transcript has ${input.contextChars} chars; nothing to base a card on`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
30
43
|
// 用户已经排了 ≥2 条消息:他马上要说的话比任何建议都准。
|
|
31
44
|
if (input.queued >= 2)
|
|
32
45
|
return { reason: "queued", detail: "the user already has queued messages" };
|
package/lib/prompt.js
CHANGED
|
@@ -9,6 +9,13 @@
|
|
|
9
9
|
// - `label` 就是点击后原样发送的用户消息(WYSIWYG);2–20 字、必须是「动词 + 具体对象」。
|
|
10
10
|
// - **宽容解析**:超长的展示文本截断、不合格的单条 option 丢掉,不再因为一个字段超长就整张卡作废。
|
|
11
11
|
// 只有「结构不可用 / 三档判定缺失 / 一条可用建议都不剩」这三种才算失败,交给 service 做一次修复调用。
|
|
12
|
+
//
|
|
13
|
+
// 落地不变量(见 docs/adr/0023-next-step-grounded-cards.md):
|
|
14
|
+
// - **任何一次要产出卡片内容的调用,都必须带同一段对话**。修复调用原来不带,于是模型只能把
|
|
15
|
+
// 「上一次输出为空」写成一张卡(「这一轮没有拿到任何对话内容…把对话贴进来?」);
|
|
16
|
+
// - **空输出不是格式问题**:重发原请求,不拿空字符串去「修格式」;
|
|
17
|
+
// - **结构合法不等于有用**:卡片里至少要有一个对象能在对话里原样找到(`isGroundedIn`),否则丢弃;
|
|
18
|
+
// - **对话本身是空的就不调模型**:那是接线故障(`deriveMessages` 没接上),不是模型的问题。
|
|
12
19
|
|
|
13
20
|
import { PROMPT_VERSION } from "./scheme.js";
|
|
14
21
|
|
|
@@ -38,6 +45,22 @@ export const STANCE_MAX = 40;
|
|
|
38
45
|
export const OPTIONS_MAX = 2;
|
|
39
46
|
/** 修复调用里回贴模型原文的最大长度(避免把上次超长输出再喂回去撑爆上下文)。 */
|
|
40
47
|
export const REPAIR_ECHO_MAX = 4000;
|
|
48
|
+
/**
|
|
49
|
+
* 能做「落地校验」的对话材料上限(每行字符数)。
|
|
50
|
+
*
|
|
51
|
+
* 校验用的是「模型看到的那段对话」的**未裁剪**版本:卡片摘要里的数字/文件名常常出现在
|
|
52
|
+
* 回答的后半段,而喂给模型的 transcript 每条只留 800 字。这里放宽到 4000 字,只用于机械比对,
|
|
53
|
+
* 不发给模型。实测 909 张正常卡里 908 张通过(唯一不过的那张,对象全部是中文虚指)。
|
|
54
|
+
*/
|
|
55
|
+
export const MATERIAL_CLIP = 4000;
|
|
56
|
+
/**
|
|
57
|
+
* 判定「这段对话有没有可依据的内容」的最小字符数。
|
|
58
|
+
*
|
|
59
|
+
* 不是质量阈值,而是**接线检查**:`deriveMessages()` 没接上、或被宿主改名时 transcript 为空,
|
|
60
|
+
* 此时无论模型多强都只能编——历史事故里出现的正是这种卡(「这一轮没有拿到任何对话内容」)。
|
|
61
|
+
* 实测本机 909 张正常卡的 transcript 最短 935 字,离 40 很远,所以这个阈值不会误伤真实回合。
|
|
62
|
+
*/
|
|
63
|
+
export const MIN_CONTEXT_CHARS = 40;
|
|
41
64
|
/** 重新导出:提示词版本位,service 写卡片与事件时要用。 */
|
|
42
65
|
export { PROMPT_VERSION };
|
|
43
66
|
|
|
@@ -162,6 +185,203 @@ export function ghostAgreesWithLabel(ghost, label) {
|
|
|
162
185
|
return false;
|
|
163
186
|
}
|
|
164
187
|
|
|
188
|
+
/**
|
|
189
|
+
* 这些词只说明「是哪一类东西」,指认不了「是哪一件事」——对话里出现也不算落地证据。
|
|
190
|
+
* 前一组是**生成过程自己的词**:模型一旦自述生成过程(「上一次输出为空」「JSON 解析失败」),
|
|
191
|
+
* 卡片就会出现这些词;后一组是泛化名词,任何一轮的对话里都能找到。
|
|
192
|
+
*/
|
|
193
|
+
const NOT_IDENTITY = new Set([
|
|
194
|
+
// 生成过程 / 协议字段
|
|
195
|
+
"json",
|
|
196
|
+
"summary",
|
|
197
|
+
"question",
|
|
198
|
+
"value",
|
|
199
|
+
"options",
|
|
200
|
+
"option",
|
|
201
|
+
"stance",
|
|
202
|
+
"label",
|
|
203
|
+
"nextprompt",
|
|
204
|
+
"diff",
|
|
205
|
+
"pr",
|
|
206
|
+
"api",
|
|
207
|
+
"md",
|
|
208
|
+
"e2e",
|
|
209
|
+
// 泛化名词
|
|
210
|
+
"文件名",
|
|
211
|
+
"命令",
|
|
212
|
+
"目录",
|
|
213
|
+
"文件",
|
|
214
|
+
"代码",
|
|
215
|
+
"测试",
|
|
216
|
+
"结果",
|
|
217
|
+
"数值",
|
|
218
|
+
"版本",
|
|
219
|
+
"分支",
|
|
220
|
+
"仓库",
|
|
221
|
+
"提交",
|
|
222
|
+
"修复",
|
|
223
|
+
"实现",
|
|
224
|
+
"功能",
|
|
225
|
+
"问题",
|
|
226
|
+
"改动",
|
|
227
|
+
"更新",
|
|
228
|
+
"文档",
|
|
229
|
+
"卡片",
|
|
230
|
+
"对话",
|
|
231
|
+
"原文",
|
|
232
|
+
"消息",
|
|
233
|
+
"请求",
|
|
234
|
+
"输出",
|
|
235
|
+
"输入",
|
|
236
|
+
"回复",
|
|
237
|
+
"内容",
|
|
238
|
+
"字段",
|
|
239
|
+
"解析",
|
|
240
|
+
"报错",
|
|
241
|
+
"错误",
|
|
242
|
+
"任务",
|
|
243
|
+
"步骤",
|
|
244
|
+
"流程",
|
|
245
|
+
"结论",
|
|
246
|
+
"摘要",
|
|
247
|
+
"提问",
|
|
248
|
+
"建议",
|
|
249
|
+
"决策卡",
|
|
250
|
+
"上一轮",
|
|
251
|
+
"上一次",
|
|
252
|
+
"上一条",
|
|
253
|
+
"这一轮",
|
|
254
|
+
"这一步",
|
|
255
|
+
"下一步",
|
|
256
|
+
"继续",
|
|
257
|
+
"可以",
|
|
258
|
+
"需要",
|
|
259
|
+
"以下",
|
|
260
|
+
"这段",
|
|
261
|
+
]);
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 从文本里抽「能指认是哪一件事」的对象:版本号、文件名、命令、PR 号、带数字/下划线的标识符,
|
|
265
|
+
* 以及 ≥4 字、不像泛化名词的中文片段。
|
|
266
|
+
* 与 `concreteTokens` 的区别:后者用于**按钮文案**(宁松勿严,只要沾上具体对象就放行),
|
|
267
|
+
* 这里用于**落地校验**(宁严勿松:泛化名词和生成过程自己的词都不算对象)。
|
|
268
|
+
* @param {string} text
|
|
269
|
+
* @returns {Set<string>}
|
|
270
|
+
*/
|
|
271
|
+
export function identityTokens(text) {
|
|
272
|
+
const source = typeof text === "string" ? text : "";
|
|
273
|
+
const found = new Set();
|
|
274
|
+
for (const match of source.matchAll(/[A-Za-z0-9_./#-]{3,}/gu)) {
|
|
275
|
+
const token = match[0].replace(/^[./#-]+|[./#-]+$/gu, "").toLowerCase();
|
|
276
|
+
if (token.length < 3 || NOT_IDENTITY.has(token)) continue;
|
|
277
|
+
// 有数字 / 带路径分隔符 / 足够长的英文标识符:都能指认具体对象
|
|
278
|
+
if (/[0-9]/u.test(token) || /[./_#-]/u.test(token) || token.length >= 4) found.add(token);
|
|
279
|
+
}
|
|
280
|
+
for (const match of source.matchAll(/[\u4e00-\u9fa5]{4,}/gu)) {
|
|
281
|
+
const run = match[0];
|
|
282
|
+
// 中文动词/介词常粘在名词前面(「把二分查找」),去掉最多两个前导字再比对
|
|
283
|
+
for (let cut = 0; cut <= 2; cut += 1) {
|
|
284
|
+
const token = run.slice(cut);
|
|
285
|
+
if (token.length < 4) break;
|
|
286
|
+
if (!NOT_IDENTITY.has(token)) found.add(token);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return found;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* 落地校验:卡片里至少有一个对象,能在**模型看到的那段对话**里原样找到。
|
|
294
|
+
*
|
|
295
|
+
* 这是「卡片必须在讲这一段对话」的机械判据,补的是提示词管不到的那一半:
|
|
296
|
+
* 结构合法、文案漂亮,但整段都在讲生成过程或者凭空想象的卡片,一律不落地。
|
|
297
|
+
*
|
|
298
|
+
* 两条通道,命中一条即落地:
|
|
299
|
+
* 1. **具体对象原样出现**(`identityTokens`):文件名、命令、版本号、PR 号这类硬证据;
|
|
300
|
+
* 2. **共享 ≥2 条中文 4 字片段**:短回答(一句话解释一个概念)里,卡片通常是在**改写**答案而不是
|
|
301
|
+
* 引用文件名,一个具体对象都没有。这条通道按「有没有在讲同一件事」判,而不是按「有没有抄到 ID」。
|
|
302
|
+
* 中文 4-gram 能扛住前后粘着的动词(「用一句话把二分查找定义为」里含「二分查找」)。
|
|
303
|
+
*
|
|
304
|
+
* 实测(本机 1038 条历史卡片,其中 119 条自述式):只有通道 1 时正常卡 918/919、拦下自述卡 98/119;
|
|
305
|
+
* 加上通道 2 之后正常卡 919/919、仍然拦下 98/119 —— 只赚不亏。没有它,一句话回答的回合会被误杀
|
|
306
|
+
* (2026-11-21 桌面 --deep 实测:卡片共享 12 条 4 字片段、0 个具体对象,被误判成「与对话无关」)。
|
|
307
|
+
* @param {string} text 卡片正文(summary + question + options + nextPrompt)
|
|
308
|
+
* @param {string} material 模型看到的对话材料(可以未裁剪)
|
|
309
|
+
* @returns {boolean}
|
|
310
|
+
*/
|
|
311
|
+
export function isGroundedIn(text, material) {
|
|
312
|
+
const haystack = typeof material === "string" ? material.toLowerCase() : "";
|
|
313
|
+
if (haystack.trim() === "") return false;
|
|
314
|
+
for (const token of identityTokens(text)) {
|
|
315
|
+
if (haystack.includes(token)) return true;
|
|
316
|
+
}
|
|
317
|
+
return sharedChineseGramCount(text, haystack) >= CN_GRAM_MIN;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** 中文 4-gram 的窗口大小。 */
|
|
321
|
+
const CN_GRAM = 4;
|
|
322
|
+
/** 卡片与对话至少共享这么多条 4 字片段才算在讲同一件事。 */
|
|
323
|
+
const CN_GRAM_MIN = 2;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* 卡片与对话共享多少条不同的中文 4 字片段(只看卡片侧,逐条在对话里找)。
|
|
327
|
+
* @param {string} text 卡片正文
|
|
328
|
+
* @param {string} haystack 已小写的对话材料
|
|
329
|
+
* @returns {number}
|
|
330
|
+
*/
|
|
331
|
+
export function sharedChineseGramCount(text, haystack) {
|
|
332
|
+
const source = typeof text === "string" ? text : "";
|
|
333
|
+
const hay = typeof haystack === "string" ? haystack : "";
|
|
334
|
+
if (hay === "") return 0;
|
|
335
|
+
const seen = new Set();
|
|
336
|
+
for (const match of source.matchAll(/[\u4e00-\u9fa5]{4,}/gu)) {
|
|
337
|
+
const run = match[0];
|
|
338
|
+
for (let index = 0; index + CN_GRAM <= run.length; index += 1) {
|
|
339
|
+
const gram = run.slice(index, index + CN_GRAM);
|
|
340
|
+
if (!seen.has(gram) && hay.includes(gram)) seen.add(gram);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return seen.size;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* 卡片正文:落地校验要看全部展示文本,不只是按钮文案。
|
|
348
|
+
* @param {{ summary?: string, question?: string, options?: { label?: string }[], nextPrompt?: string }} suggestion
|
|
349
|
+
* @returns {string}
|
|
350
|
+
*/
|
|
351
|
+
export function groundableText(suggestion) {
|
|
352
|
+
if (!suggestion || typeof suggestion !== "object") return "";
|
|
353
|
+
const parts = [suggestion.summary, suggestion.question, suggestion.nextPrompt];
|
|
354
|
+
for (const option of Array.isArray(suggestion.options) ? suggestion.options : []) {
|
|
355
|
+
parts.push(option?.label);
|
|
356
|
+
}
|
|
357
|
+
return parts.filter((part) => typeof part === "string" && part !== "").join("\n");
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* 这段对话是否够长到能作为判断依据(接线检查,不是质量阈值)。
|
|
362
|
+
* @param {string} transcript
|
|
363
|
+
* @returns {boolean}
|
|
364
|
+
*/
|
|
365
|
+
export function hasContext(transcript) {
|
|
366
|
+
const text = typeof transcript === "string" ? transcript.trim() : "";
|
|
367
|
+
return text.length >= MIN_CONTEXT_CHARS;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* 解析失败后走哪条恢复路径:
|
|
372
|
+
* - `retry`:首次输出**是空的**。空输出不是格式问题,拿它去「修格式」只会让模型对着
|
|
373
|
+
* 「(空)」编一张卡片(历史上 95 条垃圾卡就是这么来的);正确做法是把**同一个请求**
|
|
374
|
+
* 原样再发一次。
|
|
375
|
+
* - `repair`:有内容但格式不对(不是 JSON / 缺字段 / 按钮文案超长)。这时确实该修格式,
|
|
376
|
+
* 且修复请求必须带上同一段对话。
|
|
377
|
+
* @param {{ raw?: unknown, problem?: unknown }} input
|
|
378
|
+
* @returns {"retry" | "repair"}
|
|
379
|
+
*/
|
|
380
|
+
export function recoveryPlan(input = {}) {
|
|
381
|
+
const raw = typeof input.raw === "string" ? input.raw.trim() : "";
|
|
382
|
+
return raw === "" ? "retry" : "repair";
|
|
383
|
+
}
|
|
384
|
+
|
|
165
385
|
/**
|
|
166
386
|
* 系统提示词:判断这一轮是否值得继续(三档),并把对话压成一张决策卡,严格 JSON。
|
|
167
387
|
*
|
|
@@ -205,8 +425,12 @@ export function buildSystemPrompt(options = {}) {
|
|
|
205
425
|
" 它和 options 必须是**同一个建议**的两种说法(可以更长、更口语),不许各说一件事。",
|
|
206
426
|
`7. 语言:跟随对话中用户使用的语言(当前界面语言 ${locale},仅供参考)。`,
|
|
207
427
|
'8. **即使 value 判为 "no",也要把 summary / question / options 写完整** —— 用户可能手动要这张卡。',
|
|
208
|
-
"9.
|
|
209
|
-
|
|
428
|
+
"9. **这段对话就是你手上的全部材料,它不缺东西**:绝不要要求用户「把对话/原文/改动/回复贴过来」,",
|
|
429
|
+
' 也不要把「信息不足」当成一个方向。对话里确实没有能写进 label 的具体对象时:value 判 "no",',
|
|
430
|
+
" summary 只写这段对话里唯一可核查的事实,只给 1 条 label —— 宁可不给建议,也不要写一张要材料的卡。",
|
|
431
|
+
"10. **不要描述你自己这次生成的过程**:不要出现「上一次输出」「JSON」「解析失败」「summary / question 字段」",
|
|
432
|
+
" 「决策卡内容」「本次请求」这类字样 —— 它们不是对话里的事实,写出来只会让用户看到一张自言自语的空卡。",
|
|
433
|
+
"11. 拿不准就不要编:任何一条 label 找不到对话里的具体对象时,直接减少 options 数量(最少 1 条)。",
|
|
210
434
|
].join("\n");
|
|
211
435
|
}
|
|
212
436
|
|
|
@@ -229,41 +453,76 @@ export function buildMessages(input = {}) {
|
|
|
229
453
|
/**
|
|
230
454
|
* 失败原因 → 给修复调用的中文说明。
|
|
231
455
|
* @param {"json" | "value" | "options"} kind
|
|
456
|
+
* @param {unknown} [detail] `parseSuggestion` 的 problem.detail(用来给出可执行的收紧信息)
|
|
232
457
|
* @returns {string}
|
|
233
458
|
*/
|
|
234
|
-
export function problemText(kind) {
|
|
459
|
+
export function problemText(kind, detail) {
|
|
235
460
|
if (kind === "value") {
|
|
236
461
|
return 'value 必须是 "must" / "could" / "no" 三者之一(不要用 needed 之类的旧字段代替)';
|
|
237
462
|
}
|
|
238
463
|
if (kind === "options") {
|
|
239
|
-
|
|
464
|
+
const base = `options 里没有一条可用的建议:需要 1–${OPTIONS_MAX} 条,label 为 ${LABEL_MIN}–${LABEL_MAX} 字、必须是「动词 + 对话里的具体对象」,不能是「检查定义是否准确」这类放到哪一轮都成立的空话`;
|
|
465
|
+
// 把「你上一次到底写了多少字」直接写进修复请求:模型数不准自己的字数(实测 20 字上限
|
|
466
|
+
// 被写成 21–22 字,只提示「2–20 字」修不回来),给出实际数字才知道要压多少。
|
|
467
|
+
const overshoot = overlongLabelHint(detail);
|
|
468
|
+
return overshoot === "" ? base : `${base}。${overshoot}`;
|
|
240
469
|
}
|
|
241
470
|
return "不是合法 JSON,或缺少 summary / question 这两个必填文本字段";
|
|
242
471
|
}
|
|
243
472
|
|
|
244
473
|
/**
|
|
245
|
-
*
|
|
474
|
+
* 从解析失败的 detail 里读「上一次 label 到底几字」,生成一句可执行的收紧提示。
|
|
475
|
+
* @param {unknown} detail `parseSuggestion` 的 problem.detail(如 `dropped-option:0:label-length:22`)
|
|
476
|
+
* @returns {string} 没有长度问题时返回空串
|
|
477
|
+
*/
|
|
478
|
+
export function overlongLabelHint(detail) {
|
|
479
|
+
const text = typeof detail === "string" ? detail : "";
|
|
480
|
+
/** @type {number[]} */
|
|
481
|
+
const lengths = [];
|
|
482
|
+
for (const match of text.matchAll(/label-length:(\d+)/gu)) {
|
|
483
|
+
const value = Number(match[1]);
|
|
484
|
+
if (Number.isSafeInteger(value) && value > 0) lengths.push(value);
|
|
485
|
+
}
|
|
486
|
+
if (lengths.length === 0) return "";
|
|
487
|
+
const longest = Math.max(...lengths);
|
|
488
|
+
return `你上一次的 label 有 ${lengths.join(" / ")} 字,上限是 ${LABEL_MAX} 字(最长那条超了 ${longest - LABEL_MAX} 字)——请压到 ${LABEL_MAX} 字以内,并保留同一个具体对象`;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* 构造「修复」调用:**把同一段对话再带上**,然后回贴上次原文与具体问题,只要求它修格式。
|
|
493
|
+
*
|
|
494
|
+
* 为什么必须带对话(否则就是历史事故的根因):修复只回贴「上一次输出 + 报错」,模型手里就只剩
|
|
495
|
+
* 「上一次输出为空、缺少 summary / question」这一条信息;它的唯一出路是把这条信息写成一张卡:
|
|
496
|
+
* 「这一轮没有拿到任何对话内容……把对话贴进来?」。这张卡结构合法、能过校验、还能显示出来 ——
|
|
497
|
+
* 于是「没有对话内容」的卡反复出现在用户面前。一次修复不能凭空修内容,它必须看得见原料。
|
|
246
498
|
*
|
|
247
499
|
* 刻意只用一条 user 消息、不伪造 assistant 轮次(宿主 adapter 对 assistant 消息有额外要求,
|
|
248
500
|
* 伪造容易在 provider 侧被拒)。
|
|
249
|
-
* @param {{ raw: unknown, problem: "json" | "value" | "options" }} input
|
|
501
|
+
* @param {{ transcript?: string, raw: unknown, problem: "json" | "value" | "options", detail?: unknown }} input
|
|
250
502
|
* @returns {{ role: "user", content: { type: "text", text: string }[] }[]}
|
|
251
503
|
*/
|
|
252
504
|
export function buildRepairMessage(input) {
|
|
505
|
+
const transcript = typeof input.transcript === "string" ? input.transcript.trim() : "";
|
|
253
506
|
const raw = typeof input.raw === "string" ? input.raw : String(input.raw ?? "");
|
|
254
507
|
const echoed = raw.length > REPAIR_ECHO_MAX ? `${raw.slice(0, REPAIR_ECHO_MAX)}…` : raw;
|
|
255
508
|
const text = [
|
|
256
|
-
"
|
|
257
|
-
`问题:${problemText(input.problem)}。`,
|
|
509
|
+
"以下是最近的对话(与上一次请求相同),请据此修正你上一次的决策卡输出。",
|
|
258
510
|
"",
|
|
259
|
-
"
|
|
511
|
+
"对话:",
|
|
512
|
+
transcript === "" ? "(没有可用的对话内容)" : transcript,
|
|
513
|
+
"",
|
|
514
|
+
"你上一次的输出:",
|
|
260
515
|
'"""',
|
|
261
516
|
echoed === "" ? "(空)" : echoed,
|
|
262
517
|
'"""',
|
|
263
518
|
"",
|
|
519
|
+
`问题:${problemText(input.problem, input.detail)}。`,
|
|
520
|
+
"",
|
|
264
521
|
"请只输出修正后的 JSON 对象,结构如下(字段含义与之前的要求完全相同):",
|
|
265
522
|
'{ "value": "must" | "could" | "no", "reason": "…", "summary": "…", "question": "…", "options": [ { "stance": "…", "label": "…" } ], "nextPrompt": "…" }',
|
|
266
523
|
"不要输出任何解释、不要用代码围栏。",
|
|
524
|
+
"summary / question / options 的内容必须仍然来自上面这段对话;不要描述这次修正本身," +
|
|
525
|
+
"也不要要求用户补充对话内容 —— 对话就在上面。",
|
|
267
526
|
].join("\n");
|
|
268
527
|
return [{ role: "user", content: [{ type: "text", text }] }];
|
|
269
528
|
}
|
package/lib/report.js
CHANGED
|
@@ -305,6 +305,9 @@ export function summarize(events) {
|
|
|
305
305
|
gates: gateCounts,
|
|
306
306
|
errors: { total: errors.length, byKind: errorKinds },
|
|
307
307
|
schemaShare: gateOkTurns === 0 ? 0 : (errorKinds.schema ?? 0) / gateOkTurns,
|
|
308
|
+
// 落地校验丢弃率:结构合法但讲不到这段对话的卡(自述生成过程 / 凭空想象)。
|
|
309
|
+
// 单独一个指标,因为它对应的病根和「格式失败」完全不同(见 docs/adr/0023)。
|
|
310
|
+
ungroundedShare: gateOkTurns === 0 ? 0 : (errorKinds.ungrounded ?? 0) / gateOkTurns,
|
|
308
311
|
insufficient: turns.size < MIN_TURNS || shown < MIN_SHOWN,
|
|
309
312
|
};
|
|
310
313
|
}
|
|
@@ -378,6 +381,14 @@ export function verdicts(metrics) {
|
|
|
378
381
|
});
|
|
379
382
|
}
|
|
380
383
|
|
|
384
|
+
if ((metrics.ungroundedShare ?? 0) > 0.05) {
|
|
385
|
+
out.push({
|
|
386
|
+
code: "ungrounded-cards",
|
|
387
|
+
text: `有 ${Math.round(metrics.ungroundedShare * 100)}% 的生成因为「卡片与对话无关」被丢弃(${metrics.errors.byKind.ungrounded ?? 0}/${metrics.turns + metrics.errors.total})。`,
|
|
388
|
+
action: "这通常是模型在自述生成过程:先确认修复调用带了对话,再收紧提示词第 9–10 条。",
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
|
|
381
392
|
if ((metrics.gates.budget ?? 0) > 0) {
|
|
382
393
|
out.push({
|
|
383
394
|
code: "budget-hit",
|
|
@@ -415,7 +426,7 @@ function ciText(ci) {
|
|
|
415
426
|
export function renderMarkdown(metrics, list) {
|
|
416
427
|
const lines = [];
|
|
417
428
|
const iso = (/** @type {number} */ at) =>
|
|
418
|
-
at > 0 ? new Date(at).toISOString().replace("T", " ").slice(0, 16)
|
|
429
|
+
at > 0 ? `${new Date(at).toISOString().replace("T", " ").slice(0, 16)}Z` : "—";
|
|
419
430
|
lines.push("# next-step 复盘报告");
|
|
420
431
|
lines.push("");
|
|
421
432
|
lines.push(`- 生成时间:${iso(metrics.lastAt)}`);
|
package/lib/scheme.js
CHANGED
package/lib/service.js
CHANGED
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
// promote / error。事件落在 `<dataRoot>/next-step/events.jsonl`,不写进会话日志。
|
|
12
12
|
// 3. 宽容解析 + 一次修复调用:格式问题不再让整张卡消失。
|
|
13
13
|
//
|
|
14
|
+
// v0.5 的一条不变量(见 docs/adr/0023):**结构合法 ≠ 有用**。任何一次要产出卡片内容的调用都必须
|
|
15
|
+
// 带同一段对话;空输出重发原请求而不是「修格式」;写卡前再做一次落地校验(卡片里至少有一个对象
|
|
16
|
+
// 能在对话里找到)。没有对话内容时直接跳过,不调模型 —— 这条路径曾经稳定产出「这一轮没有拿到
|
|
17
|
+
// 任何对话内容,请把对话贴进来」的空卡,95 条历史记录全部来自这里。
|
|
18
|
+
//
|
|
14
19
|
// 说明:插件可以 import 宿主的 @deepseek-ai/* 包(运行时由宿主解析),但不能把它们写进
|
|
15
20
|
// package.json 的 dependencies —— `pnpm check` 会拦(AGENTS.md 硬性约定 3)。
|
|
16
21
|
|
|
@@ -50,7 +55,13 @@ import {
|
|
|
50
55
|
buildRepairMessage,
|
|
51
56
|
buildSystemPrompt,
|
|
52
57
|
concreteTokens,
|
|
58
|
+
groundableText,
|
|
59
|
+
hasContext,
|
|
60
|
+
identityTokens,
|
|
61
|
+
isGroundedIn,
|
|
62
|
+
MATERIAL_CLIP,
|
|
53
63
|
parseSuggestion,
|
|
64
|
+
recoveryPlan,
|
|
54
65
|
renderTranscript,
|
|
55
66
|
textOf,
|
|
56
67
|
} from "./prompt.js";
|
|
@@ -240,6 +251,36 @@ function answerStatsOf(session) {
|
|
|
240
251
|
return { answerChars, toolCalls };
|
|
241
252
|
}
|
|
242
253
|
|
|
254
|
+
/**
|
|
255
|
+
* 恢复路径 → 事件里的 `parse` 字段(报表按它分组对比)。
|
|
256
|
+
* @param {"none" | "retry" | "repair"} recovery
|
|
257
|
+
* @returns {"ok" | "retried" | "repaired"}
|
|
258
|
+
*/
|
|
259
|
+
function parseKindOf(recovery) {
|
|
260
|
+
if (recovery === "retry") return "retried";
|
|
261
|
+
return recovery === "repair" ? "repaired" : "ok";
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 本轮要发给模型的对话材料(一次算好,闸、请求、落地校验共用同一份)。
|
|
266
|
+
*
|
|
267
|
+
* 两个口径,别混用:
|
|
268
|
+
* - `transcript` 发给模型(每条消息裁剪到 800 字,只留最近 N 条);
|
|
269
|
+
* - `material` 只用于**落地校验**(同一条窗口、不裁剪):摘要里的数字/文件名常在回答后半段,
|
|
270
|
+
* 拿裁剪过的版本去校验会误杀正常卡。它不发给模型。
|
|
271
|
+
* @param {any} session
|
|
272
|
+
* @param {any} settings
|
|
273
|
+
* @returns {{ transcript: string, material: string }}
|
|
274
|
+
*/
|
|
275
|
+
function contextOf(session, settings) {
|
|
276
|
+
const messages = typeof session?.deriveMessages === "function" ? session.deriveMessages() : [];
|
|
277
|
+
const limit = settings?.contextMessages;
|
|
278
|
+
return {
|
|
279
|
+
transcript: renderTranscript(messages, { limit }),
|
|
280
|
+
material: renderTranscript(messages, { limit, clip: MATERIAL_CLIP }),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
243
284
|
/**
|
|
244
285
|
* 卡片条数 → 其中"出过"的(预算闸只统计它们;被档位抑制的候选不占预算)。
|
|
245
286
|
* @param {Map<number, any>} cards
|
|
@@ -461,6 +502,7 @@ export class NextStepService extends TypertRemoteService {
|
|
|
461
502
|
const sessionId = session.id;
|
|
462
503
|
const { cards } = scanSession(session);
|
|
463
504
|
const stats = answerStatsOf(session);
|
|
505
|
+
const context = contextOf(session, settings);
|
|
464
506
|
|
|
465
507
|
const skip = cheapSkipReason({
|
|
466
508
|
enabled: settings.enabled,
|
|
@@ -474,6 +516,7 @@ export class NextStepService extends TypertRemoteService {
|
|
|
474
516
|
endKind: event?.data?.reason?.kind,
|
|
475
517
|
answerChars: stats.answerChars,
|
|
476
518
|
toolCalls: stats.toolCalls,
|
|
519
|
+
contextChars: context.transcript.length,
|
|
477
520
|
});
|
|
478
521
|
if (skip !== null) {
|
|
479
522
|
if (skip.reason !== "disabled") this.markSkip(skip.reason, skip.detail);
|
|
@@ -494,6 +537,7 @@ export class NextStepService extends TypertRemoteService {
|
|
|
494
537
|
seq: Number.isSafeInteger(event?.seq) ? event.seq : 0,
|
|
495
538
|
force: false,
|
|
496
539
|
feat: stats,
|
|
540
|
+
context,
|
|
497
541
|
});
|
|
498
542
|
}
|
|
499
543
|
|
|
@@ -501,7 +545,11 @@ export class NextStepService extends TypertRemoteService {
|
|
|
501
545
|
* 跑一次模型调用并为该轮写卡(自动门控与手动补生成共用)。
|
|
502
546
|
* @param {any} session
|
|
503
547
|
* @param {any} settings
|
|
504
|
-
* @param {{
|
|
548
|
+
* @param {{
|
|
549
|
+
* turn: number, seq: number, force: boolean,
|
|
550
|
+
* feat?: { answerChars: number, toolCalls: number },
|
|
551
|
+
* context?: { transcript: string, material: string },
|
|
552
|
+
* }} options
|
|
505
553
|
* force=true 时无视档位阈值(用户明确要卡),但仍受总开关/预算约束
|
|
506
554
|
* @returns {Promise<{ ok: true, card: any } | { ok: false, reason: string }>}
|
|
507
555
|
*/
|
|
@@ -510,6 +558,13 @@ export class NextStepService extends TypertRemoteService {
|
|
|
510
558
|
const turn = options.turn;
|
|
511
559
|
const feat = options.feat ?? answerStatsOf(session);
|
|
512
560
|
const sid = sidOf(sessionId);
|
|
561
|
+
const context = options.context ?? contextOf(session, settings);
|
|
562
|
+
// 补生成(force)绕过了便宜闸,所以这里再确认一次:对话是空的就不发请求。
|
|
563
|
+
if (!hasContext(context.transcript)) {
|
|
564
|
+
this.counters.skipped += 1;
|
|
565
|
+
this.markSkip("no-context", "no conversation content to base a card on");
|
|
566
|
+
return { ok: false, reason: "no-context" };
|
|
567
|
+
}
|
|
513
568
|
if (this.inflight.has(sessionId)) this.abortInflight(sessionId);
|
|
514
569
|
const controller = new AbortController();
|
|
515
570
|
this.inflight.set(sessionId, controller);
|
|
@@ -518,7 +573,7 @@ export class NextStepService extends TypertRemoteService {
|
|
|
518
573
|
settings.timeoutMs,
|
|
519
574
|
);
|
|
520
575
|
try {
|
|
521
|
-
const result = await this.generate(session, settings, controller.signal);
|
|
576
|
+
const result = await this.generate(session, settings, controller.signal, context);
|
|
522
577
|
if (controller.signal.aborted) {
|
|
523
578
|
this.markAbort(controller.signal.reason, settings.timeoutMs);
|
|
524
579
|
await this.writeErrorEvent(
|
|
@@ -534,7 +589,15 @@ export class NextStepService extends TypertRemoteService {
|
|
|
534
589
|
await this.writeErrorEvent(sid, turn, "cancelled");
|
|
535
590
|
return { ok: false, reason: "aborted" };
|
|
536
591
|
}
|
|
537
|
-
if (result
|
|
592
|
+
if (result.ok !== true) {
|
|
593
|
+
// 三种「没有可用卡片」的结局分开记,诊断面板才说得出是哪一种(docstring 见 generate)。
|
|
594
|
+
if (result.failure === "ungrounded") {
|
|
595
|
+
this.counters.failed += 1;
|
|
596
|
+
this.lastError = "generated card is not grounded in this conversation";
|
|
597
|
+
this.markFailure(this.lastError);
|
|
598
|
+
await this.writeErrorEvent(sid, turn, "ungrounded", result.detail);
|
|
599
|
+
return { ok: false, reason: "ungrounded" };
|
|
600
|
+
}
|
|
538
601
|
// generate() 已经把原因写进 lastError;这里只补事件。
|
|
539
602
|
await this.writeErrorEvent(sid, turn, "schema", this.lastError);
|
|
540
603
|
return { ok: false, reason: "schema" };
|
|
@@ -596,7 +659,9 @@ export class NextStepService extends TypertRemoteService {
|
|
|
596
659
|
summaryChars: card.summary.length,
|
|
597
660
|
questionChars: card.question.length,
|
|
598
661
|
hasGhost: card.nextPrompt !== undefined,
|
|
599
|
-
|
|
662
|
+
// 三种恢复路径都记下来:ok(一次成功)/ retried(空输出重采样)/
|
|
663
|
+
// repaired(带对话修格式)—— 复盘时这三种的输出分布完全不同
|
|
664
|
+
parse: parseKindOf(result.recovery),
|
|
600
665
|
...(result.usage === undefined ? {} : { usage: result.usage }),
|
|
601
666
|
},
|
|
602
667
|
}),
|
|
@@ -675,7 +740,7 @@ export class NextStepService extends TypertRemoteService {
|
|
|
675
740
|
}
|
|
676
741
|
|
|
677
742
|
/**
|
|
678
|
-
* 写一条 error
|
|
743
|
+
* 写一条 error 事件(失败/超时/取消/路由/落地校验),把「没出卡」的成因留痕。
|
|
679
744
|
* @param {string} sid
|
|
680
745
|
* @param {number} turn
|
|
681
746
|
* @param {string} kind
|
|
@@ -685,7 +750,11 @@ export class NextStepService extends TypertRemoteService {
|
|
|
685
750
|
async writeErrorEvent(sid, turn, kind, detail) {
|
|
686
751
|
/** @type {any} */
|
|
687
752
|
const mapped =
|
|
688
|
-
kind === "schema" ||
|
|
753
|
+
kind === "schema" ||
|
|
754
|
+
kind === "ungrounded" ||
|
|
755
|
+
kind === "timeout" ||
|
|
756
|
+
kind === "cancelled" ||
|
|
757
|
+
kind === "route"
|
|
689
758
|
? kind
|
|
690
759
|
: "llm";
|
|
691
760
|
await this.writeEvent(
|
|
@@ -700,16 +769,28 @@ export class NextStepService extends TypertRemoteService {
|
|
|
700
769
|
}
|
|
701
770
|
|
|
702
771
|
/**
|
|
703
|
-
* 一次额外补全:prepareCall + stream →
|
|
772
|
+
* 一次额外补全:prepareCall + stream → 宽容解析 → (必要时)重采样或带对话修复 → 落地校验。
|
|
773
|
+
*
|
|
774
|
+
* 四种结局,全部显式返回(不再用 null 一锅端):
|
|
775
|
+
* - `{ ok: true, suggestion, … }`
|
|
776
|
+
* - `{ ok: false, failure: "schema" }` 两次输出都不合格(原因已写进 lastError)
|
|
777
|
+
* - `{ ok: false, failure: "ungrounded" }` 结构合格,但卡片里没有任何对象能在这段对话里找到
|
|
778
|
+
*
|
|
779
|
+
* 两条硬规则(见 docs/adr/0023):
|
|
780
|
+
* 1. **空输出不修复,重发原请求**:拿空字符串去「修格式」,模型手里就只剩「上次输出为空」这条
|
|
781
|
+
* 信息,它的唯一出路是把它写成一张卡(「这一轮没有拿到任何对话内容…」)——历史 95 条垃圾卡
|
|
782
|
+
* 全部来自这里;
|
|
783
|
+
* 2. **修复请求必须带同一段对话**:修复是「改格式」,不是「重新想象内容」,没有原料就只能编。
|
|
704
784
|
* @param {any} session
|
|
705
785
|
* @param {any} settings
|
|
706
786
|
* @param {AbortSignal} signal
|
|
707
|
-
* @
|
|
708
|
-
*
|
|
709
|
-
* route: string, latencyMs: number, repaired: boolean, usage?: any
|
|
710
|
-
*
|
|
787
|
+
* @param {{ transcript: string, material: string }} context
|
|
788
|
+
* @returns {Promise<
|
|
789
|
+
* | { ok: true, suggestion: NonNullable<ReturnType<typeof parseSuggestion>["suggestion"]>, route: string, latencyMs: number, repaired: boolean, recovery: "none" | "retry" | "repair", usage?: any }
|
|
790
|
+
* | { ok: false, failure: "schema" | "ungrounded", detail?: string }
|
|
791
|
+
* >}
|
|
711
792
|
*/
|
|
712
|
-
async generate(session, settings, signal) {
|
|
793
|
+
async generate(session, settings, signal, context) {
|
|
713
794
|
const llm = serviceOf(this.ctx, "llm");
|
|
714
795
|
if (llm === undefined || typeof llm.prepareCall !== "function") {
|
|
715
796
|
throw new Error("host llm service is unavailable");
|
|
@@ -718,9 +799,7 @@ export class NextStepService extends TypertRemoteService {
|
|
|
718
799
|
const maxTokens = settings.maxTokens;
|
|
719
800
|
const locale = this.localeName();
|
|
720
801
|
const system = buildSystemPrompt({ locale });
|
|
721
|
-
const transcript =
|
|
722
|
-
limit: settings.contextMessages,
|
|
723
|
-
});
|
|
802
|
+
const transcript = context.transcript;
|
|
724
803
|
/** @type {any} */
|
|
725
804
|
let usage;
|
|
726
805
|
const startedAt = Date.now();
|
|
@@ -788,17 +867,31 @@ export class NextStepService extends TypertRemoteService {
|
|
|
788
867
|
};
|
|
789
868
|
|
|
790
869
|
const messages = buildMessages({ transcript, locale });
|
|
791
|
-
|
|
870
|
+
let raw = await run(messages);
|
|
792
871
|
let parsed = parseSuggestion(raw);
|
|
793
|
-
|
|
872
|
+
/** @type {"none" | "retry" | "repair"} */
|
|
873
|
+
let recovery = "none";
|
|
794
874
|
if (parsed.suggestion === null && parsed.problem !== null) {
|
|
795
|
-
|
|
796
|
-
|
|
875
|
+
const plan = recoveryPlan({ raw, problem: parsed.problem });
|
|
876
|
+
recovery = plan;
|
|
797
877
|
this.warn(
|
|
798
|
-
`model output did not match the card schema (${parsed.problem.kind}: ${parsed.problem.detail}),
|
|
878
|
+
`model output did not match the card schema (${parsed.problem.kind}: ${parsed.problem.detail}), ${plan === "retry" ? "resending the same request" : "repairing with the transcript"}`,
|
|
799
879
|
);
|
|
800
|
-
|
|
801
|
-
|
|
880
|
+
// 空输出:重发**同一个请求**。拿空字符串去「修格式」等于让模型凭空写一张卡。
|
|
881
|
+
// 有内容但格式不对:带同一段对话再要一次,只要求它修格式。
|
|
882
|
+
raw =
|
|
883
|
+
plan === "retry"
|
|
884
|
+
? await run(messages)
|
|
885
|
+
: await run(
|
|
886
|
+
buildRepairMessage({
|
|
887
|
+
transcript,
|
|
888
|
+
raw,
|
|
889
|
+
problem: parsed.problem.kind,
|
|
890
|
+
// 把「上一次 label 到底几字」带进修复请求:模型数不准自己的字数
|
|
891
|
+
detail: parsed.problem.detail,
|
|
892
|
+
}),
|
|
893
|
+
);
|
|
894
|
+
parsed = parseSuggestion(raw);
|
|
802
895
|
}
|
|
803
896
|
if (parsed.suggestion === null) {
|
|
804
897
|
const detail =
|
|
@@ -807,17 +900,26 @@ export class NextStepService extends TypertRemoteService {
|
|
|
807
900
|
this.lastError = `model output did not match the card schema (${detail})`;
|
|
808
901
|
this.markFailure(this.lastError);
|
|
809
902
|
this.warn(`model output did not match the card schema: ${detail}`);
|
|
810
|
-
return
|
|
903
|
+
return { ok: false, failure: "schema" };
|
|
811
904
|
}
|
|
812
905
|
if (parsed.detail !== "") {
|
|
813
906
|
// 宽容解析里被容忍的问题(截断/丢弃单条),留在日志里便于复盘提示词
|
|
814
907
|
this.warn(`card normalized with tolerated problems: ${parsed.detail}`);
|
|
815
908
|
}
|
|
909
|
+
// 落地校验:结构合法但讲不到这段对话(自述生成过程 / 凭空想象)的卡,一律不写进会话。
|
|
910
|
+
if (!isGroundedIn(groundableText(parsed.suggestion), context.material)) {
|
|
911
|
+
const detail = `identityTokens=${identityTokens(groundableText(parsed.suggestion)).size} matched=0 recovery=${recovery}`;
|
|
912
|
+
this.warn(`discarded a card that is not grounded in this conversation (${detail})`);
|
|
913
|
+
this.lastError = "generated card is not grounded in this conversation";
|
|
914
|
+
return { ok: false, failure: "ungrounded", detail };
|
|
915
|
+
}
|
|
816
916
|
return {
|
|
917
|
+
ok: true,
|
|
817
918
|
suggestion: parsed.suggestion,
|
|
818
919
|
route: `${route.provider}/${route.model}`,
|
|
819
920
|
latencyMs: Date.now() - startedAt,
|
|
820
|
-
repaired,
|
|
921
|
+
repaired: recovery === "repair",
|
|
922
|
+
recovery,
|
|
821
923
|
...(usage === undefined ? {} : { usage }),
|
|
822
924
|
};
|
|
823
925
|
}
|
package/locale/en.json
CHANGED
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
"error.exists": "This turn already has a card",
|
|
40
40
|
"error.inflight": "Already generating; try again in a moment",
|
|
41
41
|
"error.noTurn": "No completed turn to generate a card for",
|
|
42
|
+
"error.ungrounded": "The generated card did not refer to this conversation; discarded",
|
|
43
|
+
"error.noContext": "No conversation content to generate a card from",
|
|
42
44
|
"retry.generate": "Generate a next-step card",
|
|
43
45
|
"retry.generating": "Generating…",
|
|
44
46
|
"settings.nav": "Next-step suggestions",
|
package/locale/zh.json
CHANGED
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
"error.exists": "这一轮已经有卡片了",
|
|
40
40
|
"error.inflight": "正在生成,请稍候",
|
|
41
41
|
"error.noTurn": "没有可生成建议的回合",
|
|
42
|
+
"error.ungrounded": "生成的卡片与这段对话无关,已丢弃",
|
|
43
|
+
"error.noContext": "没有可用的对话内容,未生成卡片",
|
|
42
44
|
"retry.generate": "生成下一步建议",
|
|
43
45
|
"retry.generating": "正在生成…",
|
|
44
46
|
"settings.nav": "下一步建议",
|
package/package.json
CHANGED