dsh-auto-effort 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,92 +1,239 @@
1
- # dsh-auto-effort
1
+ # dsh-auto-effort · 自动推理等级
2
2
 
3
- DeepSeek Harness(DSH)插件:按你这一句话自动选推理档位(`off` / `low` / `high` / `max`)。
4
- 每条消息发出前用一次很小的模型调用做判定,判定结果只作用于**这一轮**。
3
+ 按你每条消息自动选推理档位(`off` / `low` / `high` / `max`),省心也省钱:每条消息多花约 0.0003 元、多等约 0.77 秒。
5
4
 
6
- Per-turn reasoning effort for DeepSeek Harness: one small judge call per user message,
7
- applied to that same turn.
5
+ Per-message effort for DeepSeek Harness: it picks `off` / `low` / `high` / `max` for each of your messages. Easy on your head, easy on your bill — about ¥0.0003 and 0.77 s per message.
6
+
7
+ ## 为什么用它
8
+
9
+ - **省心**:不用每次自己判断「这句值不值得深思」。简单的事自动走轻档,快;难的事自动走重档,稳。
10
+ - **省钱**:档位开低了会返工、返工比重跑贵;开高了就是在烧 token。由每条消息的难度决定,比固定开 `high` 便宜,比固定开 `low` 少返工。
11
+ - **不打断你**:判定在后台做,回答一开始就结束等待;你随时可以自己接管(见下面的开关)。
12
+
13
+ ### Why use it
14
+
15
+ - **Less thinking about thinking.** You stop deciding "is this message worth deep reasoning?". Cheap questions run light and fast; hard ones run deep and steady.
16
+ - **Cheaper.** Too low means rework, and rework costs more than the extra tokens; too high just burns tokens. Matching the level to each message beats pinning everything to `high` or `low`.
17
+ - **It stays out of your way.** Judging happens before the reply starts and ends there; you can take over at any time (see the switch below).
8
18
 
9
19
  ## 它做什么
10
20
 
11
- 1. 你发一条消息 → 插件把它单独发给判定模型(默认 `deepseek-flash`,只喂这一句,不带历史/工具结果)→ 得到 `off|low|high|max`。
12
- 2. 在消息入队之前调用宿主的 `agent.model.select()`,所以这一轮请求就用该档位。
13
- 3. 判定超时(默认 3 秒)或失败 → 退回你手动选的档位;连续 3 次失败 → 该会话切手动,不再自动改。
14
- 4. 出现 `content[].thinking` 回传错误 → 立刻回退手动并停止自动切换。
15
- 5. 子会话(subagent)完全跳过,不延迟、不判定。
21
+ 1. 你发一条消息 → 插件看**一张不超过 200 字的任务便签** + **你这条消息**,让一个小模型选一个档位。
22
+ 2. 选出档位后,在消息入队之前就把它应用到这一轮,所以这一轮请求就是用这个档位跑。
23
+ 3. 回答结束后,插件在后台更新那张便签(记录这轮在做什么、到哪一步、还差什么)。
24
+ 4. 判定失败(超时或没给出合法档位)→ 沿用你手动选的档位;连续 3 次失败 → 自动关闭并提示你。
25
+ 5. 子会话(subagent 干的活)不判定、不延迟。
16
26
 
17
- ## 安装
27
+ ### What it does
18
28
 
19
- ```
20
- plugin_manager install_bundle dsh-auto-effort
21
- ```
29
+ 1. You send a message → the plugin looks at **a task card of at most 200 characters** plus **that message**, and asks a small model for one level.
30
+ 2. The level is applied before the message is queued, so that very turn runs at it.
31
+ 3. After the reply, the card is rewritten in the background (what this turn is doing, where it got to, what is left).
32
+ 4. If judging fails (timeout, or no valid level) the plugin keeps your manual level; three failures in a row switch it off and tell you.
33
+ 5. Subagent work is never judged and never delayed.
22
34
 
23
- 或把本目录(绝对路径)交给 `install_bundle`,用本地链接方式安装。
35
+ ## 它怎么判
24
36
 
25
- ## 配置
37
+ 每轮判定一次,输入只有两样:**任务便签**(≤200 字)和**你刚发的那一条消息**。模型回一个词:`off`、`low`、`high`、`max`。
26
38
 
27
- 在 bundle 的 `cordis.patch.yml` / profile 配置里覆盖:
39
+ 便签让短句也有上下文:上一轮计划了一大堆活、你只回一句「开始吧」,那这句会按便签里没做完的事来判,而不是按两个字判。
28
40
 
29
- | 键 | 默认 | 说明 |
41
+ | 档位 | 适合什么 | 实测例子 |
30
42
  |---|---|---|
