zcode-pro 1.8.1 → 1.9.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.
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))) {
@@ -350,7 +350,11 @@ export async function listSessionsActivity(dataRoot, ids) {
350
350
  // 指定会话的子代理会话及最近活动时间(含嵌套子代理,根归属到最初的那个会话):
351
351
  // [{ id, root, at }]。子代理判活以这里写入会话库的活动时间为准——应用的运行记录两头都
352
352
  // 不可靠:长跑子代理会被误记为失败/结束(实测 48 分钟、60 分钟的都在跑着时被
353
- // 记 end),崩溃残留的又永远挂"运行中"(subagent-icon.js)
353
+ // 记 end),崩溃残留的又永远挂"运行中"(subagent-icon.js)。
354
+ // 已失败/中断的子代理(last_outcome 为 error/interrupted)不再返回:中断时父回合
355
+ // 被打断,工具的结束记录没有写入,只靠活动时间会让机器人图标一直亮着。completed
356
+ // 仍返回,继续交给应用的结束记录判死——子代理可以被再次唤起继续跑,不能凭上一次
357
+ // 的 completed 提前熄灭。老库没有 last_outcome 列时退回原查询。
354
358
  export async function listSubagentChildrenActivity(dataRoot, ids) {
355
359
  const out = [];
356
360
  const wanted = [...new Set((ids || []).map(String).filter(Boolean))];
@@ -361,13 +365,32 @@ export async function listSubagentChildrenActivity(dataRoot, ids) {
361
365
  if (!driver) return out;
362
366
  const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
363
367
  const inList = wanted.map((id) => esc(id)).join(', ');
368
+ // last_outcome 由 CLI 在回合结束时写入(completed/error/interrupted),缺列
369
+ // 说明是旧库,按老逻辑不筛
370
+ let outcomeFilter = '';
371
+ try {
372
+ if (driver.kind === 'node') {
373
+ const db = new driver.DatabaseSync(dbFile, { readOnly: true });
374
+ try {
375
+ const cols = db.prepare("PRAGMA table_info('session')").all();
376
+ if (cols.some((c) => String(c.name) === 'last_outcome')) {
377
+ outcomeFilter = "AND (s.last_outcome IS NULL OR s.last_outcome = 'completed')";
378
+ }
379
+ } finally { db.close(); }
380
+ } else {
381
+ const cols = runCli(dbFile, "PRAGMA table_info('session');").stdout;
382
+ if (cols.split(/\r?\n/).some((l) => l.split('|')[1] === 'last_outcome')) {
383
+ outcomeFilter = "AND (s.last_outcome IS NULL OR s.last_outcome = 'completed')";
384
+ }
385
+ }
386
+ } catch { /* 列名查不到按旧库处理 */ }
364
387
  const sql = `WITH RECURSIVE fam(id, root) AS (
365
388
  SELECT id, parent_id FROM session WHERE parent_id IN (${inList})
366
389
  UNION
367
390
  SELECT s.id, f.root FROM session s JOIN fam f ON s.parent_id = f.id
368
391
  ) SELECT fam.root AS root, s.id AS id, s.time_updated AS at
369
392
  FROM session s JOIN fam ON s.id = fam.id
370
- WHERE s.task_type = 'subagent_child'`;
393
+ WHERE s.task_type = 'subagent_child' ${outcomeFilter}`;
371
394
  try {
372
395
  let rows;
373
396
  if (driver.kind === 'node') {
@@ -1,4 +1,8 @@
1
1
  // 注入脚本公共工具:与 helper 通信、DOM 构建、多语言文案。
2
+ import ja, { jaErrors } from './locales/ja.js';
3
+ import ko, { koErrors } from './locales/ko.js';
4
+ import ru, { ruErrors } from './locales/ru.js';
5
+
2
6
  export const BOOT = typeof window !== 'undefined' ? (window.__ZCODEPRO__ || {}) : {};
3
7
  export const HELPER_URL = BOOT.helperUrl || 'http://127.0.0.1:47889';
4
8
 
@@ -278,8 +282,10 @@ const zh = {
278
282
  devReloadDesc: '点击后约 2-3 秒内所有 ZCode 窗口自动刷新一次并加载新脚本。',
279
283
  devToolsSwitch: '开发者工具',
280
284
  devToolsSwitchDesc: '官方侧栏的“开发者工具”面板(Token 调试 / 网络状态),默认关闭。改动写入官方每秒轮询的开关,1 秒内生效。',
281
- rowGapName: '段落间距',
282
- rowGapDesc: '会话中段落等文本块之间的垂直间距(回合之间、答案内部)。',
285
+ thinkingRowGapName: '思考段落间距',
286
+ thinkingRowGapDesc: '“已工作/工作中”过程记录里各行、思考正文之间的垂直间距。',
287
+ answerRowGapName: '回答段落间距',
288
+ answerRowGapDesc: '回答正文里段落等文本块之间、以及回合之间的垂直间距。',
283
289
  listSpacingName: '列表上下边距',
284
290
  listSpacingDesc: '答案中列表上下的留白。',
285
291
  listItemSpacingName: '列表项间距',
@@ -329,6 +335,7 @@ const zh = {
329
335
  titleGenPrompt: '提示词',
330
336
  titleGenPromptPlaceholder: '留空使用内置默认提示词(点击下方按钮可查看)',
331
337
  titleGenPromptReset: '使用默认提示词',
338
+ titleGenAssistantSummary: '(首轮回答摘要)',
332
339
  titleGenSample: '测试消息',
333
340
  titleGenTest: '测试生成',
334
341
  titleGenTesting: '生成中…',
@@ -385,6 +392,8 @@ const zh = {
385
392
  assistantFontDesc: '会话中回答正文的字体(代码块仍用等宽字体);选“默认”时跟随界面字体。',
386
393
  switcherHint: '{prev} / {next} 或 ↑ / ↓ 选择,Enter 或点击行切换,Esc 取消',
387
394
  switcherCurrent: '当前',
395
+ switcherNewTask: '新建任务',
396
+ switcherTaskDraft: '不在项目中',
388
397
  switcherEmpty: '暂无上次会话(切换过会话后可用)',
389
398
  switcherFailed: '未能切换到该会话(可能已删除)',
390
399
  switcherMore: '还有 {n} 条 · 按 c 加载',
@@ -409,6 +418,7 @@ const zh = {
409
418
  themeBgPane: '壁纸',
410
419
  themeSkinTitle: '皮肤',
411
420
  themeSkinDesc: '知名编辑器主题配色,自动匹配 ZCode 的浅色 / 深色模式;默认保持 ZCode 原样,自定义在下方自行调色。',
421
+ themeSkinDefault: '默认',
412
422
  themeSkinCustom: '自定义',
413
423
  themeCustomTitle: '自定义主题',
414
424
  themeCustomHint: '改颜色即实时生效(自动切到自定义皮肤);浅色、深色各配一次,选好 5 个颜色即可生成整套界面配色。',
@@ -477,6 +487,10 @@ const zh = {
477
487
  tableCopied: '表格已复制',
478
488
  sbItemCtx: '上下文占用',
479
489
  sbItemTokRate: '最近输出 tokens/s',
490
+ sbTokRateStreaming: '流式生成中,按文本增长估算(约 2 字符/token)',
491
+ sbTokRateNet: '(官方净生成口径,本会话树)',
492
+ sbTokRateNoData: '无 usage 数据,按文本增长估算',
493
+ sbTokRateSessionSuffix: '(本会话):',
480
494
  sbItemQuestions: '主请求数(本会话)',
481
495
  sbItemInOut: '累计输入/输出(本会话主轮请求)',
482
496
  sbItemHit: '平均缓存命中率(本会话)',
@@ -538,6 +552,8 @@ const zh = {
538
552
  featureSessionLink: '会话 ID 显示为任务名链接',
539
553
  featureSessionLinkDesc: '提问与回答里的会话 ID(sess_ / session_ 开头)显示为任务名,点击切换到该会话,悬停可看原始 ID。',
540
554
  featureComposerProviderDesc: '模型名前显示供应商名(如 BigModel-Max1 / glm-5.3),区分同名模型。',
555
+ featureComposerEditModel: '编辑时保持当前模型',
556
+ featureComposerEditModelDesc: '点编辑上一条消息时,保持你点编辑前选的模型,不会换成这条消息当时用的模型;进入编辑后仍然可以再换,重跑用最终选的模型。',
541
557
  featureSessionImport: '导入会话',
542
558
  featureSessionImportDesc: '在设置弹窗里把 Codex、Claude Code、dsh、pi 的历史会话导入成 ZCode 任务。',
543
559
  imageCopy: '复制图片',
@@ -565,6 +581,36 @@ const zh = {
565
581
  pluginsUpdateFailed: '插件更新失败',
566
582
  pluginsUpdatesAvailable: 'zcode-plugins 有 {n} 个插件可更新(ZCode Pro 设置 → 功能)',
567
583
  pluginsAutoUpdated: 'zcode-plugins 插件已更新',
584
+ tabAutoContinue: '自动继续',
585
+ acDesc: '回合因请求故障失败(红色报错横幅)或回复中途截断时,自动发一条继续指令把任务接上;重开会话(含重启 ZCode 后)没做完的任务也接上。认证、余额、模型不存在等永久性错误和手动停止不打扰。配置在 ~/.zcode/auto-continue.json。',
586
+ acEnabled: '启用',
587
+ acPrompt: '继续提示词',
588
+ acMaxRetries: '最多继续次数',
589
+ acMaxRetriesHint: '30 分钟内自动继续的累计上限,防止故障反复时刷屏',
590
+ acCooldown: '密集失败退避基数(秒)',
591
+ acCooldownHint: '2 分钟内已继续过就视为密集失败,间隔按 2 倍递增、上限 60 秒;单次失败只等 3 秒界面稳定',
592
+ acStuckAfterMin: '卡死判定(分钟)',
593
+ acStuckAfterMinHint: '后台终端任务、子代理或主回合多久没有动静才弹卡提示;会话本身也要静默同样久',
594
+ acFailedAfterMin: '失败后自动续接(分钟)',
595
+ acFailedAfterMinHint: '回合失败多久后自动继续;会先等 60 秒跳过失败后的清理事件',
596
+ acLoadFailed: '读取自动继续配置失败',
597
+ acCardKindSubagent: '子代理卡死',
598
+ acCardKindTurn: '主轮卡死',
599
+ acCardKindTerminal: '终端卡死',
600
+ acCardFailedTitle: '回合失败未续上',
601
+ acCardMore: '(队列中还有 {n} 个)',
602
+ acCardFailedDesc: '任务“{title}”{mins} 分钟前回合失败({msg}),一直没人续上。',
603
+ acCardTerminalSilent: '{count} 个后台终端任务已 {mins} 分钟没有回报',
604
+ acCardSubagentSilent: '{count} 个子代理已 {mins} 分钟没有回报',
605
+ acCardTurnStalled: '主回合已 {mins} 分钟没有进展',
606
+ acCardStuckDesc: '任务“{title}”:{parts}。确实在跑的长任务(如打包)点“知道了”即可。',
607
+ acCardKindSep: '、',
608
+ acCardPartSep: ';',
609
+ acCardJump: '跳转任务',
610
+ acCardContinue: '继续',
611
+ acCardDismiss: '知道了',
612
+ acCardContinueStartFailed: '续接启动失败:',
613
+ acCardHeadlessFailed: '无头续接启动失败,请稍后再试或手动处理。',
568
614
  tabVision: 'Vision',
569
615
  visionDesc: '主模型不支持图片输入时(如 glm-5.3),自动把消息里的图片交给下面的视觉模型识别,把描述带给主模型(zcode-vision 插件;/vision-* 命令编辑同一配置)。',
570
616
  visionEnabled: '启用',
@@ -911,8 +957,10 @@ const en = {
911
957
  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
958
  devReloading: 'Reloading…',
913
959
  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).',
960
+ thinkingRowGapName: 'Thinking paragraph spacing',
961
+ thinkingRowGapDesc: 'Vertical spacing between rows of the "Worked/Working" process view and thinking text.',
962
+ answerRowGapName: 'Answer paragraph spacing',
963
+ answerRowGapDesc: 'Vertical spacing between text blocks inside answers and between turns.',
916
964
  listSpacingName: 'List spacing',
917
965
  listSpacingDesc: 'Space above and below lists.',
918
966
  listItemSpacingName: 'List item spacing',
@@ -962,6 +1010,7 @@ const en = {
962
1010
  titleGenPrompt: 'Prompt',
963
1011
  titleGenPromptPlaceholder: 'Leave empty for the built-in default prompt (the button below shows it)',
964
1012
  titleGenPromptReset: 'Use default prompt',
1013
+ titleGenAssistantSummary: ' (first answer summary)',
965
1014
  titleGenSample: 'Test message',
966
1015
  titleGenTest: 'Test',
967
1016
  titleGenTesting: 'Generating…',
@@ -1017,6 +1066,8 @@ const en = {
1017
1066
  assistantFontDesc: 'Font of answer text in conversations (code blocks stay monospaced); "default" follows the UI font.',
1018
1067
  switcherHint: '{prev} / {next} or ↑ / ↓ to choose, Enter or click a row to switch, Esc to cancel',
1019
1068
  switcherCurrent: 'current',
1069
+ switcherNewTask: 'new task',
1070
+ switcherTaskDraft: 'no project',
1020
1071
  switcherEmpty: 'No previous session yet (available after you switch sessions)',
1021
1072
  switcherFailed: 'Failed to switch to that session (it may have been deleted)',
1022
1073
  switcherMore: '{n} more · press c to load',
@@ -1041,6 +1092,7 @@ const en = {
1041
1092
  themeBgPane: 'Wallpaper',
1042
1093
  themeSkinTitle: 'Skins',
1043
1094
  themeSkinDesc: 'Well-known editor theme palettes, auto-matching ZCode\'s light / dark mode; "Default" keeps ZCode as-is, "Custom" is tuned below.',
1095
+ themeSkinDefault: 'Default',
1044
1096
  themeSkinCustom: 'Custom',
1045
1097
  themeCustomTitle: 'Custom theme',
1046
1098
  themeCustomHint: 'Color changes apply live (auto-switches to the custom skin); set light and dark separately — pick 5 colors and the whole palette is derived.',
@@ -1109,6 +1161,10 @@ const en = {
1109
1161
  tableCopied: 'Table copied',
1110
1162
  sbItemCtx: 'Context usage',
1111
1163
  sbItemTokRate: 'Recent output tokens/s',
1164
+ sbTokRateStreaming: 'streaming; estimated from text growth (~2 chars/token)',
1165
+ sbTokRateNet: ' (net generation, session tree)',
1166
+ sbTokRateNoData: 'no usage data, estimated from text growth',
1167
+ sbTokRateSessionSuffix: ' (this session): ',
1112
1168
  sbItemQuestions: 'Main requests (this session)',
1113
1169
  sbItemInOut: 'Total input/output (main requests, this session)',
1114
1170
  sbItemHit: 'Average cache hit rate (this session)',
@@ -1170,6 +1226,8 @@ const en = {
1170
1226
  featureSessionLink: 'Session ID links',
1171
1227
  featureSessionLinkDesc: 'Shows session IDs (sess_ / session_) in chat as task names; click to switch to that session, hover for the raw ID.',
1172
1228
  featureComposerProviderDesc: 'Shows the provider before the model name (e.g. BigModel-Max1 / glm-5.3).',
1229
+ featureComposerEditModel: 'Keep current model when editing',
1230
+ 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
1231
  featureSessionImport: 'Session import',
1174
1232
  featureSessionImportDesc: 'Import sessions from Codex, Claude Code, dsh and pi as ZCode tasks from the settings dialog.',
1175
1233
  imageCopy: 'Copy image',
@@ -1197,6 +1255,36 @@ const en = {
1197
1255
  pluginsUpdateFailed: 'Plugin update failed',
1198
1256
  pluginsUpdatesAvailable: '{n} zcode-plugins update(s) available (ZCode Pro settings → Features)',
1199
1257
  pluginsAutoUpdated: 'zcode-plugins updated',
1258
+ tabAutoContinue: 'Auto-continue',
1259
+ acDesc: 'When a turn fails from a request error (red error banner) or a reply is cut off mid-output, automatically send a continue prompt to pick the task back up; unfinished tasks are also resumed after reopening the session (including after a ZCode restart). Permanent errors (auth, balance, missing model) and manual stops are left alone. Config lives in ~/.zcode/auto-continue.json.',
1260
+ acEnabled: 'Enable',
1261
+ acPrompt: 'Continue prompt',
1262
+ acMaxRetries: 'Max auto-continues',
1263
+ acMaxRetriesHint: 'Cap on auto-continues within 30 minutes, to avoid flooding on repeated failures',
1264
+ acCooldown: 'Backoff base for burst failures (s)',
1265
+ acCooldownHint: 'A continue within 2 minutes counts as a burst: interval doubles up to 60s; a single failure only waits 3s for the UI to settle',
1266
+ acStuckAfterMin: 'Stuck threshold (min)',
1267
+ acStuckAfterMinHint: 'How long a background terminal task, subagent or main turn may stay silent before the card appears; the session itself must also be silent this long',
1268
+ acFailedAfterMin: 'Auto-continue after failure (min)',
1269
+ acFailedAfterMinHint: 'How long after a failed turn to continue automatically; waits 60s first to skip post-failure cleanup events',
1270
+ acLoadFailed: 'Failed to load the auto-continue config',
1271
+ acCardKindSubagent: 'Subagent stuck',
1272
+ acCardKindTurn: 'Main turn stuck',
1273
+ acCardKindTerminal: 'Terminal stuck',
1274
+ acCardFailedTitle: 'Turn failed, not continued',
1275
+ acCardMore: ' ({n} more queued)',
1276
+ acCardFailedDesc: 'Task “{title}” failed {mins} min ago ({msg}) and was never continued.',
1277
+ acCardTerminalSilent: '{count} background terminal task(s) silent for {mins} min',
1278
+ acCardSubagentSilent: '{count} subagent(s) silent for {mins} min',
1279
+ acCardTurnStalled: 'The main turn has stalled for {mins} min',
1280
+ acCardStuckDesc: 'Task “{title}”: {parts}. Dismiss long-running builds with “Dismiss”.',
1281
+ acCardKindSep: ', ',
1282
+ acCardPartSep: '; ',
1283
+ acCardJump: 'Go to task',
1284
+ acCardContinue: 'Continue',
1285
+ acCardDismiss: 'Dismiss',
1286
+ acCardContinueStartFailed: 'Failed to start continue: ',
1287
+ acCardHeadlessFailed: 'Failed to start headless continue; retry later or handle manually.',
1200
1288
  tabVision: 'Vision',
1201
1289
  visionDesc: 'When the main model cannot see images (e.g. glm-5.3), images in messages are recognized by the vision models below and passed to the main model as text (zcode-vision plugin; /vision-* commands edit the same file).',
1202
1290
  visionEnabled: 'Enable',
@@ -1394,12 +1482,24 @@ const en = {
1394
1482
  };
1395
1483
 
1396
1484
  // 界面语言:与官方 IntlProvider 的解析一致——先读应用的 localStorage 偏好
1397
- // (zcode-locale-preference:zh-CN/en-US/system),显式偏好直接生效;'system' 或未设置时
1398
- // 官方在主进程用系统首选语言解析(macOS 上可能与渲染进程的 navigator.language 不一致:
1399
- // 系统是中文而 Chromium 报 en-US,导致注入界面误判成英文)。这里通过 preload 暴露的
1400
- // window.zcode.getSystemLocale()(IPC,异步)取主进程结果并缓存;取回前先按
1401
- // navigator.language 兜底,避免阻塞首次渲染。
1402
- let cachedSystemLocale = null; // 'zh-CN' | 'en-US' | null(尚未取回)
1485
+ // (zcode-locale-preference:zh-CN/en-US/ja-JP/ko-KR/ru-RU/system),显式偏好直接生效;
1486
+ // 'system' 或未设置时官方在主进程用系统首选语言解析(macOS 上可能与渲染进程的
1487
+ // navigator.language 不一致:系统是中文而 Chromium 报 en-US,导致注入界面误判成英文)。
1488
+ // 这里通过 preload 暴露的 window.zcode.getSystemLocale()(IPC,异步)取主进程结果并缓存;
1489
+ // 取回前先按 navigator.language 兜底,避免阻塞首次渲染。
1490
+ // 语言代码按前缀归一:zh/ja/ko/ru/en → 官方支持的五种,其余视为未知。
1491
+ export function normalizeUiLocale(raw) {
1492
+ const s = String(raw || '').trim().toLowerCase().replace(/_/g, '-');
1493
+ if (!s || s === 'system') return '';
1494
+ if (s.startsWith('zh')) return 'zh-CN';
1495
+ if (s.startsWith('en')) return 'en-US';
1496
+ if (s.startsWith('ja')) return 'ja-JP';
1497
+ if (s.startsWith('ko')) return 'ko-KR';
1498
+ if (s.startsWith('ru')) return 'ru-RU';
1499
+ return '';
1500
+ }
1501
+
1502
+ let cachedSystemLocale = null; // 'zh-CN' | 'en-US' | 'ja-JP' | 'ko-KR' | 'ru-RU' | null(尚未取回)
1403
1503
 
1404
1504
  export function startLocaleResolver() {
1405
1505
  if (cachedSystemLocale !== null) return; // 已取回则跳过,避免重复 IPC(index.js 会调用两次)
@@ -1408,33 +1508,54 @@ export function startLocaleResolver() {
1408
1508
  Promise.resolve(get())
1409
1509
  .then((locale) => {
1410
1510
  if (typeof locale === 'string' && locale) {
1411
- // 与主进程解析一致:zh 开头视为中文,其余视为英文(兼容 'zh-Hans-CN' 等原始格式)
1412
- cachedSystemLocale = locale.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
1511
+ // 兼容 'zh-Hans-CN'、'ja_JP' 等原始格式,按前缀归一到官方语言代码
1512
+ cachedSystemLocale = normalizeUiLocale(locale) || 'en-US';
1413
1513
  }
1414
1514
  })
1415
1515
  .catch(() => { /* 取回失败:沿用 navigator.language 兜底 */ });
1416
1516
  }
1417
1517
 
1418
- let zhCache = { at: 0, v: null };
1419
- export function isZhLocale() {
1518
+ let uiLocaleCache = { at: 0, v: null };
1519
+ export function uiLocale() {
1420
1520
  // 结果缓存 3 秒:一轮渲染里要调十几次,localStorage 每次读有成本;
1421
1521
  // 语言切换本来就会重载界面,短缓存跟得上
1422
- if (zhCache.v != null && Date.now() - zhCache.at < 3000) return zhCache.v;
1522
+ if (uiLocaleCache.v && Date.now() - uiLocaleCache.at < 3000) return uiLocaleCache.v;
1423
1523
  let pref = null;
1424
1524
  try { pref = window.localStorage.getItem('zcode-locale-preference'); } catch { /* ignore */ }
1425
- const v = (pref === 'zh-CN' || pref === 'en-US') ? pref === 'zh-CN'
1426
- : cachedSystemLocale ? cachedSystemLocale === 'zh-CN'
1427
- : /^zh/i.test(navigator.language || 'zh-CN');
1428
- zhCache = { at: Date.now(), v };
1525
+ const v = normalizeUiLocale(pref)
1526
+ || normalizeUiLocale(cachedSystemLocale)
1527
+ || normalizeUiLocale(navigator.language)
1528
+ || 'en-US';
1529
+ uiLocaleCache = { at: Date.now(), v };
1429
1530
  return v;
1430
1531
  }
1431
1532
 
1533
+ export function isZhLocale() {
1534
+ // 中文界面判断:只用于中文标点、数字单位等格式差异;界面文案由 t() 按五种语言取
1535
+ return uiLocale() === 'zh-CN';
1536
+ }
1537
+
1538
+ // 中文/日文共用全角标点(括号、冒号、顿号、分号)
1539
+ export function isCjkLocale() {
1540
+ const loc = uiLocale();
1541
+ return loc === 'zh-CN' || loc === 'ja-JP';
1542
+ }
1543
+
1544
+ // 官方任务菜单“重命名任务”的五种语言标签;右键菜单注入与重命名弹窗预填都按它识别
1545
+ const RENAME_LABELS = ['重命名任务', 'rename task', 'タスクの名前を変更', '작업 이름 바꾸기', 'переименовать задачу'];
1546
+ export function isRenameLabel(text) {
1547
+ const s = String(text || '').trim().toLowerCase();
1548
+ return RENAME_LABELS.some((label) => s.includes(label.toLowerCase()));
1549
+ }
1550
+
1551
+ // 界面文案:ZCode 支持的五种语言各一套;未识别的语言回退英文
1552
+ const LOCALE_DICTS = { 'zh-CN': zh, 'en-US': en, 'ja-JP': ja, 'ko-KR': ko, 'ru-RU': ru };
1432
1553
  export function t() {
1433
- return isZhLocale() ? zh : en;
1554
+ return LOCALE_DICTS[uiLocale()] || en;
1434
1555
  }
1435
1556
 
1436
- // helper 错误消息的英文映射(code → 文案):helper 原文为中文,非中文界面按 code 显示英文,
1437
- // 无映射或中文界面回退 helper 原文
1557
+ // helper 错误消息的本地化映射(code → 文案):helper 原文为中文,非中文界面按 code
1558
+ // 显示对应语言;无映射或中文界面回退 helper 原文
1438
1559
  const errEn = {
1439
1560
  'invalid-path': 'Invalid project path',
1440
1561
  'not-found': 'The folder does not exist',
@@ -1518,17 +1639,32 @@ const errEn = {
1518
1639
  'protected-path': 'Refused: the path points inside the ZCode data directory',
1519
1640
  'same-path': 'The new location is the same as the current one',
1520
1641
  'export-cancelled': 'Canceled',
1642
+ // 自动续接(ac-*)
1643
+ 'ac-read': 'auto-continue.json is not valid JSON',
1644
+ 'ac-invalid': 'Missing config object',
1645
+ 'ac-write': 'Failed to write auto-continue.json',
1646
+ 'ac-continue-invalid': 'Missing a valid sessionId or text',
1647
+ 'ac-continue-spawn': 'Failed to start the headless resume',
1648
+ 'ac-mode-unsupported': 'Auto mode is reserved and unimplemented; not resumed automatically',
1521
1649
  // 其他
1522
1650
  'no-content': 'This session has no Q&A content yet',
1523
1651
  'title-gen-disabled': 'Auto rename is not enabled',
1652
+ 'title-gen-empty': 'The title model returned no text',
1653
+ 'title-gen-thinking': 'The title model used the whole output budget on thinking and returned no title',
1654
+ 'title-gen-timeout': 'The title model request timed out',
1655
+ 'title-gen-no-title': 'The title model returned no usable title',
1524
1656
  'headroom-provider-config': 'ZCode provider config not found (v2/config.json)',
1525
1657
  };
1526
1658
 
1659
+ const LOCALE_ERR_DICTS = { 'en-US': errEn, 'ja-JP': jaErrors, 'ko-KR': koErrors, 'ru-RU': ruErrors };
1660
+
1527
1661
  export function errText(res) {
1528
1662
  if (!res) return '';
1529
- if (!isZhLocale()) {
1530
- const en = res.code && errEn[res.code];
1531
- if (en) return en;
1663
+ const loc = uiLocale();
1664
+ if (loc !== 'zh-CN') {
1665
+ // 本地语言缺该错误码时回退英文,不要露出 helper 的中文原文
1666
+ const msg = res.code && ((LOCALE_ERR_DICTS[loc] || {})[res.code] || errEn[res.code]);
1667
+ if (msg) return msg;
1532
1668
  }
1533
1669
  return res.error || '';
1534
1670
  }