@240xu/dsh-message-ops 0.13.0 → 0.15.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.md +101 -0
- package/package.json +1 -1
- package/src/client.js +155 -28
- package/src/index.js +31 -0
- package/src/ops-core.js +17 -0
- package/src/session-file.js +30 -3
package/README.md
CHANGED
|
@@ -891,6 +891,107 @@ min fence=10 → seq>=10 全藏 → 4792/4793 全被隐藏 → 正文几乎空
|
|
|
891
891
|
| `src/index.js:336-340` `revertFences` 塌缩复盘 | 「0.9.4 · 修「正文几乎空白」」 |
|
|
892
892
|
| `src/ops-core.js:551-557` 0.5.7 磁盘路径复盘 | 「0.5.7 · 第四层根因:store-miss 会话的磁盘追加路径」 |
|
|
893
893
|
|
|
894
|
+
### 0.15.0 · 回滚要「像干净请求」:工具清单变更必须一起消失
|
|
895
|
+
|
|
896
|
+
用户原话:「我说的撤回,只是不显示我重新发起的请求,就像干净请求。」
|
|
897
|
+
|
|
898
|
+
现象:回滚一条用户消息后,主对话流里「新增了 N 个工具」那行**还在**;
|
|
899
|
+
供应商报错(`llm/retry`)相关的重试行也留着。
|
|
900
|
+
|
|
901
|
+
**根因(全部在宿主实际下发的 bundle 里取证,不是推测):**
|
|
902
|
+
|
|
903
|
+
```js
|
|
904
|
+
// 宿主 dsh-client-ui-chat:developerMessageDefinition
|
|
905
|
+
match: (event) => event.type === "developer/message" ? { ... } : null
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
对比 `user/message` 的 match:
|
|
909
|
+
|
|
910
|
+
```js
|
|
911
|
+
if (event.type === "user/message")
|
|
912
|
+
return isAppendSurfaceEvent(event) && !isCompactionCheckpoint(event) ? ... : null
|
|
913
|
+
```
|
|
914
|
+
|
|
915
|
+
**`user/message` 有 `isAppendSurfaceEvent` 这道闸,`developer/message` 没有。**
|
|
916
|
+
再加上 `isVisibleChatNode` 里对含 `tool-addition`/`tool-removal` 的 context 节点
|
|
917
|
+
**强制可见**:
|
|
918
|
+
|
|
919
|
+
```js
|
|
920
|
+
node.kind !== "context" || node.data.content.some(b =>
|
|
921
|
+
b.type === "tool-addition" || b.type === "tool-removal")
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
结果:surface replace 把工具清单变更事件正确遮蔽了(**模型上下文是干净的**),
|
|
925
|
+
但 UI 照样渲染那一行 —— 用户看到「回滚没撤回干净」。
|
|
926
|
+
|
|
927
|
+
**修法**(插件侧唯一抓手是渲染层遮蔽同步,宿主渲染器改不了):
|
|
928
|
+
|
|
929
|
+
1. `listMessages` 收录 `developer/message`(此前只收 user/assistant/system)。
|
|
930
|
+
不收 → 遮蔽状态传不到客户端 → `byMessageId` 查不到 → 调用方「保持可见」。
|
|
931
|
+
2. `textSegments` 把 `tool-addition`/`tool-removal` 渲染成 `+name`/`-name`。
|
|
932
|
+
不转 → snippet 为空串 → 被 rows 的 `r.sn` 过滤条件当无效行丢掉。
|
|
933
|
+
3. compact 投影补 `id`。客户端用 `<kindLen>:<kind><id>`(实测
|
|
934
|
+
`17:developer-message<uuid>`)拼 `data-chat-node-key` 反查 seq,
|
|
935
|
+
没有 id 这条链就断了。
|
|
936
|
+
|
|
937
|
+
实机验证(3096,真实会话 1530 行):
|
|
938
|
+
|
|
939
|
+
```
|
|
940
|
+
seq= 458 id=2a306c76-6 shadowed=true | +sidebar_open
|
|
941
|
+
seq= 471 id=deb0ed06-1 shadowed=true | -subagent_codex
|
|
942
|
+
seq= 552 id=b32cdc8b-8 shadowed=true | +subagent_codex
|
|
943
|
+
seq= 700 id=8ea41701-f shadowed=true | +import_chat
|
|
944
|
+
seq=3726 id=61b519dd-d shadowed=true | +browser_click
|
|
945
|
+
```
|
|
946
|
+
|
|
947
|
+
**没有做的(且不应该做)**:`llm/retry` / `assistant/attempt` 不是 surface 节点,
|
|
948
|
+
它们不进模型上下文,遮蔽它们没有语义意义。如果你在界面上看到重试痕迹,
|
|
949
|
+
那是宿主自己的 `model-retry` / `turn-error` 节点,不在本插件管辖范围。
|
|
950
|
+
|
|
951
|
+
新增 `test/developer-message-shadow.test.js`(6 条)。测试 292(288 pass / 4 skip)。
|
|
952
|
+
|
|
953
|
+
### 0.13.1 · 修第二轮对抗审查的两个 HIGH
|
|
954
|
+
|
|
955
|
+
**HIGH-1|隐藏官方 branch 按钮在 0.2.2-alpha.2 上 100% 无效。**
|
|
956
|
+
0.12.0 用 `svg path` 的 `d` 前缀 `M13.0762…` 识别官方 branch 图标 —— 但该版本图标已改为
|
|
957
|
+
**sprite 复用**,官方组件(app bundle 里的工厂 `T(e,t)`)渲染的是:
|
|
958
|
+
|
|
959
|
+
```html
|
|
960
|
+
<svg data-icon="dsw-icon-branch-outline-regular" aria-hidden="true">
|
|
961
|
+
<use href="#dsw-icon-branch-outline-regular"/>
|
|
962
|
+
</svg>
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
**DOM 里根本没有 `<path>`**,`M13.0762` 在整个已安装 dsh 里 0 次命中 → `d` 恒为空 →
|
|
966
|
+
`suppressHostBranch()` 一个按钮也藏不掉,且静默失效、无报错。
|
|
967
|
+
更糟的是 `test/fork-dom-behavior.test.js` 当时用自造的 `<path d="M13.0762…">` 夹具,
|
|
968
|
+
**测的是自己的假设,不是宿主现实**,所以一直绿。
|
|
969
|
+
修法:主判据改为 `svg[data-icon="dsw-icon-branch-outline-regular"]`(id 由工厂
|
|
970
|
+
`Qv(e,t)=`dsw-icon-${name}-${size}`` 生成,属契约级常量),保留内联 path 作为旧宿主兼容回退;
|
|
971
|
+
测试夹具换成真实的 `<use>` 形状。
|
|
972
|
+
|
|
973
|
+
**HIGH-2|审查者认为面板分叉恒走坏回退 —— 复核后不成立。**
|
|
974
|
+
报告称 `OpsDialog` 没带 `&view=compact` 所以 `turnStartSeq` 恒 `undefined`。
|
|
975
|
+
实测(`_internals.opsList` 对同一会话跑 full / compact 两遍):full view 同样返回
|
|
976
|
+
`turnStartSeq = 4`,因为 `buildDerived` 是把它挂在**消息对象本身**上,而非 compact
|
|
977
|
+
分支返回的就是这些完整消息对象 —— compact 只是挑了字段子集,不是唯一来源。
|
|
978
|
+
故未改动。
|
|
979
|
+
|
|
980
|
+
**其余三条 MED 的复核结论**:
|
|
981
|
+
- `seq - 1` 回退对 `inheritedEventCount` 会话不成立 → **不成立**。实测 9 个
|
|
982
|
+
`isSeeded` 子会话,seq 均从 0 重新编号(`minSeq=0`),`inheritedEventCount` 只是日志
|
|
983
|
+
长度统计,不偏移 seq;restore 副本同理(服务端按新 seq 重算 `turnStartSeq`)。
|
|
984
|
+
- `persistDraft` 空转却报成功 → **成立**,已修:写入后**回读** `dsh.conversation.<sid>`,
|
|
985
|
+
对不上就报 `panel.editUnavailable` 且**不 close**。
|
|
986
|
+
- 160 字截断的 snippet 冒充原文 → **成立**,已修:新增显式 `detailFull` 状态,
|
|
987
|
+
`/text` 失败即降级为 `false`,编辑按钮要求 `detailFull === true`。
|
|
988
|
+
|
|
989
|
+
**两条 LOW 均成立并已修**:`revert.unresolved` 从未定义(改用已有的
|
|
990
|
+
`slot.revertUnmatched`);`OpsDialog` 的 `op.branch` 文案仍是旧「含该条」语义(改为 before)。
|
|
991
|
+
|
|
992
|
+
新增 `test/reviewer-round2.test.js`(8 条),其中 i18n 锁会扫出**任何**未定义的
|
|
993
|
+
`__t('…')` key。测试 276(272 pass / 4 skip)。
|
|
994
|
+
|
|
894
995
|
### 0.13.0 · 代码风格官方化 + 拆掉「格式被测试冻住」的问题
|
|
895
996
|
|
|
896
997
|
**风格**(与 `~/.dsh/deepseek-harness-master/.oxlintrc.json` 的 `@stylistic/*` 规则一致):
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -129,8 +129,8 @@ window.__ModuleLoader__.load({
|
|
|
129
129
|
'op.revertDesc': '遮蔽所选消息及其后所有可见内容;日志 append-only,可通过重新发送恢复语境。',
|
|
130
130
|
'op.delete': '仅删除这一条',
|
|
131
131
|
'op.deleteDesc': '仅遮蔽所选的一条消息;其余内容保持不变。',
|
|
132
|
-
'op.branch': '
|
|
133
|
-
'op.branchDesc': '
|
|
132
|
+
'op.branch': '从此条分叉为新会话',
|
|
133
|
+
'op.branchDesc': '把此条之前的对话复制到新会话,并把此条原文放回新会话输入框(原会话不变,非破坏操作)。',
|
|
134
134
|
'slot.revert': '回滚到此条',
|
|
135
135
|
'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
|
|
136
136
|
'slot.fork': '从此条分叉',
|
|
@@ -212,6 +212,7 @@ window.__ModuleLoader__.load({
|
|
|
212
212
|
'panel.editDone': '原文已放回输入框',
|
|
213
213
|
'panel.editEmpty': '这条消息没有可编辑的文本',
|
|
214
214
|
'panel.editUnavailable': '编辑器不可写(会话可能正在运行或尚未挂载)',
|
|
215
|
+
'panel.editNotReady': '全文尚未就绪(列表只带 160 字摘要)——请重试或改用回滚回填',
|
|
215
216
|
'panel.openNew': '打开新会话',
|
|
216
217
|
'panel.revertDone': '回滚已生效',
|
|
217
218
|
'panel.deleteDone': '删除已生效',
|
|
@@ -254,8 +255,9 @@ window.__ModuleLoader__.load({
|
|
|
254
255
|
'Shadows the picked message and all later visible content; the log stays append-only so context can be restored by re-sending.',
|
|
255
256
|
'op.delete': 'Delete only this message',
|
|
256
257
|
'op.deleteDesc': 'Shadows only the picked message; everything else stays.',
|
|
257
|
-
'op.branch': '
|
|
258
|
-
'op.branchDesc':
|
|
258
|
+
'op.branch': 'Fork into a new session from here',
|
|
259
|
+
'op.branchDesc':
|
|
260
|
+
'Copies the conversation above the picked message into a new session and puts this message back in the new composer (original untouched, non-destructive).',
|
|
259
261
|
'slot.revert': 'Revert to here',
|
|
260
262
|
'slot.revertUnmatched':
|
|
261
263
|
'Cannot locate this message seq in the log (usually the model-written summary drifted too far from the rendered text) — use the Message ops dialog instead.',
|
|
@@ -340,6 +342,7 @@ window.__ModuleLoader__.load({
|
|
|
340
342
|
'panel.editDone': 'Original text is back in the composer',
|
|
341
343
|
'panel.editEmpty': 'This message has no editable text',
|
|
342
344
|
'panel.editUnavailable': 'Composer is not writable (session may be running or not mounted)',
|
|
345
|
+
'panel.editNotReady': 'Full text is not ready (the list only carries a 160-char snippet) — retry, or use revert to refill',
|
|
343
346
|
'panel.openNew': 'Open new session',
|
|
344
347
|
'panel.revertDone': 'Revert applied',
|
|
345
348
|
'panel.deleteDone': 'Delete applied',
|
|
@@ -1123,6 +1126,8 @@ window.__ModuleLoader__.load({
|
|
|
1123
1126
|
const [picked, setPicked] = useState(null)
|
|
1124
1127
|
const [detail, setDetail] = useState('')
|
|
1125
1128
|
const [detailState, setDetailState] = useState('idle')
|
|
1129
|
+
// MED-5:detail 是**全文**还是 snippet 回退?只有全文才允许「编辑并重发」。
|
|
1130
|
+
const [detailFull, setDetailFull] = useState(false)
|
|
1126
1131
|
const [tab, setTab] = useState('messages')
|
|
1127
1132
|
const [hits, setHits] = useState(null)
|
|
1128
1133
|
const [searching, setSearching] = useState(false)
|
|
@@ -1382,6 +1387,17 @@ window.__ModuleLoader__.load({
|
|
|
1382
1387
|
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
1383
1388
|
return
|
|
1384
1389
|
}
|
|
1390
|
+
// MED-4:`persistDraft` 存在 ≠ 真的落盘。宿主的 writer 由
|
|
1391
|
+
// `bindDraftPersistence` 在视图挂载时绑定;blank/hero 态或视图未挂载时
|
|
1392
|
+
// 该函数在但空转。于是「setDraft 改的是内存编辑器、随后 close() 关面板、
|
|
1393
|
+
// 宿主重挂会话时从 localStorage 读回旧草稿」→ 用户看到成功却什么都没了。
|
|
1394
|
+
// 判据不能靠函数存在,只能**回读**:写不进存储就当失败,不 close。
|
|
1395
|
+
const sidForDraft = target.sessionId
|
|
1396
|
+
const stored = readSessionDraft(sidForDraft)
|
|
1397
|
+
if (stored != null && stored !== body) {
|
|
1398
|
+
setError(t('panel.editUnavailable'))
|
|
1399
|
+
return
|
|
1400
|
+
}
|
|
1385
1401
|
setDone(t('panel.editDone'))
|
|
1386
1402
|
notifyDone(t('panel.editDone'))
|
|
1387
1403
|
close()
|
|
@@ -1546,6 +1562,7 @@ window.__ModuleLoader__.load({
|
|
|
1546
1562
|
detailReq.current += 1
|
|
1547
1563
|
setPicked(null)
|
|
1548
1564
|
setDetail('')
|
|
1565
|
+
setDetailFull(false)
|
|
1549
1566
|
setDetailState('idle')
|
|
1550
1567
|
setConfirmAction(null)
|
|
1551
1568
|
}
|
|
@@ -1555,6 +1572,7 @@ window.__ModuleLoader__.load({
|
|
|
1555
1572
|
detailReq.current += 1
|
|
1556
1573
|
setPicked(m)
|
|
1557
1574
|
setDetail(m.snippet || '')
|
|
1575
|
+
setDetailFull(false)
|
|
1558
1576
|
setDetailState('ready')
|
|
1559
1577
|
setConfirmAction(null)
|
|
1560
1578
|
setDone('')
|
|
@@ -1631,6 +1649,7 @@ window.__ModuleLoader__.load({
|
|
|
1631
1649
|
setConfirmAction(null)
|
|
1632
1650
|
setPicked(m)
|
|
1633
1651
|
setDetail(m.snippet || '')
|
|
1652
|
+
setDetailFull(false)
|
|
1634
1653
|
setDetailState('loading')
|
|
1635
1654
|
setDone('')
|
|
1636
1655
|
const req = ++detailReq.current
|
|
@@ -1644,12 +1663,15 @@ window.__ModuleLoader__.load({
|
|
|
1644
1663
|
.then(({ res, data }) => {
|
|
1645
1664
|
if (req !== detailReq.current) return
|
|
1646
1665
|
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
1647
|
-
|
|
1666
|
+
const full = typeof data.text === 'string' && data.text !== '' ? data.text : null
|
|
1667
|
+
setDetail(full ?? (m.snippet || ''))
|
|
1668
|
+
setDetailFull(full !== null)
|
|
1648
1669
|
setDetailState('ready')
|
|
1649
1670
|
})
|
|
1650
1671
|
.catch(() => {
|
|
1651
1672
|
if (req !== detailReq.current) return
|
|
1652
1673
|
setDetail(m.snippet || '')
|
|
1674
|
+
setDetailFull(false) // 拉全文失败 → 只有截断的 snippet,不许冒充原文
|
|
1653
1675
|
setDetailState('ready')
|
|
1654
1676
|
})
|
|
1655
1677
|
},
|
|
@@ -1848,6 +1870,10 @@ window.__ModuleLoader__.load({
|
|
|
1848
1870
|
const pickedIsUser = !!pickedLive && pickedLive.role === 'user'
|
|
1849
1871
|
const canFork = !busy && !target.running && pickedIsUser && !pickedLive.shadowed && pickedLive.seq > 0
|
|
1850
1872
|
const canEdit = pickedIsUser && !pickedLive.shadowed && state === 'ready' && !busy
|
|
1873
|
+
// MED-5:只有**真拉到全文**才允许编辑。detail 在 /text 失败时会退化成
|
|
1874
|
+
// snippet,而 snippet 被服务端硬截断到 160 字(session-file.js:331)——
|
|
1875
|
+
// 拿它冒充原文会让用户改完发出时静默丢掉后半段。
|
|
1876
|
+
const editTextReady = detailFull === true && typeof detail === 'string' && detail !== ''
|
|
1851
1877
|
const deleteBlockedReason = target.running
|
|
1852
1878
|
? t('panel.running')
|
|
1853
1879
|
: state !== 'ready'
|
|
@@ -2166,9 +2192,13 @@ window.__ModuleLoader__.load({
|
|
|
2166
2192
|
{
|
|
2167
2193
|
type: 'button',
|
|
2168
2194
|
className: 'mopsAction',
|
|
2169
|
-
disabled: !canEdit,
|
|
2170
|
-
title: pickedIsUser
|
|
2171
|
-
|
|
2195
|
+
disabled: !canEdit || !editTextReady,
|
|
2196
|
+
title: !pickedIsUser
|
|
2197
|
+
? t('panel.branchUserOnly')
|
|
2198
|
+
: !editTextReady
|
|
2199
|
+
? t('panel.editNotReady')
|
|
2200
|
+
: t('panel.editHint'),
|
|
2201
|
+
onClick: () => startEdit(detail),
|
|
2172
2202
|
},
|
|
2173
2203
|
t('panel.edit'),
|
|
2174
2204
|
),
|
|
@@ -2463,24 +2493,41 @@ window.__ModuleLoader__.load({
|
|
|
2463
2493
|
* 为什么不能靠 aria-label:官方文案有 8 种语言(zh/en/ja/es/fr/de/ru/pt),
|
|
2464
2494
|
* 逐个匹配等于把 i18n 表抄进来。也不能靠 class:CSS Modules 会哈希前缀
|
|
2465
2495
|
* (实测 0.2.0-rc.2 是 `xzv4MW_`,0.2.1 起变过)。
|
|
2466
|
-
*
|
|
2467
|
-
*
|
|
2468
|
-
*
|
|
2496
|
+
*
|
|
2497
|
+
* ⚠️ 也不能靠 `<path d="…">`(0.12.0 的错误做法,0.13.1 修):0.2.2-alpha.2 的
|
|
2498
|
+
* 图标已改为 **sprite 复用**,官方组件长这样(见已安装 app bundle 的工厂函数):
|
|
2499
|
+
*
|
|
2500
|
+
* <svg data-icon="dsw-icon-branch-outline-regular" aria-hidden="true">
|
|
2501
|
+
* <use href="#dsw-icon-branch-outline-regular"/>
|
|
2502
|
+
* </svg>
|
|
2503
|
+
*
|
|
2504
|
+
* DOM 里**根本没有 `<path>`**,`M13.0762…` 在整个已安装 dsh 里 0 次命中。
|
|
2505
|
+
* 唯一稳定的是 `data-icon` 的 id:`dsw-icon-${name}-${size}`(工厂 `Qv`),
|
|
2506
|
+
* name 来自 ui-primitives 的图标表,属契约级常量。
|
|
2507
|
+
*
|
|
2508
|
+
* 我们自己的分叉按钮也故意用同一图标,所以必须按 class 显式排除。
|
|
2469
2509
|
*
|
|
2470
2510
|
* @param btn - 候选按钮(任意元素;非 button 的宿主节点返回 false)
|
|
2471
2511
|
* @returns 是否官方 branch 按钮
|
|
2472
2512
|
*/
|
|
2473
|
-
const
|
|
2513
|
+
const HOST_BRANCH_ICON_ID = 'dsw-icon-branch-outline-regular'
|
|
2474
2514
|
const HOST_BRANCH_CLASS = 'mopsUserFork'
|
|
2475
2515
|
function isHostBranchButton(btn) {
|
|
2476
2516
|
if (!btn || typeof btn.querySelector !== 'function') return false
|
|
2477
2517
|
const cls = String((btn.classList && btn.classList.value) || btn.className || '')
|
|
2478
2518
|
if (cls.split(/\s+/).includes(HOST_BRANCH_CLASS)) return false
|
|
2519
|
+
// 首选 sprite 形态:<svg data-icon="dsw-icon-branch-outline-regular">
|
|
2520
|
+
const svg = btn.querySelector('svg')
|
|
2521
|
+
if (svg && svg.getAttribute('data-icon') === HOST_BRANCH_ICON_ID) return true
|
|
2522
|
+
// 兼容旧宿主的内联 path 形态(0.2.0-rc.x):仍接受官方几何前缀
|
|
2479
2523
|
const path = btn.querySelector('svg path')
|
|
2480
2524
|
const d = path ? path.getAttribute('d') || '' : ''
|
|
2481
2525
|
return d.startsWith(HOST_BRANCH_D_PREFIX)
|
|
2482
2526
|
}
|
|
2483
2527
|
|
|
2528
|
+
/** 旧宿主的内联 path 几何前缀(仅作兼容回退,不是主判据)。 */
|
|
2529
|
+
const HOST_BRANCH_D_PREFIX = 'M13.0762 1.37207'
|
|
2530
|
+
|
|
2484
2531
|
/**
|
|
2485
2532
|
* 把文本预置成某个会话的草稿(新会话刚 fork 出来时输入框是空的)。
|
|
2486
2533
|
*
|
|
@@ -2493,7 +2540,24 @@ window.__ModuleLoader__.load({
|
|
|
2493
2540
|
function writeSessionDraft(childSessionId, text) {
|
|
2494
2541
|
try {
|
|
2495
2542
|
if (!childSessionId || typeof localStorage === 'undefined') return false
|
|
2496
|
-
|
|
2543
|
+
const key = FORK_SESSION_STORAGE_PREFIX + childSessionId
|
|
2544
|
+
// ⚠️ 必须**合并**,不能整体覆盖:同一个键里宿主还存着 `view` /
|
|
2545
|
+
// `viewRequest` 等会话视图偏好(见 dsh-client-ui-conversation 的
|
|
2546
|
+
// readConversationView / persist)。0.12.0 只写 `{draft}` 时,
|
|
2547
|
+
// fork 出的子会话恰好还没有偏好所以没暴露;0.14.0 的回填写在**正在用
|
|
2548
|
+
// 的会话**上,直接覆盖会静默清掉用户的视图选择。
|
|
2549
|
+
let base = {}
|
|
2550
|
+
try {
|
|
2551
|
+
const raw = localStorage.getItem(key)
|
|
2552
|
+
if (raw != null) {
|
|
2553
|
+
const parsed = JSON.parse(raw)
|
|
2554
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) base = parsed
|
|
2555
|
+
}
|
|
2556
|
+
} catch {
|
|
2557
|
+
/* 旧值不可解析 → 当作空对象重写(总比抛错好) */
|
|
2558
|
+
}
|
|
2559
|
+
const next = { ...base, draft: String(text || '') }
|
|
2560
|
+
localStorage.setItem(key, JSON.stringify(next))
|
|
2497
2561
|
return true
|
|
2498
2562
|
} catch (e) {
|
|
2499
2563
|
console.warn('[message-ops] writeSessionDraft failed:', e)
|
|
@@ -2501,6 +2565,26 @@ window.__ModuleLoader__.load({
|
|
|
2501
2565
|
}
|
|
2502
2566
|
}
|
|
2503
2567
|
|
|
2568
|
+
/**
|
|
2569
|
+
* 读回某会话的已保存草稿文本(宿主同一存储键)。
|
|
2570
|
+
* @param sessionId - 会话 id
|
|
2571
|
+
* @returns 文本;存储里没有该会话、或格式不可解析时返回 null
|
|
2572
|
+
*/
|
|
2573
|
+
function readSessionDraft(sessionId) {
|
|
2574
|
+
try {
|
|
2575
|
+
if (!sessionId || typeof localStorage === 'undefined') return null
|
|
2576
|
+
const raw = localStorage.getItem(FORK_SESSION_STORAGE_PREFIX + sessionId)
|
|
2577
|
+
if (raw == null) return null
|
|
2578
|
+
const parsed = JSON.parse(raw)
|
|
2579
|
+
const draft = parsed && typeof parsed === 'object' ? parsed.draft : undefined
|
|
2580
|
+
if (typeof draft === 'string') return draft
|
|
2581
|
+
if (draft && typeof draft === 'object' && typeof draft.text === 'string') return draft.text
|
|
2582
|
+
return null
|
|
2583
|
+
} catch {
|
|
2584
|
+
return null
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2504
2588
|
/** 打开会话(宿主唯一通道)。childId 需要 `session-` 前缀才不会抛 unknown session。 */
|
|
2505
2589
|
function openSessionById(sessionId) {
|
|
2506
2590
|
try {
|
|
@@ -2844,8 +2928,20 @@ window.__ModuleLoader__.load({
|
|
|
2844
2928
|
// SessionRevert.commit() → revert:null → affordance 消失)。
|
|
2845
2929
|
// 我们是 append-only,marker 不会真消失,所以由服务端按
|
|
2846
2930
|
// 「marker 之后有无 source.kind==='user' 的真实输入」算出 committed。
|
|
2847
|
-
return (
|
|
2848
|
-
|
|
2931
|
+
return (
|
|
2932
|
+
(msgs || [])
|
|
2933
|
+
.filter(m => m.marker && m.sourceKind !== 'compact-checkpoint' && m.restoreComplete !== true && m.committed !== true)
|
|
2934
|
+
// 0.14.0:排掉「自噬 marker」—— 它的 replace 区间恰好覆盖**另一条 marker**
|
|
2935
|
+
// (典型是 `startSeq === endSeq === 前一条 marker 的 seq`,content 为空)。
|
|
2936
|
+
// 这种记录不是用户做过的回滚,是旧版 dock 拿 marker 当目标留下的残迹;
|
|
2937
|
+
// 列出来只会让用户点「恢复」再生成一条同样的垃圾。
|
|
2938
|
+
.filter(m => {
|
|
2939
|
+
const rng = m.range
|
|
2940
|
+
if (!rng || !Number.isSafeInteger(rng.startSeq)) return true
|
|
2941
|
+
if (rng.startSeq !== rng.endSeq) return true
|
|
2942
|
+
const target = (msgs || []).find(x => x && x.seq === rng.startSeq)
|
|
2943
|
+
return !(target && target.marker === true)
|
|
2944
|
+
})
|
|
2849
2945
|
)
|
|
2850
2946
|
}
|
|
2851
2947
|
|
|
@@ -3126,12 +3222,28 @@ window.__ModuleLoader__.load({
|
|
|
3126
3222
|
)
|
|
3127
3223
|
const dockRows = []
|
|
3128
3224
|
for (const mk of markers || []) {
|
|
3225
|
+
// 0.14.0(dock 文案修复):`mk.snippet` 是 **marker 自己**的正文 ——
|
|
3226
|
+
// 也就是「[消息回滚] 已回滚到 seq N…」这句拼接文案本身。
|
|
3227
|
+
// 用户看到「#3417 · [消息回滚] 已回滚到 seq 3410…」,点「恢复」后
|
|
3228
|
+
// 日志里又落一条遮蔽 marker 自己的空 replace(实测 5 次)。
|
|
3229
|
+
// 正确口径:这一行代表的是「被 marker 遮蔽的那段对话」,文案必须取自
|
|
3230
|
+
// range 区间里的真实内容;区间取不到才显示序号。
|
|
3231
|
+
const rng = mk.range && Number.isSafeInteger(mk.range.startSeq) ? mk.range : null
|
|
3232
|
+
// 预览文案必须描述「被遮蔽的那段」,不能是 marker 自己的 notice 文本。
|
|
3233
|
+
// 区间退化成单点且恰好是另一条 marker 时,这条 marker 是**冗余生成**的,
|
|
3234
|
+
// 直接标出来,别让用户以为它是一轮真实对话。
|
|
3235
|
+
const span = rng ? (rng.endSeq > rng.startSeq ? 'seq ' + rng.startSeq + '..' + rng.endSeq : '#' + rng.startSeq) : ''
|
|
3236
|
+
const rangeSnippet = mk.previewFirst || span
|
|
3129
3237
|
if (Array.isArray(mk.pendingTurns) && mk.pendingTurns.length > 0) {
|
|
3130
3238
|
for (const t of mk.pendingTurns) {
|
|
3131
|
-
dockRows.push({
|
|
3239
|
+
dockRows.push({
|
|
3240
|
+
seq: mk.seq,
|
|
3241
|
+
upTo: t.upTo,
|
|
3242
|
+
snippet: t.preview + (t.count > 1 ? ' (+' + (t.count - 1) + ')' : ''),
|
|
3243
|
+
})
|
|
3132
3244
|
}
|
|
3133
|
-
} else {
|
|
3134
|
-
dockRows.push({ seq: mk.seq, snippet:
|
|
3245
|
+
} else if (rng) {
|
|
3246
|
+
dockRows.push({ seq: mk.seq, snippet: rangeSnippet, markerRange: rng })
|
|
3135
3247
|
}
|
|
3136
3248
|
}
|
|
3137
3249
|
|
|
@@ -3588,7 +3700,7 @@ window.__ModuleLoader__.load({
|
|
|
3588
3700
|
const row = rows && rows.find(r => r.seq === seq)
|
|
3589
3701
|
if (!row) {
|
|
3590
3702
|
ensureAssign(sid)
|
|
3591
|
-
notifyDone(__t('errorPrefix') +
|
|
3703
|
+
notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
|
|
3592
3704
|
return
|
|
3593
3705
|
}
|
|
3594
3706
|
btn.disabled = true
|
|
@@ -3654,7 +3766,7 @@ window.__ModuleLoader__.load({
|
|
|
3654
3766
|
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
3655
3767
|
const row = rows && rows.find(r => r.seq === seq)
|
|
3656
3768
|
if (!row) {
|
|
3657
|
-
notifyDone(__t('errorPrefix') +
|
|
3769
|
+
notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
|
|
3658
3770
|
return
|
|
3659
3771
|
}
|
|
3660
3772
|
if (!(seq > 0)) {
|
|
@@ -4159,17 +4271,32 @@ window.__ModuleLoader__.load({
|
|
|
4159
4271
|
if (bareSessionId(cache.sid) !== want) return false
|
|
4160
4272
|
const rows = cache.rows.filter(r => r && typeof r.seq === 'number' && r.seq <= boundarySeq && r.fullText)
|
|
4161
4273
|
if (!rows.length) return false
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
//
|
|
4165
|
-
|
|
4274
|
+
const text = rows[rows.length - 1].fullText
|
|
4275
|
+
// ── 0.14.0(回填失效修复)────────────────────────────────────────────
|
|
4276
|
+
// 旧实现:`__inputActions.setDraft(text)` + `persistDraft()`,然后调用方
|
|
4277
|
+
// **紧接着** `openSession(sid)` 重建整个会话视图。重建会卸载并重挂
|
|
4278
|
+
// 编辑器,新挂载走 `readConversationDraft(sid)` 从 localStorage 初始化 ——
|
|
4279
|
+
// 也就是说「回填」实际取决于 persistDraft 是否成功落盘,而再叠上
|
|
4280
|
+
// `bindDraftPersistence` 的时序(见 startEdit 处 MED-4 注释),失败时
|
|
4281
|
+
// 用户看到「已回滚」却拿不到原文。
|
|
4282
|
+
//
|
|
4283
|
+
// 唯一无竞态的路径:**直接写宿主的草稿存储键**(writeSessionDraft),
|
|
4284
|
+
// 与 fork 回填同一机制。它是 openSession 之后读到的权威值,不依赖
|
|
4285
|
+
// 编辑器是否已挂载、也不依赖 inputActions 此刻绑在哪个会话上。
|
|
4286
|
+
const persisted = writeSessionDraft(rawSid, text)
|
|
4287
|
+
// 再尽力更新活着的编辑器(视图没重建的路径,例如 dock 内联恢复)。
|
|
4288
|
+
let editorSet = false
|
|
4289
|
+
if (__inputActions && typeof __inputActions.setDraft === 'function') {
|
|
4166
4290
|
try {
|
|
4167
|
-
__inputActions.
|
|
4291
|
+
__inputActions.setDraft(text)
|
|
4292
|
+
editorSet = true
|
|
4168
4293
|
} catch (e) {
|
|
4169
|
-
console.warn('[message-ops]
|
|
4294
|
+
console.warn('[message-ops] setDraft failed:', e)
|
|
4170
4295
|
}
|
|
4171
4296
|
}
|
|
4172
|
-
|
|
4297
|
+
// 诚实返回:落盘成功(openSession 后必能读到)或活着编辑器已更新,任一即为真。
|
|
4298
|
+
// 不再用 `|| true` —— 那会让调用方永远看不到失败。
|
|
4299
|
+
return persisted || editorSet
|
|
4173
4300
|
} catch (e) {
|
|
4174
4301
|
// 原来这里 `catch {}` 完全静默 —— 失败了连痕迹都没有,排查时看不到
|
|
4175
4302
|
console.warn('[message-ops] setDraft failed:', e)
|
|
@@ -4408,7 +4535,7 @@ window.__ModuleLoader__.load({
|
|
|
4408
4535
|
return {
|
|
4409
4536
|
apply,
|
|
4410
4537
|
inject: ['slots'],
|
|
4411
|
-
__test: { activityTransition, forkBoundaryBefore, isHostBranchButton, writeSessionDraft, HOST_BRANCH_D_PREFIX },
|
|
4538
|
+
__test: { activityTransition, forkBoundaryBefore, isHostBranchButton, writeSessionDraft, HOST_BRANCH_ICON_ID, HOST_BRANCH_D_PREFIX },
|
|
4412
4539
|
}
|
|
4413
4540
|
},
|
|
4414
4541
|
})
|
package/src/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
messageTextFull,
|
|
20
20
|
turnBounds,
|
|
21
21
|
markCommitted,
|
|
22
|
+
readReplaceOp,
|
|
22
23
|
} from './session-file.js'
|
|
23
24
|
import {
|
|
24
25
|
restoreNoticeText,
|
|
@@ -516,6 +517,20 @@ async function buildDerived(logPath) {
|
|
|
516
517
|
continue
|
|
517
518
|
}
|
|
518
519
|
m.restoreComplete = prog.complete
|
|
520
|
+
// 0.14.0(dock 目标修复):把 marker 遮蔽的**区间**暴露出去。
|
|
521
|
+
//
|
|
522
|
+
// 旧实现让 dock 拿 `mk.seq`(marker **自己**的 seq)去调 /restore。而
|
|
523
|
+
// opsRestore 的第一件事是 `planRestore(events, restoreSeq, ...)` —— 它要求
|
|
524
|
+
// `restoreSeq` 本身是**带 replace 区间的那条 marker**,于是语义正确;
|
|
525
|
+
// 但 dock 同时把 `mk.seq` 当"要恢复到哪"展示给用户、还在 pendingTurns 里
|
|
526
|
+
// 用 `mk.seq` 拼 rowKey —— 一旦这一行代表的是"已提交过的旧 marker"或
|
|
527
|
+
// 空内容的合成 marker,用户点下去就会把**另一条 marker 自己**遮蔽掉,
|
|
528
|
+
// 产生一条新的、content 为空的 replace 记录(实测 seq 3424/3658/3689/
|
|
529
|
+
// 3721/3746 全是这么来的)。
|
|
530
|
+
//
|
|
531
|
+
// 正向修法:range 是 marker 的语义本体("我遮蔽了谁"),dock 只该用它。
|
|
532
|
+
const range = readReplaceOp(events.find(x => x && x.seq === m.seq) || null)
|
|
533
|
+
if (range) m.range = range
|
|
519
534
|
m.pendingTurns = pendingRestoreTurnsFromIndex(restoreIndex, m.seq, prog).map(t => ({
|
|
520
535
|
upTo: t.seqs[t.seqs.length - 1],
|
|
521
536
|
count: t.seqs.length,
|
|
@@ -673,6 +688,22 @@ async function opsList(targetCtx, sessionId, opts = {}) {
|
|
|
673
688
|
// 客户端据此算 fork 边界 = turnStartSeq - 1。只带这一个字段:turn/step
|
|
674
689
|
// 属于「重」字段,面板的虚拟行用不到(详见 compact 的取舍)。
|
|
675
690
|
turnStartSeq: m.turnStartSeq ?? null,
|
|
691
|
+
// 0.14.0(dock 目标修复):客户端必须能识别「这行是 marker」并拿到它
|
|
692
|
+
// 遮蔽的区间。旧 compact 只给 role/snippet,于是 dock 只能拿 marker
|
|
693
|
+
// **自己的** seq 当恢复目标、也只能拿 marker 自己的文案当预览 ——
|
|
694
|
+
// 用户看到「#3417 · [消息回滚] 已回滚到 seq 3410…」,点恢复又把 marker
|
|
695
|
+
// 自己遮蔽一次(实测 5 条空 replace)。
|
|
696
|
+
// 0.15.0:必须带 id —— 客户端用 `<kindLen>:<kind><id>` 拼 data-chat-node-key
|
|
697
|
+
// 反查 seq(seqOfNodeKey)。developer/message(工具清单变更)的遮蔽同步
|
|
698
|
+
// 全靠这条链:没有 id → byMessageId 查不到 → 调用方「保持可见」→
|
|
699
|
+
// 宿主那行「+49 tools」在回滚后照样显示。
|
|
700
|
+
id: m.id ?? null,
|
|
701
|
+
marker: m.marker === true,
|
|
702
|
+
range: m.range ?? null,
|
|
703
|
+
// 0.14.0:dock 的 activeMarkers 判据就是这两个字段 —— 不投影出去,
|
|
704
|
+
// 客户端拿到 undefined 会把**已恢复完毕**的 marker 继续列在待恢复列表里。
|
|
705
|
+
restoreComplete: m.restoreComplete === true,
|
|
706
|
+
committed: m.committed === true,
|
|
676
707
|
}))
|
|
677
708
|
: messages
|
|
678
709
|
|
package/src/ops-core.js
CHANGED
|
@@ -30,6 +30,18 @@ export { messageText }
|
|
|
30
30
|
/** 带语义状态码的操作错误(单点已迁至 session-file.js,此处仅转出)。 */
|
|
31
31
|
|
|
32
32
|
/** planRevert:回撤语义 = 遮蔽 targetSeq 及其之后全部可见节点(连续到末尾)。 */
|
|
33
|
+
/**
|
|
34
|
+
* 该 seq 是否是一条**回撤/删除 marker**(surfaceOp=replace 的 system/message)?
|
|
35
|
+
*
|
|
36
|
+
* 0.14.0 护栏:marker 是账本,不是对话。允许拿 marker 当回滚目标会产生一种
|
|
37
|
+
* 自噬记录 —— 新 marker 遮蔽旧 marker,`content` 为空、`startSeq===endSeq`,
|
|
38
|
+
* 界面上表现为「恢复之后又多出一条『回滚后的节点』」。实测语料里已经出现过
|
|
39
|
+
* 5 次(seq 3424/3658/3689/3721/3746),全部由 dock 用 `mk.seq` 当目标造成。
|
|
40
|
+
*/
|
|
41
|
+
export function isMarkerEvent(e) {
|
|
42
|
+
return !!e && e.type === 'system/message' && readReplaceOp(e) !== null
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
export function planRevert(surface, targetSeq) {
|
|
34
46
|
const nodes = surface && Array.isArray(surface.nodes) ? surface.nodes : []
|
|
35
47
|
const startIdx = nodes.indexOf(targetSeq)
|
|
@@ -985,6 +997,11 @@ export function diskVisibleNodes(events) {
|
|
|
985
997
|
|
|
986
998
|
/** 磁盘版 planRevert:target 必须可见,遮蔽 target 之后(含)全部可见节点。 */
|
|
987
999
|
export function planRevertFromEvents(events, targetSeq) {
|
|
1000
|
+
// 0.14.0 护栏:marker 不是对话,不能被回滚(否则产生自噬的空 replace 记录)。
|
|
1001
|
+
const targetEvent = (events ?? []).find(e => e && e.seq === targetSeq)
|
|
1002
|
+
if (isMarkerEvent(targetEvent)) {
|
|
1003
|
+
throw new OpsError(`seq ${targetSeq} is a revert/delete marker, not a message — restore it instead of reverting it`, 409)
|
|
1004
|
+
}
|
|
988
1005
|
// 目标用「消息」集合(回滚对象是消息),溯源用「全部 surface」集合(0.8.2 修正)
|
|
989
1006
|
const nodes = diskVisibleNodes(events)
|
|
990
1007
|
const startIdx = nodes.indexOf(targetSeq)
|
package/src/session-file.js
CHANGED
|
@@ -34,6 +34,11 @@ function textSegments(e) {
|
|
|
34
34
|
const out = []
|
|
35
35
|
for (const c of content) {
|
|
36
36
|
if (c && c.type === 'text' && typeof c.text === 'string' && c.text.trim()) out.push(c.text)
|
|
37
|
+
// 0.15.0:developer/message 的 tool-registry 变更块不是 text,但它是
|
|
38
|
+
// **surface 节点**(会进模型上下文),必须给它一个可读摘要 —— 否则
|
|
39
|
+
// listMessages 拿到空串、snippet 为空,客户端 rows/索引会把它当无效行丢掉。
|
|
40
|
+
else if (c && c.type === 'tool-addition' && typeof c.toolName === 'string') out.push('+' + c.toolName)
|
|
41
|
+
else if (c && c.type === 'tool-removal' && typeof c.toolName === 'string') out.push('-' + c.toolName)
|
|
37
42
|
}
|
|
38
43
|
return out
|
|
39
44
|
}
|
|
@@ -315,7 +320,21 @@ export function listMessages(events) {
|
|
|
315
320
|
const messages = []
|
|
316
321
|
for (const e of events) {
|
|
317
322
|
if (!e || typeof e.seq !== 'number') continue
|
|
318
|
-
|
|
323
|
+
// 0.15.0:把 developer/message 也收进来。
|
|
324
|
+
//
|
|
325
|
+
// 为什么必须收:宿主的 `developerMessageDefinition.match` 只看
|
|
326
|
+
// `event.type === 'developer/message'`,**不检查 surface 遮蔽状态**
|
|
327
|
+
// (对比 user/message 的 match 有 `isAppendSurfaceEvent(event)` 这道闸)。
|
|
328
|
+
// 而 `isVisibleChatNode` 又对带 tool-addition/tool-removal 的 context 节点
|
|
329
|
+
// **强制可见**。结果:回滚时工具清单变更被 surface replace 正确遮蔽了
|
|
330
|
+
// (模型上下文干净),但界面上那行「+49 tools」照样渲染 —— 用户看到的就是
|
|
331
|
+
// 「回滚没撤回干净」。
|
|
332
|
+
//
|
|
333
|
+
// 我们没法改宿主渲染器,但插件本来就在做渲染层的遮蔽同步
|
|
334
|
+
// (installUserRevertInjector 按 data-chat-node-key 精确查表藏行)。
|
|
335
|
+
// 前提是这些事件必须先出现在我们的消息列表里、并带上 id,否则
|
|
336
|
+
// byMessageId 查不到 → seqOfNodeKey 返回 null → 调用方「保持可见」。
|
|
337
|
+
if (e.type === 'user/message' || e.type === 'assistant/message' || e.type === 'system/message' || e.type === 'developer/message') {
|
|
319
338
|
const text = messageText(e)
|
|
320
339
|
const msg = e.data && e.data.message
|
|
321
340
|
// id:宿主持久化的消息身份(user 在 data.id、assistant 在 data.message.id),
|
|
@@ -325,8 +344,16 @@ export function listMessages(events) {
|
|
|
325
344
|
messages.push({
|
|
326
345
|
seq: e.seq,
|
|
327
346
|
type: e.type,
|
|
328
|
-
role:
|
|
329
|
-
|
|
347
|
+
role:
|
|
348
|
+
(msg && msg.role) ||
|
|
349
|
+
(e.type === 'user/message'
|
|
350
|
+
? 'user'
|
|
351
|
+
: e.type === 'assistant/message'
|
|
352
|
+
? 'assistant'
|
|
353
|
+
: e.type === 'developer/message'
|
|
354
|
+
? 'developer'
|
|
355
|
+
: 'system'),
|
|
356
|
+
id: (msg && msg.id) || (e.data && e.data.id) || null,
|
|
330
357
|
marker: isReplaceMarker,
|
|
331
358
|
snippet: text.replace(/\s+/g, ' ').trim().slice(0, 160),
|
|
332
359
|
// 0.4.0 composer 回填:user 消息携带全文(revert 后 setDraft 原文)
|