31
- | `enabled` | `true` | 总开关 |
32
- | `levels` | `[off, low, high, max]` | 参与判定的档位 |
33
- | `judgeModel` | `deepseek-flash` | 判定用的模型 |
34
- | `timeoutMs` | `3000` | 判定超时,超时即回退 |
35
- | `defaultLevel` | `null` | `null` = 跟随手动档位 |
36
- | `minDwellRounds` | `1` | 防抖:档位至少保持几轮 |
37
- | `requireMaxForUpgrade` | `false` | `true` 时自动最多升到 `high`,`max` 只能手动 |
38
- | `debug` | `false` | 写 `~/.dsh/auto-effort.log` |
39
- | `logFile` | `null` | 自定义日志路径 |
43
+ | `off` | 闲聊、确认、查资料、改配置、跑命令 | 列一下当前目录 |
44
+ | `low` | 小改动、改名、整理、照着已有写法改代码 | 把这段代码里的变量名统一一下 |
45
+ | `high` | 分析原因、排查报错、解释原理、写较复杂的代码 | 帮我分析为什么这个方案会慢 |
46
+ | `max` | 架构方案、多方案比较、多因素权衡、疑难 bug 的根因 | 帮我从日志一路排查这个偶发内存泄漏的根因 |
47
+
48
+ 判定结果直接用在这一轮,实测约 0.77 秒,之后不再等待。
49
+
50
+ 一轮里如果判得偏轻、却越干越长(已经到第 3 步还没结束),从第 4 步起升到 `high`,避免用轻档硬啃长任务。只升不降;判成 `high` 的不会自动再升 `max`(步数多通常意味着活多,不等于需要更强的推理)。
51
+
52
+ 判定用的完整提示词见 [docs/DETAIL.md](docs/DETAIL.md)。
53
+
54
+ ### How it judges
55
+
56
+ One judgement per turn, from two inputs only: the **task card** (≤200 chars) and **the message you just sent**. The model answers with one word: `off`, `low`, `high` or `max`.
57
+
58
+ The card is what gives short messages their context: if the last turn laid out a pile of work and you answer "ok, go ahead", that message is judged by the unfinished work on the card, not by its two characters.
59
+
60
+ | Level | Fits | Measured example |
61
+ |---|---|---|
62
+ | `off` | chat, confirmations, lookups, config changes, running commands | list the current directory |
63
+ | `low` | small edits, renames, tidying, applying an existing pattern | rename these variables consistently |
64
+ | `high` | analysis, debugging, explaining why, non-trivial code | help me work out why this approach is slow |
65
+ | `max` | architecture, comparing options, multi-factor tradeoffs, hard bug root causes | trace this intermittent memory leak in the log to its root cause |
40
66
 
41
- ## 重要限制(请先读)
67
+ The level applies to that very turn; the judgement measured about 0.77 s and nothing waits after it.
68
+
69
+ If a turn was judged light but keeps going — already 3 steps deep and not finished — it moves to `high` from step 4 on. It only escalates, never de-escalates, and a turn judged `high` never auto-escalates to `max` (many steps usually means more work, not deeper reasoning).
70
+
71
+ The full judge prompt is in [docs/DETAIL.md](docs/DETAIL.md).
72
+
73
+ ## 自动还是手动:模型菜单里的开关
74
+
75
+ 模型菜单(输入框上方那个模型名)里,推理等级下面多了一行 **「自动选择档位」**,它是一个开关:
76
+
77
+ - **关(默认)**:插件什么都不做,档位完全由你决定。
78
+ - **开**:之后每一条你发的消息都会被判定,插件替你改档位。
79
+ - **你手动选了任意一个档位**:插件立刻让位 —— 开关自动关掉,这个对话以后不再自动改档位。
80
+ - 想让自动回来:再把那个开关打开就行。
81
+
82
+ 一个已知的边界:如果你手动选的档位**正好和插件刚设的一样**,插件看不出「这是你手动选的」,所以那次不会让位。选一个不同的档位就能让它让位。
83
+
84
+ 开关是全局设置(不是每个对话各一份):关掉后所有对话都不再自动改档位。
85
+
86
+ ### Auto or manual: the switch in the model menu
87
+
88
+ In the model menu (the model name above the input box), below the effort rows, there is now **"自动选择档位"** (auto-select level). It is a switch:
89
+
90
+ - **Off (default):** the plugin does nothing; the level is entirely yours.
91
+ - **On:** every message you send gets judged and the plugin sets the level for you.
92
+ - **You pick any level by hand:** the plugin steps aside immediately — the switch turns itself off and that conversation stops being auto-adjusted.
93
+ - To bring auto back, turn the switch on again.
94
+
95
+ One known limitation: if the level you pick by hand **equals the one the plugin just set**, there is no observable difference, so it does not step aside. Picking a different level does.
96
+
97
+ The switch is a global setting, not per conversation: once off, no conversation is auto-adjusted.
98
+
99
+ ## 判定失败时
100
+
101
+ - 超时(默认 3 秒)或模型没回 `off|low|high|max` → 这一轮沿用你手动选的档位,不猜。
102
+ - 连续 3 次失败 → 自动关闭,并在对话里提示你,之后不再尝试。
103
+ - 出现 `content[].thinking` 回传错误 → 立刻退回手动并停止本会话的自动切换。
104
+
105
+ ### When judging fails
106
+
107
+ - Timeout (3 s by default) or an answer that is not one of the four words: that turn keeps your manual level; nothing is guessed.
108
+ - Three failures in a row: it switches itself off and tells you in the conversation.
109
+ - If a `content[].thinking` round-trip error appears, it falls back to manual immediately and stops auto-switching for that session.
110
+
111
+ ## 安装
112
+
113
+ ### 不懂编程
114
+
115
+ 1. 打开 DeepSeek Harness,左侧点「插件」。
116
+ 2. 找到「从本地目录安装 / 安装插件」的入口,输入 `dsh-auto-effort`,确认。
117
+ 3. 看到以 `+ dsh-auto-effort` 开头的那一行就是装好了(`+` 后面跟的版本号,应与 npm 上最新版本一致)。
118
+ 4. 刷新页面(Ctrl+R),打开模型菜单,把「自动选择档位」打开。
119
+
120
+ ### 会用命令行
121
+
122
+ ```
123
+ plugin_manager install_bundle dsh-auto-effort
124
+ ```
42
125
 
