dsh-think-effort 0.2.1 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 — 2026-11-24
4
+
5
+ - **可视化设置页**:插件 → 自动思考档位 → 配置。覆盖全部字段(启用、Auto 落点、模型默认档、子代理强度、Auto 适用范围、廉价调用、能力声明、高级诊断),保存后即时生效。
6
+ - **子代理 effort**:新增 `subagentLevel`(`inherit` / `auto` / 固定档)。`inherit` 保持 DSH 原生继承;固定档覆盖子代理自身或从父代理继承的选择;廉价调用的降档仍然优先。`reasoning_effort_status` 同步报告子代理解析结果。
7
+ - **实时配置**:`export const Config` 声明全部字段为 `volatile`;设置写入经 `loader/volatile-update` 热更新策略,无需重启、无需手改 `cordis.patch.yml`。新增运行时依赖 `@deepseek-ai/schemastery`。
8
+ - **浏览器半边**:新增 `client.js`(`plugins.row.config` 键 `dsh-think-effort#think-effort`),中英双语文案,跟随 DSH 主题变量。
9
+ - 文档:明确**新安装免重启**(DSH base bundle 的 HMR 直接激活新 bundle);升级已安装版本才需要重启 Host。
10
+ - 测试:26 项(新增子代理策略、volatile 配置热更新、子代理会话识别)。
11
+ - CI:提交 `package-lock.json`(从 npm registry 解析,不含本机路径),`test` 与 `release` 的 verify 任务先 `npm ci` 再跑语法检查与离线测试。此前的构建失败是 `index.js` 新增运行时依赖后 CI 未安装依赖(`ERR_MODULE_NOT_FOUND: @deepseek-ai/schemastery`)。
12
+
3
13
  ## 0.2.1 — 2026-11-24
4
14
 
5
15
  - `package.json` 增加有界宿主声明 `engines.dsh: ">=0.2.0-rc.1 <0.3.0-0"`,插件市场与插件管理器可据此判断兼容性。
package/README.md CHANGED
@@ -50,15 +50,32 @@ DSH Desktop → **插件市场**搜索 `dsh-think-effort` 安装;或 **插件
50
50
 
51
51
  ### 启用与验证
52
52
 
53
- 1. 安装后打开 **设置 → 插件**,确认 `dsh-think-effort` 已启用;桌面端需**完全退出并重开** DSH,Web 端需重启 `dsh web` 并硬刷新页面。
53
+ 1. **新安装不需要重启**:DSH 的 base bundle 默认启用 HMR,新 bundle 安装后直接激活(安装结果显示 `application: applied`)。打开 **插件** 页能看到「自动思考档位」即已生效;若页面是旧快照,刷新一次即可。
54
54
  2. 输入框右侧的模型 chip 应从 `deepseek-v4.1-flash-1017` 变成 `deepseek-v4.1-flash-1017 High`(或你模型的默认档)。
55
55
  3. 点开 chip →「推理等级」,应能看到 `Auto / Low / High / Max`。
56
- 4. 想核对具体模型,可让 Agent 调用只读工具 `reasoning_effort_status`,它会报告该模型声明的档位、默认档、`Auto` 的解析结果与廉价调用档位,不发送任何模型请求。
56
+ 4. 想核对具体模型,可让 Agent 调用只读工具 `reasoning_effort_status`,它会报告该模型声明的档位、默认档、`Auto` 与子代理的解析结果、廉价调用档位,不发送任何模型请求。
57
+
58
+ > **升级已安装版本**是另一回事:DSH 需要重启 Host 才能载入新的 JavaScript 模块代际(安装结果会报 `restart-required`)。这是 DSH 的进程模型,不是本插件的行为。
59
+
60
+ ### 可视化设置
61
+
62
+ **插件 → 自动思考档位 → 行右侧「配置」**(桌面/Web 相同):
63
+
64
+ ![设置页](docs/settings.png)
65
+
66
+ - **档位分配**:普通步骤的 Auto 落点、模型默认档、**子代理推理强度**、哪些模型显示 Auto;
67
+ - **廉价调用**:总开关、档位、purpose 清单;
68
+ - **能力声明**:是否写入 `reasoningEfforts`、声明哪些档位、DeepSeek host/模型匹配规则;
69
+ - **高级**:stderr 诊断。
70
+
71
+ 所有字段都是 `volatile` 配置:点「保存」后**立即生效**,不需要重启,也不用改 `cordis.patch.yml`。
57
72
 
58
73
  ### 本插件的第一次使用
59
74
 
60
75
  装上后不需要额外配置:`Auto` 与档位由插件自动声明。选中 `Auto` 即按默认档运行;选 `Low / High / Max` 即固定该档;不选(原生「提供方默认」)在普通步骤上与 `Auto` 等效。
61
76
 
77
+ 子代理默认**不干预**,保持 DSH 原生行为(继承父代理的模型与档位)。想让子代理固定用某一档,在设置页把「子代理 · 推理强度」改成 `Low / High / Max`,或选 `Auto` 跟随本插件的默认解析;廉价调用的降档仍然优先。
78
+
62
79
  ## 为什么需要它
63
80
 
64
81
  手工在 `llm-pi-ai` 里声明的 DeepSeek 网关模型(例如走自建网关的 `deepseek-v4.1-flash-1017`)在 pi-ai 的已安装目录里查不到,profile 里也没写 `reasoningEfforts`,于是:
@@ -99,6 +116,7 @@ DSH Desktop → **插件市场**搜索 `dsh-think-effort` 安装;或 **插件
99
116
  auxPurposes: [session-title, compaction, auto-review]
100
117
  auxLevel: low
101
118
  autoScope: all
119
+ subagentLevel: inherit
102
120
  trace: false
