dsh-message-rewind 1.2.2 → 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,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 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
 
@@ -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
- 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
 
@@ -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,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
- 快照失效、工作区不在 Git 仓库等限制也会直接标在小窗里,不用等到操作失败才知道。
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.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,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 gone; messages only.',
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
- empty: 'Message cannot be empty', failed: 'Operation failed. Please try again.', dialog: 'Message rewind',
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
  };
@@ -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 ?? 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
 
@@ -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,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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-message-rewind",
3
- "version": "1.2.2",
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,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 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