dsh-think-effort 0.4.0 → 0.5.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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0 — 2026-11-24
4
+
5
+ - **实时调试悬浮窗**:设置页新增「调试」区块与 `debugOverlay` 开关(默认关)。打开后,会话右下角出现可拖动的悬浮窗(`shell.overlay` 槽位),实时显示每次模型请求的档位决策:时间、用途、请求档位 → 实际发送档位、模型,以及子代理会话(带「子」标记)和 `设置更新` / `能力声明` 事件;支持「当前会话 / 全部会话 / 仅切换」筛选、一键复制、清空,窗口位置与展开状态在浏览器本地保存。
6
+ - **只记录、不改变请求**:Host 半边在适配器边界把每条决策写入内存环形缓冲(最多 300 条,不写会话日志、不落盘),经两条 `webServer` 路由(`GET /think-effort/debug?since=N`、`POST /think-effort/debug/clear`)提供增量读取与清空;开关关闭时路由返回 `enabled: false` 且不记录。
7
+ - 设置页原来的「高级」disclosure 改为「调试」区块,`trace`(stderr 诊断)移入其中。
8
+ - 测试:40 项全绿(新增调试日志 ring buffer/路由/清空契约、Host 决策记录、开关热更新、客户端悬浮窗注册与双语文案)。
9
+ - 文档:README / DETAIL(中英)新增悬浮窗说明与截图(`docs/debug-settings.png`、`docs/debug-overlay.png`);`cordis.patch.yml` 与配置表补 `debugOverlay`。
10
+
3
11
  ## 0.4.0 — 2026-11-24
4
12
 
