zcode-pro 1.8.0 → 1.8.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 +38 -28
- package/README.md +43 -33
- package/dist/inject.js +549 -59
- package/package.json +1 -1
- package/src/host/helper.mjs +39 -4
- package/src/host/main.mjs +27 -12
- package/src/host/wallpaper.mjs +3 -1
- package/src/inject/core.js +16 -4
- package/src/inject/features/composer-edit-model.js +312 -0
- package/src/inject/features/settings-dialog.js +13 -2
- package/src/inject/features/status-bar.js +59 -8
- package/src/inject/features/styles.js +70 -30
- package/src/inject/features/theme.js +53 -12
- package/src/inject/features/ws-running.js +68 -12
- package/src/inject/index.js +2 -0
- package/src/inject/ui.js +12 -2
|
@@ -9,6 +9,10 @@ import { ensureStyle } from '../ui.js';
|
|
|
9
9
|
let enabled = true;
|
|
10
10
|
let items = DEFAULT_STATUS_ITEMS.map((x) => ({ ...x }));
|
|
11
11
|
let barEl = null;
|
|
12
|
+
let liftedPane = null; // 为状态栏让出底部空间而加过 margin-bottom 的滚动容器
|
|
13
|
+
// 状态栏区域只有输入框下的官方留白时上下一共 3px,太挤:把滚动容器底再抬
|
|
14
|
+
// 10px(输入框随之上移),状态栏上下留白各约 8px
|
|
15
|
+
const BAR_LIFT = 10;
|
|
12
16
|
let lastStats = null; // /stats/usage 响应缓存(失败保旧值)
|
|
13
17
|
let lastSid = null; // 上次取数的会话 id:切换会话即作废缓存,不显示上个会话的速率
|
|
14
18
|
let statsSid = null; // lastStats 取数时的会话 id:渲染时对不上就不用(切会话瞬间不顶旧值)
|
|
@@ -293,6 +297,15 @@ function itemContent(id, L) {
|
|
|
293
297
|
}
|
|
294
298
|
}
|
|
295
299
|
|
|
300
|
+
// 输入框所在的滚动容器:会话视图里输入框区是 sticky 在聊天滚动容器底部的,
|
|
301
|
+
// 容器下边缘之外的像素会被裁掉。状态栏挤在输入框后面时,滚一下就被裁没。
|
|
302
|
+
function clipPane(el) {
|
|
303
|
+
for (let n = el.parentElement; n && n !== document.body; n = n.parentElement) {
|
|
304
|
+
if (/(auto|scroll|hidden)/.test(getComputedStyle(n).overflowY)) return n;
|
|
305
|
+
}
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
|
|
296
309
|
function renderBar() {
|
|
297
310
|
// 3.16.1 的输入框是 contenteditable(旧版是 textarea),两种都认
|
|
298
311
|
const ta = composerEl();
|
|
@@ -300,23 +313,61 @@ function renderBar() {
|
|
|
300
313
|
if (!enabled || !host || !host.parentElement) {
|
|
301
314
|
if (barEl) barEl.remove();
|
|
302
315
|
barEl = null;
|
|
316
|
+
if (liftedPane) { liftedPane.style.marginBottom = ''; liftedPane = null; }
|
|
303
317
|
lastRenderedHtml = null; // 元素没了,去重基线同步清空,重建后首渲染不被跳过
|
|
304
318
|
return;
|
|
305
319
|
}
|
|
306
|
-
|
|
320
|
+
// 会话视图:状态栏挪到滚动容器外(容器父级带定位),按输入框的横向位置绝对
|
|
321
|
+
// 定位、贴容器底,滚动裁不到它;新建会话视图没有滚动裁剪,仍在输入框后面排
|
|
322
|
+
// (下方是官方功能按钮区,不能往下压)。
|
|
323
|
+
// 按选中会话判定视图(按钮区与状态条不在同一父容器,兄弟判断不可用)
|
|
324
|
+
const hasSession = !!selectedSessionId();
|
|
325
|
+
const pane = hasSession ? clipPane(host) : null;
|
|
326
|
+
const mount = pane && pane.parentElement && getComputedStyle(pane.parentElement).position !== 'static'
|
|
327
|
+
? pane.parentElement
|
|
328
|
+
: host.parentElement;
|
|
329
|
+
if (!barEl || !barEl.isConnected || barEl.parentElement !== mount) {
|
|
307
330
|
if (!barEl) {
|
|
308
331
|
barEl = document.createElement('div');
|
|
309
332
|
barEl.className = 'zcodepro-statusbar';
|
|
310
333
|
lastRenderedHtml = null; // 新元素:内容基线作废
|
|
311
334
|
}
|
|
312
|
-
host.parentElement.insertBefore(barEl, host.nextSibling);
|
|
335
|
+
if (mount === host.parentElement) mount.insertBefore(barEl, host.nextSibling);
|
|
336
|
+
else mount.append(barEl);
|
|
337
|
+
}
|
|
338
|
+
if (mount !== host.parentElement) {
|
|
339
|
+
// 给状态栏让出上下留白:滚动容器底抬 BAR_LIFT,输入框随之上移
|
|
340
|
+
if (liftedPane && liftedPane !== pane) liftedPane.style.marginBottom = '';
|
|
341
|
+
liftedPane = pane;
|
|
342
|
+
liftedPane.style.marginBottom = `${BAR_LIFT}px`;
|
|
343
|
+
const hr = host.getBoundingClientRect();
|
|
344
|
+
const mr = mount.getBoundingClientRect();
|
|
345
|
+
// 横跨输入框底到窗口底,内容垂直居中:上下留白相等
|
|
346
|
+
barEl.style.position = 'absolute';
|
|
347
|
+
// 绝对定位以父级 padding box 为参照,减去边框宽度
|
|
348
|
+
barEl.style.left = `${Math.round(hr.left - mr.left - mount.clientLeft)}px`;
|
|
349
|
+
barEl.style.width = `${Math.round(hr.width)}px`;
|
|
350
|
+
barEl.style.top = `${Math.round(hr.bottom - mr.top - mount.clientTop)}px`;
|
|
351
|
+
// 紧挨窗底(下方只剩几像素留白)才补到窗口底;下方还有终端等面板时只贴
|
|
352
|
+
// 到列底,否则整条会伸进面板区被盖住,只剩上面那截留白
|
|
353
|
+
const below = innerHeight - mr.bottom;
|
|
354
|
+
barEl.style.bottom = `${below >= 0 && below <= 8 ? Math.round(mr.bottom - innerHeight) : 0}px`;
|
|
355
|
+
barEl.style.zIndex = '20';
|
|
356
|
+
barEl.style.marginBottom = '0';
|
|
357
|
+
barEl.style.paddingTop = '0';
|
|
358
|
+
barEl.style.paddingBottom = '0';
|
|
359
|
+
} else {
|
|
360
|
+
if (liftedPane) { liftedPane.style.marginBottom = ''; liftedPane = null; }
|
|
361
|
+
barEl.style.position = '';
|
|
362
|
+
barEl.style.left = '';
|
|
363
|
+
barEl.style.width = '';
|
|
364
|
+
barEl.style.top = '';
|
|
365
|
+
barEl.style.bottom = '';
|
|
366
|
+
barEl.style.zIndex = '';
|
|
367
|
+
barEl.style.paddingTop = '';
|
|
368
|
+
barEl.style.marginBottom = hasSession ? '-14px' : '0';
|
|
369
|
+
barEl.style.paddingBottom = hasSession ? '0' : '7px';
|
|
313
370
|
}
|
|
314
|
-
// 新建会话视图(无选中会话)下方是官方的功能按钮区,不能往下压:上下对称
|
|
315
|
-
// 留 7px;普通会话视图下方是窗口底的官方留白,压进去贴底(同为约 7px)。
|
|
316
|
-
// 按选中会话判定视图(按钮区与状态条不在同一父容器,兄弟判断不可用)
|
|
317
|
-
const hasSession = !!selectedSessionId();
|
|
318
|
-
barEl.style.marginBottom = hasSession ? '-14px' : '0';
|
|
319
|
-
barEl.style.paddingBottom = hasSession ? '0' : '7px';
|
|
320
371
|
const L = t();
|
|
321
372
|
const entries = [];
|
|
322
373
|
for (const it of items) {
|
|
@@ -11,7 +11,8 @@ import { getConfig } from '../core.js';
|
|
|
11
11
|
|
|
12
12
|
// 各样式项的应用默认值(用于设置界面显示与“恢复默认”)
|
|
13
13
|
export const STYLE_DEFAULTS = {
|
|
14
|
-
|
|
14
|
+
thinkingRowGap: 20, // 思考段落间距:“已工作/工作中”过程视图内各行之间的距离
|
|
15
|
+
answerRowGap: 20, // 回答段落间距:回答正文内文本块、回合之间的垂直间距
|
|
15
16
|
listSpacing: 12, // 列表上下留白(my-3)
|
|
16
17
|
listItemSpacing: 6, // 列表项之间的间距(space-y-1.5)
|
|
17
18
|
quoteCodeSpacing: 16, // 引用块上下留白(my-4;代码块同规则)
|
|
@@ -56,29 +57,55 @@ const SEL_TABLE = `${CONV} .space-y-4 > div:has(table)`;
|
|
|
56
57
|
|
|
57
58
|
function buildCss(styles) {
|
|
58
59
|
const parts = [];
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : null);
|
|
61
|
+
const tg = num(styles.thinkingRowGap);
|
|
62
|
+
const ag = num(styles.answerRowGap);
|
|
63
|
+
const thinkingSet = tg !== null;
|
|
64
|
+
const answerSet = ag !== null;
|
|
65
|
+
if (answerSet) {
|
|
62
66
|
parts.push(
|
|
63
67
|
// 回合内外各级容器(SECTION 自身或后代,二者都覆盖)
|
|
64
|
-
`${CONV}.pb-5,${CONV} .pb-5{padding-bottom:${
|
|
65
|
-
`${CONV}.pt-5,${CONV} .pt-5{padding-top:${
|
|
66
|
-
`${CONV} .flex.flex-col.gap-5{gap:${
|
|
67
|
-
`${CONV} .flex.flex-col.gap-4{gap:${
|
|
68
|
+
`${CONV}.pb-5,${CONV} .pb-5{padding-bottom:${ag}px !important;}`,
|
|
69
|
+
`${CONV}.pt-5,${CONV} .pt-5{padding-top:${ag}px !important;}`,
|
|
70
|
+
`${CONV} .flex.flex-col.gap-5{gap:${ag}px !important;}`,
|
|
71
|
+
`${CONV} .flex.flex-col.gap-4{gap:${ag}px !important;}`,
|
|
68
72
|
// 答案内相邻文本块之间(特殊块除外,走各自间距项)
|
|
69
|
-
`${CONV} .space-y-4 > * + *:not(${SPECIAL}){margin-block-start:${
|
|
73
|
+
`${CONV} .space-y-4 > * + *:not(${SPECIAL}){margin-block-start:${ag}px !important;margin-top:${ag}px !important;}`,
|
|
70
74
|
// 特殊块后接文本块:去掉文本块的段落间距,避免与特殊块自身留白叠加
|
|
71
75
|
`${CONV} .space-y-4 > ${SPECIAL} + *:not(${SPECIAL}){margin-block-start:0 !important;margin-top:0 !important;}`,
|
|
72
|
-
//
|
|
73
|
-
`.history-message.flex.flex-col > * +
|
|
76
|
+
// 历史回合里“已工作”展开块之后接回答正文:这段距离算回答间距
|
|
77
|
+
`.history-message.flex.flex-col > * + *[class~="group/assistant-row"]{margin-block-start:${ag}px !important;margin-top:${ag}px !important;}`,
|
|
74
78
|
// 工具/状态卡片(“N 个文件已更改”等)上方间距下限 8px:
|
|
75
|
-
//
|
|
76
|
-
`${CONV} .flex.flex-col.gap-5 > [data-slot="collapsible"]{margin-block-start:max(0px, calc(8px - ${
|
|
79
|
+
// 回答段落间距调到 0 时也不至于贴死(gap 与 margin 在弹性布局里相加)
|
|
80
|
+
`${CONV} .flex.flex-col.gap-5 > [data-slot="collapsible"]{margin-block-start:max(0px, calc(8px - ${ag}px)) !important;margin-top:max(0px, calc(8px - ${ag}px)) !important;}`,
|
|
77
81
|
);
|
|
78
82
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
if (thinkingSet) {
|
|
84
|
+
parts.push(
|
|
85
|
+
// 过程视图(思考/工具摘要/过程正文)的行块:应用给容器 4px gap + 每行
|
|
86
|
+
// 12px 上内边距(共 16px)。思考段落间距设置时直接接管:gap 归零、上内边距
|
|
87
|
+
// 按设置值,总间距等于设置值(设 0 就完全贴紧)
|
|
88
|
+
`${CONV} [data-conversation-work-items]{gap:0 !important;}`,
|
|
89
|
+
`${CONV} [data-conversation-work-items] > * + *{padding-top:${tg}px !important;}`,
|
|
90
|
+
// 过程视图里的叙述正文按思考算(比回答间距规则多一层容器限定,优先命中)
|
|
91
|
+
`${CONV} [data-conversation-work-items] .space-y-4 > * + *:not(${SPECIAL}){margin-block-start:${tg}px !important;margin-top:${tg}px !important;}`,
|
|
92
|
+
// 过程视图里特殊块后接文本块同样清零,避免与特殊块自身留白叠加(后写覆盖上一条)
|
|
93
|
+
`${CONV} [data-conversation-work-items] .space-y-4 > ${SPECIAL} + *:not(${SPECIAL}){margin-block-start:0 !important;margin-top:0 !important;}`,
|
|
94
|
+
// “已工作”展开块顶部留白(包裹层在历史内容容器内)
|
|
95
|
+
`${CONV} [data-testid^="chat-assistant-history-content"] .pt-5{padding-top:${tg}px !important;}`,
|
|
96
|
+
// 历史回合里“已工作”触发行等过程行之间;回答正文那一行走回答间距规则
|
|
97
|
+
`.history-message.flex.flex-col > * + *:not([data-slot="collapsible-content"]):not([class~="group/assistant-row"]){margin-block-start:${tg}px !important;margin-top:${tg}px !important;}`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (thinkingSet || answerSet) {
|
|
101
|
+
// 3.18 的“工作中”槽位带 -8px 上边距(默认 gap 20 → 实际 12px);行间距调小后
|
|
102
|
+
// 这层负边距会把槽位拉得贴住上面的内容(gap 7 → 实际 -1px)。清掉负边距,
|
|
103
|
+
// 让它跟其它块一样按设置的行间距排
|
|
104
|
+
parts.push(`${CONV} .flex.flex-col.gap-5 > [data-zcode-chat-loading-slot]:not(:first-child){margin-block-start:0 !important;margin-top:0 !important;}`);
|
|
105
|
+
}
|
|
106
|
+
// 特殊块(列表/引用块/表格)自身间距项未设置时跟随回答段落间距,
|
|
107
|
+
// 否则它们带的原生默认边距(12/16px)会与回答段落间距合并取大值,调小于该值无效
|
|
108
|
+
const own = (v) => (typeof v === 'number' && Number.isFinite(v) && v >= 0 ? v : (answerSet ? ag : null));
|
|
82
109
|
const ls = own(styles.listSpacing);
|
|
83
110
|
const qc = own(styles.quoteCodeSpacing);
|
|
84
111
|
const tsp = own(styles.tableSpacing);
|
|
@@ -88,7 +115,7 @@ function buildCss(styles) {
|
|
|
88
115
|
// 文本块自带的底边距(应用给段落默认 16px)清零:相邻块的边距合并会取大值,
|
|
89
116
|
// 不清零时段落间距调小于 16 无效,列表也会上边距大、下边距小。
|
|
90
117
|
// 任一间距项设置时启用,间距完全由设置的起始边距决定
|
|
91
|
-
if (
|
|
118
|
+
if (thinkingSet || answerSet || anySet) {
|
|
92
119
|
parts.push(`${CONV} .space-y-4 > :not(${SPECIAL}){margin-block-end:0 !important;margin-bottom:0 !important;}`);
|
|
93
120
|
}
|
|
94
121
|
if (tsp !== null) {
|
|
@@ -140,12 +167,24 @@ function buildCss(styles) {
|
|
|
140
167
|
}
|
|
141
168
|
const tlh = styles.thinkingLineHeight;
|
|
142
169
|
if (typeof tlh === 'number' && Number.isFinite(tlh) && tlh >= 0.8) {
|
|
143
|
-
// “思考行高”管“已工作/工作中 N
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
// 单独展开的“思考·持续了 N 秒”块内内容不在此设置范围内
|
|
170
|
+
// “思考行高”管“已工作/工作中 N 秒”过程视图与思考正文的行距(读取/编辑/查阅/
|
|
171
|
+
// 终端条目行、流式思考预览,默认 1.5):行高挂在历史内容容器上由各行继承;
|
|
172
|
+
// 过程里的叙述正文(.space-y-4)按“已工作展开块内算思考”的规则也走思考行高
|
|
147
173
|
parts.push(
|
|
148
174
|
`[data-testid^="chat-assistant-history-content"]{line-height:${tlh} !important;}`,
|
|
175
|
+
// 历史回合顶部的“已工作 N 秒”触发行在历史内容容器外,按钮自带 text-ui-base
|
|
176
|
+
// 的行高,只靠容器继承改不到;直接覆盖,否则调“思考行高”时这行不变
|
|
177
|
+
`[class~="group/history-message"]{line-height:${tlh} !important;}`,
|
|
178
|
+
// 用户要求:“已工作”展开块内的内容算思考,块外的才算回答。
|
|
179
|
+
// 历史视图整轮消息(含回答正文)都在历史内容容器里,容器内的 .space-y-4
|
|
180
|
+
// 改用思考行高;正在回答的回合里,展开块外的回答正文仍用回答行高。
|
|
181
|
+
// 放在回答行高规则之后(同特异性,后写的生效)
|
|
182
|
+
`[data-testid^="chat-assistant-history-content"] .space-y-4{line-height:${tlh} !important;}`,
|
|
183
|
+
`[data-conversation-work-items] .space-y-4{line-height:${tlh} !important;}`,
|
|
184
|
+
// 3.18 实时回合的思考正文与“工作中”行在历史容器外,且自带 text-ui-base 的
|
|
185
|
+
// 行高,只靠继承改不动;直接覆盖,调“思考行高”时正在生成的回合也生效
|
|
186
|
+
`[data-testid="chat-reasoning-content"] .whitespace-pre-wrap{line-height:${tlh} !important;}`,
|
|
187
|
+
`[data-testid="chat-loading"] *{line-height:${tlh} !important;}`,
|
|
149
188
|
);
|
|
150
189
|
}
|
|
151
190
|
const ulh = styles.userLineHeight;
|
|
@@ -267,7 +306,8 @@ export function startStyleAdjustments() {
|
|
|
267
306
|
// 边距,数值直观);间距类项再把实际边距区域用淡黄色涂出,调值时黄条
|
|
268
307
|
// 随设置实时变宽变窄。设置弹窗本身用透明遮罩,正好看得见后面的会话 ——
|
|
269
308
|
const HL_SELECTORS = {
|
|
270
|
-
|
|
309
|
+
thinkingRowGap: `${CONV} [data-conversation-work-items] > * + *, .history-message.flex.flex-col > * + *:not([data-slot="collapsible-content"]):not([class~="group/assistant-row"])`,
|
|
310
|
+
answerRowGap: `${CONV} .space-y-4 > *, ${CONV} .flex.flex-col.gap-5 > *`,
|
|
271
311
|
listSpacing: `${CONV} :is(ul, ol)`,
|
|
272
312
|
listItemSpacing: `${CONV} :is(ul, ol) > li`,
|
|
273
313
|
quoteCodeSpacing: SEL_QUOTE,
|
|
@@ -275,10 +315,9 @@ const HL_SELECTORS = {
|
|
|
275
315
|
tableCellPaddingV: `${CONV} td, ${CONV} th`,
|
|
276
316
|
tableCellPaddingH: `${CONV} td, ${CONV} th`,
|
|
277
317
|
codeLineHeight: `${CONV} diffs-container, ${CONV} pre`,
|
|
278
|
-
lineHeight: `${CONV} .space-y-4:not([data-reasoning-content] *)`,
|
|
279
|
-
//
|
|
280
|
-
|
|
281
|
-
thinkingLineHeight: `[data-testid^="chat-assistant-history-content"]`,
|
|
318
|
+
lineHeight: `${CONV} .space-y-4:not([data-reasoning-content] *):not([data-testid^="chat-assistant-history-content"] *):not([data-conversation-work-items] *)`,
|
|
319
|
+
// 思考行高作用在“已工作/工作中”过程视图、触发行与思考正文上;视图折叠未挂载时不标
|
|
320
|
+
thinkingLineHeight: `[data-testid^="chat-assistant-history-content"], [class~="group/history-message"], [data-testid="chat-loading"], [data-testid="chat-reasoning-content"]`,
|
|
282
321
|
userLineHeight: `${CONV} [class*="user-row"] .whitespace-pre-wrap`,
|
|
283
322
|
contentWidth: '[data-v4-timeline-content-column]',
|
|
284
323
|
// 双结构:新侧栏项目行 / 旧 testid 行
|
|
@@ -287,10 +326,11 @@ const HL_SELECTORS = {
|
|
|
287
326
|
};
|
|
288
327
|
|
|
289
328
|
// 间距类项的边距黄条:受影响元素与边距方向(与 buildCss 里的规则选择器保持一致)
|
|
290
|
-
//
|
|
291
|
-
//
|
|
329
|
+
// 思考行间距落在行块的上内边距里,黄条画在元素内侧;回答间距排除两种边距实际
|
|
330
|
+
// 为零的元素:特殊块自身(走各自间距项)、紧跟特殊块的文本(其起始边距被清零)
|
|
292
331
|
const HL_MARGIN = {
|
|
293
|
-
|
|
332
|
+
thinkingRowGap: { sel: `${CONV} [data-conversation-work-items] > * + *`, top: true, insideTop: true },
|
|
333
|
+
answerRowGap: { sel: `${CONV} .space-y-4 > * + *:not(${SPECIAL}):not(${SPECIAL} + *)`, top: true },
|
|
294
334
|
listSpacing: { sel: SEL_LIST, top: true, bottom: true },
|
|
295
335
|
listItemSpacing: { sel: `${CONV} :is(ul, ol) > li + li`, top: true },
|
|
296
336
|
quoteCodeSpacing: { sel: SEL_QUOTE, top: true, bottom: true },
|
|
@@ -321,7 +361,7 @@ export function showStyleHighlight(key, value = null) {
|
|
|
321
361
|
// 伪元素画在边距所在的区域(元素边界外侧),高度跟随当前设置值;
|
|
322
362
|
// 调值提交时调用方会带新值重进,黄条随之变宽变窄
|
|
323
363
|
parts.push(`${margin.sel}{position:relative !important;}`);
|
|
324
|
-
if (margin.top) parts.push(`${margin.sel}::before{content:'' !important;position:absolute;left:0;right:0
|
|
364
|
+
if (margin.top) parts.push(`${margin.sel}::before{content:'' !important;position:absolute;left:0;right:0;${margin.insideTop ? 'top:0' : 'bottom:100%'};height:${v}px;background:${HL_AMBER};pointer-events:none;}`);
|
|
325
365
|
if (margin.bottom) parts.push(`${margin.sel}::after{content:'' !important;position:absolute;left:0;right:0;top:100%;height:${v}px;background:${HL_AMBER};pointer-events:none;}`);
|
|
326
366
|
}
|
|
327
367
|
hlEl.textContent = parts.join('');
|
|
@@ -394,24 +394,44 @@ function clearWpTimers() {
|
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
// 插件卡片(沙箱 webview)页面自带的背景是实色,会把壁纸整块盖住;
|
|
397
|
-
// 用 webview 自带的 insertCSS 把 guest 页面的 html/body
|
|
398
|
-
//
|
|
397
|
+
// 用 webview 自带的 insertCSS 把 guest 页面的 html/body 背景改成“主题色遮罩 +
|
|
398
|
+
// 卡片遮罩透明度”(0 = 全透明 = 壁纸原样透出)。页面每次加载后重插(CSS 随文档
|
|
399
|
+
// 生命周期失效),遮罩滑杆(bg.cardVeil)变化时撤旧 key 重插。只做加法:
|
|
400
|
+
// 页面其余样式不动
|
|
399
401
|
let webviewScanTimer = null;
|
|
400
|
-
const wvStyled = []; // [{ el, key }]
|
|
402
|
+
const wvStyled = []; // [{ el, key, css, handler }]:壁纸关闭时撤掉遮罩,恢复卡片自己的背景
|
|
403
|
+
function cardVeilCss() {
|
|
404
|
+
const raw = Number((currentTheme.bg || {}).cardVeil);
|
|
405
|
+
const veil = Number.isFinite(raw) ? raw : 0.2;
|
|
406
|
+
// 与壁纸遮罩同源取色:面板半透明化后 --color-background 是 color-mix,直接读
|
|
407
|
+
// 自定义属性拿到的 token 认不出;resolvedColor 取计算值,rgbTriple 归一化成 rgb
|
|
408
|
+
const rgb = rgbTriple(resolvedColor('--color-background'), isDarkMode() ? '13,13,13' : '248,248,248');
|
|
409
|
+
return `html,body{background:rgba(${rgb},${veil}) !important}`;
|
|
410
|
+
}
|
|
401
411
|
function applyWebviewTransparency() {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
412
|
+
// 只处理插件卡片(zcode-sandbox 壳)的 webview:右侧预览等用户页面同样挂在
|
|
413
|
+
// <webview> 里,遮罩不能插进用户的页面。guest 未就绪(URL 为空)时先挂监听,
|
|
414
|
+
// dom-ready 拿到真实 URL 再判定
|
|
415
|
+
const guestUrl = (w) => {
|
|
416
|
+
try { return String(w.getURL ? w.getURL() : w.src || ''); } catch { return ''; }
|
|
417
|
+
};
|
|
418
|
+
const maybeCard = (w) => { const u = guestUrl(w); return u === '' || /^zcode-sandbox:\/\//i.test(u); };
|
|
419
|
+
const hook = (w, css) => {
|
|
420
|
+
if (!maybeCard(w)) return; // 明确是用户页面(http/file 等):不挂监听、不插样式
|
|
421
|
+
// on 每次现读、css 每轮扫描现算:扫描定时器只启动一次、长期存活,闭包固化
|
|
422
|
+
// 初值会让后建的 webview 拿到旧遮罩,还会每 2 秒把滑杆改后的新值覆盖回旧值
|
|
405
423
|
const on = document.documentElement.classList.contains('zcodepro-bg-on');
|
|
406
424
|
const rec = wvStyled.find((r) => r.el === w);
|
|
407
425
|
if (on && !rec) {
|
|
408
|
-
const entry = { el: w, key: null, handler: null };
|
|
426
|
+
const entry = { el: w, key: null, css, handler: null };
|
|
409
427
|
entry.handler = () => {
|
|
410
|
-
if (!wvStyled.includes(entry)) return; //
|
|
428
|
+
if (!wvStyled.includes(entry)) return; // 已随关壁纸摘牌:别再插遮罩
|
|
429
|
+
if (!maybeCard(w)) return; // dom-ready 时是用户页面:不插(URL 空则只进空白文档,无影响)
|
|
430
|
+
const myCss = entry.css; // 插入期间遮罩可能又变:结果回来只认自己这份
|
|
411
431
|
try {
|
|
412
|
-
void w.insertCSS(
|
|
413
|
-
//
|
|
414
|
-
if (wvStyled.includes(entry)) entry.key = k;
|
|
432
|
+
void w.insertCSS(myCss).then((k) => {
|
|
433
|
+
// 已摘牌或值已过期:插进去的遮罩没人撤,立刻自己撤掉
|
|
434
|
+
if (wvStyled.includes(entry) && entry.css === myCss) entry.key = k;
|
|
415
435
|
else { try { void w.removeCSS(k).catch(() => { /* ignore */ }); } catch { /* ignore */ } }
|
|
416
436
|
}).catch(() => { /* 未就绪:dom-ready 再试 */ });
|
|
417
437
|
} catch { /* 同步抛出:同上 */ }
|
|
@@ -419,13 +439,34 @@ function applyWebviewTransparency() {
|
|
|
419
439
|
w.addEventListener('dom-ready', entry.handler);
|
|
420
440
|
wvStyled.push(entry);
|
|
421
441
|
entry.handler();
|
|
442
|
+
} else if (on && rec && rec.css !== css) {
|
|
443
|
+
if (!maybeCard(w)) return; // 用户页面:不插遮罩
|
|
444
|
+
// 遮罩滑杆变了:撤旧 key 重插新值(insertCSS 的 key 对应一份 CSS 文本)
|
|
445
|
+
rec.css = css;
|
|
446
|
+
const oldKey = rec.key;
|
|
447
|
+
rec.key = null;
|
|
448
|
+
if (oldKey) { try { void w.removeCSS(oldKey).catch(() => { /* ignore */ }); } catch { /* ignore */ } }
|
|
449
|
+
try {
|
|
450
|
+
void w.insertCSS(css).then((k) => {
|
|
451
|
+
if (wvStyled.includes(rec) && rec.css === css) rec.key = k;
|
|
452
|
+
else { try { void w.removeCSS(k).catch(() => { /* ignore */ }); } catch { /* ignore */ } }
|
|
453
|
+
}).catch(() => {
|
|
454
|
+
// 没插进去(guest 未就绪等):清掉记录值让下次扫描重试,否则
|
|
455
|
+
// rec.css 已是新值、再也进不了本分支,遮罩就一直缺着
|
|
456
|
+
if (wvStyled.includes(rec) && rec.css === css) rec.css = '';
|
|
457
|
+
});
|
|
458
|
+
} catch { /* 同步抛出:同上 */ }
|
|
422
459
|
} else if (!on && rec) {
|
|
423
460
|
if (rec.handler) w.removeEventListener('dom-ready', rec.handler); // 不摘会随开关次数累积
|
|
424
461
|
if (rec.key) { try { void w.removeCSS(rec.key).catch(() => { /* ignore */ }); } catch { /* ignore */ } }
|
|
425
462
|
wvStyled.splice(wvStyled.indexOf(rec), 1);
|
|
426
463
|
}
|
|
427
464
|
};
|
|
428
|
-
|
|
465
|
+
// 每轮扫描算一次 CSS 给所有 webview 共用:卡片多时不必逐个读计算样式
|
|
466
|
+
const scan = () => {
|
|
467
|
+
const css = cardVeilCss();
|
|
468
|
+
document.querySelectorAll('webview').forEach((w) => hook(w, css));
|
|
469
|
+
};
|
|
429
470
|
scan();
|
|
430
471
|
if (!webviewScanTimer) webviewScanTimer = setInterval(scan, 2000);
|
|
431
472
|
}
|
|
@@ -174,12 +174,12 @@ const ACTIVE_IDS_TTL_MS = 25_000;
|
|
|
174
174
|
const ACTIVE_IDS_TIMEOUT_MS = 6_000;
|
|
175
175
|
const activeIdsCache = new Map(); // base → { ids, doneAt, pending }
|
|
176
176
|
|
|
177
|
-
export function listActiveIdsCached(base) {
|
|
177
|
+
export function listActiveIdsCached(base, fresh = false) {
|
|
178
178
|
const key = String(base).replace(/[\\/]+$/, '');
|
|
179
179
|
const now = Date.now();
|
|
180
180
|
const hit = activeIdsCache.get(key);
|
|
181
181
|
if (hit && hit.pending) return hit.pending;
|
|
182
|
-
if (hit && now - hit.doneAt < ACTIVE_IDS_TTL_MS) return Promise.resolve(hit.ids);
|
|
182
|
+
if (!fresh && hit && now - hit.doneAt < ACTIVE_IDS_TTL_MS) return Promise.resolve(hit.ids);
|
|
183
183
|
const services = findServices();
|
|
184
184
|
const ts = services && services.zcodeTaskService;
|
|
185
185
|
if (!ts || typeof ts.listActiveTaskIds !== 'function') return Promise.resolve(null);
|
|
@@ -282,6 +282,7 @@ function toggleNavSafe(head) {
|
|
|
282
282
|
|
|
283
283
|
function scan() {
|
|
284
284
|
wsWithRows = new Set();
|
|
285
|
+
const changed = new Set(); // 本轮运行状态有变化的工作区(用于立即催权威扫描)
|
|
285
286
|
for (const el of document.querySelectorAll(TASK_SEL)) {
|
|
286
287
|
const key = el.getAttribute('data-task-item-key') || '';
|
|
287
288
|
const ws = workspaceOf(key);
|
|
@@ -291,11 +292,26 @@ function scan() {
|
|
|
291
292
|
let set = runningByWs.get(ws);
|
|
292
293
|
if (run) {
|
|
293
294
|
if (!set) { set = new Set(); runningByWs.set(ws, set); }
|
|
295
|
+
if (!set.has(key)) changed.add(ws);
|
|
294
296
|
set.add(key);
|
|
295
297
|
} else if (set) {
|
|
296
|
-
set.delete(key);
|
|
298
|
+
if (set.delete(key)) changed.add(ws);
|
|
297
299
|
}
|
|
298
300
|
}
|
|
301
|
+
// 行上的 loader 增减是应用自己给出的实时信号:立刻作废该工作区的活跃缓存
|
|
302
|
+
// 并催一次权威扫描。否则任务结束后项目/分区图标要等 30 秒周期 + 25 秒缓存
|
|
303
|
+
// 才熄灭(折叠项目更是要等 60 秒复核)。
|
|
304
|
+
if (changed.size) {
|
|
305
|
+
for (const ws of changed) activeIdsCache.delete(String(ws).replace(/[\\/]+$/, ''));
|
|
306
|
+
// 刚变空闲的工作区先从项目活跃集合里摘掉,图标当场熄灭,权威扫描回来再校正
|
|
307
|
+
for (const ws of changed) {
|
|
308
|
+
const set = runningByWs.get(ws);
|
|
309
|
+
if (set && set.size) continue;
|
|
310
|
+
const norm = (v) => String(v || '').replace(/[\\/]+$/, '');
|
|
311
|
+
for (const p of [...activeProjectPaths]) if (norm(p) === norm(ws)) activeProjectPaths.delete(p);
|
|
312
|
+
}
|
|
313
|
+
scheduleForceScan();
|
|
314
|
+
}
|
|
299
315
|
// 无条件复核探查调度:行从有到无(折叠/卸载)时 scan 本身看不到变化,
|
|
300
316
|
// 但 wsWithRows 已更新,正是需要(重新)排复核的时机
|
|
301
317
|
syncPeeks();
|
|
@@ -433,13 +449,36 @@ let activeProjectPaths = new Set();
|
|
|
433
449
|
let authActiveByWs = new Map();
|
|
434
450
|
// 周期复查:缓存到期就无条件重扫(不看当前值)——只在 true 时扫会有两个缺口:
|
|
435
451
|
// 空闲后新任务启动无人触发(折叠分区头不亮);任务结束但数据库完成状态尚未
|
|
436
|
-
//
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
452
|
+
// 写入的过渡窗口里旧值一直被沿用。有图标亮着时 10 秒一轮、空闲时 30 秒一轮:
|
|
453
|
+
// 任务刚结束要尽快熄灭,空闲期不必高频扫(扫描本身是内存级过滤)
|
|
454
|
+
function anySpinLit() {
|
|
455
|
+
return anyActiveCache.value === true || sectionActive.task || sectionActive.project
|
|
456
|
+
|| sectionActive.pinned || activeProjectPaths.size > 0;
|
|
457
|
+
}
|
|
458
|
+
let globalScanTimer = 0;
|
|
459
|
+
function scheduleGlobalScan() {
|
|
460
|
+
clearTimeout(globalScanTimer);
|
|
461
|
+
const wait = anySpinLit() ? 10_000 : 30_000;
|
|
462
|
+
globalScanTimer = setTimeout(() => {
|
|
463
|
+
if (!document.hidden && enabled && !anyActiveCache.busy) {
|
|
464
|
+
if (anySpinLit()) globalAnyActive(true);
|
|
465
|
+
else if (Date.now() - anyActiveCache.at >= 30_000) globalAnyActive();
|
|
466
|
+
}
|
|
467
|
+
scheduleGlobalScan();
|
|
468
|
+
}, wait);
|
|
469
|
+
}
|
|
470
|
+
scheduleGlobalScan();
|
|
471
|
+
// DOM 看到运行状态变化后的立即重扫:合并 800 毫秒内的多次变化,绕过缓存
|
|
472
|
+
let forceScanTimer = 0;
|
|
473
|
+
function scheduleForceScan() {
|
|
474
|
+
if (forceScanTimer) return;
|
|
475
|
+
forceScanTimer = setTimeout(() => {
|
|
476
|
+
forceScanTimer = 0;
|
|
477
|
+
if (!document.hidden && enabled) globalAnyActive(true);
|
|
478
|
+
}, 800);
|
|
479
|
+
}
|
|
480
|
+
function globalAnyActive(force) {
|
|
481
|
+
if (!force && anyActiveCache.value !== null && Date.now() - anyActiveCache.at < 30_000) return anyActiveCache.value;
|
|
443
482
|
if (anyActiveCache.busy) return anyActiveCache.value === true;
|
|
444
483
|
anyActiveCache.busy = true;
|
|
445
484
|
sectionActive.task = false;
|
|
@@ -489,9 +528,11 @@ function globalAnyActive() {
|
|
|
489
528
|
projectPaths.set(proj.name, names);
|
|
490
529
|
}
|
|
491
530
|
// 各工作区并行查(串行 await 在几十个工作区时要跑数秒):每区两种尾斜杠
|
|
492
|
-
// 各查一次,走共享缓存(subagent-icon
|
|
531
|
+
// 各查一次,走共享缓存(subagent-icon 复用同一份结果)。强制重扫时,
|
|
532
|
+
// 当前亮着图标的工作区不吃缓存——它们正是可能刚结束、要尽快熄灭的
|
|
533
|
+
const hot = new Set([...activeProjectPaths, ...authActiveByWs.keys()]);
|
|
493
534
|
const pairs = await Promise.all([...scanPaths].map(async (base) =>
|
|
494
|
-
[base, (await listActiveIdsCached(base)) || []]));
|
|
535
|
+
[base, (await listActiveIdsCached(base, force && hot.has(base))) || []]));
|
|
495
536
|
for (const [base, ids] of pairs) {
|
|
496
537
|
if (!ids.length) continue;
|
|
497
538
|
byKindByPath.set(base, ids);
|
|
@@ -507,7 +548,21 @@ function globalAnyActive() {
|
|
|
507
548
|
// 有动静的按真活跃;长期不动的才是 syncer 卡滞误报
|
|
508
549
|
const TERMINAL = new Set(['completed', 'error', 'interrupted']);
|
|
509
550
|
const recOf = (id) => (st && st.ok && st.available ? st.statuses[id] : undefined);
|
|
551
|
+
// 侧栏可见行就是应用自己的实时判定:行在场且没有 loader,说明这个会话
|
|
552
|
+
// 确实停了。刚结束时官方活跃集合可能还没清、DB 也还在终态宽限期里,
|
|
553
|
+
// 光靠 5 分钟窗口会让图标多转很久——可见行直接否决
|
|
554
|
+
const domIdle = new Set();
|
|
555
|
+
const domRunningIds = new Set();
|
|
556
|
+
for (const el of document.querySelectorAll(TASK_SEL)) {
|
|
557
|
+
const k = el.getAttribute('data-task-item-key') || '';
|
|
558
|
+
const id = k.slice(k.lastIndexOf(':') + 1);
|
|
559
|
+
if (!id) continue;
|
|
560
|
+
if (isRunningRow(el)) domRunningIds.add(id);
|
|
561
|
+
else domIdle.add(id);
|
|
562
|
+
}
|
|
563
|
+
for (const id of domRunningIds) domIdle.delete(id);
|
|
510
564
|
const live = (id) => {
|
|
565
|
+
if (domIdle.has(id)) return false;
|
|
511
566
|
const rec = recOf(id);
|
|
512
567
|
if (rec === undefined) return true;
|
|
513
568
|
if (!TERMINAL.has(rec.status)) return true;
|
|
@@ -518,6 +573,7 @@ function globalAnyActive() {
|
|
|
518
573
|
// 满足的(listActiveTaskIds 混入的非会话标识、索引尚未记录的新会话)
|
|
519
574
|
// 不进弹窗,否则会出现点了切不过去的幽灵行
|
|
520
575
|
const liveSession = (id) => {
|
|
576
|
+
if (domIdle.has(id)) return false;
|
|
521
577
|
const rec = recOf(id);
|
|
522
578
|
if (rec === undefined) return !!domRowKeyOf(id);
|
|
523
579
|
if (!TERMINAL.has(rec.status)) return true;
|
package/src/inject/index.js
CHANGED
|
@@ -28,6 +28,7 @@ import { startTheme } from './features/theme.js';
|
|
|
28
28
|
import { startTableCopy } from './features/table-copy.js';
|
|
29
29
|
import { startSessionLink } from './features/session-link.js';
|
|
30
30
|
import { startComposerProvider } from './features/composer-provider.js';
|
|
31
|
+
import { startComposerEditModel } from './features/composer-edit-model.js';
|
|
31
32
|
import { startPluginUpdateCheck } from './features/plugin-updates.js';
|
|
32
33
|
import { ensureStyle } from './ui.js';
|
|
33
34
|
|
|
@@ -95,6 +96,7 @@ import { ensureStyle } from './ui.js';
|
|
|
95
96
|
try { startTableCopy(); } catch { /* ignore */ }
|
|
96
97
|
try { startSessionLink(); } catch { /* ignore */ }
|
|
97
98
|
try { startComposerProvider(); } catch { /* ignore */ }
|
|
99
|
+
try { startComposerEditModel(); } catch { /* ignore */ }
|
|
98
100
|
try { startSettingsEntry(); } catch { /* ignore */ }
|
|
99
101
|
// 插件更新检查慢(可能 git pull),异步进行,不阻塞其他功能
|
|
100
102
|
try { void startPluginUpdateCheck(); } catch { /* ignore */ }
|
package/src/inject/ui.js
CHANGED
|
@@ -646,6 +646,16 @@ export function ensureStyle() {
|
|
|
646
646
|
.zcodepro-textarea.zcodepro-textarea-sm { min-height: 0; }
|
|
647
647
|
/* 全局提示词大编辑框:默认/最大高度都比默认文本域更高 */
|
|
648
648
|
.zcodepro-textarea.zcodepro-textarea-lg { min-height: 16rem; max-height: 40rem; }
|
|
649
|
+
/* 设置页下拉框:壁纸开着时表面 token 被换成 color-mix 半透明,原生下拉列表
|
|
650
|
+
会渲染成黑底 + 默认黑字(深色模式看不清)。给选项写死主题的不透明底色与
|
|
651
|
+
正文色,并按明暗给 select 一个 color-scheme,列表在两种模式下都可读 */
|
|
652
|
+
[data-zcodepro-settings] select { color-scheme: light; }
|
|
653
|
+
html.theme-zai-dark [data-zcodepro-settings] select,
|
|
654
|
+
html.dark [data-zcodepro-settings] select { color-scheme: dark; }
|
|
655
|
+
[data-zcodepro-settings] select option {
|
|
656
|
+
background-color: var(--color-popover, #fff);
|
|
657
|
+
color: var(--color-foreground, #111);
|
|
658
|
+
}
|
|
649
659
|
/* 行高滑杆(样式调整标签页) */
|
|
650
660
|
.zcodepro-range {
|
|
651
661
|
-webkit-appearance: none;
|
|
@@ -744,8 +754,8 @@ export function ensureStyle() {
|
|
|
744
754
|
color: var(--color-muted-foreground, #888);
|
|
745
755
|
}
|
|
746
756
|
/* 状态栏统计(status-bar.js):输入框下方右对齐的一行小字,每项带 lucide 小图标。
|
|
747
|
-
|
|
748
|
-
|
|
757
|
+
会话视图里绝对定位到滚动容器外的底部(避开滚动裁剪),新建会话视图在输入框后
|
|
758
|
+
按原样排;位置与间距由脚本控制 */
|
|
749
759
|
.zcodepro-statusbar {
|
|
750
760
|
display: flex;
|
|
751
761
|
justify-content: flex-end;
|