zcode-pro 1.8.0 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcode-pro",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "ZCode Pro — ZCode 桌面版增强工具:壁纸引擎(图片/视频/网页)、皮肤主题、会话快捷切换、状态栏统计等二十余项界面与体验增强;不修改客户端文件,用 ZCode Pro 快捷方式启动即可生效。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -21,7 +21,14 @@ import { listImportSessions, runImport } from './session-import/index.mjs';
21
21
 
22
22
  // 会话导入(/import/list、/import/run):把外部 CLI 的历史会话写成 ZCode 任务。
23
23
 
24
- const VERSION = '1.7.0';
24
+ // 版本号以 package.json 为准:升版只改版本文件,这里不再单独维护一份
25
+ //(此前固定写 1.7.0,之后一直没跟着升,设置弹窗显示的就是旧版)
26
+ const VERSION = (() => {
27
+ try {
28
+ const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'package.json'), 'utf8'));
29
+ return String(pkg.version || '0.0.0');
30
+ } catch { return '0.0.0'; }
31
+ })();
25
32
 
26
33
  // 全局提示词固定在用户主目录:官方加载器按 HOME/USERPROFILE 拼 .zcode/AGENTS.md,
27
34
  // 不读 ZCODE_DATA_BASE_DIR(数据根迁走时全局指令仍在原位)。
