@240xu/dsh-message-ops 0.11.7 → 0.12.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 +59 -4
- package/package.json +2 -2
- package/src/client.js +367 -32
- package/src/index.js +36 -0
package/README.md
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
DSH web 插件:**消息回滚 + 删除 + 恢复**。只补 dsh 官方**没有**的能力。
|
|
4
4
|
|
|
5
|
-
> **0.9.0
|
|
5
|
+
> **0.9.0 是破坏性变更**:移除了本插件的**磁盘分支实现**与 **Markdown 导出**。
|
|
6
6
|
> 两者 dsh 官方都已有(`session/fork` 与 `/api/session.export`),详见下方「为什么不重复造轮子」。
|
|
7
|
+
>
|
|
8
|
+
> **0.12.0**:消息动作收敛到用户消息(AI 消息的分支入口移除),用户消息动作行新增
|
|
9
|
+
> opencode 式 `Fork from here`,面板内新增「编辑并重发」。详见「用法」。
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
## 10 秒速查
|
|
@@ -13,7 +16,7 @@ dsh plugin --profile web add @240xu/dsh-message-ops
|
|
|
13
16
|
# 重启 dsh web 后,会话头部点 Message ops
|
|
14
17
|
```
|
|
15
18
|
|
|
16
|
-
-
|
|
19
|
+
- 能做什么:回滚到任意消息、只删一条、恢复、从用户消息分叉(opencode before 语义)、编辑并重发;分支调用官方 session/fork
|
|
17
20
|
- 不能做什么:Markdown 导出(请用官方 `/api/session.export`)
|
|
18
21
|
- 卸载:`dsh plugin --profile web remove @240xu/dsh-message-ops`
|
|
19
22
|
|
|
@@ -40,13 +43,65 @@ dsh plugin --profile web add @240xu/dsh-message-ops
|
|
|
40
43
|
- **会话头部**的 `Message ops` 按钮 → 右侧 `OpsPanel` 抽屉(消息 / 回收站双 tab);
|
|
41
44
|
旧 `OpsDialog` 仅 `window.__MOPS_LEGACY_DIALOG === true` 时回退
|
|
42
45
|
- **助手消息** hover 行的 `Revert to here` / `Quote to composer`
|
|
43
|
-
- **用户消息** hover 行的 `Revert to here`
|
|
46
|
+
- **用户消息** hover 行的 `Revert to here` / `Fork from here`(同一动作行,见下)
|
|
44
47
|
- **输入框上方的回撤贴条**:展开后可逐条 `Restore`(消息级恢复入口)
|
|
45
48
|
- **侧栏会话行**的 `...` 菜单
|
|
46
49
|
|
|
47
|
-
面板流程:**选一条消息 → 回滚 / 仅删除 /
|
|
50
|
+
面板流程:**选一条消息 → 回滚 / 仅删除 / 编辑并重发 / 分叉 → 破坏性操作二次确认**;
|
|
48
51
|
整会话删除在回收站 tab,需输入会话标题确认。
|
|
49
52
|
|
|
53
|
+
### 0.12.0 · 动作收敛到用户消息(opencode 对齐)
|
|
54
|
+
|
|
55
|
+
四个决定,都来自「消息动作到底该挂在哪」这一个问题:
|
|
56
|
+
|
|
57
|
+
1. **分叉只属于用户消息。** fork 的目的不是「复制对话」,而是「这句话说错了,拿回
|
|
58
|
+
输入框重说」;AI 消息没有可回填的原文,从那里分叉只会得到一个半截上下文。
|
|
59
|
+
因此:
|
|
60
|
+
- **助手消息**只剩 `Revert to here` / `Quote to composer`;
|
|
61
|
+
- **官方 assistant turn-tail 上的 branch 按钮被隐藏**(官方无开关,`ui-chat` 的
|
|
62
|
+
Config 只有折叠/性能/链接几项)。识别靠**图标几何**而非 aria-label 或哈希
|
|
63
|
+
class:官方 `IconBranchOutline16` 的 `d` 是常量
|
|
64
|
+
(`packages/client/ui-primitives/src/icons/index.tsx:149`),8 种语言的按钮
|
|
65
|
+
文案各不相同,class 前缀每次发版都可能变。作用域限定在 `[data-turn-tail]`
|
|
66
|
+
内,并排除我们自己注入的 `.mopsUserFork`(它故意复用同一 path)。
|
|
67
|
+
- **用户消息**的动作行里同时有回滚与分叉,**回滚在前**(破坏性更高的排前面),
|
|
68
|
+
两者都挂在官方 `.xzv4MW_actions` 里,可见性跟着宿主 hover 走,不做悬浮层。
|
|
69
|
+
2. **分叉是 before 语义,且按「轮」切 —— 不是 `seq - 1`。** opencode 的
|
|
70
|
+
`POST /fork` 用 `before` 做**排他**边界(`projector.ts`:
|
|
71
|
+
`type === "before" ? lt(seq, ...) : lte(...)`,issue #35786 也写明 exclusive);
|
|
72
|
+
dsh 官方 `sessions.fork(source, boundary)` 的 boundary 是**闭区间**。
|
|
73
|
+
直觉做法是 `seq - 1`,但实测 40 份语料后否掉了:**真人输入的前一个事件恒是
|
|
74
|
+
同一 turn 内的 `system/message`**(真实形状
|
|
75
|
+
`turn/start → agent/inbox/spliced → step/start → system/message → user/message`),
|
|
76
|
+
按 `seq - 1` 切会得到一个「turn/step 已开、却没有任何 user 消息」的悬空前缀,
|
|
77
|
+
引擎只能补合成 closers,语义也不是「这条之前」。
|
|
78
|
+
正确边界 = 该消息所在 turn 的 `turn/start` 的**前一个**事件:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
forkBoundaryBefore(seq, turnStartSeq) {
|
|
82
|
+
if (Number.isSafeInteger(turnStartSeq) && turnStartSeq > 0) return turnStartSeq - 1
|
|
83
|
+
return Number.isSafeInteger(seq) && seq > 0 ? seq - 1 : -1 // 老服务端回退
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`turnStartSeq` 由服务端在 `GET /messages?view=compact` 里给出(`src/index.js`
|
|
88
|
+
`buildDerived`)。注意**真人 `user/message` 事件本身不带 `turn` 字段**——
|
|
89
|
+
归属靠扫一遍事件、用「当前开着的 turn」判定;`system/message` /
|
|
90
|
+
`assistant/message` 才自带 turn/step。没有 turn 信息时退回 `seq - 1`
|
|
91
|
+
(边界可能落在 turn 内部,官方会补 closers,结果仍可加载)。
|
|
92
|
+
返回 `-1` 表示不可分叉(首条消息没有「之前」)。
|
|
93
|
+
3. **原文回到新会话的输入框。** fork 成功后把该条用户消息原文写进
|
|
94
|
+
`localStorage["dsh.conversation." + childId] = { draft: text }`,再
|
|
95
|
+
`uiWorkspace.openSession(childId)`。直接写存储而不是 `inputActions.setDraft`,
|
|
96
|
+
是因为 fork 出来的会话**还没挂载**,此刻 `inputActions` 仍绑在源会话上;宿主挂载
|
|
97
|
+
新会话时会用 `readConversationDraft(sessionId)` 从同一键初始化编辑器
|
|
98
|
+
(`dsh-client-ui-conversation:4539-4554`,`parseStoredDraft` 接受字符串形态的 draft)。
|
|
99
|
+
4. **面板里直接「编辑并重发」。** 不自己复刻输入框(那会分叉草稿/附件/引用/斜杠
|
|
100
|
+
命令/提交状态机一整套行为),而是把原文交回官方编辑器:`setDraft(text)` →
|
|
101
|
+
`persistDraft()`(不落盘会被紧随的 `openSession` 用旧草稿覆盖,0.11.3 已踩过)→
|
|
102
|
+
关面板。改完直接回车发出,等价于 opencode 的「回撤 → 原文回 composer」,区别是
|
|
103
|
+
我们不预先回撤,发不发由用户决定。
|
|
104
|
+
|
|
50
105
|
## 安装
|
|
51
106
|
|
|
52
107
|
零 npm 依赖(只用 `node:fs` / `node:zlib` / `node:path` / `node:url`;zstd 压缩走
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@240xu/dsh-message-ops",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DSH web 插件:消息级回滚 / 删除 /
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "DSH web 插件:消息级回滚 / 删除 / 恢复 / 分叉 / 编辑重发(补 dsh 官方没有的部分)。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "240xu",
|
package/src/client.js
CHANGED
|
@@ -113,6 +113,10 @@ window.__ModuleLoader__.load({
|
|
|
113
113
|
'op.branchDesc': '复制所选消息(含)之前的全部事件为新会话(原会话不变,非破坏操作)。',
|
|
114
114
|
'slot.revert': '回滚到此条',
|
|
115
115
|
'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
|
|
116
|
+
'slot.fork': '从此条分叉',
|
|
117
|
+
'slot.forkHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
118
|
+
'slot.forkDone': '已分叉:新会话 {id}',
|
|
119
|
+
'slot.forkUnavailable': '分叉不可用:会话正在运行,或宿主未提供 session/fork',
|
|
116
120
|
'toast.openNew': '打开新会话',
|
|
117
121
|
'fork.official': '分支完成:新会话 {id}',
|
|
118
122
|
'fork.unavailable': '官方分支不可用:通常是因为会话正在运行,请先停止会话后重试。分支功能由 dsh 内置的 session/fork 提供。',
|
|
@@ -179,9 +183,15 @@ window.__ModuleLoader__.load({
|
|
|
179
183
|
'panel.deleteUnavailable': '会话信息尚未就绪,暂不能删除。',
|
|
180
184
|
'panel.delete': '仅删除此条',
|
|
181
185
|
'panel.deleteHint': '只遮蔽这一条,其他消息不动',
|
|
182
|
-
'panel.branch': '
|
|
183
|
-
'panel.branchHint': '
|
|
184
|
-
'panel.branchDone': '
|
|
186
|
+
'panel.branch': '从此条分叉',
|
|
187
|
+
'panel.branchHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
188
|
+
'panel.branchDone': '已分叉:新会话 {id}',
|
|
189
|
+
'panel.branchUserOnly': '分叉只对用户消息可用(AI 消息没有可回填的原文)',
|
|
190
|
+
'panel.edit': '编辑并重发',
|
|
191
|
+
'panel.editHint': '把此条原文放回输入框,改完直接发送',
|
|
192
|
+
'panel.editDone': '原文已放回输入框',
|
|
193
|
+
'panel.editEmpty': '这条消息没有可编辑的文本',
|
|
194
|
+
'panel.editUnavailable': '编辑器不可写(会话可能正在运行或尚未挂载)',
|
|
185
195
|
'panel.openNew': '打开新会话',
|
|
186
196
|
'panel.revertDone': '回滚已生效',
|
|
187
197
|
'panel.deleteDone': '删除已生效',
|
|
@@ -227,6 +237,10 @@ window.__ModuleLoader__.load({
|
|
|
227
237
|
'op.branchDesc': 'Copies everything up to and including the picked message into a new session (original untouched, non-destructive).',
|
|
228
238
|
'slot.revert': 'Revert to here',
|
|
229
239
|
'slot.revertUnmatched': '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.',
|
|
240
|
+
'slot.fork': 'Branch from here',
|
|
241
|
+
'slot.forkHint': 'Copies the conversation above this message into a new session and puts this message back in the new composer',
|
|
242
|
+
'slot.forkDone': 'Branched: new session {id}',
|
|
243
|
+
'slot.forkUnavailable': 'Branch unavailable: the session is running, or the host provides no session/fork',
|
|
230
244
|
'toast.openNew': 'Open new session',
|
|
231
245
|
'fork.official': 'Branched (official fork): new session {id}',
|
|
232
246
|
'fork.unavailable': 'Built-in branch unavailable — usually because the session is running. Stop it and retry. Branching is provided by the dsh built-in session/fork.',
|
|
@@ -293,9 +307,15 @@ window.__ModuleLoader__.load({
|
|
|
293
307
|
'panel.deleteUnavailable': 'Session details are not ready yet; deletion is disabled.',
|
|
294
308
|
'panel.delete': 'Delete only this',
|
|
295
309
|
'panel.deleteHint': 'Shadows only this message',
|
|
296
|
-
'panel.branch': '
|
|
297
|
-
'panel.branchHint': 'Copy
|
|
298
|
-
'panel.branchDone': '
|
|
310
|
+
'panel.branch': 'Fork from here',
|
|
311
|
+
'panel.branchHint': 'Copy the conversation above this message into a new session and put this message back in the new composer',
|
|
312
|
+
'panel.branchDone': 'Forked: {id}',
|
|
313
|
+
'panel.branchUserOnly': 'Fork works on user messages only (assistant messages have no text to hand back)',
|
|
314
|
+
'panel.edit': 'Edit and resend',
|
|
315
|
+
'panel.editHint': 'Put this message back in the composer to change and send',
|
|
316
|
+
'panel.editDone': 'Original text is back in the composer',
|
|
317
|
+
'panel.editEmpty': 'This message has no editable text',
|
|
318
|
+
'panel.editUnavailable': 'Composer is not writable (session may be running or not mounted)',
|
|
299
319
|
'panel.openNew': 'Open new session',
|
|
300
320
|
'panel.revertDone': 'Revert applied',
|
|
301
321
|
'panel.deleteDone': 'Delete applied',
|
|
@@ -536,16 +556,18 @@ window.__ModuleLoader__.load({
|
|
|
536
556
|
setBusyMsg(t('busy.' + (mode === 'revert' || mode === 'delete' ? mode : 'branch')))
|
|
537
557
|
setState('busy'); setError(null)
|
|
538
558
|
if (mode === 'branch') {
|
|
539
|
-
// 0.
|
|
540
|
-
//
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
559
|
+
// 0.12.0:与面板/消息行同一实现 —— opencode 的 before 语义
|
|
560
|
+
// (新会话不含此条,原文回新会话输入框)。只对用户消息成立;
|
|
561
|
+
// 分支不再回落写盘(被删的磁盘 applyBranch 语义复盘见 README)。
|
|
562
|
+
const pickedRow = picked != null ? messages.find((m) => m.seq === picked) : null
|
|
563
|
+
if (!pickedRow || pickedRow.role !== 'user') {
|
|
564
|
+
setError(t('panel.branchUserOnly'))
|
|
544
565
|
setBusyMsg('')
|
|
545
566
|
setState('error')
|
|
546
567
|
return
|
|
547
568
|
}
|
|
548
|
-
|
|
569
|
+
Promise.resolve()
|
|
570
|
+
.then(() => forkFromUserMessage(target.sessionId, picked, pickedRow.fullText || pickedRow.snippet || '', pickedRow.turnStartSeq))
|
|
549
571
|
.then((childId) => {
|
|
550
572
|
setDoneMsg(t('fork.official', { id: String(childId || '') }))
|
|
551
573
|
setBusyMsg('')
|
|
@@ -1068,6 +1090,41 @@ window.__ModuleLoader__.load({
|
|
|
1068
1090
|
}, 0)
|
|
1069
1091
|
}, [busy, confirmAction])
|
|
1070
1092
|
|
|
1093
|
+
/**
|
|
1094
|
+
* 0.12.0 面板内的「编辑并重发」:把该条用户消息的原文放进编辑器并关掉面板。
|
|
1095
|
+
*
|
|
1096
|
+
* 为什么不自己加一个输入框:编辑器已经有草稿、附件、引用、斜杠命令与提交状态机,
|
|
1097
|
+
* 面板里再复刻一套只会分叉行为。正确做法是**交回官方编辑器**:
|
|
1098
|
+
* 1. `setDraft(text)` 改编辑器内容
|
|
1099
|
+
* 2. `persistDraft()` 落 localStorage —— 否则紧随的 openSession 会用旧草稿覆盖
|
|
1100
|
+
* (0.11.3 已踩过这个坑,见 refillComposer 注释)
|
|
1101
|
+
* 3. 关面板并聚焦编辑器,用户改完直接回车发出
|
|
1102
|
+
* 语义上与 opencode 的「回撤 → 原文回到 composer」一致;区别是我们不预先回撤,
|
|
1103
|
+
* 由用户决定发不发(发了才产生新的分支上下文)。
|
|
1104
|
+
*/
|
|
1105
|
+
const startEdit = useCallback((text) => {
|
|
1106
|
+
if (!target || busy) return
|
|
1107
|
+
const body = typeof text === 'string' ? text : ''
|
|
1108
|
+
if (!body) {
|
|
1109
|
+
setError(t('panel.editEmpty'))
|
|
1110
|
+
return
|
|
1111
|
+
}
|
|
1112
|
+
if (!__inputActions || typeof __inputActions.setDraft !== 'function') {
|
|
1113
|
+
setError(t('panel.editUnavailable'))
|
|
1114
|
+
return
|
|
1115
|
+
}
|
|
1116
|
+
try {
|
|
1117
|
+
__inputActions.setDraft(body)
|
|
1118
|
+
if (typeof __inputActions.persistDraft === 'function') __inputActions.persistDraft()
|
|
1119
|
+
} catch (reason) {
|
|
1120
|
+
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
1121
|
+
return
|
|
1122
|
+
}
|
|
1123
|
+
setDone(t('panel.editDone'))
|
|
1124
|
+
notifyDone(t('panel.editDone'))
|
|
1125
|
+
close()
|
|
1126
|
+
}, [target, busy, t, close])
|
|
1127
|
+
|
|
1071
1128
|
useEffect(() => {
|
|
1072
1129
|
if (!open) return undefined
|
|
1073
1130
|
const onKey = (e) => {
|
|
@@ -1097,15 +1154,53 @@ window.__ModuleLoader__.load({
|
|
|
1097
1154
|
else if (panelRef.current) panelRef.current.focus()
|
|
1098
1155
|
}, 0)
|
|
1099
1156
|
const scrim = scrimRef.current
|
|
1100
|
-
const parent = scrim && scrim.parentElement
|
|
1101
1157
|
const hidden = []
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1158
|
+
// 0.11.8:槽位会把 scrim 挂进一个**只有 scrim 自己**的独立容器,
|
|
1159
|
+
// 于是「遍历 parent.children」永远遍历不到真实背景 —— inert 形同虚设
|
|
1160
|
+
// (实测:inert=false,Tab 能跑到背后的会话列表,读屏也读得到)。
|
|
1161
|
+
// 正确做法是从宿主挂载点(body 直接子节点)出发,把**包含 scrim 的那条
|
|
1162
|
+
// 祖先链之外**的兄弟节点全部隔离;祖先链本身不能 inert(会连面板一起废掉)。
|
|
1163
|
+
if (scrim && document.body) {
|
|
1164
|
+
const chain = new Set()
|
|
1165
|
+
for (let el = scrim; el && el !== document.body; el = el.parentElement) chain.add(el)
|
|
1166
|
+
for (const child of Array.from(document.body.children)) {
|
|
1167
|
+
if (chain.has(child)) continue
|
|
1168
|
+
if (child.tagName === 'SCRIPT' || child.tagName === 'STYLE' || child.tagName === 'LINK') continue
|
|
1105
1169
|
hidden.push({ child, inert: child.hasAttribute('inert'), aria: child.getAttribute('aria-hidden') })
|
|
1106
1170
|
child.setAttribute('inert', '')
|
|
1107
1171
|
child.setAttribute('aria-hidden', 'true')
|
|
1108
1172
|
}
|
|
1173
|
+
// 祖先链上的每一层:把**除当前链节点以外**的兄弟也隔离掉。
|
|
1174
|
+
// 典型结构 body > #root > ... > 槽位容器 > scrim,中途每层都可能带界面。
|
|
1175
|
+
for (const el of chain) {
|
|
1176
|
+
const parent = el.parentElement
|
|
1177
|
+
if (!parent || parent === document.body) continue
|
|
1178
|
+
for (const sib of Array.from(parent.children)) {
|
|
1179
|
+
if (sib === el || chain.has(sib)) continue
|
|
1180
|
+
if (sib.tagName === 'SCRIPT' || sib.tagName === 'STYLE' || sib.tagName === 'LINK') continue
|
|
1181
|
+
hidden.push({ child: sib, inert: sib.hasAttribute('inert'), aria: sib.getAttribute('aria-hidden') })
|
|
1182
|
+
sib.setAttribute('inert', '')
|
|
1183
|
+
sib.setAttribute('aria-hidden', 'true')
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
// 居中模态必须锁背景滚动:否则滚轮/触屏拖拽会把背后的会话列表滚走,
|
|
1188
|
+
// 关闭后视口停在别处。用 overflow:hidden 而非 position:fixed,
|
|
1189
|
+
// 后者会丢失滚动位置。保留原有内联值以便精确还原。
|
|
1190
|
+
const body = document.body
|
|
1191
|
+
const prevOverflow = body && body.style ? body.style.overflow : ''
|
|
1192
|
+
const prevPaddingRight = body && body.style ? body.style.paddingRight : ''
|
|
1193
|
+
let scrollbarW = 0
|
|
1194
|
+
try {
|
|
1195
|
+
scrollbarW = window.innerWidth - document.documentElement.clientWidth
|
|
1196
|
+
} catch { /* non-browser */ }
|
|
1197
|
+
if (body && body.style) {
|
|
1198
|
+
body.style.overflow = 'hidden'
|
|
1199
|
+
// 为被隐藏的经典滚动条补回等宽内边距,避免整页横向跳动。
|
|
1200
|
+
if (scrollbarW > 0) {
|
|
1201
|
+
const base = Number.parseFloat(getComputedStyle(body).paddingRight) || 0
|
|
1202
|
+
body.style.paddingRight = (base + scrollbarW) + 'px'
|
|
1203
|
+
}
|
|
1109
1204
|
}
|
|
1110
1205
|
return () => {
|
|
1111
1206
|
clearTimeout(timer)
|
|
@@ -1114,6 +1209,10 @@ window.__ModuleLoader__.load({
|
|
|
1114
1209
|
if (item.aria === null) item.child.removeAttribute('aria-hidden')
|
|
1115
1210
|
else item.child.setAttribute('aria-hidden', item.aria)
|
|
1116
1211
|
}
|
|
1212
|
+
if (body && body.style) {
|
|
1213
|
+
body.style.overflow = prevOverflow
|
|
1214
|
+
body.style.paddingRight = prevPaddingRight
|
|
1215
|
+
}
|
|
1117
1216
|
if (openRef.current) return
|
|
1118
1217
|
const trigger = triggerRef.current
|
|
1119
1218
|
triggerRef.current = null
|
|
@@ -1286,9 +1385,11 @@ window.__ModuleLoader__.load({
|
|
|
1286
1385
|
setDone('')
|
|
1287
1386
|
try {
|
|
1288
1387
|
if (mode === 'branch') {
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1388
|
+
// 0.12.0:分叉 = opencode 的 before 语义(新会话不含此条,原文回输入框)。
|
|
1389
|
+
// 非破坏操作,故不受 running 限制(官方 fork 会自己拒绝运行中源会话)。
|
|
1390
|
+
// 取文本用 `detail`(该条全文,pick 时已按 seq 拉好);非用户消息不带文本。
|
|
1391
|
+
const pickedRole = picked && picked.role
|
|
1392
|
+
const created = await forkFromUserMessage(actionSid, picked.seq, pickedRole === 'user' ? detail : '', picked.turnStartSeq)
|
|
1292
1393
|
if (sessionRef.current !== actionSid) return
|
|
1293
1394
|
setChildId(created || null)
|
|
1294
1395
|
setDone(t('panel.branchDone', { id: String(created || '') }))
|
|
@@ -1429,6 +1530,11 @@ window.__ModuleLoader__.load({
|
|
|
1429
1530
|
const revertVisibleCount = revertImpact.filter((m) => m.visible).length
|
|
1430
1531
|
const revertEnd = revertImpact.reduce((max, m) => Math.max(max, m.seq), pickedLive ? pickedLive.seq : 0)
|
|
1431
1532
|
const expectedDeleteTitle = target.expectedTitle || ''
|
|
1533
|
+
// 0.12.0:分叉/编辑只对**用户消息**成立(与 opencode 一致:fork 的语义是
|
|
1534
|
+
// 「这句话说错了,拿回去重说」,AI 消息没有可回填的原文)。
|
|
1535
|
+
const pickedIsUser = !!pickedLive && pickedLive.role === 'user'
|
|
1536
|
+
const canFork = !busy && !target.running && pickedIsUser && !pickedLive.shadowed && pickedLive.seq > 0
|
|
1537
|
+
const canEdit = pickedIsUser && !pickedLive.shadowed && state === 'ready' && !busy
|
|
1432
1538
|
const deleteBlockedReason = target.running
|
|
1433
1539
|
? t('panel.running')
|
|
1434
1540
|
: state !== 'ready'
|
|
@@ -1557,9 +1663,19 @@ window.__ModuleLoader__.load({
|
|
|
1557
1663
|
ref: deleteOneBtnRef,
|
|
1558
1664
|
onClick: () => setConfirmAction('delete'), title: t('panel.deleteHint'),
|
|
1559
1665
|
}, t('panel.delete')),
|
|
1666
|
+
// 0.12.0:编辑只对用户消息可用 —— 直接把原文交回编辑器。
|
|
1667
|
+
// 无二次确认:它不改日志,只改草稿。
|
|
1668
|
+
React.createElement('button', {
|
|
1669
|
+
type: 'button', className: 'mopsAction', disabled: !canEdit,
|
|
1670
|
+
title: pickedIsUser ? t('panel.editHint') : t('panel.branchUserOnly'),
|
|
1671
|
+
onClick: () => startEdit(detail || pickedLive.snippet || ''),
|
|
1672
|
+
}, t('panel.edit')),
|
|
1673
|
+
// 分叉同样只对用户消息可用(AI 消息没有可回填的原文),
|
|
1674
|
+
// 语义 = opencode 的 before:新会话不含此条,原文进新会话输入框。
|
|
1560
1675
|
React.createElement('button', {
|
|
1561
|
-
type: 'button', className: 'mopsAction', disabled: !
|
|
1562
|
-
onClick: () => runAction('branch'),
|
|
1676
|
+
type: 'button', className: 'mopsAction', disabled: !canFork || !!confirmAction,
|
|
1677
|
+
onClick: () => runAction('branch'),
|
|
1678
|
+
title: pickedIsUser ? t('panel.branchHint') : t('panel.branchUserOnly'),
|
|
1563
1679
|
}, t('panel.branch'))),
|
|
1564
1680
|
confirmAction
|
|
1565
1681
|
? React.createElement('div', {
|
|
@@ -1678,6 +1794,114 @@ window.__ModuleLoader__.load({
|
|
|
1678
1794
|
return { kind: 'disk' }
|
|
1679
1795
|
}
|
|
1680
1796
|
|
|
1797
|
+
// --- 0.12.0 消息级分叉(opencode 语义:分叉点**排他**,原文回到新会话输入框)-----
|
|
1798
|
+
//
|
|
1799
|
+
// 官方 `sessions.fork(source, boundary)` 的 boundary 是**闭区间**(含该事件)。
|
|
1800
|
+
// opencode 的 fork 是 before 语义(不含该条用户消息)+ 把该条放回新会话 composer。
|
|
1801
|
+
// 两者要一致,就必须把边界退到「该用户消息所在 turn 之前」。
|
|
1802
|
+
//
|
|
1803
|
+
// ⚠️ 不能退到 `seq - 1`。实测 40 份语料:真人输入的前一个事件**恒是同一 turn
|
|
1804
|
+
// 内的 system/message**(turn/start → agent/inbox/spliced → step/start →
|
|
1805
|
+
// system/message → user/message)。按 seq-1 切会得到一个「turn/step 已开、
|
|
1806
|
+
// 却没有任何 user 消息」的悬空前缀,引擎必须补合成 closers,语义也不是
|
|
1807
|
+
// 用户要的「这条之前」。
|
|
1808
|
+
// 正确边界 = 该 turn 的 turn/start seq 的**前一个**事件(`turnStartSeq - 1`)。
|
|
1809
|
+
// 服务端在 `GET /messages?view=compact` 里直接给出 `turnStartSeq`(见
|
|
1810
|
+
// src/index.js buildDerived),客户端不猜。
|
|
1811
|
+
const FORK_SESSION_STORAGE_PREFIX = 'dsh.conversation.'
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
* 官方 fork 边界(inclusive):目标用户消息所在 turn 的 turn/start 前一个事件。
|
|
1815
|
+
*
|
|
1816
|
+
* @param seq - 目标用户消息的日志 seq(仅用于无 turn 信息时的保守回退)
|
|
1817
|
+
* @param turnStartSeq - 该消息所在 turn 的 turn/start seq;服务端 compact 视图提供
|
|
1818
|
+
* @returns 可直接作为 `sessions.fork({ atSeq })` 的闭区间边界;不可分叉时 -1
|
|
1819
|
+
*/
|
|
1820
|
+
function forkBoundaryBefore(seq, turnStartSeq) {
|
|
1821
|
+
// 首选:按轮切(服务端已给出 turnStartSeq)
|
|
1822
|
+
if (Number.isSafeInteger(turnStartSeq) && turnStartSeq > 0) return turnStartSeq - 1
|
|
1823
|
+
// 回退:没有 turn 信息(老服务端 / 合成行)时退一格。
|
|
1824
|
+
// 这时切点可能落在 turn 内部,官方会补合成 closers —— 结果仍可加载,
|
|
1825
|
+
// 只是前缀边界不如按轮切干净。宁可这样也不静默不分叉。
|
|
1826
|
+
return Number.isSafeInteger(seq) && seq > 0 ? seq - 1 : -1
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
/**
|
|
1830
|
+
* 官方 assistant turn-tail 的 branch 按钮识别(0.12.0)。
|
|
1831
|
+
*
|
|
1832
|
+
* 为什么不能靠 aria-label:官方文案有 8 种语言(zh/en/ja/es/fr/de/ru/pt),
|
|
1833
|
+
* 逐个匹配等于把 i18n 表抄进来。也不能靠 class:CSS Modules 会哈希前缀
|
|
1834
|
+
* (实测 0.2.0-rc.2 是 `xzv4MW_`,0.2.1 起变过)。
|
|
1835
|
+
* 唯一稳定的是**图标几何**:官方 `IconBranchOutline16` 的 path d 是常量
|
|
1836
|
+
* (packages/client/ui-primitives/src/icons/index.tsx:149)。
|
|
1837
|
+
* 我们自己的分叉按钮复用同一 path,所以必须显式排除。
|
|
1838
|
+
*
|
|
1839
|
+
* @param btn - 候选按钮(任意元素;非 button 的宿主节点返回 false)
|
|
1840
|
+
* @returns 是否官方 branch 按钮
|
|
1841
|
+
*/
|
|
1842
|
+
const HOST_BRANCH_D_PREFIX = 'M13.0762 1.37207'
|
|
1843
|
+
const HOST_BRANCH_CLASS = 'mopsUserFork'
|
|
1844
|
+
function isHostBranchButton(btn) {
|
|
1845
|
+
if (!btn || typeof btn.querySelector !== 'function') return false
|
|
1846
|
+
const cls = String((btn.classList && btn.classList.value) || btn.className || '')
|
|
1847
|
+
if (cls.split(/\s+/).includes(HOST_BRANCH_CLASS)) return false
|
|
1848
|
+
const path = btn.querySelector('svg path')
|
|
1849
|
+
const d = path ? path.getAttribute('d') || '' : ''
|
|
1850
|
+
return d.startsWith(HOST_BRANCH_D_PREFIX)
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
/**
|
|
1854
|
+
* 把文本预置成某个会话的草稿(新会话刚 fork 出来时输入框是空的)。
|
|
1855
|
+
*
|
|
1856
|
+
* 为什么直接写 localStorage 而不是 `inputActions.setDraft`:fork 出来的是一个**还没
|
|
1857
|
+
* 挂载**的会话,此刻 `inputActions` 仍绑定在源会话上;宿主挂载新会话时会用
|
|
1858
|
+
* `readConversationDraft(sessionId)` 从 localStorage 初始化编辑器。所以**先落盘再
|
|
1859
|
+
* openSession** 才是无竞态的路径(`{ draft: '<text>' }` 是宿主 `parseStoredDraft`
|
|
1860
|
+
* 支持的字符串形态,见 dsh-client-ui-conversation:4455-4456)。
|
|
1861
|
+
*/
|
|
1862
|
+
function writeSessionDraft(childSessionId, text) {
|
|
1863
|
+
try {
|
|
1864
|
+
if (!childSessionId || typeof localStorage === 'undefined') return false
|
|
1865
|
+
localStorage.setItem(FORK_SESSION_STORAGE_PREFIX + childSessionId, JSON.stringify({ draft: String(text || '') }))
|
|
1866
|
+
return true
|
|
1867
|
+
} catch (e) {
|
|
1868
|
+
console.warn('[message-ops] writeSessionDraft failed:', e)
|
|
1869
|
+
return false
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
/** 打开会话(宿主唯一通道)。childId 需要 `session-` 前缀才不会抛 unknown session。 */
|
|
1874
|
+
function openSessionById(sessionId) {
|
|
1875
|
+
try {
|
|
1876
|
+
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') {
|
|
1877
|
+
__uiWorkspace.openSession(sessionId)
|
|
1878
|
+
return true
|
|
1879
|
+
}
|
|
1880
|
+
} catch (e) {
|
|
1881
|
+
console.warn('[message-ops] openSession failed:', e)
|
|
1882
|
+
}
|
|
1883
|
+
return false
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
/**
|
|
1887
|
+
* 从一条**用户消息**分叉:复制到该条之前,并把该条原文放回新会话输入框。
|
|
1888
|
+
*
|
|
1889
|
+
* @param sessionId - 源会话 id(前缀写法都接受,官方 store 自己归一)。
|
|
1890
|
+
* @param seq - 目标用户消息的日志 seq。
|
|
1891
|
+
* @param text - 该条用户消息原文;缺省时新会话输入框留空。
|
|
1892
|
+
* @returns 新会话 id。
|
|
1893
|
+
* @throws 无官方 fork、seq 无前驱、或宿主拒绝(会话运行中)时抛出可展示的错误。
|
|
1894
|
+
*/
|
|
1895
|
+
async function forkFromUserMessage(sessionId, seq, text, turnStartSeq) {
|
|
1896
|
+
const forkPath = pickForkPath(__sessionsSvc)
|
|
1897
|
+
if (forkPath.kind !== 'official') throw new Error(__t('slot.forkUnavailable'))
|
|
1898
|
+
const boundary = forkBoundaryBefore(seq, turnStartSeq)
|
|
1899
|
+
if (boundary < 0) throw new Error(__t('slot.forkUnavailable'))
|
|
1900
|
+
const childId = await forkPath.fork({ sessionId, atSeq: boundary, increaseTitle: true })
|
|
1901
|
+
if (childId && text) writeSessionDraft(childId, text)
|
|
1902
|
+
return childId
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1681
1905
|
// 成功反馈统一出口:devkit 标准 toast 优先,无 devkit 时对话框内文案兜底。
|
|
1682
1906
|
function notifyDone(msg, kind) {
|
|
1683
1907
|
try {
|
|
@@ -2261,7 +2485,7 @@ window.__ModuleLoader__.load({
|
|
|
2261
2485
|
const injected = (raw) => /^<system-reminder|current\s+runtime\s+context|^<system-Reminder|^background job\s+[\w-]+|^Background subagent\s+[0-9a-f]{8}-|^Agent\s+[0-9a-f]{8}-|^\[model changed:/i.test(String(raw || ''))
|
|
2262
2486
|
const rows = ((d && d.messages) || [])
|
|
2263
2487
|
.filter((m) => m && m.role === 'user')
|
|
2264
|
-
.map((m) => ({ seq: m.seq, sn: norm(m.snippet), raw: String(m.snippet == null ? '' : m.snippet), fullText: m.fullText ?? null, visible: m.visible !== false }))
|
|
2488
|
+
.map((m) => ({ seq: m.seq, sn: norm(m.snippet), raw: String(m.snippet == null ? '' : m.snippet), fullText: m.fullText ?? null, visible: m.visible !== false, turnStartSeq: m.turnStartSeq ?? null }))
|
|
2265
2489
|
.filter((r) => r.sn && !injected(r.raw))
|
|
2266
2490
|
// 0.9.1:同时产出 node-key 查表索引(隐藏 transcript 用)
|
|
2267
2491
|
const idx = buildIndex(d)
|
|
@@ -2457,7 +2681,7 @@ window.__ModuleLoader__.load({
|
|
|
2457
2681
|
const ok = block.getAttribute('data-mops-seq')
|
|
2458
2682
|
if (ok) {
|
|
2459
2683
|
btn.disabled = false
|
|
2460
|
-
btn.title = __t('slot.revert')
|
|
2684
|
+
btn.title = __t(btn.classList.contains('mopsUserFork') ? 'slot.forkHint' : 'slot.revert')
|
|
2461
2685
|
btn.removeAttribute('data-mops-unmatched')
|
|
2462
2686
|
} else {
|
|
2463
2687
|
btn.disabled = true
|
|
@@ -2465,6 +2689,11 @@ window.__ModuleLoader__.load({
|
|
|
2465
2689
|
btn.setAttribute('data-mops-unmatched', '1')
|
|
2466
2690
|
}
|
|
2467
2691
|
}
|
|
2692
|
+
/** 块内全部插件按钮一起同步(回滚 / 分叉同一动作行)。 */
|
|
2693
|
+
var syncBlockButtons = (block) => {
|
|
2694
|
+
if (!block || !block.querySelectorAll) return
|
|
2695
|
+
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserFork')) syncEnabled(block, b)
|
|
2696
|
+
}
|
|
2468
2697
|
var assignSeqs = (sid, cache, anchors) => {
|
|
2469
2698
|
const idx = cache && cache.idx
|
|
2470
2699
|
if (!idx) return
|
|
@@ -2476,11 +2705,11 @@ window.__ModuleLoader__.load({
|
|
|
2476
2705
|
const seq = hit === null ? null : hit.seq
|
|
2477
2706
|
if (seq === null || seq === undefined) {
|
|
2478
2707
|
b.setAttribute('data-mops-unmatched', '1')
|
|
2479
|
-
|
|
2708
|
+
syncBlockButtons(b)
|
|
2480
2709
|
continue
|
|
2481
2710
|
}
|
|
2482
2711
|
b.setAttribute('data-mops-seq', String(seq))
|
|
2483
|
-
|
|
2712
|
+
syncBlockButtons(b)
|
|
2484
2713
|
}
|
|
2485
2714
|
}
|
|
2486
2715
|
// 按钮可用性在 assignSeqs 内部**同步**更新(与打标同一次循环)——
|
|
@@ -2571,6 +2800,52 @@ window.__ModuleLoader__.load({
|
|
|
2571
2800
|
.finally(() => { btn.disabled = false })
|
|
2572
2801
|
})
|
|
2573
2802
|
}
|
|
2803
|
+
/**
|
|
2804
|
+
* 0.12.0 用户消息「从此条分叉」:非破坏操作,源会话一字不动。
|
|
2805
|
+
*
|
|
2806
|
+
* opencode 语义 = 复制此条**之前**的对话到一个新会话,并把此条原文放回
|
|
2807
|
+
* 新会话的输入框,让用户改完再发。因此这里要三步:
|
|
2808
|
+
* 1. 解析 seq(点击当下可能还没打标 → 先 ensureAssign 再 fetchRows)
|
|
2809
|
+
* 2. 取该条用户消息的**原文**(列表只携带 snippet,长度会被截断)
|
|
2810
|
+
* 3. fork(boundary = seq - 1) → 把原文写进子会话草稿 → 打开子会话
|
|
2811
|
+
*/
|
|
2812
|
+
var runUserFork = (btn, block) => {
|
|
2813
|
+
const sid = __currentSessionId
|
|
2814
|
+
if (!sid) return
|
|
2815
|
+
btn.disabled = true
|
|
2816
|
+
Promise.resolve()
|
|
2817
|
+
.then(() => ensureAssign(sid))
|
|
2818
|
+
.then(() => fetchRows(sid))
|
|
2819
|
+
.then(async (cache) => {
|
|
2820
|
+
const rows = cache && cache.rows
|
|
2821
|
+
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
2822
|
+
const row = rows && rows.find((r) => r.seq === seq)
|
|
2823
|
+
if (!row) {
|
|
2824
|
+
notifyDone(__t('errorPrefix') + (__t('revert.unresolved') || 'fork target verification failed'), 'error')
|
|
2825
|
+
return
|
|
2826
|
+
}
|
|
2827
|
+
if (!(seq > 0)) {
|
|
2828
|
+
notifyDone(__t('slot.forkUnavailable'), 'warn')
|
|
2829
|
+
return
|
|
2830
|
+
}
|
|
2831
|
+
let text = typeof row.fullText === 'string' ? row.fullText : ''
|
|
2832
|
+
if (!text) {
|
|
2833
|
+
try {
|
|
2834
|
+
const res = await fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(bareSessionId(sid)) + '&seq=' + encodeURIComponent(seq))
|
|
2835
|
+
const data = res.ok ? await res.json().catch(() => null) : null
|
|
2836
|
+
if (data && data.ok && typeof data.text === 'string') text = data.text
|
|
2837
|
+
} catch { /* 取全文失败:分叉照做,只是输入框留空 */ }
|
|
2838
|
+
}
|
|
2839
|
+
const childId = await forkFromUserMessage(sid, seq, text, row.turnStartSeq)
|
|
2840
|
+
notifyDone(__t('slot.forkDone', { id: String(childId || '') }))
|
|
2841
|
+
if (childId) openSessionById(childId)
|
|
2842
|
+
})
|
|
2843
|
+
.catch((reason) => {
|
|
2844
|
+
notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
2845
|
+
})
|
|
2846
|
+
.finally(() => { btn.disabled = false })
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2574
2849
|
var ensureBtn = (block) => {
|
|
2575
2850
|
// 官方动作行(含 Copy):把按钮放到这一行里,与 Copy 同级
|
|
2576
2851
|
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
@@ -2599,6 +2874,38 @@ window.__ModuleLoader__.load({
|
|
|
2599
2874
|
syncEnabled(block, btn)
|
|
2600
2875
|
return btn
|
|
2601
2876
|
}
|
|
2877
|
+
|
|
2878
|
+
/** 0.12.0 分叉按钮:与回滚按钮**同一动作行**(opencode 把 fork 放在 copy/undo 同组)。 */
|
|
2879
|
+
var ensureForkBtn = (block) => {
|
|
2880
|
+
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
2881
|
+
if (!host) {
|
|
2882
|
+
host = document.createElement('div')
|
|
2883
|
+
host.className = 'mopsUserActionsRow'
|
|
2884
|
+
block.appendChild(host)
|
|
2885
|
+
}
|
|
2886
|
+
const existing = host.querySelector('.mopsUserFork')
|
|
2887
|
+
if (existing) return existing
|
|
2888
|
+
const btn = document.createElement('button')
|
|
2889
|
+
btn.type = 'button'
|
|
2890
|
+
btn.className = 'mopsUserFork'
|
|
2891
|
+
btn.title = __t('slot.forkHint')
|
|
2892
|
+
btn.setAttribute('aria-label', __t('slot.fork'))
|
|
2893
|
+
// 官方 IconBranchOutline16 的 1:1 路径(packages/client/ui-primitives/src/icons/index.tsx:149)
|
|
2894
|
+
btn.innerHTML = '<svg width="15" height="15" viewBox="0 0 16 16" fill="none" stroke="none"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M13.0762 1.37207C14.0846 1.37228 14.9021 2.19077 14.9023 3.19922C14.9022 4.20772 14.0847 5.02518 13.0762 5.02539C12.2967 5.02539 11.6325 4.53691 11.3701 3.84961H4.35547C4.79397 4.26458 5.15861 4.7644 5.41699 5.33496L7.10645 9.06738C7.88526 10.7875 9.55104 11.9228 11.4189 12.0371C11.7085 11.4109 12.3411 10.9756 13.0762 10.9756C14.0843 10.9759 14.9023 11.7936 14.9023 12.8018C14.9023 13.81 14.0843 14.6277 13.0762 14.6279C12.2534 14.6279 11.5574 14.0832 11.3291 13.335C8.9868 13.1879 6.89981 11.7612 5.92285 9.60352L4.23242 5.87109C3.67503 4.64033 2.44878 3.84961 1.09766 3.84961V2.54883C1.10665 2.54883 1.11601 2.54975 1.125 2.5498L11.3701 2.54883C11.6326 1.86151 12.2969 1.37207 13.0762 1.37207ZM13.0762 12.2764C12.7858 12.2764 12.5508 12.5114 12.5508 12.8018C12.5508 13.0921 12.7858 13.3281 13.0762 13.3281C13.3664 13.3279 13.6025 13.092 13.6025 12.8018C13.6025 12.5115 13.3664 12.2766 13.0762 12.2764ZM13.0762 2.67285C12.7855 2.67285 12.55 2.90861 12.5498 3.19922C12.5499 3.48987 12.7855 3.72559 13.0762 3.72559C13.3667 3.72538 13.6024 3.48975 13.6025 3.19922C13.6023 2.90874 13.3666 2.67306 13.0762 2.67285Z"/></svg>'
|
|
2895
|
+
btn.addEventListener('click', (e) => {
|
|
2896
|
+
e.preventDefault(); e.stopPropagation()
|
|
2897
|
+
if (btn.disabled) return
|
|
2898
|
+
runUserFork(btn, block)
|
|
2899
|
+
})
|
|
2900
|
+
host.appendChild(btn)
|
|
2901
|
+
syncEnabled(block, btn)
|
|
2902
|
+
return btn
|
|
2903
|
+
}
|
|
2904
|
+
// 两个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),分叉在后(非破坏)。
|
|
2905
|
+
var ensureUserActions = (block) => {
|
|
2906
|
+
ensureBtn(block)
|
|
2907
|
+
ensureForkBtn(block)
|
|
2908
|
+
}
|
|
2602
2909
|
// 0.9.7(P0-2 读合并):把 150/700/1600ms 三档并成**一次**真网络请求,
|
|
2603
2910
|
// 落点 = 本 burst 第一档 + 1500ms ≈ 原来的 1600ms 那一档。
|
|
2604
2911
|
// 🔴 红线:这一档是「视图重建后重算隐藏」的兜底,绝不能砍成 0。
|
|
@@ -2631,13 +2938,41 @@ window.__ModuleLoader__.load({
|
|
|
2631
2938
|
const sid = __currentSessionId
|
|
2632
2939
|
if (!sid) return
|
|
2633
2940
|
const blocks = userAnchors()
|
|
2634
|
-
for (const b of blocks)
|
|
2941
|
+
for (const b of blocks) ensureUserActions(b)
|
|
2942
|
+
suppressHostBranch()
|
|
2635
2943
|
// 0.9.1:**始终**刷新(原先只在按钮未打标时刷)——
|
|
2636
2944
|
// 打标后 transcript 再变化(openSession 重建 / 分页 / restore 重放)
|
|
2637
2945
|
// 就再也不会重算隐藏,导致「界面停在旧状态,必须重载页面才对」。
|
|
2638
2946
|
ensureAssign(sid)
|
|
2639
2947
|
} catch { /* 注入失败不影响会话 */ }
|
|
2640
2948
|
}
|
|
2949
|
+
/**
|
|
2950
|
+
* 0.12.0 隐藏官方 assistant turn-tail 上的 branch 按钮。
|
|
2951
|
+
*
|
|
2952
|
+
* 产品决定:分叉只属于**用户消息**(opencode 语义 —— fork 的目的是「这句话说错了,
|
|
2953
|
+
* 拿回输入框重说」,AI 消息没有可回填的原文,分叉出去只会得到一个半截对话)。
|
|
2954
|
+
* 官方把 branch 画在 MessageIconActions 里,与 copy 同一行;官方没有开关
|
|
2955
|
+
* (ui-chat 的 Config 只有折叠/性能/链接几项),所以只能在渲染层隐藏。
|
|
2956
|
+
*
|
|
2957
|
+
* 识别方式不用 aria-label(8 种语言各不同),也不用哈希 class,而用
|
|
2958
|
+
* **图标路径前缀**:官方 IconBranchOutline16 的 d 是固定字符串
|
|
2959
|
+
* (packages/client/ui-primitives/src/icons/index.tsx:149)。作用域限定在
|
|
2960
|
+
* `[data-turn-tail]`(官方 TurnTailNodeView 渲染的稳定属性),
|
|
2961
|
+
* 并排除我们自己注入的 .mopsUserFork(它复用同一 path)。
|
|
2962
|
+
*/
|
|
2963
|
+
var suppressHostBranch = () => {
|
|
2964
|
+
let hidden = 0
|
|
2965
|
+
for (const btn of document.querySelectorAll('[data-turn-tail] button')) {
|
|
2966
|
+
if (!isHostBranchButton(btn)) continue
|
|
2967
|
+
hidden++
|
|
2968
|
+
if (btn.getAttribute('data-mops-host-branch') !== 'hidden') {
|
|
2969
|
+
btn.setAttribute('data-mops-host-branch', 'hidden')
|
|
2970
|
+
btn.style.display = 'none'
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
return hidden
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2641
2976
|
// 触发:hover / 滚动 / DOM 变化 / 变更事件
|
|
2642
2977
|
document.addEventListener('mouseover', (e) => {
|
|
2643
2978
|
try {
|
|
@@ -2645,7 +2980,7 @@ window.__ModuleLoader__.load({
|
|
|
2645
2980
|
if (!__currentSessionId) return
|
|
2646
2981
|
const block = e.target.closest('[class*="Sixlwa_userRow"], [data-chat-flow-kind="user"]')
|
|
2647
2982
|
if (!block) return
|
|
2648
|
-
|
|
2983
|
+
ensureUserActions(block)
|
|
2649
2984
|
if (!block.hasAttribute('data-mops-seq')) ensureAssign(__currentSessionId)
|
|
2650
2985
|
} catch { /* noop */ }
|
|
2651
2986
|
}, { passive: true })
|
|
@@ -2662,7 +2997,7 @@ window.__ModuleLoader__.load({
|
|
|
2662
2997
|
// 这是正确性问题,不只是性能。
|
|
2663
2998
|
// ③ attributeFilter 只盯 data-chat-node-key:本插件不写该属性(写的是
|
|
2664
2999
|
// data-mops-seq / hidden),所以不会被自己触发成环。
|
|
2665
|
-
var MO_SEL = '[data-chat-node-key],[data-chat-flow-kind="user"],[class*="xzv4MW_actions"],[class*="_userRow"]'
|
|
3000
|
+
var MO_SEL = '[data-chat-node-key],[data-chat-flow-kind="user"],[class*="xzv4MW_actions"],[class*="_userRow"],[data-turn-tail]'
|
|
2666
3001
|
var scanPendingSince = 0
|
|
2667
3002
|
var scheduleScan = () => {
|
|
2668
3003
|
var now = Date.now()
|
|
@@ -2715,9 +3050,9 @@ window.__ModuleLoader__.load({
|
|
|
2715
3050
|
tag.textContent = [
|
|
2716
3051
|
// 不再用 absolute + :hover:按钮作为宿主动作行的子元素,
|
|
2717
3052
|
// 由宿主 [data-actions-reveal] 统一控制显隐(触屏也跟着宿主走)。
|
|
2718
|
-
'.mopsUserRevert{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:6px;background:transparent;color:var(--dsw-alias-label-tertiary,#9a9aa0);cursor:pointer;padding:0;flex:none}',
|
|
2719
|
-
'.mopsUserRevert:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12))}',
|
|
2720
|
-
'.mopsUserRevert:disabled{opacity:.4;cursor:default}',
|
|
3053
|
+
'.mopsUserRevert,.mopsUserFork{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:6px;background:transparent;color:var(--dsw-alias-label-tertiary,#9a9aa0);cursor:pointer;padding:0;flex:none}',
|
|
3054
|
+
'.mopsUserRevert:hover,.mopsUserFork:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12))}',
|
|
3055
|
+
'.mopsUserRevert:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default}',
|
|
2721
3056
|
'.mopsUserActionsRow{height:28px;display:flex;align-items:center;gap:8px;margin-left:-6px}',
|
|
2722
3057
|
'@media (hover:none){.mopsUserActionsRow{opacity:1}}',
|
|
2723
3058
|
].join('')
|
|
@@ -3104,6 +3439,6 @@ window.__ModuleLoader__.load({
|
|
|
3104
3439
|
installUserRevertInjector()
|
|
3105
3440
|
}
|
|
3106
3441
|
|
|
3107
|
-
return { apply, inject: ['slots'], __test: { activityTransition } }
|
|
3442
|
+
return { apply, inject: ['slots'], __test: { activityTransition, forkBoundaryBefore, isHostBranchButton, writeSessionDraft, HOST_BRANCH_D_PREFIX } }
|
|
3108
3443
|
},
|
|
3109
3444
|
})
|
package/src/index.js
CHANGED
|
@@ -429,6 +429,38 @@ async function buildDerived(logPath) {
|
|
|
429
429
|
const turnEndSeq = {};
|
|
430
430
|
for (const [turn, seq] of bounds.ends) turnEndSeq[turn] = seq;
|
|
431
431
|
for (const [turn, seq] of bounds.starts) if (!(turn in turnEndSeq)) turnEndSeq[turn] = seq;
|
|
432
|
+
// 0.12.0 分叉边界:给每条消息挂「它所在 turn 的 turn/start seq」。
|
|
433
|
+
//
|
|
434
|
+
// 为什么不能按 seq-1 切:实测 40 份语料里,真人输入的**前一个事件恒是同一 turn
|
|
435
|
+
// 内的 system/message**(turn/start → agent/inbox/spliced → step/start →
|
|
436
|
+
// system/message → user/message),按 seq-1 分叉会得到「turn/step 已开、
|
|
437
|
+
// 但没有 user 消息」的悬空前缀 —— 引擎得补合成 closers,语义也不是用户想要的
|
|
438
|
+
// 「这条之前」。
|
|
439
|
+
// 正确边界 = turn/start 的**前一个**事件 seq(= turnStartSeq - 1);
|
|
440
|
+
// 首个 turn(seq 4)之前只有 seq 0..3 的会话头/permission 事件,也成立。
|
|
441
|
+
const turnStartSeq = {};
|
|
442
|
+
for (const [turn, seq] of bounds.starts) turnStartSeq[turn] = seq;
|
|
443
|
+
// ⚠️ 真人 `user/message` 事件**不带 `turn` 字段**(实测:data 里只有 id/source/message),
|
|
444
|
+
// 它是否属于某轮由投影决定,不是日志里的事实。`system/message`/`assistant/message`
|
|
445
|
+
// 才带 turn/step。所以不能只查 `m.turn` —— 必须扫一遍事件,用「当前开着的 turn」
|
|
446
|
+
// 给每条消息定归属(user 消息恒落在 turn/start 之后、turn/end 之前)。
|
|
447
|
+
const enclosingTurnStart = new Map(); // message seq -> 所属 turn 的 turn/start seq
|
|
448
|
+
let openTurnStart = null;
|
|
449
|
+
for (const e of events) {
|
|
450
|
+
if (!e || typeof e.seq !== "number") continue;
|
|
451
|
+
if (e.type === "turn/start") { openTurnStart = e.seq; continue; }
|
|
452
|
+
if (e.type === "turn/end") { openTurnStart = null; continue; }
|
|
453
|
+
if (e.type !== "user/message" && e.type !== "assistant/message" && e.type !== "system/message") continue;
|
|
454
|
+
const ownTurn = e.data && e.data.turn;
|
|
455
|
+
const startSeq = Number.isSafeInteger(ownTurn) && turnStartSeq[ownTurn] != null
|
|
456
|
+
? turnStartSeq[ownTurn]
|
|
457
|
+
: openTurnStart;
|
|
458
|
+
enclosingTurnStart.set(e.seq, startSeq ?? null);
|
|
459
|
+
}
|
|
460
|
+
for (const m of messages) {
|
|
461
|
+
if (!m || typeof m.seq !== "number") continue;
|
|
462
|
+
m.turnStartSeq = enclosingTurnStart.get(m.seq) ?? null;
|
|
463
|
+
}
|
|
432
464
|
return { header, messages, shadowed, turnEndSeq };
|
|
433
465
|
}
|
|
434
466
|
|
|
@@ -501,6 +533,10 @@ async function opsList(targetCtx, sessionId, opts = {}) {
|
|
|
501
533
|
time: m.time,
|
|
502
534
|
visible: m.visible,
|
|
503
535
|
shadowed: m.shadowed,
|
|
536
|
+
// 0.12.0:分叉要按**轮**切,不能按 seq-1 切(见 buildDerived 的注释)。
|
|
537
|
+
// 客户端据此算 fork 边界 = turnStartSeq - 1。只带这一个字段:turn/step
|
|
538
|
+
// 属于「重」字段,面板的虚拟行用不到(详见 compact 的取舍)。
|
|
539
|
+
turnStartSeq: m.turnStartSeq ?? null,
|
|
504
540
|
}))
|
|
505
541
|
: messages;
|
|
506
542
|
|