zcode-pro 1.5.1 → 1.6.2
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 +33 -21
- package/README.md +23 -13
- package/dist/inject.js +9803 -7820
- package/package.json +3 -2
- package/src/host/cdp.mjs +13 -3
- package/src/host/helper.mjs +1591 -495
- package/src/host/main.mjs +412 -26
- package/src/host/paths.mjs +17 -9
- package/src/host/pickFolder.mjs +11 -4
- package/src/host/settings.mjs +15 -2
- package/src/host/setup.mjs +57 -18
- package/src/host/skill-stats.mjs +163 -0
- package/src/host/taskIndex.mjs +198 -66
- package/src/host/taskOrder.mjs +128 -57
- package/src/host/version.mjs +15 -7
- package/src/host/wallpaper.mjs +328 -0
- package/src/host/webdav.mjs +66 -10
- package/src/inject/core.js +300 -105
- package/src/inject/features/alias-migration.js +8 -4
- package/src/inject/features/alias.js +2 -2
- package/src/inject/features/auto-rename.js +166 -0
- package/src/inject/features/composer-provider.js +82 -63
- package/src/inject/features/copy-path.js +1 -1
- package/src/inject/features/file-menu.js +9 -3
- package/src/inject/features/idle-reclaim.js +31 -8
- package/src/inject/features/image-menu.js +2 -2
- package/src/inject/features/newtab-panels.js +13 -3
- package/src/inject/features/pinned-collapse.js +11 -3
- package/src/inject/features/plugin-card-retry.js +18 -8
- package/src/inject/features/project-menu.js +1 -1
- package/src/inject/features/relocate-dialog.js +2 -1
- package/src/inject/features/sandbox-reclaim.js +17 -1
- package/src/inject/features/session-link.js +200 -0
- package/src/inject/features/session-switch.js +61 -27
- package/src/inject/features/settings-dialog.js +544 -158
- package/src/inject/features/status-bar.js +126 -24
- package/src/inject/features/table-copy.js +18 -2
- package/src/inject/features/task-order.js +48 -14
- package/src/inject/features/theme.js +644 -99
- package/src/inject/features/title-gen.js +5 -4
- package/src/inject/features/title-lock.js +13 -8
- package/src/inject/features/turn-usage.js +69 -29
- package/src/inject/features/ws-running.js +32 -11
- package/src/inject/index.js +18 -1
- package/src/inject/provider-fields.js +2 -2
- package/src/inject/ui.js +91 -17
|
@@ -81,15 +81,16 @@ function linkDominant(t) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
async function onNewTaskRow(key) {
|
|
84
|
+
// 开关检查放最前:功能关着就不用等选中标记、不占 attempted 名额
|
|
85
|
+
const cfg = await getConfig().catch(() => null);
|
|
86
|
+
if (!cfg || !cfg.titleGen || cfg.titleGen.enabled !== true) return;
|
|
87
|
+
|
|
84
88
|
// 新任务行创建时选中标记可能晚一拍;短暂等待它成为当前会话,
|
|
85
89
|
// 期间没选中(其他入口建的任务)就不处理
|
|
86
90
|
const selDeadline = Date.now() + SELECT_WAIT_MS;
|
|
87
91
|
while (currentKey() !== key && Date.now() < selDeadline) await sleep(200);
|
|
88
92
|
if (currentKey() !== key) return;
|
|
89
93
|
|
|
90
|
-
const cfg = await getConfig().catch(() => null);
|
|
91
|
-
if (!cfg || !cfg.titleGen || cfg.titleGen.enabled !== true) return;
|
|
92
|
-
|
|
93
94
|
const sessId = sessIdOf(key);
|
|
94
95
|
if (!sessId || attempted.has(sessId)) return;
|
|
95
96
|
attempted.add(sessId);
|
|
@@ -124,7 +125,7 @@ async function onNewTaskRow(key) {
|
|
|
124
125
|
let lastChange = Date.now();
|
|
125
126
|
try {
|
|
126
127
|
while (Date.now() - startAt < COLLECT_MAX_MS) {
|
|
127
|
-
await sleep(
|
|
128
|
+
await sleep(2000); // 2 秒查一次:每次都要全量扫用户消息行,500ms 太勤
|
|
128
129
|
if (currentKey() !== key) { lastChange = Date.now(); continue; } // 切走:暂停收集
|
|
129
130
|
texts = userTexts();
|
|
130
131
|
if (texts.length !== lastCount) {
|
|
@@ -105,15 +105,20 @@ function writeTitle(el, text) {
|
|
|
105
105
|
function scheduleEnforce(key, { immediate = false } = {}) {
|
|
106
106
|
if (immediate) {
|
|
107
107
|
// 新上屏的行(项目展开/滚动复现)带着旧名出现,用户此刻正看着列表——
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
// 立即钉回,不等复核;写前先拉最新表:缓存表可能还是重命名前的旧名,
|
|
109
|
+
// 直接用会把刚改的新名闪回旧名(拉表失败/功能关闭则本轮不干预,同复核分支;
|
|
110
|
+
// fetchPinned 有并发去重,与复核批量触发合用一次请求)
|
|
111
|
+
void (async () => {
|
|
112
|
+
const map = await fetchPinned();
|
|
113
|
+
if (!map) return;
|
|
114
|
+
const want = map.get(sessIdOf(key));
|
|
115
|
+
if (want === undefined) return;
|
|
116
|
+
for (const item of findRows(key)) {
|
|
117
|
+
// 拉表期间行内可能出现输入框(进入重命名),编辑中的行不写
|
|
118
|
+
if (item.querySelector('input, textarea, [contenteditable="true"]')) continue;
|
|
119
|
+
for (const el of titleElsOf(item)) writeTitle(el, want);
|
|
115
120
|
}
|
|
116
|
-
}
|
|
121
|
+
})();
|
|
117
122
|
}
|
|
118
123
|
if (pendingKeys.has(key)) return;
|
|
119
124
|
pendingKeys.add(key);
|
|
@@ -43,6 +43,7 @@ function fmt(n) {
|
|
|
43
43
|
if (n >= 1e8) return (n / 1e8).toFixed(1) + '亿';
|
|
44
44
|
if (n >= 1e4) {
|
|
45
45
|
const wan = Math.round((n / 1e4) * 10) / 10;
|
|
46
|
+
if (wan >= 10000) return (Math.round((n / 1e8) * 10) / 10) + '亿'; // 万位四舍五入进到 1 万万 → 显示亿
|
|
46
47
|
return (wan % 1 === 0 ? String(wan) : wan.toFixed(1)) + '万';
|
|
47
48
|
}
|
|
48
49
|
return String(n);
|
|
@@ -53,9 +54,12 @@ function fmt(n) {
|
|
|
53
54
|
// 行内时间文本只用于解析该轮的提问时刻
|
|
54
55
|
function findRows() {
|
|
55
56
|
const rows = [];
|
|
57
|
+
const seen = new Set();
|
|
56
58
|
for (const btn of document.querySelectorAll('[data-testid^="v4-copy-"]')) {
|
|
57
59
|
const row = btn.parentElement;
|
|
58
|
-
|
|
60
|
+
// 一行有多个复制按钮时只收一次(桶归属按行算,重了会把一份用量算多遍)
|
|
61
|
+
if (!row || seen.has(row)) continue;
|
|
62
|
+
seen.add(row);
|
|
59
63
|
if (!row.querySelector('[data-testid^="v4-feedback-"]')) continue;
|
|
60
64
|
const timeEl = [...row.querySelectorAll('span')].find((s) => /\d{1,2}:\d{2}$/.test((s.textContent || '').trim()));
|
|
61
65
|
if (timeEl) { const ts = rowTimeTs((timeEl.textContent || '').trim()); if (ts != null) rows.push({ row, ts }); }
|
|
@@ -63,8 +67,10 @@ function findRows() {
|
|
|
63
67
|
return rows;
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
// 当前会话 id
|
|
67
|
-
|
|
70
|
+
// 当前会话 id:优先选中行,无选中行(新建任务视图等)回退侧栏最新一行。
|
|
71
|
+
// 只认 :sess/:session 形态的键,其它任务键返回空串;
|
|
72
|
+
// 状态栏用自己的严格版(selectedSessionId,不回退)
|
|
73
|
+
export function currentSessionId() {
|
|
68
74
|
const rows = [...document.querySelectorAll('[data-task-item-key]')];
|
|
69
75
|
const cur = rows.find((e) => (e.className + '').includes('bg-selected')) || rows[rows.length - 1];
|
|
70
76
|
const key = cur ? cur.getAttribute('data-task-item-key') : '';
|
|
@@ -73,18 +79,8 @@ function currentSessionId() {
|
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
function injectRow(row, bucket) {
|
|
76
|
-
row.dataset.zcodeproTurn = '1';
|
|
77
82
|
if (!bucket || bucket.in + bucket.out <= 0) return;
|
|
78
83
|
const L = t();
|
|
79
|
-
const el = document.createElement('span');
|
|
80
|
-
el.dataset.zcodeproTurnSpan = '1';
|
|
81
|
-
el.className = 'select-none text-ui-sm text-foreground-subtlest';
|
|
82
|
-
// 按钮行是 flex 容器:本元素作为子项会被压缩导致内容折行,锁成单行
|
|
83
|
-
el.style.whiteSpace = 'nowrap';
|
|
84
|
-
el.style.display = 'inline-flex';
|
|
85
|
-
el.style.alignItems = 'center';
|
|
86
|
-
el.style.gap = '4px'; // 组与 · 分隔之间的间距
|
|
87
|
-
el.style.marginLeft = '10px'; // 与左侧时间拉开
|
|
88
84
|
// 与状态栏同款:图标 + 文字 + 数据;缓存有量时给命中率
|
|
89
85
|
// 保留两位小数:长上下文会话命中率普遍 99%+,取整会全部显示 100% 失真
|
|
90
86
|
const cachePct = bucket.in > 0 && bucket.cacheRead > 0
|
|
@@ -101,47 +97,82 @@ function injectRow(row, bucket) {
|
|
|
101
97
|
else if (s.id === 'turnOut') sections.push(group(icon('down') + em(L.sbLabelOut) + fmt(bucket.out)));
|
|
102
98
|
else if (s.id === 'turnCache' && cachePct) sections.push(group(icon('cache') + em(L.sbLabelCache) + cachePct + '%'));
|
|
103
99
|
}
|
|
104
|
-
|
|
100
|
+
const old = row.querySelector('[data-zcodepro-turn-span]');
|
|
101
|
+
if (!sections.length) {
|
|
102
|
+
// 全隐藏:撤掉行里已有的标注与行标记(不注入)
|
|
103
|
+
if (old) old.remove();
|
|
104
|
+
delete row.dataset.zcodeproTurn;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
105
107
|
const VBAR = '<span style="display:inline-block;width:1px;height:10px;background:currentColor;opacity:.3;margin:0 5px"></span>';
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
const html = VBAR + sections.join(DOT);
|
|
109
|
+
// 数据没变就不动 DOM(含段的显隐顺序):每轮全删全注会在流式期反复触发布局
|
|
110
|
+
if (old && old.innerHTML === html) { row.dataset.zcodeproTurn = '1'; return; }
|
|
111
|
+
if (old) old.remove();
|
|
112
|
+
const el = document.createElement('span');
|
|
113
|
+
el.dataset.zcodeproTurnSpan = '1';
|
|
114
|
+
el.className = 'select-none text-ui-sm text-foreground-subtlest';
|
|
115
|
+
// 按钮行是 flex 容器:本元素作为子项会被压缩导致内容折行,锁成单行
|
|
116
|
+
el.style.whiteSpace = 'nowrap';
|
|
117
|
+
el.style.display = 'inline-flex';
|
|
118
|
+
el.style.alignItems = 'center';
|
|
119
|
+
el.style.gap = '4px'; // 组与 · 分隔之间的间距
|
|
120
|
+
el.style.marginLeft = '10px'; // 与左侧时间拉开
|
|
121
|
+
el.innerHTML = html;
|
|
122
|
+
el.title = `${L.turnUsageTitle}${isZhLocale() ? ':' : ': '}${L.sbLabelIn} ${bucket.in.toLocaleString()} / ${L.sbLabelOut} ${bucket.out.toLocaleString()}`
|
|
108
123
|
+ (bucket.cacheRead > 0 ? ` / ${L.sbLabelCache} ${bucket.cacheRead.toLocaleString()}` : '');
|
|
124
|
+
row.dataset.zcodeproTurn = '1';
|
|
109
125
|
row.append(el); // 追加在按钮行末尾(时间之后)
|
|
110
126
|
}
|
|
111
127
|
|
|
112
128
|
// 回答行时间文本 → 当年本地时间的时间戳(毫秒)。
|
|
113
|
-
// 官方三种形态:今天“18:16”、昨天“昨天 18:16”、更早“10/21 17:41”。
|
|
129
|
+
// 官方三种形态:今天“18:16”、昨天“昨天 18:16”/“Yesterday 18:16”、更早“10/21 17:41”。
|
|
114
130
|
// 行时间是提问时刻,调用桶是完成时刻——一轮的用量按“本条提问到下一条
|
|
115
131
|
// 提问之间”的区间归属(见 scan),因此这里只取可比时间戳
|
|
116
132
|
function rowTimeTs(text) {
|
|
117
133
|
const now = new Date();
|
|
118
134
|
let m = text.match(/^(\d{1,2}):(\d{2})$/);
|
|
119
135
|
if (m) return new Date(now.getFullYear(), now.getMonth(), now.getDate(), +m[1], +m[2]).getTime();
|
|
120
|
-
m = text.match(
|
|
121
|
-
if (m) { const y = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1); return new Date(y.getFullYear(), y.getMonth(), y.getDate(), +m[
|
|
136
|
+
m = text.match(/^(昨天|Yesterday)\s*(\d{1,2}):(\d{2})$/);
|
|
137
|
+
if (m) { const y = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1); return new Date(y.getFullYear(), y.getMonth(), y.getDate(), +m[2], +m[3]).getTime(); }
|
|
122
138
|
m = text.match(/^(\d{1,2})\/(\d{1,2})\s*(\d{1,2}):(\d{2})$/);
|
|
123
|
-
if (m)
|
|
139
|
+
if (m) {
|
|
140
|
+
// 月日形态不带年份:算出来在未来的按上一年(1 月看到 12 月的行)
|
|
141
|
+
let ts = new Date(now.getFullYear(), +m[1] - 1, +m[2], +m[3], +m[4]).getTime();
|
|
142
|
+
if (ts > now.getTime()) ts = new Date(now.getFullYear() - 1, +m[1] - 1, +m[2], +m[3], +m[4]).getTime();
|
|
143
|
+
return ts;
|
|
144
|
+
}
|
|
124
145
|
return null;
|
|
125
146
|
}
|
|
126
147
|
|
|
127
148
|
let lastSid = '';
|
|
128
149
|
function scan() {
|
|
129
|
-
|
|
150
|
+
// 清理只在回答行内做(原来全档删标注再重注,长会话白扫白写):
|
|
151
|
+
// 行内旧标注与旧版本格式(标题前缀“本轮/”Turn“)的标注一并清
|
|
152
|
+
const clearRow = (row) => {
|
|
153
|
+
for (const el of row.querySelectorAll('[data-zcodepro-turn-span], span[title^="本轮"], span[title^="Turn"]')) el.remove();
|
|
154
|
+
delete row.dataset.zcodeproTurn;
|
|
155
|
+
};
|
|
156
|
+
const rows = findRows().sort((a, b) => a.ts - b.ts); // 可见行按时间升序
|
|
157
|
+
// 清理放在 enabled 判定之前:关闭统计开关后残留的标注也能被清掉
|
|
158
|
+
if (!enabled) {
|
|
159
|
+
for (const r of rows) clearRow(r.row);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
130
162
|
// 会话切换瞬间:旧会话的桶还留在 recentTurns 里,若继续归属会把别的会话
|
|
131
163
|
// 的调用安到新视图的旧回答上——先清掉并立即重拉(拉到前只清不注)
|
|
132
164
|
const sid = currentSessionId();
|
|
133
165
|
if (sid !== lastSid) {
|
|
134
166
|
lastSid = sid;
|
|
135
167
|
recentTurns = [];
|
|
168
|
+
for (const r of rows) clearRow(r.row);
|
|
136
169
|
void tick();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (document.hidden || !recentTurns.length) {
|
|
173
|
+
for (const r of rows) clearRow(r.row);
|
|
174
|
+
return;
|
|
137
175
|
}
|
|
138
|
-
// 每轮重算:先移除上一次注入的标注并清行标记(进行中的轮数值会增长);
|
|
139
|
-
// 按标题前缀一并清掉旧版本格式的标注
|
|
140
|
-
for (const el of document.querySelectorAll('[data-zcodepro-turn-span], span[title^="本轮"], span[title^="Turn"]')) el.remove();
|
|
141
|
-
for (const row of document.querySelectorAll('[data-zcodepro-turn]')) delete row.dataset.zcodeproTurn;
|
|
142
|
-
if (document.hidden || !recentTurns.length) return;
|
|
143
|
-
const rows = findRows().sort((a, b) => a.ts - b.ts); // 可见行按时间升序
|
|
144
|
-
if (!rows.length) return;
|
|
145
176
|
// 区间归属:每条回答拥有“自己的提问时刻 ≤ 桶完成时刻 < 下一条提问时刻”
|
|
146
177
|
// 的全部调用(一轮可能跨多个分钟);最后一条收到其后所有桶(进行中的轮)。
|
|
147
178
|
// 行集是虚拟列表的可见窗口,同一条回答的邻居行在场时归属稳定
|
|
@@ -163,14 +194,20 @@ function scan() {
|
|
|
163
194
|
}
|
|
164
195
|
for (let i = 0; i < rows.length; i++) {
|
|
165
196
|
if (agg[i].in + agg[i].out > 0) injectRow(rows[i].row, agg[i]);
|
|
197
|
+
else clearRow(rows[i].row); // 归属变空(窗口移动等):撤掉旧标注
|
|
166
198
|
}
|
|
167
199
|
}
|
|
168
200
|
|
|
201
|
+
let tickSeq = 0;
|
|
169
202
|
async function tick() {
|
|
170
203
|
if (!enabled || document.hidden) return;
|
|
171
204
|
const sid = currentSessionId();
|
|
205
|
+
const seq = ++tickSeq;
|
|
172
206
|
const res = await rpc('/stats/usage' + (sid ? '?session=' + encodeURIComponent(sid) : '')).catch(() => null);
|
|
173
207
|
if (res && res.ok && Array.isArray(res.recentTurns)) {
|
|
208
|
+
// 乱序的在途响应不采纳,且取数期间换了会话就丢弃(旧会话的桶
|
|
209
|
+
// 不能安到新视图的回答行上)——与 status-bar 的 tickSeq 守卫同款
|
|
210
|
+
if (seq !== tickSeq || sid !== currentSessionId()) return;
|
|
174
211
|
// 同分钟桶随时间增长,全量替换
|
|
175
212
|
recentTurns = res.recentTurns;
|
|
176
213
|
scan();
|
|
@@ -181,7 +218,10 @@ export function startTurnUsage() {
|
|
|
181
218
|
void getConfig().then((cfg) => { enabled = cfg.features ? cfg.features.statusBar !== false : true; }).catch(() => {});
|
|
182
219
|
refreshTurnItems();
|
|
183
220
|
window.addEventListener('zcodepro:config-changed', () => {
|
|
184
|
-
void getConfig().then((cfg) => {
|
|
221
|
+
void getConfig().then((cfg) => {
|
|
222
|
+
enabled = cfg.features ? cfg.features.statusBar !== false : true;
|
|
223
|
+
scan(); // 开关变化后立即重扫:关掉时清残留标注
|
|
224
|
+
}).catch(() => {});
|
|
185
225
|
refreshTurnItems();
|
|
186
226
|
});
|
|
187
227
|
// 回答行出现即注入(去抖);数据 5 秒刷新一次
|
|
@@ -124,8 +124,10 @@ let wsWithRows = new Set(); // 最近一次扫描时仍有会话行在 DOM
|
|
|
124
124
|
// 应用内部服务对象(含 zcodeTaskService.releaseWorkspacePreparation):从 React
|
|
125
125
|
// fiber 树上找持有它的组件(file-menu.js 同款取 fiber 的思路),找到后缓存
|
|
126
126
|
let servicesRef = null;
|
|
127
|
+
let servicesMissAt = 0; // 找不到服务也记时刻:fiber 全遍历(上限 6 万节点)代价高,60 秒内不重走
|
|
127
128
|
export function findServices() {
|
|
128
129
|
if (servicesRef) return servicesRef;
|
|
130
|
+
if (servicesMissAt && Date.now() - servicesMissAt < 60_000) return null;
|
|
129
131
|
try {
|
|
130
132
|
const rootEl = document.getElementById('root');
|
|
131
133
|
const containerKey = rootEl && Object.keys(rootEl).find((k) => k.startsWith('__reactContainer$'));
|
|
@@ -154,8 +156,10 @@ export function findServices() {
|
|
|
154
156
|
};
|
|
155
157
|
visit(rootEl[containerKey]);
|
|
156
158
|
if (found) servicesRef = found;
|
|
159
|
+
else servicesMissAt = Date.now();
|
|
157
160
|
return found;
|
|
158
161
|
} catch {
|
|
162
|
+
servicesMissAt = Date.now();
|
|
159
163
|
return null;
|
|
160
164
|
}
|
|
161
165
|
}
|
|
@@ -356,7 +360,12 @@ function sectionHeads() {
|
|
|
356
360
|
const btn = sv.closest('button');
|
|
357
361
|
if (btn) heads.push(btn);
|
|
358
362
|
}
|
|
359
|
-
for (const h3 of document.querySelectorAll('h3'))
|
|
363
|
+
for (const h3 of document.querySelectorAll('h3')) {
|
|
364
|
+
// 聊天正文里的 markdown 标题不是分区头:不排除会把转圈图标插进聊天内容
|
|
365
|
+
//(顺带省掉流式渲染期新标题节点的解析与强制布局开销)
|
|
366
|
+
if (h3.closest('main')) continue;
|
|
367
|
+
heads.push(h3);
|
|
368
|
+
}
|
|
360
369
|
return heads.map((head) => {
|
|
361
370
|
const cached = headInfoCache.get(head);
|
|
362
371
|
if (cached) return { head, cont: cached.cont, kind: cached.kind };
|
|
@@ -375,7 +384,7 @@ function sectionHeads() {
|
|
|
375
384
|
const SEC_SPIN_CLASS = 'zcodepro-ws-sec-spin';
|
|
376
385
|
|
|
377
386
|
// 全局权威扫描:listActiveTaskIds 遍历侧栏全部项目(/projects-v2 提供路径,
|
|
378
|
-
// 尾斜杠两种形式各查一次),任一非终态会话即“有任务在跑”。
|
|
387
|
+
// 尾斜杠两种形式各查一次),任一非终态会话即“有任务在跑”。30 秒节流缓存;
|
|
379
388
|
// 接口不可用(≤3.15.x)时无缓存,分区头退回 DOM 检测
|
|
380
389
|
let anyActiveCache = { at: 0, value: null, busy: false };
|
|
381
390
|
// 活跃按分区归属:task = “任务”分区(非项目工作区),project = “项目”分区,
|
|
@@ -390,12 +399,13 @@ let activeProjectPaths = new Set();
|
|
|
390
399
|
let authActiveByWs = new Map();
|
|
391
400
|
// 周期复查:缓存到期就无条件重扫(不看当前值)——只在 true 时扫会有两个缺口:
|
|
392
401
|
// 空闲后新任务启动无人触发(折叠分区头不亮);任务结束但数据库完成状态尚未
|
|
393
|
-
// 写入的过渡窗口里旧值一直被沿用。每
|
|
402
|
+
// 写入的过渡窗口里旧值一直被沿用。每 30 秒全量一次,扫描本身是内存级过滤
|
|
394
403
|
setInterval(() => {
|
|
395
|
-
if (
|
|
396
|
-
|
|
404
|
+
if (document.hidden || !enabled) return; // 后台/功能关闭不扫,回前台下一轮补上
|
|
405
|
+
if (!anyActiveCache.busy && Date.now() - anyActiveCache.at >= 30_000) globalAnyActive();
|
|
406
|
+
}, 30_000);
|
|
397
407
|
function globalAnyActive() {
|
|
398
|
-
if (anyActiveCache.value !== null && Date.now() - anyActiveCache.at <
|
|
408
|
+
if (anyActiveCache.value !== null && Date.now() - anyActiveCache.at < 30_000) return anyActiveCache.value;
|
|
399
409
|
if (anyActiveCache.busy) return anyActiveCache.value === true;
|
|
400
410
|
anyActiveCache.busy = true;
|
|
401
411
|
sectionActive.task = false;
|
|
@@ -444,10 +454,15 @@ function globalAnyActive() {
|
|
|
444
454
|
}
|
|
445
455
|
projectPaths.set(proj.name, names);
|
|
446
456
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
const b = await
|
|
450
|
-
|
|
457
|
+
// 各工作区并行查(串行 await 在几十个工作区时要跑数秒):每区两种尾斜杠各查一次
|
|
458
|
+
const pairs = await Promise.all([...scanPaths].map(async (base) => {
|
|
459
|
+
const [a, b] = await Promise.all([
|
|
460
|
+
ts.listActiveTaskIds({ workspacePath: base }),
|
|
461
|
+
ts.listActiveTaskIds({ workspacePath: base + '/' }),
|
|
462
|
+
]);
|
|
463
|
+
return [base, [...(Array.isArray(a) ? a : []), ...(Array.isArray(b) ? b : [])].map(String)];
|
|
464
|
+
}));
|
|
465
|
+
for (const [base, ids] of pairs) {
|
|
451
466
|
if (!ids.length) continue;
|
|
452
467
|
byKindByPath.set(base, ids);
|
|
453
468
|
const kind = projPaths.has(base) ? 'project' : 'task';
|
|
@@ -558,7 +573,7 @@ function applySectionSpin() {
|
|
|
558
573
|
const list = head.nextElementSibling;
|
|
559
574
|
expanded = !list || list.offsetHeight > 0;
|
|
560
575
|
}
|
|
561
|
-
if (!kind)
|
|
576
|
+
if (!kind) continue; // 折叠后解析不到归属且无缓存:跳过这个分区头(不动现有图标),继续处理其余分区头
|
|
562
577
|
// 已置顶标题(h3)单独看 pinned scope,不复用 task 的
|
|
563
578
|
const scoped = head.tagName === 'H3' ? sectionActive.pinned
|
|
564
579
|
: kind === 'project' ? sectionActive.project : sectionActive.task;
|
|
@@ -893,6 +908,12 @@ let scanDebounce = 0;
|
|
|
893
908
|
export function startWsRunningSpin() {
|
|
894
909
|
if (installed || typeof document === 'undefined') return;
|
|
895
910
|
installed = true;
|
|
911
|
+
// 加载中图标用默认灰压深一点点:既比默认灰显眼,又不像主题色那么跳
|
|
912
|
+
//(描边是 currentColor,改 color 即可)
|
|
913
|
+
const st = document.createElement('style');
|
|
914
|
+
st.id = '__zcodepro_ws_style__';
|
|
915
|
+
st.textContent = '.zcodepro-ws-loader{color:color-mix(in srgb, currentColor 85%, black) !important}';
|
|
916
|
+
document.head.append(st);
|
|
896
917
|
void refreshConfig();
|
|
897
918
|
pollConfig();
|
|
898
919
|
|
package/src/inject/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import { startStatusBar } from './features/status-bar.js';
|
|
|
15
15
|
import { startTurnUsage } from './features/turn-usage.js';
|
|
16
16
|
import { startTitleLock } from './features/title-lock.js';
|
|
17
17
|
import { startTitleGen } from './features/title-gen.js';
|
|
18
|
+
import { startAutoRename, handleTaskRowMenu } from './features/auto-rename.js';
|
|
18
19
|
import { startWsRunningSpin } from './features/ws-running.js';
|
|
19
20
|
import { startIdleReclaim } from './features/idle-reclaim.js';
|
|
20
21
|
import { startSandboxReclaim } from './features/sandbox-reclaim.js';
|
|
@@ -24,6 +25,7 @@ import { startPinnedCollapse } from './features/pinned-collapse.js';
|
|
|
24
25
|
import { startStyleAdjustments } from './features/styles.js';
|
|
25
26
|
import { startTheme } from './features/theme.js';
|
|
26
27
|
import { startTableCopy } from './features/table-copy.js';
|
|
28
|
+
import { startSessionLink } from './features/session-link.js';
|
|
27
29
|
import { startComposerProvider } from './features/composer-provider.js';
|
|
28
30
|
import { startPluginUpdateCheck } from './features/plugin-updates.js';
|
|
29
31
|
import { ensureStyle } from './ui.js';
|
|
@@ -36,7 +38,19 @@ import { ensureStyle } from './ui.js';
|
|
|
36
38
|
const boot = window.__ZCODEPRO__ || {};
|
|
37
39
|
const sameGeneration = window.__zcodeproBootedToken && boot.token
|
|
38
40
|
&& window.__zcodeproBootedToken === boot.token;
|
|
39
|
-
if (!sameGeneration)
|
|
41
|
+
if (!sameGeneration) {
|
|
42
|
+
// 换代刷新限次(记在 sessionStorage,跨刷新存活):两个不同 token 的注入器
|
|
43
|
+
// 互相看对方不顺眼时,30 秒内最多刷 2 次,别进无限刷新
|
|
44
|
+
const key = 'zcodeproReloadLog';
|
|
45
|
+
let log = [];
|
|
46
|
+
try { log = JSON.parse(sessionStorage.getItem(key) || '[]'); } catch { /* ignore */ }
|
|
47
|
+
if (!Array.isArray(log)) log = [];
|
|
48
|
+
log = log.filter((ts) => Date.now() - ts < 30000);
|
|
49
|
+
if (log.length < 2) {
|
|
50
|
+
try { sessionStorage.setItem(key, JSON.stringify([...log, Date.now()])); } catch { /* ignore */ }
|
|
51
|
+
location.reload();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
40
54
|
return;
|
|
41
55
|
}
|
|
42
56
|
window.__zcodeproInjected = true;
|
|
@@ -54,6 +68,7 @@ import { ensureStyle } from './ui.js';
|
|
|
54
68
|
observeRadixPopups((content) => {
|
|
55
69
|
try { handleProjectMenu(content); } catch { /* 单个功能失败不影响其他 */ }
|
|
56
70
|
try { handleFileMenu(content); } catch { /* ignore */ }
|
|
71
|
+
try { handleTaskRowMenu(content); } catch { /* ignore */ }
|
|
57
72
|
});
|
|
58
73
|
try { void startAliasWatcher(); } catch { /* ignore */ }
|
|
59
74
|
// 别名迁移弹窗(3.16.1+ 且仍有存量别名时才动作),内部自带等待与窗口聚焦判断
|
|
@@ -62,6 +77,7 @@ import { ensureStyle } from './ui.js';
|
|
|
62
77
|
try { startSessionSwitch(); } catch { /* ignore */ }
|
|
63
78
|
try { startTitleLock(); } catch { /* ignore */ }
|
|
64
79
|
try { startTitleGen(); } catch { /* ignore */ }
|
|
80
|
+
try { startAutoRename(); } catch { /* ignore */ }
|
|
65
81
|
try { startImageMenu(); } catch { /* ignore */ }
|
|
66
82
|
try { startWsRunningSpin(); } catch { /* ignore */ }
|
|
67
83
|
try { startIdleReclaim(); } catch { /* ignore */ }
|
|
@@ -75,6 +91,7 @@ import { ensureStyle } from './ui.js';
|
|
|
75
91
|
try { startStyleAdjustments(); } catch { /* ignore */ }
|
|
76
92
|
try { startTheme(); } catch { /* ignore */ }
|
|
77
93
|
try { startTableCopy(); } catch { /* ignore */ }
|
|
94
|
+
try { startSessionLink(); } catch { /* ignore */ }
|
|
78
95
|
try { startComposerProvider(); } catch { /* ignore */ }
|
|
79
96
|
try { startSettingsEntry(); } catch { /* ignore */ }
|
|
80
97
|
// 插件更新检查慢(可能 git pull),异步进行,不阻塞其他功能
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// - 'session':跟随当前会话(连接由会话侧解析,不存地址密钥);
|
|
5
5
|
// - 其余:供应商 id;已删的 id 保留为“已删除”选项,调用方靠保存的地址/
|
|
6
6
|
// 密钥副本继续直连。
|
|
7
|
-
import { h } from './core.js';
|
|
7
|
+
import { h, t } from './core.js';
|
|
8
8
|
|
|
9
9
|
export const PROVIDER_FIELD_CLS = 'h-8 w-full rounded-lg border border-border bg-input px-2.5 text-ui-sm text-foreground outline-none transition-shadow placeholder:text-foreground-subtle focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40';
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@ export const PROVIDER_FIELD_CLS = 'h-8 w-full rounded-lg border border-border bg
|
|
|
12
12
|
// 输入;当前值不在列表里(条目被删或手输 id)时保留为带 staleLabel 标注的
|
|
13
13
|
// 选项,不清空、不跳值;当前值为空时插入一个 emptyLabel 空选项,避免下拉框
|
|
14
14
|
// 假装选中第一项而配置里其实没选
|
|
15
|
-
export function comboField(current, options, onChange, { disabled = false, placeholder = '', staleLabel =
|
|
15
|
+
export function comboField(current, options, onChange, { disabled = false, placeholder = '', staleLabel = t().manualInput, emptyLabel = '' } = {}) {
|
|
16
16
|
const sel = h('select', { class: PROVIDER_FIELD_CLS, disabled: disabled || undefined });
|
|
17
17
|
const input = h('input', { type: 'text', value: current, placeholder, class: PROVIDER_FIELD_CLS, disabled: disabled || undefined });
|
|
18
18
|
const sync = () => {
|
package/src/inject/ui.js
CHANGED
|
@@ -5,19 +5,40 @@ import { h, t } from './core.js';
|
|
|
5
5
|
|
|
6
6
|
let toastTimer = null;
|
|
7
7
|
|
|
8
|
+
// 提示条:设置弹窗里触发的提示居中叠在弹窗上,其余居中显示在 ZCode 窗体中间。
|
|
9
|
+
// kind 区分成功 / 警告 / 失败 / 信息('ok' 是旧调用点的成功写法,按成功处理);
|
|
10
|
+
// 配色走 ensureStyle 的自有样式,不依赖宿主 Tailwind 生成配色工具类
|
|
11
|
+
const TOAST_KINDS = {
|
|
12
|
+
success: { name: 'success', glyph: '✓', ms: 2600 },
|
|
13
|
+
warning: { name: 'warning', glyph: '!', ms: 3600 },
|
|
14
|
+
error: { name: 'error', glyph: '✕', ms: 5000 },
|
|
15
|
+
info: { name: 'info', glyph: 'ⓘ', ms: 2600 },
|
|
16
|
+
};
|
|
17
|
+
|
|
8
18
|
export function showToast(text, kind = 'info') {
|
|
9
19
|
document.getElementById('__zcodepro_toast__')?.remove();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
style: 'animation:zcodepro-fade-in .18s ease; left: 1.5rem;',
|
|
20
|
+
clearTimeout(toastTimer);
|
|
21
|
+
const v = TOAST_KINDS[kind === 'ok' ? 'success' : kind] || TOAST_KINDS.info;
|
|
22
|
+
const chip = h('div', {
|
|
23
|
+
class: `zcodepro-toast zcodepro-toast-${v.name}`,
|
|
24
|
+
style: 'animation:zcodepro-fade-in .18s ease;',
|
|
16
25
|
},
|
|
26
|
+
h('span', { class: 'zcodepro-toast-glyph' }, v.glyph),
|
|
17
27
|
h('span', { class: 'truncate' }, text));
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
const wrap = h('div', { id: '__zcodepro_toast__', class: 'pointer-events-none flex items-center justify-center' });
|
|
29
|
+
// 设置弹窗可拖动、内部可滚动:按弹窗当前盒子定位(fixed),
|
|
30
|
+
// 提示始终落在可见弹窗的正中间;不属于弹窗的提示落到窗体正中间
|
|
31
|
+
const host = document.querySelector('[data-zcodepro-settings]');
|
|
32
|
+
if (host) {
|
|
33
|
+
const r = host.getBoundingClientRect();
|
|
34
|
+
wrap.style.cssText = `position:fixed; left:${Math.round(r.left)}px; top:${Math.round(r.top)}px;`
|
|
35
|
+
+ ` width:${Math.round(r.width)}px; height:${Math.round(r.height)}px; z-index:100;`;
|
|
36
|
+
} else {
|
|
37
|
+
wrap.style.cssText = 'position:fixed; inset:0; z-index:100;';
|
|
38
|
+
}
|
|
39
|
+
wrap.append(chip);
|
|
40
|
+
document.body.append(wrap);
|
|
41
|
+
toastTimer = setTimeout(() => wrap.remove(), v.ms);
|
|
21
42
|
}
|
|
22
43
|
|
|
23
44
|
// 复用应用自身 AlertDialog 的真实类名组合(逆向自 app.asar 渲染层源码):
|
|
@@ -45,6 +66,10 @@ export function openDialog({ title, description, onMount, onClose, width = 'sm:m
|
|
|
45
66
|
const prevActive = document.activeElement;
|
|
46
67
|
let cleanupDrag = null;
|
|
47
68
|
const close = () => {
|
|
69
|
+
// 先 blur 弹窗内焦点元素:输入框靠 change 提交,直接 remove 不触发 change,
|
|
70
|
+
// Esc 关弹窗会把没失焦的输入悄悄丢掉
|
|
71
|
+
const active = document.activeElement;
|
|
72
|
+
if (active && overlayEl.contains(active)) { try { active.blur(); } catch { /* ignore */ } }
|
|
48
73
|
overlayEl.remove();
|
|
49
74
|
dialogStack = dialogStack.filter((e) => e !== overlayEl);
|
|
50
75
|
document.removeEventListener('keydown', onKey);
|
|
@@ -102,14 +127,40 @@ export function openDialog({ title, description, onMount, onClose, width = 'sm:m
|
|
|
102
127
|
titleEl.style.cursor = 'move';
|
|
103
128
|
titleEl.style.userSelect = 'none';
|
|
104
129
|
let dragging = false, sx = 0, sy = 0, ox = 0, oy = 0;
|
|
105
|
-
//
|
|
106
|
-
//
|
|
130
|
+
// 应用自绘标题栏高度:标题栏带 -webkit-app-region:drag,是合成层区域、
|
|
131
|
+
// 在所有页面内容之上——卡片钻到它下面后拖动把手和关闭按钮就再也点不到。
|
|
132
|
+
// 实测 3.16.2 起宿主样式表不再编译 platform-linux-desktop:top-12,遮罩
|
|
133
|
+
// 让位旧机制失效,因此运行时实测标题栏(结果短缓存,视图切换后能跟上)
|
|
134
|
+
let tbCache = { at: 0, h: 0 };
|
|
135
|
+
const titleBarHeight = () => {
|
|
136
|
+
if (Date.now() - tbCache.at < 2000) return tbCache.h;
|
|
137
|
+
let h = 0;
|
|
138
|
+
try {
|
|
139
|
+
for (const el of document.querySelectorAll('[class*="app-region"], [style*="app-region"], header')) {
|
|
140
|
+
const st = getComputedStyle(el);
|
|
141
|
+
if ((st.webkitAppRegion || st.appRegion) !== 'drag') continue;
|
|
142
|
+
const r = el.getBoundingClientRect();
|
|
143
|
+
if (r.top <= 2 && r.height > 8 && r.height < 120) h = Math.max(h, r.bottom);
|
|
144
|
+
}
|
|
145
|
+
} catch { /* ignore */ }
|
|
146
|
+
tbCache = { at: Date.now(), h };
|
|
147
|
+
return h;
|
|
148
|
+
};
|
|
149
|
+
// 卡片未平移时的矩形(当前矩形扣除平移量)。平移边界按卡片实际边缘不出
|
|
150
|
+
// 窗体算(旧算法按遮罩内居中对称取值:顶部能钻进标题栏、底部也够不到边)
|
|
151
|
+
const baseRect = () => {
|
|
152
|
+
const r = content.getBoundingClientRect();
|
|
153
|
+
return { left: r.left - ox, top: r.top - oy, right: r.right - ox, bottom: r.bottom - oy };
|
|
154
|
+
};
|
|
155
|
+
// 单轴夹取:范围倒挂(卡片比可用空间还宽/高)时取中点,保证两边均可见
|
|
156
|
+
const clampAxis = (v, lo, hi) => (lo > hi ? (lo + hi) / 2 : Math.min(hi, Math.max(lo, v)));
|
|
107
157
|
const clampPos = (x, y) => {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
158
|
+
const M = 8; // 距窗体边缘的留白
|
|
159
|
+
const b = baseRect();
|
|
160
|
+
return [
|
|
161
|
+
clampAxis(x, M - b.left, (window.innerWidth - M) - b.right),
|
|
162
|
+
clampAxis(y, (titleBarHeight() + M) - b.top, (window.innerHeight - M) - b.bottom),
|
|
163
|
+
];
|
|
113
164
|
};
|
|
114
165
|
const applyPos = () => {
|
|
115
166
|
content.style.transform = (ox || oy) ? `translate(${ox}px, ${oy}px)` : '';
|
|
@@ -379,6 +430,29 @@ export function ensureStyle() {
|
|
|
379
430
|
if (!root) return;
|
|
380
431
|
root.append(h('style', { id: '__zcodepro_style__' }, `
|
|
381
432
|
@keyframes zcodepro-fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
|
|
433
|
+
/* 会话 ID 显示为任务名链接(session-link.js):观感贴近正文链接,主题变量缺失时回退字面量 */
|
|
434
|
+
.zcodepro-sess-link {
|
|
435
|
+
color: var(--color-link, var(--color-primary, #4a9eff));
|
|
436
|
+
cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
|
|
437
|
+
}
|
|
438
|
+
.zcodepro-sess-link:hover { opacity: .8; }
|
|
439
|
+
/* 提示条四态(成功/警告/失败/信息):配色用主题变量加字面量兜底,
|
|
440
|
+
不依赖宿主 Tailwind 生成配色工具类 */
|
|
441
|
+
.zcodepro-toast {
|
|
442
|
+
display: flex; align-items: center; gap: .5rem;
|
|
443
|
+
max-width: 28rem; padding: .75rem 1rem;
|
|
444
|
+
border-radius: .5rem; border: 1px solid var(--color-border, #555);
|
|
445
|
+
background: var(--color-menu, #1f1f1f); color: var(--color-foreground, #eee);
|
|
446
|
+
font-size: .875rem; box-shadow: 0 10px 15px -3px rgb(0 0 0 / .3);
|
|
447
|
+
}
|
|
448
|
+
.zcodepro-toast .zcodepro-toast-glyph { font-weight: 600; }
|
|
449
|
+
.zcodepro-toast-success { border-color: #22c55e; }
|
|
450
|
+
.zcodepro-toast-success .zcodepro-toast-glyph { color: #22c55e; }
|
|
451
|
+
.zcodepro-toast-warning { border-color: #f59e0b; }
|
|
452
|
+
.zcodepro-toast-warning .zcodepro-toast-glyph { color: #f59e0b; }
|
|
453
|
+
.zcodepro-toast-error { border-color: var(--color-destructive, #ef4444); }
|
|
454
|
+
.zcodepro-toast-error .zcodepro-toast-glyph { color: var(--color-destructive, #ef4444); }
|
|
455
|
+
.zcodepro-toast-info .zcodepro-toast-glyph { color: var(--color-foreground-subtle, #999); }
|
|
382
456
|
/* 弹窗遮罩/面板兜底:不依赖应用 Tailwind 类是否仍存在;主题色走 --color-* 变量,缺失时回退字面量 */
|
|
383
457
|
.zcodepro-overlay { background-color: rgba(0, 0, 0, 0.6); }
|
|
384
458
|
.zcodepro-overlay[data-overlay="none"] { background-color: transparent; }
|
|
@@ -482,7 +556,7 @@ export function ensureStyle() {
|
|
|
482
556
|
}
|
|
483
557
|
.zcodepro-bg-card:hover { filter: brightness(1.15); }
|
|
484
558
|
.zcodepro-bg-card[data-state="active"] { border-color: var(--color-primary, #333); }
|
|
485
|
-
.zcodepro-bg-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
|
559
|
+
.zcodepro-bg-card img, .zcodepro-bg-card video { width: 100%; height: 100%; object-fit: cover; display: block; }
|
|
486
560
|
.zcodepro-bg-del {
|
|
487
561
|
position: absolute; top: 4px; right: 4px; width: 20px; height: 20px;
|
|
488
562
|
border-radius: 6px; border: none; cursor: pointer; font-size: 11px; line-height: 1;
|