zcode-pro 1.5.0 → 1.6.1

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.
@@ -1,6 +1,6 @@
1
1
  // “ZCode Pro 增强设置”弹窗:功能开关 + 外观 + 运行状态。
2
2
  // 顶部标签页切换(视觉参考侧栏“分组/项目”切换);配置写入 helper(~/.zcode/zcodepro.json)。
3
- import { h, t, rpc, getConfig, clearConfigCache, errText, HELPER_URL, isZhLocale, isNewProjectSidebar, DEFAULT_SHORTCUTS, DEFAULT_STATUS_ITEMS, DEFAULT_TURN_ITEMS, STATUS_SESSION_IDS, STATUS_GLOBAL_IDS } from '../core.js';
3
+ import { h, t, rpc, getConfig, clearConfigCache, errText, HELPER_URL, liveBoot, isZhLocale, isNewProjectSidebar, DEFAULT_SHORTCUTS, DEFAULT_STATUS_ITEMS, DEFAULT_TURN_ITEMS, STATUS_SESSION_IDS, STATUS_GLOBAL_IDS } from '../core.js';
4
4
  import { openDialog, dialogFooter, btnPrimary, btnSecondary, btnSmall, settingRow, ensureStyle, showToast, numberField, unitField } from '../ui.js';
5
5
  import { comboField, providerOptionsOf, modelOptionsOf, modelPlaceholderOf, isManualConn } from '../provider-fields.js';
6
6
  import { refreshAliases } from './alias.js';
@@ -14,6 +14,9 @@ function openExternal(url) {
14
14
  try { void window.zcode.openExternal(url); } catch { /* ignore */ }
15
15
  }
16
16
 
17
+ // 文件名比较归一:Windows 大小写不敏感、macOS 返回 NFD 分解字符
18
+ const sameName = (a, b) => String(a).normalize('NFC').toLowerCase() === String(b).normalize('NFC').toLowerCase();
19
+
17
20
  // 插件市场仓库(设置页“自动更新”行的仓库名链接指向它)
18
21
  const PLUGINS_REPO_URL = 'https://github.com/duanluan/zcode-plugins';
19
22
 
