dsh-message-rewind 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -45,12 +45,18 @@ Your own messages get **edit / rollback / copy** buttons under the bubble:
45
45
 
46
46
  <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/message-actions-v1.3.0.png" alt="Edit, rollback and copy buttons under a user message" width="760">
47
47
 
48
- 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 — blue for **messages only**, red for **messages + files**. When the record is incomplete the switch is not offered, so only a messages-only rollback is possible:
48
+ 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:
49
49
 
50
50
  | Edit popover | Rollback confirmation |
51
51
  | :---: | :---: |
52
52
  | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/edit-dialog-v1.3.0.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/rollback-dialog-v1.3.0.png" alt="Rollback confirmation: a one-line confirm when no files changed" width="360"> |
53
53
 
54
+ The rollback scope is colour-coded: blue for **messages only**, red for **messages + files**. The chosen option turns solid, while the other keeps a light wash of its colour:
55
+
56
+ | Messages only (blue, default) | Messages + files (red) |
57
+ | :---: | :---: |
58
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/rollback-scope-messages-v1.4.0.png" alt="Messages only: the blue solid button is selected" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/rollback-scope-files-v1.4.0.png" alt="Messages + files: the red solid button is selected, with the restore hint below" width="360"> |
59
+
54
60
  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:
55
61
 
56
62
  | Flips above near the bottom | Narrow screen (390px) | Light theme |
@@ -82,7 +88,7 @@ If you prefer editing the profile yourself, the manual route is the same three s
82
88
  ```json
83
89
  {
84
90
  "dependencies": {
85
- "dsh-message-rewind": "^1.3.0"
91
+ "dsh-message-rewind": "^1.5.0"
86
92
  }
87
93
  }
88
94
  ```
@@ -134,12 +140,15 @@ Lost or truncated snapshots, queued prompts, and non-Git workspaces are called o
134
140
  | --- | --- |
135
141
  | Binary file | Cannot be restored (only text diffs are recorded) |
136
142
  | A file exceeds the recorder's text size limit | No content was kept to compare, so it cannot be restored |
143
+ | Renamed file | The recorder only keeps the new path, so the old path cannot be restored: a pure rename is refused, while a rename with edits only rolls back the new path's content |
137
144
  | 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. |
138
145
  | 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 |
139
146
  | 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 |
140
147
  | The file was changed again after being recorded (by you or another tool) | Rollback is **refused** rather than overwriting your later changes |
141
148
  | The conversation has no workspace | Messages-only rollback |
142
149
 
150
+ The recorder compares newline-terminated text, so a restored file that had no final newline gains one.
151
+
143
152
  ## FAQ
144
153
 
145
154
  **Q: Does the sidebar get an extra conversation after a rollback?**
package/README.md CHANGED
@@ -47,12 +47,18 @@
47
47
 
48
48
  <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/message-actions-v1.3.0.png" alt="消息气泡下方的编辑、回滚、复制按钮" width="760">
49
49
 
50
- 点铅笔或回滚按钮之后,小窗直接出现在那个按钮正下方,并用一个小箭头指向它;点窗外或按 Esc 就收起。编辑窗一打开就会读出这条消息之后记录到的文件改动,默认只显示一行「已记录 N 处文件改动」,展开才看具体路径;要不要连文件一起还原,用一个二选一的开关决定——蓝色是「只回滚消息」,红色是「连文件一起回滚」(记录不完整时开关不出现,只能回滚消息):
50
+ 点铅笔或回滚按钮之后,小窗直接出现在那个按钮正下方,并用一个小箭头指向它;点窗外或按 Esc 就收起。编辑窗一打开就会读出这条消息之后记录到的文件改动,默认只显示一行「已记录 N 处文件改动」,展开才看具体路径;要不要连文件一起还原,用一个二选一的开关决定(记录不完整时开关不出现,只能回滚消息):
51
51
 
52
52
  | 编辑小窗 | 回滚确认 |
53
53
  | :---: | :---: |
54
54
  | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/edit-dialog-v1.3.0.png" alt="编辑小窗:文件改动收起成一行,回滚范围二选一" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/rollback-dialog-v1.3.0.png" alt="回滚确认:没有文件改动时只剩一行确认" width="360"> |
55
55
 
56
+ 回滚范围用颜色区分:蓝色是「只回滚消息」,红色是「连文件一起回滚」。选中的一项会变成整块实色,未选中的保留一层同色淡底:
57
+
58
+ | 只回滚消息(蓝色,默认) | 连文件一起回滚(红色) |
59
+ | :---: | :---: |
60
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/rollback-scope-messages-v1.4.0.png" alt="只回滚消息:蓝色实心按钮,默认选中" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/rollback-scope-files-v1.4.0.png" alt="连文件一起回滚:红色实心按钮,下方提示文件会还原" width="360"> |
61
+
56
62
  小窗跟着按钮走:窗口底部放不下时自动翻到按钮上方,窄屏下收窄到屏幕宽度,亮色主题也保持同一套层级:
57
63
 
58
64
  | 靠近底部时翻到上方 | 窄屏(390px) | 亮色主题 |
