dsh-message-rewind 1.2.0 → 1.2.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 CHANGED
@@ -25,19 +25,19 @@ Only messages you sent have these buttons. The **Copy** button is still there, i
25
25
 
26
26
  Your own messages get **edit / delete / copy** buttons under the bubble:
27
27
 
28
- <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/message-actions.png" alt="Edit, delete and copy buttons under a user message" width="760">
28
+ <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/message-actions.png" alt="Edit, delete and copy buttons under a user message" width="760">
29
29
 
30
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:
31
31
 
32
32
  | Edit popover | Delete confirmation |
33
33
  | :---: | :---: |
34
- | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/edit-dialog.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/delete-dialog.png" alt="Delete confirmation: a one-line confirm when no files changed" width="360"> |
34
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/edit-dialog.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/v1.2.0/img/delete-dialog.png" alt="Delete confirmation: a one-line confirm when no files changed" width="360"> |
35
35
 
36
36
  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:
37
37
 
38
38
  | Flips above near the bottom | Narrow screen (390px) | Light theme |
39
39
  | :---: | :---: | :---: |
40
- | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-flip.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.png" alt="Popover narrowed to a 390px viewport" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-light.png" alt="Delete popover in the light theme" width="240"> |
40
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-flip.png" alt="Popover flipped above the button, arrow pointing down at it" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-narrow.png" alt="Popover narrowed to a 390px viewport" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-light.png" alt="Delete popover in the light theme" width="240"> |
41
41
 
42
42
  Snapshot and Git-worktree limits are shown in the popover itself, not after a failed operation.
43
43
 
package/README.md CHANGED
@@ -27,19 +27,19 @@
27
27
 
28
28
  自己发出的消息,气泡下方会多出「编辑 / 删除 / 复制」三个按钮:
29
29
 
30
- <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/message-actions.png" alt="消息气泡下方的编辑、删除、复制按钮" width="760">
30
+ <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/message-actions.png" alt="消息气泡下方的编辑、删除、复制按钮" width="760">
31
31
 
32
32
  点铅笔或垃圾桶之后,小窗直接出现在那个按钮正下方,并用一个小箭头指向它;点窗外或按 Esc 就收起。编辑窗一打开就会读出这条消息之后记录到的文件改动,默认只显示一行「已记录 N 处文件改动」,展开才看具体路径;要不要连文件一起还原,用一个二选一的开关决定:
33
33
 
34
34
  | 编辑小窗 | 删除确认 |
35
35
  | :---: | :---: |
36
- | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/edit-dialog.png" alt="编辑小窗:文件改动收起成一行,回滚范围二选一" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/delete-dialog.png" alt="删除确认:没有文件改动时只剩一行确认" width="360"> |
36
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/edit-dialog.png" alt="编辑小窗:文件改动收起成一行,回滚范围二选一" width="360"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/delete-dialog.png" alt="删除确认:没有文件改动时只剩一行确认" width="360"> |
37
37
 
38
38
  小窗跟着按钮走:窗口底部放不下时自动翻到按钮上方,窄屏下收窄到屏幕宽度,亮色主题也保持同一套层级:
39
39
 
40
40
  | 靠近底部时翻到上方 | 窄屏(390px) | 亮色主题 |
41
41
  | :---: | :---: | :---: |
42
- | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-flip.png" alt="小窗翻到按钮上方,箭头朝下指向按钮" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-narrow.png" alt="窄屏下小窗收窄到屏幕宽度" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/main/img/popover-light.png" alt="亮色主题下的删除小窗" width="240"> |
42
+ | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-flip.png" alt="小窗翻到按钮上方,箭头朝下指向按钮" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-narrow.png" alt="窄屏下小窗收窄到屏幕宽度" width="240"> | <img src="https://raw.githubusercontent.com/xCube007/dsh-message-rewind/v1.2.0/img/popover-light.png" alt="亮色主题下的删除小窗" width="240"> |
43
43
 
44
44
  快照失效、工作区不在 Git 仓库等限制也会直接标在小窗里,不用等到操作失败才知道。
45
45
 
package/files.test.js CHANGED
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * File-rewind self-check against a real temporary directory. The recorded
3
3
  * diffs are handcrafted to match what `dsh-workspace-changes` produces: it diffs
4
- * newline-terminated text with jsdiff, so every hunk line carries its `\n`, and a
5
- * deletion is `before: true, after: false`.
4
+ * newline-terminated text with jsdiff but hands back every hunk line without its
5
+ * newline — an empty body is one blank line — and a deletion is
6
+ * `before: true, after: false`.
6
7
  */
7
8
  import assert from 'node:assert/strict';
8
9
  import { promises as fsp } from 'node:fs';
@@ -49,6 +50,26 @@ await check('created file is removed', async () => {
49
50
  await assert.rejects(() => fsp.stat(abs(createdName)));
50
51
  });
51
52
 
