@xiaoyuyu6420/dsh-backup 0.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/LICENSE +21 -0
- package/README.md +123 -0
- package/README.zh.md +115 -0
- package/cordis.patch.yml +4 -0
- package/lib/client.js +334 -0
- package/lib/index.js +941 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 xiaoyuyu6420
|
|
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.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# dsh-backup
|
|
2
|
+
|
|
3
|
+
[](https://github.com/topics/dsh-plugin)
|
|
4
|
+
|
|
5
|
+
One-command backup **and restore** for DeepSeek Harness user data — sessions,
|
|
6
|
+
settings, credentials, skills, and plugin config under `~/.dsh`, excluding
|
|
7
|
+
reinstallable `node_modules` — with sha256 checksums, integrity verification,
|
|
8
|
+
automatic rotation, and scheduled auto-backup that survives restarts. Works on
|
|
9
|
+
macOS, Linux, and Windows.
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
- **`/backup`** — immediately back up `~/.dsh` to `~/Desktop/dsh-backups/dsh-<timestamp>.tar.gz`
|
|
14
|
+
- **`/backup list`** — list existing backups (name + size) and auto-backup status
|
|
15
|
+
- **`/backup verify [prefix|all]`** — validate archive checksums (default: the newest)
|
|
16
|
+
- **`/backup restore <prefix|latest> [--dry-run]`** — restore `~/.dsh` from an archive
|
|
17
|
+
- **`/backup auto <N>|off|status`** — auto-backup every N hours (1–720; keeps 3 copies below 24h, 7 otherwise; persisted across restarts)
|
|
18
|
+
- **`/backup --keep N`** — override the rotation count (default 7)
|
|
19
|
+
- **`/backup github status|sync`** — GitHub sync status / push now
|
|
20
|
+
- **`backup_dsh` tool** — same capability for the model (`mode=backup|list|verify|restore|auto`)
|
|
21
|
+
|
|
22
|
+
## GitHub sync
|
|
23
|
+
|
|
24
|
+
With `config.githubRepo` set, every backup (manual, automatic, or panel) is
|
|
25
|
+
also pushed to a Git repository — archives, checksum sidecars, and rotation
|
|
26
|
+
deletions stay in sync:
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
- id: dsh-backup
|
|
30
|
+
name: 'dsh-backup'
|
|
31
|
+
config:
|
|
32
|
+
githubRepo: 'your-name/dsh-backups' # owner/repo, full URL, or a local path
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Use a **private** repository — archives contain plaintext credentials. For an
|
|
36
|
+
`https` remote, set the token in the environment (`DSH_BACKUP_GITHUB_TOKEN` or
|
|
37
|
+
`GITHUB_TOKEN`); it is only written into the sync worktree's credential file
|
|
38
|
+
(never process args). Push is `HEAD:main --force-with-lease`; archives over
|
|
39
|
+
90 MB are skipped with a notice. State (last push, last error) lives in
|
|
40
|
+
`<destination>/auto.json` and shows in the panel and `/backup github status`.
|
|
41
|
+
|
|
42
|
+
## Settings panel (Web)
|
|
43
|
+
|
|
44
|
+
The same controls have a visual entry: a **Backup** tab inside Settings → Plugins
|
|
45
|
+
(`dsh web`). It shows the destination, auto-backup state, GitHub sync status, and
|
|
46
|
+
every archive with its size, and offers one-click back-up-now, per-archive
|
|
47
|
+
verify, download, and restore with a dry-run preview plus explicit confirmation.
|
|
48
|
+
Downloads stream from the loopback-only route `GET /backup-download/<name>`.
|
|
49
|
+
The tab talks to the host through the `backupPanel` Typert Remote namespace
|
|
50
|
+
(`/api` RPC); the browser bundle ships prebuilt in `lib/client.js` — no build
|
|
51
|
+
step at install time.
|
|
52
|
+
|
|
53
|
+
## How restore works
|
|
54
|
+
|
|
55
|
+
Restore is safe by construction:
|
|
56
|
+
|
|
57
|
+
1. The archive's sha256 is verified first — a corrupt archive never touches existing data.
|
|
58
|
+
2. Entries are listed and any path outside the backup root rejects the restore (tar path-traversal guard).
|
|
59
|
+
3. The current `~/.dsh` is snapshotted, then moved aside to `~/.dsh.pre-restore-<timestamp>` — restore replaces rather than merges.
|
|
60
|
+
4. The archive is extracted; restart `dsh` afterwards so restored sessions and settings take effect.
|
|
61
|
+
|
|
62
|
+
`--dry-run` shows the archive summary without writing anything.
|
|
63
|
+
|
|
64
|
+
## Configuration (optional)
|
|
65
|
+
|
|
66
|
+
Plugin `config` in the active cordis profile:
|
|
67
|
+
|
|
68
|
+
```yaml
|
|
69
|
+
- id: dsh-backup
|
|
70
|
+
name: 'dsh-backup'
|
|
71
|
+
config:
|
|
72
|
+
destination: '~/Backups/dsh' # default ~/Desktop/dsh-backups
|
|
73
|
+
keep: 10 # default rotation count
|
|
74
|
+
exclude: # extra tar --exclude patterns
|
|
75
|
+
- '*cache*'
|
|
76
|
+
githubRepo: 'name/dsh-backups' # optional GitHub sync (see below)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Auto-backup state lives in `<destination>/auto.json` and resumes after restart.
|
|
80
|
+
|
|
81
|
+
## Security note
|
|
82
|
+
|
|
83
|
+
Backups contain plaintext credentials (`.credentials.yaml`, `qq-bridge/config.json`).
|
|
84
|
+
Archives and checksum sidecars are chmod 600 on POSIX (Windows relies on
|
|
85
|
+
per-user profile ACLs), but do **not** sync the backup directory to untrusted
|
|
86
|
+
locations, and treat archives as sensitive as your API keys.
|
|
87
|
+
|
|
88
|
+
Storage note: the plugin writes its own data (archives, checksum sidecars,
|
|
89
|
+
`auto.json`) directly through `node:fs`, the same pattern as DSH's own session
|
|
90
|
+
persistence — the `ctx.fs` capability is the model-facing sandboxed surface and
|
|
91
|
+
does not apply to host-owned storage.
|
|
92
|
+
|
|
93
|
+
## Install
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
dsh plugin --profile web add dsh-backup
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Then restart `dsh web` (plugin discovery is cached per process) and run `/backup`,
|
|
100
|
+
or open Settings → Plugins → Backup.
|
|
101
|
+
|
|
102
|
+
## Requirements
|
|
103
|
+
|
|
104
|
+
- macOS, Linux, or Windows 10+ with `tar` in PATH (Windows ships bsdtar in
|
|
105
|
+
System32; Git Bash's GNU tar also works — checksums prefer `sha256sum`/`shasum`
|
|
106
|
+
and fall back to an in-process hash on Windows)
|
|
107
|
+
- DSH `0.1.0-rc.6` or compatible
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
Zero runtime dependencies — the host plugin is `lib/index.js`. The browser half
|
|
112
|
+
lives in `src/` and is bundled (zod inlined, React/Cordis external) into
|
|
113
|
+
`lib/client.js`, which is committed so git installs never build:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
node scripts/build-client.mjs # rebuild the client bundle after editing src/
|
|
117
|
+
node scripts/smoke.mjs # host smoke suite (real temp dir, mocked DSH services)
|
|
118
|
+
node scripts/smoke-client.mjs # client bundle: handshake, schemas, tab registration, SSR
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# dsh-backup
|
|
2
|
+
|
|
3
|
+
[](https://github.com/topics/dsh-plugin)
|
|
4
|
+
|
|
5
|
+
一键备份**与恢复** DeepSeek Harness 用户数据——`~/.dsh` 下的会话、设置、凭据、
|
|
6
|
+
技能与插件配置(排除可重装的 node_modules),自动生成 sha256 校验和、完整性
|
|
7
|
+
校验、自动轮换,定时自动备份状态落盘、重启续跑。支持 macOS / Linux / Windows。
|
|
8
|
+
|
|
9
|
+
## 命令
|
|
10
|
+
|
|
11
|
+
- **`/backup`** —— 立即备份 `~/.dsh` 到 `~/Desktop/dsh-backups/dsh-<时间戳>.tar.gz`
|
|
12
|
+
- **`/backup list`** —— 列出已有备份(名称 + 大小)与自动备份状态
|
|
13
|
+
- **`/backup verify [前缀|all]`** —— 校验归档完整性(缺省校验最新一份)
|
|
14
|
+
- **`/backup restore <前缀|latest> [--dry-run]`** —— 从归档恢复 `~/.dsh`
|
|
15
|
+
- **`/backup auto <N小时>|off|status`** —— 每 N 小时自动备份(1~720;<24h 保留 3 份,否则 7 份;状态持久化,重启续跑)
|
|
16
|
+
- **`/backup --keep N`** —— 覆盖轮换保留份数(默认 7)
|
|
17
|
+
- **`/backup github status|sync`** —— GitHub 同步状态 / 立即推送
|
|
18
|
+
- **`backup_dsh` 工具** —— 模型可调用同一能力(`mode=backup|list|verify|restore|auto`)
|
|
19
|
+
|
|
20
|
+
## GitHub 同步
|
|
21
|
+
|
|
22
|
+
配置 `config.githubRepo` 后,每次备份(手动 / 定时 / 面板)都会把归档、校验
|
|
23
|
+
边车与轮换删除一并推送到 Git 仓库:
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
- id: dsh-backup
|
|
27
|
+
name: 'dsh-backup'
|
|
28
|
+
config:
|
|
29
|
+
githubRepo: '你的账号/dsh-backups' # owner/repo、完整 URL 或本地路径
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**请使用私有仓库**——归档含明文凭据。https 远端需要环境变量 token
|
|
33
|
+
(`DSH_BACKUP_GITHUB_TOKEN` 或 `GITHUB_TOKEN`),token 只写入同步工作树的
|
|
34
|
+
credential 文件(不进进程参数)。推送为 `HEAD:main --force-with-lease`;
|
|
35
|
+
超过 90MB 的归档会跳过并提示。同步状态(上次推送 / 错误)存于
|
|
36
|
+
`<destination>/auto.json`,面板与 `/backup github status` 可见。
|
|
37
|
+
|
|
38
|
+
## Settings 可视面板(Web)
|
|
39
|
+
|
|
40
|
+
同样的能力在 `dsh web` 的 **Settings → Plugins → 备份** 标签页有可视化入口:
|
|
41
|
+
显示备份目录、自动备份状态、GitHub 同步状态和每份归档的大小,支持一键立即
|
|
42
|
+
备份、逐份校验、**下载**、带 dry-run 预览与二次确认的恢复。下载走仅限本机的
|
|
43
|
+
`GET /backup-download/<归档名>` 路由。面板经 `backupPanel` Typert Remote
|
|
44
|
+
命名空间(`/api` RPC)与宿主通信;浏览器 bundle 预构建在 `lib/client.js`,
|
|
45
|
+
安装时无需构建。
|
|
46
|
+
|
|
47
|
+
## 恢复的工作方式
|
|
48
|
+
|
|
49
|
+
恢复安全性是设计出来的:
|
|
50
|
+
|
|
51
|
+
1. 先校验归档 sha256——损坏的归档绝不触碰现有数据。
|
|
52
|
+
2. 列出归档条目,任何超出备份根目录的路径都会拒绝恢复(tar 路径穿越防护)。
|
|
53
|
+
3. 当前 `~/.dsh` 先自动快照,再移动到 `~/.dsh.pre-restore-<时间戳>`——恢复是替换而不是合并。
|
|
54
|
+
4. 解压归档后重启 `dsh`,恢复的会话与配置即生效。
|
|
55
|
+
|
|
56
|
+
`--dry-run` 只显示归档概要,不写入任何内容。
|
|
57
|
+
|
|
58
|
+
## 配置(可选)
|
|
59
|
+
|
|
60
|
+
在生效的 cordis profile 中为插件声明 `config`:
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
- id: dsh-backup
|
|
64
|
+
name: 'dsh-backup'
|
|
65
|
+
config:
|
|
66
|
+
destination: '~/Backups/dsh' # 默认 ~/Desktop/dsh-backups
|
|
67
|
+
keep: 10 # 默认轮换保留份数
|
|
68
|
+
exclude: # 额外的 tar --exclude 模式
|
|
69
|
+
- '*cache*'
|
|
70
|
+
githubRepo: '账号/dsh-backups' # 可选 GitHub 同步(见下文)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
自动备份状态保存在 `<destination>/auto.json`,重启后续跑。
|
|
74
|
+
|
|
75
|
+
## 安全说明
|
|
76
|
+
|
|
77
|
+
备份包含明文凭据(`.credentials.yaml`、`qq-bridge/config.json`)。归档与校验
|
|
78
|
+
文件在 POSIX 上为 `chmod 600`(Windows 依赖用户目录 ACL),但请**不要**把备份
|
|
79
|
+
目录同步到不受信的位置,并像对待 API key 一样对待备份文件。
|
|
80
|
+
|
|
81
|
+
存储说明:插件自有数据(归档、校验和、`auto.json`)直接经 `node:fs` 写入,
|
|
82
|
+
与 DSH 自身的会话持久化同一模式——`ctx.fs` 能力是模型面的沙箱 surface,
|
|
83
|
+
不适用于宿主插件的自有存储。
|
|
84
|
+
|
|
85
|
+
## 安装
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
dsh plugin --profile web add dsh-backup
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
然后重启 `dsh web`(插件发现按进程缓存),输入 `/backup` 或打开
|
|
92
|
+
Settings → Plugins → 备份。
|
|
93
|
+
|
|
94
|
+
## 依赖
|
|
95
|
+
|
|
96
|
+
- macOS、Linux 或 Windows 10+,PATH 中有 `tar`(Windows 自带 System32 的
|
|
97
|
+
bsdtar,Git Bash 的 GNU tar 也可以;校验和优先 `sha256sum`/`shasum`,
|
|
98
|
+
Windows 上回退进程内哈希)
|
|
99
|
+
- DSH `0.1.0-rc.6` 或兼容版本
|
|
100
|
+
|
|
101
|
+
## 开发
|
|
102
|
+
|
|
103
|
+
运行时零依赖——宿主插件就是 `lib/index.js`。浏览器半边源码在 `src/`,
|
|
104
|
+
打包(zod 内联、React/Cordis 保持 external)产物 `lib/client.js` 提交进仓库,
|
|
105
|
+
git 安装无需构建:
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
node scripts/build-client.mjs # 改 src/ 后重新打包客户端
|
|
109
|
+
node scripts/smoke.mjs # 宿主冒烟(真实临时目录 + 模拟 DSH 服务)
|
|
110
|
+
node scripts/smoke-client.mjs # 客户端 bundle:握手/schema/标签页注册/SSR
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 许可证
|
|
114
|
+
|
|
115
|
+
MIT
|
package/cordis.patch.yml
ADDED