@@ -84,7 +90,7 @@ dsh plugin --profile web add dsh-message-rewind
84
90
  ```json
85
91
  {
86
92
  "dependencies": {
87
- "dsh-message-rewind": "^1.3.0"
93
+ "dsh-message-rewind": "^1.5.0"
88
94
  }
89
95
  }
90
96
  ```
@@ -136,12 +142,15 @@ DSH 启动日志里会出现 `message-rewind` 且状态为 active;刷新页面
136
142
  | --- | --- |
137
143
  | 二进制文件 | 无法回滚(只记录了文本 diff) |
138
144
  | 单个文件超过记录器的文本大小上限 | 没有保存可回滚的内容,无法回滚 |
145
+ | 重命名文件 | 记录器只按新路径记录,无法恢复旧路径:纯重命名会直接拒绝,改过内容的重命名只能回滚新路径的内容 |
139
146
  | 工作区不在 Git 仓库内,且文件是被 shell 命令改的 | 无法记录,因而无法回滚;在该目录 `git init` 后可完整记录 |
140
147
  | 单轮改动的文件数超过记录上限(默认 500) | 记录被截断,视为快照不完整,只能回滚消息 |
141
148
  | 会话重启或释放后,早先的快照已过期 | 提示「文件改动快照不可用或记录被截断」,此时只能回滚消息 |
142
149
  | 文件在记录之后又被你(或别的工具)改过 | 回滚会被**拒绝**,不会覆盖掉你后来的改动 |
143
150
  | 这个会话没有工作区 | 只能回滚消息 |
144
151
 
152
+ 记录器比较的是补上结尾换行之后的文本,所以回滚一个本来没有结尾换行的文件时,会补一个换行。
153
+
145
154
  ## 常见问题
146
155
 
147
156
  **Q:回滚之后,侧边栏是不是会多出一条对话?**
package/client.js CHANGED
@@ -438,13 +438,19 @@ window.__ModuleLoader__.load({
438
438
  const token = request.token;
439
439
  patchIf(token, { busy: true, error: null });
440
440
  try {
441
+ // A write that reached the Host must never be abandoned: the Host
442
+ // keeps rolling back files and forking regardless, so a client
443
+ // timeout would report failure for work that already happened.
444
+ // `inspect` is a read and keeps its bound; the dialog cannot be
445
+ // closed while this promise is pending (`writing()` guards close).
441
446
  const result = await remote('execute', {
442
447
  sessionId: request.sessionId,
443
448
  seq: request.seq,
444
449
  action: request.kind,
445
450
  text: request.text,
446
451
  rewindFiles,
447
- }, signalFor(request));
452
+ clientTimeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
453
+ });
448
454
  if (current?.token !== token) return;
449
455
  if (!result || typeof result.sessionId !== 'string') throw new Error(t('failed'));
450
456
  publish(null);
package/files.js CHANGED
@@ -49,6 +49,14 @@ export async function readFileState(path, display) {
49
49
  */
50
50
  export function invert(state, diff) {
51
51
  if (state.exists !== diff.after) throw userError('file-changed', `${diff.display} 在记录之后又被修改过,已停止回滚。`);
52
+ // A rename, a permission-only change, or a trailing-newline edit compares
53
+ // equal after the recorder terminates both sides: both files exist but the
54
+ // diff has no hunks. The recorder lists a rename only under its NEW path,
55
+ // so writing that path back can never restore the old one; refuse instead
56
+ // of reporting a silent success.
57
+ if (diff.before && diff.after && (diff.hunks?.length ?? 0) === 0) {
58
+ throw userError('unsupported-diff', `${diff.display} 没有可回滚的文本行,可能是重命名或权限变更。`);
59
+ }
52
60
  // A file this turn created has nothing to invert: the pre-turn state is absence.
53
61
  // Its current content is still compared, so a later edit is refused instead of
54
62
  // being deleted silently.
package/index.js CHANGED
@@ -249,11 +249,25 @@ export function apply(ctx) {
249
249
  sessionId: childId,
250
250
  mode: 'queue',
251
251
  content,
252
+ ...(typeof request?.clientTimeZone === 'string' ? { clientTimeZone: request.clientTimeZone } : {}),
252
253
  }, new AbortController().signal);
253
254
  }
254
255
  } catch (error) {
255
- if (undo) await undo().catch((undoError) => { error.message = `${text(error)};${text(undoError)}`; });
256
- throw error;
256
+ // The files may already be rolled back. Undo first, and keep the undo
257
+ // failure's stable code so the Client warns that files need manual
258
+ // checking instead of collapsing it into the generic `unknown` text.
259
+ let failure = error;
260
+ if (undo) {
261
+ try {
262
+ await undo();
263
+ } catch (undoError) {
264
+ failure = userError('file-restore-failed', `${text(error)};${text(undoError)}`);
265
+ }
266
+ }
267
+ // A rejected prompt leaves a branch nobody asked for; retire it so the
268
+ // sidebar still holds one conversation. Best effort: the failure wins.
269
+ if (childId !== undefined) await purge(childId).catch(() => {});
270
+ throw failure;
257
271
  }
258
272
  return { sessionId: childId, restored, sourceSessionId: sessionId };
259
273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-message-rewind",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
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",