@worktool/dsh-config-sync 0.0.0-stage → 1.1.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/LICENSE +21 -0
- package/README.md +92 -2
- package/assets/icon.svg +14 -0
- package/cordis.patch.yml +4 -0
- package/docs/DETAIL.md +27 -0
- package/lib/client.js +377 -0
- package/lib/index.js +1027 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +61 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SupremeIdol
|
|
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
CHANGED
|
@@ -1,3 +1,93 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @worktool/dsh-config-sync
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@worktool/dsh-config-sync)
|
|
4
|
+
[](https://www.npmjs.com/package/@worktool/dsh-config-sync)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://github.com/SupremeIdol/dsh-config-sync)
|
|
7
|
+
|
|
8
|
+
DeepSeek Harness(DSH)配置同步插件:把你的 **全局配置、全局 Skills、已安装插件清单** 导出为一个可版本化的同步包,并支持通过 **Git(SSH)** 同步到自建仓库(如 Gitee),换机或重装后一键还原。
|
|
9
|
+
|
|
10
|
+
## 功能
|
|
11
|
+
|
|
12
|
+
- 导出(自动脱敏):
|
|
13
|
+
- `settings.yaml`:仅清空**密钥类字段**(apiKey / secret / token / password / bearer / privateKey / accessKey 等),并记录到 `redactions.json`;`maxTokens`、`contextWindow` 等普通参数会被保留
|
|
14
|
+
- `AGENTS.md`(全局记忆)
|
|
15
|
+
- **`AGENTS.md` 里引用的本地文件**(如 `~/.dsh/drawio-rules.md`,以及 Markdown 相对链接指向的本地文件)→ 存入 `config/linked/`,导入时按原相对路径还原;`skills/`、`.agent-presets/` 在各自开关开启时按专门逻辑导出,引用解析会自动去重;关闭这些开关时则改由 `config/linked/` 兜底带上
|
|
16
|
+
- `.agent-presets/`
|
|
17
|
+
- `profiles/<profile>/cordis.patch.yml`、`cordis.yml`
|
|
18
|
+
- 全局 `skills/`
|
|
19
|
+
- 已安装插件清单(`name@version`)
|
|
20
|
+
- 导入:
|
|
21
|
+
- 先自动备份当前状态到 `~/.dsh/config-sync/backups/<时间戳>/`
|
|
22
|
+
- 按 `name@version` 自动下载安装插件(优先官方 registry,失败回退镜像)
|
|
23
|
+
- 还原配置与 skills;本地/link 插件会跳过并提示
|
|
24
|
+
- 导入 `settings.yaml` 时,**本机已存在的密钥会被保留**(不会被导出包里的空值覆盖);换到全新机器首次导入后,仍需手动补填密钥
|
|
25
|
+
- 云同步:`git push / pull`(SSH),仓库地址由你自行配置
|
|
26
|
+
- 安全提示:推送前会用**不带任何凭据**的匿名 `git ls-remote` **探测仓库是否可被公开访问**——`http(s)`/`git://` 直接探测,SSH 地址自动转 https(仅标准 22 端口;探测前会剥离地址里的 `user:token@`,避免带凭据误判为公开);判定为公开时弹窗要求勾选确认;Host 侧对公开地址也会强制要求确认(`allowPublic`)后才允许推送。**同一地址首次成功推送后会被记住,之后不再重复探测;地址一改则重新探测**。设置页提供「重新检测」按钮,可忘记该地址的信任并强制立即重测。另有**严格模式**开关:开启后「无法判定是否公开」(如网络受限、非标准 ssh 端口、内网不可达)也会先要求确认,不再默认按私有放行
|
|
27
|
+
- 界面:设置 →「配置同步」;同时提供 Agent 工具:
|
|
28
|
+
`config_sync_status` / `config_sync_export` / `config_sync_import` / `config_sync_push` / `config_sync_pull`
|
|
29
|
+
|
|
30
|
+
## 永不导出
|
|
31
|
+
|
|
32
|
+
`.credentials.yaml`、`.env`、`mcp_connector_grants/`、`storages/`(运行时)、`sessions/`、`cache/`、`attachments/`、`node_modules/`、日志。
|
|
33
|
+
|
|
34
|
+
## 同步包结构
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
manifest.json # schema/时间/DSH 版本/工具版本/counts
|
|
38
|
+
plugins.json # [{name,version,builtin,local}] + local[]
|
|
39
|
+
config/settings.yaml
|
|
40
|
+
config/AGENTS.md
|
|
41
|
+
config/linked/** # AGENTS.md 引用的本地文件(如 drawio-rules.md)
|
|
42
|
+
config/agent-presets/**
|
|
43
|
+
config/profile/{cordis.patch.yml,cordis.yml}
|
|
44
|
+
skills/<name>/**
|
|
45
|
+
redactions.json # 被脱敏字段
|
|
46
|
+
excluded.json # 被排除项
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 安装
|
|
50
|
+
|
|
51
|
+
- 在 DSH 的「插件市场」搜索并安装 `@worktool/dsh-config-sync`(或让插件管理器安装 npm 包 `@worktool/dsh-config-sync`)。
|
|
52
|
+
- 也可从本仓库源码本地安装:把插件管理器指向本目录即可(`dsh.bundle.patch` 会生效)。
|
|
53
|
+
|
|
54
|
+
安装后到「设置 → 配置同步」填写 Git(SSH)仓库地址即可。
|
|
55
|
+
|
|
56
|
+
### 通过自定义插件市场索引安装
|
|
57
|
+
|
|
58
|
+
本仓库根目录提供 `market-index.json`。在 DSH「插件市场 / Discover」里添加索引地址:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
https://raw.githubusercontent.com/SupremeIdol/dsh-config-sync/main/market-index.json
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
即可在市场里直接看到并安装 `@worktool/dsh-config-sync`(索引同时收录了 `@worktool/dsh-diagram`)。
|
|
65
|
+
|
|
66
|
+
## 常见问题
|
|
67
|
+
|
|
68
|
+
### 安装时报 `ERR_PNPM_NO_MATCHING_VERSION ... npmmirror.com`
|
|
69
|
+
|
|
70
|
+
原因:国内环境默认使用 `registry.npmmirror.com` 镜像,新发布的版本通常要过几分钟到几小时才同步,这段时间 pnpm 会找不到对应版本。
|
|
71
|
+
|
|
72
|
+
解决(任选其一):
|
|
73
|
+
|
|
74
|
+
- 等镜像同步后重试;
|
|
75
|
+
- 安装时显式指定官方源(插件管理器里把 registry 设为 `https://registry.npmjs.org/`):
|
|
76
|
+
```
|
|
77
|
+
plugin_manager install_bundle
|
|
78
|
+
target = @worktool/dsh-config-sync@1.0.0
|
|
79
|
+
registry = https://registry.npmjs.org/
|
|
80
|
+
```
|
|
81
|
+
- 一次性配置(推荐):在 DSH profile 目录的 `.npmrc` 里加一行
|
|
82
|
+
```
|
|
83
|
+
@worktool:registry=https://registry.npmjs.org/
|
|
84
|
+
```
|
|
85
|
+
之后 `@worktool/*` 都走官方源,其它包仍走镜像,不影响速度。
|
|
86
|
+
|
|
87
|
+
## English
|
|
88
|
+
|
|
89
|
+
Export/import DSH global config, skills, and installed plugins (name@version); Git(SSH) cloud sync to your own repo. Secrets are never exported; settings containing secret keys are redacted. Configure the repo under Settings → Config Sync.
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
package/assets/icon.svg
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="cs" x1="0" y1="0" x2="1" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#4a86e8"/>
|
|
5
|
+
<stop offset="1" stop-color="#3aa66f"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect x="10" y="10" width="44" height="44" rx="12" fill="#e8f0fe"/>
|
|
9
|
+
<rect x="10" y="10" width="44" height="44" rx="12" fill="none" stroke="url(#cs)" stroke-width="2"/>
|
|
10
|
+
<path d="M20 27h18a5 5 0 0 1 5 5v2" fill="none" stroke="url(#cs)" stroke-width="3" stroke-linecap="round"/>
|
|
11
|
+
<path d="M40 30l3 4 3-4" fill="none" stroke="#3aa66f" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
|
|
12
|
+
<path d="M44 40H26a5 5 0 0 1-5-5v-2" fill="none" stroke="url(#cs)" stroke-width="3" stroke-linecap="round"/>
|
|
13
|
+
<path d="M24 37l-3-4-3 4" fill="none" stroke="#4a86e8" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
|
|
14
|
+
</svg>
|
package/cordis.patch.yml
ADDED
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# 配置同步 · 详情
|
|
2
|
+
|
|
3
|
+
## 数据流
|
|
4
|
+
|
|
5
|
+
1. 用户在「设置 → 配置同步」勾选要同步的内容。
|
|
6
|
+
2. Host 半扫描 `~/.dsh` 下白名单路径,`settings.yaml` 经过密钥脱敏,打包到 `~/.dsh/config-sync/repo`;同时解析 `AGENTS.md` 中形如 `~/.dsh/xxx` 的引用与 Markdown 本地相对链接,把被引用的文件(如 `drawio-rules.md`)一并打包到 `config/linked/`,导入时按原相对路径还原。
|
|
7
|
+
3. 点击「推送到仓库」:在该工作副本执行 `git add/commit/push`(SSH)。
|
|
8
|
+
4. 新机器点击「拉取并导入」:`git fetch/reset` → 备份当前 → 按 `plugins.json` 调 `pluginManager.installBundle(name@version)` 自动装插件 → 还原配置与 skills。
|
|
9
|
+
|
|
10
|
+
## Host 半能力(调用的 DSH 服务)
|
|
11
|
+
|
|
12
|
+
- `connection.fetch.register`:注册 `/api/worktool/dsh-config-sync/*` 路由
|
|
13
|
+
- `pluginManager.installBundle / updateBundle`:导入时安装/升级插件
|
|
14
|
+
- `tools.register`:注册 5 个 Agent 工具
|
|
15
|
+
|
|
16
|
+
## 安全
|
|
17
|
+
|
|
18
|
+
- 只读/白名单扫描,`.credentials.yaml`、`.env` 等永不读取。
|
|
19
|
+
- `settings.yaml` 只对**密钥类键名**(apikey/secret/token/password/bearer/privateKey/accessKey 等)的值清空(`apiKeyEnv` 等环境变量名保留,`maxTokens`/`contextWindow` 等普通参数保留);导入时若本机已有该密钥则保留本机值,避免被脱敏空值覆盖。
|
|
20
|
+
- Git 凭据走系统 SSH/凭据助手,不写入同步包。
|
|
21
|
+
- 推送前用**不带任何凭据**的匿名 `git ls-remote` 探测目标仓库是否可被公开访问:`http(s)`/`git://` 直接探测;SSH 地址自动转其 https 等价地址(仅标准 22 端口);探测前剥离地址中的 `user:token@`,避免带凭据把私有误判公开。判定为公开时,UI 弹窗要求勾选确认,Host 侧对公开地址也强制要求 `allowPublic:true` 才允许推送。同一地址首次成功推送后会记入 `state.json` 的 `trustedRepos`,之后推送不再探测;地址变更则重新探测。**严格模式**开启后,`checked=false`(网络受限/非标准 ssh 端口/无法判定)也会被视为需确认,避免"未知被当成私有"直接外泄。
|
|
22
|
+
|
|
23
|
+
## 注意
|
|
24
|
+
|
|
25
|
+
- 导入配置与插件后通常需要 **重启 DSH** 才能全部生效。
|
|
26
|
+
- 本地 `link:`/`file:` 插件无法在别的机器自动安装,会在结果里列出并跳过。
|
|
27
|
+
- 首次 `git push` 到 **空仓库** 会自动建立分支;请确保该 SSH key 已加入对应仓库(如 Gitee 的部署公钥/账户公钥)。
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@worktool/dsh-config-sync",
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const h = React.createElement;
|
|
6
|
+
const API = "/api/worktool/dsh-config-sync";
|
|
7
|
+
const HDRS = { "content-type": "application/json", "x-dsh-config-sync": "1" };
|
|
8
|
+
|
|
9
|
+
async function api(pathname, body) {
|
|
10
|
+
const res = await fetch(API + pathname, {
|
|
11
|
+
method: body ? "POST" : "GET",
|
|
12
|
+
headers: HDRS,
|
|
13
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
14
|
+
});
|
|
15
|
+
let json;
|
|
16
|
+
try {
|
|
17
|
+
json = await res.json();
|
|
18
|
+
} catch {
|
|
19
|
+
throw new Error("HTTP " + res.status);
|
|
20
|
+
}
|
|
21
|
+
if (!json.ok) throw new Error(json.error || "HTTP " + res.status);
|
|
22
|
+
return json.data;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const styles = {
|
|
26
|
+
wrap: {
|
|
27
|
+
display: "flex",
|
|
28
|
+
flexDirection: "column",
|
|
29
|
+
gap: "14px",
|
|
30
|
+
padding: "4px 2px 40px",
|
|
31
|
+
color: "var(--dsw-alias-label-primary, #eee)",
|
|
32
|
+
fontFamily: "inherit",
|
|
33
|
+
maxWidth: "820px",
|
|
34
|
+
},
|
|
35
|
+
card: {
|
|
36
|
+
border: "0.5px solid var(--dsw-alias-border-l2, #494949)",
|
|
37
|
+
borderRadius: "16px",
|
|
38
|
+
background: "var(--dsw-alias-bg-layer-1, transparent)",
|
|
39
|
+
padding: "16px 18px",
|
|
40
|
+
display: "flex",
|
|
41
|
+
flexDirection: "column",
|
|
42
|
+
gap: "12px",
|
|
43
|
+
},
|
|
44
|
+
title: { margin: 0, fontSize: "22px", lineHeight: "30px", fontWeight: 600 },
|
|
45
|
+
desc: { margin: 0, color: "var(--dsw-alias-label-tertiary, #a0a0a0)", fontSize: "13px", lineHeight: "20px" },
|
|
46
|
+
row: { display: "flex", alignItems: "center", gap: "10px", flexWrap: "wrap" },
|
|
47
|
+
label: { fontSize: "12px", color: "var(--dsw-alias-label-secondary, #b9b9b9)", minWidth: "84px" },
|
|
48
|
+
input: {
|
|
49
|
+
flex: "1 1 320px",
|
|
50
|
+
height: "34px",
|
|
51
|
+
padding: "0 12px",
|
|
52
|
+
borderRadius: "10px",
|
|
53
|
+
border: "0.5px solid var(--dsw-alias-border-l3, #555)",
|
|
54
|
+
background: "var(--dsw-alias-bg-layer-2, transparent)",
|
|
55
|
+
color: "var(--dsw-alias-label-primary, #eee)",
|
|
56
|
+
fontSize: "13px",
|
|
57
|
+
boxSizing: "border-box",
|
|
58
|
+
},
|
|
59
|
+
btn: {
|
|
60
|
+
height: "32px",
|
|
61
|
+
padding: "0 14px",
|
|
62
|
+
borderRadius: "9px",
|
|
63
|
+
border: "0.5px solid var(--dsw-alias-border-l3, #555)",
|
|
64
|
+
background: "var(--dsw-alias-bg-layer-2, transparent)",
|
|
65
|
+
color: "var(--dsw-alias-label-primary, #eee)",
|
|
66
|
+
fontSize: "13px",
|
|
67
|
+
cursor: "pointer",
|
|
68
|
+
},
|
|
69
|
+
btnPrimary: {
|
|
70
|
+
height: "32px",
|
|
71
|
+
padding: "0 16px",
|
|
72
|
+
borderRadius: "9px",
|
|
73
|
+
border: "0.5px solid var(--dsw-alias-brand-primary, #4a86e8)",
|
|
74
|
+
background: "var(--dsw-alias-brand-primary, #4a86e8)",
|
|
75
|
+
color: "#fff",
|
|
76
|
+
fontSize: "13px",
|
|
77
|
+
fontWeight: 600,
|
|
78
|
+
cursor: "pointer",
|
|
79
|
+
},
|
|
80
|
+
chk: { display: "inline-flex", alignItems: "center", gap: "6px", fontSize: "13px", color: "var(--dsw-alias-label-secondary, #b9b9b9)" },
|
|
81
|
+
log: {
|
|
82
|
+
margin: 0,
|
|
83
|
+
padding: "10px 12px",
|
|
84
|
+
borderRadius: "10px",
|
|
85
|
+
background: "var(--dsw-alias-bg-layer-2, rgba(128,128,128,.08))",
|
|
86
|
+
color: "var(--dsw-alias-label-secondary, #b9b9b9)",
|
|
87
|
+
fontSize: "12px",
|
|
88
|
+
lineHeight: "18px",
|
|
89
|
+
whiteSpace: "pre-wrap",
|
|
90
|
+
wordBreak: "break-word",
|
|
91
|
+
maxHeight: "240px",
|
|
92
|
+
overflow: "auto",
|
|
93
|
+
fontFamily: "ui-monospace, SFMono-Regular, Consolas, monospace",
|
|
94
|
+
},
|
|
95
|
+
hint: { fontSize: "11px", color: "var(--dsw-alias-label-tertiary, #a0a0a0)", lineHeight: "17px" },
|
|
96
|
+
warnHint: { fontSize: "12px", color: "var(--dsw-alias-label-warning, #e0a30c)", lineHeight: "18px", flexBasis: "100%" },
|
|
97
|
+
overlay: {
|
|
98
|
+
position: "fixed", inset: 0, zIndex: 9999,
|
|
99
|
+
background: "rgba(0,0,0,.55)", display: "flex",
|
|
100
|
+
alignItems: "center", justifyContent: "center", padding: "20px",
|
|
101
|
+
},
|
|
102
|
+
modal: {
|
|
103
|
+
width: "min(520px, 100%)",
|
|
104
|
+
border: "0.5px solid var(--dsw-alias-border-l2, #494949)",
|
|
105
|
+
borderRadius: "16px",
|
|
106
|
+
background: "var(--dsw-alias-bg-layer-1, #1f1f1f)",
|
|
107
|
+
color: "var(--dsw-alias-label-primary, #eee)",
|
|
108
|
+
padding: "20px 22px",
|
|
109
|
+
display: "flex", flexDirection: "column", gap: "14px",
|
|
110
|
+
boxShadow: "0 18px 50px rgba(0,0,0,.45)",
|
|
111
|
+
},
|
|
112
|
+
modalTitle: { margin: 0, fontSize: "16px", fontWeight: 600, color: "var(--dsw-alias-label-warning, #e0a30c)" },
|
|
113
|
+
modalText: { margin: 0, fontSize: "13px", lineHeight: "21px", color: "var(--dsw-alias-label-secondary, #c9c9c9)" },
|
|
114
|
+
btnWarn: {
|
|
115
|
+
height: "34px", padding: "0 16px", borderRadius: "9px",
|
|
116
|
+
border: "0.5px solid #e0a30c", background: "rgba(224,163,12,.16)",
|
|
117
|
+
color: "#e0a30c", fontSize: "13px", fontWeight: 600, cursor: "pointer",
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
function ConfigSyncSection() {
|
|
122
|
+
const [st, setSt] = React.useState(null);
|
|
123
|
+
const [repoUrl, setRepoUrl] = React.useState("");
|
|
124
|
+
const [branch, setBranch] = React.useState("main");
|
|
125
|
+
const [inc, setInc] = React.useState({ settings: true, agents: true, presets: true, skills: true, plugins: true, optional: false });
|
|
126
|
+
const [busy, setBusy] = React.useState("");
|
|
127
|
+
const [log, setLog] = React.useState("");
|
|
128
|
+
const [pubConfirm, setPubConfirm] = React.useState(null); // {kind:'push', url, via}
|
|
129
|
+
const [probe, setProbe] = React.useState(null); // {public, checked, reason, via}
|
|
130
|
+
const [ack, setAck] = React.useState(false); // 弹窗内「我已了解风险」勾选
|
|
131
|
+
const [strict, setStrict] = React.useState(false); // 严格模式:无法判定公开性时也要求确认
|
|
132
|
+
|
|
133
|
+
const push = (line) => setLog((prev) => (prev ? prev + "\n" : "") + line);
|
|
134
|
+
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
api("/state")
|
|
137
|
+
.then((s) => {
|
|
138
|
+
setSt(s);
|
|
139
|
+
setRepoUrl(s.repoUrl || "");
|
|
140
|
+
setBranch(s.branch || "main");
|
|
141
|
+
if (s.include) setInc({ ...inc, ...s.include });
|
|
142
|
+
setStrict(!!s.strictPublic);
|
|
143
|
+
})
|
|
144
|
+
.catch((e) => push("加载状态失败: " + e.message));
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
// 地址变化时,节流探测仓库是否可匿名公开访问
|
|
148
|
+
React.useEffect(() => {
|
|
149
|
+
if (!String(repoUrl || "").trim()) {
|
|
150
|
+
setProbe(null);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
let alive = true;
|
|
154
|
+
const t = setTimeout(() => {
|
|
155
|
+
api("/probe", { repoUrl })
|
|
156
|
+
.then((r) => { if (alive) setProbe(r); })
|
|
157
|
+
.catch(() => {});
|
|
158
|
+
}, 500);
|
|
159
|
+
return () => { alive = false; clearTimeout(t); };
|
|
160
|
+
}, [repoUrl]);
|
|
161
|
+
|
|
162
|
+
async function run(label, fn) {
|
|
163
|
+
setBusy(label);
|
|
164
|
+
push("▶ " + label + " …");
|
|
165
|
+
try {
|
|
166
|
+
const data = await fn();
|
|
167
|
+
push("✓ " + label + " 完成: " + JSON.stringify(data.counts || data, null, 0).slice(0, 800));
|
|
168
|
+
const s = await api("/state").catch(() => null);
|
|
169
|
+
if (s) setSt(s);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
push("✗ " + label + " 失败: " + e.message);
|
|
172
|
+
} finally {
|
|
173
|
+
setBusy("");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const toggle = (k) => (ev) => setInc({ ...inc, [k]: ev.target.checked });
|
|
178
|
+
|
|
179
|
+
const chk = (k, labelText) =>
|
|
180
|
+
h("label", { style: styles.chk }, h("input", { type: "checkbox", checked: !!inc[k], onChange: toggle(k) }), labelText);
|
|
181
|
+
|
|
182
|
+
const doPush = (allowPublic) => run("推送到仓库", () => api("/push", { repoUrl, branch, include: inc, allowPublic: !!allowPublic }));
|
|
183
|
+
async function requestPush() {
|
|
184
|
+
setBusy("检测仓库可见性");
|
|
185
|
+
let r = probe;
|
|
186
|
+
try {
|
|
187
|
+
r = await api("/probe", { repoUrl });
|
|
188
|
+
setProbe(r);
|
|
189
|
+
} catch { /* 探测失败则沿用上次结果 */ }
|
|
190
|
+
setBusy("");
|
|
191
|
+
const need = r && (typeof r.confirmNeeded === "boolean" ? r.confirmNeeded : !!r.public);
|
|
192
|
+
if (need) {
|
|
193
|
+
setAck(false);
|
|
194
|
+
setPubConfirm({ kind: "push", url: repoUrl, via: r && r.via, public: !!(r && r.public), unknown: !r || (!r.public && r.checked === false), reason: r && r.reason });
|
|
195
|
+
} else {
|
|
196
|
+
doPush(false);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 忘记该地址的信任并强制重新探测
|
|
201
|
+
async function reprobe() {
|
|
202
|
+
if (!String(repoUrl || "").trim()) {
|
|
203
|
+
push("请先填写仓库地址");
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
setBusy("重新检测仓库");
|
|
207
|
+
try {
|
|
208
|
+
const r = await api("/probe", { repoUrl, force: true });
|
|
209
|
+
setProbe(r);
|
|
210
|
+
push("重新检测:" + (r.trusted ? "已信任" : r.public ? "公开(需确认)" : r.checked ? "私有/不可匿名访问" : (r.strict ? "无法判定(严格模式:推送前会确认)" : "无法检测")));
|
|
211
|
+
} catch (e) {
|
|
212
|
+
push("重新检测失败: " + e.message);
|
|
213
|
+
} finally {
|
|
214
|
+
setBusy("");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return h(
|
|
219
|
+
"section",
|
|
220
|
+
{ style: styles.wrap },
|
|
221
|
+
h(
|
|
222
|
+
"div",
|
|
223
|
+
{ style: styles.card },
|
|
224
|
+
h("h2", { style: styles.title }, "配置同步"),
|
|
225
|
+
h(
|
|
226
|
+
"p",
|
|
227
|
+
{ style: styles.desc },
|
|
228
|
+
"把 DSH 的全局配置(settings、AGENTS.md、agent-presets)、全局 Skills、已安装插件(name@version)导出为一个可同步的仓库;导入时自动下载安装插件。密钥与运行时会话数据永不导出。"
|
|
229
|
+
),
|
|
230
|
+
h(
|
|
231
|
+
"div",
|
|
232
|
+
{ style: styles.row },
|
|
233
|
+
h("span", { style: styles.label }, "仓库地址"),
|
|
234
|
+
h("input", {
|
|
235
|
+
style: styles.input,
|
|
236
|
+
placeholder: "git@gitee.com:you/dsh-config.git(SSH)",
|
|
237
|
+
value: repoUrl,
|
|
238
|
+
onChange: (e) => setRepoUrl(e.target.value),
|
|
239
|
+
}),
|
|
240
|
+
h("button", { style: { ...styles.btn, height: "32px" }, disabled: !!busy, onClick: reprobe }, "重新检测"),
|
|
241
|
+
probe
|
|
242
|
+
? probe.trusted
|
|
243
|
+
? h("span", { style: { ...styles.warnHint, color: "var(--dsw-alias-label-tertiary, #a0a0a0)" } }, "✓ 已信任该地址(上次推送成功,后续不再探测)")
|
|
244
|
+
: probe.public
|
|
245
|
+
? h("span", { style: styles.warnHint }, "⚠ 已检测:该仓库可被匿名公开访问(公开)。推送前必须二次确认。")
|
|
246
|
+
: probe.checked
|
|
247
|
+
? h("span", { style: { ...styles.warnHint, color: "var(--dsw-alias-label-tertiary, #a0a0a0)" } }, "✓ 已检测:需凭据访问(私有 / 不可匿名访问)。")
|
|
248
|
+
: h(
|
|
249
|
+
"span",
|
|
250
|
+
{ style: strict ? styles.warnHint : { ...styles.warnHint, color: "var(--dsw-alias-label-tertiary, #a0a0a0)" } },
|
|
251
|
+
strict ? "⚠ 无法匿名判定是否公开(严格模式:推送前会要求确认)。" : "该地址无法匿名检测公开性,按私有处理(如需更稳妥可开严格模式)。"
|
|
252
|
+
)
|
|
253
|
+
: null
|
|
254
|
+
),
|
|
255
|
+
h(
|
|
256
|
+
"div",
|
|
257
|
+
{ style: styles.row },
|
|
258
|
+
h("span", { style: styles.label }, "分支"),
|
|
259
|
+
h("input", { style: { ...styles.input, flex: "0 1 160px" }, value: branch, onChange: (e) => setBranch(e.target.value) })
|
|
260
|
+
),
|
|
261
|
+
h(
|
|
262
|
+
"label",
|
|
263
|
+
{ style: styles.chk },
|
|
264
|
+
h("input", {
|
|
265
|
+
type: "checkbox",
|
|
266
|
+
checked: !!strict,
|
|
267
|
+
onChange: async (e) => {
|
|
268
|
+
const v = e.target.checked;
|
|
269
|
+
setStrict(v);
|
|
270
|
+
try {
|
|
271
|
+
await api("/settings", { strictPublic: v });
|
|
272
|
+
push("严格模式:" + (v ? "已开启" : "已关闭"));
|
|
273
|
+
} catch (err) {
|
|
274
|
+
push("保存严格模式失败: " + err.message);
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
}),
|
|
278
|
+
"严格模式:无法判定公开性时也要求确认(连“网络受限/未知”也先确认,不默认当私有放行)"
|
|
279
|
+
),
|
|
280
|
+
h(
|
|
281
|
+
"div",
|
|
282
|
+
{ style: styles.row },
|
|
283
|
+
chk("settings", "settings.yaml"),
|
|
284
|
+
chk("agents", "AGENTS.md(含引用文件)"),
|
|
285
|
+
chk("presets", "agent-presets"),
|
|
286
|
+
chk("skills", "Skills"),
|
|
287
|
+
chk("plugins", "插件"),
|
|
288
|
+
chk("optional", "主题/环境(可选)")
|
|
289
|
+
),
|
|
290
|
+
h(
|
|
291
|
+
"div",
|
|
292
|
+
{ style: styles.row },
|
|
293
|
+
h("button", { style: styles.btn, disabled: !!busy, onClick: () => run("导出到本地同步仓", () => api("/export", { include: inc })) }, "导出"),
|
|
294
|
+
h("button", { style: styles.btn, disabled: !!busy, onClick: () => run("从本地同步仓导入", () => api("/import", { include: inc })) }, "本地导入"),
|
|
295
|
+
h(
|
|
296
|
+
"button",
|
|
297
|
+
{ style: styles.btnPrimary, disabled: !!busy, onClick: requestPush },
|
|
298
|
+
"推送到仓库"
|
|
299
|
+
),
|
|
300
|
+
h(
|
|
301
|
+
"button",
|
|
302
|
+
{ style: styles.btn, disabled: !!busy, onClick: () => run("从仓库拉取并导入", () => api("/pull", { repoUrl, branch })) },
|
|
303
|
+
"拉取并导入"
|
|
304
|
+
)
|
|
305
|
+
),
|
|
306
|
+
h(
|
|
307
|
+
"p",
|
|
308
|
+
{ style: styles.hint },
|
|
309
|
+
st
|
|
310
|
+
? `同步仓:${st.repoDir} | 插件 ${st.pluginCount} | skills 文件 ${st.skillsCount} | 上次同步:${st.lastSync || "无"} | 上次备份:${st.lastBackup || "无"}`
|
|
311
|
+
: "加载中…"
|
|
312
|
+
),
|
|
313
|
+
h(
|
|
314
|
+
"p",
|
|
315
|
+
{ style: styles.hint },
|
|
316
|
+
"永不导出:.credentials.yaml、.env、mcp_connector_grants/、storages/、sessions/、cache/、node_modules/ 等。settings 中含密钥的字段会被自动脱敏。"
|
|
317
|
+
)
|
|
318
|
+
),
|
|
319
|
+
pubConfirm
|
|
320
|
+
? h(
|
|
321
|
+
"div",
|
|
322
|
+
{ style: styles.overlay, onClick: (e) => { if (e.target === e.currentTarget) setPubConfirm(null); } },
|
|
323
|
+
h(
|
|
324
|
+
"div",
|
|
325
|
+
{ style: styles.modal },
|
|
326
|
+
h("h3", { style: styles.modalTitle }, pubConfirm.public ? "⚠️ 公开地址确认" : "⚠️ 无法确认仓库是否为公开"),
|
|
327
|
+
h("p", { style: styles.modalText }, pubConfirm.public ? "你填写的备份地址可被匿名公开读取(公开仓库):" : "无法匿名判定该地址是否公开(严格模式)。可能是网络受限、私有或不可达:"),
|
|
328
|
+
h("p", { style: { ...styles.modalText, fontFamily: "ui-monospace, monospace", wordBreak: "break-all" } }, String(pubConfirm.url || "")),
|
|
329
|
+
h("p", { style: styles.modalText }, "推送会把 AGENTS.md、skills、插件清单等配置提交到该仓库;若该仓库是公开的,任何能访问它的人都可能看到这些内容(密钥已在导出时脱敏,但仍可能包含隐私信息)。"),
|
|
330
|
+
h(
|
|
331
|
+
"label",
|
|
332
|
+
{ style: styles.chk },
|
|
333
|
+
h("input", { type: "checkbox", checked: ack, onChange: (e) => setAck(e.target.checked) }),
|
|
334
|
+
pubConfirm.public ? "我已了解风险,确认这是公开仓库" : "我已了解风险,确认仍要推送到该地址"
|
|
335
|
+
),
|
|
336
|
+
h(
|
|
337
|
+
"div",
|
|
338
|
+
{ style: styles.row },
|
|
339
|
+
h("button", { style: styles.btn, onClick: () => setPubConfirm(null) }, "取消"),
|
|
340
|
+
h(
|
|
341
|
+
"button",
|
|
342
|
+
{ style: { ...styles.btnWarn, opacity: ack ? 1 : 0.5, cursor: ack ? "pointer" : "not-allowed" }, disabled: !ack, onClick: () => { if (!ack) return; setPubConfirm(null); doPush(true); } },
|
|
343
|
+
pubConfirm.public ? "确认是公开地址,仍要推送" : "确认仍要推送"
|
|
344
|
+
)
|
|
345
|
+
)
|
|
346
|
+
)
|
|
347
|
+
)
|
|
348
|
+
: null,
|
|
349
|
+
log ? h("pre", { style: styles.log }, log) : null,
|
|
350
|
+
busy ? h("p", { style: styles.hint }, "处理中:" + busy + " …(安装插件可能较慢)") : null
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
inject: ["slots"],
|
|
356
|
+
apply(ctx) {
|
|
357
|
+
ctx.slots.inject("settings.section", () => {
|
|
358
|
+
try {
|
|
359
|
+
return ctx.slots.register(
|
|
360
|
+
{
|
|
361
|
+
name: "settings.section",
|
|
362
|
+
id: "dsh-config-sync",
|
|
363
|
+
order: 60,
|
|
364
|
+
label: () => "配置同步",
|
|
365
|
+
icon: "settings",
|
|
366
|
+
},
|
|
367
|
+
ConfigSyncSection
|
|
368
|
+
);
|
|
369
|
+
} catch (e) {
|
|
370
|
+
console.warn("config-sync: register settings.section failed:", e);
|
|
371
|
+
return () => {};
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
},
|
|
377
|
+
});
|