dsh-think-effort 0.3.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/client.js CHANGED
@@ -1,11 +1,20 @@
1
1
  /**
2
2
  * Browser half of `dsh-think-effort`: the visual settings page for one row.
3
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.
4
+ * The page renders in two places, from one form:
5
+ *
6
+ * - the Plugins page's `plugins.row.config` slot, keyed by
7
+ * `<package name>#<row id>`, so the bundle's row gains a Configure control;
8
+ * - the Settings panel's `settings.section` slot, so the same options are
9
+ * reachable where a person looks for settings instead of only behind a
10
+ * bundle row.
11
+ *
6
12
  * The page owner supplies `form`: the accepted Host values of this row plus one
7
13
  * revision-fenced `mutate`. Every field is volatile, so saving writes the
8
- * profile patch and the running policy follows without a restart.
14
+ * profile patch and the running policy follows without a restart. The Settings
15
+ * entry reads the row's settings namespace through `configForms` and exists
16
+ * only while the Host serves it, so a deployment without this row shows no
17
+ * trace of the page.
9
18
  *
10
19
  * The layout follows the desktop reference implementation: purpose rows
11
20
  * (ordinary step, subagent, cheap calls) over a shared effort vocabulary, with
@@ -20,11 +29,24 @@ window.__ModuleLoader__.load({
20
29
  const h = React.createElement;
21
30
 
22
31
  const NS = 'think-effort';
23
- const ROW_KEY = 'dsh-think-effort#think-effort';
32
+ /** The bundle row this page belongs to; the row id is also the Host settings namespace. */
33
+ const ROW_ID = 'think-effort';
34
+ const ROW_KEY = `dsh-think-effort#${ROW_ID}`;
35
+ /** Settings navigation section id; the shell pairs it with the icon of the same id. */
36
+ const SECTION_ID = 'think-effort';
37
+ /** Right after the built-in Plugins section (order 15): the plugin's own options. */
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';
24
45
  const EFFORT_ORDER = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
25
46
  const KNOWN_PURPOSES = ['session-title', 'compaction', 'auto-review'];
26
47
 
