@philomelcc/dsh-workbench 0.1.8 → 0.1.10

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.
Files changed (5) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -0
  3. package/client.js +313 -25
  4. package/index.js +44 -6
  5. package/package.json +19 -5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 philomelcc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  外壳本体:顶部第二行的标签切换、每个模块一整页,以及模块注册用的那套小 API。
4
4
 
5
+ ## 0.1.9 的变化
6
+
7
+ - 新增**功能开关**和**工作台设置页**(系统栏最左侧的 mark 图标):主题切换、余额显示、重启按钮、进行中光效、单次消耗估计,都能单独关掉。
8
+ - 顶部第一行系统栏改为**镜像原生侧栏导航项**,任何注册 `sidebar.panellist` 的插件都会自动出现。
9
+ - 模块支持**无外壳运行**:没有工作台时自己注册到原生侧栏。
10
+ - 设置入口挪到左上角,工作台图标重绘为「带标签栏的面板」;`apiVersion` 仍是 `1`。
11
+
12
+ 完整变更见 [CHANGELOG](https://github.com/philomelcc/dsh-workbench/blob/main/CHANGELOG.md)。
13
+
5
14
  它单独装没什么用——至少配一个模块:
6
15
 
7
16
  ```powershell
package/client.js CHANGED
@@ -21,6 +21,61 @@ window.__ModuleLoader__.load({
21
21
  labelSecondary: 'var(--dsw-alias-label-secondary)',
22
22
  };
23
23
 
24
+ // ---------- feature switches ----------
25
+ // The shell is optional decoration on top of the navigation layer: someone
26
+ // who only wants the tab row can turn the rest off and let another plugin
27
+ // own balances, themes or cost estimates. Every switch defaults to on, so
28
+ // installing the shell keeps the previous behaviour.
29
+ const FEATURE_KEYS = ['theme', 'balance', 'restart', 'glow', 'cost'];
30
+ const FEATURE_DEFAULTS = { theme: true, balance: true, restart: true, glow: true, cost: true };
31
+ const FEATURE_LABELS = {
32
+ theme: { title: '主题切换', hint: '顶部栏的深色 / 浅色 / 纸色三个色块' },
33
+ balance: { title: '余额显示', hint: '顶部栏的账户余额' },
34
+ restart: { title: '重启按钮', hint: '顶部栏的一键重启(需要外部管理器)' },
35
+ glow: { title: '进行中光效', hint: '会话运行中时列表行的流动光效' },
36
+ cost: { title: '单次消耗估计', hint: '每轮对话结束时显示的 token 与费用估算' },
37
+ };
38
+
39
+ function createFeaturesStore() {
40
+ const KEY = 'dsh-workbench:features';
41
+ const listeners = new Set();
42
+ let state = read();
43
+
44
+ function read() {
45
+ const next = { ...FEATURE_DEFAULTS };
46
+ try {
47
+ const raw = localStorage.getItem(KEY);
48
+ if (raw) {
49
+ const parsed = JSON.parse(raw);
50
+ for (const key of FEATURE_KEYS) {
51
+ if (typeof parsed[key] === 'boolean') next[key] = parsed[key];
52
+ }
53
+ }
54
+ } catch (_error) { /* storage disabled */ }
55
+ return next;
56
+ }
57
+
58
+ return {
59
+ getSnapshot() { return state; },
60
+ set(key, value) {
61
+ if (!FEATURE_KEYS.includes(key) || state[key] === value) return;
62
+ state = { ...state, [key]: value };
63
+ try { localStorage.setItem(KEY, JSON.stringify(state)); } catch (_error) { /* storage disabled */ }
64
+ for (const fn of listeners) fn();
65
+ },
66
+ subscribe(fn) {
67
+ listeners.add(fn);
68
+ return () => { listeners.delete(fn); };
69
+ },
70
+ };
71
+ }
72
+
73
+ const features = createFeaturesStore();
74
+
75
+ function useFeatures() {
76
+ return React.useSyncExternalStore(features.subscribe, features.getSnapshot);
77
+ }
78
+
24
79
  // ---------- shared UI primitives ----------
25
80
  function StatusDot(props) {
26
81
  const ok = props.ok !== false;
@@ -246,16 +301,30 @@ window.__ModuleLoader__.load({
246
301
  return api;
247
302
  }
248
303
 
249
- // ---------- workbench icon ----------
250
- function WorkbenchIcon(props) {
304
+ // ---------- settings icon & page ----------
305
+ const SETTINGS_VIEW_ID = 'workbench-settings';
306
+
307
+ // A panel with its own tab strip: the workbench's mark, distinct from the
308
+ // native "More" grid (four squares) so the two do not read alike.
309
+ function IconWorkbenchTabs(props) {
251
310
  const size = props.size || 20;
252
- return h('svg', {
253
- viewBox: '0 0 24 24', width: size, height: size, 'aria-hidden': true, fill: 'none',
254
- },
255
- h('rect', { x: 3.5, y: 3.5, width: 7, height: 7, rx: 1.6, stroke: 'currentColor', strokeWidth: 1.5 }),
256
- h('rect', { x: 13.5, y: 3.5, width: 7, height: 7, rx: 1.6, stroke: 'currentColor', strokeWidth: 1.5 }),
257
- h('rect', { x: 3.5, y: 13.5, width: 7, height: 7, rx: 1.6, stroke: 'currentColor', strokeWidth: 1.5 }),
258
- h('rect', { x: 13.5, y: 13.5, width: 7, height: 7, rx: 1.6, stroke: 'currentColor', strokeWidth: 1.5 }),
311
+ return h('svg', { viewBox: '0 0 24 24', width: size, height: size, 'aria-hidden': true, fill: 'none' },
312
+ h('rect', { x: 3.5, y: 4.5, width: 17, height: 15, rx: 2.5, stroke: 'currentColor', strokeWidth: 1.5 }),
313
+ h('path', { d: 'M3.5 9.2h17', stroke: 'currentColor', strokeWidth: 1.4 }),
314
+ h('circle', { cx: 6.4, cy: 6.85, r: 0.85, fill: 'currentColor' }),
315
+ h('circle', { cx: 9.4, cy: 6.85, r: 0.85, fill: 'currentColor' }),
316
+ h('path', { d: 'M6.2 13.2h5.6M6.2 16h8.4', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' }),
317
+ );
318
+ }
319
+
320
+ function IconSettings(props) {
321
+ const size = props.size || 20;
322
+ return h('svg', { viewBox: '0 0 24 24', width: size, height: size, 'aria-hidden': true, fill: 'none' },
323
+ h('circle', { cx: 12, cy: 12, r: 3.2, stroke: 'currentColor', strokeWidth: 1.5 }),
324
+ h('path', {
325
+ d: 'M19.4 13.5a7.7 7.7 0 0 0 0-3l1.7-1.2-1.9-3.3-2 .8a7.6 7.6 0 0 0-2.6-1.5L14.3 3h-3.8l-.3 2.3a7.6 7.6 0 0 0-2.6 1.5l-2-.8-1.9 3.3 1.7 1.2a7.7 7.7 0 0 0 0 3l-1.7 1.2 1.9 3.3 2-.8a7.6 7.6 0 0 0 2.6 1.5l.3 2.3h3.8l.3-2.3a7.6 7.6 0 0 0 2.6-1.5l2 .8 1.9-3.3z',
326
+ stroke: 'currentColor', strokeWidth: 1.4, strokeLinejoin: 'round',
327
+ }),
259
328
  );
260
329
  }
261
330
 
@@ -311,8 +380,112 @@ window.__ModuleLoader__.load({
311
380
  // ────────────────────────── top bar (stage 1) ──────────────────────────
312
381
  const TOPBAR_HEIGHT = 102;
313
382
 
383
+ // ---------- settings page ----------
384
+ // Reachable from the gear in the system bar. Two jobs: turn the shell's own
385
+ // extras on or off, and show which modules registered a page.
386
+ function WorkbenchSettings() {
387
+ const enabled = useFeatures();
388
+ const reg = useRegistry();
389
+ // Only tabbed modules belong here: the shell's own overview and this
390
+ // settings page live in the system bar, not in the module row.
391
+ const views = Array.from(reg.views.values())
392
+ .filter((item) => item.tab !== false)
393
+ .sort((a, b) => a.order - b.order);
394
+
395
+ function toggleRow(key) {
396
+ const meta = FEATURE_LABELS[key];
397
+ const on = enabled[key];
398
+ return h('div', {
399
+ key,
400
+ style: {
401
+ display: 'flex', alignItems: 'center', gap: 14,
402
+ padding: '12px 14px', borderBottom: '1px solid ' + tokens.border1,
403
+ },
404
+ },
405
+ h('div', { style: { flex: '1 1 auto', minWidth: 0 } },
406
+ h('div', { style: { fontWeight: 550 } }, meta.title),
407
+ h('div', { style: { fontSize: 11, color: tokens.labelSecondary } }, meta.hint),
408
+ ),
409
+ h('button', {
410
+ type: 'button',
411
+ role: 'switch',
412
+ 'aria-checked': on ? 'true' : 'false',
413
+ 'aria-label': meta.title,
414
+ onClick: () => features.set(key, !on),
415
+ style: {
416
+ position: 'relative', width: 40, height: 22, borderRadius: 999,
417
+ border: '1px solid ' + (on ? 'var(--dsw-alias-brand-primary)' : tokens.border2),
418
+ background: on ? 'var(--dsw-alias-brand-primary)' : tokens.bgLayer2,
419
+ cursor: 'pointer', flex: '0 0 auto', padding: 0,
420
+ transition: 'background .15s, border-color .15s',
421
+ },
422
+ },
423
+ h('span', {
424
+ 'aria-hidden': true,
425
+ style: {
426
+ position: 'absolute', top: 2, left: on ? 20 : 2,
427
+ width: 16, height: 16, borderRadius: '50%',
428
+ background: on ? '#fff' : 'var(--dsw-alias-label-secondary)',
429
+ transition: 'left .15s',
430
+ },
431
+ }),
432
+ ),
433
+ );
434
+ }
435
+
436
+ function viewRow(item) {
437
+ return h('div', {
438
+ key: item.id,
439
+ style: {
440
+ display: 'flex', alignItems: 'center', gap: 10,
441
+ padding: '10px 14px', borderBottom: '1px solid ' + tokens.border1,
442
+ },
443
+ },
444
+ h('div', { style: { width: 22, height: 22, color: tokens.labelSecondary, flex: '0 0 auto', display: 'flex', alignItems: 'center', justifyContent: 'center' } },
445
+ item.icon ? h(item.icon, { size: 18, active: false }) : null),
446
+ h('div', { style: { flex: '1 1 auto', minWidth: 0 } },
447
+ h('div', { style: { fontWeight: 550, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, item.title),
448
+ h('div', { style: { fontSize: 11, color: tokens.labelSecondary } },
449
+ (item.tab === false ? '无标签页 · ' : '标签页 · ') + item.id + ' · order ' + item.order),
450
+ ),
451
+ );
452
+ }
453
+
454
+ return h('div', {
455
+ style: {
456
+ padding: '24px 28px', maxWidth: 920, margin: '0 auto', height: '100%',
457
+ boxSizing: 'border-box', overflowY: 'auto',
458
+ color: tokens.label, background: tokens.bgBase,
459
+ },
460
+ },
461
+ h('h2', { style: { margin: '0 0 4px', fontSize: 20, fontWeight: 650 } }, '工作台设置'),
462
+ h('div', { style: { fontSize: 13, color: tokens.labelSecondary, marginBottom: 20 } },
463
+ '只想要导航分层的话,上面这些都可以关掉,交给别的插件。'),
464
+ h('div', null,
465
+ h(SectionHeader, { title: '功能', subtitle: '外壳自带、可以单独关闭的额外功能' }),
466
+ h(Card, null, FEATURE_KEYS.map(toggleRow)),
467
+ ),
468
+ h('div', { style: { marginTop: 20 } },
469
+ h(SectionHeader, { title: '已注册的模块', subtitle: '它们出现在顶部第二行的模块栏' }),
470
+ h(Card, null,
471
+ views.length === 0
472
+ ? h(EmptyState, { text: '还没有模块注册页面。' })
473
+ : views.map(viewRow),
474
+ ),
475
+ ),
476
+ );
477
+ }
478
+
314
479
  async function restartDsh() {
315
- try { await fetch('/wb/workbench/restart', { method: 'POST' }); } catch (_e) {}
480
+ try {
481
+ const res = await fetch('/wb/workbench/restart', { method: 'POST' });
482
+ const json = await res.json().catch(() => null);
483
+ if (json && json.ok === false) {
484
+ window.alert(json.hint || '这台机器上没有可用的重启管理器,请手动重启 DSH Web。');
485
+ }
486
+ } catch (_error) {
487
+ /* offline: nothing to do */
488
+ }
316
489
  }
317
490
 
318
491
  function createBalanceStore(ctx) {
@@ -665,8 +838,74 @@ window.__ModuleLoader__.load({
665
838
  return ThemeSwitcher;
666
839
  }
667
840
 
841
+ // ---------- native sidebar panel mirror ----------
842
+ // The workbench keeps no navigation list of its own: whatever the sidebar
843
+ // lists (Plugins, Automations, More — plus any plugin that registers a
844
+ // panel later) is mirrored into the top bar, click delegated to that row.
845
+ function createPanelMirror() {
846
+ function PanelMirror() {
847
+ const [items, setItems] = React.useState(function () { return []; });
848
+
849
+ React.useEffect(function () {
850
+ function sync() {
851
+ const list = document.querySelector('nav[class*="panelList"]');
852
+ if (!list) return;
853
+ const next = [];
854
+ Array.prototype.forEach.call(list.children, function (node) {
855
+ const btn = node.tagName === 'BUTTON'
856
+ ? node
857
+ : (node.querySelector ? node.querySelector('button') : null);
858
+ if (!btn) return;
859
+ const label = btn.getAttribute('aria-label') || String(node.textContent || '').trim();
860
+ const svg = btn.querySelector('svg');
861
+ next.push({ label: label || '入口', html: svg ? svg.outerHTML : '', btn: btn });
862
+ });
863
+ setItems(function (prev) {
864
+ const same = prev.length === next.length && prev.every(function (item, index) {
865
+ return item.label === next[index].label && item.html === next[index].html;
866
+ });
867
+ return same ? prev : next;
868
+ });
869
+ }
870
+ sync();
871
+ const observer = new MutationObserver(sync);
872
+ observer.observe(document.body, { childList: true, subtree: true });
873
+ return function () { observer.disconnect(); };
874
+ }, []);
875
+
876
+ return h('div', { className: 'wb-topbar-icons', style: { display: 'flex', gap: 2, flex: 1, overflow: 'hidden' } },
877
+ items.map(function (item, index) {
878
+ return h('button', {
879
+ key: item.label + ':' + index,
880
+ type: 'button',
881
+ className: 'wb-nav-item',
882
+ 'aria-label': item.label,
883
+ onClick: function () {
884
+ try { item.btn.click(); } catch (_error) { /* row went away */ }
885
+ },
886
+ style: {
887
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
888
+ gap: 4, height: 34, padding: '0 9px', borderRadius: 8, border: 'none',
889
+ background: 'transparent', color: 'var(--dsw-alias-label-secondary)',
890
+ cursor: 'pointer', flex: '0 0 auto', transition: 'background .15s, color .15s',
891
+ },
892
+ },
893
+ h('span', {
894
+ 'aria-hidden': true,
895
+ style: { display: 'inline-flex', width: 18, height: 18, flex: '0 0 auto' },
896
+ dangerouslySetInnerHTML: { __html: item.html },
897
+ }),
898
+ h('span', { className: 'wb-nav-label' }, item.label),
899
+ );
900
+ }),
901
+ );
902
+ }
903
+ return PanelMirror;
904
+ }
905
+
668
906
  function createTopBar(ctx, balance) {
669
907
  const ThemeSwitcher = createThemeSwitcher(ctx);
908
+ const PanelMirror = createPanelMirror();
670
909
 
671
910
  function BalanceChip() {
672
911
  const snap = React.useSyncExternalStore(balance.subscribe, balance.getSnapshot);
@@ -731,6 +970,7 @@ window.__ModuleLoader__.load({
731
970
  function TopBar(props) {
732
971
  const rootRef = React.useRef(null);
733
972
  const tabsRef = React.useRef(null);
973
+ const enabled = useFeatures();
734
974
  const reg = useRegistry();
735
975
  const usePanelInfo = props.usePanelInfo;
736
976
  const panelInfo = typeof usePanelInfo === 'function' ? usePanelInfo((s) => s) : null;
@@ -887,12 +1127,25 @@ window.__ModuleLoader__.load({
887
1127
  return h('div', { ref: rootRef, style: { position: 'fixed', top: 0, left: 0, right: 0, height: TOPBAR_HEIGHT, zIndex: 100, pointerEvents: 'auto', display: 'flex', flexDirection: 'column', background: 'var(--dsw-alias-bg-base)', borderBottom: '1px solid var(--dsw-alias-border-l1)' } },
888
1128
  h('div', { style: { height: 56, display: 'flex', alignItems: 'center', gap: 10, padding: '0 14px' } },
889
1129
  h('div', { className: 'wb-topbar-brand', style: { width: 214, flex: '0 0 auto' } }),
890
- h('div', { className: 'wb-topbar-icons', style: { display: 'flex', gap: 2, flex: 1, overflow: 'hidden' } },
891
- iconBtn('workbench', '工作台', IconGrid),
892
- iconBtn('plugins', '插件', IconPlugins),
893
- iconBtn('schedules', '自动化任务', IconClock),
1130
+ // System-level entry, first in the top-left corner: the workbench's
1131
+ // own mark opens its settings (feature switches + module list).
1132
+ h('button', {
1133
+ type: 'button',
1134
+ className: 'wb-nav-item wb-settings-entry',
1135
+ 'aria-label': '工作台设置',
1136
+ onClick: () => selectPanel(SETTINGS_VIEW_ID),
1137
+ style: {
1138
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
1139
+ gap: 4, height: 34, padding: '0 9px', borderRadius: 8, border: 'none',
1140
+ background: 'transparent', color: 'var(--dsw-alias-label-secondary)',
1141
+ cursor: 'pointer', flex: '0 0 auto', transition: 'background .15s, color .15s',
1142
+ },
1143
+ },
1144
+ h(IconWorkbenchTabs, { size: 18 }),
1145
+ h('span', { className: 'wb-nav-label' }, '工作台'),
894
1146
  ),
895
- h(ThemeSwitcher),
1147
+ h(PanelMirror),
1148
+ enabled.theme ? h(ThemeSwitcher) : null,
896
1149
  ),
897
1150
  h('div', { style: { height: 45, display: 'flex', alignItems: 'center', gap: 8, padding: '0 14px', borderTop: '1px solid var(--dsw-alias-border-l1)' } },
898
1151
  h('div', { ref: tabsRef, style: { position: 'relative', display: 'flex', alignItems: 'center', gap: 4, flex: 1, overflowX: 'auto', overflowY: 'hidden' } },
@@ -915,12 +1168,12 @@ window.__ModuleLoader__.load({
915
1168
  tabs.map(viewTab),
916
1169
  ),
917
1170
  h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, flex: '0 0 auto' } },
918
- h(BalanceChip, null),
919
- h('button', {
1171
+ enabled.balance ? h(BalanceChip, null) : null,
1172
+ enabled.restart ? h('button', {
920
1173
  type: 'button', title: '重启 DSH', className: 'wb-restart',
921
1174
  onClick: () => { restartDsh(ctx); },
922
1175
  style: { width: 28, height: 28, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', borderRadius: 8, border: '1px solid var(--dsw-alias-border-l2)', background: 'transparent', color: 'var(--dsw-alias-label-secondary)', cursor: 'pointer', flex: '0 0 auto', transition: 'background .12s, color .12s, border-color .12s' },
923
- }, h(IconRestart, { size: 15 })),
1176
+ }, h(IconRestart, { size: 15 })) : null,
924
1177
  ),
925
1178
  ),
926
1179
  );
@@ -1001,9 +1254,16 @@ window.__ModuleLoader__.load({
1001
1254
  return key.indexOf("v4-pro") >= 0 ? PRICING["deepseek-v4-pro"] : PRICING["deepseek-flash"];
1002
1255
  }
1003
1256
 
1257
+ function timeMs(value) {
1258
+ var n = typeof value === "number" ? value : Number(value);
1259
+ if (!isFinite(n) || n <= 0) return undefined;
1260
+ // Turn times can arrive in seconds; anything below 1e12 ms is seconds.
1261
+ return n < 1e12 ? n * 1000 : n;
1262
+ }
1263
+
1004
1264
  function computeCost(usage, ts) {
1005
1265
  var model = modelOf(usage);
1006
- var peak = isPeak(ts);
1266
+ var peak = isPeak(timeMs(ts));
1007
1267
  var table = peak ? pricesFor(model).peak : pricesFor(model).offPeak;
1008
1268
  var hit = num(usage && usage.cacheReadTokens);
1009
1269
  var miss = num(usage && usage.uncachedInputTokens) + num(usage && usage.cacheWriteTokens);
@@ -1063,7 +1323,7 @@ window.__ModuleLoader__.load({
1063
1323
  ? entry.data.get("turn-tail")
1064
1324
  : undefined;
1065
1325
  if (tail && tail.tokenUsage && matchesTail(tail, seq, turnId)) {
1066
- return tail.tokenUsage;
1326
+ return tail;
1067
1327
  }
1068
1328
  }
1069
1329
  }
@@ -1072,7 +1332,7 @@ window.__ModuleLoader__.load({
1072
1332
  var found;
1073
1333
  snapshot.nodes.forEach(function (node) {
1074
1334
  if (!node || node.kind !== "turn-tail" || !node.data || !node.data.tokenUsage) return;
1075
- if (matchesTail(node.data, seq, turnId)) found = node.data.tokenUsage;
1335
+ if (matchesTail(node.data, seq, turnId)) found = node.data;
1076
1336
  });
1077
1337
  if (found) return found;
1078
1338
  }
@@ -1127,7 +1387,9 @@ window.__ModuleLoader__.load({
1127
1387
  });
1128
1388
  }
1129
1389
  if (!usage) return null;
1130
- var entry = computeCost(usage, Date.now());
1390
+ // Price by the turn's own timestamp, not by when this row happens to
1391
+ // render: otherwise every historical turn reprices at the current hour.
1392
+ var entry = computeCost(usage.tokenUsage, usage.time);
1131
1393
  return h(
1132
1394
  "div",
1133
1395
  {
@@ -1542,12 +1804,23 @@ body[data-wb-paper="1"] [class*="_hoverPath"] {
1542
1804
  id: 'workbench',
1543
1805
  title: '工作台',
1544
1806
  subtitle: '工作台总览:已接入的视图与浮窗',
1545
- icon: WorkbenchIcon,
1807
+ icon: IconWorkbenchTabs,
1546
1808
  component: WorkbenchOverview,
1547
1809
  order: -10,
1548
1810
  tab: false,
1549
1811
  }), 'workbench: overview view');
1550
1812
 
1813
+ // Settings page: no tab — it is reached from the gear in the system bar.
1814
+ ctx.effect(() => api.registerView({
1815
+ id: SETTINGS_VIEW_ID,
1816
+ title: '工作台设置',
1817
+ subtitle: '功能开关与已注册的模块',
1818
+ icon: IconSettings,
1819
+ component: WorkbenchSettings,
1820
+ order: -20,
1821
+ tab: false,
1822
+ }), 'workbench: settings view');
1823
+
1551
1824
  const balance = createBalanceStore(ctx);
1552
1825
  try {
1553
1826
  ctx.effect(() => { balance.start(); return () => balance.stop(); }, 'workbench: balance polling');
@@ -1571,15 +1844,30 @@ body[data-wb-paper="1"] [class*="_hoverPath"] {
1571
1844
  }
1572
1845
 
1573
1846
  const TurnCost = createTurnCost();
1847
+ function TurnCostGated(props) {
1848
+ const enabled = useFeatures();
1849
+ if (!enabled.cost) return null;
1850
+ return h(TurnCost, props);
1851
+ }
1574
1852
  ctx.slots.inject('conversation.chat.turnTail', () => ctx.slots.register({
1575
1853
  name: 'conversation.chat.turnTail',
1576
1854
  id: 'workbench-turn-cost',
1577
1855
  order: 600,
1578
- }, TurnCost));
1856
+ }, TurnCostGated));
1579
1857
 
1580
1858
  // 注意:ctx.effect 接收的是「返回 dispose 的函数」。
1581
1859
  // 直接传 installGlow(ctx) 的返回值会让 effect 立刻执行清理,光效刚装上就被拆掉。
1582
- ctx.effect(() => installGlow(ctx), 'workbench: glow');
1860
+ // The switch can turn it off at runtime, so mount/unmount follows the store.
1861
+ ctx.effect(() => {
1862
+ let dispose = null;
1863
+ const sync = () => {
1864
+ if (dispose) { dispose(); dispose = null; }
1865
+ if (features.getSnapshot().glow) dispose = installGlow(ctx);
1866
+ };
1867
+ sync();
1868
+ const unsubscribe = features.subscribe(sync);
1869
+ return () => { unsubscribe(); if (dispose) dispose(); };
1870
+ }, 'workbench: glow');
1583
1871
 
1584
1872
  } catch (err) {
1585
1873
  console.error('[workbench] apply failed:', err);
package/index.js CHANGED
@@ -2,12 +2,41 @@
2
2
  * Host half of the workbench shell.
3
3
  *
4
4
  * The workbench's value lives in the Client half (module API + overview page).
5
- * The only Host duty is the one-click restart endpoint, which stops the running
6
- * web host in a detached process and lets the scheduled task relaunch it, so the
7
- * current page simply reconnects.
5
+ * The only Host duty is the one-click restart endpoint: it stops the running web
6
+ * host and lets an external supervisor start it again, so the current page
7
+ * simply reconnects. A restart is only offered when such a supervisor is
8
+ * actually present — exiting without one would strand the user with a dead
9
+ * server.
8
10
  */
9
11
  import { execSync } from 'node:child_process';
10
12
 
13
+ /** Supervisor that can start the host again, resolved per platform. */
14
+ function resolveSupervisor() {
15
+ const command = process.env.DSH_RESTART_CMD || '';
16
+ if (command) return { kind: 'command', command };
17
+ if (process.platform !== 'win32') return null;
18
+ // No default task name: this package ships to other machines, where the
19
+ // author's scheduled task does not exist. Enable the button by setting
20
+ // DSH_RESTART_TASK (a Windows scheduled task name) or DSH_RESTART_CMD
21
+ // (any command that starts the host again).
22
+ const task = process.env.DSH_RESTART_TASK || '';
23
+ if (!task) return null;
24
+ try {
25
+ execSync(`schtasks /query /tn ${JSON.stringify(task)}`, { windowsHide: true, stdio: 'ignore' });
26
+ return { kind: 'task', task };
27
+ } catch (_error) {
28
+ return null;
29
+ }
30
+ }
31
+
32
+ function startSupervisor(supervisor) {
33
+ if (supervisor.kind === 'command') {
34
+ execSync(supervisor.command, { windowsHide: true, stdio: 'ignore' });
35
+ return;
36
+ }
37
+ execSync(`schtasks /run /tn ${JSON.stringify(supervisor.task)}`, { windowsHide: true, stdio: 'ignore' });
38
+ }
39
+
11
40
  export const inject = ['webServer'];
12
41
 
13
42
  export function apply(ctx) {
@@ -28,12 +57,21 @@ export function apply(ctx) {
28
57
  res.end('method not allowed\n');
29
58
  return;
30
59
  }
31
- // 先看 3080 是否在跑,再决定要不要让 ensure 脚本拉起。
32
- // 响应先到达页面,然后本进程退出,由每 5 分钟一次的 ensure 任务重新拉起。
60
+ // Refuse without a supervisor: exiting here would leave no server behind.
61
+ const supervisor = resolveSupervisor();
62
+ if (!supervisor) {
63
+ res.writeHead(409, { 'Content-Type': 'application/json; charset=utf-8' });
64
+ res.end(JSON.stringify({
65
+ ok: false,
66
+ reason: 'no-supervisor',
67
+ hint: '这台机器上没有可用的重启管理器,请手动重启 DSH Web。',
68
+ }));
69
+ return;
70
+ }
33
71
  res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8' });
34
72
  res.end(JSON.stringify({ ok: true, restarting: true, etaSeconds: 300 }));
35
73
  setTimeout(() => {
36
- try { execSync('schtasks /run /tn philomel-dsh-web', { windowsHide: true, stdio: 'ignore' }); } catch (_e) {}
74
+ try { startSupervisor(supervisor); } catch (_e) { /* best effort */ }
37
75
  process.exit(0);
38
76
  }, 300);
39
77
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@philomelcc/dsh-workbench",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "description": "Workbench shell for DeepSeek Harness: a view/page module API, shared UI primitives and a top-bar switcher.",
6
6
  "license": "MIT",
@@ -14,20 +14,34 @@
14
14
  "bugs": {
15
15
  "url": "https://github.com/philomelcc/dsh-workbench/issues"
16
16
  },
17
- "keywords": ["dsh", "deepseek-harness", "workbench", "plugin", "web-ui"],
17
+ "keywords": [
18
+ "dsh",
19
+ "deepseek-harness",
20
+ "workbench",
21
+ "plugin",
22
+ "web-ui"
23
+ ],
18
24
  "exports": {
19
25
  ".": "./index.js",
20
26
  "./client": "./client.js",
21
27
  "./locale/*.json": "./locale/*.json",
22
28
  "./icon": "./icon.svg"
23
29
  },
24
- "files": ["index.js", "client.js", "cordis.patch.yml", "locale/*.json", "icon.svg"],
30
+ "files": [
31
+ "index.js",
32
+ "client.js",
33
+ "cordis.patch.yml",
34
+ "locale/*.json",
35
+ "icon.svg"
36
+ ],
25
37
  "publishConfig": {
26
38
  "access": "public",
27
39
  "registry": "https://registry.npmjs.org/"
28
40
  },
29
41
  "dsh": {
30
- "bundle": { "patch": "./cordis.patch.yml" },
42
+ "bundle": {
43
+ "patch": "./cordis.patch.yml"
44
+ },
31
45
  "client": {
32
46
  "platform": "web",
33
47
  "inject": [
@@ -38,4 +52,4 @@
38
52
  ]
39
53
  }
40
54
  }
41
- }
55
+ }