dsh-session-rewind 0.0.0-stage → 1.2.8

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 2310770803
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,153 @@
1
+ # dsh-session-rewind
2
+
3
+ [中文](README.md) | English
4
+
5
+ A DSH Web plugin that puts **Rewind** on every finished Turn: a per-Turn control
6
+ in the Chat timeline plus one entry in the Session header, branching the
7
+ conversation at that Turn and restoring the files that Turn changed.
8
+
9
+ In DSH Web, rewind to any **finished Turn**: every Turn in the Chat timeline has a
10
+ `Rewind` button, and the Session header adds one more entry point that lists every
11
+ rewindable Turn of the session. Rewinding forks a new session at that Turn and
12
+ restores the files that Turn changed.
13
+
14
+ ## Two entry points
15
+
16
+ | Where | What it does |
17
+ | --- | --- |
18
+ | The ↶ in the Session header (`conversation.session.header.actions`) | Lists **every** finished Turn of this session (Turn N + prompt preview + file count); pick with ↑↓, confirm with Enter, go back with Esc. After picking a Turn, choose "Rewind conversation only" or "Rewind and restore N files" — no need to scroll back to that Turn. |
19
+ | `Rewind` at the end of each finished Turn (`conversation.chat.turnTail`) | Rewinds that one Turn directly; the panel lets you check the files to restore and choose "Rewind conversation" or "Restore files only". |
20
+
21
+ ## What it does
22
+
23
+ Choosing a Turn opens a small panel with two independent halves:
24
+
25
+ 1. **Rewind the conversation.** A committed Turn cannot be edited in place: the
26
+ session log is append-only and branching is the supported operation. The
27
+ panel therefore creates a *new* session that ends exactly at that Turn
28
+ (`sessions.fork` with the Turn's `turn/end` seq), opens it, and pre-fills its
29
+ composer with the Turn's original user prompt so you can edit it and send it
30
+ again. The original session is left untouched.
31
+ 2. **Restore the files that Turn changed.** While a Turn runs, every file the
32
+ model creates or rewrites is captured *before* the mutation and stored as a
33
+ content-addressed blob. The panel lists those files; the checked ones are put
34
+ back to their pre-Turn content (a file the Turn created is removed).
35
+
36
+ The two halves can be used together (`Rewind conversation`) or separately
37
+ (`Restore files only`).
38
+
39
+ ### Why a fork instead of an in-place rewind
40
+
41
+ The community plugin [`SiriLee/dsh-rewind`](https://github.com/SiriLee/dsh-rewind)
42
+ offers an **in-place rewind** (inside the same session it moves the
43
+ model-visible surface back to an earlier user message by appending a
44
+ `surfaceOp: replace` marker). We borrowed its **entry points and interaction**
45
+ (a ↶ next to each message/Turn, a mode picker, a file impact list,
46
+ ↑↓/Enter/Esc, a header candidate list) but deliberately did **not** adopt its
47
+ in-place rollback, because:
48
+
49
+ - An in-place rewind needs more than an appended marker: the front end must also
50
+ hide the rolled-back rows, and DSH exposes no extension point for that. The
51
+ reference plugin does it by wrapping the private `uiConversation.views`
52
+ registry, and its own source comments say *"The seam is private … not an
53
+ extension point"* — it breaks with version upgrades.
54
+ - `sessions.fork` is the branching capability DSH officially gives the UI — the
55
+ built-in "branch in new chat" button uses it — so it is stable across upgrades
56
+ and naturally satisfies "context truncated + editable + resendable".
57
+
58
+ If you would rather have an in-place rewind (same session, no new session), you
59
+ can install `dsh-rewind-plugin` separately; the two do not conflict.
60
+
61
+ ## Install
62
+
63
+ **Install from the plugin market (recommended):** **Plugins → Discover** →
64
+ **Index sources** → add
65
+ `https://raw.githubusercontent.com/2310770803/dsh-session-rewind/main/index.json`
66
+ → search `rewind` or `Session Rewind` → install. The index format and the release
67
+ process are documented in [docs/publishing.md](docs/publishing.md).
68
+
69
+ This machine (profile `desktop`) already has that index source written into
70
+ `cordis.patch.yml`, so opening Discover shows the entry.
71
+
72
+ **Install from the source directory** (what this machine currently does):
73
+
74
+ ```js
75
+ // plugin_manager
76
+ { action: 'install_bundle', target: 'E:\\\\DeepSeek Harness\\\\dsh-session-rewind' }
77
+ ```
78
+
79
+ ## How it is put together
80
+
81
+ | half | mechanism |
82
+ | --- | --- |
83
+ | conversation | Client `sessions.fork({ sessionId, atSeq })` + `uiWorkspace.openSession`, the same idiom as the built-in branch button; the draft is pre-seeded through the Conversation store's per-session `localStorage` key so the composer already holds the original prompt |
84
+ | files (capture) | `fs/write-intent` / `fs/edit-intent` waterfalls (`{ prepend: true }`), with the tool execution mapped back to its Session through a `tools/pre-execute` `WeakMap` — the same coupling `workspace-changes` uses |
85
+ | files (restore) | text pre-images through the `fs` service (path resolution, locks, version guard); binary pre-images and deletions through Node, on the archive's own recorded absolute path |
86
+
87
+ ## Where data lives
88
+
89
+ ```
90
+ $DSH_HOME/plugin-data/dsh-session-rewind/
91
+ index.json per-session, per-Turn file records
92
+ blobs/<sha256>.bin the pre-Turn bytes
93
+ ```
94
+
95
+ Nothing leaves the machine: the four Host routes are loopback-only,
96
+ same-origin `/api` routes with DSH Web's own Host/Origin trust fence.
97
+
98
+ `GET /api/session-rewind.selfcheck` reports what the running Host has actually
99
+ wired up (archive totals, whether the Web half is in the boot graph, the route
100
+ list). It is read-only and never exposes session content.
101
+
102
+ ## Limits
103
+
104
+ - Only mutations that go through the DSH filesystem service inside a Turn are
105
+ captured. Files changed by a shell command, by `git`, or outside a Turn are
106
+ not recorded and therefore not restored.
107
+ - Files written by tools that bypass the `fs` write-intent waterfall are not
108
+ captured either: the Office tools (`word_create`, `excel_update`, …) call the
109
+ filesystem service directly, so a `.docx`/`.xlsx` they produce is **not** in the
110
+ archive and cannot be rewound. Plain text, Markdown, and source code edited
111
+ through the `write`/`edit` tools are covered.
112
+ - A Turn snapshots at most 200 files, and no pre-image larger than 2 MiB; larger
113
+ files are listed as "not restorable" instead of being silently skipped.
114
+ - Files inside `.git` are never captured, so a restore cannot corrupt the
115
+ repository.
116
+ - The archive keeps the newest 400 Turns; older records are pruned with their
117
+ blobs.
118
+ - A restore writes the recorded content back. It does not re-run anything, and it
119
+ does not delete files the Turn merely *modified*.
120
+ - A plugin-originated write has no Agent context, so the `fs` service refuses it
121
+ by default. Restores rebuild the policy from the Turn's own workspace
122
+ (`workspace-write`) and widen to `danger-full-access` only for a path the
123
+ archive recorded outside it.
124
+ - Capture starts with the Turn that is open when the plugin mounts: a Turn
125
+ already running at install time is recovered from the live log tail, but a
126
+ plugin loaded later than the Turn's first write cannot see earlier mutations.
127
+ - The naming and wording of the panel follow the DSH locale service; the bundled
128
+ dictionaries are Chinese and English.
129
+
130
+ ## Tests
131
+
132
+ The package ships the suites used to verify it; they need no browser and no
133
+ profile:
134
+
135
+ ```
136
+ node test/selftest.mjs # Turn location, prompt extraction, archive, restorer
137
+ node test/route-smoke.mjs # all routes, their fences, and path allow-listing
138
+ node test/client-smoke.mjs # the Web half: both slots, panel, candidate list, fork, draft
139
+ ```
140
+
141
+ ## Package layout
142
+
143
+ | file | role |
144
+ | --- | --- |
145
+ | `cordis.patch.yml` | inserts the `session-rewind` plugin row |
146
+ | `src/index.js` | Host entry, re-exports `apply` / `inject` / `name` |
147
+ | `src/plugin.js` | Host wiring: Turn tracking, mutation capture, the four routes |
148
+ | `src/lib/archive.js` | durable pre-Turn archive, pruning, blob store |
149
+ | `src/lib/restore.js` | putting one captured file back |
150
+ | `src/lib/route.js` | routes and the `/api` trust fence |
151
+ | `lib/client.js` | Web half: the turn-tail control, the header entry, the panel |
152
+ | `locale/*.json` | `meta.title` / `meta.description` for the plugin list |
153
+ | `index.json` | format-1 plugin-market index (see `docs/publishing.md`) |
package/README.md CHANGED
@@ -1,3 +1,163 @@
1
- # Temporary Holding Version
1
+ # dsh-session-rewind · 会话回退
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A DSH Web plugin that puts **Rewind** on every finished Turn: a per-Turn control
4
+ in the Chat timeline plus one entry in the Session header, branching the
5
+ conversation at that Turn and restoring the files that Turn changed.
6
+
7
+ 在 DSH Web 里回退到任意**已完成的回合**:对话时间线的每个回合旁有 `回退` 按钮,会话标题栏还有一个
8
+ 总入口,列出本会话所有可回退的回合;回退会从该回合处分叉出新会话,并把该回合改动过的文件恢复原状。
9
+
10
+ ## 两个入口 · Two entry points
11
+
12
+ | 位置 | 作用 |
13
+ | --- | --- |
14
+ | **你发出的那条消息旁的 ↶** | 点开选「仅回退对话」或「回退对话并恢复文件」。**就地回退**:这条消息及之后的对话内容从模型上下文撤回,原话立刻回到本会话输入框,改完直接重发。 |
15
+ | 会话标题栏的 ↶(`conversation.session.header.actions`) | 列出本会话**所有**可回退的消息(第 N 轮 + 提问预览 + 文件数),↑↓ 选择、Enter 确认、Esc 返回;选中后同样是就地回退,也可以选「在新会话中分支」。 |
16
+ | 每个已完成回合末尾的 `回退`(`conversation.chat.turnTail`) | 旧入口,保留兼容:就这一轮做分叉回退,面板里可勾选要恢复的文件。 |
17
+
18
+ **核心行为(就地回退)**:选中你某条消息 → 追加一条 `surfaceOp: replace` 标记,把模型可见的
19
+ surface 从这条消息起整体撤回 → 被撤回的行从对话里消失(轨迹面板仍可查,日志从未删改)→
20
+ 这条消息的**原文放进输入框**,你可以修改后重新发送。会话不换、不新建。
21
+
22
+ ## What it does · 功能
23
+
24
+ Choosing a Turn opens a small panel with two independent halves:
25
+
26
+ 1. **Rewind the conversation.** A committed Turn cannot be edited in place: the
27
+ session log is append-only and branching is the supported operation. The
28
+ panel therefore creates a *new* session that ends exactly at that Turn
29
+ (`sessions.fork` with the Turn's `turn/end` seq), opens it, and pre-fills its
30
+ composer with the Turn's original user prompt so you can edit it and send it
31
+ again. The original session is left untouched.
32
+ 2. **Restore the files that Turn changed.** While a Turn runs, every file the
33
+ model creates or rewrites is captured *before* the mutation and stored as a
34
+ content-addressed blob. The panel lists those files; the checked ones are put
35
+ back to their pre-Turn content (a file the Turn created is removed).
36
+
37
+ The two halves can be used together (`回退对话`) or separately
38
+ (`仅恢复文件`).
39
+
40
+ 选中某个回合后:
41
+
42
+ 1. **回退对话**:会话日志是只追加的,所以“回退”= 在该回合的 `turn/end` 处**分叉**出一个新会话并打开它,
43
+ 同时把该回合原本的用户输入写回新会话的输入框,你可以直接修改后重新发送;原会话完全不动。
44
+ 2. **恢复文件**:该回合运行期间,每个被创建或改写的文件都会在**写入前**抓取一份原始字节存档。
45
+ 面板会列出这些文件,勾选的会被恢复为修改前的内容;该回合新建的文件会被删除。
46
+
47
+ ### 就地撤回 vs 分叉:两个都给了
48
+
49
+ - **就地回退(主)**:同一会话内撤回,靠一条 `surfaceOp: replace` 标记实现——这是 DSH 自己
50
+ 压缩(compaction)用的同一机制,日志只追加、不删改。
51
+ - **分叉(次)**:`sessions.fork` 在该回合 `turn/end` 处新建一份会话,内置「在新对话中分支」
52
+ 按钮用的就是它,升级最稳。
53
+
54
+ 唯一的妥协在**前端隐藏被撤回的行**:DSH 没有为用户消息提供动作槽,也没有公开「隐藏某段行」
55
+ 的接口,所以这里按参考插件 `SiriLee/dsh-rewind` 的做法在前端补:给每条用户消息注入一个 ↶
56
+ (锚点取行内最后一个按钮的父节点),回退后按 `data-chat-turn` 隐藏该行及之后的行。全部特性
57
+ 检测、卸载即还原;DSH 若在未来提供动作槽,这里会切成槽位实现。
58
+
59
+ ### 参考插件为什么没有全盘照搬
60
+
61
+ 社区里的 [`SiriLee/dsh-rewind`](https://github.com/SiriLee/dsh-rewind) 提供**就地回退**(同一会话内
62
+ 把模型可见 surface 切回更早的用户消息,靠追加一条 `surfaceOp: replace` 标记实现)。我们借鉴了它的
63
+ **入口与交互**(每条消息/每轮旁的 ↶、模式选择、文件影响清单、↑↓/Enter/Esc、标题栏候选列表),但**没有**
64
+ 采用它的就地撤回,原因是:
65
+
66
+ - 就地撤回不仅要追加标记,还必须在**前端**把被撤回的行隐藏起来,而 DSH 没有为此提供扩展点——
67
+ 参考插件是通过包装私有的 `uiConversation.views` registry 做到的,其源码自己注明
68
+ *"The seam is private … not an extension point"*,随版本升级会破。
69
+ - `sessions.fork` 是 DSH 给 UI 的官方分支能力(内置「在新对话中分支」按钮用的就是它),
70
+ 升级稳定,且天然满足“上下文被截断 + 可改可重发”。
71
+
72
+ 如果你更希望要就地撤回(同一会话、不产生新会话),可以另装 `dsh-rewind-plugin`;两者不冲突。
73
+
74
+ ## Install · 安装
75
+
76
+ **从插件市场安装(推荐)**:左侧 **插件 → 发现(Discover)** → **索引源** → 添加
77
+ `https://raw.githubusercontent.com/2310770803/dsh-session-rewind/main/index.json`
78
+ → 搜索 `rewind` 或 `会话回退` → 安装。索引格式与发布流程见 [docs/publishing.md](docs/publishing.md)。
79
+
80
+ 本机(profile `desktop`)已把这个索引源写进 `cordis.patch.yml`,打开「发现」即可看到条目。
81
+
82
+ **从源码目录安装**(本机当前就是这种方式):
83
+
84
+ ```js
85
+ // plugin_manager
86
+ { action: 'install_bundle', target: 'E:\\DeepSeek Harness\\dsh-session-rewind' }
87
+ ```
88
+
89
+ ## How it is put together · 实现
90
+
91
+ | half | mechanism |
92
+ | --- | --- |
93
+ | conversation | Client `sessions.fork({ sessionId, atSeq })` + `uiWorkspace.openSession`, the same idiom as the built-in branch button; the draft is pre-seeded through the Conversation store's per-session `localStorage` key so the composer already holds the original prompt |
94
+ | files (capture) | `fs/write-intent` / `fs/edit-intent` waterfalls (`{ prepend: true }`), with the tool execution mapped back to its Session through a `tools/pre-execute` `WeakMap` — the same coupling `workspace-changes` uses |
95
+ | files (restore) | text pre-images through the `fs` service (path resolution, locks, version guard); binary pre-images and deletions through Node, on the archive's own recorded absolute path |
96
+
97
+ ## Where data lives · 数据位置
98
+
99
+ ```
100
+ $DSH_HOME/plugin-data/dsh-session-rewind/
101
+ index.json per-session, per-Turn file records
102
+ blobs/<sha256>.bin the pre-Turn bytes
103
+ ```
104
+
105
+ Nothing leaves the machine: the four Host routes are loopback-only,
106
+ same-origin `/api` routes with DSH Web's own Host/Origin trust fence.
107
+
108
+ `GET /api/session-rewind.selfcheck` reports what the running Host has actually
109
+ wired up (archive totals, whether the Web half is in the boot graph, the route
110
+ list). It is read-only and never exposes session content.
111
+
112
+ ## Limits · 限制
113
+
114
+ - Only mutations that go through the DSH filesystem service inside a Turn are
115
+ captured. Files changed by a shell command, by `git`, or outside a Turn are
116
+ not recorded and therefore not restored.
117
+ - Files written by tools that bypass the `fs` write-intent waterfall are not
118
+ captured either: the Office tools (`word_create`, `excel_update`, …) call the
119
+ filesystem service directly, so a `.docx`/`.xlsx` they produce is **not** in the
120
+ archive and cannot be rewound. Plain text, Markdown, and source code edited
121
+ through the `write`/`edit` tools are covered.
122
+ - A Turn snapshots at most 200 files, and no pre-image larger than 2 MiB; larger
123
+ files are listed as "not restorable" instead of being silently skipped.
124
+ - Files inside `.git` are never captured, so a restore cannot corrupt the
125
+ repository.
126
+ - The archive keeps the newest 400 Turns; older records are pruned with their
127
+ blobs.
128
+ - A restore writes the recorded content back. It does not re-run anything, and it
129
+ does not delete files the Turn merely *modified*.
130
+ - A plugin-originated write has no Agent context, so the `fs` service refuses it
131
+ by default. Restores rebuild the policy from the Turn's own workspace
132
+ (`workspace-write`) and widen to `danger-full-access` only for a path the
133
+ archive recorded outside it.
134
+ - Capture starts with the Turn that is open when the plugin mounts: a Turn
135
+ already running at install time is recovered from the live log tail, but a
136
+ plugin loaded later than the Turn's first write cannot see earlier mutations.
137
+ - The naming and wording of the panel follow the DSH locale service; the bundled
138
+ dictionaries are Chinese and English.
139
+
140
+ ## Tests · 测试
141
+
142
+ The package ships the suites used to verify it; they need no browser and no
143
+ profile:
144
+
145
+ ```
146
+ node test/selftest.mjs # Turn location, prompt extraction, archive, restorer
147
+ node test/route-smoke.mjs # all routes, their fences, and path allow-listing
148
+ node test/client-smoke.mjs # the Web half: both slots, panel, candidate list, fork, draft
149
+ ```
150
+
151
+ ## Package layout
152
+
153
+ | file | role |
154
+ | --- | --- |
155
+ | `cordis.patch.yml` | inserts the `session-rewind` plugin row |
156
+ | `src/index.js` | Host entry, re-exports `apply` / `inject` / `name` |
157
+ | `src/plugin.js` | Host wiring: Turn tracking, mutation capture, the four routes |
158
+ | `src/lib/archive.js` | durable pre-Turn archive, pruning, blob store |
159
+ | `src/lib/restore.js` | putting one captured file back |
160
+ | `src/lib/route.js` | routes and the `/api` trust fence |
161
+ | `lib/client.js` | Web half: the turn-tail control, the header entry, the panel |
162
+ | `locale/*.json` | `meta.title` / `meta.description` for the plugin list |
163
+ | `index.json` | format-1 plugin-market index (see `docs/publishing.md`) |
@@ -0,0 +1,9 @@
1
+ # Add one dual-face plugin row to the Web profile.
2
+ #
3
+ # The Host half (src/index.js) archives the pre-Turn content of every workspace
4
+ # file a Turn mutates and serves the two rewind routes; dsh.client discovers the
5
+ # browser half from this same package manifest and mounts a rewind control in
6
+ # the Chat turn tail of every finished Turn.
7
+ - insert:
8
+ - id: session-rewind
9
+ name: dsh-session-rewind
package/icon.svg ADDED
@@ -0,0 +1,7 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Session Rewind">
2
+ <rect x="2" y="2" width="60" height="60" rx="14" fill="#111827"/>
3
+ <path d="M27 13a15 15 0 1 1-13.4 8.2" fill="none" stroke="#7DA2F7" stroke-width="5" stroke-linecap="round"/>
4
+ <path d="M12.5 9.5v12h12" fill="none" stroke="#7DA2F7" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
5
+ <path d="M37 30h11a3 3 0 0 1 3 3v16a3 3 0 0 1-3 3H37a3 3 0 0 1-3-3V33a3 3 0 0 1 3-3z" fill="none" stroke="#E5E7EB" stroke-width="3"/>
6
+ <path d="M15 40h8M15 46h8M15 52h8" fill="none" stroke="#E5E7EB" stroke-width="3" stroke-linecap="round"/>
7
+ </svg>