27
48
  const zh = {
49
+ nav: '自动思考档位',
28
50
  intro: '按“用途”分配推理强度:普通步骤、子代理、Harness 自己的廉价调用。改动即时生效,不需要重启。',
29
51
  loading: '正在读取插件配置…',
30
52
  unavailable: '这个部署没有提供可编辑的插件配置(设置服务未挂载,或该行没有可实时编辑的字段)。',
@@ -69,9 +91,37 @@ window.__ModuleLoader__.load({
69
91
  patternHint: '网关别名用,例如 ^deepseek;不区分大小写。',
70
92
  declareModelsRow: '额外声明',
71
93
  declareModelsHint: '每行一个 provider/model,或一个模型 ID 正则;用于没有匹配到上面两条规则的网关。',
72
- advanced: '高级',
73
- traceRow: '把每次决策写到 stderr',
74
- 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: '切换',
75
125
  enabledRow: '启用插件',
76
126
  enabledHint: '总开关;关闭后不注入 Auto、不改写任何请求。',
77
127
  summary: 'Auto → {auto} · 子代理 → {sub} · 廉价调用 → {aux}',
@@ -88,6 +138,7 @@ window.__ModuleLoader__.load({
88
138
  };
89
139
 
90
140
  const en = {
141
+ nav: 'Automatic thinking depth',
91
142
  intro: 'Assign thinking depth by purpose: ordinary steps, subagents, and the Harness\'s own cheap calls. Changes apply immediately, without a restart.',
92
143
  loading: 'Reading plugin configuration…',
93
144
  unavailable: 'This deployment exposes no editable plugin configuration (the settings service is not mounted, or this row has no live fields).',
@@ -132,9 +183,37 @@ window.__ModuleLoader__.load({
132
183
  patternHint: 'For gateway aliases, such as ^deepseek; case insensitive.',
133
184
  declareModelsRow: 'Extra declarations',
134
185
  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.',
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',
138
217
  enabledRow: 'Enable this plugin',
139
218
  enabledHint: 'Master switch; when off, no Auto is injected and no request is rewritten.',
140
219
  summary: 'Auto → {auto} · Subagent → {sub} · Cheap calls → {aux}',
@@ -159,7 +238,7 @@ window.__ModuleLoader__.load({
159
238
  const FIELDS = [
160
239
  'enabled', 'declareCapability', 'deepseekHosts', 'deepseekModelPattern',
161
240
  'declareModels', 'efforts', 'defaultEffort', 'autoLevel', 'autoScope',
162
- 'auxDowngrade', 'auxPurposes', 'auxLevel', 'subagentLevel', 'trace',
241
+ 'auxDowngrade', 'auxPurposes', 'auxLevel', 'subagentLevel', 'debugOverlay', 'trace',
163
242
  ];
164
243
 
165
244
  function equal(a, b) {
@@ -247,6 +326,36 @@ window.__ModuleLoader__.load({
247
326
  .dte-details > summary { cursor: pointer; padding: 11px 14px; font-weight: 600; }
248
327
  .dte-details[open] > summary { border-bottom: 1px solid var(--dsw-alias-border-l1); }
249
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); }
250
359
  @media (max-width: 720px) {
251
360
  .dte-row { grid-template-columns: minmax(0, 1fr); gap: 6px; }
252
361
  .dte-row-hint { grid-column: 1; }
@@ -598,14 +707,24 @@ window.__ModuleLoader__.load({
598
707
  }),
599
708
  ],
600
709
  }),
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
- })),
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
+ }),
609
728
  h('div', { className: 'dte-footer' },
610
729
  h('button', { className: 'dte-btn dte-btn-primary', disabled: busy || !dirty, onClick: () => void save() }, busy ? t('saving') : t('save')),
611
730
  h('button', { className: 'dte-btn', disabled: busy, onClick: () => void reset() }, t('reset')),
@@ -624,6 +743,422 @@ window.__ModuleLoader__.load({
624
743
  return t('summary', { auto, sub, aux });
625
744
  }
626
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
+
1131
+ /**
1132
+ * The Settings panel's copy of the page.
1133
+ *
1134
+ * The Plugins page receives `form` from its row owner; a Settings section
1135
+ * is owned by the shell and receives only `close`, so this copy reads the
1136
+ * row's settings form from the `configForms` service. Both surfaces share
1137
+ * that one form, so an edit belongs to the same profile write either way.
1138
+ */
1139
+ function SettingsSection({ useConfig, mutate, t }) {
1140
+ const state = useConfig((snapshot) => snapshot);
1141
+ const form = React.useMemo(() => ({ state, mutate }), [state, mutate]);
1142
+ return Page({ form, t });
1143
+ }
1144
+
1145
+ /** Settings navigation glyph: a gauge arc with a needle, matching the bundle icon's motif. */
1146
+ function SectionIcon({ size }) {
1147
+ return h('svg', {
1148
+ viewBox: '0 0 24 24',
1149
+ width: size,
1150
+ height: size,
1151
+ fill: 'none',
1152
+ stroke: 'currentColor',
1153
+ strokeWidth: 1.8,
1154
+ strokeLinecap: 'round',
1155
+ 'aria-hidden': 'true',
1156
+ },
1157
+ h('path', { d: 'M4.5 16.5a7.5 7.5 0 1 1 15 0' }),
1158
+ h('path', { d: 'M12 16.5 16 11.5' }),
1159
+ h('circle', { cx: 12, cy: 16.5, r: 1.6, fill: 'currentColor', stroke: 'none' }));
1160
+ }
1161
+
627
1162
  function apply(ctx) {
628
1163
  const locale = ctx.get('locale');
629
1164
  if (locale !== undefined) {
@@ -648,8 +1183,50 @@ window.__ModuleLoader__.load({
648
1183
  }, (props) => props.view === 'summary'
649
1184
  ? Summary({ form: props.form, t })
650
1185
  : Page({ form: props.form, t })));
1186
+ // The same form under Settings: a bundle row alone is too hidden a home
1187
+ // for a plugin's options. The entry exists only while the Host serves
1188
+ // this row's settings namespace, so a profile without the row (or one
1189
+ // whose row exposes no volatile fields) shows no trace of the page.
1190
+ ctx.effect(() => ctx.configForms.whileServed([ROW_ID], () => {
1191
+ const form = ctx.configForms.get(ROW_ID);
1192
+ const offSection = slots.inject('settings.section', () => slots.register({
1193
+ name: 'settings.section',
1194
+ id: SECTION_ID,
1195
+ order: SECTION_ORDER,
1196
+ label: () => t('nav'),
1197
+ locale: NS,
1198
+ inject: () => ({
1199
+ mutate: (ops, revision) => form.mutate(ops, revision),
1200
+ hooks: {
1201
+ config: {
1202
+ getSnapshot: () => form.getSnapshot(),
1203
+ subscribe: (listener) => form.subscribe(listener),
1204
+ },
1205
+ },
1206
+ t,
1207
+ }),
1208
+ }, SettingsSection));
1209
+ const offIcon = slots.inject('settings.section.icon', () => slots.register({
1210
+ name: 'settings.section.icon',
1211
+ id: SECTION_ID,
1212
+ locale: NS,
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 })));
1222
+ return () => {
1223
+ offSection();
1224
+ offIcon();
1225
+ offOverlay();
1226
+ };
1227
+ }), 'think-effort: settings entry');
651
1228
  }
652
1229
 
653
- return { inject: ['slots', 'locale'], apply };
1230
+ return { inject: ['slots', 'locale', 'configForms'], apply };
654
1231
  },
655
1232
  });