@kangyishuai/dsh-advisor 0.2.0 → 0.4.0

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
@@ -53,31 +53,52 @@ Re-run `pnpm pack` + `add` after changing the code. The plugin has a host half a
53
53
 
54
54
  Settings live in one JSON file, `<DSH_HOME>/advisor.settings.json` (`DSH_HOME` defaults to `~/.dsh`; the plugin's `dataRoot` config overrides it). The host re-reads the file before each consultation (1 s cache), so editing it applies to the next call without a restart. Unknown keys are dropped, out-of-range numbers are clamped, and a corrupt file falls back to the defaults. **The default is `off`** — a plugin that spends money and sends conversation content stays opt-in.
55
55
 
56
- | Key | Default | Range / values | Meaning |
57
- | -------------------- | ----------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
58
- | `mode` | `"off"` | `off` / `shadow` / `advisory` | Whether the plugin may call the advisor at all. |
59
- | `provider` | `""` | route name from Settings → Models, up to 300 chars | Advisor route. Empty means never call. |
60
- | `model` | `""` | model id under that route, up to 300 chars | Advisor model. Empty means never call. |
61
- | `reasoningEffort` | `""` | an effort id from the model, `""` = model default | Thinking effort for the advisor. An unsupported value is retried once without an effort; `doctor` warns about it. |
62
- | `maxTokens` | `4096` | 256–32000 | Output cap per consultation. |
63
- | `temperature` | `null` | 0–2, `null` = not sent | `null` lets the model adapter decide. |
64
- | `maxCallsPerTurn` | `1` | 0–8, `0` = unlimited | Consultations per turn. |
65
- | `maxCallsPerSession` | `32` | 0–1000, `0` = unlimited | Consultations per session. |
66
- | `maxCallsPerHour` | `12` | 0–500, `0` = unlimited | Sliding one-hour window. |
67
- | `maxCostPerDayUsd` | `0` | 0–10000, `0` = unlimited | Daily spend ceiling in USD. Only meaningful once the two prices below are set. |
68
- | `priceInputPerMTok` | `0` | 0–1000 | Your advisor model's input price, USD per million tokens. `0` = do not estimate money. |
69
- | `priceOutputPerMTok` | `0` | 0–1000 | Output price, USD per million tokens. |
70
- | `privacyScope` | `"summary"` | `full` / `summary` / `off` | How much of the conversation is sent — see [Cost & privacy](#cost--privacy). |
71
- | `redact` | `true` | boolean | Best-effort scrubbing of token-shaped strings before anything is sent. |
72
- | `immuneTurns` | `3` | 0–20 | Turns to stay quiet after a delivery. Used by shadow delivery; reserved in this MVP — see the note below. |
73
- | `dedupe` | `true` | boolean | Suppress repeated suggestions. Used by shadow delivery; reserved for the tool path — see the note below. |
74
- | `sessionCap` | `24` | 0–200 | Max advice items delivered per session; once reached only `blocker` still gets through. |
75
- | `tiers` | `{}` | map of `"provider/model"` → number | Capability ranks for the pairing check. Without an entry the pairing is reported as unverified, never as passed. |
76
- | `pairingEnforcement` | `"warn"` | `warn` / `block` | What to do when the advisor's declared tier is lower than the main model's. |
77
- | `timeoutMs` | `90000` | 5000–600000 | Per-consultation timeout; `/advisor cancel` aborts sooner. |
78
- | `maxInputChars` | `60000` | 4000–400000 | Total transcript budget; excess in the middle is elided and head/tail are kept. |
79
-
80
- > **Note on `sessionCap`, `dedupe`, `immuneTurns`:** `sessionCap` is enforced — after that many delivered items in one session only `blocker` advice is still returned. `dedupe` and `immuneTurns` are persisted and used by the shadow path, but the tool path does not suppress a consultation because of them (you asked for it explicitly). The ceilings that stop _calls_ altogether are `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDayUsd`.
56
+ **Settings UI.** Settings → General → Advisor. With the default `off`, the card shows only the mode, a one-line status and “Configure advisor”. Expanding or enabling it reveals:
57
+
58
+ - **Basics**: mode, currency, provider, model, reasoning effort, daily budget, send scope, redaction.
59
+ - **Advanced** (folded by default): call limits, workspace limits, CNY-per-USD rate, prices, output/input caps, advice-item cap, allowlist, auto-review, file reading, shadow dedupe, sent-content recording. The heading shows “Defaults” or “N changed”.
60
+ - **Status & diagnostics** (folded by default): calls/tokens/cost, last result/skip reason, send preview, diagnostics, settings and ledger paths.
61
+
62
+ The “?” next to an advanced field expands an inline help block (click or activate with the keyboard) with the description, default/range and technical key; hover is only a supplement. Click **Save** to apply changes to the next consultation.
63
+
64
+ Money fields accept decimals: budgets up to 2, unit prices up to 4.
65
+
66
+ | Key | UI label | Default | Range / values | Meaning |
67
+ | ------------------------- | ------------------------------ | ----------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
68
+ | `mode` | Mode | `"off"` | off / shadow / advisory | Whether the plugin may consult at all. Off by default; opt in explicitly. |
69
+ | `provider` | Provider | `""` | route name from Settings → Models, ≤300 chars | Advisor route. Empty means never call. |
70
+ | `model` | Model | `""` | model id under that route, ≤300 chars | Advisor model. Empty means never call. |
71
+ | `reasoningEffort` | Reasoning effort | `""` | a supported effort id, `""` = model default | An unsupported value is retried once without an effort. |
72
+ | `maxTokens` | Output limit | `4096` | 256–32000 | Maximum output tokens per consultation. |
73
+ | `temperature` | Randomness | `null` | 0–2, `null` = not sent | Empty lets the model decide. |
74
+ | `maxCallsPerTurn` | Calls per turn | `1` | 0–8, 0 = unlimited | Maximum consultations per turn. |
75
+ | `maxCallsPerSession` | Calls per session | `32` | 0–1000, 0 = unlimited | Maximum consultations per session. |
76
+ | `maxCallsPerHour` | Calls per hour | `12` | 0–500, 0 = unlimited | Sliding one-hour window. |
77
+ | `currency` | Currency | `"USD"` | USD / CNY | Amounts and prices are entered in this currency; the ledger/pool stay in USD internally. |
78
+ | `usdToCny` | CNY per USD | `7.2` | 0.1–100 | 1 USD = ? CNY; used only for CNY conversion; manual, never fetched. |
79
+ | `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. |
80
+ | `priceInputPerMTok` | Input price | `0` | 0–1000; up to 4 decimals | Advisor input price in the selected currency per 1M tokens; 0 = do not price. |
81
+ | `priceOutputPerMTok` | Output price | `0` | 0–1000; up to 4 decimals | Output price in the selected currency per 1M tokens. |
82
+ | `privacyScope` | Send scope | `"summary"` | off / summary / full | How much conversation content is sent — see Cost & privacy. |
83
+ | `redact` | Redact before sending | `true` | boolean | Best-effort masking of common key formats; not a guarantee. |
84
+ | `immuneTurns` | JSON only: Immune turns | `3` | 0–20 | Turns to stay quiet after a delivery; used by shadow delivery. |
85
+ | `dedupe` | Dedupe in shadow mode | `true` | boolean | In shadow mode, the same advice is recorded once; the tool path does not block on it. |
86
+ | `sessionCap` | Advice items per session | `24` | 0–200 | Max advice items shown per session; once reached only blockers get through. |
87
+ | `tiers` | JSON only: Tiers | `{}` | `"provider/model"` → number | Capability ranks for the pairing check; without an entry the pairing is unverified. |
88
+ | `allowedModels` | Model allowlist | `[]` | string array | Empty = no limit; accepts provider/model or a bare model id. |
89
+ | `confirmedHosts` | JSON/button: Confirmed hosts | `[]` | string array | Cross-provider confirmation list; the settings-card button writes it. |
90
+ | `pairingEnforcement` | JSON only: Pairing enforcement | `"warn"` | warn / block | When the advisor tier is lower: warn allows and warns; block refuses. |
91
+ | `workspaceMaxCallsPerDay` | Workspace calls per day | `200` | 0–100000, 0 = unlimited | Workspace-wide, shared across sessions, resets on the local day. |
92
+ | `workspaceMaxCostPerDay` | Workspace daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Workspace-wide daily ceiling in the selected currency. |
93
+ | `postAnswer` | Auto-review after each turn | `"off"` | off / card | In advisory mode, runs once after each answer; records only, never inserts. |
94
+ | `advisorTools` | Let the advisor read files | `false` | boolean | Lets it read working-directory files (up to 5, read-only); costs one extra call. |
95
+ | `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. |
96
+ | `timeoutMs` | JSON only: Timeout | `90000` | 5000–600000 | Per-consultation timeout; `/advisor cancel` aborts sooner. |
97
+ | `maxInputChars` | Input limit | `60000` | 4000–400000 | Total transcript budget; excess in the middle is elided, head/tail kept. |
98
+
99
+ **Currency and ledger.** Amounts and prices in settings are entered in `currency` (USD/CNY); `usdToCny` is a manual rate. The ledger and workspace pool always store USD: limits/prices are converted to USD at call time and displayed back in the selected currency. Switching currency converts the form amounts at the rate before saving; old `maxCostPerDayUsd` / `workspaceMaxCostPerDayUsd` keys migrate as USD to the new keys. A rate change affects future conversion/display, not the historical ledger.
100
+
101
+ > **Note on `sessionCap`, `dedupe`, `immuneTurns`:** `sessionCap` is enforced — after that many delivered items in one session only `blocker` advice is still returned. `dedupe` and `immuneTurns` are persisted and used by the shadow path, but the tool path does not suppress a consultation because of them (you asked for it explicitly). The ceilings that stop _calls_ altogether are `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDay`.
81
102
 
82
103
  Example (placeholder route and model names — use the ones the picker shows you):
83
104
 
@@ -93,11 +114,11 @@ Example (placeholder route and model names — use the ones the picker shows you
93
114
 
94
115
  **Two-pass evidence (opt-in).** With `advisorTools: true` the advisor may answer with `needs: [{kind:"file", ref:"path"}]`. The plugin reads those files **inside the session working directory only** (≤5 files, ≤64 KiB each, `../` and symlink escapes rejected), then calls the advisor once more with the quoted evidence so it can revise. This is the "advisor can check the facts" mode; it costs one extra model call. A rejected or unreadable path is reported back as unavailable evidence instead of failing the consultation.
95
116
 
96
- **Workspace budget.** Besides the per-session ceilings, a shared pool (`<DSH_HOME>/advisor/budget.json`) counts calls and estimated cost per local day across sessions (`workspaceMaxCallsPerDay`, `workspaceMaxCostPerDayUsd`).
117
+ **Workspace budget.** Besides the per-session ceilings, a shared pool (`<DSH_HOME>/advisor/budget.json`) counts calls and estimated cost per local day across sessions (`workspaceMaxCallsPerDay`, `workspaceMaxCostPerDay`).
97
118
 
98
119
  **Evidence anchors.** Each advice item may cite `{kind, ref}` anchors (a tool-call id, a message id, a file path). The plugin checks every ref against the session and marks the item unverified when nothing matches; if **none** of the cited anchors exist, the severity is downgraded one step and the advice says so. This is how a hallucinated "that failing command" gets caught.
99
120
 
100
- **Advice line and report.** Each consultation is recorded as a session plugin record (not part of the model-visible surface), so the turn gets a compact advisor line in the chat and `/advisor report` can attribute adoption over time. Attribution is deliberately conservative: no signal, no credit.
121
+ **Advice line and report.** Each consultation is recorded as a session plugin record (not part of the model-visible surface), so the turn gets a compact advisor line in the chat and `/advisor report` can attribute adoption over time. Attribution is deliberately conservative: no signal, no credit. Expanding the line shows the trigger, local time, advisor model, characters sent and the usage/cost summary for that consultation. When a sent-content preview was stored, the expanded line also offers a “View sent content” toggle.
101
122
 
102
123
  **Picking a model.** `/advisor` opens a picker listing the routes and models already configured in DSH, plus _off_ and _add / configure provider_. Choosing a model switches `mode` to `advisory`. `/advisor doctor` tells you line by line what is still missing.
103
124
 
@@ -127,11 +148,12 @@ This is the section to read before turning it on.
127
148
 
128
149
  - **Every consultation is an extra model call**, billed by the advisor route against that provider's quota. The main model's own usage is unaffected.
129
150
  - **Token accounting is ours.** DSH records usage only for the main loop's assistant messages, so the plugin writes its own ledger: `<DSH_HOME>/advisor/usage.jsonl`, one JSON object per consultation (time, session id, trigger `tool` / `shadow` / `manual`, provider, model, effort, verdict, severity, input/output/cache tokens, estimated cost, duration, error code). The file is append-only, rolls over to `usage.jsonl.1` at 2 MiB, and totals are restored from its tail on startup.
130
- - **Money needs your prices.** DSH's model metadata has no price field. Set `priceInputPerMTok` and `priceOutputPerMTok`; with zeros the ledger records tokens only and no dollar amount is shown. The plugin never guesses prices.
151
+ - **Money needs your prices.** DSH's model metadata has no price field. Set `priceInputPerMTok` and `priceOutputPerMTok` in the selected `currency`; with zeros the ledger records tokens only and no money amount is shown. The ledger stores the USD equivalent; built-in reference prices are USD and are converted for CNY display. The plugin never guesses prices.
131
152
  - **The daily budget counts spend already recorded**, so the one consultation that crosses the ceiling still completes and is charged.
132
153
  - **Conversation content leaves the machine when the advisor route is external.** The transcript — with tool calls and results, bounded by `privacyScope` and `maxInputChars` — is sent to whatever base URL that route points at. If that is another vendor, your conversation leaves this machine. Only a route pointing at a local gateway keeps it local. The plugin sends nothing else: no telemetry, no analytics, no network access besides the consultation itself.
133
154
  - **`privacyScope` decides how much is sent.** `summary` (default): each text block up to 2,000 characters, tool arguments up to 300, tool results up to 700. `off`: user and assistant text only, up to 1,200 characters, with no tool traffic at all. `full`: text up to 4,000, tool arguments up to 1,200, tool results up to 3,500. The rendered transcript is then capped at `maxInputChars` (60,000 by default): the first 30% and the tail are kept and the middle is replaced by an elision marker.
134
155
  - **Redaction is best-effort.** With `redact: true` (default) the plugin scrubs common token-shaped strings, `Authorization` headers, `KEY=` / `TOKEN:`-style assignments, credentials embedded in URLs and PEM private-key blocks **before** clipping. It is a heuristic filter, **not a secret scanner**: it will miss things, it cannot guarantee that a secret never leaves, and it is no substitute for deciding whether this repository may be sent to that provider at all.
156
+ - **The sent-content preview is written to the session record.** With `tracePrompt: "preview"` (default), the first and last 2,000 characters of the text actually sent (after redaction and `maxInputChars` clipping) are stored in the session plugin record and can be opened from the advisor line; `off` stores metadata only. With `redact` off, the preview is raw text.
135
157
  - **Start in `shadow`.** It answers "what would it have said, and what would that have cost" without putting model output back into your session. Read the ledger for a few days, then switch to `advisory`.
136
158
 
137
159
  ## Compatibility
@@ -159,7 +181,7 @@ Nothing else: no workspace files, no session-log records of its own (a consultat
159
181
  - **Pairing needs your declaration.** DSH has no cross-vendor capability catalog, so "is the advisor at least as strong as the main model" can only come from your `tiers`. Without an entry the result says **unverified** and the consultation proceeds; it never pretends the check passed. With `pairingEnforcement: "block"` a lower declared tier rejects the consultation.
160
182
  - **Token counts can be low on an aborted call.** If a consultation is cancelled or times out, no usage chunk may arrive; the ledger then records the call with zero tokens and a cost budget can lag real spend. Treat the ledger as a good estimate, not an invoice.
161
183
  - **The advisor route can be broken from outside this plugin** (wrong base URL, missing key, rate limit). Every failure becomes a structured tool result (`MISSING_CREDENTIAL`, `rate_limited`, `overloaded`, `prompt_too_long`, `timeout`, `aborted`, …) and never breaks the turn.
162
- - **No settings card in this MVP.** Configuration is the JSON file plus the picker; there is no Settings → General page yet.
184
+ - **The settings card lives at the bottom of Settings → General.** It may need scrolling; keys marked JSON-only still need the settings file, and the `/advisor` picker remains available.
163
185
  - **Partially enforced knobs.** `sessionCap` caps delivered advice per session (blockers exempt); `dedupe` / `immuneTurns` only matter on the shadow path — see [Configure](#configure).
164
186
  - **One attempt, not a retry loop.** A malformed advisor answer is reported as unavailable rather than retried; an unsupported thinking effort is retried exactly once without an effort.
165
187
  - **`shadow` mode still spends quota.** It skips the injection, not the call. And while `shadow` is on, an explicit `advisor` tool call still returns its advice: the mode suppresses the automatic end-of-turn review, not a model-initiated consultation. Use `off` to stop all calls.
@@ -170,11 +192,13 @@ Nothing else: no workspace files, no session-log records of its own (a consultat
170
192
  ```bash
171
193
  pnpm verify # repo-wide gates: lint, typecheck, plugin conventions, docs, unit tests
172
194
  cd packages/advisor && pnpm test # unit tests for this plugin (node --test)
195
+ pnpm smoke:advisor # web end-to-end smoke in a throwaway DSH home (spends nothing)
173
196
  pnpm smoke:advisor-desktop # desktop (Electron) read-only regression over CDP
174
197
  pnpm smoke:agent-tool # repo-wide real-model tool smoke (needs credentials; SKIPs without them)
175
198
  ```
176
199
 
177
200
  - `pnpm verify` is the release gate and must pass before a PR.
201
+ - `pnpm smoke:advisor` starts a real host in a throwaway `DSH_HOME` (one temporary workspace, no credentials needed), installs the packed plugin and asserts: the client half loads, `/` lists `advisor`, the settings card renders, and `/advisor doctor` / `preview` / `confirm` / `report all` produce output — then checks that **no ledger file was created**, i.e. it spent nothing. Command output is read from the session log because the host renders command cards collapsed.
178
202
  - `pnpm smoke:advisor-desktop` is the desktop (Electron) read-only regression, required because the plugin has a client half. It attaches to the running app over CDP, confirms the plugin's client half actually loaded, and never triggers a paid consultation. Pass `--require` in release gates so an unreachable debug port fails instead of silently skipping. It expects the app started with `open -a "DeepSeek Harness" --args --remote-debugging-port=9222 --remote-debugging-address=127.0.0.1`.
179
203
  - `pnpm smoke:agent-tool` exercises a registered tool with a real model in a throwaway DSH home. It needs model credentials and exits as SKIP without them — a SKIP is not a pass.
180
204
 
package/README.zh-CN.md CHANGED
@@ -53,31 +53,52 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
53
53
 
54
54
  插件设置只有一个 JSON 文件:`<DSH_HOME>/advisor.settings.json`(`DSH_HOME` 默认 `~/.dsh`,插件配置里的 `dataRoot` 可覆盖)。宿主在每次徵询前重读(1 秒缓存),所以改文件对下一次调用立即生效,不用重启。未知键会被丢弃,越界的数字会被夹紧到区间,文件损坏则回落到默认值。**默认是 `off`**——一个会花钱、会把会话内容发出去的插件必须显式开启。
55
55
 
56
- | 键 | 默认 | 范围 / 取值 | 说明 |
57
- | -------------------- | ----------- | -------------------------------------- | ------------------------------------------------------------------- |
58
- | `mode` | `"off"` | `off` / `shadow` / `advisory` | 是否允许调用顾问。 |
59
- | `provider` | `""` | 设置 → 模型里的路由名,最长 300 字符 | 顾问路由。留空 = 永不调用。 |
60
- | `model` | `""` | 该路由下的模型 id,最长 300 字符 | 顾问模型。留空 = 永不调用。 |
61
- | `reasoningEffort` | `""` | 模型支持的思考档 id,`""` = 用模型默认 | 顾问的思考档。填了不支持的值会去掉思考档重试一次,`doctor` 会告警。 |
62
- | `maxTokens` | `4096` | 256–32000 | 单次徵询的输出上限。 |
63
- | `temperature` | `null` | 0–2,`null` = 不传 | `null` 表示交给模型 adapter 决定。 |
64
- | `maxCallsPerTurn` | `1` | 0–8,`0` = 不限 | 每回合徵询次数。 |
65
- | `maxCallsPerSession` | `32` | 0–1000,`0` = 不限 | 每会话徵询次数。 |
66
- | `maxCallsPerHour` | `12` | 0–500,`0` = 不限 | 滚动一小时内。 |
67
- | `maxCostPerDayUsd` | `0` | 0–10000,`0` = 不限 | 每日金额上限(美元)。只有下面两个单价填了才有意义。 |
68
- | `priceInputPerMTok` | `0` | 0–1000 | 顾问模型的输入单价,美元 / 百万 token。`0` = 不算钱。 |
69
- | `priceOutputPerMTok` | `0` | 0–1000 | 输出单价,美元 / 百万 token。 |
70
- | `privacyScope` | `"summary"` | `full` / `summary` / `off` | 发送多少内容——见[成本与隐私](#成本与隐私)。 |
71
- | `redact` | `true` | 布尔 | 发送前对密钥形态的字符串做尽力而为的脱敏。 |
72
- | `immuneTurns` | `3` | 0–20 | 投递后保持安静的回合数。shadow 投递用;工具路径不据此拦截。 |
73
- | `dedupe` | `true` | 布尔 | 抑制重复建议。shadow 投递用;工具路径不据此拦截。 |
74
- | `sessionCap` | `24` | 0–200 | 单会话最多投递多少条建议;到顶后只有 `blocker` 继续投递。 |
75
- | `tiers` | `{}` | `"provider/model"` → 数字的映射 | 配对校验用的能力档位。没有条目时结论是「未校验」,不会假装通过。 |
76
- | `pairingEnforcement` | `"warn"` | `warn` / `block` | 顾问声明的档位低于主模型时怎么办。 |
77
- | `timeoutMs` | `90000` | 5000–600000 | 单次徵询超时;`/advisor cancel` 可以更早中止。 |
78
- | `maxInputChars` | `60000` | 4000–400000 | 会话文本总预算;超出部分折叠中间、保留首尾。 |
79
-
80
- > **关于 `sessionCap`、`dedupe`、`immuneTurns`:** `sessionCap` 会生效——单会话投递到上限后,只有 `blocker` 级建议还会返回。`dedupe` 与 `immuneTurns` 会被保存并用于 shadow 路径,但工具路径不会因为它们跳过徵询(是模型显式要求的)。真正会拦住**调用本身**的是 `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDayUsd`。
56
+ **设置页。** 设置 → 通用 → 顾问。默认 `off` 时卡片只显示模式、一句状态和「配置顾问」;展开或启用后才显示:
57
+
58
+ - **基础**:模式、币种、服务商、模型、思考档、每日预算、发送范围、发送前脱敏。
59
+ - **高级**(默认折叠):调用限额、工作区限额、人民币汇率、单价、输出/输入上限、建议条数、白名单、答后复查、读文件核实、影子去重、记录发送内容;折叠标题会标出「默认值」或「N 项已修改」。
60
+ - **状态与诊断**(默认折叠):累计调用/token/金额、最近结果/跳过原因、发送预览、诊断、设置文件与账本路径。
61
+
62
+ 高级字段旁的「?」点开或用键盘激活会显示说明、默认值与范围、技术名;悬停只是补充。改完点「保存」才对下一次徵询生效。
63
+
64
+ 金额字段支持小数:预算最多 2 位,单价最多 4 位。
65
+
66
+ | 键 | 设置页名称 | 默认 | 范围 / 取值 | 说明 |
67
+ | ------------------------- | ----------------------------- | ----------- | ------------------------------------ | ----------------------------------------------------------------------------- |
68
+ | `mode` | 模式 | `"off"` | off / shadow / advisory | 是否允许徵询。默认关闭,显式开启才生效。 |
69
+ | `provider` | 服务商 | `""` | 设置 → 模型里的路由名,≤300 字符 | 顾问路由。留空 = 永不调用。 |
70
+ | `model` | 模型 | `""` | 该路由下的模型 id,≤300 字符 | 顾问模型。留空 = 永不调用。 |
71
+ | `reasoningEffort` | 思考档 | `""` | 模型支持的思考档 id,`""` = 模型默认 | 填了不支持的值会去掉思考档重试一次。 |
72
+ | `maxTokens` | 输出上限 | `4096` | 256–32000 | 单次徵询最多生成多少 token。 |
73
+ | `temperature` | 随机性 | `null` | 0–2,`null` = 不传 | 留空由模型决定。 |
74
+ | `maxCallsPerTurn` | 每回合调用上限 | `1` | 0–8,0 = 不限 | 每回合最多徵询几次。 |
75
+ | `maxCallsPerSession` | 每会话调用上限 | `32` | 0–1000,0 = 不限 | 每个会话最多徵询几次。 |
76
+ | `maxCallsPerHour` | 每小时调用上限 | `12` | 0–500,0 = 不限 | 滚动一小时内。 |
77
+ | `currency` | 币种 | `"USD"` | USD / CNY | 金额和单价按此币种填写;账本/预算池内部仍记 USD。 |
78
+ | `usdToCny` | 人民币汇率 | `7.2` | 0.1–100 | 1 USD = ? CNY;只在人民币时用于换算;手动维护,不联网。 |
79
+ | `maxCostPerDay` | 每日预算(按币种) | `0` | 0–10000,0 = 不限;最多 2 位小数 | 每天最多花多少(按 `currency`);只有填了单价才计算金额。 |
80
+ | `priceInputPerMTok` | 输入单价 | `0` | 0–1000;最多 4 位小数 | 顾问模型输入价,按 `currency` / 百万 token;0 = 不算钱。 |
81
+ | `priceOutputPerMTok` | 输出单价 | `0` | 0–1000;最多 4 位小数 | 输出价,按 `currency` / 百万 token。 |
82
+ | `privacyScope` | 发送范围 | `"summary"` | off / summary / full | 发多少会话内容,见「成本与隐私」。 |
83
+ | `redact` | 发送前脱敏 | `true` | 布尔 | 尽量遮掉常见密钥格式;不能保证全部遮住。 |
84
+ | `immuneTurns` | 仅 JSON:免疫回合 | `3` | 0–20 | 投递后保持安静的回合数;只用于 shadow 投递。 |
85
+ | `dedupe` | 影子模式去重 | `true` | 布尔 | 影子模式下相同建议只记一次;工具路径不据此拦截。 |
86
+ | `sessionCap` | 建议条数上限 | `24` | 0–200 | 单会话最多展示几条建议;到顶后只有 blocker 继续。 |
87
+ | `tiers` | 仅 JSON:能力档位 | `{}` | `"provider/model"` → 数字 | 配对校验用的档位;没有条目时结论是「未校验」。 |
88
+ | `allowedModels` | 模型白名单 | `[]` | 字符串数组 | 留空 = 不限制;可写 provider/model 或裸 model id。 |
89
+ | `confirmedHosts` | 仅 JSON/按钮:已确认 provider | `[]` | 字符串数组 | 跨 provider 发送的确认名单;设置卡里的按钮会写入。 |
90
+ | `pairingEnforcement` | 仅 JSON:配对校验 | `"warn"` | warn / block | 顾问档位低于主模型时:warn 放行并告警,block 拒绝。 |
91
+ | `workspaceMaxCallsPerDay` | 工作区每日调用上限 | `200` | 0–100000,0 = 不限 | 工作区级,跨会话累计,按本地日重置。 |
92
+ | `workspaceMaxCostPerDay` | 工作区每日预算(按币种) | `0` | 0–10000,0 = 不限;最多 2 位小数 | 工作区级每日金额上限(按 `currency`)。 |
93
+ | `postAnswer` | 回合结束后自动复查 | `"off"` | off / card | advisory 模式下每轮回答后自动复查一次;只记录,不插回对话。 |
94
+ | `advisorTools` | 允许顾问读文件核实 | `false` | 布尔 | 允许顾问读工作目录内的文件(≤5 个、只读);多一次调用。 |
95
+ | `tracePrompt` | 记录发送内容 | `"preview"` | `preview` / `off` | 在会话记录里保留实际发送文本的首尾各 2,000 字符(脱敏后);`off` 只记元数据。 |
96
+ | `timeoutMs` | 仅 JSON:超时 | `90000` | 5000–600000 | 单次徵询超时;`/advisor cancel` 可以更早中止。 |
97
+ | `maxInputChars` | 输入上限 | `60000` | 4000–400000 | 会话文本总预算;超出保留首尾、省略中间。 |
98
+
99
+ **币种与账本。** 设置里的金额和单价按 `currency` 填写(USD/CNY),`usdToCny` 是手动汇率。账本与工作区预算池内部始终记 USD:调用时把设置金额换算成 USD,展示时再换回当前币种。切换币种会按汇率折算当前表单金额,保存前不会落盘;旧版 `maxCostPerDayUsd` / `workspaceMaxCostPerDayUsd` 键会按 USD 自动迁移到新键。汇率变化只影响之后的换算和展示,不会重写历史账本。
100
+
101
+ > **关于 `sessionCap`、`dedupe`、`immuneTurns`:** `sessionCap` 会生效——单会话投递到上限后,只有 `blocker` 级建议还会返回。`dedupe` 与 `immuneTurns` 会被保存并用于 shadow 路径,但工具路径不会因为它们跳过徵询(是模型显式要求的)。真正会拦住**调用本身**的是 `maxCallsPerTurn` / `maxCallsPerSession` / `maxCallsPerHour` / `maxCostPerDay`。
81
102
 
82
103
  示例(路由名和模型名是占位,请用选择器里看到的真实值):
83
104
 
@@ -109,24 +130,27 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
109
130
 
110
131
  `advisor` **工具**和命令是两回事:工具由模型调用,不是你。它没有必填参数;可选的 `focus` 是一句话,用来说明你想让顾问解决的疑点——不是任务本身,任务永远是整段对话。
111
132
 
133
+ 每次徵询还会在回合末尾留下一条紧凑的顾问线(不进入模型可见的 surface);展开后显示本次徵询的触发方式、本地时间、顾问模型、发送字符数与用量/成本摘要。 记录了发送内容时,展开后可以点「查看发送内容」看当时实际发送文本的首尾片段。
134
+
112
135
  ## 成本与隐私
113
136
 
114
137
  这一节请在开启前读完。
115
138
 
116
139
  - **每次徵询都是一次额外的模型调用**,按顾问路由计费,走那家 provider 的额度。主模型自身的 usage 不受影响。
117
140
  - **token 由插件自己记账。** DSH 只为主动环里的 assistant 消息记 usage,所以插件单写一份账本:`<DSH_HOME>/advisor/usage.jsonl`,一次徵询一行 JSON(时间、会话 id、触发方式 `tool` / `shadow` / `manual`、provider、model、思考档、结论、严重度、输入 / 输出 / 缓存 token、估算金额、耗时、错误码)。文件只追加,超过 2 MiB 滚动到 `usage.jsonl.1`,启动时从文件尾部恢复累计数。
118
- - **算钱需要你填单价。** DSH 的模型元数据没有价格字段。填 `priceInputPerMTok` 和 `priceOutputPerMTok`;都留 0 时账本只记 token,界面不显示金额。插件从不猜价格。
141
+ - **算钱需要你填单价。** DSH 的模型元数据没有价格字段。按 `currency` 填 `priceInputPerMTok` 和 `priceOutputPerMTok`;都留 0 时账本只记 token,界面不显示金额。账本内部记 USD 等价,内置参考价是 USD,人民币展示时折算。插件从不猜价格。
119
142
  - **每日预算统计的是已经记下的花费**,所以跨过上限的那一次徵询仍会完成并计费。
120
143
  - **顾问路由在外部时,会话内容会离开本机。** 渲染后的会话文本(含工具调用与结果,受 `privacyScope` 和 `maxInputChars` 限制)会发到该路由指向的 baseURL。如果那是另一家厂商,你的对话就离开了这台机器;只有指向本地网关的路由才留在本机。除此之外插件什么都不发:没有遥测,没有统计,除了徵询本身不访问网络。
121
144
  - **`privacyScope` 决定发多少。** `summary`(默认):每个文本块最多 2,000 字符,工具参数最多 300,工具结果最多 700。`off`:只发用户与助手的文本(最多 1,200 字符),完全不发工具往来。`full`:文本最多 4,000,工具参数最多 1,200,工具结果最多 3,500。渲染完再按 `maxInputChars`(默认 60,000)封顶:保留前 30% 和结尾,中间替换成省略标记。
122
145
  - **脱敏是尽力而为。** `redact: true`(默认)会在**截断之前**清掉常见的密钥形态字符串、`Authorization` 头、`KEY=` / `TOKEN:` 形式的赋值、URL 里内嵌的凭据,以及 PEM 私钥块。它是启发式过滤,**不是密钥扫描器**:一定会漏,也无法保证密钥绝不外发;更不能替代「这个仓库是否允许发给那家 provider」这个判断。
146
+ - **发送预览会写入会话记录。** `tracePrompt: "preview"`(默认)会把本次实际发送文本的首尾各 2,000 字符(脱敏、按 `maxInputChars` 截断后)写进会话插件记录,展开顾问线后可查看;`off` 只记元数据。若同时关闭 `redact`,预览就是原文片段。
123
147
  - **先开 `shadow`。** 它回答的是「它本来会说什么、本来要花多少」,但不把模型输出塞回你的会话。看几天账本,再切到 `advisory`。
124
148
 
125
149
  ## 兼容性
126
150
 
127
- | 已验证的 DSH 版本 | 状态 |
128
- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
129
- | 0.2.2-rc.1 | 已在该版本验证:单测(设置夹紧、选路与配对、预算守卫、会话渲染、脱敏、输出契约)与 `pnpm probe:runtime`;桌面端只读回归为 `pnpm smoke:advisor-desktop`。其他 DSH 版本未验证。 |
151
+ | 已验证的 DSH 版本 | 状态 |
152
+ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
153
+ | 0.2.2-rc.1 | 已在该版本验证:单测(81 条)与 `pnpm probe:runtime`;web 端到端冒烟 `pnpm smoke:advisor`、桌面端只读回归 `pnpm smoke:advisor-desktop`。其他 DSH 版本未验证。 |
130
154
 
131
155
  插件不声明 `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`。
132
156
 
@@ -146,7 +170,7 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
146
170
  - **配对档位需要你自己声明。** DSH 没有跨厂商的能力目录,所以「顾问是不是至少和主模型一样强」只能来自你填的 `tiers`。没有条目时结论是**未校验**,徵询照常进行;它不会假装校验通过。把 `pairingEnforcement` 设成 `"block"` 时,档位更低的顾问会被拒绝。
147
171
  - **被中止的调用 token 可能记少。** 徵询被取消或超时时,可能收不到 usage chunk;账本会把这次记成 0 token,金额预算可能落后于真实花费。把账本当可靠估算,别当账单。
148
172
  - **顾问路由可能因为插件之外的原因坏掉**(baseURL 写错、缺密钥、限流)。所有失败都会变成结构化的工具结果(`MISSING_CREDENTIAL`、`rate_limited`、`overloaded`、`prompt_too_long`、`timeout`、`aborted`…),不会把回合弄断。
149
- - **本 MVP 没有设置页卡片。** 配置就是 JSON 文件加选择器,还没有「设置 → 通用」里的卡片。
173
+ - **设置卡在「设置 → 通用」的底部。** 可能需要往下滚;标了「仅 JSON」的键仍要改设置文件,或继续用 `/advisor` 选择器。
150
174
  - **部分生效的旋钮。** `sessionCap` 会限制单会话投递条数(blocker 豁免);`dedupe` / `immuneTurns` 只在 shadow 路径上有意义——见[配置](#配置)。
151
175
  - **只试一次,没有重试循环。** 顾问输出解析失败会报 unavailable,不重试;不支持的思考档只会去掉思考档重试一次。
152
176
  - **`shadow` 模式照样花钱。** 它省掉的是回灌,不是调用。而且 `shadow` 期间,模型主动调用 `advisor` 工具仍会拿到建议:这个模式抑制的是回合结束后的自动复查,不是模型发起的徵询。要彻底停调用请用 `off`。
@@ -157,11 +181,13 @@ dsh plugin --profile desktop add /tmp/kangyishuai-dsh-advisor-*.tgz
157
181
  ```bash
158
182
  pnpm verify # 仓库级门禁:lint、类型、插件规范、文档一致性、单测
159
183
  cd packages/advisor && pnpm test # 本插件的单测(node --test)
184
+ pnpm smoke:advisor # web 端到端冒烟(一次性 DSH_HOME,不花钱)
160
185
  pnpm smoke:advisor-desktop # 桌面版(Electron)只读回归,走 CDP
161
186
  pnpm smoke:agent-tool # 仓库级真实模型工具冒烟(需要凭据,没有就 SKIP)
162
187
  ```
163
188
 
164
189
  - `pnpm verify` 是发版门禁,提 PR 之前必须通过。
190
+ - `pnpm smoke:advisor` 在一次性 `DSH_HOME` 里起真实宿主(只放一个临时工作区、不需要凭据),装包后验证:client 半加载、`/` 菜单出现 `advisor`、设置卡渲染、`/advisor doctor`/`preview`/`confirm`/`report all` 都有输出,并断言**没有生成账本文件**(即没有花钱)。命令输出读会话日志,因为宿主的命令卡片在 DOM 里是折叠的。
165
191
  - `pnpm smoke:advisor-desktop` 是桌面版(Electron)只读回归;插件有 client 半,所以这是硬性要求。它通过 CDP 连上正在运行的应用、确认 client 半真的加载,**不会**触发需要付费的徵询。发版门禁里加 `--require`,这样连不上调试端口会失败而不是静默跳过。它要求应用用 `open -a "DeepSeek Harness" --args --remote-debugging-port=9222 --remote-debugging-address=127.0.0.1` 启动。
166
192
  - `pnpm smoke:agent-tool` 在一次性 DSH 目录里用真实模型驱动一个已注册工具。需要模型凭据;没有凭据时以 SKIP 退出——SKIP 不等于通过。
167
193
 
package/lib/budget.js CHANGED
@@ -6,6 +6,8 @@
6
6
  import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
7
7
  import { join } from "node:path";
8
8
 
9
+ import { toUsd } from "./money.js";
10
+
9
11
  /** 预算池文件名(位于数据根下的 advisor/ 目录)。 */
10
12
  export const BUDGET_FILE = "budget.json";
11
13
 
@@ -40,7 +42,7 @@ export function normalizePool(raw, today) {
40
42
  /**
41
43
  * 池子是否还能容纳一次调用。
42
44
  * @param {{ calls: number, costUsd: number }} pool
43
- * @param {{ workspaceMaxCallsPerDay: number, workspaceMaxCostPerDayUsd: number }} settings
45
+ * @param {{ workspaceMaxCallsPerDay: number, workspaceMaxCostPerDay: number, currency?: string, usdToCny?: number }} settings
44
46
  * @param {number} [estimatedCostUsd]
45
47
  * @returns {{ ok: true } | { ok: false, code: "workspace_calls"|"workspace_budget", used: number, limit: number }}
46
48
  */
@@ -49,9 +51,13 @@ export function checkPool(pool, settings, estimatedCostUsd = 0) {
49
51
  if (maxCalls > 0 && pool.calls >= maxCalls) {
50
52
  return { ok: false, code: "workspace_calls", used: pool.calls, limit: maxCalls };
51
53
  }
52
- const maxCost = Number(settings?.workspaceMaxCostPerDayUsd ?? 0) || 0;
53
- if (maxCost > 0 && pool.costUsd + estimatedCostUsd >= maxCost) {
54
- return { ok: false, code: "workspace_budget", used: pool.costUsd, limit: maxCost };
54
+ const maxCostUsd = toUsd(
55
+ settings?.workspaceMaxCostPerDay,
56
+ settings?.currency,
57
+ settings?.usdToCny,
58
+ );
59
+ if (maxCostUsd > 0 && pool.costUsd + estimatedCostUsd >= maxCostUsd) {
60
+ return { ok: false, code: "workspace_budget", used: pool.costUsd, limit: maxCostUsd };
55
61
  }
56
62
  return { ok: true };
57
63
  }
package/lib/catalog.js CHANGED
@@ -9,6 +9,8 @@
9
9
  //
10
10
  // 纯数据 + 纯函数,不 import 宿主包。
11
11
 
12
+ import { toUsd } from "./money.js";
13
+
12
14
  /**
13
15
  * 能力档位(越大越强)。同一族按代际与规格排序;跨族只保证「明显更强/更弱」的关系。
14
16
  * 键是模型 id 的小写匹配片段,按**从长到短**匹配,避免 `deepseek-v4` 抢走 `deepseek-v4.1-flash`。
@@ -112,13 +114,22 @@ export function effectiveRank(tiers, route) {
112
114
 
113
115
  /**
114
116
  * 有效单价:用户声明 > 内置;都没有返回 `{ input: 0, output: 0 }`(= 不算钱)。
115
- * @param {{ priceInputPerMTok: number, priceOutputPerMTok: number }} settings
117
+ * @param {{ priceInputPerMTok: number, priceOutputPerMTok: number, currency?: string, usdToCny?: number }} settings
116
118
  * @param {string} modelId
117
119
  * @returns {{ input: number, output: number, source: "settings"|"builtin"|"none" }}
118
120
  */
119
121
  export function effectivePrice(settings, modelId) {
120
- const input = Number(settings?.priceInputPerMTok ?? 0) || 0;
121
- const output = Number(settings?.priceOutputPerMTok ?? 0) || 0;
122
+ // 设置里的单价按 settings.currency 填写;内部估算统一换算成 USD。
123
+ const input = toUsd(
124
+ Number(settings?.priceInputPerMTok ?? 0) || 0,
125
+ settings?.currency,
126
+ settings?.usdToCny,
127
+ );
128
+ const output = toUsd(
129
+ Number(settings?.priceOutputPerMTok ?? 0) || 0,
130
+ settings?.currency,
131
+ settings?.usdToCny,
132
+ );
122
133
  if (input > 0 || output > 0) return { input, output, source: "settings" };
123
134
  const builtin = builtinPrice(modelId);
124
135
  if (builtin !== undefined) return { ...builtin, source: "builtin" };