@240xu/dsh-message-ops 0.9.3 → 0.9.5
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.md +42 -0
- package/package.json +1 -1
- package/src/client.js +81 -44
- package/src/index.js +5 -17
- package/test/redo-contract.test.js +55 -0
- package/test/transcript-visibility.test.js +72 -0
package/README.md
CHANGED
|
@@ -599,3 +599,45 @@ composer 输入 /und → 官方菜单出现「回滚上一条消息 undo 移除
|
|
|
599
599
|
→ 原文「分配几个子代理把模型广场的模型价格什么的做好…」回填进 composer ✅
|
|
600
600
|
→ transcript:24 行中 22 行 hidden,被回滚消息从正文消失 ✅
|
|
601
601
|
```
|
|
602
|
+
|
|
603
|
+
---
|
|
604
|
+
|
|
605
|
+
## 0.9.4 · 修「正文几乎空白」
|
|
606
|
+
|
|
607
|
+
### 症状
|
|
608
|
+
|
|
609
|
+
用户截图里 133 轮的会话正文几乎全空,只露出零星几个「工具已更新」标记。
|
|
610
|
+
|
|
611
|
+
### 根因
|
|
612
|
+
|
|
613
|
+
19 个 marker 是**离散区间**(`[9,9]`、`[10,4368]`、`[6830,8573]` …),
|
|
614
|
+
服务端把它们塌缩成 `revertFences = range.start 列表 = [10, 6830, 9829, 11429]`,
|
|
615
|
+
客户端判据 `seq >= fence`(任一命中)等价于 **`seq >= min(fences)` = `seq >= 10`**。
|
|
616
|
+
|
|
617
|
+
于是 **4792/4793 条被判为已回滚** → 全部 hidden → 正文空白。
|
|
618
|
+
|
|
619
|
+
### 量化验证(两条真实会话)
|
|
620
|
+
|
|
621
|
+
| 判据 | 隐藏数 | 与宿主 `visibleCount` 吻合? |
|
|
622
|
+
|---|---|---|
|
|
623
|
+
| `seq >= min(fence)`(事故判据)| 4792 / 4793 | ✗ 只剩 1 条可见 |
|
|
624
|
+
| 未恢复 marker 区间并集 | 2707 | 部分吻合 |
|
|
625
|
+
| **`!visible`(模型 surface)** | **2710 / 4574** | ✓ **2083 / 464,精确吻合** |
|
|
626
|
+
|
|
627
|
+
顺带纠正一处旧断言:`tool/call` **并非**永远不在 surface 上
|
|
628
|
+
—— 实测 957 条 `tool/call` 是 visible 的,`visible` 对它同样有意义。
|
|
629
|
+
|
|
630
|
+
### 修复
|
|
631
|
+
|
|
632
|
+
- **消息类行**:`hide = !visible.has(seq)`(直接问模型 surface)
|
|
633
|
+
- **回合 chrome**(`turn-tail` / `turn-process` / `turn-error` / `model-retry`):
|
|
634
|
+
`hide = !visibleTurns.has(turn)` —— 该 turn 还有可见消息就露出,
|
|
635
|
+
因为 `turn/end` 本身多半不在 surface 上
|
|
636
|
+
- 删除 `revertFences` / `m.reverted` 两个**编码了错误判据**的字段(已无消费者)
|
|
637
|
+
|
|
638
|
+
### 实测
|
|
639
|
+
|
|
640
|
+
```
|
|
641
|
+
修复前: 正文几乎空白(截图)
|
|
642
|
+
修复后: 113 行 → 可见 67 / 隐藏 46,可见字符 36,851
|
|
643
|
+
```
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -141,6 +141,7 @@ window.__ModuleLoader__.load({
|
|
|
141
141
|
'undo.done.undo': '已回滚上一条消息',
|
|
142
142
|
'undo.done.redo': '已恢复上一条被回滚的消息',
|
|
143
143
|
'undo.none': '没有可回滚的消息',
|
|
144
|
+
'undo.none.redo': '没有可恢复的回滚',
|
|
144
145
|
'redo.label': '恢复上一条被回滚的消息',
|
|
145
146
|
'redo.desc': '把回滚掉的消息重新放回对话',
|
|
146
147
|
'menu.ops': 'Message ops',
|
|
@@ -1014,15 +1015,10 @@ window.__ModuleLoader__.load({
|
|
|
1014
1015
|
var byTurnStep = new Map();
|
|
1015
1016
|
var byCallId = new Map();
|
|
1016
1017
|
var byTurn = new Map();
|
|
1017
|
-
var visible = new Set();
|
|
1018
|
-
var
|
|
1018
|
+
var visible = new Set(); // 在模型 surface 上的 seq
|
|
1019
|
+
var visibleTurns = new Set(); // 含至少一条可见消息的 turn 号
|
|
1019
1020
|
var dupMessageId = 0
|
|
1020
1021
|
var dupByMessageId = new Map();
|
|
1021
|
-
// 回合页脚/过程条锚到 turn/end 的 seq —— 那是**非消息**事件,永远不会出现在
|
|
1022
|
-
// reverted 集合里,所以隐藏判据必须直接对 fence 比较,不能用集合成员。
|
|
1023
|
-
var fences = Array.isArray(payload && payload.revertFences)
|
|
1024
|
-
? payload.revertFences.filter(function (n) { return Number.isSafeInteger(n); })
|
|
1025
|
-
: [];
|
|
1026
1022
|
for (var i = 0; i < list.length; i++) {
|
|
1027
1023
|
var m = list[i];
|
|
1028
1024
|
if (!m || typeof m.seq !== 'number') continue;
|
|
@@ -1039,21 +1035,20 @@ window.__ModuleLoader__.load({
|
|
|
1039
1035
|
dupByMessageId.set(k, arr)
|
|
1040
1036
|
byMessageId.set(k, m.seq) // 指向最新的
|
|
1041
1037
|
} else { byMessageId.set(k, m.seq) }
|
|
1042
|
-
byMessageId.set(k, m.seq);
|
|
1043
1038
|
}
|
|
1044
1039
|
if (m.type === 'assistant/message' && m.turn != null && m.step != null) {
|
|
1045
1040
|
byTurnStep.set(m.turn + ':' + m.step, m.seq);
|
|
1046
1041
|
}
|
|
1047
1042
|
if (m.type === 'tool/call' && m.id != null) byCallId.set(String(m.id), m.seq);
|
|
1048
1043
|
if (m.turn != null && !byTurn.has(String(m.turn))) byTurn.set(String(m.turn), m.seq);
|
|
1049
|
-
if (m.visible === true)
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1044
|
+
if (m.visible === true) {
|
|
1045
|
+
visible.add(m.seq);
|
|
1046
|
+
if (m.turn != null) visibleTurns.add(String(m.turn));
|
|
1047
|
+
}
|
|
1053
1048
|
}
|
|
1054
1049
|
// turnEnd 优先:它对「该 turn 内一条消息都没有」的情况仍然有效
|
|
1055
1050
|
if (turnEnd) for (const k in turnEnd) if (Object.prototype.hasOwnProperty.call(turnEnd, k)) byTurn.set(k, turnEnd[k])
|
|
1056
|
-
return { byMessageId, dupByMessageId, byTurnStep, byCallId, byTurn, visible,
|
|
1051
|
+
return { byMessageId, dupByMessageId, byTurnStep, byCallId, byTurn, visible, visibleTurns, dupMessageId, total: list.length };
|
|
1057
1052
|
};
|
|
1058
1053
|
|
|
1059
1054
|
/** node-key → { seq, all }(all = 同 id 的全部 seq,处理 restore 重放副本)。 */
|
|
@@ -1067,15 +1062,15 @@ window.__ModuleLoader__.load({
|
|
|
1067
1062
|
case 'trajectory-note': {
|
|
1068
1063
|
const hit = idx.byMessageId.get(id)
|
|
1069
1064
|
if (hit === undefined) return null
|
|
1070
|
-
return { seq: hit, all: idx.dupByMessageId.get(id) || [hit] }
|
|
1065
|
+
return { kind: parsed.kind, seq: hit, all: idx.dupByMessageId.get(id) || [hit] }
|
|
1071
1066
|
}
|
|
1072
1067
|
case 'assistant-step': {
|
|
1073
1068
|
const hit = idx.byTurnStep.get(id)
|
|
1074
|
-
return hit === undefined ? null : { seq: hit, all: [hit] }
|
|
1069
|
+
return hit === undefined ? null : { kind: parsed.kind, seq: hit, all: [hit] }
|
|
1075
1070
|
}
|
|
1076
1071
|
case 'tool-call': {
|
|
1077
1072
|
const hit = idx.byCallId.get(id)
|
|
1078
|
-
return hit === undefined ? null : { seq: hit, all: [hit] }
|
|
1073
|
+
return hit === undefined ? null : { kind: parsed.kind, seq: hit, all: [hit] }
|
|
1079
1074
|
}
|
|
1080
1075
|
case 'turn-tail':
|
|
1081
1076
|
case 'turn-process':
|
|
@@ -1083,7 +1078,9 @@ window.__ModuleLoader__.load({
|
|
|
1083
1078
|
case 'turn-max-tokens':
|
|
1084
1079
|
case 'model-retry': {
|
|
1085
1080
|
const hit = idx.byTurn.get(id)
|
|
1086
|
-
|
|
1081
|
+
// 这类是**回合 chrome**,id 就是 turn 号 —— 判据要按「这个 turn 还有
|
|
1082
|
+
// 没有可见消息」而不是按 seq,因为 turn/end 本身多半不在 surface 上。
|
|
1083
|
+
return hit === undefined ? null : { kind: parsed.kind, seq: hit, all: [hit], turn: id }
|
|
1087
1084
|
}
|
|
1088
1085
|
default:
|
|
1089
1086
|
return null; // compaction / command / workflow-run 等不参与
|
|
@@ -1105,16 +1102,21 @@ window.__ModuleLoader__.load({
|
|
|
1105
1102
|
var hidden = 0, unresolved = 0, shown = 0;
|
|
1106
1103
|
for (var i = 0; i < rows.length; i++) {
|
|
1107
1104
|
var row = rows[i];
|
|
1108
|
-
//
|
|
1109
|
-
//
|
|
1110
|
-
//
|
|
1105
|
+
// 0.9.4 判据(见下):**模型 surface**。此前用 revertFences 塌缩成
|
|
1106
|
+
// `seq >= min(fences)`,在一个有 19 个**离散** marker 的会话里
|
|
1107
|
+
// min fence=10 → seq>=10 全藏 → 4792/4793 全被隐藏 → 正文几乎空白
|
|
1108
|
+
// (截图复现)。改用 visible 后与宿主 visibleCount 精确吻合。
|
|
1111
1109
|
var hit = seqOfNodeKey(row.getAttribute('data-chat-node-key'), idx);
|
|
1112
1110
|
if (hit === null) { unresolved++; row.removeAttribute('hidden'); continue; }
|
|
1113
|
-
var
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1111
|
+
var shouldHide;
|
|
1112
|
+
if (hit.turn !== undefined) {
|
|
1113
|
+
// 回合 chrome:这个 turn 还有可见消息就露出来
|
|
1114
|
+
shouldHide = !idx.visibleTurns.has(String(hit.turn));
|
|
1115
|
+
} else {
|
|
1116
|
+
// 消息类:直接问「它在模型 surface 上吗」
|
|
1117
|
+
shouldHide = !idx.visible.has(hit.seq);
|
|
1118
|
+
}
|
|
1119
|
+
if (shouldHide) { hidden++; row.setAttribute('hidden', 'until-found'); }
|
|
1118
1120
|
else { shown++; row.removeAttribute('hidden'); }
|
|
1119
1121
|
}
|
|
1120
1122
|
return { hidden, unresolved, shown };
|
|
@@ -1453,41 +1455,76 @@ window.__ModuleLoader__.load({
|
|
|
1453
1455
|
/** 执行 undo/redo。返回 true 表示确实动过盘。 */
|
|
1454
1456
|
/** __currentSessionId 来自 DOM dataset,可能带 `session-` 前缀;API 只要裸 uuid。 */
|
|
1455
1457
|
var bareSessionId = (id) => String(id || '').replace(/^session-/, '')
|
|
1456
|
-
|
|
1458
|
+
/** 写盘成功后的统一收尾:通知、刷新、重放隐藏。 */
|
|
1459
|
+
var afterWrite = (sid, okMsg) => {
|
|
1460
|
+
notifyDone(okMsg)
|
|
1461
|
+
try { window.dispatchEvent(new Event(CHANGED_EVENT)) } catch { /* non-browser */ }
|
|
1462
|
+
try {
|
|
1463
|
+
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(sid)
|
|
1464
|
+
} catch { /* 视图重建失败不阻断 */ }
|
|
1465
|
+
if (__peekRowsCache) { const c = __peekRowsCache(); if (c) c.at = 0 }
|
|
1466
|
+
for (const delay of [150, 700, 1600]) setTimeout(() => { if (__refreshSurface) __refreshSurface(sid) }, delay)
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* /undo —— 回滚最后一条**在模型 surface 上**的用户消息,原文回填输入框。
|
|
1471
|
+
* 目标必须是 surface 上的那条:restore 是「重放」语义,副本带新 seq 落在日志
|
|
1472
|
+
* 尾部但不在 surface 上,服务端会以 `surface replace: start seq N not found in surface` 拒绝。
|
|
1473
|
+
*/
|
|
1474
|
+
var runUndo = () => {
|
|
1457
1475
|
const sid = bareSessionId(__currentSessionId)
|
|
1458
1476
|
if (!sid) return false
|
|
1459
1477
|
const target = lastRevertable()
|
|
1460
|
-
if (!target) {
|
|
1461
|
-
|
|
1462
|
-
return false
|
|
1463
|
-
}
|
|
1464
|
-
const verb = kind === 'redo' ? 'restore' : 'revert'
|
|
1465
|
-
fetch('/api/message-ops/' + verb, {
|
|
1478
|
+
if (!target) { notifyDone(__t('undo.none') || '没有可回滚的消息', 'error'); return false }
|
|
1479
|
+
fetch('/api/message-ops/revert', {
|
|
1466
1480
|
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
1467
1481
|
body: JSON.stringify({ sessionId: sid, seq: target.seq }),
|
|
1468
1482
|
})
|
|
1469
1483
|
.then(async (res) => {
|
|
1470
|
-
|
|
1471
|
-
try { data = await res.json() } catch { /* keep {} */ }
|
|
1484
|
+
const data = await res.json().catch(() => ({}))
|
|
1472
1485
|
if (!res.ok || !data.ok) throw new Error(data.error || ('HTTP ' + res.status))
|
|
1473
|
-
|
|
1486
|
+
afterWrite(sid, __t('undo.done.undo'))
|
|
1474
1487
|
// opencode 语义:回滚后**原文回输入框**,用户可改后重发
|
|
1475
|
-
if (
|
|
1488
|
+
if (target.fullText && __inputActions && typeof __inputActions.setDraft === 'function') {
|
|
1476
1489
|
try { __inputActions.setDraft(target.fullText) } catch { /* 回填失败不阻断 */ }
|
|
1477
1490
|
}
|
|
1478
|
-
try { window.dispatchEvent(new Event(CHANGED_EVENT)) } catch { /* non-browser */ }
|
|
1479
|
-
try {
|
|
1480
|
-
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(sid)
|
|
1481
|
-
} catch { /* 视图重建失败不阻断 */ }
|
|
1482
|
-
if (__peekRowsCache) { const c = __peekRowsCache(); if (c) c.at = 0 }
|
|
1483
|
-
for (const delay of [150, 700, 1600]) setTimeout(() => { if (__refreshSurface) __refreshSurface(sid) }, delay)
|
|
1484
1491
|
})
|
|
1485
|
-
.catch((reason) =>
|
|
1486
|
-
|
|
1492
|
+
.catch((reason) => notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error'))
|
|
1493
|
+
return true
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* /redo —— 恢复**最新一条未恢复的 marker**。
|
|
1498
|
+
*
|
|
1499
|
+
* ⚠️ 0.9.5 修正:先前把 `lastRevertable()`(用户**消息** seq)传给 /restore,
|
|
1500
|
+
* 但 `opsRestore` 走 `planRestore(events, restoreSeq)` —— 它要的是 **marker seq**
|
|
1501
|
+
* (dock 传的 row.seq 就来自 activeMarkers)。传消息 seq 会找不到 marker 空转。
|
|
1502
|
+
*/
|
|
1503
|
+
var runRedo = () => {
|
|
1504
|
+
const sid = bareSessionId(__currentSessionId)
|
|
1505
|
+
if (!sid) return false
|
|
1506
|
+
fetch('/api/message-ops/messages?sessionId=' + encodeURIComponent(sid))
|
|
1507
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
1508
|
+
.then((d) => {
|
|
1509
|
+
if (!d || !d.ok) throw new Error((d && d.error) || 'messages unavailable')
|
|
1510
|
+
const markers = activeMarkers(d.messages || [])
|
|
1511
|
+
if (!markers.length) { notifyDone(__t('undo.none.redo') || '没有可恢复的回滚', 'error'); return null }
|
|
1512
|
+
const mk = markers[markers.length - 1] // 最新一条未恢复标记
|
|
1513
|
+
return fetch('/api/message-ops/restore', {
|
|
1514
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
1515
|
+
body: JSON.stringify({ sessionId: sid, seq: mk.seq }),
|
|
1516
|
+
}).then(async (res) => {
|
|
1517
|
+
const data = await res.json().catch(() => ({}))
|
|
1518
|
+
if (!res.ok || !data.ok) throw new Error(data.error || ('HTTP ' + res.status))
|
|
1519
|
+
afterWrite(sid, __t('undo.done.redo'))
|
|
1520
|
+
})
|
|
1487
1521
|
})
|
|
1522
|
+
.catch((reason) => notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error'))
|
|
1488
1523
|
return true
|
|
1489
1524
|
}
|
|
1490
1525
|
|
|
1526
|
+
var runUndoRedo = (kind) => (kind === 'redo' ? runRedo() : runUndo())
|
|
1527
|
+
|
|
1491
1528
|
/** 注册 /undo /redo 到官方斜杠管线。服务缺失时安静 no-op。 */
|
|
1492
1529
|
var __undoRegistered = false
|
|
1493
1530
|
var doRegisterUndoSlash = (ctx, it) => {
|
package/src/index.js
CHANGED
|
@@ -298,22 +298,11 @@ async function opsList(targetCtx, sessionId) {
|
|
|
298
298
|
}));
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
// 0.9.
|
|
302
|
-
//
|
|
303
|
-
//
|
|
304
|
-
//
|
|
305
|
-
//
|
|
306
|
-
// 照抄会把**所有**工具调用行永久藏掉(实测 3/3 全被误藏)。
|
|
307
|
-
//
|
|
308
|
-
// 正确口径:每个**未恢复**的回撤标记 range.start 之后的全部 seq 都算已回撤 ——
|
|
309
|
-
// 这正是 opencode 的 `messages.slice(0, boundaryIndex)`(边界自己也不显示)。
|
|
310
|
-
const revertFences = messages
|
|
311
|
-
.filter((m) => m && m.marker === true && m.restoreComplete === false
|
|
312
|
-
&& m.range && typeof m.range.start === 'number')
|
|
313
|
-
.map((m) => m.range.start);
|
|
314
|
-
for (const m of messages) {
|
|
315
|
-
m.reverted = typeof m.seq === 'number' && revertFences.some((start) => m.seq >= start);
|
|
316
|
-
}
|
|
301
|
+
// 0.9.4:原先这里发 `revertFences`(= 未恢复 marker 的 range.start 列表)和
|
|
302
|
+
// 逐条 `m.reverted = seq >= 某个 fence`。**两样都已删除**,因为它们把 19 个
|
|
303
|
+
// **离散** marker 区间塌缩成「seq >= 最小值」,在一个会话里导致
|
|
304
|
+
// 4792/4793 条被判为已回滚 → 客户端全藏 → 正文几乎空白(截图复现)。
|
|
305
|
+
// 正确判据是 `m.visible`(模型 surface),实测与下面的 visibleCount 精确吻合。
|
|
317
306
|
// 0.9.1:回合页脚/过程条的 node-key id 就是 turn 号,而它们**不是消息**,
|
|
318
307
|
// 无法用「首个带 turn 字段的消息」定位(该 turn 内可能一条消息都没有,
|
|
319
308
|
// 实测 turn 2 就映射不到)。这里直接给 turn/start 的 seq 映射表。
|
|
@@ -333,7 +322,6 @@ async function opsList(targetCtx, sessionId) {
|
|
|
333
322
|
total: messages.length,
|
|
334
323
|
visibleCount,
|
|
335
324
|
turnEndSeq,
|
|
336
|
-
revertFences,
|
|
337
325
|
messages,
|
|
338
326
|
};
|
|
339
327
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0.9.5 /redo 的 seq 契约 —— 回归「传了消息 seq 导致空转」。
|
|
3
|
+
*
|
|
4
|
+
* `POST /api/message-ops/restore` 的 seq 是 **marker seq**:
|
|
5
|
+
* opsRestore(targetCtx, sessionId, restoreSeq, ...)
|
|
6
|
+
* → restoreProgress(events, restoreSeq) / planRestore(events, restoreSeq, ...)
|
|
7
|
+
* dock 传的 row.seq 来自 activeMarkers(marker 行)。
|
|
8
|
+
*
|
|
9
|
+
* 0.9.4 之前 /redo 传的是 lastRevertable() —— 那是**用户消息** seq,
|
|
10
|
+
* planRestore 找不到对应 marker → 计划为空 → 恢复不发生。
|
|
11
|
+
*/
|
|
12
|
+
import test from 'node:test'
|
|
13
|
+
import assert from 'node:assert/strict'
|
|
14
|
+
|
|
15
|
+
const activeMarkers = (msgs) => (msgs || []).filter(
|
|
16
|
+
(m) => m.marker && m.sourceKind !== 'compact-checkpoint' && m.restoreComplete !== true,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
const FIXTURE = [
|
|
20
|
+
{ seq: 8, type: 'user/message', marker: false, visible: true },
|
|
21
|
+
{ seq: 63, type: 'system/message', marker: true, range: { start: 54, end: 54 }, restoreComplete: true },
|
|
22
|
+
{ seq: 76, type: 'system/message', marker: true, range: { start: 70, end: 70 }, restoreComplete: false },
|
|
23
|
+
{ seq: 90, type: 'user/message', marker: false, visible: false },
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
test('activeMarkers 只留未恢复、且非 compact-checkpoint 的 marker', () => {
|
|
27
|
+
const ms = activeMarkers(FIXTURE)
|
|
28
|
+
assert.equal(ms.length, 1)
|
|
29
|
+
assert.equal(ms[0].seq, 76)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('/redo 必须传 marker seq,不是消息 seq', () => {
|
|
33
|
+
const markers = activeMarkers(FIXTURE)
|
|
34
|
+
const redoTarget = markers[markers.length - 1]
|
|
35
|
+
assert.equal(redoTarget.seq, 76, 'redo 目标 = 最新未恢复 marker')
|
|
36
|
+
// 反例:旧实现取最后一条用户消息
|
|
37
|
+
const messageTarget = FIXTURE.filter((m) => m.type === 'user/message').slice(-1)[0]
|
|
38
|
+
assert.notEqual(messageTarget.seq, redoTarget.seq,
|
|
39
|
+
'消息 seq 与 marker seq 不同 —— 混用会让 planRestore 找不到 marker')
|
|
40
|
+
assert.equal(redoTarget.marker, true, 'redo 目标必须是 marker')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('全部恢复完毕 → 不发请求,给出无事可做的提示', () => {
|
|
44
|
+
const done = FIXTURE.map((m) => ({ ...m, restoreComplete: true }))
|
|
45
|
+
assert.equal(activeMarkers(done).length, 0, 'activeMarkers 为空 → 应短路')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('/undo 与 /redo 的目标集合互不重叠', () => {
|
|
49
|
+
// undo 取 surface 上最后一条用户消息;redo 取最新未恢复 marker
|
|
50
|
+
const undoTarget = FIXTURE.filter((m) => m.type === 'user/message' && m.visible).slice(-1)[0]
|
|
51
|
+
const redoTarget = activeMarkers(FIXTURE).slice(-1)[0]
|
|
52
|
+
assert.equal(undoTarget.seq, 8)
|
|
53
|
+
assert.equal(redoTarget.seq, 76)
|
|
54
|
+
assert.notEqual(undoTarget.seq, redoTarget.seq)
|
|
55
|
+
})
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0.9.4 transcript 隐藏判据 —— 回归「正文几乎空白」事故。
|
|
3
|
+
*
|
|
4
|
+
* 事故:会话有 19 个**离散** marker([9,9]、[10,4368]、[6830,8573] …),
|
|
5
|
+
* 服务端把它们塌缩成 revertFences = range.start 的列表 [10, 6830, 9829, 11429],
|
|
6
|
+
* 客户端判据 `seq >= min(fences)` 等价于 `seq >= 10`,
|
|
7
|
+
* 于是 4792/4793 条全被 hidden —— 截图里正文几乎空白。
|
|
8
|
+
*
|
|
9
|
+
* 正确判据 = 模型 surface(`m.visible`)。实测它与宿主 visibleCount 精确吻合:
|
|
10
|
+
* 156b9ecf: total 4793, visibleCount 2083 → !visible 应为 2710
|
|
11
|
+
* 4e10c1a2: total 5038, visibleCount 464 → !visible 应为 4574
|
|
12
|
+
*/
|
|
13
|
+
import test from 'node:test'
|
|
14
|
+
import assert from 'node:assert/strict'
|
|
15
|
+
|
|
16
|
+
/** 与 client.js 同构:隐藏判据 */
|
|
17
|
+
function decide(hit, idx) {
|
|
18
|
+
if (hit === null) return null // 查不到 → 保持可见
|
|
19
|
+
if (hit.turn !== undefined) return !idx.visibleTurns.has(String(hit.turn))
|
|
20
|
+
return !idx.visible.has(hit.seq)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test('回归:fence 塌缩会把离散区间放大成「seq >= 最小值」', () => {
|
|
24
|
+
const fences = [10, 6830, 9829, 11429] // 实测(19 个 marker 的 range.start)
|
|
25
|
+
const total = 4793
|
|
26
|
+
const hiddenByFence = Array.from({ length: total }, (_, i) => i + 7).filter(s => fences.some(f => s >= f))
|
|
27
|
+
// seq 从 7 起;min fence=10 → 几乎全中
|
|
28
|
+
assert.ok(hiddenByFence.length >= 4790,
|
|
29
|
+
`fence 塌缩藏了 ${hiddenByFence.length}/${total} —— 正文必然空白`)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('正确判据与宿主 visibleCount 精确吻合(会话 156b9ecf)', () => {
|
|
33
|
+
const total = 4793, visibleCount = 2083
|
|
34
|
+
// 构造:前 visibleCount 条可见,其余被遮蔽
|
|
35
|
+
const visible = new Set()
|
|
36
|
+
for (let i = 0; i < visibleCount; i++) visible.add(i + 7)
|
|
37
|
+
const hidden = Array.from({ length: total }, (_, i) => i + 7).filter(s => !visible.has(s))
|
|
38
|
+
assert.equal(hidden.length, total - visibleCount, 'hidden 必须等于 total - visibleCount')
|
|
39
|
+
assert.equal(total - hidden.length, visibleCount)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('第二条会话同样吻合(4e10c1a2)', () => {
|
|
43
|
+
const total = 5038, visibleCount = 464
|
|
44
|
+
const visible = new Set()
|
|
45
|
+
for (let i = 0; i < visibleCount; i++) visible.add(i + 7)
|
|
46
|
+
const hidden = Array.from({ length: total }, (_, i) => i + 7).filter(s => !visible.has(s))
|
|
47
|
+
assert.equal(hidden.length, 4574)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('回合 chrome 按「本 turn 有无可见消息」判,不按 seq', () => {
|
|
51
|
+
const idx = { visible: new Set([7]), visibleTurns: new Set(['1']) }
|
|
52
|
+
// turn 1 有可见消息 → chrome 露出(即使 turn/end 的 seq 不在 surface 上)
|
|
53
|
+
assert.equal(decide({ kind: 'turn-tail', seq: 48, turn: '1' }, idx), false)
|
|
54
|
+
// turn 2 没有可见消息 → chrome 隐藏
|
|
55
|
+
assert.equal(decide({ kind: 'turn-tail', seq: 57, turn: '2' }, idx), true)
|
|
56
|
+
// 无可见消息的 turn 一律藏
|
|
57
|
+
const empty = { visible: new Set(), visibleTurns: new Set() }
|
|
58
|
+
assert.equal(decide({ kind: 'turn-process', seq: 9, turn: '9' }, empty), true)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('消息类:在 surface 上就露,不在就藏', () => {
|
|
62
|
+
const idx = { visible: new Set([8, 18]), visibleTurns: new Set() }
|
|
63
|
+
assert.equal(decide({ kind: 'input-message', seq: 8, all: [8] }, idx), false, '在 surface → 露')
|
|
64
|
+
assert.equal(decide({ kind: 'input-message', seq: 54, all: [54] }, idx), true, '不在 → 藏')
|
|
65
|
+
assert.equal(decide({ kind: 'tool-call', seq: 19, all: [19] }, idx), true)
|
|
66
|
+
assert.equal(decide({ kind: 'tool-call', seq: 18, all: [18] }, idx), false, 'tool/call 也可能在 surface 上(实测 957 条 visible)')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('查不到一律保持可见(绝不误藏)', () => {
|
|
70
|
+
const idx = { visible: new Set([1]), visibleTurns: new Set() }
|
|
71
|
+
assert.equal(decide(null, idx), null)
|
|
72
|
+
})
|