zcode-pro 1.6.2 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,367 @@
1
+ // 设置弹窗的“导入会话”标签页:列出来源会话、筛选、多选导入。
2
+ import { h, t, rpc, errText } from '../core.js';
3
+ import { btnSmall, showToast } from '../ui.js';
4
+ import { findServices } from './ws-running.js';
5
+
6
+ const INPUT_CLS = 'h-8 w-full rounded-lg border border-border bg-input px-2.5 text-ui-sm text-foreground outline-none transition-shadow placeholder:text-foreground-subtle focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40';
7
+
8
+ function tag(text, title = '') {
9
+ return h('span', { class: 'shrink-0 rounded border border-border px-1 text-ui-xs text-foreground-subtle', title: title || undefined }, text);
10
+ }
11
+
12
+ function when(ms) {
13
+ if (!ms) return '';
14
+ try { return new Date(ms).toLocaleString(); } catch { return ''; }
15
+ }
16
+
17
+ export function createSessionImportPane() {
18
+ const L = t();
19
+ const root = h('div', { role: 'tabpanel', style: 'display:none' });
20
+
21
+ let sources = [];
22
+ let active = '';
23
+ let sessions = [];
24
+ let selected = new Set();
25
+ let projects = [];
26
+ let projectId = '';
27
+ let showAll = false;
28
+ let onlyProject = false;
29
+ let search = '';
30
+ let loading = false;
31
+ let importing = false;
32
+ let loaded = false;
33
+ let pendingReload = false;
34
+ let searchTimer = null;
35
+
36
+ const statusEl = h('div', { class: 'mt-2 min-h-4 text-ui-xs/relaxed text-foreground-subtle' });
37
+ const listEl = h('div', { class: 'max-h-80 overflow-auto divide-y divide-border' });
38
+ const sourceTabs = h('div', { role: 'tablist', 'aria-orientation': 'horizontal', class: 'zcodepro-tablist' });
39
+ const searchInput = h('input', {
40
+ type: 'text', class: INPUT_CLS + ' min-w-0 flex-1', placeholder: L.importSearch,
41
+ spellcheck: 'false', autocomplete: 'off',
42
+ });
43
+ const projectSelect = h('select', { class: INPUT_CLS + ' min-w-0 max-w-56' });
44
+ const onlyProjectBox = h('input', { type: 'checkbox' });
45
+ const showAllBox = h('input', { type: 'checkbox', title: L.importShowAllTip });
46
+ const selectAllBox = h('input', { type: 'checkbox' });
47
+ const refreshBtn = btnSmall(L.importRefresh, () => { void loadList(); });
48
+ const importBtn = btnSmall(L.importSelected.replace('{n}', '0'), () => { void doImport(); }, 'shrink-0', 'primary');
49
+ importBtn.disabled = true;
50
+
51
+ const setStatus = (text, kind = '') => {
52
+ statusEl.textContent = text || '';
53
+ statusEl.className = 'mt-2 min-h-4 text-ui-xs/relaxed '
54
+ + (kind === 'error' ? 'text-destructive' : 'text-foreground-subtle');
55
+ };
56
+
57
+ const selectedProject = () => projects.find((p) => p.id === projectId) || null;
58
+ const projectRoots = () => (selectedProject()?.roots || []).map((r) => r.path).filter(Boolean);
59
+
60
+ // 侧边栏的任务树由页面里的控制器维护,直接写库不会通知它。导入完成后在 React
61
+ // 树里找到持有 tree/factTree 的控制器,调用它的 refresh(),项目列表和“任务”
62
+ // 区就会重新拉取;任务索引里已经写了 unread_at,原生未读蓝点随之出现。
63
+ const refreshTaskTree = async () => {
64
+ const rootEl = document.getElementById('root');
65
+ const containerKey = rootEl && Object.keys(rootEl).find((k) => k.startsWith('__reactContainer$'));
66
+ if (!containerKey) return false;
67
+ const seen = new Set();
68
+ let found = null;
69
+ const scan = (o) => {
70
+ if (!o || typeof o !== 'object' || seen.has(o) || found) return;
71
+ seen.add(o);
72
+ try {
73
+ if (typeof o.refresh === 'function' && 'factTree' in o && 'tree' in o) found = o;
74
+ } catch { /* ignore */ }
75
+ };
76
+ let visited = 0;
77
+ const visit = (f) => {
78
+ if (!f || found || visited > 60000) return;
79
+ visited++;
80
+ for (const h of [f.memoizedProps, f.memoizedState]) {
81
+ if (!h || typeof h !== 'object') continue;
82
+ scan(h);
83
+ for (const v of Object.values(h)) if (v && typeof v === 'object') scan(v);
84
+ }
85
+ visit(f.child);
86
+ visit(f.sibling);
87
+ };
88
+ visit(rootEl[containerKey]);
89
+ if (!found) return false;
90
+ try {
91
+ await found.refresh();
92
+ return true;
93
+ } catch {
94
+ return false;
95
+ }
96
+ };
97
+
98
+ // 导入任务只写了库,对应会话的工作区没有准备过,任务列表服务里没有这个来源;
99
+ // 用户点归档/置顶/未读时 mutation 会报“无法解析唯一 source”。导入后对每个
100
+ // 来源工作区恢复一次会话,注册工作区,再做树刷新,让原生操作可用。
101
+ const prepareWorkspaces = async (imported) => {
102
+ const ag = findServices()?.zcodeAgentService;
103
+ if (!ag || typeof ag.resumeSession !== 'function') return;
104
+ const seen = new Set();
105
+ for (const item of imported) {
106
+ if (!item.workspace || seen.has(item.workspace)) continue;
107
+ seen.add(item.workspace);
108
+ try {
109
+ await ag.resumeSession({ workspacePath: item.workspace, sessionId: item.taskId });
110
+ } catch { /* 单个工作区准备失败不影响其他 */ }
111
+ }
112
+ };
113
+
114
+ const renderSources = () => {
115
+ sourceTabs.replaceChildren(...sources.filter((s) => s.available).map((s) => h('button', {
116
+ type: 'button', role: 'tab', class: 'zcodepro-tab',
117
+ 'aria-selected': String(active === s.id),
118
+ 'data-state': active === s.id ? 'active' : 'inactive',
119
+ disabled: !s.available,
120
+ title: s.available ? '' : L.importSourceMissing,
121
+ onClick: () => {
122
+ if (!s.available || active === s.id) return;
123
+ active = s.id;
124
+ selected = new Set();
125
+ sessions = [];
126
+ renderSources();
127
+ void loadList();
128
+ },
129
+ }, s.label)));
130
+ };
131
+
132
+ const selectable = () => sessions.filter((s) => !s.imported);
133
+ const allSelected = () => {
134
+ const list = selectable();
135
+ return list.length > 0 && list.every((s) => selected.has(s.sessionId));
136
+ };
137
+
138
+ const renderList = () => {
139
+ selectAllBox.checked = allSelected();
140
+ selectAllBox.disabled = importing || !selectable().length;
141
+ importBtn.textContent = L.importSelected.replace('{n}', String(selected.size));
142
+ importBtn.disabled = importing || !selected.size;
143
+ if (loading) {
144
+ listEl.replaceChildren(h('div', { class: 'px-3 py-6 text-center text-ui-sm text-foreground-subtle' }, L.importLoading));
145
+ return;
146
+ }
147
+ if (!sessions.length) {
148
+ listEl.replaceChildren(h('div', { class: 'px-3 py-6 text-center text-ui-sm text-foreground-subtle' }, L.importNoSessions));
149
+ return;
150
+ }
151
+ listEl.replaceChildren(...sessions.map((s) => {
152
+ const checked = selected.has(s.sessionId);
153
+ const box = h('input', {
154
+ type: 'checkbox', class: 'mt-0.5 shrink-0', checked,
155
+ disabled: importing || s.imported,
156
+ onChange: () => {
157
+ if (box.checked) selected.add(s.sessionId);
158
+ else selected.delete(s.sessionId);
159
+ renderList();
160
+ },
161
+ });
162
+ const tags = [];
163
+ if (s.imported) {
164
+ tags.push(tag(
165
+ s.importedArchived ? L.importAlreadyArchived : L.importAlready,
166
+ s.importedArchived ? L.importArchivedTaskTip : '',
167
+ ));
168
+ }
169
+ if (s.archived) tags.push(tag(L.importArchived));
170
+ if (s.subagent) tags.push(tag(L.importSubagent));
171
+ if (s.codexImport) tags.push(tag(L.importCodexCopy));
172
+ if (s.large) tags.push(tag(L.importLarge));
173
+ if (s.cwdExists === false) tags.push(tag(L.importCwdMissing));
174
+ return h('label', {
175
+ class: 'flex cursor-pointer items-start gap-2 px-3 py-2 transition-colors hover:bg-surface-hover',
176
+ title: s.cwd || '',
177
+ },
178
+ box,
179
+ h('div', { class: 'min-w-0 flex-1' },
180
+ h('div', { class: 'truncate text-ui-sm' }, s.title || s.sessionId),
181
+ h('div', { class: 'mt-0.5 flex items-center gap-2 overflow-hidden' },
182
+ h('span', { class: 'min-w-0 flex-1 truncate text-ui-xs text-foreground-subtle' }, s.cwd || s.sourcePath || ''),
183
+ h('span', { class: 'shrink-0 text-ui-xs text-foreground-subtle' }, when(s.updatedAt)),
184
+ ...tags)));
185
+ }));
186
+ };
187
+
188
+ const loadProjects = async () => {
189
+ const res = await rpc('/projects-v2');
190
+ projects = res.ok && Array.isArray(res.projects) ? res.projects : [];
191
+ const current = projectId;
192
+ projectSelect.replaceChildren(
193
+ h('option', { value: '' }, L.importProjectNone),
194
+ ...projects.map((p) => h('option', { value: p.id }, p.name || p.id)),
195
+ );
196
+ projectSelect.value = projects.some((p) => p.id === current) ? current : '';
197
+ projectId = projectSelect.value;
198
+ onlyProjectBox.disabled = !projectId;
199
+ if (!projectId) { onlyProjectBox.checked = false; onlyProject = false; }
200
+ };
201
+
202
+ const loadList = async () => {
203
+ if (loading || importing) { pendingReload = true; return; }
204
+ loading = true;
205
+ renderList();
206
+ const done = () => {
207
+ loading = false;
208
+ if (pendingReload) {
209
+ pendingReload = false;
210
+ queueMicrotask(() => { void loadList(); });
211
+ }
212
+ };
213
+ if (!sources.length || !sources.some((s) => s.id === active && s.available)) {
214
+ const meta = await rpc('/import/list', { method: 'POST', body: { source: '' } });
215
+ if (meta.ok && Array.isArray(meta.sources)) sources = meta.sources;
216
+ if (!sources.some((s) => s.id === active && s.available)) {
217
+ active = (sources.find((s) => s.available) || {}).id || '';
218
+ }
219
+ renderSources();
220
+ if (!active) {
221
+ sessions = [];
222
+ done();
223
+ renderList();
224
+ setStatus(L.importNoSource);
225
+ return;
226
+ }
227
+ }
228
+ const res = await rpc('/import/list', {
229
+ method: 'POST',
230
+ body: {
231
+ source: active, showAll, search,
232
+ roots: onlyProject && projectId ? projectRoots() : [],
233
+ },
234
+ });
235
+ if (!res.ok) {
236
+ sessions = [];
237
+ done();
238
+ renderList();
239
+ setStatus(errText(res), 'error');
240
+ return;
241
+ }
242
+ sources = res.sources || sources;
243
+ sessions = res.sessions || [];
244
+ const usable = new Set(selectable().map((s) => s.sessionId));
245
+ selected = new Set([...selected].filter((id) => usable.has(id)));
246
+ if (!active || !sources.some((s) => s.id === active)) {
247
+ active = (sources.find((s) => s.available) || {}).id || '';
248
+ }
249
+ done();
250
+ renderSources();
251
+ renderList();
252
+ setStatus(res.unavailable ? L.importNoSource : '');
253
+ };
254
+
255
+ const doImport = async () => {
256
+ if (importing || !selected.size) return;
257
+ const chosen = sessions.filter((s) => selected.has(s.sessionId));
258
+ if (!chosen.length) return;
259
+ if (chosen.some((s) => s.large)) {
260
+ if (!window.confirm(L.importConfirmLarge)) return;
261
+ }
262
+ importing = true;
263
+ renderList();
264
+ setStatus(L.importImporting);
265
+ let summary = '';
266
+ let summaryKind = '';
267
+ try {
268
+ const res = await rpc('/import/run', {
269
+ method: 'POST',
270
+ body: {
271
+ source: active,
272
+ projectId: projectId || null,
273
+ items: chosen.map((s) => ({
274
+ sessionId: s.sessionId, sourcePath: s.sourcePath, title: s.title, cwd: s.cwd,
275
+ })),
276
+ },
277
+ });
278
+ if (!res.ok) {
279
+ setStatus(errText(res), 'error');
280
+ showToast(L.importFailed + ': ' + errText(res), 'error');
281
+ return;
282
+ }
283
+ const imported = Array.isArray(res.imported) ? res.imported : [];
284
+ const skipped = Array.isArray(res.skipped) ? res.skipped : [];
285
+ const failed = Array.isArray(res.failed) ? res.failed : [];
286
+ const msg = L.importDone.replace('{ok}', String(imported.length))
287
+ .replace('{skip}', String(skipped.length)).replace('{fail}', String(failed.length));
288
+ const detail = failed.slice(0, 3).map((f) => `${f.sessionId}: ${f.error}`).join('; ');
289
+ summary = msg + (detail ? ' · ' + detail : '');
290
+ summaryKind = failed.length ? 'error' : '';
291
+ showToast(msg, failed.length ? 'error' : 'success');
292
+ if (imported.length) {
293
+ void (async () => {
294
+ await prepareWorkspaces(imported);
295
+ await refreshTaskTree().catch(() => {});
296
+ })();
297
+ }
298
+ selected = new Set();
299
+ } finally {
300
+ importing = false;
301
+ }
302
+ await loadList();
303
+ setStatus(summary, summaryKind);
304
+ };
305
+
306
+ searchInput.addEventListener('input', () => {
307
+ search = searchInput.value;
308
+ clearTimeout(searchTimer);
309
+ searchTimer = setTimeout(() => { void loadList(); }, 250);
310
+ });
311
+ projectSelect.addEventListener('change', () => {
312
+ projectId = projectSelect.value;
313
+ onlyProjectBox.disabled = !projectId;
314
+ if (!projectId) { onlyProjectBox.checked = false; onlyProject = false; }
315
+ void loadList();
316
+ });
317
+ onlyProjectBox.addEventListener('change', () => {
318
+ onlyProject = onlyProjectBox.checked;
319
+ void loadList();
320
+ });
321
+ showAllBox.addEventListener('change', () => {
322
+ showAll = showAllBox.checked;
323
+ selected = new Set();
324
+ void loadList();
325
+ });
326
+ selectAllBox.addEventListener('change', () => {
327
+ if (selectAllBox.checked) selected = new Set(selectable().map((s) => s.sessionId));
328
+ else selected = new Set();
329
+ renderList();
330
+ });
331
+
332
+ const checkLabel = (box, text, title = '') => h('label', { class: 'flex shrink-0 items-center gap-1.5 text-ui-xs text-foreground-subtle', title: title || undefined }, box, text);
333
+
334
+ root.append(
335
+ h('p', { class: 'text-ui-sm/relaxed text-foreground-subtle' }, L.importDesc),
336
+ h('div', { class: 'mt-3' }, sourceTabs),
337
+ h('div', { class: 'mt-2 flex flex-wrap items-center gap-2' },
338
+ searchInput,
339
+ projectSelect,
340
+ checkLabel(onlyProjectBox, L.importOnlyProject),
341
+ checkLabel(showAllBox, L.importShowAll, L.importShowAllTip),
342
+ refreshBtn),
343
+ h('div', { class: 'mt-2 flex items-center justify-between gap-2' },
344
+ h('div', { class: 'flex items-center gap-2' },
345
+ checkLabel(selectAllBox, L.importSelectAll),
346
+ h('span', { class: 'text-ui-xs text-foreground-subtle' }, L.importProjectHint)),
347
+ importBtn),
348
+ h('div', { class: 'mt-2 rounded-xl border border-border' }, listEl),
349
+ statusEl,
350
+ );
351
+
352
+ root.__onShow = () => {
353
+ if (importing) return;
354
+ if (!loaded) {
355
+ loaded = true;
356
+ setStatus(L.importLoading);
357
+ void (async () => {
358
+ await loadProjects();
359
+ await loadList();
360
+ })();
361
+ } else {
362
+ void loadList();
363
+ }
364
+ };
365
+
366
+ return root;
367
+ }
@@ -7,7 +7,9 @@ import { rpc, t, getConfig } from '../core.js';
7
7
  import { ensureStyle, showToast } from '../ui.js';