43
- - 与 npm 上的 `dsh-thinking-levels` **没有任何关系**:本包是独立实现,不走它的 pre-step/build 方案。
44
- - **不是官方 `agent/pre-step` 方案。** brief 原方案要求在 `agent/pre-step` 里 `agent.model.select()`,但宿主在调用该钩子**之前**就已取好档位,所以那里改只能影响下一条消息。本插件改为在 `agent/created` 时包装该 agent 的 `followup`/`steer`:先判定、再 `select()`、再入队,因此能作用于当前这一轮。它**不修改** `agent/request`,不会触发 thinking 回传报错。
45
- - 判定质量有限:偏“查资料/闲聊”的问题有时判成 `low` 而不是 `off`。
46
- - 当前版本没有输入框旁的档位/理由界面(宿主原本的档位选择器会反映插件选中的档位)。
126
+ 或者把本目录的绝对路径交给 `install_bundle`(本地链接方式,改代码后重装即可)。
47
127
 
48
- ## 生效范围:哪些对话会被自动调档
128
+ ### Install
49
129
 
50
- 插件在对话的 agent **创建的那一刻**接管它的“发送消息”动作。所以规则很简单:
130
+ - Not a programmer: open DeepSeek Harness → 插件 on the left → install a bundle by name → `dsh-auto-effort` → confirm. The line starting with `+ dsh-auto-effort` means it worked (the version after `+` should match the latest on npm).
131
+ - Command line: `plugin_manager install_bundle dsh-auto-effort`, or point `install_bundle` at this directory's absolute path for a local link.
132
+
133
+ ## 生效范围
134
+
135
+ 插件在对话的 agent **创建的那一刻**接管它的发送动作,所以:
51
136
 
52
137
  | 对话是什么时候的 | 会不会自动调档 |
53
138
  |---|---|
54
139
  | 装好插件**之后**新建的对话 | ✅ 会 |
55
- | 装好插件**之前**就已经打开、正在用的对话 | ❌ 本次不会(它的 agent 早就创建好了,插件拿不到) |
56
- | 上面那种老对话,**重启 DSH 后重新打开** | ✅ 会(重新打开会为它新建 agent) |
140
+ | 装好插件**之前**就开着、正在用的对话 | ❌ 本次不会(agent 早就创建好了) |
141
+ | 那种老对话,**重启 DSH 后重新打开** | ✅ 会(重新打开会新建 agent) |
57
142
  | 子会话(subagent 跑的活) | ❌ 不判定、不延迟 |
58
143
 
59
- 一句话:**新对话立刻生效;老对话重启 DSH 再打开就生效;只有“安装那一刻正开着的会话”这一种情况本次不生效。**
144
+ 一句话:**新对话立刻生效;老对话重启 DSH 再打开就生效;只有「安装那一刻正开着的会话」本次不生效。**
60
145
 