103
121
  ```
104
122
 
@@ -116,6 +134,7 @@ DSH Desktop → **插件市场**搜索 `dsh-think-effort` 安装;或 **插件
116
134
  | `auxPurposes` | `session-title, compaction, auto-review` | 视为廉价调用的 `purpose` |
117
135
  | `auxLevel` | `low` | 廉价调用用的档位 |
118
136
  | `autoScope` | `all` | `all` / `declared` / `off` |
137
+ | `subagentLevel` | `inherit` | 子代理档位:`inherit` / `auto` / `low`…`max`;固定档会覆盖子代理自身或继承的选择 |
119
138
  | `trace` | `false` | 把决策写到 stderr(排查用) |
120
139
 
121
140
  ## 兼容性
@@ -174,21 +193,37 @@ Copy the `.tgz` (or an unpacked directory with `package.json` at its root) to th
174
193
 
175
194
  ### Enable and verify
176
195
 
177
- 1. Settings → Plugins: confirm `dsh-think-effort` is enabled. Desktop needs a full quit and relaunch; Web needs `dsh web` restarted and a hard refresh.
196
+ 1. A **fresh install needs no restart**: the base bundle enables HMR, so a new bundle activates immediately (`application: applied`). The "Automatic thinking depth" card appears under **Plugins**; refresh the page if the list is stale.
178
197
  2. The model chip next to the composer reads `<model> High` (the model's default depth) instead of the bare model id.
179
198
  3. Open the chip → "Reasoning level": `Auto / Low / High / Max` are listed.
180
- 4. For a specific model, ask the agent to call the read-only `reasoning_effort_status` tool: it reports the declared depths, the default, what `Auto` resolves to and the cheap-call depth, without sending a model request.
199
+ 4. For a specific model, ask the agent to call the read-only `reasoning_effort_status` tool: it reports the declared depths, the default, what `Auto` and subagents resolve to, and the cheap-call depth, without sending a model request.
200
+
201
+ > **Upgrading an installed version** is different: DSH must restart the Host to load a fresh JavaScript module generation (`restart-required`). That is DSH's process model, not this plugin's behavior.
202
+
203
+ ### Visual settings
204
+
205
+ **Plugins → Automatic thinking depth → Configure** on the row (Desktop and Web):
206
+
207
+ ![Settings page](docs/settings.png)
208
+
209
+ - **Depth assignment**: the ordinary-step Auto target, the model default, the **subagent effort**, and which models offer Auto;
210
+ - **Cheap calls**: switch, level, and purpose list;
211
+ - **Capability declaration**: whether to write `reasoningEfforts`, which depths to declare, and the DeepSeek host/model rules;
212
+ - **Advanced**: stderr diagnostics.
213
+
214
+ Every field is `volatile`: **Save** applies immediately, without a restart and without hand-editing `cordis.patch.yml`.
181
215
 
182
216
  ### Features
183
217
 
184
218
  - Declares `reasoningEfforts` for DeepSeek models that carry none (gateway aliases included), so the selector finally has levels.
185
219
  - `Auto` resolves to the declared default depth on every request; an explicit pick passes through untouched.
220
+ - **Subagent effort**: `inherit` keeps DSH's native behavior; `auto` follows this plugin's default; a fixed depth overrides the child's own or inherited pick.
186
221
  - Cheap host-owned calls (`session-title`, `compaction`, `auto-review`) drop to `low` only when the model declares it, regardless of the session's own choice.
187
222
  - Idempotent: a second boot writes nothing; unload restores the original adapter registrations and retires a durable `auto`.
188
223
 
189
224
  ### Configuration
190
225
 
191
- Override the `think-effort` row in the profile's `cordis.patch.yml`; the fields are listed in the Chinese section above. `declareCapability`, `efforts`, `defaultEffort`, `auxPurposes`, `auxLevel`, `autoScope` and `trace` are the ones most often changed.
226
+ Override the `think-effort` row in the profile's `cordis.patch.yml`; the fields are listed in the Chinese section above. `declareCapability`, `efforts`, `defaultEffort`, `auxPurposes`, `auxLevel`, `autoScope`, `subagentLevel` and `trace` are the ones most often changed. Most users should use the visual settings page instead of editing this file.
192
227
 
193
228
  ### Compatibility
194
229
 
package/client.js ADDED
@@ -0,0 +1,655 @@
1
+ /**
2
+ * Browser half of `dsh-think-effort`: the visual settings page for one row.
3
+ *
4
+ * The page registers into the Plugins page's `plugins.row.config` slot, keyed
5
+ * by `<package name>#<row id>`, so the bundle's row gains a Configure control.
6
+ * The page owner supplies `form`: the accepted Host values of this row plus one
7
+ * revision-fenced `mutate`. Every field is volatile, so saving writes the
8
+ * profile patch and the running policy follows without a restart.
9
+ *
10
+ * The layout follows the desktop reference implementation: purpose rows
11
+ * (ordinary step, subagent, cheap calls) over a shared effort vocabulary, with
12
+ * capability declaration in an advanced block. It is plain hyperscript with
13
+ * theme tokens; nothing here imports another plugin's runtime.
14
+ */
15
+
16
+ window.__ModuleLoader__.load({
17
+ id: 'dsh-think-effort',
18
+ factory(require) {
19
+ const React = require('react');
20
+ const h = React.createElement;
21
+
22
+ const NS = 'think-effort';
23
+ const ROW_KEY = 'dsh-think-effort#think-effort';
24
+ const EFFORT_ORDER = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
25
+ const KNOWN_PURPOSES = ['session-title', 'compaction', 'auto-review'];
26
+
27
+ const zh = {
28
+ intro: '按“用途”分配推理强度:普通步骤、子代理、Harness 自己的廉价调用。改动即时生效,不需要重启。',
29
+ loading: '正在读取插件配置…',
30
+ unavailable: '这个部署没有提供可编辑的插件配置(设置服务未挂载,或该行没有可实时编辑的字段)。',
31
+ noForm: '这里没有拿到这个插件的配置表单;请在「插件」页打开本插件行的「配置」。',
32
+ save: '保存',
33
+ saving: '保存中…',
34
+ saved: '已保存,立即生效。',
35
+ reset: '恢复默认',
36
+ resetConfirm: '把本插件所有被覆盖的字段恢复为默认值?',
37
+ saveFailed: '保存被拒绝:可能被更高层配置覆盖,或值未通过校验。',
38
+ resetFailed: '恢复默认被拒绝。',
39
+ noChanges: '没有需要保存的改动。',
40
+ unsaved: '有未保存的改动。',
41
+ invalidPattern: '模型 ID 正则需要是合法的 JavaScript 正则。',
42
+ invalidEfforts: '至少保留一个档位。',
43
+ effortPicker: '自动思考档位',
44
+ sectionPurpose: '档位分配',
45
+ sectionPurposeHint: '每一类请求各自决定用什么强度;显式选择的具体档位不会被“普通步骤”覆盖。',
46
+ autoRow: '普通步骤 · Auto 落到',
47
+ autoRowHint: '模型选择器里的 Auto 在普通对话步骤上使用的档位。',
48
+ defaultRow: '模型默认档',
49
+ defaultRowHint: '路由声明的默认档;Auto 选“跟随默认档”时使用它,也是廉价调用降档的参照。',
50
+ autoScopeRow: '哪些模型显示 Auto',
51
+ autoScopeHint: 'all:所有模型;declared:只在本插件声明过能力的模型;off:完全不注入 Auto。',
52
+ subagentRow: '子代理 · 推理强度',
53
+ subagentRowHint: 'DSH 的子代理默认继承父代理的模型与档位。这里可以给子代理统一指定强度;“不干预”保持原生行为。恢复默认值也是“不干预”。',
54
+ sectionAux: '廉价调用',
55
+ auxSwitch: '把 Harness 自己的廉价调用降到低档',
56
+ auxSwitchHint: '会话标题、压缩、自动复核这类有界的小请求,不应该继承会话的深度。',
57
+ auxLevelRow: '廉价调用使用的档位',
58
+ auxPurposesRow: '视为廉价调用的 purpose',
59
+ auxPurposesHint: '按 LLM 请求的 purpose 匹配;勾选常见项,或在“其他”里补充。',
60
+ auxOther: '其他(逗号分隔)',
61
+ sectionCapability: '能力声明',
62
+ capabilitySwitch: '为没有推理元数据的 DeepSeek 模型声明档位',
63
+ capabilitySwitchHint: '写入 llm-pi-ai 的 reasoningEfforts 与路由默认档;已有声明绝不覆盖。',
64
+ effortsRow: '声明的档位(按强度排序)',
65
+ effortsHint: 'DeepSeek V4 原生为 low / high / max;取消勾选可移除不支持的档位。',
66
+ hostsRow: 'DeepSeek 端点后缀',
67
+ hostsHint: '逗号分隔;默认 deepseek.com。只做 host 后缀匹配,子域名也算。',
68
+ patternRow: '模型 ID 正则',
69
+ patternHint: '网关别名用,例如 ^deepseek;不区分大小写。',
70
+ declareModelsRow: '额外声明',
71
+ declareModelsHint: '每行一个 provider/model,或一个模型 ID 正则;用于没有匹配到上面两条规则的网关。',
72
+ advanced: '高级',
73
+ traceRow: '把每次决策写到 stderr',
74
+ traceHint: '排查用;默认关闭。',
75
+ enabledRow: '启用插件',
76
+ enabledHint: '总开关;关闭后不注入 Auto、不改写任何请求。',
77
+ summary: 'Auto → {auto} · 子代理 → {sub} · 廉价调用 → {aux}',
78
+ inherit: '不干预(原生行为)',
79
+ auto: 'Auto(按默认档)',
80
+ followDefault: '跟随默认档',
81
+ on: '开',
82
+ off: '关',
83
+ all: '所有模型',
84
+ declared: '仅声明过的模型',
85
+ disabled: '已关闭',
86
+ custom: '自定义',
87
+ otherLevel: '其他档位',
88
+ };
89
+
90
+ const en = {
91
+ intro: 'Assign thinking depth by purpose: ordinary steps, subagents, and the Harness\'s own cheap calls. Changes apply immediately, without a restart.',
92
+ loading: 'Reading plugin configuration…',
93
+ unavailable: 'This deployment exposes no editable plugin configuration (the settings service is not mounted, or this row has no live fields).',
94
+ noForm: 'The configuration form for this row is not available here. Open the plugin row\'s Configure control on the Plugins page.',
95
+ save: 'Save',
96
+ saving: 'Saving…',
97
+ saved: 'Saved. It applies immediately.',
98
+ reset: 'Restore defaults',
99
+ resetConfirm: 'Restore every overridden field of this plugin to its default?',
100
+ saveFailed: 'The save was refused: a higher configuration layer may override this row, or a value failed validation.',
101
+ resetFailed: 'Restoring defaults was refused.',
102
+ noChanges: 'Nothing to save.',
103
+ unsaved: 'Unsaved changes.',
104
+ invalidPattern: 'The model-id pattern must be a valid JavaScript regular expression.',
105
+ invalidEfforts: 'Keep at least one depth.',
106
+ effortPicker: 'Automatic thinking depth',
107
+ sectionPurpose: 'Depth assignment',
108
+ sectionPurposeHint: 'Each purpose chooses its own depth; an explicit pick is never overridden by the ordinary-step rule.',
109
+ autoRow: 'Ordinary step · Auto resolves to',
110
+ autoRowHint: 'The depth the model selector\'s Auto uses for ordinary conversation steps.',
111
+ defaultRow: 'Model default depth',
112
+ defaultRowHint: 'The route\'s declared default. Used when Auto follows the default, and as the reference for cheap-call downgrades.',
113
+ autoScopeRow: 'Which models offer Auto',
114
+ autoScopeHint: 'all: every model; declared: only models this plugin declared; off: do not inject Auto at all.',
115
+ subagentRow: 'Subagent · reasoning effort',
116
+ subagentRowHint: 'DSH subagents inherit the parent model and depth by default. Pin a depth for them here; "Do not intervene" keeps native behavior, and so does restoring this field.',
117
+ sectionAux: 'Cheap calls',
118
+ auxSwitch: 'Drop the Harness\'s own cheap calls to a low depth',
119
+ auxSwitchHint: 'Session titles, compaction, and auto-review are bounded auxiliary requests and should not inherit the conversation\'s depth.',
120
+ auxLevelRow: 'Depth used by cheap calls',
121
+ auxPurposesRow: 'Purposes treated as cheap calls',
122
+ auxPurposesHint: 'Matched against the LLM request purpose. Tick the common ones, or add more under "Other".',
123
+ auxOther: 'Other (comma separated)',
124
+ sectionCapability: 'Capability declaration',
125
+ capabilitySwitch: 'Declare depths for DeepSeek models that carry no reasoning metadata',
126
+ capabilitySwitchHint: 'Writes reasoningEfforts and the route default into llm-pi-ai. An existing declaration is never overwritten.',
127
+ effortsRow: 'Declared depths (escalation order)',
128
+ effortsHint: 'DeepSeek V4 declares low / high / max; untick a depth the endpoint does not support.',
129
+ hostsRow: 'DeepSeek endpoint suffixes',
130
+ hostsHint: 'Comma separated; deepseek.com by default. Matching is by host suffix, so subdomains count.',
131
+ patternRow: 'Model-id pattern',
132
+ patternHint: 'For gateway aliases, such as ^deepseek; case insensitive.',
133
+ declareModelsRow: 'Extra declarations',
134
+ declareModelsHint: 'One provider/model per line, or a model-id regular expression, for gateways the rules above miss.',
135
+ advanced: 'Advanced',
136
+ traceRow: 'Write every decision to stderr',
137
+ traceHint: 'Diagnostics only; off by default.',
138
+ enabledRow: 'Enable this plugin',
139
+ enabledHint: 'Master switch; when off, no Auto is injected and no request is rewritten.',
140
+ summary: 'Auto → {auto} · Subagent → {sub} · Cheap calls → {aux}',
141
+ inherit: 'Do not intervene (native)',
142
+ auto: 'Auto (default depth)',
143
+ followDefault: 'Follow the model default',
144
+ on: 'On',
145
+ off: 'Off',
146
+ all: 'All models',
147
+ declared: 'Only declared models',
148
+ disabled: 'Disabled',
149
+ custom: 'Custom',
150
+ otherLevel: 'Other depth',
151
+ };
152
+
153
+ const LEVEL_LABELS = {
154
+ off: 'Off', minimal: 'Minimal', low: 'Low', medium: 'Medium',
155
+ high: 'High', xhigh: 'Extra high', max: 'Max',
156
+ };
157
+
158
+ /** All fields the page edits, in display order. */
159
+ const FIELDS = [
160
+ 'enabled', 'declareCapability', 'deepseekHosts', 'deepseekModelPattern',
161
+ 'declareModels', 'efforts', 'defaultEffort', 'autoLevel', 'autoScope',
162
+ 'auxDowngrade', 'auxPurposes', 'auxLevel', 'subagentLevel', 'trace',
163
+ ];
164
+
165
+ function equal(a, b) {
166
+ return JSON.stringify(a) === JSON.stringify(b);
167
+ }
168
+
169
+ function asArray(value) {
170
+ return Array.isArray(value) ? value : [];
171
+ }
172
+
173
+ function splitList(text) {
174
+ return String(text ?? '')
175
+ .split(/[\n,,;;]+/)
176
+ .map((item) => item.trim())
177
+ .filter((item, index, all) => item !== '' && all.indexOf(item) === index);
178
+ }
179
+
180
+ /** Whether a string is a usable regular expression for model-id matching. */
181
+ function validPattern(text) {
182
+ try {
183
+ new RegExp(String(text ?? ''));
184
+ return true;
185
+ } catch {
186
+ return false;
187
+ }
188
+ }
189
+
190
+ /** Depth vocabulary of a draft, escalation-ordered, without auto/off. */
191
+ function depthLevels(draft) {
192
+ const declared = asArray(draft?.efforts).filter((id) => typeof id === 'string' && id !== 'auto' && id !== 'off');
193
+ const extra = declared.filter((id) => !EFFORT_ORDER.includes(id));
194
+ return [...EFFORT_ORDER.filter((id) => declared.includes(id)), ...extra];
195
+ }
196
+
197
+ /** Depth Auto resolves to for the draft. */
198
+ function autoDepth(draft) {
199
+ if (!draft || draft.autoLevel === 'model-default' || draft.autoLevel === undefined) return draft?.defaultEffort;
200
+ return draft.autoLevel;
201
+ }
202
+
203
+ function levelLabel(level) {
204
+ if (level === 'inherit') return null;
205
+ return LEVEL_LABELS[level] ?? level;
206
+ }
207
+
208
+ function styleText() {
209
+ return `
210
+ .dte-page { display: flex; flex-direction: column; gap: 18px; color: var(--dsw-alias-label-primary); font-size: 13px; line-height: 1.55; }
211
+ .dte-intro { margin: 0; color: var(--dsw-alias-label-secondary); max-width: 72ch; }
212
+ .dte-summary { display: flex; flex-wrap: wrap; gap: 8px; }
213
+ .dte-pill { border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--dsw-alias-label-secondary); }
214
+ .dte-pill b { color: var(--dsw-alias-label-primary); font-weight: 600; }
215
+ .dte-section { border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1); border-radius: 10px; overflow: hidden; }
216
+ .dte-section-head { padding: 12px 14px; border-bottom: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); }
217
+ .dte-section-title { margin: 0; font-size: 13px; font-weight: 600; }
218
+ .dte-section-hint { margin: 3px 0 0; font-size: 12px; color: var(--dsw-alias-label-secondary); }
219
+ .dte-row { display: grid; grid-template-columns: minmax(160px, 220px) minmax(0, 1fr); gap: 12px 18px; padding: 12px 14px; border-top: 1px solid var(--dsw-alias-border-l1); align-items: start; }
220
+ .dte-row:first-child { border-top: 0; }
221
+ .dte-row-label { padding-top: 5px; font-weight: 500; }
222
+ .dte-row-hint { grid-column: 2; margin: -4px 0 0; font-size: 12px; color: var(--dsw-alias-label-secondary); }
223
+ .dte-control { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
224
+ .dte-inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
225
+ .dte-input, .dte-select, .dte-textarea {
226
+ box-sizing: border-box; width: 100%; max-width: 520px; padding: 6px 9px;
227
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 7px;
228
+ background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary);
229
+ font: inherit; outline: none;
230
+ }
231
+ .dte-input:focus, .dte-select:focus, .dte-textarea:focus { border-color: var(--dsw-alias-brand-primary); }
232
+ .dte-textarea { min-height: 68px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
233
+ .dte-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px; padding: 3px 10px; cursor: pointer; user-select: none; background: var(--dsw-alias-bg-base); }
234
+ .dte-chip-on { border-color: var(--dsw-alias-brand-primary); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 12%, transparent); }
235
+ .dte-chip input { margin: 0; }
236
+ .dte-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
237
+ .dte-switch input { width: 15px; height: 15px; margin: 0; accent-color: var(--dsw-alias-brand-primary); }
238
+ .dte-footer { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; position: sticky; bottom: 0; margin-top: 2px; padding: 12px 0 4px; border-top: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-base); }
239
+ .dte-btn { border: 1px solid var(--dsw-alias-border-l1); border-radius: 8px; padding: 6px 16px; font: inherit; cursor: pointer; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); }
240
+ .dte-btn:disabled { opacity: .55; cursor: default; }
241
+ .dte-btn-primary { border-color: var(--dsw-alias-brand-primary); background: var(--dsw-alias-brand-primary); color: #fff; }
242
+ .dte-status { font-size: 12px; }
243
+ .dte-status-ok { color: var(--dsw-alias-state-success-primary); }
244
+ .dte-status-error { color: var(--dsw-alias-state-error-primary); }
245
+ .dte-status-muted { color: var(--dsw-alias-label-secondary); }
246
+ .dte-details { border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-layer-1); }
247
+ .dte-details > summary { cursor: pointer; padding: 11px 14px; font-weight: 600; }
248
+ .dte-details[open] > summary { border-bottom: 1px solid var(--dsw-alias-border-l1); }
249
+ .dte-details .dte-row:first-of-type { border-top: 0; }
250
+ @media (max-width: 720px) {
251
+ .dte-row { grid-template-columns: minmax(0, 1fr); gap: 6px; }
252
+ .dte-row-hint { grid-column: 1; }
253
+ .dte-row-label { padding-top: 0; }
254
+ }
255
+ `;
256
+ }
257
+
258
+ function Section({ title, hint, children }) {
259
+ return h('section', { className: 'dte-section' },
260
+ h('div', { className: 'dte-section-head' },
261
+ h('h3', { className: 'dte-section-title' }, title),
262
+ hint ? h('p', { className: 'dte-section-hint' }, hint) : null),
263
+ children);
264
+ }
265
+
266
+ function Row({ key, label, hint, children }) {
267
+ return h('div', { key, className: 'dte-row' },
268
+ h('div', { className: 'dte-row-label' }, label),
269
+ h('div', { className: 'dte-control' }, children),
270
+ hint ? h('p', { className: 'dte-row-hint' }, hint) : null);
271
+ }
272
+
273
+ function Switch({ checked, onChange, label, disabled }) {
274
+ return h('label', { className: 'dte-switch' },
275
+ h('input', { type: 'checkbox', checked: checked === true, disabled, onChange: (event) => onChange(event.target.checked) }),
276
+ h('span', null, label));
277
+ }
278
+
279
+ function levelOptions(draft, includeAuto) {
280
+ const levels = depthLevels(draft);
281
+ return levels.map((id) => ({ value: id, label: LEVEL_LABELS[id] ?? id }));
282
+ }
283
+
284
+ function Select({ value, options, onChange, disabled }) {
285
+ const known = options.some((option) => option.value === value);
286
+ return h('select', { className: 'dte-select', value: value ?? '', disabled, onChange: (event) => onChange(event.target.value) },
287
+ !known && value !== undefined && value !== '' ? h('option', { value, disabled: true }, String(value)) : null,
288
+ options.map((option) => h('option', { key: option.value, value: option.value, disabled: option.disabled }, option.label)));
289
+ }
290
+
291
+ function Page({ form, t }) {
292
+ const state = form?.state;
293
+ const value = state?.value ?? {};
294
+ const [draft, setDraft] = React.useState(null);
295
+ const [dirty, setDirty] = React.useState(false);
296
+ const [busy, setBusy] = React.useState(false);
297
+ const [message, setMessage] = React.useState(null);
298
+ const serialized = JSON.stringify(value);
299
+
300
+ React.useEffect(() => {
301
+ if (dirty) return;
302
+ setDraft(JSON.parse(serialized));
303
+ }, [serialized, dirty]);
304
+
305
+ const current = draft ?? value;
306
+ const levels = depthLevels(current);
307
+ const levelChoices = levels.length > 0 ? levels : ['low', 'high', 'max'];
308
+ const auto = autoDepth(current) ?? '(adapter default)';
309
+ const sub = current.subagentLevel === 'inherit' || current.subagentLevel === undefined
310
+ ? t('inherit')
311
+ : current.subagentLevel === 'auto' ? t('auto') : levelLabel(current.subagentLevel);
312
+ const aux = current.auxDowngrade === false ? t('off') : (levelLabel(current.auxLevel) ?? current.auxLevel);
313
+
314
+ if (form === undefined) {
315
+ return h('div', { className: 'dte-page' }, h('style', null, styleText()),
316
+ h('p', { className: 'dte-intro' }, t('noForm')));
317
+ }
318
+ if (state?.status === 'loading') {
319
+ return h('div', { className: 'dte-page' }, h('style', null, styleText()),
320
+ h('p', { className: 'dte-intro' }, t('loading')));
321
+ }
322
+ if (state?.status === 'unavailable') {
323
+ return h('div', { className: 'dte-page' }, h('style', null, styleText()),
324
+ h('p', { className: 'dte-intro' }, t('unavailable')));
325
+ }
326
+
327
+ const patch = (field, next) => {
328
+ setDirty(true);
329
+ setMessage(null);
330
+ setDraft({ ...(draft ?? value), [field]: next });
331
+ };
332
+
333
+ const validate = () => {
334
+ if (asArray(current.efforts).length === 0) return t('invalidEfforts');
335
+ if (!validPattern(current.deepseekModelPattern)) return t('invalidPattern');
336
+ for (const entry of asArray(current.declareModels)) {
337
+ if (entry.includes('/')) continue;
338
+ if (!validPattern(entry)) return t('invalidPattern');
339
+ }
340
+ return null;
341
+ };
342
+
343
+ const save = async () => {
344
+ const invalid = validate();
345
+ if (invalid !== null) {
346
+ setMessage({ kind: 'error', text: invalid });
347
+ return;
348
+ }
349
+ const ops = [];
350
+ for (const field of FIELDS) {
351
+ if (!equal(current[field], value[field])) {
352
+ ops.push({ op: 'set', path: [field], value: current[field] });
353
+ }
354
+ }
355
+ if (ops.length === 0) {
356
+ setMessage({ kind: 'muted', text: t('noChanges') });
357
+ return;
358
+ }
359
+ setBusy(true);
360
+ try {
361
+ const accepted = await form.mutate(ops, state.revision);
362
+ if (accepted) {
363
+ setDirty(false);
364
+ setDraft(null);
365
+ setMessage({ kind: 'ok', text: t('saved') });
366
+ } else {
367
+ setMessage({ kind: 'error', text: t('saveFailed') });
368
+ }
369
+ } catch (error) {
370
+ setMessage({ kind: 'error', text: `${t('saveFailed')} ${error instanceof Error ? error.message : String(error)}` });
371
+ } finally {
372
+ setBusy(false);
373
+ }
374
+ };
375
+
376
+ const reset = async () => {
377
+ if (typeof window !== 'undefined' && typeof window.confirm === 'function' && !window.confirm(t('resetConfirm'))) return;
378
+ const user = state.user !== null && typeof state.user === 'object' ? state.user : {};
379
+ const ops = FIELDS.filter((field) => Object.prototype.hasOwnProperty.call(user, field))
380
+ .map((field) => ({ op: 'unset', path: [field] }));
381
+ if (ops.length === 0) {
382
+ setMessage({ kind: 'muted', text: t('noChanges') });
383
+ return;
384
+ }
385
+ setBusy(true);
386
+ try {
387
+ const accepted = await form.mutate(ops, state.revision);
388
+ if (accepted) {
389
+ setDirty(false);
390
+ setDraft(null);
391
+ setMessage({ kind: 'ok', text: t('saved') });
392
+ } else {
393
+ setMessage({ kind: 'error', text: t('resetFailed') });
394
+ }
395
+ } catch (error) {
396
+ setMessage({ kind: 'error', text: `${t('resetFailed')} ${error instanceof Error ? error.message : String(error)}` });
397
+ } finally {
398
+ setBusy(false);
399
+ }
400
+ };
401
+
402
+ const toggleEffort = (level) => {
403
+ const declared = asArray(current.efforts);
404
+ const next = declared.includes(level)
405
+ ? declared.filter((id) => id !== level)
406
+ : [...declared, level].sort((a, b) => {
407
+ const ia = EFFORT_ORDER.indexOf(a);
408
+ const ib = EFFORT_ORDER.indexOf(b);
409
+ return (ia < 0 ? 99 : ia) - (ib < 0 ? 99 : ib);
410
+ });
411
+ patch('efforts', next);
412
+ };
413
+
414
+ const togglePurpose = (purpose) => {
415
+ const purposes = asArray(current.auxPurposes);
416
+ patch('auxPurposes', purposes.includes(purpose)
417
+ ? purposes.filter((item) => item !== purpose)
418
+ : [...purposes, purpose]);
419
+ };
420
+
421
+ const customPurposes = asArray(current.auxPurposes).filter((purpose) => !KNOWN_PURPOSES.includes(purpose));
422
+
423
+ const autoOptions = [
424
+ { value: 'model-default', label: t('followDefault') },
425
+ ...levelChoices.map((id) => ({ value: id, label: LEVEL_LABELS[id] ?? id })),
426
+ ];
427
+ const subagentOptions = [
428
+ { value: 'inherit', label: t('inherit') },
429
+ { value: 'auto', label: t('auto') },
430
+ ...levelChoices.map((id) => ({ value: id, label: LEVEL_LABELS[id] ?? id })),
431
+ ];
432
+ const scopeOptions = [
433
+ { value: 'all', label: t('all') },
434
+ { value: 'declared', label: t('declared') },
435
+ { value: 'off', label: t('off') },
436
+ ];
437
+ const levelSelect = (field) => Select({
438
+ value: current[field],
439
+ options: levelChoices.map((id) => ({ value: id, label: LEVEL_LABELS[id] ?? id })),
440
+ onChange: (next) => patch(field, next),
441
+ disabled: busy,
442
+ });
443
+
444
+ // DeepSeek V4's native vocabulary first, then any extra level this row
445
+ // already declares; never offer a standard level the endpoint lacks.
446
+ const declaredEfforts = [...new Set(['low', 'high', 'max', ...asArray(current.efforts)])];
447
+
448
+ return h('div', { className: 'dte-page' },
449
+ h('style', null, styleText()),
450
+ h('p', { className: 'dte-intro' }, t('intro')),
451
+ h('div', { className: 'dte-summary' },
452
+ h('span', { className: 'dte-pill' }, t('autoRow'), ' ', h('b', null, auto)),
453
+ h('span', { className: 'dte-pill' }, t('subagentRow'), ' ', h('b', null, sub)),
454
+ h('span', { className: 'dte-pill' }, t('sectionAux'), ' ', h('b', null, aux))),
455
+ Section({
456
+ title: t('sectionPurpose'),
457
+ hint: t('sectionPurposeHint'),
458
+ children: [
459
+ Row({
460
+ key: 'enabled',
461
+ label: t('enabledRow'),
462
+ hint: t('enabledHint'),
463
+ children: Switch({ checked: current.enabled !== false, disabled: busy, label: current.enabled === false ? t('off') : t('on'), onChange: (next) => patch('enabled', next) }),
464
+ }),
465
+ Row({
466
+ key: 'auto',
467
+ label: t('autoRow'),
468
+ hint: t('autoRowHint'),
469
+ children: Select({ value: current.autoLevel ?? 'model-default', options: autoOptions, disabled: busy, onChange: (next) => patch('autoLevel', next) }),
470
+ }),
471
+ Row({
472
+ key: 'default',
473
+ label: t('defaultRow'),
474
+ hint: t('defaultRowHint'),
475
+ children: Select({ value: current.defaultEffort, options: levelChoices.map((id) => ({ value: id, label: LEVEL_LABELS[id] ?? id })), disabled: busy, onChange: (next) => patch('defaultEffort', next) }),
476
+ }),
477
+ Row({
478
+ key: 'subagent',
479
+ label: t('subagentRow'),
480
+ hint: t('subagentRowHint'),
481
+ children: Select({ value: current.subagentLevel ?? 'inherit', options: subagentOptions, disabled: busy, onChange: (next) => patch('subagentLevel', next) }),
482
+ }),
483
+ Row({
484
+ key: 'scope',
485
+ label: t('autoScopeRow'),
486
+ hint: t('autoScopeHint'),
487
+ children: Select({ value: current.autoScope ?? 'all', options: scopeOptions, disabled: busy, onChange: (next) => patch('autoScope', next) }),
488
+ }),
489
+ ],
490
+ }),
491
+ Section({
492
+ title: t('sectionAux'),
493
+ children: [
494
+ Row({
495
+ key: 'auxSwitch',
496
+ label: t('auxSwitch'),
497
+ hint: t('auxSwitchHint'),
498
+ children: Switch({ checked: current.auxDowngrade !== false, disabled: busy, label: current.auxDowngrade === false ? t('off') : t('on'), onChange: (next) => patch('auxDowngrade', next) }),
499
+ }),
500
+ Row({
501
+ key: 'auxLevel',
502
+ label: t('auxLevelRow'),
503
+ children: levelSelect('auxLevel'),
504
+ }),
505
+ Row({
506
+ key: 'auxPurposes',
507
+ label: t('auxPurposesRow'),
508
+ hint: t('auxPurposesHint'),
509
+ children: [
510
+ h('div', { key: 'known', className: 'dte-inline' },
511
+ KNOWN_PURPOSES.map((purpose) => h('label', {
512
+ key: purpose,
513
+ className: 'dte-chip' + (asArray(current.auxPurposes).includes(purpose) ? ' dte-chip-on' : ''),
514
+ },
515
+ h('input', {
516
+ type: 'checkbox',
517
+ checked: asArray(current.auxPurposes).includes(purpose),
518
+ disabled: busy,
519
+ onChange: () => togglePurpose(purpose),
520
+ }),
521
+ h('code', null, purpose)))),
522
+ h('input', {
523
+ key: 'other',
524
+ className: 'dte-input',
525
+ placeholder: t('auxOther'),
526
+ value: customPurposes.join(', '),
527
+ disabled: busy,
528
+ onChange: (event) => {
529
+ const known = asArray(current.auxPurposes).filter((purpose) => KNOWN_PURPOSES.includes(purpose));
530
+ patch('auxPurposes', [...known, ...splitList(event.target.value)]);
531
+ },
532
+ }),
533
+ ],
534
+ }),
535
+ ],
536
+ }),
537
+ Section({
538
+ title: t('sectionCapability'),
539
+ children: [
540
+ Row({
541
+ key: 'declare',
542
+ label: t('capabilitySwitch'),
543
+ hint: t('capabilitySwitchHint'),
544
+ children: Switch({ checked: current.declareCapability !== false, disabled: busy, label: current.declareCapability === false ? t('off') : t('on'), onChange: (next) => patch('declareCapability', next) }),
545
+ }),
546
+ Row({
547
+ key: 'efforts',
548
+ label: t('effortsRow'),
549
+ hint: t('effortsHint'),
550
+ children: h('div', { className: 'dte-inline' },
551
+ declaredEfforts.map((level) => h('label', {
552
+ key: level,
553
+ className: 'dte-chip' + (asArray(current.efforts).includes(level) ? ' dte-chip-on' : ''),
554
+ },
555
+ h('input', {
556
+ type: 'checkbox',
557
+ checked: asArray(current.efforts).includes(level),
558
+ disabled: busy,
559
+ onChange: () => toggleEffort(level),
560
+ }),
561
+ LEVEL_LABELS[level] ?? level))),
562
+ }),
563
+ Row({
564
+ key: 'hosts',
565
+ label: t('hostsRow'),
566
+ hint: t('hostsHint'),
567
+ children: h('input', {
568
+ className: 'dte-input',
569
+ value: asArray(current.deepseekHosts).join(', '),
570
+ disabled: busy,
571
+ placeholder: 'deepseek.com',
572
+ onChange: (event) => patch('deepseekHosts', splitList(event.target.value)),
573
+ }),
574
+ }),
575
+ Row({
576
+ key: 'pattern',
577
+ label: t('patternRow'),
578
+ hint: t('patternHint'),
579
+ children: h('input', {
580
+ className: 'dte-input',
581
+ value: current.deepseekModelPattern ?? '',
582
+ disabled: busy,
583
+ placeholder: '^deepseek',
584
+ onChange: (event) => patch('deepseekModelPattern', event.target.value),
585
+ }),
586
+ }),
587
+ Row({
588
+ key: 'declareModels',
589
+ label: t('declareModelsRow'),
590
+ hint: t('declareModelsHint'),
591
+ children: h('textarea', {
592
+ className: 'dte-textarea',
593
+ value: asArray(current.declareModels).join('\n'),
594
+ disabled: busy,
595
+ placeholder: 'my-gateway/deepseek-v4.1-flash-1017\n^deepseek-',
596
+ onChange: (event) => patch('declareModels', splitList(event.target.value)),
597
+ }),
598
+ }),
599
+ ],
600
+ }),
601
+ h('details', { className: 'dte-details' },
602
+ h('summary', null, t('advanced')),
603
+ Row({
604
+ key: 'trace',
605
+ label: t('traceRow'),
606
+ hint: t('traceHint'),
607
+ children: Switch({ checked: current.trace === true, disabled: busy, label: current.trace === true ? t('on') : t('off'), onChange: (next) => patch('trace', next) }),
608
+ })),
609
+ h('div', { className: 'dte-footer' },
610
+ h('button', { className: 'dte-btn dte-btn-primary', disabled: busy || !dirty, onClick: () => void save() }, busy ? t('saving') : t('save')),
611
+ h('button', { className: 'dte-btn', disabled: busy, onClick: () => void reset() }, t('reset')),
612
+ message !== null
613
+ ? h('span', { className: `dte-status dte-status-${message.kind}` }, message.text)
614
+ : h('span', { className: 'dte-status dte-status-muted' }, dirty ? t('unsaved') : '')));
615
+ }
616
+
617
+ function Summary({ form, t }) {
618
+ const value = form?.state?.value ?? {};
619
+ const auto = autoDepth(value) ?? '—';
620
+ const sub = value.subagentLevel === 'inherit' || value.subagentLevel === undefined
621
+ ? t('inherit')
622
+ : value.subagentLevel === 'auto' ? t('auto') : levelLabel(value.subagentLevel);
623
+ const aux = value.auxDowngrade === false ? t('off') : (levelLabel(value.auxLevel) ?? value.auxLevel ?? '—');
624
+ return t('summary', { auto, sub, aux });
625
+ }
626
+
627
+ function apply(ctx) {
628
+ const locale = ctx.get('locale');
629
+ if (locale !== undefined) {
630
+ ctx.effect(() => {
631
+ const disposers = [];
632
+ try {
633
+ disposers.push(locale.register(NS, 'zh', zh), locale.register(NS, 'en', en));
634
+ } catch {
635
+ /* a locale registration failure must not hide the page */
636
+ }
637
+ return () => {
638
+ for (const dispose of disposers) dispose();
639
+ };
640
+ }, 'think-effort: dictionaries');
641
+ }
642
+ const t = locale?.bind(NS) ?? ((key) => key);
643
+ const slots = ctx.get('slots');
644
+ if (slots === undefined) return;
645
+ slots.inject('plugins.row.config', () => slots.register({
646
+ name: 'plugins.row.config',
647
+ key: ROW_KEY,
648
+ }, (props) => props.view === 'summary'
649
+ ? Summary({ form: props.form, t })
650
+ : Page({ form: props.form, t })));
651
+ }
652
+
653
+ return { inject: ['slots', 'locale'], apply };
654
+ },
655
+ });
package/cordis.patch.yml CHANGED
@@ -40,4 +40,6 @@
40
40
  - auto-review
