dsh-quote-annotate-pro 0.2.6 → 0.2.7
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/CHANGELOG.md +13 -2
- package/lib/client.js +106 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的所有重要变更都记在这里。版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
|
|
4
4
|
|
|
5
|
+
## 0.2.7 — 引用渲染定版:输入框与对话区都不再"先露原文"
|
|
6
|
+
|
|
7
|
+
- **输入框侧(本次)**:插入引用后**同一帧内**完成装饰 —— 不再走 `setTimeout`,改为在 `MutationObserver` 回调里同步执行(回调先于绘制),消除此前约 40ms 的"先露出完整引用块"窗口
|
|
8
|
+
- **对话区侧(本次)**:位置行不再"先露一百多毫秒再被隐藏"(依据录屏 + diag-sink 日志定位)
|
|
9
|
+
- 用户消息行有两副面孔:宿主的正式行带 `data-chat-anchor-key`,但消息刚发出去的那一下先渲染成 `div.*_userRow`(**还没有锚点属性**)→ 插件此前够不到,实测空窗约 122ms
|
|
10
|
+
- 现在两类行都按用户行处理(`USER_ROW_SEL`):行出现的**同一帧**就完成装饰(MutationObserver 回调先于绘制),不再等防抖
|
|
11
|
+
- 宿主在渲染后还会重排气泡内容(实测再约 120ms 一次),会把已隐藏的位置行换回原文;判定改为**看内容**(`rowHasRawHeader()`)而不是看 `data-dshq-sent` 标记,重排的同一帧即补装饰
|
|
12
|
+
- 观察器增加 `attributeFilter: ['data-chat-anchor-key','data-chat-flow-kind']`,覆盖"先插文本、后挂锚点"的渲染顺序
|
|
13
|
+
- **文本零改动**:装饰只加样式类/包一层隐藏元素,**消息文本仍是 `【引用 · 第N轮 · 角色】` + 原文** → 模型侧定位能力不变
|
|
14
|
+
- 新增静默诊断探针(`cmp:probe` 等),仅在运行 `npm run diag` 时上报;发布版无任何网络请求
|
|
15
|
+
|
|
5
16
|
## 0.2.6 — 输入框与消息统一为紧凑引用(消除插入瞬间的闪烁)
|
|
6
17
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
18
|
+
- **输入框里的引用**:插入后渲染成**紧凑原文块**(位置行隐藏)
|
|
19
|
+
- 实现:装饰函数暴露为模块级钩子,插入成功即调用一次
|
|
9
20
|
- **引用文本去掉 `> ` 前缀**(`【引用 · 第N轮 · 角色】` + 原文),编辑器里不再多露一个符号
|
|
10
21
|
- **文本保持完整**:界面只是隐藏位置行(加样式类,不动编辑器文本),因此**发送出去的内容仍带轮次/角色** → 模型侧定位能力不变
|
|
11
22
|
- 消息侧(0.2.3)的紧凑渲染保持不变,输入与输出观感一致
|
package/lib/client.js
CHANGED
|
@@ -149,6 +149,8 @@ window.__ModuleLoader__.load({
|
|
|
149
149
|
const refCodecs = new Map()
|
|
150
150
|
// 输入框引用装饰的"立即执行"钩子:插入后马上贴样式,避免先露出旧样子再变(用户反馈的瞬间闪烁)
|
|
151
151
|
let composerDecorateNow = null
|
|
152
|
+
// 诊断用:最近一次插入引用的时刻(毫秒),用于测"装饰相对插入晚了多久"
|
|
153
|
+
let lastInsertAt = 0
|
|
152
154
|
|
|
153
155
|
// 页面内反馈 toast(点击 chip 时显示结果)
|
|
154
156
|
const toastStore = {
|
|
@@ -806,6 +808,7 @@ window.__ModuleLoader__.load({
|
|
|
806
808
|
} catch (e) { /* ignore */ }
|
|
807
809
|
report('insert:chip', { ref, anchorKey: item.anchorKey || null, header, chars: item.text.length })
|
|
808
810
|
// 立刻给刚插入的内容贴样式,避免"先露出旧样子、稍后才变紧凑"的闪烁
|
|
811
|
+
lastInsertAt = (typeof performance !== 'undefined' ? performance.now() : Date.now())
|
|
809
812
|
try { if (typeof composerDecorateNow === 'function') composerDecorateNow() } catch (e) { /* ignore */ }
|
|
810
813
|
setStatus({
|
|
811
814
|
ok: true,
|
|
@@ -1324,17 +1327,22 @@ window.__ModuleLoader__.load({
|
|
|
1324
1327
|
const scan = () => {
|
|
1325
1328
|
timer = null
|
|
1326
1329
|
try {
|
|
1327
|
-
for (const row of document.querySelectorAll(
|
|
1328
|
-
|
|
1329
|
-
if (
|
|
1330
|
+
for (const row of document.querySelectorAll(USER_ROW_SEL)) {
|
|
1331
|
+
const kind = row.getAttribute('data-chat-flow-kind')
|
|
1332
|
+
if (kind && kind !== 'user') continue
|
|
1330
1333
|
let walker
|
|
1331
1334
|
try { walker = document.createTreeWalker(row, NodeFilter.SHOW_TEXT, null) } catch (e) { continue }
|
|
1332
1335
|
const targets = []
|
|
1333
1336
|
let n = walker.nextNode()
|
|
1334
1337
|
while (n) {
|
|
1335
|
-
|
|
1338
|
+
const parent = n.parentElement
|
|
1339
|
+
// 已经装饰过的部分(隐藏的位置行 / 紧凑引用块)不再重复处理
|
|
1340
|
+
const managed = parent && typeof parent.closest === 'function'
|
|
1341
|
+
? parent.closest('.dshq-sent-header, .dshq-sent-quote') : null
|
|
1342
|
+
if (!managed && HEADER_RE.test(n.nodeValue || '')) targets.push(n)
|
|
1336
1343
|
n = walker.nextNode()
|
|
1337
1344
|
}
|
|
1345
|
+
if (targets.length === 0) continue
|
|
1338
1346
|
let done = false
|
|
1339
1347
|
for (const t of targets) { try { if (transformTextNode(t)) done = true } catch (e) { /* ignore */ } }
|
|
1340
1348
|
if (done && row.dataset) row.dataset.dshqSent = '1'
|
|
@@ -1342,10 +1350,80 @@ window.__ModuleLoader__.load({
|
|
|
1342
1350
|
} catch (e) { report('sent:scan-throw', String((e && e.message) || e)) }
|
|
1343
1351
|
}
|
|
1344
1352
|
const schedule = () => { if (timer === null) timer = setTimeout(scan, 300) }
|
|
1353
|
+
// 消息从输入框进入对话区时,首帧先画出的是原始文本(含"【引用 · …】"位置行),
|
|
1354
|
+
// 300ms 防抖会让它闪一下。MutationObserver 回调在下一次绘制前执行,
|
|
1355
|
+
// 因此只要这次变动牵扯到"还没装饰过的用户消息行"就同步扫一次,首帧即完成隐藏;
|
|
1356
|
+
// 其余情况(例如助手流式输出)仍走防抖,不增加扫描开销。
|
|
1357
|
+
// 用户消息行有两副面孔:正式行带 anchor 属性;但实测"刚发出去"的那一下,
|
|
1358
|
+
// 宿主先渲染出 <div class="cJsG2q_userRow">(还没有 data-chat-anchor-key),
|
|
1359
|
+
// 等属性挂上才轮得到插件 —— 那段空窗就是用户看到的闪。两类都按用户行处理。
|
|
1360
|
+
const USER_ROW_SEL = '[data-chat-anchor-key][data-chat-flow-kind="user"], [class*="userRow" i]'
|
|
1361
|
+
const asElement = (node) => (node && node.nodeType === 1 ? node : (node && node.parentElement) || null)
|
|
1362
|
+
// 行里是否还存在"没被插件接管过的"位置行文本。
|
|
1363
|
+
// 宿主会在渲染后重排/替换气泡内容(实测发送后约 120ms 会有一次),
|
|
1364
|
+
// 那时我们贴好的隐藏 span 会被换回原始文本 —— 用内容判断而不是用标记判断,
|
|
1365
|
+
// 才能在重渲染的同一帧里立刻补装饰。
|
|
1366
|
+
const rowHasRawHeader = (row) => {
|
|
1367
|
+
try {
|
|
1368
|
+
const walker = document.createTreeWalker(row, NodeFilter.SHOW_TEXT, null)
|
|
1369
|
+
let n = walker.nextNode()
|
|
1370
|
+
while (n) {
|
|
1371
|
+
const parent = n.parentElement
|
|
1372
|
+
const managed = parent && typeof parent.closest === 'function'
|
|
1373
|
+
? parent.closest('.dshq-sent-header, .dshq-sent-quote') : null
|
|
1374
|
+
if (!managed && HEADER_RE.test(n.nodeValue || '')) return true
|
|
1375
|
+
n = walker.nextNode()
|
|
1376
|
+
}
|
|
1377
|
+
return false
|
|
1378
|
+
} catch (e) { return false }
|
|
1379
|
+
}
|
|
1380
|
+
const touchesPendingUserRow = (node) => {
|
|
1381
|
+
const el = asElement(node)
|
|
1382
|
+
if (!el || typeof el.closest !== 'function') return false
|
|
1383
|
+
const row = el.closest(USER_ROW_SEL)
|
|
1384
|
+
// ① 变动落在用户消息行内部(含行自身):只要还能找到未接管的位置行就立刻扫
|
|
1385
|
+
if (row) {
|
|
1386
|
+
const kind = row.getAttribute('data-chat-flow-kind')
|
|
1387
|
+
if (kind && kind !== 'user') return false
|
|
1388
|
+
return rowHasRawHeader(row)
|
|
1389
|
+
}
|
|
1390
|
+
// ② 新增的子树里带着这样的用户消息行(宿主可能整块替换容器)
|
|
1391
|
+
if (typeof el.querySelector === 'function') {
|
|
1392
|
+
try {
|
|
1393
|
+
for (const r of el.querySelectorAll(USER_ROW_SEL)) {
|
|
1394
|
+
const kind = r.getAttribute('data-chat-flow-kind')
|
|
1395
|
+
if (kind && kind !== 'user') continue
|
|
1396
|
+
if (rowHasRawHeader(r)) return true
|
|
1397
|
+
}
|
|
1398
|
+
} catch (e) { /* ignore */ }
|
|
1399
|
+
}
|
|
1400
|
+
return false
|
|
1401
|
+
}
|
|
1402
|
+
const onMutations = (records) => {
|
|
1403
|
+
let urgent = false
|
|
1404
|
+
try {
|
|
1405
|
+
for (const r of records) {
|
|
1406
|
+
const cands = [r.target]
|
|
1407
|
+
const added = r.addedNodes
|
|
1408
|
+
if (added) { for (const n of added) cands.push(n) }
|
|
1409
|
+
for (const c of cands) {
|
|
1410
|
+
if (!urgent && touchesPendingUserRow(c)) urgent = true
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
if (urgent) scan()
|
|
1414
|
+
} catch (e) { /* ignore */ }
|
|
1415
|
+
schedule()
|
|
1416
|
+
}
|
|
1345
1417
|
scan()
|
|
1346
1418
|
try {
|
|
1347
|
-
observer = new MutationObserver(
|
|
1348
|
-
observer.observe(document.body, {
|
|
1419
|
+
observer = new MutationObserver(onMutations)
|
|
1420
|
+
observer.observe(document.body, {
|
|
1421
|
+
childList: true,
|
|
1422
|
+
subtree: true,
|
|
1423
|
+
characterData: true,
|
|
1424
|
+
attributes: true,
|
|
1425
|
+
attributeFilter: ['data-chat-anchor-key', 'data-chat-flow-kind'],
|
|
1426
|
+
})
|
|
1349
1427
|
} catch (e) { report('sent:observer-throw', String((e && e.message) || e)) }
|
|
1350
1428
|
return () => {
|
|
1351
1429
|
if (timer !== null) clearTimeout(timer)
|
|
@@ -1364,6 +1442,7 @@ window.__ModuleLoader__.load({
|
|
|
1364
1442
|
let timer = null
|
|
1365
1443
|
let observer = null
|
|
1366
1444
|
const isSingleLine = (t) => t !== '' && t.indexOf('\n') === -1
|
|
1445
|
+
let lastSig = ''
|
|
1367
1446
|
const decorate = () => {
|
|
1368
1447
|
timer = null
|
|
1369
1448
|
try {
|
|
@@ -1382,7 +1461,23 @@ window.__ModuleLoader__.load({
|
|
|
1382
1461
|
if (!isSingleLine(t)) break
|
|
1383
1462
|
quoteEls.push(el)
|
|
1384
1463
|
}
|
|
1385
|
-
if (!headerEl)
|
|
1464
|
+
if (!headerEl) {
|
|
1465
|
+
// 诊断:编辑器里出现了"【引用"但没能匹配成"位置行 + 正文行"时,把结构打出来
|
|
1466
|
+
const raw = String(ed.textContent || '')
|
|
1467
|
+
if (raw.indexOf('【引用') >= 0) {
|
|
1468
|
+
const sig = raw.slice(0, 40) + '|' + kids.length
|
|
1469
|
+
if (sig !== lastSig) {
|
|
1470
|
+
lastSig = sig
|
|
1471
|
+
report('cmp:probe', {
|
|
1472
|
+
ms: lastInsertAt ? Math.round((typeof performance !== 'undefined' ? performance.now() : Date.now()) - lastInsertAt) : null,
|
|
1473
|
+
kids: kids.length,
|
|
1474
|
+
singles: kids.map((el) => (isSingleLine(String(el.textContent || '').trim()) ? 1 : 0)).join(''),
|
|
1475
|
+
first: String((kids[0] && kids[0].textContent) || '').slice(0, 24),
|
|
1476
|
+
})
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
continue
|
|
1480
|
+
}
|
|
1386
1481
|
headerEl.classList.add('dshq-cmp-header')
|
|
1387
1482
|
quoteEls.forEach((el, idx) => {
|
|
1388
1483
|
el.classList.add('dshq-cmp-quote')
|
|
@@ -1393,11 +1488,13 @@ window.__ModuleLoader__.load({
|
|
|
1393
1488
|
}
|
|
1394
1489
|
} catch (e) { report('cmp:scan-throw', String((e && e.message) || e)) }
|
|
1395
1490
|
}
|
|
1396
|
-
|
|
1491
|
+
// 关键:MutationObserver 回调在**下一次绘制之前**执行 —— 因此在这里同步装饰即可消除
|
|
1492
|
+
// "先露出完整引用块、稍后才变紧凑"的闪烁(之前用 setTimeout(40ms) 期间已经画了一帧)。
|
|
1493
|
+
// decorate() 只在缺少 class 时改动 DOM,不会形成观察循环。
|
|
1397
1494
|
decorate()
|
|
1398
1495
|
composerDecorateNow = decorate
|
|
1399
1496
|
try {
|
|
1400
|
-
observer = new MutationObserver(
|
|
1497
|
+
observer = new MutationObserver(() => { decorate() })
|
|
1401
1498
|
observer.observe(document.body, { childList: true, subtree: true, characterData: true })
|
|
1402
1499
|
} catch (e) { report('cmp:observer-throw', String((e && e.message) || e)) }
|
|
1403
1500
|
return () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-quote-annotate-pro",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "选区引用与锚点批注(增强 fork):划词 → 批注 → 带精确锚点的引用;输入框上方只显示原文片段,点一下跳回原文;发送时把轮次/角色写入引用块,让模型精确知道你指的是哪一处。",
|
|
5
5
|
"keywords": ["dsh", "dsh-plugin", "deepseek-harness", "quote", "annotate", "selection", "reference", "anchor"],
|
|
6
6
|
"license": "MIT",
|