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
|
@@ -311,7 +311,7 @@ export function openMigrationDialog() {
|
|
|
311
311
|
clearConfigCache();
|
|
312
312
|
renderList();
|
|
313
313
|
window.dispatchEvent(new CustomEvent('zcodepro:aliases-changed'));
|
|
314
|
-
if (ok === dead.length) showToast(L.aliasMigrateDeadCleared.replace('{n}', String(ok)));
|
|
314
|
+
if (ok === dead.length) showToast(L.aliasMigrateDeadCleared.replace('{n}', String(ok)), 'success');
|
|
315
315
|
else showToast(L.aliasMigrateDeadClearFailed, 'error');
|
|
316
316
|
};
|
|
317
317
|
|
|
@@ -351,9 +351,9 @@ export function openMigrationDialog() {
|
|
|
351
351
|
decide();
|
|
352
352
|
close();
|
|
353
353
|
if (!failed.length) {
|
|
354
|
-
showToast(L.aliasMigrateDone.replace('{n}', String(ok)), '
|
|
354
|
+
showToast(L.aliasMigrateDone.replace('{n}', String(ok)), 'success');
|
|
355
355
|
} else if (ok) {
|
|
356
|
-
showToast(L.aliasMigratePartial.replace('{n}', String(ok)).replace('{m}', String(failed.length)), '
|
|
356
|
+
showToast(L.aliasMigratePartial.replace('{n}', String(ok)).replace('{m}', String(failed.length)), 'warning');
|
|
357
357
|
} else {
|
|
358
358
|
showToast(L.aliasMigrateAllFailed, 'error');
|
|
359
359
|
}
|
|
@@ -386,7 +386,11 @@ export function openMigrationDialog() {
|
|
|
386
386
|
return footer;
|
|
387
387
|
})()
|
|
388
388
|
);
|
|
389
|
-
})()
|
|
389
|
+
})().catch((err) => {
|
|
390
|
+
// 异步体任一异常都要收场:否则弹窗空着永远转圈,还有未处理的拒绝
|
|
391
|
+
console.warn('[zcodepro] alias-migrate 弹窗内容加载失败: ' + (err && err.message));
|
|
392
|
+
try { close(); } catch { /* ignore */ }
|
|
393
|
+
});
|
|
390
394
|
},
|
|
391
395
|
});
|
|
392
396
|
}
|
|
@@ -174,7 +174,7 @@ export function openAliasDialog(project) {
|
|
|
174
174
|
close();
|
|
175
175
|
clearConfigCache();
|
|
176
176
|
await refreshAliases();
|
|
177
|
-
showToast(name ? L.aliasSaved : L.aliasCleared);
|
|
177
|
+
showToast(name ? L.aliasSaved : L.aliasCleared, 'success');
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
180
|
showToast((L.failed) + ': ' + (errText(res) || L.retryHint), 'error');
|
|
@@ -203,7 +203,7 @@ export function openAliasDialog(project) {
|
|
|
203
203
|
close();
|
|
204
204
|
clearConfigCache();
|
|
205
205
|
await refreshAliases();
|
|
206
|
-
showToast(L.aliasCleared);
|
|
206
|
+
showToast(L.aliasCleared, 'success');
|
|
207
207
|
} else showToast((L.failed) + ': ' + (errText(res) || L.retryHint), 'error');
|
|
208
208
|
}));
|
|
209
209
|
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// 手动“自动重命名”:按会话最近 N 轮问答 + 设置弹窗“自动重命名”tab 的提示词
|
|
2
|
+
// 重新生成任务名,按“手动重命名”写库(已重命名也覆盖——用户显式改名)。两个入口:
|
|
3
|
+
// - 任务行悬浮按钮:挂在官方悬浮操作区(data-task-row-actions,归档按钮旁)。
|
|
4
|
+
// 操作区悬停才渲染、React 重渲染会抹掉注入节点,按行内变动去抖补挂;
|
|
5
|
+
// - 右键菜单:在“重命名任务”下方插入一项。菜单是 Radix 浮层,右键任务行时
|
|
6
|
+
// 先记下会话键,菜单出现后克隆官方菜单项样式插入。
|
|
7
|
+
// 生成成功即更新侧栏行并刷新标题锁定表(同 title-gen.js);手动动作失败弹提示
|
|
8
|
+
//(不再静默)。入口各有开关、素材轮数可调,都在“自动重命名”tab 下。
|
|
9
|
+
import { rpc, getConfig, itemsOf, itemText, closeRadixMenu, t, errText } from '../core.js';
|
|
10
|
+
import { showToast } from '../ui.js';
|
|
11
|
+
import { setRowTitle, refreshPinnedTitles } from './title-lock.js';
|
|
12
|
+
|
|
13
|
+
const TASK_SEL = '[data-task-item-key]';
|
|
14
|
+
const ACTIONS_SEL = '[data-task-row-actions]';
|
|
15
|
+
const SCAN_DEBOUNCE_MS = 300; // 任务行相关 DOM 变动后的去抖
|
|
16
|
+
const RENAME_CTX_VALID_MS = 15000; // 右键任务行到菜单出现的有效窗口
|
|
17
|
+
|
|
18
|
+
let installed = false;
|
|
19
|
+
const runningKeys = new Set(); // 正在生成的会话键,防重复触发
|
|
20
|
+
let ctxKey = ''; // 最近右键的任务行键(菜单浮层不带行,靠它定位目标会话)
|
|
21
|
+
let ctxAt = 0;
|
|
22
|
+
|
|
23
|
+
function sessIdOf(key) {
|
|
24
|
+
const i = key.lastIndexOf(':');
|
|
25
|
+
return i > 0 ? key.slice(i + 1) : '';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function runAutoRename(key) {
|
|
29
|
+
const L = t();
|
|
30
|
+
const sessId = sessIdOf(key);
|
|
31
|
+
if (!sessId || runningKeys.has(key)) return;
|
|
32
|
+
runningKeys.add(key);
|
|
33
|
+
showToast(L.autoRenameWorking, 'info');
|
|
34
|
+
try {
|
|
35
|
+
const res = await rpc('/title-gen/rename', { method: 'POST', body: { sessId } }).catch(() => null);
|
|
36
|
+
if (res && res.ok && res.title) {
|
|
37
|
+
setRowTitle(key, res.title);
|
|
38
|
+
void refreshPinnedTitles();
|
|
39
|
+
showToast(L.autoRenameDone + res.title, 'success');
|
|
40
|
+
} else {
|
|
41
|
+
showToast(errText(res) || L.failed, 'error');
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
runningKeys.delete(key);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 自动起名图标:四角星 + 小闪星(纯手绘路径,风格随所在按钮的 stroke 设置)
|
|
49
|
+
function sparklesSvg(cls) {
|
|
50
|
+
const ns = 'http://www.w3.org/2000/svg';
|
|
51
|
+
const svg = document.createElementNS(ns, 'svg');
|
|
52
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
53
|
+
svg.setAttribute('fill', 'none');
|
|
54
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
55
|
+
svg.setAttribute('stroke-width', '1.5');
|
|
56
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
57
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
58
|
+
svg.setAttribute('class', cls);
|
|
59
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
60
|
+
const star = document.createElementNS(ns, 'path');
|
|
61
|
+
star.setAttribute('d', 'M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9L12 3z');
|
|
62
|
+
const spark = document.createElementNS(ns, 'path');
|
|
63
|
+
spark.setAttribute('d', 'M19 14.5l.8 2.2 2.2.8-2.2.8-.8 2.2-.8-2.2-2.2-.8 2.2-.8.8-2.2z');
|
|
64
|
+
svg.append(star, spark);
|
|
65
|
+
return svg;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 悬浮按钮:官方操作区(悬停才渲染)出现即在归档按钮旁补挂。克隆归档按钮的
|
|
69
|
+
// 包装与样式,换图标与文案;注入节点被 React 重渲染抹掉后由观察器补回
|
|
70
|
+
async function injectHoverButtons() {
|
|
71
|
+
const cfg = await getConfig();
|
|
72
|
+
if (!cfg || !cfg.titleGen) return; // 配置没取到:不动现有按钮,等下一轮
|
|
73
|
+
const enabled = cfg.titleGen.hoverBtn !== false;
|
|
74
|
+
const L = t();
|
|
75
|
+
for (const area of document.querySelectorAll(ACTIONS_SEL)) {
|
|
76
|
+
const existing = area.querySelector('[data-zcodepro-item="auto-rename"]');
|
|
77
|
+
if (!enabled) {
|
|
78
|
+
existing?.remove();
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (existing) continue;
|
|
82
|
+
const row = area.closest(TASK_SEL);
|
|
83
|
+
const key = row ? row.getAttribute('data-task-item-key') : '';
|
|
84
|
+
if (!key) continue;
|
|
85
|
+
const archive = area.querySelector('button[data-testid^="task-archive-"]');
|
|
86
|
+
if (!archive) continue;
|
|
87
|
+
const anchor = archive.closest('[data-slot="tooltip-trigger"]') || archive;
|
|
88
|
+
const node = anchor.cloneNode(true);
|
|
89
|
+
const btn = node.tagName === 'BUTTON' ? node : node.querySelector('button');
|
|
90
|
+
if (!btn) continue;
|
|
91
|
+
btn.removeAttribute('data-testid');
|
|
92
|
+
btn.setAttribute('data-zcodepro-item', 'auto-rename');
|
|
93
|
+
btn.setAttribute('aria-label', L.autoRenameItem);
|
|
94
|
+
btn.setAttribute('title', L.autoRenameItem);
|
|
95
|
+
btn.querySelector('svg')?.remove();
|
|
96
|
+
btn.append(sparklesSvg('h-3.5 w-3.5'));
|
|
97
|
+
btn.addEventListener('mousedown', (e) => e.stopPropagation()); // 不触发行拖拽
|
|
98
|
+
btn.addEventListener('click', (e) => {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
e.stopPropagation(); // 不触发行点击(切换会话)
|
|
101
|
+
void runAutoRename(key);
|
|
102
|
+
});
|
|
103
|
+
anchor.parentNode.insertBefore(node, anchor);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 右键菜单注入:在“重命名任务”下方插入“自动重命名”(克隆同款菜单项样式)。
|
|
108
|
+
// Radix 只初始化一次菜单内容、重复打开复用同一节点,插入前查重
|
|
109
|
+
export function handleTaskRowMenu(content) {
|
|
110
|
+
if (!ctxKey || Date.now() - ctxAt > RENAME_CTX_VALID_MS) return;
|
|
111
|
+
if (content.querySelector('[data-zcodepro-item="auto-rename"]')) return;
|
|
112
|
+
const anchor = itemsOf(content).find((el) => /^重命名|^rename/i.test(itemText(el)));
|
|
113
|
+
if (!anchor) return;
|
|
114
|
+
const key = ctxKey;
|
|
115
|
+
void getConfig().then((cfg) => {
|
|
116
|
+
if (!cfg || !cfg.titleGen || cfg.titleGen.menuEntry === false) return;
|
|
117
|
+
if (content.querySelector('[data-zcodepro-item="auto-rename"]')) return; // 等配置期间已注入
|
|
118
|
+
const L = t();
|
|
119
|
+
const item = anchor.cloneNode(false);
|
|
120
|
+
item.removeAttribute('id');
|
|
121
|
+
item.removeAttribute('data-highlighted');
|
|
122
|
+
item.setAttribute('data-zcodepro-item', 'auto-rename');
|
|
123
|
+
item.textContent = L.autoRenameItem;
|
|
124
|
+
item.addEventListener('mouseenter', () => {
|
|
125
|
+
for (const el of content.querySelectorAll('[role="menuitem"]')) el.removeAttribute('data-highlighted');
|
|
126
|
+
item.setAttribute('data-highlighted', '');
|
|
127
|
+
});
|
|
128
|
+
item.addEventListener('mouseleave', () => item.removeAttribute('data-highlighted'));
|
|
129
|
+
item.addEventListener('click', (e) => {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
e.stopPropagation();
|
|
132
|
+
closeRadixMenu(content); // 先关菜单再动手
|
|
133
|
+
void runAutoRename(key);
|
|
134
|
+
});
|
|
135
|
+
anchor.after(item);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function startAutoRename() {
|
|
140
|
+
if (installed || typeof document === 'undefined') return;
|
|
141
|
+
installed = true;
|
|
142
|
+
|
|
143
|
+
// 右键记下目标会话(捕获阶段,菜单未弹出前)
|
|
144
|
+
document.addEventListener('contextmenu', (e) => {
|
|
145
|
+
const row = e.target instanceof Element && e.target.closest(TASK_SEL);
|
|
146
|
+
ctxKey = row ? (row.getAttribute('data-task-item-key') || '') : '';
|
|
147
|
+
ctxAt = Date.now();
|
|
148
|
+
}, true);
|
|
149
|
+
|
|
150
|
+
// 悬浮按钮按任务行相关变动去抖补挂(聊天区流式输出的高频变动在此滤掉)
|
|
151
|
+
let scanTimer = 0;
|
|
152
|
+
const schedule = () => {
|
|
153
|
+
if (scanTimer) return;
|
|
154
|
+
scanTimer = setTimeout(() => { scanTimer = 0; void injectHoverButtons(); }, SCAN_DEBOUNCE_MS);
|
|
155
|
+
};
|
|
156
|
+
const inTaskRow = (node) => !!(node instanceof Element && node.closest && node.closest(TASK_SEL));
|
|
157
|
+
new MutationObserver((muts) => {
|
|
158
|
+
for (const m of muts) {
|
|
159
|
+
if (inTaskRow(m.target) || [...m.addedNodes].some((n) => inTaskRow(n))) { schedule(); return; }
|
|
160
|
+
}
|
|
161
|
+
}).observe(document.body, { childList: true, subtree: true });
|
|
162
|
+
|
|
163
|
+
void injectHoverButtons();
|
|
164
|
+
// 设置弹窗开关保存后立即生效(撤钮后补挂/移除按钮)
|
|
165
|
+
window.addEventListener('zcodepro:config-changed', schedule);
|
|
166
|
+
}
|
|
@@ -8,86 +8,99 @@ import { t, getConfig } from '../core.js';
|
|
|
8
8
|
let installed = false;
|
|
9
9
|
let enabled = true; // helper features.composerProvider(默认开)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
const TRIGGER_SEL = '[data-testid="chat-model-select-trigger"]';
|
|
12
|
+
|
|
13
|
+
// 从 aria-label 拆出 “供应商 / 模型”。label 形态:
|
|
14
|
+
// "<供应商>/<模型名> <附加说明(如 最高)>";有的供应商名本身不含 /、
|
|
15
|
+
// 有的官方项整条没有 /(旧版内置项)——没有 / 时 provider 为 null:
|
|
16
|
+
// 补名没得补(调用方跳过),但还原还认得出模型名
|
|
17
|
+
function labelParts(label) {
|
|
18
|
+
const text = (label || '').trim();
|
|
19
|
+
if (!text) return null;
|
|
20
|
+
const i = text.indexOf('/');
|
|
21
|
+
if (i > 0) {
|
|
22
|
+
const provider = text.slice(0, i).trim();
|
|
23
|
+
const model = text.slice(i + 1).trim().split(/\s+/)[0];
|
|
24
|
+
return provider && model ? { provider, model } : null;
|
|
25
|
+
}
|
|
26
|
+
return { provider: null, model: text.split(/\s+/)[0] };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 模型名文本 span:官方结构是 外层 title 容器 > 内层 title 层 > 纯文本 span,
|
|
30
|
+
// 按“在最内层 title 层里、自己不带 title、没有子元素”识别;同级的
|
|
31
|
+
// “最高/开启”说明 span 不在 title 层里,不能碰(首版误把它也替换成全名)。
|
|
32
|
+
// 换模型时旧文本可能还在退场动画里没摘掉,按文本内容认目标:等于模型名
|
|
33
|
+
//(官方原文)、或以 “ / 模型名” 结尾(此前补过供应商名的文本)才算
|
|
34
|
+
function holdersOf(btn, model) {
|
|
35
|
+
const innermost = [...btn.querySelectorAll('span[title]')].filter((sp) => !sp.querySelector('span[title]'));
|
|
36
|
+
const holders = [];
|
|
37
|
+
for (const sp of innermost) {
|
|
38
|
+
for (const el of sp.querySelectorAll('span:not([title])')) {
|
|
39
|
+
if (el.querySelector('span')) continue;
|
|
40
|
+
const text = el.textContent.trim();
|
|
41
|
+
if (!text) continue;
|
|
42
|
+
if (text === model || text.endsWith(` / ${model}`)) holders.push(el);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return holders;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 改文本优先改文本节点本身:直接 textContent 覆盖会把应用持有的文本节点换成
|
|
49
|
+
// 新节点,它后续的更新就落不到可见文本上了
|
|
50
|
+
function setText(el, text) {
|
|
51
|
+
const node = el.firstChild;
|
|
52
|
+
if (node && node.nodeType === 3 && !node.nextSibling) node.nodeValue = text;
|
|
53
|
+
else el.textContent = text;
|
|
22
54
|
}
|
|
23
55
|
|
|
24
56
|
function apply() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (!model) continue;
|
|
35
|
-
for (const sp of btn.querySelectorAll('span[title]')) sp.setAttribute('title', model);
|
|
36
|
-
for (const el of btn.querySelectorAll('span[title] span:not([title])')) {
|
|
37
|
-
if (!el.querySelector('span') && el.textContent.includes('/')) el.textContent = model;
|
|
57
|
+
for (const btn of document.querySelectorAll(TRIGGER_SEL)) {
|
|
58
|
+
const parts = labelParts(btn.getAttribute('aria-label') || '');
|
|
59
|
+
if (!parts) continue;
|
|
60
|
+
const holders = holdersOf(btn, parts.model);
|
|
61
|
+
if (enabled) {
|
|
62
|
+
if (!parts.provider || !holders.length) continue;
|
|
63
|
+
const target = `${parts.provider} / ${parts.model}`;
|
|
64
|
+
for (const el of holders) {
|
|
65
|
+
if (el.textContent.trim() !== target) setText(el, target);
|
|
38
66
|
}
|
|
67
|
+
// title 跟显示文本一致,悬停可见全名
|
|
68
|
+
for (const sp of btn.querySelectorAll('span[title]')) {
|
|
69
|
+
if (sp.getAttribute('title') !== target) sp.setAttribute('title', target);
|
|
70
|
+
}
|
|
71
|
+
btn.dataset.zcodeproProviderShown = '1';
|
|
72
|
+
} else if (btn.dataset.zcodeproProviderShown) {
|
|
73
|
+
// 关闭时把补过的文本与 title 还原为官方模型名,不必等应用重渲染
|
|
74
|
+
for (const el of holders) {
|
|
75
|
+
if (el.textContent.trim() !== parts.model) setText(el, parts.model);
|
|
76
|
+
}
|
|
77
|
+
for (const sp of btn.querySelectorAll('span[title]')) sp.setAttribute('title', parts.model);
|
|
39
78
|
delete btn.dataset.zcodeproProviderShown;
|
|
40
79
|
}
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
for (const btn of document.querySelectorAll('[data-testid="chat-model-select-trigger"]')) {
|
|
44
|
-
// 只处理 a[data-composer-combined-model] 主触发器;aria-label 缺失时跳过
|
|
45
|
-
const label = btn.getAttribute('aria-label') || '';
|
|
46
|
-
const display = labelToDisplay(label);
|
|
47
|
-
if (!display) continue;
|
|
48
|
-
// 显示 span 是嵌套两层的 title 结构(外层裁剪容器 + 内层相对定位层),
|
|
49
|
-
// 文本都在最内层 span;只改文本与 title,不动结构
|
|
50
|
-
// 官方结构:外层 title 容器 > 内层 title 层 > 纯文本 span(模型名)。
|
|
51
|
-
// 只改 title 链内的文本——按“祖先带 title”识别模型名文本;同级的
|
|
52
|
-
// “最高/开启”说明 span(无 title 祖先链上的 title 层)不属于模型名,
|
|
53
|
-
// 不能碰(首版误把它也替换成全名)
|
|
54
|
-
const titleSpans = [...btn.querySelectorAll('span[title]')];
|
|
55
|
-
if (!titleSpans.length) continue;
|
|
56
|
-
const innermost = titleSpans.filter((sp) => !sp.querySelector('span[title]'));
|
|
57
|
-
if (!innermost.length) continue;
|
|
58
|
-
const holders = [];
|
|
59
|
-
for (const sp of innermost) {
|
|
60
|
-
sp.querySelectorAll('span:not([title])').forEach((el) => {
|
|
61
|
-
if (!el.querySelector('span') && el.textContent.trim() && !el.textContent.includes('/')) holders.push(el);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (!holders.length) continue;
|
|
65
|
-
for (const sp of titleSpans) {
|
|
66
|
-
if (sp.getAttribute('title') !== display) sp.setAttribute('title', display);
|
|
67
|
-
}
|
|
68
|
-
for (const el of holders) el.textContent = display;
|
|
69
|
-
btn.dataset.zcodeproProviderShown = '1';
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
export function startComposerProvider() {
|
|
74
84
|
if (installed || typeof document === 'undefined') return;
|
|
75
85
|
installed = true;
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
const COMPOSER_SEL = '[data-composer-layout], [data-composer-leading-content], [data-testid="chat-model-select-trigger"]';
|
|
86
|
+
// 先过滤再调度:无关变更直接忽略,连去抖定时器都不排——流式输出的高频
|
|
87
|
+
// 文本变更不会叫醒本模块
|
|
88
|
+
const COMPOSER_SEL = '[data-composer-layout], [data-composer-leading-actions], [data-composer-leading-content], [data-testid="chat-model-select-trigger"]';
|
|
79
89
|
const relevant = (muts) => {
|
|
80
90
|
for (const m of muts) {
|
|
81
91
|
if (m.type === 'childList') {
|
|
82
92
|
for (const n of [...m.addedNodes, ...m.removedNodes]) {
|
|
83
|
-
|
|
93
|
+
// 触发器内部的节点增删也算:换模型、开合下拉都把整段标签换成新节点,
|
|
94
|
+
// 那一批次里没有别的动静,漏掉就等不到下次补名
|
|
95
|
+
if (n instanceof Element && (n.matches?.(COMPOSER_SEL) || n.querySelector?.(COMPOSER_SEL) || n.closest?.(TRIGGER_SEL))) return true;
|
|
84
96
|
}
|
|
97
|
+
} else if (m.type === 'attributes') {
|
|
98
|
+
// 只认触发器按钮身上的属性(换模型就改它的 aria-label /
|
|
99
|
+
// data-model-current-value);同名模型换供应商时文本一动不动,全靠这里
|
|
100
|
+
if (m.target instanceof Element && m.target.closest?.(TRIGGER_SEL)) return true;
|
|
85
101
|
} else if (m.type === 'characterData') {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (el.matches?.('[data-composer-layout], [data-composer-leading-actions], [data-composer-leading-content]')) return true;
|
|
89
|
-
el = el.parentElement;
|
|
90
|
-
}
|
|
102
|
+
const el = m.target.parentElement?.closest?.(COMPOSER_SEL);
|
|
103
|
+
if (el) return true;
|
|
91
104
|
}
|
|
92
105
|
}
|
|
93
106
|
return false;
|
|
@@ -107,6 +120,12 @@ export function startComposerProvider() {
|
|
|
107
120
|
}).catch(() => {});
|
|
108
121
|
});
|
|
109
122
|
const observer = new MutationObserver((muts) => { if (enabled && relevant(muts)) schedule(); });
|
|
110
|
-
observer.observe(document.body, {
|
|
123
|
+
observer.observe(document.body, {
|
|
124
|
+
childList: true,
|
|
125
|
+
subtree: true,
|
|
126
|
+
characterData: true,
|
|
127
|
+
attributes: true,
|
|
128
|
+
attributeFilter: ['aria-label', 'data-model-current-value'], // 这两个只有应用会写,不认 title,避免自己改 title 叫醒自己
|
|
129
|
+
});
|
|
111
130
|
apply();
|
|
112
131
|
}
|
|
@@ -28,7 +28,7 @@ export async function appendCopyPathItem(menu, anchorItem, project) {
|
|
|
28
28
|
|
|
29
29
|
async function copyText(text) {
|
|
30
30
|
const L = t();
|
|
31
|
-
if (await copyToClipboard(text)) showToast(L.pathCopied);
|
|
31
|
+
if (await copyToClipboard(text)) showToast(L.pathCopied, 'success');
|
|
32
32
|
else showToast(L.pathCopyFailed, 'error');
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// 不用宿主 openInFileManager——其在 Linux/Windows 的实现只是 shell.openPath,即用默认应用打开)。
|
|
7
7
|
// 路径获取(按序尝试):触发器 title(文件 chip 右键场景,message.tsx 写入绝对路径)→
|
|
8
8
|
// 触发器/菜单的 React fiber props(OpenSplitButton 场景 target/fileLink/row.path)。
|
|
9
|
-
import { t, closeRadixMenu, itemsOf, itemText, rpc } from '../core.js';
|
|
9
|
+
import { t, closeRadixMenu, itemsOf, itemText, rpc, errText } from '../core.js';
|
|
10
10
|
import { getConfig } from '../core.js';
|
|
11
11
|
import { showToast } from '../ui.js';
|
|
12
12
|
|
|
@@ -58,7 +58,9 @@ function pathFromReactFiber(el) {
|
|
|
58
58
|
try {
|
|
59
59
|
const key = Object.keys(el).find((k) => k.startsWith('__reactFiber$'));
|
|
60
60
|
let fiber = key ? el[key] : null;
|
|
61
|
-
|
|
61
|
+
// 层数上限 100:预览卡片“打开 ▾”下拉的触发器到 OpenSplitButton(target.path)实测 41 层,
|
|
62
|
+
// Radix 的 provider/Slot 中间层多,40 会差一层拿不到路径
|
|
63
|
+
for (let i = 0; fiber && i < 100; i++, fiber = fiber.return) {
|
|
62
64
|
const props = fiber.memoizedProps;
|
|
63
65
|
if (!props || typeof props !== 'object') continue;
|
|
64
66
|
for (const k of ['target', 'fileLink', 'row']) {
|
|
@@ -130,7 +132,11 @@ export function handleFileMenu(content) {
|
|
|
130
132
|
// 打开失败(路径不存在等)弹 toast 报错,不再无声无息
|
|
131
133
|
const fire = (endpoint, label) => {
|
|
132
134
|
rpc(endpoint, { method: 'POST', body: { path } })
|
|
133
|
-
.then((r) => {
|
|
135
|
+
.then((r) => {
|
|
136
|
+
if (r && r.ok === false) {
|
|
137
|
+
showToast(L.fileActionFailed.replaceAll('{label}', label).replaceAll('{err}', errText(r) || L.unknownError), 'error');
|
|
138
|
+
}
|
|
139
|
+
})
|
|
134
140
|
.catch(() => { /* 网络异常时 helper 多半未运行,此时菜单不会注入,静默 */ });
|
|
135
141
|
};
|
|
136
142
|
// “默认应用打开”锚在编辑器列表末尾(无可用编辑器时即“未找到可用 App”禁用项)之上;
|
|
@@ -29,6 +29,13 @@ const blockUntil = new Map(); // 项目路径 → 此前不得再次回收的
|
|
|
29
29
|
let scanDisabledLogged = false;
|
|
30
30
|
const bootAt = Date.now(); // 注入时刻 ≈ 应用启动时刻
|
|
31
31
|
let startupSweepDone = false; // 启动一次性回收是否已执行
|
|
32
|
+
// 功能开关缓存成模块变量(config-changed 时更新):关闭时巡检早退,
|
|
33
|
+
// 不再每个周期发一次 getConfig,也不扫系统进程
|
|
34
|
+
let enabled = true;
|
|
35
|
+
|
|
36
|
+
// 项目路径比较前统一去掉尾部分隔符:wsRunningSnapshot().current 是行键原始
|
|
37
|
+
// 前缀(可带尾斜杠),候选路径已去尾分隔符,写法不同会被当成两个项目
|
|
38
|
+
const normP = (v) => String(v || '').replace(/[\\/]+$/, '');
|
|
32
39
|
|
|
33
40
|
|
|
34
41
|
// 项目清单改读 helper 的 /projects-v2(官方任务索引 projects/project_roots):
|
|
@@ -39,7 +46,7 @@ async function sidebarWorkspaces() {
|
|
|
39
46
|
if (res && res.ok && res.available) {
|
|
40
47
|
for (const proj of res.projects || []) {
|
|
41
48
|
for (const r of proj.roots || []) {
|
|
42
|
-
const p =
|
|
49
|
+
const p = normP(r.path);
|
|
43
50
|
if (p) out.add(p);
|
|
44
51
|
}
|
|
45
52
|
}
|
|
@@ -49,7 +56,10 @@ async function sidebarWorkspaces() {
|
|
|
49
56
|
|
|
50
57
|
async function reclaim(ws) {
|
|
51
58
|
const services = findServices();
|
|
52
|
-
if (!services)
|
|
59
|
+
if (!services) {
|
|
60
|
+
console.info('[zcodepro] idle-reclaim: 会话服务不可用,本轮不回收 ' + ws);
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
53
63
|
try {
|
|
54
64
|
// 应用内部的工作区键带尾分隔符(宿主日志可见),不带则键对不上、调用成空操作
|
|
55
65
|
await services.zcodeTaskService.releaseWorkspacePreparation({
|
|
@@ -76,16 +86,21 @@ async function tryReclaim(ws, cooldownMs) {
|
|
|
76
86
|
blockUntil.set(ws, Date.now() + cooldownMs); return;
|
|
77
87
|
}
|
|
78
88
|
// 复核要展开读行、网络请求也有耗时:期间用户可能已切到该项目,回收前再确认一次归属
|
|
79
|
-
const currentNow = wsRunningSnapshot().current;
|
|
80
|
-
if (!currentNow || currentNow === ws) { blockUntil.set(ws, Date.now() + cooldownMs); return; }
|
|
89
|
+
const currentNow = normP(wsRunningSnapshot().current);
|
|
90
|
+
if (!currentNow || currentNow === normP(ws)) { blockUntil.set(ws, Date.now() + cooldownMs); return; }
|
|
81
91
|
await reclaim(ws);
|
|
82
92
|
// 无论成败都冷却:失败退避重试;成功后用户再点开则进程重建、重新计时
|
|
83
93
|
blockUntil.set(ws, Date.now() + cooldownMs);
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
async function tick() {
|
|
97
|
+
if (!enabled) {
|
|
98
|
+
idleSince.clear();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
87
101
|
const cfg = await getConfig();
|
|
88
|
-
|
|
102
|
+
enabled = !cfg.features || cfg.features.idleReclaim !== false;
|
|
103
|
+
if (!enabled) {
|
|
89
104
|
idleSince.clear();
|
|
90
105
|
return;
|
|
91
106
|
}
|
|
@@ -102,15 +117,15 @@ async function tick() {
|
|
|
102
117
|
idleSince.clear();
|
|
103
118
|
return;
|
|
104
119
|
}
|
|
105
|
-
const busy = new Set(snap.running);
|
|
106
|
-
busy.add(snap.current);
|
|
120
|
+
const busy = new Set(snap.running.map(normP));
|
|
121
|
+
busy.add(normP(snap.current));
|
|
107
122
|
|
|
108
123
|
const workspaces = await sidebarWorkspaces();
|
|
109
124
|
for (const ws of [...idleSince.keys(), ...blockUntil.keys()]) {
|
|
110
125
|
if (!workspaces.has(ws)) { idleSince.delete(ws); blockUntil.delete(ws); }
|
|
111
126
|
}
|
|
112
127
|
|
|
113
|
-
const candidates = [...workspaces].filter((ws) => !busy.has(ws));
|
|
128
|
+
const candidates = [...workspaces].filter((ws) => !busy.has(normP(ws)));
|
|
114
129
|
const res = candidates.length
|
|
115
130
|
? await rpc('/idle-busy', { method: 'POST', body: { paths: candidates } })
|
|
116
131
|
: { ok: true, scan: true, busy: [] };
|
|
@@ -148,6 +163,14 @@ async function tick() {
|
|
|
148
163
|
}
|
|
149
164
|
|
|
150
165
|
export function startIdleReclaim() {
|
|
166
|
+
// 开关经设置弹窗改动时更新缓存(外部直接改配置文件不走这条路,靠下一轮
|
|
167
|
+
// tick 里的 getConfig 兜——但那要功能开着才会走到)
|
|
168
|
+
window.addEventListener('zcodepro:config-changed', () => {
|
|
169
|
+
void getConfig(true).then((cfg) => {
|
|
170
|
+
enabled = !cfg.features || cfg.features.idleReclaim !== false;
|
|
171
|
+
if (!enabled) idleSince.clear();
|
|
172
|
+
}).catch(() => {});
|
|
173
|
+
});
|
|
151
174
|
const loop = () => { tick().catch(() => { /* 单次巡检失败不影响后续 */ }); };
|
|
152
175
|
loop();
|
|
153
176
|
setInterval(loop, CHECK_MS);
|
|
@@ -116,11 +116,11 @@ async function copyImage(img, preBlob) {
|
|
|
116
116
|
if (!blob) throw new Error('empty image');
|
|
117
117
|
if (blob.type !== 'image/png') blob = await toPng(blob);
|
|
118
118
|
await navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);
|
|
119
|
-
showToast(L.imageCopied);
|
|
119
|
+
showToast(L.imageCopied, 'success');
|
|
120
120
|
} catch {
|
|
121
121
|
// 部分 Electron/Linux 组合上 navigator.clipboard 写图片报 DataError(写文本正常),
|
|
122
122
|
// 回退 execCommand:选中 <img> 后复制,Chromium 会把图片本体写入剪贴板
|
|
123
|
-
if (copyViaSelection(img)) showToast(L.imageCopied);
|
|
123
|
+
if (copyViaSelection(img)) showToast(L.imageCopied, 'success');
|
|
124
124
|
else showToast(L.imageCopyFailed, 'error');
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -54,7 +54,11 @@ function findOpenSidePane() {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// pluginUiBridgeService(listSurfaces 数据源)
|
|
57
|
+
// 找不到也记退避时间戳:fiber 全遍历(上限 20 万节点)每 5 秒重走一遍太贵,
|
|
58
|
+
// 60 秒后再试(bridge 随应用启动就绪,晚到超过一分钟的场景很少)
|
|
59
|
+
let bridgeMissAt = 0;
|
|
57
60
|
function findBridge() {
|
|
61
|
+
if (bridgeMissAt && Date.now() - bridgeMissAt < 60_000) return null;
|
|
58
62
|
let holder = null;
|
|
59
63
|
const seen = new Set();
|
|
60
64
|
const scan = (o) => {
|
|
@@ -74,6 +78,7 @@ function findBridge() {
|
|
|
74
78
|
}
|
|
75
79
|
return false;
|
|
76
80
|
});
|
|
81
|
+
if (!holder) bridgeMissAt = Date.now();
|
|
77
82
|
return holder;
|
|
78
83
|
}
|
|
79
84
|
|
|
@@ -170,8 +175,13 @@ async function injectPanels(grid) {
|
|
|
170
175
|
ev.stopPropagation();
|
|
171
176
|
const sc = sessionScope();
|
|
172
177
|
const open = findOpenSidePane();
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
// 打开函数找不到与没有会话是两回事,提示分开,别都说成“需要会话”
|
|
179
|
+
if (!open) {
|
|
180
|
+
showToast(L.ntpOpenMissing, 'warning');
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (!sc) {
|
|
184
|
+
showToast(L.ntpNeedSession, 'warning');
|
|
175
185
|
return;
|
|
176
186
|
}
|
|
177
187
|
try {
|
|
@@ -189,7 +199,7 @@ async function injectPanels(grid) {
|
|
|
189
199
|
});
|
|
190
200
|
} catch (e) {
|
|
191
201
|
console.warn('[zcodepro] 打开插件面板失败', e);
|
|
192
|
-
showToast(L.ntpNeedSession, '
|
|
202
|
+
showToast(L.ntpNeedSession, 'warning');
|
|
193
203
|
}
|
|
194
204
|
});
|
|
195
205
|
grid.append(card);
|
|
@@ -16,9 +16,12 @@ let enabled = true; // 配置开关(features.pinnedCollapse !== false)
|
|
|
16
16
|
let syncTimer = 0;
|
|
17
17
|
|
|
18
18
|
// 已置顶标题的识别不依赖文案(跟随界面语言):h3 的下一个兄弟是含任务行的
|
|
19
|
-
// 列表容器——3.15.x 是 UL,3.16.1 起是 DIV
|
|
19
|
+
// 列表容器——3.15.x 是 UL,3.16.1 起是 DIV,不限定标签。
|
|
20
|
+
// 聊天正文里的 markdown 标题也是 h3(ws-running.js 的 sectionHeads 同款排除),
|
|
21
|
+
// 不排除会把折叠开关插进聊天内容
|
|
20
22
|
function findPinnedHeader() {
|
|
21
23
|
for (const h3 of document.querySelectorAll('h3')) {
|
|
24
|
+
if (h3.closest('main')) continue;
|
|
22
25
|
const list = h3.nextElementSibling;
|
|
23
26
|
if (list && list.querySelector('li[data-task-item-key]')) return h3;
|
|
24
27
|
}
|
|
@@ -69,8 +72,13 @@ function apply() {
|
|
|
69
72
|
return true;
|
|
70
73
|
}
|
|
71
74
|
h3.classList.add(HEAD_CLASS);
|
|
72
|
-
//
|
|
73
|
-
|
|
75
|
+
// 整行可点(与“项目”分区头一致);开关禁用后旧监听变空转,无需摘除。
|
|
76
|
+
// dataset 防重:React 清掉注入的按钮后本函数重跑,监听器叠加会让一次点击
|
|
77
|
+
// 触发多次折叠切换
|
|
78
|
+
if (!h3.dataset.zcodeproPinHead) {
|
|
79
|
+
h3.dataset.zcodeproPinHead = '1';
|
|
80
|
+
h3.addEventListener('click', () => { if (enabled) toggle(); });
|
|
81
|
+
}
|
|
74
82
|
const btn = h('button', {
|
|
75
83
|
type: 'button',
|
|
76
84
|
class: 'zcodepro-pin-chevron',
|