@240xu/dsh-message-ops 0.21.0 → 0.22.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
@@ -1316,3 +1316,26 @@ textarea 预填真实全文 89 字(非 snippet)
1316
1316
  之后翻文件也拿不到原文 —— 正好对上用户「后续几次能恢复、之后彻底删」的诉求
1317
1317
 
1318
1318
  测试 353(349 pass / 4 skip),`prettier --check` 全绿。
1319
+
1320
+ ### 0.22.0 · 深挖审计修复(grapheme 截断 / 全文口径 / 编辑框告知)
1321
+
1322
+ 用户要求「分配多项专家子代理,对内容的 bug 还有 UX 进行深挖」。两轮 8 名专项成员
1323
+ 全部中途失败、无报告落盘,但半截结论与 `.audit-tmp/` 里的真执行脚本有效。
1324
+ Lead 逐条复核后落地 3 个修复。汇总见 `design-demos/audit-round-summary.md`。
1325
+
1326
+ 1. **引用截断按 grapheme 切**(真 bug):`clipQuote` 原按 `Array.from`(code point)
1327
+ 切 600 字,会拆散 grapheme cluster。真执行实测 `a×598 + 👨‍👩‍👧‍👦` 被切成
1328
+ `U+1f468 U+200d U+2026`(悬空 ZWJ + 半个家庭 emoji)。改用
1329
+ `Intl.Segmenter('zh', {granularity:'grapheme'})`,切点只落在 grapheme 边界。
1330
+ 2. **fullText 与 /text 同口径**(真 bug):`listMessages` 的 `fullText` 原用
1331
+ `messageText`(首段),而 `/text` 用 `messageTextFull`(全段)。宿主把长文本拆成
1332
+ 多段时,`refillComposer` / `forkFromUserMessage` 回填丢后半段。
1333
+ 现 `snippet` 仍用首段(摘要本就该短),`fullText` 显式改用 `messageTextFull`。
1334
+ 3. **编辑框隐私告知覆盖**(UX 缺口):0.21 的告知只覆盖面板确认框与行内按钮,
1335
+ 但 `EditResendOverlay` 点「发送并回撤」也走 `/revert`。把 `edit.replaceHint`
1336
+ 的 zh/en 文案补成「这不是删除——AI 看不到,但原文仍在本地会话文件、
1337
+ 可被恢复、翻文件仍能读到」,不新增 UI 元素以免「一堵字」。
1338
+
1339
+ 新增 `test/audit-deep-fixes.test.js`(4 条,含 3 条真执行);更新 2 条过期的
1340
+ 0.20 契约(code point → grapheme)。测试 357(353 pass / 4 skip),
1341
+ `prettier --check` 全绿。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-message-ops",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "DSH web 插件:消息级回滚 / 删除 / 恢复 / 分叉 / 编辑重发(补 dsh 官方没有的部分)。",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/client.js CHANGED
@@ -158,7 +158,8 @@ window.__ModuleLoader__.load({
158
158
  'edit.doneSubmitted': '已回撤,改后的消息已提交',
159
159
  'edit.manual': '已回撤,改后的文本已放进输入框——请按回车发送',
160
160
  'edit.running': '会话正在运行:需先停止会话再编辑重发',
161
- 'edit.replaceHint': '发送会先回撤此条及其之后的全部可见消息,再把改后的文本作为新消息发出;日志仍保留,可从回撤区重放。',
161
+ 'edit.replaceHint':
162
+ '发送会先回撤此条及其之后的全部可见消息,再把改后的文本作为新消息发出。注意:这不是删除——AI 看不到被回撤的内容,但原文仍保留在本地会话文件、可被恢复,直接翻看会话文件仍能读到。',
162
163
  'toast.openNew': '打开新会话',
163
164
  'fork.official': '分支完成:新会话 {id}',
164
165
  'fork.unavailable': '官方分支不可用:通常是因为会话正在运行,请先停止会话后重试。分支功能由 dsh 内置的 session/fork 提供。',
@@ -313,7 +314,7 @@ window.__ModuleLoader__.load({
313
314
  'edit.manual': 'Reverted; the edited text is in the composer — press Enter to send',
314
315
  'edit.running': 'The session is running: stop it before editing and resending',
315
316
  'edit.replaceHint':
316
- 'Sending reverts this message and every visible message after it, then sends the edited text as a new message. The log is kept, so you can replay it from the revert dock.',
317
+ 'Sending reverts this message and every visible message after it, then sends the edited text as a new message. Note: this is not deletion — the AI will not see the reverted content, but the original text stays in the local session file, can be restored, and is still readable by opening that file directly.',
317
318
  'toast.openNew': 'Open new session',
318
319
  'fork.official': 'Branched (official fork): new session {id}',
319
320
  'fork.unavailable':
@@ -3337,11 +3338,23 @@ window.__ModuleLoader__.load({
3337
3338
  const QUOTE_MAX_CHARS = 600
3338
3339
  // 0.20.0(bug-hunt M-1):按 Unicode code point 截断,且尽量在换行/空格处收尾,
3339
3340
  // 避免把 emoji(代理对)或 markdown 围栏 ``` 从中间切坏。
3341
+ // 0.22.0(真执行实测):按 code point 切会拆散 grapheme cluster。
3342
+ // 实测 'a'.repeat(598) + '👨‍👩‍👧‍👦' → 尾部 U+1f468 U+200d U+2026,
3343
+ // 家庭 emoji 被切成单人 + 悬空 ZWJ。改用 Intl.Segmenter 按 grapheme 切。
3344
+ let quoteSegmenter = null
3345
+ const graphemes = raw => {
3346
+ if (typeof Intl !== 'undefined' && Intl.Segmenter) {
3347
+ quoteSegmenter ||= new Intl.Segmenter('zh', { granularity: 'grapheme' })
3348
+ return Array.from(quoteSegmenter.segment(String(raw)), part => part.segment)
3349
+ }
3350
+ return Array.from(String(raw))
3351
+ }
3340
3352
  const clipQuote = raw => {
3341
- const chars = Array.from(String(raw))
3353
+ const chars = graphemes(raw)
3342
3354
  if (chars.length <= QUOTE_MAX_CHARS) return chars.join('')
3343
3355
  let end = QUOTE_MAX_CHARS
3344
- // 往前找最近的空白/换行边界(最多回退 40 个字符),不破坏单词
3356
+ // 往前找最近的空白/换行边界(最多回退 40 个 grapheme),不破坏单词;
3357
+ // 找不到就硬切(此时至少不会拆散单个 grapheme)
3345
3358
  for (let i = end; i > Math.max(0, end - 40); i--) {
3346
3359
  if (/[\s\n]/.test(chars[i - 1])) {
3347
3360
  end = i
@@ -335,7 +335,13 @@ export function listMessages(events) {
335
335
  // 前提是这些事件必须先出现在我们的消息列表里、并带上 id,否则
336
336
  // byMessageId 查不到 → seqOfNodeKey 返回 null → 调用方「保持可见」。
337
337
  if (e.type === 'user/message' || e.type === 'assistant/message' || e.type === 'system/message' || e.type === 'developer/message') {
338
+ // 0.22.0:`snippet` 用首段即可,但 `fullText` 必须用**全段**。
339
+ // 旧实现两者共用 messageText(首段),当宿主把长文本拆成多个 content 段
340
+ // (compaction checkpoint 实测 321+7954+20 三段)时,fullText 只有第一段
341
+ // → refillComposer / fork 回填丢掉后半段,与 /text 接口(messageTextFull)
342
+ // 口径分裂。这里显式分开。
338
343
  const text = messageText(e)
344
+ const fullTextValue = messageTextFull(e)
339
345
  const msg = e.data && e.data.message
340
346
  // id:宿主持久化的消息身份(user 在 data.id、assistant 在 data.message.id),
341
347
  // 供 0.2.0 assistant-actions 槽(ownerProps={messageId})反查 seq。
@@ -357,7 +363,7 @@ export function listMessages(events) {
357
363
  marker: isReplaceMarker,
358
364
  snippet: text.replace(/\s+/g, ' ').trim().slice(0, 160),
359
365
  // 0.4.0 composer 回填:user 消息携带全文(revert 后 setDraft 原文)
360
- fullText: e.type === 'user/message' ? text : null,
366
+ fullText: e.type === 'user/message' ? fullTextValue : null,
361
367
  // 0.4.1 dock:replace 标记携带范围与来源(区分手工回撤 vs compaction)
362
368
  range:
363
369
  isReplaceMarker && e.surfaceOp.startSeq != null && e.surfaceOp.endSeq != null