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.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/inject.js +777 -172
- package/package.json +2 -2
- package/src/host/helper.mjs +318 -37
- package/src/host/taskIndex.mjs +266 -0
- package/src/inject/core.js +49 -13
- package/src/inject/features/plugin-updates.js +58 -0
- package/src/inject/features/session-link.js +3 -1
- package/src/inject/features/session-switch.js +10 -7
- package/src/inject/features/settings-dialog.js +81 -14
- package/src/inject/features/status-bar.js +37 -17
- package/src/inject/features/subagent-icon.js +473 -0
- package/src/inject/features/turn-usage.js +35 -23
- package/src/inject/features/ws-running.js +2 -2
- package/src/inject/index.js +2 -0
- package/src/inject/ui.js +8 -0
package/src/host/taskIndex.mjs
CHANGED
|
@@ -317,6 +317,272 @@ export async function listTaskStatuses(dataRoot, ids) {
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
+
// 批量查会话最近活动时间:id → time_updated(毫秒,查不到记 0)。子代理运行状态
|
|
321
|
+
// 的新鲜度校验用——应用的 running 记录崩溃/重启后不清理(实测残留数月的僵死记录),
|
|
322
|
+
// 子代理运行时消息不断写入会话库,长时间无动静的按僵死处理(subagent-icon.js)
|
|
323
|
+
export async function listSessionsActivity(dataRoot, ids) {
|
|
324
|
+
const out = {};
|
|
325
|
+
const wanted = [...new Set((ids || []).map(String).filter(Boolean))];
|
|
326
|
+
if (!wanted.length) return out;
|
|
327
|
+
const dbFile = join(dataRoot, 'cli', 'db', 'db.sqlite');
|
|
328
|
+
if (!existsSync(dbFile)) return out;
|
|
329
|
+
const driver = await loadDriver();
|
|
330
|
+
if (!driver) return out;
|
|
331
|
+
const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
|
|
332
|
+
const inList = wanted.map((id) => esc(id)).join(', ');
|
|
333
|
+
try {
|
|
334
|
+
let rows;
|
|
335
|
+
if (driver.kind === 'node') {
|
|
336
|
+
const db = new driver.DatabaseSync(dbFile, { readOnly: true });
|
|
337
|
+
try { rows = db.prepare(`SELECT id, time_updated FROM session WHERE id IN (${inList})`).all(); } finally { db.close(); }
|
|
338
|
+
} else {
|
|
339
|
+
const agg = runCli(dbFile,
|
|
340
|
+
`SELECT coalesce(json_group_array(json_object('id', id, 'time_updated', time_updated)), '[]') FROM session WHERE id IN (${inList});`);
|
|
341
|
+
rows = JSON.parse(agg.stdout.trim() || '[]');
|
|
342
|
+
}
|
|
343
|
+
for (const r of rows) out[String(r.id)] = Number(r.time_updated) || 0;
|
|
344
|
+
return out;
|
|
345
|
+
} catch {
|
|
346
|
+
return out; // 读取失败按无活动处理(调用方视为僵死,不亮图标)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// 指定会话的子代理会话及最近活动时间(含嵌套子代理,根归属到最初的那个会话):
|
|
351
|
+
// [{ id, root, at }]。子代理判活以这里写入会话库的活动时间为准——应用的运行记录两头都
|
|
352
|
+
// 不可靠:长跑子代理会被误记为失败/结束(实测 48 分钟、60 分钟的都在跑着时被
|
|
353
|
+
// 记 end),崩溃残留的又永远挂"运行中"(subagent-icon.js)
|
|
354
|
+
export async function listSubagentChildrenActivity(dataRoot, ids) {
|
|
355
|
+
const out = [];
|
|
356
|
+
const wanted = [...new Set((ids || []).map(String).filter(Boolean))];
|
|
357
|
+
if (!wanted.length) return out;
|
|
358
|
+
const dbFile = join(dataRoot, 'cli', 'db', 'db.sqlite');
|
|
359
|
+
if (!existsSync(dbFile)) return out;
|
|
360
|
+
const driver = await loadDriver();
|
|
361
|
+
if (!driver) return out;
|
|
362
|
+
const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
|
|
363
|
+
const inList = wanted.map((id) => esc(id)).join(', ');
|
|
364
|
+
const sql = `WITH RECURSIVE fam(id, root) AS (
|
|
365
|
+
SELECT id, parent_id FROM session WHERE parent_id IN (${inList})
|
|
366
|
+
UNION
|
|
367
|
+
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
|
|
369
|
+
FROM session s JOIN fam ON s.id = fam.id
|
|
370
|
+
WHERE s.task_type = 'subagent_child'`;
|
|
371
|
+
try {
|
|
372
|
+
let rows;
|
|
373
|
+
if (driver.kind === 'node') {
|
|
374
|
+
const db = new driver.DatabaseSync(dbFile, { readOnly: true });
|
|
375
|
+
try { rows = db.prepare(sql).all(); } finally { db.close(); }
|
|
376
|
+
} else {
|
|
377
|
+
const agg = runCli(dbFile,
|
|
378
|
+
`SELECT coalesce(json_group_array(json_object('root', root, 'id', id, 'at', at)), '[]') FROM (${sql});`);
|
|
379
|
+
rows = JSON.parse(agg.stdout.trim() || '[]');
|
|
380
|
+
}
|
|
381
|
+
for (const r of rows) out.push({ id: String(r.id), root: String(r.root), at: Number(r.at) || 0 });
|
|
382
|
+
return out;
|
|
383
|
+
} catch {
|
|
384
|
+
return out;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// 状态栏统计用:会话 → trace_id。父子会话(含子代理)共享同一 trace,
|
|
389
|
+
// 状态栏据此把子代理的模型调用算进父会话的输出速率
|
|
390
|
+
export async function listSessionsTrace(dataRoot, ids) {
|
|
391
|
+
const out = {};
|
|
392
|
+
const wanted = [...new Set((ids || []).map(String).filter(Boolean))];
|
|
393
|
+
if (!wanted.length) return out;
|
|
394
|
+
const dbFile = join(dataRoot, 'cli', 'db', 'db.sqlite');
|
|
395
|
+
if (!existsSync(dbFile)) return out;
|
|
396
|
+
const driver = await loadDriver();
|
|
397
|
+
if (!driver) return out;
|
|
398
|
+
const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
|
|
399
|
+
const inList = wanted.map((id) => esc(id)).join(', ');
|
|
400
|
+
try {
|
|
401
|
+
let rows;
|
|
402
|
+
if (driver.kind === 'node') {
|
|
403
|
+
const db = new driver.DatabaseSync(dbFile, { readOnly: true });
|
|
404
|
+
try { rows = db.prepare(`SELECT id, trace_id FROM session WHERE id IN (${inList})`).all(); } finally { db.close(); }
|
|
405
|
+
} else {
|
|
406
|
+
const agg = runCli(dbFile,
|
|
407
|
+
`SELECT coalesce(json_group_array(json_object('id', id, 'trace_id', trace_id)), '[]') FROM session WHERE id IN (${inList});`);
|
|
408
|
+
rows = JSON.parse(agg.stdout.trim() || '[]');
|
|
409
|
+
}
|
|
410
|
+
for (const r of rows) out[String(r.id)] = String(r.trace_id || '');
|
|
411
|
+
return out;
|
|
412
|
+
} catch {
|
|
413
|
+
return out; // 读取失败按无 trace 处理(速率退化为只算本会话)
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// 官方口径的每轮用量(Token 调试同源数据与公式):主轮请求逐条返回 + 会话汇总。
|
|
418
|
+
// TPS = 输出 ÷(耗时 − 首 token 时机)= 官方“Output tokens ÷ 首个输出 token 到
|
|
419
|
+
// 请求结束的秒数”;命中率 = 缓存读 ÷ 输入(输入含缓存读,官方同语义)。
|
|
420
|
+
// query_source 只算 main_turn:起名等辅助小调用不进主轮统计(官方同款口径)。
|
|
421
|
+
// treeTrace 给出时 summary.tps 按会话树(本会话+同 trace 子代理)的最近请求算
|
|
422
|
+
// 60 秒窗净生成速率(窗口锚定最近一笔完成,锚不随请求时刻移动)
|
|
423
|
+
export async function listSessionModelUsage(dataRoot, sessionId, treeTrace = '') {
|
|
424
|
+
const empty = { rounds: [], summary: { requests: 0, totalIn: 0, totalOut: 0, totalCacheRead: 0, hitRate: null, tps: null } };
|
|
425
|
+
const sid = String(sessionId || '');
|
|
426
|
+
if (!sid) return empty;
|
|
427
|
+
const dbFile = join(dataRoot, 'cli', 'db', 'db.sqlite');
|
|
428
|
+
if (!existsSync(dbFile)) return empty;
|
|
429
|
+
const driver = await loadDriver();
|
|
430
|
+
if (!driver) return empty;
|
|
431
|
+
const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
|
|
432
|
+
const sql = `SELECT completed_at, duration_ms, time_to_first_token_ms, input_tokens, output_tokens,`
|
|
433
|
+
+ ` reasoning_tokens, cache_read_input_tokens, cache_creation_input_tokens, computed_total_tokens`
|
|
434
|
+
+ ` FROM model_usage WHERE session_id = ${esc(sid)} AND query_source = 'main_turn'`
|
|
435
|
+
+ ` AND status = 'completed' AND completed_at IS NOT NULL ORDER BY completed_at ASC`;
|
|
436
|
+
try {
|
|
437
|
+
let rows;
|
|
438
|
+
if (driver.kind === 'node') {
|
|
439
|
+
const db = new driver.DatabaseSync(dbFile, { readOnly: true });
|
|
440
|
+
try { rows = db.prepare(sql).all(); } finally { db.close(); }
|
|
441
|
+
} else {
|
|
442
|
+
const agg = runCli(dbFile,
|
|
443
|
+
`SELECT coalesce(json_group_array(json_object('completed_at', completed_at, 'duration_ms', duration_ms,`
|
|
444
|
+
+ ` 'time_to_first_token_ms', time_to_first_token_ms, 'input_tokens', input_tokens, 'output_tokens', output_tokens,`
|
|
445
|
+
+ ` 'reasoning_tokens', reasoning_tokens, 'cache_read_input_tokens', cache_read_input_tokens,`
|
|
446
|
+
+ ` 'cache_creation_input_tokens', cache_creation_input_tokens, 'computed_total_tokens', computed_total_tokens)), '[]')`
|
|
447
|
+
+ ` FROM (${sql});`);
|
|
448
|
+
rows = JSON.parse(agg.stdout.trim() || '[]');
|
|
449
|
+
}
|
|
450
|
+
const num = (v) => Number(v) || 0;
|
|
451
|
+
// 净生成时长 = 耗时 − 首 token 时机。两种情形按全程(耗时)算生成时长:
|
|
452
|
+
// 1. 非流式/整段返回:首 token 时机贴着结束(实测只差 20-30ms),扣出来是
|
|
453
|
+
// 毫秒级会把速率顶到几万 tok/s(首 token 占耗时 8 成以上即判定);
|
|
454
|
+
// 2. 首 token 时机缺失(部分供应商不回传,如 glm-5.3 占近三成):排除掉会
|
|
455
|
+
// 让整段速率消失。只有耗时也没有时留 null
|
|
456
|
+
const genMsOf = (dur, ttft) => (dur > 0 ? (ttft > 0 && ttft < dur * 0.8 ? dur - ttft : dur) : null);
|
|
457
|
+
const rounds = rows.map((r, i) => {
|
|
458
|
+
const inp = num(r.input_tokens);
|
|
459
|
+
const cacheRead = num(r.cache_read_input_tokens);
|
|
460
|
+
const ttft = num(r.time_to_first_token_ms);
|
|
461
|
+
const dur = num(r.duration_ms);
|
|
462
|
+
const genMs = genMsOf(dur, ttft);
|
|
463
|
+
const out = num(r.output_tokens);
|
|
464
|
+
return {
|
|
465
|
+
idx: i + 1,
|
|
466
|
+
at: num(r.completed_at),
|
|
467
|
+
in: inp,
|
|
468
|
+
out,
|
|
469
|
+
total: num(r.computed_total_tokens),
|
|
470
|
+
reasoning: num(r.reasoning_tokens),
|
|
471
|
+
cacheRead,
|
|
472
|
+
cacheWrite: num(r.cache_creation_input_tokens),
|
|
473
|
+
hitRate: inp > 0 ? cacheRead / inp : null,
|
|
474
|
+
genMs,
|
|
475
|
+
tps: genMs ? out / (genMs / 1000) : null,
|
|
476
|
+
};
|
|
477
|
+
});
|
|
478
|
+
const summary = { requests: rounds.length, totalIn: 0, totalOut: 0, totalCacheRead: 0, hitRate: null };
|
|
479
|
+
for (const r of rounds) {
|
|
480
|
+
summary.totalIn += r.in;
|
|
481
|
+
summary.totalOut += r.out;
|
|
482
|
+
summary.totalCacheRead += r.cacheRead;
|
|
483
|
+
}
|
|
484
|
+
summary.hitRate = summary.totalIn > 0 ? summary.totalCacheRead / summary.totalIn : null;
|
|
485
|
+
// 会话树最近请求的净生成速率:单独一条查询(trace 索引),取最近 30 笔里落在
|
|
486
|
+
// “最近完成时刻前 60 秒”的请求,Σ输出 ÷ Σ净生成秒数;没有可用行留 null
|
|
487
|
+
summary.tps = null;
|
|
488
|
+
try {
|
|
489
|
+
const tSql = `SELECT output_tokens, duration_ms, time_to_first_token_ms, completed_at FROM model_usage`
|
|
490
|
+
+ ` WHERE (session_id = ${esc(sid)}${treeTrace ? ` OR trace_id = ${esc(treeTrace)}` : ''})`
|
|
491
|
+
+ ` AND query_source = 'main_turn' AND status = 'completed' AND completed_at IS NOT NULL`
|
|
492
|
+
+ ` ORDER BY completed_at DESC LIMIT 30`;
|
|
493
|
+
let tRows;
|
|
494
|
+
if (driver.kind === 'node') {
|
|
495
|
+
const db = new driver.DatabaseSync(dbFile, { readOnly: true });
|
|
496
|
+
try { tRows = db.prepare(tSql).all(); } finally { db.close(); }
|
|
497
|
+
} else {
|
|
498
|
+
const agg = runCli(dbFile,
|
|
499
|
+
`SELECT coalesce(json_group_array(json_object('output_tokens', output_tokens, 'duration_ms', duration_ms,`
|
|
500
|
+
+ ` 'time_to_first_token_ms', time_to_first_token_ms, 'completed_at', completed_at)), '[]') FROM (${tSql});`);
|
|
501
|
+
tRows = JSON.parse(agg.stdout.trim() || '[]');
|
|
502
|
+
}
|
|
503
|
+
if (tRows.length) {
|
|
504
|
+
const anchorT = num(tRows[0].completed_at);
|
|
505
|
+
let outSum = 0;
|
|
506
|
+
let genSum = 0;
|
|
507
|
+
for (const r of tRows) {
|
|
508
|
+
if (num(r.completed_at) < anchorT - 60_000) break;
|
|
509
|
+
const genMs = genMsOf(num(r.duration_ms), num(r.time_to_first_token_ms));
|
|
510
|
+
if (genMs) { outSum += num(r.output_tokens); genSum += genMs; }
|
|
511
|
+
}
|
|
512
|
+
if (genSum > 0) summary.tps = outSum / (genSum / 1000);
|
|
513
|
+
}
|
|
514
|
+
} catch { /* 速率取不到留 null,其它汇总不受影响 */ }
|
|
515
|
+
return { rounds, summary };
|
|
516
|
+
} catch {
|
|
517
|
+
return empty; // 读取失败按无数据处理(每轮标注与状态栏项自然隐藏)
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// 项目里"真未读"的任务数(未读但排除错误态):项目行蓝色未读徽标的判据——
|
|
522
|
+
// 错误态任务行显示的是红色错误点(应用图标优先级 错误>未读),它的未读不该再
|
|
523
|
+
// 把项目徽标点亮成蓝色(subagent-icon.js)
|
|
524
|
+
export async function listProjectsUnread(dataRoot, projectIds) {
|
|
525
|
+
const out = {};
|
|
526
|
+
const wanted = [...new Set((projectIds || []).map(String).filter(Boolean))];
|
|
527
|
+
if (!wanted.length) return out;
|
|
528
|
+
const dbFile = taskIndexPath(dataRoot);
|
|
529
|
+
if (!existsSync(dbFile)) return out;
|
|
530
|
+
const driver = await loadDriver();
|
|
531
|
+
if (!driver) return out;
|
|
532
|
+
const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
|
|
533
|
+
const inList = wanted.map((id) => esc(id)).join(', ');
|
|
534
|
+
const sql = `SELECT project_id, sum(CASE WHEN task_status = 'error' THEN 0 ELSE 1 END) AS n
|
|
535
|
+
FROM tasks WHERE project_id IN (${inList}) AND unread_at IS NOT NULL
|
|
536
|
+
AND deleted = 0 AND coalesce(cli_deleted, 0) = 0
|
|
537
|
+
GROUP BY project_id`;
|
|
538
|
+
try {
|
|
539
|
+
let rows;
|
|
540
|
+
if (driver.kind === 'node') {
|
|
541
|
+
const db = new driver.DatabaseSync(dbFile, { readOnly: true });
|
|
542
|
+
try { rows = db.prepare(sql).all(); } finally { db.close(); }
|
|
543
|
+
} else {
|
|
544
|
+
const agg = runCli(dbFile,
|
|
545
|
+
`SELECT coalesce(json_group_array(json_object('project_id', project_id, 'n', n)), '[]') FROM (${sql});`);
|
|
546
|
+
rows = JSON.parse(agg.stdout.trim() || '[]');
|
|
547
|
+
}
|
|
548
|
+
for (const r of rows) out[String(r.project_id)] = Number(r.n) || 0;
|
|
549
|
+
return out;
|
|
550
|
+
} catch {
|
|
551
|
+
return null; // 读取失败返回 null,调用方不干预徽标
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// 某工作区的任务会话 id(最近更新在前,7 天内有动静的取 30 个):折叠项目行扫
|
|
556
|
+
// 子代理运行状态的候选清单——行折叠后会话 id 不在 DOM 里,只能从任务索引反查。
|
|
557
|
+
// 7 天窗:长跑子代理的父会话最晚在派出子代理那一趟被写过,超过 7 天的会话里
|
|
558
|
+
// 还挂着子代理的实测都是僵死记录(shortcut: 超长后台子代理会漏,等用户反馈再放宽)
|
|
559
|
+
export async function listWorkspaceTaskIds(dataRoot, wsPath) {
|
|
560
|
+
const dbFile = taskIndexPath(dataRoot);
|
|
561
|
+
if (!existsSync(dbFile)) return [];
|
|
562
|
+
const driver = await loadDriver();
|
|
563
|
+
if (!driver) return [];
|
|
564
|
+
const esc = (v) => "'" + String(v).replace(/'/g, "''") + "'";
|
|
565
|
+
// 任务行的工作区路径可能带尾分隔符(实测两种都有),两侧都归一后比较
|
|
566
|
+
const target = esc(String(wsPath || '').replace(/[\\/]+$/, ''));
|
|
567
|
+
const where = `rtrim(rtrim(workspace_path, '/'), char(92)) = ${target}`;
|
|
568
|
+
const since = Date.now() - 7 * 86400_000;
|
|
569
|
+
const sql = `SELECT task_id FROM tasks WHERE ${where} AND deleted = 0 AND updated_at >= ${since} ORDER BY updated_at DESC LIMIT 30`;
|
|
570
|
+
try {
|
|
571
|
+
let rows;
|
|
572
|
+
if (driver.kind === 'node') {
|
|
573
|
+
const db = new driver.DatabaseSync(dbFile, { readOnly: true });
|
|
574
|
+
try { rows = db.prepare(sql).all(); } finally { db.close(); }
|
|
575
|
+
} else {
|
|
576
|
+
const agg = runCli(dbFile,
|
|
577
|
+
`SELECT coalesce(json_group_array(json_object('task_id', task_id)), '[]') FROM (${sql});`);
|
|
578
|
+
rows = JSON.parse(agg.stdout.trim() || '[]');
|
|
579
|
+
}
|
|
580
|
+
return rows.map((r) => String(r.task_id)).filter(Boolean);
|
|
581
|
+
} catch {
|
|
582
|
+
return [];
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
320
586
|
// 状态栏统计用:任务总数(未删除的会话行)
|
|
321
587
|
export async function countTasks(dataRoot) {
|
|
322
588
|
const dbFile = taskIndexPath(dataRoot);
|
package/src/inject/core.js
CHANGED
|
@@ -67,22 +67,25 @@ export const DEFAULT_SHORTCUTS = {
|
|
|
67
67
|
|
|
68
68
|
// 状态栏任务统计项的两个组:会话级跟随当前会话,全局级始终显示;
|
|
69
69
|
// 设置里两节各自排序,保存时归一化为会话组在前(状态栏两组间一道竖线)
|
|
70
|
-
export const STATUS_SESSION_IDS = new Set(['ctx', 'questions', 'tokRate']);
|
|
70
|
+
export const STATUS_SESSION_IDS = new Set(['ctx', 'questions', 'tokRate', 'inOut', 'avgHit']);
|
|
71
71
|
export const STATUS_GLOBAL_IDS = new Set(['todayTokens', 'totalTokens', 'tasks']);
|
|
72
72
|
|
|
73
73
|
// 状态栏统计项的默认清单(顺序即默认显示顺序);设置 → 外观 → 状态栏里
|
|
74
74
|
// 可调顺序与显隐,配置存在 config.statusBar.items(整表覆盖)
|
|
75
|
-
// 每轮回答统计项(turn-usage.js
|
|
75
|
+
// 每轮回答统计项(turn-usage.js):回答末尾标注的四段,各自可显隐(顺序固定)
|
|
76
76
|
export const DEFAULT_TURN_ITEMS = [
|
|
77
77
|
{ id: 'turnIn', on: true }, // 输入
|
|
78
78
|
{ id: 'turnOut', on: true }, // 输出
|
|
79
|
+
{ id: 'turnTps', on: true }, // TPS(输出 ÷ 净生成秒数,官方口径)
|
|
79
80
|
{ id: 'turnCache', on: true }, // 缓存命中率
|
|
80
81
|
];
|
|
81
82
|
|
|
82
83
|
export const DEFAULT_STATUS_ITEMS = [
|
|
83
84
|
{ id: 'tokRate', on: true }, // 最近输出 tokens/s(60 秒窗口,本会话)
|
|
85
|
+
{ id: 'avgHit', on: true }, // 平均缓存命中率(本会话)
|
|
86
|
+
{ id: 'inOut', on: true }, // 累计输入/输出(本会话主轮请求)
|
|
84
87
|
{ id: 'ctx', on: true }, // 上下文占用
|
|
85
|
-
{ id: 'questions', on: true }, //
|
|
88
|
+
{ id: 'questions', on: true }, // 主请求数(官方 model_usage 口径)
|
|
86
89
|
{ id: 'todayTokens', on: true }, // 今日 token(今天的会话记录完整,数据准确)
|
|
87
90
|
{ id: 'totalTokens', on: true }, // 累计 token(官方使用统计,全历史)
|
|
88
91
|
{ id: 'tasks', on: true }, // 任务总数
|
|
@@ -174,7 +177,7 @@ const zh = {
|
|
|
174
177
|
proxyPlaceholder: 'http://127.0.0.1:7890',
|
|
175
178
|
proxySave: '保存',
|
|
176
179
|
proxySaved: '代理设置已保存',
|
|
177
|
-
proxyHint: '
|
|
180
|
+
proxyHint: '留空保存即清除手填代理:Windows 跟随系统代理,其他平台直连。',
|
|
178
181
|
proxyTest: '检测',
|
|
179
182
|
proxyTesting: '检测中…',
|
|
180
183
|
proxyTestEmpty: '请先输入代理地址',
|
|
@@ -246,6 +249,8 @@ const zh = {
|
|
|
246
249
|
devReload: '重载 ZCode Pro',
|
|
247
250
|
devReloading: '重载中…',
|
|
248
251
|
devReloadDesc: '点击后约 2-3 秒内所有 ZCode 窗口自动刷新一次并加载新脚本。',
|
|
252
|
+
devToolsSwitch: '开发者工具',
|
|
253
|
+
devToolsSwitchDesc: '官方侧栏的“开发者工具”面板(Token 调试 / 网络状态),默认关闭。改动写入官方每秒轮询的开关,1 秒内生效。',
|
|
249
254
|
rowGapName: '段落间距',
|
|
250
255
|
rowGapDesc: '会话中段落等文本块之间的垂直间距(回合之间、答案内部)。',
|
|
251
256
|
listSpacingName: '列表上下边距',
|
|
@@ -315,6 +320,10 @@ const zh = {
|
|
|
315
320
|
autoRenameDone: '已重命名:',
|
|
316
321
|
featureWsRunning: '折叠时任务运行中提示',
|
|
317
322
|
featureWsRunningDesc: '有会话运行时,折叠的项目与任务分区头显示加载图标,全部结束消失。',
|
|
323
|
+
featureSubagentIcon: '子代理运行中提示',
|
|
324
|
+
featureSubagentIconDesc: '后台子代理在跑显机器人、后台终端命令在跑显终端图标(同时在跑机器人优先);未读圆点让位到行尾常显;会话运行中始终显示转圈图标;项目未读徽标忽略错误行。',
|
|
325
|
+
subagentRobotTip: '子代理运行中',
|
|
326
|
+
subagentTermTip: '后台命令运行中',
|
|
318
327
|
tabPerformance: '性能',
|
|
319
328
|
perfDesc: 'ZCode 为每个打开过的项目常驻一个会话进程,应用自身不会回收,项目多了内存占用就高。开启后,长时间未使用且没有任务在跑的项目会被自动释放:会话记录不受影响,再次打开时自动恢复,仅首次回复有几秒等待。正在使用的项目、运行中的会话与后台命令、定时任务都不会被回收。后台命令检测依赖系统进程信息(Linux / macOS / Windows 各走系统自带工具),检测不可用时功能自动停用。',
|
|
320
329
|
featureIdleReclaim: '空闲项目内存回收',
|
|
@@ -366,7 +375,7 @@ const zh = {
|
|
|
366
375
|
tabStatusPane: '状态栏',
|
|
367
376
|
themeColorsPane: '主题',
|
|
368
377
|
themeBgRegions: '分区背景',
|
|
369
|
-
themeBgRegionFollow: '
|
|
378
|
+
themeBgRegionFollow: '默认(全局壁纸)',
|
|
370
379
|
themeBgRegionLeft: '左侧边栏',
|
|
371
380
|
themeBgRegionCenter: '中间区域',
|
|
372
381
|
themeBgRegionRight: '右侧边栏',
|
|
@@ -419,7 +428,7 @@ const zh = {
|
|
|
419
428
|
themeBgDialogFrost: '设置弹窗磨砂',
|
|
420
429
|
themeBgMisc: '其他',
|
|
421
430
|
themeBgFollowGlobal: '跟随全局',
|
|
422
|
-
themeBgRegionsHint: '
|
|
431
|
+
themeBgRegionsHint: '来源选“默认(全局壁纸)”即该区不单独设置、直接显示全局壁纸;每行的缩放、遮罩可单独设置,选“跟随全局”即跟随“画面”的值;模糊、转场、播放仅作用于全局壁纸(分区只能铺图,不能播视频)。分区用文件夹时,轮换间隔与随机顺序沿用全局设置。',
|
|
423
432
|
themeBgPlayback: '播放(视频壁纸)',
|
|
424
433
|
themeBgVolume: '音量',
|
|
425
434
|
themeBgVolumeHint: '视频壁纸的音轨音量,0 = 静音(默认)',
|
|
@@ -439,7 +448,9 @@ const zh = {
|
|
|
439
448
|
tableCopied: '表格已复制',
|
|
440
449
|
sbItemCtx: '上下文占用',
|
|
441
450
|
sbItemTokRate: '最近输出 tokens/s',
|
|
442
|
-
sbItemQuestions: '
|
|
451
|
+
sbItemQuestions: '主请求数(本会话)',
|
|
452
|
+
sbItemInOut: '累计输入/输出(本会话主轮请求)',
|
|
453
|
+
sbItemHit: '平均缓存命中率(本会话)',
|
|
443
454
|
sbMaster: '启用统计',
|
|
444
455
|
sbMasterDesc: '总开关:关闭后输入框右下角的统计行与每轮回答的用量标注一起停用。',
|
|
445
456
|
sbGroupSession: '会话统计(跟随当前会话)',
|
|
@@ -448,8 +459,11 @@ const zh = {
|
|
|
448
459
|
sbLabelIn: '输入',
|
|
449
460
|
sbLabelOut: '输出',
|
|
450
461
|
sbLabelCache: '缓存',
|
|
462
|
+
sbLabelTps: '输出 tok/s',
|
|
463
|
+
sbLabelInOut: '输入/输出',
|
|
464
|
+
sbLabelHit: '平均命中',
|
|
451
465
|
turnUsageTitle: '本轮 token',
|
|
452
|
-
sbLabelQuestions: '
|
|
466
|
+
sbLabelQuestions: '主请求数',
|
|
453
467
|
sbItemTodayTokens: '今日 token',
|
|
454
468
|
sbItemTasks: '任务总数',
|
|
455
469
|
sbLabelCtx: '上下文',
|
|
@@ -638,6 +652,10 @@ const zh = {
|
|
|
638
652
|
headroomInterval: '监视间隔',
|
|
639
653
|
headroomIntervalDesc: '省电监视器轮询电源状态的间隔(10–3600 秒,默认 60);保存后从下一轮巡检起生效。',
|
|
640
654
|
headroomSecUnit: '秒',
|
|
655
|
+
serenaSwitch: 'Serena 语义检索',
|
|
656
|
+
serenaSwitchDesc: '注册 Serena MCP:用符号定位、引用查找等语义工具代替整文件读取,省 token。写入 ZCode MCP 配置,重启会话后生效。',
|
|
657
|
+
serenaEnabled: '已开启 Serena,重启会话后生效',
|
|
658
|
+
serenaDisabled: '已关闭 Serena,重启会话后移除',
|
|
641
659
|
upgradeCheck: '检查更新',
|
|
642
660
|
upgradeChecking: '检查中…',
|
|
643
661
|
upgradeUpToDate: '已是最新({v})',
|
|
@@ -761,7 +779,7 @@ const en = {
|
|
|
761
779
|
proxyPlaceholder: 'http://127.0.0.1:7890',
|
|
762
780
|
proxySave: 'Save',
|
|
763
781
|
proxySaved: 'Proxy settings saved.',
|
|
764
|
-
proxyHint: 'Save empty to clear the proxy.',
|
|
782
|
+
proxyHint: 'Save empty to clear the manual proxy; Windows then follows the system proxy, other platforms connect directly.',
|
|
765
783
|
proxyTest: 'Test',
|
|
766
784
|
proxyTesting: 'Testing…',
|
|
767
785
|
proxyTestEmpty: 'Enter a proxy address first',
|
|
@@ -831,6 +849,8 @@ const en = {
|
|
|
831
849
|
syncVerSaved: 'Saved to',
|
|
832
850
|
devModeDesc: 'For development: after changing zcode-pro code, click "Reload ZCode Pro" instead of restarting ZCode. It builds automatically (when running from the source repo), restarts the ZCode Pro launcher process (fresh helper and injected script), and every ZCode window refreshes and re-injects. The ZCode app itself and all sessions stay untouched.',
|
|
833
851
|
devReload: 'Reload ZCode Pro',
|
|
852
|
+
devToolsSwitch: 'Developer tools',
|
|
853
|
+
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.',
|
|
834
854
|
devReloading: 'Reloading…',
|
|
835
855
|
devReloadDesc: 'Every ZCode window refreshes automatically within 2-3 seconds to load the new script.',
|
|
836
856
|
rowGapName: 'Paragraph spacing',
|
|
@@ -901,6 +921,10 @@ const en = {
|
|
|
901
921
|
autoRenameDone: 'Renamed: ',
|
|
902
922
|
featureWsRunning: 'Running indicator when collapsed',
|
|
903
923
|
featureWsRunningDesc: 'Collapsed project and task headers show a loader while sessions run.',
|
|
924
|
+
featureSubagentIcon: 'Subagent running indicator',
|
|
925
|
+
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.',
|
|
926
|
+
subagentRobotTip: 'Subagents running',
|
|
927
|
+
subagentTermTip: 'Background commands running',
|
|
904
928
|
tabPerformance: 'Performance',
|
|
905
929
|
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.',
|
|
906
930
|
featureIdleReclaim: 'Idle project memory reclaim',
|
|
@@ -952,7 +976,7 @@ const en = {
|
|
|
952
976
|
tabStatusPane: 'Status bar',
|
|
953
977
|
themeColorsPane: 'Theme',
|
|
954
978
|
themeBgRegions: 'Regional backgrounds',
|
|
955
|
-
themeBgRegionFollow: '
|
|
979
|
+
themeBgRegionFollow: 'Default (global)',
|
|
956
980
|
themeBgRegionLeft: 'Left sidebar',
|
|
957
981
|
themeBgRegionCenter: 'Center area',
|
|
958
982
|
themeBgRegionRight: 'Right sidebar',
|
|
@@ -1005,7 +1029,7 @@ const en = {
|
|
|
1005
1029
|
themeBgDialogFrost: 'Frosted settings window',
|
|
1006
1030
|
themeBgMisc: 'Other',
|
|
1007
1031
|
themeBgFollowGlobal: 'Follow global',
|
|
1008
|
-
themeBgRegionsHint: 'Fit and mask can be set per row; "Follow global" uses the Display values. Blur, transition and playback apply only to the global wallpaper (regions are static images, no video). Region folders reuse the global rotation interval and order settings.',
|
|
1032
|
+
themeBgRegionsHint: '"Default (global)" means the region is not set on its own and just shows the global wallpaper. Fit and mask can be set per row; "Follow global" uses the Display values. Blur, transition and playback apply only to the global wallpaper (regions are static images, no video). Region folders reuse the global rotation interval and order settings.',
|
|
1009
1033
|
themeBgPlayback: 'Playback (video)',
|
|
1010
1034
|
themeBgVolume: 'Volume',
|
|
1011
1035
|
themeBgVolumeHint: 'Audio track volume of video wallpapers, 0 = muted (default)',
|
|
@@ -1025,7 +1049,9 @@ const en = {
|
|
|
1025
1049
|
tableCopied: 'Table copied',
|
|
1026
1050
|
sbItemCtx: 'Context usage',
|
|
1027
1051
|
sbItemTokRate: 'Recent output tokens/s',
|
|
1028
|
-
sbItemQuestions: '
|
|
1052
|
+
sbItemQuestions: 'Main requests (this session)',
|
|
1053
|
+
sbItemInOut: 'Total input/output (main requests, this session)',
|
|
1054
|
+
sbItemHit: 'Average cache hit rate (this session)',
|
|
1029
1055
|
sbMaster: 'Enable statistics',
|
|
1030
1056
|
sbMasterDesc: 'Master switch: turning this off disables both the input-box statistics and per-turn labels.',
|
|
1031
1057
|
sbGroupSession: 'Session statistics (follows the current session)',
|
|
@@ -1034,8 +1060,11 @@ const en = {
|
|
|
1034
1060
|
sbLabelIn: 'in',
|
|
1035
1061
|
sbLabelOut: 'out',
|
|
1036
1062
|
sbLabelCache: 'cache',
|
|
1063
|
+
sbLabelTps: 'out tok/s',
|
|
1064
|
+
sbLabelInOut: 'in/out',
|
|
1065
|
+
sbLabelHit: 'avg hit',
|
|
1037
1066
|
turnUsageTitle: 'Turn tokens',
|
|
1038
|
-
sbLabelQuestions: '
|
|
1067
|
+
sbLabelQuestions: 'reqs',
|
|
1039
1068
|
sbItemTodayTokens: 'Tokens today',
|
|
1040
1069
|
sbItemTasks: 'Tasks',
|
|
1041
1070
|
sbLabelCtx: 'ctx',
|
|
@@ -1224,6 +1253,10 @@ const en = {
|
|
|
1224
1253
|
headroomInterval: 'Watch interval',
|
|
1225
1254
|
headroomIntervalDesc: 'Seconds between power checks (10–3600, default 60); applies from the next round.',
|
|
1226
1255
|
headroomSecUnit: 's',
|
|
1256
|
+
serenaSwitch: 'Serena semantic search',
|
|
1257
|
+
serenaSwitchDesc: 'Registers the Serena MCP: symbol lookup and reference search instead of reading whole files, saving tokens. Written to the ZCode MCP config; takes effect after restarting the session.',
|
|
1258
|
+
serenaEnabled: 'Serena enabled; takes effect after restarting the session',
|
|
1259
|
+
serenaDisabled: 'Serena disabled; removed after restarting the session',
|
|
1227
1260
|
upgradeCheck: 'Check for updates',
|
|
1228
1261
|
upgradeChecking: 'Checking…',
|
|
1229
1262
|
upgradeUpToDate: 'Up to date ({v})',
|
|
@@ -1374,9 +1407,12 @@ const errEn = {
|
|
|
1374
1407
|
'headroom-action': 'The headroom action failed',
|
|
1375
1408
|
'headroom-status': 'Failed to read the headroom status',
|
|
1376
1409
|
'headroom-update': 'headroom update failed',
|
|
1410
|
+
'serena-config-unreadable': 'ZCode config is unparseable; aborted writing',
|
|
1377
1411
|
'ZCODE_NOT_FOUND': 'ZCode executable not found',
|
|
1378
1412
|
'plugins-status': 'Failed to read the plugin list',
|
|
1379
1413
|
'plugins-update': 'Failed to update plugins',
|
|
1414
|
+
'plugins-market-git': 'Git is missing and GitHub is unreachable. Install Git or set a proxy in ZCode Pro → Proxy, then retry.',
|
|
1415
|
+
'plugins-market-network': 'Cannot reach GitHub. If your network needs a proxy, set it in ZCode Pro → Proxy, then retry.',
|
|
1380
1416
|
'sync-invalid': 'Invalid sync settings',
|
|
1381
1417
|
'sync-not-configured': 'Set the sync type to WebDAV and save the config first',
|
|
1382
1418
|
'sync-remote-missing': 'No synced data on the server yet; upload from another computer first',
|
|
@@ -5,6 +5,62 @@ import { rpc, getConfig, t } from '../core.js';
|
|
|
5
5
|
import { showToast } from '../ui.js';
|
|
6
6
|
|
|
7
7
|
const NOTIFIED_KEY = 'zcodepro-plugin-updates-notified';
|
|
8
|
+
const AUTO_UPDATE_LAUNCH_KEY = 'zcodepro-plugin-autoupdate-launch';
|
|
9
|
+
const AUTO_UPDATE_SESSION_KEY = 'zcodepro-plugin-autoupdate-session-claim';
|
|
10
|
+
|
|
11
|
+
// 当前 ZCode 启动批次的标记:页面 URL 的 zcodeLaunchMarks 带本次启动时间戳,
|
|
12
|
+
// 页面刷新不变、关掉重开变新值。取不到时退回 sessionStorage(刷新还在,
|
|
13
|
+
// 应用重启后失效),两条路都取不到时用本模块内存标记兜底。
|
|
14
|
+
function autoUpdateLaunchMark() {
|
|
15
|
+
try {
|
|
16
|
+
const raw = new URLSearchParams(location.search).get('zcodeLaunchMarks');
|
|
17
|
+
if (raw) {
|
|
18
|
+
const createdAt = JSON.parse(raw)?.createdAt;
|
|
19
|
+
if (createdAt != null) return `launch:${createdAt}`;
|
|
20
|
+
}
|
|
21
|
+
} catch { /* ignore */ }
|
|
22
|
+
try {
|
|
23
|
+
let id = sessionStorage.getItem('zcodepro-plugin-autoupdate-session');
|
|
24
|
+
if (!id) {
|
|
25
|
+
id = `session:${Date.now()}:${Math.random().toString(36).slice(2)}`;
|
|
26
|
+
sessionStorage.setItem('zcodepro-plugin-autoupdate-session', id);
|
|
27
|
+
}
|
|
28
|
+
return id;
|
|
29
|
+
} catch { return `memory:${Date.now()}:${Math.random().toString(36).slice(2)}`; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let memoryClaimed = false;
|
|
33
|
+
|
|
34
|
+
// 注入脚本通常在页面文档开始时执行,URL 上的启动标记还在;若 Pro 后接入已加载
|
|
35
|
+
// 页面、URL 已被应用改写,退回 sessionStorage(即按窗口计)。只读一次并缓存,
|
|
36
|
+
// 应用内路由后面再改 URL 也不影响同一批次的判断。
|
|
37
|
+
const LAUNCH_MARK = autoUpdateLaunchMark();
|
|
38
|
+
|
|
39
|
+
// 在一个存储里领取:返回 true/false,存储不可用返回 null。localStorage 写失败
|
|
40
|
+
// (配额/权限)时不直接掉到内存标记,先试 sessionStorage,页面刷新后仍能记住。
|
|
41
|
+
function claimIn(storage, key, mark) {
|
|
42
|
+
try {
|
|
43
|
+
if (storage.getItem(key) === mark) return false;
|
|
44
|
+
storage.setItem(key, mark);
|
|
45
|
+
return true;
|
|
46
|
+
} catch { return null; }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 领取本次启动的自动更新机会:同一启动批次只有第一次返回 true。
|
|
50
|
+
// 只在真要执行更新前调用——只检查没更新不占名额;更新一旦发起,本次启动不再
|
|
51
|
+
// 自动重试,失败请手动点“检查更新”或重启 ZCode。
|
|
52
|
+
export function claimAutoUpdateRun() {
|
|
53
|
+
const mark = LAUNCH_MARK;
|
|
54
|
+
const local = typeof localStorage === 'undefined' ? null : localStorage;
|
|
55
|
+
const viaLocal = local ? claimIn(local, AUTO_UPDATE_LAUNCH_KEY, mark) : null;
|
|
56
|
+
if (viaLocal !== null) return viaLocal;
|
|
57
|
+
const session = typeof sessionStorage === 'undefined' ? null : sessionStorage;
|
|
58
|
+
const viaSession = session ? claimIn(session, AUTO_UPDATE_SESSION_KEY, mark) : null;
|
|
59
|
+
if (viaSession !== null) return viaSession;
|
|
60
|
+
if (memoryClaimed) return false;
|
|
61
|
+
memoryClaimed = true;
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
8
64
|
|
|
9
65
|
export async function startPluginUpdateCheck() {
|
|
10
66
|
const status = await rpc('/plugins/status');
|
|
@@ -14,6 +70,8 @@ export async function startPluginUpdateCheck() {
|
|
|
14
70
|
|
|
15
71
|
const config = await getConfig();
|
|
16
72
|
if ((config.features || {}).autoUpdatePlugins === true) {
|
|
73
|
+
// 每次 ZCode 启动只自动更新一次:启动检查没更新过、设置弹窗先到,谁先谁占名额
|
|
74
|
+
if (!claimAutoUpdateRun()) return;
|
|
17
75
|
const res = await rpc('/plugins/update', { method: 'POST', body: {} });
|
|
18
76
|
if (res.ok) showToast(L.pluginsAutoUpdated, 'success');
|
|
19
77
|
else showToast(L.pluginsUpdateFailed + ': ' + (res.error || ''), 'error');
|
|
@@ -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
|
-
|
|
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
|
|
450
|
-
//
|
|
451
|
-
//
|
|
449
|
+
// e 打开最近 10 条(c 可继续加载更早的)。attention 弹窗(r)开着时切到
|
|
450
|
+
// 最近列表(关掉重开,与 r 在 mru 弹窗开着时的行为对称);mru 已开着则
|
|
451
|
+
// 不动作。只在 mru 为空(连当前会话都没有,如停在新建任务页)才提示——
|
|
452
|
+
// 首次仅开着当前会话时照常打开,列表里就是它这一条
|
|
452
453
|
if (k === hotkeys.switchRecent) {
|
|
453
|
-
if (
|
|
454
|
-
|
|
455
|
-
|
|
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 的
|