zcode-pro 1.8.2 → 1.10.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.
@@ -20,6 +20,9 @@ import { existsSync } from 'node:fs';
20
20
  import { join } from 'node:path';
21
21
 
22
22
  const BUSY_TIMEOUT_MS = 5000;
23
+ // 子代理轮次结束与 session.time_updated 的写入先后有几毫秒差;超过这段时长的新活动
24
+ // 才算下一轮已经开始(继续对话),见 listSubagentChildrenActivity
25
+ const SUBAGENT_TURN_START_GRACE_MS = 5000;
23
26
 
24
27
  export function taskIndexPath(dataRoot) {
25
28
  return join(dataRoot, 'v2', 'tasks-index.sqlite');
@@ -350,7 +353,13 @@ export async function listSessionsActivity(dataRoot, ids) {
350
353
  // 指定会话的子代理会话及最近活动时间(含嵌套子代理,根归属到最初的那个会话):
351
354
  // [{ id, root, at }]。子代理判活以这里写入会话库的活动时间为准——应用的运行记录两头都
352
355
  // 不可靠:长跑子代理会被误记为失败/结束(实测 48 分钟、60 分钟的都在跑着时被
353
- // 记 end),崩溃残留的又永远挂"运行中"(subagent-icon.js)
356
+ // 记 end),崩溃残留的又永远挂"运行中"(subagent-icon.js)。
357
+ // “还在跑”按轮次判定:turn_usage 里每个已结束轮次的 completed_at 是最后一片记录
358
+ // 的写入时间,会话的 time_updated 晚于它(留写入先后余量)说明之后又开了新轮
359
+ // (继续对话),才算在跑;没有轮次记录且 last_outcome 为空(第一轮还没结束)也算。
360
+ // 已结束且没有后续活动的子代理不返回:中断时父回合被打断,工具的结束记录没有写入;
361
+ // 被继续唤起过的子代理,应用记的结束时间还停在最初那次,只靠活动时间会让机器人
362
+ // 图标一直亮着。老库缺 last_outcome 列或 turn_usage 表时退回原查询。
354
363
  export async function listSubagentChildrenActivity(dataRoot, ids) {
355
364
  const out = [];
356
365
  const wanted = [...new Set((ids || []).map(String).filter(Boolean))];
@@ -361,11 +370,35 @@ export async function listSubagentChildrenActivity(dataRoot, ids) {
361
370
  if (!driver) return out;
362
371
  const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
363
372
  const inList = wanted.map((id) => esc(id)).join(', ');
373
+ // last_outcome 列(0.16.9+)与 turn_usage 表(0.15.0+):旧库缺哪个就退回对应的老逻辑
374
+ let hasOutcome = false;
375
+ let hasTurnUsage = false;
376
+ try {
377
+ if (driver.kind === 'node') {
378
+ const db = new driver.DatabaseSync(dbFile, { readOnly: true });
379
+ try {
380
+ const cols = db.prepare("PRAGMA table_info('session')").all();
381
+ hasOutcome = cols.some((c) => String(c.name) === 'last_outcome');
382
+ hasTurnUsage = !!db.prepare(
383
+ "SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'turn_usage'").get();
384
+ } finally { db.close(); }
385
+ } else {
386
+ const cols = runCli(dbFile, "PRAGMA table_info('session');").stdout;
387
+ hasOutcome = cols.split(/\r?\n/).some((l) => l.split('|')[1] === 'last_outcome');
388
+ const tables = runCli(dbFile,
389
+ "SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'turn_usage';").stdout;
390
+ hasTurnUsage = tables.trim() === 'turn_usage';
391
+ }
392
+ } catch { /* 探测失败按旧库处理 */ }
393
+ const outcomeCol = hasOutcome ? ', s.last_outcome AS outcome' : '';
394
+ const doneCol = hasTurnUsage
395
+ ? ', (SELECT max(t.completed_at) FROM turn_usage t WHERE t.session_id = s.id) AS done'
396
+ : '';
364
397
  const sql = `WITH RECURSIVE fam(id, root) AS (
365
398
  SELECT id, parent_id FROM session WHERE parent_id IN (${inList})
366
399
  UNION
367
400
  SELECT s.id, f.root FROM session s JOIN fam f ON s.parent_id = f.id
368
- ) SELECT fam.root AS root, s.id AS id, s.time_updated AS at
401
+ ) SELECT fam.root AS root, s.id AS id, s.time_updated AS at${outcomeCol}${doneCol}
369
402
  FROM session s JOIN fam ON s.id = fam.id
370
403
  WHERE s.task_type = 'subagent_child'`;
371
404
  try {
@@ -374,11 +407,24 @@ export async function listSubagentChildrenActivity(dataRoot, ids) {
374
407
  const db = new driver.DatabaseSync(dbFile, { readOnly: true });
375
408
  try { rows = db.prepare(sql).all(); } finally { db.close(); }
376
409
  } else {
410
+ const fields = ["'root', root", "'id', id", "'at', at"];
411
+ if (hasOutcome) fields.push("'outcome', outcome");
412
+ if (hasTurnUsage) fields.push("'done', done");
377
413
  const agg = runCli(dbFile,
378
- `SELECT coalesce(json_group_array(json_object('root', root, 'id', id, 'at', at)), '[]') FROM (${sql});`);
414
+ `SELECT coalesce(json_group_array(json_object(${fields.join(', ')})), '[]') FROM (${sql});`);
379
415
  rows = JSON.parse(agg.stdout.trim() || '[]');
380
416
  }
381
- for (const r of rows) out.push({ id: String(r.id), root: String(r.root), at: Number(r.at) || 0 });
417
+ for (const r of rows) {
418
+ const at = Number(r.at) || 0;
419
+ if (hasOutcome && hasTurnUsage) {
420
+ const done = Number(r.done) || 0;
421
+ // 已结束轮次之后没有新活动:不在跑。第一轮还没结束(done=0、outcome 空)算在跑
422
+ if (done > 0 ? !(at > done + SUBAGENT_TURN_START_GRACE_MS) : !!r.outcome) continue;
423
+ } else if (hasOutcome && r.outcome && r.outcome !== 'completed') {
424
+ continue;
425
+ }
426
+ out.push({ id: String(r.id), root: String(r.root), at });
427
+ }
382
428
  return out;
383
429
  } catch {
384
430
  return out;
@@ -914,6 +960,79 @@ export async function listTaskWorkspaceMap(dataRoot) {
914
960
  return out;
915
961
  }
916
962
 
963
+ // 会话 ID → 祖先会话 ID 列表(自身在前,沿 CLI 会话库的 parent_id 逐级上溯,
964
+ // 最多 32 级防环)。子代理会话(sess_subagent_agent_*)不在任务索引里,只有
965
+ // 上溯到根会话才查得到它属于哪个项目;查不到的 id 不出现在结果里。
966
+ export async function listSessionAncestors(dataRoot, ids) {
967
+ const out = {};
968
+ const wanted = [...new Set((ids || []).map(String).filter(Boolean))];
969
+ if (!wanted.length) return out;
970
+ const dbFile = join(dataRoot, 'cli', 'db', 'db.sqlite');
971
+ if (!existsSync(dbFile)) return out;
972
+ const driver = await loadDriver();
973
+ if (!driver) return out;
974
+ const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
975
+ const inList = wanted.map((id) => esc(id)).join(', ');
976
+ const sql = `WITH RECURSIVE up(id, node, lvl) AS (
977
+ SELECT id, id, 0 FROM session WHERE id IN (${inList})
978
+ UNION
979
+ SELECT u.id, s.parent_id, u.lvl + 1 FROM up u JOIN session s ON s.id = u.node
980
+ WHERE u.lvl < 32
981
+ ) SELECT id, node FROM up WHERE node IS NOT NULL AND node <> '' ORDER BY id, lvl`;
982
+ try {
983
+ let rows;
984
+ if (driver.kind === 'node') {
985
+ const db = new driver.DatabaseSync(dbFile, { readOnly: true });
986
+ try { rows = db.prepare(sql).all(); } finally { db.close(); }
987
+ } else {
988
+ const agg = runCli(dbFile,
989
+ `SELECT coalesce(json_group_array(json_object('id', id, 'node', node)), '[]') FROM (${sql});`);
990
+ rows = JSON.parse(agg.stdout.trim() || '[]');
991
+ }
992
+ for (const r of rows) {
993
+ const id = String(r.id);
994
+ if (!out[id]) out[id] = [];
995
+ const node = String(r.node);
996
+ if (!out[id].includes(node)) out[id].push(node);
997
+ }
998
+ return out;
999
+ } catch {
1000
+ return out;
1001
+ }
1002
+ }
1003
+
1004
+ // 工作区内子代理会话的最近活动时间(毫秒):空闲回收的子代理保护用。
1005
+ // 按会话库的 directory 直查,不受 /workspace-sessions 的 30 条/7 天限制。
1006
+ // directory 的分隔符/尾斜杠/大小写在各平台写法不一(Linux 带尾 /,Windows 可能
1007
+ // 带尾 \ 或大小写不同),SQL 内双侧归一后比较。
1008
+ // 返回 0 = 无子代理活动(含会话库不存在:确定没有);null = 读库失败/驱动不可用
1009
+ //(调用方按未知处理,不当作没有)
1010
+ export async function listWorkspaceSubagentActivity(dataRoot, path) {
1011
+ const norm = String(path || '').replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase();
1012
+ if (!norm) return 0;
1013
+ const dbFile = join(dataRoot, 'cli', 'db', 'db.sqlite');
1014
+ if (!existsSync(dbFile)) return 0;
1015
+ const driver = await loadDriver();
1016
+ if (!driver) return null;
1017
+ const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
1018
+ const sql = `SELECT max(time_updated) AS at FROM session
1019
+ WHERE task_type = 'subagent_child'
1020
+ AND lower(rtrim(replace(directory, ${esc('\\')}, '/'), '/')) = ${esc(norm)}`;
1021
+ try {
1022
+ let row;
1023
+ if (driver.kind === 'node') {
1024
+ const db = new driver.DatabaseSync(dbFile, { readOnly: true });
1025
+ try { row = db.prepare(sql).get(); } finally { db.close(); }
1026
+ } else {
1027
+ const agg = runCli(dbFile, `SELECT coalesce(json_object('at', at), 'null') FROM (${sql});`);
1028
+ row = JSON.parse(agg.stdout.trim() || 'null');
1029
+ }
1030
+ return Number(row && row.at) || 0;
1031
+ } catch {
1032
+ return null;
1033
+ }
1034
+ }
1035
+
917
1036
  function runCli(dbFile, script) {
918
1037
  const r = spawnSync('sqlite3', ['-bail', '-batch', dbFile], {
919
1038
  windowsHide: true,
@@ -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
 
@@ -331,6 +335,7 @@ const zh = {
331
335
  titleGenPrompt: '提示词',
332
336
  titleGenPromptPlaceholder: '留空使用内置默认提示词(点击下方按钮可查看)',
333
337
  titleGenPromptReset: '使用默认提示词',
338
+ titleGenAssistantSummary: '(首轮回答摘要)',
334
339
  titleGenSample: '测试消息',
335
340
  titleGenTest: '测试生成',
336
341
  titleGenTesting: '生成中…',
@@ -353,6 +358,8 @@ const zh = {
353
358
  featureSubagentIconDesc: '后台子代理在跑显机器人、后台终端命令在跑显终端图标(同时在跑机器人优先);未读圆点让位到行尾常显;会话运行中始终显示转圈图标;项目未读徽标忽略错误行。',
354
359
  subagentRobotTip: '子代理运行中',
355
360
  subagentTermTip: '后台命令运行中',
361
+ subagentFreshLabel: '子代理无活动多久算结束(分钟)',
362
+ subagentFreshHint: '超过这个时长没有子代理活动视为结束:不再亮机器人图标,也不再查询官方结束记录。查询只对最近仍有活动的会话发起,避免为空闲项目启动会话进程。',
356
363
  tabPerformance: '性能',
357
364
  perfDesc: 'ZCode 为每个打开过的项目常驻一个会话进程,应用自身不会回收,项目多了内存占用就高。开启后,长时间未使用且没有任务在跑的项目会被自动释放:会话记录不受影响,再次打开时自动恢复,仅首次回复有几秒等待。正在使用的项目、运行中的会话与后台命令、定时任务都不会被回收。后台命令检测依赖系统进程信息(Linux / macOS / Windows 各走系统自带工具),检测不可用时功能自动停用。',
358
365
  featureIdleReclaim: '空闲项目内存回收',
@@ -387,6 +394,8 @@ const zh = {
387
394
  assistantFontDesc: '会话中回答正文的字体(代码块仍用等宽字体);选“默认”时跟随界面字体。',
388
395
  switcherHint: '{prev} / {next} 或 ↑ / ↓ 选择,Enter 或点击行切换,Esc 取消',
389
396
  switcherCurrent: '当前',
397
+ switcherNewTask: '新建任务',
398
+ switcherTaskDraft: '不在项目中',
390
399
  switcherEmpty: '暂无上次会话(切换过会话后可用)',
391
400
  switcherFailed: '未能切换到该会话(可能已删除)',
392
401
  switcherMore: '还有 {n} 条 · 按 c 加载',
@@ -411,6 +420,7 @@ const zh = {
411
420
  themeBgPane: '壁纸',
412
421
  themeSkinTitle: '皮肤',
413
422
  themeSkinDesc: '知名编辑器主题配色,自动匹配 ZCode 的浅色 / 深色模式;默认保持 ZCode 原样,自定义在下方自行调色。',
423
+ themeSkinDefault: '默认',
414
424
  themeSkinCustom: '自定义',
415
425
  themeCustomTitle: '自定义主题',
416
426
  themeCustomHint: '改颜色即实时生效(自动切到自定义皮肤);浅色、深色各配一次,选好 5 个颜色即可生成整套界面配色。',
@@ -479,6 +489,10 @@ const zh = {
479
489
  tableCopied: '表格已复制',
480
490
  sbItemCtx: '上下文占用',
481
491
  sbItemTokRate: '最近输出 tokens/s',
492
+ sbTokRateStreaming: '流式生成中,按文本增长估算(约 2 字符/token)',
493
+ sbTokRateNet: '(官方净生成口径,本会话树)',
494
+ sbTokRateNoData: '无 usage 数据,按文本增长估算',
495
+ sbTokRateSessionSuffix: '(本会话):',
482
496
  sbItemQuestions: '主请求数(本会话)',
483
497
  sbItemInOut: '累计输入/输出(本会话主轮请求)',
484
498
  sbItemHit: '平均缓存命中率(本会话)',
@@ -569,6 +583,36 @@ const zh = {
569
583
  pluginsUpdateFailed: '插件更新失败',
570
584
  pluginsUpdatesAvailable: 'zcode-plugins 有 {n} 个插件可更新(ZCode Pro 设置 → 功能)',
571
585
  pluginsAutoUpdated: 'zcode-plugins 插件已更新',
586
+ tabAutoContinue: '自动继续',
587
+ acDesc: '回合因请求故障失败(红色报错横幅)或回复中途截断时,自动发一条继续指令把任务接上;重开会话(含重启 ZCode 后)没做完的任务也接上。认证、余额、模型不存在等永久性错误和手动停止不打扰。配置在 ~/.zcode/auto-continue.json。',
588
+ acEnabled: '启用',
589
+ acPrompt: '继续提示词',
590
+ acMaxRetries: '最多继续次数',
591
+ acMaxRetriesHint: '30 分钟内自动继续的累计上限,防止故障反复时刷屏',
592
+ acCooldown: '密集失败退避基数(秒)',
593
+ acCooldownHint: '2 分钟内已继续过就视为密集失败,间隔按 2 倍递增、上限 60 秒;单次失败只等 3 秒界面稳定',
594
+ acStuckAfterMin: '卡死判定(分钟)',
595
+ acStuckAfterMinHint: '后台终端任务、子代理或主回合多久没有动静才弹卡提示;会话本身也要静默同样久',
596
+ acFailedAfterMin: '失败后自动续接(分钟)',
597
+ acFailedAfterMinHint: '回合失败多久后自动继续;会先等 60 秒跳过失败后的清理事件',
598
+ acLoadFailed: '读取自动继续配置失败',
599
+ acCardKindSubagent: '子代理卡死',
600
+ acCardKindTurn: '主轮卡死',
601
+ acCardKindTerminal: '终端卡死',
602
+ acCardFailedTitle: '回合失败未续上',
603
+ acCardMore: '(队列中还有 {n} 个)',
604
+ acCardFailedDesc: '任务“{title}”{mins} 分钟前回合失败({msg}),一直没人续上。',
605
+ acCardTerminalSilent: '{count} 个后台终端任务已 {mins} 分钟没有回报',
606
+ acCardSubagentSilent: '{count} 个子代理已 {mins} 分钟没有回报',
607
+ acCardTurnStalled: '主回合已 {mins} 分钟没有进展',
608
+ acCardStuckDesc: '任务“{title}”:{parts}。确实在跑的长任务(如打包)点“知道了”即可。',
609
+ acCardKindSep: '、',
610
+ acCardPartSep: ';',
611
+ acCardJump: '跳转任务',
612
+ acCardContinue: '继续',
613
+ acCardDismiss: '知道了',
614
+ acCardContinueStartFailed: '续接启动失败:',
615
+ acCardHeadlessFailed: '无头续接启动失败,请稍后再试或手动处理。',
572
616
  tabVision: 'Vision',
573
617
  visionDesc: '主模型不支持图片输入时(如 glm-5.3),自动把消息里的图片交给下面的视觉模型识别,把描述带给主模型(zcode-vision 插件;/vision-* 命令编辑同一配置)。',
574
618
  visionEnabled: '启用',
@@ -968,6 +1012,7 @@ const en = {
968
1012
  titleGenPrompt: 'Prompt',
969
1013
  titleGenPromptPlaceholder: 'Leave empty for the built-in default prompt (the button below shows it)',
970
1014
  titleGenPromptReset: 'Use default prompt',
1015
+ titleGenAssistantSummary: ' (first answer summary)',
971
1016
  titleGenSample: 'Test message',
972
1017
  titleGenTest: 'Test',
973
1018
  titleGenTesting: 'Generating…',
@@ -989,6 +1034,8 @@ const en = {
989
1034
  featureSubagentIconDesc: 'Task rows show a robot icon while subagents run and a terminal icon while background commands run (robot wins when both); the unread dot moves to the row end; running sessions always show a spinner; project unread badges ignore error rows.',
990
1035
  subagentRobotTip: 'Subagents running',
991
1036
  subagentTermTip: 'Background commands running',
1037
+ subagentFreshLabel: 'Minutes without subagent activity before considered finished',
1038
+ subagentFreshHint: 'Longer than this without subagent activity counts as finished: the robot icon turns off and official end records are no longer queried. Queries only go to sessions with recent activity, so idle projects are not started.',
992
1039
  tabPerformance: 'Performance',
993
1040
  perfDesc: 'ZCode keeps a session process resident for every project you have opened and never reclaims it, so memory grows with projects. When enabled, projects unused for a while with nothing running release their memory automatically: sessions are untouched and reload when reopened, with a few seconds\' wait on the first reply. The project in use, running sessions, background commands and scheduled tasks are never reclaimed. Background-command detection reads system process info via built-in tools (Linux / macOS / Windows); when unavailable, the feature disables itself.',
994
1041
  featureIdleReclaim: 'Idle project memory reclaim',
@@ -1023,6 +1070,8 @@ const en = {
1023
1070
  assistantFontDesc: 'Font of answer text in conversations (code blocks stay monospaced); "default" follows the UI font.',
1024
1071
  switcherHint: '{prev} / {next} or ↑ / ↓ to choose, Enter or click a row to switch, Esc to cancel',
1025
1072
  switcherCurrent: 'current',
1073
+ switcherNewTask: 'new task',
1074
+ switcherTaskDraft: 'no project',
1026
1075
  switcherEmpty: 'No previous session yet (available after you switch sessions)',
1027
1076
  switcherFailed: 'Failed to switch to that session (it may have been deleted)',
1028
1077
  switcherMore: '{n} more · press c to load',
@@ -1047,6 +1096,7 @@ const en = {
1047
1096
  themeBgPane: 'Wallpaper',
1048
1097
  themeSkinTitle: 'Skins',
1049
1098
  themeSkinDesc: 'Well-known editor theme palettes, auto-matching ZCode\'s light / dark mode; "Default" keeps ZCode as-is, "Custom" is tuned below.',
1099
+ themeSkinDefault: 'Default',
1050
1100
  themeSkinCustom: 'Custom',
1051
1101
  themeCustomTitle: 'Custom theme',
1052
1102
  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.',
@@ -1115,6 +1165,10 @@ const en = {
1115
1165
  tableCopied: 'Table copied',
1116
1166
  sbItemCtx: 'Context usage',
1117
1167
  sbItemTokRate: 'Recent output tokens/s',
1168
+ sbTokRateStreaming: 'streaming; estimated from text growth (~2 chars/token)',
1169
+ sbTokRateNet: ' (net generation, session tree)',
1170
+ sbTokRateNoData: 'no usage data, estimated from text growth',
1171
+ sbTokRateSessionSuffix: ' (this session): ',
1118
1172
  sbItemQuestions: 'Main requests (this session)',
1119
1173
  sbItemInOut: 'Total input/output (main requests, this session)',
1120
1174
  sbItemHit: 'Average cache hit rate (this session)',
@@ -1205,6 +1259,36 @@ const en = {
1205
1259
  pluginsUpdateFailed: 'Plugin update failed',
1206
1260
  pluginsUpdatesAvailable: '{n} zcode-plugins update(s) available (ZCode Pro settings → Features)',
1207
1261
  pluginsAutoUpdated: 'zcode-plugins updated',
1262
+ tabAutoContinue: 'Auto-continue',
1263
+ 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.',
1264
+ acEnabled: 'Enable',
1265
+ acPrompt: 'Continue prompt',
1266
+ acMaxRetries: 'Max auto-continues',
1267
+ acMaxRetriesHint: 'Cap on auto-continues within 30 minutes, to avoid flooding on repeated failures',
1268
+ acCooldown: 'Backoff base for burst failures (s)',
1269
+ 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',
1270
+ acStuckAfterMin: 'Stuck threshold (min)',
1271
+ 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',
1272
+ acFailedAfterMin: 'Auto-continue after failure (min)',
1273
+ acFailedAfterMinHint: 'How long after a failed turn to continue automatically; waits 60s first to skip post-failure cleanup events',
1274
+ acLoadFailed: 'Failed to load the auto-continue config',
1275
+ acCardKindSubagent: 'Subagent stuck',
1276
+ acCardKindTurn: 'Main turn stuck',
1277
+ acCardKindTerminal: 'Terminal stuck',
1278
+ acCardFailedTitle: 'Turn failed, not continued',
1279
+ acCardMore: ' ({n} more queued)',
1280
+ acCardFailedDesc: 'Task “{title}” failed {mins} min ago ({msg}) and was never continued.',
1281
+ acCardTerminalSilent: '{count} background terminal task(s) silent for {mins} min',
1282
+ acCardSubagentSilent: '{count} subagent(s) silent for {mins} min',
1283
+ acCardTurnStalled: 'The main turn has stalled for {mins} min',
1284
+ acCardStuckDesc: 'Task “{title}”: {parts}. Dismiss long-running builds with “Dismiss”.',
1285
+ acCardKindSep: ', ',
1286
+ acCardPartSep: '; ',
1287
+ acCardJump: 'Go to task',
1288
+ acCardContinue: 'Continue',
1289
+ acCardDismiss: 'Dismiss',
1290
+ acCardContinueStartFailed: 'Failed to start continue: ',
1291
+ acCardHeadlessFailed: 'Failed to start headless continue; retry later or handle manually.',
1208
1292
  tabVision: 'Vision',
1209
1293
  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).',
1210
1294
  visionEnabled: 'Enable',
@@ -1402,12 +1486,24 @@ const en = {
1402
1486
  };
1403
1487
 
1404
1488
  // 界面语言:与官方 IntlProvider 的解析一致——先读应用的 localStorage 偏好
1405
- // (zcode-locale-preference:zh-CN/en-US/system),显式偏好直接生效;'system' 或未设置时
1406
- // 官方在主进程用系统首选语言解析(macOS 上可能与渲染进程的 navigator.language 不一致:
1407
- // 系统是中文而 Chromium 报 en-US,导致注入界面误判成英文)。这里通过 preload 暴露的
1408
- // window.zcode.getSystemLocale()(IPC,异步)取主进程结果并缓存;取回前先按
1409
- // navigator.language 兜底,避免阻塞首次渲染。
1410
- let cachedSystemLocale = null; // 'zh-CN' | 'en-US' | null(尚未取回)
1489
+ // (zcode-locale-preference:zh-CN/en-US/ja-JP/ko-KR/ru-RU/system),显式偏好直接生效;
1490
+ // 'system' 或未设置时官方在主进程用系统首选语言解析(macOS 上可能与渲染进程的
1491
+ // navigator.language 不一致:系统是中文而 Chromium 报 en-US,导致注入界面误判成英文)。
1492
+ // 这里通过 preload 暴露的 window.zcode.getSystemLocale()(IPC,异步)取主进程结果并缓存;
1493
+ // 取回前先按 navigator.language 兜底,避免阻塞首次渲染。
1494
+ // 语言代码按前缀归一:zh/ja/ko/ru/en → 官方支持的五种,其余视为未知。
1495
+ export function normalizeUiLocale(raw) {
1496
+ const s = String(raw || '').trim().toLowerCase().replace(/_/g, '-');
1497
+ if (!s || s === 'system') return '';
1498
+ if (s.startsWith('zh')) return 'zh-CN';
1499
+ if (s.startsWith('en')) return 'en-US';
1500
+ if (s.startsWith('ja')) return 'ja-JP';
1501
+ if (s.startsWith('ko')) return 'ko-KR';
1502
+ if (s.startsWith('ru')) return 'ru-RU';
1503
+ return '';
1504
+ }
1505
+
1506
+ let cachedSystemLocale = null; // 'zh-CN' | 'en-US' | 'ja-JP' | 'ko-KR' | 'ru-RU' | null(尚未取回)
1411
1507
 
1412
1508
  export function startLocaleResolver() {
1413
1509
  if (cachedSystemLocale !== null) return; // 已取回则跳过,避免重复 IPC(index.js 会调用两次)
@@ -1416,33 +1512,54 @@ export function startLocaleResolver() {
1416
1512
  Promise.resolve(get())
1417
1513
  .then((locale) => {
1418
1514
  if (typeof locale === 'string' && locale) {
1419
- // 与主进程解析一致:zh 开头视为中文,其余视为英文(兼容 'zh-Hans-CN' 等原始格式)
1420
- cachedSystemLocale = locale.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
1515
+ // 兼容 'zh-Hans-CN'、'ja_JP' 等原始格式,按前缀归一到官方语言代码
1516
+ cachedSystemLocale = normalizeUiLocale(locale) || 'en-US';
1421
1517
  }
1422
1518
  })
1423
1519
  .catch(() => { /* 取回失败:沿用 navigator.language 兜底 */ });
1424
1520
  }
1425
1521
 
1426
- let zhCache = { at: 0, v: null };
1427
- export function isZhLocale() {
1522
+ let uiLocaleCache = { at: 0, v: null };
1523
+ export function uiLocale() {
1428
1524
  // 结果缓存 3 秒:一轮渲染里要调十几次,localStorage 每次读有成本;
1429
1525
  // 语言切换本来就会重载界面,短缓存跟得上
1430
- if (zhCache.v != null && Date.now() - zhCache.at < 3000) return zhCache.v;
1526
+ if (uiLocaleCache.v && Date.now() - uiLocaleCache.at < 3000) return uiLocaleCache.v;
1431
1527
  let pref = null;
1432
1528
  try { pref = window.localStorage.getItem('zcode-locale-preference'); } catch { /* ignore */ }
1433
- const v = (pref === 'zh-CN' || pref === 'en-US') ? pref === 'zh-CN'
1434
- : cachedSystemLocale ? cachedSystemLocale === 'zh-CN'
1435
- : /^zh/i.test(navigator.language || 'zh-CN');
1436
- zhCache = { at: Date.now(), v };
1529
+ const v = normalizeUiLocale(pref)
1530
+ || normalizeUiLocale(cachedSystemLocale)
1531
+ || normalizeUiLocale(navigator.language)
1532
+ || 'en-US';
1533
+ uiLocaleCache = { at: Date.now(), v };
1437
1534
  return v;
1438
1535
  }
1439
1536
 
1537
+ export function isZhLocale() {
1538
+ // 中文界面判断:只用于中文标点、数字单位等格式差异;界面文案由 t() 按五种语言取
1539
+ return uiLocale() === 'zh-CN';
1540
+ }
1541
+
1542
+ // 中文/日文共用全角标点(括号、冒号、顿号、分号)
1543
+ export function isCjkLocale() {
1544
+ const loc = uiLocale();
1545
+ return loc === 'zh-CN' || loc === 'ja-JP';
1546
+ }
1547
+
1548
+ // 官方任务菜单“重命名任务”的五种语言标签;右键菜单注入与重命名弹窗预填都按它识别
1549
+ const RENAME_LABELS = ['重命名任务', 'rename task', 'タスクの名前を変更', '작업 이름 바꾸기', 'переименовать задачу'];
1550
+ export function isRenameLabel(text) {
1551
+ const s = String(text || '').trim().toLowerCase();
1552
+ return RENAME_LABELS.some((label) => s.includes(label.toLowerCase()));
1553
+ }
1554
+
1555
+ // 界面文案:ZCode 支持的五种语言各一套;未识别的语言回退英文
1556
+ const LOCALE_DICTS = { 'zh-CN': zh, 'en-US': en, 'ja-JP': ja, 'ko-KR': ko, 'ru-RU': ru };
1440
1557
  export function t() {
1441
- return isZhLocale() ? zh : en;
1558
+ return LOCALE_DICTS[uiLocale()] || en;
1442
1559
  }
1443
1560
 
1444
- // helper 错误消息的英文映射(code → 文案):helper 原文为中文,非中文界面按 code 显示英文,
1445
- // 无映射或中文界面回退 helper 原文
1561
+ // helper 错误消息的本地化映射(code → 文案):helper 原文为中文,非中文界面按 code
1562
+ // 显示对应语言;无映射或中文界面回退 helper 原文
1446
1563
  const errEn = {
1447
1564
  'invalid-path': 'Invalid project path',
1448
1565
  'not-found': 'The folder does not exist',
@@ -1526,17 +1643,32 @@ const errEn = {
1526
1643
  'protected-path': 'Refused: the path points inside the ZCode data directory',
1527
1644
  'same-path': 'The new location is the same as the current one',
1528
1645
  'export-cancelled': 'Canceled',
1646
+ // 自动续接(ac-*)
1647
+ 'ac-read': 'auto-continue.json is not valid JSON',
1648
+ 'ac-invalid': 'Missing config object',
1649
+ 'ac-write': 'Failed to write auto-continue.json',
1650
+ 'ac-continue-invalid': 'Missing a valid sessionId or text',
1651
+ 'ac-continue-spawn': 'Failed to start the headless resume',
1652
+ 'ac-mode-unsupported': 'Auto mode is reserved and unimplemented; not resumed automatically',
1529
1653
  // 其他
1530
1654
  'no-content': 'This session has no Q&A content yet',
1531
1655
  'title-gen-disabled': 'Auto rename is not enabled',
1656
+ 'title-gen-empty': 'The title model returned no text',
1657
+ 'title-gen-thinking': 'The title model used the whole output budget on thinking and returned no title',
1658
+ 'title-gen-timeout': 'The title model request timed out',
1659
+ 'title-gen-no-title': 'The title model returned no usable title',
1532
1660
  'headroom-provider-config': 'ZCode provider config not found (v2/config.json)',
1533
1661
  };
1534
1662
 
1663
+ const LOCALE_ERR_DICTS = { 'en-US': errEn, 'ja-JP': jaErrors, 'ko-KR': koErrors, 'ru-RU': ruErrors };
1664
+
1535
1665
  export function errText(res) {
1536
1666
  if (!res) return '';
1537
- if (!isZhLocale()) {
1538
- const en = res.code && errEn[res.code];
1539
- if (en) return en;
1667
+ const loc = uiLocale();
1668
+ if (loc !== 'zh-CN') {
1669
+ // 本地语言缺该错误码时回退英文,不要露出 helper 的中文原文
1670
+ const msg = res.code && ((LOCALE_ERR_DICTS[loc] || {})[res.code] || errEn[res.code]);
1671
+ if (msg) return msg;
1540
1672
  }
1541
1673
  return res.error || '';
1542
1674
  }