dsh-message-rewind 1.2.2 → 1.2.4
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 +14 -12
- package/README.md +15 -13
- package/client.js +17 -11
- package/index.js +121 -29
- package/package.json +5 -4
- package/rewind.js +18 -6
- package/client.test.js +0 -420
- package/files.test.js +0 -181
- package/index.test.js +0 -227
- package/manifest.test.js +0 -25
- package/rewind.test.js +0 -89
package/README.en.md
CHANGED
|
@@ -16,10 +16,10 @@ 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
|
|
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
|
|
|
@@ -27,7 +27,7 @@ Your own messages get **edit / delete / copy** buttons under the bubble:
|
|
|
27
27
|
|
|
28
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
|
| :---: | :---: |
|
|
@@ -39,7 +39,7 @@ The popover follows its button: it flips above when there is no room below, narr
|
|
|
39
39
|
| :---: | :---: | :---: |
|
|
40
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
|
-
|
|
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
|
|
|
@@ -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.
|
|
67
|
+
"dsh-message-rewind": "^1.2.4"
|
|
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,24 +115,26 @@ 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
|
-
|
|
|
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
|
|
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, removes the original from the sidebar, and deletes its log directory directly; the normal path writes no archive entry. Repeated edits therefore do not pile up same-titled archive entries. 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
|
-
Normally it is deleted. Only when its log directory is still held open and cannot be removed does the
|
|
131
|
+
Normally it is deleted outright and never reaches the archive. Only when the live session cannot be detached, or its log directory is still held open and cannot be removed, does the plugin fall back to archiving it; the log is not silently lost.
|
|
130
132
|
|
|
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
|
|
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,10 +18,10 @@
|
|
|
18
18
|
| --- | --- |
|
|
19
19
|
| 改掉已发送的消息 | 点消息气泡下方的铅笔,改完点「保存并重发」,这条消息之后的内容会被截断,然后按你改后的内容重新开始 |
|
|
20
20
|
| 撤掉一条越界的消息 | 点垃圾桶,确认后这条消息连同它之后的所有对话一起删除 |
|
|
21
|
-
| 连文件一起还原 |
|
|
21
|
+
| 连文件一起还原 | 删除/编辑时,如果那一轮动过文件且改动记录完整,按钮下方的小窗会让你选「只回滚消息」还是「连文件一起回滚」 |
|
|
22
22
|
| 不打扰正在跑的任务 | 有未结束的轮次时直接拒绝操作,不会和正在执行的 turn 抢写 |
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
只有你自己发出的普通消息才有这两个按钮;一轮运行中被追加的 steering 行不提供编辑/删除。「复制」按钮仍在,位置不变。
|
|
25
25
|
|
|
26
26
|
## 界面
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
|
|
30
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
|
| :---: | :---: |
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
| :---: | :---: | :---: |
|
|
42
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
|
-
|
|
44
|
+
有文件改动时,快照失效或记录不完整、工作区不在 Git 仓库等限制也会直接标在小窗里,不用等到操作失败才知道。
|
|
45
45
|
|
|
46
46
|
## 安装
|
|
47
47
|
|
|
@@ -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.
|
|
69
|
+
"dsh-message-rewind": "^1.2.4"
|
|
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
|
-
|
|
109
|
+
快照失效或记录不完整、还有排队中的消息、工作区不在 Git 仓库等情况会在小窗里用一行提示说明。
|
|
110
110
|
|
|
111
111
|
## 文件回滚:什么能回、什么回不了
|
|
112
112
|
|
|
@@ -117,24 +117,26 @@ 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
|
-
|
|
130
|
+
不会,始终只有一条对话(标题通常沿用原会话)。但底层会话 ID 会变:DSH 的会话日志是只追加的,没有「删掉中间一段」的接口,插件只能 fork 出一个截断后的分支,再把原会话从侧边栏摘掉并直接删除其日志目录;正常路径不写入归档。所以反复编辑/删除不会在归档里堆出同名会话;如果你在别处引用过这个会话 ID,需要重新取一次。删除的是第一条消息时,替换出来的新会话还没有标题,可能先显示默认标题。
|
|
129
131
|
|
|
130
132
|
**Q:原会话的记录还能找回吗?**
|
|
131
|
-
|
|
133
|
+
正常情况下会被直接删除,不进入归档。只有当运行中的原会话摘不掉,或日志目录被占用、删不掉时,才会退回归档兜底;失败也不会静默丢日志。
|
|
132
134
|
|
|
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
|
-
|
|
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,8 +41,8 @@ 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': '会话标识无效。',
|
|
46
47
|
'error.missing-session': '找不到这个会话,它可能已被删除。',
|
|
47
48
|
'error.unknown-endpoint': '未知接口。',
|
|
@@ -59,12 +60,12 @@ window.__ModuleLoader__.load({
|
|
|
59
60
|
filesCount: '{n} file changes recorded',
|
|
60
61
|
messagesOnly: 'Messages only', withFiles: 'Messages + files',
|
|
61
62
|
fileWarning: 'Files are restored to their state before this message.',
|
|
62
|
-
incomplete: 'File snapshots are
|
|
63
|
+
incomplete: 'File snapshots are unavailable or the change record is incomplete; messages only.',
|
|
63
64
|
running: 'A turn is still running — stop it first',
|
|
64
65
|
queued: 'Queued prompts are discarded too.',
|
|
65
66
|
noGit: 'No Git here: only DSH file-tool edits can be rolled back.',
|
|
66
67
|
attachments: 'Messages with attachments can only be deleted, not edited',
|
|
67
|
-
|
|
68
|
+
failed: 'Operation failed. Please try again.',
|
|
68
69
|
'error.invalid-message': 'Invalid message position.',
|
|
69
70
|
'error.stale-message': 'This message is no longer in the conversation. Refresh and try again.',
|
|
70
71
|
'error.not-user-message': 'Only messages you sent can be edited or deleted.',
|
|
@@ -73,6 +74,7 @@ window.__ModuleLoader__.load({
|
|
|
73
74
|
'error.file-unreadable': 'A file could not be read, so nothing was rolled back.',
|
|
74
75
|
'error.file-too-large': 'A file exceeds the text-rollback size limit, so nothing was rolled back.',
|
|
75
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.',
|
|
76
78
|
'error.file-rewind': 'File rollback failed; nothing was written.',
|
|
77
79
|
'error.path-escape': 'A file lies outside that turn\u2019s workspace, so nothing was rolled back.',
|
|
78
80
|
'error.file-restore-failed': 'File rollback was interrupted; some files need manual checking.',
|
|
@@ -83,7 +85,7 @@ window.__ModuleLoader__.load({
|
|
|
83
85
|
'error.open-turn': 'Stop the running turn before editing or deleting messages.',
|
|
84
86
|
'error.attachments': 'Messages with attachments can only be deleted.',
|
|
85
87
|
'error.empty-message': 'The message cannot be empty.',
|
|
86
|
-
'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.',
|
|
87
89
|
'error.no-workspace': 'This conversation has no workspace; roll back messages only.',
|
|
88
90
|
'error.invalid-session': 'Invalid session id.',
|
|
89
91
|
'error.missing-session': 'This conversation no longer exists.',
|
|
@@ -269,7 +271,7 @@ window.__ModuleLoader__.load({
|
|
|
269
271
|
const onKey = (event) => {
|
|
270
272
|
if (event.key === 'Escape' && !lockedRef.current) { event.preventDefault(); onClose(); return; }
|
|
271
273
|
if (event.key !== 'Tab' || !node) return;
|
|
272
|
-
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)') ?? [])];
|
|
273
275
|
if (items.length === 0) { event.preventDefault(); return; }
|
|
274
276
|
const firstItem = items[0];
|
|
275
277
|
const lastItem = items[items.length - 1];
|
|
@@ -394,9 +396,9 @@ window.__ModuleLoader__.load({
|
|
|
394
396
|
const getSnapshot = () => current;
|
|
395
397
|
// Loading is the only cancellable busy phase: an execute that already
|
|
396
398
|
// reached the Host cannot be safely abandoned from the Client.
|
|
399
|
+
const writing = () => current !== null && current.busy && current.phase !== 'loading';
|
|
397
400
|
const close = () => {
|
|
398
|
-
if (!current) return;
|
|
399
|
-
if (current.busy && current.phase !== 'loading') return;
|
|
401
|
+
if (!current || writing()) return;
|
|
400
402
|
current.abort?.abort();
|
|
401
403
|
publish(null);
|
|
402
404
|
};
|
|
@@ -455,7 +457,7 @@ window.__ModuleLoader__.load({
|
|
|
455
457
|
.then(() => new Promise((resolveDelay) => window.setTimeout(resolveDelay, 200)))
|
|
456
458
|
.then(() => remote('purge', { sessionId: source }, typeof AbortSignal.timeout === 'function' ? AbortSignal.timeout(REQUEST_TIMEOUT) : undefined))
|
|
457
459
|
.then((outcome) => {
|
|
458
|
-
if (!outcome || outcome.removed !== true) console.warn('[message-rewind] source session
|
|
460
|
+
if (!outcome || outcome.removed !== true) console.warn('[message-rewind] source session not fully removed:', outcome?.message ?? 'log not deleted');
|
|
459
461
|
})
|
|
460
462
|
.catch((error) => { console.warn('[message-rewind] purge failed:', error instanceof Error ? error.message : String(error)); });
|
|
461
463
|
}
|
|
@@ -498,12 +500,16 @@ window.__ModuleLoader__.load({
|
|
|
498
500
|
const isOpenFor = (kind, sessionId, seq) => current !== null && current.kind === kind && current.sessionId === sessionId && current.seq === seq;
|
|
499
501
|
|
|
500
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;
|
|
501
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() };
|
|
502
507
|
publish(dialog);
|
|
503
508
|
void inspectEdit(dialog);
|
|
504
509
|
}
|
|
505
510
|
|
|
506
511
|
function openDelete(sessionId, seq, anchor) {
|
|
512
|
+
if (writing()) return;
|
|
507
513
|
publish({ token: {}, instance: ++opens, kind: 'delete', sessionId, seq, text: '', anchor: anchor ?? null, phase: 'loading', busy: true, error: null, details: null, abort: new AbortController() });
|
|
508
514
|
void check();
|
|
509
515
|
}
|
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,8 +8,8 @@ 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
|
|
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
|
|
|
@@ -90,7 +90,9 @@ async function insideGitWorkTree(cwd) {
|
|
|
90
90
|
} catch {
|
|
91
91
|
/* keep walking up */
|
|
92
92
|
}
|
|
93
|
-
|
|
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,6 +109,9 @@ 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;
|
|
@@ -162,6 +167,13 @@ export function apply(ctx) {
|
|
|
162
167
|
incomplete = true;
|
|
163
168
|
continue;
|
|
164
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;
|
|
165
177
|
for (const file of summary.files) files.set(`${summary.cwd}\0${file.path}`, file.display);
|
|
166
178
|
}
|
|
167
179
|
return { files: [...files.values()], incomplete };
|
|
@@ -219,9 +231,9 @@ export function apply(ctx) {
|
|
|
219
231
|
let restored = 0;
|
|
220
232
|
let undo = null;
|
|
221
233
|
if (withFiles) {
|
|
222
|
-
if (describe(records).incomplete) throw userError('incomplete-snapshot', '
|
|
234
|
+
if (describe(records).incomplete) throw userError('incomplete-snapshot', '部分文件改动快照不可用或记录不完整,只能回滚消息。');
|
|
223
235
|
if (records.some((record) => record.summary)) {
|
|
224
|
-
if (!inspection.meta.cwd) throw userError('no-workspace', '
|
|
236
|
+
if (!inspection.meta.cwd) throw userError('no-workspace', '这个会话没有工作区,只能回滚消息。');
|
|
225
237
|
const targets = await plan(sessionId, records);
|
|
226
238
|
const applied = await applyRewind(targets);
|
|
227
239
|
undo = applied.undo;
|
|
@@ -247,43 +259,123 @@ export function apply(ctx) {
|
|
|
247
259
|
}
|
|
248
260
|
|
|
249
261
|
/**
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* store for this Host's lifetime — so waiting for `sessions.get()` to clear
|
|
257
|
-
* would never finish. Deletion is attempted directly and its outcome is
|
|
258
|
-
* reported, with liveness used only to explain a failure.
|
|
262
|
+
* Detach one live source Session. The store's disposal event closes its
|
|
263
|
+
* persistence writer and makes the harness publish `api-session/removed`, so
|
|
264
|
+
* the log can be deleted after the write handle is gone.
|
|
265
|
+
* @param sessionId - session to detach.
|
|
266
|
+
* @returns true when a live session was detached, false when it was cold.
|
|
267
|
+
* @throws when a live session is still attached afterwards.
|
|
259
268
|
*/
|
|
260
|
-
async function
|
|
269
|
+
async function detachSession(sessionId) {
|
|
270
|
+
const sessions = ctx.get('sessions');
|
|
271
|
+
const live = sessions?.get?.(sessionId);
|
|
272
|
+
if (live === undefined) return false;
|
|
273
|
+
// Archive used to stop queued work before hiding the session; keep that
|
|
274
|
+
// stop without writing an archive entry.
|
|
275
|
+
try { await ctx.parallel?.('workspace/session-stop', { sessionId }); } catch { /* stop is best effort */ }
|
|
276
|
+
try { await sessions.flush?.(live); } catch { /* the log is about to be deleted */ }
|
|
261
277
|
try {
|
|
262
|
-
|
|
278
|
+
const entry = sessions.liveEntryFor?.(live);
|
|
279
|
+
if (entry !== undefined) sessions.detachEntered?.(entry);
|
|
263
280
|
} catch (error) {
|
|
264
|
-
|
|
265
|
-
|
|
281
|
+
throw new Error(`会话仍在本进程中运行,无法移除:${text(error)}`);
|
|
282
|
+
}
|
|
283
|
+
if (sessions.get?.(sessionId) !== undefined) throw new Error('会话仍在本进程中运行,无法移除。');
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Drop the traces a deleted source session leaves outside its log: the
|
|
289
|
+
* archived/pinned registry flags, workspace accounting, and projection cache.
|
|
290
|
+
* @param sessionId - deleted session.
|
|
291
|
+
* @param detachedLive - whether {@link detachSession} already published its removal.
|
|
292
|
+
*/
|
|
293
|
+
async function cleanupSession(sessionId, detachedLive) {
|
|
294
|
+
if (!detachedLive) {
|
|
295
|
+
try { ctx.emit?.('api-session/removed', sessionId); } catch { /* client refresh is the fallback */ }
|
|
296
|
+
}
|
|
297
|
+
const registry = ctx.get('workspaceRegistry');
|
|
298
|
+
try {
|
|
299
|
+
if (registry?.archivedSessionIds?.includes?.(sessionId) === true) {
|
|
300
|
+
await ctx.workspaceController.unarchiveSession({ sessionId });
|
|
301
|
+
}
|
|
302
|
+
} catch {
|
|
303
|
+
/* a stale archive id is cleaned up by the harness/archive surfaces */
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
if (registry?.pinnedSessionIds?.includes?.(sessionId) === true) {
|
|
307
|
+
await ctx.workspaceController.unpinSession({ sessionId });
|
|
308
|
+
}
|
|
309
|
+
} catch {
|
|
310
|
+
/* a stale pin never renders a row without a session */
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const table = ctx.get('sessionProjectionCache')?.requireTable?.();
|
|
314
|
+
if (table !== undefined) await table.delete(sessionId);
|
|
315
|
+
} catch {
|
|
316
|
+
/* the projection cache is a fold shortcut, not an authority */
|
|
266
317
|
}
|
|
318
|
+
try {
|
|
319
|
+
for (const workspace of registry?.list?.() ?? []) {
|
|
320
|
+
if (typeof workspace.detachSession === 'function') await workspace.detachSession(sessionId);
|
|
321
|
+
}
|
|
322
|
+
} catch {
|
|
323
|
+
/* stale accounting never shows a row without a live or persisted session */
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Remove a rolled-back source session for good. The harness keeps session logs
|
|
329
|
+
* append-only and offers no delete API, so this retires the artifact itself:
|
|
330
|
+
* detach the live Session, delete its directory, and drop its archive flag /
|
|
331
|
+
* workspace accounting / projection cache. The normal path never archives, so
|
|
332
|
+
* repeated rewinds cannot fill the archive with copies of one conversation.
|
|
333
|
+
*/
|
|
334
|
+
async function purge(sessionId) {
|
|
267
335
|
const directory = await sessionDirectory(SESSIONS_ROOT, sessionId);
|
|
268
|
-
|
|
269
|
-
|
|
336
|
+
let detachedLive = false;
|
|
337
|
+
if (directory === undefined) {
|
|
338
|
+
// A log another surface already removed still needs its row cleaned up.
|
|
339
|
+
try { detachedLive = await detachSession(sessionId); } catch { /* remove the row below */ }
|
|
340
|
+
await cleanupSession(sessionId, detachedLive);
|
|
341
|
+
return { removed: false, archivedOnly: false, message: '未找到会话日志目录,未删除任何内容。' };
|
|
342
|
+
}
|
|
343
|
+
if (ctx.get('sessions')?.get?.(sessionId) !== undefined) {
|
|
344
|
+
try {
|
|
345
|
+
detachedLive = await detachSession(sessionId);
|
|
346
|
+
} catch (error) {
|
|
347
|
+
// Leaving a live session with its log is better than deleting the log
|
|
348
|
+
// out from under it; hide the row with the old archive fallback.
|
|
349
|
+
try {
|
|
350
|
+
await ctx.workspaceController.archiveSession({ sessionId, stopActivity: true });
|
|
351
|
+
return { removed: false, archivedOnly: true, message: `${text(error)},已移出侧边栏` };
|
|
352
|
+
} catch (archiveError) {
|
|
353
|
+
return { removed: false, archivedOnly: false, message: `${text(error)};${text(archiveError)}` };
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
270
357
|
let failure;
|
|
271
358
|
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
272
359
|
try {
|
|
273
360
|
await fsp.rm(directory, { recursive: true, force: true });
|
|
274
|
-
|
|
361
|
+
failure = undefined;
|
|
362
|
+
break;
|
|
275
363
|
} catch (error) {
|
|
276
364
|
failure = error;
|
|
277
365
|
await delay(250);
|
|
278
366
|
}
|
|
279
367
|
}
|
|
280
|
-
|
|
281
|
-
removed
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
368
|
+
if (failure !== undefined) {
|
|
369
|
+
// Keep the old fallback only when the bytes could not be removed.
|
|
370
|
+
try {
|
|
371
|
+
await ctx.workspaceController.archiveSession({ sessionId, stopActivity: true });
|
|
372
|
+
return { removed: false, archivedOnly: true, message: `日志目录无法删除,已移出侧边栏:${text(failure)}` };
|
|
373
|
+
} catch (archiveError) {
|
|
374
|
+
return { removed: false, archivedOnly: false, message: `日志目录无法删除,且未能移出侧边栏:${text(failure)};${text(archiveError)}` };
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
await cleanupSession(sessionId, detachedLive);
|
|
378
|
+
return { removed: true, archivedOnly: false };
|
|
287
379
|
}
|
|
288
380
|
|
|
289
381
|
async function dispatch(endpoint, payload) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-message-rewind",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
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,8 +39,7 @@
|
|
|
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",
|
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
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|