zcode-pro 1.6.1 → 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 +31 -21
- package/README.md +20 -12
- package/dist/inject.js +10431 -8836
- package/package.json +2 -1
- package/src/host/cdp.mjs +13 -3
- package/src/host/helper.mjs +1287 -488
- package/src/host/main.mjs +368 -30
- 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 +54 -15
- package/src/host/skill-stats.mjs +6 -1
- package/src/host/taskIndex.mjs +464 -66
- package/src/host/taskOrder.mjs +128 -57
- package/src/host/version.mjs +15 -7
- package/src/host/wallpaper.mjs +76 -59
- package/src/host/webdav.mjs +66 -10
- package/src/inject/core.js +228 -103
- package/src/inject/features/alias-migration.js +5 -1
- package/src/inject/features/auto-rename.js +166 -0
- package/src/inject/features/file-menu.js +6 -2
- package/src/inject/features/idle-reclaim.js +31 -8
- package/src/inject/features/newtab-panels.js +11 -1
- package/src/inject/features/pinned-collapse.js +11 -3
- package/src/inject/features/plugin-card-retry.js +18 -8
- package/src/inject/features/plugin-updates.js +58 -0
- package/src/inject/features/sandbox-reclaim.js +17 -1
- package/src/inject/features/session-link.js +202 -0
- package/src/inject/features/session-switch.js +67 -30
- package/src/inject/features/settings-dialog.js +323 -124
- package/src/inject/features/status-bar.js +150 -28
- package/src/inject/features/subagent-icon.js +473 -0
- package/src/inject/features/table-copy.js +18 -2
- package/src/inject/features/task-order.js +47 -13
- package/src/inject/features/theme.js +88 -31
- 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 +99 -47
- package/src/inject/features/ws-running.js +28 -13
- package/src/inject/index.js +7 -0
- package/src/inject/provider-fields.js +2 -2
- package/src/inject/ui.js +14 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// 会话 ID 显示为任务名链接:把提问与回答文本里的 sess_xxx / session_xxx 渲染成
|
|
2
|
+
// 任务名链接,点击切到对应会话。任务名优先取侧栏行标题,行不在场(项目折叠等)
|
|
3
|
+
// 时按 id 批量查任务索引(/task-statuses);查不到名字就保留原 ID 文本,仍然可点。
|
|
4
|
+
// 只改纯文本节点:代码块/链接/按钮/输入框/自家已处理节点不动;流式输出中的行
|
|
5
|
+
// 先跳过(文本还在变,等渲染完成后整行补处理),避免与应用重绘互相干扰。
|
|
6
|
+
import { rpc, t, getConfig } from '../core.js';
|
|
7
|
+
import { ensureStyle, showToast } from '../ui.js';
|
|
8
|
+
|
|
9
|
+
const CONV = '[class*="@md/conversation"]';
|
|
10
|
+
// contenteditable 也要跳过:行内编辑用的是 Lexical 托管 DOM,改它里面的文本节点会被
|
|
11
|
+
// Lexical 删掉再插回,两边来回触发会让页面卡死(消息里带会话 ID 时必现)
|
|
12
|
+
const SKIP_SEL = 'pre, code, a, button, input, textarea, select, [contenteditable], [data-zcodepro-sess]';
|
|
13
|
+
// 会话 id:sess_ 与 session_ 两种前缀(新版应用为 session_),尾字符必须是
|
|
14
|
+
// 字母数字(防止把 "session_xxx-" 里说明文字的连字符吞进来)
|
|
15
|
+
const SESS_RE = /(?<![A-Za-z0-9_])(?:session|sess)_[A-Za-z0-9][A-Za-z0-9_-]*[A-Za-z0-9]/g;
|
|
16
|
+
|
|
17
|
+
// 纯文本里找出会话 ID 的位置(自检脚本直接断言它);每次重置游标保证重复调用安全
|
|
18
|
+
export function matchIds(text) {
|
|
19
|
+
SESS_RE.lastIndex = 0;
|
|
20
|
+
const out = [];
|
|
21
|
+
for (let m; (m = SESS_RE.exec(text));) {
|
|
22
|
+
out.push({ start: m.index, end: m.index + m[0].length, id: m[0] });
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let installed = false;
|
|
28
|
+
let enabled = true;
|
|
29
|
+
const titleCache = new Map(); // 会话 id → 任务名(查过一次就不再查)
|
|
30
|
+
const TITLE_CACHE_MAX = 500;
|
|
31
|
+
const pendingIds = new Set(); // 扫到但还没查过名字的 id
|
|
32
|
+
let fetchTimer = 0;
|
|
33
|
+
// 处理过的文本节点记下来(确认没有会话 id 或在跳过区的):流式输出期间反复
|
|
34
|
+
// 重扫时跳过它们,不再逐个跑正则。文本改动会让标记作废(观察器里删标记)
|
|
35
|
+
const doneNodes = new WeakSet();
|
|
36
|
+
const streamingRows = new Set(); // 流式输出中跳过的回答行:渲染完成后整行补处理
|
|
37
|
+
|
|
38
|
+
function makeLink(id) {
|
|
39
|
+
const span = document.createElement('span');
|
|
40
|
+
span.className = 'zcodepro-sess-link';
|
|
41
|
+
span.dataset.zcodeproSess = id;
|
|
42
|
+
span.title = id; // 悬停看原始 ID
|
|
43
|
+
span.textContent = titleCache.get(id) || id;
|
|
44
|
+
return span;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function processTextNode(node) {
|
|
48
|
+
if (!node || doneNodes.has(node)) return;
|
|
49
|
+
const text = node.textContent || '';
|
|
50
|
+
if (!text.includes('sess')) { doneNodes.add(node); return; }
|
|
51
|
+
const el = node.parentElement;
|
|
52
|
+
if (!el || el.closest(SKIP_SEL)) { doneNodes.add(node); return; }
|
|
53
|
+
// 流式输出中的行文本还在变,等渲染完成再处理(不记已处理,行收尾时补)
|
|
54
|
+
const row = el.closest('[class*="-row"]');
|
|
55
|
+
if (row && row.querySelector('[data-is-streaming]')) { streamingRows.add(row); return; }
|
|
56
|
+
const ms = matchIds(text);
|
|
57
|
+
if (!ms.length) { doneNodes.add(node); return; }
|
|
58
|
+
doneNodes.add(node);
|
|
59
|
+
const frag = document.createDocumentFragment();
|
|
60
|
+
let pos = 0;
|
|
61
|
+
for (const m of ms) {
|
|
62
|
+
if (m.start > pos) frag.append(document.createTextNode(text.slice(pos, m.start)));
|
|
63
|
+
if (!titleCache.has(m.id) && !pendingIds.has(m.id)) pendingIds.add(m.id);
|
|
64
|
+
frag.append(makeLink(m.id));
|
|
65
|
+
pos = m.end;
|
|
66
|
+
}
|
|
67
|
+
if (pos < text.length) frag.append(document.createTextNode(text.slice(pos)));
|
|
68
|
+
node.replaceWith(frag);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 收集子树里的文本节点(先收集再处理:边走边替换会漏掉刚换出来的节点)
|
|
72
|
+
function walkTexts(root, out) {
|
|
73
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
74
|
+
for (let n; (n = walker.nextNode());) out.push(n);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 流式结束的行补处理:结束信号([data-is-streaming] 摘除)本身是一次 DOM 变动,
|
|
78
|
+
// 观察器回调里调到这里检查;行已经不在 DOM 就出队
|
|
79
|
+
function flushStreamingRows() {
|
|
80
|
+
if (!streamingRows.size) return;
|
|
81
|
+
const nodes = [];
|
|
82
|
+
for (const row of [...streamingRows]) {
|
|
83
|
+
if (!row.isConnected) { streamingRows.delete(row); continue; }
|
|
84
|
+
if (row.querySelector('[data-is-streaming]')) continue;
|
|
85
|
+
streamingRows.delete(row);
|
|
86
|
+
walkTexts(row, nodes);
|
|
87
|
+
}
|
|
88
|
+
for (const n of nodes) processTextNode(n);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function scan() {
|
|
92
|
+
const nodes = [];
|
|
93
|
+
for (const conv of document.querySelectorAll(CONV)) walkTexts(conv, nodes);
|
|
94
|
+
for (const n of nodes) processTextNode(n);
|
|
95
|
+
flushStreamingRows();
|
|
96
|
+
queueTitleFetch();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 名字批量查任务索引(节流合并一次扫描里的多个 id)
|
|
100
|
+
function queueTitleFetch() {
|
|
101
|
+
if (fetchTimer || !pendingIds.size) return;
|
|
102
|
+
fetchTimer = setTimeout(() => {
|
|
103
|
+
fetchTimer = 0;
|
|
104
|
+
const ids = [...pendingIds];
|
|
105
|
+
pendingIds.clear();
|
|
106
|
+
void fetchTitles(ids);
|
|
107
|
+
}, 500);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 查不到/查失败都不再重试,等下一次整页重新扫描(如刷新)再查
|
|
111
|
+
async function fetchTitles(ids) {
|
|
112
|
+
const st = await rpc('/task-statuses?ids=' + encodeURIComponent(ids.join(','))).catch(() => null);
|
|
113
|
+
if (!st || !st.ok || !st.available || !st.statuses) return;
|
|
114
|
+
for (const id of ids) {
|
|
115
|
+
const rec = st.statuses[id];
|
|
116
|
+
if (rec && rec.title) {
|
|
117
|
+
const title = String(rec.title);
|
|
118
|
+
titleCache.set(id, title);
|
|
119
|
+
// 标题缓存只增不减会慢慢攒内存(session-switch.js 的 titles 同款问题):
|
|
120
|
+
// 超上限删最旧的(Map 迭代序即插入序),删掉的 id 之后再扫到会重新查名
|
|
121
|
+
while (titleCache.size > TITLE_CACHE_MAX) titleCache.delete(titleCache.keys().next().value);
|
|
122
|
+
for (const span of document.querySelectorAll(`[data-zcodepro-sess="${CSS.escape(id)}"]`)) {
|
|
123
|
+
span.textContent = title;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 关闭功能时把已渲染的链接还原成纯 ID 文本(disable 后不留可点的残留)
|
|
130
|
+
function unwrapAll() {
|
|
131
|
+
for (const span of [...document.querySelectorAll('[data-zcodepro-sess]')]) {
|
|
132
|
+
span.replaceWith(document.createTextNode(span.getAttribute('data-zcodepro-sess') || ''));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function setEnabled(cfg) {
|
|
137
|
+
const next = cfg.features ? cfg.features.sessionLink !== false : true;
|
|
138
|
+
if (enabled && !next) unwrapAll();
|
|
139
|
+
enabled = next;
|
|
140
|
+
// 刚打开开关时会话区没有变动,补一次扫描才能立刻出链接(此时全量扫正是必要时机)
|
|
141
|
+
if (next) scan();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 只有会话容器内的变动才值得处理:侧栏/弹窗等高频变动在此滤掉
|
|
145
|
+
const inConv = (el) => !!(el && el.closest && el.closest(CONV));
|
|
146
|
+
|
|
147
|
+
export function startSessionLink() {
|
|
148
|
+
if (installed || typeof document === 'undefined') return;
|
|
149
|
+
installed = true;
|
|
150
|
+
ensureStyle();
|
|
151
|
+
void getConfig().then(setEnabled).catch(() => {});
|
|
152
|
+
window.addEventListener('zcodepro:config-changed', () => {
|
|
153
|
+
void getConfig(true).then(setEnabled).catch(() => {});
|
|
154
|
+
});
|
|
155
|
+
scan();
|
|
156
|
+
// 观察器优先做定向处理:只跑变动涉及的文本节点(新增子树、改动的文本),
|
|
157
|
+
// 不再每 300ms 全量重扫整个会话容器;只有会话容器整块换新(首次、切视图)
|
|
158
|
+
// 才全量扫一次。流式输出期间的高频变动在这里被压成逐节点的轻检查
|
|
159
|
+
new MutationObserver((muts) => {
|
|
160
|
+
const texts = [];
|
|
161
|
+
let structural = false;
|
|
162
|
+
for (const m of muts) {
|
|
163
|
+
if (m.type === 'characterData') {
|
|
164
|
+
// 文本改过:已处理标记作废。开关关着也做,重新打开时标记不失真
|
|
165
|
+
doneNodes.delete(m.target);
|
|
166
|
+
if (enabled && inConv(m.target.parentElement)) texts.push(m.target);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
for (const n of m.addedNodes) {
|
|
170
|
+
if (!enabled) continue;
|
|
171
|
+
if (n.nodeType === Node.TEXT_NODE) {
|
|
172
|
+
if (inConv(n.parentElement)) texts.push(n);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (!(n instanceof Element) || !n.closest) continue;
|
|
176
|
+
if (n.matches(CONV) || n.querySelector(CONV)) { structural = true; continue; }
|
|
177
|
+
if (inConv(n) && !n.closest(SKIP_SEL)) walkTexts(n, texts);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (!enabled) return;
|
|
181
|
+
if (structural) { scan(); return; }
|
|
182
|
+
for (const t of texts) processTextNode(t);
|
|
183
|
+
flushStreamingRows();
|
|
184
|
+
queueTitleFetch();
|
|
185
|
+
}).observe(document.body, { childList: true, subtree: true, characterData: true });
|
|
186
|
+
|
|
187
|
+
// 点击事件委托给 document:应用重绘换掉链接节点也不影响后续点击
|
|
188
|
+
document.addEventListener('click', (e) => {
|
|
189
|
+
const span = e.target instanceof Element && e.target.closest('[data-zcodepro-sess]');
|
|
190
|
+
if (!span || !enabled) return;
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
e.stopPropagation();
|
|
193
|
+
const id = span.getAttribute('data-zcodepro-sess') || '';
|
|
194
|
+
// 行在场就用行的真实键(键形带尾斜杠也能命中);不在场按 id 兜底找
|
|
195
|
+
const row = document.querySelector(`[data-task-item-key$=":${CSS.escape(id)}"]`);
|
|
196
|
+
const key = row ? row.getAttribute('data-task-item-key') : `:${id}`;
|
|
197
|
+
// switchTo 动态引入:本文件的自检只测纯函数,别把测试牵进会话切换的 DOM 依赖
|
|
198
|
+
void import('./session-switch.js')
|
|
199
|
+
.then((m) => m.switchTo(key))
|
|
200
|
+
.then((ok) => { if (!ok) showToast(t().switcherFailed, 'error'); });
|
|
201
|
+
});
|
|
202
|
+
}
|
|
@@ -23,6 +23,7 @@ let mru = []; // 会话键(data-task-item-key),最近使用的在
|
|
|
23
23
|
let current = null; // 当前会话键
|
|
24
24
|
let titles = new Map(); // 键 → 会话标题(展示缓存;条目在 DOM 时实时读取)
|
|
25
25
|
let popupEl = null; // 打开的切换弹窗(null = 未打开)
|
|
26
|
+
let popupList = null; // 弹窗打开时的列表快照(null = 弹窗未打开)
|
|
26
27
|
let aliasesCache = {}; // 项目路径 → 别名(打开弹窗时预取,renderPopup 同步使用)
|
|
27
28
|
let highlight = 0;
|
|
28
29
|
let scanDebounce = 0;
|
|
@@ -33,8 +34,10 @@ let lastRunKeys = null; // 上次采样的运行键集合(用于识别“运
|
|
|
33
34
|
// 键位(alt+字母/数字):默认见 core.js,可在设置 → 快捷键修改;
|
|
34
35
|
// 设置保存时会派发 zcodepro:config-changed,这里刷新缓存
|
|
35
36
|
let hotkeys = { ...DEFAULT_SHORTCUTS };
|
|
37
|
+
let featureOn = true; // features.sessionSwitch 的同步缓存:键按下时先判再拦截
|
|
36
38
|
function loadHotkeys() {
|
|
37
39
|
return getConfig(true).then((cfg) => {
|
|
40
|
+
featureOn = !(cfg.features && cfg.features.sessionSwitch === false);
|
|
38
41
|
const sc = cfg && cfg.shortcuts;
|
|
39
42
|
if (sc && typeof sc === 'object') {
|
|
40
43
|
for (const k of Object.keys(DEFAULT_SHORTCUTS)) {
|
|
@@ -58,15 +61,18 @@ function workspaceOf(key) {
|
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
function findCurrent() {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
64
|
+
// 交给选择器引擎找选中行(比全表扫 className 快,语义相同)
|
|
65
|
+
return document.querySelector('[data-task-item-key].bg-selected');
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
// 会话 id(键的最后一段):同一会话的键有“权威拼键/DOM 行键”两种形态,
|
|
69
|
+
// unseen 的增删与当前会话比较都按 id,别按整键。入参容 null/undefined——
|
|
70
|
+
// current 在新建任务视图(无选中行)时一直是 null
|
|
71
|
+
const idOf = (k) => { const s = String(k || ''); return s.slice(s.lastIndexOf(':') + 1); };
|
|
72
|
+
|
|
67
73
|
// 记录一次“切到 key”;顺带刷新在场条目的标题缓存。切入即视为已查看
|
|
68
74
|
function record(key) {
|
|
69
|
-
if (key) unseen.delete(
|
|
75
|
+
if (key) for (const k of unseen) if (idOf(k) === idOf(key)) unseen.delete(k);
|
|
70
76
|
if (key && key !== current) {
|
|
71
77
|
current = key;
|
|
72
78
|
mru = mru.filter((k) => k !== key);
|
|
@@ -75,13 +81,41 @@ function record(key) {
|
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
|
|
84
|
+
// “运行结束记未查看”的判定(10 秒采样定时器每轮调用):对比上一轮运行键集合
|
|
85
|
+
// prevKeys 与本轮 nowKeys,从运行集合消失(转终态)且结束时不是当前会话的键
|
|
86
|
+
// 并入 unseen 集合。按会话 id 判“消失”——同一会话的键形会随行挂载/卸载在
|
|
87
|
+
// “权威拼的键”与“DOM 行键”之间切换,按整键比较会把键形切换误判成运行结束,
|
|
88
|
+
// 生成一行点不动的“未查看”幽灵行;当前查看中的会话同样按 id 排除,currentKey
|
|
89
|
+
// 容 null/undefined(新建任务视图无选中行)。超上限留最近 UNSEEN_LIMIT 条。
|
|
90
|
+
// 返回处理后的新 unseen 集合(不改入参);从 setInterval 抽成具名函数供测试截取
|
|
91
|
+
function collectEndedUnseen(prevKeys, nowKeys, currentKey, unseenSet) {
|
|
92
|
+
const out = new Set(unseenSet);
|
|
93
|
+
if (prevKeys) {
|
|
94
|
+
const nowIds = new Set([...nowKeys].map(idOf));
|
|
95
|
+
const curId = currentKey == null ? '' : idOf(currentKey);
|
|
96
|
+
for (const k of prevKeys) {
|
|
97
|
+
if (!nowIds.has(idOf(k)) && idOf(k) !== curId) out.add(k);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return out.size > UNSEEN_LIMIT ? new Set([...out].slice(-UNSEEN_LIMIT)) : out;
|
|
101
|
+
}
|
|
102
|
+
|
|
78
103
|
// 扫描:bg-selected 标记识别当前会话(新建任务自动跳转等非点击切换也能捕捉);
|
|
79
104
|
// 标记缺失时由点击兜底记录。顺带刷新在场条目的标题缓存
|
|
80
105
|
function scan() {
|
|
81
106
|
const cur = findCurrent();
|
|
82
107
|
if (cur) record(cur.getAttribute('data-task-item-key'));
|
|
108
|
+
const seen = new Set();
|
|
83
109
|
for (const el of document.querySelectorAll('[data-task-item-key]')) {
|
|
84
|
-
|
|
110
|
+
const key = el.getAttribute('data-task-item-key');
|
|
111
|
+
seen.add(key);
|
|
112
|
+
titles.set(key, firstLineOf(el));
|
|
113
|
+
}
|
|
114
|
+
// 标题缓存兜底清理:会话键只增不减会慢慢攒内存;保留弹窗要用的(最近使用 +
|
|
115
|
+
// 当前在场),删掉的以后要用会按“无缓存”重新取
|
|
116
|
+
if (titles.size > 500) {
|
|
117
|
+
const keep = new Set([...seen, current, ...mru, ...(popupList || []), ...unseen]);
|
|
118
|
+
for (const k of titles.keys()) if (!keep.has(k)) titles.delete(k);
|
|
85
119
|
}
|
|
86
120
|
}
|
|
87
121
|
|
|
@@ -113,7 +147,8 @@ function scheduleScan() {
|
|
|
113
147
|
}
|
|
114
148
|
|
|
115
149
|
// 切到指定会话:条目不在 DOM(项目折叠)时先展开项目行,等条目出现再点击
|
|
116
|
-
|
|
150
|
+
//(session-link.js 的会话 ID 链接也走这里切换)
|
|
151
|
+
export async function switchTo(key) {
|
|
117
152
|
// 权威扫描拼出的键(工作区前缀无尾斜杠)可能与行键(可能带尾斜杠)不同形,
|
|
118
153
|
// 精确匹配落空时按会话 id 后缀兜底(会话 id 全局唯一,不会命中别的会话)
|
|
119
154
|
const id = key.slice(key.lastIndexOf(':') + 1);
|
|
@@ -147,7 +182,6 @@ async function switchTo(key) {
|
|
|
147
182
|
// 判定才是“运行中”,点击也命中在场行)
|
|
148
183
|
function attentionList() {
|
|
149
184
|
const run = wsRunningKeys();
|
|
150
|
-
const idOf = (k) => k.slice(k.lastIndexOf(':') + 1);
|
|
151
185
|
const runKeyById = new Map([...run].map((k) => [idOf(k), k]));
|
|
152
186
|
const listed = new Set();
|
|
153
187
|
const head = [];
|
|
@@ -164,9 +198,12 @@ function attentionList() {
|
|
|
164
198
|
return [...head, ...tail];
|
|
165
199
|
}
|
|
166
200
|
|
|
167
|
-
// 弹窗当前列表:普通模式为 MRU 全量;attention 模式为运行中 +
|
|
201
|
+
// 弹窗当前列表:普通模式为 MRU 全量;attention 模式为运行中 + 未查看。
|
|
202
|
+
// 弹窗开着期间 10 秒采样定时器会增删“运行中/未查看”条目、点击记录会改 MRU,
|
|
203
|
+
// 用实时列表对渲染时的高亮下标取目标会错位切错会话——打开时存下快照,
|
|
204
|
+
// 移动与提交一律用它,弹窗关闭即丢弃
|
|
168
205
|
function activeList() {
|
|
169
|
-
return popupMode === 'attention' ? attentionList() : mru;
|
|
206
|
+
return popupList || (popupMode === 'attention' ? attentionList() : mru);
|
|
170
207
|
}
|
|
171
208
|
|
|
172
209
|
function closePopup(commit) {
|
|
@@ -175,6 +212,7 @@ function closePopup(commit) {
|
|
|
175
212
|
const list = activeList();
|
|
176
213
|
popupEl.remove();
|
|
177
214
|
popupEl = null;
|
|
215
|
+
popupList = null;
|
|
178
216
|
if (commit && list[idx] && list[idx] !== current) {
|
|
179
217
|
void switchTo(list[idx]).then((ok) => { if (!ok) showToast(t().switcherFailed, 'error'); });
|
|
180
218
|
}
|
|
@@ -256,10 +294,13 @@ async function openPopupInner(mode) {
|
|
|
256
294
|
popupMode = mode;
|
|
257
295
|
visibleCount = INITIAL_COUNT;
|
|
258
296
|
highlight = 0;
|
|
297
|
+
popupList = null;
|
|
259
298
|
const cfg = await getConfig().catch(() => null);
|
|
260
299
|
aliasesCache = (cfg && cfg.aliases && typeof cfg.aliases === 'object') ? cfg.aliases : {};
|
|
261
300
|
// attention 模式的行可能整段来自权威扫描(折叠项目),先补齐它们的标题再渲染
|
|
262
301
|
if (mode === 'attention') await fetchMissingTitles(attentionList()).catch(() => {});
|
|
302
|
+
// 快照定格在这一刻的列表(渲染、移动、提交共用,见 activeList 注释)
|
|
303
|
+
popupList = activeList();
|
|
263
304
|
ensureStyle();
|
|
264
305
|
const L = t();
|
|
265
306
|
popupEl = h('div', {
|
|
@@ -320,23 +361,14 @@ export function startSessionSwitch() {
|
|
|
320
361
|
document.addEventListener('visibilitychange', () => { if (!document.hidden) scan(); });
|
|
321
362
|
|
|
322
363
|
// “运行完未查看”跟踪:周期采样运行键集合(ws-running 维护的实时状态),
|
|
323
|
-
//
|
|
324
|
-
//
|
|
364
|
+
// 判定规则在 collectEndedUnseen(键形切换不算结束、当前会话不记、超上限截尾,
|
|
365
|
+
// 见其注释)。用户切入该会话(record)即清除。注入前已结束的任务无从判定,
|
|
366
|
+
// 不追溯
|
|
325
367
|
setInterval(() => {
|
|
326
368
|
if (document.hidden) return;
|
|
327
369
|
const now = wsRunningKeys();
|
|
328
|
-
|
|
329
|
-
// 按会话 id 判“从运行集合消失”:同一会话的键形会随行挂载/卸载在
|
|
330
|
-
// “权威拼的键”与“DOM 行键”之间切换,按整键比较会把键形切换误判成
|
|
331
|
-
// 运行结束,生成一行点不动的“未查看”幽灵行
|
|
332
|
-
const idOf = (k) => k.slice(k.lastIndexOf(':') + 1);
|
|
333
|
-
const nowIds = new Set([...now].map(idOf));
|
|
334
|
-
for (const k of lastRunKeys) {
|
|
335
|
-
if (!nowIds.has(idOf(k)) && k !== current) unseen.add(k);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
370
|
+
unseen = collectEndedUnseen(lastRunKeys, now, current, unseen);
|
|
338
371
|
lastRunKeys = now;
|
|
339
|
-
if (unseen.size > UNSEEN_LIMIT) unseen = new Set([...unseen].slice(-UNSEEN_LIMIT));
|
|
340
372
|
}, 10_000);
|
|
341
373
|
|
|
342
374
|
// 点击兜底:bg-selected 标记不可用/未出现时,点条目(含本功能派发的合成点击)即记录
|
|
@@ -380,6 +412,8 @@ export function startSessionSwitch() {
|
|
|
380
412
|
const isHot = k === hotkeys.switchLast || k === hotkeys.switchPrev || k === hotkeys.switchNext
|
|
381
413
|
|| k === hotkeys.switchRecent || k === hotkeys.switchAttention;
|
|
382
414
|
if (!isHot) return;
|
|
415
|
+
// 功能关闭时不拦截按键(先同步判再 preventDefault,别吞掉应用自己的键位)
|
|
416
|
+
if (!featureOn) return;
|
|
383
417
|
e.preventDefault();
|
|
384
418
|
e.stopImmediatePropagation();
|
|
385
419
|
void (async () => {
|
|
@@ -412,14 +446,17 @@ export function startSessionSwitch() {
|
|
|
412
446
|
await openPopup('attention');
|
|
413
447
|
return;
|
|
414
448
|
}
|
|
415
|
-
// e
|
|
416
|
-
//
|
|
417
|
-
//
|
|
449
|
+
// e 打开最近 10 条(c 可继续加载更早的)。attention 弹窗(r)开着时切到
|
|
450
|
+
// 最近列表(关掉重开,与 r 在 mru 弹窗开着时的行为对称);mru 已开着则
|
|
451
|
+
// 不动作。只在 mru 为空(连当前会话都没有,如停在新建任务页)才提示——
|
|
452
|
+
// 首次仅开着当前会话时照常打开,列表里就是它这一条
|
|
418
453
|
if (k === hotkeys.switchRecent) {
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
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');
|
|
423
460
|
return;
|
|
424
461
|
}
|
|
425
462
|
// x/c:弹窗已开着(含 attention 模式)直接在当前列表移动——attention 的
|