@240xu/dsh-message-ops 0.7.0 → 0.9.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 CHANGED
@@ -1,13 +1,37 @@
1
1
  # @240xu/dsh-message-ops
2
2
 
3
- DSH web 插件:**消息回滚 + 消息删除 + 消息分支** 三合一。在会话头部添加分支图标按钮,
4
- 侧栏会话行 "..." 菜单注入「消息操作」项,打开统一操作对话框:
3
+ DSH web 插件:**消息回滚 + 删除 + 恢复**。只补 dsh 官方**没有**的能力。
5
4
 
6
- - **回滚(Revert)**:遮蔽所选消息及其后的全部可见内容(DSH 原生 surface replace 语义)。
7
- 日志 append-only,原事件完整保留,语境可通过重新发送恢复。
8
- - **删除(Delete)**:仅遮蔽所选的那一条消息,其余内容不变(同样是 surface replace)。
9
- - **分支(Branch)**:把所选消息(含)之前的全部事件复制为一个**新会话**,
10
- 新会话 header 携带 `parentSession=<原会话 id>`,原会话一个字节都不动 —— 唯一的非破坏操作。
5
+ > **0.9.0 是破坏性变更**:移除了本插件的**分支**与 **Markdown 导出**。
6
+ > 两者 dsh 官方都已有(`session/fork` 与 `/api/session.export`),详见下方「为什么不重复造轮子」。
7
+
8
+ ## 官方没有、本插件提供的
9
+
10
+ | 能力 | 官方 dsh 0.2.0-rc.2 | 本插件 |
11
+ |---|---|---|
12
+ | **消息回滚**(遮蔽该条及其后全部内容) | ❌ 没有。`SurfaceOp` 只有 `append\|replace`,**没有解除遮蔽的操作**;`undo` 仅指草稿编辑器的 Ctrl+Z | ✅ |
13
+ | **单条删除** | ❌ 没有。官方 README 明文 *"sessions can be archived but never deleted"* | ✅ |
14
+ | **恢复**(撤销一次回滚/删除) | ❌ 没有 | ✅ |
15
+
16
+ ## 为什么不重复造轮子(0.9.0 的取舍)
17
+
18
+ - **分支** → 官方有完整实现:RPC `session/fork`(`atSeq` 任意)+ `SessionStore.fork()`
19
+ + UI 消息级按钮 + 官方埋点就叫 `branch_session_click`。
20
+ 本插件原先还有一个磁盘实现(`applyBranch`)作为「官方失败时的回落」,但它语义是错的:
21
+ 删掉了 `isSeeded`(官方 fork 设 `true`)、不写 `inheritedEventCount`、
22
+ 也不补 fork closers → 产出的子会话边界可能悬空。**已删除**,失败时直接提示停止运行中的会话。
23
+ - **Markdown 导出** → 官方 `/api/session.export` 提供 ZIP 归档(原始 JSONL + 附件,面向迁移/复现)。
24
+ 格式确实不重叠,但本插件的导出**零 UI 入口**(实测路由可用但前端从不调用),等于死代码。**已删除**。
25
+
26
+ ## 用法
27
+
28
+ - **会话头部**的 `Message ops (revert / delete / branch)` 按钮 → 统一对话框
29
+ - **助手消息** hover 行的 `Revert to here` / `Quote to composer`
30
+ - **用户消息** hover 行的 `Revert to here`
31
+ - **输入框上方的回撤贴条**:展开后可逐条 `Restore`(这是恢复的唯一入口)
32
+ - **侧栏会话行**的 `...` 菜单
33
+
34
+ 对话框流程:**先在列表里选一条消息 → 上方出现三个操作 → 破坏性操作需勾选确认**。
11
35
 
12
36
  ## 安装
13
37
 
@@ -370,3 +394,93 @@ Playwright 实测 opencode web(127.0.0.1:4096)后四项改造:
370
394
  - 验证:单测 44/44;Playwright 失败用例先红后绿(`inOfficialRow && sameRowAsCopy
371
395
  && !overlapsBubble` 全真 + `POST /revert 200` + 贴条出现);对话框路径全环
372
396
  (回滚→贴条→展开→恢复→条清空+无前缀)复跑通过。