8
8
 
9
9
  const CONV = '[class*="@md/conversation"]';
10
- const SKIP_SEL = 'pre, code, a, button, input, textarea, select, [data-zcodepro-sess]';
10
+ // contenteditable 也要跳过:行内编辑用的是 Lexical 托管 DOM,改它里面的文本节点会被
11
+ // Lexical 删掉再插回,两边来回触发会让页面卡死(消息里带会话 ID 时必现)
12
+ const SKIP_SEL = 'pre, code, a, button, input, textarea, select, [contenteditable], [data-zcodepro-sess]';
11
13
  // 会话 id:sess_ 与 session_ 两种前缀(新版应用为 session_),尾字符必须是
12
14
  // 字母数字(防止把 "session_xxx-" 里说明文字的连字符吞进来)
13
15
  const SESS_RE = /(?<![A-Za-z0-9_])(?:session|sess)_[A-Za-z0-9][A-Za-z0-9_-]*[A-Za-z0-9]/g;
@@ -446,14 +446,17 @@ export function startSessionSwitch() {
446
446
  await openPopup('attention');
447
447
  return;
448
448
  }
449
- // e 只负责打开(初始显示最近 10 条,c 可继续加载更早的);已开着或正在
450
- // 打开时不动作。只在 mru 为空(连当前会话都没有,如停在新建任务页)才
451
- // 提示——首次仅开着当前会话时照常打开,列表里就是它这一条
449
+ // e 打开最近 10 条(c 可继续加载更早的)。attention 弹窗(r)开着时切到
450
+ // 最近列表(关掉重开,与 r 在 mru 弹窗开着时的行为对称);mru 已开着则
451
+ // 不动作。只在 mru 为空(连当前会话都没有,如停在新建任务页)才提示——
452
+ // 首次仅开着当前会话时照常打开,列表里就是它这一条
452
453
  if (k === hotkeys.switchRecent) {
453
- if (!e.repeat && !popupEl && !openPopupInflight) {
454
- if (!mru.length) { showToast(t().switcherEmpty, 'warning'); return; }
455
- await openPopup('mru');
456
- }
454
+ if (e.repeat) return;
455
+ if (openPopupInflight) await openPopupInflight;
456
+ if (popupEl && popupMode !== 'attention') return;
457
+ if (!mru.length) { showToast(t().switcherEmpty, 'warning'); return; }
458
+ if (popupEl) closePopup(false);
459
+ await openPopup('mru');
457
460
  return;
458
461
  }