41
41
  auxLevel: low
42
42
  # Which models offer Auto: all | declared | off.
43
- autoScope: all
43
+ autoScope: all
44
+ # Subagent calls: inherit | auto | low/high/max. Applies immediately.
45
+ subagentLevel: inherit
package/docs/DETAIL.en.md CHANGED
@@ -7,12 +7,16 @@ Declarative thinking-depth control for DeepSeek (and other) reasoning models: th
7
7
  1. **Declares the capability (on by default).** A hand-declared DeepSeek gateway model under `llm-pi-ai` usually carries no reasoning metadata: the selector offers no depth, and any depth is refused. The plugin recognizes DeepSeek models by endpoint and model id and writes `reasoningEfforts` (default `low / high / max`) plus the route default depth (`high`) into the `llm-pi-ai` settings surface. A model that already declares `reasoningEfforts` — including an explicit `false` — is never touched.
8
8
  2. **Offers `Auto`.** One `Auto` entry is prepended to the model's depth list.
9
9
  3. **Resolves per request.** At the adapter boundary `auto` becomes the declared default; a request whose `purpose` is a cheap host-owned call becomes `low` when the model declares it — regardless of the session's own choice, because those bounded calls never inherit it; a manually picked depth passes through untouched and is validated by DSH itself.
10
+ 4. **Subagent depth.** A subagent effort can be pinned (`inherit` / `auto` / `low`…`max`). `inherit` keeps DSH's native inheritance; a fixed depth overrides the child's own or inherited pick, while a cheap-call downgrade still wins.
10
11
 
