@240xu/dsh-message-ops 0.22.0 → 0.23.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 +33 -0
- package/package.json +1 -1
- package/src/client.js +94 -230
- package/src/ops-core.js +6 -2
package/README.md
CHANGED
|
@@ -1339,3 +1339,36 @@ Lead 逐条复核后落地 3 个修复。汇总见 `design-demos/audit-round-sum
|
|
|
1339
1339
|
新增 `test/audit-deep-fixes.test.js`(4 条,含 3 条真执行);更新 2 条过期的
|
|
1340
1340
|
0.20 契约(code point → grapheme)。测试 357(353 pass / 4 skip),
|
|
1341
1341
|
`prettier --check` 全绿。
|
|
1342
|
+
|
|
1343
|
+
### 0.23.0 · 引用让位宿主 + 恢复官方分支 + 深挖真 bug 修复
|
|
1344
|
+
|
|
1345
|
+
用户:「引用做得巧妙点,不要每次把整个上下文塞给 AI」+「把犯蠢做的东西全部审计
|
|
1346
|
+
修一下」+「dsh 官方似乎已经有消息分支」。智能体团队 11 份专项报告,Lead 逐条
|
|
1347
|
+
复核落地。汇总见 `design-demos/audit-round2-summary.md`。
|
|
1348
|
+
|
|
1349
|
+
1. **引用按钮删除(让位宿主划词引用)**:实证宿主 `dsh-message-quotes` 已有
|
|
1350
|
+
完整划词引用(`data-text-interaction-source` + `selectionchange` +
|
|
1351
|
+
`inputActions.insertQuote`),只在选中文字时、选中多少引多少。我们旧按钮
|
|
1352
|
+
选区体系不匹配 → 退化成塞 600 字全文;而 `deriveMessages()` 本就给出完整
|
|
1353
|
+
历史 → 引用未遮蔽消息 = 同一内容进 prompt 两遍。AI 动作槽改 `return null`,
|
|
1354
|
+
组件保留(它捕获 `inputActions`,删了会让编辑框/面板/回填失效)。
|
|
1355
|
+
真机:选中 20 字 → QuoteNode 正好 20 字,宿主 toolbar 出现,无重复注入。
|
|
1356
|
+
2. **恢复官方消息分支**:官方 `TurnTailNodeView` 的 `MessageIconActions` 本就有
|
|
1357
|
+
`sessions.fork({atSeq: turn-tail seq})` 分支按钮。0.12 起我们把它藏了
|
|
1358
|
+
(`suppressHostBranch`)又自己造 `mopsUserFork`,是重复造轮子。
|
|
1359
|
+
删抑制 + 删行内 fork,恢复官方按钮;面板 branch 保留(底层本来就是官方 fork)。
|
|
1360
|
+
真机:`hostBranchIconBtns=3 / hidden=0 / mopsFork=0`。
|
|
1361
|
+
3. **S-1 restore 重放丢段**(HIGH):`planRestore` 用 `messageText`(首段),
|
|
1362
|
+
多段消息恢复后永久丢后半段,实测 898 条受影响、175 万字符。改 `messageTextFull`。
|
|
1363
|
+
4. **S-2 dock 遮蔽计数恒 0**(HIGH):服务端 range 是 `{startSeq,endSeq}`,
|
|
1364
|
+
client 只读 `{start,end}`。改成兼容两种形状。
|
|
1365
|
+
5. **文案自我打脸**:`op.delete` 说「删除」但实现是遮蔽,而隐私告知自己写着
|
|
1366
|
+
「这不是删除」。6 个 key 改成「遮蔽此条」,去掉给外行看的 `append-only`。
|
|
1367
|
+
6. **回填失败仍报成功**:`runUserRevert` 先报成功再回填且丢弃返回值。
|
|
1368
|
+
改成先回填、按结果报成功/`warn`(新增 `done.revertNoRefill`)。
|
|
1369
|
+
7. **测试假绿灯**:变异测试抓到 3 类高危(submitEditedText 被 stub、
|
|
1370
|
+
`assert.ok(true)` 守卫、i18n 值语义盲区),补 3 条真执行提交测试 +
|
|
1371
|
+
硬失败守卫 + 反义值检测。
|
|
1372
|
+
|
|
1373
|
+
过程中 Lead 误删 `ensureBtn` 导致用户消息按钮全失效,已从 git 取回并真机复验
|
|
1374
|
+
`mopsRevert=9 / mopsEdit=9`。测试 360(356 pass / 4 skip),`prettier --check` 全绿。
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -125,9 +125,9 @@ window.__ModuleLoader__.load({
|
|
|
125
125
|
'dialog.invisible': '(已遮蔽,仅日志可见)',
|
|
126
126
|
'dialog.showMore': '显示更多(剩余 {n} 条)',
|
|
127
127
|
'dialog.more': '…(仅显示最近 200 条,共 {n} 条)',
|
|
128
|
-
'op.revert': '
|
|
129
|
-
'op.revertDesc': '
|
|
130
|
-
'op.delete': '
|
|
128
|
+
'op.revert': '回撤到此条及之后',
|
|
129
|
+
'op.revertDesc': '把这条及之后的对话从 AI 可见内容里隐藏;原文仍保留,可以放回。',
|
|
130
|
+
'op.delete': '遮蔽此条',
|
|
131
131
|
'op.deleteDesc': '仅遮蔽所选的一条消息;其余内容保持不变。',
|
|
132
132
|
'op.branch': '从此条分叉为新会话',
|
|
133
133
|
'op.branchDesc': '把此条之前的对话复制到新会话,并把此条原文放回新会话输入框(原会话不变,非破坏操作)。',
|
|
@@ -173,7 +173,8 @@ window.__ModuleLoader__.load({
|
|
|
173
173
|
'busy.branch': '分支中…',
|
|
174
174
|
'done.restore': '恢复完成:重放 {n} 条,跳过不可重放 {s} 条',
|
|
175
175
|
'done.revert': '已回滚(原文仍保留在本地会话文件,可被恢复);刷新页面后生效',
|
|
176
|
-
'done.
|
|
176
|
+
'done.revertNoRefill': '已回滚,但原文未能放回输入框(会话可能尚未挂载);可重试或从消息操作面板手动复制',
|
|
177
|
+
'done.delete': '已遮蔽,刷新页面后生效',
|
|
177
178
|
'action.reload': '刷新页面',
|
|
178
179
|
errorPrefix: '操作失败:',
|
|
179
180
|
'dock.title': '已回撤 {n} 条消息',
|
|
@@ -226,12 +227,12 @@ window.__ModuleLoader__.load({
|
|
|
226
227
|
'panel.deleteConfirmTitle': '仅删除 #{seq}?',
|
|
227
228
|
'panel.deleteConfirmBody': '将遮蔽这 1 条消息,其他内容不动;日志仍保留,可恢复。',
|
|
228
229
|
'panel.confirmRevert': '确认回滚',
|
|
229
|
-
'panel.confirmDeleteOne': '
|
|
230
|
+
'panel.confirmDeleteOne': '确认遮蔽',
|
|
230
231
|
'panel.retry': '重试',
|
|
231
232
|
'panel.searching': '搜索中…',
|
|
232
233
|
'panel.deleteSessionImpact': '共 {n} 条消息;移入回收站后 7 天内可恢复。',
|
|
233
234
|
'panel.deleteUnavailable': '会话信息尚未就绪,暂不能删除。',
|
|
234
|
-
'panel.delete': '
|
|
235
|
+
'panel.delete': '遮蔽此条',
|
|
235
236
|
'panel.deleteHint': '只遮蔽这一条,其他消息不动',
|
|
236
237
|
'panel.branch': '从此条分叉',
|
|
237
238
|
'panel.branchHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
@@ -242,7 +243,7 @@ window.__ModuleLoader__.load({
|
|
|
242
243
|
// 原消息仍在,界面出现两条相似消息)。opencode 也没有消息级编辑。
|
|
243
244
|
'panel.openNew': '打开新会话',
|
|
244
245
|
'panel.revertDone': '回滚已生效',
|
|
245
|
-
'panel.deleteDone': '
|
|
246
|
+
'panel.deleteDone': '已遮蔽',
|
|
246
247
|
'panel.count': '共 {n} 条 · 可见 {v} · 已回滚 {s}',
|
|
247
248
|
'panel.deleteSession': '删除整条会话',
|
|
248
249
|
'panel.deleteSessionHint': '移入回收站,7 天内可恢复。请输入标题确认:',
|
|
@@ -277,10 +278,10 @@ window.__ModuleLoader__.load({
|
|
|
277
278
|
'dialog.invisible': ' (shadowed, log-only)',
|
|
278
279
|
'dialog.showMore': 'Show more ({n} older)',
|
|
279
280
|
'dialog.more': '…(showing latest 200 of {n})',
|
|
280
|
-
'op.revert': 'Revert
|
|
281
|
+
'op.revert': 'Revert to here',
|
|
281
282
|
'op.revertDesc':
|
|
282
283
|
'Shadows the picked message and all later visible content; the log stays append-only so context can be restored by re-sending.',
|
|
283
|
-
'op.delete': '
|
|
284
|
+
'op.delete': 'Hide this message',
|
|
284
285
|
'op.deleteDesc': 'Shadows only the picked message; everything else stays.',
|
|
285
286
|
'op.branch': 'Fork into a new session from here',
|
|
286
287
|
'op.branchDesc':
|
|
@@ -329,7 +330,9 @@ window.__ModuleLoader__.load({
|
|
|
329
330
|
'busy.branch': 'Branching…',
|
|
330
331
|
'done.restore': 'Restored: replayed {n}, skipped non-replayable {s}',
|
|
331
332
|
'done.revert': 'Reverted (original text stays in the local session file and can be restored); reload to apply',
|
|
332
|
-
'done.
|
|
333
|
+
'done.revertNoRefill':
|
|
334
|
+
'Reverted, but the original text could not be put back in the composer (the view may not be mounted yet); retry or copy it manually from Message Ops',
|
|
335
|
+
'done.delete': 'Hidden; reload to apply',
|
|
333
336
|
'action.reload': 'Reload page',
|
|
334
337
|
errorPrefix: 'Operation failed: ',
|
|
335
338
|
'dock.title': '{n} rolled back messages',
|
|
@@ -374,18 +377,18 @@ window.__ModuleLoader__.load({
|
|
|
374
377
|
'panel.revertHint': 'Includes this message and all visible messages after it',
|
|
375
378
|
'panel.revertConfirmTitle': 'Revert to #{seq}?',
|
|
376
379
|
'panel.revertConfirmBody':
|
|
377
|
-
'This shadows {n} messages (#{start}–#{end}), including {v} visible. The
|
|
380
|
+
'This shadows {n} messages (#{start}–#{end}), including {v} visible. The original text stays in the local session file and can be put back.',
|
|
378
381
|
'panel.revertPrivacyNote':
|
|
379
382
|
'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.',
|
|
380
383
|
'panel.deleteConfirmTitle': 'Delete only #{seq}?',
|
|
381
384
|
'panel.deleteConfirmBody': 'This shadows this one message; everything else stays. The log stays append-only and can be restored.',
|
|
382
385
|
'panel.confirmRevert': 'Confirm revert',
|
|
383
|
-
'panel.confirmDeleteOne': 'Confirm
|
|
386
|
+
'panel.confirmDeleteOne': 'Confirm hide',
|
|
384
387
|
'panel.retry': 'Retry',
|
|
385
388
|
'panel.searching': 'Searching…',
|
|
386
389
|
'panel.deleteSessionImpact': 'Total {n} messages; recoverable from trash for 7 days.',
|
|
387
390
|
'panel.deleteUnavailable': 'Session details are not ready yet; deletion is disabled.',
|
|
388
|
-
'panel.delete': '
|
|
391
|
+
'panel.delete': 'Hide this',
|
|
389
392
|
'panel.deleteHint': 'Shadows only this message',
|
|
390
393
|
'panel.branch': 'Fork from here',
|
|
391
394
|
'panel.branchHint': 'Copy the conversation above this message into a new session and put this message back in the new composer',
|
|
@@ -393,7 +396,7 @@ window.__ModuleLoader__.load({
|
|
|
393
396
|
'panel.branchUserOnly': 'Fork works on user messages only (assistant messages have no text to hand back)',
|
|
394
397
|
'panel.openNew': 'Open new session',
|
|
395
398
|
'panel.revertDone': 'Revert applied',
|
|
396
|
-
'panel.deleteDone': '
|
|
399
|
+
'panel.deleteDone': 'Hidden',
|
|
397
400
|
'panel.count': 'Total {n} · visible {v} · shadowed {s}',
|
|
398
401
|
'panel.deleteSession': 'Delete whole session',
|
|
399
402
|
'panel.deleteSessionHint': 'Moves it to trash for 7 days. Type the title to confirm:',
|
|
@@ -2506,12 +2509,15 @@ window.__ModuleLoader__.load({
|
|
|
2506
2509
|
const opts = options || {}
|
|
2507
2510
|
const attempts = Number.isSafeInteger(opts.attempts) && opts.attempts > 0 ? opts.attempts : EDIT_SUBMIT_ATTEMPTS
|
|
2508
2511
|
const intervalMs = Number.isSafeInteger(opts.intervalMs) && opts.intervalMs >= 0 ? opts.intervalMs : EDIT_SUBMIT_INTERVAL_MS
|
|
2509
|
-
|
|
2512
|
+
// 0.23.0:允许真执行测试注入 inputActions(生产路径仍读模块级 __inputActions)。
|
|
2513
|
+
// 之前测试把 deps.submitEdited 整个 stub 掉,真实提交逻辑从未被执行过。
|
|
2514
|
+
const readInputActions = typeof opts.getInputActions === 'function' ? opts.getInputActions : () => __inputActions
|
|
2515
|
+
const before = readInputActions()
|
|
2510
2516
|
return new Promise(resolve => {
|
|
2511
2517
|
let n = 0
|
|
2512
2518
|
const tick = () => {
|
|
2513
2519
|
n += 1
|
|
2514
|
-
const ia =
|
|
2520
|
+
const ia = readInputActions()
|
|
2515
2521
|
const usable = ia && typeof ia.submit === 'function' && typeof ia.setDraft === 'function'
|
|
2516
2522
|
const remounted = !!ia && ia !== before
|
|
2517
2523
|
if (usable && (remounted || n >= attempts)) {
|
|
@@ -2997,56 +3003,6 @@ window.__ModuleLoader__.load({
|
|
|
2997
3003
|
return Number.isSafeInteger(seq) && seq > 0 ? seq - 1 : -1
|
|
2998
3004
|
}
|
|
2999
3005
|
|
|
3000
|
-
/**
|
|
3001
|
-
* 官方 assistant turn-tail 的 branch 按钮识别(0.12.0)。
|
|
3002
|
-
*
|
|
3003
|
-
* 为什么不能靠 aria-label:官方文案有 8 种语言(zh/en/ja/es/fr/de/ru/pt),
|
|
3004
|
-
* 逐个匹配等于把 i18n 表抄进来。也不能靠 class:CSS Modules 会哈希前缀
|
|
3005
|
-
* (实测 0.2.0-rc.2 是 `xzv4MW_`,0.2.1 起变过)。
|
|
3006
|
-
*
|
|
3007
|
-
* ⚠️ 也不能靠 `<path d="…">`(0.12.0 的错误做法,0.13.1 修):0.2.2-alpha.2 的
|
|
3008
|
-
* 图标已改为 **sprite 复用**,官方组件长这样(见已安装 app bundle 的工厂函数):
|
|
3009
|
-
*
|
|
3010
|
-
* <svg data-icon="dsw-icon-branch-outline-regular" aria-hidden="true">
|
|
3011
|
-
* <use href="#dsw-icon-branch-outline-regular"/>
|
|
3012
|
-
* </svg>
|
|
3013
|
-
*
|
|
3014
|
-
* DOM 里**根本没有 `<path>`**,`M13.0762…` 在整个已安装 dsh 里 0 次命中。
|
|
3015
|
-
* 唯一稳定的是 `data-icon` 的 id:`dsw-icon-${name}-${size}`(工厂 `Qv`),
|
|
3016
|
-
* name 来自 ui-primitives 的图标表,属契约级常量。
|
|
3017
|
-
*
|
|
3018
|
-
* 我们自己的分叉按钮也故意用同一图标,所以必须按 class 显式排除。
|
|
3019
|
-
*
|
|
3020
|
-
* @param btn - 候选按钮(任意元素;非 button 的宿主节点返回 false)
|
|
3021
|
-
* @returns 是否官方 branch 按钮
|
|
3022
|
-
*/
|
|
3023
|
-
const HOST_BRANCH_ICON_ID = 'dsw-icon-branch-outline-regular'
|
|
3024
|
-
const HOST_BRANCH_CLASS = 'mopsUserFork'
|
|
3025
|
-
function isHostBranchButton(btn) {
|
|
3026
|
-
if (!btn || typeof btn.querySelector !== 'function') return false
|
|
3027
|
-
const cls = String((btn.classList && btn.classList.value) || btn.className || '')
|
|
3028
|
-
if (cls.split(/\s+/).includes(HOST_BRANCH_CLASS)) return false
|
|
3029
|
-
// 首选 sprite 形态:<svg data-icon="dsw-icon-branch-outline-regular">
|
|
3030
|
-
const svg = btn.querySelector('svg')
|
|
3031
|
-
if (svg && svg.getAttribute('data-icon') === HOST_BRANCH_ICON_ID) return true
|
|
3032
|
-
// 兼容旧宿主的内联 path 形态(0.2.0-rc.x):仍接受官方几何前缀
|
|
3033
|
-
const path = btn.querySelector('svg path')
|
|
3034
|
-
const d = path ? path.getAttribute('d') || '' : ''
|
|
3035
|
-
return d.startsWith(HOST_BRANCH_D_PREFIX)
|
|
3036
|
-
}
|
|
3037
|
-
|
|
3038
|
-
/** 旧宿主的内联 path 几何前缀(仅作兼容回退,不是主判据)。 */
|
|
3039
|
-
const HOST_BRANCH_D_PREFIX = 'M13.0762 1.37207'
|
|
3040
|
-
|
|
3041
|
-
/**
|
|
3042
|
-
* 把文本预置成某个会话的草稿(新会话刚 fork 出来时输入框是空的)。
|
|
3043
|
-
*
|
|
3044
|
-
* 为什么直接写 localStorage 而不是 `inputActions.setDraft`:fork 出来的是一个**还没
|
|
3045
|
-
* 挂载**的会话,此刻 `inputActions` 仍绑定在源会话上;宿主挂载新会话时会用
|
|
3046
|
-
* `readConversationDraft(sessionId)` 从 localStorage 初始化编辑器。所以**先落盘再
|
|
3047
|
-
* openSession** 才是无竞态的路径(`{ draft: '<text>' }` 是宿主 `parseStoredDraft`
|
|
3048
|
-
* 支持的字符串形态,见 dsh-client-ui-conversation:4455-4456)。
|
|
3049
|
-
*/
|
|
3050
3006
|
function writeSessionDraft(childSessionId, text) {
|
|
3051
3007
|
try {
|
|
3052
3008
|
if (!childSessionId || typeof localStorage === 'undefined') return false
|
|
@@ -3463,9 +3419,24 @@ window.__ModuleLoader__.load({
|
|
|
3463
3419
|
},
|
|
3464
3420
|
icon,
|
|
3465
3421
|
)
|
|
3466
|
-
// 0.
|
|
3467
|
-
//
|
|
3468
|
-
|
|
3422
|
+
// 0.23.0:AI 消息动作区**不再注入任何按钮**。
|
|
3423
|
+
//
|
|
3424
|
+
// 用户反馈:「引用不要每次把一整个上下文重新全部塞给 AI」。核查结论:
|
|
3425
|
+
// · 宿主自带完整划词引用 —— dsh-message-quotes/lib/client.js:48 调
|
|
3426
|
+
// inputActions.insertQuote(text),注册在 conversation.chat.text-interaction
|
|
3427
|
+
// 槽,只在用户选中文字(textInteraction.active !== null)时渲染,
|
|
3428
|
+
// 「选中多少引多少」,从不引整条。
|
|
3429
|
+
// · 我们旧按钮用 [data-chat-node-key] 判选区,与宿主的
|
|
3430
|
+
// [data-text-interaction-source] 体系不匹配 → 高频判不出选区 →
|
|
3431
|
+
// 退化成 clipQuote(fullText) 把 600 字塞进 composer。
|
|
3432
|
+
// · 而 deriveMessages() 本就遍历 surface.nodes 给出完整历史,
|
|
3433
|
+
// 引用当前会话里未被遮蔽的消息 = 同一内容在 prompt 里出现两遍,纯冗余。
|
|
3434
|
+
// 所以正确做法是让位给宿主,不再重复造轮子。
|
|
3435
|
+
//
|
|
3436
|
+
// ⚠️ 本组件**必须保留**:它负责捕获 inputActions 到 __inputActions
|
|
3437
|
+
//(编辑框 / 面板 / 行内回填都依赖),删组件会让这些功能静默失效。
|
|
3438
|
+
// 只 return null,不删注册。
|
|
3439
|
+
return null
|
|
3469
3440
|
}
|
|
3470
3441
|
|
|
3471
3442
|
// 0.4.2 引入(恢复的标记自动离开活跃列表 = opencode clear 语义)。
|
|
@@ -3608,8 +3579,12 @@ window.__ModuleLoader__.load({
|
|
|
3608
3579
|
// 0.5.2(P2):标题口径 = 标记 range 内 visible=false 的去重 seq 数
|
|
3609
3580
|
const seen = new Set()
|
|
3610
3581
|
for (const mk of act) {
|
|
3611
|
-
|
|
3612
|
-
|
|
3582
|
+
// 0.23.0(深挖 S-2):服务端 buildDerived 用 readReplaceOp 把 range
|
|
3583
|
+
// 覆盖成 {startSeq,endSeq},而旧代码只读 {start,end} → 计数恒为 0。
|
|
3584
|
+
// 两种形状都兼容,并防御旧缓存里仍是 {start,end} 的情况。
|
|
3585
|
+
const rng = mk.range || {}
|
|
3586
|
+
const start = Number.isSafeInteger(rng.startSeq) ? rng.startSeq : Number.isSafeInteger(rng.start) ? rng.start : mk.seq
|
|
3587
|
+
const end = Number.isSafeInteger(rng.endSeq) ? rng.endSeq : Number.isSafeInteger(rng.end) ? rng.end : start
|
|
3613
3588
|
for (const m of msgs) {
|
|
3614
3589
|
if (m && m.visible === false && typeof m.seq === 'number' && m.seq >= start && m.seq <= end) seen.add(m.seq)
|
|
3615
3590
|
}
|
|
@@ -4162,11 +4137,7 @@ window.__ModuleLoader__.load({
|
|
|
4162
4137
|
// 0.18.0/0.20.0:三种按钮各有自己的提示文案(编辑按钮不能写 revert 的 hint)
|
|
4163
4138
|
// 0.21.0:回滚按钮统一用「带隐私提示」的 title —— syncEnabled 会在
|
|
4164
4139
|
// 注入后重设 title,若这里仍用 slot.revert 会覆盖掉 ensureBtn 里的隐私提示。
|
|
4165
|
-
const hintKey = btn.classList.contains('
|
|
4166
|
-
? 'slot.forkHint'
|
|
4167
|
-
: btn.classList.contains('mopsUserEdit')
|
|
4168
|
-
? 'slot.editHint'
|
|
4169
|
-
: 'slot.revertPrivacyHint'
|
|
4140
|
+
const hintKey = btn.classList.contains('mopsUserEdit') ? 'slot.editHint' : 'slot.revertPrivacyHint'
|
|
4170
4141
|
const ok = block.getAttribute('data-mops-seq')
|
|
4171
4142
|
if (ok) {
|
|
4172
4143
|
btn.disabled = false
|
|
@@ -4181,7 +4152,7 @@ window.__ModuleLoader__.load({
|
|
|
4181
4152
|
/** 块内全部插件按钮一起同步(回滚 / 编辑 / 分叉同一动作行)。 */
|
|
4182
4153
|
var syncBlockButtons = block => {
|
|
4183
4154
|
if (!block || !block.querySelectorAll) return
|
|
4184
|
-
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserEdit
|
|
4155
|
+
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserEdit')) syncEnabled(block, b)
|
|
4185
4156
|
}
|
|
4186
4157
|
var assignSeqs = (sid, cache, anchors) => {
|
|
4187
4158
|
const idx = cache && cache.idx
|
|
@@ -4281,12 +4252,15 @@ window.__ModuleLoader__.load({
|
|
|
4281
4252
|
/* keep {} */
|
|
4282
4253
|
}
|
|
4283
4254
|
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
4284
|
-
|
|
4255
|
+
// 0.23.0(深挖):先回填再报成功,回填失败要让用户知道。
|
|
4256
|
+
// 旧实现先 notifyDone(done.revert) 再 refillComposer 且丢弃返回值 →
|
|
4257
|
+
// 用户看到「已回滚」却拿到空输入框(0.14.0 踩过的同一类静默失败)。
|
|
4285
4258
|
// 0.17.0(冲突 C2):按钮路径原先漏了「立刻标遮蔽」,
|
|
4286
4259
|
// 导致刷新窗口内重复点击会拿已遮蔽的 seq 去 POST → 409。
|
|
4287
4260
|
markRowsShadowedFrom(row.seq)
|
|
4288
|
-
|
|
4289
|
-
|
|
4261
|
+
const filled = refillComposer(sid, row.seq)
|
|
4262
|
+
if (filled) notifyDone(__t('done.revert'))
|
|
4263
|
+
else notifyDone(__t('done.revertNoRefill'), 'warn')
|
|
4290
4264
|
emitChanged()
|
|
4291
4265
|
try {
|
|
4292
4266
|
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(sid)
|
|
@@ -4309,119 +4283,6 @@ window.__ModuleLoader__.load({
|
|
|
4309
4283
|
})
|
|
4310
4284
|
})
|
|
4311
4285
|
}
|
|
4312
|
-
/**
|
|
4313
|
-
* 0.12.0 用户消息「从此条分叉」:非破坏操作,源会话一字不动。
|
|
4314
|
-
*
|
|
4315
|
-
* opencode 语义 = 复制此条**之前**的对话到一个新会话,并把此条原文放回
|
|
4316
|
-
* 新会话的输入框,让用户改完再发。因此这里要三步:
|
|
4317
|
-
* 1. 解析 seq(点击当下可能还没打标 → 先 ensureAssign 再 fetchRows)
|
|
4318
|
-
* 2. 取该条用户消息的**原文**(列表只携带 snippet,长度会被截断)
|
|
4319
|
-
* 3. fork(boundary = seq - 1) → 把原文写进子会话草稿 → 打开子会话
|
|
4320
|
-
*/
|
|
4321
|
-
var runUserFork = (btn, block) => {
|
|
4322
|
-
const sid = __currentSessionId
|
|
4323
|
-
if (!sid) return
|
|
4324
|
-
btn.disabled = true
|
|
4325
|
-
Promise.resolve()
|
|
4326
|
-
.then(() => ensureAssign(sid))
|
|
4327
|
-
.then(() => fetchRows(sid))
|
|
4328
|
-
.then(async cache => {
|
|
4329
|
-
const rows = cache && cache.rows
|
|
4330
|
-
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
4331
|
-
const row = rows && rows.find(r => r.seq === seq)
|
|
4332
|
-
if (!row) {
|
|
4333
|
-
notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
|
|
4334
|
-
return
|
|
4335
|
-
}
|
|
4336
|
-
if (!(seq > 0)) {
|
|
4337
|
-
notifyDone(__t('slot.forkUnavailable'), 'warn')
|
|
4338
|
-
return
|
|
4339
|
-
}
|
|
4340
|
-
let text = typeof row.fullText === 'string' ? row.fullText : ''
|
|
4341
|
-
if (!text) {
|
|
4342
|
-
try {
|
|
4343
|
-
const res = await fetch(
|
|
4344
|
-
'/api/message-ops/text?sessionId=' + encodeURIComponent(bareSessionId(sid)) + '&seq=' + encodeURIComponent(seq),
|
|
4345
|
-
)
|
|
4346
|
-
const data = res.ok ? await res.json().catch(() => null) : null
|
|
4347
|
-
if (data && data.ok && typeof data.text === 'string') text = data.text
|
|
4348
|
-
} catch {
|
|
4349
|
-
/* 取全文失败:分叉照做,只是输入框留空 */
|
|
4350
|
-
}
|
|
4351
|
-
}
|
|
4352
|
-
const childId = await forkFromUserMessage(sid, seq, text, row.turnStartSeq)
|
|
4353
|
-
notifyDone(__t('slot.forkDone', { id: String(childId || '') }))
|
|
4354
|
-
if (childId) openSessionById(childId)
|
|
4355
|
-
})
|
|
4356
|
-
.catch(reason => {
|
|
4357
|
-
notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
4358
|
-
})
|
|
4359
|
-
.finally(() => {
|
|
4360
|
-
btn.disabled = false
|
|
4361
|
-
})
|
|
4362
|
-
}
|
|
4363
|
-
|
|
4364
|
-
var ensureBtn = block => {
|
|
4365
|
-
// 官方动作行(含 Copy):把按钮放到这一行里,与 Copy 同级
|
|
4366
|
-
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
4367
|
-
if (!host) {
|
|
4368
|
-
host = document.createElement('div')
|
|
4369
|
-
host.className = 'mopsUserActionsRow'
|
|
4370
|
-
block.appendChild(host)
|
|
4371
|
-
}
|
|
4372
|
-
let btn = host.querySelector('.mopsUserRevert')
|
|
4373
|
-
if (btn) return btn
|
|
4374
|
-
btn = document.createElement('button')
|
|
4375
|
-
btn.type = 'button'
|
|
4376
|
-
btn.className = 'mopsUserRevert'
|
|
4377
|
-
// 0.21.0:行内回滚按钮不经过面板确认框,隐私告知必须挂在这里(hover 可见)
|
|
4378
|
-
btn.title = __t('slot.revertPrivacyHint')
|
|
4379
|
-
btn.setAttribute('aria-label', __t('slot.revert'))
|
|
4380
|
-
btn.innerHTML =
|
|
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>'
|
|
4382
|
-
btn.addEventListener('click', e => {
|
|
4383
|
-
e.preventDefault()
|
|
4384
|
-
e.stopPropagation()
|
|
4385
|
-
if (btn.disabled) return
|
|
4386
|
-
runUserRevert(btn, block)
|
|
4387
|
-
})
|
|
4388
|
-
host.appendChild(btn)
|
|
4389
|
-
// 0.9.7(P2-1):新按钮按块的**当前**打标状态立刻同步一次。
|
|
4390
|
-
// 门控之后 assignSeqs 可能被跳过(签名未变),靠这里保证「宿主重建了
|
|
4391
|
-
// 动作行 → 按钮重新挂上」这种情况仍然是 disabled/title 正确的。
|
|
4392
|
-
syncEnabled(block, btn)
|
|
4393
|
-
return btn
|
|
4394
|
-
}
|
|
4395
|
-
|
|
4396
|
-
/** 0.12.0 分叉按钮:与回滚按钮**同一动作行**(opencode 把 fork 放在 copy/undo 同组)。 */
|
|
4397
|
-
var ensureForkBtn = block => {
|
|
4398
|
-
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
4399
|
-
if (!host) {
|
|
4400
|
-
host = document.createElement('div')
|
|
4401
|
-
host.className = 'mopsUserActionsRow'
|
|
4402
|
-
block.appendChild(host)
|
|
4403
|
-
}
|
|
4404
|
-
const existing = host.querySelector('.mopsUserFork')
|
|
4405
|
-
if (existing) return existing
|
|
4406
|
-
const btn = document.createElement('button')
|
|
4407
|
-
btn.type = 'button'
|
|
4408
|
-
btn.className = 'mopsUserFork'
|
|
4409
|
-
btn.title = __t('slot.forkHint')
|
|
4410
|
-
btn.setAttribute('aria-label', __t('slot.fork'))
|
|
4411
|
-
// 官方 IconBranchOutline16 的 1:1 路径(packages/client/ui-primitives/src/icons/index.tsx:149)
|
|
4412
|
-
btn.innerHTML =
|
|
4413
|
-
'<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="none"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M13.0762 1.37207C14.0846 1.37228 14.9021 2.19077 14.9023 3.19922C14.9022 4.20772 14.0847 5.02518 13.0762 5.02539C12.2967 5.02539 11.6325 4.53691 11.3701 3.84961H4.35547C4.79397 4.26458 5.15861 4.7644 5.41699 5.33496L7.10645 9.06738C7.88526 10.7875 9.55104 11.9228 11.4189 12.0371C11.7085 11.4109 12.3411 10.9756 13.0762 10.9756C14.0843 10.9759 14.9023 11.7936 14.9023 12.8018C14.9023 13.81 14.0843 14.6277 13.0762 14.6279C12.2534 14.6279 11.5574 14.0832 11.3291 13.335C8.9868 13.1879 6.89981 11.7612 5.92285 9.60352L4.23242 5.87109C3.67503 4.64033 2.44878 3.84961 1.09766 3.84961V2.54883C1.10665 2.54883 1.11601 2.54975 1.125 2.5498L11.3701 2.54883C11.6326 1.86151 12.2969 1.37207 13.0762 1.37207ZM13.0762 12.2764C12.7858 12.2764 12.5508 12.5114 12.5508 12.8018C12.5508 13.0921 12.7858 13.3281 13.0762 13.3281C13.3664 13.3279 13.6025 13.092 13.6025 12.8018C13.6025 12.5115 13.3664 12.2766 13.0762 12.2764ZM13.0762 2.67285C12.7855 2.67285 12.55 2.90861 12.5498 3.19922C12.5499 3.48987 12.7855 3.72559 13.0762 3.72559C13.3667 3.72538 13.6024 3.48975 13.6025 3.19922C13.6023 2.90874 13.3666 2.67306 13.0762 2.67285Z"/></svg>'
|
|
4414
|
-
btn.addEventListener('click', e => {
|
|
4415
|
-
e.preventDefault()
|
|
4416
|
-
e.stopPropagation()
|
|
4417
|
-
if (btn.disabled) return
|
|
4418
|
-
runUserFork(btn, block)
|
|
4419
|
-
})
|
|
4420
|
-
host.appendChild(btn)
|
|
4421
|
-
syncEnabled(block, btn)
|
|
4422
|
-
return btn
|
|
4423
|
-
}
|
|
4424
|
-
|
|
4425
4286
|
/**
|
|
4426
4287
|
* 0.20.0 铅笔编辑按钮:与回滚**同一动作行**,插在回滚与分叉之间。
|
|
4427
4288
|
*
|
|
@@ -4506,12 +4367,46 @@ window.__ModuleLoader__.load({
|
|
|
4506
4367
|
}
|
|
4507
4368
|
|
|
4508
4369
|
// 三个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),编辑居中,分叉最后(非破坏)。
|
|
4370
|
+
var ensureBtn = block => {
|
|
4371
|
+
// 官方动作行(含 Copy):把按钮放到这一行里,与 Copy 同级
|
|
4372
|
+
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
4373
|
+
if (!host) {
|
|
4374
|
+
host = document.createElement('div')
|
|
4375
|
+
host.className = 'mopsUserActionsRow'
|
|
4376
|
+
block.appendChild(host)
|
|
4377
|
+
}
|
|
4378
|
+
let btn = host.querySelector('.mopsUserRevert')
|
|
4379
|
+
if (btn) return btn
|
|
4380
|
+
btn = document.createElement('button')
|
|
4381
|
+
btn.type = 'button'
|
|
4382
|
+
btn.className = 'mopsUserRevert'
|
|
4383
|
+
// 0.21.0:行内回滚按钮不经过面板确认框,隐私告知必须挂在这里(hover 可见)
|
|
4384
|
+
btn.title = __t('slot.revertPrivacyHint')
|
|
4385
|
+
btn.setAttribute('aria-label', __t('slot.revert'))
|
|
4386
|
+
btn.innerHTML =
|
|
4387
|
+
'<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>'
|
|
4388
|
+
btn.addEventListener('click', e => {
|
|
4389
|
+
e.preventDefault()
|
|
4390
|
+
e.stopPropagation()
|
|
4391
|
+
if (btn.disabled) return
|
|
4392
|
+
runUserRevert(btn, block)
|
|
4393
|
+
})
|
|
4394
|
+
host.appendChild(btn)
|
|
4395
|
+
// 0.9.7(P2-1):新按钮按块的**当前**打标状态立刻同步一次。
|
|
4396
|
+
// 门控之后 assignSeqs 可能被跳过(签名未变),靠这里保证「宿主重建了
|
|
4397
|
+
// 动作行 → 按钮重新挂上」这种情况仍然是 disabled/title 正确的。
|
|
4398
|
+
syncEnabled(block, btn)
|
|
4399
|
+
return btn
|
|
4400
|
+
}
|
|
4401
|
+
|
|
4509
4402
|
var ensureUserActions = block => {
|
|
4510
4403
|
// 0.20.0:铅笔回归,但语义变了 —— 独立编辑框 + 点「发送并回撤」才写,
|
|
4511
4404
|
// 不再是 0.18.0 那种「只回填 composer」的伪编辑。
|
|
4405
|
+
// 0.23.0:行内 fork 按钮已删 —— dsh 官方在 AI 回合尾部已有
|
|
4406
|
+
// sessions.fork(conversation.chat.assistant-actions / TurnTailNodeView)。
|
|
4407
|
+
// 分叉能力统一由官方按钮 + 面板 branch(同样走官方 sessions.fork)承担。
|
|
4512
4408
|
ensureBtn(block)
|
|
4513
4409
|
ensureEditBtn(block)
|
|
4514
|
-
ensureForkBtn(block)
|
|
4515
4410
|
}
|
|
4516
4411
|
// 0.9.7(P0-2 读合并):把 150/700/1600ms 三档并成**一次**真网络请求,
|
|
4517
4412
|
// 落点 = 本 burst 第一档 + 1500ms ≈ 原来的 1600ms 那一档。
|
|
@@ -4553,7 +4448,6 @@ window.__ModuleLoader__.load({
|
|
|
4553
4448
|
if (!sid) return
|
|
4554
4449
|
const blocks = userAnchors()
|
|
4555
4450
|
for (const b of blocks) ensureUserActions(b)
|
|
4556
|
-
suppressHostBranch()
|
|
4557
4451
|
// 0.9.1:**始终**刷新(原先只在按钮未打标时刷)——
|
|
4558
4452
|
// 打标后 transcript 再变化(openSession 重建 / 分页 / restore 重放)
|
|
4559
4453
|
// 就再也不会重算隐藏,导致「界面停在旧状态,必须重载页面才对」。
|
|
@@ -4562,33 +4456,6 @@ window.__ModuleLoader__.load({
|
|
|
4562
4456
|
/* 注入失败不影响会话 */
|
|
4563
4457
|
}
|
|
4564
4458
|
}
|
|
4565
|
-
/**
|
|
4566
|
-
* 0.12.0 隐藏官方 assistant turn-tail 上的 branch 按钮。
|
|
4567
|
-
*
|
|
4568
|
-
* 产品决定:分叉只属于**用户消息**(opencode 语义 —— fork 的目的是「这句话说错了,
|
|
4569
|
-
* 拿回输入框重说」,AI 消息没有可回填的原文,分叉出去只会得到一个半截对话)。
|
|
4570
|
-
* 官方把 branch 画在 MessageIconActions 里,与 copy 同一行;官方没有开关
|
|
4571
|
-
* (ui-chat 的 Config 只有折叠/性能/链接几项),所以只能在渲染层隐藏。
|
|
4572
|
-
*
|
|
4573
|
-
* 识别方式不用 aria-label(8 种语言各不同),也不用哈希 class,而用
|
|
4574
|
-
* **图标路径前缀**:官方 IconBranchOutline16 的 d 是固定字符串
|
|
4575
|
-
* (packages/client/ui-primitives/src/icons/index.tsx:149)。作用域限定在
|
|
4576
|
-
* `[data-turn-tail]`(官方 TurnTailNodeView 渲染的稳定属性),
|
|
4577
|
-
* 并排除我们自己注入的 .mopsUserFork(它复用同一 path)。
|
|
4578
|
-
*/
|
|
4579
|
-
var suppressHostBranch = () => {
|
|
4580
|
-
let hidden = 0
|
|
4581
|
-
for (const btn of document.querySelectorAll('[data-turn-tail] button')) {
|
|
4582
|
-
if (!isHostBranchButton(btn)) continue
|
|
4583
|
-
hidden++
|
|
4584
|
-
if (btn.getAttribute('data-mops-host-branch') !== 'hidden') {
|
|
4585
|
-
btn.setAttribute('data-mops-host-branch', 'hidden')
|
|
4586
|
-
btn.style.display = 'none'
|
|
4587
|
-
}
|
|
4588
|
-
}
|
|
4589
|
-
return hidden
|
|
4590
|
-
}
|
|
4591
|
-
|
|
4592
4459
|
// 触发:hover / 滚动 / DOM 变化 / 变更事件
|
|
4593
4460
|
document.addEventListener(
|
|
4594
4461
|
'mouseover',
|
|
@@ -4700,11 +4567,11 @@ window.__ModuleLoader__.load({
|
|
|
4700
4567
|
// (宿主 .xzv4MW_actions 已定 height:28px,改小会撑裂行高)。
|
|
4701
4568
|
// · 无淡入动画(opencode 源码注释明写 "Hover actions show and hide
|
|
4702
4569
|
// at once, without a fade")—— 显隐完全交给宿主 [data-actions-reveal]。
|
|
4703
|
-
'.mopsUserRevert,.mopsUserEdit
|
|
4704
|
-
'.mopsUserRevert svg,.mopsUserEdit svg
|
|
4705
|
-
'.mopsUserRevert:hover,.mopsUserEdit:hover
|
|
4706
|
-
'.mopsUserRevert:disabled,.mopsUserEdit:disabled
|
|
4707
|
-
'.mopsUserRevert:focus-visible,.mopsUserEdit:focus-visible
|
|
4570
|
+
'.mopsUserRevert,.mopsUserEdit{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:4px;background:transparent;color:var(--dsw-alias-label-tertiary,#808080);cursor:pointer;padding:0;flex:none}',
|
|
4571
|
+
'.mopsUserRevert svg,.mopsUserEdit svg{width:14px;height:14px;display:block}',
|
|
4572
|
+
'.mopsUserRevert:hover,.mopsUserEdit:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
4573
|
+
'.mopsUserRevert:disabled,.mopsUserEdit:disabled{opacity:.4;cursor:default;background:transparent}',
|
|
4574
|
+
'.mopsUserRevert:focus-visible,.mopsUserEdit:focus-visible{outline:2px solid var(--dsw-alias-border-l2,#b8b8b8);outline-offset:1px}',
|
|
4708
4575
|
// 0.18.0:用户反馈「点时间图标也会回撤」——根因不是绑定错误,而是
|
|
4709
4576
|
// 我们的按钮被 appendChild 到宿主 .actions 行末尾,而该行在
|
|
4710
4577
|
// data-clock="start"(用户消息)时第一个子元素就是**时间文本**:
|
|
@@ -5237,10 +5104,7 @@ window.__ModuleLoader__.load({
|
|
|
5237
5104
|
__test: {
|
|
5238
5105
|
activityTransition,
|
|
5239
5106
|
forkBoundaryBefore,
|
|
5240
|
-
isHostBranchButton,
|
|
5241
5107
|
writeSessionDraft,
|
|
5242
|
-
HOST_BRANCH_ICON_ID,
|
|
5243
|
-
HOST_BRANCH_D_PREFIX,
|
|
5244
5108
|
// 0.20.0:编辑并重发的编排层(可注入 deps 真执行断言时序)
|
|
5245
5109
|
sendEditAndRevert,
|
|
5246
5110
|
submitEditedText,
|
package/src/ops-core.js
CHANGED
|
@@ -21,7 +21,7 @@ import { OpsError } from './session-file.js'
|
|
|
21
21
|
* @module dsh-message-ops/ops-core
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import { readReplaceOp, messageText, computeShadowed } from './session-file.js'
|
|
24
|
+
import { readReplaceOp, messageText, messageTextFull, computeShadowed } from './session-file.js'
|
|
25
25
|
|
|
26
26
|
// messageText 的单点实现在 session-file.js(listMessages 同用);此处转出保持
|
|
27
27
|
// 既有导入面兼容(ops-core 的 messageText 调用方不受影响)。
|
|
@@ -447,7 +447,11 @@ export function planRestore(events, restoreSeq, upToSeq, excludeSeqs) {
|
|
|
447
447
|
if (!e || typeof e.seq !== 'number' || e.seq < startSeq || e.seq > cap) continue
|
|
448
448
|
if (e.type === 'user/message' || e.type === 'assistant/message') {
|
|
449
449
|
if (excluded && excluded.has(e.seq)) continue
|
|
450
|
-
|
|
450
|
+
// 0.23.0(深挖 S-1):重放必须取**全段**。宿主把长文本拆成多个 content
|
|
451
|
+
// 段(compaction checkpoint 实测 321+7954+20 三段),旧实现用 messageText
|
|
452
|
+
// 只取首段 → 恢复副本永久丢掉后半段。实测 898 条多段消息受影响、
|
|
453
|
+
// 累计丢 175 万字符,其中 133 条是真人输入。
|
|
454
|
+
const text = messageTextFull(e)
|
|
451
455
|
if (!text.trim()) {
|
|
452
456
|
skipped++
|
|
453
457
|
continue
|