61
- ## 开销:每判定一次花多少 token、多少钱
146
+ ### Scope
147
+
148
+ The plugin takes over the send action at the moment a conversation's agent is **created**:
149
+
150
+ | Conversation started | Auto-adjusted |
151
+ |---|---|
152
+ | after the plugin was installed | ✅ yes |
153
+ | before it, still open | ❌ not this time (its agent already exists) |
154
+ | one of those, reopened after restarting DSH | ✅ yes (reopening creates a new agent) |
155
+ | subagent work | ❌ never judged, never delayed |
156
+
157
+ ## 开销
62
158
 
63
159
  每条**用户消息**判定一次,工具调用回合不重复判定。
64
160
 
65
161
  | 项 | 数量 |
66
162
  |---|---|
67
163
  | 额外请求数 | 每条用户消息 1 次 |
68
- | 输入 token | 固定说明约 257 个汉字(≈ 150–200 token)+ 你这条消息本身 |
69
- | 输出 token | 上限 8 token,实际通常 1 个词(如 `low`) |
70
- | 思考 token | 0(判定请求以 `off` 档运行,不产生思考内容) |
164
+ | 输入 token | 固定说明 + 便签(≤200 字)+ 你这条消息 |
165
+ | 输出 token | 上限 8,实际通常 1 个词 |
71
166
 
72
- 成本就是一次很小请求的钱,公式:
167
+ | 用量 | 大概成本 |
168
+ |---|---|
169
+ | 一条普通消息 | **¥0.0002 – ¥0.001**(通常 0.0003 元左右) |
170
+ | 100 条消息 | ¥0.03 – ¥0.1(几分钱) |
73
171
 
