dsh-message-rewind 1.2.1 → 1.2.3

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.en.md CHANGED
@@ -16,34 +16,34 @@ Edit and delete your own messages in [DeepSeek Harness](https://github.com/deeps
16
16
  | --- | --- |
17
17
  | Change a sent message | Click the pencil under your bubble, edit the text, then click **Save and resend**. Everything after that message is truncated and the conversation restarts from your edited text. |
18
18
  | Drop an out-of-line message | Click the trash icon and confirm. That message and every following turn are deleted. |
19
- | Restore files too | When deleting or editing, if that turn recorded file changes, the popover lets you choose **messages only** or **messages and files**. |
19
+ | Restore files too | When deleting or editing, if that turn recorded file changes and the record is complete, the popover lets you choose **messages only** or **messages and files**. |
20
20
  | Stay out of a running task | The action is refused while a turn is still running, so it never races the agent's writes. |
21
21
 
22
- Only messages you sent have these buttons. The **Copy** button is still there, in the same position.
22
+ Only your regular messages have these buttons; steering rows injected during a running turn do not offer edit/delete. The **Copy** button is still there, in the same position.
23
23
 
24
24
  ## Screenshots
25
25
 
26
26
  Your own messages get **edit / delete / copy** buttons under the bubble:
27
27
 
28
- <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/message-actions.png" alt="Edit, delete and copy buttons under a user message" width="760">
28
+ <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/message-actions-v1.2.1.png" alt="Edit, delete and copy buttons under a user message" width="760">
29
29
 
30
- The popover opens right under the button you clicked and points at it with a small arrow; click outside or press Esc to dismiss it. The editor reads the file changes recorded after that message as soon as it opens — collapsed into one **N file changes recorded** line unless you expand it — and a two-way switch decides whether files are restored too:
30
+ The popover opens right under the button you clicked and points at it with a small arrow; click outside or press Esc to dismiss it. The editor reads the file changes recorded after that message as soon as it opens — collapsed into one **N file changes recorded** line unless you expand it — and a two-way switch decides whether files are restored too. When the record is incomplete the switch is not offered, so only a messages-only rollback is possible:
31
31
 
32
32
  | Edit popover | Delete confirmation |
33
33
  | :---: | :---: |
34
- | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/edit-dialog.png" alt="Edit popover: file changes collapse to one line, rollback scope is a two-way switch" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/delete-dialog.png" alt="Delete confirmation: a one-line confirm when no files changed" width="360"> |
34
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/edit-dialog-v1.2.1.png" alt="Edit popover: file changes collapse to one line, rollback scope is a two-way switch" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/delete-dialog-v1.2.1.png" alt="Delete confirmation: a one-line confirm when no files changed" width="360"> |
35
35
 
36
36
  The popover follows its button: it flips above when there is no room below, narrows to the screen width on small viewports, and keeps the same layering in the light theme:
37
37
 
38
38
  | Flips above near the bottom | Narrow screen (390px) | Light theme |
39
39
  | :---: | :---: | :---: |
40
- | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-flip.png" alt="Popover flipped above the button, arrow pointing down at it" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-narrow.png" alt="Popover narrowed to a 390px viewport" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-light.png" alt="Delete popover in the light theme" width="240"> |
40
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-flip-v1.2.1.png" alt="Popover flipped above the button, arrow pointing down at it" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-narrow-v1.2.1.png" alt="Popover narrowed to a 390px viewport" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-light-v1.2.1.png" alt="Delete popover in the light theme" width="240"> |
41
41
 
42
- Snapshot and Git-worktree limits are shown in the popover itself, not after a failed operation.
42
+ When file changes were recorded, snapshot and Git-worktree limits are shown in the popover itself, not after a failed operation.
43
43
 
44
44
  ## Install
45
45
 
46
- Requires DSH 0.2.1-rc.3 or newer (0.2.x) and Node.js ≥ 20; verified on 0.2.1-rc.5. DSH validates `engines.dsh` at startup and refuses to load the plugin on an older host.
46
+ Requires DSH 0.2.2-rc.1 or newer (0.2.x) and Node.js ≥ 20; verified on 0.2.2-rc.1. DSH validates `engines.dsh` at startup and refuses to load the plugin on an older host.
47
47
 
48
48
  ### From npm (recommended)
49
49
 
@@ -64,7 +64,7 @@ If you prefer editing the profile yourself, the manual route is the same three s
64
64
  ```json
65
65
  {
66
66
  "dependencies": {
67
- "dsh-message-rewind": "^1.2.0"
67
+ "dsh-message-rewind": "^1.2.3"
68
68
  }
69
69
  }
70
70
  ```
@@ -99,12 +99,12 @@ The DSH startup log lists `message-rewind` as active. Refresh the page and your
99
99
 
100
100
  1. Click the pencil → a popover opens under the button; change the text and click **Save and resend**.
101
101
  2. Click the trash icon → click **Delete** to remove that message and every following turn.
102
- 3. The popover reads the file changes recorded after that message as soon as it opens and keeps them collapsed into one line; when files changed it also offers a two-way **Rollback scope**:
102
+ 3. The popover reads the file changes recorded after that message as soon as it opens and keeps them collapsed into one line; when files changed and their record is complete it also offers a two-way **Rollback scope**:
103
103
  - **Messages only** (default) — leave files untouched;
104
104
  - **Messages + files** — restore files to their content before that message;
105
105
  - pick the scope, then click **Save and resend** or **Delete**.
106
106
 
107
- Lost snapshots, queued prompts, and non-Git workspaces are called out in one-line notes inside the popover.
107
+ Lost or truncated snapshots, queued prompts, and non-Git workspaces are called out in one-line notes inside the popover.
108
108
 
109
109
  ## File rollback: what can and cannot be restored
110
110
 
@@ -115,15 +115,17 @@ Lost snapshots, queued prompts, and non-Git workspaces are called out in one-lin
115
115
  | Situation | Result |
116
116
  | --- | --- |
117
117
  | Binary file | Cannot be restored (only text diffs are recorded) |
118
+ | A file exceeds the recorder's text size limit | No content was kept to compare, so it cannot be restored |
118
119
  | Workspace is not a Git repository and the file was changed by a shell command | Not recorded, so it cannot be restored. Run `git init` in that directory to record everything. |
119
- | Session restarted or released, so earlier snapshots expired | You are told some snapshots are unavailable; messages-only rollback still works |
120
+ | A turn changed more files than the record cap (500 by default) | The record is truncated, so the snapshot counts as incomplete and only messages can be rolled back |
121
+ | Session restarted or released, so earlier snapshots expired | You are told the snapshot is unavailable or the record was truncated; messages-only rollback still works |
120
122
  | The file was changed again after being recorded (by you or another tool) | Rollback is **refused** rather than overwriting your later changes |
121
123
  | The conversation has no workspace | Messages-only rollback |
122
124
 
123
125
  ## FAQ
124
126
 
125
127
  **Q: Does the sidebar get an extra conversation after a rollback?**
126
- No — there is always just one conversation with the same name. The underlying session ID does change, though: DSH session logs are append-only and have no "delete a middle chunk" API, so the plugin forks a truncated branch, archives the original out of the sidebar, and deletes its log directory. If you referenced that session ID elsewhere, fetch it again.
128
+ No — there is always just one conversation, and its title normally carries over. The underlying session ID does change, though: DSH session logs are append-only and have no "delete a middle chunk" API, so the plugin forks a truncated branch, archives the original out of the sidebar, and deletes its log directory. If you referenced that session ID elsewhere, fetch it again. When the first message is deleted, the replacement is a new conversation that has not been titled yet, so it may show the default title.
127
129
 
128
130
  **Q: Can the original record be recovered?**
129
131
  Normally it is deleted. Only when its log directory is still held open and cannot be removed does the original stay in the archive.
@@ -131,8 +133,8 @@ Normally it is deleted. Only when its log directory is still held open and canno
131
133
  **Q: Why can't messages with attachments be edited?**
132
134
  Attachments are stored as part of the message content, and editing only supports plain-text messages. Messages with attachments can still be deleted.
133
135
 
134
- **Q: The button says a turn is still running?**
135
- Stop the running task first. Also note that queued prompts are discarded together with the deleted record — the popover warns you about this.
136
+ **Q: The edit and delete buttons are greyed out with a "turn is still running" note?**
137
+ Stop the running task first; the buttons stay disabled until the turn ends. Also note that queued prompts are discarded together with the deleted record — the popover warns you about this.
136
138
 
137
139
  **Q: I don't see the buttons.**
138
140
  Check that the plugin is enabled under **Settings → Plugins** and that you refreshed the page. Only messages you sent have these buttons.
package/README.md CHANGED
@@ -18,34 +18,34 @@
18
18
  | --- | --- |
19
19
  | 改掉已发送的消息 | 点消息气泡下方的铅笔,改完点「保存并重发」,这条消息之后的内容会被截断,然后按你改后的内容重新开始 |
20
20
  | 撤掉一条越界的消息 | 点垃圾桶,确认后这条消息连同它之后的所有对话一起删除 |
21
- | 连文件一起还原 | 删除/编辑时,如果那一轮动过文件,按钮下方的小窗会让你选「只回滚消息」还是「连文件一起回滚」 |
21
+ | 连文件一起还原 | 删除/编辑时,如果那一轮动过文件且改动记录完整,按钮下方的小窗会让你选「只回滚消息」还是「连文件一起回滚」 |
22
22
  | 不打扰正在跑的任务 | 有未结束的轮次时直接拒绝操作,不会和正在执行的 turn 抢写 |
23
23
 
24
- 只有你自己发出的消息才有这两个按钮;「复制」按钮仍在,位置不变。
24
+ 只有你自己发出的普通消息才有这两个按钮;一轮运行中被追加的 steering 行不提供编辑/删除。「复制」按钮仍在,位置不变。
25
25
 
26
26
  ## 界面
27
27
 
28
28
  自己发出的消息,气泡下方会多出「编辑 / 删除 / 复制」三个按钮:
29
29
 
30
- <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/message-actions.png" alt="消息气泡下方的编辑、删除、复制按钮" width="760">
30
+ <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/message-actions-v1.2.1.png" alt="消息气泡下方的编辑、删除、复制按钮" width="760">
31
31
 
32
- 点铅笔或垃圾桶之后,小窗直接出现在那个按钮正下方,并用一个小箭头指向它;点窗外或按 Esc 就收起。编辑窗一打开就会读出这条消息之后记录到的文件改动,默认只显示一行「已记录 N 处文件改动」,展开才看具体路径;要不要连文件一起还原,用一个二选一的开关决定:
32
+ 点铅笔或垃圾桶之后,小窗直接出现在那个按钮正下方,并用一个小箭头指向它;点窗外或按 Esc 就收起。编辑窗一打开就会读出这条消息之后记录到的文件改动,默认只显示一行「已记录 N 处文件改动」,展开才看具体路径;要不要连文件一起还原,用一个二选一的开关决定(记录不完整时开关不出现,只能回滚消息):
33
33
 
34
34
  | 编辑小窗 | 删除确认 |
35
35
  | :---: | :---: |
36
- | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/edit-dialog.png" alt="编辑小窗:文件改动收起成一行,回滚范围二选一" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/delete-dialog.png" alt="删除确认:没有文件改动时只剩一行确认" width="360"> |
36
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/edit-dialog-v1.2.1.png" alt="编辑小窗:文件改动收起成一行,回滚范围二选一" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/delete-dialog-v1.2.1.png" alt="删除确认:没有文件改动时只剩一行确认" width="360"> |
37
37
 
38
38
  小窗跟着按钮走:窗口底部放不下时自动翻到按钮上方,窄屏下收窄到屏幕宽度,亮色主题也保持同一套层级:
39
39
 
40
40
  | 靠近底部时翻到上方 | 窄屏(390px) | 亮色主题 |
41
41
  | :---: | :---: | :---: |
42
- | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-flip.png" alt="小窗翻到按钮上方,箭头朝下指向按钮" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-narrow.png" alt="窄屏下小窗收窄到屏幕宽度" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-light.png" alt="亮色主题下的删除小窗" width="240"> |
42
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-flip-v1.2.1.png" alt="小窗翻到按钮上方,箭头朝下指向按钮" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-narrow-v1.2.1.png" alt="窄屏下小窗收窄到屏幕宽度" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-light-v1.2.1.png" alt="亮色主题下的删除小窗" width="240"> |
43
43
 
44
- 快照失效、工作区不在 Git 仓库等限制也会直接标在小窗里,不用等到操作失败才知道。
44
+ 有文件改动时,快照失效或记录不完整、工作区不在 Git 仓库等限制也会直接标在小窗里,不用等到操作失败才知道。
45
45
 
46
46
  ## 安装
47
47
 
48
- 需要 DSH 0.2.1-rc.3 及以上(0.2.x),Node.js ≥ 20;已在 0.2.1-rc.5 上验证。宿主启动时会按 `engines.dsh` 校验,低于该版本会拒绝加载。
48
+ 需要 DSH 0.2.2-rc.1 及以上(0.2.x),Node.js ≥ 20;已在 0.2.2-rc.1 上验证。宿主启动时会按 `engines.dsh` 校验,低于该版本会拒绝加载。
49
49
 
50
50
  ### 从 npm 安装(推荐)
51
51
 
@@ -66,7 +66,7 @@ dsh plugin --profile web add dsh-message-rewind
66
66
  ```json
67
67
  {
68
68
  "dependencies": {
69
- "dsh-message-rewind": "^1.2.0"
69
+ "dsh-message-rewind": "^1.2.3"
70
70
  }
71
71
  }
72
72
  ```
@@ -101,12 +101,12 @@ DSH 启动日志里会出现 `message-rewind` 且状态为 active;刷新页面
101
101
 
102
102
  1. 点铅笔 → 按钮下方弹出小窗,改完点「保存并重发」。
103
103
  2. 点垃圾桶 → 点「删除」,删除这条消息及其后的全部对话。
104
- 3. 小窗打开时就会读取这条消息之后记录到的文件改动:默认折叠成一行「已记录 N 处文件改动」,点开可看路径;有改动时还会多出一个二选一的回滚范围:
104
+ 3. 小窗打开时就会读取这条消息之后记录到的文件改动:默认折叠成一行「已记录 N 处文件改动」,点开可看路径;改动记录完整且有改动时还会多出一个二选一的回滚范围:
105
105
  - **只回滚消息**(默认):文件保持现状;
106
106
  - **连文件一起回滚**:文件恢复成这条消息之前的内容;
107
107
  - 选好范围后,点「保存并重发」或「删除」执行。
108
108
 
109
- 快照失效、还有排队中的消息、工作区不在 Git 仓库等情况会在小窗里用一行提示说明。
109
+ 快照失效或记录不完整、还有排队中的消息、工作区不在 Git 仓库等情况会在小窗里用一行提示说明。
110
110
 
111
111
  ## 文件回滚:什么能回、什么回不了
112
112
 
@@ -117,15 +117,17 @@ DSH 启动日志里会出现 `message-rewind` 且状态为 active;刷新页面
117
117
  | 情况 | 结果 |
118
118
  | --- | --- |
119
119
  | 二进制文件 | 无法回滚(只记录了文本 diff) |
120
+ | 单个文件超过记录器的文本大小上限 | 没有保存可回滚的内容,无法回滚 |
120
121
  | 工作区不在 Git 仓库内,且文件是被 shell 命令改的 | 无法记录,因而无法回滚;在该目录 `git init` 后可完整记录 |
121
- | 会话重启或释放后,早先的快照已过期 | 提示「部分改动快照已不可用」,此时只能只回滚消息 |
122
+ | 单轮改动的文件数超过记录上限(默认 500) | 记录被截断,视为快照不完整,只能回滚消息 |
123
+ | 会话重启或释放后,早先的快照已过期 | 提示「文件改动快照不可用或记录被截断」,此时只能回滚消息 |
122
124
  | 文件在记录之后又被你(或别的工具)改过 | 回滚会被**拒绝**,不会覆盖掉你后来的改动 |
123
- | 这个会话没有工作区 | 只能只回滚消息 |
125
+ | 这个会话没有工作区 | 只能回滚消息 |
124
126
 
125
127
  ## 常见问题
126
128
 
127
129
  **Q:回滚之后,侧边栏是不是会多出一条对话?**
128
- 不会,始终只有一条同名对话。但底层会话 ID 会变:DSH 的会话日志是只追加的,没有「删掉中间一段」的接口,插件只能 fork 出一个截断后的分支,再把原会话移出侧边栏并删除其日志目录。所以如果你在别处引用过这个会话 ID,需要重新取一次。
130
+ 不会,始终只有一条对话(标题通常沿用原会话)。但底层会话 ID 会变:DSH 的会话日志是只追加的,没有「删掉中间一段」的接口,插件只能 fork 出一个截断后的分支,再把原会话移出侧边栏并删除其日志目录。所以如果你在别处引用过这个会话 ID,需要重新取一次。删除的是第一条消息时,替换出来的新会话还没有标题,可能先显示默认标题。
129
131
 
130
132
  **Q:原会话的记录还能找回吗?**
131
133
  正常情况下会被删除。只有当日志目录被占用删不掉时,原会话会保留在归档里。
@@ -133,8 +135,8 @@ DSH 启动日志里会出现 `message-rewind` 且状态为 active;刷新页面
133
135
  **Q:为什么带附件的消息不能编辑?**
134
136
  附件是作为消息内容的一部分存下来的,编辑只支持纯文本消息。带附件的消息可以删除。
135
137
 
136
- **Q:点按钮提示「当前有未结束的轮次」?**
137
- 先停止正在运行的任务再操作。另外,如果有排队中的消息,它们会随被删除的记录一起作废——小窗里会提示。
138
+ **Q:编辑/删除按钮是灰的,提示「当前有未结束的轮次」?**
139
+ 先停止正在运行的任务再操作;轮次结束前按钮不可用。另外,如果有排队中的消息,它们会随被删除的记录一起作废——小窗里会提示。
138
140
 
139
141
  **Q:看不到按钮?**
140
142
  确认插件已在「设置 → 插件」里启用、并且刷新过一次页面;另外只有你自己发的消息才有这两个按钮。
package/client.js CHANGED
@@ -16,12 +16,12 @@ window.__ModuleLoader__.load({
16
16
  filesCount: '已记录 {n} 处文件改动',
17
17
  messagesOnly: '只回滚消息', withFiles: '连文件一起回滚',
18
18
  fileWarning: '文件会还原到这条消息之前。',
19
- incomplete: '文件快照已失效,只能回滚消息。',
19
+ incomplete: '文件改动快照不可用或改动记录不完整,只能回滚消息。',
20
20
  running: '当前有未结束的轮次,请先停止运行',
21
21
  queued: '排队中的消息会一并作废。',
22
22
  noGit: '工作区不在 Git 仓库内:只有 DSH 文件工具的改动可回滚。',
23
23
  attachments: '含附件的消息暂时只能删除,不能编辑',
24
- empty: '消息不能为空', failed: '操作失败,请重试。', dialog: '消息回滚',
24
+ failed: '操作失败,请重试。',
25
25
  'error.invalid-message': '消息位置无效。',
26
26
  'error.stale-message': '这条消息已不在当前对话记录里,请刷新后重试。',
27
27
  'error.not-user-message': '只能编辑或删除你发送的消息。',
@@ -30,6 +30,7 @@ window.__ModuleLoader__.load({
30
30
  'error.file-unreadable': '有文件无法读取,未回滚任何文件。',
31
31
  'error.file-too-large': '有文件超过文本回滚上限,未回滚任何文件。',
32
32
  'error.file-binary': '有文件不是 UTF-8 文本,未回滚任何文件。',
33
+ 'error.oversized-file': '文件超过回滚大小上限,未回滚任何文件。',
33
34
  'error.file-rewind': '文件回滚失败,未写入任何文件。',
34
35
  'error.path-escape': '有文件不在该轮工作区内,未回滚任何文件。',
35
36
  'error.file-restore-failed': '文件回滚中断,部分文件需人工检查。',
@@ -40,9 +41,10 @@ window.__ModuleLoader__.load({
40
41
  'error.open-turn': '请先停止当前运行,再编辑或删除消息。',
41
42
  'error.attachments': '含附件的消息暂时只能删除,不能编辑。',
42
43
  'error.empty-message': '消息不能为空。',
43
- 'error.incomplete-snapshot': '部分文件改动快照已不可用,只能只回滚消息。',
44
- 'error.no-workspace': '这个会话没有工作区,只能只回滚消息。',
44
+ 'error.incomplete-snapshot': '部分文件改动快照不可用或改动记录不完整,只能回滚消息。',
45
+ 'error.no-workspace': '这个会话没有工作区,只能回滚消息。',
45
46
  'error.invalid-session': '会话标识无效。',
47
+ 'error.missing-session': '找不到这个会话,它可能已被删除。',
46
48
  'error.unknown-endpoint': '未知接口。',
47
49
  'error.request-too-large': '请求体过大。',
48
50
  'error.bad-request': '请求格式无效。',
@@ -58,12 +60,12 @@ window.__ModuleLoader__.load({
58
60
  filesCount: '{n} file changes recorded',
59
61
  messagesOnly: 'Messages only', withFiles: 'Messages + files',
60
62
  fileWarning: 'Files are restored to their state before this message.',
61
- incomplete: 'File snapshots are gone; messages only.',
63
+ incomplete: 'File snapshots are unavailable or the change record is incomplete; messages only.',
62
64
  running: 'A turn is still running — stop it first',
63
65
  queued: 'Queued prompts are discarded too.',
64
66
  noGit: 'No Git here: only DSH file-tool edits can be rolled back.',
65
67
  attachments: 'Messages with attachments can only be deleted, not edited',
66
- empty: 'Message cannot be empty', failed: 'Operation failed. Please try again.', dialog: 'Message rewind',
68
+ failed: 'Operation failed. Please try again.',
67
69
  'error.invalid-message': 'Invalid message position.',
68
70
  'error.stale-message': 'This message is no longer in the conversation. Refresh and try again.',
69
71
  'error.not-user-message': 'Only messages you sent can be edited or deleted.',
@@ -72,6 +74,7 @@ window.__ModuleLoader__.load({
72
74
  'error.file-unreadable': 'A file could not be read, so nothing was rolled back.',
73
75
  'error.file-too-large': 'A file exceeds the text-rollback size limit, so nothing was rolled back.',
74
76
  'error.file-binary': 'A file is not UTF-8 text, so nothing was rolled back.',
77
+ 'error.oversized-file': 'A file exceeds the rollback size limit, so nothing was rolled back.',
75
78
  'error.file-rewind': 'File rollback failed; nothing was written.',
76
79
  'error.path-escape': 'A file lies outside that turn\u2019s workspace, so nothing was rolled back.',
77
80
  'error.file-restore-failed': 'File rollback was interrupted; some files need manual checking.',
@@ -82,9 +85,10 @@ window.__ModuleLoader__.load({
82
85
  'error.open-turn': 'Stop the running turn before editing or deleting messages.',
83
86
  'error.attachments': 'Messages with attachments can only be deleted.',
84
87
  'error.empty-message': 'The message cannot be empty.',
85
- 'error.incomplete-snapshot': 'Some file snapshots are unavailable; roll back messages only.',
88
+ 'error.incomplete-snapshot': 'Some file snapshots are unavailable or the change record is incomplete; roll back messages only.',
86
89
  'error.no-workspace': 'This conversation has no workspace; roll back messages only.',
87
90
  'error.invalid-session': 'Invalid session id.',
91
+ 'error.missing-session': 'This conversation no longer exists.',
88
92
  'error.unknown-endpoint': 'Unknown endpoint.',
89
93
  'error.request-too-large': 'The request body is too large.',
90
94
  'error.bad-request': 'Invalid request.',
@@ -267,7 +271,7 @@ window.__ModuleLoader__.load({
267
271
  const onKey = (event) => {
268
272
  if (event.key === 'Escape' && !lockedRef.current) { event.preventDefault(); onClose(); return; }
269
273
  if (event.key !== 'Tab' || !node) return;
270
- const items = [...(node.querySelectorAll?.('textarea, input:not(:disabled), button:not(:disabled)') ?? [])];
274
+ const items = [...(node.querySelectorAll?.('textarea:not(:disabled), input:not(:disabled), button:not(:disabled)') ?? [])];
271
275
  if (items.length === 0) { event.preventDefault(); return; }
272
276
  const firstItem = items[0];
273
277
  const lastItem = items[items.length - 1];
@@ -323,7 +327,7 @@ window.__ModuleLoader__.load({
323
327
 
324
328
  return {
325
329
  name: 'dsh-message-rewind',
326
- inject: ['slots', 'uiWorkspace', 'locale', 'connection'],
330
+ inject: ['slots', 'uiWorkspace', 'locale', 'connection', 'sessions'],
327
331
  apply(ctx) {
328
332
  try {
329
333
  install(ctx);
@@ -392,9 +396,9 @@ window.__ModuleLoader__.load({
392
396
  const getSnapshot = () => current;
393
397
  // Loading is the only cancellable busy phase: an execute that already
394
398
  // reached the Host cannot be safely abandoned from the Client.
399
+ const writing = () => current !== null && current.busy && current.phase !== 'loading';
395
400
  const close = () => {
396
- if (!current) return;
397
- if (current.busy && current.phase !== 'loading') return;
401
+ if (!current || writing()) return;
398
402
  current.abort?.abort();
399
403
  publish(null);
400
404
  };
@@ -402,6 +406,26 @@ window.__ModuleLoader__.load({
402
406
  // belongs to, so a closed or replaced dialog is never resurrected.
403
407
  const patchIf = (token, fields) => { if (current !== null && current.token === token) publish({ ...current, ...fields }); };
404
408
 
409
+ // 0.2.2 only opens a Session its Client catalog knows. A child the Host
410
+ // creates over RPC enters that catalog through a forwarded
411
+ // Session-added frame that races this reply, so pull the Session list
412
+ // (a refresh) until the row lands before navigating; otherwise
413
+ // `openSession` throws and strands the user on the source conversation.
414
+ async function openCreated(sessionId) {
415
+ const catalogued = () => {
416
+ try {
417
+ return ctx.sessions.list.getSnapshot().byId[sessionId] !== undefined;
418
+ } catch {
419
+ return false;
420
+ }
421
+ };
422
+ for (let attempt = 0; attempt < 10 && !catalogued(); attempt += 1) {
423
+ if (attempt > 0) await new Promise((resolveDelay) => window.setTimeout(resolveDelay, 100));
424
+ await ctx.sessions.refresh().catch(() => {});
425
+ }
426
+ ctx.uiWorkspace.openSession(sessionId);
427
+ }
428
+
405
429
  async function execute(rewindFiles) {
406
430
  const request = current;
407
431
  if (!request || request.busy) return;
@@ -420,7 +444,13 @@ window.__ModuleLoader__.load({
420
444
  publish(null);
421
445
  // Navigate first so the source's client reference is released, then let
422
446
  // the host retire its log: the sidebar keeps exactly one conversation.
423
- ctx.uiWorkspace.openSession(result.sessionId);
447
+ try {
448
+ await openCreated(result.sessionId);
449
+ } catch (error) {
450
+ // The rollback happened; never retire the source the UI still shows.
451
+ console.warn('[message-rewind] the new conversation could not be opened:', error instanceof Error ? error.message : String(error));
452
+ return;
453
+ }
424
454
  const source = result.sourceSessionId;
425
455
  if (typeof source === 'string' && source !== result.sessionId) {
426
456
  Promise.resolve()
@@ -470,12 +500,16 @@ window.__ModuleLoader__.load({
470
500
  const isOpenFor = (kind, sessionId, seq) => current !== null && current.kind === kind && current.sessionId === sessionId && current.seq === seq;
471
501
 
472
502
  function openEdit(sessionId, seq, text, anchor) {
503
+ // A write in flight keeps its dialog: replacing it would strand the
504
+ // reply that still owns navigation and source cleanup.
505
+ if (writing()) return;
473
506
  const dialog = { token: {}, instance: ++opens, kind: 'edit', sessionId, seq, text, anchor: anchor ?? null, phase: 'edit', busy: false, checking: true, error: null, details: null, abort: new AbortController() };
474
507
  publish(dialog);
475
508
  void inspectEdit(dialog);
476
509
  }
477
510
 
478
511
  function openDelete(sessionId, seq, anchor) {
512
+ if (writing()) return;
479
513
  publish({ token: {}, instance: ++opens, kind: 'delete', sessionId, seq, text: '', anchor: anchor ?? null, phase: 'loading', busy: true, error: null, details: null, abort: new AbortController() });
480
514
  void check();
481
515
  }
@@ -643,7 +677,7 @@ window.__ModuleLoader__.load({
643
677
  () => copyText())));
644
678
  }
645
679
 
646
- ctx.slots.inject('conversation.chat.node', () => ctx.slots.register({ name: 'conversation.chat.node', key: 'user', locale: NS }, UserActions));
680
+ ctx.slots.inject('conversation.chat.node', () => ctx.slots.register({ name: 'conversation.chat.node', key: 'user', priority: -1, locale: NS }, UserActions));
647
681
  ctx.slots.inject('shell.overlay', () => ctx.slots.register({ name: 'shell.overlay', id: 'message-rewind.dialog', locale: NS }, RewindDialog));
648
682
  }
649
683
  };
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { promises as fsp } from 'node:fs';
2
- import { basename, isAbsolute, join, relative, sep } from 'node:path';
2
+ import { basename, dirname, isAbsolute, join, relative, sep } from 'node:path';
3
3
  import { homedir } from 'node:os';
4
4
  import { randomUUID } from 'node:crypto';
5
5
  import { prepareCut, userError } from './rewind.js';
@@ -8,12 +8,12 @@ import { planRewind, applyRewind } from './files.js';
8
8
  const MAX_BODY_BYTES = 1024 * 1024;
9
9
  const CHANNEL = '/message-rewind';
10
10
  const DIFF_TIMEOUT = 30_000;
11
- /** Matches the `$DSH_HOME` > `~/.dsh` resolution the harness itself uses. */
12
- const SESSIONS_ROOT = join(process.env.DSH_HOME ?? join(homedir(), '.dsh'), 'sessions');
11
+ /** Matches the `$DSH_HOME` > `~/.dsh` resolution the harness itself uses, where a blank override counts as unset. */
12
+ const SESSIONS_ROOT = join(process.env.DSH_HOME?.trim() ? process.env.DSH_HOME : join(homedir(), '.dsh'), 'sessions');
13
13
  /** The harness mints `session-<uuid>`; refuse anything that could address a path. */
14
14
  const SESSION_ID = /^session-[0-9a-zA-Z]+(?:-[0-9a-zA-Z]+)*$/;
15
15
 
16
- export const inject = ['sessionController', 'workspaceChanges', 'workspaceController', 'connection', 'webServer'];
16
+ export const inject = ['sessionController', 'sessionQuery', 'workspaceChanges', 'workspaceController', 'connection', 'webServer'];
17
17
 
18
18
  const text = (error) => (error instanceof Error ? error.message : String(error));
19
19
 
@@ -90,7 +90,9 @@ async function insideGitWorkTree(cwd) {
90
90
  } catch {
91
91
  /* keep walking up */
92
92
  }
93
- const parent = join(current, '..');
93
+ // `dirname` reaches a fixed point (`.` or the filesystem root) even for a
94
+ // relative cwd, where joining `..` would never end the walk.
95
+ const parent = dirname(current);
94
96
  if (parent === current) return false;
95
97
  current = parent;
96
98
  }
@@ -107,13 +109,34 @@ export function apply(ctx) {
107
109
  async function readDiff(sessionId, seq, index) {
108
110
  const diff = await ctx.workspaceChanges.diff(sessionId, seq, index, diffTimeout());
109
111
  if (!diff) throw userError('snapshot-missing', '文件改动快照已不可用,未回滚任何文件。');
112
+ // Oversized text is refused by the recorder before it can be compared; it
113
+ // is not binary, so report the size limit instead of the encoding.
114
+ if (diff.kind === 'oversized') throw userError('oversized-file', `文件超过回滚大小上限:${diff.display}`);
110
115
  if (diff.kind !== 'text') throw userError('binary-file', `只能回滚文本文件:${diff.display}`);
111
116
  if (diff.coarse) throw userError('coarse-diff', `改动过大,无法安全回滚:${diff.display}`);
112
117
  return diff;
113
118
  }
114
119
 
120
+ /**
121
+ * Read one session's recorded events and creation metadata without activating
122
+ * it. DSH 0.2.2 replaced `sessionController.inspect` with the cold-safe
123
+ * `sessionQuery.readSession`, whose `session` field is the Session header.
124
+ * @param sessionId - session whose durable log is read.
125
+ * @returns the full event log and the metadata the cut needs.
126
+ */
127
+ async function readInspection(sessionId) {
128
+ let read;
129
+ try {
130
+ read = await ctx.sessionQuery.readSession(sessionId);
131
+ } catch (error) {
132
+ if (error?.code === 'SESSION_QUERY_SESSION_NOT_FOUND') throw userError('missing-session', '找不到这个会话,它可能已被删除。');
133
+ throw error;
134
+ }
135
+ return { events: read.events, meta: { cwd: read.session.cwd, agentPreset: read.session.agentPreset } };
136
+ }
137
+
115
138
  async function load(sessionId, seq) {
116
- const inspection = await ctx.sessionController.inspect(sessionId);
139
+ const inspection = await readInspection(sessionId);
117
140
  const cut = prepareCut(inspection.events, seq);
118
141
  const records = cut.records.map((recordSeq) => ({
119
142
  seq: recordSeq,
@@ -144,6 +167,13 @@ export function apply(ctx) {
144
167
  incomplete = true;
145
168
  continue;
146
169
  }
170
+ // The recorder caps `files` at its maxFiles budget while `total` counts
171
+ // every changed file; the surplus cannot be read back, so the snapshot is
172
+ // not complete and rolling files back would silently leave some changed.
173
+ if (summary.total > summary.files.length) incomplete = true;
174
+ // A path outside the session working directory is stored absolute; the
175
+ // rewind plan refuses it, so the dialog must not offer a file rollback.
176
+ if (summary.files.some((file) => isAbsolute(file.path))) incomplete = true;
147
177
  for (const file of summary.files) files.set(`${summary.cwd}\0${file.path}`, file.display);
148
178
  }
149
179
  return { files: [...files.values()], incomplete };
@@ -201,9 +231,9 @@ export function apply(ctx) {
201
231
  let restored = 0;
202
232
  let undo = null;
203
233
  if (withFiles) {
204
- if (describe(records).incomplete) throw userError('incomplete-snapshot', '部分文件改动快照已不可用,只能只回滚消息。');
234
+ if (describe(records).incomplete) throw userError('incomplete-snapshot', '部分文件改动快照不可用或记录不完整,只能回滚消息。');
205
235
  if (records.some((record) => record.summary)) {
206
- if (!inspection.meta.cwd) throw userError('no-workspace', '这个会话没有工作区,只能只回滚消息。');
236
+ if (!inspection.meta.cwd) throw userError('no-workspace', '这个会话没有工作区,只能回滚消息。');
207
237
  const targets = await plan(sessionId, records);
208
238
  const applied = await applyRewind(targets);
209
239
  undo = applied.undo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-message-rewind",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "DeepSeek Harness plugin: edit sent messages and roll back following turns, optionally restoring recorded file changes.",
5
5
  "license": "MIT",
6
6
  "author": "xCube007",
@@ -23,11 +23,13 @@
23
23
  "edit"
24
24
  ],
25
25
  "type": "module",
26
+ "main": "./index.js",
26
27
  "exports": {
27
28
  ".": "./index.js",
28
29
  "./client": "./client.js",
29
30
  "./locale/*.json": "./locale/*.json",
30
- "./icon": "./icon.svg"
31
+ "./icon": "./icon.svg",
32
+ "./package.json": "./package.json"
31
33
  },
32
34
  "files": [
33
35
  "index.js",
@@ -37,12 +39,11 @@
37
39
  "cordis.patch.yml",
38
40
  "locale/*.json",
39
41
  "icon.svg",
40
- "README.en.md",
41
- "*.test.js"
42
+ "README.en.md"
42
43
  ],
43
44
  "engines": {
44
45
  "node": ">=20",
45
- "dsh": ">=0.2.1-rc.3 <0.3.0-0"
46
+ "dsh": ">=0.2.2-rc.1 <0.3.0-0"
46
47
  },
47
48
  "scripts": {
48
49
  "test": "node manifest.test.js && node rewind.test.js && node files.test.js && node index.test.js && node client.test.js",
package/rewind.js CHANGED
@@ -19,7 +19,7 @@ export function userError(code, message) {
19
19
  * @param events - a session's event prefix, ordered by `seq`.
20
20
  * @param seq - the exact `seq` of the user message to cut at.
21
21
  * @returns the message content, the fork boundary (undefined when nothing precedes the turn),
22
- * whether the cut spans an open turn, and the `workspace/changes` sequences removed by the cut.
22
+ * whether the cut spans an open turn, and each cut turn's last `workspace/changes` sequence.
23
23
  */
24
24
  export function prepareCut(events, seq) {
25
25
  if (!Number.isSafeInteger(seq) || seq < 0) throw userError('invalid-message', '消息位置无效。');
@@ -48,11 +48,23 @@ export function prepareCut(events, seq) {
48
48
  if (event.type === 'turn/start') hasOpenTurn = true;
49
49
  else if (event.type === 'turn/end') hasOpenTurn = false;
50
50
  }
51
- const records = events
52
- .slice(position)
53
- .filter((event) => event.type === 'workspace/changes')
54
- .map((event) => event.seq)
55
- .sort((left, right) => left - right);
51
+ // One turn can append several `workspace/changes` records: the recorder reads
52
+ // once when the turn stops and again at `turn/end` when a tool result settled
53
+ // in between, and a later record supersedes the earlier ones. Only a turn's
54
+ // last record describes its net change, so replaying the others would invert
55
+ // the same diff twice.
56
+ const records = [];
57
+ const turns = new Set();
58
+ for (let cursor = events.length - 1; cursor >= position; cursor--) {
59
+ const event = events[cursor];
60
+ if (event.type !== 'workspace/changes') continue;
61
+ const turn = event.data?.turn;
62
+ if (Number.isSafeInteger(turn)) {
63
+ if (turns.has(turn)) continue;
64
+ turns.add(turn);
65
+ }
66
+ records.unshift(event.seq);
67
+ }
56
68
  return { content, boundary, hasOpenTurn, records };
57
69
  }
58
70