@240xu/dsh-message-ops 0.18.0 → 0.19.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.
Files changed (3) hide show
  1. package/README.md +36 -0
  2. package/package.json +1 -1
  3. package/src/client.js +69 -278
package/README.md CHANGED
@@ -1192,3 +1192,39 @@ blockAt(text, needle) // 从 needle 起按**大括号配平**切出整块
1192
1192
 
1193
1193
  **顺带修的**:`test/user-fork-edit.test.js` 等新测试从一开始就写成格式无关
1194
1194
  (大括号配平 + 真执行),不再重蹈覆辙。
1195
+
1196
+ ### 0.19.0 · 动作区收敛(审计后修订)
1197
+
1198
+ 用户:「编辑并重发为什么还存在?把情况理清楚,逐项解决」+ 启用 superpowers。
1199
+
1200
+ 审计发现决定性事实:profile 里**已安装并加载**
1201
+ `@linxin666/dsh-client-ui-message-edit@0.4.14`,它注入 `conversation.chat.turnTail`
1202
+ 槽,提供的正是「编辑并重发」:回合末尾一个文字按钮 → 原地 textarea(radius 12px,
1203
+ 全 `--dsw-alias-*` token)→ `sessions.fork({atSeq: seq-1})` →
1204
+ `reference.binding.session.prompt(editedText, "queue")`。源会话不动,Esc 取消、
1205
+ Ctrl/Cmd+Enter 重发。也就是说**本插件从 0.12.0 起造的编辑入口全是重复的劣质轮子**。
1206
+
1207
+ 设计文档:`docs/superpowers/specs/2026-11-06-message-actions-ux-design.md`(§9 修订)。
1208
+
1209
+ 四项改动:
1210
+
1211
+ 1. **收敛编辑入口**:删除行内铅笔 `mopsUserEdit` / `ensureEditBtn` / `runUserEdit`、
1212
+ 面板 `panel.edit` 一组与 `startEdit`、`client.js` 里的老 `setDraft` 路径、
1213
+ 相关 i18n 与派生状态。用户消息动作行收敛为 `时间 → 宿主Copy → | 回撤 → 分叉`。
1214
+ 编辑并重发交由已装的专门插件在 turn-tail 提供。
1215
+
1216
+ 2. **删 AI 时钟按钮**:`client.js` 里那个 `IconClock` = `runRevert`(回滚到此条),
1217
+ 与用户消息回撤重复。连 `runRevert` / `IconClock` 定义一并删除。
1218
+ AI 消息动作区**只留一个引用按钮**。
1219
+
1220
+ 3. **引用重做**:
1221
+ - 图标不再回退 `IconCopyOutlineRegular`(会与宿主自带 Copy 撞脸)
1222
+ - 优先引用**用户在消息里选中的文字**;无选中才取整条,但截断到 600 字
1223
+ 并标注 `引用自 seq N`(走 i18n `quote.sourcePrefix`)
1224
+ - 仍走宿主官方 `insertQuote`(结构化 QuoteNode → 模型可见 markdown
1225
+ blockquote + QuotePreview 可视化 + 删除按钮),不手工拼 `> `
1226
+
1227
+ 4. **dock 不再自动折叠**:删掉「markers 变化 → setOpen(false)」的 effect。
1228
+ 折叠只由用户点击改变;恢复=重放(新 seq、不回原位)的语义与文案不变。
1229
+
1230
+ 测试 313(309 pass / 4 skip),`prettier --check` 全绿。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-message-ops",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "DSH web 插件:消息级回滚 / 删除 / 恢复 / 分叉 / 编辑重发(补 dsh 官方没有的部分)。",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/client.js CHANGED
@@ -133,10 +133,6 @@ window.__ModuleLoader__.load({
133
133
  'op.branchDesc': '把此条之前的对话复制到新会话,并把此条原文放回新会话输入框(原会话不变,非破坏操作)。',
134
134
  'slot.revert': '回滚到此条',
135
135
  'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
136
- 'slot.edit': '编辑(复制原文到输入框)',
137
- 'slot.editHint': '复制此条原文到输入框;发出后新增一条消息,不修改原消息',
138
- 'slot.editDone': '原文已复制到输入框',
139
- 'slot.editNoText': '这条消息没有可复制的文本',
140
136
  'slot.fork': '从此条分叉',
141
137
  'slot.forkHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
142
138
  'slot.forkDone': '已分叉:新会话 {id}',
@@ -167,6 +163,7 @@ window.__ModuleLoader__.load({
167
163
  'slot.quote': '引用到输入框',
168
164
  'quote.done': '已引用到输入框',
169
165
  'quote.unavailable': '引用不可用(输入框不可写或无全文)',
166
+ 'quote.sourcePrefix': '引用自 seq {seq}',
170
167
  'undo.label': '回滚上一条消息',
171
168
  'undo.desc': '移除最后一条用户消息,原文回填输入框',
172
169
  'undo.done.undo': '已回滚上一条消息',
@@ -214,12 +211,6 @@ window.__ModuleLoader__.load({
214
211
  // 0.17.0(冲突 R2):行为是「复制原文到输入框」,不修改原消息。
215
212
  // 旧文案「编辑并重发」暗示会改原消息,实测会误导(发出后是新增一条,
216
213
  // 原消息仍在,界面出现两条相似消息)。opencode 也没有消息级编辑。
217
- 'panel.edit': '复制到输入框',
218
- 'panel.editHint': '把此条原文复制到输入框;发出后会新增一条消息,不会修改原消息',
219
- 'panel.editDone': '原文已复制到输入框',
220
- 'panel.editEmpty': '这条消息没有可编辑的文本',
221
- 'panel.editUnavailable': '编辑器不可写(会话可能正在运行或尚未挂载)',
222
- 'panel.editNotReady': '全文尚未就绪(列表只带 160 字摘要)——请重试或改用回滚回填',
223
214
  'panel.openNew': '打开新会话',
224
215
  'panel.revertDone': '回滚已生效',
225
216
  'panel.deleteDone': '删除已生效',
@@ -268,10 +259,6 @@ window.__ModuleLoader__.load({
268
259
  'slot.revert': 'Revert to here',
269
260
  'slot.revertUnmatched':
270
261
  '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.',
271
- 'slot.edit': 'Edit (copy text to composer)',
272
- 'slot.editHint': 'Copies this text into the composer; sending adds a new message without modifying the original',
273
- 'slot.editDone': 'Original text copied to the composer',
274
- 'slot.editNoText': 'This message has no text to copy',
275
262
  'slot.fork': 'Branch from here',
276
263
  'slot.forkHint': 'Copies the conversation above this message into a new session and puts this message back in the new composer',
277
264
  'slot.forkDone': 'Branched: new session {id}',
@@ -303,6 +290,7 @@ window.__ModuleLoader__.load({
303
290
  'slot.quote': 'Quote to composer',
304
291
  'quote.done': 'Quoted into composer',
305
292
  'quote.unavailable': 'Quote unavailable (composer locked or no full text)',
293
+ 'quote.sourcePrefix': 'Quoted from seq {seq}',
306
294
  'undo.label': 'Undo last message',
307
295
  'undo.desc': 'Remove the last user message and put its original text back into the composer',
308
296
  'undo.done.undo': 'Undid the last message',
@@ -348,12 +336,6 @@ window.__ModuleLoader__.load({
348
336
  'panel.branchHint': 'Copy the conversation above this message into a new session and put this message back in the new composer',
349
337
  'panel.branchDone': 'Forked: {id}',
350
338
  'panel.branchUserOnly': 'Fork works on user messages only (assistant messages have no text to hand back)',
351
- 'panel.edit': 'Copy to composer',
352
- 'panel.editHint': 'Copies this text into the composer; sending adds a new message and does not modify the original',
353
- 'panel.editDone': 'Original text copied to the composer',
354
- 'panel.editEmpty': 'This message has no editable text',
355
- 'panel.editUnavailable': 'Composer is not writable (session may be running or not mounted)',
356
- 'panel.editNotReady': 'Full text is not ready (the list only carries a 160-char snippet) — retry, or use revert to refill',
357
339
  'panel.openNew': 'Open new session',
358
340
  'panel.revertDone': 'Revert applied',
359
341
  'panel.deleteDone': 'Delete applied',
@@ -778,19 +760,7 @@ window.__ModuleLoader__.load({
778
760
  // `?` 分支把成功文案当错误抛出。对话框 mode 只有 revert|delete|branch,
779
761
  // branch 在上面已 return,故 done.restore 分支在此不可达,一并删掉。
780
762
  const okMsg = mode === 'revert' ? t('done.revert') : t('done.delete')
781
- // 0.4.0 composer 回填(opencode 式):回滚用户消息 → 原文回填输入框,「编辑重发」零按钮
782
- // 0.11.3:必须走统一出口,且要落盘 —— 直接 setDraft 会被随后的
783
- // openSession 用 localStorage 里的旧草稿覆盖(见 refillComposer 注释)。
784
- if (mode === 'revert' && pickedMsg && pickedMsg.role === 'user' && pickedMsg.fullText) {
785
- try {
786
- if (__inputActions && typeof __inputActions.setDraft === 'function') {
787
- __inputActions.setDraft(pickedMsg.fullText)
788
- if (typeof __inputActions.persistDraft === 'function') __inputActions.persistDraft()
789
- }
790
- } catch (e) {
791
- console.warn('[message-ops] refill failed:', e)
792
- }
793
- }
763
+ // 0.19.0:回填统一由 refillComposer 承担;老 setDraft 路径已删(见 spec §9)。
794
764
  setDoneMsg(okMsg)
795
765
  setBusyMsg('')
796
766
  setState('done')
@@ -1182,7 +1152,6 @@ window.__ModuleLoader__.load({
1182
1152
  const [detail, setDetail] = useState('')
1183
1153
  const [detailState, setDetailState] = useState('idle')
1184
1154
  // MED-5:detail 是**全文**还是 snippet 回退?只有全文才允许「编辑并重发」。
1185
- const [detailFull, setDetailFull] = useState(false)
1186
1155
  const [tab, setTab] = useState('messages')
1187
1156
  const [hits, setHits] = useState(null)
1188
1157
  const [searching, setSearching] = useState(false)
@@ -1411,63 +1380,6 @@ window.__ModuleLoader__.load({
1411
1380
  }, 0)
1412
1381
  }, [busy, confirmAction])
1413
1382
 
1414
- /**
1415
- * 0.12.0 面板内的「编辑并重发」:把该条用户消息的原文放进编辑器并关掉面板。
1416
- *
1417
- * 为什么不自己加一个输入框:编辑器已经有草稿、附件、引用、斜杠命令与提交状态机,
1418
- * 面板里再复刻一套只会分叉行为。正确做法是**交回官方编辑器**:
1419
- * 1. `setDraft(text)` 改编辑器内容
1420
- * 2. `persistDraft()` 落 localStorage —— 否则紧随的 openSession 会用旧草稿覆盖
1421
- * (0.11.3 已踩过这个坑,见 refillComposer 注释)
1422
- * 3. 关面板并聚焦编辑器,用户改完直接回车发出
1423
- * 语义上与 opencode 的「回撤 → 原文回到 composer」一致;区别是我们不预先回撤,
1424
- * 由用户决定发不发(发了才产生新的分支上下文)。
1425
- */
1426
- const startEdit = useCallback(
1427
- text => {
1428
- if (!target || busy) return
1429
- const body = typeof text === 'string' ? text : ''
1430
- if (!body) {
1431
- setError(t('panel.editEmpty'))
1432
- return
1433
- }
1434
- // ── 0.17.0(冲突 C1):与 refillComposer 统一成**同一条**回填路径 ──
1435
- //
1436
- // 旧实现走 `__inputActions.setDraft` + `persistDraft`,且
1437
- // `!__inputActions` 就直接失败返回 —— 但 refillComposer(回滚路径)
1438
- // 早在 0.14.0 就改成了「先写宿主草稿键、再尽力更新编辑器」,不依赖
1439
- // 编辑器是否已挂载。同一件事两条实现、两种可靠性,必须合并。
1440
- //
1441
- // 现在统一为:① writeSessionDraft 落盘(权威值)② 尽力 setDraft
1442
- // ③ 回读校验(写不进去就报错且不 close,保留 0.13.1 MED-4 的护栏)
1443
- const sidForDraft = target.sessionId
1444
- const persisted = writeSessionDraft(sidForDraft, body)
1445
- let editorSet = false
1446
- if (__inputActions && typeof __inputActions.setDraft === 'function') {
1447
- try {
1448
- __inputActions.setDraft(body)
1449
- editorSet = true
1450
- } catch (reason) {
1451
- console.warn('[message-ops] setDraft failed:', reason)
1452
- }
1453
- }
1454
- // 回读校验:落盘失败才是真风险(编辑器可能没挂载,那不是错误)
1455
- const stored = readSessionDraft(sidForDraft)
1456
- if (stored !== body) {
1457
- setError(t('panel.editUnavailable'))
1458
- return
1459
- }
1460
- if (!persisted && !editorSet) {
1461
- setError(t('panel.editUnavailable'))
1462
- return
1463
- }
1464
- setDone(t('panel.editDone'))
1465
- notifyDone(t('panel.editDone'))
1466
- close()
1467
- },
1468
- [target, busy, t, close],
1469
- )
1470
-
1471
1383
  useEffect(() => {
1472
1384
  if (!open) return undefined
1473
1385
  const onKey = e => {
@@ -1625,7 +1537,6 @@ window.__ModuleLoader__.load({
1625
1537
  detailReq.current += 1
1626
1538
  setPicked(null)
1627
1539
  setDetail('')
1628
- setDetailFull(false)
1629
1540
  setDetailState('idle')
1630
1541
  setConfirmAction(null)
1631
1542
  }
@@ -1635,7 +1546,6 @@ window.__ModuleLoader__.load({
1635
1546
  detailReq.current += 1
1636
1547
  setPicked(m)
1637
1548
  setDetail(m.snippet || '')
1638
- setDetailFull(false)
1639
1549
  setDetailState('ready')
1640
1550
  setConfirmAction(null)
1641
1551
  setDone('')
@@ -1712,7 +1622,6 @@ window.__ModuleLoader__.load({
1712
1622
  setConfirmAction(null)
1713
1623
  setPicked(m)
1714
1624
  setDetail(m.snippet || '')
1715
- setDetailFull(false)
1716
1625
  setDetailState('loading')
1717
1626
  setDone('')
1718
1627
  const req = ++detailReq.current
@@ -1728,13 +1637,11 @@ window.__ModuleLoader__.load({
1728
1637
  if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
1729
1638
  const full = typeof data.text === 'string' && data.text !== '' ? data.text : null
1730
1639
  setDetail(full ?? (m.snippet || ''))
1731
- setDetailFull(full !== null)
1732
1640
  setDetailState('ready')
1733
1641
  })
1734
1642
  .catch(() => {
1735
1643
  if (req !== detailReq.current) return
1736
- setDetail(m.snippet || '')
1737
- setDetailFull(false) // 拉全文失败 → 只有截断的 snippet,不许冒充原文
1644
+ setDetail(m.snippet || '') // 拉全文失败 → 只有截断的 snippet,不许冒充原文
1738
1645
  setDetailState('ready')
1739
1646
  })
1740
1647
  },
@@ -1932,11 +1839,9 @@ window.__ModuleLoader__.load({
1932
1839
  // 「这句话说错了,拿回去重说」,AI 消息没有可回填的原文)。
1933
1840
  const pickedIsUser = !!pickedLive && pickedLive.role === 'user'
1934
1841
  const canFork = !busy && !target.running && pickedIsUser && !pickedLive.shadowed && pickedLive.seq > 0
1935
- const canEdit = pickedIsUser && !pickedLive.shadowed && state === 'ready' && !busy
1936
1842
  // MED-5:只有**真拉到全文**才允许编辑。detail 在 /text 失败时会退化成
1937
1843
  // snippet,而 snippet 被服务端硬截断到 160 字(session-file.js:331)——
1938
1844
  // 拿它冒充原文会让用户改完发出时静默丢掉后半段。
1939
- const editTextReady = detailFull === true && typeof detail === 'string' && detail !== ''
1940
1845
  const deleteBlockedReason = target.running
1941
1846
  ? t('panel.running')
1942
1847
  : state !== 'ready'
@@ -2248,23 +2153,6 @@ window.__ModuleLoader__.load({
2248
2153
  },
2249
2154
  t('panel.delete'),
2250
2155
  ),
2251
- // 0.12.0:编辑只对用户消息可用 —— 直接把原文交回编辑器。
2252
- // 无二次确认:它不改日志,只改草稿。
2253
- React.createElement(
2254
- 'button',
2255
- {
2256
- type: 'button',
2257
- className: 'mopsAction',
2258
- disabled: !canEdit || !editTextReady,
2259
- title: !pickedIsUser
2260
- ? t('panel.branchUserOnly')
2261
- : !editTextReady
2262
- ? t('panel.editNotReady')
2263
- : t('panel.editHint'),
2264
- onClick: () => startEdit(detail),
2265
- },
2266
- t('panel.edit'),
2267
- ),
2268
2156
  // 分叉同样只对用户消息可用(AI 消息没有可回填的原文),
2269
2157
  // 语义 = opencode 的 before:新会话不含此条,原文进新会话输入框。
2270
2158
  React.createElement(
@@ -2719,33 +2607,13 @@ window.__ModuleLoader__.load({
2719
2607
  )
2720
2608
  }
2721
2609
 
2722
- // 官方图标适配:0.2.0 primitives 的 IconClock 与原生操作行同款;
2723
- // require 失败(0.1.x 或裁剪环境)回退内联 SVG,槽在 0.1.x 本就不存在,仅防御。
2724
- // 0.9.0:移除 IconTrash —— 消息级删除按钮从未渲染(删除只在对话框里),
2725
- // 专家核查确认 IconTrash/TrashFallback 零渲染点,是死代码。
2726
- var IconClock = null
2727
- try {
2728
- const P = require('@deepseek-ai/dsh-client-ui-primitives')
2729
- IconClock = P && P.IconClockOutlineRegular
2730
- } catch {
2731
- /* fallback below */
2732
- }
2733
- if (!IconClock)
2734
- IconClock = function ClockFallback() {
2735
- // 官方 IconClockOutlineArtwork 1:1 路径( Regular = 1px stroke)
2736
- return React.createElement(
2737
- 'svg',
2738
- { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
2739
- React.createElement('path', {
2740
- d: 'M8 14C11.3137 14 14 11.3137 14 8C14 4.68629 11.3137 2 8 2C4.68629 2 2 4.68629 2 8C2 11.3137 4.68629 14 8 14Z',
2741
- }),
2742
- React.createElement('path', { d: 'M8 4.31V8.46L11 10.08' }),
2743
- )
2744
- }
2745
2610
  var IconQuote = null
2746
2611
  try {
2747
2612
  const P2 = require('@deepseek-ai/dsh-client-ui-primitives')
2748
- IconQuote = P2 && (P2.IconChatOutlineRegular || P2.IconCopyOutlineRegular)
2613
+ // 0.19.0:不再回退到 IconCopyOutlineRegular —— 宿主在 AI 消息下方本来就
2614
+ // 有一个 Copy 按钮,用复制图标做「引用」会变成两个一模一样的复制按钮。
2615
+ // 优先官方 chat 类图标;拿不到就用下面的引号几何(明确的引用语义)。
2616
+ IconQuote = P2 && P2.IconChatOutlineRegular
2749
2617
  } catch {
2750
2618
  /* fallback below */
2751
2619
  }
@@ -2875,40 +2743,6 @@ window.__ModuleLoader__.load({
2875
2743
  return false
2876
2744
  }
2877
2745
 
2878
- const runRevert = () => {
2879
- if (busy || seq == null || running) return
2880
- setBusy('revert')
2881
- // 0.5.2(P2):Promise.resolve 包裹——fetch/stringify 同步抛出也转为
2882
- // rejection 落进 finally,busy 永不卡死
2883
- Promise.resolve()
2884
- .then(() =>
2885
- fetch('/api/message-ops/revert', {
2886
- method: 'POST',
2887
- headers: { 'content-type': 'application/json' },
2888
- body: JSON.stringify({ sessionId, seq }),
2889
- }),
2890
- )
2891
- .then(async res => {
2892
- let data = {}
2893
- try {
2894
- data = await res.json()
2895
- } catch {
2896
- /* keep {} */
2897
- }
2898
- if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
2899
- notifyDone(t('done.revert'))
2900
- // 0.9.6:回填被删掉的那句用户原文(边界是 AI 消息时取它之前那条用户消息)。
2901
- // 此前这个入口完全不回填 —— 表现就是「回滚成功但消息框空着」。
2902
- refillComposer(sessionId, seq)
2903
- revealSession()
2904
- emitChanged()
2905
- })
2906
- .catch(reason => {
2907
- notifyDone(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
2908
- })
2909
- .finally(() => setBusy(null))
2910
- }
2911
-
2912
2746
  // ── 0.18.0:引用改用官方 insertQuote(结构化 QuoteNode)──────────────────
2913
2747
  //
2914
2748
  // 旧实现(0.5.0)用 `captureInsertion` + `insertText` 手工拼 `> ` markdown:
@@ -2928,6 +2762,36 @@ window.__ModuleLoader__.load({
2928
2762
  // `$replaceDetectSpanWithNodes([$createQuoteNode(text, labels), Go(" ")])`
2929
2763
  // 即:在当前光标处插入一个**真正的 QuoteNode**(带 remove 标签、独立 undo),
2930
2764
  // 并自动补一个空格分隔。这才是"规范"的引用。
2765
+ /**
2766
+ * 0.19.0 引用:只引用「选中的一小段」,不再把整条 AI 消息塞进 composer。
2767
+ *
2768
+ * 用户原话:「这个引用为什么是直接把这个消息直接给我填进输入框,这什么情况?」
2769
+ * 根因:旧实现把 fullText / /text 接口返回的**整条全文**传给 insertQuote,
2770
+ * 于是 composer 里冒出一个几千字的巨大引用块,看起来就像"把消息整个塞进去"。
2771
+ *
2772
+ * 宿主官方 insertQuote 的语义是「引用一段选中文字」(QuoteNode +
2773
+ * QuotePreview 可视化 + 模型可见的 markdown blockquote),本就该用小段。
2774
+ *
2775
+ * 文本来源优先级:
2776
+ * 1. 用户在该消息内选中的文字(window.getSelection,限定消息节点内)
2777
+ * 2. 无选中 → 取整条但截断到 QUOTE_MAX_CHARS,并标注来源(seq / 角色)
2778
+ */
2779
+ const QUOTE_MAX_CHARS = 600
2780
+ const selectionInMessage = () => {
2781
+ try {
2782
+ const sel = window.getSelection && window.getSelection()
2783
+ if (!sel || sel.isCollapsed || sel.rangeCount === 0) return null
2784
+ const text = String(sel.toString() || '').replace(/\s+$/g, '')
2785
+ if (!text || text.length > QUOTE_MAX_CHARS * 2) return null
2786
+ // 只认落在消息节点内的选区,避免把别处选的文字当成这条消息的引用
2787
+ const anchor = sel.anchorNode && (sel.anchorNode.nodeType === 1 ? sel.anchorNode : sel.anchorNode.parentElement)
2788
+ const root = anchor && anchor.closest && anchor.closest('[data-chat-node-key],[data-chat-flow-kind]')
2789
+ if (!root) return null
2790
+ return text.length > QUOTE_MAX_CHARS ? text.slice(0, QUOTE_MAX_CHARS) + '…' : text
2791
+ } catch {
2792
+ return null
2793
+ }
2794
+ }
2931
2795
  const runQuote = () => {
2932
2796
  const finish = ok => notifyDone(ok ? t('quote.done') : t('quote.unavailable'), ok ? 'ok' : 'warn')
2933
2797
  try {
@@ -2940,7 +2804,6 @@ window.__ModuleLoader__.load({
2940
2804
  finish(false)
2941
2805
  return
2942
2806
  }
2943
- // insertQuote 的返回值是 boolean(是否真的插入了)
2944
2807
  let ok = false
2945
2808
  try {
2946
2809
  ok = inputActions.insertQuote(text.replace(/\r\n?/g, '\n')) !== false
@@ -2950,14 +2813,24 @@ window.__ModuleLoader__.load({
2950
2813
  }
2951
2814
  finish(ok)
2952
2815
  }
2953
- // assistant 消息 fullText 恒 null(列表不携带)→ 按 seq 取单条全文
2816
+ // ① 选中片段优先(结构化的小段引用,模型可见)
2817
+ const selected = selectionInMessage()
2818
+ if (selected != null) {
2819
+ put(selected)
2820
+ return
2821
+ }
2822
+ // ② 无选中:取整条但截断 + 标注来源,不再静默塞全文
2823
+ const withSource = full => {
2824
+ const clipped = full.length > QUOTE_MAX_CHARS ? full.slice(0, QUOTE_MAX_CHARS) + '…' : full
2825
+ return t('quote.sourcePrefix', { seq: String(seq) }) + '\n' + clipped
2826
+ }
2954
2827
  if (fullText != null && fullText !== '') {
2955
- put(fullText)
2828
+ put(withSource(fullText))
2956
2829
  return
2957
2830
  }
2958
2831
  fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sessionId) + '&seq=' + encodeURIComponent(seq))
2959
2832
  .then(r => (r.ok ? r.json() : null))
2960
- .then(d => put(d && d.ok && typeof d.text === 'string' ? d.text : null))
2833
+ .then(d => put(d && d.ok && typeof d.text === 'string' ? withSource(d.text) : null))
2961
2834
  .catch(() => put(null))
2962
2835
  } catch (e) {
2963
2836
  notifyDone(t('errorPrefix') + (e && e.message ? e.message : String(e)), 'error')
@@ -2991,12 +2864,9 @@ window.__ModuleLoader__.load({
2991
2864
  },
2992
2865
  icon,
2993
2866
  )
2994
- return React.createElement(
2995
- 'span',
2996
- { style: { display: 'inline-flex', gap: 0 } },
2997
- act(React.createElement(IconClock, { size: 16 }), t('slot.revert'), 'revert', runRevert, running),
2998
- act(React.createElement(IconQuote, { size: 16 }), t('slot.quote'), 'quote', runQuote, false),
2999
- )
2867
+ // 0.19.0(spec §9):AI 消息动作区只留「引用」。
2868
+ // 原时钟图标 = runRevert(回滚到此条),与用户消息回撤重复,用户要求删除。
2869
+ return act(React.createElement(IconQuote, { size: 16 }), t('slot.quote'), 'quote', runQuote, false)
3000
2870
  }
3001
2871
 
3002
2872
  // 0.4.2 引入(恢复的标记自动离开活跃列表 = opencode clear 语义)。
@@ -3213,10 +3083,11 @@ window.__ModuleLoader__.load({
3213
3083
  if (step.reload) loadRef.current()
3214
3084
  }, [sessionId, activityAt])
3215
3085
 
3216
- // items 变化自动折叠(opencode createEffect 同款;必须在早退之前——Hooks 规则)
3217
- useEffect(() => {
3218
- setOpen(false)
3219
- }, [markers && markers.length, markers && markers[0] && markers[0].seq])
3086
+ // 0.19.0(spec §3.4):去掉「markers 变化就自动折叠」。
3087
+ // 用户反馈:点开 dock 后一操作就被收回去,很烦。折叠状态只由用户
3088
+ // 点击 header / chevron 改变;恢复=重放的语义与文案保持不变。
3089
+ // 注意:不能整个删掉这个 useEffect 的「早退之前」位置约束 —— 这里只是
3090
+ // 不再写 setOpen(false),Hooks 顺序不受影响(下方无其它 Hook 依赖它)。
3220
3091
  if (!markers || !markers.length) return null
3221
3092
 
3222
3093
  const restoreRow = row => {
@@ -3690,11 +3561,7 @@ window.__ModuleLoader__.load({
3690
3561
  var syncEnabled = (block, btn) => {
3691
3562
  if (!btn) return
3692
3563
  // 0.18.0:三种按钮各有自己的提示文案(新增编辑按钮后不能都写 revert)
3693
- const hintKey = btn.classList.contains('mopsUserFork')
3694
- ? 'slot.forkHint'
3695
- : btn.classList.contains('mopsUserEdit')
3696
- ? 'slot.editHint'
3697
- : 'slot.revert'
3564
+ const hintKey = btn.classList.contains('mopsUserFork') ? 'slot.forkHint' : 'slot.revert'
3698
3565
  const ok = block.getAttribute('data-mops-seq')
3699
3566
  if (ok) {
3700
3567
  btn.disabled = false
@@ -3709,7 +3576,7 @@ window.__ModuleLoader__.load({
3709
3576
  /** 块内全部插件按钮一起同步(回滚 / 分叉同一动作行)。 */
3710
3577
  var syncBlockButtons = block => {
3711
3578
  if (!block || !block.querySelectorAll) return
3712
- for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserEdit, .mopsUserFork')) syncEnabled(block, b)
3579
+ for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserFork')) syncEnabled(block, b)
3713
3580
  }
3714
3581
  var assignSeqs = (sid, cache, anchors) => {
3715
3582
  const idx = cache && cache.idx
@@ -3920,81 +3787,6 @@ window.__ModuleLoader__.load({
3920
3787
  return btn
3921
3788
  }
3922
3789
 
3923
- /**
3924
- * 0.18.0 编辑按钮:与回滚**同一动作行**,铅笔图标。
3925
- *
3926
- * 语义 = 把该条原文放回输入框(不遮蔽后续、不修改原消息)。发出后会新增
3927
- * 一条消息 —— 与面板里的「复制到输入框」是同一件事,两条入口共用
3928
- * `refillToComposer` 实现,避免又出现"同语义两套实现"。
3929
- *
3930
- * 图标取官方 `edit-outline`(宿主 icon sprite 里的 dsw-icon-edit-outline-regular)。
3931
- */
3932
- var ensureEditBtn = block => {
3933
- let host = block.querySelector('[class*="xzv4MW_actions"]')
3934
- if (!host) {
3935
- host = document.createElement('div')
3936
- host.className = 'mopsUserActionsRow'
3937
- block.appendChild(host)
3938
- }
3939
- const existing = host.querySelector('.mopsUserEdit')
3940
- if (existing) return existing
3941
- const btn = document.createElement('button')
3942
- btn.type = 'button'
3943
- btn.className = 'mopsUserEdit'
3944
- btn.title = __t('slot.edit')
3945
- btn.setAttribute('aria-label', __t('slot.edit'))
3946
- // 铅笔:官方 edit-outline 的几何(16 viewBox)
3947
- btn.innerHTML =
3948
- '<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="none">' +
3949
- '<path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M11.9 1.4a1.6 1.6 0 0 1 2.3 0l.4.4a1.6 1.6 0 0 1 0 2.3l-1 1-2.7-2.7 1-1ZM9.8 3.5l2.7 2.7-6.9 6.9a1 1 0 0 1-.4.2l-2.6.7a.5.5 0 0 1-.6-.6l.7-2.6a1 1 0 0 1 .2-.4l6.9-6.9Z"/>' +
3950
- '</svg>'
3951
- btn.addEventListener('click', e => {
3952
- e.preventDefault()
3953
- e.stopPropagation()
3954
- if (btn.disabled) return
3955
- runUserEdit(btn, block)
3956
- })
3957
- host.appendChild(btn)
3958
- syncEnabled(block, btn)
3959
- return btn
3960
- }
3961
-
3962
- /**
3963
- * 0.18.0 行内编辑:把该条原文放回输入框。
3964
- *
3965
- * 直接复用 `refillComposer`(回滚路径用的同一实现)——
3966
- * 0.17.0 刚把"同语义两套实现"问题清理掉,绝不能在这里再引入一条。
3967
- */
3968
- var runUserEdit = (btn, block) => {
3969
- const sid = __currentSessionId
3970
- if (!sid) return
3971
- const seq = Number(block.getAttribute('data-mops-seq'))
3972
- if (!Number.isFinite(seq)) {
3973
- notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
3974
- return
3975
- }
3976
- btn.disabled = true
3977
- Promise.resolve()
3978
- .then(() => ensureAssign(sid))
3979
- .then(() => fetchRows(sid))
3980
- .then(cache => {
3981
- const rows = cache && cache.rows
3982
- const row = rows && rows.find(r => r.seq === seq)
3983
- if (!row) {
3984
- notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
3985
- return
3986
- }
3987
- const ok = refillComposer(sid, seq)
3988
- notifyDone(ok ? __t('slot.editDone') : __t('slot.editNoText'), ok ? 'ok' : 'warn')
3989
- })
3990
- .catch(reason => {
3991
- notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
3992
- })
3993
- .finally(() => {
3994
- btn.disabled = false
3995
- })
3996
- }
3997
-
3998
3790
  /** 0.12.0 分叉按钮:与回滚按钮**同一动作行**(opencode 把 fork 放在 copy/undo 同组)。 */
3999
3791
  var ensureForkBtn = block => {
4000
3792
  let host = block.querySelector('[class*="xzv4MW_actions"]')
@@ -4025,10 +3817,9 @@ window.__ModuleLoader__.load({
4025
3817
  }
4026
3818
  // 两个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),分叉在后(非破坏)。
4027
3819
  var ensureUserActions = block => {
3820
+ // 0.19.0(spec §9):编辑并重发由已装的 message-edit 插件在 turnTail 提供,
3821
+ // 本插件动作行收敛为:回撤 → 分叉。
4028
3822
  ensureBtn(block)
4029
- // 0.18.0:编辑按钮与回滚**同一动作行**(用户要求:和回撤放同一个地方)。
4030
- // 顺序 = 回滚 → 编辑 → 分叉,破坏性从左到右递减。
4031
- ensureEditBtn(block)
4032
3823
  ensureForkBtn(block)
4033
3824
  }
4034
3825
  // 0.9.7(P0-2 读合并):把 150/700/1600ms 三档并成**一次**真网络请求,
@@ -4218,11 +4009,11 @@ window.__ModuleLoader__.load({
4218
4009
  // (宿主 .xzv4MW_actions 已定 height:28px,改小会撑裂行高)。
4219
4010
  // · 无淡入动画(opencode 源码注释明写 "Hover actions show and hide
4220
4011
  // at once, without a fade")—— 显隐完全交给宿主 [data-actions-reveal]。
4221
- '.mopsUserRevert,.mopsUserEdit,.mopsUserFork{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:4px;background:transparent;color:var(--dsw-alias-label-tertiary,#808080);cursor:pointer;padding:0;flex:none}',
4222
- '.mopsUserRevert svg,.mopsUserEdit svg,.mopsUserFork svg{width:14px;height:14px;display:block}',
4223
- '.mopsUserRevert:hover,.mopsUserEdit:hover,.mopsUserFork:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-secondary,#6b6b70)}',
4224
- '.mopsUserRevert:disabled,.mopsUserEdit:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default;background:transparent}',
4225
- '.mopsUserRevert:focus-visible,.mopsUserEdit:focus-visible,.mopsUserFork:focus-visible{outline:2px solid var(--dsw-alias-border-l2,#b8b8b8);outline-offset:1px}',
4012
+ '.mopsUserRevert,.mopsUserFork{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:4px;background:transparent;color:var(--dsw-alias-label-tertiary,#808080);cursor:pointer;padding:0;flex:none}',
4013
+ '.mopsUserRevert svg,.mopsUserFork svg{width:14px;height:14px;display:block}',
4014
+ '.mopsUserRevert:hover,.mopsUserFork:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-secondary,#6b6b70)}',
4015
+ '.mopsUserRevert:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default;background:transparent}',
4016
+ '.mopsUserRevert:focus-visible,.mopsUserFork:focus-visible{outline:2px solid var(--dsw-alias-border-l2,#b8b8b8);outline-offset:1px}',
4226
4017
  // 0.18.0:用户反馈「点时间图标也会回撤」——根因不是绑定错误,而是
4227
4018
  // 我们的按钮被 appendChild 到宿主 .actions 行末尾,而该行在
4228
4019
  // data-clock="start"(用户消息)时第一个子元素就是**时间文本**:
@@ -4488,7 +4279,7 @@ window.__ModuleLoader__.load({
4488
4279
  // **紧接着** `openSession(sid)` 重建整个会话视图。重建会卸载并重挂
4489
4280
  // 编辑器,新挂载走 `readConversationDraft(sid)` 从 localStorage 初始化 ——
4490
4281
  // 也就是说「回填」实际取决于 persistDraft 是否成功落盘,而再叠上
4491
- // `bindDraftPersistence` 的时序(见 startEdit 处 MED-4 注释),失败时
4282
+ // `bindDraftPersistence` 的时序(见 0.13.1 MED-4),失败时
4492
4283
  // 用户看到「已回滚」却拿不到原文。
4493
4284
  //
4494
4285
  // 唯一无竞态的路径:**直接写宿主的草稿存储键**(writeSessionDraft),