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.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/inject.js +3377 -130
- package/package.json +2 -2
- package/src/host/helper.mjs +423 -28
- package/src/host/taskIndex.mjs +25 -2
- package/src/inject/core.js +149 -21
- package/src/inject/features/auto-continue.js +574 -0
- package/src/inject/features/auto-rename.js +3 -3
- package/src/inject/features/newtab-panels.js +10 -4
- package/src/inject/features/session-switch.js +170 -11
- package/src/inject/features/settings-dialog.js +117 -33
- package/src/inject/features/status-bar.js +25 -20
- package/src/inject/features/subagent-icon.js +3 -1
- package/src/inject/features/title-gen.js +3 -3
- package/src/inject/features/title-lock.js +2 -2
- package/src/inject/features/turn-usage.js +49 -15
- package/src/inject/index.js +2 -0
- package/src/inject/locales/ja.js +770 -0
- package/src/inject/locales/ko.js +770 -0
- package/src/inject/locales/ru.js +770 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// 全局项(今日 / 累计 token、任务总数)优先取官方使用统计(云端,5 分钟刷新),
|
|
4
4
|
// 回退本地聚合。数据 2 秒刷新一次;上下文占用读官方输入框工具栏的窗口显示
|
|
5
5
|
//(“已用 497,101 / 总量 1,000,000”),按官方同款格式渲染。
|
|
6
|
-
import { t, rpc, getConfig, isZhLocale, DEFAULT_STATUS_ITEMS } from '../core.js';
|
|
6
|
+
import { t, rpc, getConfig, isZhLocale, isCjkLocale, DEFAULT_STATUS_ITEMS } from '../core.js';
|
|
7
7
|
import { ensureStyle } from '../ui.js';
|
|
8
8
|
|
|
9
9
|
let enabled = true;
|
|
@@ -67,21 +67,27 @@ function selectedSessionId() {
|
|
|
67
67
|
|
|
68
68
|
// 官方输入框工具栏的上下文显示:title 形如“上下文已用 61,400 / 总量 1,000,000”,
|
|
69
69
|
// 解析出已用与总量;读不到返回 null(ctx 项回退按会话记录估算 token 数)。
|
|
70
|
+
// 各语言模板不同:en“Context usage 61,400 of 1,000,000”、ja“コンテキスト使用量
|
|
71
|
+
// 61,400 / 1,000,000”、ko 总量在前“컨텍스트 사용량 1,000,000 중 61,400”、
|
|
72
|
+
// ru“Использование контекста: 61,400 из 1,000,000”。模板只有两个数,按大小
|
|
73
|
+
// 取小的为已用,兼容韩语的倒序。
|
|
74
|
+
function parseCtxTitle(text) {
|
|
75
|
+
if (!/上下文|context|コンテキスト|컨텍스트|контекст/i.test(text)) return null;
|
|
76
|
+
// 数字分隔符跟随 Intl.NumberFormat:en/zh/ja 用逗号,ru/ko 用空格(含 NBSP)
|
|
77
|
+
const nums = [...String(text).matchAll(/\d[\d,\s\u00A0\u202F\u2009']*/g)]
|
|
78
|
+
.map((m) => Number(m[0].replace(/[^\d]/g, '')));
|
|
79
|
+
if (nums.length < 2) return null;
|
|
80
|
+
const used = Math.min(nums[0], nums[1]);
|
|
81
|
+
const size = Math.max(nums[0], nums[1]);
|
|
82
|
+
return used > 0 && size >= used ? { used, size } : null;
|
|
83
|
+
}
|
|
84
|
+
|
|
70
85
|
// 直接在全文档找(该显示全局唯一),排除自己渲染的 title。
|
|
71
86
|
// 命中过的元素记下来:每轮全文档扫 [title] 太贵,元素还在就直接读它
|
|
72
87
|
let ctxEl = null;
|
|
73
88
|
let ctxMissAt = 0; // 全档扫落空后的时刻:30 秒内不再扫(每 2 秒一轮照扫太贵)
|
|
74
89
|
function readCtx() {
|
|
75
|
-
const parse = (el) =>
|
|
76
|
-
const text = el.getAttribute('title') || el.getAttribute('aria-label') || '';
|
|
77
|
-
if (!/上下文|context/i.test(text)) return null;
|
|
78
|
-
// 格式为“已用 497,101 / 总量 1,000,000”:斜杠后可能带“总量”等文字再接数字
|
|
79
|
-
const m = text.match(/([\d][\d,]*)\s*\/[^0-9]*([\d][\d,]*)/);
|
|
80
|
-
if (!m) return null;
|
|
81
|
-
const used = Number(m[1].replace(/,/g, ''));
|
|
82
|
-
const size = Number(m[2].replace(/,/g, ''));
|
|
83
|
-
return used > 0 && size > used ? { used, size } : null;
|
|
84
|
-
};
|
|
90
|
+
const parse = (el) => parseCtxTitle(el.getAttribute('title') || el.getAttribute('aria-label') || '');
|
|
85
91
|
if (ctxEl && ctxEl.isConnected) {
|
|
86
92
|
const hit = parse(ctxEl);
|
|
87
93
|
if (hit) return hit;
|
|
@@ -235,16 +241,15 @@ function itemContent(id, L) {
|
|
|
235
241
|
const useEst = streaming && est != null;
|
|
236
242
|
const shown = useEst ? est : (tps != null ? tps : est);
|
|
237
243
|
if (shown == null) return null;
|
|
238
|
-
const zh = isZhLocale();
|
|
239
244
|
const estMark = useEst || tps == null ? '≈' : '';
|
|
240
245
|
const detail = useEst
|
|
241
|
-
?
|
|
246
|
+
? L.sbTokRateStreaming
|
|
242
247
|
: tps != null
|
|
243
|
-
? `${L.sbLabelOut} ${tps.toLocaleString()} tok/s${
|
|
244
|
-
:
|
|
248
|
+
? `${L.sbLabelOut} ${tps.toLocaleString()} tok/s${L.sbTokRateNet}`
|
|
249
|
+
: L.sbTokRateNoData;
|
|
245
250
|
return {
|
|
246
251
|
html: sbIcon('tokRate') + label(L.sbLabelOut) + `<b>${estMark}${fmtNum(Math.round(shown * 10) / 10)} tok/s</b>`,
|
|
247
|
-
title: `${L.sbItemTokRate}${
|
|
252
|
+
title: `${L.sbItemTokRate}${L.sbTokRateSessionSuffix}${detail}`,
|
|
248
253
|
tone: '',
|
|
249
254
|
};
|
|
250
255
|
}
|
|
@@ -254,8 +259,8 @@ function itemContent(id, L) {
|
|
|
254
259
|
const pct = Math.round((dom.used / dom.size) * 1000) / 10;
|
|
255
260
|
const tone = pct >= 95 ? 'danger' : pct >= 80 ? 'warn' : '';
|
|
256
261
|
return {
|
|
257
|
-
html: sbIcon('ctx') + label(L.sbLabelCtx) + `<b>${fmtNum(dom.used)}/${fmtNum(dom.size)}${
|
|
258
|
-
title: `${L.sbItemCtx}${
|
|
262
|
+
html: sbIcon('ctx') + label(L.sbLabelCtx) + `<b>${fmtNum(dom.used)}/${fmtNum(dom.size)}${isCjkLocale() ? '(' : '('}${pct}%${isCjkLocale() ? ')' : ')'}</b>`,
|
|
263
|
+
title: `${L.sbItemCtx}${isCjkLocale() ? ':' : ': '}${dom.used.toLocaleString()} / ${dom.size.toLocaleString()}`,
|
|
259
264
|
tone,
|
|
260
265
|
};
|
|
261
266
|
}
|
|
@@ -270,14 +275,14 @@ function itemContent(id, L) {
|
|
|
270
275
|
const s = (lastStats && statsSid === selectedSessionId()) ? lastStats.sessionSummary : null;
|
|
271
276
|
return s && s.totalIn + s.totalOut > 0 ? {
|
|
272
277
|
html: sbIcon('inOut') + label(L.sbLabelInOut) + `${fmtNum(s.totalIn)}/${fmtNum(s.totalOut)}`,
|
|
273
|
-
title: `${L.sbItemInOut}${
|
|
278
|
+
title: `${L.sbItemInOut}${isCjkLocale() ? ':' : ': '}${s.totalIn.toLocaleString()} / ${s.totalOut.toLocaleString()}`,
|
|
274
279
|
} : null;
|
|
275
280
|
}
|
|
276
281
|
case 'avgHit': {
|
|
277
282
|
const s = (lastStats && statsSid === selectedSessionId()) ? lastStats.sessionSummary : null;
|
|
278
283
|
return s && s.hitRate != null ? {
|
|
279
284
|
html: sbIcon('hit') + label(L.sbLabelHit) + `${(s.hitRate * 100).toFixed(2)}%`,
|
|
280
|
-
title: `${L.sbItemHit}${
|
|
285
|
+
title: `${L.sbItemHit}${isCjkLocale() ? ':' : ': '}${(s.hitRate * 100).toFixed(2)}%`,
|
|
281
286
|
} : null;
|
|
282
287
|
}
|
|
283
288
|
case 'todayTokens': {
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
// 纯文件系统扫描)。不能用会话快照(getTaskSnapshot):出快照会把会话 resume
|
|
11
11
|
// 起来,逐会话轮询快照曾造成整夜 6600 次/小时 resume、会话内存暴涨。
|
|
12
12
|
// 信号:子代理子会话写入 CLI 会话库的活动时间(/subagent-children,含嵌套子代理,
|
|
13
|
-
// 由 host
|
|
13
|
+
// 由 host 查库;已失败/中断的子代理由 host 按 last_outcome 排除——中断时父回合被
|
|
14
|
+
// 打断、结束记录没有写入,只按活动时间会一直亮着)。不用应用 zcodeAgentService 的
|
|
15
|
+
// 运行列表判活——它两头都不可靠:
|
|
14
16
|
// 长跑子代理跑着跑着会被误记为失败/结束(实测 48 分钟、60 分钟的都中过招),
|
|
15
17
|
// 崩溃/中断残留的又永远挂"运行中"(实测残留数月)。子代理运行时消息不断写入
|
|
16
18
|
// 会话库,超过 60 分钟无动静视为僵死不亮(单个长工具调用可静默 20 分钟上下,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// 并刷新锁定表,新名即刻上屏;
|
|
14
14
|
// - 失败静默(一次生成失败不打扰用户),每个会话只尝试一次。
|
|
15
15
|
// 扫描事件驱动(任务行相关变动去抖 300ms)+ 低频兜底轮询,选法同 title-lock。
|
|
16
|
-
import { rpc, getConfig } from '../core.js';
|
|
16
|
+
import { rpc, getConfig, uiLocale, t } from '../core.js';
|
|
17
17
|
import { setRowTitle, refreshPinnedTitles } from './title-lock.js';
|
|
18
18
|
|
|
19
19
|
const CONV = '[class*="@md/conversation"]';
|
|
@@ -148,7 +148,7 @@ async function onNewTaskRow(key) {
|
|
|
148
148
|
if (currentKey() !== key) continue;
|
|
149
149
|
const a = assistantText();
|
|
150
150
|
if (a && a.length > 80) {
|
|
151
|
-
texts.push(
|
|
151
|
+
texts.push(t().titleGenAssistantSummary + a);
|
|
152
152
|
break;
|
|
153
153
|
}
|
|
154
154
|
}
|
|
@@ -157,7 +157,7 @@ async function onNewTaskRow(key) {
|
|
|
157
157
|
// 失败静默但重试(模型调用偶发失败不应让本次会话永远失去标题):5 秒一次
|
|
158
158
|
// 错开瞬时抖动;20 秒一次兜住“会话刚建的几秒内索引模型信息未写定”
|
|
159
159
|
//(实测新会话 8 秒时解析到的模型不存在,稍后即正常)
|
|
160
|
-
const callTitleGen = () => rpc('/title-gen/run', { method: 'POST', body: { sessId, text: texts.join('\n') } }).catch(() => null);
|
|
160
|
+
const callTitleGen = () => rpc('/title-gen/run', { method: 'POST', body: { sessId, text: texts.join('\n'), locale: uiLocale() } }).catch(() => null);
|
|
161
161
|
let res = await callTitleGen();
|
|
162
162
|
for (const delay of [5000, 20000]) {
|
|
163
163
|
if (res && res.ok) break;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// 点中重命名菜单项后把预填值换成锁定名兜住这个口子(见 prefillRenameDialog)。
|
|
18
18
|
// 扫描事件驱动(任务行相关变动去抖 150ms;characterData 必须订阅——React
|
|
19
19
|
// 改标题文本走 nodeValue,只产生 characterData 变动)+ 低频兜底轮询。
|
|
20
|
-
import { rpc } from '../core.js';
|
|
20
|
+
import { rpc, isRenameLabel } from '../core.js';
|
|
21
21
|
|
|
22
22
|
const TASK_SEL = '[data-task-item-key]';
|
|
23
23
|
const SCAN_DEBOUNCE_MS = 150; // 相关 DOM 变动后的去抖,合并连续变动
|
|
@@ -304,7 +304,7 @@ export function startTitleLock() {
|
|
|
304
304
|
document.addEventListener('click', (e) => {
|
|
305
305
|
if (!renameCtx || renameCtx.armed) return;
|
|
306
306
|
const item = e.target instanceof Element && e.target.closest('[role="menuitem"], [data-radix-collection-item]');
|
|
307
|
-
if (item &&
|
|
307
|
+
if (item && isRenameLabel(item.textContent || '')) {
|
|
308
308
|
renameCtx.armed = true;
|
|
309
309
|
renameCtx.at = Date.now();
|
|
310
310
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// 后面追加“竖线 + 输入/输出/TPS/缓存”标注(段顺序与显隐可在设置里调)。
|
|
3
3
|
// 数据来自官方 model_usage(Token 调试同源,含首 token 时机),按“本条提问到
|
|
4
4
|
// 下一条提问”的区间归属到回答行;只统计主轮请求,辅助小调用不计。
|
|
5
|
-
import { t, rpc, getConfig, isZhLocale } from '../core.js';
|
|
5
|
+
import { t, rpc, getConfig, isZhLocale, isCjkLocale, uiLocale } from '../core.js';
|
|
6
6
|
|
|
7
7
|
let enabled = true;
|
|
8
8
|
let rounds = []; // 官方主轮请求 [{idx, at, in, out, cacheRead, genMs, tps…}] 按完成时间升序
|
|
@@ -65,7 +65,8 @@ function findRows() {
|
|
|
65
65
|
if (!row || seen.has(row)) continue;
|
|
66
66
|
seen.add(row);
|
|
67
67
|
if (!row.querySelector('[data-testid^="v4-feedback-"]')) continue;
|
|
68
|
-
|
|
68
|
+
// 时间文本可能是“18:16”“5:41 PM”“오후 5:41”,不要求时间在末尾
|
|
69
|
+
const timeEl = [...row.querySelectorAll('span')].find((s) => /\d{1,2}:\d{2}/.test((s.textContent || '').trim()));
|
|
69
70
|
if (timeEl) { const ts = rowTimeTs((timeEl.textContent || '').trim()); if (ts != null) rows.push({ row, ts }); }
|
|
70
71
|
}
|
|
71
72
|
return rows;
|
|
@@ -130,7 +131,7 @@ function injectRow(row, bucket) {
|
|
|
130
131
|
el.style.gap = '4px'; // 组与 · 分隔之间的间距
|
|
131
132
|
el.style.marginLeft = '10px'; // 与左侧时间拉开
|
|
132
133
|
el.innerHTML = html;
|
|
133
|
-
el.title = `${L.turnUsageTitle}${
|
|
134
|
+
el.title = `${L.turnUsageTitle}${isCjkLocale() ? ':' : ': '}${L.sbLabelIn} ${bucket.in.toLocaleString()} / ${L.sbLabelOut} ${bucket.out.toLocaleString()}`
|
|
134
135
|
+ (tps != null ? ` / ${L.sbLabelOut} ${Math.round(tps * 10) / 10} tok/s` : '')
|
|
135
136
|
+ (bucket.cacheRead > 0 ? ` / ${L.sbLabelCache} ${bucket.cacheRead.toLocaleString()}` : '');
|
|
136
137
|
row.dataset.zcodeproTurn = '1';
|
|
@@ -138,23 +139,56 @@ function injectRow(row, bucket) {
|
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
// 回答行时间文本 → 当年本地时间的时间戳(毫秒)。
|
|
141
|
-
//
|
|
142
|
+
// 官方五种界面语言的形态:今天“18:16”/“5:41 PM”、昨天“昨天 18:16”/“Yesterday
|
|
143
|
+
// 18:16”/“昨日 18:16”/“어제 오후 5:41”/“Вчера 18:16”、更早“10/21 17:41”/
|
|
144
|
+
// “10/21, 5:41 PM”/“10. 21. 오후 5:41”/“21.10, 17:41”(含年份时多一段)。
|
|
142
145
|
// 行时间是提问时刻,调用桶是完成时刻——一轮的用量按“本条提问到下一条
|
|
143
146
|
// 提问之间”的区间归属(见 scan),因此这里只取可比时间戳
|
|
147
|
+
function datePair(nums, loc) {
|
|
148
|
+
const [a, b] = nums;
|
|
149
|
+
if (a > 12) return [b, a]; // 大于 12 的只能是日
|
|
150
|
+
if (b > 12) return [a, b];
|
|
151
|
+
return loc === 'ru-RU' ? [b, a] : [a, b]; // 俄语是日.月,其余界面是月/日
|
|
152
|
+
}
|
|
144
153
|
function rowTimeTs(text) {
|
|
145
154
|
const now = new Date();
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
m
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
const raw = String(text || '').trim();
|
|
156
|
+
if (!raw) return null;
|
|
157
|
+
// 时间可能带前置或后置的 AM/PM、午前/午後、오전/오후(韩语是“오후 5:41”)
|
|
158
|
+
const m = raw.match(/(?:(AM|PM|午前|午後|오전|오후)\s*)?(\d{1,2}):(\d{2})(?:\s*(AM|PM|午前|午後|오전|오후))?/i);
|
|
159
|
+
if (!m) return null;
|
|
160
|
+
const marker = (m[1] || m[4] || '').toLowerCase();
|
|
161
|
+
let hour = +m[2];
|
|
162
|
+
const minute = +m[3];
|
|
163
|
+
if (marker === 'pm' || marker === '午後' || marker === '오후') { if (hour < 12) hour += 12; }
|
|
164
|
+
else if (marker) { if (hour === 12) hour = 0; }
|
|
165
|
+
const timeText = (raw.slice(0, m.index) + ' ' + raw.slice(m.index + m[0].length)).trim();
|
|
166
|
+
// 昨天/昨日/어제/Вчера:官方在时间前加语言对应的“昨天”
|
|
167
|
+
if (/昨天|昨日|Yesterday|어제|Вчера/i.test(timeText)) {
|
|
168
|
+
const y = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
|
|
169
|
+
return new Date(y.getFullYear(), y.getMonth(), y.getDate(), hour, minute).getTime();
|
|
170
|
+
}
|
|
171
|
+
// 只剩时间 = 今天
|
|
172
|
+
const dateText = timeText.replace(/[^\d./年月日년월일]+/g, ' ').trim();
|
|
173
|
+
if (!dateText) return new Date(now.getFullYear(), now.getMonth(), now.getDate(), hour, minute).getTime();
|
|
174
|
+
// 日期分隔符只认官方 Intl 输出的 / 和 .(以及年月日写法);10-21 这类不猜
|
|
175
|
+
if (!/[./年月日년월일]/.test(timeText)) return null;
|
|
176
|
+
const nums = (dateText.match(/\d+/g) || []).map(Number);
|
|
177
|
+
if (nums.length < 2 || nums.length > 3) return null;
|
|
178
|
+
let year = now.getFullYear();
|
|
179
|
+
let md = nums;
|
|
180
|
+
if (nums.length === 3) {
|
|
181
|
+
const yi = nums.findIndex((n) => n >= 1000);
|
|
182
|
+
if (yi === 0) { year = nums[0]; md = [nums[1], nums[2]]; }
|
|
183
|
+
else if (yi === 2) { year = nums[2]; md = [nums[0], nums[1]]; }
|
|
184
|
+
else return null;
|
|
156
185
|
}
|
|
157
|
-
|
|
186
|
+
const [month, day] = datePair(md, uiLocale());
|
|
187
|
+
if (month < 1 || month > 12 || day < 1 || day > 31) return null;
|
|
188
|
+
let ts = new Date(year, month - 1, day, hour, minute).getTime();
|
|
189
|
+
// 不带年份的月日:算出来在未来的按上一年(1 月看到 12 月的行)
|
|
190
|
+
if (nums.length === 2 && ts > now.getTime()) ts = new Date(year - 1, month - 1, day, hour, minute).getTime();
|
|
191
|
+
return ts;
|
|
158
192
|
}
|
|
159
193
|
|
|
160
194
|
let lastSid = '';
|
package/src/inject/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import { startSubagentIcon } from './features/subagent-icon.js';
|
|
|
21
21
|
import { startIdleReclaim } from './features/idle-reclaim.js';
|
|
22
22
|
import { startSandboxReclaim } from './features/sandbox-reclaim.js';
|
|
23
23
|
import { startPluginCardRetry } from './features/plugin-card-retry.js';
|
|
24
|
+
import { startAutoContinue } from './features/auto-continue.js';
|
|
24
25
|
import { startToolbarIcons } from './features/toolbar-icons.js';
|
|
25
26
|
import { startPinnedCollapse } from './features/pinned-collapse.js';
|
|
26
27
|
import { startStyleAdjustments } from './features/styles.js';
|
|
@@ -86,6 +87,7 @@ import { ensureStyle } from './ui.js';
|
|
|
86
87
|
try { startIdleReclaim(); } catch { /* ignore */ }
|
|
87
88
|
try { startSandboxReclaim(); } catch { /* ignore */ }
|
|
88
89
|
try { startPluginCardRetry(); } catch { /* ignore */ }
|
|
90
|
+
try { startAutoContinue(); } catch { /* ignore */ }
|
|
89
91
|
try { startToolbarIcons(); } catch { /* ignore */ }
|
|
90
92
|
try { startNewtabPanels(); } catch { /* ignore */ }
|
|
91
93
|
try { startStatusBar(); } catch { /* ignore */ }
|