@240xu/dsh-message-ops 0.47.2 → 0.48.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
@@ -2050,7 +2050,12 @@ applyScriptLive`),replace 语义由 `applySurfaceReplace` 唯一拥有。旧
2050
2050
 
2051
2051
  基准:`npm run bench:incremental`(离线合成事件,可复现增量派生成本);CI 每次在
2052
2052
  Node 22/24 上跑 20k 事件档并设 200ms 宽松上限(本地 revert 批 1.5ms / restore 批 1.9ms,
2053
- 全量重算 49ms 是增量合并的 14.4×)。
2053
+ 全量重算 49ms 是增量合并的 14.4×)。冷读路径的组件成本可用
2054
+ `npm run bench:derive -- <会话日志路径>`(需设 `DSH_HOME`)复现。
2055
+
2056
+ 0.48.0 摘要生成改为「边扫描边折叠、凑满上限即停」:`listMessages` 在 20k 事件 / 9.1MB
2057
+ 文本的会话上从 **132ms → 43ms**,冷 `/messages` 从 528ms → 473ms;新旧实现逐字符等价
2058
+ (12000 组随机对拍 + 真实语料 5892 行 0 差异)。
2054
2059
 
2055
2060
  真机验证记录见 [`docs/verification/`](docs/verification/README.md)(环境基线、复核手法、
2056
2061
  每轮逐项判定与证据)。最近一轮:0.46.1 在宿主 0.2.3-alpha.3 上的 P0 修复复验(9 项 PASS)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-message-ops",
3
- "version": "0.47.2",
3
+ "version": "0.48.0",
4
4
  "description": "DSH web 插件:消息级回滚 / 删除 / 恢复 / 分叉 / 编辑重发(补 dsh 官方没有的部分)。",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -125,6 +125,7 @@
125
125
  'panel.trashMoving': '删除中断,仅存副本留作人工恢复',
126
126
  'panel.trashCorrupt': '清单损坏,只能永久删除',
127
127
  'panel.trashManual': '需人工处理',
128
+ 'panel.trashManualExpiry': '不会自动清理',
128
129
  'panel.purgeConfirm': '再点一次永久删除',
129
130
  'panel.restored': '会话已恢复',
130
131
  'panel.purged': '回收站条目已永久删除',
@@ -251,6 +252,7 @@
251
252
  'panel.trashMoving': 'Delete was interrupted; the only copy is kept for manual recovery',
252
253
  'panel.trashCorrupt': 'Manifest is corrupt; only deleting forever is possible',
253
254
  'panel.trashManual': 'Needs manual handling',
255
+ 'panel.trashManualExpiry': 'never auto-purged',
254
256
  'panel.purgeConfirm': 'Click again to delete forever',
255
257
  'panel.restored': 'Session restored',
256
258
  'panel.purged': 'Trash entry permanently deleted',
@@ -726,8 +726,8 @@
726
726
  const r = await readOpsJson(res)
727
727
  if (!r.ok) throw opsError(r.status, r.data)
728
728
  setTrash(prev => prev.filter(x => x.trashId !== trashId))
729
+ // 0.47.3:面板内已有绿色横幅,不要再弹同文案 toast(真机复核 finding #1)。
729
730
  setDone(t('panel.restored'))
730
- notifyDone(t('panel.restored'))
731
731
  emitChanged()
732
732
  // 0.33.13:unarchive 后宿主 feed 会把行放回侧栏,无需整页 reload。
733
733
  } catch (reason) {
@@ -759,8 +759,8 @@
759
759
  if (!r.ok) throw opsError(r.status, r.data)
760
760
  setTrash(prev => prev.filter(x => x.trashId !== trashId))
761
761
  setPurgeId(null)
762
+ // 0.47.3:同上 —— 横幅已可见,去掉重复 toast。
762
763
  setDone(t('panel.purged'))
763
- notifyDone(t('panel.purged'))
764
764
  } catch (reason) {
765
765
  setError(timeoutText(reason, t('errorPrefix')))
766
766
  } finally {
@@ -1395,8 +1395,14 @@
1395
1395
  React.createElement(
1396
1396
  'div',
1397
1397
  { className: 'mopsTrashMeta' },
1398
+ // 0.47.3(真机 UI 复核 finding):`moving` 是删除中断留下的孤儿,
1399
+ // 服务端**永不自动清理**(只能人工 purge)→ 显示到期时间会误导。
1398
1400
  (item.sessionId || t('panel.trashManual')) +
1399
- (item.expiresAt ? ' · ' + t('panel.expires') + ' ' + new Date(item.expiresAt).toLocaleDateString() : ''),
1401
+ (item.state === 'moving'
1402
+ ? ' · ' + t('panel.trashManualExpiry')
1403
+ : item.expiresAt
1404
+ ? ' · ' + t('panel.expires') + ' ' + new Date(item.expiresAt).toLocaleDateString()
1405
+ : ''),
1400
1406
  ),
1401
1407
  ),
1402
1408
  // 0.42.0(srv-audit D9/D10):异常态条目不提供 Restore ——
package/src/client.js CHANGED
@@ -423,6 +423,7 @@ window.__ModuleLoader__.load({
423
423
  'panel.trashMoving': '删除中断,仅存副本留作人工恢复',
424
424
  'panel.trashCorrupt': '清单损坏,只能永久删除',
425
425
  'panel.trashManual': '需人工处理',
426
+ 'panel.trashManualExpiry': '不会自动清理',
426
427
  'panel.purgeConfirm': '再点一次永久删除',
427
428
  'panel.restored': '会话已恢复',
428
429
  'panel.purged': '回收站条目已永久删除',
@@ -549,6 +550,7 @@ window.__ModuleLoader__.load({
549
550
  'panel.trashMoving': 'Delete was interrupted; the only copy is kept for manual recovery',
550
551
  'panel.trashCorrupt': 'Manifest is corrupt; only deleting forever is possible',
551
552
  'panel.trashManual': 'Needs manual handling',
553
+ 'panel.trashManualExpiry': 'never auto-purged',
552
554
  'panel.purgeConfirm': 'Click again to delete forever',
553
555
  'panel.restored': 'Session restored',
554
556
  'panel.purged': 'Trash entry permanently deleted',
@@ -1597,8 +1599,8 @@ window.__ModuleLoader__.load({
1597
1599
  const r = await readOpsJson(res)
1598
1600
  if (!r.ok) throw opsError(r.status, r.data)
1599
1601
  setTrash(prev => prev.filter(x => x.trashId !== trashId))
1602
+ // 0.47.3:面板内已有绿色横幅,不要再弹同文案 toast(真机复核 finding #1)。
1600
1603
  setDone(t('panel.restored'))
1601
- notifyDone(t('panel.restored'))
1602
1604
  emitChanged()
1603
1605
  // 0.33.13:unarchive 后宿主 feed 会把行放回侧栏,无需整页 reload。
1604
1606
  } catch (reason) {
@@ -1630,8 +1632,8 @@ window.__ModuleLoader__.load({
1630
1632
  if (!r.ok) throw opsError(r.status, r.data)
1631
1633
  setTrash(prev => prev.filter(x => x.trashId !== trashId))
1632
1634
  setPurgeId(null)
1635
+ // 0.47.3:同上 —— 横幅已可见,去掉重复 toast。
1633
1636
  setDone(t('panel.purged'))
1634
- notifyDone(t('panel.purged'))
1635
1637
  } catch (reason) {
1636
1638
  setError(timeoutText(reason, t('errorPrefix')))
1637
1639
  } finally {
@@ -2266,8 +2268,14 @@ window.__ModuleLoader__.load({
2266
2268
  React.createElement(
2267
2269
  'div',
2268
2270
  { className: 'mopsTrashMeta' },
2271
+ // 0.47.3(真机 UI 复核 finding):`moving` 是删除中断留下的孤儿,
2272
+ // 服务端**永不自动清理**(只能人工 purge)→ 显示到期时间会误导。
2269
2273
  (item.sessionId || t('panel.trashManual')) +
2270
- (item.expiresAt ? ' · ' + t('panel.expires') + ' ' + new Date(item.expiresAt).toLocaleDateString() : ''),
2274
+ (item.state === 'moving'
2275
+ ? ' · ' + t('panel.trashManualExpiry')
2276
+ : item.expiresAt
2277
+ ? ' · ' + t('panel.expires') + ' ' + new Date(item.expiresAt).toLocaleDateString()
2278
+ : ''),
2271
2279
  ),
2272
2280
  ),
2273
2281
  // 0.42.0(srv-audit D9/D10):异常态条目不提供 Restore ——
@@ -354,6 +354,45 @@ export function findSessionDirs(sessionId) {
354
354
  }
355
355
 
356
356
  /** 从事件流提取消息级列表(user/assistant/system message + tool/call 摘要)。 */
357
+ /**
358
+ * 折叠空白后取前缀摘要(与 `text.replace(/\s+/g, ' ').trim().slice(0, limit)` 逐字符等价)。
359
+ *
360
+ * 0.48.0(性能):旧实现对每条消息的全文做一次全串正则替换再截断 —— 20k 事件日志实测
361
+ * 占 `listMessages` 的约 70%(9.1MB 文本 90ms / 总 132ms),而结果只取前 160 字符。
362
+ * 改为「边扫描边折叠、凑满上限即停」:常见文本只扫前约 200 字符。
363
+ * 语义必须保持:首部空白丢弃、连续空白折叠为一个空格、上限**包含**可能的尾部空格
364
+ *(旧实现先 trim 再 slice,故第 limit 位若是空格会保留)。
365
+ *
366
+ * @param {string} text 原始文本
367
+ * @param {number} [limit] 摘要字符上限(默认 160)
368
+ * @returns {string} 折叠后的摘要
369
+ */
370
+ export function collapsedSnippet(text, limit = 160) {
371
+ if (typeof text !== 'string' || text.length === 0) return ''
372
+ const isSpace = ch =>
373
+ ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r' || ch === '\f' || ch === '\v' ||
374
+ ch === '\u00a0' || ch === '\u1680' || ch === '\u2028' || ch === '\u2029' || ch === '\u202f' ||
375
+ ch === '\u205f' || ch === '\u3000' || ch === '\ufeff' || (ch >= '\u2000' && ch <= '\u200a')
376
+ let out = ''
377
+ let pendingSpace = false
378
+ for (let i = 0; i < text.length; i += 1) {
379
+ if (out.length >= limit) break
380
+ const ch = text[i]
381
+ if (isSpace(ch)) {
382
+ if (out.length > 0) pendingSpace = true
383
+ continue
384
+ }
385
+ if (pendingSpace) {
386
+ if (out.length >= limit) break
387
+ out += ' '
388
+ pendingSpace = false
389
+ if (out.length >= limit) break
390
+ }
391
+ out += ch
392
+ }
393
+ return out
394
+ }
395
+
357
396
  /**
358
397
  * turn 号 → 该 turn 首/末事件 seq 的映射。
359
398
  *
@@ -439,7 +478,7 @@ export function listMessages(events) {
439
478
  : 'system'),
440
479
  id: (msg && msg.id) || (e.data && e.data.id) || null,
441
480
  marker: isReplaceMarker,
442
- snippet: text.replace(/\s+/g, ' ').trim().slice(0, 160),
481
+ snippet: collapsedSnippet(text, 160),
443
482
  // 0.4.0 composer 回填:user 消息携带全文(revert 后 setDraft 原文)
444
483
  fullText: e.type === 'user/message' ? fullTextValue : null,
445
484
  // 0.4.1 dock:replace 标记携带范围与来源(区分手工回撤 vs compaction)