@240xu/dsh-message-ops 0.13.0 → 0.13.1

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 +42 -0
  2. package/package.json +1 -1
  3. package/src/client.js +82 -15
package/README.md CHANGED
@@ -891,6 +891,48 @@ 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.13.1 · 修第二轮对抗审查的两个 HIGH
895
+
896
+ **HIGH-1|隐藏官方 branch 按钮在 0.2.2-alpha.2 上 100% 无效。**
897
+ 0.12.0 用 `svg path` 的 `d` 前缀 `M13.0762…` 识别官方 branch 图标 —— 但该版本图标已改为
898
+ **sprite 复用**,官方组件(app bundle 里的工厂 `T(e,t)`)渲染的是:
899
+
900
+ ```html
901
+ <svg data-icon="dsw-icon-branch-outline-regular" aria-hidden="true">
902
+ <use href="#dsw-icon-branch-outline-regular"/>
903
+ </svg>
904
+ ```
905
+
906
+ **DOM 里根本没有 `<path>`**,`M13.0762` 在整个已安装 dsh 里 0 次命中 → `d` 恒为空 →
907
+ `suppressHostBranch()` 一个按钮也藏不掉,且静默失效、无报错。
908
+ 更糟的是 `test/fork-dom-behavior.test.js` 当时用自造的 `<path d="M13.0762…">` 夹具,
909
+ **测的是自己的假设,不是宿主现实**,所以一直绿。
910
+ 修法:主判据改为 `svg[data-icon="dsw-icon-branch-outline-regular"]`(id 由工厂
911
+ `Qv(e,t)=`dsw-icon-${name}-${size}`` 生成,属契约级常量),保留内联 path 作为旧宿主兼容回退;
912
+ 测试夹具换成真实的 `<use>` 形状。
913
+
914
+ **HIGH-2|审查者认为面板分叉恒走坏回退 —— 复核后不成立。**
915
+ 报告称 `OpsDialog` 没带 `&view=compact` 所以 `turnStartSeq` 恒 `undefined`。
916
+ 实测(`_internals.opsList` 对同一会话跑 full / compact 两遍):full view 同样返回
917
+ `turnStartSeq = 4`,因为 `buildDerived` 是把它挂在**消息对象本身**上,而非 compact
918
+ 分支返回的就是这些完整消息对象 —— compact 只是挑了字段子集,不是唯一来源。
919
+ 故未改动。
920
+
921
+ **其余三条 MED 的复核结论**:
922
+ - `seq - 1` 回退对 `inheritedEventCount` 会话不成立 → **不成立**。实测 9 个
923
+ `isSeeded` 子会话,seq 均从 0 重新编号(`minSeq=0`),`inheritedEventCount` 只是日志
924
+ 长度统计,不偏移 seq;restore 副本同理(服务端按新 seq 重算 `turnStartSeq`)。
925
+ - `persistDraft` 空转却报成功 → **成立**,已修:写入后**回读** `dsh.conversation.<sid>`,
926
+ 对不上就报 `panel.editUnavailable` 且**不 close**。
927
+ - 160 字截断的 snippet 冒充原文 → **成立**,已修:新增显式 `detailFull` 状态,
928
+ `/text` 失败即降级为 `false`,编辑按钮要求 `detailFull === true`。
929
+
930
+ **两条 LOW 均成立并已修**:`revert.unresolved` 从未定义(改用已有的
931
+ `slot.revertUnmatched`);`OpsDialog` 的 `op.branch` 文案仍是旧「含该条」语义(改为 before)。
932
+
933
+ 新增 `test/reviewer-round2.test.js`(8 条),其中 i18n 锁会扫出**任何**未定义的
934
+ `__t('…')` key。测试 276(272 pass / 4 skip)。
935
+
894
936
  ### 0.13.0 · 代码风格官方化 + 拆掉「格式被测试冻住」的问题
895
937
 
