dsh-plugin-syncer 0.0.0-stage → 0.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.md CHANGED
@@ -1,3 +1,122 @@
1
- # Temporary Holding Version
1
+ # dsh-sync
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
+ 在多台电脑之间双向同步 DeepSeek Harness 的插件启停与插件配置。用 Gitee 私有仓库当同步盘,不需要自己买服务器。
4
+
5
+ ## 它是怎么工作的
6
+
7
+ ```
8
+ Gitee 私有仓库
9
+ └── dsh-sync/
10
+ └── devices/
11
+ ├── work-pc-xxxx.json ← 公司电脑只写这个文件,只读对方的
12
+ └── home-pc-yyyy.json ← 家里电脑只写这个文件,只读对方的
13
+ ```
14
+
15
+ - 每台机器每 15 秒(可配 5–3600 秒)拉取远端目录,只下载 sha 变化的文件。
16
+ - 每个插件条目单独合并:`rev` 大者胜,`rev` 相同比 `at`,再比 `origin`,结果确定。
17
+ - 本机只写自己的 `devices/<设备ID>.json`,因此不存在文件级互相覆盖;两台同时改同一插件才会进冲突目录。
18
+ - 合并结果通过 DSH 自己的接口落盘,不手写 YAML:
19
+ - 配置 → `configEditor.edit`(保留注释、schema 校验、失败回滚)
20
+ - 启停 → `pluginManager.setPluginEnabled`
21
+ - 对方有、本机没有的插件 → `pluginManager.installBundle`
22
+ - 推送前先拉取再合并,避免用旧快照覆盖对方刚写入的值。
23
+ - 每个条目还带 `version` 与 `source`(来自 profile `package.json` 的依赖声明):
24
+ - 本机缺这个包 → 按 `name@version` 安装(`saveExact`,版本锁定)。
25
+ - 对方版本更新、且来源是 npm registry → 先 `pluginManager.updateBundle` 升到同一版本,插件重载后再写配置。
26
+ - 版本对不上又不能自动升级(降级、`file:` 本地链接、git 源)→ 不写配置,记进 `deferred`,本地照旧,等版本对齐后自动重试。
27
+
28
+ ## 安装
29
+
30
+ 前置:DSH Desktop;一个 Gitee 私有仓库;一个 Gitee 私人令牌(勾选 `projects`)。
31
+
32
+ 第一台:
33
+
34
+ 1. 在 Gitee 新建**私有**仓库(勾选“使用 Readme 文件初始化”,分支用 `main`)。
35
+ 2. 生成私人令牌:设置 → 私人令牌 → 勾选 `projects`。
36
+ 3. 把令牌存进 `%USERPROFILE%\.dsh\dsh-sync\token`(一行纯文本,UTF-8,无 BOM)。
37
+ 4. 把 `dsh-sync-0.2.1.zip` 解压到任意目录,用 `plugin_manager install_bundle` 安装解压后的 `dsh-sync` 目录(绝对路径)。
38
+ 5. 在 `C:\Users\<你>\.dsh\profiles\desktop\cordis.patch.yml` 末尾加覆盖行(把 owner/repo 换成你的):
39
+
40
+ ```yaml
41
+ - id: dsh-sync
42
+ name: dsh-sync
43
+ config:
44
+ provider: gitee
45
+ owner: 你的Gitee用户名
46
+ repo: 你的私有仓库名
47
+ branch: main
48
+ path: dsh-sync
49
+ intervalSeconds: 15
50
+ installMissing: true
51
+ updatePlugins: true
52
+ ```
53
+
54
+ 保存后 DSH 会热重载插件,几秒内把本机快照推上去。
55
+
56
+ 第二台:
57
+
58
+ 1. 把 `dsh-sync-0.2.1.zip` 拷到那台机器,解压(例如 `C:\Tools\dsh-sync`)。
59
+ 2. 用 `plugin_manager install_bundle` 安装这个目录(`target` 填绝对路径);如果那台装过 0.1.x,覆盖安装后重启一次 DSH,确保加载的是 0.2.1 代码。
60
+ 3. 复制同一段 patch 配置(带上 `updatePlugins: true`)。设备 ID 会自动生成,不会和第一台撞。
61
+ 4. 看 `~/.dsh/dsh-sync/status-*.json`:`configured: true`、`entries` 与第一台差不多、`lastError` 为空即接通;两边各自只写自己的 `devices/<id>.json`。
62
+
63
+ ## 配置项
64
+
65
+ | 键 | 默认 | 说明 |
66
+ | --- | --- | --- |
67
+ | `provider` | `gitee` | `gitee` / `github` / `file`(`file` 是共享目录,便于测试) |
68
+ | `owner` / `repo` / `branch` | 空 / 空 / `main` | 仓库位置 |
69
+ | `path` | `dsh-sync` | 仓库内的子目录 |
70
+ | `dir` | 空 | 仅 `file`:共享目录绝对路径(如网盘同步盘) |
71
+ | `token` | 空 | 不建议直接写;优先级见下 |
72
+ | `tokenFile` | `~/.dsh/dsh-sync/token` | 令牌文件路径 |
73
+ | `deviceId` | 自动 | 留空即可;强迫症可手动指定 |
74
+ | `intervalSeconds` | `15` | 轮询间隔,最小 5 |
75
+ | `installMissing` | `true` | 对方有、本机没有的包是否自动安装 |
76
+ | `updatePlugins` | `true` | 对方版本更新时是否自动升级(仅 npm registry 源;不会降级) |
77
+ | `excludeEntries` | `[]` | 不同步的插件 id 列表 |
78
+
79
+ 令牌查找顺序:配置里的 `token` → `tokenFile` → 环境变量 `DSH_SYNC_TOKEN`。令牌不会写进 patch。
80
+
81
+ ## 同步范围
82
+
83
+ - 同步第三方插件的启停、配置与**版本**。
84
+ - 版本同步规则:远端版本较新且来源是 npm registry → 自动升级;本机缺包 → 按记录的版本安装;降级、`file:` 本地链接、git 源不自动更新,只保留本地设置并把条目放进 `deferred`,等两台版本一致后自动补配置。
85
+ - 插件代码本身不随配置走:写在本地磁盘或 `file:` 链接上的魔改版,dsh-sync 不会用远端覆盖它,也不会把本机改动传给对方。
86
+ - 手工改过 registry 包内容、但依赖仍写死版本号的(比如当前这台机器的 `dsh-pet`),dsh-sync 只能看到版本号,检测不到代码差异。若不想被升级覆盖就加进 `excludeEntries`;当前选择**不排除**,因此对端上报更高版本后,本机会升级并覆盖本地改动。
87
+ - DSH 核心包(`@deepseek-ai/*`)默认**不**同步,只有当你自己的 patch 里显式写过该 id(比如 `agent-default-model`、`ui-chat`)时才同步,避免一台机器停用核心组件把另一台搞坏。
88
+ - 停用的插件无法写配置(DSH 不暴露它的配置入口),会保留 `enabled=false`,等对方启用后再补配置。
89
+ - 冲突(两台同时改同一个插件)写入 `~/.dsh/dsh-sync/conflicts/<hash>.json`,两边都保留,需人工合并。
90
+
91
+ ## 状态与排错
92
+
93
+ - 状态:`C:\Users\<你>\.dsh\dsh-sync\status-<profileKey>.json`,含 `configured`、`entries`、`pending`、`deferred`、`lastPullAt`、`lastPushAt`、`lastError`。
94
+ - `deferred`:对方版本较高、但本机不能自动升级(降级 / 本地链接 / git 源)时保留,表示“这份配置暂时不应用”,版本对齐后自动清除并重试。
95
+ - 日志:同目录 `sync-<profileKey>.log`(ndjson,1MB 轮转)。
96
+ - 本地状态:`state-<profileKey>.json`,记录设备 ID、各条目版本、已知远端 sha。
97
+ - 首次配置后看 status:`configured: false` 并带 `configErrors` 说明缺什么;修正后自动恢复轮询。
98
+
99
+ 常见问题:
100
+
101
+ - `401`:令牌无效或没勾 `projects`。
102
+ - `404`:仓库名/用户名写错,或仓库不是私有但分支不对。
103
+ - `409` / `conflict`:远端文件被别的进程写过,下一轮会用新 sha 重试。
104
+ - 插件不生效:确认 `pluginManager.listPlugins()` 里该条目的 `fiberPhase` 是 `active`;停用的条目无法写配置。
105
+
106
+ ## 已验证
107
+
108
+ - v0.2.1 单测:远端版本较新且为 npm 源 → 先 `updateBundle` 再等重载、不影响本地配置;本地链接/降级 → `skipped`;本机缺包 → 按 `name@version` 精确安装;版本回填补写时归属到本机(不再冒用对端 origin)。
109
+ - Windows 真机(`desktop` Profile):安装、HMR 重载、远端改配置写入 patch、远端停用/启用插件、未配置时只报一次错并停止轮询。
110
+ - 真机模拟版本冲突:对端把 `dsh-whale-widget` 写成更旧的 `0.0.1` → 本机 `deferred` 冻结并写日志,不改插件;对端改回 `0.4.2` → 自动解除。
111
+ - file provider 双引擎模拟两台机器:A 首推、B 拉取;A 改配置 B 收到;B 停用 A 收到;A 启用 B 收到;冲突文件生成。
112
+ - Gitee 传输层走真实 HTTP 的端到端测试(本地 mock 的 v5 contents API):两台引擎经 HTTP 互相同步配置与启停,`409` 视为冲突、`401` 报 auth 错误。
113
+ - Gitee 公开仓库 contents 接口实测可达(200,base64 正常解码)。
114
+
115
+ ## 已知边界
116
+
117
+ - 只同步“可寻址”的配置与版本;插件代码目录本身不搬运。本地魔改版(`file:` 源、非 registry)不会被远端覆盖,也不会自动装到对方。
118
+ - 版本只升不降;`git:` / `file:` / `link:` 源不自动更新。
119
+ - 不同步 `~/.dsh/.credentials.yaml`;插件配置里的密钥会随私有仓库走,介意就加进 `excludeEntries`。
120
+ - bundle 加载顺序没有公开 API,v1 不动顺序。
121
+ - 不做“仅本机”的字段隔离;所有可同步字段都会同步。
122
+ - Gitee 对单文件大小有限制(远小于 1MB),插件配置正常不会超。
@@ -0,0 +1,18 @@
1
+ # dsh-sync: keep plugin settings, enable/disable state and the plugin set in
2
+ # sync between machines through a private repository.
3
+ #
4
+ # 1. Create an empty private repository (Gitee by default).
5
+ # 2. Put an access token into ~/.dsh/dsh-sync/token, or set DSH_SYNC_TOKEN.
6
+ # The token is never read from this file unless you fill `token` yourself.
7
+ # 3. Fill owner/repo below. `provider` may be gitee, github, gitea or file.
8
+ - insert:
9
+ - id: dsh-sync
10
+ name: dsh-sync
11
+ config:
12
+ provider: gitee
13
+ owner: ""
14
+ repo: ""
15
+ branch: main
16
+ path: dsh-sync
17
+ intervalSeconds: 15
18
+ installMissing: true
package/icon.svg ADDED
@@ -0,0 +1,15 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" width="128" height="128">
2
+ <defs>
3
+ <linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0" stop-color="#4f8cff"/>
5
+ <stop offset="1" stop-color="#8a5cff"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <rect x="4" y="4" width="120" height="120" rx="28" fill="url(#g)"/>
9
+ <g fill="none" stroke="#ffffff" stroke-width="8" stroke-linecap="round" stroke-linejoin="round">
10
+ <path d="M92 44H44a14 14 0 0 0-14 14v6"/>
11
+ <path d="M76 28l16 16-16 16"/>
12
+ <path d="M36 84h48a14 14 0 0 0 14-14v-6"/>
13
+ <path d="M52 100L36 84l16-16"/>
14
+ </g>
15
+ </svg>
package/index.js ADDED
@@ -0,0 +1,26 @@
1
+ import { SyncEngine } from './lib/engine.js'
2
+
3
+ export const name = 'dsh-sync'
4
+ export const inject = ['configEditor', 'pluginManager']
5
+
6
+ let active = null
7
+
8
+ /**
9
+ * Host-only bundle entry. Everything the engine registers is owned by one
10
+ * effect, so a profile reload stops the old timers before the next start.
11
+ */
12
+ export function apply(ctx, config) {
13
+ const engine = new SyncEngine(ctx, config)
14
+ active = engine
15
+ ctx.effect(() => {
16
+ engine.start()
17
+ return () => {
18
+ engine.stop()
19
+ if (active === engine) active = null
20
+ }
21
+ })
22
+ }
23
+
24
+ export function currentEngine() {
25
+ return active
26
+ }
package/lib/apply.js ADDED
@@ -0,0 +1,153 @@
1
+ import { installedVersion } from './snapshot.js'
2
+ import { compareSemver, isJsonSafe, isSemver, valueHash } from './util.js'
3
+
4
+ const NPM_NAME = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/i
5
+
6
+ export function isInstallableName(name) {
7
+ return typeof name === 'string' && NPM_NAME.test(name) && !name.startsWith('.')
8
+ }
9
+
10
+ /**
11
+ * Timers created while this plugin is being reconciled inherit the HMR
12
+ * transaction's AsyncLocalStorage store. Every later run then looks "nested"
13
+ * to hmr.runExclusive, which refuses with "HMR transactions cannot be nested".
14
+ * Run guarded operations with the stale store exited so the HMR APIs accept
15
+ * them; at that point the original transaction has long finished.
16
+ */
17
+ function outsideHmr(ctx, fn) {
18
+ const hmr = ctx.get('hmr')
19
+ const store = hmr?.executing
20
+ if (store && typeof store.getStore === 'function' && typeof store.exit === 'function' && store.getStore()) {
21
+ return store.exit(fn)
22
+ }
23
+ return fn()
24
+ }
25
+
26
+ /**
27
+ * Keep the plugin code in step with the machine that wrote the config. A config
28
+ * is only replayed once the local install is the same version; when it is older
29
+ * and came from the npm registry, update it in place, otherwise leave the local
30
+ * setup alone and report why.
31
+ */
32
+ async function ensureVersion(ctx, manager, target, helpers) {
33
+ if (!isSemver(target.version)) return null
34
+ const remote = target.version
35
+ if (typeof target.name !== 'string' || target.name.startsWith('@deepseek-ai/')) return null
36
+ const profileDir = helpers.profileDir || ctx.get('profileContext')?.dir || ''
37
+ const local = installedVersion(profileDir, target.name)
38
+ if (!local) return null
39
+ if (local === remote) return null
40
+
41
+ const order = compareSemver(remote, local)
42
+ if (order < 0) {
43
+ return { status: 'skipped', reason: `remote ${remote} is older than local ${local}; downgrades are not synced` }
44
+ }
45
+
46
+ const kind = target.source?.kind || 'npm'
47
+ if (!helpers.updatePlugins) {
48
+ return { status: 'skipped', reason: `remote ${remote} is newer than local ${local}; updatePlugins is off` }
49
+ }
50
+ if (kind !== 'npm') {
51
+ return { status: 'skipped', reason: `remote ${remote} is newer than local ${local}; source is ${kind}, not auto-updatable` }
52
+ }
53
+ if (!isInstallableName(target.name)) {
54
+ return { status: 'skipped', reason: `remote ${remote} is newer than local ${local}; not a registry package` }
55
+ }
56
+
57
+ helpers.log.info('updating plugin to match remote', { name: target.name, from: local, to: remote })
58
+ let result
59
+ try {
60
+ result = await outsideHmr(ctx, () =>
61
+ manager.updateBundle(target.name, remote, { requestId: `dsh-sync-${target.id}-${Date.now()}` }),
62
+ )
63
+ } catch (error) {
64
+ return { status: 'skipped', reason: `update to ${remote} failed: ${error?.message || error}` }
65
+ }
66
+ if (result?.result?.application === 'failed') {
67
+ return { status: 'skipped', reason: `update to ${remote} refused: ${result.result.error?.message || result.result.error?.code || 'failed'}` }
68
+ }
69
+ return { status: 'pending', reason: `plugin updated ${local} -> ${remote}; config applies after it reloads` }
70
+ }
71
+
72
+ /**
73
+ * Replay one merged entry on this machine. Returns a status instead of
74
+ * throwing so a single broken plugin cannot stop the rest of the sync.
75
+ */
76
+ export async function applyTarget(ctx, target, helpers) {
77
+ const editor = ctx.get('configEditor')
78
+ const manager = ctx.get('pluginManager')
79
+ if (!editor || typeof editor.edit !== 'function') return { status: 'pending', reason: 'configEditor unavailable' }
80
+ if (!manager || typeof manager.setPluginEnabled !== 'function') return { status: 'pending', reason: 'pluginManager unavailable' }
81
+
82
+ const find = () => {
83
+ const entries = editor.entries()
84
+ return (
85
+ entries.find((entry) => entry?.options?.id === target.id) ||
86
+ (target.name ? entries.find((entry) => entry?.options?.name === target.name) : undefined)
87
+ )
88
+ }
89
+
90
+ let entry = find()
91
+ if (!entry) {
92
+ if (!helpers.installMissing) return { status: 'missing', reason: 'not installed' }
93
+ if (!isInstallableName(target.name)) return { status: 'missing', reason: 'cannot install non-package name' }
94
+ const pinned = isSemver(target.version) && (target.source?.kind || 'npm') === 'npm'
95
+ const spec = pinned ? `${target.name}@${target.version}` : target.name
96
+ helpers.log.info('installing missing plugin', { name: spec })
97
+ try {
98
+ await outsideHmr(ctx, () => manager.installBundle(spec, { enabled: true, saveExact: pinned }))
99
+ } catch (error) {
100
+ if (error?.code === 'already-installed') {
101
+ // Fall through and wait: reload may still be in flight.
102
+ } else {
103
+ return { status: 'error', reason: `install failed: ${error?.message || error}` }
104
+ }
105
+ }
106
+ entry = await helpers.waitFor({ id: target.id, name: target.name })
107
+ if (!entry) return { status: 'pending', reason: 'installed but not loaded yet' }
108
+ }
109
+
110
+ if (target.enabled !== false) {
111
+ const gate = await ensureVersion(ctx, manager, target, helpers)
112
+ if (gate) return gate
113
+ }
114
+
115
+ if (entry.disabled !== true && target.enabled === false) {
116
+ const result = await outsideHmr(ctx, () => manager.setPluginEnabled(entry.id, false))
117
+ if (result?.application === 'failed') {
118
+ helpers.log.warn('disable refused', { id: target.id, error: result.error })
119
+ return { status: 'error', reason: result.error?.message || result.error?.code || 'disable failed' }
120
+ }
121
+ const after = find()
122
+ if (after && after.disabled !== true) return { status: 'pending', reason: 'disable did not converge' }
123
+ return { status: 'applied' }
124
+ }
125
+
126
+ if (entry.disabled === true && target.enabled === true) {
127
+ const result = await outsideHmr(ctx, () => manager.setPluginEnabled(entry.id, true))
128
+ if (result?.application === 'failed') {
129
+ helpers.log.warn('enable refused', { id: target.id, error: result.error })
130
+ return { status: 'error', reason: result.error?.message || result.error?.code || 'enable failed' }
131
+ }
132
+ entry = await helpers.waitFor({ id: target.id, name: target.name })
133
+ if (!entry) return { status: 'pending', reason: 'enable did not converge' }
134
+ }
135
+
136
+ if (target.enabled === false) return { status: 'applied' }
137
+ if (entry.disabled === true) return { status: 'pending', reason: 'plugin is still disabled' }
138
+ if (!entry.fiber || entry.fiber.state !== 2) return { status: 'pending', reason: 'plugin is not active yet' }
139
+
140
+ const desired = { enabled: true, config: target.config ?? {} }
141
+ if (!isJsonSafe(desired.config)) return { status: 'error', reason: 'config is not JSON-serializable' }
142
+ const current = { enabled: entry.disabled !== true, config: entry.options.config ?? {} }
143
+ if (valueHash(current) === valueHash(desired)) return { status: 'unchanged' }
144
+
145
+ try {
146
+ await outsideHmr(ctx, () => editor.edit(entry, () => JSON.parse(JSON.stringify(desired.config))))
147
+ } catch (error) {
148
+ return { status: 'error', reason: error?.message || String(error) }
149
+ }
150
+ return { status: 'applied' }
151
+ }
152
+
153
+
package/lib/config.js ADDED
@@ -0,0 +1,101 @@
1
+ import fs from 'node:fs'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import { clampInt } from './util.js'
5
+
6
+ export const DEFAULT_CONFIG = {
7
+ provider: 'gitee',
8
+ apiBase: '',
9
+ owner: '',
10
+ repo: '',
11
+ branch: 'main',
12
+ path: 'dsh-sync',
13
+ // Local directory provider (`provider: file`): a synced folder or network share.
14
+ dir: '',
15
+ intervalSeconds: 15,
16
+ installMissing: true,
17
+ // Upgrade a plugin when the winning document was written by a machine on a
18
+ // newer version. Downgrades are never automatic.
19
+ updatePlugins: true,
20
+ excludeEntries: [],
21
+ tokenEnv: 'DSH_SYNC_TOKEN',
22
+ tokenFile: '',
23
+ token: '',
24
+ deviceId: '',
25
+ logLevel: 'info',
26
+ maxDocBytes: 512 * 1024,
27
+ }
28
+
29
+ export function dshHome() {
30
+ const home = process.env.DSH_HOME?.trim()
31
+ return home || path.join(os.homedir(), '.dsh')
32
+ }
33
+
34
+ export function stateDir() {
35
+ return path.join(dshHome(), 'dsh-sync')
36
+ }
37
+
38
+ export function normalizeConfig(raw) {
39
+ const input = raw && typeof raw === 'object' ? raw : {}
40
+ const cfg = { ...DEFAULT_CONFIG, ...input }
41
+
42
+ cfg.provider = String(cfg.provider ?? 'gitee').trim().toLowerCase()
43
+ if (!['gitee', 'github', 'gitea', 'file'].includes(cfg.provider)) cfg.provider = 'gitee'
44
+
45
+ for (const key of ['apiBase', 'owner', 'repo', 'branch', 'path', 'dir', 'tokenEnv', 'tokenFile', 'token', 'deviceId', 'logLevel']) {
46
+ cfg[key] = typeof cfg[key] === 'string' ? cfg[key].trim() : ''
47
+ }
48
+
49
+ cfg.owner = cfg.owner.replace(/^\/+|\/+$/g, '')
50
+ cfg.repo = cfg.repo.replace(/\.git$/i, '').replace(/^\/+|\/+$/g, '')
51
+ cfg.branch = cfg.branch || 'main'
52
+ cfg.path = cfg.path.replace(/^\/+|\/+$/g, '') || 'dsh-sync'
53
+ cfg.dir = expandHome(cfg.dir)
54
+ cfg.tokenFile = expandHome(cfg.tokenFile)
55
+
56
+ cfg.intervalSeconds = clampInt(cfg.intervalSeconds, 5, 3600, 15)
57
+ cfg.maxDocBytes = clampInt(cfg.maxDocBytes, 32 * 1024, 2 * 1024 * 1024, 512 * 1024)
58
+ cfg.installMissing = cfg.installMissing !== false
59
+ cfg.updatePlugins = cfg.updatePlugins !== false
60
+ cfg.excludeEntries = Array.isArray(cfg.excludeEntries)
61
+ ? cfg.excludeEntries.map((item) => String(item ?? '').trim()).filter(Boolean)
62
+ : []
63
+ if (!['debug', 'info', 'warn', 'error'].includes(cfg.logLevel)) cfg.logLevel = 'info'
64
+
65
+ return cfg
66
+ }
67
+
68
+ export function validateConfig(cfg) {
69
+ const problems = []
70
+ const warnings = []
71
+ if (cfg.provider === 'file') {
72
+ if (!cfg.dir) problems.push('`dir` is required when provider is "file"')
73
+ } else {
74
+ if (!cfg.owner) problems.push('`owner` is required')
75
+ if (!cfg.repo) problems.push('`repo` is required')
76
+ if (cfg.provider === 'github' && !cfg.apiBase && !/^[A-Za-z0-9_.-]+$/.test(cfg.owner)) {
77
+ warnings.push('GitHub owner looks unusual')
78
+ }
79
+ if (!cfg.token && !process.env[cfg.tokenEnv || 'DSH_SYNC_TOKEN']) {
80
+ const file = cfg.tokenFile || path.join(stateDir(), 'token')
81
+ let hasFile = false
82
+ try {
83
+ hasFile = fs.existsSync(file) && fs.statSync(file).size > 0
84
+ } catch {}
85
+ if (!hasFile) {
86
+ problems.push(`access token not found (config.token, ${cfg.tokenEnv || 'DSH_SYNC_TOKEN'}, or the token file)`)
87
+ }
88
+ }
89
+ }
90
+ if (cfg.provider === 'gitee' && cfg.apiBase && !/^https:\/\//i.test(cfg.apiBase)) {
91
+ warnings.push('apiBase should use https')
92
+ }
93
+ return { ok: problems.length === 0, problems, warnings }
94
+ }
95
+
96
+ function expandHome(value) {
97
+ if (!value) return value
98
+ if (value === '~') return os.homedir()
99
+ if (value.startsWith('~/') || value.startsWith('~\\')) return path.join(os.homedir(), value.slice(2))
100
+ return value
101
+ }