zcode-pro 1.8.1 → 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.1",
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(数据根迁走时全局指令仍在原位)。
@@ -316,6 +323,7 @@ export function defaultConfig() {
316
323
  tableCopy: true, // 表格工具条"复制表格"按钮:富文本剪贴板,粘贴即表格(table-copy.js)
317
324
  sessionLink: true, // 会话 ID 显示为任务名链接:聊天里的 sess_/session_ 显示为任务名,点击切换(session-link.js)
318
325
  composerProvider: true, // 输入框模型名前显示供应商名(composer-provider.js)
326
+ composerEditModel: true, // 编辑上一条消息时保持输入框当前模型(composer-edit-model.js)
319
327
  sessionImport: true, // 导入会话:把 Codex/Claude Code/dsh/pi 的历史会话复制成 ZCode 任务
320
328
  },
321
329
  // 空闲项目内存回收的判定时长(分钟,1–1440):项目无运行中会话、无后台命令
@@ -326,7 +334,8 @@ export function defaultConfig() {
326
334
  idleReclaimStartupMinutes: 5,
327
335
  // 样式调整(设置弹窗“样式调整”标签页)。null = 不覆盖,跟随应用默认。
328
336
  styles: {
329
- rowGap: null, // 段落间距:会话内各块之间的垂直间距(应用默认 20px)
337
+ thinkingRowGap: null, // 思考段落间距:“已工作/工作中”过程视图内各行的垂直间距(应用默认 20px)
338
+ answerRowGap: null, // 回答段落间距:回答正文与回合之间的垂直间距(应用默认 20px)
330
339
  listSpacing: null, // 列表上下留白(应用默认 12px)
331
340
  listItemSpacing: null, // 列表项之间的间距(应用默认 6px)
332
341
  quoteCodeSpacing: null, // 引用/代码块上下留白(应用默认 16px,my-4)
@@ -416,6 +425,22 @@ let configUnreadable = false;
416
425
  export function configFileUnreadable() {
417
426
  return configUnreadable;
418
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
+
419
444
  export function loadConfig(configFile) {
420
445
  try {
421
446
  if (!existsSync(configFile)) { configUnreadable = false; return defaultConfig(); }
@@ -430,7 +455,7 @@ export function loadConfig(configFile) {
430
455
  idleReclaimMinutes: Number.isFinite(minutes) && minutes >= 1 ? Math.min(1440, Math.round(minutes)) : 30,
431
456
  idleReclaimStartupMinutes: Number.isFinite(startupMinutes) && startupMinutes >= 0 ? Math.min(1440, Math.round(startupMinutes)) : 5,
432
457
  features: { ...defaultConfig().features, ...(saved.features || {}) },
433
- styles: { ...defaultConfig().styles, ...(saved.styles && typeof saved.styles === 'object' ? saved.styles : {}) },
458
+ styles: migrateStyles(saved.styles),
434
459
  aliases: { ...((saved.aliases && typeof saved.aliases === 'object') ? saved.aliases : {}) },
435
460
  headroomRoutes: { ...((saved.headroomRoutes && typeof saved.headroomRoutes === 'object' && !Array.isArray(saved.headroomRoutes)) ? saved.headroomRoutes : {}) },
436
461
  titleGen: mergeTitleGenConfig(saved.titleGen),
@@ -3615,7 +3640,11 @@ export async function classifyIdleBusyWindows(procs, paths, lookupTaskWs) {
3615
3640
  function applyStylesPartial(base, partial) {
3616
3641
  const out = (base && typeof base === 'object') ? base : {};
3617
3642
  if (!partial || typeof partial !== 'object') return out;
3618
- 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']) {
3619
3648
  if (key in partial) {
3620
3649
  const v = partial[key];
3621
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))) {
@@ -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: '列表项间距',
@@ -538,6 +540,8 @@ const zh = {
538
540
  featureSessionLink: '会话 ID 显示为任务名链接',
539
541
  featureSessionLinkDesc: '提问与回答里的会话 ID(sess_ / session_ 开头)显示为任务名,点击切换到该会话,悬停可看原始 ID。',
540
542
  featureComposerProviderDesc: '模型名前显示供应商名(如 BigModel-Max1 / glm-5.3),区分同名模型。',
543
+ featureComposerEditModel: '编辑时保持当前模型',
544
+ featureComposerEditModelDesc: '点编辑上一条消息时,保持你点编辑前选的模型,不会换成这条消息当时用的模型;进入编辑后仍然可以再换,重跑用最终选的模型。',
541
545
  featureSessionImport: '导入会话',
542
546
  featureSessionImportDesc: '在设置弹窗里把 Codex、Claude Code、dsh、pi 的历史会话导入成 ZCode 任务。',
543
547
  imageCopy: '复制图片',
@@ -911,8 +915,10 @@ const en = {
911
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.',
912
916
  devReloading: 'Reloading…',
913
917
  devReloadDesc: 'Every ZCode window refreshes automatically within 2-3 seconds to load the new script.',
914
- rowGapName: 'Paragraph spacing',
915
- 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.',
916
922
  listSpacingName: 'List spacing',
917
923
  listSpacingDesc: 'Space above and below lists.',
918
924
  listItemSpacingName: 'List item spacing',
@@ -1170,6 +1176,8 @@ const en = {
1170
1176
  featureSessionLink: 'Session ID links',
1171
1177
  featureSessionLinkDesc: 'Shows session IDs (sess_ / session_) in chat as task names; click to switch to that session, hover for the raw ID.',
1172
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.',
1173
1181
  featureSessionImport: 'Session import',
1174
1182
  featureSessionImportDesc: 'Import sessions from Codex, Claude Code, dsh and pi as ZCode tasks from the settings dialog.',
1175
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'),
@@ -9,6 +9,10 @@ import { ensureStyle } from '../ui.js';
9
9
  let enabled = true;
10
10
  let items = DEFAULT_STATUS_ITEMS.map((x) => ({ ...x }));
11
11
  let barEl = null;
12
+ let liftedPane = null; // 为状态栏让出底部空间而加过 margin-bottom 的滚动容器
13
+ // 状态栏区域只有输入框下的官方留白时上下一共 3px,太挤:把滚动容器底再抬
14
+ // 10px(输入框随之上移),状态栏上下留白各约 8px
15
+ const BAR_LIFT = 10;
12
16
  let lastStats = null; // /stats/usage 响应缓存(失败保旧值)
13
17
  let lastSid = null; // 上次取数的会话 id:切换会话即作废缓存,不显示上个会话的速率
14
18
  let statsSid = null; // lastStats 取数时的会话 id:渲染时对不上就不用(切会话瞬间不顶旧值)
@@ -293,6 +297,15 @@ function itemContent(id, L) {
293
297
  }
294
298
  }
295
299
 
300
+ // 输入框所在的滚动容器:会话视图里输入框区是 sticky 在聊天滚动容器底部的,
301
+ // 容器下边缘之外的像素会被裁掉。状态栏挤在输入框后面时,滚一下就被裁没。
302
+ function clipPane(el) {
303
+ for (let n = el.parentElement; n && n !== document.body; n = n.parentElement) {
304
+ if (/(auto|scroll|hidden)/.test(getComputedStyle(n).overflowY)) return n;
305
+ }
306
+ return null;
307
+ }
308
+
296
309
  function renderBar() {
297
310
  // 3.16.1 的输入框是 contenteditable(旧版是 textarea),两种都认
298
311
  const ta = composerEl();
@@ -300,23 +313,61 @@ function renderBar() {
300
313
  if (!enabled || !host || !host.parentElement) {
301
314
  if (barEl) barEl.remove();
302
315
  barEl = null;
316
+ if (liftedPane) { liftedPane.style.marginBottom = ''; liftedPane = null; }
303
317
  lastRenderedHtml = null; // 元素没了,去重基线同步清空,重建后首渲染不被跳过
304
318
  return;
305
319
  }
306
- if (!barEl || !barEl.isConnected) {
320
+ // 会话视图:状态栏挪到滚动容器外(容器父级带定位),按输入框的横向位置绝对
321
+ // 定位、贴容器底,滚动裁不到它;新建会话视图没有滚动裁剪,仍在输入框后面排
322
+ // (下方是官方功能按钮区,不能往下压)。
323
+ // 按选中会话判定视图(按钮区与状态条不在同一父容器,兄弟判断不可用)
324
+ const hasSession = !!selectedSessionId();
325
+ const pane = hasSession ? clipPane(host) : null;
326
+ const mount = pane && pane.parentElement && getComputedStyle(pane.parentElement).position !== 'static'
327
+ ? pane.parentElement
328
+ : host.parentElement;
329
+ if (!barEl || !barEl.isConnected || barEl.parentElement !== mount) {
307
330
  if (!barEl) {
308
331
  barEl = document.createElement('div');
309
332
  barEl.className = 'zcodepro-statusbar';
310
333
  lastRenderedHtml = null; // 新元素:内容基线作废
311
334
  }
312
- host.parentElement.insertBefore(barEl, host.nextSibling);
335
+ if (mount === host.parentElement) mount.insertBefore(barEl, host.nextSibling);
336
+ else mount.append(barEl);
337
+ }
338
+ if (mount !== host.parentElement) {
339
+ // 给状态栏让出上下留白:滚动容器底抬 BAR_LIFT,输入框随之上移
340
+ if (liftedPane && liftedPane !== pane) liftedPane.style.marginBottom = '';
341
+ liftedPane = pane;
342
+ liftedPane.style.marginBottom = `${BAR_LIFT}px`;
343
+ const hr = host.getBoundingClientRect();
344
+ const mr = mount.getBoundingClientRect();
345
+ // 横跨输入框底到窗口底,内容垂直居中:上下留白相等
346
+ barEl.style.position = 'absolute';
347
+ // 绝对定位以父级 padding box 为参照,减去边框宽度
348
+ barEl.style.left = `${Math.round(hr.left - mr.left - mount.clientLeft)}px`;
349
+ barEl.style.width = `${Math.round(hr.width)}px`;
350
+ barEl.style.top = `${Math.round(hr.bottom - mr.top - mount.clientTop)}px`;
351
+ // 紧挨窗底(下方只剩几像素留白)才补到窗口底;下方还有终端等面板时只贴
352
+ // 到列底,否则整条会伸进面板区被盖住,只剩上面那截留白
353
+ const below = innerHeight - mr.bottom;
354
+ barEl.style.bottom = `${below >= 0 && below <= 8 ? Math.round(mr.bottom - innerHeight) : 0}px`;
355
+ barEl.style.zIndex = '20';
356
+ barEl.style.marginBottom = '0';
357
+ barEl.style.paddingTop = '0';
358
+ barEl.style.paddingBottom = '0';
359
+ } else {
360
+ if (liftedPane) { liftedPane.style.marginBottom = ''; liftedPane = null; }
361
+ barEl.style.position = '';
362
+ barEl.style.left = '';
363
+ barEl.style.width = '';
364
+ barEl.style.top = '';
365
+ barEl.style.bottom = '';
366
+ barEl.style.zIndex = '';
367
+ barEl.style.paddingTop = '';
368
+ barEl.style.marginBottom = hasSession ? '-14px' : '0';
369
+ barEl.style.paddingBottom = hasSession ? '0' : '7px';
313
370
  }
314
- // 新建会话视图(无选中会话)下方是官方的功能按钮区,不能往下压:上下对称
315
- // 留 7px;普通会话视图下方是窗口底的官方留白,压进去贴底(同为约 7px)。
316
- // 按选中会话判定视图(按钮区与状态条不在同一父容器,兄弟判断不可用)
317
- const hasSession = !!selectedSessionId();
318
- barEl.style.marginBottom = hasSession ? '-14px' : '0';
319
- barEl.style.paddingBottom = hasSession ? '0' : '7px';
320
371
  const L = t();
321
372
  const entries = [];
322
373
  for (const it of items) {