@240xu/dsh-message-ops 0.13.1 → 0.16.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 +100 -0
- package/package.json +1 -1
- package/src/client.js +88 -18
- package/src/index.js +31 -0
- package/src/ops-core.js +17 -0
- package/src/session-file.js +30 -3
package/README.md
CHANGED
|
@@ -891,6 +891,106 @@ 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.16.0 · 视觉对齐 opencode(有依据、有取舍)
|
|
895
|
+
|
|
896
|
+
**方法**:不是照着印象改,而是拉了 `sst/opencode` 源码
|
|
897
|
+
(commit `82229fb7`,version 2.2.5,sparse-checkout 取 `packages/app/src` +
|
|
898
|
+
`packages/session-ui` + `packages/client/src`),逐条读 CSS 与组件,产出
|
|
899
|
+
`design-demos/opencode-visual-spec.md`(912 行,64 处 `证据:` 标注)。
|
|
900
|
+
|
|
901
|
+
**三个反直觉的实证结论**(都做了反向验证):
|
|
902
|
+
|
|
903
|
+
1. **opencode 没有「悬停浮出一排按钮」** —— 只有 1 枚 `chevron-down` 按钮
|
|
904
|
+
(20×20,radius 4px,图标 14px,`ghost-muted` #808080),点击弹出下拉菜单,
|
|
905
|
+
copy / fork / revert 全在菜单项里。
|
|
906
|
+
2. **revert 后没有任何「变灰 / 删除线 / 半透明」** —— 是**投影层直接过滤**
|
|
907
|
+
(`message.id < revertMessageID`),被裁的行根本不进虚拟列表。
|
|
908
|
+
全仓 `data-reverted` / `isReverted` 零命中。
|
|
909
|
+
3. **没有消息级 edit,也没有「已回滚」常驻提示** —— 只有 5s toast 带 Undo
|
|
910
|
+
+ `/undo` `/redo` 斜杠命令。
|
|
911
|
+
|
|
912
|
+
**本次改动(按用户拍板:保留横排按钮与 dock,只对齐视觉规格)**:
|
|
913
|
+
|
|
914
|
+
| 项 | 改前 | 改后 | 依据 |
|
|
915
|
+
|---|---|---|---|
|
|
916
|
+
| 图标尺寸 | 15px | **14px** | opencode `size="small"` |
|
|
917
|
+
| 按钮圆角 | 6px(宿主默认) | **4px** | `icon-button.css:29-33` |
|
|
918
|
+
| 图标颜色 | `label-tertiary`(#9a9aa0) | **#808080** | `--v2-icon-icon-muted` |
|
|
919
|
+
| hover 前景 | 不变色 | **转 `label-secondary`** | `icon-button.css:103-106` |
|
|
920
|
+
| 焦点可见 | 无 | **`focus-visible` 2px outline** | 无障碍补齐 |
|
|
921
|
+
| 淡入动画 | 宿主 80ms | **保持 80ms**(不改) | opencode 源码注释明写 "without a fade";宿主 80ms 已足够短 |
|
|
922
|
+
|
|
923
|
+
**明确不改的(宿主约束,照抄反而更差)**:
|
|
924
|
+
|
|
925
|
+
- **20px 按钮尺寸做不到**:DSH 宿主动作行 `.xzv4MW_actions` 已定
|
|
926
|
+
`height: 28px`,插件内嵌按钮改 20px 会撑裂行高。只能对齐图标与颜色。
|
|
927
|
+
- **不改成 chevron 菜单**:用户明确要「fork 与回撤在同一位置」,改成菜单会推翻
|
|
928
|
+
这个诉求;且 DSH 无现成菜单浮层体系,要新建 `shell.overlay` 实现。
|
|
929
|
+
- **保留 RevertDock 与确认弹窗**:opencode 的 revert 是轻量 stage+redo,
|
|
930
|
+
DSH 是 append-only 遮蔽 + 需刷新生效,代价高得多;且 DSH 没有 `/redo`
|
|
931
|
+
那种便捷恢复入口,删了 dock 会让用户不知道如何恢复。
|
|
932
|
+
- **不引入 `--v2-*` token**:插件全部使用 `--dsw-alias-*`,深色模式自动跟随。
|
|
933
|
+
引入第二套 token 会出现双轨配色。
|
|
934
|
+
|
|
935
|
+
### 0.15.0 · 回滚要「像干净请求」:工具清单变更必须一起消失
|
|
936
|
+
|
|
937
|
+
用户原话:「我说的撤回,只是不显示我重新发起的请求,就像干净请求。」
|
|
938
|
+
|
|
939
|
+
现象:回滚一条用户消息后,主对话流里「新增了 N 个工具」那行**还在**;
|
|
940
|
+
供应商报错(`llm/retry`)相关的重试行也留着。
|
|
941
|
+
|
|
942
|
+
**根因(全部在宿主实际下发的 bundle 里取证,不是推测):**
|
|
943
|
+
|
|
944
|
+
```js
|
|
945
|
+
// 宿主 dsh-client-ui-chat:developerMessageDefinition
|
|
946
|
+
match: (event) => event.type === "developer/message" ? { ... } : null
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
对比 `user/message` 的 match:
|
|
950
|
+
|
|
951
|
+
```js
|
|
952
|
+
if (event.type === "user/message")
|
|
953
|
+
return isAppendSurfaceEvent(event) && !isCompactionCheckpoint(event) ? ... : null
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
**`user/message` 有 `isAppendSurfaceEvent` 这道闸,`developer/message` 没有。**
|
|
957
|
+
再加上 `isVisibleChatNode` 里对含 `tool-addition`/`tool-removal` 的 context 节点
|
|
958
|
+
**强制可见**:
|
|
959
|
+
|
|
960
|
+
```js
|
|
961
|
+
node.kind !== "context" || node.data.content.some(b =>
|
|
962
|
+
b.type === "tool-addition" || b.type === "tool-removal")
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
结果:surface replace 把工具清单变更事件正确遮蔽了(**模型上下文是干净的**),
|
|
966
|
+
但 UI 照样渲染那一行 —— 用户看到「回滚没撤回干净」。
|
|
967
|
+
|
|
968
|
+
**修法**(插件侧唯一抓手是渲染层遮蔽同步,宿主渲染器改不了):
|
|
969
|
+
|
|
970
|
+
1. `listMessages` 收录 `developer/message`(此前只收 user/assistant/system)。
|
|
971
|
+
不收 → 遮蔽状态传不到客户端 → `byMessageId` 查不到 → 调用方「保持可见」。
|
|
972
|
+
2. `textSegments` 把 `tool-addition`/`tool-removal` 渲染成 `+name`/`-name`。
|
|
973
|
+
不转 → snippet 为空串 → 被 rows 的 `r.sn` 过滤条件当无效行丢掉。
|
|
974
|
+
3. compact 投影补 `id`。客户端用 `<kindLen>:<kind><id>`(实测
|
|
975
|
+
`17:developer-message<uuid>`)拼 `data-chat-node-key` 反查 seq,
|
|
976
|
+
没有 id 这条链就断了。
|
|
977
|
+
|
|
978
|
+
实机验证(3096,真实会话 1530 行):
|
|
979
|
+
|
|
980
|
+
```
|
|
981
|
+
seq= 458 id=2a306c76-6 shadowed=true | +sidebar_open
|
|
982
|
+
seq= 471 id=deb0ed06-1 shadowed=true | -subagent_codex
|
|
983
|
+
seq= 552 id=b32cdc8b-8 shadowed=true | +subagent_codex
|
|
984
|
+
seq= 700 id=8ea41701-f shadowed=true | +import_chat
|
|
985
|
+
seq=3726 id=61b519dd-d shadowed=true | +browser_click
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
**没有做的(且不应该做)**:`llm/retry` / `assistant/attempt` 不是 surface 节点,
|
|
989
|
+
它们不进模型上下文,遮蔽它们没有语义意义。如果你在界面上看到重试痕迹,
|
|
990
|
+
那是宿主自己的 `model-retry` / `turn-error` 节点,不在本插件管辖范围。
|
|
991
|
+
|
|
992
|
+
新增 `test/developer-message-shadow.test.js`(6 条)。测试 292(288 pass / 4 skip)。
|
|
993
|
+
|
|
894
994
|
### 0.13.1 · 修第二轮对抗审查的两个 HIGH
|
|
895
995
|
|
|
896
996
|
**HIGH-1|隐藏官方 branch 按钮在 0.2.2-alpha.2 上 100% 无效。**
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -2540,7 +2540,24 @@ window.__ModuleLoader__.load({
|
|
|
2540
2540
|
function writeSessionDraft(childSessionId, text) {
|
|
2541
2541
|
try {
|
|
2542
2542
|
if (!childSessionId || typeof localStorage === 'undefined') return false
|
|
2543
|
-
|
|
2543
|
+
const key = FORK_SESSION_STORAGE_PREFIX + childSessionId
|
|
2544
|
+
// ⚠️ 必须**合并**,不能整体覆盖:同一个键里宿主还存着 `view` /
|
|
2545
|
+
// `viewRequest` 等会话视图偏好(见 dsh-client-ui-conversation 的
|
|
2546
|
+
// readConversationView / persist)。0.12.0 只写 `{draft}` 时,
|
|
2547
|
+
// fork 出的子会话恰好还没有偏好所以没暴露;0.14.0 的回填写在**正在用
|
|
2548
|
+
// 的会话**上,直接覆盖会静默清掉用户的视图选择。
|
|
2549
|
+
let base = {}
|
|
2550
|
+
try {
|
|
2551
|
+
const raw = localStorage.getItem(key)
|
|
2552
|
+
if (raw != null) {
|
|
2553
|
+
const parsed = JSON.parse(raw)
|
|
2554
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) base = parsed
|
|
2555
|
+
}
|
|
2556
|
+
} catch {
|
|
2557
|
+
/* 旧值不可解析 → 当作空对象重写(总比抛错好) */
|
|
2558
|
+
}
|
|
2559
|
+
const next = { ...base, draft: String(text || '') }
|
|
2560
|
+
localStorage.setItem(key, JSON.stringify(next))
|
|
2544
2561
|
return true
|
|
2545
2562
|
} catch (e) {
|
|
2546
2563
|
console.warn('[message-ops] writeSessionDraft failed:', e)
|
|
@@ -2911,8 +2928,20 @@ window.__ModuleLoader__.load({
|
|
|
2911
2928
|
// SessionRevert.commit() → revert:null → affordance 消失)。
|
|
2912
2929
|
// 我们是 append-only,marker 不会真消失,所以由服务端按
|
|
2913
2930
|
// 「marker 之后有无 source.kind==='user' 的真实输入」算出 committed。
|
|
2914
|
-
return (
|
|
2915
|
-
|
|
2931
|
+
return (
|
|
2932
|
+
(msgs || [])
|
|
2933
|
+
.filter(m => m.marker && m.sourceKind !== 'compact-checkpoint' && m.restoreComplete !== true && m.committed !== true)
|
|
2934
|
+
// 0.14.0:排掉「自噬 marker」—— 它的 replace 区间恰好覆盖**另一条 marker**
|
|
2935
|
+
// (典型是 `startSeq === endSeq === 前一条 marker 的 seq`,content 为空)。
|
|
2936
|
+
// 这种记录不是用户做过的回滚,是旧版 dock 拿 marker 当目标留下的残迹;
|
|
2937
|
+
// 列出来只会让用户点「恢复」再生成一条同样的垃圾。
|
|
2938
|
+
.filter(m => {
|
|
2939
|
+
const rng = m.range
|
|
2940
|
+
if (!rng || !Number.isSafeInteger(rng.startSeq)) return true
|
|
2941
|
+
if (rng.startSeq !== rng.endSeq) return true
|
|
2942
|
+
const target = (msgs || []).find(x => x && x.seq === rng.startSeq)
|
|
2943
|
+
return !(target && target.marker === true)
|
|
2944
|
+
})
|
|
2916
2945
|
)
|
|
2917
2946
|
}
|
|
2918
2947
|
|
|
@@ -3193,12 +3222,28 @@ window.__ModuleLoader__.load({
|
|
|
3193
3222
|
)
|
|
3194
3223
|
const dockRows = []
|
|
3195
3224
|
for (const mk of markers || []) {
|
|
3225
|
+
// 0.14.0(dock 文案修复):`mk.snippet` 是 **marker 自己**的正文 ——
|
|
3226
|
+
// 也就是「[消息回滚] 已回滚到 seq N…」这句拼接文案本身。
|
|
3227
|
+
// 用户看到「#3417 · [消息回滚] 已回滚到 seq 3410…」,点「恢复」后
|
|
3228
|
+
// 日志里又落一条遮蔽 marker 自己的空 replace(实测 5 次)。
|
|
3229
|
+
// 正确口径:这一行代表的是「被 marker 遮蔽的那段对话」,文案必须取自
|
|
3230
|
+
// range 区间里的真实内容;区间取不到才显示序号。
|
|
3231
|
+
const rng = mk.range && Number.isSafeInteger(mk.range.startSeq) ? mk.range : null
|
|
3232
|
+
// 预览文案必须描述「被遮蔽的那段」,不能是 marker 自己的 notice 文本。
|
|
3233
|
+
// 区间退化成单点且恰好是另一条 marker 时,这条 marker 是**冗余生成**的,
|
|
3234
|
+
// 直接标出来,别让用户以为它是一轮真实对话。
|
|
3235
|
+
const span = rng ? (rng.endSeq > rng.startSeq ? 'seq ' + rng.startSeq + '..' + rng.endSeq : '#' + rng.startSeq) : ''
|
|
3236
|
+
const rangeSnippet = mk.previewFirst || span
|
|
3196
3237
|
if (Array.isArray(mk.pendingTurns) && mk.pendingTurns.length > 0) {
|
|
3197
3238
|
for (const t of mk.pendingTurns) {
|
|
3198
|
-
dockRows.push({
|
|
3239
|
+
dockRows.push({
|
|
3240
|
+
seq: mk.seq,
|
|
3241
|
+
upTo: t.upTo,
|
|
3242
|
+
snippet: t.preview + (t.count > 1 ? ' (+' + (t.count - 1) + ')' : ''),
|
|
3243
|
+
})
|
|
3199
3244
|
}
|
|
3200
|
-
} else {
|
|
3201
|
-
dockRows.push({ seq: mk.seq, snippet:
|
|
3245
|
+
} else if (rng) {
|
|
3246
|
+
dockRows.push({ seq: mk.seq, snippet: rangeSnippet, markerRange: rng })
|
|
3202
3247
|
}
|
|
3203
3248
|
}
|
|
3204
3249
|
|
|
@@ -3768,7 +3813,7 @@ window.__ModuleLoader__.load({
|
|
|
3768
3813
|
btn.title = __t('slot.revert')
|
|
3769
3814
|
btn.setAttribute('aria-label', __t('slot.revert'))
|
|
3770
3815
|
btn.innerHTML =
|
|
3771
|
-
'<svg width="
|
|
3816
|
+
'<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>'
|
|
3772
3817
|
btn.addEventListener('click', e => {
|
|
3773
3818
|
e.preventDefault()
|
|
3774
3819
|
e.stopPropagation()
|
|
@@ -3800,7 +3845,7 @@ window.__ModuleLoader__.load({
|
|
|
3800
3845
|
btn.setAttribute('aria-label', __t('slot.fork'))
|
|
3801
3846
|
// 官方 IconBranchOutline16 的 1:1 路径(packages/client/ui-primitives/src/icons/index.tsx:149)
|
|
3802
3847
|
btn.innerHTML =
|
|
3803
|
-
'<svg width="
|
|
3848
|
+
'<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>'
|
|
3804
3849
|
btn.addEventListener('click', e => {
|
|
3805
3850
|
e.preventDefault()
|
|
3806
3851
|
e.stopPropagation()
|
|
@@ -3995,9 +4040,19 @@ window.__ModuleLoader__.load({
|
|
|
3995
4040
|
tag.textContent = [
|
|
3996
4041
|
// 不再用 absolute + :hover:按钮作为宿主动作行的子元素,
|
|
3997
4042
|
// 由宿主 [data-actions-reveal] 统一控制显隐(触屏也跟着宿主走)。
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4043
|
+
// 0.16.0 视觉对齐 opencode(sst/opencode @82229fb7 实测规格):
|
|
4044
|
+
// · 图标 14px / 描边 1.2(opencode IconButton size="small")
|
|
4045
|
+
// · 颜色 #808080(--v2-icon-icon-muted,映射到 DSH 的 label-tertiary)
|
|
4046
|
+
// · 圆角 4px(opencode)而非宿主默认 6px —— 按钮本身是我们注入的,
|
|
4047
|
+
// radius 可自由设置;只有 28px 尺寸受宿主动作行高度物理约束
|
|
4048
|
+
// (宿主 .xzv4MW_actions 已定 height:28px,改小会撑裂行高)。
|
|
4049
|
+
// · 无淡入动画(opencode 源码注释明写 "Hover actions show and hide
|
|
4050
|
+
// at once, without a fade")—— 显隐完全交给宿主 [data-actions-reveal]。
|
|
4051
|
+
'.mopsUserRevert,.mopsUserFork{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}',
|
|
4052
|
+
'.mopsUserRevert svg,.mopsUserFork svg{width:14px;height:14px;display:block}',
|
|
4053
|
+
'.mopsUserRevert:hover,.mopsUserFork:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
4054
|
+
'.mopsUserRevert:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default;background:transparent}',
|
|
4055
|
+
'.mopsUserRevert:focus-visible,.mopsUserFork:focus-visible{outline:2px solid var(--dsw-alias-border-l2,#b8b8b8);outline-offset:1px}',
|
|
4001
4056
|
'.mopsUserActionsRow{height:28px;display:flex;align-items:center;gap:8px;margin-left:-6px}',
|
|
4002
4057
|
'@media (hover:none){.mopsUserActionsRow{opacity:1}}',
|
|
4003
4058
|
].join('')
|
|
@@ -4226,17 +4281,32 @@ window.__ModuleLoader__.load({
|
|
|
4226
4281
|
if (bareSessionId(cache.sid) !== want) return false
|
|
4227
4282
|
const rows = cache.rows.filter(r => r && typeof r.seq === 'number' && r.seq <= boundarySeq && r.fullText)
|
|
4228
4283
|
if (!rows.length) return false
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
//
|
|
4232
|
-
|
|
4284
|
+
const text = rows[rows.length - 1].fullText
|
|
4285
|
+
// ── 0.14.0(回填失效修复)────────────────────────────────────────────
|
|
4286
|
+
// 旧实现:`__inputActions.setDraft(text)` + `persistDraft()`,然后调用方
|
|
4287
|
+
// **紧接着** `openSession(sid)` 重建整个会话视图。重建会卸载并重挂
|
|
4288
|
+
// 编辑器,新挂载走 `readConversationDraft(sid)` 从 localStorage 初始化 ——
|
|
4289
|
+
// 也就是说「回填」实际取决于 persistDraft 是否成功落盘,而再叠上
|
|
4290
|
+
// `bindDraftPersistence` 的时序(见 startEdit 处 MED-4 注释),失败时
|
|
4291
|
+
// 用户看到「已回滚」却拿不到原文。
|
|
4292
|
+
//
|
|
4293
|
+
// 唯一无竞态的路径:**直接写宿主的草稿存储键**(writeSessionDraft),
|
|
4294
|
+
// 与 fork 回填同一机制。它是 openSession 之后读到的权威值,不依赖
|
|
4295
|
+
// 编辑器是否已挂载、也不依赖 inputActions 此刻绑在哪个会话上。
|
|
4296
|
+
const persisted = writeSessionDraft(rawSid, text)
|
|
4297
|
+
// 再尽力更新活着的编辑器(视图没重建的路径,例如 dock 内联恢复)。
|
|
4298
|
+
let editorSet = false
|
|
4299
|
+
if (__inputActions && typeof __inputActions.setDraft === 'function') {
|
|
4233
4300
|
try {
|
|
4234
|
-
__inputActions.
|
|
4301
|
+
__inputActions.setDraft(text)
|
|
4302
|
+
editorSet = true
|
|
4235
4303
|
} catch (e) {
|
|
4236
|
-
console.warn('[message-ops]
|
|
4304
|
+
console.warn('[message-ops] setDraft failed:', e)
|
|
4237
4305
|
}
|
|
4238
4306
|
}
|
|
4239
|
-
|
|
4307
|
+
// 诚实返回:落盘成功(openSession 后必能读到)或活着编辑器已更新,任一即为真。
|
|
4308
|
+
// 不再用 `|| true` —— 那会让调用方永远看不到失败。
|
|
4309
|
+
return persisted || editorSet
|
|
4240
4310
|
} catch (e) {
|
|
4241
4311
|
// 原来这里 `catch {}` 完全静默 —— 失败了连痕迹都没有,排查时看不到
|
|
4242
4312
|
console.warn('[message-ops] setDraft failed:', e)
|
package/src/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
messageTextFull,
|
|
20
20
|
turnBounds,
|
|
21
21
|
markCommitted,
|
|
22
|
+
readReplaceOp,
|
|
22
23
|
} from './session-file.js'
|
|
23
24
|
import {
|
|
24
25
|
restoreNoticeText,
|
|
@@ -516,6 +517,20 @@ async function buildDerived(logPath) {
|
|
|
516
517
|
continue
|
|
517
518
|
}
|
|
518
519
|
m.restoreComplete = prog.complete
|
|
520
|
+
// 0.14.0(dock 目标修复):把 marker 遮蔽的**区间**暴露出去。
|
|
521
|
+
//
|
|
522
|
+
// 旧实现让 dock 拿 `mk.seq`(marker **自己**的 seq)去调 /restore。而
|
|
523
|
+
// opsRestore 的第一件事是 `planRestore(events, restoreSeq, ...)` —— 它要求
|
|
524
|
+
// `restoreSeq` 本身是**带 replace 区间的那条 marker**,于是语义正确;
|
|
525
|
+
// 但 dock 同时把 `mk.seq` 当"要恢复到哪"展示给用户、还在 pendingTurns 里
|
|
526
|
+
// 用 `mk.seq` 拼 rowKey —— 一旦这一行代表的是"已提交过的旧 marker"或
|
|
527
|
+
// 空内容的合成 marker,用户点下去就会把**另一条 marker 自己**遮蔽掉,
|
|
528
|
+
// 产生一条新的、content 为空的 replace 记录(实测 seq 3424/3658/3689/
|
|
529
|
+
// 3721/3746 全是这么来的)。
|
|
530
|
+
//
|
|
531
|
+
// 正向修法:range 是 marker 的语义本体("我遮蔽了谁"),dock 只该用它。
|
|
532
|
+
const range = readReplaceOp(events.find(x => x && x.seq === m.seq) || null)
|
|
533
|
+
if (range) m.range = range
|
|
519
534
|
m.pendingTurns = pendingRestoreTurnsFromIndex(restoreIndex, m.seq, prog).map(t => ({
|
|
520
535
|
upTo: t.seqs[t.seqs.length - 1],
|
|
521
536
|
count: t.seqs.length,
|
|
@@ -673,6 +688,22 @@ async function opsList(targetCtx, sessionId, opts = {}) {
|
|
|
673
688
|
// 客户端据此算 fork 边界 = turnStartSeq - 1。只带这一个字段:turn/step
|
|
674
689
|
// 属于「重」字段,面板的虚拟行用不到(详见 compact 的取舍)。
|
|
675
690
|
turnStartSeq: m.turnStartSeq ?? null,
|
|
691
|
+
// 0.14.0(dock 目标修复):客户端必须能识别「这行是 marker」并拿到它
|
|
692
|
+
// 遮蔽的区间。旧 compact 只给 role/snippet,于是 dock 只能拿 marker
|
|
693
|
+
// **自己的** seq 当恢复目标、也只能拿 marker 自己的文案当预览 ——
|
|
694
|
+
// 用户看到「#3417 · [消息回滚] 已回滚到 seq 3410…」,点恢复又把 marker
|
|
695
|
+
// 自己遮蔽一次(实测 5 条空 replace)。
|
|
696
|
+
// 0.15.0:必须带 id —— 客户端用 `<kindLen>:<kind><id>` 拼 data-chat-node-key
|
|
697
|
+
// 反查 seq(seqOfNodeKey)。developer/message(工具清单变更)的遮蔽同步
|
|
698
|
+
// 全靠这条链:没有 id → byMessageId 查不到 → 调用方「保持可见」→
|
|
699
|
+
// 宿主那行「+49 tools」在回滚后照样显示。
|
|
700
|
+
id: m.id ?? null,
|
|
701
|
+
marker: m.marker === true,
|
|
702
|
+
range: m.range ?? null,
|
|
703
|
+
// 0.14.0:dock 的 activeMarkers 判据就是这两个字段 —— 不投影出去,
|
|
704
|
+
// 客户端拿到 undefined 会把**已恢复完毕**的 marker 继续列在待恢复列表里。
|
|
705
|
+
restoreComplete: m.restoreComplete === true,
|
|
706
|
+
committed: m.committed === true,
|
|
676
707
|
}))
|
|
677
708
|
: messages
|
|
678
709
|
|
package/src/ops-core.js
CHANGED
|
@@ -30,6 +30,18 @@ export { messageText }
|
|
|
30
30
|
/** 带语义状态码的操作错误(单点已迁至 session-file.js,此处仅转出)。 */
|
|
31
31
|
|
|
32
32
|
/** planRevert:回撤语义 = 遮蔽 targetSeq 及其之后全部可见节点(连续到末尾)。 */
|
|
33
|
+
/**
|
|
34
|
+
* 该 seq 是否是一条**回撤/删除 marker**(surfaceOp=replace 的 system/message)?
|
|
35
|
+
*
|
|
36
|
+
* 0.14.0 护栏:marker 是账本,不是对话。允许拿 marker 当回滚目标会产生一种
|
|
37
|
+
* 自噬记录 —— 新 marker 遮蔽旧 marker,`content` 为空、`startSeq===endSeq`,
|
|
38
|
+
* 界面上表现为「恢复之后又多出一条『回滚后的节点』」。实测语料里已经出现过
|
|
39
|
+
* 5 次(seq 3424/3658/3689/3721/3746),全部由 dock 用 `mk.seq` 当目标造成。
|
|
40
|
+
*/
|
|
41
|
+
export function isMarkerEvent(e) {
|
|
42
|
+
return !!e && e.type === 'system/message' && readReplaceOp(e) !== null
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
export function planRevert(surface, targetSeq) {
|
|
34
46
|
const nodes = surface && Array.isArray(surface.nodes) ? surface.nodes : []
|
|
35
47
|
const startIdx = nodes.indexOf(targetSeq)
|
|
@@ -985,6 +997,11 @@ export function diskVisibleNodes(events) {
|
|
|
985
997
|
|
|
986
998
|
/** 磁盘版 planRevert:target 必须可见,遮蔽 target 之后(含)全部可见节点。 */
|
|
987
999
|
export function planRevertFromEvents(events, targetSeq) {
|
|
1000
|
+
// 0.14.0 护栏:marker 不是对话,不能被回滚(否则产生自噬的空 replace 记录)。
|
|
1001
|
+
const targetEvent = (events ?? []).find(e => e && e.seq === targetSeq)
|
|
1002
|
+
if (isMarkerEvent(targetEvent)) {
|
|
1003
|
+
throw new OpsError(`seq ${targetSeq} is a revert/delete marker, not a message — restore it instead of reverting it`, 409)
|
|
1004
|
+
}
|
|
988
1005
|
// 目标用「消息」集合(回滚对象是消息),溯源用「全部 surface」集合(0.8.2 修正)
|
|
989
1006
|
const nodes = diskVisibleNodes(events)
|
|
990
1007
|
const startIdx = nodes.indexOf(targetSeq)
|
package/src/session-file.js
CHANGED
|
@@ -34,6 +34,11 @@ function textSegments(e) {
|
|
|
34
34
|
const out = []
|
|
35
35
|
for (const c of content) {
|
|
36
36
|
if (c && c.type === 'text' && typeof c.text === 'string' && c.text.trim()) out.push(c.text)
|
|
37
|
+
// 0.15.0:developer/message 的 tool-registry 变更块不是 text,但它是
|
|
38
|
+
// **surface 节点**(会进模型上下文),必须给它一个可读摘要 —— 否则
|
|
39
|
+
// listMessages 拿到空串、snippet 为空,客户端 rows/索引会把它当无效行丢掉。
|
|
40
|
+
else if (c && c.type === 'tool-addition' && typeof c.toolName === 'string') out.push('+' + c.toolName)
|
|
41
|
+
else if (c && c.type === 'tool-removal' && typeof c.toolName === 'string') out.push('-' + c.toolName)
|
|
37
42
|
}
|
|
38
43
|
return out
|
|
39
44
|
}
|
|
@@ -315,7 +320,21 @@ export function listMessages(events) {
|
|
|
315
320
|
const messages = []
|
|
316
321
|
for (const e of events) {
|
|
317
322
|
if (!e || typeof e.seq !== 'number') continue
|
|
318
|
-
|
|
323
|
+
// 0.15.0:把 developer/message 也收进来。
|
|
324
|
+
//
|
|
325
|
+
// 为什么必须收:宿主的 `developerMessageDefinition.match` 只看
|
|
326
|
+
// `event.type === 'developer/message'`,**不检查 surface 遮蔽状态**
|
|
327
|
+
// (对比 user/message 的 match 有 `isAppendSurfaceEvent(event)` 这道闸)。
|
|
328
|
+
// 而 `isVisibleChatNode` 又对带 tool-addition/tool-removal 的 context 节点
|
|
329
|
+
// **强制可见**。结果:回滚时工具清单变更被 surface replace 正确遮蔽了
|
|
330
|
+
// (模型上下文干净),但界面上那行「+49 tools」照样渲染 —— 用户看到的就是
|
|
331
|
+
// 「回滚没撤回干净」。
|
|
332
|
+
//
|
|
333
|
+
// 我们没法改宿主渲染器,但插件本来就在做渲染层的遮蔽同步
|
|
334
|
+
// (installUserRevertInjector 按 data-chat-node-key 精确查表藏行)。
|
|
335
|
+
// 前提是这些事件必须先出现在我们的消息列表里、并带上 id,否则
|
|
336
|
+
// byMessageId 查不到 → seqOfNodeKey 返回 null → 调用方「保持可见」。
|
|
337
|
+
if (e.type === 'user/message' || e.type === 'assistant/message' || e.type === 'system/message' || e.type === 'developer/message') {
|
|
319
338
|
const text = messageText(e)
|
|
320
339
|
const msg = e.data && e.data.message
|
|
321
340
|
// id:宿主持久化的消息身份(user 在 data.id、assistant 在 data.message.id),
|
|
@@ -325,8 +344,16 @@ export function listMessages(events) {
|
|
|
325
344
|
messages.push({
|
|
326
345
|
seq: e.seq,
|
|
327
346
|
type: e.type,
|
|
328
|
-
role:
|
|
329
|
-
|
|
347
|
+
role:
|
|
348
|
+
(msg && msg.role) ||
|
|
349
|
+
(e.type === 'user/message'
|
|
350
|
+
? 'user'
|
|
351
|
+
: e.type === 'assistant/message'
|
|
352
|
+
? 'assistant'
|
|
353
|
+
: e.type === 'developer/message'
|
|
354
|
+
? 'developer'
|
|
355
|
+
: 'system'),
|
|
356
|
+
id: (msg && msg.id) || (e.data && e.data.id) || null,
|
|
330
357
|
marker: isReplaceMarker,
|
|
331
358
|
snippet: text.replace(/\s+/g, ' ').trim().slice(0, 160),
|
|
332
359
|
// 0.4.0 composer 回填:user 消息携带全文(revert 后 setDraft 原文)
|