@@ -158,7 +161,7 @@ export function openSettingsDialog() {
158
161
  // sm:max-w-3xl 不存在会失去约束拉满全屏;max-w-3xl=48rem 存在——英文界面
159
162
  // 标签栏较长,42rem 会挤出一块空白并触发横向滚动
160
163
  width: 'max-w-3xl',
161
- bodyClass: 'mt-1',
164
+ bodyClass: 'mt-0',
162
165
  overlay: 'none',
163
166
  draggable: true,
164
167
  posKey: 'settings',
@@ -168,9 +171,13 @@ export function openSettingsDialog() {
168
171
  if (rtkUpgradePollStop) rtkUpgradePollStop();
169
172
  },
170
173
  onMount: async ({ body, close, content }) => {
174
+ // 标记设置弹窗:showToast 据此把弹窗内触发的提示居中叠在弹窗上
175
+ if (content) content.setAttribute('data-zcodepro-settings', '1');
171
176
  // 标题行:左侧“ZCode Pro”点击跳转 GitHub 仓库;右上角 X 关闭弹窗(替代底部按钮)。
172
177
  // h2 仍是拖拽把手——X 上阻止 mousedown 冒泡,避免点关闭时误触发拖拽
173
178
  const titleEl = content && content.firstElementChild;
179
+ // 版本行稍后并入标题(要等 health 请求返回),这里先留引用
180
+ let titleLeft = null;
174
181
  if (titleEl && titleEl.tagName === 'H2') {
175
182
  titleEl.classList.add('flex', 'w-full', 'items-center', 'justify-between');
176
183
  const ns = 'http://www.w3.org/2000/svg';
@@ -184,7 +191,7 @@ export function openSettingsDialog() {
184
191
  }
185
192
  return svg;
186
193
  };
187
- const titleLeft = h('span', { class: 'flex min-w-0 items-center' }, L.settingsTitle);
194
+ titleLeft = h('span', { class: 'flex min-w-0 items-center' }, L.settingsTitle);
188
195
  if (typeof window.zcode?.openExternal === 'function') {
189
196
  const REPO_URL = 'https://github.com/duanluan/zcode-pro';
190
197
  titleLeft.replaceChildren(
@@ -206,9 +213,9 @@ export function openSettingsDialog() {
206
213
  }, '✕');
207
214
  titleEl.replaceChildren(titleLeft, closeX);
208
215
  }
209
- // 八个只读请求相互独立:并行取(串行时 headroom 的版本探测一项就约
216
+ // 九个只读请求相互独立:并行取(串行时 headroom 的版本探测一项就约
210
217
  // 700ms,弹窗打开明显卡顿)
211
- const [health, config, agentsRes, visionRes, titleGenRes, titleGenProvidersRes, rtkRes, headroomRes] = await Promise.all([
218
+ const [health, config, agentsRes, visionRes, titleGenRes, titleGenProvidersRes, rtkRes, headroomRes, zcodeConfigRes] = await Promise.all([
212
219
  rpc('/health'),
213
220
  getConfig(true),
214
221
  rpc('/agents'),
@@ -217,6 +224,7 @@ export function openSettingsDialog() {
217
224
  rpc('/title-gen/providers'),
218
225
  rpc('/rtk'),
219
226
  rpc('/headroom'),
227
+ rpc('/zcode-config'),
220
228
  ]);
221
229
  // 供应商表(含各供应商可选模型):视觉代理的模型下拉也用这份
222
230
  const titleGenProviders = titleGenProvidersRes.ok && Array.isArray(titleGenProvidersRes.providers)
@@ -228,7 +236,7 @@ export function openSettingsDialog() {
228
236
  // 通知常驻功能(如侧栏菜单并入顶栏)立即按新配置启用/停用
229
237
  window.dispatchEvent(new CustomEvent('zcodepro:config-changed'));
230
238
  if (!res.ok) {
231
- body.querySelector('[data-zcodepro-status]').replaceChildren(
239
+ statusLine.replaceChildren(
232
240
  h('span', { class: 'text-ui-sm text-destructive' }, L.failed + ': ' + errText(res))
233
241
  );
234
242
  return false;
@@ -236,13 +244,15 @@ export function openSettingsDialog() {
236
244
  return true;
237
245
  };
238
246
 
247
+ // 版本行跟在标题文字后(左留间距);也是功能开关保存失败时的报错位置
239
248
  const statusLine = h('div', {
240
- class: 'flex items-center gap-2 text-ui-sm text-foreground-subtle',
249
+ class: 'ml-2 flex min-w-0 items-center gap-1.5 text-ui-xs text-foreground-subtle',
241
250
  'data-zcodepro-status': '1',
242
251
  },
243
252
  h('span', { class: 'inline-block size-2 rounded-full bg-emerald-500' }),
244
- h('span', { class: 'text-foreground-subtle/70' }, `${health.version} · ${HELPER_URL}`)
253
+ h('span', { class: 'truncate text-foreground-subtle/70' }, `${health.version} · ${HELPER_URL}`)
245
254
  );
255
+ if (titleLeft) titleLeft.append(statusLine);
246
256
 
247
257
  // 双列网格:功能开关行短小(名称+开关+折行描述),两列排布把 15+ 行压到
248
258
  // 一屏内。列间加分隔线、行距拉开(gap-y-1),格内不留底 padding——
@@ -252,7 +262,7 @@ export function openSettingsDialog() {
252
262
  // 状态文字写入统一入口:文本与悬停 title 一起更新(描述位被动态内容替换后
253
263
  // 仍保持悬停全文约定)
254
264
  const setPluginsStatus = (text) => {
255
- setPluginsStatus(text);
265
+ pluginsStatusLine.textContent = text;
256
266
  pluginsStatusLine.setAttribute('title', text);
257
267
  };
258
268
  const pluginsBtn = btnSmall(L.pluginsCheckNow, () => { void runPluginsUpdate(); });
@@ -461,15 +471,17 @@ export function openSettingsDialog() {
461
471
  communityCard(L.wechatGroupTitle, L.wechatGroupDesc.replaceAll('{id}', WECHAT_ID),
462
472
  () => hCopyIcon('size-4 shrink-0 text-foreground-subtle'),
463
473
  async () => {
464
- if (await copyToClipboard(WECHAT_ID)) showToast(L.wechatIdCopied);
474
+ if (await copyToClipboard(WECHAT_ID)) showToast(L.wechatIdCopied, 'success');
465
475
  }));
466
476
 
467
477
  // 标签页切换:功能(现有内容)/ 外观 / 全局提示词 / 视觉代理
468
478
  let activeTab = 'features';
479
+ // 二级 tab 栏(外观 / 行为各一条):登记后统一放到滚动区上方的固定区
480
+ const subTabBars = {};
469
481
  // 插件更新卡片:显示 duanluan-zcode-plugins 市场状态,一键更新(helper /plugins/* 端点);
470
482
  // 状态异步加载,打开弹窗不等待
471
483
 
472
- const paneFeatures = h('div', { role: 'tabpanel', class: 'mt-4' },
484
+ const paneFeatures = h('div', { role: 'tabpanel', class: 'mt-2' },
473
485
  h('div', {}, rows),
474
486
  communityCards,
475
487
  );
@@ -499,8 +511,7 @@ export function openSettingsDialog() {
499
511
  }),
500
512
  hkCell('↑ / ↓', L.hkArrow.replaceAll('{prev}', keys.switchPrev).replaceAll('{next}', keys.switchNext)),
501
513
  hkCell('Enter', L.hkEnter),
502
- hkCell('Esc', L.hkEsc),
503
- hkCell(L.hkReleaseKey, L.hkRelease));
514
+ hkCell('Esc', L.hkEsc));
504
515
  };
505
516
  const stopHkRecording = () => {
506
517
  hkRecording = null;
@@ -523,12 +534,12 @@ export function openSettingsDialog() {
523
534
  e.stopImmediatePropagation();
524
535
  if (e.key === 'Escape') { stopHkRecording(); return; }
525
536
  const k = e.key.toLowerCase();
526
- if (!/^[a-z0-9]$/.test(k)) { showToast(L.hkInvalid, 'error'); return; }
537
+ if (!/^[a-z0-9]$/.test(k)) { showToast(L.hkInvalid, 'warning'); return; }
527
538
  const keys = hkKeys();
528
539
  const names = hkNames();
529
540
  const conflict = HK_ACTIONS.find(([a]) => a !== hkRecording && keys[a] === k);
530
541
  if (conflict) {
531
- showToast(L.hkConflict.replaceAll('{k}', k).replaceAll('{name}', names[conflict[0]]), 'error');
542
+ showToast(L.hkConflict.replaceAll('{k}', k).replaceAll('{name}', names[conflict[0]]), 'warning');
532
543
  return;
533
544
  }
534
545
  const a = hkRecording;
@@ -563,23 +574,23 @@ export function openSettingsDialog() {
563
574
  refreshRows(); // 功能标签页的开关描述跟随默认键位
564
575
  renderShortcuts();
565
576
  };
566
- const paneShortcuts = h('div', { role: 'tabpanel', class: 'mt-4', style: 'display:none' },
577
+ const paneShortcuts = h('div', { role: 'tabpanel', style: 'display:none' },
567
578
  h('div', { class: 'mb-2 text-ui-sm font-medium' }, L.hkTitle),
568
579
  h('div', { class: 'mb-2 flex items-center gap-2' },
569
580
  h('div', { class: 'min-w-0 flex-1 text-ui-xs/relaxed text-foreground-subtle' }, L.hkEditHint),
570
581
  h('div', { class: 'shrink-0' }, btnSmall(L.hkReset, () => { void resetShortcuts(); }))),
571
582
  hkCard,
572
583
  );
573
- const paneStyles = h('div', { role: 'tabpanel', class: 'mt-2', style: 'display:none' });
574
- const panePerf = h('div', { role: 'tabpanel', class: 'mt-4', style: 'display:none' });
575
- const paneAgents = h('div', { role: 'tabpanel', class: 'mt-2', style: 'display:none' });
576
- const paneProxy = h('div', { role: 'tabpanel', class: 'mt-4', style: 'display:none' });
577
- const paneSync = h('div', { role: 'tabpanel', class: 'mt-4', style: 'display:none' });
578
- const paneVision = h('div', { role: 'tabpanel', class: 'mt-4', style: 'display:none' });
579
- const paneRtk = h('div', { role: 'tabpanel', class: 'mt-4', style: 'display:none' });
580
- const paneHeadroom = h('div', { role: 'tabpanel', class: 'mt-4', style: 'display:none' });
581
- const paneTitleGen = h('div', { role: 'tabpanel', class: 'mt-4', style: 'display:none' });
582
- const paneDebug = h('div', { role: 'tabpanel', class: 'mt-4', style: 'display:none' });
584
+ const paneStyles = h('div', { role: 'tabpanel', style: 'display:none' });
585
+ const panePerf = h('div', { role: 'tabpanel', style: 'display:none' });
586
+ const paneAgents = h('div', { role: 'tabpanel', style: 'display:none' });
587
+ const paneProxy = h('div', { role: 'tabpanel', style: 'display:none' });
588
+ const paneSync = h('div', { role: 'tabpanel', style: 'display:none' });
589
+ const paneVision = h('div', { role: 'tabpanel', style: 'display:none' });
590
+ const paneRtk = h('div', { role: 'tabpanel', style: 'display:none' });
591
+ const paneHeadroom = h('div', { role: 'tabpanel', style: 'display:none' });
592
+ const paneTitleGen = h('div', { role: 'tabpanel', style: 'display:none' });
593
+ const paneDebug = h('div', { role: 'tabpanel', style: 'display:none' });
583
594
  const panes = { features: paneFeatures, shortcuts: paneShortcuts, styles: paneStyles, perf: panePerf, agents: paneAgents, proxy: paneProxy, sync: paneSync, vision: paneVision, headroom: paneHeadroom, rtk: paneRtk, debug: paneDebug };
584
595
  // 一级 tab 顺序:功能 → 外观 → 行为 → 性能 → 快捷键 → 代理/同步/插件页
585
596
  const tabDefs = [
@@ -610,6 +621,7 @@ export function openSettingsDialog() {
610
621
  // 切走“快捷键”标签页时结束键位录制:否则在其它标签页打字会被录制监听吞掉
611
622
  if (name !== 'shortcuts' && hkRecording) stopHkRecording();
612
623
  for (const [id, pane] of Object.entries(panes)) pane.style.display = id === name ? '' : 'none';
624
+ for (const [id, bar] of Object.entries(subTabBars)) bar.style.display = id === name ? '' : 'none';
613
625
  renderTabs();
614
626
  };
615
627
  renderTabs();
@@ -767,10 +779,10 @@ export function openSettingsDialog() {
767
779
  renderToolbarSwitch();
768
780
  // “外观”标签页的二级结构:样式(原内容)/ 状态栏(统计项顺序与显隐)/
769
781
  // 主题(皮肤与自定义主题)/ 背景图(图库、文件夹轮换、网址)
770
- const paneStylesSub1 = h('div', { class: 'mt-4' });
771
- const paneStylesSub2 = h('div', { class: 'mt-4', style: 'display:none' });
772
- const paneStylesSub3 = h('div', { class: 'mt-4', style: 'display:none' });
773
- const paneStylesSub4 = h('div', { class: 'mt-4', style: 'display:none' });
782
+ const paneStylesSub1 = h('div', { class: 'mt-2' });
783
+ const paneStylesSub2 = h('div', { class: 'mt-2', style: 'display:none' });
784
+ const paneStylesSub3 = h('div', { class: 'mt-2', style: 'display:none' });
785
+ const paneStylesSub4 = h('div', { class: 'mt-2', style: 'display:none' });
774
786
  const ITEM_NAMES = {
775
787
  ctx: 'sbItemCtx', questions: 'sbItemQuestions',
776
788
  todayTokens: 'sbItemTodayTokens', totalTokens: 'sbItemTotalTokens', tasks: 'sbItemTasks',
@@ -889,7 +901,7 @@ export function openSettingsDialog() {
889
901
  h('div', { class: 'mt-3 mb-1 text-ui-sm font-medium' }, L.sbGroupTurn),
890
902
  turnList);
891
903
  // —— “颜色”子页(paneStylesSub3):预设皮肤卡片 + 自定义主题编辑 ——
892
- // —— “背景图”子页(paneStylesSub4):无背景 / 图库 / 文件夹轮换 / 网址 ——
904
+ // —— “壁纸”子页(paneStylesSub4):无壁纸 / 图库 / 文件夹轮换 / 图片网址 / 网页 ——
893
905
  let themeCfg = structuredClone(config.theme || {});
894
906
  const numOrBg = (v, d) => (typeof v === 'number' && Number.isFinite(v) ? v : d);
895
907
  themeCfg.skin = themeCfg.skin || 'default';
@@ -942,14 +954,28 @@ export function openSettingsDialog() {
942
954
  renderThemeBg();
943
955
  const res = await rpc('/bg');
944
956
  bgLoading = false;
945
- if (res.ok && Array.isArray(res.files)) bgFiles = res.files;
946
- // 图库模式下当前文件可能已被删(同步/手动删除):自动回无背景并提示一次
947
- if (themeCfg.bg.mode === 'library' && themeCfg.bg.file
948
- && !bgFiles.some((f) => f.name === themeCfg.bg.file)) {
949
- themeCfg = { ...themeCfg, bg: { ...themeCfg.bg, file: '' } };
950
- await saveTheme({ bg: { file: '' } });
951
- showToast(L.themeBgDeletedActive, 'success');
952
- return;
957
+ const listed = res.ok && Array.isArray(res.files);
958
+ if (listed) bgFiles = res.files;
959
+ // 清"指向已删文件的引用"只在拿到真实列表后做:取数失败时 bgFiles 是空的,
960
+ // 按空列表当"全删了"清引用会把还在的文件引用误清掉
961
+ if (listed) {
962
+ // 分区背景指向已删文件的引用一并清掉:否则分区继续请求已删文件名,静默铺不出图
963
+ const regionPatch = {};
964
+ for (const [k, r] of Object.entries(themeCfg.bg.regions || {})) {
965
+ if (r && r.mode === 'library' && r.file && !bgFiles.some((f) => sameName(f.name, r.file))) regionPatch[k] = { ...r, file: '' };
966
+ }
967
+ if (Object.keys(regionPatch).length) {
968
+ themeCfg = { ...themeCfg, bg: { ...themeCfg.bg, regions: { ...themeCfg.bg.regions, ...regionPatch } } };
969
+ await saveTheme({ bg: { regions: { ...themeCfg.bg.regions } } });
970
+ }
971
+ // 图库模式下当前文件可能已被删(同步/手动删除):自动回无背景并提示一次
972
+ if (themeCfg.bg.mode === 'library' && themeCfg.bg.file
973
+ && !bgFiles.some((f) => sameName(f.name, themeCfg.bg.file))) {
974
+ themeCfg = { ...themeCfg, bg: { ...themeCfg.bg, file: '' } };
975
+ await saveTheme({ bg: { file: '' } });
976
+ showToast(L.themeBgDeletedActive, 'success');
977
+ return;
978
+ }
953
979
  }
954
980
  renderThemeBg();
955
981
  };
@@ -961,8 +987,9 @@ export function openSettingsDialog() {
961
987
  : { count: 0, dir: themeCfg.bg.folder };
962
988
  renderThemeBg();
963
989
  };
964
- // 上传:多选文件逐张转 base64 传 helper;第一张上传且当前无背景时自动选为当前
965
- const bgInput = h('input', { type: 'file', accept: '.png,.jpg,.jpeg,.webp,.gif,.bmp,.avif', multiple: '', style: 'display:none' });
990
+ // 上传:图片转 base64 传 helper,视频走 raw 字节流接口(base64 会把内存翻倍);
991
+ // 第一个上传且当前无壁纸时自动选为当前
992
+ const bgInput = h('input', { type: 'file', accept: '.png,.jpg,.jpeg,.webp,.gif,.bmp,.avif,.mp4,.webm,.mov', multiple: '', style: 'display:none' });
966
993
  bgInput.addEventListener('change', () => {
967
994
  const files = [...bgInput.files || []];
968
995
  bgInput.value = '';
@@ -970,17 +997,26 @@ export function openSettingsDialog() {
970
997
  void (async () => {
971
998
  let first = themeCfg.bg.file;
972
999
  for (const f of files) {
973
- const dataUrl = await new Promise((resolve) => {
974
- const r = new FileReader();
975
- r.onload = () => resolve(String(r.result || ''));
976
- r.onerror = () => resolve('');
977
- r.readAsDataURL(f);
978
- });
979
- if (!dataUrl) continue;
980
- const res = await rpc('/bg', { method: 'POST', body: { name: f.name, data: dataUrl } });
981
- if (!res.ok) { showToast(L.failed + ': ' + errText(res), 'error'); continue; }
1000
+ let res = null;
1001
+ if (/\.(mp4|webm|mov)$/i.test(f.name)) {
1002
+ res = await fetch(`${HELPER_URL}/bg/upload?name=${encodeURIComponent(f.name)}`, {
1003
+ method: 'POST',
1004
+ headers: { 'X-ZCodePro-Token': liveBoot().token || '' },
1005
+ body: f,
1006
+ }).then((r) => r.json()).catch((e) => ({ ok: false, error: String((e && e.message) || e) }));
1007
+ } else {
1008
+ const dataUrl = await new Promise((resolve) => {
1009
+ const r = new FileReader();
1010
+ r.onload = () => resolve(String(r.result || ''));
1011
+ r.onerror = () => resolve('');
1012
+ r.readAsDataURL(f);
1013
+ });
1014
+ if (!dataUrl) continue;
1015
+ res = await rpc('/bg', { method: 'POST', body: { name: f.name, data: dataUrl } });
1016
+ }
1017
+ if (!res || !res.ok) { showToast(L.failed + ': ' + errText(res || {}), 'error'); continue; }
982
1018
  if (Array.isArray(res.files)) bgFiles = res.files;
983
- if (!first) first = f.name;
1019
+ if (!first) first = res.name || f.name; // 落盘名以 helper 回传为准(清洗可能改名)
984
1020
  }
985
1021
  if (first && first !== themeCfg.bg.file) await saveTheme({ bg: { file: first } });
986
1022
  else renderThemeBg();
@@ -1067,17 +1103,24 @@ export function openSettingsDialog() {
1067
1103
  if (mode === 'library') {
1068
1104
  const sel = h('select', { class: 'h-7 max-w-40 rounded-lg border border-border bg-input px-1.5 text-ui-xs text-foreground outline-none' });
1069
1105
  sel.append(h('option', { value: '' }, '—'));
1070
- for (const f of bgFiles) sel.append(h('option', { value: f.name }, f.name));
1106
+ for (const f of bgFiles) {
1107
+ if (/\.(mp4|webm|mov)$/i.test(f.name)) continue; // 分区是 CSS 铺图,视频播不了
1108
+ sel.append(h('option', { value: f.name }, f.name));
1109
+ }
1071
1110
  sel.value = (cur && cur.file) || '';
1072
1111
  sel.addEventListener('change', () => setRegion(region, { ...cur, file: sel.value }));
1073
1112
  valueCtrl = sel;
1074
1113
  } else if (mode === 'folder') {
1075
1114
  const inp = h('input', { type: 'text', value: (cur && cur.folder) || '', class: themeInputCls.replace('h-8', 'h-7'), placeholder: '/path/to/wallpapers' });
1076
- inp.addEventListener('change', () => { if (inp.value.trim()) setRegion(region, { ...cur, folder: inp.value.trim() }); });
1115
+ inp.addEventListener('change', () => { setRegion(region, { ...cur, folder: inp.value.trim() }); }); // 空值 = 清空目录,应用侧会撤掉旧图规则
1077
1116
  valueCtrl = inp;
1078
1117
  } else if (mode === 'url') {
1079
1118
  const inp = h('input', { type: 'url', value: (cur && cur.url) || '', class: themeInputCls.replace('h-8', 'h-7'), placeholder: 'https://...' });
1080
- inp.addEventListener('change', () => { if (/^https?:\/\/\S+$/.test(inp.value.trim())) setRegion(region, { ...cur, url: inp.value.trim() }); });
1119
+ inp.addEventListener('change', () => {
1120
+ const v = inp.value.trim();
1121
+ if (/^https?:\/\/\S+$/.test(v) && !/[<>"'\\]/.test(v)) setRegion(region, { ...cur, url: v });
1122
+ else { showToast(L.themeBgUrlInvalid, 'warning'); renderThemeBg(); } // 非法网址不保存:提示并回显已存值
1123
+ });
1081
1124
  valueCtrl = inp;
1082
1125
  }
1083
1126
  return h('div', { class: 'flex flex-wrap items-center gap-2' },
@@ -1120,7 +1163,12 @@ export function openSettingsDialog() {
1120
1163
  const modeBtn = (id, label) => h('button', {
1121
1164
  type: 'button', class: 'zcodepro-tab',
1122
1165
  'data-state': themeCfg.bg.mode === id ? 'active' : 'inactive',
1123
- onClick: () => void saveTheme({ bg: { mode: id } }),
1166
+ onClick: () => {
1167
+ // url 与 web 共用 bg.url:互切时清空,别让另一模式的网址留着静默失效
1168
+ const cur = themeCfg.bg.mode;
1169
+ const cross = (cur === 'url' || cur === 'web') && (id === 'url' || id === 'web') && cur !== id;
1170
+ void saveTheme({ bg: cross ? { mode: id, url: '' } : { mode: id } });
1171
+ },
1124
1172
  }, label);
1125
1173
  // 文件夹路径输入 + 浏览(系统对话框);确认时先校验目录再保存
1126
1174
  const folderInput = h('input', { type: 'text', value: themeCfg.bg.folder, class: themeInputCls, placeholder: '/path/to/wallpapers' });
@@ -1152,14 +1200,22 @@ export function openSettingsDialog() {
1152
1200
  const randomCheck = h('input', { type: 'checkbox' });
1153
1201
  randomCheck.checked = themeCfg.bg.folderRandom !== false;
1154
1202
  randomCheck.addEventListener('change', () => { void saveTheme({ bg: { folderRandom: randomCheck.checked } }); });
1155
- // 网址输入:change 提交;空值回无背景
1203
+ // 图片网址输入:change 提交;空值回无壁纸
1156
1204
  const urlInput = h('input', { type: 'url', value: themeCfg.bg.url, class: themeInputCls, placeholder: 'https://...' });
1157
1205
  urlInput.addEventListener('change', () => {
1158
1206
  const v = urlInput.value.trim();
1159
1207
  if (!v) { void saveTheme({ bg: { mode: 'none', url: '' } }); return; }
1160
- if (!/^https?:\/\/\S+$/.test(v)) { showToast(L.themeBgUrlInvalid, 'error'); renderThemeBg(); return; }
1208
+ if (!/^https?:\/\/\S+$/.test(v) || /[<>"'\\]/.test(v)) { showToast(L.themeBgUrlInvalid, 'warning'); renderThemeBg(); return; }
1161
1209
  void saveTheme({ bg: { mode: 'url', url: v } });
1162
1210
  });
1211
+ // 网页壁纸输入:与图片网址共用 bg.url 字段,模式不同渲染方式不同
1212
+ const webInput = h('input', { type: 'url', value: themeCfg.bg.url, class: themeInputCls, placeholder: 'https://...' });
1213
+ webInput.addEventListener('change', () => {
1214
+ const v = webInput.value.trim();
1215
+ if (!v) { void saveTheme({ bg: { mode: 'none', url: '' } }); return; }
1216
+ if (!/^https?:\/\/\S+$/.test(v) || /[<>"'\\]/.test(v)) { showToast(L.themeBgUrlInvalid, 'warning'); renderThemeBg(); return; }
1217
+ void saveTheme({ bg: { mode: 'web', url: v } });
1218
+ });
1163
1219
  const libCard = (f) => {
1164
1220
  const del = h('button', {
1165
1221
  type: 'button', class: 'zcodepro-bg-del', title: L.themeBgDelete,
@@ -1173,12 +1229,16 @@ export function openSettingsDialog() {
1173
1229
  })();
1174
1230
  },
1175
1231
  }, '✕');
1232
+ // 视频用 <video> 拉首帧当缩略图(preload=metadata 只取元数据不下载全片)
1233
+ const thumb = /\.(mp4|webm|mov)$/i.test(f.name)
1234
+ ? h('video', { src: bgUrl(f.name), preload: 'metadata', muted: '' })
1235
+ : h('img', { src: bgUrl(f.name), alt: '', loading: 'lazy' });
1176
1236
  return h('button', {
1177
1237
  type: 'button', class: 'zcodepro-bg-card',
1178
- 'data-state': themeCfg.bg.mode === 'library' && themeCfg.bg.file === f.name ? 'active' : 'inactive',
1238
+ 'data-state': themeCfg.bg.mode === 'library' && sameName(themeCfg.bg.file, f.name) ? 'active' : 'inactive',
1179
1239
  title: f.name,
1180
1240
  onClick: () => void saveTheme({ bg: { mode: 'library', file: themeCfg.bg.file === f.name ? '' : f.name } }),
1181
- }, h('img', { src: bgUrl(f.name), alt: '', loading: 'lazy' }), del);
1241
+ }, thumb, del);
1182
1242
  };
1183
1243
  const section = (titleText, body) => h('div', { class: 'mt-3' },
1184
1244
  h('div', { class: 'mb-1.5 text-ui-xs font-medium text-foreground-subtle' }, titleText), body);
@@ -1188,7 +1248,11 @@ export function openSettingsDialog() {
1188
1248
  h('span', { class: 'text-ui-xs/relaxed text-foreground-subtle' }, bgLoading ? '…' : (bgFiles.length ? '' : L.themeBgEmpty)),
1189
1249
  btnSmall(L.themeBgUpload, () => bgInput.click())),
1190
1250
  bgFiles.length ? h('div', { class: 'grid grid-cols-4 gap-2', style: 'max-height:13.5rem;overflow-y:auto;' },
1191
- ...bgFiles.map(libCard)) : null)),
1251
+ ...bgFiles.map(libCard)) : null,
1252
+ h('div', { class: 'flex items-center gap-2' },
1253
+ h('label', { class: 'flex items-center gap-1.5 text-ui-xs text-foreground-subtle' }, randomCheck, L.themeBgFolderRandom),
1254
+ numField(themeCfg.bg.intervalMin, 0, 1440, (v) => { void saveTheme({ bg: { intervalMin: v } }); }, L.themeBgIntervalHint),
1255
+ h('span', { class: 'text-ui-xs text-foreground-subtle' }, L.themeBgIntervalUnit)))),
1192
1256
  ] : themeCfg.bg.mode === 'folder' ? [
1193
1257
  section(L.themeBgModeFolder, h('div', { class: 'flex flex-col gap-2' },
1194
1258
  h('div', { class: 'flex items-center gap-2' }, folderInput, browseBtn),
@@ -1207,17 +1271,52 @@ export function openSettingsDialog() {
1207
1271
  numField(themeCfg.bg.intervalMin, 0, 1440, (v) => { void saveTheme({ bg: { intervalMin: v } }); }, L.themeBgUrlIntervalHint),
1208
1272
  h('span', { class: 'text-ui-xs text-foreground-subtle' }, L.themeBgIntervalUnit)),
1209
1273
  h('p', { class: 'text-ui-xs/relaxed text-foreground-subtle' }, L.themeBgUrlHint))),
1274
+ ] : themeCfg.bg.mode === 'web' ? [
1275
+ section(L.themeBgModeWeb, h('div', { class: 'flex flex-col gap-2' },
1276
+ webInput,
1277
+ h('p', { class: 'text-ui-xs/relaxed text-foreground-subtle' }, L.themeBgWebHint))),
1210
1278
  ] : [h('p', { class: 'mt-3 text-ui-xs/relaxed text-foreground-subtle' }, L.themeBgNoneHint)];
1211
1279
  const fitBtn = (id, label) => h('button', {
1212
1280
  type: 'button', class: 'zcodepro-tab',
1213
1281
  'data-state': (themeCfg.bg.fit || 'cover') === id ? 'active' : 'inactive',
1214
1282
  onClick: () => void saveTheme({ bg: { fit: id } }),
1215
1283
  }, label);
1284
+ const transBtn = (id, label) => h('button', {
1285
+ type: 'button', class: 'zcodepro-tab',
1286
+ 'data-state': (themeCfg.bg.transition || 'cut') === id ? 'active' : 'inactive',
1287
+ onClick: () => void saveTheme({ bg: { transition: id } }),
1288
+ }, label);
1289
+ const pauseCheck = (key, label) => {
1290
+ const c = h('input', { type: 'checkbox' });
1291
+ c.checked = key === 'pauseOnHidden' ? themeCfg.bg.pauseOnHidden !== false : !!themeCfg.bg[key];
1292
+ c.addEventListener('change', () => void saveTheme({ bg: { [key]: c.checked } }));
1293
+ return h('label', { class: 'flex items-center gap-1.5 text-ui-xs text-foreground-subtle' }, c, label);
1294
+ };
1295
+ // 播放行只作用于视频壁纸:音量滑杆 + 倍速/帧率下拉
1296
+ const selectField = (value, options, commit) => {
1297
+ const sel = h('select', { class: 'h-7 rounded-lg border border-border bg-input px-1.5 text-ui-xs text-foreground outline-none' });
1298
+ for (const [v, label] of options) sel.append(h('option', { value: String(v) }, label));
1299
+ sel.value = String(value);
1300
+ sel.addEventListener('change', () => commit(sel.value));
1301
+ return sel;
1302
+ };
1303
+ const labelledRow = (label, ctrl) => h('div', { class: 'flex items-center gap-3' },
1304
+ h('span', { class: 'shrink-0 whitespace-nowrap text-ui-xs font-medium text-foreground-subtle', style: 'width:72px' }, label), ctrl);
1305
+ const volumeRow = () => sliderRow(L.themeBgVolume, L.themeBgVolumeHint, 0, 100, 1, Math.round(numOr(themeCfg.bg.videoVolume, 0) * 100), '%',
1306
+ (v) => { void saveTheme({ bg: { videoVolume: v / 100 } }); }, '');
1307
+ const rateRow = () => labelledRow(L.themeBgRate,
1308
+ selectField(numOr(themeCfg.bg.playbackRate, 1), [['0.5', '0.5x'], ['0.75', '0.75x'], ['1', '1x'], ['1.25', '1.25x'], ['1.5', '1.5x'], ['2', '2x']],
1309
+ (v) => { void saveTheme({ bg: { playbackRate: Number(v) } }); }));
1310
+ const fpsRow = () => h('div', { class: 'flex flex-col gap-0.5' },
1311
+ labelledRow(L.themeBgFps, selectField(numOr(themeCfg.bg.fpsCap, 0), [['0', L.themeBgFpsOff], ['15', '15 fps'], ['30', '30 fps'], ['60', '60 fps']],
1312
+ (v) => { void saveTheme({ bg: { fpsCap: Number(v) } }); })),
1313
+ h('span', { class: 'text-ui-xs/relaxed text-foreground-subtle' }, L.themeBgFpsHint));
1216
1314
  paneStylesSub4.replaceChildren(
1217
1315
  h('p', { class: 'text-ui-sm/relaxed text-foreground-subtle' }, L.themeBgDesc),
1218
1316
  h('div', { class: 'mt-2 flex flex-wrap gap-1' },
1219
1317
  modeBtn('none', L.themeBgModeNone), modeBtn('library', L.themeBgModeLibrary),
1220
- modeBtn('folder', L.themeBgModeFolder), modeBtn('url', L.themeBgModeUrl)),
1318
+ modeBtn('folder', L.themeBgModeFolder), modeBtn('url', L.themeBgModeUrl),
1319
+ modeBtn('web', L.themeBgModeWeb)),
1221
1320
  ...modeArea,
1222
1321
  section(L.themeBgRegions, h('div', { class: 'flex flex-col gap-2' },
1223
1322
  regionRow('left', L.themeBgRegionLeft),
@@ -1227,8 +1326,18 @@ export function openSettingsDialog() {
1227
1326
  h('span', { class: 'text-ui-xs font-medium text-foreground-subtle' }, L.themeBgFit),
1228
1327
  fitBtn('cover', L.themeBgFitCover), fitBtn('contain', L.themeBgFitContain),
1229
1328
  fitBtn('fill', L.themeBgFitFill), fitBtn('tile', L.themeBgFitTile)),
1329
+ h('div', { class: 'mt-3 flex flex-wrap items-center gap-2' },
1330
+ h('span', { class: 'text-ui-xs font-medium text-foreground-subtle' }, L.themeBgTransition),
1331
+ transBtn('cut', L.themeBgTransitionCut), transBtn('fade', L.themeBgTransitionFade)),
1332
+ h('div', { class: 'mt-3 flex flex-wrap items-center gap-2' },
1333
+ h('span', { class: 'text-ui-xs font-medium text-foreground-subtle' }, L.themeBgPause),
1334
+ pauseCheck('pauseOnHidden', L.themeBgPauseHidden),
1335
+ pauseCheck('pauseOnBlur', L.themeBgPauseBlur),
1336
+ pauseCheck('pauseOnBattery', L.themeBgPauseBattery)),
1230
1337
  h('div', { class: 'mt-3 flex flex-col gap-2' },
1231
1338
  maskRow(), blurRow(), panelRow()),
1339
+ section(L.themeBgPlayback, h('div', { class: 'flex flex-col gap-2' },
1340
+ volumeRow(), rateRow(), fpsRow())),
1232
1341
  bgInput,
1233
1342
  );
1234
1343
  };
@@ -1258,7 +1367,8 @@ export function openSettingsDialog() {
1258
1367
  },
1259
1368
  }, label)));
1260
1369
  renderStylesSubTabs();
1261
- paneStyles.append(stylesSubTablist, paneStylesSub1, paneStylesSub2, paneStylesSub3, paneStylesSub4);
1370
+ subTabBars.styles = stylesSubTablist;
1371
+ paneStyles.append(paneStylesSub1, paneStylesSub2, paneStylesSub3, paneStylesSub4);
1262
1372
  paneStylesSub1.append(
1263
1373
  toolbarSwitchWrap,
1264
1374
  h('div', { class: 'mt-2 flex flex-col gap-0.5 rounded-xl border border-border p-1' },
@@ -1298,16 +1408,138 @@ export function openSettingsDialog() {
1298
1408
  const res = await rpc('/agents', { method: 'POST', body: { content: agentsArea.value } });
1299
1409
  if (res.ok) {
1300
1410
  agentsOriginal = typeof res.content === 'string' ? res.content : agentsArea.value;
1301
- showToast(L.agentsSaved);
1411
+ showToast(L.agentsSaved, 'success');
1302
1412
  } else {
1303
1413
  showToast(L.failed + ': ' + errText(res), 'error');
1304
1414
  agentsSaveBtn.disabled = false;
1305
1415
  }
1306
1416
  };
1307
- // “行为”标签页:二级标签切换“全局提示词 / 任务名”。全局提示词编辑
1417
+ // “行为 → ZCode CLI”:zcode-cli 运行时的行为配置(写 ~/.zcode/cli/config.json)+
1418
+ // 技能清单检查。开关与预算数字框改动即存,每次只提交自己那个键;
1419
+ // 目录列表显式保存
1420
+ const paneZcode = h('div', { class: 'mt-2' });
1421
+ let snap = zcodeConfigRes;
1422
+ const setZcode = async (body) => {
1423
+ const res = await rpc('/zcode-config', { method: 'POST', body });
1424
+ if (!res.ok) {
1425
+ showToast(L.failed + ': ' + errText(res), 'error');
1426
+ return false;
1427
+ }
1428
+ snap = res;
1429
+ return true;
1430
+ };
1431
+ if (!snap.ok) {
1432
+ paneZcode.append(h('p', { class: 'mt-2 text-ui-sm text-destructive' }, L.failed + ': ' + errText(snap)));
1433
+ } else {
1434
+ const fmt = (n) => String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
1435
+ // —— 技能清单检查:完整清单字符数对照预算,超了就提示被降级 ——
1436
+ const countsEl = h('div', { class: 'text-ui-sm text-foreground' });
1437
+ const charsEl = h('div', { class: 'mt-0.5 text-ui-sm text-foreground' });
1438
+ const statusEl = h('div', { class: 'mt-0.5 text-ui-sm' });
1439
+ // —— 技能清单预算:数字框改动即存;“用建议值”写入并保存 ——
1440
+ const budgetField = numberField({
1441
+ value: snap.values.skills.metadataBudget,
1442
+ fallback: snap.stats.defaultBudget,
1443
+ min: 0,
1444
+ max: 1000000,
1445
+ step: 1000,
1446
+ onCommit: async (v) => {
1447
+ if (await setZcode({ skills: { metadataBudget: v } })) renderStats();
1448
+ },
1449
+ });
1450
+ const budgetTag = h('span', { class: 'text-ui-xs text-foreground-subtle' });
1451
+ const suggestEl = h('div', { class: 'min-w-0 flex-1 text-ui-xs/relaxed text-foreground-subtle' });
1452
+ const renderStats = () => {
1453
+ countsEl.textContent = L.zcodeStatsCounts
1454
+ .replaceAll('{total}', fmt(snap.stats.total))
1455
+ .replaceAll('{user}', fmt(snap.stats.userCount))
1456
+ .replaceAll('{plugin}', fmt(snap.stats.pluginCount));
1457
+ charsEl.textContent = L.zcodeStatsChars.replaceAll('{n}', fmt(snap.stats.fullChars));
1458
+ statusEl.textContent = snap.stats.degraded ? L.zcodeStatsDegraded : L.zcodeStatsOk;
1459
+ statusEl.className = 'mt-0.5 text-ui-sm ' + (snap.stats.degraded ? 'text-destructive' : 'text-foreground');
1460
+ budgetTag.textContent = snap.configured.skills.metadataBudget ? '' : L.zcodeBudgetDefaultTag;
1461
+ suggestEl.textContent = L.zcodeStatsSuggest.replaceAll('{n}', fmt(snap.stats.suggested));
1462
+ };
1463
+ const applyBtn = btnSmall(L.zcodeBudgetApply, async () => {
1464
+ if (await setZcode({ skills: { metadataBudget: snap.stats.suggested } })) {
1465
+ budgetField.set(snap.values.skills.metadataBudget);
1466
+ renderStats();
1467
+ showToast(L.zcodeBudgetApplied, 'success');
1468
+ }
1469
+ }, 'shrink-0');
1470
+ // 检查与预算同一行两个块
1471
+ const statsBudgetRow = h('div', { class: 'mt-2 flex items-stretch gap-2' },
1472
+ h('div', { class: 'flex min-w-0 flex-1 flex-col rounded-xl border border-border p-3' },
1473
+ h('div', { class: 'text-ui-sm font-medium' }, L.zcodeStatsTitle),
1474
+ countsEl, charsEl, statusEl,
1475
+ h('div', { class: 'mt-1 text-ui-xs/relaxed text-foreground-subtle' }, L.zcodeStatsNote)),
1476
+ h('div', { class: 'flex min-w-0 flex-1 flex-col rounded-xl border border-border p-3' },
1477
+ h('div', { class: 'text-ui-sm font-medium' }, L.zcodeSkillBudget),
1478
+ h('div', { class: 'mt-0.5 text-ui-xs/relaxed text-foreground-subtle' }, L.zcodeSkillBudgetDesc),
1479
+ h('div', { class: 'mt-2 flex items-center gap-1' }, budgetField.el, budgetTag),
1480
+ h('div', { class: 'mt-1 flex items-center gap-2' }, suggestEl, applyBtn)));
1481
+ // —— 开关组:skills / features 两段配置键,点一次只写一个键 ——
1482
+ const togglesWrap = h('div', { class: 'mt-2 flex flex-col gap-0.5 rounded-xl border border-border p-1' });
1483
+ const renderToggles = () => {
1484
+ const v = snap.values;
1485
+ const row = (name, desc, checked, patch) => settingRow(name, desc, checked, async () => {
1486
+ if (await setZcode(patch(!checked))) renderToggles();
1487
+ });
1488
+ // 分组标题省略:每行描述都带 skills./features. 键名前缀,分组名是重复信息
1489
+ togglesWrap.replaceChildren(
1490
+ row(L.zcodeSkillEnabled, L.zcodeSkillEnabledDesc, v.skills.enabled, (n) => ({ skills: { enabled: n } })),
1491
+ row(L.zcodeSkillIncludeInstructions, L.zcodeSkillIncludeInstructionsDesc, v.skills.includeInstructions, (n) => ({ skills: { includeInstructions: n } })),
1492
+ row(L.zcodeFeatCompact, L.zcodeFeatCompactDesc, v.features.compact, (n) => ({ features: { compact: n } })),
1493
+ row(L.zcodeFeatRewind, L.zcodeFeatRewindDesc, v.features.rewind, (n) => ({ features: { rewind: n } })),
1494
+ row(L.zcodeFeatSubagent, L.zcodeFeatSubagentDesc, v.features.subagent, (n) => ({ features: { subagent: n } })),
1495
+ row(L.zcodeFeatSkill, L.zcodeFeatSkillDesc, v.features.skill, (n) => ({ features: { skill: n } })),
1496
+ row(L.zcodeFeatMcp, L.zcodeFeatMcpDesc, v.features.mcp, (n) => ({ features: { mcp: n } })),
1497
+ // 记忆不放这里:官方“工作区记忆”是桌面设置里的 memoryEnabled
1498
+ // (~/.zcode/v2/setting.json),与本页写的 agent 配置不是同一层开关
1499
+ h('div', { class: 'px-2 pb-1 pt-1 text-ui-xs/relaxed text-foreground-subtle' }, L.zcodeMemoryHint),
1500
+ );
1501
+ };
1502
+ // —— 额外技能目录:多行文本,显式保存 ——
1503
+ const rootsArea = h('textarea', {
1504
+ class: 'zcodepro-textarea zcodepro-textarea-sm',
1505
+ rows: 3,
1506
+ spellcheck: 'false',
1507
+ placeholder: '/path/to/skills',
1508
+ });
1509
+ let rootsOriginal = snap.values.skills.roots.join('\n');
1510
+ rootsArea.value = rootsOriginal;
1511
+ const rootsSaveBtn = btnSmall(L.zcodeSave, async () => {
1512
+ rootsSaveBtn.disabled = true;
1513
+ const lines = rootsArea.value.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
1514
+ if (await setZcode({ skills: { roots: lines } })) {
1515
+ rootsOriginal = snap.values.skills.roots.join('\n');
1516
+ renderStats(); // 目录影响清单统计
1517
+ showToast(L.zcodeRootsSaved, 'success');
1518
+ } else {
1519
+ rootsSaveBtn.disabled = false;
1520
+ }
1521
+ }, 'shrink-0', 'primary');
1522
+ rootsSaveBtn.disabled = true;
1523
+ rootsArea.addEventListener('input', () => {
1524
+ rootsSaveBtn.disabled = rootsArea.value === rootsOriginal;
1525
+ });
1526
+ renderStats();
1527
+ renderToggles();
1528
+ paneZcode.append(
1529
+ h('p', { class: 'text-ui-sm/relaxed text-foreground-subtle' }, L.zcodeDesc),
1530
+ statsBudgetRow,
1531
+ togglesWrap,
1532
+ h('div', { class: 'mt-2 rounded-xl border border-border p-2' },
1533
+ h('div', { class: 'text-ui-sm font-medium text-foreground' }, L.zcodeSkillRoots),
1534
+ h('div', { class: 'mt-0.5 text-ui-xs/relaxed text-foreground-subtle' }, L.zcodeSkillRootsDesc),
1535
+ h('div', { class: 'mt-2' }, rootsArea),
1536
+ h('div', { class: 'mt-2 flex justify-end' }, rootsSaveBtn)),
1537
+ );
1538
+ }
1539
+ // “行为”标签页:二级标签切换“ZCode / 全局提示词 / 任务名”。全局提示词编辑
1308
1540
  // ~/.zcode/AGENTS.md;任务名(智能起名)面板复用 paneTitleGen(原本是
1309
1541
  // 一级标签页,收进来后不再单独出现在顶部标签栏)
1310
- const agentsPromptPane = h('div', { class: 'mt-4' });
1542
+ const agentsPromptPane = h('div', { class: 'mt-2' });
1311
1543
  agentsPromptPane.append(
1312
1544
  h('p', { class: 'text-ui-sm/relaxed text-foreground-subtle' }, L.agentsDesc),
1313
1545
  ...(agentsFailed
@@ -1316,11 +1548,12 @@ export function openSettingsDialog() {
1316
1548
  h('div', { class: 'mt-3' }, agentsArea),
1317
1549
  h('div', { class: 'mt-3 flex justify-end' }, agentsSaveBtn),
1318
1550
  );
1319
- let agentsSubTab = 'prompt';
1320
- const agentsSubPanes = { prompt: agentsPromptPane, titleGen: paneTitleGen };
1551
+ let agentsSubTab = 'zcode';
1552
+ const agentsSubPanes = { zcode: paneZcode, prompt: agentsPromptPane, titleGen: paneTitleGen };
1321
1553
  const agentsSubList = h('div', { role: 'tablist', 'aria-orientation': 'horizontal', class: 'zcodepro-tablist' });
1322
1554
  const renderAgentsSubTabs = () => {
1323
1555
  agentsSubList.replaceChildren(...[
1556
+ ['zcode', L.tabZcode],
1324
1557
  ['prompt', L.tabAgents],
1325
1558
  ['titleGen', L.tabTitleGen],
1326
1559
  ].map(([id, label]) => h('button', {
@@ -1336,7 +1569,8 @@ export function openSettingsDialog() {
1336
1569
  };
1337
1570
  for (const [pid, pane] of Object.entries(agentsSubPanes)) pane.style.display = pid === agentsSubTab ? '' : 'none';
1338
1571
  renderAgentsSubTabs();
1339
- paneAgents.append(agentsSubList, agentsPromptPane, paneTitleGen);
1572
+ subTabBars.agents = agentsSubList;
1573
+ paneAgents.append(paneZcode, agentsPromptPane, paneTitleGen);
1340
1574
 
1341
1575
  // “代理”:为 helper 发起的网络访问(插件市场更新/安装、headroom 本体升级)设
1342
1576
  // HTTP 代理;保存即生效(helper 子进程环境变量注入),不影响 ZCode 应用与模型请求。
@@ -1356,7 +1590,7 @@ export function openSettingsDialog() {
1356
1590
  if (res.ok) {
1357
1591
  proxyOriginal = res.config && typeof res.config.proxy === 'string' ? res.config.proxy : proxyInput.value.trim();
1358
1592
  proxyInput.value = proxyOriginal;
1359
- showToast(L.proxySaved);
1593
+ showToast(L.proxySaved, 'success');
1360
1594
  } else {
1361
1595
  proxySaveBtn.disabled = false;
1362
1596
  showToast(L.failed + ': ' + errText(res), 'error');
@@ -1551,7 +1785,7 @@ export function openSettingsDialog() {
1551
1785
  syncLoginInput.value = res.sync.login;
1552
1786
  syncPasswordInput.value = res.sync.password;
1553
1787
  syncHistoryInput.value = syncFormOriginal.historyLimit;
1554
- showToast(L.syncSaved);
1788
+ showToast(L.syncSaved, 'success');
1555
1789
  } else {
1556
1790
  showToast(L.failed + ': ' + errText(res), 'error');
1557
1791
  syncCheckDirty();
@@ -1895,7 +2129,7 @@ export function openSettingsDialog() {
1895
2129
  compressThresholdKB: 1024,
1896
2130
  skipAfterFailures: 2,
1897
2131
  skipMinutes: 30,
1898
- forceIntercept: true,
2132
+ // forceIntercept 不写:缺省 = 自动(跟随宿主「模型设置」图片开关,zcode-vision ≥1.7.9)
1899
2133
  };
1900
2134
  let visionCfg = visionRes.ok && visionRes.config && typeof visionRes.config === 'object'
1901
2135
  ? structuredClone(visionRes.config)
@@ -2120,26 +2354,37 @@ export function openSettingsDialog() {
2120
2354
  await persistVision();
2121
2355
  renderVision();
2122
2356
  })))),
2123
- // 链模式 + 强制拦截开关合到一行(启用开关已上移信息卡)
2124
- h('div', { class: 'mt-3 flex flex-wrap items-center gap-x-4 gap-y-1.5 rounded-xl border border-border p-1' },
2125
- h('span', { class: 'ml-1.5 shrink-0 text-ui-sm font-medium text-foreground' }, L.visionMode),
2126
- modeBtn('fallback', L.visionModeFallback, L.visionModeFallbackDesc),
2127
- modeBtn('pipeline', L.visionModePipeline, L.visionModePipelineDesc),
2128
- h('div', { class: 'ml-auto flex items-center gap-4' },
2357
+ // 链模式 / 主模型策略 / 识图卡片 三项均分一行、各格内容左对齐(启用开关已上移信息卡)
2358
+ h('div', { class: 'mt-3 grid grid-cols-1 items-center gap-1.5 rounded-xl border border-border p-2 sm:grid-cols-3' },
2359
+ h('div', { class: 'flex flex-wrap items-center gap-2' },
2360
+ h('span', { class: 'shrink-0 text-ui-sm font-medium text-foreground' }, L.visionMode),
2361
+ modeBtn('fallback', L.visionModeFallback, L.visionModeFallbackDesc),
2362
+ modeBtn('pipeline', L.visionModePipeline, L.visionModePipelineDesc),
2363
+ ),
2364
+ (() => {
2365
+ // 三态:不能识图就使用插件(null,POST 侧删键恢复插件缺省联动)/ 始终使用插件 / 不使用插件
2366
+ const sel = h('select', { class: 'h-8 rounded-lg border border-border bg-input px-2 text-ui-sm text-foreground outline-none', title: L.visionForceInterceptHint },
2367
+ h('option', { value: 'auto' }, L.visionForceInterceptAuto),
2368
+ h('option', { value: 'true' }, L.visionForceInterceptTrue),
2369
+ h('option', { value: 'false' }, L.visionForceInterceptFalse));
2370
+ sel.value = visionCfg.forceIntercept === true ? 'true' : visionCfg.forceIntercept === false ? 'false' : 'auto';
2371
+ sel.addEventListener('change', () => {
2372
+ visionCfg.forceIntercept = sel.value === 'true' ? true : sel.value === 'false' ? false : null;
2373
+ void persistVision();
2374
+ });
2375
+ return h('label', { class: 'flex items-center gap-1.5', title: L.visionForceInterceptHint },
2376
+ h('span', { class: 'text-ui-sm font-medium text-foreground' }, L.visionForceIntercept), sel);
2377
+ })(),
2378
+ h('div', { class: 'flex items-center' },
2129
2379
  settingRow(L.visionCardUi, '', visionCfg.cardUi !== false, async () => {
2130
2380
  visionCfg.cardUi = !(visionCfg.cardUi !== false);
2131
2381
  await persistVision();
2132
2382
  renderVision();
2133
2383
  }),
2134
- settingRow(L.visionForceIntercept, '', visionCfg.forceIntercept !== false, async () => {
2135
- visionCfg.forceIntercept = !(visionCfg.forceIntercept !== false);
2136
- await persistVision();
2137
- renderVision();
2138
- }),
2139
2384
  ),
2140
2385
  ),
2141
- // 压缩阈值 / 连续失败次数 / 跳过分钟数 三个数字一行
2142
- h('div', { class: 'mt-2 flex flex-wrap items-center gap-x-4 gap-y-1.5 rounded-xl border border-border p-1' },
2386
+ // 压缩阈值 / 连续失败次数 / 跳过分钟数 三个数字一行(p-2 与上方信息卡对齐)
2387
+ h('div', { class: 'mt-2 flex flex-wrap items-center gap-x-4 gap-y-1.5 rounded-xl border border-border p-2' },
2143
2388
  (() => {
2144
2389
  const n = h('input', { type: 'number', min: '0', step: '128', title: L.visionCompressKBHint,
2145
2390
  class: 'h-7 w-16 rounded-lg border border-border bg-input px-2 text-right text-ui-xs tabular-nums text-foreground outline-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40' });
@@ -2280,7 +2525,7 @@ export function openSettingsDialog() {
2280
2525
  const v = input.value.trim();
2281
2526
  if (!v) return;
2282
2527
  if (!/^(git:)?[A-Za-z0-9._-]+$/.test(v) || rtkCfg.whitelist.includes(v)) {
2283
- showToast(L.rtkWhitelistInvalid, 'error');
2528
+ showToast(L.rtkWhitelistInvalid, 'warning');
2284
2529
  return;
2285
2530
  }
2286
2531
  if (await persistRtk({ whitelist: [...rtkCfg.whitelist, v] })) {
@@ -2383,7 +2628,7 @@ export function openSettingsDialog() {
2383
2628
  if (await persistRtk({ whitelist: [] })) {
2384
2629
  rtkCfg.whitelist = [];
2385
2630
  renderRtk();
2386
- showToast(L.rtkWhitelistCleared);
2631
+ showToast(L.rtkWhitelistCleared, 'success');
2387
2632
  }
2388
2633
  })();
2389
2634
  }, 'shrink-0'))),
@@ -2505,7 +2750,7 @@ export function openSettingsDialog() {
2505
2750
  clearInterval(timerIv);
2506
2751
  hrBusy = false;
2507
2752
  await hrRefresh();
2508
- showToast(doneMsg, isStart ? 'success' : undefined);
2753
+ showToast(doneMsg, 'success');
2509
2754
  return;
2510
2755
  }
2511
2756
  }
@@ -2524,7 +2769,7 @@ export function openSettingsDialog() {
2524
2769
  return false;
2525
2770
  }
2526
2771
  if (res.config) Object.assign(hrCfg, res.config);
2527
- if (warn) showToast(warn);
2772
+ if (warn) showToast(warn, 'warning');
2528
2773
  // 非生命周期动作(backend/power):稍等后刷一次
2529
2774
  if (!isStart && !isStop) {
2530
2775
  hrBusy = false;
@@ -2593,7 +2838,7 @@ export function openSettingsDialog() {
2593
2838
  }
2594
2839
  if (res.usage) headroomRes.usage = res.usage;
2595
2840
  renderHrUsageSwitch();
2596
- if (next && !res.changed && !(res.usage && res.usage.enabled)) showToast(L.hrUsageNone);
2841
+ if (next && !res.changed && !(res.usage && res.usage.enabled)) showToast(L.hrUsageNone, 'warning');
2597
2842
  }));
2598
2843
  };
2599
2844
  renderHrUsageSwitch();
@@ -2922,9 +3167,17 @@ export function openSettingsDialog() {
2922
3167
  };
2923
3168
  renderTitleGenPane();
2924
3169
 
3170
+ // 一级 / 二级 tab 放到滚动区(body)之上的固定区:内容滚动时标题、
3171
+ // 版本行(已并入标题行)与两级 tab 始终可见
3172
+ const subTabHost = h('div', { class: 'mt-2' });
3173
+ for (const bar of Object.values(subTabBars)) {
3174
+ bar.style.display = 'none';
3175
+ subTabHost.append(bar);
3176
+ }
3177
+ // flex-col:两个 tab 栏都是 inline-flex,走块布局会在栏下垫出基线空隙;
3178
+ // items-start:不拉伸子项,tab 栏胶囊底色保持内容宽度
3179
+ content.insertBefore(h('div', { class: 'flex flex-col items-start' }, tablist, subTabHost), body);
2925
3180
  body.append(
2926
- statusLine,
2927
- tablist,
2928
3181
  paneFeatures,
2929
3182
  paneShortcuts,
2930
3183
  paneAgents,