@240xu/dsh-message-ops 0.16.0 → 0.17.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 +46 -0
  2. package/package.json +1 -1
  3. package/src/client.js +59 -29
package/README.md CHANGED
@@ -891,6 +891,52 @@ min fence=10 → seq>=10 全藏 → 4792/4793 全被隐藏 → 正文几乎空
891
891
  | `src/index.js:336-340` `revertFences` 塌缩复盘 | 「0.9.4 · 修「正文几乎空白」」 |
892
892
  | `src/ops-core.js:551-557` 0.5.7 磁盘路径复盘 | 「0.5.7 · 第四层根因:store-miss 会话的磁盘追加路径」 |
893
893
 
894
+ ### 0.17.0 · 动作入口冲突清理
895
+
896
+ 用户问:「那个编辑并重发是你的吗?你看看有多少是功能冲突的」
897
+
898
+ **是插件自造的**(`git log -S "panel.editDone"` 只有 `d699ddb` 一次提交),
899
+ opencode 没有消息级编辑。查下来三个真冲突,全部已修:
900
+
901
+ #### C1 · 回填有两条实现,可靠性不同
902
+
903
+ | 路径 | 旧实现 | 问题 |
904
+ |---|---|---|
905
+ | `refillComposer`(回滚) | `writeSessionDraft`(0.14.0 起) | 不依赖编辑器,可靠 |
906
+ | `startEdit`(面板编辑) | `__inputActions.setDraft` + `persistDraft`,且 `!__inputActions` **直接失败** | 依赖 `bindDraftPersistence` 绑定的 writer,视图未挂载时空转 |
907
+
908
+ 同一语义两条实现、两种可靠性 → **合并**为同一条路径:
909
+ 先 `writeSessionDraft` 落盘(权威值)→ 尽力 `setDraft`(立刻可见)→ 回读校验。
910
+
911
+ #### R2 · 「编辑并重发」文案误导
912
+
913
+ `startEdit` **完全不调服务端**(函数体内无 fetch)。它只把原文放回输入框,
914
+ **不遮蔽原消息**。用户改完发出后:
915
+
916
+ - 日志 **append 一条新 user/message**
917
+ - 原消息 **仍然 visible**,不被遮蔽
918
+ - 界面上出现**两条相似消息**,用户以为「改了」,实际「加了一条」
919
+
920
+ 而旧文案 `编辑并重发` / `Edit and resend` 暗示的是「修改原消息」。
921
+ 改为 **`复制到输入框`** / `Copy to composer`,提示补上
922
+ 「发出后会新增一条消息,不会修改原消息」。
923
+
924
+ #### C2 · 防 409 护栏只有一条路径有
925
+
926
+ `/undo`(`runUndo`)在回滚成功后立刻把 `rowsCache` 里 `>= seq` 的行标成
927
+ `shadowed = true`,注释写明是为了防止刷新窗口内重复点击拿到已遮蔽的 seq。
928
+ **按钮路径 `runUserRevert` 漏了这段** —— 同一语义两套实现,其中一套少了护栏。
929
+
930
+ 抽成共享函数 `markRowsShadowedFrom(boundarySeq)`,两条路径都调。
931
+
932
+ #### 没动的重复入口(故意的)
933
+
934
+ `/undo` vs 按钮、`/redo` vs dock 恢复、`message_ops` tool vs UI——
935
+ 这些是不同上下文/不同调用方,共用 `ops-core.js` 同一个核,不算冲突。
936
+ 详见 `design-demos/conflict-audit-lead.md`。
937
+
938
+ 新增 `test/action-conflict.test.js`(6 条)。测试 298(294 pass / 4 skip)。
939
+
894
940
  ### 0.16.0 · 视觉对齐 opencode(有依据、有取舍)
895
941
 
