zcode-pro 1.8.2 → 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.
@@ -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
 
@@ -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: '生成中…',
@@ -387,6 +392,8 @@ const zh = {
387
392
  assistantFontDesc: '会话中回答正文的字体(代码块仍用等宽字体);选“默认”时跟随界面字体。',
388
393
  switcherHint: '{prev} / {next} 或 ↑ / ↓ 选择,Enter 或点击行切换,Esc 取消',
389
394
  switcherCurrent: '当前',
395
+ switcherNewTask: '新建任务',
396
+ switcherTaskDraft: '不在项目中',
390
397
  switcherEmpty: '暂无上次会话(切换过会话后可用)',
391
398
  switcherFailed: '未能切换到该会话(可能已删除)',
392
399
  switcherMore: '还有 {n} 条 · 按 c 加载',
@@ -411,6 +418,7 @@ const zh = {
411
418
  themeBgPane: '壁纸',
412
419
  themeSkinTitle: '皮肤',
413
420
  themeSkinDesc: '知名编辑器主题配色,自动匹配 ZCode 的浅色 / 深色模式;默认保持 ZCode 原样,自定义在下方自行调色。',
421
+ themeSkinDefault: '默认',
414
422
  themeSkinCustom: '自定义',
415
423
  themeCustomTitle: '自定义主题',
416
424
  themeCustomHint: '改颜色即实时生效(自动切到自定义皮肤);浅色、深色各配一次,选好 5 个颜色即可生成整套界面配色。',
@@ -479,6 +487,10 @@ const zh = {
479
487
  tableCopied: '表格已复制',
480
488
  sbItemCtx: '上下文占用',
481
489
  sbItemTokRate: '最近输出 tokens/s',
490
+ sbTokRateStreaming: '流式生成中,按文本增长估算(约 2 字符/token)',
491
+ sbTokRateNet: '(官方净生成口径,本会话树)',
492
+ sbTokRateNoData: '无 usage 数据,按文本增长估算',
493
+ sbTokRateSessionSuffix: '(本会话):',
482
494
  sbItemQuestions: '主请求数(本会话)',
483
495
  sbItemInOut: '累计输入/输出(本会话主轮请求)',
484
496
  sbItemHit: '平均缓存命中率(本会话)',
@@ -569,6 +581,36 @@ const zh = {
569
581
  pluginsUpdateFailed: '插件更新失败',
570
582
  pluginsUpdatesAvailable: 'zcode-plugins 有 {n} 个插件可更新(ZCode Pro 设置 → 功能)',
571
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: '无头续接启动失败,请稍后再试或手动处理。',
572
614
  tabVision: 'Vision',
573
615
  visionDesc: '主模型不支持图片输入时(如 glm-5.3),自动把消息里的图片交给下面的视觉模型识别,把描述带给主模型(zcode-vision 插件;/vision-* 命令编辑同一配置)。',
574
616
  visionEnabled: '启用',
@@ -968,6 +1010,7 @@ const en = {
968
1010
  titleGenPrompt: 'Prompt',
969
1011
  titleGenPromptPlaceholder: 'Leave empty for the built-in default prompt (the button below shows it)',
970
1012
  titleGenPromptReset: 'Use default prompt',
1013
+ titleGenAssistantSummary: ' (first answer summary)',
971
1014
  titleGenSample: 'Test message',
972
1015
  titleGenTest: 'Test',
973
1016
  titleGenTesting: 'Generating…',
@@ -1023,6 +1066,8 @@ const en = {
1023
1066
  assistantFontDesc: 'Font of answer text in conversations (code blocks stay monospaced); "default" follows the UI font.',
1024
1067
  switcherHint: '{prev} / {next} or ↑ / ↓ to choose, Enter or click a row to switch, Esc to cancel',
1025
1068
  switcherCurrent: 'current',
1069
+ switcherNewTask: 'new task',
1070
+ switcherTaskDraft: 'no project',
1026
1071
  switcherEmpty: 'No previous session yet (available after you switch sessions)',
1027
1072
  switcherFailed: 'Failed to switch to that session (it may have been deleted)',
1028
1073
  switcherMore: '{n} more · press c to load',
@@ -1047,6 +1092,7 @@ const en = {
1047
1092
  themeBgPane: 'Wallpaper',
1048
1093
  themeSkinTitle: 'Skins',
1049
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',
1050
1096
  themeSkinCustom: 'Custom',
1051
1097
  themeCustomTitle: 'Custom theme',
1052
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.',
@@ -1115,6 +1161,10 @@ const en = {
1115
1161
  tableCopied: 'Table copied',
1116
1162
  sbItemCtx: 'Context usage',
1117
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): ',
1118
1168
  sbItemQuestions: 'Main requests (this session)',
1119
1169
  sbItemInOut: 'Total input/output (main requests, this session)',
1120
1170
  sbItemHit: 'Average cache hit rate (this session)',
@@ -1205,6 +1255,36 @@ const en = {
1205
1255
  pluginsUpdateFailed: 'Plugin update failed',
1206
1256
  pluginsUpdatesAvailable: '{n} zcode-plugins update(s) available (ZCode Pro settings → Features)',
1207
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.',
1208
1288
  tabVision: 'Vision',
1209
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).',
1210
1290
  visionEnabled: 'Enable',
@@ -1402,12 +1482,24 @@ const en = {
1402
1482
  };
1403
1483
 
1404
1484
  // 界面语言:与官方 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(尚未取回)
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(尚未取回)
1411
1503
 
1412
1504
  export function startLocaleResolver() {
1413
1505
  if (cachedSystemLocale !== null) return; // 已取回则跳过,避免重复 IPC(index.js 会调用两次)
@@ -1416,33 +1508,54 @@ export function startLocaleResolver() {
1416
1508
  Promise.resolve(get())
1417
1509
  .then((locale) => {
1418
1510
  if (typeof locale === 'string' && locale) {
1419
- // 与主进程解析一致:zh 开头视为中文,其余视为英文(兼容 'zh-Hans-CN' 等原始格式)
1420
- cachedSystemLocale = locale.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
1511
+ // 兼容 'zh-Hans-CN'、'ja_JP' 等原始格式,按前缀归一到官方语言代码
1512
+ cachedSystemLocale = normalizeUiLocale(locale) || 'en-US';
1421
1513
  }
1422
1514
  })
1423
1515
  .catch(() => { /* 取回失败:沿用 navigator.language 兜底 */ });
1424
1516
  }
1425
1517
 
1426
- let zhCache = { at: 0, v: null };
1427
- export function isZhLocale() {
1518
+ let uiLocaleCache = { at: 0, v: null };
1519
+ export function uiLocale() {
1428
1520
  // 结果缓存 3 秒:一轮渲染里要调十几次,localStorage 每次读有成本;
1429
1521
  // 语言切换本来就会重载界面,短缓存跟得上
1430
- if (zhCache.v != null && Date.now() - zhCache.at < 3000) return zhCache.v;
1522
+ if (uiLocaleCache.v && Date.now() - uiLocaleCache.at < 3000) return uiLocaleCache.v;
1431
1523
  let pref = null;
1432
1524
  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 };
1525
+ const v = normalizeUiLocale(pref)
1526
+ || normalizeUiLocale(cachedSystemLocale)
1527
+ || normalizeUiLocale(navigator.language)
1528
+ || 'en-US';
1529
+ uiLocaleCache = { at: Date.now(), v };
1437
1530
  return v;
1438
1531
  }
1439
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 };
1440
1553
  export function t() {
1441
- return isZhLocale() ? zh : en;
1554
+ return LOCALE_DICTS[uiLocale()] || en;
1442
1555
  }
1443
1556
 
1444
- // helper 错误消息的英文映射(code → 文案):helper 原文为中文,非中文界面按 code 显示英文,
1445
- // 无映射或中文界面回退 helper 原文
1557
+ // helper 错误消息的本地化映射(code → 文案):helper 原文为中文,非中文界面按 code
1558
+ // 显示对应语言;无映射或中文界面回退 helper 原文
1446
1559
  const errEn = {
1447
1560
  'invalid-path': 'Invalid project path',
1448
1561
  'not-found': 'The folder does not exist',
@@ -1526,17 +1639,32 @@ const errEn = {
1526
1639
  'protected-path': 'Refused: the path points inside the ZCode data directory',
1527
1640
  'same-path': 'The new location is the same as the current one',
1528
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',
1529
1649
  // 其他
1530
1650
  'no-content': 'This session has no Q&A content yet',
1531
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',
1532
1656
  'headroom-provider-config': 'ZCode provider config not found (v2/config.json)',
1533
1657
  };
1534
1658
 
1659
+ const LOCALE_ERR_DICTS = { 'en-US': errEn, 'ja-JP': jaErrors, 'ko-KR': koErrors, 'ru-RU': ruErrors };
1660
+
1535
1661
  export function errText(res) {
1536
1662
  if (!res) return '';
1537
- if (!isZhLocale()) {
1538
- const en = res.code && errEn[res.code];
1539
- 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;
1540
1668
  }
1541
1669
  return res.error || '';
1542
1670
  }