@240xu/dsh-message-ops 0.20.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 +59 -0
- package/package.json +1 -1
- package/src/client.js +40 -8
- package/src/session-file.js +7 -1
package/README.md
CHANGED
|
@@ -1280,3 +1280,62 @@ textarea 预填真实全文 89 字(非 snippet)
|
|
|
1280
1280
|
中期需宿主提供 per-seq payload 重写。此项**未改代码**,仅出报告待决断。
|
|
1281
1281
|
|
|
1282
1282
|
测试 348(344 pass / 4 skip),`prettier --check` 全绿。
|
|
1283
|
+
|
|
1284
|
+
### 0.21.0 · 回撤隐私预期修正 + 宿主能力需求
|
|
1285
|
+
|
|
1286
|
+
用户问:「回撤的话 AI 还看得到吗?翻会话文件拿得到吗?我希望彻底删除,
|
|
1287
|
+
但因为要恢复,至少在后续几次里能恢复」+「按 opencode 的真删时机来,看看有没有方法」。
|
|
1288
|
+
|
|
1289
|
+
**Spike 结论**(只读查证 + 一次性破坏性试验,未碰真实会话):
|
|
1290
|
+
- AI **看不到**(模型只读 `surface.nodes`);但翻 `session.v4.jsonl.zstd` **拿得到**,
|
|
1291
|
+
实测 161 条被回撤消息原文逐字可读
|
|
1292
|
+
- **物理删中间行会 corrupt**:宿主 `surface.js:425` 的 seq 连续性校验会抛
|
|
1293
|
+
`session event seq 12 is not contiguous; expected 8`(已用宿主 `foldSurface` 实测)
|
|
1294
|
+
- **照抄 opencode 的尾部 DELETE 对不上几何**:opencode 删的是「边界之后的尾部」,
|
|
1295
|
+
而 DSH 真实数据里 49 个回撤 marker **全是中间型**(距末尾几千事件)
|
|
1296
|
+
- **脱敏重写在磁盘冷数据层可行**(保留事件数/seq/类型、把 content 改 `[redacted]`,
|
|
1297
|
+
实测 `foldSurface` 通过),但宿主**没有 reload 入口**、且需持写锁 → 必须宿主来做
|
|
1298
|
+
|
|
1299
|
+
**本次落地(方案 1 + 2)**:
|
|
1300
|
+
|
|
1301
|
+
1. **诚实告知(纯插件,止住隐私预期落差)**
|
|
1302
|
+
- 回撤确认框常显告知条 `panel.revertPrivacyNote`:明确「这不是删除,
|
|
1303
|
+
AI 看不到,但原文仍在本地会话文件、可被恢复、翻文件仍能读到」
|
|
1304
|
+
- 行内回滚按钮 title `slot.revertPrivacyHint`(`syncEnabled` 统一,
|
|
1305
|
+
修掉了它覆盖 ensureBtn 初始值的问题)
|
|
1306
|
+
- 成功 toast `done.revert` 补上「原文仍保留、可恢复」
|
|
1307
|
+
- 真实 Chromium 验证:行内 title 与面板确认框告知条均正确渲染
|
|
1308
|
+
|
|
1309
|
+
2. **给宿主的正式需求文档**
|
|
1310
|
+
`docs/superpowers/specs/2026-11-10-host-per-seq-redaction-request.md`(203 行):
|
|
1311
|
+
- 请求两个能力:**per-seq payload 重写**(改 data 不删行、不破坏 seq 连续性)
|
|
1312
|
+
+ **在 commit 时机自动触发 + 内存 surface 重建**
|
|
1313
|
+
- 对标 opencode 的三个 commit 触发点(prompt / compact / 手动)
|
|
1314
|
+
- 含试验数据、源码行号、接口建议、验收标准
|
|
1315
|
+
- 语义:stage 期间可恢复(现状不变),用户继续对话后宿主脱敏 commit,
|
|
1316
|
+
之后翻文件也拿不到原文 —— 正好对上用户「后续几次能恢复、之后彻底删」的诉求
|
|
1317
|
+
|
|
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
package/src/client.js
CHANGED
|
@@ -132,6 +132,7 @@ window.__ModuleLoader__.load({
|
|
|
132
132
|
'op.branch': '从此条分叉为新会话',
|
|
133
133
|
'op.branchDesc': '把此条之前的对话复制到新会话,并把此条原文放回新会话输入框(原会话不变,非破坏操作)。',
|
|
134
134
|
'slot.revert': '回滚到此条',
|
|
135
|
+
'slot.revertPrivacyHint': '回滚到此条(不是删除:AI 看不到,但原文仍在本地会话文件)',
|
|
135
136
|
'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
|
|
136
137
|
'slot.fork': '从此条分叉',
|
|
137
138
|
'slot.forkHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
@@ -157,7 +158,8 @@ window.__ModuleLoader__.load({
|
|
|
157
158
|
'edit.doneSubmitted': '已回撤,改后的消息已提交',
|
|
158
159
|
'edit.manual': '已回撤,改后的文本已放进输入框——请按回车发送',
|
|
159
160
|
'edit.running': '会话正在运行:需先停止会话再编辑重发',
|
|
160
|
-
'edit.replaceHint':
|
|
161
|
+
'edit.replaceHint':
|
|
162
|
+
'发送会先回撤此条及其之后的全部可见消息,再把改后的文本作为新消息发出。注意:这不是删除——AI 看不到被回撤的内容,但原文仍保留在本地会话文件、可被恢复,直接翻看会话文件仍能读到。',
|
|
161
163
|
'toast.openNew': '打开新会话',
|
|
162
164
|
'fork.official': '分支完成:新会话 {id}',
|
|
163
165
|
'fork.unavailable': '官方分支不可用:通常是因为会话正在运行,请先停止会话后重试。分支功能由 dsh 内置的 session/fork 提供。',
|
|
@@ -170,7 +172,7 @@ window.__ModuleLoader__.load({
|
|
|
170
172
|
'busy.delete': '删除中…',
|
|
171
173
|
'busy.branch': '分支中…',
|
|
172
174
|
'done.restore': '恢复完成:重放 {n} 条,跳过不可重放 {s} 条',
|
|
173
|
-
'done.revert': '
|
|
175
|
+
'done.revert': '已回滚(原文仍保留在本地会话文件,可被恢复);刷新页面后生效',
|
|
174
176
|
'done.delete': '删除完成,刷新页面后生效',
|
|
175
177
|
'action.reload': '刷新页面',
|
|
176
178
|
errorPrefix: '操作失败:',
|
|
@@ -216,6 +218,11 @@ window.__ModuleLoader__.load({
|
|
|
216
218
|
'panel.revertHint': '包含此条及其后的可见消息',
|
|
217
219
|
'panel.revertConfirmTitle': '回滚到 #{seq}?',
|
|
218
220
|
'panel.revertConfirmBody': '将遮蔽 #{start}–#{end} 的 {n} 条消息,其中可见 {v} 条;日志仍保留,可恢复。',
|
|
221
|
+
// 0.21.0:隐私预期落差修正。回撤不是「删除」,别让用户以为内容消失了。
|
|
222
|
+
// 实测(design-demos/revert-data-semantics.md):AI 看不到(模型只读 surface.nodes),
|
|
223
|
+
// 但被回撤消息的原文仍逐字留在本地 session.v4.jsonl.zstd 里,翻文件拿得到。
|
|
224
|
+
'panel.revertPrivacyNote':
|
|
225
|
+
'注意:这不是删除。AI 将看不到这些消息,但原文仍完整保留在本地会话文件中,可被恢复;直接翻看会话文件仍能读到。',
|
|
219
226
|
'panel.deleteConfirmTitle': '仅删除 #{seq}?',
|
|
220
227
|
'panel.deleteConfirmBody': '将遮蔽这 1 条消息,其他内容不动;日志仍保留,可恢复。',
|
|
221
228
|
'panel.confirmRevert': '确认回滚',
|
|
@@ -279,6 +286,7 @@ window.__ModuleLoader__.load({
|
|
|
279
286
|
'op.branchDesc':
|
|
280
287
|
'Copies the conversation above the picked message into a new session and puts this message back in the new composer (original untouched, non-destructive).',
|
|
281
288
|
'slot.revert': 'Revert to here',
|
|
289
|
+
'slot.revertPrivacyHint': 'Revert to here (not deletion: hidden from the AI, but the original text stays in the local session file)',
|
|
282
290
|
'slot.revertUnmatched':
|
|
283
291
|
'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.',
|
|
284
292
|
'slot.fork': 'Branch from here',
|
|
@@ -306,7 +314,7 @@ window.__ModuleLoader__.load({
|
|
|
306
314
|
'edit.manual': 'Reverted; the edited text is in the composer — press Enter to send',
|
|
307
315
|
'edit.running': 'The session is running: stop it before editing and resending',
|
|
308
316
|
'edit.replaceHint':
|
|
309
|
-
'Sending reverts this message and every visible message after it, then sends the edited text as a new message.
|
|
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.',
|
|
310
318
|
'toast.openNew': 'Open new session',
|
|
311
319
|
'fork.official': 'Branched (official fork): new session {id}',
|
|
312
320
|
'fork.unavailable':
|
|
@@ -320,7 +328,7 @@ window.__ModuleLoader__.load({
|
|
|
320
328
|
'busy.delete': 'Deleting…',
|
|
321
329
|
'busy.branch': 'Branching…',
|
|
322
330
|
'done.restore': 'Restored: replayed {n}, skipped non-replayable {s}',
|
|
323
|
-
'done.revert': 'Reverted; reload to apply',
|
|
331
|
+
'done.revert': 'Reverted (original text stays in the local session file and can be restored); reload to apply',
|
|
324
332
|
'done.delete': 'Deleted; reload to apply',
|
|
325
333
|
'action.reload': 'Reload page',
|
|
326
334
|
errorPrefix: 'Operation failed: ',
|
|
@@ -367,6 +375,8 @@ window.__ModuleLoader__.load({
|
|
|
367
375
|
'panel.revertConfirmTitle': 'Revert to #{seq}?',
|
|
368
376
|
'panel.revertConfirmBody':
|
|
369
377
|
'This shadows {n} messages (#{start}–#{end}), including {v} visible. The log stays append-only and can be restored.',
|
|
378
|
+
'panel.revertPrivacyNote':
|
|
379
|
+
'Note: this is not deletion. The AI will no longer see these messages, but the original text stays in the local session file and can be recovered — reading the session file directly still reveals it.',
|
|
370
380
|
'panel.deleteConfirmTitle': 'Delete only #{seq}?',
|
|
371
381
|
'panel.deleteConfirmBody': 'This shadows this one message; everything else stays. The log stays append-only and can be restored.',
|
|
372
382
|
'panel.confirmRevert': 'Confirm revert',
|
|
@@ -1149,6 +1159,8 @@ window.__ModuleLoader__.load({
|
|
|
1149
1159
|
'.mopsActionConfirm{display:flex;flex-direction:column;gap:7px;margin-top:10px;padding:10px;border:1px solid var(--dsw-alias-border-l2,#e6e6e6);background:var(--dsw-alias-bg-layer-1,#fff)}',
|
|
1150
1160
|
'.mopsImpactTitle{font-size:12px;font-weight:600}',
|
|
1151
1161
|
'.mopsImpact{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1162
|
+
// 常显隐私告知条:左竖线 + 灰底,与红色错误条区分;不可关闭,避免"勾了就真删"的误解
|
|
1163
|
+
'.mopsPrivacyNote{margin-top:2px;padding:6px 9px;border-left:2px solid var(--dsw-alias-label-tertiary,#9a9aa0);background:var(--dsw-alias-bg-layer-2,#efefef);border-radius:0 4px 4px 0;font-size:11px;line-height:1.5;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1152
1164
|
'.mopsAction{height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-l2,#cfcfcf);background:transparent;cursor:pointer;font-size:11px}',
|
|
1153
1165
|
'.mopsAction:hover:not(:disabled){border-color:var(--dsw-alias-label-primary,#0f1115)}',
|
|
1154
1166
|
'.mopsAction.primary{border-color:var(--dsw-alias-label-primary,#0f1115);background:var(--dsw-alias-label-primary,#0f1115);color:var(--dsw-alias-bg-layer-1,#fff)}',
|
|
@@ -2246,6 +2258,11 @@ window.__ModuleLoader__.load({
|
|
|
2246
2258
|
})
|
|
2247
2259
|
: t('panel.deleteConfirmBody'),
|
|
2248
2260
|
),
|
|
2261
|
+
// 0.21.0:revert 的常显隐私告知(零副作用、纯文案)。
|
|
2262
|
+
// 只在回滚确认态出现;删除确认不需要(删单条同样遮蔽,但语义不同)。
|
|
2263
|
+
confirmAction === 'revert'
|
|
2264
|
+
? React.createElement('div', { className: 'mopsPrivacyNote', role: 'note' }, t('panel.revertPrivacyNote'))
|
|
2265
|
+
: null,
|
|
2249
2266
|
React.createElement(
|
|
2250
2267
|
'div',
|
|
2251
2268
|
{ className: 'mopsConfirmRow' },
|
|
@@ -3321,11 +3338,23 @@ window.__ModuleLoader__.load({
|
|
|
3321
3338
|
const QUOTE_MAX_CHARS = 600
|
|
3322
3339
|
// 0.20.0(bug-hunt M-1):按 Unicode code point 截断,且尽量在换行/空格处收尾,
|
|
3323
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
|
+
}
|
|
3324
3352
|
const clipQuote = raw => {
|
|
3325
|
-
const chars =
|
|
3353
|
+
const chars = graphemes(raw)
|
|
3326
3354
|
if (chars.length <= QUOTE_MAX_CHARS) return chars.join('')
|
|
3327
3355
|
let end = QUOTE_MAX_CHARS
|
|
3328
|
-
// 往前找最近的空白/换行边界(最多回退 40
|
|
3356
|
+
// 往前找最近的空白/换行边界(最多回退 40 个 grapheme),不破坏单词;
|
|
3357
|
+
// 找不到就硬切(此时至少不会拆散单个 grapheme)
|
|
3329
3358
|
for (let i = end; i > Math.max(0, end - 40); i--) {
|
|
3330
3359
|
if (/[\s\n]/.test(chars[i - 1])) {
|
|
3331
3360
|
end = i
|
|
@@ -4131,11 +4160,13 @@ window.__ModuleLoader__.load({
|
|
|
4131
4160
|
var syncEnabled = (block, btn) => {
|
|
4132
4161
|
if (!btn) return
|
|
4133
4162
|
// 0.18.0/0.20.0:三种按钮各有自己的提示文案(编辑按钮不能写 revert 的 hint)
|
|
4163
|
+
// 0.21.0:回滚按钮统一用「带隐私提示」的 title —— syncEnabled 会在
|
|
4164
|
+
// 注入后重设 title,若这里仍用 slot.revert 会覆盖掉 ensureBtn 里的隐私提示。
|
|
4134
4165
|
const hintKey = btn.classList.contains('mopsUserFork')
|
|
4135
4166
|
? 'slot.forkHint'
|
|
4136
4167
|
: btn.classList.contains('mopsUserEdit')
|
|
4137
4168
|
? 'slot.editHint'
|
|
4138
|
-
: 'slot.
|
|
4169
|
+
: 'slot.revertPrivacyHint'
|
|
4139
4170
|
const ok = block.getAttribute('data-mops-seq')
|
|
4140
4171
|
if (ok) {
|
|
4141
4172
|
btn.disabled = false
|
|
@@ -4343,7 +4374,8 @@ window.__ModuleLoader__.load({
|
|
|
4343
4374
|
btn = document.createElement('button')
|
|
4344
4375
|
btn.type = 'button'
|
|
4345
4376
|
btn.className = 'mopsUserRevert'
|
|
4346
|
-
|
|
4377
|
+
// 0.21.0:行内回滚按钮不经过面板确认框,隐私告知必须挂在这里(hover 可见)
|
|
4378
|
+
btn.title = __t('slot.revertPrivacyHint')
|
|
4347
4379
|
btn.setAttribute('aria-label', __t('slot.revert'))
|
|
4348
4380
|
btn.innerHTML =
|
|
4349
4381
|
'<svg width="14" height="14" viewBox="0 0 16 16" fill="none"><path d="M2.5 8a5.5 5.5 0 1 0 1.6-3.9" stroke="currentColor" stroke-width="1.2"/><path d="M2.2 2.8v3h3" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>'
|
package/src/session-file.js
CHANGED
|
@@ -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' ?
|
|
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
|