11
12
  ## Usage
12
13
 
13
14
  - Pick `Auto` in the model selector to state "use the default depth", or a concrete depth to pin it.
14
15
  - Leaving the depth unset (the native "provider default" row) behaves like `Auto` on ordinary steps — both land on the declared default; `Auto` only records the intent in the session. The cheap-call downgrade applies either way.
15
16
  - The recognized models, default depth and cheap-call list live in the plugin row's config (`think-effort` in `cordis.patch.yml`).
17
+ - The visual settings page is preferred: **Plugins → Automatic thinking depth → Configure**. Every field is `volatile`, so Save applies immediately without a restart.
18
+
19
+ ![Settings page](settings.png)
16
20
 
17
21
  ## Limitations
18
22
 
@@ -36,8 +40,9 @@ Declarative thinking-depth control for DeepSeek (and other) reasoning models: th
36
40
  | `auxPurposes` | `session-title, compaction, auto-review` | Purposes treated as cheap |
37
41
  | `auxLevel` | `low` | Depth those calls request |
38
42
  | `autoScope` | `all` | `all` / `declared` / `off` |
43
+ | `subagentLevel` | `inherit` | Subagent depth: `inherit` / `auto` / a fixed depth; a fixed depth overrides the child's own or inherited pick |
39
44
  | `trace` | `false` | Write decisions to stderr for diagnosis |