896
938
  **风格**(与 `~/.dsh/deepseek-harness-master/.oxlintrc.json` 的 `@stylistic/*` 规则一致):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-message-ops",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "DSH web 插件:消息级回滚 / 删除 / 恢复 / 分叉 / 编辑重发(补 dsh 官方没有的部分)。",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/client.js CHANGED
@@ -129,8 +129,8 @@ window.__ModuleLoader__.load({
129
129
  'op.revertDesc': '遮蔽所选消息及其后所有可见内容;日志 append-only,可通过重新发送恢复语境。',
130
130
  'op.delete': '仅删除这一条',
131
131
  'op.deleteDesc': '仅遮蔽所选的一条消息;其余内容保持不变。',
132
- 'op.branch': '从此条分支为新会话',
133
- 'op.branchDesc': '复制所选消息(含)之前的全部事件为新会话(原会话不变,非破坏操作)。',
132
+ 'op.branch': '从此条分叉为新会话',
133
+ 'op.branchDesc': '把此条之前的对话复制到新会话,并把此条原文放回新会话输入框(原会话不变,非破坏操作)。',
134
134
  'slot.revert': '回滚到此条',
135
135
  'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
136
136
  'slot.fork': '从此条分叉',
@@ -212,6 +212,7 @@ window.__ModuleLoader__.load({
212
212
  'panel.editDone': '原文已放回输入框',
213
213
  'panel.editEmpty': '这条消息没有可编辑的文本',
214
214
  'panel.editUnavailable': '编辑器不可写(会话可能正在运行或尚未挂载)',
215
+ 'panel.editNotReady': '全文尚未就绪(列表只带 160 字摘要)——请重试或改用回滚回填',
215
216
  'panel.openNew': '打开新会话',
216
217
  'panel.revertDone': '回滚已生效',
217
218
  'panel.deleteDone': '删除已生效',
@@ -254,8 +255,9 @@ window.__ModuleLoader__.load({
254
255
  'Shadows the picked message and all later visible content; the log stays append-only so context can be restored by re-sending.',
255
256
  'op.delete': 'Delete only this message',
256
257
  'op.deleteDesc': 'Shadows only the picked message; everything else stays.',
257
- 'op.branch': 'Branch into a new session from here',
258
- 'op.branchDesc': 'Copies everything up to and including the picked message into a new session (original untouched, non-destructive).',
258
+ 'op.branch': 'Fork into a new session from here',
259
+ 'op.branchDesc':
260
+ 'Copies the conversation above the picked message into a new session and puts this message back in the new composer (original untouched, non-destructive).',
259
261
  'slot.revert': 'Revert to here',
260
262
  'slot.revertUnmatched':
261
263
  'Cannot locate this message seq in the log (usually the model-written summary drifted too far from the rendered text) — use the Message ops dialog instead.',
@@ -340,6 +342,7 @@ window.__ModuleLoader__.load({
340
342
  'panel.editDone': 'Original text is back in the composer',
341
343
  'panel.editEmpty': 'This message has no editable text',
342
344
  'panel.editUnavailable': 'Composer is not writable (session may be running or not mounted)',
345
+ 'panel.editNotReady': 'Full text is not ready (the list only carries a 160-char snippet) — retry, or use revert to refill',
343
346
  'panel.openNew': 'Open new session',
344
347
  'panel.revertDone': 'Revert applied',
345
348
  'panel.deleteDone': 'Delete applied',
@@ -1123,6 +1126,8 @@ window.__ModuleLoader__.load({
1123
1126
  const [picked, setPicked] = useState(null)
1124
1127
  const [detail, setDetail] = useState('')
1125
1128
  const [detailState, setDetailState] = useState('idle')
1129
+ // MED-5:detail 是**全文**还是 snippet 回退?只有全文才允许「编辑并重发」。
1130
+ const [detailFull, setDetailFull] = useState(false)
1126
1131
  const [tab, setTab] = useState('messages')
1127
1132
  const [hits, setHits] = useState(null)
1128
1133
  const [searching, setSearching] = useState(false)
@@ -1382,6 +1387,17 @@ window.__ModuleLoader__.load({
1382
1387
  setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
1383
1388
  return
1384
1389
  }
1390
+ // MED-4:`persistDraft` 存在 ≠ 真的落盘。宿主的 writer 由
1391
+ // `bindDraftPersistence` 在视图挂载时绑定;blank/hero 态或视图未挂载时
1392
+ // 该函数在但空转。于是「setDraft 改的是内存编辑器、随后 close() 关面板、
1393
+ // 宿主重挂会话时从 localStorage 读回旧草稿」→ 用户看到成功却什么都没了。
1394
+ // 判据不能靠函数存在,只能**回读**:写不进存储就当失败,不 close。
1395
+ const sidForDraft = target.sessionId
1396
+ const stored = readSessionDraft(sidForDraft)
1397
+ if (stored != null && stored !== body) {
1398
+ setError(t('panel.editUnavailable'))
1399
+ return
1400
+ }
1385
1401
  setDone(t('panel.editDone'))
1386
1402
  notifyDone(t('panel.editDone'))
1387
1403
  close()
@@ -1546,6 +1562,7 @@ window.__ModuleLoader__.load({
1546
1562
  detailReq.current += 1
1547
1563
  setPicked(null)
1548
1564
  setDetail('')
1565
+ setDetailFull(false)
1549
1566
  setDetailState('idle')
1550
1567
  setConfirmAction(null)
1551
1568
  }
@@ -1555,6 +1572,7 @@ window.__ModuleLoader__.load({
1555
1572
  detailReq.current += 1
1556
1573
  setPicked(m)
1557
1574
  setDetail(m.snippet || '')
1575
+ setDetailFull(false)
1558
1576
  setDetailState('ready')
1559
1577
  setConfirmAction(null)
1560
1578
  setDone('')
@@ -1631,6 +1649,7 @@ window.__ModuleLoader__.load({
1631
1649
  setConfirmAction(null)
1632
1650
  setPicked(m)
1633
1651
  setDetail(m.snippet || '')
1652
+ setDetailFull(false)
1634
1653
  setDetailState('loading')
1635
1654
  setDone('')
1636
1655
  const req = ++detailReq.current
@@ -1644,12 +1663,15 @@ window.__ModuleLoader__.load({
1644
1663
  .then(({ res, data }) => {
1645
1664
  if (req !== detailReq.current) return
1646
1665
  if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
1647
- setDetail(typeof data.text === 'string' && data.text ? data.text : m.snippet || '')
1666
+ const full = typeof data.text === 'string' && data.text !== '' ? data.text : null
1667
+ setDetail(full ?? (m.snippet || ''))
1668
+ setDetailFull(full !== null)
1648
1669
  setDetailState('ready')
1649
1670
  })
1650
1671
  .catch(() => {
1651
1672
  if (req !== detailReq.current) return
1652
1673
  setDetail(m.snippet || '')
1674
+ setDetailFull(false) // 拉全文失败 → 只有截断的 snippet,不许冒充原文
1653
1675
  setDetailState('ready')
1654
1676
  })
1655
1677
  },
@@ -1848,6 +1870,10 @@ window.__ModuleLoader__.load({
1848
1870
  const pickedIsUser = !!pickedLive && pickedLive.role === 'user'
1849
1871
  const canFork = !busy && !target.running && pickedIsUser && !pickedLive.shadowed && pickedLive.seq > 0
1850
1872
  const canEdit = pickedIsUser && !pickedLive.shadowed && state === 'ready' && !busy
1873
+ // MED-5:只有**真拉到全文**才允许编辑。detail 在 /text 失败时会退化成
1874
+ // snippet,而 snippet 被服务端硬截断到 160 字(session-file.js:331)——
1875
+ // 拿它冒充原文会让用户改完发出时静默丢掉后半段。
1876
+ const editTextReady = detailFull === true && typeof detail === 'string' && detail !== ''
1851
1877
  const deleteBlockedReason = target.running
1852
1878
  ? t('panel.running')
1853
1879
  : state !== 'ready'
@@ -2166,9 +2192,13 @@ window.__ModuleLoader__.load({
2166
2192
  {
2167
2193
  type: 'button',
2168
2194
  className: 'mopsAction',
2169
- disabled: !canEdit,
2170
- title: pickedIsUser ? t('panel.editHint') : t('panel.branchUserOnly'),
2171
- onClick: () => startEdit(detail || pickedLive.snippet || ''),
2195
+ disabled: !canEdit || !editTextReady,
2196
+ title: !pickedIsUser
2197
+ ? t('panel.branchUserOnly')
2198
+ : !editTextReady
2199
+ ? t('panel.editNotReady')
2200
+ : t('panel.editHint'),
2201
+ onClick: () => startEdit(detail),
2172
2202
  },
2173
2203
  t('panel.edit'),
2174
2204
  ),
@@ -2463,24 +2493,41 @@ window.__ModuleLoader__.load({
2463
2493
  * 为什么不能靠 aria-label:官方文案有 8 种语言(zh/en/ja/es/fr/de/ru/pt),
2464
2494
  * 逐个匹配等于把 i18n 表抄进来。也不能靠 class:CSS Modules 会哈希前缀
2465
2495
  * (实测 0.2.0-rc.2 是 `xzv4MW_`,0.2.1 起变过)。
2466
- * 唯一稳定的是**图标几何**:官方 `IconBranchOutline16` 的 path d 是常量
2467
- * (packages/client/ui-primitives/src/icons/index.tsx:149)。
2468
- * 我们自己的分叉按钮复用同一 path,所以必须显式排除。
2496
+ *
2497
+ * ⚠️ 也不能靠 `<path d="…">`(0.12.0 的错误做法,0.13.1 修):0.2.2-alpha.2 的
2498
+ * 图标已改为 **sprite 复用**,官方组件长这样(见已安装 app bundle 的工厂函数):
2499
+ *
2500
+ * <svg data-icon="dsw-icon-branch-outline-regular" aria-hidden="true">
2501
+ * <use href="#dsw-icon-branch-outline-regular"/>
2502
+ * </svg>
2503
+ *
2504
+ * DOM 里**根本没有 `<path>`**,`M13.0762…` 在整个已安装 dsh 里 0 次命中。
2505
+ * 唯一稳定的是 `data-icon` 的 id:`dsw-icon-${name}-${size}`(工厂 `Qv`),
2506
+ * name 来自 ui-primitives 的图标表,属契约级常量。
2507
+ *
2508
+ * 我们自己的分叉按钮也故意用同一图标,所以必须按 class 显式排除。
2469
2509
  *
2470
2510
  * @param btn - 候选按钮(任意元素;非 button 的宿主节点返回 false)
2471
2511
  * @returns 是否官方 branch 按钮
2472
2512
  */
2473
- const HOST_BRANCH_D_PREFIX = 'M13.0762 1.37207'
2513
+ const HOST_BRANCH_ICON_ID = 'dsw-icon-branch-outline-regular'
2474
2514
  const HOST_BRANCH_CLASS = 'mopsUserFork'
2475
2515
  function isHostBranchButton(btn) {
2476
2516
  if (!btn || typeof btn.querySelector !== 'function') return false
2477
2517
  const cls = String((btn.classList && btn.classList.value) || btn.className || '')
2478
2518
  if (cls.split(/\s+/).includes(HOST_BRANCH_CLASS)) return false
2519
+ // 首选 sprite 形态:<svg data-icon="dsw-icon-branch-outline-regular">
2520
+ const svg = btn.querySelector('svg')
2521
+ if (svg && svg.getAttribute('data-icon') === HOST_BRANCH_ICON_ID) return true
2522
+ // 兼容旧宿主的内联 path 形态(0.2.0-rc.x):仍接受官方几何前缀
2479
2523
  const path = btn.querySelector('svg path')
2480
2524
  const d = path ? path.getAttribute('d') || '' : ''
2481
2525
  return d.startsWith(HOST_BRANCH_D_PREFIX)
2482
2526
  }
2483
2527
 
2528
+ /** 旧宿主的内联 path 几何前缀(仅作兼容回退,不是主判据)。 */
2529
+ const HOST_BRANCH_D_PREFIX = 'M13.0762 1.37207'
2530
+
2484
2531
  /**
2485
2532
  * 把文本预置成某个会话的草稿(新会话刚 fork 出来时输入框是空的)。
2486
2533
  *
@@ -2501,6 +2548,26 @@ window.__ModuleLoader__.load({
2501
2548
  }
2502
2549
  }
2503
2550
 
2551
+ /**
2552
+ * 读回某会话的已保存草稿文本(宿主同一存储键)。
2553
+ * @param sessionId - 会话 id
2554
+ * @returns 文本;存储里没有该会话、或格式不可解析时返回 null
2555
+ */
2556
+ function readSessionDraft(sessionId) {
2557
+ try {
2558
+ if (!sessionId || typeof localStorage === 'undefined') return null
2559
+ const raw = localStorage.getItem(FORK_SESSION_STORAGE_PREFIX + sessionId)
2560
+ if (raw == null) return null
2561
+ const parsed = JSON.parse(raw)
2562
+ const draft = parsed && typeof parsed === 'object' ? parsed.draft : undefined
2563
+ if (typeof draft === 'string') return draft
2564
+ if (draft && typeof draft === 'object' && typeof draft.text === 'string') return draft.text
2565
+ return null
2566
+ } catch {
2567
+ return null
2568
+ }
2569
+ }
2570
+
2504
2571
  /** 打开会话(宿主唯一通道)。childId 需要 `session-` 前缀才不会抛 unknown session。 */
2505
2572
  function openSessionById(sessionId) {
2506
2573
  try {
@@ -3588,7 +3655,7 @@ window.__ModuleLoader__.load({
3588
3655
  const row = rows && rows.find(r => r.seq === seq)
3589
3656
  if (!row) {
3590
3657
  ensureAssign(sid)
3591
- notifyDone(__t('errorPrefix') + (__t('revert.unresolved') || 'revert target verification failed'), 'error')
3658
+ notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
3592
3659
  return
3593
3660
  }
3594
3661
  btn.disabled = true
@@ -3654,7 +3721,7 @@ window.__ModuleLoader__.load({
3654
3721
  const seq = Number(block.getAttribute('data-mops-seq'))
3655
3722
  const row = rows && rows.find(r => r.seq === seq)
3656
3723
  if (!row) {
3657
- notifyDone(__t('errorPrefix') + (__t('revert.unresolved') || 'fork target verification failed'), 'error')
3724
+ notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
3658
3725
  return
3659
3726
  }
3660
3727
  if (!(seq > 0)) {
@@ -4408,7 +4475,7 @@ window.__ModuleLoader__.load({
4408
4475
  return {
4409
4476
  apply,
4410
4477
  inject: ['slots'],
4411
- __test: { activityTransition, forkBoundaryBefore, isHostBranchButton, writeSessionDraft, HOST_BRANCH_D_PREFIX },
4478
+ __test: { activityTransition, forkBoundaryBefore, isHostBranchButton, writeSessionDraft, HOST_BRANCH_ICON_ID, HOST_BRANCH_D_PREFIX },
4412
4479
  }
4413
4480
  },
4414
4481
  })