896
942
  **方法**:不是照着印象改,而是拉了 `sst/opencode` 源码
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-message-ops",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "DSH web 插件:消息级回滚 / 删除 / 恢复 / 分叉 / 编辑重发(补 dsh 官方没有的部分)。",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/client.js CHANGED
@@ -207,9 +207,12 @@ window.__ModuleLoader__.load({
207
207
  'panel.branchHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
208
208
  'panel.branchDone': '已分叉:新会话 {id}',
209
209
  'panel.branchUserOnly': '分叉只对用户消息可用(AI 消息没有可回填的原文)',
210
- 'panel.edit': '编辑并重发',
211
- 'panel.editHint': '把此条原文放回输入框,改完直接发送',
212
- 'panel.editDone': '原文已放回输入框',
210
+ // 0.17.0(冲突 R2):行为是「复制原文到输入框」,不修改原消息。
211
+ // 旧文案「编辑并重发」暗示会改原消息,实测会误导(发出后是新增一条,
212
+ // 原消息仍在,界面出现两条相似消息)。opencode 也没有消息级编辑。
213
+ 'panel.edit': '复制到输入框',
214
+ 'panel.editHint': '把此条原文复制到输入框;发出后会新增一条消息,不会修改原消息',
215
+ 'panel.editDone': '原文已复制到输入框',
213
216
  'panel.editEmpty': '这条消息没有可编辑的文本',
214
217
  'panel.editUnavailable': '编辑器不可写(会话可能正在运行或尚未挂载)',
215
218
  'panel.editNotReady': '全文尚未就绪(列表只带 160 字摘要)——请重试或改用回滚回填',
@@ -337,9 +340,9 @@ window.__ModuleLoader__.load({
337
340
  'panel.branchHint': 'Copy the conversation above this message into a new session and put this message back in the new composer',
338
341
  'panel.branchDone': 'Forked: {id}',
339
342
  'panel.branchUserOnly': 'Fork works on user messages only (assistant messages have no text to hand back)',
340
- 'panel.edit': 'Edit and resend',
341
- 'panel.editHint': 'Put this message back in the composer to change and send',
342
- 'panel.editDone': 'Original text is back in the composer',
343
+ 'panel.edit': 'Copy to composer',
344
+ 'panel.editHint': 'Copies this text into the composer; sending adds a new message and does not modify the original',
345
+ 'panel.editDone': 'Original text copied to the composer',
343
346
  'panel.editEmpty': 'This message has no editable text',
344
347
  'panel.editUnavailable': 'Composer is not writable (session may be running or not mounted)',
345
348
  'panel.editNotReady': 'Full text is not ready (the list only carries a 160-char snippet) — retry, or use revert to refill',
@@ -1376,25 +1379,33 @@ window.__ModuleLoader__.load({
1376
1379
  setError(t('panel.editEmpty'))
1377
1380
  return
1378
1381
  }
1379
- if (!__inputActions || typeof __inputActions.setDraft !== 'function') {
1380
- setError(t('panel.editUnavailable'))
1381
- return
1382
+ // ── 0.17.0(冲突 C1):与 refillComposer 统一成**同一条**回填路径 ──
1383
+ //
1384
+ // 旧实现走 `__inputActions.setDraft` + `persistDraft`,且
1385
+ // `!__inputActions` 就直接失败返回 —— 但 refillComposer(回滚路径)
1386
+ // 早在 0.14.0 就改成了「先写宿主草稿键、再尽力更新编辑器」,不依赖
1387
+ // 编辑器是否已挂载。同一件事两条实现、两种可靠性,必须合并。
1388
+ //
1389
+ // 现在统一为:① writeSessionDraft 落盘(权威值)② 尽力 setDraft
1390
+ // ③ 回读校验(写不进去就报错且不 close,保留 0.13.1 MED-4 的护栏)
1391
+ const sidForDraft = target.sessionId
1392
+ const persisted = writeSessionDraft(sidForDraft, body)
1393
+ let editorSet = false
1394
+ if (__inputActions && typeof __inputActions.setDraft === 'function') {
1395
+ try {
1396
+ __inputActions.setDraft(body)
1397
+ editorSet = true
1398
+ } catch (reason) {
1399
+ console.warn('[message-ops] setDraft failed:', reason)
1400
+ }
1382
1401
  }
1383
- try {
1384
- __inputActions.setDraft(body)
1385
- if (typeof __inputActions.persistDraft === 'function') __inputActions.persistDraft()
1386
- } catch (reason) {
1387
- setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
1402
+ // 回读校验:落盘失败才是真风险(编辑器可能没挂载,那不是错误)
1403
+ const stored = readSessionDraft(sidForDraft)
1404
+ if (stored !== body) {
1405
+ setError(t('panel.editUnavailable'))
1388
1406
  return
1389
1407
  }
1390
- // MED-4:`persistDraft` 存在 ≠ 真的落盘。宿主的 writer 由
1391
- // `bindDraftPersistence` 在视图挂载时绑定;blank/hero 态或视图未挂载时
1392
- // 该函数在但空转。于是「setDraft 改的是内存编辑器、随后 close() 关面板、
1393
- // 宿主重挂会话时从 localStorage 读回旧草稿」→ 用户看到成功却什么都没了。
1394
- // 判据不能靠函数存在,只能**回读**:写不进存储就当失败,不 close。
1395
- const sidForDraft = target.sessionId
1396
- const stored = readSessionDraft(sidForDraft)
1397
- if (stored != null && stored !== body) {
1408
+ if (!persisted && !editorSet) {
1398
1409
  setError(t('panel.editUnavailable'))
1399
1410
  return
1400
1411
  }
@@ -3721,6 +3732,9 @@ window.__ModuleLoader__.load({
3721
3732
  }
3722
3733
  if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
3723
3734
  notifyDone(__t('done.revert'))
3735
+ // 0.17.0(冲突 C2):按钮路径原先漏了「立刻标遮蔽」,
3736
+ // 导致刷新窗口内重复点击会拿已遮蔽的 seq 去 POST → 409。
3737
+ markRowsShadowedFrom(row.seq)
3724
3738
  // 0.9.6:统一回填出口 —— 这个入口原先也不回填
3725
3739
  refillComposer(sid, row.seq)
3726
3740
  emitChanged()
@@ -4273,6 +4287,28 @@ window.__ModuleLoader__.load({
4273
4287
  * - AI 时钟按钮 → boundary 是 AI 消息 seq → 取到它之前那条用户消息 ✓
4274
4288
  * 会话不匹配时直接放弃(不跨会话写,避免串台)。
4275
4289
  */
4290
+ /**
4291
+ * 回滚成功后立刻把本地行缓存标成已遮蔽(0.17.0 · 冲突 C2)。
4292
+ *
4293
+ * 为什么必须做:回滚成功后到视图刷新完成之间有一个窗口期,
4294
+ * `rowsCache.rows[*].shadowed` 还是旧值。此时用户再点同一行按钮
4295
+ * (或另一行更靠后的),`runUserRevert` 会拿**已被遮蔽的 seq** 去
4296
+ * POST /revert → 服务端 409 `start seq N not found in surface`。
4297
+ *
4298
+ * 原先只有 `/undo` 路径(`runUndo`)做了这件事,按钮路径漏了 ——
4299
+ * 同一语义两套实现、其中一套少了护栏。这里抽成共享函数,两条路径都调。
4300
+ *
4301
+ * @param boundarySeq - 本次回滚的目标 seq;>= 它的都已不可再回滚
4302
+ */
4303
+ var markRowsShadowedFrom = boundarySeq => {
4304
+ const cache = __peekRowsCache ? __peekRowsCache() : null
4305
+ if (!cache || !Array.isArray(cache.rows)) return
4306
+ for (const r of cache.rows) {
4307
+ if (r && typeof r.seq === 'number' && r.seq >= boundarySeq) r.shadowed = true
4308
+ }
4309
+ cache.at = 0
4310
+ }
4311
+
4276
4312
  var refillComposer = (rawSid, boundarySeq) => {
4277
4313
  try {
4278
4314
  const cache = __peekRowsCache ? __peekRowsCache() : null
@@ -4341,13 +4377,7 @@ window.__ModuleLoader__.load({
4341
4377
  if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
4342
4378
  // 0.11.3:立刻把本行标成已遮蔽,否则 afterWrite 的异步刷新窗里
4343
4379
  // 再点一次 /undo 仍会选中同一个 seq → 409。
4344
- const rowsCache = __peekRowsCache ? __peekRowsCache() : null
4345
- if (rowsCache && Array.isArray(rowsCache.rows)) {
4346
- for (const r of rowsCache.rows) {
4347
- if (r && typeof r.seq === 'number' && r.seq >= target.seq) r.shadowed = true
4348
- }
4349
- rowsCache.at = 0
4350
- }
4380
+ markRowsShadowedFrom(target.seq)
4351
4381
  refillComposer(rawSid, target.seq) // 先回填,再重建视图(与对话框一致)
4352
4382
  afterWrite(rawSid, __t('undo.done.undo'))
4353
4383
  })