459
462
  // x/c:弹窗已开着(含 attention 模式)直接在当前列表移动——attention 的
@@ -8,6 +8,8 @@ import { migrationCard } from './alias-migration.js';
8
8
  import { applyStyles, STYLE_DEFAULTS, showStyleHighlight, hideStyleHighlight } from './styles.js';
9
9
  import { THEME_SKINS, CUSTOM_DEFAULTS } from './theme.js';
10
10
  import { copyToClipboard, hCopyIcon } from './copy-path.js';
11
+ import { claimAutoUpdateRun } from './plugin-updates.js';
12
+ import { createSessionImportPane } from './session-import.js';
11
13
 
12
14
  // 调宿主桥在系统浏览器打开外链;宿主没暴露该能力时静默忽略
13
15
  function openExternal(url) {
@@ -287,13 +289,13 @@ export function openSettingsDialog() {
287
289
  showToast(pluginsStatusLine.textContent, 'success');
288
290
  };
289
291
  void (async () => {
290
- // 打开设置弹窗即自动更新(与启动时同语义):开关开着且有新版时直接更,
291
- // 状态行如实显示过程与结果;开关关闭时只检查并显示“N 个可更新”
292
+ // 打开设置弹窗时,只有本次 ZCode 启动还没自动更新过才直接更:
293
+ // 同一次启动里反复开关弹窗不再重复下载/更新。开关关闭时只显示可更新数
292
294
  const cfg = await getConfig(true).catch(() => null);
293
295
  const res = await rpc('/plugins/status');
294
- if (!res.ok) { setPluginsStatus(''); return; }
296
+ if (!res.ok) { setPluginsStatus(errText(res)); return; }
295
297
  const n = (res.updates || []).length;
296
- if (cfg && (cfg.features || {}).autoUpdatePlugins === true && n > 0) {
298
+ if (cfg && (cfg.features || {}).autoUpdatePlugins === true && n > 0 && claimAutoUpdateRun()) {
297
299
  void runPluginsUpdate();
298
300
  return;
299
301
  }
@@ -394,6 +396,11 @@ export function openSettingsDialog() {
394
396
  if (await setFeature('composerProvider', next)) f.composerProvider = next;
395
397
  refreshRows();
396
398
  }),
399
+ settingRow(L.featureSessionImport, L.featureSessionImportDesc, f.sessionImport !== false, async () => {
400
+ const next = !(f.sessionImport !== false);
401
+ if (await setFeature('sessionImport', next)) f.sessionImport = next;
402
+ refreshRows();
403
+ }),
397
404
  settingRow(L.featureSandboxReclaim, L.featureSandboxReclaimDesc, f.sandboxReclaim !== false, async () => {
398
405
  const next = !(f.sandboxReclaim !== false);
399
406
  if (await setFeature('sandboxReclaim', next)) f.sandboxReclaim = next;
@@ -409,6 +416,11 @@ export function openSettingsDialog() {
409
416
  if (await setFeature('wsRunningSpin', next)) f.wsRunningSpin = next;
410
417
  refreshRows();
411
418
  }),
419
+ settingRow(L.featureSubagentIcon, L.featureSubagentIconDesc, f.subagentIcon !== false, async () => {
420
+ const next = !(f.subagentIcon !== false);
421
+ if (await setFeature('subagentIcon', next)) f.subagentIcon = next;
422
+ refreshRows();
423
+ }),
412
424
  settingRow(L.featureNewtabPanels, L.featureNewtabPanelsDesc, f.newtabPanels !== false, async () => {
413
425
  const next = !(f.newtabPanels !== false);
414
426
  if (await setFeature('newtabPanels', next)) f.newtabPanels = next;
@@ -591,12 +603,13 @@ export function openSettingsDialog() {
591
603
  const paneAgents = h('div', { role: 'tabpanel', style: 'display:none' });
592
604
  const paneProxy = h('div', { role: 'tabpanel', style: 'display:none' });
593
605
  const paneSync = h('div', { role: 'tabpanel', style: 'display:none' });
606
+ const paneImport = createSessionImportPane();
594
607
  const paneVision = h('div', { role: 'tabpanel', style: 'display:none' });
595
608
  const paneRtk = h('div', { role: 'tabpanel', style: 'display:none' });
596
609
  const paneHeadroom = h('div', { role: 'tabpanel', style: 'display:none' });
597
610
  const paneTitleGen = h('div', { role: 'tabpanel', style: 'display:none' });
598
611
  const paneDebug = h('div', { role: 'tabpanel', style: 'display:none' });
599
- const panes = { features: paneFeatures, shortcuts: paneShortcuts, styles: paneStyles, perf: panePerf, agents: paneAgents, proxy: paneProxy, sync: paneSync, vision: paneVision, headroom: paneHeadroom, rtk: paneRtk, debug: paneDebug };
612
+ const panes = { features: paneFeatures, shortcuts: paneShortcuts, styles: paneStyles, perf: panePerf, agents: paneAgents, proxy: paneProxy, sync: paneSync, import: paneImport, vision: paneVision, headroom: paneHeadroom, rtk: paneRtk, debug: paneDebug };
600
613
  // 一级 tab 顺序:功能 → 外观 → 行为 → 性能 → 快捷键 → 代理/同步/插件页
601
614
  const tabDefs = [
602
615
  ['features', L.tabFeatures],
@@ -606,6 +619,7 @@ export function openSettingsDialog() {
606
619
  ['shortcuts', L.tabShortcuts],
607
620
  ['proxy', L.tabProxy],
608
621
  ['sync', L.tabSync],
622
+ ...(config.features.sessionImport !== false ? [['import', L.tabImport]] : []),
609
623
  ['vision', L.tabVision],
610
624
  ['headroom', L.tabHeadroom],
611
625
  ['rtk', L.tabRtk],
@@ -627,6 +641,7 @@ export function openSettingsDialog() {
627
641
  if (name !== 'shortcuts' && hkRecording) stopHkRecording();
628
642
  for (const [id, pane] of Object.entries(panes)) pane.style.display = id === name ? '' : 'none';
629
643
  for (const [id, bar] of Object.entries(subTabBars)) bar.style.display = id === name ? '' : 'none';
644
+ if (name === 'import') paneImport.__onShow?.();
630
645
  renderTabs();
631
646
  };
632
647
  renderTabs();
@@ -830,7 +845,7 @@ export function openSettingsDialog() {
830
845
  const sbList = h('div', { class: 'divide-y divide-border rounded-xl border border-border' });
831
846
  const sbGlobalList = h('div', { class: 'divide-y divide-border rounded-xl border border-border' });
832
847
  // 每轮统计节(输入/输出/缓存,只开关不排序——显示顺序固定)
833
- const TURN_NAMES = { turnIn: 'sbLabelIn', turnOut: 'sbLabelOut', turnCache: 'sbLabelCache' };
848
+ const TURN_NAMES = { turnIn: 'sbLabelIn', turnOut: 'sbLabelOut', turnTps: 'sbLabelTps', turnCache: 'sbLabelCache' };
834
849
  const turnItems = () => {
835
850
  const saved = config.statusBar && Array.isArray(config.statusBar.turnItems) ? config.statusBar.turnItems : null;
836
851
  if (!saved) return DEFAULT_TURN_ITEMS.map((x) => ({ ...x }));
@@ -1102,7 +1117,7 @@ export function openSettingsDialog() {
1102
1117
  ...CUSTOM_FIELDS.map(([k, key]) => customInput(mode, k, L[key])))))),
1103
1118
  );
1104
1119
  };
1105
- // 分区背景行:跟随全局 / 图库(下拉选图)/ 文件夹 / 网址
1120
+ // 分区背景行:默认(全局壁纸)/ 图库(下拉选图)/ 文件夹 / 网址
1106
1121
  // regionMaskTimers 记各分区遮罩滑杆的防抖提交(按行分开,互不误撤);
1107
1122
  // 只有"跟随全局"胶囊撤本行在途提交(它写 null 与拖动值直接冲突)
1108
1123
  const regionMaskTimers = {};
@@ -1706,12 +1721,6 @@ export function openSettingsDialog() {
1706
1721
  const proxyTestBtn = btnSmall(L.proxyTest, () => { void runProxyTest(); }, 'shrink-0');
1707
1722
  const runProxyTest = async () => {
1708
1723
  if (proxyTesting) return;
1709
- // 空地址不发请求(等网络超时才报“检测失败”的体验太差),立即提示
1710
- if (!proxyInput.value.trim()) {
1711
- proxyTestState.className = 'mt-2 text-ui-xs/relaxed text-amber-500';
1712
- proxyTestState.textContent = L.proxyTestEmpty;
1713
- return;
1714
- }
1715
1724
  proxyTesting = true;
1716
1725
  proxyTestBtn.disabled = true;
1717
1726
  proxyTestBtn.textContent = L.proxyTesting;
@@ -2210,9 +2219,43 @@ export function openSettingsDialog() {
2210
2219
  // 就自己刷新,宁可多刷一次也不能停在旧代码 + 失效 token 上
2211
2220
  setTimeout(() => { try { location.reload(); } catch { /* ignore */ } }, 2000);
2212
2221
  };
2222
+ // 开发者工具开关:官方侧栏面板(Token 调试/网络状态)由官方自己读 localStorage 的
2223
+ // zcode:developer-tools:enabled / zcode:token-debug:enabled(每秒轮询,值为
2224
+ // 0/false/off/no 算关)。默认关闭,打开与否完全由用户决定
2225
+ const DT_KEYS = ['zcode:developer-tools:enabled', 'zcode:token-debug:enabled'];
2226
+ const dtRead = (v) => v !== null && !['0', 'false', 'off', 'no'].includes(v.trim().toLowerCase());
2227
+ const dtOn = () => DT_KEYS.some((k) => dtRead(localStorage.getItem(k)));
2228
+ const dtSet = (on) => {
2229
+ for (const k of DT_KEYS) {
2230
+ if (on) localStorage.setItem(k, 'true');
2231
+ else localStorage.removeItem(k);
2232
+ }
2233
+ };
2234
+ const dtSwitchBtn = (checked) => h('button', {
2235
+ type: 'button', role: 'switch', 'aria-checked': String(checked),
2236
+ class: 'relative inline-flex shrink-0 cursor-pointer items-center',
2237
+ }, h('span', { class: 'zcodepro-switch', 'data-zcodepro-switch': '', 'data-state': checked ? 'on' : 'off' },
2238
+ h('span', { class: 'zcodepro-switch-knob' })));
2239
+ const devToolsRow = () => {
2240
+ const sw = dtSwitchBtn(dtOn());
2241
+ return h('div', {
2242
+ class: 'flex cursor-pointer items-center justify-between gap-2 px-2 py-1.5',
2243
+ onClick: () => {
2244
+ dtSet(!dtOn());
2245
+ const n = dtOn();
2246
+ sw.setAttribute('aria-checked', String(n));
2247
+ sw.firstElementChild.setAttribute('data-state', n ? 'on' : 'off');
2248
+ },
2249
+ },
2250
+ h('div', { class: 'min-w-0' },
2251
+ h('div', { class: 'text-ui-sm font-medium text-foreground' }, L.devToolsSwitch),
2252
+ h('div', { class: 'mt-0.5 text-ui-xs/relaxed text-foreground-subtle' }, L.devToolsSwitchDesc)),
2253
+ sw);
2254
+ };
2213
2255
  paneDebug.append(
2214
2256
  h('p', { class: 'text-ui-sm/relaxed text-foreground-subtle' }, L.devModeDesc),
2215
- h('div', { class: 'mt-3 rounded-xl border border-border' },
2257
+ h('div', { class: 'mt-3 divide-y divide-border rounded-xl border border-border' },
2258
+ devToolsRow(),
2216
2259
  h('div', { class: 'flex items-center justify-between gap-2 px-2 py-1.5' },
2217
2260
  h('div', { class: 'min-w-0' },
2218
2261
  h('div', { class: 'text-ui-sm font-medium text-foreground' }, L.devReload),
@@ -2226,7 +2269,15 @@ export function openSettingsDialog() {
2226
2269
  // 默认单级链与 zcode-vision 插件 DEFAULT_CONFIG 保持一致:session(跟随会话供应商、
2227
2270
  // 模型留空=会话当前模型)。需要兜底级可手动加 GLM 订阅直连。
2228
2271
  // 赠送额度级 trust-build 暂不进默认:ZCode 网关不放行无人值守调用(ADR-0002)。
2229
- const VISION_DEFAULT_PROMPT = '请详细描述这张图片的全部内容。若是界面或图表截图,请先把所有错误、警告、异常状态逐字引用出来(含完整原文),再描述整体布局、文字与关键数据。';
2272
+ const VISION_DEFAULT_PROMPT_ZH = '请详细描述这张图片的全部内容。若是界面或图表截图,请先把所有错误、警告、异常状态逐字引用出来(含完整原文),再描述整体布局、文字与关键数据。';
2273
+ const VISION_DEFAULT_PROMPT_EN = 'Describe the entire content of this image in detail. If it is a UI or chart screenshot, first quote every error, warning, and abnormal state verbatim (including the full text), then describe the overall layout, text, and key data.';
2274
+ const VISION_DEFAULT_PROMPT = isZhLocale() ? VISION_DEFAULT_PROMPT_ZH : VISION_DEFAULT_PROMPT_EN;
2275
+ // 已保存的配置里如果是内置默认提示词(旧版固定中文),按当前语言重新取:
2276
+ // 否则切到英文后老配置仍然发中文提示词。用户自己改过的提示词不动。
2277
+ const isBuiltinVisionPrompt = (p) => {
2278
+ const text = String(p || '').trim();
2279
+ return text === VISION_DEFAULT_PROMPT_ZH || text === VISION_DEFAULT_PROMPT_EN;
2280
+ };
2230
2281
  const VISION_DEFAULT_CFG = {
2231
2282
  enabled: true,
2232
2283
  chainMode: 'fallback',
@@ -2244,6 +2295,11 @@ export function openSettingsDialog() {
2244
2295
  let visionCfg = visionRes.ok && visionRes.config && typeof visionRes.config === 'object'
2245
2296
  ? structuredClone(visionRes.config)
2246
2297
  : null;
2298
+ if (visionCfg && Array.isArray(visionCfg.proxies)) {
2299
+ for (const proxy of visionCfg.proxies) {
2300
+ if (isBuiltinVisionPrompt(proxy.prompt)) proxy.prompt = VISION_DEFAULT_PROMPT;
2301
+ }
2302
+ }
2247
2303
  // 自动初始化只试一次(每次打开弹窗):写盘失败回退手动“添加代理”卡
2248
2304
  let visionAutoInitTried = false;
2249
2305
  let visionSaveTimer = null;
@@ -2952,6 +3008,25 @@ export function openSettingsDialog() {
2952
3008
  }));
2953
3009
  };
2954
3010
  renderHrUsageSwitch();
3011
+ // Serena:语义代码检索 MCP 开关。不走 hrRun(与压缩代理进程无关),点击即时
3012
+ // 写 cli/config.json;ZCode 新会话启动时加载该 MCP,当前会话不重连。
3013
+ const hrSerenaRow = h('div');
3014
+ const renderSerenaSwitch = () => {
3015
+ const serenaOn = !!(headroomRes.serena && headroomRes.serena.enabled);
3016
+ hrSerenaRow.replaceChildren(
3017
+ settingRow(L.serenaSwitch, L.serenaSwitchDesc, serenaOn, async () => {
3018
+ const next = !serenaOn;
3019
+ const res = await rpc('/headroom', { method: 'POST', body: { serena: next } });
3020
+ if (!res.ok) {
3021
+ showToast(L.failed + ': ' + errText(res), 'error');
3022
+ return;
3023
+ }
3024
+ if (res.serena) headroomRes.serena = res.serena;
3025
+ renderSerenaSwitch();
3026
+ showToast(next ? L.serenaEnabled : L.serenaDisabled, 'success');
3027
+ }));
3028
+ };
3029
+ renderSerenaSwitch();
2955
3030
  const hrRefreshBtn = btnSmall(L.headroomRefresh, () => { void hrRefresh(); });
2956
3031
  const hrStartBtn = btnSmall(L.headroomStart, () => { void hrRun({ action: 'start' }); });
2957
3032
  const hrRestartBtn = btnSmall(L.headroomRestart, () => { void hrRun({ action: 'restart' }); });
@@ -3120,6 +3195,7 @@ export function openSettingsDialog() {
3120
3195
  hrIntervalField.el,
3121
3196
  h('span', { class: 'w-4 text-ui-xs text-foreground-subtle' }, L.headroomSecUnit))),
3122
3197
  hrPwrHint),
3198
+ h('div', { class: 'mt-2 rounded-xl border border-border p-1' }, hrSerenaRow),
3123
3199
  );
3124
3200
  };
3125
3201
  renderHeadroomPane();
@@ -3317,6 +3393,7 @@ export function openSettingsDialog() {
3317
3393
  panePerf,
3318
3394
  paneProxy,
3319
3395
  paneSync,
3396
+ paneImport,
3320
3397
  paneVision,
3321
3398
  paneHeadroom,
3322
3399
  paneRtk,