dsh-recall-plugin 1.0.3 → 1.2.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.md +25 -7
- package/lib/client.js +11 -1
- package/lib/index.js +50 -588
- package/lib/maintenance.js +107 -0
- package/lib/scripts.posix.js +290 -0
- package/lib/scripts.pwsh.js +334 -0
- package/lib/snapshots.js +192 -0
- package/lib/store.js +249 -0
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|

|
|
7
|
-

|
|
7
|
+

|
|
8
8
|

|
|
9
9
|

|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
**在任意一条你发过的消息下方**,**点「↶ 撤回」**,**工作区文件和对话历史一起回到那条消息发出之前的状态**。
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
## 界面预览
|
|
16
15
|
- 撤回按钮位置
|
|
17
16
|
|
|
@@ -27,20 +26,22 @@
|
|
|
27
26
|
- **文件 + 对话,整段回退**:撤回的不只是聊天记录,agent 改过的文件也一并回到原样。
|
|
28
27
|
- **不碰你项目自己的 git**:快照存在独立的影子 git 仓库里,你的分支、暂存区、未提交改动统统不受影响;`.git`、`node_modules` 自动排除。
|
|
29
28
|
- **项目目录保持干净**:快照始终存在 `$DSH_HOME` 下,不会往项目里塞任何东西;与会话的沙箱权限无关(workspace-write / read-only 会话照常快照与回退),仅当 home 本身不可写(如指到只读盘)才降级到项目内 `.dsh-recall-snapshots`(降级时页面会提示),home 恢复后自动迁走、清理干净。
|
|
30
|
-
-
|
|
29
|
+
- **可以反复后悔**:只要会话还在(含归档),快照全量保留、不修剪。撤回一次后还能再撤到更早;撤回时被覆盖的文件也一直找得回来。会话被彻底删除后,其快照随之清理(见下)。
|
|
31
30
|
- **先看清单再动手**:点撤回先弹出将变更的文件清单(修改 / 恢复 / 删除),确认后才执行,不会稀里糊涂覆盖。
|
|
32
31
|
- **磁盘友好**:快照走 git delta 压缩,是增量不是整目录拷贝;超过 100MB 的大文件自动跳过。
|
|
32
|
+
- **自动瘦身**:定期 `git gc` 把 loose 对象压 pack(无损,快照一个不丢);会话删除后其快照自动清理;构建产物可经 `exclude.txt` 全局排除(见下)。
|
|
33
33
|
|
|
34
34
|
## 已知限制
|
|
35
35
|
|
|
36
36
|
- 快照在**消息发送时**创建,插件启用前的历史消息没有快照,不显示撤回按钮。
|
|
37
37
|
- 会话第一条用户消息无法回退对话(仅文件回退),因为 fork 需要更早的 turn 边界。
|
|
38
|
-
-
|
|
38
|
+
- 支持 Windows(PowerShell 5.1/7 + git CLI)与 Linux/macOS(bash + git CLI)。Windows 真机验证充分;Linux 已在 WSL2(Ubuntu 26.04,bash 5.3 + git 2.53)实测全流程(含中文路径、home 降级、会话清理、gc);macOS 侧脚本按 bash 3.2 兼容编写,尚未真机实测。
|
|
39
39
|
- 工作区内嵌套的其他 git 仓库(子目录自带 `.git`)不进快照,其内容不参与回退。
|
|
40
|
+
- 文件名含换行/TAB 的极端情形不在 diff 清单的解析能力内(概率可忽略)。
|
|
40
41
|
|
|
41
42
|
## 安装
|
|
42
43
|
|
|
43
|
-
前置:
|
|
44
|
+
前置:git CLI(未装时撤回按钮不出现,页面顶部会提示安装 git,不影响 DSH 运行);Windows 上 PowerShell 5.1 / 7 均可,Linux/macOS 需 bash + git;DSH 0.1.0-rc.x(依赖版本见 `peerDependencies`)。
|
|
44
45
|
|
|
45
46
|
|
|
46
47
|
- DSH 官方插件命令:安装并自动挂载进 web profile
|
|
@@ -59,7 +60,7 @@ pm2 restart <你的dsh进程名> # 若用 pm2 托管
|
|
|
59
60
|
|
|
60
61
|
**验证**:重启后硬刷新页面(Ctrl+Shift+R),悬停任意一条插件启用后发送的用户消息——复制按钮旁出现「↶」即生效。没有按钮?九成是没重启 DSH 进程,或 git CLI 不在 PATH 里。
|
|
61
62
|
|
|
62
|
-
**卸载**:`dsh plugin --profile web remove dsh-recall-plugin`(同时移除依赖与挂载层),快照数据保留在
|
|
63
|
+
**卸载**:`dsh plugin --profile web remove dsh-recall-plugin`(同时移除依赖与挂载层),快照数据保留在 home 下 `dsh-recall-snapshots/`,想彻底清除手动删掉该目录即可。
|
|
63
64
|
|
|
64
65
|
## 使用
|
|
65
66
|
|
|
@@ -67,11 +68,28 @@ pm2 restart <你的dsh进程名> # 若用 pm2 托管
|
|
|
67
68
|
2. 点击 → 确认面板展示将变更的文件清单(修改 / 恢复 / 删除)。
|
|
68
69
|
3. 点「确认回退」→ 文件恢复到该消息发送前的状态;视图切到新会话(该消息及之后的对话移除),原会话归档、随时可找回。
|
|
69
70
|
|
|
71
|
+
## 快照维护与清理
|
|
72
|
+
|
|
73
|
+
快照全量保留的前提是「会话还有找回的可能」,在此之上插件自动控制磁盘占用,无需手动管理:
|
|
74
|
+
|
|
75
|
+
- **定期 gc**:每 50 条快照或距上次 gc 24 小时(先到先触发),后台执行 `git gc` 把 loose 对象压成 pack。无损操作——所有快照照常可回退。节流凭据写在影子仓库内的 `gc.stamp`,重启 DSH 不会重置周期。两个阈值可用环境变量覆盖(一般用不着):`DSH_RECALL_GC_SNAPS`、`DSH_RECALL_GC_HOURS`。
|
|
76
|
+
- **会话删除联动清理**:会话被彻底删除(会话日志从磁盘消失)后,下一次维护会自动删除该会话的全部快照并释放空间。**归档不算删除**——撤回功能自己归档的原会话日志仍在,快照保留、随时可从归档找回。判断很保守:会话只是冷着(不内存里)不会误清;无法核实日志状态时宁可不清。
|
|
77
|
+
- **用户自定义排除**:在 home 下 `dsh-recall-snapshots/exclude.txt`(即 `$DSH_HOME/dsh-recall-snapshots/exclude.txt`,未设置时为 `~/.dsh/dsh-recall-snapshots/exclude.txt`;UTF-8)里一行一条 gitignore 风格 pattern(`#` 开头为注释),例如:
|
|
78
|
+
|
|
79
|
+
```gitignore
|
|
80
|
+
# 构建产物不进快照
|
|
81
|
+
dist/
|
|
82
|
+
build/
|
|
83
|
+
*.log
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
对所有项目生效,下一次快照/回退立即应用,无需重启。新增排除只影响之后的快照;**回退到更早的快照时,当时尚未排除的文件仍会被恢复**(回到当时的状态,这正是回退语义)。想彻底清掉已进快照的目录,可手动删除 home 下 `dsh-recall-snapshots/` 里对应项目的哈希目录。
|
|
87
|
+
|
|
70
88
|
## 工作原理
|
|
71
89
|
|
|
72
90
|
每条用户消息发送时(agent 动文件之前),工作区被快照进一个独立的影子 git 仓库;撤回时用 `git archive` 恢复文件、通过 DSH 官方 `sessions.fork` 机制把会话切到该消息之前。二进制安全,全程不触碰项目自身的 git 状态。
|
|
73
91
|
|
|
74
|
-
-
|
|
92
|
+
- 快照存储:home 下 `dsh-recall-snapshots/<SHA256(项目绝对路径)>/`,内含影子 git 仓库(`git/`,tag 名为 `snap-<消息ID>`)与索引文件 `index.json`(消息 ID → 快照时间 / 会话)。Windows 上脚本走 PowerShell,Linux/macOS 走 bash(按 `ctx.shell` 平台层挂载的执行器自动分叉)。
|
|
75
93
|
- 想直接翻历史快照:
|
|
76
94
|
|
|
77
95
|
```powershell
|
package/lib/client.js
CHANGED
|
@@ -118,19 +118,29 @@ window.__ModuleLoader__.load({
|
|
|
118
118
|
initedSessionId = sessionId
|
|
119
119
|
initDone = api('init', { sessionId }).then((res) => {
|
|
120
120
|
const notice = res && res.notice
|
|
121
|
+
if (notice && notice.unsupported) {
|
|
122
|
+
showNotice('unsupported', '撤回插件仅支持 Windows / Linux / macOS,当前平台的快照不可用。')
|
|
123
|
+
}
|
|
121
124
|
if (notice && notice.gitMissing) {
|
|
122
125
|
showNotice('git', '未检测到 git CLI,撤回功能不可用(快照引擎依赖 git)。安装 git 并重启 DSH 后即可使用。')
|
|
123
126
|
}
|
|
124
127
|
if (notice && notice.homeFallback) {
|
|
125
128
|
showNotice('home', 'home 目录不可写,快照已降级存储到项目内 .dsh-recall-snapshots 目录。')
|
|
126
129
|
}
|
|
127
|
-
}).catch(() => {
|
|
130
|
+
}).catch(() => {
|
|
131
|
+
// init 失败(如页面先于 Host API 就绪加载)时清掉标记:否则本会话
|
|
132
|
+
// 内被判定“已初始化”,撤回按钮永不出现;清掉后下一条消息挂载会重试
|
|
133
|
+
if (initedSessionId === sessionId) initedSessionId = null
|
|
134
|
+
})
|
|
128
135
|
return initDone
|
|
129
136
|
}
|
|
130
137
|
|
|
131
138
|
// 消息时间:当天只显示时分,跨天显示月/日 时分
|
|
132
139
|
function clockText(ms) {
|
|
133
140
|
try {
|
|
141
|
+
// time 字段缺失或非法时返回空串:Invalid Date 不会 throw,
|
|
142
|
+
// 不拦会渲染出 "NaN/NaN NaN:NaN" 这样的坏时间戳
|
|
143
|
+
if (!ms || isNaN(new Date(ms).getTime())) return ''
|
|
134
144
|
const d = new Date(ms)
|
|
135
145
|
const now = new Date()
|
|
136
146
|
const sameDay = d.getFullYear() === now.getFullYear() && d.getMonth() === now.getMonth() && d.getDate() === now.getDate()
|