40
45
 
41
46
  ## Diagnostic tool
42
47
 
43
- An Agent can call `reasoning_effort_status` for a provider/model: it reports the declared depths, the default, what `Auto` resolves to and the cheap-call depth, without sending any model request.
48
+ An Agent can call `reasoning_effort_status` for a provider/model: it reports the declared depths, the default, what `Auto` and subagents resolve to, and the cheap-call depth, without sending any model request.
package/docs/DETAIL.zh.md CHANGED
@@ -7,12 +7,16 @@
7
7
  1. **声明能力(默认开启)**:手工在 `llm-pi-ai` 里声明的 DeepSeek 网关模型通常没有推理元数据——选择器里没有任何档位,任何档位也会被拒绝。插件按 endpoint 与模型 ID 识别 DeepSeek 模型,把 `reasoningEfforts`(默认 `low / high / max`)与路由默认档(`high`)写进 `llm-pi-ai` 的设置面。已经有 `reasoningEfforts`(包括显式 `false`)的模型不会被改动。
8
8
  2. **提供 `Auto`**:在模型目录的档位列表最前面补一个 `Auto`。
9
9
  3. **逐请求解析**:在适配器边界把 `auto` 换成声明默认档;`purpose` 属于廉价调用时换成 `low`(仅当模型声明了它,且**与会话选了什么都无关**——会话标题/图片摘要本来就不继承会话档位);手动选的档位一律原样透传,由 DSH 自己校验。
