@kangyishuai/dsh-advisor 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > A separately configured advisor model the main model can consult when _it_ decides to — before committing to an approach, when an error keeps recurring, before declaring a task done. Advisory only: it reads the conversation, returns structured advice, and never approves, blocks or runs anything.
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-advisor?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-advisor) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.2-4b6bfb)](#compatibility) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
5
+ [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-advisor?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-advisor) [![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
 
@@ -68,40 +68,40 @@ The “?” next to an advanced field expands an inline help block (click or act
68
68
 
69
69
  Money fields accept decimals: budgets up to 2, unit prices up to 4.
70
70
 
71
- | Key | UI label | Default | Range / values | Meaning |
72
- | ------------------------- | ------------------------------ | ----------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
73
- | `mode` | Mode | `"off"` | off / shadow / advisory | Whether the plugin may consult at all. Off by default; opt in explicitly. |
74
- | `provider` | Provider | `""` | route name from Settings → Models, ≤300 chars | Advisor route. Empty means never call. |
75
- | `model` | Model | `""` | model id under that route, ≤300 chars | Advisor model. Empty means never call. |
76
- | `reasoningEffort` | Reasoning effort | `""` | a supported effort id, `""` = model default | An unsupported value is retried once without an effort. |
77
- | `maxTokens` | Output limit | `4096` | 256–32000 | Maximum output tokens per consultation. |
78
- | `temperature` | Randomness | `null` | 0–2, `null` = not sent | Empty lets the model decide. |
79
- | `maxCallsPerTurn` | Calls per turn | `1` | 0–8, 0 = unlimited | Maximum consultations per turn. |
80
- | `maxCallsPerSession` | Calls per session | `32` | 0–1000, 0 = unlimited | Maximum consultations per session. |
81
- | `maxCallsPerHour` | Calls per hour | `12` | 0–500, 0 = unlimited | Sliding one-hour window. |
82
- | `currency` | Currency | `"USD"` | USD / CNY | Amounts and prices are entered in this currency; the ledger/pool stay in USD internally. |
83
- | `usdToCny` | CNY per USD | `7.2` | 0.1–100 | 1 USD = ? CNY; used only for CNY conversion; manual, never fetched. |
84
- | `maxCostPerDay` | Daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Daily spend ceiling in the selected currency; only counted when prices are set. |
85
- | `priceInputPerMTok` | Input price | `0` | 0–1000; up to 4 decimals | Advisor input price in the selected currency per 1M tokens; 0 = do not price. |
86
- | `priceOutputPerMTok` | Output price | `0` | 0–1000; up to 4 decimals | Output price in the selected currency per 1M tokens. |
87
- | `priceCacheReadPerMTok` | Cache-read price | `0` | 0–1000; up to 4 decimals | Input-token price for cache reads/hits in the selected currency; 0 = do not price cache tokens. |
88
- | `priceCacheWritePerMTok` | Cache-write price | `0` | 0–1000; up to 4 decimals | Input-token price for cache writes/creations in the selected currency; 0 = do not price cache tokens. |
89
- | `privacyScope` | Send scope | `"summary"` | off / summary / full | How much conversation content is sent — see Cost & privacy. |
90
- | `redact` | Redact before sending | `true` | boolean | Best-effort masking of common key formats; not a guarantee. |
91
- | `immuneTurns` | JSON only: Immune turns | `3` | 0–20 | Turns to stay quiet after a delivery; used by shadow delivery. |
92
- | `dedupe` | Dedupe in shadow mode | `true` | boolean | In shadow mode, the same advice is recorded once; the tool path does not block on it. |
93
- | `sessionCap` | Advice items per session | `24` | 0–200 | Max advice items shown per session; once reached only blockers get through. |
94
- | `tiers` | JSON only: Tiers | `{}` | `"provider/model"` → number | Capability ranks for the pairing check; without an entry the pairing is unverified. |
95
- | `allowedModels` | Model allowlist | `[]` | string array | Empty = no limit; accepts provider/model or a bare model id. |
96
- | `confirmedHosts` | JSON/button: Confirmed hosts | `[]` | string array | Cross-provider confirmation list; the settings-card button writes it. |
97
- | `pairingEnforcement` | JSON only: Pairing enforcement | `"warn"` | warn / block | When the advisor tier is lower: warn allows and warns; block refuses. |
98
- | `workspaceMaxCallsPerDay` | Workspace calls per day | `200` | 0–100000, 0 = unlimited | Workspace-wide, shared across sessions, resets on the local day. |
99
- | `workspaceMaxCostPerDay` | Workspace daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Workspace-wide daily ceiling in the selected currency. |
100
- | `postAnswer` | Auto-review after each turn | `"off"` | off / card | In advisory mode, runs once after each answer; records only, never inserts. |
101
- | `advisorTools` | Let the advisor read files | `false` | boolean | Lets it read working-directory files (up to 5, read-only); costs one extra call. |
102
- | `tracePrompt` | Keep sent content | `"preview"` | `preview` / `off` | Stores the first/last 2,000 chars of the text actually sent (after redaction) in the session record; `off` stores metadata only. |
103
- | `timeoutMs` | JSON only: Timeout | `90000` | 5000–600000 | Per-consultation timeout; `/advisor cancel` aborts sooner. |
104
- | `maxInputChars` | Input limit | `60000` | 4000–400000 | Total transcript budget; excess in the middle is elided, head/tail kept. |
71
+ | Key | UI label | Default | Range / values | Meaning |
72
+ | ------------------------- | ------------------------------ | ----------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
73
+ | `mode` | Mode | `"off"` | off / shadow / advisory | Whether the plugin may consult at all. Off by default; opt in explicitly. |
74
+ | `provider` | Provider | `""` | route name from Settings → Models, ≤300 chars | Advisor route. Empty means never call. |
75
+ | `model` | Model | `""` | model id under that route, ≤300 chars | Advisor model. Empty means never call. |
76
+ | `reasoningEffort` | Reasoning effort | `""` | a supported effort id, `""` = model default | An unsupported value is retried once without an effort. |
77
+ | `maxTokens` | Output limit | `4096` | 256–32000 | Maximum output tokens per consultation. |
78
+ | `temperature` | Randomness | `null` | 0–2, `null` = not sent | Empty lets the model decide. |
79
+ | `maxCallsPerTurn` | Calls per turn | `1` | 0–8, 0 = unlimited | Maximum consultations per turn. |
80
+ | `maxCallsPerSession` | Calls per session | `32` | 0–1000, 0 = unlimited | Maximum consultations per session. |
81
+ | `maxCallsPerHour` | Calls per hour | `12` | 0–500, 0 = unlimited | Sliding one-hour window. |
82
+ | `currency` | Currency | `"USD"` | USD / CNY | Amounts and prices are entered in this currency; the ledger/pool stay in USD internally. |
83
+ | `usdToCny` | CNY per USD | `7.2` | 0.1–100 | 1 USD = ? CNY; used only for CNY conversion; manual, never fetched. |
84
+ | `maxCostPerDay` | Daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Daily spend ceiling in the selected currency; only counted when prices are set. |
85
+ | `priceInputPerMTok` | Input price | `0` | 0–1000; up to 4 decimals | Advisor input price in the selected currency per 1M tokens; 0 = do not price. |
86
+ | `priceOutputPerMTok` | Output price | `0` | 0–1000; up to 4 decimals | Output price in the selected currency per 1M tokens. |
87
+ | `priceCacheReadPerMTok` | Cache-read price | `0` | 0–1000; up to 4 decimals | Input-token price for cache reads/hits in the selected currency; 0 = do not price cache tokens. |
88
+ | `priceCacheWritePerMTok` | Cache-write price | `0` | 0–1000; up to 4 decimals | Input-token price for cache writes/creations in the selected currency; 0 = do not price cache tokens. |
89
+ | `privacyScope` | Send scope | `"summary"` | off / summary / full | How much conversation content is sent — see Cost & privacy. |
90
+ | `redact` | Redact before sending | `true` | boolean | Best-effort masking of common key formats; not a guarantee. |
91
+ | `immuneTurns` | JSON only: Immune turns | `3` | 0–20 | Turns to stay quiet after a delivery; used by shadow delivery. |
92
+ | `dedupe` | Dedupe in shadow mode | `true` | boolean | In shadow mode, the same advice is recorded once; the tool path does not block on it. |
93
+ | `sessionCap` | Advice items per session | `24` | 0–200 | Max advice items shown per session; once reached only blockers get through. |
94
+ | `tiers` | JSON only: Tiers | `{}` | `"provider/model"` → number | Capability ranks for the pairing check; without an entry the pairing is unverified. |
95
+ | `allowedModels` | Model allowlist | `[]` | string array | Empty = no limit; accepts provider/model or a bare model id. |
96
+ | `confirmedHosts` | JSON/button: Confirmed hosts | `[]` | string array | Cross-provider confirmation list; the settings-card button writes it. |
97
+ | `pairingEnforcement` | JSON only: Pairing enforcement | `"warn"` | warn / block | When the advisor tier is lower: warn allows and warns; block refuses. |
98
+ | `workspaceMaxCallsPerDay` | Workspace calls per day | `200` | 0–100000, 0 = unlimited | Workspace-wide, shared across sessions, resets on the local day. |
99
+ | `workspaceMaxCostPerDay` | Workspace daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Workspace-wide daily ceiling in the selected currency. |
100
+ | `postAnswer` | Auto-review after each turn | `"off"` | off / card | In advisory mode, runs once after each answer; records only, never inserts. |
101
+ | `advisorTools` | Let the advisor read files | `false` | boolean | Lets it read working-directory files (up to 5, read-only); costs one extra call. |
102
+ | `tracePrompt` | Keep sent content | `"preview"` | `preview` / `off` | Stores the first/last 2,000 chars of the text actually sent (after redaction) in the session record; `off` stores metadata only. |
103
+ | `timeoutMs` | JSON only: Timeout | `90000` | 5000–600000 | Per-consultation timeout; `/advisor cancel` aborts sooner. A hit reports `code: "timeout"` (distinct from `aborted`). Slow routes do reach it: over 28 real consultations here the latencies were p50 6.2s / p90 52.5s, and two hit the 90s ceiling — measure your route and raise this if it is slow. |
104
+ | `maxInputChars` | Input limit | `60000` | 4000–400000 | Total transcript budget; excess in the middle is elided, head/tail kept. |
105
105
 
106
106
  **Cache prices.** The host usage exposes `cacheReadTokens` / `cacheWriteTokens`, both input-side; there is no cache-output token. Cache tokens are additional input tokens and are not subtracted from `inputTokens`. `priceCacheReadPerMTok` / `priceCacheWritePerMTok` = 0 means cache tokens are not priced; if the ledger has cache tokens while both are 0, the status area warns that cache tokens are unpriced. Built-in reference prices have no cache prices and the plugin does not guess.
107
107
 
@@ -167,10 +167,11 @@ This is the section to read before turning it on.
167
167
 
168
168
  ## Compatibility
169
169
 
170
- | DSH version | Status |
171
- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
172
- | 0.2.2-rc.2 | Verified 2026-11-12: unit tests + `pnpm probe:runtime` 67/67 + web `pnpm smoke:advisor` 13/13 on a throwaway DSH home (no model calls, ledger 0). Desktop read-only regression (live app over CDP): 18 passing + 1 skipped (the session had no advisor records). |
173
- | 0.2.2-rc.1 | Verified on this version: unit tests (settings clamping, route selection and pairing, budget guard, transcript rendering, redaction, output contract) and `pnpm probe:runtime`; the desktop read-only regression is `pnpm smoke:advisor-desktop`. Other DSH versions are not verified. |
170
+ | DSH version | Status |
171
+ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
172
+ | 0.2.2-rc.3 | **0.6.1** (2026-11-14): no code change needed for this DSH build. Verified: 138 unit tests + `pnpm probe:runtime` 72/72 + web `pnpm smoke:advisor` **14/14** (throwaway DSH home, no model calls) + desktop read-only regression **19 PASS + 1 SKIP** (the SKIP is a session with no advisor record). Only tooling changed: the probe now scans hashed frontend assets instead of pinning one filename, and the theme-token snapshot was re-stamped to rc.3 (456 tokens, none added or removed). |
173
+ | 0.2.2-rc.2 | **0.6.0 → 0.6.1** (2026-11-14): adds the decision log `decisions.jsonl` plus `pnpm advisor:review`; settings moved to their own "Settings → Advisor" section (three-row summary + collapsed "More settings"). Verified: unit tests (20 of them cover the decision log) + `pnpm probe:runtime` 72/72 + web `pnpm smoke:advisor` **14/14** (throwaway DSH home, no model calls). The settings section was additionally checked on a live desktop build via read-only CDP (DOM + screenshot); the desktop read-only regression reports **19 PASS + 1 SKIP** (the SKIP is a session with no advisor record — the script never fabricates a consultation). 0.6.1 only fixes the decision-log reason codes (`aborted`/`blocked` no longer fall through to `skipped-other`); 18 unit tests cover it and the desktop regression was not re-run. |
174
+ | 0.2.2-rc.1 | Verified on this version: unit tests (settings clamping, route selection and pairing, budget guard, transcript rendering, redaction, output contract) and `pnpm probe:runtime`; the desktop read-only regression is `pnpm smoke:advisor-desktop`. Other DSH versions are not verified. |
174
175
 
175
176
  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 this table as the compatibility statement. After a DSH upgrade run `pnpm probe:runtime`, `pnpm smoke:advisor-desktop` and the unit tests, then check `/advisor doctor`.
176
177
 
package/README.zh-CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > 给主模型配一个单独配置的顾问模型,由**主模型自己决定**什么时候值得问:动手之前、反复失败时、宣告完成之前。顾问只给建议:它读整段对话、返回结构化答复,不批准、不拦截、不执行任何动作。
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-advisor?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-advisor) [![DSH](https://img.shields.io/badge/verified%20on%20DSH-0.2.2--rc.2-4b6bfb)](#兼容性) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
5
+ [![npm](https://img.shields.io/npm/v/@kangyishuai/dsh-advisor?color=cb3837&logo=npm)](https://www.npmjs.com/package/@kangyishuai/dsh-advisor) [![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
 
@@ -68,40 +68,40 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
68
68
 
69
69
  金额字段支持小数:预算最多 2 位,单价最多 4 位。
70
70
 
71
- | 键 | 设置页名称 | 默认 | 范围 / 取值 | 说明 |
72
- | ------------------------- | ----------------------------- | ----------- | ------------------------------------ | ----------------------------------------------------------------------------- |
73
- | `mode` | 模式 | `"off"` | off / shadow / advisory | 是否允许徵询。默认关闭,显式开启才生效。 |
74
- | `provider` | 服务商 | `""` | 设置 → 模型里的路由名,≤300 字符 | 顾问路由。留空 = 永不调用。 |
75
- | `model` | 模型 | `""` | 该路由下的模型 id,≤300 字符 | 顾问模型。留空 = 永不调用。 |
76
- | `reasoningEffort` | 思考档 | `""` | 模型支持的思考档 id,`""` = 模型默认 | 填了不支持的值会去掉思考档重试一次。 |
77
- | `maxTokens` | 输出上限 | `4096` | 256–32000 | 单次徵询最多生成多少 token。 |
78
- | `temperature` | 随机性 | `null` | 0–2,`null` = 不传 | 留空由模型决定。 |
79
- | `maxCallsPerTurn` | 每回合调用上限 | `1` | 0–8,0 = 不限 | 每回合最多徵询几次。 |
80
- | `maxCallsPerSession` | 每会话调用上限 | `32` | 0–1000,0 = 不限 | 每个会话最多徵询几次。 |
81
- | `maxCallsPerHour` | 每小时调用上限 | `12` | 0–500,0 = 不限 | 滚动一小时内。 |
82
- | `currency` | 币种 | `"USD"` | USD / CNY | 金额和单价按此币种填写;账本/预算池内部仍记 USD。 |
83
- | `usdToCny` | 人民币汇率 | `7.2` | 0.1–100 | 1 USD = ? CNY;只在人民币时用于换算;手动维护,不联网。 |
84
- | `maxCostPerDay` | 每日预算(按币种) | `0` | 0–10000,0 = 不限;最多 2 位小数 | 每天最多花多少(按 `currency`);只有填了单价才计算金额。 |
85
- | `priceInputPerMTok` | 输入单价 | `0` | 0–1000;最多 4 位小数 | 顾问模型输入价,按 `currency` / 百万 token;0 = 不算钱。 |
86
- | `priceOutputPerMTok` | 输出单价 | `0` | 0–1000;最多 4 位小数 | 输出价,按 `currency` / 百万 token。 |
87
- | `priceCacheReadPerMTok` | 缓存读取单价 | `0` | 0–1000;最多 4 位小数 | 缓存读取/命中的输入 token 单价,按 `currency`;0 = 不计缓存部分。 |
88
- | `priceCacheWritePerMTok` | 缓存写入单价 | `0` | 0–1000;最多 4 位小数 | 缓存写入/创建的输入 token 单价,按 `currency`;0 = 不计缓存部分。 |
89
- | `privacyScope` | 发送范围 | `"summary"` | off / summary / full | 发多少会话内容,见「成本与隐私」。 |
90
- | `redact` | 发送前脱敏 | `true` | 布尔 | 尽量遮掉常见密钥格式;不能保证全部遮住。 |
91
- | `immuneTurns` | 仅 JSON:免疫回合 | `3` | 0–20 | 投递后保持安静的回合数;只用于 shadow 投递。 |
92
- | `dedupe` | 影子模式去重 | `true` | 布尔 | 影子模式下相同建议只记一次;工具路径不据此拦截。 |
93
- | `sessionCap` | 建议条数上限 | `24` | 0–200 | 单会话最多展示几条建议;到顶后只有 blocker 继续。 |
94
- | `tiers` | 仅 JSON:能力档位 | `{}` | `"provider/model"` → 数字 | 配对校验用的档位;没有条目时结论是「未校验」。 |
95
- | `allowedModels` | 模型白名单 | `[]` | 字符串数组 | 留空 = 不限制;可写 provider/model 或裸 model id。 |
96
- | `confirmedHosts` | 仅 JSON/按钮:已确认 provider | `[]` | 字符串数组 | 跨 provider 发送的确认名单;设置卡里的按钮会写入。 |
97
- | `pairingEnforcement` | 仅 JSON:配对校验 | `"warn"` | warn / block | 顾问档位低于主模型时:warn 放行并告警,block 拒绝。 |
98
- | `workspaceMaxCallsPerDay` | 工作区每日调用上限 | `200` | 0–100000,0 = 不限 | 工作区级,跨会话累计,按本地日重置。 |
99
- | `workspaceMaxCostPerDay` | 工作区每日预算(按币种) | `0` | 0–10000,0 = 不限;最多 2 位小数 | 工作区级每日金额上限(按 `currency`)。 |
100
- | `postAnswer` | 回合结束后自动复查 | `"off"` | off / card | advisory 模式下每轮回答后自动复查一次;只记录,不插回对话。 |
101
- | `advisorTools` | 允许顾问读文件核实 | `false` | 布尔 | 允许顾问读工作目录内的文件(≤5 个、只读);多一次调用。 |
102
- | `tracePrompt` | 记录发送内容 | `"preview"` | `preview` / `off` | 在会话记录里保留实际发送文本的首尾各 2,000 字符(脱敏后);`off` 只记元数据。 |
103
- | `timeoutMs` | 仅 JSON:超时 | `90000` | 5000–600000 | 单次徵询超时;`/advisor cancel` 可以更早中止。 |
104
- | `maxInputChars` | 输入上限 | `60000` | 4000–400000 | 会话文本总预算;超出保留首尾、省略中间。 |
71
+ | 键 | 设置页名称 | 默认 | 范围 / 取值 | 说明 |
72
+ | ------------------------- | ----------------------------- | ----------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
73
+ | `mode` | 模式 | `"off"` | off / shadow / advisory | 是否允许徵询。默认关闭,显式开启才生效。 |
74
+ | `provider` | 服务商 | `""` | 设置 → 模型里的路由名,≤300 字符 | 顾问路由。留空 = 永不调用。 |
75
+ | `model` | 模型 | `""` | 该路由下的模型 id,≤300 字符 | 顾问模型。留空 = 永不调用。 |
76
+ | `reasoningEffort` | 思考档 | `""` | 模型支持的思考档 id,`""` = 模型默认 | 填了不支持的值会去掉思考档重试一次。 |
77
+ | `maxTokens` | 输出上限 | `4096` | 256–32000 | 单次徵询最多生成多少 token。 |
78
+ | `temperature` | 随机性 | `null` | 0–2,`null` = 不传 | 留空由模型决定。 |
79
+ | `maxCallsPerTurn` | 每回合调用上限 | `1` | 0–8,0 = 不限 | 每回合最多徵询几次。 |
80
+ | `maxCallsPerSession` | 每会话调用上限 | `32` | 0–1000,0 = 不限 | 每个会话最多徵询几次。 |
81
+ | `maxCallsPerHour` | 每小时调用上限 | `12` | 0–500,0 = 不限 | 滚动一小时内。 |
82
+ | `currency` | 币种 | `"USD"` | USD / CNY | 金额和单价按此币种填写;账本/预算池内部仍记 USD。 |
83
+ | `usdToCny` | 人民币汇率 | `7.2` | 0.1–100 | 1 USD = ? CNY;只在人民币时用于换算;手动维护,不联网。 |
84
+ | `maxCostPerDay` | 每日预算(按币种) | `0` | 0–10000,0 = 不限;最多 2 位小数 | 每天最多花多少(按 `currency`);只有填了单价才计算金额。 |
85
+ | `priceInputPerMTok` | 输入单价 | `0` | 0–1000;最多 4 位小数 | 顾问模型输入价,按 `currency` / 百万 token;0 = 不算钱。 |
86
+ | `priceOutputPerMTok` | 输出单价 | `0` | 0–1000;最多 4 位小数 | 输出价,按 `currency` / 百万 token。 |
87
+ | `priceCacheReadPerMTok` | 缓存读取单价 | `0` | 0–1000;最多 4 位小数 | 缓存读取/命中的输入 token 单价,按 `currency`;0 = 不计缓存部分。 |
88
+ | `priceCacheWritePerMTok` | 缓存写入单价 | `0` | 0–1000;最多 4 位小数 | 缓存写入/创建的输入 token 单价,按 `currency`;0 = 不计缓存部分。 |
89
+ | `privacyScope` | 发送范围 | `"summary"` | off / summary / full | 发多少会话内容,见「成本与隐私」。 |
90
+ | `redact` | 发送前脱敏 | `true` | 布尔 | 尽量遮掉常见密钥格式;不能保证全部遮住。 |
91
+ | `immuneTurns` | 仅 JSON:免疫回合 | `3` | 0–20 | 投递后保持安静的回合数;只用于 shadow 投递。 |
92
+ | `dedupe` | 影子模式去重 | `true` | 布尔 | 影子模式下相同建议只记一次;工具路径不据此拦截。 |
93
+ | `sessionCap` | 建议条数上限 | `24` | 0–200 | 单会话最多展示几条建议;到顶后只有 blocker 继续。 |
94
+ | `tiers` | 仅 JSON:能力档位 | `{}` | `"provider/model"` → 数字 | 配对校验用的档位;没有条目时结论是「未校验」。 |
95
+ | `allowedModels` | 模型白名单 | `[]` | 字符串数组 | 留空 = 不限制;可写 provider/model 或裸 model id。 |
96
+ | `confirmedHosts` | 仅 JSON/按钮:已确认 provider | `[]` | 字符串数组 | 跨 provider 发送的确认名单;设置卡里的按钮会写入。 |
97
+ | `pairingEnforcement` | 仅 JSON:配对校验 | `"warn"` | warn / block | 顾问档位低于主模型时:warn 放行并告警,block 拒绝。 |
98
+ | `workspaceMaxCallsPerDay` | 工作区每日调用上限 | `200` | 0–100000,0 = 不限 | 工作区级,跨会话累计,按本地日重置。 |
99
+ | `workspaceMaxCostPerDay` | 工作区每日预算(按币种) | `0` | 0–10000,0 = 不限;最多 2 位小数 | 工作区级每日金额上限(按 `currency`)。 |
100
+ | `postAnswer` | 回合结束后自动复查 | `"off"` | off / card | advisory 模式下每轮回答后自动复查一次;只记录,不插回对话。 |
101
+ | `advisorTools` | 允许顾问读文件核实 | `false` | 布尔 | 允许顾问读工作目录内的文件(≤5 个、只读);多一次调用。 |
102
+ | `tracePrompt` | 记录发送内容 | `"preview"` | `preview` / `off` | 在会话记录里保留实际发送文本的首尾各 2,000 字符(脱敏后);`off` 只记元数据。 |
103
+ | `timeoutMs` | 仅 JSON:超时 | `90000` | 5000–600000 | 单次徵询超时;`/advisor cancel` 可以更早中止。撞上超时会返回 `code: "timeout"`(与 `aborted` 分开)。慢路由真的会撞到:本机 28 次真实徵询实测 p50 6.2s / p90 52.5s,其中两次打满 90 秒——先量你那条路由,慢就调大。 |
104
+ | `maxInputChars` | 输入上限 | `60000` | 4000–400000 | 会话文本总预算;超出保留首尾、省略中间。 |
105
105
 
106
106
  **缓存单价。** 宿主 usage 里只有 `cacheReadTokens` / `cacheWriteTokens`(都是输入侧),没有缓存输出 token;缓存 token 是额外的输入 token,不从 `inputTokens` 扣。`priceCacheReadPerMTok` / `priceCacheWritePerMTok` 为 0 时不计缓存部分;如果账本里有缓存 token 而缓存单价为 0,状态区会提示「缓存 token 未计价」。内置参考价没有缓存价,不做猜测。
107
107
 
@@ -157,10 +157,11 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
157
157
 
158
158
  ## 兼容性
159
159
 
160
- | 已验证的 DSH 版本 | 状态 |
161
- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
162
- | 0.2.2-rc.2 | 2026-11-12 已验证:单测 + `pnpm probe:runtime` 67/67 + Web `pnpm smoke:advisor` 13/13(临时 DSH home,不发起模型调用,账本 0)。桌面只读回归(live 桌面版,CDP):19 PASS + 1 SKIP(SKIP 是该会话没有顾问记录;冷启动实测)。 |
163
- | 0.2.2-rc.1 | 已在该版本验证:单测(81 条)与 `pnpm probe:runtime`;web 端到端冒烟 `pnpm smoke:advisor`、桌面端只读回归 `pnpm smoke:advisor-desktop`。其他 DSH 版本未验证。 |
160
+ | 已验证的 DSH 版本 | 状态 |
161
+ | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
162
+ | 0.2.2-rc.3 | **0.6.1**(2026-11-14):这一版 DSH 不需要改代码。已验证:138 项单测 + `pnpm probe:runtime` 72/72 + web `pnpm smoke:advisor` **14/14**(临时 DSH home,不发起模型调用)+ 桌面只读回归 **19 PASS + 1 SKIP**(SKIP 是本会话没有顾问记录)。只改了工具:探针改为扫描带哈希的前端产物、主题 token 快照重新标记为 rc.3(456 个,无增无减)。 |
163
+ | 0.2.2-rc.2 | **0.6.0 → 0.6.1**(2026-11-14):新增决策日志 `decisions.jsonl` + `pnpm advisor:review` 复盘;设置搬到「设置 → 顾问」分节(首屏三行摘要 + 更多设置折叠)。已验证:单测(含 `decisions` 20 项、linter 全绿)+ `pnpm probe:runtime` 72/72 + web `pnpm smoke:advisor` **14/14**(临时 DSH home,不发起模型调用)。设置分节另有真机只读 CDP 核验(DOM + 截图:三行摘要、更多设置默认收起);桌面只读回归 **19 PASS + 1 SKIP**(SKIP 是该会话没有顾问记录,脚本不制造徵询)。0.6.1 只修决策日志的原因码归类(`aborted`/`blocked` 不再落到 `skipped-other`),单测 18 项覆盖,未复跑桌面回归。 |
164
+ | 0.2.2-rc.1 | 已在该版本验证:单测(81 条)与 `pnpm probe:runtime`;web 端到端冒烟 `pnpm smoke:advisor`、桌面端只读回归 `pnpm smoke:advisor-desktop`。其他 DSH 版本未验证。 |
164
165
 
165
166
  插件不声明 `engines.dsh`,也不声明 `@deepseek-ai/*` 的 peer 范围:DSH 还在预发布阶段,semver 对预发布版本不可靠(见 [ADR 0005](../../docs/adr/0005-dsh-version-compatibility.md))。这张表就是兼容性声明。DSH 升级后请跑 `pnpm probe:runtime`、`pnpm smoke:advisor-desktop` 和单测,再看 `/advisor doctor`。
166
167
 
@@ -180,7 +181,7 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
180
181
  - **配对档位需要你自己声明。** DSH 没有跨厂商的能力目录,所以「顾问是不是至少和主模型一样强」只能来自你填的 `tiers`。没有条目时结论是**未校验**,徵询照常进行;它不会假装校验通过。把 `pairingEnforcement` 设成 `"block"` 时,档位更低的顾问会被拒绝。
181
182
  - **被中止的调用 token 可能记少。** 徵询被取消或超时时,可能收不到 usage chunk;账本会把这次记成 0 token,金额预算可能落后于真实花费。把账本当可靠估算,别当账单。
182
183
  - **顾问路由可能因为插件之外的原因坏掉**(baseURL 写错、缺密钥、限流)。所有失败都会变成结构化的工具结果(`MISSING_CREDENTIAL`、`rate_limited`、`overloaded`、`prompt_too_long`、`timeout`、`aborted`…),不会把回合弄断。
183
- - **设置卡在「设置 → 通用」的底部。** 可能需要往下滚;标了「仅 JSON」的键仍要改设置文件,或继续用 `/advisor` 选择器。
184
+ - **设置页在「设置 → 顾问」这个独立分节里**(首屏三行摘要 + 「更多设置」折叠);标了「仅 JSON」的键仍要改设置文件,或继续用 `/advisor` 选择器。
184
185
  - **部分生效的旋钮。** `sessionCap` 会限制单会话投递条数(blocker 豁免);`dedupe` / `immuneTurns` 只在 shadow 路径上有意义——见[配置](#配置)。
185
186
  - **只试一次,没有重试循环。** 顾问输出解析失败会报 unavailable,不重试;不支持的思考档只会去掉思考档重试一次。
186
187
  - **`shadow` 模式照样花钱。** 它省掉的是回灌,不是调用。而且 `shadow` 期间,模型主动调用 `advisor` 工具仍会拿到建议:这个模式抑制的是回合结束后的自动复查,不是模型发起的徵询。要彻底停调用请用 `off`。
@@ -0,0 +1,29 @@
1
+ // @ts-check
2
+ // 「顾问调用被中止」的细分:**超时**与**用户/回合取消**是两件事。
3
+ //
4
+ // 为什么单独一个模块:`call.js` 会 import `@deepseek-ai/dsh-llm`(`BlockAssembler`),
5
+ // 而测试环境里没有宿主包,单独 import 它就跑不起来。把判据抽成不依赖宿主的纯函数,
6
+ // 才能在 `node --test` 里覆盖——这条分类直接影响用户看到的错误码(README 里
7
+ // `timeout` 与 `aborted` 是两个不同的失败码,别再把超时混进 `aborted`)。
8
+
9
+ /** 超时文案里用的时长:整分钟写「N 分钟」,其余写「N 秒」。 @param {number} ms */
10
+ export function formatTimeout(ms) {
11
+ if (!Number.isFinite(ms) || ms <= 0) return "未知时长";
12
+ // 不足 1 秒按 1 秒算:否则 120ms 的超时会说出「0 秒」这种废话。
13
+ const seconds = Math.max(1, Math.round(ms / 1000));
14
+ if (seconds >= 60 && seconds % 60 === 0) return `${seconds / 60} 分钟`;
15
+ return `${seconds} 秒`;
16
+ }
17
+
18
+ /**
19
+ * @param {{ cancelled?: boolean, timedOut?: boolean, timeoutMs?: number }} [input]
20
+ * @returns {{ code: "aborted" | "timeout", message: string }}
21
+ */
22
+ export function classifyAbort(input = {}) {
23
+ const { cancelled = false, timedOut = false, timeoutMs = 0 } = input;
24
+ // 用户主动取消优先:`/advisor cancel` 触发的 abort 不该被说成「超时」。
25
+ if (cancelled) return { code: "aborted", message: "顾问调用被中止" };
26
+ if (timedOut) return { code: "timeout", message: `顾问调用超时(${formatTimeout(timeoutMs)})` };
27
+ // 既没超时也没被取消:保留原来的兜底说法(例如宿主自己中止了流)。
28
+ return { code: "aborted", message: "顾问调用被中止" };
29
+ }
package/lib/call.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // 一次顾问调用:prepareCall → stream → 聚合文本 / usage / 错误分类。
3
3
  // 这是整个插件唯一会花钱的地方,所有失败都必须变成**结构化结果**,绝不向上抛。
4
4
  import { BlockAssembler } from "@deepseek-ai/dsh-llm";
5
+ import { classifyAbort } from "./abort-reason.js";
5
6
  import { advisorSystemPrompt, buildAdvisorInput, mintNonce } from "./prompt.js";
6
7
 
7
8
  /** 额外调用统一打这个 purpose:也是递归防护的判据(监听器按它跳过自己)。 */
@@ -93,6 +94,12 @@ export async function callAdvisor(input) {
93
94
 
94
95
  // 超时与用户中断合并:任一触发都中止(绝不留下孤儿请求继续烧 token)。
95
96
  const timeoutSignal = AbortSignal.timeout(settings.timeoutMs);
97
+ // 超时与用户取消都会让流以 aborted 收尾,事后无法从 finish 分辨;
98
+ // 这里先记住「信号里的一员确实因超时触发」,收尾时用它区分 code。
99
+ let timedOut = false;
100
+ timeoutSignal.addEventListener("abort", () => {
101
+ timedOut = true;
102
+ });
96
103
  const signals = [input.signal, timeoutSignal].filter(Boolean);
97
104
  const signal =
98
105
  signals.length > 1 && typeof AbortSignal.any === "function"
@@ -162,10 +169,16 @@ export async function callAdvisor(input) {
162
169
  };
163
170
  }
164
171
  if (settled?.kind === "aborted" || finish?.kind === "aborted") {
172
+ const verdict = classifyAbort({
173
+ // 外部 signal 先于超时触发 → 用户/回合取消;超时 signal 触发 → 超时。
174
+ cancelled: timedOut !== true && (input.signal?.aborted ?? false),
175
+ timedOut,
176
+ timeoutMs: settings.timeoutMs,
177
+ });
165
178
  return {
166
179
  ok: false,
167
- code: "aborted",
168
- message: "顾问调用被中止",
180
+ code: verdict.code,
181
+ message: verdict.message,
169
182
  ms: Date.now() - startedAt,
170
183
  model,
171
184
  effort: useEffort,
package/lib/decisions.js CHANGED
@@ -36,6 +36,10 @@ const SKIP_PATTERNS = [
36
36
  [/投递上限|会话上限|session.?cap/iu, "skipped-limit"],
37
37
  [/预算|额度|budget|quota/iu, "skipped-budget"],
38
38
  [/确认|confirm/iu, "skipped-needs-confirmation"],
39
+ // finishTurn 在非正常结束时会写「回合被中断 / 被阻塞」,
40
+ // 不加这两条就会归到 skipped-other(真实日志里踩到过)。
41
+ [/中断|abort/iu, "skipped-aborted"],
42
+ [/阻塞|blocked/iu, "skipped-blocked"],
39
43
  ];
40
44
 
41
45
  /**
@@ -83,14 +87,18 @@ export function turnFeatures(input) {
83
87
  export function buildDecision(input) {
84
88
  const advice = input.advice;
85
89
  const consulted = advice !== undefined && advice !== null;
90
+ const endKind = input.endKind ?? "completed";
91
+ // 结束原因本身就是最可靠的原因码来源;不要把它降级成「从人话里猜」。
92
+ const endKindCode =
93
+ endKind === "aborted" ? "skipped-aborted" : endKind === "blocked" ? "skipped-blocked" : null;
86
94
  return {
87
95
  at: input.at ?? new Date().toISOString(),
88
96
  sessionId: input.sessionId,
89
97
  turn: input.turn,
90
- endKind: input.endKind ?? "completed",
98
+ endKind,
91
99
  consulted,
92
100
  // 没徵询时给出原因码,复盘时先看这一列。
93
- skipCode: consulted ? null : classifySkip(input.skipReason),
101
+ skipCode: consulted ? null : (endKindCode ?? classifySkip(input.skipReason)),
94
102
  skipReason: consulted ? null : (input.skipReason ?? ""),
95
103
  ...turnFeatures(input.features ?? {}),
96
104
  adviceId: advice?.adviceId ?? null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kangyishuai/dsh-advisor",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Pair the main model with a stronger advisor model it consults at key moments: autonomous second opinion, cost ledger, and model picker",
5
5
  "keywords": [
6
6
  "dsh",