53
+ // --- the recorder's hunk lines carry no newline; a blank line is one line ---
54
+ const blankCreatedName = 'blank-created.txt';
55
+ const blankCreatedDiff = textDiff(blankCreatedName, false, true, [{ oldStart: 0, oldLines: 0, newStart: 1, newLines: 3, lines: ['+a', '+', '+b'] }]);
56
+ await check('created file with a blank line is removed', async () => {
57
+ await fsp.writeFile(abs(blankCreatedName), 'a\n\nb\n', 'utf8');
58
+ const targets = await planRewind(readDiffFrom({ '13:0': blankCreatedDiff }), recordsFor([{ seq: 13, files: [{ path: blankCreatedName, display: blankCreatedName }] }]));
59
+ assert.deepEqual([...targets.values()][0].original, { exists: false, text: null });
60
+ await applyRewind(targets);
61
+ await assert.rejects(() => fsp.stat(abs(blankCreatedName)));
62
+ });
63
+
64
+ const blankEditedName = 'blank-edited.txt';
65
+ const blankEditedDiff = textDiff(blankEditedName, true, true, [{ oldStart: 1, oldLines: 4, newStart: 1, newLines: 4, lines: [' a', ' ', '-b', '+B', ' c'] }]);
66
+ await check('blank context line still inverts a modification', async () => {
67
+ await fsp.writeFile(abs(blankEditedName), 'a\n\nB\nc\n', 'utf8');
68
+ const targets = await planRewind(readDiffFrom({ '14:0': blankEditedDiff }), recordsFor([{ seq: 14, files: [{ path: blankEditedName, display: blankEditedName }] }]));
69
+ await applyRewind(targets);
70
+ assert.equal(await fsp.readFile(abs(blankEditedName), 'utf8'), 'a\n\nb\nc\n');
71
+ });
72
+
52
73
  // --- a turn that modified a file is reverted -------------------------------
53
74
  const editedName = 'edited.txt';
54
75
  const editedDiff = textDiff(editedName, true, true, [{ oldStart: 1, oldLines: 3, newStart: 1, newLines: 3, lines: [' zero\n', ' one\n', '-two\n', '+TWO\n'] }]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-message-rewind",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
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",
package/rewind.js CHANGED
@@ -65,6 +65,19 @@ export function terminated(text) {
65
65
  return text.endsWith('\n') ? text : `${text}\n`;
66
66
  }
67
67
 
68
+ /**
69
+ * One hunk line's body with its terminating newline. The recorder's jsdiff
70
+ * output drops the newline from every hunk line, so an empty body means one
71
+ * blank line rather than no line; older fixtures keep the newline. Both shapes
72
+ * must read as exactly one line ending.
73
+ * @param body - the text after the leading marker.
74
+ * @returns the body with one terminating newline.
75
+ */
76
+ function lineText(body) {
77
+ if (body === '') return '\n';
78
+ return body.endsWith('\n') ? body : `${body}\n`;
79
+ }
80
+
68
81
  /**
69
82
  * Undo one recorded diff against the current text.
70
83
  * A hunk carries only changed and context lines; unrelated trailing lines are retained.
@@ -84,7 +97,7 @@ export function inversePatch(current, hunks) {
84
97
  cursor = start;
85
98
  for (const line of hunk.lines) {
86
99
  const marker = line[0];
87
- const body = terminated(line.slice(1));
100
+ const body = lineText(line.slice(1));
88
101
  if (marker === '\\') throw userError('unsupported-diff', '无结尾换行的文件差异暂不支持,未回滚任何文件。');
89
102
  if (marker === '+') {
90
103
  if (lines[cursor] !== body) throw userError('file-changed', '文件版本已改变,未回滚任何文件。');
@@ -115,7 +128,7 @@ export function textSide(exists, hunks, after) {
115
128
  for (const hunk of hunks) {
116
129
  for (const line of hunk.lines) {
117
130
  const wanted = after ? line[0] !== '-' : line[0] !== '+';
118
- if (wanted && line[0] !== '\\') lines.push(terminated(line.slice(1)));
131
+ if (wanted && line[0] !== '\\') lines.push(lineText(line.slice(1)));
119
132
  }
120
133
  }
121
134
  if (!exists) {
package/rewind.test.js CHANGED
@@ -72,5 +72,18 @@ assert.equal(terminated(''), '');
72
72
  assert.equal(inversePatch('abc', [{ oldStart: 0, oldLines: 0, newStart: 1, newLines: 1, lines: ['+abc'] }]), '');
73
73
  const unterminated = [{ oldStart: 1, oldLines: 1, newStart: 1, newLines: 2, lines: [' x\n', '+y'] }];
74
74
  assert.equal(inversePatch('x\ny', unterminated), 'x\n');
75
+ // The recorder's jsdiff output strips the newline from every hunk line, and an
76
+ // empty body is one blank line rather than no line; both shapes must invert.
77
+ const stripped = [{ oldStart: 1, oldLines: 4, newStart: 1, newLines: 4, lines: [' a', ' ', '-b', '+B', ' c'] }];
78
+ assert.equal(textSide(true, stripped, true), 'a\n\nB\nc\n');
79
+ assert.equal(textSide(true, stripped, false), 'a\n\nb\nc\n');
80
+ assert.equal(inversePatch('a\n\nB\nc\n', stripped), 'a\n\nb\nc\n');
81
+ const insertedBlank = [{ oldStart: 1, oldLines: 4, newStart: 1, newLines: 5, lines: [' a', ' ', ' b', '+', ' c'] }];
82
+ assert.equal(textSide(true, insertedBlank, true), 'a\n\nb\n\nc\n');
83
+ assert.equal(inversePatch('a\n\nb\n\nc\n', insertedBlank), 'a\n\nb\nc\n');
84
+ const createdBlank = [{ oldStart: 0, oldLines: 0, newStart: 1, newLines: 3, lines: ['+a', '+', '+b'] }];
85
+ assert.equal(textSide(true, createdBlank, true), 'a\n\nb\n');
86
+ assert.equal(textSide(false, createdBlank, false), null);
87
+
75
88
  console.log('rewind self-check passed');
76
89