10
+ 4. **子代理档位**:可给子代理统一指定强度(`inherit` / `auto` / `low`…`max`)。`inherit` 保持 DSH 原生继承;固定档会覆盖子代理自身或从父代理继承的选择,廉价调用的降档仍然优先。
10
11
 
11
12
  ## 使用
12
13
 
13
14
  - 在模型选择器里选 `Auto` 即声明「按默认档走」;选具体档位即固定该档位。
14
15
  - 不选任何档位(原生“提供方默认”)在普通步骤上与 `Auto` 等效,都会落到声明默认档;差别只是 `Auto` 把意图记录进会话。廉价调用的降档在任何情况下都生效。
15
16
  - 识别范围、默认档、廉价调用清单都在插件配置里(`cordis.patch.yml` 的 `think-effort` 行)。
17
+ - 更推荐用可视化设置:**插件 → 自动思考档位 → 配置**,字段全部是 `volatile` 配置,保存后立即生效(无需重启)。
18
+
19
+ ![设置页](settings.png)
16
20
 
17
21
  ## 限制
18
22
 
@@ -36,8 +40,9 @@
36
40
  | `auxPurposes` | `session-title, compaction, auto-review` | 视为廉价调用的 `purpose` |
37
41
  | `auxLevel` | `low` | 廉价调用用的档位 |
38
42
  | `autoScope` | `all` | `all` / `declared` / `off` |
43
+ | `subagentLevel` | `inherit` | 子代理档位:`inherit` / `auto` / 固定档;固定档覆盖子代理自身或继承的选择 |
39
44
  | `trace` | `false` | 把决策写到 stderr(排查用) |
40
45
 
41
46
  ## 诊断工具
42
47
 
43
- 会话里可以让 Agent 调 `reasoning_effort_status`:它报告某模型声明的档位、默认档、`Auto` 解析结果与廉价调用档位,不发任何模型请求。
48
+ 会话里可以让 Agent 调 `reasoning_effort_status`:它报告某模型声明的档位、默认档、`Auto` 与子代理的解析结果、廉价调用档位,不发任何模型请求。
Binary file
package/index.js CHANGED
@@ -39,7 +39,10 @@
39
39
  * @module dsh-think-effort
40
40
  */
41
41
 