5
13
  - **设置里多一个入口**:同一条配置现在注册进 DSH 设置面板的 `settings.section`(导航项「自动思考档位」,紧跟「内置插件」),并带一个仪表盘图标的 `settings.section.icon`。以前只能从「插件 → 自动思考档位 → 行 → 配置」进入,入口太深;两处共用同一份表单与同一次写入。
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **中文(默认)** · [English](#english)
4
4
 
5
- 给 DeepSeek Harness(DSH)加一套**声明式自动思考档位**:模型选择器里出现 `Auto`,普通步骤落到模型声明的默认档(DeepSeek 为 `high`),会话标题、上下文压缩、自动复审这类由 Harness 自己发起的廉价调用自动用 `low`。
5
+ 给 DeepSeek Harness(DSH)加一套**声明式自动思考档位**:模型选择器里出现 `Auto`,普通步骤落到模型声明的默认档(DeepSeek 为 `high`),会话标题、上下文压缩、自动复审这类由 Harness 自己发起的廉价调用自动用 `low`。打开调试开关后,每次请求的档位决策会实时出现在会话界面的悬浮窗里,子代理的决策也在其中。
6
6
 
7
7
  ## 快速开始
8
8
 
@@ -71,10 +71,26 @@ DSH Desktop → **插件市场**搜索 `dsh-think-effort` 安装;或 **插件
71
71
  - **档位分配**:普通步骤的 Auto 落点、模型默认档、**子代理推理强度**、哪些模型显示 Auto;
72
72
  - **廉价调用**:总开关、档位、purpose 清单;
73
73
  - **能力声明**:是否写入 `reasoningEfforts`、声明哪些档位、DeepSeek host/模型匹配规则;
74
- - **高级**:stderr 诊断。
74
+ - **调试**:会话界面的实时档位切换日志、stderr 诊断。
75
75
 
76
76
  所有字段都是 `volatile` 配置:点「保存」后**立即生效**,不需要重启,也不用改 `cordis.patch.yml`。「设置」里的入口只在 Host 提供该行设置命名空间时出现,卸载或关闭本插件后不留空页面。
77
77
 
78
+ ### 实时调试悬浮窗
79
+
80
+ 设置页的「调试 → 在会话界面显示实时档位切换日志」打开后,会话右下角会出现一个可拖动的小窗口:
81
+
82
+ ![设置页里的调试开关](docs/debug-settings.png)
83
+
84
+ ![实时档位切换日志](docs/debug-overlay.png)
85
+
86
+ - **每次请求都记一条**:时间、用途(普通步骤 / 会话标题 / 压缩 / 自动复核)、请求档位(`Auto` 或具体档)、实际发送档位,以及模型;
87
+ - **子代理单独标记**:子代理会话由同一个 Host 处理,因此它的决策也在同一个窗口里,带「子」标记;
88
+ - **切换直观可见**:插件真正改写了档位(如 `auto → high`)的行高亮;同一会话同一用途的档位发生变化时,行尾出现 `⇄`;
89
+ - **筛选与复制**:可在「当前会话 / 全部会话 / 仅切换」之间切换,一键复制为文本,方便贴到 issue;
90
+ - **只记录、不改变请求**:关掉开关后日志立即停止记录,窗口消失;记录只存在 Host 内存里(最多 300 条),不写会话日志、不落盘。
91
+
92
+ 窗口位置与展开状态记在浏览器本地,刷新页面后保持原样;「设置更新」「能力声明」也会作为事件出现在日志里,方便确认保存是否生效。
93
+
78
94
  ### 本插件的第一次使用
79
95
 
80
96
  装上后不需要额外配置:`Auto` 与档位由插件自动声明。选中 `Auto` 即按默认档运行;选 `Low / High / Max` 即固定该档;不选(原生「提供方默认」)在普通步骤上与 `Auto` 等效。
@@ -122,6 +138,7 @@ DSH Desktop → **插件市场**搜索 `dsh-think-effort` 安装;或 **插件
122
138
  auxLevel: low
123
139
  autoScope: all
124
140
  subagentLevel: inherit
141
+ debugOverlay: false
125
142
  trace: false
126
143
  ```
127
144
 
@@ -140,6 +157,7 @@ DSH Desktop → **插件市场**搜索 `dsh-think-effort` 安装;或 **插件
140
157
  | `auxLevel` | `low` | 廉价调用用的档位 |
141
158
  | `autoScope` | `all` | `all` / `declared` / `off` |
142
159
  | `subagentLevel` | `inherit` | 子代理档位:`inherit` / `auto` / `low`…`max`;固定档会覆盖子代理自身或继承的选择 |
160
+ | `debugOverlay` | `false` | 在会话界面显示实时档位切换日志(只记录,不改请求) |
143
161
  | `trace` | `false` | 把决策写到 stderr(排查用) |
144
162
 
145
163
  ## 兼容性
@@ -158,7 +176,7 @@ MIT。
158
176
 
159
177
  **中文简介**:给 DeepSeek Harness 加一套声明式自动思考档位——`Auto` 落到模型声明的默认档,廉价调用自动用低档。
160
178
 
161
- Declarative automatic thinking depth for DeepSeek Harness: the model selector gains `Auto`, normal steps use the model's declared default depth (`high` on DeepSeek), and cheap host-owned calls — session titles, compaction, auto-review — drop to `low`.
179
+ Declarative automatic thinking depth for DeepSeek Harness: the model selector gains `Auto`, normal steps use the model's declared default depth (`high` on DeepSeek), and cheap host-owned calls — session titles, compaction, auto-review — drop to `low`. Turn on the debug switch and every request's effort decision appears live in a floating window over the conversation, subagent decisions included.
162
180
 
163
181
  ### Quick start
164
182
 
@@ -219,10 +237,26 @@ The same form is reachable from **two places**; both read and write the identica
219
237
  - **Depth assignment**: the ordinary-step Auto target, the model default, the **subagent effort**, and which models offer Auto;
220
238
  - **Cheap calls**: switch, level, and purpose list;
221
239
  - **Capability declaration**: whether to write `reasoningEfforts`, which depths to declare, and the DeepSeek host/model rules;
222
- - **Advanced**: stderr diagnostics.
240
+ - **Debug**: the conversation's live effort-switch log and stderr diagnostics.
223
241
 
224
242
  Every field is `volatile`: **Save** applies immediately, without a restart and without hand-editing `cordis.patch.yml`. The Settings entry exists only while the Host serves this row's settings namespace, so disabling or removing the plugin leaves no empty page behind.
225
243
 
244
+ ### Live debug window
245
+
246
+ Turn on **Debug → Show the live effort-switch log in the conversation** and a movable window appears at the conversation's bottom-right corner:
247
+
248
+ ![The debug switch in Settings](docs/debug-settings.png)
249
+
250
+ ![The live effort-switch log](docs/debug-overlay.png)
251
+
252
+ - **One line per request**: time, purpose (ordinary step / session title / compaction / auto-review), requested depth (`Auto` or an explicit level), the depth actually sent, and the model;
253
+ - **Subagents are marked**: subagent sessions run in the same Host process, so their decisions land in the same window with a `Sub` badge;
254
+ - **Switches stand out**: rows the plugin actually rewrote (for example `auto → high`) are highlighted, and a level change for the same session and purpose is marked `⇄`;
255
+ - **Filter and copy**: switch between this session, all sessions, and switches only; copy the log as text for an issue report;
256
+ - **Records only, never rewrites**: turning the switch off stops recording and hides the window; the journal lives in Host memory (300 records at most) and never touches the session log or disk.
257
+
258
+ The window's position and open state persist in the browser, so a page refresh keeps them. Settings updates and capability declarations also appear as events, which makes a save's effect easy to confirm.
259
+
226
260
  ### Features
227
261
 
228
262
  - Declares `reasoningEfforts` for DeepSeek models that carry none (gateway aliases included), so the selector finally has levels.
@@ -230,10 +264,11 @@ Every field is `volatile`: **Save** applies immediately, without a restart and w
230
264
  - **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.
231
265
  - 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.
232
266
  - Idempotent: a second boot writes nothing; unload restores the original adapter registrations and retires a durable `auto`.
267
+ - **Live debug window**: an opt-in, bounded, in-memory journal served over a Host route and rendered as a movable log over the conversation, subagent decisions included.
233
268
 
234
269
  ### Configuration
235
270
 
236
- 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.
271
+ 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`, `debugOverlay` and `trace` are the ones most often changed. Most users should use the visual settings page instead of editing this file.
237
272
 
238
273
  ### Compatibility
239
274
 
package/client.js CHANGED
@@ -36,6 +36,12 @@ window.__ModuleLoader__.load({
36
36
  const SECTION_ID = 'think-effort';
37
37
  /** Right after the built-in Plugins section (order 15): the plugin's own options. */
38
38
  const SECTION_ORDER = 16;
39
+ /** Host route that serves the opt-in debug journal (see `src/debug.js`). */
40
+ const DEBUG_PATH = '/think-effort/debug';
41
+ const DEBUG_CLEAR_PATH = '/think-effort/debug/clear';
42
+ /** The overlay's localStorage keys: a reopened page keeps the reader's window. */
43
+ const DEBUG_OPEN_KEY = 'dte.debug.open';
44
+ const DEBUG_POS_KEY = 'dte.debug.pos';
39
45
  const EFFORT_ORDER = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
40
46
  const KNOWN_PURPOSES = ['session-title', 'compaction', 'auto-review'];
41
47
 
@@ -85,9 +91,37 @@ window.__ModuleLoader__.load({
85
91
  patternHint: '网关别名用,例如 ^deepseek;不区分大小写。',
86
92
  declareModelsRow: '额外声明',
87
93
  declareModelsHint: '每行一个 provider/model,或一个模型 ID 正则;用于没有匹配到上面两条规则的网关。',
88
- advanced: '高级',
89
- traceRow: '把每次决策写到 stderr',
90
- traceHint: '排查用;默认关闭。',
94
+ debugSection: '调试',
95
+ debugSectionHint: '调试只记录、不改变任何请求:打开后,每次模型请求的档位决策都会实时出现在会话界面的悬浮窗里。',
96
+ debugOverlayRow: '在会话界面显示实时档位切换日志',
97
+ debugOverlayHint: '会话右下角出现悬浮调试窗:每条模型请求的用途、请求档位和实际发送档位都会实时记录,包括子代理会话和 Harness 的廉价调用。',
98
+ debugTraceRow: '同时把决策写到 Host 的 stderr',
99
+ debugTraceHint: '给开发者排查用;普通使用不需要。',
100
+ debugPill: '档位调试',
101
+ debugTitle: '思考档位 · 实时切换日志',
102
+ debugLive: '记录中',
103
+ debugPaused: '未开启',
104
+ debugEmpty: '等待下一次模型请求…',
105
+ debugDisabledOnHost: '表单已打开调试,但 Host 还没有注册调试接口。完全退出并重新打开 DeepSeek Harness 后生效。',
106
+ debugLoadFailed: '读取调试日志失败:',
107
+ debugClear: '清空',
108
+ debugCopy: '复制',
109
+ debugCopied: '已复制',
110
+ debugCollapse: '收起',
111
+ debugFilterCurrent: '当前会话',
112
+ debugFilterAll: '全部会话',
113
+ debugFilterSwitched: '仅切换',
114
+ debugCount: '共 {n} 条',
115
+ debugSubagent: '子',
116
+ debugKindConfig: '设置更新',
117
+ debugKindCapability: '能力声明',
118
+ debugModelDefault: '模型默认',
119
+ debugPurposeAgent: '普通步骤',
120
+ debugPurposeTitle: '会话标题',
121
+ debugPurposeCompaction: '压缩',
122
+ debugPurposeReview: '自动复核',
123
+ debugUnknown: '未知',
124
+ debugSwitch: '切换',
91
125
  enabledRow: '启用插件',
92
126
  enabledHint: '总开关;关闭后不注入 Auto、不改写任何请求。',
93
127
  summary: 'Auto → {auto} · 子代理 → {sub} · 廉价调用 → {aux}',
@@ -149,9 +183,37 @@ window.__ModuleLoader__.load({
149
183
  patternHint: 'For gateway aliases, such as ^deepseek; case insensitive.',
150
184
  declareModelsRow: 'Extra declarations',
151
185
  declareModelsHint: 'One provider/model per line, or a model-id regular expression, for gateways the rules above miss.',
152
- advanced: 'Advanced',
153
- traceRow: 'Write every decision to stderr',
154
- traceHint: 'Diagnostics only; off by default.',
186
+ debugSection: 'Debug',
187
+ debugSectionHint: 'Debugging records but never changes a request: when on, every effort decision appears live in a floating log over the conversation.',
188
+ debugOverlayRow: 'Show the live effort-switch log in the conversation',
189
+ debugOverlayHint: 'A floating debug window appears at the conversation\'s bottom-right corner: each model request\'s purpose, requested depth, and the depth actually sent, including subagent sessions and the Harness\'s cheap calls.',
190
+ debugTraceRow: 'Also write decisions to the Host\'s stderr',
191
+ debugTraceHint: 'For developer diagnostics; not needed for normal use.',
192
+ debugPill: 'Effort debug',
193
+ debugTitle: 'Thinking depth · live switch log',
194
+ debugLive: 'Recording',
195
+ debugPaused: 'Off',
196
+ debugEmpty: 'Waiting for the next model request…',
197
+ debugDisabledOnHost: 'The form has debugging on, but the Host has not registered the debug route. Quit and reopen DeepSeek Harness to load it.',
198
+ debugLoadFailed: 'Could not read the debug log: ',
199
+ debugClear: 'Clear',
200
+ debugCopy: 'Copy',
201
+ debugCopied: 'Copied',
202
+ debugCollapse: 'Collapse',
203
+ debugFilterCurrent: 'This session',
204
+ debugFilterAll: 'All sessions',
205
+ debugFilterSwitched: 'Switches only',
206
+ debugCount: '{n} entries',
207
+ debugSubagent: 'Sub',
208
+ debugKindConfig: 'Settings update',
209
+ debugKindCapability: 'Capability declared',
210
+ debugModelDefault: 'model default',
211
+ debugPurposeAgent: 'Ordinary step',
212
+ debugPurposeTitle: 'Session title',
213
+ debugPurposeCompaction: 'Compaction',
214
+ debugPurposeReview: 'Auto-review',
215
+ debugUnknown: 'Unknown',
216
+ debugSwitch: 'switched',
155
217
  enabledRow: 'Enable this plugin',
156
218
  enabledHint: 'Master switch; when off, no Auto is injected and no request is rewritten.',
157
219
  summary: 'Auto → {auto} · Subagent → {sub} · Cheap calls → {aux}',
@@ -176,7 +238,7 @@ window.__ModuleLoader__.load({
176
238
  const FIELDS = [
177
239
  'enabled', 'declareCapability', 'deepseekHosts', 'deepseekModelPattern',
178
240
  'declareModels', 'efforts', 'defaultEffort', 'autoLevel', 'autoScope',
179
- 'auxDowngrade', 'auxPurposes', 'auxLevel', 'subagentLevel', 'trace',
241
+ 'auxDowngrade', 'auxPurposes', 'auxLevel', 'subagentLevel', 'debugOverlay', 'trace',
180
242
  ];
181
243
 
182
244
  function equal(a, b) {
@@ -264,6 +326,36 @@ window.__ModuleLoader__.load({
264
326
  .dte-details > summary { cursor: pointer; padding: 11px 14px; font-weight: 600; }
265
327
  .dte-details[open] > summary { border-bottom: 1px solid var(--dsw-alias-border-l1); }
266
328
  .dte-details .dte-row:first-of-type { border-top: 0; }
329
+ .dte-dbg-pill { position: fixed; right: 18px; bottom: 92px; z-index: 70; display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px; background: var(--dsw-alias-bg-overlay); color: var(--dsw-alias-label-primary); font: inherit; font-size: 12px; cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, .16); pointer-events: auto; }
330
+ .dte-dbg-pill-count { min-width: 18px; padding: 0 5px; border-radius: 999px; background: color-mix(in srgb, var(--dsw-alias-brand-primary) 16%, transparent); color: var(--dsw-alias-brand-primary); font-variant-numeric: tabular-nums; }
331
+ .dte-dbg-card { position: fixed; right: 18px; bottom: 92px; z-index: 71; display: flex; flex-direction: column; width: min(440px, calc(100vw - 32px)); max-height: min(52vh, 480px); border: 1px solid var(--dsw-alias-border-l1); border-radius: 12px; background: var(--dsw-alias-bg-overlay); color: var(--dsw-alias-label-primary); box-shadow: 0 16px 40px rgba(0, 0, 0, .22); pointer-events: auto; overflow: hidden; }
332
+ .dte-dbg-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2); cursor: grab; user-select: none; }
333
+ .dte-dbg-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dsw-alias-state-idle-primary); flex: none; }
334
+ .dte-dbg-dot-live { background: var(--dsw-alias-state-success-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--dsw-alias-state-success-primary) 22%, transparent); }
335
+ .dte-dbg-title { font-size: 12px; font-weight: 600; }
336
+ .dte-dbg-count { font-size: 11px; color: var(--dsw-alias-label-secondary); }
337
+ .dte-dbg-head-actions { margin-left: auto; display: flex; gap: 4px; }
338
+ .dte-dbg-btn { border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); font: inherit; font-size: 11px; padding: 2px 7px; cursor: pointer; }
339
+ .dte-dbg-btn:hover { color: var(--dsw-alias-label-primary); }
340
+ .dte-dbg-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 7px 12px; border-bottom: 1px solid var(--dsw-alias-border-l1); }
341
+ .dte-dbg-chip { border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px; padding: 2px 9px; font-size: 11px; cursor: pointer; background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-secondary); }
342
+ .dte-dbg-chip-on { border-color: var(--dsw-alias-brand-primary); color: var(--dsw-alias-brand-primary); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 12%, transparent); }
343
+ .dte-dbg-body { flex: 1 1 auto; min-height: 64px; overflow: auto; padding: 4px 0; }
344
+ .dte-dbg-row { padding: 5px 12px; border-left: 2px solid transparent; font-size: 11px; }
345
+ .dte-dbg-row + .dte-dbg-row { border-top: 1px solid color-mix(in srgb, var(--dsw-alias-border-l1) 55%, transparent); }
346
+ .dte-dbg-row-switched { border-left-color: var(--dsw-alias-brand-primary); background: color-mix(in srgb, var(--dsw-alias-brand-primary) 6%, transparent); }
347
+ .dte-dbg-line { display: flex; align-items: baseline; gap: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; overflow: hidden; }
348
+ .dte-dbg-time { color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
349
+ .dte-dbg-badge { flex: none; border-radius: 4px; padding: 0 4px; font-size: 10px; background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 18%, transparent); color: var(--dsw-alias-state-warn-primary); }
350
+ .dte-dbg-purpose { flex: none; color: var(--dsw-alias-label-secondary); }
351
+ .dte-dbg-levels { overflow: hidden; text-overflow: ellipsis; }
352
+ .dte-dbg-levels b { color: var(--dsw-alias-brand-primary); font-weight: 600; }
353
+ .dte-dbg-meta { display: flex; gap: 8px; margin-top: 1px; font-size: 10px; color: var(--dsw-alias-label-secondary); white-space: nowrap; overflow: hidden; }
354
+ .dte-dbg-meta span { overflow: hidden; text-overflow: ellipsis; }
355
+ .dte-dbg-empty { padding: 14px 12px; font-size: 12px; color: var(--dsw-alias-label-secondary); }
356
+ .dte-dbg-note { padding: 8px 12px; font-size: 11px; color: var(--dsw-alias-state-warn-primary); }
357
+ .dte-dbg-foot { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-top: 1px solid var(--dsw-alias-border-l1); font-size: 10px; color: var(--dsw-alias-label-secondary); }
358
+ .dte-dbg-foot-flash { color: var(--dsw-alias-state-success-primary); }
267
359
  @media (max-width: 720px) {
268
360
  .dte-row { grid-template-columns: minmax(0, 1fr); gap: 6px; }
269
361
  .dte-row-hint { grid-column: 1; }
@@ -615,14 +707,24 @@ window.__ModuleLoader__.load({
615
707
  }),
616
708
  ],
617
709
  }),
