@kangyishuai/dsh-advisor 0.6.1 → 0.6.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 +94 -72
- package/README.zh-CN.md +107 -79
- package/lib/abort-reason.js +29 -0
- package/lib/adoption.js +12 -3
- package/lib/budget.js +36 -33
- package/lib/call.js +45 -11
- package/lib/client.js +381 -80
- package/lib/command-text.js +125 -0
- package/lib/day.js +44 -0
- package/lib/deadline.js +94 -0
- package/lib/decisions.js +162 -75
- package/lib/fs-atomic.js +106 -0
- package/lib/guard.js +14 -5
- package/lib/ledger.js +65 -77
- package/lib/messages.js +108 -0
- package/lib/redact.js +15 -2
- package/lib/service.js +197 -139
- package/lib/settings.js +2 -2
- package/lib/tool-result.js +46 -0
- package/lib/tool-schema.js +4 -2
- package/lib/transcript.js +1 -1
- package/locale/en.json +17 -1
- package/locale/zh.json +24 -8
- package/package.json +1 -1
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
|
-
[](https://www.npmjs.com/package/@kangyishuai/dsh-advisor) [](https://www.npmjs.com/package/@kangyishuai/dsh-advisor) [](#compatibility) [](./LICENSE)
|
|
6
6
|
|
|
7
7
|
[中文](./README.zh-CN.md)
|
|
8
8
|
|
|
@@ -23,9 +23,13 @@ This is an **on-demand** advisor, not a passive reviewer. The main model decides
|
|
|
23
23
|
- **Budgets and a ledger.** Per turn, per session, per hour and a per-day cost ceiling, plus a token ledger at `<DSH_HOME>/advisor/usage.jsonl`. DSH does not record usage for extra model calls, so the plugin records it itself.
|
|
24
24
|
- **A decision log, so "should it have asked?" can be answered with data.** `<DSH_HOME>/advisor/decisions.jsonl` gets
|
|
25
25
|
**one row per turn** (including turns with no consultation): whether it consulted, the reason code when it did not,
|
|
26
|
-
answer length / tool calls / errors, and
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
answer length / tool calls / errors, and how the advice fared afterwards: `accepted` when the next assistant message
|
|
27
|
+
or tool call used something the advice named, `user-typed-other` when the next human message did not, `no-action`
|
|
28
|
+
when the next turn ended with no human reaction at all. Injected host context (time / goal / runtime context) is
|
|
29
|
+
never counted as a user reaction. `pnpm advisor:review` reports consult and acceptance rates per bucket **together
|
|
30
|
+
with the outcome coverage**, and lists two kinds of suspects: probably-missed and probably-wasted. Only
|
|
31
|
+
**top-level sessions** are logged — subagent turns are excluded on purpose, so these are main-session rates.
|
|
32
|
+
Local file only — no network, no change to when it consults.
|
|
29
33
|
|
|
30
34
|
### What it is not
|
|
31
35
|
|
|
@@ -56,9 +60,9 @@ Re-run `pnpm pack` + `add` after changing the code. The plugin has a host half a
|
|
|
56
60
|
|
|
57
61
|
**The advisor model's base URL, API key and wire protocol are not managed by this plugin.** Configure them in DSH _Settings → Models_ — the `dsh-llm-pi-ai` `providers` map, where each key is one route. This plugin only stores the **route name** and a model id; it never reads or writes credentials.
|
|
58
62
|
|
|
59
|
-
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.
|
|
63
|
+
Settings live in one JSON file, `<DSH_HOME>/advisor.settings.json` (`DSH_HOME` defaults to `~/.dsh`; the plugin's `dataRoot` config overrides it, and the plugin config's `language` (`zh`/`en`) overrides the slash-menu description language, which otherwise follows `LANG`/`LC_ALL`). 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.
|
|
60
64
|
|
|
61
|
-
**Settings UI.** Settings → **Advisor** (its own section now, no longer buried in General). The first screen is three rows: mode, route, budget; everything else sits in a “More settings” fold that starts collapsed. With the default `off`, the card shows only the mode, a one-line status and “Configure advisor”. Enabling it reveals:
|
|
65
|
+
**Settings UI.** Settings → **Advisor** (its own section now, no longer buried in General). The first screen is three rows: mode, route, budget; everything else sits in a “More settings” fold that starts collapsed. The mode row carries an **effective-status badge**: the saved `mode` is only a preference, and the host skips consultations when the configuration is incomplete, so the badge reports what actually takes effect and why (“In effect” / “Shadow: log only” / “Off: no advisor model selected” / “Off: mode is off”). With the default `off`, the card shows only the mode, a one-line status and “Configure advisor”. Enabling it reveals:
|
|
62
66
|
|
|
63
67
|
- **Basics**: mode, currency, provider, model, reasoning effort, daily budget, send scope, redaction.
|
|
64
68
|
- **Advanced** (folded by default): call limits, workspace limits, CNY-per-USD rate, prices (including cache read/write), output/input caps, advice-item cap, allowlist, auto-review, file reading, shadow dedupe, sent-content recording. The heading shows “Defaults” or “N changed”.
|
|
@@ -68,40 +72,40 @@ The “?” next to an advanced field expands an inline help block (click or act
|
|
|
68
72
|
|
|
69
73
|
Money fields accept decimals: budgets up to 2, unit prices up to 4.
|
|
70
74
|
|
|
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 |
|
|
104
|
-
| `maxInputChars` | Input limit | `60000` | 4000–400000 | Total transcript budget; excess in the middle is elided, head/tail kept.
|
|
75
|
+
| Key | UI label | Default | Range / values | Meaning |
|
|
76
|
+
| ------------------------- | ------------------------------ | ----------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
77
|
+
| `mode` | Mode | `"off"` | off / shadow / advisory | Whether the plugin may consult at all. Off by default; opt in explicitly. |
|
|
78
|
+
| `provider` | Provider | `""` | route name from Settings → Models, ≤300 chars | Advisor route. Empty means never call. |
|
|
79
|
+
| `model` | Model | `""` | model id under that route, ≤300 chars | Advisor model. Empty means never call. |
|
|
80
|
+
| `reasoningEffort` | Reasoning effort | `""` | a supported effort id, `""` = model default | An unsupported value is retried once without an effort. |
|
|
81
|
+
| `maxTokens` | Output limit | `4096` | 256–32000 | Maximum output tokens per consultation. |
|
|
82
|
+
| `temperature` | Randomness | `null` | 0–2, `null` = not sent | Empty lets the model decide. |
|
|
83
|
+
| `maxCallsPerTurn` | Calls per turn | `1` | 0–8, 0 = unlimited | Maximum consultations per turn. |
|
|
84
|
+
| `maxCallsPerSession` | Calls per session | `32` | 0–1000, 0 = unlimited | Maximum consultations per session. |
|
|
85
|
+
| `maxCallsPerHour` | Calls per hour | `12` | 0–500, 0 = unlimited | Sliding one-hour window. |
|
|
86
|
+
| `currency` | Currency | `"USD"` | USD / CNY | Amounts and prices are entered in this currency; the ledger/pool stay in USD internally. |
|
|
87
|
+
| `usdToCny` | CNY per USD | `7.2` | 0.1–100 | 1 USD = ? CNY; used only for CNY conversion; manual, never fetched. |
|
|
88
|
+
| `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. |
|
|
89
|
+
| `priceInputPerMTok` | Input price | `0` | 0–1000; up to 4 decimals | Advisor input price in the selected currency per 1M tokens; 0 = do not price. |
|
|
90
|
+
| `priceOutputPerMTok` | Output price | `0` | 0–1000; up to 4 decimals | Output price in the selected currency per 1M tokens. |
|
|
91
|
+
| `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. |
|
|
92
|
+
| `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. |
|
|
93
|
+
| `privacyScope` | Send scope | `"summary"` | off / summary / full | How much conversation content is sent — see Cost & privacy. |
|
|
94
|
+
| `redact` | Redact before sending | `true` | boolean | Best-effort masking of common key formats; not a guarantee. |
|
|
95
|
+
| `immuneTurns` | JSON only: Immune turns | `3` | 0–20 | Turns to stay quiet after a delivery; used by shadow delivery. |
|
|
96
|
+
| `dedupe` | Dedupe in shadow mode | `true` | boolean | In shadow mode, the same advice is recorded once; the tool path does not block on it. |
|
|
97
|
+
| `sessionCap` | Advice items per session | `24` | 0–200 | Max advice items shown per session; once reached only blockers get through. |
|
|
98
|
+
| `tiers` | JSON only: Tiers | `{}` | `"provider/model"` → number | Capability ranks for the pairing check; without an entry the pairing is unverified. |
|
|
99
|
+
| `allowedModels` | Model allowlist | `[]` | string array | Empty = no limit; accepts provider/model or a bare model id. |
|
|
100
|
+
| `confirmedHosts` | JSON/button: Confirmed hosts | `[]` | string array | Cross-provider confirmation list; the settings-card button writes it. |
|
|
101
|
+
| `pairingEnforcement` | JSON only: Pairing enforcement | `"warn"` | warn / block | When the advisor tier is lower: warn allows and warns; block refuses. |
|
|
102
|
+
| `workspaceMaxCallsPerDay` | Workspace calls per day | `200` | 0–100000, 0 = unlimited | Workspace-wide, shared across sessions, resets on the local day. |
|
|
103
|
+
| `workspaceMaxCostPerDay` | Workspace daily budget | `0` | 0–10000, 0 = unlimited; up to 2 decimals | Workspace-wide daily ceiling in the selected currency. |
|
|
104
|
+
| `postAnswer` | Auto-review after each turn | `"off"` | off / card | In advisory mode, runs once after each answer; records only, never inserts. |
|
|
105
|
+
| `advisorTools` | Let the advisor read files | `false` | boolean | Lets it read working-directory files (up to 5, read-only); costs one extra call. |
|
|
106
|
+
| `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. |
|
|
107
|
+
| `timeoutMs` | JSON only: Timeout | `90000` | 5000–600000 | Hard per-consultation deadline. At `startedAt + timeoutMs` the plugin **aborts the request itself** and returns `code: "timeout"` (distinct from `aborted`) without waiting for the stream to end; `/advisor cancel` aborts sooner. A timed-out call is recorded with `costUsd: 0` / zero tokens (the plugin never bills what it did not receive), but the provider may still charge for work done before the abort — see the residual-risk note under [Side effects](#side-effects-limitations--risks). Slow routes do reach it: over 28 real consultations latencies were p50 6.2s / p90 52.5s, and two hit the 90s ceiling — measure your route and raise this if it is slow. |
|
|
108
|
+
| `maxInputChars` | Input limit | `60000` | 4000–400000 | Total transcript budget; excess in the middle is elided, head/tail kept. |
|
|
105
109
|
|
|
106
110
|
**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
111
|
|
|
@@ -123,31 +127,38 @@ Example (placeholder route and model names — use the ones the picker shows you
|
|
|
123
127
|
|
|
124
128
|
**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.
|
|
125
129
|
|
|
126
|
-
**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`).
|
|
130
|
+
**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`). Updates are serialized and written with a unique temp file + rename, so two sessions finishing at the same time cannot lose a count, and the pre-check includes this consultation's estimated cost (same `>=` boundary as the per-session daily budget).
|
|
127
131
|
|
|
128
132
|
**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.
|
|
129
133
|
|
|
130
|
-
**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.
|
|
134
|
+
**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 — and the report now prints the **traceable denominator** (`traceable/total`) next to the adoption count, because most advice items name nothing that can be matched later and "adopted 0" alone would read as "never adopted". 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.
|
|
131
135
|
|
|
132
136
|
**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.
|
|
133
137
|
|
|
134
138
|
## Commands
|
|
135
139
|
|
|
136
|
-
| Command | What it does
|
|
137
|
-
| -------------------------------------- |
|
|
138
|
-
| `/advisor` | Opens the model picker (client half). Routes and models are re-read every time; nothing is cached across openings.
|
|
139
|
-
| `/advisor status` |
|
|
140
|
-
| `/advisor on` | Sets `advisory`. Refuses with a pointer to the picker when no advisor model is configured.
|
|
141
|
-
| `/advisor off` | Sets `off`: no consultation is made, no request is sent.
|
|
142
|
-
| `/advisor shadow` | Sets `shadow`: consult after each completed turn and record it, without feeding it back.
|
|
143
|
-
| `/advisor ask` | Runs one consultation **now** and returns the advice as command output.
|
|
144
|
-
| `/advisor cancel` | Aborts the in-flight consultation — the request is aborted, not merely ignored.
|
|
145
|
-
| `/advisor preview` | **Sends nothing.** Prints exactly what the next consultation would transmit: target route, scope, character/token estimate, omitted host context, tool traffic, redaction hits, allowlist verdict, cross-provider confirmation state, price source and today's workspace usage.
|
|
146
|
-
| `/advisor confirm` | Allows sending the conversation to the current provider when it differs from the main model's provider.
|
|
147
|
-
| `/advisor report all` | Cross-session report from the advice ledger (`<DSH_HOME>/advisor/advice.jsonl`): totals by severity, model and day.
|
|
148
|
-
| `/advisor report` | Per-session advice report: how many were delivered, how many were **adopted** (heuristic: a path / backticked command / anchored ref from the advice shows up in later events), and how many evidence anchors verified.
|
|
149
|
-
| `/advisor doctor` | Self-check: host `llm` service, registered routes, route resolution and context window, supported efforts, mode, session budget, ledger state, last failure. Each line states its conclusion and, where relevant, the next step.
|
|
150
|
-
| `/advisor <provider>/<model> [effort]` | Sets the advisor route directly, with the same validation as the picker (unknown route, missing credentials and unsupported effort are rejected with a readable reason).
|
|
140
|
+
| Command | What it does |
|
|
141
|
+
| -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
142
|
+
| `/advisor` | Opens the model picker (client half). Routes and models are re-read every time; nothing is cached across openings. |
|
|
143
|
+
| `/advisor status` | Multi-line status: the **saved mode** vs the **effective state** (e.g. “Off: no advisor model selected”), chosen route, consultations this session and this turn against the limits, cumulative tokens, the last result, and why the last consultation was skipped. |
|
|
144
|
+
| `/advisor on` | Sets `advisory`. Refuses with a pointer to the picker when no advisor model is configured. |
|
|
145
|
+
| `/advisor off` | Sets `off`: no consultation is made, no request is sent. |
|
|
146
|
+
| `/advisor shadow` | Sets `shadow`: consult after each completed turn and record it, without feeding it back. |
|
|
147
|
+
| `/advisor ask` | Runs one consultation **now** and returns the advice as command output. |
|
|
148
|
+
| `/advisor cancel` | Aborts the in-flight consultation — the request is aborted, not merely ignored. |
|
|
149
|
+
| `/advisor preview` | **Sends nothing.** Prints exactly what the next consultation would transmit: target route, scope, character/token estimate, omitted host context, tool traffic, redaction hits, allowlist verdict, cross-provider confirmation state, price source and today's workspace usage. |
|
|
150
|
+
| `/advisor confirm` | Allows sending the conversation to the current provider when it differs from the main model's provider. |
|
|
151
|
+
| `/advisor report all` | Cross-session report from the advice ledger (`<DSH_HOME>/advisor/advice.jsonl`): totals by severity, model and day. |
|
|
152
|
+
| `/advisor report` | Per-session advice report: how many were delivered, how many were **adopted** (heuristic: a path / backticked command / anchored ref from the advice shows up in later events), how many are **traceable at all** (the denominator — adoption is only meaningful for those), and how many evidence anchors verified. |
|
|
153
|
+
| `/advisor doctor` | Self-check: host `llm` service, registered routes, route resolution and context window, supported efforts, mode, session budget, ledger state, last failure. Each line states its conclusion and, where relevant, the next step. |
|
|
154
|
+
| `/advisor <provider>/<model> [effort]` | Sets the advisor route directly, with the same validation as the picker (unknown route, missing credentials and unsupported effort are rejected with a readable reason). |
|
|
155
|
+
|
|
156
|
+
**What command output looks like.** Every `/advisor …` receipt starts with **the command line the user typed** (e.g. `/advisor status`) on its first line, then the multi-line body — so even the session log (`command/done.data.text`) records which command ran. On screen there are two surfaces:
|
|
157
|
+
|
|
158
|
+
- **Command card**: the plugin registers its own renderer for the `advisor` command (the host's keyed `conversation.chat.commandview` child slot). The card header is the original command line and the body is the complete multi-line output (`white-space: pre-wrap`, no ellipsis, no truncation, selectable text).
|
|
159
|
+
- **Command receipt panel**: after a local submission succeeds the host emits `command/executed`; the plugin puts the same output into a panel at the lower right. It does **not** auto-dismiss (four seconds is not enough to read a full status), and stays until you press ✕ or the next receipt replaces it.
|
|
160
|
+
|
|
161
|
+
Why both: the host Chat folds slash-command nodes into a process group (titled “已完成分析” / “Completed analysis”, which the plugin cannot move the node out of), so the command card needs that group expanded; the receipt panel is visible the moment you press Enter. In a brand-new empty session the host hero state does not render command nodes at all ([runtime §5.2](../../docs/runtime/0.2.2-rc.5.md#52-命令卡片只在非空白会话里渲染2026-11-20-实测)), and only the receipt panel is visible.
|
|
151
162
|
|
|
152
163
|
The `advisor` **tool** is separate from the command: the model calls it, not you. It takes no required arguments; its optional `focus` is one sentence naming the doubt you want settled — not the task itself, because the transcript always is.
|
|
153
164
|
|
|
@@ -156,21 +167,23 @@ The `advisor` **tool** is separate from the command: the model calls it, not you
|
|
|
156
167
|
This is the section to read before turning it on.
|
|
157
168
|
|
|
158
169
|
- **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.
|
|
159
|
-
- **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-read/cache-write tokens, estimated cost, duration, error code).
|
|
170
|
+
- **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, local day key, session id, trigger `tool` / `shadow` / `manual`, provider, model, effort, verdict, severity, input/output/cache-read/cache-write tokens, estimated cost, duration, error code). Each row is appended with a single `O_APPEND` write inside a per-file queue — never a read-everything-then-rewrite — so two turns ending at once cannot overwrite each other. The file rolls over to `usage.jsonl.1` at 2 MiB; totals, today's spend, the session call count and the last hour's call timestamps are restored from its tail (last 2 MiB) on startup. Per-turn counters are intentionally in-process: their lifetime is one turn.
|
|
160
171
|
- **Money needs your prices.** DSH's model metadata has no price field. Set `priceInputPerMTok`, `priceOutputPerMTok`, `priceCacheReadPerMTok` and `priceCacheWritePerMTok` 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, but there are no built-in cache prices. The plugin never guesses prices.
|
|
161
|
-
- **The daily budget
|
|
172
|
+
- **The daily budget is checked before sending, including this consultation's estimated cost.** If the recorded spend plus the estimate would reach `maxCostPerDay`, the consultation is refused with `budget_exhausted` and nothing is sent; the same `>=` boundary and the same pre-check apply to the workspace pool. The estimate can be off (it assumes ~3 characters per token and half of `maxTokens` in output), so a call may still finish slightly above the ceiling — the ledger records the real usage, and the next call is refused.
|
|
162
173
|
- **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.
|
|
163
174
|
- **`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.
|
|
164
|
-
- **Redaction is best-effort.** With `redact: true` (default) the plugin scrubs common token-shaped strings, `Authorization` headers, `KEY=` / `
|
|
175
|
+
- **Redaction is best-effort.** With `redact: true` (default) the plugin scrubs common token-shaped strings, `Authorization` headers, bare `Bearer <token>`, JWTs, `KEY=` / `token:` / `apiKey:`-style assignments (key names are case-insensitive), 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. Key names are matched as case-insensitive substrings, so ordinary text such as `keywords: …` or `monkey: …` can occasionally be over-redacted too — that trade-off is intentional (it errs toward not leaking); the rule is not narrowed further because that would drop `apiKey:`.
|
|
165
176
|
- **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.
|
|
166
177
|
- **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`.
|
|
167
178
|
|
|
168
179
|
## Compatibility
|
|
169
180
|
|
|
170
|
-
| DSH version | Status
|
|
171
|
-
| ----------- |
|
|
172
|
-
| 0.2.2-rc.
|
|
173
|
-
| 0.2.2-rc.
|
|
181
|
+
| DSH version | Status |
|
|
182
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
183
|
+
| 0.2.2-rc.5 | **0.6.2** (2026-11-19): no code change needed for this DSH build. Verified: 142 unit tests + `pnpm probe:runtime` 72/72 + web `pnpm smoke:advisor` **15/15** + desktop read-only regression **19 PASS + 1 SKIP**. The new host surfaces in this release — the `CONTENT_REFUSED` failure code and search-provider default routing — are not used by this plugin ([runtime rc.5](../../docs/runtime/0.2.2-rc.5.md)). |
|
|
184
|
+
| 0.2.2-rc.3 | **0.6.2** (2026-11-14): separates **timeout** from **cancelled**. A consultation that hits `timeoutMs` (default 90 s) now reports `code: "timeout"` and “顾问调用超时(N 秒)” instead of being lumped into `aborted`, matching the failure-code list this README already promised; sub-second durations no longer render as “0 秒”. Found by tracing a real `aborted` tool result: the call/result timestamps were 90,017 ms apart and the ledger recorded `ms:90002` with zero tokens, matching the `timeoutMs: 90000` set explicitly in `<DSH_HOME>/advisor.settings.json`. Measured on 28 real consultations p50 6.2 s / p90 52.5 s with two hitting the ceiling, so the default was left alone and the numbers documented instead. Verified: 142 unit tests (4 new) + `pnpm probe:runtime` 72/72 + web `pnpm smoke:advisor` **14/14** + desktop read-only regression **19 PASS + 1 SKIP**; timeout/cancel/error/happy paths additionally exercised against a stubbed host. The real end-to-end check was done on a live 0.6.2 host with `timeoutMs` temporarily set to 5000: the tool returned “顾问不可用(timeout):顾问调用超时(5 秒)” and the ledger recorded `code:"timeout" / ms:5003 / costUsd:0` (settings restored afterwards). |
|
|
185
|
+
| 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. |
|
|
186
|
+
| 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
187
|
|
|
175
188
|
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
189
|
|
|
@@ -178,24 +191,32 @@ The plugin declares no `engines.dsh` and no `@deepseek-ai/*` peer range: DSH is
|
|
|
178
191
|
|
|
179
192
|
**What it writes**
|
|
180
193
|
|
|
181
|
-
| Path
|
|
182
|
-
|
|
|
183
|
-
| `<DSH_HOME>/advisor.settings.json`
|
|
184
|
-
| `<DSH_HOME>/advisor/usage.jsonl` (+ `.1`)
|
|
194
|
+
| Path | What |
|
|
195
|
+
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
|
|
196
|
+
| `<DSH_HOME>/advisor.settings.json` | Plugin settings; written by `/advisor` and the picker, re-read before every consultation (atomic temp + rename). |
|
|
197
|
+
| `<DSH_HOME>/advisor/usage.jsonl` (+ `.1`) | One line per consultation; append-only (single `O_APPEND` write), rotated at 2 MiB. |
|
|
198
|
+
| `<DSH_HOME>/advisor/decisions.jsonl` (+ `.1`) | One line per **top-level** turn; append-only, rotated at 2 MiB. Outcome back-fills rewrite the file atomically. |
|
|
199
|
+
| `<DSH_HOME>/advisor/advice.jsonl` | One line per delivered advice item; append-only. |
|
|
200
|
+
| `<DSH_HOME>/advisor/budget.json` | Workspace daily pool (`calls`, `costUsd`); atomic temp + rename, serialized read-modify-write. |
|
|
185
201
|
|
|
186
|
-
Nothing else: no workspace files, no session-log records of its own (a consultation shows up as an ordinary tool call and tool result in the transcript), no telemetry.
|
|
202
|
+
Nothing else: no workspace files, no session-log records of its own (a consultation shows up as an ordinary tool call and tool result in the transcript), no telemetry. All files are plain JSONL/JSON under the data root; deleting the `advisor/` directory resets the ledger, budgets and decision history but not the settings file. The data root is meant for a single host process — the write queue is in-process, there is no cross-process file lock.
|
|
187
203
|
|
|
188
204
|
- **The advice is model output.** It can be wrong, vague, or confidently wrong. The plugin validates the _shape_ — a JSON object, a known verdict and severity, length caps, declared evidence anchors — not the content. Weigh it and verify it; the main model still owns the decision.
|
|
189
205
|
- **Command surface is UI-only.** `ctx.commands` is a human command registry: UI-less hosts (headless `-p`, ACP automation) provide no command adapter, so `/advisor` is unavailable there. The tool, the settings file and the RPCs still work; "three-end parity" for the command surface is not achievable by design, not a missing feature.
|
|
190
206
|
- **Semi-public host seams.** `llm.prepareCall`, `llm.resolveModelInfo`, `session.deriveMessages`, `tools.register`, `commands.register` and `session/event` on the host side, and `commandUi.decorate` (the picker) on the client side, are not a stable public API. A DSH upgrade can silently disable the tool, the picker or the command. Run `pnpm probe:runtime` after every upgrade; installation failures are logged rather than thrown, so check `/advisor doctor` and the host logs.
|
|
191
207
|
- **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.
|
|
192
208
|
- **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.
|
|
209
|
+
- **The hard timeout is enforced by this plugin, not by the provider.** At `timeoutMs` the plugin aborts its own request signal and returns `timeout` immediately (it does not wait for the stream to close, and does not record cost/tokens for that call). Residual risk: the host/provider may keep the HTTP request alive server-side for a while, and the provider may still bill for tokens generated before the abort was processed. If you need a hard spend cap, keep `maxCostPerDay` / `workspaceMaxCostPerDay` set as well — those are checked in the ledger, which does not see an aborted call's usage.
|
|
193
210
|
- **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.
|
|
194
211
|
- **The settings live in their own Settings → Advisor section**, with a three-row summary on top and a collapsed “More settings” fold. Keys marked JSON-only still need the settings file, and the `/advisor` picker remains available.
|
|
195
212
|
- **Partially enforced knobs.** `sessionCap` caps delivered advice per session (blockers exempt); `dedupe` / `immuneTurns` only matter on the shadow path — see [Configure](#configure).
|
|
196
213
|
- **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.
|
|
197
214
|
- **`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.
|
|
198
|
-
- **Subagent sessions** are skipped by the automatic shadow review; only top-level turns are reviewed.
|
|
215
|
+
- **Subagent sessions** are skipped by the automatic shadow review; only top-level turns are reviewed. The same filter applies to the decision log (`decisions.jsonl`), so consult/acceptance rates from `pnpm advisor:review` are **main-session** rates — consultations made inside fork/spawn subagents are not rows in that file.
|
|
216
|
+
- **The command card still sits inside a host-collapsed group.** The host Chat folds slash-command nodes into a collapsible process group (titled “Completed analysis”), which is host business grouping with no plugin extension point to move the node out. What the plugin can do instead: (a) put the original command line on the first line of the receipt, (b) render the complete multi-line output in its own command card, and (c) show a command receipt panel at the lower right so the output is visible as soon as you press Enter. In a brand-new empty session the host hero state renders no command node, so only the receipt panel appears.
|
|
217
|
+
- **The model may still mention the advisor's switch state on its own.** Tool results no longer carry internal switch state (“off / unconfigured / shadow”) — they return a neutral skip plus an explicit instruction not to report that state — but the final wording is model behavior and cannot be hard-guaranteed by a plugin.
|
|
218
|
+
- **The neutral skip has a cost (U1-11 trade-off).** Because the model only sees “no advice was given this time”, it can no longer explain _why_ (or point you at `/advisor on`), and since the tool card renders the same `content` the model reads, the card no longer shows the real skip reason either. The real reason is still there: `/advisor status` and `/advisor doctor` report the saved mode, the effective state and the reason. This is the accepted trade-off between hiding internal state from the model and keeping the model able to explain itself.
|
|
219
|
+
- **The slash-menu command description follows the system language.** The host has no locale service and does not translate `commands.register()` descriptions; the plugin reads its own `locale/<lang>.json` `host` section at activation and picks `config.language` (`zh`/`en`) or `LANG`/`LC_ALL`, falling back to English. Chinese systems get the Chinese description in the `/` menu; the settings card and command output remain Chinese (existing host-half copy).
|
|
199
220
|
|
|
200
221
|
## Testing & verification
|
|
201
222
|
|
|
@@ -208,8 +229,9 @@ pnpm smoke:agent-tool # repo-wide real-model tool smoke (needs credential
|
|
|
208
229
|
```
|
|
209
230
|
|
|
210
231
|
- `pnpm verify` is the release gate and must pass before a PR.
|
|
211
|
-
-
|
|
212
|
-
- `pnpm smoke:advisor
|
|
232
|
+
- The plugin currently has **232 unit tests** (`node --test`), including the money/budget layer that used to have none: atomic append for the usage/advice/decision logs, serialized workspace-pool updates, local-day accounting across restarts, session/hour counter restore, hard-timeout semantics, decision-outcome coverage, command-receipt formatting (command line on the first line, multi-line output kept intact, effective-state wording), host-half locale loading, and locale dictionary parity (including an assertion that the embedded dictionary and `LOCALE_EXTRA` never define the same key).
|
|
233
|
+
- `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 (the host renders command cards collapsed); a new assertion checks that every advisor receipt starts with the original command line (`/advisor …`), which only the log and the plugin's own card can prove because the host's generic card shows just the command name.
|
|
234
|
+
- `pnpm smoke:advisor-desktop` is the desktop (Electron) read-only regression, required because the plugin has a client half. This round adds six assertions: the `/advisor status|doctor` receipt starts with the original command line, the status receipt carries an “生效 / Effective” line, the plugin command card's DOM shows the command line and the complete multi-line output, and the lower-right receipt (`[data-advisor-receipt]`) appears right after submitting a command. **This round did not re-run the desktop regression** (batch policy: update the assertions only, never touch the live desktop app); the authoritative PASS/SKIP counts come from the lead's run. 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`.
|
|
213
235
|
- `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.
|
|
214
236
|
|
|
215
237
|
Manual end-to-end check, the only way to confirm a real advisor call:
|