zcode-pro 1.6.2 → 1.7.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.
@@ -8,6 +8,7 @@ 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';
11
12
 
12
13
  // 调宿主桥在系统浏览器打开外链;宿主没暴露该能力时静默忽略
13
14
  function openExternal(url) {
@@ -287,13 +288,13 @@ export function openSettingsDialog() {
287
288
  showToast(pluginsStatusLine.textContent, 'success');
288
289
  };
289
290
  void (async () => {
290
- // 打开设置弹窗即自动更新(与启动时同语义):开关开着且有新版时直接更,
291
- // 状态行如实显示过程与结果;开关关闭时只检查并显示“N 个可更新”
291
+ // 打开设置弹窗时,只有本次 ZCode 启动还没自动更新过才直接更:
292
+ // 同一次启动里反复开关弹窗不再重复下载/更新。开关关闭时只显示可更新数
292
293
  const cfg = await getConfig(true).catch(() => null);
293
294
  const res = await rpc('/plugins/status');
294
- if (!res.ok) { setPluginsStatus(''); return; }
295
+ if (!res.ok) { setPluginsStatus(errText(res)); return; }
295
296
  const n = (res.updates || []).length;
296
- if (cfg && (cfg.features || {}).autoUpdatePlugins === true && n > 0) {
297
+ if (cfg && (cfg.features || {}).autoUpdatePlugins === true && n > 0 && claimAutoUpdateRun()) {
297
298
  void runPluginsUpdate();
298
299
  return;
299
300
  }
@@ -409,6 +410,11 @@ export function openSettingsDialog() {
409
410
  if (await setFeature('wsRunningSpin', next)) f.wsRunningSpin = next;
410
411
  refreshRows();
411
412
  }),
413
+ settingRow(L.featureSubagentIcon, L.featureSubagentIconDesc, f.subagentIcon !== false, async () => {
414
+ const next = !(f.subagentIcon !== false);
415
+ if (await setFeature('subagentIcon', next)) f.subagentIcon = next;
416
+ refreshRows();
417
+ }),
412
418
  settingRow(L.featureNewtabPanels, L.featureNewtabPanelsDesc, f.newtabPanels !== false, async () => {
413
419
  const next = !(f.newtabPanels !== false);
414
420
  if (await setFeature('newtabPanels', next)) f.newtabPanels = next;
@@ -830,7 +836,7 @@ export function openSettingsDialog() {
830
836
  const sbList = h('div', { class: 'divide-y divide-border rounded-xl border border-border' });
831
837
  const sbGlobalList = h('div', { class: 'divide-y divide-border rounded-xl border border-border' });
832
838
  // 每轮统计节(输入/输出/缓存,只开关不排序——显示顺序固定)
833
- const TURN_NAMES = { turnIn: 'sbLabelIn', turnOut: 'sbLabelOut', turnCache: 'sbLabelCache' };
839
+ const TURN_NAMES = { turnIn: 'sbLabelIn', turnOut: 'sbLabelOut', turnTps: 'sbLabelTps', turnCache: 'sbLabelCache' };
834
840
  const turnItems = () => {
835
841
  const saved = config.statusBar && Array.isArray(config.statusBar.turnItems) ? config.statusBar.turnItems : null;
836
842
  if (!saved) return DEFAULT_TURN_ITEMS.map((x) => ({ ...x }));
@@ -1102,7 +1108,7 @@ export function openSettingsDialog() {
1102
1108
  ...CUSTOM_FIELDS.map(([k, key]) => customInput(mode, k, L[key])))))),
1103
1109
  );
1104
1110
  };
1105
- // 分区背景行:跟随全局 / 图库(下拉选图)/ 文件夹 / 网址
1111
+ // 分区背景行:默认(全局壁纸)/ 图库(下拉选图)/ 文件夹 / 网址
1106
1112
  // regionMaskTimers 记各分区遮罩滑杆的防抖提交(按行分开,互不误撤);
1107
1113
  // 只有"跟随全局"胶囊撤本行在途提交(它写 null 与拖动值直接冲突)
1108
1114
  const regionMaskTimers = {};
@@ -1706,12 +1712,6 @@ export function openSettingsDialog() {
1706
1712
  const proxyTestBtn = btnSmall(L.proxyTest, () => { void runProxyTest(); }, 'shrink-0');
1707
1713
  const runProxyTest = async () => {
1708
1714
  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
1715
  proxyTesting = true;
1716
1716
  proxyTestBtn.disabled = true;
1717
1717
  proxyTestBtn.textContent = L.proxyTesting;
@@ -2210,9 +2210,43 @@ export function openSettingsDialog() {
2210
2210
  // 就自己刷新,宁可多刷一次也不能停在旧代码 + 失效 token 上
2211
2211
  setTimeout(() => { try { location.reload(); } catch { /* ignore */ } }, 2000);
2212
2212
  };
2213
+ // 开发者工具开关:官方侧栏面板(Token 调试/网络状态)由官方自己读 localStorage 的
2214
+ // zcode:developer-tools:enabled / zcode:token-debug:enabled(每秒轮询,值为
2215
+ // 0/false/off/no 算关)。默认关闭,打开与否完全由用户决定
2216
+ const DT_KEYS = ['zcode:developer-tools:enabled', 'zcode:token-debug:enabled'];
2217
+ const dtRead = (v) => v !== null && !['0', 'false', 'off', 'no'].includes(v.trim().toLowerCase());
2218
+ const dtOn = () => DT_KEYS.some((k) => dtRead(localStorage.getItem(k)));
2219
+ const dtSet = (on) => {
2220
+ for (const k of DT_KEYS) {
2221
+ if (on) localStorage.setItem(k, 'true');
2222
+ else localStorage.removeItem(k);
2223
+ }
2224
+ };
2225
+ const dtSwitchBtn = (checked) => h('button', {
2226
+ type: 'button', role: 'switch', 'aria-checked': String(checked),
2227
+ class: 'relative inline-flex shrink-0 cursor-pointer items-center',
2228
+ }, h('span', { class: 'zcodepro-switch', 'data-zcodepro-switch': '', 'data-state': checked ? 'on' : 'off' },
2229
+ h('span', { class: 'zcodepro-switch-knob' })));
2230
+ const devToolsRow = () => {
2231
+ const sw = dtSwitchBtn(dtOn());
2232
+ return h('div', {
2233
+ class: 'flex cursor-pointer items-center justify-between gap-2 px-2 py-1.5',
2234
+ onClick: () => {
2235
+ dtSet(!dtOn());
2236
+ const n = dtOn();
2237
+ sw.setAttribute('aria-checked', String(n));
2238
+ sw.firstElementChild.setAttribute('data-state', n ? 'on' : 'off');
2239
+ },
2240
+ },
2241
+ h('div', { class: 'min-w-0' },
2242
+ h('div', { class: 'text-ui-sm font-medium text-foreground' }, L.devToolsSwitch),
2243
+ h('div', { class: 'mt-0.5 text-ui-xs/relaxed text-foreground-subtle' }, L.devToolsSwitchDesc)),
2244
+ sw);
2245
+ };
2213
2246
  paneDebug.append(
2214
2247
  h('p', { class: 'text-ui-sm/relaxed text-foreground-subtle' }, L.devModeDesc),
2215
- h('div', { class: 'mt-3 rounded-xl border border-border' },
2248
+ h('div', { class: 'mt-3 divide-y divide-border rounded-xl border border-border' },
2249
+ devToolsRow(),
2216
2250
  h('div', { class: 'flex items-center justify-between gap-2 px-2 py-1.5' },
2217
2251
  h('div', { class: 'min-w-0' },
2218
2252
  h('div', { class: 'text-ui-sm font-medium text-foreground' }, L.devReload),
@@ -2226,7 +2260,15 @@ export function openSettingsDialog() {
2226
2260
  // 默认单级链与 zcode-vision 插件 DEFAULT_CONFIG 保持一致:session(跟随会话供应商、
2227
2261
  // 模型留空=会话当前模型)。需要兜底级可手动加 GLM 订阅直连。
2228
2262
  // 赠送额度级 trust-build 暂不进默认:ZCode 网关不放行无人值守调用(ADR-0002)。
2229
- const VISION_DEFAULT_PROMPT = '请详细描述这张图片的全部内容。若是界面或图表截图,请先把所有错误、警告、异常状态逐字引用出来(含完整原文),再描述整体布局、文字与关键数据。';
2263
+ const VISION_DEFAULT_PROMPT_ZH = '请详细描述这张图片的全部内容。若是界面或图表截图,请先把所有错误、警告、异常状态逐字引用出来(含完整原文),再描述整体布局、文字与关键数据。';
2264
+ 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.';
2265
+ const VISION_DEFAULT_PROMPT = isZhLocale() ? VISION_DEFAULT_PROMPT_ZH : VISION_DEFAULT_PROMPT_EN;
2266
+ // 已保存的配置里如果是内置默认提示词(旧版固定中文),按当前语言重新取:
2267
+ // 否则切到英文后老配置仍然发中文提示词。用户自己改过的提示词不动。
2268
+ const isBuiltinVisionPrompt = (p) => {
2269
+ const text = String(p || '').trim();
2270
+ return text === VISION_DEFAULT_PROMPT_ZH || text === VISION_DEFAULT_PROMPT_EN;
2271
+ };
2230
2272
  const VISION_DEFAULT_CFG = {
2231
2273
  enabled: true,
2232
2274
  chainMode: 'fallback',
@@ -2244,6 +2286,11 @@ export function openSettingsDialog() {
2244
2286
  let visionCfg = visionRes.ok && visionRes.config && typeof visionRes.config === 'object'
2245
2287
  ? structuredClone(visionRes.config)
2246
2288
  : null;
2289
+ if (visionCfg && Array.isArray(visionCfg.proxies)) {
2290
+ for (const proxy of visionCfg.proxies) {
2291
+ if (isBuiltinVisionPrompt(proxy.prompt)) proxy.prompt = VISION_DEFAULT_PROMPT;
2292
+ }
2293
+ }
2247
2294
  // 自动初始化只试一次(每次打开弹窗):写盘失败回退手动“添加代理”卡
2248
2295
  let visionAutoInitTried = false;
2249
2296
  let visionSaveTimer = null;
@@ -2952,6 +2999,25 @@ export function openSettingsDialog() {
2952
2999
  }));
2953
3000
  };
2954
3001
  renderHrUsageSwitch();
3002
+ // Serena:语义代码检索 MCP 开关。不走 hrRun(与压缩代理进程无关),点击即时
3003
+ // 写 cli/config.json;ZCode 新会话启动时加载该 MCP,当前会话不重连。
3004
+ const hrSerenaRow = h('div');
3005
+ const renderSerenaSwitch = () => {
3006
+ const serenaOn = !!(headroomRes.serena && headroomRes.serena.enabled);
3007
+ hrSerenaRow.replaceChildren(
3008
+ settingRow(L.serenaSwitch, L.serenaSwitchDesc, serenaOn, async () => {
3009
+ const next = !serenaOn;
3010
+ const res = await rpc('/headroom', { method: 'POST', body: { serena: next } });
3011
+ if (!res.ok) {
3012
+ showToast(L.failed + ': ' + errText(res), 'error');
3013
+ return;
3014
+ }
3015
+ if (res.serena) headroomRes.serena = res.serena;
3016
+ renderSerenaSwitch();
3017
+ showToast(next ? L.serenaEnabled : L.serenaDisabled, 'success');
3018
+ }));
3019
+ };
3020
+ renderSerenaSwitch();
2955
3021
  const hrRefreshBtn = btnSmall(L.headroomRefresh, () => { void hrRefresh(); });
2956
3022
  const hrStartBtn = btnSmall(L.headroomStart, () => { void hrRun({ action: 'start' }); });
2957
3023
  const hrRestartBtn = btnSmall(L.headroomRestart, () => { void hrRun({ action: 'restart' }); });
@@ -3120,6 +3186,7 @@ export function openSettingsDialog() {
3120
3186
  hrIntervalField.el,
3121
3187
  h('span', { class: 'w-4 text-ui-xs text-foreground-subtle' }, L.headroomSecUnit))),
3122
3188
  hrPwrHint),
3189
+ h('div', { class: 'mt-2 rounded-xl border border-border p-1' }, hrSerenaRow),
3123
3190
  );
3124
3191
  };
3125
3192
  renderHeadroomPane();
@@ -46,9 +46,13 @@ let lastRenderedHtml = null; // renderBar 去重:内容没变不重写 DOM
46
46
 
47
47
  // —— 工具 ——
48
48
 
49
- // 选中会话的 id:只认 bg-selected 行(不走 turn-usage 的“侧栏最新一行”回退——
50
- // 那会让新建会话视图顶着别的会话数据);无选中返回空串
49
+ // 选中会话的 id:优先读会话面板自身的 data-session-id(官方属性,跟着对话视图
50
+ // 走——侧栏项目折叠后选中行会从 DOM 卸载,只认行会让整组会话项消失),
51
+ // 再回退 bg-selected 行;都没有返回空串
51
52
  function selectedSessionId() {
53
+ const pane = document.querySelector('[data-session-id]');
54
+ const pid = pane ? pane.getAttribute('data-session-id') : '';
55
+ if (pid && /^(?:sess|session)_/.test(pid)) return pid;
52
56
  // 交给选择器引擎找选中行(比全表扫 className 快,语义相同)
53
57
  const row = document.querySelector('[data-task-item-key].bg-selected');
54
58
  const key = row ? row.getAttribute('data-task-item-key') : '';
@@ -169,12 +173,14 @@ const GLOBAL_GROUP = new Set(['todayTokens', 'totalTokens', 'tasks']);
169
173
 
170
174
  // 各统计项的 lucide 图标(12px 内联,描边风格与官方一致)
171
175
  const SB_ICONS = {
172
- tokRate: '<path d="m12 14 4-4"/><path d="M3.34 19a10 10 0 1 1 17.32 0"/>',
176
+ tokRate: '<path d="m12 11 4-4"/><path d="M3.34 16a10 10 0 1 1 17.32 0"/>',
173
177
  ctx: '<path d="M21.21 15.89A10 10 0 1 1 8 2.83"/><path d="M22 12A10 10 0 0 0 12 2v10z"/>',
174
178
  asks: '<path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/>',
175
179
  today: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>',
176
180
  total: '<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5V19A9 3 0 0 0 21 19V5"/><path d="M3 12A9 3 0 0 0 21 12"/>',
177
181
  tasks: '<rect x="3" y="5" width="6" height="6" rx="1"/><path d="m3 17 2 2 4-4"/><path d="M13 6h8"/><path d="M13 12h8"/><path d="M13 18h8"/>',
182
+ inOut: '<path d="m21 16-4 4-4-4"/><path d="M17 20V4"/><path d="m3 8 4-4 4 4"/><path d="M7 4v16"/>',
183
+ hit: '<path d="m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a2 2 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a2 2 0 0 0 0-1.83Z"/><path d="m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65"/><path d="m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65"/>',
178
184
  coins: '<circle cx="8" cy="8" r="6"/><path d="M18.09 10.37A6 6 0 1 1 10.34 18"/><path d="M7 6h1v4"/><path d="m16.71 13.88.7.71-2.82 2.82"/>',
179
185
  };
180
186
  const sbIcon = (name) => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="zcodepro-sb-icon">${SB_ICONS[name]}</svg>`;
@@ -211,18 +217,19 @@ function itemContent(id, L) {
211
217
  case 'tokRate': {
212
218
  const sid = selectedSessionId();
213
219
  if (!sid) return null; // 无选中会话不显示
214
- // 显示优先级:生成中的实时估算(usage 缺失/长调用期间唯一动得起来的信号)
215
- // > 真实锚定值(该会话数据就是取自它)> 最近一次估算(usage 缺失的会话答完后)
216
- const streaming = streamEst && Date.now() - streamEst.at < 6000;
217
- const r = (g && g.rate60 && statsSid === sid) ? g.rate60 : null;
220
+ // 官方净生成口径:本会话树(含子代理)最近 60 秒窗内主轮请求的
221
+ // Σ输出 ÷ Σ净生成秒数(与 Token 调试/每轮标注同款公式);usage 全缺
222
+ //(供应商不回传 token)才用文本增长估算兜底——估算按 2 字符/token 折算,
223
+ // 实测虚高 2-4 倍,有真实数据时绝不能让它抢显示
224
+ const s = (lastStats && statsSid === sid) ? lastStats.sessionSummary : null;
225
+ const tps = s && s.tps != null ? s.tps : null;
218
226
  const est = streamEst ? streamEst.value : null;
219
- const useEst = !!streaming || !(r && r.out > 0);
220
- const shown = useEst ? est : r.out;
227
+ const shown = tps != null ? tps : est;
221
228
  if (shown == null) return null;
222
229
  const zh = isZhLocale();
223
- const estMark = useEst && est != null ? '≈' : '';
224
- const detail = r
225
- ? `${L.sbLabelOut} ${r.out.toLocaleString()} tok/s · ${zh ? '总量' : 'total'} ${r.total.toLocaleString()} tok/s`
230
+ const estMark = tps == null && est != null ? '≈' : '';
231
+ const detail = tps != null
232
+ ? `${L.sbLabelOut} ${tps.toLocaleString()} tok/s${zh ? '(官方净生成口径,本会话树)' : ' (net generation, session tree)'}`
226
233
  : (zh ? '无 usage 数据,按文本增长估算' : 'no usage data, estimated from text growth');
227
234
  return {
228
235
  html: sbIcon('tokRate') + label(L.sbLabelOut) + `<b>${estMark}${fmtNum(Math.round(shown * 10) / 10)} tok/s</b>`,
@@ -244,10 +251,23 @@ function itemContent(id, L) {
244
251
  return null; // 官方窗口数据不在(视图切换间隙等)时该项隐藏
245
252
  }
246
253
  case 'questions': {
247
- // 官方“对话问题导航”的真实计数(当前会话的问题总数)
248
- const nav = document.querySelector('[data-testid="v4-turn-navigator"]');
249
- const n = nav ? Number(nav.getAttribute('data-item-count')) : 0;
250
- return n > 0 ? { html: sbIcon('asks') + label(L.sbLabelQuestions) + String(n), title: L.sbItemQuestions } : null;
254
+ // 主轮请求数:官方 model_usage 口径(与 Token 调试的“主轮请求”同源)
255
+ const s = (lastStats && statsSid === selectedSessionId()) ? lastStats.sessionSummary : null;
256
+ return s && s.requests > 0 ? { html: sbIcon('asks') + label(L.sbLabelQuestions) + String(s.requests), title: L.sbItemQuestions } : null;
257
+ }
258
+ case 'inOut': {
259
+ const s = (lastStats && statsSid === selectedSessionId()) ? lastStats.sessionSummary : null;
260
+ return s && s.totalIn + s.totalOut > 0 ? {
261
+ html: sbIcon('inOut') + label(L.sbLabelInOut) + `${fmtNum(s.totalIn)}/${fmtNum(s.totalOut)}`,
262
+ title: `${L.sbItemInOut}${isZhLocale() ? ':' : ': '}${s.totalIn.toLocaleString()} / ${s.totalOut.toLocaleString()}`,
263
+ } : null;
264
+ }
265
+ case 'avgHit': {
266
+ const s = (lastStats && statsSid === selectedSessionId()) ? lastStats.sessionSummary : null;
267
+ return s && s.hitRate != null ? {
268
+ html: sbIcon('hit') + label(L.sbLabelHit) + `${(s.hitRate * 100).toFixed(2)}%`,
269
+ title: `${L.sbItemHit}${isZhLocale() ? ':' : ': '}${(s.hitRate * 100).toFixed(2)}%`,
270
+ } : null;
251
271
  }
252
272
  case 'todayTokens': {
253
273
  const n = (official && official.todayTokens != null) ? official.todayTokens : (g ? g.todayTokens : 0);
@@ -287,7 +307,7 @@ function renderBar() {
287
307
  // 新建会话视图(无选中会话)下方是官方的功能按钮区,不能往下压:上下对称
288
308
  // 留 7px;普通会话视图下方是窗口底的官方留白,压进去贴底(同为约 7px)。
289
309
  // 按选中会话判定视图(按钮区与状态条不在同一父容器,兄弟判断不可用)
290
- const hasSession = !!document.querySelector('[data-task-item-key].bg-selected');
310
+ const hasSession = !!selectedSessionId();
291
311
  barEl.style.marginBottom = hasSession ? '-14px' : '0';
292
312
  barEl.style.paddingBottom = hasSession ? '0' : '7px';
293
313
  const L = t();