74
- ```
75
- 单条成本 ≈ (150~200 + 你的消息字数 × 0.6) × 输入单价 + 1 × 输出单价
76
- ```
172
+ 按 2026-11 官方价(`deepseek-flash`:输入 $0.15/M 闲时、$0.30/M 忙时;输出 $0.60/M 闲时、$1.20/M 忙时)。价格以 [官方定价页](https://api-docs.deepseek.com/quick_start/pricing) 为准;前缀命中缓存时更便宜。
77
173
 
78
- 按 2026-11 官方价(`deepseek-flash`:输入 $0.15/M 闲时、$0.30/M 忙时;输出 $0.60/M 闲时、$1.20/M 忙时;1 美元≈7.1 元)代入,**实际花多少**:
174
+ 代价还有延迟:判定要先做完才把消息入队,每条消息比平时晚约 0.77 秒(上限 `timeoutMs`,默认 3 秒,超时即退回手动档位,不阻塞对话)。
79
175
 
80
- | 用量 | 大概成本 |
176
+ 想完全不花这笔钱:把「自动选择档位」关掉(或 `enabled: false`)。
177
+
178
+ ### Cost
179
+
180
+ One judgement per **user message**; tool-call steps are not re-judged.
181
+
182
+ | Item | Amount |
81
183
  |---|---|
82
- | 一条普通消息 | **¥0.0002 – ¥0.001**(大约千分之几毛,通常 0.0003 元左右) |
83
- | 100 条消息 | ¥0.03 – ¥0.1(几分钱) |
184
+ | Extra requests | 1 per user message |
185
+ | Input tokens | fixed instructions + the card (≤200 chars) + your message |
186
+ | Output tokens | at most 8, usually one word |
187
+
188
+ | Volume | Rough cost |
189
+ |---|---|
190
+ | one ordinary message | **¥0.0002 – ¥0.001** (usually around ¥0.0003) |
191
+ | 100 messages | ¥0.03 – ¥0.1 |
192
+
193
+ Prices as of 2026-11 (`deepseek-flash`: $0.15/M input off-peak, $0.30/M peak; $0.60/M output off-peak, $1.20/M peak). Check the [official price page](https://api-docs.deepseek.com/quick_start/pricing); prefix caching makes it cheaper.
84
194
 
85
- 长消息会略高(输入按字数涨),输出永远只有几个 token,可以忽略。价格随官方调整,以 platform.deepseek.com 定价页为准;前缀命中缓存时还会更便宜。
195
+ There is also latency: judging finishes before the message is queued, so each message leaves about 0.77 s later (`timeoutMs` caps it at 3 s; on timeout the manual level is used and the conversation is not blocked).
86
196
 
87
- 代价还有一点延迟:判定要先做完才把消息入队,所以每条消息会比平时晚约 0.3–1 秒发出(超时上限 `timeoutMs`,默认 3 秒,超时即退回手动档位,不阻塞)。
197
+ To spend nothing at all: turn the switch off (or set `enabled: false`).
198
+
199
+ ## 它是怎么做到的
200
+
201
+ DSH 在组装一次请求之前会先定下这一轮用哪个档位,插件在这个时间点之前就把选好的档位交给宿主,所以它从第一句就生效。它只调用宿主公开的档位选择接口,不去改请求内容,因此不会出现「思考内容没回传」那类错误。
202
+
203
+ ### How it works
204
+
205
+ DSH fixes the effort for a request before assembling it, and the plugin hands in the chosen level before that moment, so it applies from the very first message. It only uses the host's public selection API and never rewrites the request, so thinking-round-trip errors cannot come from it.
206
+
207
+ ## 配置
88
208
 
89
- 想完全不花这笔钱:`enabled: false`(完全停止),或把 `levels` 收窄。
209
+ 在 bundle 的 `cordis.patch.yml` 或 profile 配置里覆盖:
210
+
211
+ | 键 | 默认 | 说明 |
212
+ |---|---|---|
213
+ | `enabled` | `true` | 总开关 |
214
+ | `mode` | `manual` | `manual` = 不自动改;`auto` = 每轮判定(模型菜单里的开关写的就是它) |
215
+ | `levels` | `[off, low, high, max]` | 参与判定的档位 |
216
+ | `judgeModel` | `deepseek-flash` | 判定用的模型 |
217
+ | `timeoutMs` | `3000` | 判定超时,超时即回退 |
218
+ | `defaultLevel` | `null` | 判定失败时用的档位;`null` = 跟随手动档位 |
219
+ | `requireMaxForUpgrade` | `false` | `true` 时自动最多升到 `high`,`max` 只能手动 |
220
+ | `escalateAfterSteps` | `3` | 一轮里走到第几步还没结束就升到 `high`;`0` = 关闭同轮升档 |
221
+ | `debug` | `false` | 写 `~/.dsh/auto-effort.log` |
222
+ | `logFile` | `null` | 自定义日志路径 |
223
+
224
+ ### Configuration
225
+
226
+ | Key | Default | Meaning |
227
+ |---|---|---|
228
+ | `enabled` | `true` | master switch |
229
+ | `mode` | `manual` | `manual` = never adjust; `auto` = judge every turn (this is what the menu switch writes) |
230
+ | `levels` | `[off, low, high, max]` | levels the judge may pick |
231
+ | `judgeModel` | `deepseek-flash` | model used for judging |
232
+ | `timeoutMs` | `3000` | judge timeout; on timeout the manual level is used |
233
+ | `defaultLevel` | `null` | level used when judging fails; `null` = follow the manual level |
234
+ | `requireMaxForUpgrade` | `false` | when `true`, auto never goes above `high`; `max` stays manual |
235
+ | `escalateAfterSteps` | `3` | raise to `high` when a turn is this many steps deep; `0` disables it |
236
+ | `debug` | `false` | write `~/.dsh/auto-effort.log` |
90
237
 
91
238
  ## 卸载
92
239
 
@@ -96,24 +243,51 @@ plugin_manager remove_bundle dsh-auto-effort
96
243
 
97
244
  卸载会同时清掉 profile 里 `dsh.profile.bundles` 的记录,不残留 override。
98
245
 
246
+ ### Uninstall
247
+
248
+ `plugin_manager remove_bundle dsh-auto-effort` also clears the profile's `dsh.profile.bundles` entry and leaves no override behind.
249
+
250
+ ## 没生效怎么办
251
+
252
+ 1. 这个对话是插件安装**之前**就开着的吗?新建一个对话试试。
253
+ 2. 「自动选择档位」是开着的吗?关着时插件不做任何事。
254
+ 3. 打开 `debug: true`,看 `~/.dsh/auto-effort.log`:应该有 `agent … wrapped` 和 `turn N judging`。日志里不记录消息原文,只有长度和档位。
255
+ 4. 日志里出现 `manual pick detected` 说明你手动接管过:把开关重新打开。
256
+
257
+ ### If it seems to do nothing
258
+
259
+ 1. Was this conversation opened before the plugin was installed? Try a new one.
260
+ 2. Is the 自动选择档位 switch on? With it off the plugin does nothing.
261
+ 3. Turn on `debug: true` and read `~/.dsh/auto-effort.log`: you should see `agent … wrapped` and `turn N judging`. The log never contains message text, only lengths and levels.
262
+ 4. A `manual pick detected` line means you took over by hand: turn the switch back on.
263
+
99
264
  ## 排障
100
265
 
101
- **卸载“本地目录链接”方式安装的包,会把那个本地目录清空。** 用绝对路径装(`install_bundle /path/to/dsh-auto-effort`)时,profile 里是一条 `link:` 链接;卸载这个链接时,pnpm 的清理会连带删掉被链接目录里的文件。开发时如果改完想“卸掉重装”,先备份,或直接按下面的方式重装:
266
+ **卸载「本地目录链接」方式安装的包,会把那个本地目录清空。** 用绝对路径装时,profile 里是一条 `link:`,卸载这个链接时 pnpm 的清理会连带删掉被链接目录里的文件。开发时先备份,或从线上包恢复:
102
267
 
103
268
  ```
104
- # 从线上包恢复一份完整源码
105
269
  npm pack dsh-auto-effort@<版本>
106
270
  tar -xzf dsh-auto-effort-<版本>.tgz --strip-components=1 -C <你的目录>
107
271
  ```
108
272
 
109
- 从 npm 正常安装(`install_bundle dsh-auto-effort`)不会有这个问题,删的是 profile 里那份拷贝。开发循环更安全的做法是:不要卸载,改完文件后重新 `install_bundle <目录>`(同一版本会提示 `already-installed`,所以开发时每次改完把 `version` 提一位再装,或用 `remove_bundle` 前先 `git commit`)。
273
+ 从 npm 正常安装(`install_bundle dsh-auto-effort`)没有这个问题。
274
+
275
+ **安装后第一次激活报 `failed to import … index.js` 的 `ENOENT`**:从本地链接切到 npm 版本时,第一次激活可能还指向旧链接路径;卸载 → 安装两次即可。
276
+
277
+ ### Troubleshooting
110
278
 
111
- **别人装的时候报 `failed to import … index.js` 的 `ENOENT`**:先确认 profile 里那条依赖现在是版本号而不是 `link:` 路径;如果是从本地链接切到 npm 版本,卸载 → 安装两次即可,第一次激活可能还指向旧链接路径。
279
+ Removing a bundle that was installed from a **local directory link** empties that directory: pnpm's cleanup follows the `link:` and deletes the linked files. Back it up, or restore with `npm pack … && tar -xzf … --strip-components=1`. Installing from npm does not have this problem.
280
+
281
+ An `ENOENT … index.js` on the first activation after switching from a local link to the npm version means it still pointed at the old path; remove and install again.
112
282
 
113
283
  ## 开发
114
284
 
115
285
  ```
116
- node --test # 或分别运行 tools/test-think-level*.mjs
286
+ npm test # 两个离线自测脚本,不需要网络
117
287
  ```
118
288
 
119
289
  采用 MIT 许可。
290
+
291
+ ### Development
292
+
293
+ `npm test` runs both offline suites (no network). MIT licensed.
package/client.js ADDED
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Client half: one switch inside the composer's model menu, below the four
3
+ * reasoning levels.
4
+ *
5
+ * It is a switch, not a level: `off/low/high/max` are the only values the API
6
+ * accepts, so "auto" never becomes an effort value. The switch writes the
7
+ * `mode` field of this bundle's own settings entry (`auto-effort`), which the
8
+ * host half declares as a volatile field — the running plugin reads the change
9
+ * immediately, without a reload and without a new conversation.
10
+ */
11
+ window.__ModuleLoader__.load({
12
+ id: 'dsh-auto-effort',
13
+ factory(require) {
14
+ const React = require('react')
15
+ const h = React.createElement
16
+ const ENTRY = 'auto-effort'
17
+ const AUTO = 'auto'
18
+ const MANUAL = 'manual'
19
+
20
+ /** The switch state from a config snapshot; null while still loading. */
21
+ function readMode(snapshot) {
22
+ const value = snapshot?.value
23
+ if (value === null || typeof value !== 'object') return null
24
+ return value.mode === AUTO ? AUTO : MANUAL
25
+ }
26
+
27
+ function AutoRow(ctx) {
28
+ let form = null
29
+ let formError = null
30
+ try {
31
+ form = ctx.configForms.get(ENTRY)
32
+ } catch (error) {
33
+ formError = error
34
+ }
35
+ const [snapshot, setSnapshot] = React.useState(() => (form ? form.getSnapshot() : null))
36
+ const [pending, setPending] = React.useState(false)
37
+
38
+ React.useEffect(() => {
39
+ if (!form) return undefined
40
+ return form.subscribe(() => setSnapshot(form.getSnapshot()))
41
+ }, [form])
42
+
43
+ const mode = readMode(snapshot)
44
+ const on = mode === AUTO
45
+ const ready = form !== null && mode !== null && snapshot?.writable !== false
46
+
47
+ const toggle = () => {
48
+ if (!ready || pending || !form) return
49
+ setPending(true)
50
+ const next = on ? MANUAL : AUTO
51
+ Promise.resolve(form.set('mode', next))
52
+ .catch(error => ctx.logger?.warn?.(`cannot switch mode: ${String(error)}`))
53
+ .finally(() => setPending(false))
54
+ }
55
+
56
+ return h(
57
+ 'div',
58
+ {
59
+ role: 'menuitemcheckbox',
60
+ 'aria-checked': on,
61
+ tabIndex: 0,
62
+ onClick: toggle,
63
+ onKeyDown: event => {
64
+ if (event.key === 'Enter' || event.key === ' ') {
65
+ event.preventDefault()
66
+ toggle()
67
+ }
68
+ },
69
+ style: {
70
+ display: 'flex',
71
+ alignItems: 'center',
72
+ justifyContent: 'space-between',
73
+ gap: 12,
74
+ padding: '8px 12px',
75
+ fontSize: 13,
76
+ lineHeight: '20px',
77
+ cursor: ready ? 'pointer' : 'default',
78
+ opacity: ready ? 1 : 0.55,
79
+ userSelect: 'none',
80
+ },
81
+ },
82
+ h('span', { style: { flex: '1 1 auto' } }, '自动选择档位'),
83
+ h(
84
+ 'span',
85
+ {
86
+ 'aria-hidden': true,
87
+ style: {
88
+ position: 'relative',
89
+ display: 'inline-block',
90
+ flex: '0 0 auto',
91
+ width: 30,
92
+ height: 18,
93
+ borderRadius: 9,
94
+ background: on ? '#3b82f6' : 'rgba(128,128,128,0.45)',
95
+ transition: 'background 120ms ease',
96
+ },
97
+ },
98
+ h('span', {
99
+ style: {
100
+ position: 'absolute',
101
+ top: 2,
102
+ left: on ? 14 : 2,
103
+ width: 14,
104
+ height: 14,
105
+ borderRadius: '50%',
106
+ background: '#fff',
107
+ transition: 'left 120ms ease',
108
+ },
109
+ }),
110
+ ),
111
+ )
112
+ }
113
+
114
+ return {
115
+ inject: ['slots', 'configForms'],
116
+ apply(ctx) {
117
+ ctx.slots.inject('conversation.input.model.options', () =>
118
+ ctx.slots.register(
119
+ { name: 'conversation.input.model.options', id: 'auto-effort-auto', order: 20 },
120
+ () => AutoRow(ctx),
121
+ ),
122
+ )
123
+ },
124
+ }
125
+ },
126
+ })
package/config.js CHANGED
@@ -10,12 +10,17 @@ export const LEVELS = Object.freeze(['off', 'low', 'high', 'max'])
10
10
  /** Config exactly as the brief §3.5 prescribes. */
11
11
  export const DEFAULT_CONFIG = Object.freeze({
12
12
  enabled: true,
13
+ // 'manual' = the plugin never touches the level; 'auto' = judge every user
14
+ // turn. The composer menu switch (and the plugin page) writes this field.
15
+ mode: 'manual',
13
16
  levels: LEVELS,
14
17
  judgeModel: 'deepseek-flash',
15
18
  timeoutMs: 3000,
16
19
  defaultLevel: null,
17
- minDwellRounds: 1,
18
20
  requireMaxForUpgrade: false,
21
+ // Same-turn escalation: when a turn judged off/low has already reached this
22
+ // many steps, raise the level for its remaining steps. 0 disables it.
23
+ escalateAfterSteps: 3,
19
24
  // One line per judged turn in `~/.dsh/auto-effort.log` when enabled. Off by
20
25
  // default for a published bundle; set `debug: true` or `logFile` to inspect.
21
26
  debug: false,
@@ -26,6 +31,21 @@ function fail(message) {
26
31
  throw new Error(`[auto-effort] invalid config: ${message}`)
27
32
  }
28
33
 
34
+ /**
35
+ * Read one config field, unwrapping a volatile reference.
36
+ *
37
+ * A field declared `.volatile()` in `schema.js` reaches the plugin as a live
38
+ * reference (read with `.get()`), not as a plain value, so validation and the
39
+ * switch itself have to look through it.
40
+ * @param {Record<string, unknown>} input
41
+ * @param {string} key
42
+ */
43
+ export function field(input, key) {
44
+ const value = input?.[key]
45
+ if (value !== null && typeof value === 'object' && typeof value.get === 'function') return value.get()
46
+ return value
47
+ }
48
+
29
49
  /**
30
50
  * Merge defaults with the patch/profiles config and validate every field.
31
51
  * @param {unknown} raw - value handed to `apply` by the Cordis loader.
@@ -35,10 +55,13 @@ export function resolveConfig(raw) {
35
55
  const input = raw === undefined || raw === null ? {} : raw
36
56
  if (typeof input !== 'object' || Array.isArray(input)) fail('expected an object')
37
57
 
38
- const enabled = input.enabled ?? DEFAULT_CONFIG.enabled
58
+ const enabled = field(input, 'enabled') ?? DEFAULT_CONFIG.enabled
39
59
  if (typeof enabled !== 'boolean') fail('enabled must be a boolean')
40
60
 
41
- const levelsInput = input.levels ?? DEFAULT_CONFIG.levels
61
+ const mode = field(input, 'mode') ?? DEFAULT_CONFIG.mode
62
+ if (mode !== 'manual' && mode !== 'auto') fail('mode must be "manual" or "auto"')
63
+
64
+ const levelsInput = field(input, 'levels') ?? DEFAULT_CONFIG.levels
42
65
  if (!Array.isArray(levelsInput) || levelsInput.length === 0) fail('levels must be a non-empty array')
43
66
  const levels = []
44
67
  for (const level of levelsInput) {
@@ -46,39 +69,43 @@ export function resolveConfig(raw) {
46
69
  if (!levels.includes(level)) levels.push(level)
47
70
  }
48
71
 
49
- const judgeModel = input.judgeModel ?? DEFAULT_CONFIG.judgeModel
72
+ const judgeModel = field(input, 'judgeModel') ?? DEFAULT_CONFIG.judgeModel
50
73
  if (typeof judgeModel !== 'string' || judgeModel.trim() === '') fail('judgeModel must be a non-empty string')
51
74
 
52
- const timeoutMs = input.timeoutMs ?? DEFAULT_CONFIG.timeoutMs
75
+ const timeoutMs = field(input, 'timeoutMs') ?? DEFAULT_CONFIG.timeoutMs
53
76
  if (!Number.isInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 60_000) {
54
77
  fail('timeoutMs must be an integer between 100 and 60000')
55
78
  }
56
79
 
57
- const defaultLevel = input.defaultLevel ?? DEFAULT_CONFIG.defaultLevel
80
+ const defaultLevel = field(input, 'defaultLevel') ?? DEFAULT_CONFIG.defaultLevel
58
81
  if (defaultLevel !== null && !LEVELS.includes(defaultLevel)) {
59
82
  fail(`defaultLevel must be null or one of ${LEVELS.join(', ')}`)
60
83
  }
61
84
 
62
- const minDwellRounds = input.minDwellRounds ?? DEFAULT_CONFIG.minDwellRounds
63
- if (!Number.isInteger(minDwellRounds) || minDwellRounds < 1) fail('minDwellRounds must be an integer >= 1')
64
85
 
65
- const requireMaxForUpgrade = input.requireMaxForUpgrade ?? DEFAULT_CONFIG.requireMaxForUpgrade
86
+ const requireMaxForUpgrade = field(input, 'requireMaxForUpgrade') ?? DEFAULT_CONFIG.requireMaxForUpgrade
66
87
  if (typeof requireMaxForUpgrade !== 'boolean') fail('requireMaxForUpgrade must be a boolean')
67
88
 
68
- const debug = input.debug ?? DEFAULT_CONFIG.debug
89
+ const escalateAfterSteps = field(input, 'escalateAfterSteps') ?? DEFAULT_CONFIG.escalateAfterSteps
90
+ if (!Number.isInteger(escalateAfterSteps) || escalateAfterSteps < 0 || escalateAfterSteps > 50) {
91
+ fail('escalateAfterSteps must be an integer between 0 and 50')
92
+ }
93
+
94
+ const debug = field(input, 'debug') ?? DEFAULT_CONFIG.debug
69
95
  if (typeof debug !== 'boolean') fail('debug must be a boolean')
70
96
 
71
- const logFile = input.logFile ?? DEFAULT_CONFIG.logFile
97
+ const logFile = field(input, 'logFile') ?? DEFAULT_CONFIG.logFile
72
98
  if (logFile !== null && typeof logFile !== 'string') fail('logFile must be null or a path string')
73
99
 
74
100
  return Object.freeze({
75
101
  enabled,
102
+ mode,
76
103
  levels: Object.freeze(levels),
77
104
  judgeModel,
78
105
  timeoutMs,
79
106
  defaultLevel,
80
- minDwellRounds,
81
107
  requireMaxForUpgrade,
108
+ escalateAfterSteps,
82
109
  debug,
83
110
  logFile,
84
111
  })
package/cordis.patch.yml CHANGED
@@ -3,6 +3,7 @@
3
3
  name: 'dsh-auto-effort'
4
4
  config:
5
5
  enabled: true
6
+ mode: manual
6
7
  levels:
7
8
  - off
8
9
  - low
@@ -11,7 +12,7 @@
11
12
  judgeModel: deepseek-flash
12
13
  timeoutMs: 3000
13
14
  defaultLevel: null
14
- minDwellRounds: 1
15
15
  requireMaxForUpgrade: false
16
+ escalateAfterSteps: 3
16
17
  debug: false
17
18
  logFile: null