397
+
398
+ ## 0.8.0 · 按轮步进恢复(对齐 opencode 展开行语义)
399
+
400
+ opencode 实测:展开行 = 每条被遮蔽消息一行,点行**只恢复该消息及其同轮回复**,
401
+ 后续保持遮蔽。0.8.0 把"按标记整段恢复"升级为"按轮步进":
402
+
403
+ - **服务端**:
404
+ - `planRestore(events, seq, upToSeq?, excludeSeqs?)`:`upToSeq` 截断重放区间;
405
+ `excludeSeqs` 排除已重放源 seq(**B1 修复**:此前每轮从区间头重放 →
406
+ 消息副本成倍刷屏,实测 seq8 被重放 5 次)。
407
+ - 恢复 notice 新增 `restoredSourceSeqs`(本次重放的源 seq 列表)——
408
+ 引擎准入**不拒绝** data 未知字段(研究册 01 §8),且实测磁盘原样持久化。
409
+ - `restoreProgress()`:标记的恢复进度(restored/pending/complete/legacy);
410
+ `pendingRestoreTurns()`:未重放轮切分(一个 user 及其后继 assistant 为一轮)。
411
+ - `GET /messages` 为每个标记附 `restoreComplete` + `pendingTurns`
412
+ (含 preview,一次建 seq→text 索引,避免每标记全量扫)。
413
+ - `POST /restore` 接受可选 `upToSeq`(live 与磁盘两路径一致)。
414
+ - **客户端**:
415
+ - 贴条行 = 待恢复轮(`#markerSeq · 首条预览 (+N)`),点击只回该轮;
416
+ - 标记活跃判定收敛到服务端权威 `restoreComplete`(删除客户端 restoresSeq
417
+ 集合旧判——按轮下部分恢复的标记也带 restoresSeq,旧逻辑会误杀,
418
+ 实测:第一轮恢复后整条消失);
419
+ - 全部轮恢复完 → 标记不活跃 → 贴条消失;兼容旧 notice(视为整段已恢复)。
420
+ - **验证**:单测 **49/49**(新增 5 条:upToSeq 截断 / notice 字段 / 进度推进 /
421
+ 旧通知兼容 / B1 排除);Playwright `v080.cjs` 全环 **GREEN**:
422
+ 5 行=5 轮 → 点第一行(S1 副本=1、余 4 轮、贴条保持)→ 逐轮清空 →
423
+ `markerActive=false`、无前缀、贴条消失;0.7.0 布局用例复跑 GREEN;
424
+ 对话框路径复跑通过(恢复亦按轮)。
425
+
426
+ ## 0.8.1 · discard 停用面 + 用户会话实查结论
427
+
428
+ - 新增 `POST /restore {discard:true}`:不重放内容、仅停用标记(notice 带
429
+ `discarded:true`,进度判定视为完成)。适用场景:清掉"没有可重放内容/不希望
430
+ 重放"的惰性标记。
431
+ - 用户主会话(4e10c1a2)实查:8 个测试标记在 0.8.0 语义下全部 complete=True
432
+ (区间无可重放消息内容——链式遮蔽的是其他标记),贴条不再显示,**无需丢弃**;
433
+ hidden≈2710 的大头是 compact-checkpoint(引擎自身历史压缩设计),非测试污染
434
+ (修正 0.8.0 时代"2709 条测试污染"的误判)。清理前已备份日志
435
+ (~/.dsh/backups/session-4e10c1a2.*.zstd.bak,9.2MB)。
436
+ - 单测 50/50(+1 discard 语义)。
437
+
438
+ ---
439
+
440
+ ## 0.9.0 变更清单
441
+
442
+ ### 移除(与官方重复或无入口)
443
+ - `src/branch.js` 整个删除;`/api/message-ops/branch` 路由、tool 的 `branch` 动作、
444
+ 客户端的磁盘回落(`diskBranch`)与 `fork.disk` 文案全部移除。**分支现在只走官方 `sessions.fork()`**,
445
+ 失败时提示「官方分支不可用,通常是会话正在运行」。
446
+ - `/api/message-ops/export` 路由、`exportMarkdown()`、tool 的 `export` 动作移除。
447
+ **导出一律用官方 `/api/session.export`**(ZIP 归档)。
448
+ - 死代码清理:`IconTrash`/`TrashFallback`(零渲染点)、对话框内永不可达的 restore 分支、
449
+ 4 组 restore locale 文案(dock 用自己的 `dock.*` 键)。
450
+
451
+ ### 修复(均为浏览器实测发现,静态审查无法发现)
452
+ 1. **用户消息回滚按钮恒定失效**。四个 bug 叠在一起:
453
+ - `userAnchors()` 匹配 CSS-module 生成的前缀 `Sixlwa_*`,而 dsh 0.2.0-rc.2 的哈希已变为
454
+ `EvIC1a_*` → 锚点集为空;
455
+ - 过滤了 `m.visible !== false`,但宿主聊天视图**不施加**遮蔽模型、照常渲染被回滚的消息
456
+ → 配对候选与 DOM 块零交集;
457
+ - `injected()` 的 `current\s+runtime\s+context` 跑在 `norm()`(`replace(/\s+/g,'')`,删掉**全部**空白)
458
+ 之后的串上 → 永远匹配不上,伪 user 行漏进配对;
459
+ - 按钮可用性在 fetch 回调里做事后全局扫描,与 DOM 注入/重排竞态
460
+ → 块已打上 seq 而按钮仍禁用。
461
+ 现在实测 `data-mops-seq=["8","54"]`、按钮可用;配不上的块会被**禁用并说明原因**,
462
+ 而不是留一个点了才报错的装饰按钮。
463
+ 2. **对话区硬编码 `_flowItem` 会误收官方 `turn-tail`**(官方 branch 按钮所在行)→ 收紧为
464
+ `data-chat-flow-kind="user"` + `_userRow|_userStack|_bubble`。
465
+ 3. `defineTool` 注册失败原先 `catch(() => {})` 静默吞掉,无法诊断 → 改为 `console.warn`。
466
+
467
+ ### 契约测试
468
+ 新增 `test/revert-contract.test.js`:把 **dsh 官方三层闸**接进测试 ——
469
+ ① 格式层 `assertV4RowAdmission` + `restoreReleasedV4Artifact`、
470
+ ② 运行时层(role 匹配 / `source.kind` 非空 / `system/message` 必须 `system-prompt`)、
471
+ ③ **UI 装配层**(`turn/end.data.reason` 必填)。
472
+ 只��第 ① 层会得到「全绿但 UI 崩」的假象(0.8.x 实机踩过:`dsh-client-ui-trajectory`
473
+ 的装配器无防护读 `reason.kind`,缺字段直接白屏)。
474
+
475
+ ## 事件形状的三条硬规则(写错就是整份日志报废)
476
+
477
+ 1. **`system/message` 的 `source.kind` 必须严格是 `"system-prompt"`** ——
478
+ Session 运行时层(`dsh-session/lib/index.js:1206`)比格式闸更严。
479
+ 2. **`turn/end.data.reason` 必填**(`types.d.ts:271-276`)——UI 装配器直接读 `reason.kind`。
480
+ 3. **空闲会话要写 notice,必须自带一个合成 turn**(`turn/start`+`step/start`+notice+`step/end`+`turn/end`,
481
+ 带 `reason:{kind:"interrupted"}`)——v4 要求 `system/message` 匹配**打开的** turn/step,
482
+ 而正常会话都以 `turn/end` 收尾(实测 340/364 空闲时是关闭的)。引擎 append-only 插不进已有 step,
483
+ 但合成一整个 turn 合法。dsh 自己的崩溃恢复(`openTurnClosers`)用同一手法。
484
+
485
+ `surfaceOp: replace` 的 notice **不会**渲染成对话行(`dsh-client-ui-chat/lib/client.js:9370`
486
+ 只渲染 `surfaceOp==="append"`),这是设计如此 —— 回撤提示由输入框上方的贴条负责。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@240xu/dsh-message-ops",
3
- "version": "0.7.0",
4
- "description": "Roll back, branch, and export any DSH conversation — from the UI or straight from the agent via a message_ops tool. Non-destructive: logs stay append-only and recoverable. 消息回滚/删除/分支/导出四合一,内置 message_ops agent 工具;非破坏语义,日志只追加可恢复。",
3
+ "version": "0.9.0",
4
+ "description": "DSH web 插件:消息级回滚 / 删除 / 恢复(补 dsh 官方没有的部分)。分支与导出用官方内置能力。",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "240xu",
package/src/client.js CHANGED
@@ -41,6 +41,8 @@ window.__ModuleLoader__.load({
41
41
  'dialog.session': '会话:',
42
42
  'dialog.runningWarn': '⚠ 会话正在运行:请先停止该会话再执行回滚/删除/分支。',
43
43
  'dialog.pick': '选择一条消息:',
44
+ 'dialog.pickFirst': '第 1 步 · 在下方选择一条消息,第 2 步在这里选择操作。',
45
+ 'dialog.pickedAs': '已选 #{seq} · {{text}}',
44
46
  'dialog.invisible': '(已遮蔽,仅日志可见)',
45
47
  'dialog.showMore': '显示更多(剩余 {n} 条)',
46
48
  'dialog.more': '…(仅显示最近 200 条,共 {n} 条)',
@@ -63,18 +65,14 @@ window.__ModuleLoader__.load({
63
65
  'done.delete': '删除完成,刷新页面后生效',
64
66
  'action.reload': '刷新页面',
65
67
  'errorPrefix': '操作失败:',
66
- 'op.restore': '恢复(重放被遮蔽的消息)',
67
- 'op.restoreDesc': '仅当选中行是回滚/删除标记时可用。这是重放而非取消遮蔽:被遮蔽的用户/助手消息会以新 seq 重新追加并带「[恢复]」前缀;不可重放的事件(如工具调用)会被跳过并计数。',
68
68
  'slot.revert': '回滚到此条',
69
69
  'slot.delete': '删除此条',
70
70
  'slot.branch': '从此分支',
71
71
  'toast.openNew': '打开新会话',
72
72
  'fork.official': '分支完成:新会话 {id}',
73
- 'fork.disk': '分支完成:新会话 {id}(列表刷新后可见)',
73
+ 'fork.unavailable': '官方分支不可用:通常是因为会话正在运行,请先停止会话后重试。分支功能由 dsh 内置的 session/fork 提供。',
74
74
  'done.restore': '恢复完成:重放 {n} 条,跳过不可重放 {s} 条',
75
75
  'busy.restore': '恢复中…',
76
- 'confirm.restore': '恢复',
77
- 'ack.restore': '我已了解:恢复将以新 seq 重放被遮蔽的消息(原日志不变)',
78
76
  'dock.title': '已回撤 {n} 条消息',
79
77
  'dock.expand': '展开回撤列表',
80
78
  'dock.collapse': '折叠回撤列表',
@@ -96,6 +94,8 @@ window.__ModuleLoader__.load({
96
94
  'dialog.session': 'Session: ',
97
95
  'dialog.runningWarn': '⚠ Session is running: stop it before revert / delete / branch.',
98
96
  'dialog.pick': 'Pick a message:',
97
+ 'dialog.pickFirst': 'Step 1 · pick a message below, then choose an operation here.',
98
+ 'dialog.pickedAs': 'Selected #${seq} · ${text}',
99
99
  'dialog.invisible': ' (shadowed, log-only)',
100
100
  'dialog.showMore': 'Show more ({n} older)',
101
101
  'dialog.more': '…(showing latest 200 of {n})',
@@ -105,14 +105,13 @@ window.__ModuleLoader__.load({
105
105
  'op.deleteDesc': 'Shadows only the picked message; everything else stays.',
106
106
  'op.branch': 'Branch into a new session from here',
107
107
  'op.branchDesc': 'Copies everything up to and including the picked message into a new session (original untouched, non-destructive).',
108
- 'op.restore': 'Restore (replay shadowed messages)',
109
- 'op.restoreDesc': 'Only when the selected row is a revert/delete marker. This is a replay, not an un-shadow: shadowed user/assistant messages are re-appended with NEW seqs and a [Restored] prefix; non-replayable events (tool calls) are skipped and counted.',
110
108
  'slot.revert': 'Revert to here',
109
+ '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.',
111
110
  'slot.delete': 'Delete this message',
112
111
  'slot.branch': 'Branch from here',
113
112
  'toast.openNew': 'Open new session',
114
113
  'fork.official': 'Branched (official fork): new session {id}',
115
- 'fork.disk': 'Branched: new session {id} (visible after list refresh)',
114
+ '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.',
116
115
  'ack.revert': 'I understand: revert shadows the picked message and everything after it',
117
116
  'ack.delete': 'I understand: this message will be shadowed (kept in the log)',
118
117
  'confirm.revert': 'Revert',
@@ -124,8 +123,6 @@ window.__ModuleLoader__.load({
124
123
  'done.branch': 'Branched: new session {id} (visible after list refresh)',
125
124
  'done.restore': 'Restored: replayed {n}, skipped non-replayable {s}',
126
125
  'busy.restore': 'Restoring…',
127
- 'confirm.restore': 'Restore',
128
- 'ack.restore': 'I understand: restore re-appends shadowed messages with new seqs (the log stays append-only)',
129
126
  'done.revert': 'Reverted; reload to apply',
130
127
  'done.delete': 'Deleted; reload to apply',
131
128
  'action.reload': 'Reload page',
@@ -323,72 +320,40 @@ window.__ModuleLoader__.load({
323
320
  setMode(m); setAcknowledged(false); setError(null)
324
321
  }, [picked, state])
325
322
 
326
- // 磁盘分支回退(0.1.x / 官方 fork 失败时):POST /api/message-ops/branch
327
- const diskBranch = (cause) => {
328
- const finish = () => {
329
- fetch('/api/message-ops/branch', {
330
- method: 'POST', headers: { 'content-type': 'application/json' },
331
- body: JSON.stringify({ sessionId: target.sessionId, upToSeq: picked }),
332
- })
333
- .then(async (res) => {
334
- let data = {}
335
- try { data = await res.json() } catch { /* keep {} */ }
336
- if (!res.ok || !data.ok) throw new Error(data.error || `HTTP ${res.status}`)
337
- setDoneMsg(t('fork.disk', { id: data.newId || '' }))
338
- setBusyMsg('')
339
- setChildId(null)
340
- setState('done')
341
- // ISessions.refresh() 是宿主现行 API;refreshList 是旧名兜底。
342
- if (__sessionsSvc) {
343
- try {
344
- const r = typeof __sessionsSvc.refresh === 'function'
345
- ? __sessionsSvc.refresh()
346
- : (typeof __sessionsSvc.refreshList === 'function' ? __sessionsSvc.refreshList() : null)
347
- if (r != null) Promise.resolve(r).catch(() => {})
348
- } catch { /* ignore */ }
349
- }
350
- })
351
- .catch((reason) => {
352
- setBusyMsg('')
353
- setState('ready')
354
- setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
355
- })
356
- }
357
- if (cause) {
358
- // 官方 fork 失败原因留痕后回退
359
- setError(t('errorPrefix') + (cause && cause.message ? cause.message : String(cause)) + ' → fallback')
360
- }
361
- finish()
362
- }
363
-
364
323
  const run = useCallback(() => {
365
324
  if (state === 'busy' || picked == null || !mode) return
366
- if (mode !== 'branch' && mode !== 'restore' && !acknowledged) return
367
- setBusyMsg(t('busy.' + (mode === 'revert' || mode === 'delete' || mode === 'restore' ? mode : 'branch')))
325
+ if (mode !== 'branch' && !acknowledged) return
326
+ setBusyMsg(t('busy.' + (mode === 'revert' || mode === 'delete' ? mode : 'branch')))
368
327
  setState('busy'); setError(null)
369
328
  if (mode === 'branch') {
370
- // 0.3.0 分支双路径:官方 sessions.fork({atSeq})(0.2.0+,子会话进宿主
371
- // 列表并可立即打开)优先;0.1.x / fork 缺席回退磁盘 applyBranch。
329
+ // 0.9.0:分支**只走官方** sessions.fork({atSeq})。
330
+ // 原先有一条「官方失败 → 磁盘 applyBranch」的回落,但那个实现语义是错的:
331
+ // 它删掉 isSeeded(官方 fork 设 true)、不写 inheritedEventCount、
332
+ // 也不调 buildForkSeed 补 step/turn closers → 产出的子会话边界可能悬空。
333
+ // 官方 fork 失败通常意味着源会话正在运行,正确做法是拒绝而非绕过引擎写盘。
372
334
  const forkPath = pickForkPath(__sessionsSvc)
373
- if (forkPath.kind === 'official') {
374
- forkPath.fork({ sessionId: target.sessionId, atSeq: picked, increaseTitle: true })
375
- .then((childId) => {
376
- setDoneMsg(t('fork.official', { id: String(childId || '') }))
377
- setBusyMsg('')
378
- setChildId(childId || null)
379
- setState('done')
380
- notifyDone(t('fork.official', { id: String(childId || '') }))
381
- })
382
- .catch((reason) => {
383
- // 官方 fork 失败(如未编目)→ 回退磁盘分支,不中断用户
384
- return diskBranch(reason)
385
- })
335
+ if (forkPath.kind !== 'official') {
336
+ setError(t('fork.unavailable'))
337
+ setBusyMsg('')
338
+ setState('error')
386
339
  return
387
340
  }
388
- diskBranch(null)
341
+ forkPath.fork({ sessionId: target.sessionId, atSeq: picked, increaseTitle: true })
342
+ .then((childId) => {
343
+ setDoneMsg(t('fork.official', { id: String(childId || '') }))
344
+ setBusyMsg('')
345
+ setChildId(childId || null)
346
+ setState('done')
347
+ notifyDone(t('fork.official', { id: String(childId || '') }))
348
+ })
349
+ .catch((reason) => {
350
+ setError(String((reason && reason.message) || reason || t('fork.unavailable')))
351
+ setBusyMsg('')
352
+ setState('error')
353
+ })
389
354
  return
390
355
  }
391
- const path = mode === 'restore' ? 'restore' : mode
356
+ const path = mode
392
357
  const body = { sessionId: target.sessionId, seq: picked }
393
358
  Promise.resolve()
394
359
  .then(() => fetch('/api/message-ops/' + path, {
@@ -403,7 +368,6 @@ window.__ModuleLoader__.load({
403
368
  // S6 修复(G-M1):不再 900ms 裸 location.reload。成功走 devkit
404
369
  // 标准 toast(无 devkit 时降级为对话框内 doneMsg),并提供手动
405
370
  // 「刷新页面」按钮。
406
- const okMsg = mode === 'restore'
407
371
  ? t('done.restore', { n: String(data.restoredCount != null ? data.restoredCount : '?'), s: String(data.skipped != null ? data.skipped : 0) })
408
372
  : t(mode === 'revert' ? 'done.revert' : 'done.delete')
409
373
  // 0.4.0 composer 回填(opencode 式):回滚用户消息 → 原文回填输入框,「编辑重发」零按钮
@@ -442,6 +406,35 @@ window.__ModuleLoader__.load({
442
406
  const pagedCount = shownBase.length - shown.length
443
407
  const pickedMsg = picked != null ? messages.find((m) => m.seq === picked) : null
444
408
 
409
+ // 0.9.0 可发现性:操作区固定在**消息列表之前**。
410
+ // 原先它在列表之后,而列表是 260px 滚动 + 分批渲染 50 条/页 ——
411
+ // 未选中消息时三个 radio 完全不在视野内,用户以为「只有列表、没有操作」。
412
+ // 未选中时给明确指引,而不是空着。
413
+ const opsPanel = pickedMsg
414
+ ? React.createElement('div', { key: 'ops', style: { margin: '8px 0 0' } },
415
+ React.createElement('div', { style: { ...metaStyle, margin: '0 0 4px' } },
416
+ t('dialog.pickedAs', { seq: String(pickedMsg.seq), text: (pickedMsg.snippet || '').slice(0, 60) })),
417
+ ['revert', 'delete', 'branch'].map((m, i) => React.createElement('div', { key: m, style: { marginTop: i === 0 ? 6 : 4 } },
418
+ React.createElement('label', { style: optStyle },
419
+ React.createElement('input', {
420
+ type: 'radio', name: 'dsh-message-ops-mode', checked: mode === m,
421
+ onChange: () => chooseMode(m), disabled: state === 'busy',
422
+ }),
423
+ t('op.' + m)),
424
+ mode === m ? React.createElement('div', { style: descStyle }, t('op.' + m + 'Desc')) : null,
425
+ )),
426
+ mode && mode !== 'branch'
427
+ ? React.createElement('label', { key: 'ack', style: optStyle },
428
+ React.createElement('input', {
429
+ type: 'checkbox', checked: acknowledged, disabled: state === 'busy',
430
+ onChange: (e) => setAcknowledged(e.target.checked),
431
+ }),
432
+ t(mode === 'revert' ? 'ack.revert' : 'ack.delete'))
433
+ : null,
434
+ )
435
+ : React.createElement('div', { key: 'opshint', style: { ...metaStyle, margin: '8px 0 0', padding: '6px 8px', borderRadius: 6, background: 'var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.1))' } },
436
+ t('dialog.pickFirst'))
437
+
445
438
  let body
446
439
  if (state === 'loading') {
447
440
  body = React.createElement('div', { key: 'load', style: statusStyle }, t('dialog.loading'))
@@ -450,6 +443,7 @@ window.__ModuleLoader__.load({
450
443
  } else {
451
444
  body = React.createElement(React.Fragment, null, [
452
445
  target.running ? React.createElement('div', { key: 'warn', style: warnStyle }, t('dialog.runningWarn')) : null,
446
+ opsPanel,
453
447
  React.createElement('div', { key: 'pick', style: metaStyle }, t('dialog.pick')),
454
448
  React.createElement('div', { key: 'list', style: listStyle },
455
449
  hiddenCount > 0
@@ -482,26 +476,7 @@ window.__ModuleLoader__.load({
482
476
  '#' + m.seq + ' ' + (m.role || '') + ' · ' + (m.snippet || '') + (m.visible === false ? t('dialog.invisible') : '')),
483
477
  )),
484
478
  ),
485
- pickedMsg ? React.createElement('div', { key: 'ops' },
486
- // restore 仅对 revert/delete 落定的 replace 标记行提供(重放语义)
487
- // 0.6.0(用户定调):恢复不进对话框——唯一入口是输入框上方贴条;
488
- ['revert', 'delete', 'branch'].map((m, i) => React.createElement('div', { key: m, style: { marginTop: i === 0 ? 8 : 4 } },
489
- React.createElement('label', { style: optStyle },
490
- React.createElement('input', {
491
- type: 'radio', name: 'dsh-message-ops-mode', checked: mode === m,
492
- onChange: () => chooseMode(m), disabled: state === 'busy',
493
- }),
494
- t('op.' + m)),
495
- mode === m ? React.createElement('div', { style: descStyle }, t('op.' + m + 'Desc')) : null,
496
- ))) : null,
497
- mode && mode !== 'branch'
498
- ? React.createElement('label', { key: 'ack', style: optStyle },
499
- React.createElement('input', {
500
- type: 'checkbox', checked: acknowledged, disabled: state === 'busy',
501
- onChange: (e) => setAcknowledged(e.target.checked),
502
- }),
503
- t(mode === 'revert' ? 'ack.revert' : mode === 'restore' ? 'ack.restore' : 'ack.delete'))
504
- : null,
479
+ opsPanel,
505
480
  ])
506
481
  }
507
482
 
@@ -591,14 +566,14 @@ window.__ModuleLoader__.load({
591
566
  }, React.createElement(BranchIcon))
592
567
  }
593
568
 
594
- // 官方图标适配:0.2.0 primitives 的 IconClock/IconTrash 与原生操作行同款;
569
+ // 官方图标适配:0.2.0 primitives 的 IconClock 与原生操作行同款;
595
570
  // require 失败(0.1.x 或裁剪环境)回退内联 SVG,槽在 0.1.x 本就不存在,仅防御。
571
+ // 0.9.0:移除 IconTrash —— 消息级删除按钮从未渲染(删除只在对话框里),
572
+ // 专家核查确认 IconTrash/TrashFallback 零渲染点,是死代码。
596
573
  var IconClock = null
597
- var IconTrash = null
598
574
  try {
599
575
  const P = require('@deepseek-ai/dsh-client-ui-primitives')
600
576
  IconClock = P && P.IconClockOutlineRegular
601
- IconTrash = P && P.IconTrashOutlineRegular
602
577
  } catch { /* fallback below */ }
603
578
  if (!IconClock) IconClock = function ClockFallback() {
604
579
  // 官方 IconClockOutlineArtwork 1:1 路径( Regular = 1px stroke)
@@ -615,14 +590,6 @@ window.__ModuleLoader__.load({
615
590
  return React.createElement('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
616
591
  React.createElement('path', { d: 'M3 6.5A3.5 3.5 0 0 1 6.5 3H7v1.5h-.5A2 2 0 0 0 4.5 6.5V7H7v3.5H3V6.5ZM9 6.5A3.5 3.5 0 0 1 12.5 3H13v1.5h-.5A2 2 0 0 0 10.5 6.5V7H13v3.5H9V6.5Z' }))
617
592
  }
618
- if (!IconTrash) IconTrash = function TrashFallback() {
619
- // 官方 IconTrashOutlineArtwork 1:1 路径
620
- return React.createElement('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
621
- React.createElement('path', { d: 'M1.28149 3.88831H14.7187' }),
622
- React.createElement('path', { d: 'M5.41602 3.88833V2.47962C5.41602 2.29282 5.52492 2.11366 5.71876 1.98157C5.9126 1.84948 6.17551 1.77527 6.44964 1.77527H9.55053C9.82466 1.77527 10.0876 1.84948 10.2814 1.98157C10.4752 2.11366 10.5841 2.29282 10.5841 2.47962V3.88833' }),
623
- React.createElement('path', { d: 'M3.29749 5.10193L4.06585 13.0192C4.10899 13.4595 4.48223 13.7942 4.92504 13.7942H11.0751C11.5179 13.7942 11.8912 13.4595 11.9343 13.0192L12.7027 5.10193' }),
624
- React.createElement('path', { d: 'M6.27637 7.51831V11.1829M9.72378 7.51831V11.1829' }))
625
- }
626
593
 
627
594
  // --- 0.3.0 assistant-actions 官方槽:每条 AI 消息旁的原生回撤按钮 ------------
628
595
  // 契约(dsh-cordis-client-runner):scope session,条目组件收 { messageId } +
@@ -772,11 +739,11 @@ window.__ModuleLoader__.load({
772
739
  // 0.4.2 引入(恢复的标记自动离开活跃列表 = opencode clear 语义)。
773
740
  // 0.5.0 脚本化编辑曾误删本函数 → dock 100% 静默失效(P0,0.5.2 恢复)。
774
741
  function activeMarkers(msgs) {
775
- const restored = new Set()
776
- for (const m of msgs || []) {
777
- if (m && typeof m.restoresSeq === 'number') restored.add(m.restoresSeq)
778
- }
779
- return (msgs || []).filter((m) => m.marker && m.sourceKind !== 'compact-checkpoint' && !restored.has(m.seq))
742
+ // 0.8.0:活跃判定收敛到服务端权威字段 restoreComplete
743
+ // (按 restoredSourceSeqs 进度算;旧 notice 无该字段 → 服务端视为整段已恢复)。
744
+ // 旧的"行内 restoresSeq 集合"客户端判定已删除——按轮步进下部分恢复的标记
745
+ // 也带 restoresSeq,旧逻辑会把它们误杀(实测:第一轮恢复后整条消失)。
746
+ return (msgs || []).filter((m) => m.marker && m.sourceKind !== 'compact-checkpoint' && m.restoreComplete !== true)
780
747
  }
781
748
 
782
749
  function RevertDock(props) {
@@ -856,11 +823,12 @@ window.__ModuleLoader__.load({
856
823
 
857
824
  const restoreRow = (row) => {
858
825
  if (restoring != null || running) return
859
- setRestoring(row.seq)
826
+ setRestoring(rowKey(row))
860
827
  Promise.resolve()
861
828
  .then(() => fetch('/api/message-ops/restore', {
862
829
  method: 'POST', headers: { 'content-type': 'application/json' },
863
- body: JSON.stringify({ sessionId, seq: row.seq }),
830
+ // 0.8.0:upToSeq 存在 → 按轮步进恢复(只重放到该 seq)
831
+ body: JSON.stringify(row.upTo != null ? { sessionId, seq: row.seq, upToSeq: row.upTo } : { sessionId, seq: row.seq }),
864
832
  }))
865
833
  .then(async (res) => {
866
834
  let data = {}
@@ -888,13 +856,26 @@ window.__ModuleLoader__.load({
888
856
  const label = t('dock.title', { n: String(shadowCount || markers.length) })
889
857
  const preview = markers[0] && markers[0].snippet ? markers[0].snippet : ''
890
858
 
891
- const rowEl = (row) => React.createElement('div', { key: row.seq, className: 'mopsRdRow' },
859
+ // 0.8.0:行 = 待恢复"轮"(对齐 opencode 按轮步进);无可重放轮的标记
860
+ // 保留旧式整段行(空区间 → 停用 notice 路径)。restoring 键区分同标记多轮。
861
+ const rowKey = (row) => (row.upTo != null ? row.seq + ':' + row.upTo : String(row.seq))
862
+ const rowEl = (row) => React.createElement('div', { key: rowKey(row), className: 'mopsRdRow' },
892
863
  React.createElement('span', { className: 'mopsRdRowText' }, '#' + row.seq + ' · ' + (row.snippet || '')),
893
864
  React.createElement('button', {
894
865
  type: 'button', className: 'mopsRdRestore', disabled: restoring != null || running,
895
866
  onClick: () => restoreRow(row),
896
- }, restoring === row.seq ? t('dock.restoring') : t('dock.restore')),
867
+ }, restoring === rowKey(row) ? t('dock.restoring') : t('dock.restore')),
897
868
  )
869
+ const dockRows = []
870
+ for (const mk of markers || []) {
871
+ if (Array.isArray(mk.pendingTurns) && mk.pendingTurns.length > 0) {
872
+ for (const t of mk.pendingTurns) {
873
+ dockRows.push({ seq: mk.seq, upTo: t.upTo, snippet: t.preview + (t.count > 1 ? ' (+' + (t.count - 1) + ')' : '') })
874
+ }
875
+ } else {
876
+ dockRows.push({ seq: mk.seq, snippet: mk.snippet })
877
+ }
878
+ }
898
879
 
899
880
  const chevron = React.createElement('button', {
900
881
  type: 'button', 'aria-label': open ? t('dock.collapse') : t('dock.expand'), 'aria-expanded': open,
@@ -916,7 +897,7 @@ window.__ModuleLoader__.load({
916
897
  React.createElement('span', { className: 'mopsRdLabel' + (open ? '' : ' mopsRdLabelCollapsed') }, label),
917
898
  open ? null : React.createElement('span', { className: 'mopsRdPreview' }, preview),
918
899
  React.createElement('span', { style: { marginLeft: 'auto', flex: 'none' } }, chevron)),
919
- open ? React.createElement('div', { className: 'mopsRdList' }, markers.map(rowEl)) : null,
900
+ open ? React.createElement('div', { className: 'mopsRdList' }, dockRows.map(rowEl)) : null,
920
901
  )
921
902
  }
922
903
 
@@ -947,12 +928,21 @@ window.__ModuleLoader__.load({
947
928
  .then((r) => (r.ok ? r.json() : null))
948
929
  .then((d) => {
949
930
  // 宿主会把 <system-reminder> / runtime context 等也记为 role=user 的行,
950
- // DOM 里并不渲染成"我的消息"块 —— 必须滤掉,否则按序配对会错位(0.7.0 根因)。
951
- const injected = (sn) => /^<system-reminder|current\s+runtime\s+context|^<system-Reminder/i.test(sn)
931
+ // DOM 里并不渲���成"我的消息"块 —— 必须滤掉,否则按序配对会错位(0.7.0 根因)。
932
+ //
933
+ // 0.9.0 两个实机 bug(浏览器实测:4 个按钮 data-mops-seq 全为 null,点击必失败):
934
+ // ① 正则跑在 norm() 之后的串上,而 norm 是 replace(/\s+/g,'') —— 删掉**全部**空白,
935
+ // `current\s+runtime\s+context` 永远匹配不上 → runtime-context 伪行漏进配对。
936
+ // 修法:injected() 改判**原始 snippet**。
937
+ // ② 过滤了 `m.visible !== false`,但宿主聊天视图**不施��**遮蔽模型,照常渲染
938
+ // 被回滚遮蔽的消息 → 配对候选与 DOM 块零交集。
939
+ // 修法:DOM 配对必须覆盖全部 user 行(含遮蔽态)。
940
+ // 注意:对话框的「可回滚目标」列表仍应过滤 visible(那是另一套语义)。
941
+ const injected = (raw) => /^<system-reminder|current\s+runtime\s+context|^<system-Reminder/i.test(String(raw || ''))
952
942
  const rows = ((d && d.messages) || [])
953
- .filter((m) => m && m.role === 'user' && m.visible !== false)
954
- .map((m) => ({ seq: m.seq, sn: norm(m.snippet) }))
955
- .filter((r) => r.sn && !injected(r.sn))
943
+ .filter((m) => m && m.role === 'user')
944
+ .map((m) => ({ seq: m.seq, sn: norm(m.snippet), raw: String(m.snippet == null ? '' : m.snippet) }))
945
+ .filter((r) => r.sn && !injected(r.raw))
956
946
  rowsCache = { sid: sid, rows: rows, at: Date.now() }
957
947
  return rows
958
948
  })
@@ -967,20 +957,49 @@ window.__ModuleLoader__.load({
967
957
  const add = (el) => { if (el && !seen.has(el)) { seen.add(el); out.push(el) } }
968
958
  const rows = Array.from(document.querySelectorAll('[class*="xzv4MW_actions"]'))
969
959
  for (const r of rows) {
970
- const block = r.closest('[data-chat-flow-kind="user"]') || r.closest('[class*="Sixlwa_userRow"]') || r.parentElement
971
- // 只取用户消息:块文本需能对应到 user 行(排除助理消息的动作行)
972
- if (block && /Sixlwa_userRow|Sixlwa_userStack|Sixlwa_bubble/.test(block.innerHTML.slice(0, 4000))) add(block)
960
+ const block = r.closest('[data-chat-flow-kind="user"]')
961
+ || r.closest('[class*="_userRow"], [class*="_userStack"], [class*="_bubble"]')
962
+ || r.parentElement
963
+ // 0.9.0:只按**稳定属性** + hash-immune 类名后缀判定,不再匹配 CSS-module
964
+ // 生成的前缀(`Sixlwa_*`)。dsh 0.2.0-rc.2 的哈希已变为 `EvIC1a_flowItem`,
965
+ // 旧前缀正则把所有块都滤掉 → anchors 为空 → 按钮拿不到 seq → 点击必失败。
966
+ //
967
+ // ⚠️ 不要把 `_flowItem` 当兜底:那是**通用**流块,官方把 branch 按钮��放在
968
+ // `data-chat-flow-kind="turn-tail"` 的 _flowItem 里(实测会把 turn-tail 当成
969
+ // 用户消息,给它挂上回滚按钮)。只用 user 属性 + user 类名后缀。
970
+ if (block) {
971
+ const flow = block.getAttribute('data-chat-flow-kind')
972
+ const isUser = flow === 'user' || /_userRow|_userStack|_bubble/.test(block.className || '')
973
+ if (isUser) add(block)
974
+ }
973
975
  }
974
976
  // 回退:属性锚点
975
977
  for (const k of document.querySelectorAll('[data-chat-flow-kind="user"]')) add(k)
976
978
  return out
977
979
  }
980
+ // 0.9.0:把配对结果反映到按钮可用性上。
981
+ // 配不上(data-mops-unmatched)→ 禁用 + 说明原因,绝不留装饰按钮。
982
+ var syncEnabled = (block, btn) => {
983
+ if (!btn) return
984
+ const ok = block.getAttribute('data-mops-seq')
985
+ if (ok) {
986
+ btn.disabled = false
987
+ btn.title = __t('slot.revert')
988
+ btn.removeAttribute('data-mops-unmatched')
989
+ } else {
990
+ btn.disabled = true
991
+ btn.title = __t('slot.revertUnmatched')
992
+ btn.setAttribute('data-mops-unmatched', '1')
993
+ }
994
+ }
978
995
  var assignSeqs = (sid, rows) => {
979
996
  if (!rows) return
980
997
  const blocks = userAnchors()
981
998
  let ri = 0
999
+ var missed = 0
982
1000
  for (const b of blocks) {
983
1001
  b.removeAttribute('data-mops-seq')
1002
+ b.removeAttribute('data-mops-unmatched')
984
1003
  const head = norm((b.innerText || '').slice(0, 240))
985
1004
  let hit = -1
986
1005
  for (let j = ri; j < rows.length; j++) {
@@ -989,8 +1008,20 @@ window.__ModuleLoader__.load({
989
1008
  if (a && b && (head.includes(a) || rows[j].sn.includes(b))) { hit = j; break }
990
1009
  }
991
1010
  if (hit >= 0) { b.setAttribute('data-mops-seq', String(rows[hit].seq)); ri = hit + 1 }
1011
+ syncEnabled(b, b.querySelector && b.querySelector('.mopsUserRevert'))
1012
+ if (false) {
1013
+ // 0.9.0:配不上就**如实标记**而不是留一个点了才报错的装饰按钮。
1014
+ // 已知局限:配对是前 40 字子串包含,模型自己写的摘要与宿主渲染文本
1015
+ // 措辞漂移(实测 playwright/playright)就会失配。
1016
+ missed++
1017
+ b.setAttribute('data-mops-unmatched', '1')
1018
+ }
992
1019
  }
1020
+ return missed
993
1021
  }
1022
+ // 按钮可用性在 assignSeqs 内部**同步**更新(与打标同一次循环)——
1023
+ // 之前放在 fetch 回调里做事后全局扫描,会与 DOM 注入/重排竞态,导致
1024
+ // 块已打上 seq 而按钮仍是禁用态(实测:block seq=[8,54],按钮 disabled=true)。
994
1025
  var ensureAssign = (sid) => fetchRows(sid).then((rows) => assignSeqs(sid, rows))
995
1026
  // 0.7.0:点击时先**同步完成**配对(打标是异步 fetch 的结果,
996
1027
  // 早先点在未打标的按钮上会静默失败 = 用户反馈的"点了没用")。