618
- h('details', { className: 'dte-details' },
619
- h('summary', null, t('advanced')),
620
- Row({
621
- key: 'trace',
622
- label: t('traceRow'),
623
- hint: t('traceHint'),
624
- children: Switch({ checked: current.trace === true, disabled: busy, label: current.trace === true ? t('on') : t('off'), onChange: (next) => patch('trace', next) }),
625
- })),
710
+ Section({
711
+ title: t('debugSection'),
712
+ hint: t('debugSectionHint'),
713
+ children: [
714
+ Row({
715
+ key: 'debugOverlay',
716
+ label: t('debugOverlayRow'),
717
+ hint: t('debugOverlayHint'),
718
+ children: Switch({ checked: current.debugOverlay === true, disabled: busy, label: current.debugOverlay === true ? t('on') : t('off'), onChange: (next) => patch('debugOverlay', next) }),
719
+ }),
720
+ Row({
721
+ key: 'trace',
722
+ label: t('debugTraceRow'),
723
+ hint: t('debugTraceHint'),
724
+ children: Switch({ checked: current.trace === true, disabled: busy, label: current.trace === true ? t('on') : t('off'), onChange: (next) => patch('trace', next) }),
725
+ }),
726
+ ],
727
+ }),
626
728
  h('div', { className: 'dte-footer' },
627
729
  h('button', { className: 'dte-btn dte-btn-primary', disabled: busy || !dirty, onClick: () => void save() }, busy ? t('saving') : t('save')),
628
730
  h('button', { className: 'dte-btn', disabled: busy, onClick: () => void reset() }, t('reset')),
@@ -641,6 +743,391 @@ window.__ModuleLoader__.load({
641
743
  return t('summary', { auto, sub, aux });
642
744
  }
643
745
 
746
+ // ── floating debug log ───────────────────────────────────────────────────
747
+ // The Host keeps the journal (one record per model request, including
748
+ // subagent sessions); this half only polls it while the switch is on and
749
+ // renders it in a movable window over the conversation. Nothing here reads
750
+ // the session log, so the window shows decisions the log cannot carry.
751
+
752
+ function storageGet(key) {
753
+ try {
754
+ return window.localStorage.getItem(key);
755
+ } catch {
756
+ return null;
757
+ }
758
+ }
759
+
760
+ function storageSet(key, value) {
761
+ try {
762
+ window.localStorage.setItem(key, value);
763
+ } catch {
764
+ /* a page without storage keeps its default window placement */
765
+ }
766
+ }
767
+
768
+ function readDebugPos() {
769
+ const text = storageGet(DEBUG_POS_KEY);
770
+ if (typeof text !== 'string' || text === '') return null;
771
+ try {
772
+ const value = JSON.parse(text);
773
+ if (typeof value?.left === 'number' && typeof value?.top === 'number') return { left: value.left, top: value.top };
774
+ } catch {
775
+ /* an unusable saved position falls back to the corner */
776
+ }
777
+ return null;
778
+ }
779
+
780
+ /**
781
+ * Host origin for the debug route: the desktop shell's transport when the
782
+ * page is not served from the Host, otherwise this page's origin.
783
+ * @returns {string|null} origin, or null for a relative URL.
784
+ */
785
+ function debugOrigin() {
786
+ try {
787
+ const transport = globalThis.__DSH_TRANSPORT__;
788
+ if (transport !== null && typeof transport === 'object' && typeof transport.streamBaseUrl === 'string' && transport.streamBaseUrl !== '') {
789
+ return new URL(transport.streamBaseUrl).origin;
790
+ }
791
+ } catch {
792
+ /* fall through to the page origin */
793
+ }
794
+ try {
795
+ if (/^https?:$/.test(window.location.protocol)) return window.location.origin;
796
+ } catch {
797
+ /* no location in a bare test realm */
798
+ }
799
+ return null;
800
+ }
801
+
802
+ /** Fetch through the desktop shell's carrier when one is installed. */
803
+ function debugFetch(url, init) {
804
+ const transport = globalThis.__DSH_TRANSPORT__;
805
+ if (transport !== null && typeof transport === 'object' && typeof transport.fetch === 'function') return transport.fetch(url, init);
806
+ return fetch(url, init);
807
+ }
808
+
809
+ function debugUrl(path, query) {
810
+ const origin = debugOrigin();
811
+ return `${origin === null ? '' : origin}${path}${query ?? ''}`;
812
+ }
813
+
814
+ function clockOf(at) {
815
+ const date = new Date(typeof at === 'number' ? at : Date.now());
816
+ const pad = (value) => String(value).padStart(2, '0');
817
+ return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
818
+ }
819
+
820
+ function purposeLabel(purpose, t) {
821
+ if (purpose === 'agent') return t('debugPurposeAgent');
822
+ if (purpose === 'session-title') return t('debugPurposeTitle');
823
+ if (purpose === 'compaction') return t('debugPurposeCompaction');
824
+ if (purpose === 'auto-review') return t('debugPurposeReview');
825
+ return typeof purpose === 'string' && purpose !== '' ? purpose : t('debugUnknown');
826
+ }
827
+
828
+ function shortModel(model) {
829
+ const text = String(model ?? '');
830
+ return text.length > 26 ? `${text.slice(0, 25)}…` : text;
831
+ }
832
+
833
+ function shortSession(entry) {
834
+ if (typeof entry.title === 'string' && entry.title !== '') return entry.title;
835
+ const id = typeof entry.sessionId === 'string' ? entry.sessionId : '';
836
+ return id.length > 12 ? id.slice(0, 12) : id;
837
+ }
838
+
839
+ function clampNumber(value, low, high) {
840
+ return Math.min(Math.max(value, low), high);
841
+ }
842
+
843
+ /** Subscribe to one config form without the slot framework's helper. */
844
+ function useFormSnapshot(form) {
845
+ const [snapshot, setSnapshot] = React.useState(() => form.getSnapshot());
846
+ React.useEffect(() => {
847
+ setSnapshot(form.getSnapshot());
848
+ const dispose = form.subscribe(() => setSnapshot(form.getSnapshot()));
849
+ return () => {
850
+ if (typeof dispose === 'function') dispose();
851
+ };
852
+ }, [form]);
853
+ return snapshot;
854
+ }
855
+
856
+ /** One line describing the live rules, shown in the window footer. */
857
+ function debugSummary(value, t) {
858
+ const auto = autoDepth(value) ?? '—';
859
+ const sub = value?.subagentLevel === 'inherit' || value?.subagentLevel === undefined
860
+ ? t('inherit')
861
+ : value.subagentLevel === 'auto' ? t('auto') : (LEVEL_LABELS[value.subagentLevel] ?? value.subagentLevel);
862
+ const aux = value?.auxDowngrade === false ? t('off') : (LEVEL_LABELS[value?.auxLevel] ?? value?.auxLevel ?? '—');
863
+ return `Auto ${auto} · ${sub} · ${aux}`;
864
+ }
865
+
866
+ /** The settings snapshot a `volatile` save recorded in the journal. */
867
+ function configText(entry, t) {
868
+ const auto = entry.autoLevel === 'model-default' || entry.autoLevel === undefined ? entry.defaultEffort : entry.autoLevel;
869
+ const sub = entry.subagentLevel === 'inherit' || entry.subagentLevel === undefined ? t('inherit') : entry.subagentLevel;
870
+ const aux = entry.auxDowngrade === false ? t('off') : entry.auxLevel;
871
+ const debug = entry.debugOverlay === true ? t('on') : t('off');
872
+ return `${auto ?? '—'} · ${sub ?? '—'} · ${aux ?? '—'} · ${debug}`;
873
+ }
874
+
875
+ function debugRow(entry, t) {
876
+ const switched = entry?.switched === true;
877
+ const className = `dte-dbg-row${switched ? ' dte-dbg-row-switched' : ''}`;
878
+ if (entry?.kind === 'config') {
879
+ return h('div', { key: entry.seq, className },
880
+ h('div', { className: 'dte-dbg-line' },
881
+ h('span', { className: 'dte-dbg-time' }, clockOf(entry.at)),
882
+ h('span', { className: 'dte-dbg-purpose' }, t('debugKindConfig')),
883
+ h('span', { className: 'dte-dbg-levels' }, configText(entry, t))),
884
+ h('div', { className: 'dte-dbg-meta' },
885
+ h('span', null, `enabled ${entry.enabled === false ? 'off' : 'on'}`)));
886
+ }
887
+ if (entry?.kind === 'capability') {
888
+ const declared = Array.isArray(entry.declared) ? entry.declared : [];
889
+ const efforts = Array.isArray(entry.efforts) ? entry.efforts.join('/') : '—';
890
+ return h('div', { key: entry.seq, className },
891
+ h('div', { className: 'dte-dbg-line' },
892
+ h('span', { className: 'dte-dbg-time' }, clockOf(entry.at)),
893
+ h('span', { className: 'dte-dbg-purpose' }, t('debugKindCapability')),
894
+ h('span', { className: 'dte-dbg-levels' }, `${declared.length} × ${efforts} → ${entry.defaultEffort ?? '—'}`)),
895
+ h('div', { className: 'dte-dbg-meta' },
896
+ h('span', { title: declared.join(', ') }, declared.join(', '))));
897
+ }
898
+ const requested = typeof entry?.requested === 'string' ? entry.requested : t('debugModelDefault');
899
+ const applied = typeof entry?.applied === 'string' ? entry.applied : t('debugModelDefault');
900
+ return h('div', {
901
+ key: entry?.seq,
902
+ className,
903
+ title: `${entry?.provider ?? ''}/${entry?.model ?? ''}`,
904
+ },
905
+ h('div', { className: 'dte-dbg-line' },
906
+ h('span', { className: 'dte-dbg-time' }, clockOf(entry?.at)),
907
+ entry?.subagent === true ? h('span', { className: 'dte-dbg-badge' }, t('debugSubagent')) : null,
908
+ h('span', { className: 'dte-dbg-purpose' }, purposeLabel(entry?.purpose, t)),
909
+ h('span', { className: 'dte-dbg-levels' }, requested, ' → ', h('b', null, applied)),
910
+ entry?.changed === true
911
+ ? h('span', { className: 'dte-dbg-purpose', title: `${entry.from ?? '—'} → ${applied}` }, '⇄')
912
+ : null),
913
+ h('div', { className: 'dte-dbg-meta' },
914
+ h('span', null, shortModel(entry?.model)),
915
+ h('span', { title: entry?.sessionId ?? '' }, shortSession(entry ?? {}))));
916
+ }
917
+
918
+ /**
919
+ * The conversation's floating debug window.
920
+ *
921
+ * Rendered only while `debugOverlay` is on. It polls the Host journal as a
922
+ * delta, keeps a bounded local copy, and groups nothing: the reader wants
923
+ * the raw per-request decision, including subagent sessions, which share
924
+ * the same Host process and therefore the same journal.
925
+ */
926
+ function DebugOverlay({ form, useSessions, t }) {
927
+ const snapshot = useFormSnapshot(form);
928
+ const enabled = snapshot?.status === 'ready' && snapshot.value?.debugOverlay === true;
929
+ // The main-view Session is the one this conversation is showing; the
930
+ // filter also admits its subagent descendants through the durable links.
931
+ const current = typeof useSessions === 'function'
932
+ ? useSessions((state) => {
933
+ const rows = Object.values(state?.byId ?? {});
934
+ for (const row of rows) {
935
+ if (row !== null && typeof row === 'object' && (row.retainedBy?.mainView ?? 0) > 0) return row.id;
936
+ }
937
+ return null;
938
+ })
939
+ : null;
940
+ const [open, setOpen] = React.useState(() => storageGet(DEBUG_OPEN_KEY) === '1');
941
+ const [entries, setEntries] = React.useState([]);
942
+ const [meta, setMeta] = React.useState({ enabled: false, latest: 0, error: null });
943
+ const [filter, setFilter] = React.useState('current');
944
+ const [flash, setFlash] = React.useState(null);
945
+ const [pos, setPos] = React.useState(() => readDebugPos());
946
+ const nextSeq = React.useRef(0);
947
+ const flashTimer = React.useRef(null);
948
+
949
+ React.useEffect(() => () => {
950
+ if (flashTimer.current !== null) window.clearTimeout(flashTimer.current);
951
+ }, []);
952
+
953
+ React.useEffect(() => {
954
+ if (!enabled) return undefined;
955
+ let stopped = false;
956
+ let timer = null;
957
+ const schedule = (delay) => {
958
+ if (!stopped) timer = window.setTimeout(poll, delay);
959
+ };
960
+ const poll = () => {
961
+ debugFetch(debugUrl(DEBUG_PATH, `?since=${String(nextSeq.current)}`), {
962
+ cache: 'no-store',
963
+ headers: { accept: 'application/json' },
964
+ })
965
+ .then((response) => (response.ok ? response.json() : Promise.reject(new Error(`HTTP ${String(response.status)}`))))
966
+ .then((payload) => {
967
+ if (stopped || payload === null || typeof payload !== 'object') return;
968
+ if (payload.enabled === false) {
969
+ setEntries([]);
970
+ setMeta({ enabled: false, latest: 0, error: null });
971
+ nextSeq.current = 0;
972
+ return;
973
+ }
974
+ const reset = payload.reset === true;
975
+ if (reset) setEntries([]);
976
+ const fresh = Array.isArray(payload.entries) ? payload.entries : [];
977
+ if (typeof payload.latest === 'number') nextSeq.current = payload.latest;
978
+ if (fresh.length > 0) {
979
+ setEntries((previous) => [...(reset ? [] : previous), ...fresh].slice(-300));
980
+ }
981
+ setMeta({ enabled: true, latest: typeof payload.latest === 'number' ? payload.latest : 0, error: null });
982
+ })
983
+ .catch((error) => {
984
+ if (!stopped) setMeta((previous) => ({ ...previous, error: String(error?.message ?? error) }));
985
+ })
986
+ .finally(() => {
987
+ schedule(open ? 700 : 2500);
988
+ });
989
+ };
990
+ poll();
991
+ return () => {
992
+ stopped = true;
993
+ if (timer !== null) window.clearTimeout(timer);
994
+ };
995
+ }, [enabled, open]);
996
+
997
+ const flashText = (text) => {
998
+ setFlash(text);
999
+ if (flashTimer.current !== null) window.clearTimeout(flashTimer.current);
1000
+ flashTimer.current = window.setTimeout(() => {
1001
+ flashTimer.current = null;
1002
+ setFlash(null);
1003
+ }, 1800);
1004
+ };
1005
+
1006
+ if (!enabled) return null;
1007
+
1008
+ const visible = entries.filter((entry) => {
1009
+ if (entry?.kind !== 'request') return filter !== 'switched';
1010
+ if (filter === 'switched') return entry.switched === true;
1011
+ if (filter === 'current' && current !== null) {
1012
+ return entry.sessionId === current || entry.parentSession === current || entry.rootSessionId === current;
1013
+ }
1014
+ return true;
1015
+ });
1016
+
1017
+ const copy = () => {
1018
+ const text = visible.map((entry) => {
1019
+ if (entry?.kind === 'request') {
1020
+ return `${clockOf(entry.at)} ${entry.subagent === true ? '[sub]' : '[main]'} ${entry.provider}/${entry.model} ${entry.purpose ?? '-'} ${entry.requested ?? 'default'} -> ${entry.applied ?? 'default'}`;
1021
+ }
1022
+ if (entry?.kind === 'capability') return `${clockOf(entry.at)} [capability] ${(entry.declared ?? []).join(', ')}`;
1023
+ return `${clockOf(entry.at)} [config] ${configText(entry ?? {}, t)}`;
1024
+ }).join('\n');
1025
+ try {
1026
+ const write = navigator.clipboard?.writeText?.(text);
1027
+ if (write !== undefined) write.then(() => flashText(t('debugCopied'))).catch(() => undefined);
1028
+ else flashText(t('debugCopied'));
1029
+ } catch {
1030
+ /* a page without clipboard access simply cannot copy */
1031
+ }
1032
+ };
1033
+
1034
+ const clear = () => {
1035
+ nextSeq.current = 0;
1036
+ setEntries([]);
1037
+ debugFetch(debugUrl(DEBUG_CLEAR_PATH), { method: 'POST', headers: { 'x-think-effort-debug': '1' } }).catch(() => undefined);
1038
+ };
1039
+
1040
+ const collapse = () => {
1041
+ setOpen(false);
1042
+ storageSet(DEBUG_OPEN_KEY, '0');
1043
+ };
1044
+
1045
+ const beginDrag = (event) => {
1046
+ if (event.button !== 0) return;
1047
+ const target = event.target;
1048
+ if (target !== null && typeof target?.closest === 'function' && target.closest('button') !== null) return;
1049
+ const card = event.currentTarget?.parentElement;
1050
+ if (card === null || card === undefined || typeof card.getBoundingClientRect !== 'function') return;
1051
+ const rect = card.getBoundingClientRect();
1052
+ const offset = { x: event.clientX - rect.left, y: event.clientY - rect.top };
1053
+ const move = (moveEvent) => {
1054
+ const maxLeft = Math.max(0, (window.innerWidth || 0) - rect.width - 8);
1055
+ const maxTop = Math.max(0, (window.innerHeight || 0) - 48);
1056
+ setPos({
1057
+ left: clampNumber(moveEvent.clientX - offset.x, 8, maxLeft),
1058
+ top: clampNumber(moveEvent.clientY - offset.y, 8, maxTop),
1059
+ });
1060
+ };
1061
+ const end = () => {
1062
+ window.removeEventListener('pointermove', move);
1063
+ window.removeEventListener('pointerup', end);
1064
+ window.removeEventListener('pointercancel', end);
1065
+ setPos((currentPos) => {
1066
+ if (currentPos !== null) storageSet(DEBUG_POS_KEY, JSON.stringify(currentPos));
1067
+ return currentPos;
1068
+ });
1069
+ };
1070
+ window.addEventListener('pointermove', move);
1071
+ window.addEventListener('pointerup', end);
1072
+ window.addEventListener('pointercancel', end);
1073
+ event.preventDefault();
1074
+ };
1075
+
1076
+ const filterChip = (id, label) => h('button', {
1077
+ type: 'button',
1078
+ key: id,
1079
+ className: 'dte-dbg-chip' + (filter === id ? ' dte-dbg-chip-on' : ''),
1080
+ onClick: () => setFilter(id),
1081
+ }, label);
1082
+
1083
+ if (!open) {
1084
+ return h(React.Fragment, null, h('style', null, styleText()),
1085
+ h('button', {
1086
+ type: 'button',
1087
+ className: 'dte-dbg-pill',
1088
+ title: t('debugPill'),
1089
+ onClick: () => {
1090
+ setOpen(true);
1091
+ storageSet(DEBUG_OPEN_KEY, '1');
1092
+ },
1093
+ },
1094
+ h('span', { className: 'dte-dbg-dot' + (meta.enabled ? ' dte-dbg-dot-live' : '') }),
1095
+ t('debugPill'),
1096
+ entries.length > 0 ? h('span', { className: 'dte-dbg-pill-count' }, String(entries.length)) : null));
1097
+ }
1098
+
1099
+ const style = pos === null
1100
+ ? undefined
1101
+ : { left: `${String(pos.left)}px`, top: `${String(pos.top)}px`, right: 'auto', bottom: 'auto' };
1102
+ return h(React.Fragment, null, h('style', null, styleText()),
1103
+ h('div', { className: 'dte-dbg-card', style },
1104
+ h('div', { className: 'dte-dbg-head', onPointerDown: beginDrag },
1105
+ h('span', { className: 'dte-dbg-dot' + (meta.enabled ? ' dte-dbg-dot-live' : '') }),
1106
+ h('span', { className: 'dte-dbg-title' }, t('debugTitle')),
1107
+ h('span', { className: 'dte-dbg-count' }, t('debugCount', { n: String(visible.length) })),
1108
+ h('div', { className: 'dte-dbg-head-actions' },
1109
+ h('button', { type: 'button', className: 'dte-dbg-btn', onClick: copy }, flash ?? t('debugCopy')),
1110
+ h('button', { type: 'button', className: 'dte-dbg-btn', onClick: clear }, t('debugClear')),
1111
+ h('button', { type: 'button', className: 'dte-dbg-btn', title: t('debugCollapse'), onClick: collapse }, '—'))),
1112
+ h('div', { className: 'dte-dbg-filters' },
1113
+ filterChip('current', t('debugFilterCurrent')),
1114
+ filterChip('all', t('debugFilterAll')),
1115
+ filterChip('switched', t('debugFilterSwitched'))),
1116
+ meta.error !== null
1117
+ ? h('div', { className: 'dte-dbg-note' }, `${t('debugLoadFailed')}${meta.error}`)
1118
+ : null,
1119
+ meta.error === null && meta.enabled !== true
1120
+ ? h('div', { className: 'dte-dbg-note' }, t('debugDisabledOnHost'))
1121
+ : null,
1122
+ h('div', { className: 'dte-dbg-body' },
1123
+ visible.length === 0
1124
+ ? h('div', { className: 'dte-dbg-empty' }, t('debugEmpty'))
1125
+ : [...visible].reverse().map((entry) => debugRow(entry, t))),
1126
+ h('div', { className: 'dte-dbg-foot' },
1127
+ h('span', null, debugSummary(snapshot.value ?? {}, t)),
1128
+ h('span', { style: { marginLeft: 'auto' } }, meta.enabled ? t('debugLive') : t('debugPaused')))));
1129
+ }
1130
+
644
1131
  /**
645
1132
  * The Settings panel's copy of the page.
646
1133
  *
@@ -724,9 +1211,18 @@ window.__ModuleLoader__.load({
724
1211
  id: SECTION_ID,
725
1212
  locale: NS,
726
1213
  }, SectionIcon));
1214
+ // The floating debug log lives in the frame-wide overlay layer, above
1215
+ // every column, and renders only while the debug switch is on. It shares
1216
+ // the one form controller, so the switch it obeys is the same save.
1217
+ const offOverlay = slots.inject('shell.overlay', () => slots.register({
1218
+ name: 'shell.overlay',
1219
+ id: 'think-effort-debug',
1220
+ order: 40,
1221
+ }, (props) => DebugOverlay({ form, useSessions: props.useSessions, t })));
727
1222
  return () => {
728
1223
  offSection();
729
1224
  offIcon();
1225
+ offOverlay();
730
1226
  };
731
1227
  }), 'think-effort: settings entry');
732
1228
  }
package/cordis.patch.yml CHANGED
@@ -42,4 +42,8 @@
42
42
  # Which models offer Auto: all | declared | off.
43
43
  autoScope: all
44
44
  # Subagent calls: inherit | auto | low/high/max. Applies immediately.
45
- subagentLevel: inherit
45
+ subagentLevel: inherit
46
+ # Record every effort decision for the conversation's floating debug
47
+ # log (Settings -> Automatic thinking depth -> Debug). Off by default;
48
+ # turning it on never changes a request.
49
+ debugOverlay: false
package/docs/DETAIL.en.md CHANGED
@@ -8,6 +8,7 @@ Declarative thinking-depth control for DeepSeek (and other) reasoning models: th
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
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.
11
+ 5. **Live debug log.** An optional floating window shows every request's effort decision (requested → sent), subagent sessions included. It records only; it never changes a request.
11
12
 
12
13
  ## Usage
13
14
 
@@ -18,6 +19,17 @@ Declarative thinking-depth control for DeepSeek (and other) reasoning models: th
18
19
 
19
20
  ![The Settings entry](settings-section.png)
20
21
 
22
+ ## Live debug log
23
+
24
+ Turn on **Debug → Show the live effort-switch log in the conversation** and a movable window (the `shell.overlay` seat) appears at the conversation's bottom-right corner, showing:
25
+
26
+ - each model request's time, purpose, requested depth, the depth actually sent, and the model;
27
+ - subagent sessions' decisions (with a `Sub` badge) — a subagent runs in the same Host process and therefore shares the one journal;
28
+ - `Settings update` and `Capability declared` events, so a save's effect is visible;
29
+ - filters for this session, all sessions, and switches only, plus one-click copy.
30
+
31
+ Two halves: the Host half appends each decision, at the adapter boundary, to an **in-memory ring buffer** (300 records at most, never written to the session log or disk) and serves it through two `webServer` routes — a cursor-based read and a clear; the browser half polls only while the switch is on, and keeps the window's position and open state in browser storage. With the switch off the routes answer `enabled: false`, the window disappears, and recording stops.
32
+
21
33
  ## Where the settings page comes from
22
34
 
23
35
  - The row page registers into the plugin manager's `plugins.row.config`, keyed `dsh-think-effort#think-effort`.
@@ -48,6 +60,7 @@ Declarative thinking-depth control for DeepSeek (and other) reasoning models: th
48
60
  | `auxLevel` | `low` | Depth those calls request |
49
61
  | `autoScope` | `all` | `all` / `declared` / `off` |
50
62
  | `subagentLevel` | `inherit` | Subagent depth: `inherit` / `auto` / a fixed depth; a fixed depth overrides the child's own or inherited pick |
63
+ | `debugOverlay` | `false` | Live effort-switch log over the conversation (records only, never rewrites; 300 records in Host memory) |
51
64
  | `trace` | `false` | Write decisions to stderr for diagnosis |
52
65
 
53
66
  ## Diagnostic tool
package/docs/DETAIL.zh.md CHANGED
@@ -8,6 +8,7 @@
8
8
  2. **提供 `Auto`**:在模型目录的档位列表最前面补一个 `Auto`。
9
9
  3. **逐请求解析**:在适配器边界把 `auto` 换成声明默认档;`purpose` 属于廉价调用时换成 `low`(仅当模型声明了它,且**与会话选了什么都无关**——会话标题/图片摘要本来就不继承会话档位);手动选的档位一律原样透传,由 DSH 自己校验。
10
10
  4. **子代理档位**:可给子代理统一指定强度(`inherit` / `auto` / `low`…`max`)。`inherit` 保持 DSH 原生继承;固定档会覆盖子代理自身或从父代理继承的选择,廉价调用的降档仍然优先。
11
+ 5. **实时调试日志**:可选的悬浮窗,展示每次请求的档位决策(请求档位 → 实际档位),包括子代理会话;只记录,不改变任何请求。
11
12
 
12
13
  ## 使用
13
14
 
@@ -18,6 +19,17 @@
18
19
 
19
20
  ![设置面板里的入口](settings-section.png)
20
21
 
22
+ ## 实时调试日志
23
+
24
+ 设置页「调试 → 在会话界面显示实时档位切换日志」打开后,会话右下角出现一个可拖动的悬浮窗(`shell.overlay` 槽位),实时显示:
25
+
26
+ - 每次模型请求的时间、用途、请求档位与实际发送档位、模型;
27
+ - 子代理会话的决策(带「子」标记)——子代理与主会话在同一个 Host 进程里,共用同一份日志;
28
+ - `设置更新` 与 `能力声明` 事件,便于确认保存是否生效;
29
+ - 「当前会话 / 全部会话 / 仅切换」筛选与一键复制。
30
+
31
+ 实现分两半:Host 半边在适配器边界把每条决策写入一个**内存环形缓冲**(最多 300 条,不写会话日志、不落盘),并通过两条 `webServer` 路由提供增量读取与清空;浏览器半边按开关状态轮询,只在打开时请求,窗口位置与展开状态存在浏览器本地。关掉开关后路由返回 `enabled: false`,窗口消失、记录停止。
32
+
21
33
  ## 设置页从哪里来
22
34
 
23
35
  - 插件行页面注册进插件管理器的 `plugins.row.config`,键为 `dsh-think-effort#think-effort`;
@@ -48,6 +60,7 @@
48
60
  | `auxLevel` | `low` | 廉价调用用的档位 |
49
61
  | `autoScope` | `all` | `all` / `declared` / `off` |
50
62
  | `subagentLevel` | `inherit` | 子代理档位:`inherit` / `auto` / 固定档;固定档覆盖子代理自身或继承的选择 |
63
+ | `debugOverlay` | `false` | 会话界面的实时档位切换日志(只记录,不改请求;Host 内存最多 300 条) |
51
64
  | `trace` | `false` | 把决策写到 stderr(排查用) |
52
65
 
53
66
  ## 诊断工具
Binary file
Binary file
package/index.js CHANGED
@@ -49,6 +49,7 @@ import {
49
49
  shouldDeclare,
50
50
  withAutoEffort,
51
51
  } from './src/policy.js';
52
+ import { createDebugJournal, registerDebugRoutes } from './src/debug.js';
52
53
 
53
54
  /** The llm-pi-ai settings entry id in a composed profile. */
54
55
  const PI_AI_NAMESPACE = 'llm-pi-ai';
@@ -88,6 +89,12 @@ export const Config = z.object({
88
89
  auxLevel: z.string().default(DEFAULT_CONFIG.auxLevel).volatile(),
89
90
  /** Subagent-owned calls: `inherit`, `auto`, or a fixed level. */
90
91
  subagentLevel: z.string().default(DEFAULT_CONFIG.subagentLevel).volatile(),
92
+ /**
93
+ * Record every effort decision in a bounded in-memory journal and serve it to
94
+ * the conversation's floating debug log. Off by default; when off the journal
95
+ * stays empty and the routes answer `enabled: false`.
96
+ */
97
+ debugOverlay: z.boolean().default(DEFAULT_CONFIG.debugOverlay).volatile(),
91
98
  /** Diagnostic stderr trace of each decision. */
92
99
  trace: z.boolean().default(false).volatile(),
93
100
  });
@@ -247,6 +254,132 @@ export function apply(ctx, rawConfig) {
247
254
  /** Log de-duplication for per-request decisions. */
248
255
  const logged = new Set();
249
256
 
257
+ // ── debug journal ────────────────────────────────────────────────────────
258
+ // The browser half renders this as a floating log over the conversation.
259
+ // Recording is gated by the live config reference, so the switch costs
260
+ // nothing while it is off and applies on the next request after a save.
261
+ const debugJournal = createDebugJournal();
262
+ const debugOn = () => config.debugOverlay === true;
263
+ /** Session facts for the journal, cached because headers do not change. */
264
+ const debugSessions = new Map();
265
+ /** Last level served per `session|purpose`, so a record can name the switch. */
266
+ const debugLast = new Map();
267
+
268
+ /** Read one live Session header, when the store still holds it. */
269
+ const headerOf = (sessionId) => {
270
+ try {
271
+ return ctx.get('sessions')?.get?.(sessionId)?.header;
272
+ } catch {
273
+ return undefined;
274
+ }
275
+ };
276
+
277
+ /**
278
+ * Describe one request's session for the journal: whether it belongs to a
279
+ * subagent, the durable parent link, and the title when one is known.
280
+ * @param {string} [sessionId] stamped session identity.
281
+ * @returns {object} JSON-safe identity fields.
282
+ */
283
+ const debugSessionFacts = (sessionId) => {
284
+ if (typeof sessionId !== 'string' || sessionId === '') {
285
+ return { sessionId: null, parentSession: null, rootSessionId: null, subagent: false, title: null };
286
+ }
287
+ const cached = debugSessions.get(sessionId);
288
+ if (cached !== undefined) return cached;
289
+ let agent;
290
+ try {
291
+ agent = ctx.get('agents')?.get?.(sessionId);
292
+ } catch {
293
+ agent = undefined;
294
+ }
295
+ const session = agent?.session ?? (() => {
296
+ try {
297
+ return ctx.get('sessions')?.get?.(sessionId);
298
+ } catch {
299
+ return undefined;
300
+ }
301
+ })();
302
+ const header = session?.header;
303
+ const parentSession = typeof header?.parentSession === 'string' ? header.parentSession : null;
304
+ let rootSessionId = sessionId;
305
+ let cursor = header;
306
+ for (let depth = 0; depth < 8 && cursor !== undefined; depth += 1) {
307
+ if (typeof cursor.parentSession !== 'string') {
308
+ rootSessionId = typeof cursor.id === 'string' ? cursor.id : rootSessionId;
309
+ break;
310
+ }
311
+ rootSessionId = cursor.parentSession;
312
+ cursor = headerOf(cursor.parentSession);
313
+ if (cursor === undefined) break;
314
+ }
315
+ let title = null;
316
+ try {
317
+ const snapshot = ctx.get('sessionTitle')?.get?.(session);
318
+ if (typeof snapshot?.title === 'string' && snapshot.title !== '') title = snapshot.title;
319
+ } catch {
320
+ /* a missing title service only costs the label */
321
+ }
322
+ const facts = {
323
+ sessionId,
324
+ parentSession,
325
+ rootSessionId,
326
+ subagent: isSubagentAgent(agent) || header?.origin === 'subagent' || (typeof header?.delegationDepth === 'number' && header.delegationDepth > 0),
327
+ title,
328
+ };
329
+ if (debugSessions.size > 200) debugSessions.clear();
330
+ debugSessions.set(sessionId, facts);
331
+ return facts;
332
+ };
333
+
334
+ /**
335
+ * Append one journal record while the debug switch is on.
336
+ * @param {string} kind record type.
337
+ * @param {object} [fields] JSON-safe fields.
338
+ */
339
+ const debugRecord = (kind, fields) => {
340
+ if (debugOn() !== true) return;
341
+ try {
342
+ debugJournal.record(kind, fields);
343
+ } catch {
344
+ /* a debug record must never break a model request */
345
+ }
346
+ };
347
+
348
+ /**
349
+ * Record one per-request effort decision: what the selection asked for, what
350
+ * the adapter will send, and whether that differs from the previous call of
351
+ * the same session and purpose (the "switch" a reader is looking for).
352
+ * @param {object} input decision facts.
353
+ * @param {string} input.provider route key.
354
+ * @param {string} input.model model id.
355
+ * @param {object} input.options the request options the adapter receives.
356
+ * @param {string} [input.level] the level the plugin applied, if any.
357
+ */
358
+ const debugRequest = ({ provider, model, options, level }) => {
359
+ if (debugOn() !== true) return;
360
+ // An ordinary agent step usually carries no purpose; name it explicitly so
361
+ // the browser half can label it instead of showing "unknown".
362
+ const purpose = typeof options.purpose === 'string' && options.purpose !== '' ? options.purpose : 'agent';
363
+ const requested = typeof options.reasoningEffort === 'string' ? options.reasoningEffort : null;
364
+ const applied = level ?? requested;
365
+ const facts = debugSessionFacts(options.sessionId);
366
+ const key = `${facts.sessionId ?? '-'}|${purpose ?? '-'}`;
367
+ const previous = debugLast.get(key) ?? null;
368
+ if (debugLast.size > 200) debugLast.clear();
369
+ debugLast.set(key, applied);
370
+ debugRecord('request', {
371
+ ...facts,
372
+ provider,
373
+ model,
374
+ purpose,
375
+ requested,
376
+ applied,
377
+ switched: level !== undefined && level !== requested,
378
+ from: previous,
379
+ changed: previous !== null && previous !== applied,
380
+ });
381
+ };
382
+
250
383
  // ── capability declaration ───────────────────────────────────────────────
251
384
  /** Serialize settings writes; a boot burst must not stack whole-section updates. */
252
385
  let syncTail = Promise.resolve();
@@ -269,6 +402,11 @@ export function apply(ctx, rawConfig) {
269
402
  try {
270
403
  await settings.update(PI_AI_NAMESPACE, { providers: plan.section.providers }, section.revision);
271
404
  trace('capability sync: section written');
405
+ debugRecord('capability', {
406
+ declared: plan.declared.map((entry) => `${entry.provider}/${entry.model}`),
407
+ efforts: [...config.efforts],
408
+ defaultEffort: config.defaultEffort,
409
+ });
272
410
  void selfCheck();
273
411
  ctx.logger?.info?.(
274
412
  '[think-effort] declared DeepSeek effort capabilities in %s: %s',
@@ -306,6 +444,7 @@ export function apply(ctx, rawConfig) {
306
444
  efforts: reasoning !== null && typeof reasoning === 'object' ? reasoning.efforts : undefined,
307
445
  defaultEffort: reasoning !== null && typeof reasoning === 'object' ? reasoning.defaultEffort : undefined,
308
446
  }, config);
447
+ debugRequest({ provider, model, options, level });
309
448
  if (level === undefined || level === options.reasoningEffort) return options;
310
449
  const key = `${provider}/${model}/${String(options.purpose ?? '-')}/${level}`;
311
450
  trace('translate: %s/%s purpose=%s requested=%s -> %s', provider, model, String(options.purpose ?? '-'), String(options.reasoningEffort), level);
@@ -393,6 +532,15 @@ export function apply(ctx, rawConfig) {
393
532
  ctx.on('loader/volatile-update', () => {
394
533
  config = readConfig(rawConfig);
395
534
  trace('volatile update: enabled=%s subagentLevel=%s', config.enabled, config.subagentLevel);
535
+ debugRecord('config', {
536
+ enabled: config.enabled,
537
+ debugOverlay: config.debugOverlay,
538
+ autoLevel: config.autoLevel,
539
+ defaultEffort: config.defaultEffort,
540
+ subagentLevel: config.subagentLevel,
541
+ auxDowngrade: config.auxDowngrade,
542
+ auxLevel: config.auxLevel,
543
+ });
396
544
  if (config.enabled === false) return;
397
545
  syncCapabilities();
398
546
  });
@@ -489,6 +637,16 @@ export function apply(ctx, rawConfig) {
489
637
  scope.effect(() => scope.tools.register(statusTool), 'think-effort: status tool');
490
638
  });
491
639
 
640
+ // ── debug routes ─────────────────────────────────────────────────────────
641
+ // The conversation's floating debug log polls these. One effect owns both
642
+ // route registrations, so unloading the bundle removes the endpoints.
643
+ ctx.inject?.(['webServer'], (scope) => {
644
+ scope.effect(() => registerDebugRoutes(scope, {
645
+ journal: debugJournal,
646
+ enabled: () => config.debugOverlay === true,
647
+ }), 'think-effort: debug routes');
648
+ });
649
+
492
650
  // Unload: put every registry entry we replaced back, then retire a durable
493
651
  // `auto` selection so a session cannot keep a mask that no longer resolves
494
652
  // (DSH validates the selection against the model's efforts on every request).
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 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.",
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. A debug switch shows every request's effort decision (subagents included) in a floating log over the conversation.",
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),廉价调用用 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.4.0",
3
+ "version": "0.5.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, give subagents their own depth, drop cheap host-owned calls to Low, and edit every rule on a live visual settings page reachable from both Settings and the Plugins row.",
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, edit every rule on a live visual settings page, and watch each request's effort decision live in a floating debug log over the conversation.",
6
6
  "icon": "./icon.svg",
7
7
  "license": "MIT",
8
8
  "author": "mhlywxl",
@@ -14,7 +14,9 @@
14
14
  "thinking-level",
15
15
  "deepseek",
16
16
  "subagent",
17
- "settings-page"
17
+ "settings-page",
18
+ "debug-overlay",
19
+ "live-log"
18
20
  ],
19
21
  "exports": {
20
22
  ".": "./index.js",
package/src/debug.js ADDED
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Opt-in debug journal and the Host routes that serve it to the browser half.
3
+ *
4
+ * <h2>Why a journal instead of a log line</h2>
5
+ *
6
+ * The plugin already writes each decision to the Host log (`trace`). A person
7
+ * watching the conversation cannot see that log, and the interesting event —
8
+ * "this request asked for `auto` and went out as `max`" — is produced per model
9
+ * request inside the adapter facade. So the Host half appends every decision to
10
+ * a small in-memory ring buffer while the debug switch is on, and the browser
11
+ * half polls these routes and renders the buffer as a floating log over the
12
+ * conversation (including subagent sessions, which share the one Host process).
13
+ *
14
+ * <h2>Contract</h2>
15
+ *
16
+ * - The journal is a bounded ring buffer of JSON-safe records; it lives only in
17
+ * Host memory and never touches the session log, so turning the switch off
18
+ * leaves no trace and no migration behind.
19
+ * - Every route answers `enabled: false` while the switch is off. The switch is
20
+ * the live config reference, so the browser half notices a save immediately.
21
+ * - Reads are `GET …?since=<seq>`; the answer is a delta plus the buffer's
22
+ * current bounds, so a client that fell behind can discard its view instead of
23
+ * showing a gap. `POST …/clear` empties the buffer (guarded by a header, so a
24
+ * cross-site form post cannot reach it).
25
+ *
26
+ * @module dsh-think-effort/debug
27
+ */
28
+
29
+ /** Exact route the browser half polls. */
30
+ export const DEBUG_PATH = '/think-effort/debug';
31
+ /** Exact route that empties the journal. */
32
+ export const DEBUG_CLEAR_PATH = '/think-effort/debug/clear';
33
+ /** Header a clear request must carry, so a cross-site form post cannot reach it. */
34
+ export const DEBUG_CLEAR_HEADER = 'x-think-effort-debug';
35
+ /** Records kept before the oldest ones are dropped. */
36
+ export const DEBUG_LIMIT = 300;
37
+
38
+ /** JSON response helper for a raw Node route handler. */
39
+ function sendJson(response, status, body) {
40
+ const text = JSON.stringify(body);
41
+ const headers = {
42
+ 'content-type': 'application/json; charset=utf-8',
43
+ 'cache-control': 'no-store',
44
+ 'content-length': String(Buffer.byteLength(text)),
45
+ };
46
+ if (typeof response.writeHead === 'function') response.writeHead(status, headers);
47
+ response.end(text);
48
+ }
49
+
50
+ /**
51
+ * Whether a request comes from this application's own page.
52
+ *
53
+ * The custom route sits outside the `/api` bridge, so it has no cookie
54
+ * authentication of its own. Browsers send `Sec-Fetch-Site` on every request
55
+ * they make; a cross-site request is refused, while a missing header (an older
56
+ * engine, or the desktop page's own transport) is admitted — the Host binds to
57
+ * loopback in every shipped composition.
58
+ * @param {object} request Node request.
59
+ * @returns {boolean} true when the request may read the journal.
60
+ */
61
+ function sameOrigin(request) {
62
+ const site = request?.headers?.['sec-fetch-site'];
63
+ return typeof site !== 'string' || site === 'same-origin' || site === 'none';
64
+ }
65
+
66
+ /**
67
+ * Create the bounded in-memory journal.
68
+ * @param {object} [options] overrides for tests.
69
+ * @param {number} [options.limit] records to keep.
70
+ * @param {() => number} [options.now] clock, so records are deterministic in tests.
71
+ * @returns {object} the journal.
72
+ */
73
+ export function createDebugJournal({ limit = DEBUG_LIMIT, now = () => Date.now() } = {}) {
74
+ /** @type {Array<object>} */
75
+ const records = [];
76
+ /** Monotone sequence; survives `clear()` so a client's cursor never replays. */
77
+ let seq = 0;
78
+
79
+ return {
80
+ /** Highest sequence ever appended. */
81
+ get latest() {
82
+ return seq;
83
+ },
84
+ /** Records currently buffered. */
85
+ get size() {
86
+ return records.length;
87
+ },
88
+ /**
89
+ * Append one record.
90
+ * @param {string} kind record type: `request`, `config` or `capability`.
91
+ * @param {object} [fields] JSON-safe fields of the record.
92
+ * @returns {number} the record's sequence number.
93
+ */
94
+ record(kind, fields = {}) {
95
+ seq += 1;
96
+ records.push({ seq, at: now(), kind, ...fields });
97
+ if (records.length > limit) records.splice(0, records.length - limit);
98
+ return seq;
99
+ },
100
+ /**
101
+ * Read the records after a cursor.
102
+ * @param {number} [since] last sequence the caller already has.
103
+ * @returns {{latest: number, oldest: number|null, reset: boolean, entries: object[]}} the delta.
104
+ */
105
+ snapshot(since = 0) {
106
+ const cursor = Number.isFinite(since) && since > 0 ? Math.floor(since) : 0;
107
+ const oldest = records.length > 0 ? records[0].seq : null;
108
+ // The cursor names a record the buffer no longer holds: the caller must
109
+ // replace its view instead of appending a delta with a hole in it.
110
+ const reset = cursor > 0 && oldest !== null && cursor + 1 < oldest;
111
+ return {
112
+ latest: seq,
113
+ oldest,
114
+ reset,
115
+ entries: records.filter((entry) => entry.seq > cursor),
116
+ };
117
+ },
118
+ /** Empty the buffer; the sequence keeps counting so clients stay consistent. */
119
+ clear() {
120
+ records.length = 0;
121
+ return seq;
122
+ },
123
+ };
124
+ }
125
+
126
+ /**
127
+ * Register the debug routes on the Host web server.
128
+ *
129
+ * The plugin owns both routes through one Cordis effect, so disabling the bundle
130
+ * removes the endpoints instead of leaving live handlers behind.
131
+ *
132
+ * @param {object} webCtx context providing `webServer`.
133
+ * @param {object} options wiring.
134
+ * @param {object} options.journal the journal to serve.
135
+ * @param {() => boolean} options.enabled live debug switch.
136
+ * @returns {() => void} disposer removing both routes.
137
+ */
138
+ export function registerDebugRoutes(webCtx, { journal, enabled }) {
139
+ const disposers = [];
140
+ try {
141
+ disposers.push(webCtx.webServer.register({
142
+ kind: 'exact',
143
+ path: DEBUG_PATH,
144
+ handler(request, response) {
145
+ if (request.method !== 'GET' && request.method !== 'HEAD') {
146
+ sendJson(response, 405, { ok: false, error: 'method' });
147
+ return;
148
+ }
149
+ if (!sameOrigin(request)) {
150
+ sendJson(response, 403, { ok: false, error: 'origin' });
151
+ return;
152
+ }
153
+ if (enabled() !== true) {
154
+ sendJson(response, 200, { ok: true, enabled: false, latest: journal.latest, oldest: null, reset: false, entries: [] });
155
+ return;
156
+ }
157
+ let since = 0;
158
+ try {
159
+ const url = new URL(String(request.url ?? '/'), 'http://dsh.invalid');
160
+ since = Number(url.searchParams.get('since') ?? '0');
161
+ } catch {
162
+ /* an unparseable URL reads from the beginning */
163
+ }
164
+ sendJson(response, 200, { ok: true, enabled: true, ...journal.snapshot(since) });
165
+ },
166
+ }));
167
+ disposers.push(webCtx.webServer.register({
168
+ kind: 'exact',
169
+ path: DEBUG_CLEAR_PATH,
170
+ handler(request, response) {
171
+ if (request.method !== 'POST') {
172
+ sendJson(response, 405, { ok: false, error: 'method' });
173
+ return;
174
+ }
175
+ if (!sameOrigin(request) || request.headers?.[DEBUG_CLEAR_HEADER] !== '1') {
176
+ sendJson(response, 403, { ok: false, error: 'origin' });
177
+ return;
178
+ }
179
+ sendJson(response, 200, { ok: true, latest: journal.clear() });
180
+ },
181
+ }));
182
+ } catch (error) {
183
+ for (const dispose of disposers) dispose?.();
184
+ throw error;
185
+ }
186
+ return () => {
187
+ for (const dispose of disposers) dispose?.();
188
+ };
189
+ }
package/src/policy.js CHANGED
@@ -92,6 +92,8 @@ export const DEFAULT_CONFIG = {
92
92
  * id forces that depth (clamped to the model's declared vocabulary).
93
93
  */
94
94
  subagentLevel: 'inherit',
95
+ /** Record every effort decision for the conversation's floating debug log. */
96
+ debugOverlay: false,
95
97
  /** Diagnostic stderr trace of each decision. */
96
98
  trace: false,
97
99
  };