dsh-message-rewind 1.4.1 → 1.5.1
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 +6 -1
- package/README.md +6 -1
- package/client.js +7 -1
- package/files.js +8 -0
- package/index.js +51 -13
- 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.1"
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
```
|
|
@@ -140,17 +140,22 @@ 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?**
|
|
152
155
|
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 and rollbacks therefore do not pile up same-titled archive entries. If you referenced that session ID elsewhere, fetch it again. When the first message is rolled back, the replacement is a new conversation that has not been titled yet, so it may show the default title.
|
|
153
156
|
|
|
157
|
+
The pin follows the replacement (it moves to the front of the pinned rows); the **manual sort position** is stored in the browser, which the plugin cannot read, so the row lands at the end of its group — drag it back manually.
|
|
158
|
+
|
|
154
159
|
**Q: Can the original record be recovered?**
|
|
155
160
|
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.
|
|
156
161
|
|
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.1"
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
```
|
|
@@ -142,17 +142,22 @@ 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:回滚之后,侧边栏是不是会多出一条对话?**
|
|
154
157
|
不会,始终只有一条对话(标题通常沿用原会话)。但底层会话 ID 会变:DSH 的会话日志是只追加的,没有「删掉中间一段」的接口,插件只能 fork 出一个截断后的分支,再把原会话从侧边栏摘掉并直接删除其日志目录;正常路径不写入归档。所以反复编辑/回滚不会在归档里堆出同名会话;如果你在别处引用过这个会话 ID,需要重新取一次。回滚的是第一条消息时,替换出来的新会话还没有标题,可能先显示默认标题。
|
|
155
158
|
|
|
159
|
+
置顶会跟着新会话走(会排在置顶区最前);但「手动排序」的位置保存在浏览器本地,插件读不到,新行会落在分组末尾,需要手动拖回原位。
|
|
160
|
+
|
|
156
161
|
**Q:原会话的记录还能找回吗?**
|
|
157
162
|
正常情况下会被直接删除,不进入归档。只有当运行中的原会话摘不掉,或日志目录被占用、删不掉时,才会退回归档兜底;失败也不会静默丢日志。
|
|
158
163
|
|
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
|
@@ -189,21 +189,45 @@ export function apply(ctx) {
|
|
|
189
189
|
return registry.list().find((workspace) => workspace.sessionIds.includes(sessionId));
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Move a source pin to the replacement branch. The registry pin set is keyed
|
|
194
|
+
* by session id, so a fork starts unpinned; `pinSession` prepends, which puts
|
|
195
|
+
* the replacement at the front of the pinned rows. Best effort on purpose: a
|
|
196
|
+
* rejected pin must never fail the rewind itself.
|
|
197
|
+
* @param sessionId - the cut source, still pinned at this point.
|
|
198
|
+
* @param childId - the replacement that receives the pin.
|
|
199
|
+
*/
|
|
200
|
+
async function carryPin(sessionId, childId) {
|
|
201
|
+
const pinned = ctx.get('workspaceRegistry')?.pinnedSessionIds;
|
|
202
|
+
if (!Array.isArray(pinned) || !pinned.includes(sessionId)) return;
|
|
203
|
+
try {
|
|
204
|
+
await ctx.workspaceController.pinSession({ sessionId: childId });
|
|
205
|
+
} catch {
|
|
206
|
+
/* the branch is live and attached; an unexpected pin refusal leaves it unpinned */
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
192
210
|
async function forkOrCreate(sessionId, boundary, meta) {
|
|
211
|
+
let childId;
|
|
193
212
|
if (boundary !== undefined) {
|
|
194
213
|
const forked = await ctx.sessionController.fork({ sessionId, atSeq: boundary });
|
|
195
|
-
|
|
214
|
+
childId = forked.sessionId;
|
|
215
|
+
} else {
|
|
216
|
+
// The first-message cut has no boundary to fork at, so it creates a fresh
|
|
217
|
+
// session. A bare `cwd` is not attached to any workspace, while the fork
|
|
218
|
+
// path is: reuse the source workspace so the conversation stays in its group.
|
|
219
|
+
const request = {};
|
|
220
|
+
const workspace = workspaceFor(sessionId);
|
|
221
|
+
if (workspace !== undefined) request.workspaceId = workspace.id;
|
|
222
|
+
else if (meta.cwd !== undefined) request.cwd = meta.cwd;
|
|
223
|
+
if (meta.agentPreset !== undefined) request.agentPreset = meta.agentPreset;
|
|
224
|
+
const created = await ctx.sessionController.create(request);
|
|
225
|
+
childId = created.sessionId;
|
|
196
226
|
}
|
|
197
|
-
//
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const workspace = workspaceFor(sessionId);
|
|
202
|
-
if (workspace !== undefined) request.workspaceId = workspace.id;
|
|
203
|
-
else if (meta.cwd !== undefined) request.cwd = meta.cwd;
|
|
204
|
-
if (meta.agentPreset !== undefined) request.agentPreset = meta.agentPreset;
|
|
205
|
-
const created = await ctx.sessionController.create(request);
|
|
206
|
-
return created.sessionId;
|
|
227
|
+
// Pin the replacement before the client can open it and before `purge`
|
|
228
|
+
// retires the source; the sidebar then shows it straight away.
|
|
229
|
+
await carryPin(sessionId, childId);
|
|
230
|
+
return childId;
|
|
207
231
|
}
|
|
208
232
|
|
|
209
233
|
async function inspect(sessionId, seq) {
|
|
@@ -249,11 +273,25 @@ export function apply(ctx) {
|
|
|
249
273
|
sessionId: childId,
|
|
250
274
|
mode: 'queue',
|
|
251
275
|
content,
|
|
276
|
+
...(typeof request?.clientTimeZone === 'string' ? { clientTimeZone: request.clientTimeZone } : {}),
|
|
252
277
|
}, new AbortController().signal);
|
|
253
278
|
}
|
|
254
279
|
} catch (error) {
|
|
255
|
-
|
|
256
|
-
|
|
280
|
+
// The files may already be rolled back. Undo first, and keep the undo
|
|
281
|
+
// failure's stable code so the Client warns that files need manual
|
|
282
|
+
// checking instead of collapsing it into the generic `unknown` text.
|
|
283
|
+
let failure = error;
|
|
284
|
+
if (undo) {
|
|
285
|
+
try {
|
|
286
|
+
await undo();
|
|
287
|
+
} catch (undoError) {
|
|
288
|
+
failure = userError('file-restore-failed', `${text(error)};${text(undoError)}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// A rejected prompt leaves a branch nobody asked for; retire it so the
|
|
292
|
+
// sidebar still holds one conversation. Best effort: the failure wins.
|
|
293
|
+
if (childId !== undefined) await purge(childId).catch(() => {});
|
|
294
|
+
throw failure;
|
|
257
295
|
}
|
|
258
296
|
return { sessionId: childId, restored, sourceSessionId: sessionId };
|
|
259
297
|
}
|
package/package.json
CHANGED