dsh-message-rewind 1.4.1 → 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 +4 -1
- package/README.md +4 -1
- package/client.js +7 -1
- package/files.js +8 -0
- package/index.js +16 -2
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -88,7 +88,7 @@ If you prefer editing the profile yourself, the manual route is the same three s
|
|
|
88
88
|
```json
|
|
89
89
|
{
|
|
90
90
|
"dependencies": {
|
|
91
|
-
"dsh-message-rewind": "^1.
|
|
91
|
+
"dsh-message-rewind": "^1.5.0"
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
```
|
|
@@ -140,12 +140,15 @@ Lost or truncated snapshots, queued prompts, and non-Git workspaces are called o
|
|
|
140
140
|
| --- | --- |
|
|
141
141
|
| Binary file | Cannot be restored (only text diffs are recorded) |
|
|
142
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 |
|
|
143
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. |
|
|
144
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 |
|
|
145
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 |
|
|
146
147
|
| The file was changed again after being recorded (by you or another tool) | Rollback is **refused** rather than overwriting your later changes |
|
|
147
148
|
| The conversation has no workspace | Messages-only rollback |
|
|
148
149
|
|
|
150
|
+
The recorder compares newline-terminated text, so a restored file that had no final newline gains one.
|
|
151
|
+
|
|
149
152
|
## FAQ
|
|
150
153
|
|
|
151
154
|
**Q: Does the sidebar get an extra conversation after a rollback?**
|
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ dsh plugin --profile web add dsh-message-rewind
|
|
|
90
90
|
```json
|
|
91
91
|
{
|
|
92
92
|
"dependencies": {
|
|
93
|
-
"dsh-message-rewind": "^1.
|
|
93
|
+
"dsh-message-rewind": "^1.5.0"
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
```
|
|
@@ -142,12 +142,15 @@ DSH 启动日志里会出现 `message-rewind` 且状态为 active;刷新页面
|
|
|
142
142
|
| --- | --- |
|
|
143
143
|
| 二进制文件 | 无法回滚(只记录了文本 diff) |
|
|
144
144
|
| 单个文件超过记录器的文本大小上限 | 没有保存可回滚的内容,无法回滚 |
|
|
145
|
+
| 重命名文件 | 记录器只按新路径记录,无法恢复旧路径:纯重命名会直接拒绝,改过内容的重命名只能回滚新路径的内容 |
|
|
145
146
|
| 工作区不在 Git 仓库内,且文件是被 shell 命令改的 | 无法记录,因而无法回滚;在该目录 `git init` 后可完整记录 |
|
|
146
147
|
| 单轮改动的文件数超过记录上限(默认 500) | 记录被截断,视为快照不完整,只能回滚消息 |
|
|
147
148
|
| 会话重启或释放后,早先的快照已过期 | 提示「文件改动快照不可用或记录被截断」,此时只能回滚消息 |
|
|
148
149
|
| 文件在记录之后又被你(或别的工具)改过 | 回滚会被**拒绝**,不会覆盖掉你后来的改动 |
|
|
149
150
|
| 这个会话没有工作区 | 只能回滚消息 |
|
|
150
151
|
|
|
152
|
+
记录器比较的是补上结尾换行之后的文本,所以回滚一个本来没有结尾换行的文件时,会补一个换行。
|
|
153
|
+
|
|
151
154
|
## 常见问题
|
|
152
155
|
|
|
153
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
|
-
|
|
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
|
-
|
|
256
|
-
|
|
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