42
+ import z from '@deepseek-ai/schemastery';
43
+
42
44
  import {
45
+ DEFAULT_CONFIG,
43
46
  normalizeConfig,
44
47
  planCapabilitySection,
45
48
  resolveCallEffort,
@@ -50,6 +53,67 @@ import {
50
53
  /** The llm-pi-ai settings entry id in a composed profile. */
51
54
  const PI_AI_NAMESPACE = 'llm-pi-ai';
52
55
 
56
+ /**
57
+ * The row's complete tuning surface, exposed to Settings as a live form.
58
+ *
59
+ * Every field is volatile: the plugin manager page edits one row and the
60
+ * running policy must follow without remounting the adapter facade, so the
61
+ * values arrive as references and are re-read on `loader/volatile-update`.
62
+ * Defaults mirror `cordis.patch.yml` and {@link DEFAULT_CONFIG}.
63
+ */
64
+ export const Config = z.object({
65
+ /** Master switch for the whole policy. */
66
+ enabled: z.boolean().default(true).volatile(),
67
+ /** Declare `reasoningEfforts` for matched models that carry none. */
68
+ declareCapability: z.boolean().default(true).volatile(),
69
+ /** Endpoint suffixes treated as an official DeepSeek host. */
70
+ deepseekHosts: z.array(z.string()).default([...DEFAULT_CONFIG.deepseekHosts]).volatile(),
71
+ /** Model-id test for hand-declared gateways. */
72
+ deepseekModelPattern: z.string().default(DEFAULT_CONFIG.deepseekModelPattern).volatile(),
73
+ /** Extra `provider/model` keys or model-id tests to declare. */
74
+ declareModels: z.array(z.string()).default([]).volatile(),
75
+ /** Declared depth vocabulary, escalation-ordered. */
76
+ efforts: z.array(z.string()).default([...DEFAULT_CONFIG.efforts]).volatile(),
77
+ /** Route default depth; `auto` resolves here unless `autoLevel` pins another. */
78
+ defaultEffort: z.string().default(DEFAULT_CONFIG.defaultEffort).volatile(),
79
+ /** `model-default` follows the route default, or a fixed level id. */
80
+ autoLevel: z.string().default(DEFAULT_CONFIG.autoLevel).volatile(),
81
+ /** Which models offer Auto: `all` | `declared` | `off`. */
82
+ autoScope: z.union([z.const('all'), z.const('declared'), z.const('off')]).default(DEFAULT_CONFIG.autoScope).volatile(),
83
+ /** Downgrade cheap host-owned calls when the model declares the level. */
84
+ auxDowngrade: z.boolean().default(DEFAULT_CONFIG.auxDowngrade).volatile(),
85
+ /** LLM request purposes that are host-owned cheap calls. */
86
+ auxPurposes: z.array(z.string()).default([...DEFAULT_CONFIG.auxPurposes]).volatile(),
87
+ /** Level those calls request. */
88
+ auxLevel: z.string().default(DEFAULT_CONFIG.auxLevel).volatile(),
89
+ /** Subagent-owned calls: `inherit`, `auto`, or a fixed level. */
90
+ subagentLevel: z.string().default(DEFAULT_CONFIG.subagentLevel).volatile(),
91
+ /** Diagnostic stderr trace of each decision. */
92
+ trace: z.boolean().default(false).volatile(),
93
+ });
94
+
95
+ /** Whether one parsed config value is a volatile reference. */
96
+ function isVolatileRef(value) {
97
+ return value !== null && typeof value === 'object' && typeof value.get === 'function' && !Array.isArray(value);
98
+ }
99
+
100
+ /**
101
+ * Read the live policy config from the row's (possibly volatile) values.
102
+ * Constants and tests pass plain values; the Loader passes references.
103
+ * @param {object} [rawConfig] this row's config.
104
+ * @returns {object} a normalized plain config.
105
+ */
106
+ export function readConfig(rawConfig) {
107
+ const source = rawConfig !== null && typeof rawConfig === 'object' ? rawConfig : {};
108
+ const plain = {};
109
+ for (const key of Object.keys(DEFAULT_CONFIG)) {
110
+ const value = source[key];
111
+ const plainValue = isVolatileRef(value) ? value.get() : value;
112
+ if (plainValue !== undefined) plain[key] = plainValue;
113
+ }
114
+ return normalizeConfig(plain);
115
+ }
116
+
53
117
  /**
54
118
  * Marks one facade so a re-run can tell "this registration already carries my
55
119
  * wrapper" from "this is a third party's adapter". Not enumerable: it must not
@@ -126,13 +190,26 @@ function readPiAiSection(ctx) {
126
190
  }
127
191
  }
128
192
 
193
+ /**
194
+ * Whether one live Agent belongs to a subagent session.
195
+ * @param {object} [agent] a live Agent handle (`ctx.agents.get(id)`).
196
+ * @returns {boolean} true for a delegated child session.
197
+ */
198
+ export function isSubagentAgent(agent) {
199
+ const header = agent?.session?.header;
200
+ if (header === null || typeof header !== 'object') return false;
201
+ return header.origin === 'subagent'
202
+ || (typeof header.delegationDepth === 'number' && header.delegationDepth > 0);
203
+ }
204
+
129
205
  /**
130
206
  * Plugin body.
131
207
  * @param {import('@deepseek-ai/cordis').Context} ctx the owning Host context.
132
208
  * @param {object} [rawConfig] this row's config from the profile patch.
133
209
  */
134
210
  export function apply(ctx, rawConfig) {
135
- const config = normalizeConfig(rawConfig);
211
+ /** Live policy config; re-read after a volatile update so Settings edits apply at once. */
212
+ let config = readConfig(rawConfig);
136
213
  /** Diagnostic channel: opt-in stderr trace for a profile that hides the Host log. */
137
214
  const trace = (message, ...rest) => {
138
215
  if (config.trace !== true) return;
@@ -152,6 +229,21 @@ export function apply(ctx, rawConfig) {
152
229
 
153
230
  /** Models this plugin declared, keyed `provider/model` (used by `autoScope: declared`). */
154
231
  const declaredModels = new Set();
232
+ /**
233
+ * Whether one request belongs to a subagent session. DSH stamps the session
234
+ * id on every request; the child's session header carries its durable
235
+ * delegation origin, so no extra seam or cached classification is needed.
236
+ * @param {string} [sessionId] stamped session identity.
237
+ * @returns {boolean} true for a subagent-owned session.
238
+ */
239
+ const isSubagentSession = (sessionId) => {
240
+ if (typeof sessionId !== 'string' || sessionId === '') return false;
241
+ try {
242
+ return isSubagentAgent(ctx.get('agents')?.get?.(sessionId));
243
+ } catch {
244
+ return false;
245
+ }
246
+ };
155
247
  /** Log de-duplication for per-request decisions. */
156
248
  const logged = new Set();
157
249
 
@@ -197,17 +289,20 @@ export function apply(ctx, rawConfig) {
197
289
 
198
290
  const policyDeps = {
199
291
  decorate(info, provider, model) {
292
+ if (config.enabled === false) return info;
200
293
  if (info === null || typeof info !== 'object') return info;
201
294
  const key = `${provider}/${model}`;
202
295
  const declared = declaredModels.has(key) || shouldDeclare({ provider, modelId: model }, config).declared;
203
296
  return withAutoEffort(info, config, { declared });
204
297
  },
205
298
  translate(provider, model, options, info) {
299
+ if (config.enabled === false) return options;
206
300
  if (options === null || typeof options !== 'object') return options;
207
301
  const reasoning = info !== null && typeof info === 'object' ? info.reasoning : undefined;
208
302
  const level = resolveCallEffort({
209
303
  requested: options.reasoningEffort,
210
304
  purpose: options.purpose,
305
+ isSubagent: isSubagentSession(options.sessionId),
211
306
  efforts: reasoning !== null && typeof reasoning === 'object' ? reasoning.efforts : undefined,
212
307
  defaultEffort: reasoning !== null && typeof reasoning === 'object' ? reasoning.defaultEffort : undefined,
213
308
  }, config);
@@ -292,6 +387,15 @@ export function apply(ctx, rawConfig) {
292
387
  if (ns === PI_AI_NAMESPACE) syncCapabilities();
293
388
  });
294
389
  ctx.on('app-boot/config-reload', () => syncCapabilities());
390
+ // A Settings edit commits volatile fields into the running references; the
391
+ // adapter facade reads this `config` variable per request, so only a re-read
392
+ // and one capability reconciliation are needed here.
393
+ ctx.on('loader/volatile-update', () => {
394
+ config = readConfig(rawConfig);
395
+ trace('volatile update: enabled=%s subagentLevel=%s', config.enabled, config.subagentLevel);
396
+ if (config.enabled === false) return;
397
+ syncCapabilities();
398
+ });
295
399
  // Delayed retries cover the boot order where this plugin applies before the
296
400
  // settings service has described the llm-pi-ai entry, and no later commit
297
401
  // touches that namespace. The second beat also covers a bundle installed
@@ -364,10 +468,21 @@ export function apply(ctx, rawConfig) {
364
468
  const auto = resolveCallEffort({ requested: 'auto', efforts: reasoning?.efforts, defaultEffort, purpose: 'agent' }, config);
365
469
  const auxPurpose = config.auxPurposes[0] ?? 'session-title';
366
470
  const aux = resolveCallEffort({ requested: 'auto', efforts: reasoning?.efforts, defaultEffort, purpose: auxPurpose }, config);
471
+ const subagentLevel = config.subagentLevel ?? 'inherit';
472
+ const subagent = subagentLevel === 'inherit'
473
+ ? undefined
474
+ : resolveCallEffort({ isSubagent: true, efforts: reasoning?.efforts, defaultEffort, purpose: 'agent' }, config);
367
475
  const summary = efforts.length === 0
368
476
  ? `${provider}/${model} declares no reasoning depths; the selector offers only the provider default.`
369
- : `${provider}/${model}: ${efforts.join(' | ')}; default=${defaultEffort ?? '(none)'}; Auto -> ${auto ?? '(adapter default)'} for a normal step -> ${aux ?? '(adapter default)'} for ${auxPurpose}.`;
370
- return { ok: true, provider, model, efforts, defaultEffort: defaultEffort ?? null, auto: auto ?? null, aux: aux ?? null, auxPurpose, summary };
477
+ : `${provider}/${model}: ${efforts.join(' | ')}; default=${defaultEffort ?? '(none)'}; Auto -> ${auto ?? '(adapter default)'} for a normal step -> ${aux ?? '(adapter default)'} for ${auxPurpose}`
478
+ + (subagentLevel === 'inherit'
479
+ ? '; subagents follow their own selection.'
480
+ : `; subagents -> ${subagent ?? '(adapter default)'} (${subagentLevel}).`);
481
+ return {
482
+ ok: true, provider, model, efforts, defaultEffort: defaultEffort ?? null,
483
+ auto: auto ?? null, aux: aux ?? null, auxPurpose,
484
+ subagentLevel, subagent: subagent ?? null, summary,
485
+ };
371
486
  },
372
487
  };
373
488
  ctx.inject?.(['tools'], (scope) => {
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Automatic thinking depth",
4
- "description": "Adds Auto to the model selector for reasoning models and resolves it per request: the declared default depth for normal steps (high on DeepSeek), Low for cheap host-owned calls such as session titles and compaction, and the model's own declared vocabulary everywhere else.",
4
+ "description": "Adds Auto to the model selector for reasoning models and resolves it per request: the declared default for normal steps (high on DeepSeek), Low for cheap host-owned calls, and an optional depth just for subagents — all editable on a live visual settings page.",
5
5
  "detail": "docs/DETAIL.en.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "自动思考档位",
4
- "description": "为推理模型在模型选择器里加上 Auto,并逐请求解析:普通步骤用模型声明的默认档位(DeepSeek 为 high),会话标题/压缩等由 Harness 自己发起的廉价调用用 low,其余情况只用模型自己声明的档位。",
4
+ "description": "为推理模型在模型选择器里加上 Auto,并逐请求解析:普通步骤用声明的默认档(DeepSeek 为 high),廉价调用用 low,子代理可单独指定强度;全部规则都能在可视化设置页即时调整。",
5
5
  "detail": "docs/DETAIL.zh.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-think-effort",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
- "description": "Automatic thinking depth for DeepSeek routes in DeepSeek Harness: declare the model's effort vocabulary, add Auto to the model selector, resolve it to the declared default, and drop cheap host-owned calls to Low.",
5
+ "description": "Automatic thinking depth for DeepSeek routes in DeepSeek Harness: declare the model's effort vocabulary, add Auto to the model selector, resolve it to the declared default, give subagents their own depth, drop cheap host-owned calls to Low, and edit every rule on a live visual settings page.",
6
6
  "icon": "./icon.svg",
7
7
  "license": "MIT",
8
8
  "author": "mhlywxl",
@@ -12,16 +12,20 @@
12
12
  "deepseek-harness",
13
13
  "reasoning-effort",
14
14
  "thinking-level",
15
- "deepseek"
15
+ "deepseek",
16
+ "subagent",
17
+ "settings-page"
16
18
  ],
17
19
  "exports": {
18
20
  ".": "./index.js",
19
21
  "./locale/*.json": "./locale/*.json",
20
22
  "./icon": "./icon.svg",
21
- "./package.json": "./package.json"
23
+ "./package.json": "./package.json",
24
+ "./client": "./client.js"
22
25
  },
23
26
  "files": [
24
27
  "index.js",
28
+ "client.js",
25
29
  "src/**",
26
30
  "cordis.patch.yml",
27
31
  "locale/*.json",
@@ -42,6 +46,10 @@
42
46
  "dsh": {
43
47
  "bundle": {
44
48
  "patch": "./cordis.patch.yml"
49
+ },
50
+ "client": {
51
+ "platform": "web",
52
+ "immediately": true
45
53
  }
46
54
  },
47
55
  "repository": {
@@ -51,5 +59,8 @@
51
59
  "homepage": "https://github.com/mhlywxl/dsh-think-effort#readme",
52
60
  "bugs": {
53
61
  "url": "https://github.com/mhlywxl/dsh-think-effort/issues"
62
+ },
63
+ "dependencies": {
64
+ "@deepseek-ai/schemastery": "^3.18.5"
54
65
  }
55
66
  }
package/src/policy.js CHANGED
@@ -86,6 +86,14 @@ export const DEFAULT_CONFIG = {
86
86
  auxLevel: 'low',
87
87
  /** Which models get the `auto` mask in the model selector: `all` | `declared` | `off`. */
88
88
  autoScope: 'all',
89
+ /**
90
+ * Effort for subagent-owned calls: `inherit` leaves the child agent's own
91
+ * selection alone; `auto` follows this plugin's default resolution; a level
92
+ * id forces that depth (clamped to the model's declared vocabulary).
93
+ */
94
+ subagentLevel: 'inherit',
95
+ /** Diagnostic stderr trace of each decision. */
96
+ trace: false,
89
97
  };
90
98
 
91
99
  /** Merge a patch row over the defaults without validating types yet. */
@@ -373,6 +381,24 @@ export function isAuxPurpose(purpose, rawCfg) {
373
381
  return typeof purpose === 'string' && cfg.auxPurposes.includes(purpose);
374
382
  }
375
383
 
384
+ /**
385
+ * Depth `auto` resolves to for ordinary steps.
386
+ * @param {object} cfg normalized plugin config.
387
+ * @param {readonly object[]} efforts declared vocabulary.
388
+ * @param {string} [defaultEffort] model/route default depth.
389
+ * @returns {string | undefined} a declared depth, or undefined without one.
390
+ */
391
+ function autoTarget(cfg, efforts, defaultEffort) {
392
+ const depths = depthLevels(efforts);
393
+ if (depths.length === 0) return undefined;
394
+ const target = cfg.autoLevel === 'model-default' || cfg.autoLevel === undefined
395
+ ? defaultEffort
396
+ : cfg.autoLevel;
397
+ if (typeof target === 'string' && depths.includes(target)) return target;
398
+ if (typeof target === 'string') return clampEffort(target, efforts);
399
+ return clampEffort('high', efforts, depths[depths.length - 1]);
400
+ }
401
+
376
402
  /**
377
403
  * Decide the effort one model request should carry.
378
404
  *
@@ -382,36 +408,43 @@ export function isAuxPurpose(purpose, rawCfg) {
382
408
  * with no explicit selection either: those calls are applied
383
409
  * unconditionally, because a session's own depth never applies to a bounded
384
410
  * summary request.
385
- * 2. An explicit level → `undefined`: a user pick is passed through untouched
411
+ * 2. A subagent-owned call with `subagentLevel` set → that level, or the
412
+ * plugin's `auto` resolution for `auto`. The child's own selection and
413
+ * inherited parent selection are overridden only when the user opted in.
414
+ * 3. An explicit level → `undefined`: a user pick is passed through untouched
386
415
  * (DSH validates it against the same vocabulary, so an undeclared pick never
387
416
  * reaches the wire).
388
- * 3. No explicit selection on an ordinary call → `undefined`: the adapter's own
417
+ * 4. No explicit selection on an ordinary call → `undefined`: the adapter's own
389
418
  * default stands (with the declaration above, that is `high`).
390
- * 4. `auto` → the declared route default (DeepSeek: `high`), or the
419
+ * 5. `auto` → the declared route default (DeepSeek: `high`), or the
391
420
  * highest declared depth when the route names none.
392
421
  *
393
422
  * @param {object} input decision inputs.
394
423
  * @param {string} [input.requested] the selection's effort.
395
424
  * @param {string} [input.purpose] LLM request purpose.
425
+ * @param {boolean} [input.isSubagent] whether the call belongs to a subagent session.
396
426
  * @param {readonly object[]} [input.efforts] declared vocabulary.
397
427
  * @param {string} [input.defaultEffort] route/model default depth.
398
428
  * @param {object} rawCfg plugin config.
399
429
  * @returns {string | undefined} the level to send, or undefined to leave the request alone.
400
430
  */
401
- export function resolveCallEffort({ requested, purpose, efforts, defaultEffort }, rawCfg) {
431
+ export function resolveCallEffort({ requested, purpose, isSubagent, efforts, defaultEffort }, rawCfg) {
402
432
  const cfg = normalizeConfig(rawCfg);
403
- if (requested !== undefined && requested !== AUTO_EFFORT) return undefined;
404
433
  const depths = depthLevels(efforts);
405
434
  if (depths.length === 0) return undefined;
406
- if (isAuxPurpose(purpose, cfg)) {
407
- const aux = clampEffort(cfg.auxLevel, efforts);
435
+ const aux = isAuxPurpose(purpose, cfg) ? clampEffort(cfg.auxLevel, efforts) : undefined;
436
+ // A pinned subagent depth outranks the child's own or inherited selection:
437
+ // without that, a child inheriting the parent's fixed depth could never be
438
+ // lowered and the setting would be inert for the common case. Cheap calls
439
+ // still win, because a summary request has no task difficulty to describe.
440
+ if (isSubagent === true && cfg.subagentLevel !== undefined && cfg.subagentLevel !== 'inherit') {
408
441
  if (aux !== undefined) return aux;
442
+ return cfg.subagentLevel === AUTO_EFFORT
443
+ ? autoTarget(cfg, efforts, defaultEffort)
444
+ : clampEffort(cfg.subagentLevel, efforts);
409
445
  }
446
+ if (requested !== undefined && requested !== AUTO_EFFORT) return undefined;
447
+ if (aux !== undefined) return aux;
410
448
  if (requested === undefined) return undefined;
411
- const target = cfg.autoLevel === 'model-default' || cfg.autoLevel === undefined
412
- ? defaultEffort
413
- : cfg.autoLevel;
414
- if (typeof target === 'string' && depths.includes(target)) return target;
415
- if (typeof target === 'string') return clampEffort(target, efforts);
416
- return clampEffort('high', efforts, depths[depths.length - 1]);
449
+ return autoTarget(cfg, efforts, defaultEffort);
417
450
  }