@@ -250,6 +257,10 @@ export function mergeThemeConfig(saved) {
250
257
  transition: bg.transition === 'fade' ? 'fade' : 'cut',
251
258
  fpsCap: TRANSCODE_FPS.has(Number(bg.fpsCap)) ? Number(bg.fpsCap) : 0,
252
259
  dialogFrost: bg.dialogFrost !== false,
260
+ // 插件卡片遮罩:注入插件沙箱页的主题色遮罩透明度(0=壁纸原样透出,1=实底);
261
+ // 默认 20%,卡片略实的初始观感,用户可在壁纸设置里调
262
+ cardVeil: bg.cardVeil != null && bg.cardVeil !== '' && Number.isFinite(Number(bg.cardVeil))
263
+ ? Math.min(1, Math.max(0, Number(bg.cardVeil))) : 0.2,
253
264
  videoVolume: bg.videoVolume != null && Number.isFinite(Number(bg.videoVolume))
254
265
  ? Math.min(1, Math.max(0, Number(bg.videoVolume))) : 0,
255
266
  playbackRate: bg.playbackRate != null && Number.isFinite(Number(bg.playbackRate))
@@ -275,6 +286,7 @@ export function mergeThemeConfig(saved) {
275
286
  export const BG_PARAM_KEYS = {
276
287
  maskOpacity: 'number', blurPx: 'number', panelOpacity: 'number', videoVolume: 'number', playbackRate: 'number',
277
288
  pauseOnHidden: 'boolean', pauseOnBlur: 'boolean', pauseOnBattery: 'boolean', dialogFrost: 'boolean',
289
+ cardVeil: 'number',
278
290
  fit: BG_FITS, transition: new Set(['cut', 'fade']), fpsCap: new Set([0, ...TRANSCODE_FPS]),
279
291
  };
280
292
 
@@ -311,6 +323,7 @@ export function defaultConfig() {
311
323
  tableCopy: true, // 表格工具条"复制表格"按钮:富文本剪贴板,粘贴即表格(table-copy.js)
312
324
  sessionLink: true, // 会话 ID 显示为任务名链接:聊天里的 sess_/session_ 显示为任务名,点击切换(session-link.js)
313
325
  composerProvider: true, // 输入框模型名前显示供应商名(composer-provider.js)
326
+ composerEditModel: true, // 编辑上一条消息时保持输入框当前模型(composer-edit-model.js)
314
327
  sessionImport: true, // 导入会话:把 Codex/Claude Code/dsh/pi 的历史会话复制成 ZCode 任务
315
328
  },
316
329
  // 空闲项目内存回收的判定时长(分钟,1–1440):项目无运行中会话、无后台命令
@@ -321,7 +334,8 @@ export function defaultConfig() {
321
334
  idleReclaimStartupMinutes: 5,
322
335
  // 样式调整(设置弹窗“样式调整”标签页)。null = 不覆盖,跟随应用默认。
323
336
  styles: {
324
- rowGap: null, // 段落间距:会话内各块之间的垂直间距(应用默认 20px)
337
+ thinkingRowGap: null, // 思考段落间距:“已工作/工作中”过程视图内各行的垂直间距(应用默认 20px)
338
+ answerRowGap: null, // 回答段落间距:回答正文与回合之间的垂直间距(应用默认 20px)
325
339
  listSpacing: null, // 列表上下留白(应用默认 12px)
326
340
  listItemSpacing: null, // 列表项之间的间距(应用默认 6px)
327
341
  quoteCodeSpacing: null, // 引用/代码块上下留白(应用默认 16px,my-4)
@@ -411,6 +425,22 @@ let configUnreadable = false;
411
425
  export function configFileUnreadable() {
412
426
  return configUnreadable;
413
427
  }
428
+ // 旧版单一的“段落间距”(rowGap)已拆成思考/回答两项:读旧配置或旧同步文档时
429
+ // 把旧值同时给到两项。新键显式出现过(哪怕是 null)就不再迁移,避免“恢复默认”
430
+ // 之后又被旧值顶回去
431
+ function migrateStyles(saved) {
432
+ const src = saved && typeof saved === 'object' && !Array.isArray(saved) ? saved : {};
433
+ const out = { ...defaultConfig().styles, ...src };
434
+ const legacy = src.rowGap;
435
+ if (typeof legacy === 'number' && Number.isFinite(legacy) && legacy >= 0
436
+ && !('thinkingRowGap' in src) && !('answerRowGap' in src)) {
437
+ out.thinkingRowGap = Math.round(legacy);
438
+ out.answerRowGap = Math.round(legacy);
439
+ delete out.rowGap;
440
+ }
441
+ return out;
442
+ }
443
+
414
444
  export function loadConfig(configFile) {
415
445
  try {
416
446
  if (!existsSync(configFile)) { configUnreadable = false; return defaultConfig(); }
@@ -425,7 +455,7 @@ export function loadConfig(configFile) {
425
455
  idleReclaimMinutes: Number.isFinite(minutes) && minutes >= 1 ? Math.min(1440, Math.round(minutes)) : 30,
426
456
  idleReclaimStartupMinutes: Number.isFinite(startupMinutes) && startupMinutes >= 0 ? Math.min(1440, Math.round(startupMinutes)) : 5,
427
457
  features: { ...defaultConfig().features, ...(saved.features || {}) },
428
- styles: { ...defaultConfig().styles, ...(saved.styles && typeof saved.styles === 'object' ? saved.styles : {}) },
458
+ styles: migrateStyles(saved.styles),
429
459
  aliases: { ...((saved.aliases && typeof saved.aliases === 'object') ? saved.aliases : {}) },
430
460
  headroomRoutes: { ...((saved.headroomRoutes && typeof saved.headroomRoutes === 'object' && !Array.isArray(saved.headroomRoutes)) ? saved.headroomRoutes : {}) },
431
461
  titleGen: mergeTitleGenConfig(saved.titleGen),
@@ -1010,6 +1040,7 @@ export function startHelper({ port, token, dataRoot, state, agentsFile = default
1010
1040
  pauseOnBlur: bt.bg && bt.bg.pauseOnBlur !== undefined ? bt.bg.pauseOnBlur : cur.bg.pauseOnBlur,
1011
1041
  pauseOnBattery: bt.bg && bt.bg.pauseOnBattery !== undefined ? bt.bg.pauseOnBattery : cur.bg.pauseOnBattery,
1012
1042
  dialogFrost: bt.bg && bt.bg.dialogFrost !== undefined ? bt.bg.dialogFrost : cur.bg.dialogFrost,
1043
+ cardVeil: bt.bg && bt.bg.cardVeil !== undefined ? bt.bg.cardVeil : cur.bg.cardVeil,
1013
1044
  regions: bt.bg && bt.bg.regions !== undefined ? bt.bg.regions : cur.bg.regions,
1014
1045
  },
1015
1046
  };
@@ -3609,7 +3640,11 @@ export async function classifyIdleBusyWindows(procs, paths, lookupTaskWs) {
3609
3640
  function applyStylesPartial(base, partial) {
3610
3641
  const out = (base && typeof base === 'object') ? base : {};
3611
3642
  if (!partial || typeof partial !== 'object') return out;
3612
- for (const key of ['rowGap', 'listSpacing', 'listItemSpacing', 'quoteCodeSpacing', 'tableSpacing', 'tableCellPaddingV', 'tableCellPaddingH', 'sidebarProjectSpacing', 'sidebarTaskSpacing']) {
3643
+ // 旧客户端/旧同步文档仍发 rowGap:折算到拆开后的两项
3644
+ if ('rowGap' in partial && !('thinkingRowGap' in partial) && !('answerRowGap' in partial)) {
3645
+ partial = { ...partial, thinkingRowGap: partial.rowGap, answerRowGap: partial.rowGap };
3646
+ }
3647
+ for (const key of ['thinkingRowGap', 'answerRowGap', 'listSpacing', 'listItemSpacing', 'quoteCodeSpacing', 'tableSpacing', 'tableCellPaddingV', 'tableCellPaddingH', 'sidebarProjectSpacing', 'sidebarTaskSpacing']) {
3613
3648
  if (key in partial) {
3614
3649
  const v = partial[key];
3615
3650
  if (v === null) out[key] = null;
package/src/host/main.mjs CHANGED
@@ -254,14 +254,15 @@ function fileUrlUnderInstall(fileUrl, installDir) {
254
254
  }
255
255
 
256
256
  // 可注入判定:引导脚本内含 helper 鉴权 token,只能进 ZCode 应用自身的页面。
257
- // 规则:http(s) 只放行本机回环地址;file:// 只放行 ZCode 安装目录下的页面
258
- //(应用 UI 在 <安装目录>/resources/app.asar/ 里);拦截外部网页与
259
- // data/blob/view-source/about 子文档,沙箱页同样不带 token;应用自有协议
260
- // 维持放行。refreshInjectScripts 重注册时目标可能已导航离开应用页,需重跑同款判定
257
+ // 规则:只放行 ZCode 安装目录下的 file:// 页面(应用 UI 在
258
+ // <安装目录>/resources/app.asar/ 里);http(s) 一律不注入——本机回环地址也可能是
259
+ // 用户自己打开的预览页/开发服务器(右侧预览就是这个形态),不能碰;拦截外部
260
+ // 网页与 data/blob/view-source/about 子文档,沙箱页同样不带 token;应用自有
261
+ // 协议维持放行。refreshInjectScripts 重注册时目标可能已导航离开应用页,需重跑同款判定
261
262
  export function isInjectableAppPage(url, installDir) {
262
263
  const u = String(url || '');
263
264
  if (/^zcode-sandbox:\/\//i.test(u)) return false;
264
- if (/^https?:\/\//i.test(u) && !/^https?:\/\/(127\.0\.0\.1|localhost)(:\d+)?(\/|$|\?|#)/i.test(u)) return false;
265
+ if (/^https?:\/\//i.test(u)) return false;
265
266
  if (/^(data|blob|view-source|about):/i.test(u)) return false;
266
267
  // file: 不带双斜杠的形态(file:/etc/…)也要过前缀校验,别落到末尾的放行
267
268
  if (/^file:/i.test(u)) return fileUrlUnderInstall(u, installDir);
@@ -282,7 +283,7 @@ export function buildGuard(installDir) {
282
283
  return `if ((function () {
283
284
  var h = location.href;
284
285
  if (/^(zcode-sandbox|about|data|blob|view-source):/i.test(h)) return false;
285
- if (/^https?:\\/\\//i.test(h)) return /^https?:\\/\\/(127\\.0\\.0\\.1|localhost)(:\\d+)?(\\/|$|\\?|#)/i.test(h);
286
+ if (/^https?:\\/\\//i.test(h)) return false;
286
287
  if (/^file:\\/\\//i.test(h)) {
287
288
  var raw = location.pathname, p;
288
289
  try { p = decodeURI(raw); } catch (e) { p = raw; }
@@ -422,8 +423,8 @@ export async function run(argv) {
422
423
  server.close();
423
424
  process.exit(1);
424
425
  }
425
- // 注入包按 mtime+size 缓存:npm run build 之后不用重启启动器——已打开页面
426
- // 下次“调试-重新加载”、新页面首次注入都直接吃新构建的包。
426
+ // 注入包按 mtime+size 缓存(仅在开发模式下每 3 秒复查):开发模式改完代码
427
+ // 重新构建后不用重启启动器,已打开页面下次“调试-重新加载”就吃新包。
427
428
  // shortcut: 同一毫秒内改写成相同字节数的内容检测不到,构建产物几乎不会出现,
428
429
  // 如真遇到可把缓存键换成内容哈希
429
430
  const injectCache = { mtime: 0, size: 0, source: '' };
@@ -555,7 +556,8 @@ export async function run(argv) {
555
556
  process.on('SIGTERM', () => { stopping = true; try { conn.close(); } catch {} try { helperMod.dispose?.(); } catch {} server.close(); process.exit(0); });
556
557
 
557
558
  // dist/inject.js 变更后把各页面的新文档脚本换成新包:已打开页面不打断,
558
- // 下次“调试-重新加载”即跑新代码(新页面首次注入本来就是新包)
559
+ // 下次“调试-重新加载”即跑新代码(新页面首次注入本来就是新包)。
560
+ // 只在开发模式运行:普通用户的构建产物不会变,不必每 3 秒查一次。
559
561
  async function refreshInjectScripts() {
560
562
  if (!conn || conn.closed) return; // 断连时注册会失败、日志也记不准,跳过;重连后 handleAttach 全量注册
561
563
  let source;
@@ -635,7 +637,8 @@ export async function run(argv) {
635
637
  // helper.mjs 变更时热替换辅助服务:先导入新模块(语法错在这里抛出、旧服务
636
638
  // 不动),再关旧起新。每次热替换都是全新模块实例,helper 模块级状态
637
639
  //(rollout 解析缓存等)从零开始。shortcut: 只覆盖 helper.mjs
638
- // 自身,它的依赖(settings.mjs、taskIndex.mjs 等)与 main.mjs 的改动仍需重启启动器
640
+ // 自身,它的依赖(settings.mjs、taskIndex.mjs 等)与 main.mjs 的改动仍需重启启动器。
641
+ // 只在开发模式运行:普通用户的 helper.mjs 不会在运行中变化,不必每 3 秒查一次。
639
642
  const helperStamp = () => {
640
643
  try { const st = statSync(join(here, 'helper.mjs')); return st.mtimeMs + ':' + st.size; } catch { return ''; }
641
644
  };
@@ -691,11 +694,23 @@ export async function run(argv) {
691
694
  }
692
695
  }
693
696
 
697
+ // 普通用户没有“调试”标签页,注入包也不会在运行中变化,热刷新只在开发模式开启。
698
+ const devActive = (() => {
699
+ if (process.env.ZCODEPRO_DEV === '1') return true;
700
+ try {
701
+ return JSON.parse(readFileSync(join(resolveDataRootDir(), 'zcodepro.json'), 'utf8')).devMode === true;
702
+ } catch {
703
+ return false;
704
+ }
705
+ })();
706
+
694
707
  while (!stopping) {
695
708
  await sleep(3000);
696
709
  if (stopping) break;
697
- await refreshInjectScripts();
698
- await maybeSwapHelper();
710
+ if (devActive) {
711
+ await refreshInjectScripts();
712
+ await maybeSwapHelper();
713
+ }
699
714
  if (!conn.closed) continue;
700
715
  // 连接断开:ZCode 退出则一并退出,否则重连
701
716
  if (!(await cdpAlive(args.cdpPort))) {
@@ -32,6 +32,7 @@ function usage() {
32
32
  pauseOnHidden=true 窗口最小化暂停 pauseOnBlur=false 窗口失焦暂停
33
33
  pauseOnBattery=false 电池供电暂停
34
34
  dialogFrost=true 设置弹窗磨砂透出壁纸
35
+ cardVeil=0.2 插件卡片遮罩 0-1
35
36
  wallpaper upload [--select] <文件路径>... 把本机图片/视频复制进图库(--select 顺手设为壁纸)
36
37
  wallpaper delete <图库文件名> 从图库删除
37
38
  `;
@@ -282,7 +283,7 @@ zcode-pro(ZCode 桌面版增强工具)内置壁纸引擎:图片、视频
282
283
  | \`zcode-pro wallpaper list\` | 看当前配置和图库文件 |
283
284
  | \`zcode-pro wallpaper set none\\|library <文件>\\|folder <目录>\\|url <地址>\\|web <地址>\` | 切换壁纸来源 |
284
285
  | \`zcode-pro wallpaper rotate <分钟> [--random\\|--sequential]\` | 文件夹轮换/网址刷新间隔(0 = 不轮换/不刷新) |
285
- | \`zcode-pro wallpaper params <键=值>...\` | 调画面(遮罩/模糊/面板/缩放)、转场、播放(音量/倍速/帧率)、暂停条件、弹窗磨砂 |
286
+ | \`zcode-pro wallpaper params <键=值>...\` | 调画面(遮罩/模糊/面板/缩放/插件卡片遮罩)、转场、播放(音量/倍速/帧率)、暂停条件、弹窗磨砂 |
286
287
  | \`zcode-pro wallpaper upload [--select] <文件路径>...\` | 把本机图片/视频复制进图库(--select 顺手设为当前壁纸) |
287
288
  | \`zcode-pro wallpaper delete <图库文件名>\` | 从图库删文件 |
288
289
 
@@ -310,6 +311,7 @@ zcode-pro(ZCode 桌面版增强工具)内置壁纸引擎:图片、视频
310
311
  | videoVolume / playbackRate | 音量 0-1 / 倍速 0.5-2 | 数值 |
311
312
  | pauseOnHidden / pauseOnBlur / pauseOnBattery | 最小化/失焦/电池暂停 | true/false |
312
313
  | dialogFrost | 设置弹窗磨砂透出壁纸(false = 恢复不透明底) | true/false |
314
+ | cardVeil | 插件卡片遮罩:插件卡片透出壁纸时垫在卡片底下的主题色遮罩 | 0-1,默认 0.2 |
313
315
  | regions.left / center / right | 分区背景,每区可独立缩放/遮罩(null = 跟随全局;仅静态图,mode 取 library/folder/url,文件夹轮换复用全局间隔与顺序) | {mode,file,folder,url,fit,maskOpacity} |
314
316
  `;
315
317
 
@@ -278,8 +278,10 @@ const zh = {
278
278
  devReloadDesc: '点击后约 2-3 秒内所有 ZCode 窗口自动刷新一次并加载新脚本。',
279
279
  devToolsSwitch: '开发者工具',
280
280
  devToolsSwitchDesc: '官方侧栏的“开发者工具”面板(Token 调试 / 网络状态),默认关闭。改动写入官方每秒轮询的开关,1 秒内生效。',
281
- rowGapName: '段落间距',
282
- rowGapDesc: '会话中段落等文本块之间的垂直间距(回合之间、答案内部)。',
281
+ thinkingRowGapName: '思考段落间距',
282
+ thinkingRowGapDesc: '“已工作/工作中”过程记录里各行、思考正文之间的垂直间距。',
283
+ answerRowGapName: '回答段落间距',
284
+ answerRowGapDesc: '回答正文里段落等文本块之间、以及回合之间的垂直间距。',
283
285
  listSpacingName: '列表上下边距',
284
286
  listSpacingDesc: '答案中列表上下的留白。',
285
287
  listItemSpacingName: '列表项间距',
@@ -453,6 +455,8 @@ const zh = {
453
455
  themeBgBlur: '画面模糊',
454
456
  themeBgPanel: '面板不透明度',
455
457
  themeBgDialogFrost: '设置弹窗磨砂',
458
+ themeBgCardVeil: '插件卡片遮罩',
459
+ themeBgCardVeilHint: '壁纸开着时垫在插件卡片底下的主题色遮罩:0 不遮(壁纸原样透出),越大卡片越实在、越暗。',
456
460
  themeBgMisc: '其他',
457
461
  themeBgFollowGlobal: '跟随全局',
458
462
  themeBgRegionsHint: '来源选“默认(全局壁纸)”即该区不单独设置、直接显示全局壁纸;每行的缩放、遮罩可单独设置,选“跟随全局”即跟随“画面”的值;模糊、转场、播放仅作用于全局壁纸(分区只能铺图,不能播视频)。分区用文件夹时,轮换间隔与随机顺序沿用全局设置。',
@@ -536,6 +540,8 @@ const zh = {
536
540
  featureSessionLink: '会话 ID 显示为任务名链接',
537
541
  featureSessionLinkDesc: '提问与回答里的会话 ID(sess_ / session_ 开头)显示为任务名,点击切换到该会话,悬停可看原始 ID。',
538
542
  featureComposerProviderDesc: '模型名前显示供应商名(如 BigModel-Max1 / glm-5.3),区分同名模型。',
543
+ featureComposerEditModel: '编辑时保持当前模型',
544
+ featureComposerEditModelDesc: '点编辑上一条消息时,保持你点编辑前选的模型,不会换成这条消息当时用的模型;进入编辑后仍然可以再换,重跑用最终选的模型。',
539
545
  featureSessionImport: '导入会话',
540
546
  featureSessionImportDesc: '在设置弹窗里把 Codex、Claude Code、dsh、pi 的历史会话导入成 ZCode 任务。',
541
547
  imageCopy: '复制图片',
@@ -909,8 +915,10 @@ const en = {
909
915
  devToolsSwitchDesc: 'The official "Developer tools" side pane (Token debug / Network status), off by default. The change goes to the flag the official app polls every second.',
910
916
  devReloading: 'Reloading…',
911
917
  devReloadDesc: 'Every ZCode window refreshes automatically within 2-3 seconds to load the new script.',
912
- rowGapName: 'Paragraph spacing',
913
- rowGapDesc: 'Vertical spacing between text blocks (turns, paragraphs inside answers).',
918
+ thinkingRowGapName: 'Thinking paragraph spacing',
919
+ thinkingRowGapDesc: 'Vertical spacing between rows of the "Worked/Working" process view and thinking text.',
920
+ answerRowGapName: 'Answer paragraph spacing',
921
+ answerRowGapDesc: 'Vertical spacing between text blocks inside answers and between turns.',
914
922
  listSpacingName: 'List spacing',
915
923
  listSpacingDesc: 'Space above and below lists.',
916
924
  listItemSpacingName: 'List item spacing',
@@ -1083,6 +1091,8 @@ const en = {
1083
1091
  themeBgBlur: 'Wallpaper blur',
1084
1092
  themeBgPanel: 'Panel opacity',
1085
1093
  themeBgDialogFrost: 'Frosted settings window',
1094
+ themeBgCardVeil: 'Plugin card veil',
1095
+ themeBgCardVeilHint: 'Theme-colored veil behind plugin cards while a wallpaper is on: 0 shows the wallpaper as-is; higher makes cards more solid and darker.',
1086
1096
  themeBgMisc: 'Other',
1087
1097
  themeBgFollowGlobal: 'Follow global',
1088
1098
  themeBgRegionsHint: '"Default (global)" means the region is not set on its own and just shows the global wallpaper. Fit and mask can be set per row; "Follow global" uses the Display values. Blur, transition and playback apply only to the global wallpaper (regions are static images, no video). Region folders reuse the global rotation interval and order settings.',
@@ -1166,6 +1176,8 @@ const en = {
1166
1176
  featureSessionLink: 'Session ID links',
1167
1177
  featureSessionLinkDesc: 'Shows session IDs (sess_ / session_) in chat as task names; click to switch to that session, hover for the raw ID.',
1168
1178
  featureComposerProviderDesc: 'Shows the provider before the model name (e.g. BigModel-Max1 / glm-5.3).',
1179
+ featureComposerEditModel: 'Keep current model when editing',
1180
+ featureComposerEditModelDesc: 'Keeps the model you selected before clicking edit instead of switching to the model the message was sent with. You can still change it in the editor; the rerun uses the final selection.',
1169
1181
  featureSessionImport: 'Session import',
1170
1182
  featureSessionImportDesc: 'Import sessions from Codex, Claude Code, dsh and pi as ZCode tasks from the settings dialog.',
1171
1183
  imageCopy: 'Copy image',
@@ -0,0 +1,312 @@
1
+ // 编辑上一条消息时保持输入框当前模型:官方进入编辑态会载入这条消息提交时的模型,
2
+ // 把用户刚在输入框里切好的模型换回去。这里在点编辑按钮时记下当前模型,
3
+ // 编辑态出现后直接调用模型选择器的 onValueChange 改回去(找不到回调时退回菜单);
4
+ // 重跑就使用当前选择的模型。
5
+ import { getConfig } from '../core.js';
6
+
7
+ const TRIGGER_SEL = '[data-testid="chat-model-select-trigger"]';
8
+ const PROVIDER_TRIGGER_SEL = '[data-testid="composer-provider-trigger"]';
9
+ const EDIT_BAR_SEL = '[data-testid="v4-composer-edit-bar"]';
10
+ const EDIT_BTN_PREFIX = 'v4-edit-';
11
+ const ITEM_PREFIX = 'chat-model-select-item-';
12
+ const GROUP_PREFIX = 'chat-model-select-group-';
13
+
14
+ let installed = false;
15
+ let enabled = true;
16
+ let modelBeforeEdit = null;
17
+ let pendingEdit = false;
18
+ let editRequestAt = 0;
19
+ let providerListAt = 0;
20
+ let applying = false;
21
+
22
+ function currentModelValue() {
23
+ const trigger = document.querySelector(TRIGGER_SEL);
24
+ return trigger ? trigger.getAttribute('data-model-current-value') || '' : '';
25
+ }
26
+
27
+ // 与官方 encodeCustomModelValue 对应:custom:<providerId>:<modelName>
28
+ export function decodeProviderId(value) {
29
+ if (!value || !value.startsWith('custom:')) return null;
30
+ const body = value.slice('custom:'.length);
31
+ const index = body.indexOf(':');
32
+ const encoded = index < 0 ? body : body.slice(0, index);
33
+ try {
34
+ return decodeURIComponent(encoded);
35
+ } catch {
36
+ return encoded;
37
+ }
38
+ }
39
+
40
+ function findByTestId(exact) {
41
+ return (
42
+ [...document.querySelectorAll('[data-testid]')].find(
43
+ (el) => el.getAttribute('data-testid') === exact,
44
+ ) || null
45
+ );
46
+ }
47
+
48
+ function clickModelItem(value) {
49
+ const item = findByTestId(ITEM_PREFIX + value);
50
+ if (!item) return false;
51
+ item.click();
52
+ return true;
53
+ }
54
+
55
+ // 自定义 provider 的模型在别的供应商下:先点模型菜单顶部的供应商行展开列表,
56
+ // 列表里的分组项才是 chat-model-select-group-registry-provider:<providerId>。
57
+ function openProviderList() {
58
+ const trigger = document.querySelector(PROVIDER_TRIGGER_SEL);
59
+ if (!trigger) return false;
60
+ trigger.focus();
61
+ for (const name of ['pointerenter', 'mouseenter', 'mousemove']) {
62
+ trigger.dispatchEvent(new MouseEvent(name, { bubbles: true, cancelable: true, view: window }));
63
+ }
64
+ trigger.click();
65
+ return true;
66
+ }
67
+
68
+ function openProviderGroup(providerId) {
69
+ const group = findByTestId(GROUP_PREFIX + 'registry-provider:' + providerId);
70
+ if (!group) {
71
+ // 列表还没展开或点空了:等下一轮再看,别在同一轮里反复点把已展开的列表收起来。
72
+ if (Date.now() - providerListAt > 400) {
73
+ providerListAt = Date.now();
74
+ openProviderList();
75
+ }
76
+ return false;
77
+ }
78
+ group.focus();
79
+ for (const name of ['pointerenter', 'mouseenter', 'mousemove']) {
80
+ group.dispatchEvent(new MouseEvent(name, { bubbles: true, cancelable: true, view: window }));
81
+ }
82
+ group.click();
83
+ return true;
84
+ }
85
+
86
+ function menuIsOpen() {
87
+ return Boolean(
88
+ document.querySelector(`[data-testid^="${ITEM_PREFIX}"]`) ||
89
+ document.querySelector(`[data-testid^="${GROUP_PREFIX}"]`),
90
+ );
91
+ }
92
+
93
+ // 模型菜单是 Radix 的受控下拉菜单,只派发 click 打不开,要按真实指针操作走一遍 pointerdown。
94
+ function openModelMenu() {
95
+ const trigger = document.querySelector(TRIGGER_SEL);
96
+ if (!trigger || trigger.disabled || trigger.getAttribute('aria-disabled') === 'true') {
97
+ return false;
98
+ }
99
+ if (trigger.getAttribute('aria-expanded') === 'true' || menuIsOpen()) return true;
100
+ trigger.focus();
101
+ const base = {
102
+ bubbles: true,
103
+ cancelable: true,
104
+ composed: true,
105
+ view: window,
106
+ button: 0,
107
+ pointerId: 1,
108
+ pointerType: 'mouse',
109
+ isPrimary: true,
110
+ };
111
+ trigger.dispatchEvent(new PointerEvent('pointerdown', { ...base, buttons: 1 }));
112
+ trigger.dispatchEvent(new PointerEvent('pointerup', { ...base, buttons: 0 }));
113
+ trigger.click();
114
+ return true;
115
+ }
116
+
117
+ // 直接改模型:模型选择器组件的 props 里有 onValueChange(菜单项选中时调用的同一个
118
+ // 函数),顺着触发按钮的 React fiber 往上找即可,不用打开菜单。找不到时退回菜单。
119
+ function setModelDirect(value) {
120
+ const trigger = document.querySelector(TRIGGER_SEL);
121
+ if (!trigger) return false;
122
+ const fiberKey = Object.keys(trigger).find((k) => k.startsWith('__reactFiber$'));
123
+ if (!fiberKey) return false;
124
+ let fiber = trigger[fiberKey];
125
+ for (let i = 0; fiber && i < 80; i += 1) {
126
+ const props = fiber.memoizedProps || {};
127
+ if (
128
+ props.composerOptions &&
129
+ typeof props.composerOptions === 'object' &&
130
+ typeof props.onValueChange === 'function'
131
+ ) {
132
+ try {
133
+ props.onValueChange(value);
134
+ return true;
135
+ } catch {
136
+ return false;
137
+ }
138
+ }
139
+ fiber = fiber.return;
140
+ }
141
+ return false;
142
+ }
143
+
144
+ // 先直接改;直接改没生效(结构变化/被拒)再走菜单。
145
+ function applyModel(value) {
146
+ if (!setModelDirect(value)) {
147
+ selectModel(value);
148
+ return;
149
+ }
150
+ setTimeout(() => {
151
+ if (!enabled || !document.querySelector(EDIT_BAR_SEL)) return;
152
+ if (currentModelValue() !== value) selectModel(value);
153
+ }, 300);
154
+ }
155
+
156
+ // 合并菜单选中模型后官方故意不关(方便继续调思考强度),这里点一下菜单外面收掉。
157
+ function closeModelMenu() {
158
+ const base = {
159
+ bubbles: true,
160
+ cancelable: true,
161
+ composed: true,
162
+ view: window,
163
+ button: 0,
164
+ pointerId: 1,
165
+ pointerType: 'mouse',
166
+ isPrimary: true,
167
+ };
168
+ document.body.dispatchEvent(new PointerEvent('pointerdown', { ...base, buttons: 1 }));
169
+ document.body.dispatchEvent(new PointerEvent('pointerup', { ...base, buttons: 0 }));
170
+ document.body.dispatchEvent(new MouseEvent('click', { ...base, buttons: 0 }));
171
+ }
172
+
173
+ // 打开模型菜单并选中 value。菜单可能按 provider 分组,目标是二级菜单里的模型项。
174
+ function selectModel(value) {
175
+ if (applying || !enabled) return;
176
+ if (currentModelValue() === value) return;
177
+ applying = true;
178
+ let attempts = 0;
179
+ let groupOpened = false;
180
+ const step = () => {
181
+ if (!enabled || currentModelValue() === value) {
182
+ applying = false;
183
+ return;
184
+ }
185
+ if (!menuIsOpen()) {
186
+ openModelMenu();
187
+ groupOpened = false;
188
+ }
189
+ if (clickModelItem(value)) {
190
+ // 给官方提交选择留一帧,再收菜单并释放 applying。
191
+ setTimeout(() => {
192
+ closeModelMenu();
193
+ applying = false;
194
+ }, 100);
195
+ return;
196
+ }
197
+ const providerId = decodeProviderId(value);
198
+ if (providerId) {
199
+ // 子菜单开一次就够,反复点会把已经展开的菜单又收起来。
200
+ if (!groupOpened) groupOpened = openProviderGroup(providerId);
201
+ } else {
202
+ // 非 custom 值:逐个展开分组找目标项。
203
+ for (const group of document.querySelectorAll(`[data-testid^="${GROUP_PREFIX}"]`)) {
204
+ group.focus();
205
+ for (const name of ['pointerenter', 'mouseenter', 'mousemove']) {
206
+ group.dispatchEvent(
207
+ new MouseEvent(name, { bubbles: true, cancelable: true, view: window }),
208
+ );
209
+ }
210
+ group.click();
211
+ if (clickModelItem(value)) {
212
+ applying = false;
213
+ return;
214
+ }
215
+ }
216
+ }
217
+ attempts += 1;
218
+ if (attempts < 20) setTimeout(step, 120);
219
+ else {
220
+ applying = false;
221
+ console.warn('[zcodepro] composer-edit-model: 没能选回模型 ' + value);
222
+ }
223
+ };
224
+ if (!menuIsOpen() && !openModelMenu()) {
225
+ applying = false;
226
+ return;
227
+ }
228
+ setTimeout(step, 80);
229
+ }
230
+
231
+ function onEditClick(event) {
232
+ if (!enabled) return;
233
+ const target = event.target;
234
+ if (!(target instanceof Element)) return;
235
+ if (!target.closest(`[data-testid^="${EDIT_BTN_PREFIX}"]`)) return;
236
+ const value = currentModelValue();
237
+ if (document.querySelector(EDIT_BAR_SEL)) return;
238
+ if (!value) return;
239
+ modelBeforeEdit = value;
240
+ pendingEdit = true;
241
+ editRequestAt = Date.now();
242
+ }
243
+
244
+ function onMutate() {
245
+ if (!enabled) return;
246
+ const bar = document.querySelector(EDIT_BAR_SEL);
247
+ if (!bar) {
248
+ // 点完编辑到编辑条出现之间有若干帧,期间别的 DOM 变化不能把刚记下的模型清掉;
249
+ // 超过 3 秒还没等到编辑条,说明这次点击没有进入编辑态,再清。
250
+ if (!pendingEdit || Date.now() - editRequestAt > 3000) {
251
+ pendingEdit = false;
252
+ modelBeforeEdit = null;
253
+ }
254
+ applying = false;
255
+ return;
256
+ }
257
+ if (!pendingEdit || !modelBeforeEdit) return;
258
+ if (Date.now() - editRequestAt > 3000) {
259
+ pendingEdit = false;
260
+ modelBeforeEdit = null;
261
+ return;
262
+ }
263
+ pendingEdit = false;
264
+ const target = modelBeforeEdit;
265
+ let checks = 0;
266
+ // 官方载入原消息模型可能晚一帧到几帧;等它稳定后再比较,避免改在它前面被它覆盖。
267
+ const tick = () => {
268
+ if (!enabled || !document.querySelector(EDIT_BAR_SEL)) return;
269
+ const current = currentModelValue();
270
+ if (current && current !== target) {
271
+ const official = current;
272
+ applyModel(target);
273
+ // 官方如果在后面又改回原消息的模型,再选回来;用户自己选的其它模型不干预。
274
+ const watch = (left) => {
275
+ if (!enabled || !document.querySelector(EDIT_BAR_SEL)) return;
276
+ if (currentModelValue() === official && left > 0) {
277
+ applyModel(target);
278
+ setTimeout(() => watch(left - 1), 400);
279
+ }
280
+ };
281
+ setTimeout(() => watch(2), 400);
282
+ return;
283
+ }
284
+ checks += 1;
285
+ if (checks < 16) setTimeout(tick, 50);
286
+ };
287
+ setTimeout(tick, 60);
288
+ }
289
+
290
+ export function startComposerEditModel() {
291
+ if (installed || typeof document === 'undefined') return;
292
+ installed = true;
293
+ void getConfig()
294
+ .then((cfg) => {
295
+ enabled = cfg.features ? cfg.features.composerEditModel !== false : true;
296
+ })
297
+ .catch(() => {});
298
+ window.addEventListener('zcodepro:config-changed', () => {
299
+ void getConfig(true)
300
+ .then((cfg) => {
301
+ enabled = cfg.features ? cfg.features.composerEditModel !== false : true;
302
+ if (!enabled) {
303
+ pendingEdit = false;
304
+ modelBeforeEdit = null;
305
+ }
306
+ })
307
+ .catch(() => {});
308
+ });
309
+ document.addEventListener('click', onEditClick, true);
310
+ new MutationObserver(onMutate).observe(document.body, { childList: true, subtree: true });
311
+ onMutate();
312
+ }
@@ -396,6 +396,11 @@ export function openSettingsDialog() {
396
396
  if (await setFeature('composerProvider', next)) f.composerProvider = next;
397
397
  refreshRows();
398
398
  }),
399
+ settingRow(L.featureComposerEditModel, L.featureComposerEditModelDesc, f.composerEditModel !== false, async () => {
400
+ const next = !(f.composerEditModel !== false);
401
+ if (await setFeature('composerEditModel', next)) f.composerEditModel = next;
402
+ refreshRows();
403
+ }),
399
404
  settingRow(L.featureSessionImport, L.featureSessionImportDesc, f.sessionImport !== false, async () => {
400
405
  const next = !(f.sessionImport !== false);
401
406
  if (await setFeature('sessionImport', next)) f.sessionImport = next;
@@ -729,10 +734,11 @@ export function openSettingsDialog() {
729
734
  styleCell(L.sidebarProjectSpacingName, L.sidebarProjectSpacingDesc, 'sidebarProjectSpacing', { max: 24 }),
730
735
  styleCell(L.sidebarTaskSpacingName, L.sidebarTaskSpacingDesc, 'sidebarTaskSpacing', { max: 24 }),
731
736
  widthCell,
732
- styleCell(L.rowGapName, L.rowGapDesc, 'rowGap'),
733
737
  styleCell(L.userLineHeightName, L.userLineHeightDesc, 'userLineHeight', { min: 1, max: 3, step: 0.05, unit: 'x' }),
734
- styleCell(L.lineHeightName, L.lineHeightDesc, 'lineHeight', { min: 1, max: 3, step: 0.05, unit: 'x' }),
735
738
  styleCell(L.thinkingLineHeightName, L.thinkingLineHeightDesc, 'thinkingLineHeight', { min: 1, max: 3, step: 0.05, unit: 'x' }),
739
+ styleCell(L.thinkingRowGapName, L.thinkingRowGapDesc, 'thinkingRowGap'),
740
+ styleCell(L.lineHeightName, L.lineHeightDesc, 'lineHeight', { min: 1, max: 3, step: 0.05, unit: 'x' }),
741
+ styleCell(L.answerRowGapName, L.answerRowGapDesc, 'answerRowGap'),
736
742
  styleCell(L.codeLineHeightName, L.codeLineHeightDesc, 'codeLineHeight', { min: 1, max: 3, step: 0.05, unit: 'x' }),
737
743
  styleCell(L.listSpacingName, L.listSpacingDesc, 'listSpacing'),
738
744
  styleCell(L.listItemSpacingName, L.listItemSpacingDesc, 'listItemSpacing'),
@@ -1313,6 +1319,10 @@ export function openSettingsDialog() {
1313
1319
  void saveTheme({ bg: { dialogFrost: !(themeCfg.bg.dialogFrost !== false) } });
1314
1320
  });
1315
1321
  };
1322
+ // 插件卡片遮罩:壁纸开着时垫在插件卡片页底下的主题色遮罩,
1323
+ // 0 = 壁纸原样透出,越大卡片越实在、越暗。默认 20%。没壁纸时整行不显示
1324
+ const cardVeilRow = () => sliderRow(L.themeBgCardVeil, '', 0, 100, 1, Math.round(numOr(themeCfg.bg.cardVeil, 0.2) * 100), '%',
1325
+ (v) => { void saveTheme({ bg: { cardVeil: v / 100 } }); }, L.themeBgCardVeilHint);
1316
1326
  // 图片网址输入:change 提交;空值回无壁纸
1317
1327
  const urlInput = h('input', { type: 'url', value: themeCfg.bg.url, class: themeInputCls, placeholder: 'https://...' });
1318
1328
  urlInput.addEventListener('change', () => {
@@ -1457,6 +1467,7 @@ export function openSettingsDialog() {
1457
1467
  pauseCheck('pauseOnHidden', L.themeBgPauseHidden),
1458
1468
  pauseCheck('pauseOnBlur', L.themeBgPauseBlur),
1459
1469
  pauseCheck('pauseOnBattery', L.themeBgPauseBattery)),
1470
+ themeCfg.bg.mode !== 'none' ? cardVeilRow() : null,
1460
1471
  dialogFrostRow())),
1461
1472
  bgInput,
1462
1473
  );