dsh-config-sync-plugin 0.4.9 → 0.4.11
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.en.md +14 -2
- package/README.md +14 -2
- package/client.js +51 -53
- package/index.js +53 -33
- package/package.json +1 -1
- package/runtime/apply.ps1 +12 -17
- package/runtime/capture.ps1 +1 -1
- package/runtime/dsh-sync-common.ps1 +1 -1
- package/runtime/restore.ps1 +11 -13
- package/runtime/sync.ps1 +6 -4
- package/tools/clientcheck.mjs +3 -2
- package/tools/pack-plugin.ps1 +11 -3
- package/tools/selftest.mjs +56 -31
package/README.en.md
CHANGED
|
@@ -43,7 +43,7 @@ Source A Remote (Gitee / GitHub / …) Target B
|
|
|
43
43
|
|
|
44
44
|
| Item | Requirement | When missing |
|
|
45
45
|
|---|---|---|
|
|
46
|
-
| Client version |
|
|
46
|
+
| Client version | Since 0.4.10 no need to match: version differences only show a notice, pull is not blocked (experimental bundles are still dropped) | `version mismatch` notice in the panel/log; configs still sync |
|
|
47
47
|
| Target `.dsh` | The client must have run at least once, so `profiles\<profile>` exists | `[X] target profile does not exist (DSH never installed here?)` → pull aborts |
|
|
48
48
|
| Node / Electron runner | Ships with the client (`<AppRoot>\node.exe` or `DeepSeek Harness.exe`) | `no usable built-in runtime`, session cwd is not rewritten → **the session list stays empty** |
|
|
49
49
|
| Repo skeleton | Written automatically by the source machine's initial push | A repo with only `settings\` and no `apply.ps1` cannot run on B; redo the initial push |
|
|
@@ -257,6 +257,18 @@ Two display fixes on top of 0.3.77:
|
|
|
257
257
|
|
|
258
258
|
The "Plugin update" card now shows an **npm download URL** line with the actual fallback addresses (domestic mirror `registry.npmmirror.com` + official `registry.npmjs.org`). When the GitHub release download is unreachable (common in mainland China), the update package automatically falls back to npm. It is still verified against the authoritative sha256 in `version.json` — switching source never relaxes verification. The two sources back each other up: the mirror can briefly 404 during its first-sync window, and the official source takes over. The npm tarball is byte-identical to the GitHub release tgz (same sha256).
|
|
259
259
|
|
|
260
|
+
### Code cleanup and consistency fixes: equivalent refactor, no feature change (0.4.11)
|
|
261
|
+
|
|
262
|
+
This release is an equivalent refactor. The normal sync path is identical to 0.4.10 and no user-visible feature changes:
|
|
263
|
+
|
|
264
|
+
- **Gate criteria consolidated**: `pushAllowed` / `pullAllowed` are now unified into `canPush()` / `canPull()`, word-for-word equivalent to the original criteria; the fast criteria on the close path are unchanged and introduce no new allow conditions.
|
|
265
|
+
- **One fewer remote request**: the periodic re-check already ran `git fetch` and has the drift, so it reuses it via `driftOverride` instead of fetching again.
|
|
266
|
+
- **Idempotent force-kill**: multiple force-kill triggers within 1.5 seconds execute only once, so the close hook / periodic pre-queue / frontend beacon do not kill the same process family repeatedly.
|
|
267
|
+
- **Single source of truth**: the plugin root and version are consolidated to a single `PLUGIN_DIR` / `PLUGIN_VERSION` definition; dead code (`lsRemoteHeads`, unused imports, unused state) was removed.
|
|
268
|
+
- **Consistency fixes**: `market-index.json` `publishTimestamp` normalized to milliseconds; leading-zero versions gain an `npmVersion` field; packaging excludes `_stage-*` / `_refactor-*` / `*.bak*` temp artifacts; the restore flow's AppRoot detection and experimental-bundle (`app.asar`) recognition are aligned with the main path; the language header is computed at request time (POST follows a language switch too); `callUpdate` now checks failures.
|
|
269
|
+
|
|
270
|
+
Self-test: the four `node --check` targets, `selftest.mjs` and `clientcheck.mjs` match the 0.4.10 baseline item by item (the 8 prepare failures in this environment are pre-existing baseline failures with no `origin` configured, not introduced by this release).
|
|
271
|
+
|
|
260
272
|
### Pending push but nothing happens on × close: backend periodic pre-queue (0.4.05)
|
|
261
273
|
|
|
262
274
|
End-to-end diagnosis (manual POST to `/config-sync/auto-exit`) proved the backend check and route are fine — it instantly returns `queued:true`, queues the watcher, force-exits DSH and completes the push. Root cause is the frontend: `pagehide → navigator.sendBeacon('/config-sync/auto-exit')` never reaches the backend when DSH really exits (no beacon arrival in launch.log during × close), yet 0.3.96+ relied solely on it — code-level selftests passed but real UI never verified it.
|
|
@@ -636,7 +648,7 @@ The panel has a "Sync content" card (placed at the very bottom of the page): the
|
|
|
636
648
|
- Skipping applies to **both directions**: `capture.ps1` stops capturing (nothing new lands in the repo) and `apply.ps1` stops restoring (your machine is untouched). `-PruneSkills` also stops treating "a skill you unchecked" as an extra to delete.
|
|
637
649
|
- The card carries one more switch, "Also delete the cloud copy when unchecked", **off by default**: while off, unchecking just means "this machine stops caring" and the cloud copy stays, so re-ticking resumes immediately; when on, unchecking really deletes the matching folder/sub-path from the repo on the next push (the other machine can no longer pull it) and **that deletion cannot be undone**.
|
|
638
650
|
- Items you cannot tick (the five profile files, mnemon) are deliberately group-level switches: the lockfile specifiers must match package.json, and excluding one alone breaks installation.
|
|
639
|
-
- **The "Local profile" group is required and cannot be unchecked** (the panel shows "required" and greys the checkbox out). It is not an optional extra but a precondition of `apply.ps1`: when `profile\package.json` or `profile\cordis.patch.yml` is missing from the repo, a pull stops with `[X] 仓库内容不完整`; and `profile\host-contract.json` in the same group
|
|
651
|
+
- **The "Local profile" group is required and cannot be unchecked** (the panel shows "required" and greys the checkbox out). It is not an optional extra but a precondition of `apply.ps1`: when `profile\package.json` or `profile\cordis.patch.yml` is missing from the repo, a pull stops with `[X] 仓库内容不完整`; and `profile\host-contract.json` in the same group since 0.4.10 only feeds the "App / contract" info strip — version differences no longer block pull. Editing `config-sync-scope.json` to `false` does not help either: `capture.ps1`, `apply.ps1` and the panel all treat it as on (`Test-SyncGroupEnabled` pins it).
|
|
640
652
|
|
|
641
653
|
## Plugin data & extra paths (0.3.51)
|
|
642
654
|
|
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ DSH 插件:左侧栏多一行「配置同步」,点开是整页体检面板
|
|
|
41
41
|
|
|
42
42
|
| 项 | 要求 | 不满足时的表现 |
|
|
43
43
|
|---|---|---|
|
|
44
|
-
| 客户端版本 |
|
|
44
|
+
| 客户端版本 | 0.4.10 起**无需同版本**:版本不同只提示、不阻断拉取(实验性 bundle 仍会剔除) | 面板/日志提示 `版本不一致`,配置照常同步 |
|
|
45
45
|
| 目标机器 `.dsh` | 至少启动过一次客户端,存在 `profiles\<profile>` | `[X] 目标 profile 不存在(本机还没装过 DSH?)` → 拉取直接退出 |
|
|
46
46
|
| Node / Electron 执行器 | 客户端自带(`<AppRoot>\node.exe` 或 `DeepSeek Harness.exe`) | `本机没有可用的内置运行时`,会话 cwd 无法改写,**会话列表会是空的** |
|
|
47
47
|
| 仓库骨架 | 由源机器首次推送自动写入 | 仓库里只有 `settings\`、没有 `apply.ps1` → 目标机器跑不起来,必须重新初始化推送 |
|
|
@@ -277,6 +277,18 @@ pwsh -File runtime\sync.ps1 pull `
|
|
|
277
277
|
|
|
278
278
|
「插件更新」卡新增一行 **npm 下载路径**,直接显示实际兜底地址(国内镜像 `registry.npmmirror.com` + 官方 `registry.npmjs.org` 两个源)。GitHub release 整段不通时(国内常见),更新包会自动兜底从 npm 下载;仍按 `version.json` 里的权威 sha256 校验,换源不放宽校验。两个源互为备份:镜像首发同步窗口期会短暂 404,官方源随即兜上。实测 npm tarball 与 GitHub release tgz 是同一份产物、sha256 完全一致。
|
|
279
279
|
|
|
280
|
+
### 代码整理与一致性修复:等价重构,功能不变(0.4.11)
|
|
281
|
+
|
|
282
|
+
本版是一次等价重构,正常同步路径与 0.4.10 完全一致,不改变任何用户可见功能:
|
|
283
|
+
|
|
284
|
+
- **门禁判据收敛**:`pushAllowed` / `pullAllowed` 抽成 `canPush()` / `canPull()` 统一函数,判据与原来逐字等价;退出关闭路径的 fast 判据保持原样,不引入新的放行条件。
|
|
285
|
+
- **少一次远端请求**:定时复查已经 `git fetch` 得到 drift,直接复用并传给 `checkAndQueueAutoSync`(`driftOverride`),不再重复 fetch。
|
|
286
|
+
- **强杀幂等**:1.5 秒内多次触发强杀只执行一次,避免窗口关闭钩子 / 定时预排 / 前端信标三路重复杀同一进程族。
|
|
287
|
+
- **单一定义**:插件根目录与版本收敛到 `PLUGIN_DIR` / `PLUGIN_VERSION` 单一来源;删除从未调用的 `lsRemoteHeads`、死导入与未使用的 state 等死代码。
|
|
288
|
+
- **一致性修复**:`market-index.json` 的 `publishTimestamp` 统一为毫秒;前导零版本补 `npmVersion` 字段;打包排除 `_stage-*` / `_refactor-*` / `*.bak*` 等临时产物;还原流程的 AppRoot 探测与实验 bundle(`app.asar`)识别对齐主链路;语言头改为请求时计算(切换语言后 POST 也跟随);`callUpdate` 补失败判断。
|
|
289
|
+
|
|
290
|
+
自测:`node --check` 四项、`selftest.mjs`、`clientcheck.mjs` 与 0.4.10 基线逐项一致(本环境 8 项 prepare 失败为无 origin 的既有基线失败,非本版引入)。
|
|
291
|
+
|
|
280
292
|
### 点 × 立即执行待推送/待拉取:后端窗口监视(0.4.06)
|
|
281
293
|
|
|
282
294
|
0.4.05 把「点 × 后没执行」的根因定位到前端信标送不到后端,用 2 分钟定时复查预排 watcher 绕开。但预排有窗口期:用户在两次复查之间点 ×,那一刻既没有预排 watcher、信标又送不到,退出后就什么都不执行。
|
|
@@ -624,7 +636,7 @@ DSH 的会话标题会演进:先产生 fallback 临时标题(首条消息截
|
|
|
624
636
|
- 勾选记在 `~\.dsh\config-sync-scope.json`,跟本机走、不进仓库;只留与默认不同的项,删掉就恢复全勾。
|
|
625
637
|
- 跳过**两侧都生效**:`capture.ps1` 不抓、`apply.ps1` 不还原;`-PruneSkills` 也不会把"勾掉的本机技能"当多出来的项删掉。
|
|
626
638
|
- 另有开关「取消勾选时顺手删掉云端副本」,**默认关**;打开后取消勾选会真的删仓库里的对应目录(删除不可恢复)。
|
|
627
|
-
- **`本机 profile` 是必需内容**:仓库里没有 `profile\package.json` 或 `cordis.patch.yml` 时拉取会 `[X] 仓库内容不完整` 退出;`profile\host-contract.json`
|
|
639
|
+
- **`本机 profile` 是必需内容**:仓库里没有 `profile\package.json` 或 `cordis.patch.yml` 时拉取会 `[X] 仓库内容不完整` 退出;`profile\host-contract.json` 自 0.4.10 起只用于「本机/契约」信息条展示,版本不同不再阻断拉取。
|
|
628
640
|
|
|
629
641
|
## 插件数据与额外路径(0.3.51)
|
|
630
642
|
|
package/client.js
CHANGED
|
@@ -231,6 +231,10 @@ window.__ModuleLoader__.load({
|
|
|
231
231
|
)
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
+
// 状态口径统一:后端 0.4.10 起用 uncommitted,旧快照/旧版本可能只有 dirty;
|
|
235
|
+
// 这里统一取值函数,local.pending / repo.pending 仍是“待推送”语义,保持原样。
|
|
236
|
+
const uncommittedOf = (repo) => (repo?.uncommitted ?? repo?.dirty ?? 0)
|
|
237
|
+
|
|
234
238
|
/**
|
|
235
239
|
* 左侧徽标:只说**本机自身**的状态(配置是否齐、依赖是否缺、有没有未提交/未推送的改动)。
|
|
236
240
|
* 「云端比本机领先多少」一律交给右侧云端徽标(cloudLine),否则标题行会同时出现
|
|
@@ -257,17 +261,9 @@ window.__ModuleLoader__.load({
|
|
|
257
261
|
? { kind: 'init', text: M('本机与云端都还没有内容:待「初始化推送」', 'Local repo and cloud are both empty — Initialize push') }
|
|
258
262
|
: { kind: 'pull', text: M('本机仓库还没有内容:待从云端「拉取」', 'Local repo has no content yet — pull it from the cloud') }
|
|
259
263
|
}
|
|
260
|
-
|
|
261
|
-
return {
|
|
262
|
-
kind: 'warn',
|
|
263
|
-
text: M(
|
|
264
|
-
`版本不一致(本机 ${version.local} ≠ 契约 ${version.contract})`,
|
|
265
|
-
`Version mismatch (local ${version.local} ≠ contract ${version.contract})`,
|
|
266
|
-
),
|
|
267
|
-
}
|
|
268
|
-
}
|
|
264
|
+
// 0.4.10 起:本机/契约版本不一致不再算告警——拉取不再因版本不一致被阻断,只保留左上角信息条展示。
|
|
269
265
|
if (repo.behind === null) return { kind: 'idle', text: M('读不到本机 git 状态(git 不可用或没 upstream)', 'Cannot read local git state (git missing or no upstream)') }
|
|
270
|
-
if (repo
|
|
266
|
+
if (uncommittedOf(repo) > 0) return { kind: 'warn', text: M(`本机有 ${uncommittedOf(repo)} 处未提交改动,建议推送`, `${uncommittedOf(repo)} uncommitted change(s) — consider pushing`) }
|
|
271
267
|
if (repo.ahead > 0) return { kind: 'warn', text: M(`本机有 ${repo.ahead} 个提交还没推送`, `${repo.ahead} local commit(s) not pushed yet`) }
|
|
272
268
|
// git 干净不代表没东西要推:新会话/新资料还躺在 ~\.dsh 里,没 capture 之前仓库是完全干净的
|
|
273
269
|
const local = data.local || {}
|
|
@@ -337,14 +333,15 @@ window.__ModuleLoader__.load({
|
|
|
337
333
|
}
|
|
338
334
|
|
|
339
335
|
/** 每个 POST 都带 accept-language:宿主的建议句/错误信息按它出中文或英文。 */
|
|
340
|
-
|
|
336
|
+
// 函数化:每次请求现读语言,避免面板加载后才切换语言时 POST 仍带旧 accept-language。
|
|
337
|
+
const jsonHeaders = () => ({ 'content-type': 'application/json', ...langHeaders() })
|
|
341
338
|
|
|
342
339
|
async function callPrepare(action, message, backupDir) {
|
|
343
340
|
const res = await fetch('/config-sync/prepare', {
|
|
344
341
|
method: 'POST',
|
|
345
342
|
cache: 'no-store',
|
|
346
343
|
credentials: 'same-origin',
|
|
347
|
-
headers: jsonHeaders,
|
|
344
|
+
headers: jsonHeaders(),
|
|
348
345
|
body: JSON.stringify({ action, message: message || '', backupDir: backupDir || '' }),
|
|
349
346
|
})
|
|
350
347
|
const text = await res.text()
|
|
@@ -359,7 +356,7 @@ window.__ModuleLoader__.load({
|
|
|
359
356
|
method: 'POST',
|
|
360
357
|
cache: 'no-store',
|
|
361
358
|
credentials: 'same-origin',
|
|
362
|
-
headers: jsonHeaders,
|
|
359
|
+
headers: jsonHeaders(),
|
|
363
360
|
body: JSON.stringify(payload),
|
|
364
361
|
})
|
|
365
362
|
const text = await res.text()
|
|
@@ -375,7 +372,7 @@ window.__ModuleLoader__.load({
|
|
|
375
372
|
method: 'POST',
|
|
376
373
|
cache: 'no-store',
|
|
377
374
|
credentials: 'same-origin',
|
|
378
|
-
headers: jsonHeaders,
|
|
375
|
+
headers: jsonHeaders(),
|
|
379
376
|
body: JSON.stringify(payload),
|
|
380
377
|
})
|
|
381
378
|
const text = await res.text()
|
|
@@ -395,7 +392,7 @@ window.__ModuleLoader__.load({
|
|
|
395
392
|
method: 'POST',
|
|
396
393
|
cache: 'no-store',
|
|
397
394
|
credentials: 'same-origin',
|
|
398
|
-
headers: jsonHeaders,
|
|
395
|
+
headers: jsonHeaders(),
|
|
399
396
|
body: JSON.stringify(payload),
|
|
400
397
|
}
|
|
401
398
|
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
@@ -416,7 +413,7 @@ window.__ModuleLoader__.load({
|
|
|
416
413
|
method: 'POST',
|
|
417
414
|
cache: 'no-store',
|
|
418
415
|
credentials: 'same-origin',
|
|
419
|
-
headers: jsonHeaders,
|
|
416
|
+
headers: jsonHeaders(),
|
|
420
417
|
body: JSON.stringify(payload),
|
|
421
418
|
}
|
|
422
419
|
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
@@ -437,7 +434,7 @@ window.__ModuleLoader__.load({
|
|
|
437
434
|
method: 'POST',
|
|
438
435
|
cache: 'no-store',
|
|
439
436
|
credentials: 'same-origin',
|
|
440
|
-
headers: jsonHeaders,
|
|
437
|
+
headers: jsonHeaders(),
|
|
441
438
|
body: JSON.stringify(payload),
|
|
442
439
|
}
|
|
443
440
|
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
@@ -455,14 +452,14 @@ window.__ModuleLoader__.load({
|
|
|
455
452
|
method: 'POST',
|
|
456
453
|
cache: 'no-store',
|
|
457
454
|
credentials: 'same-origin',
|
|
458
|
-
headers: jsonHeaders,
|
|
455
|
+
headers: jsonHeaders(),
|
|
459
456
|
body: JSON.stringify(payload),
|
|
460
457
|
}
|
|
461
458
|
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
462
459
|
const text = await res.text()
|
|
463
460
|
let body
|
|
464
461
|
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
465
|
-
if (!res.ok || !body) throw new Error((body && body.error) || `${res.status}`)
|
|
462
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
466
463
|
return body
|
|
467
464
|
}
|
|
468
465
|
|
|
@@ -473,7 +470,7 @@ window.__ModuleLoader__.load({
|
|
|
473
470
|
method: 'POST',
|
|
474
471
|
cache: 'no-store',
|
|
475
472
|
credentials: 'same-origin',
|
|
476
|
-
headers: jsonHeaders,
|
|
473
|
+
headers: jsonHeaders(),
|
|
477
474
|
body: JSON.stringify(payload),
|
|
478
475
|
}
|
|
479
476
|
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
@@ -492,7 +489,7 @@ window.__ModuleLoader__.load({
|
|
|
492
489
|
method,
|
|
493
490
|
cache: 'no-store',
|
|
494
491
|
credentials: 'same-origin',
|
|
495
|
-
headers: payload ? jsonHeaders : langHeaders(),
|
|
492
|
+
headers: payload ? jsonHeaders() : langHeaders(),
|
|
496
493
|
body: payload ? JSON.stringify(payload) : undefined,
|
|
497
494
|
})
|
|
498
495
|
const text = await res.text()
|
|
@@ -514,7 +511,7 @@ window.__ModuleLoader__.load({
|
|
|
514
511
|
method: 'POST',
|
|
515
512
|
cache: 'no-store',
|
|
516
513
|
credentials: 'same-origin',
|
|
517
|
-
headers: jsonHeaders,
|
|
514
|
+
headers: jsonHeaders(),
|
|
518
515
|
body: JSON.stringify(payload),
|
|
519
516
|
}
|
|
520
517
|
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
@@ -696,8 +693,8 @@ window.__ModuleLoader__.load({
|
|
|
696
693
|
k: M('远端', 'Remote'),
|
|
697
694
|
v: repo.exists
|
|
698
695
|
? M(
|
|
699
|
-
`落后 ${repo.behind ?? '?'} · 领先 ${repo.ahead ?? '?'} · 未提交 ${repo
|
|
700
|
-
`behind ${repo.behind ?? '?'} · ahead ${repo.ahead ?? '?'} · uncommitted ${repo
|
|
696
|
+
`落后 ${repo.behind ?? '?'} · 领先 ${repo.ahead ?? '?'} · 未提交 ${uncommittedOf(repo)}` + (repo.pending ? `(本机待同步 ${repo.pending})` : ''),
|
|
697
|
+
`behind ${repo.behind ?? '?'} · ahead ${repo.ahead ?? '?'} · uncommitted ${uncommittedOf(repo)}` + (repo.pending ? ` (${repo.pending} pending on this machine)` : ''),
|
|
701
698
|
)
|
|
702
699
|
: (repo.empty ? M('(拉取之后才有得比)', '(available after the first pull)') : M('(不可用)', '(unavailable)')),
|
|
703
700
|
}),
|
|
@@ -853,7 +850,6 @@ window.__ModuleLoader__.load({
|
|
|
853
850
|
const [busy, setBusy] = react.useState(false)
|
|
854
851
|
const [err, setErr] = react.useState('')
|
|
855
852
|
const [msg, setMsg] = react.useState('')
|
|
856
|
-
const [made, setMade] = react.useState(null)
|
|
857
853
|
const [confirm, setConfirm] = react.useState(null) // { snap, preview }:确认环节
|
|
858
854
|
const [queued, setQueued] = react.useState(null) // restore-now 的排队结果
|
|
859
855
|
const [manual, setManual] = react.useState(null) // 认不出类型时的「手动还原」指引
|
|
@@ -1172,17 +1168,6 @@ window.__ModuleLoader__.load({
|
|
|
1172
1168
|
manualBlock,
|
|
1173
1169
|
queuedBlock,
|
|
1174
1170
|
lastRestoreBlock,
|
|
1175
|
-
made
|
|
1176
|
-
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
|
|
1177
|
-
h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } },
|
|
1178
|
-
M(`已生成:${made.path}`, `Generated: ${made.path}`)),
|
|
1179
|
-
h('div', { style: S.code }, made.command || ''),
|
|
1180
|
-
h('div', { style: S.footnote }, M(
|
|
1181
|
-
'完全退出 DSH 后双击这份 .cmd:先打印计划,输 y 才真正写(写前自动备份当前状态)。',
|
|
1182
|
-
'Quit DSH, then double-click the .cmd: it prints the plan and only writes after y (backing up the current state first).',
|
|
1183
|
-
)),
|
|
1184
|
-
)
|
|
1185
|
-
: null,
|
|
1186
1171
|
err ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`操作失败:${err}`, `Failed: ${err}`)) : null,
|
|
1187
1172
|
msg ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } }, msg) : null,
|
|
1188
1173
|
h('div', { style: S.footnote }, M(
|
|
@@ -2015,7 +2000,7 @@ window.__ModuleLoader__.load({
|
|
|
2015
2000
|
try {
|
|
2016
2001
|
const res = await fetch('/config-sync/auto', {
|
|
2017
2002
|
method: 'POST', cache: 'no-store', credentials: 'same-origin',
|
|
2018
|
-
headers: jsonHeaders,
|
|
2003
|
+
headers: jsonHeaders(),
|
|
2019
2004
|
body: JSON.stringify({ action, ...(extra || {}) }),
|
|
2020
2005
|
})
|
|
2021
2006
|
const text = await res.text()
|
|
@@ -2101,6 +2086,8 @@ window.__ModuleLoader__.load({
|
|
|
2101
2086
|
type: 'button',
|
|
2102
2087
|
style: canPullNow ? S.btnPrimary : { ...S.btnPrimary, opacity: 0.5, cursor: 'not-allowed' },
|
|
2103
2088
|
disabled: Boolean(busy) || !canPullNow,
|
|
2089
|
+
// 文案分叉是刻意的,与设置页摘要行不同:本卡的推送按钮在 initMode 下会切成「初始化推送」,
|
|
2090
|
+
// 所以这里指引写「先初始化推送」与按钮实际标签一致;摘要行按钮固定「立即推送」,两处场景不同,保留各自口径。
|
|
2104
2091
|
title: canPullNow ? '' : M('云端还是空的:没有内容可拉,先「初始化推送」', 'The cloud is still empty — nothing to pull, initialize push first'),
|
|
2105
2092
|
onClick: () => act('pull-now'),
|
|
2106
2093
|
}, M('立即拉取(会关闭 DSH)', 'Pull now (closes DSH)')),
|
|
@@ -2249,7 +2236,6 @@ window.__ModuleLoader__.load({
|
|
|
2249
2236
|
// 定时器放 ref 里:数据每刷新一次 effect 就会重跑,若在 effect 里 return 清理函数,
|
|
2250
2237
|
// 会把还没到点的"5 秒后消失"定时器一起清掉,提示就一直挂在屏幕上。
|
|
2251
2238
|
const toastTimer = react.useRef(null)
|
|
2252
|
-
const headerRef = react.useRef(null)
|
|
2253
2239
|
const summary = summarize(data)
|
|
2254
2240
|
// 门禁分三条:有路径就能生成还原脚本;拉取允许「真仓库 or 空目录」;推送只允许真仓库。
|
|
2255
2241
|
// 空目录 = 新机器还没拉过,面板只放行「拉取」,推送按钮直接禁掉(后端也会再拦一次)。
|
|
@@ -2313,6 +2299,9 @@ window.__ModuleLoader__.load({
|
|
|
2313
2299
|
if (failure) {
|
|
2314
2300
|
showToast(M(`重新检测失败:${failure}`, `Re-check failed: ${failure}`))
|
|
2315
2301
|
} else {
|
|
2302
|
+
// 时间格式三处不统一是刻意保留:toast 只需当前「时分秒」即时反馈,短格式更轻;
|
|
2303
|
+
// 概览指标用固定 M/D HH:mm 省版面,待办卡用 toLocaleString 出完整日期。三者可见格式不同,
|
|
2304
|
+
// 统一会改变用户看到的文案,按功能不变优先保持原样。
|
|
2316
2305
|
const t = new Date().toLocaleTimeString()
|
|
2317
2306
|
showToast(M(`已重新检测,数据已是最新(${t})`, `Re-checked, data is up to date (${t})`))
|
|
2318
2307
|
}
|
|
@@ -2356,7 +2345,9 @@ window.__ModuleLoader__.load({
|
|
|
2356
2345
|
}
|
|
2357
2346
|
}
|
|
2358
2347
|
|
|
2359
|
-
// 老路径遗留(install-live
|
|
2348
|
+
// 老路径遗留(install-live 装好了但没重启):只重启,不装东西。
|
|
2349
|
+
// 这里保留 restartDsh:restartRequired 场景下包已经覆盖进插件目录,只缺一次重启;
|
|
2350
|
+
// 主路径 restartAndInstall 走 install-restart,会先检查 prepared 包并再次安装,和这个场景不等价。
|
|
2360
2351
|
const restartDsh = async () => {
|
|
2361
2352
|
setUpdBusy(true)
|
|
2362
2353
|
try {
|
|
@@ -2468,9 +2459,12 @@ window.__ModuleLoader__.load({
|
|
|
2468
2459
|
return { kind: 'idle', text: M('云端检查中…', 'Checking the cloud…') }
|
|
2469
2460
|
})()
|
|
2470
2461
|
|
|
2462
|
+
// cloudLine 实际可能返回 ok / error / pull / init / idle;原先 init 落到默认「检查中」,
|
|
2463
|
+
// error 也只写「不一致」,这里按 chipLabel 的同款口径补全每一种 kind 的短标签。
|
|
2471
2464
|
const cloudLabel = cloudLine.kind === 'ok' ? M('一致', 'In sync')
|
|
2472
|
-
: (cloudLine.kind === 'error' ? M('
|
|
2473
|
-
: (cloudLine.kind === 'pull' ? M('待拉取', 'To pull')
|
|
2465
|
+
: (cloudLine.kind === 'error' ? M('检查失败', 'Check failed')
|
|
2466
|
+
: (cloudLine.kind === 'pull' ? M('待拉取', 'To pull')
|
|
2467
|
+
: (cloudLine.kind === 'init' ? M('待初始化', 'To initialize') : M('检查中', 'Checking'))))
|
|
2474
2468
|
|
|
2475
2469
|
// 插件更新卡:老版本机器进来第一眼就能看到"有新版本 x.y.z"和更新按钮;
|
|
2476
2470
|
// 更新相关的配置(清单地址、只读令牌)也收在这张卡里,别散到「云端仓库」去。
|
|
@@ -2638,9 +2632,9 @@ window.__ModuleLoader__.load({
|
|
|
2638
2632
|
)
|
|
2639
2633
|
const versionText = !data ? '…'
|
|
2640
2634
|
: `${data.version.local || '?'} / ${data.version.contract || '?'}`
|
|
2635
|
+
// 0.4.10 起:版本不一致不再标红/标黄(拉取已不因版本差异阻断),信息条仅作展示。
|
|
2641
2636
|
const metrics = h('div', { style: S.strip },
|
|
2642
|
-
metric(M('本机 / 契约', 'App / contract'), versionText,
|
|
2643
|
-
data && data.version.local && data.version.contract && !data.version.match ? 'warn' : 'ok'),
|
|
2637
|
+
metric(M('本机 / 契约', 'App / contract'), versionText, 'ok'),
|
|
2644
2638
|
metric('bundle',
|
|
2645
2639
|
!data ? '…' : (data.bundles.unresolved.length
|
|
2646
2640
|
? M(`缺 ${data.bundles.unresolved.length} / ${data.bundles.total}`, `${data.bundles.unresolved.length} missing / ${data.bundles.total}`)
|
|
@@ -2817,7 +2811,7 @@ window.__ModuleLoader__.load({
|
|
|
2817
2811
|
// 页头在滚动区之外:内容滚不到它上面,区标签跳转后的标题也只出现在它下面
|
|
2818
2812
|
h('div', { style: S.pageHeaderWrap },
|
|
2819
2813
|
h('div', { style: S.pageHeaderInner },
|
|
2820
|
-
h('div', {
|
|
2814
|
+
h('div', { style: S.pageHeader },
|
|
2821
2815
|
h('div', { style: S.pageHeaderMain },
|
|
2822
2816
|
h('div', { style: S.pageTitleRow },
|
|
2823
2817
|
h('div', { style: S.pageTitle }, M('配置同步', 'Config Sync')),
|
|
@@ -2873,12 +2867,13 @@ window.__ModuleLoader__.load({
|
|
|
2873
2867
|
...(conflictCard ? [['conflict', M('同步冲突', 'Sync conflicts')]] : []),
|
|
2874
2868
|
...(showRoots ? [['roots', M('本机路径', 'Local paths')]] : []),
|
|
2875
2869
|
['targets', M('同步目标', 'Targets')],
|
|
2876
|
-
|
|
2877
|
-
['
|
|
2878
|
-
['
|
|
2879
|
-
['
|
|
2880
|
-
['
|
|
2881
|
-
['
|
|
2870
|
+
// 导航文案与 Section 标题口径对齐:key 仍是滚动锚点,只改显示标签,不改功能分组。
|
|
2871
|
+
['automation', M('自动化与插件更新', 'Automation & plugin update')],
|
|
2872
|
+
['actions', M('退出后执行', 'After exit')],
|
|
2873
|
+
['restore', M('还原备份', 'Restore backup')],
|
|
2874
|
+
['scope', M('同步内容', 'Sync content')],
|
|
2875
|
+
['extra', M('插件数据与额外路径', 'Plugin data & extra paths')],
|
|
2876
|
+
['workspace', M('工作区显示', 'Workspace visibility')],
|
|
2882
2877
|
['feedback', M('问题反馈', 'Feedback')],
|
|
2883
2878
|
].map((pair) => {
|
|
2884
2879
|
const sid = pair[0], label = pair[1]
|
|
@@ -3535,8 +3530,8 @@ window.__ModuleLoader__.load({
|
|
|
3535
3530
|
v: data.repo.behind === null
|
|
3536
3531
|
? M('读不到', 'Unavailable')
|
|
3537
3532
|
: M(
|
|
3538
|
-
`落后 ${data.repo.behind} · 领先 ${data.repo.ahead} · 未提交 ${data.repo
|
|
3539
|
-
`behind ${data.repo.behind} · ahead ${data.repo.ahead} · uncommitted ${data.repo
|
|
3533
|
+
`落后 ${data.repo.behind} · 领先 ${data.repo.ahead} · 未提交 ${uncommittedOf(data.repo)}` + (data.repo.pending ? `(本机待同步 ${data.repo.pending})` : ''),
|
|
3534
|
+
`behind ${data.repo.behind} · ahead ${data.repo.ahead} · uncommitted ${uncommittedOf(data.repo)}` + (data.repo.pending ? ` (${data.repo.pending} pending on this machine)` : ''),
|
|
3540
3535
|
),
|
|
3541
3536
|
}) : null,
|
|
3542
3537
|
data ? h(Kv, {
|
|
@@ -3554,6 +3549,9 @@ window.__ModuleLoader__.load({
|
|
|
3554
3549
|
type: 'button',
|
|
3555
3550
|
style: canPull ? S.btnPrimary : { ...S.btnPrimary, opacity: 0.5, cursor: 'not-allowed' },
|
|
3556
3551
|
disabled: Boolean(actBusy) || !canPull,
|
|
3552
|
+
// 文案分叉是刻意的,与「自动同步」卡不同:本摘要行的推送按钮固定显示「立即推送」,
|
|
3553
|
+
// 两边都空时那次推送即初始化推送;自动同步卡在 initMode 会把按钮切成「初始化推送」。
|
|
3554
|
+
// 两处场景不同,各自指引与旁边按钮标签一致,保留原口径。
|
|
3557
3555
|
title: canPull ? '' : M('云端还是空的:没有内容可拉,先「立即推送」', 'The cloud is still empty — nothing to pull, push first'),
|
|
3558
3556
|
onClick: () => actNow('pull-now'),
|
|
3559
3557
|
}, actBusy === 'pull-now' ? M('排队中…', 'Queueing…') : M('立即拉取(会关闭 DSH)', 'Pull now (closes DSH)')),
|
|
@@ -3647,7 +3645,7 @@ window.__ModuleLoader__.load({
|
|
|
3647
3645
|
method: 'POST',
|
|
3648
3646
|
cache: 'no-store',
|
|
3649
3647
|
credentials: 'same-origin',
|
|
3650
|
-
headers: jsonHeaders,
|
|
3648
|
+
headers: jsonHeaders(),
|
|
3651
3649
|
body: JSON.stringify({ action: 'busy', sessionId: sessionId || '' }),
|
|
3652
3650
|
})
|
|
3653
3651
|
if (!res.ok) return false
|
package/index.js
CHANGED
|
@@ -27,7 +27,7 @@ import { fileURLToPath } from 'node:url'
|
|
|
27
27
|
// 0.3.76:会话投影缓存守卫(agent-busy 自动清缓存,让缓存按日志重建)
|
|
28
28
|
import { runGuard, clearSessionCaches, appendGuardLog } from './runtime/tools/session-cache-guard.mjs'
|
|
29
29
|
// 0.3.76:工作区显示状态(三态 + 会话独立隐藏),自包含读写 DSH 两个权威文件
|
|
30
|
-
import { readView
|
|
30
|
+
import { readView } from './runtime/tools/workspace-view.mjs'
|
|
31
31
|
// 0.3.82:实时通道。拿不到 workspaceRegistry 时,这两个函数内部自动退回上面的文件写法。
|
|
32
32
|
import { setWorkspaceStateLive, setSessionStateLive } from './runtime/tools/workspace-view.mjs'
|
|
33
33
|
|
|
@@ -75,6 +75,8 @@ function t(zh, en) {
|
|
|
75
75
|
// ---- 插件自身的版本与更新源 ----
|
|
76
76
|
// 插件目录就是 index.js 所在目录(apply 会把它部署成 <AppRoot>\dsh-config-sync-plugin-<ver>\)。
|
|
77
77
|
const PLUGIN_DIR = dirname(fileURLToPath(import.meta.url))
|
|
78
|
+
// pluginRoot()/pluginVersion() 是历史调用点保留的同义包装,统一回到这一份定义,避免三处口径漂移。
|
|
79
|
+
function pluginRoot() { return PLUGIN_DIR }
|
|
78
80
|
const PLUGIN_VERSION = (() => {
|
|
79
81
|
try {
|
|
80
82
|
const pkg = JSON.parse(readFileSync(join(PLUGIN_DIR, 'package.json'), 'utf8'))
|
|
@@ -452,12 +454,8 @@ function runGit(args, env, timeout = 20000) {
|
|
|
452
454
|
})
|
|
453
455
|
}
|
|
454
456
|
|
|
455
|
-
function lsRemoteHeads(url, settings) {
|
|
456
|
-
return probeRemote(url, settings).then((p) => (p ? p.heads : null))
|
|
457
|
-
}
|
|
458
|
-
|
|
459
457
|
/** 临时 bare 仓库里数一次远端某个分支的文件数;失败返回 null。 */
|
|
460
|
-
async function remoteFileCount(url, settings
|
|
458
|
+
async function remoteFileCount(url, settings) {
|
|
461
459
|
const env = gitProbeEnv(settings)
|
|
462
460
|
let dir = ''
|
|
463
461
|
try {
|
|
@@ -492,7 +490,7 @@ async function probeRemote(url, settings) {
|
|
|
492
490
|
let value = null
|
|
493
491
|
if (heads === null) value = { heads: null, files: null }
|
|
494
492
|
else if (heads === 0) value = { heads: 0, files: 0 }
|
|
495
|
-
else value = { heads, files: await remoteFileCount(url, settings
|
|
493
|
+
else value = { heads, files: await remoteFileCount(url, settings) }
|
|
496
494
|
remoteProbeCache.set(url, { at: Date.now(), value })
|
|
497
495
|
return value
|
|
498
496
|
}
|
|
@@ -935,6 +933,19 @@ function repoPhase(dir) {
|
|
|
935
933
|
return others.length === 0 ? 'empty' : 'unusable'
|
|
936
934
|
}
|
|
937
935
|
|
|
936
|
+
/**
|
|
937
|
+
* 仓库三态 → 推送/拉取门禁的唯一判据来源(面板 inspect 与后端自动同步共用口径)。
|
|
938
|
+
* phase: ok=真仓库 / empty=空目录 / missing=未建 / unusable=填错路径。
|
|
939
|
+
* remoteFiles: 云端分支树文件数,0=空、null=判不了。
|
|
940
|
+
* 注:判据与 0.4.10 原实现逐字一致,抽取只为消除三处重复,不改变任何放行行为。
|
|
941
|
+
*/
|
|
942
|
+
function canPush(phase, remoteFiles) {
|
|
943
|
+
return phase === 'ok' || (phase === 'empty' && remoteFiles === 0)
|
|
944
|
+
}
|
|
945
|
+
function canPull(phase, remoteFiles) {
|
|
946
|
+
return phase === 'ok' || ((phase === 'empty' || phase === 'missing') && remoteFiles !== 0)
|
|
947
|
+
}
|
|
948
|
+
|
|
938
949
|
/**
|
|
939
950
|
* 体检。全部只读,不写任何文件(除了 prepare 那次由用户显式触发的 cmd 生成)。
|
|
940
951
|
*/
|
|
@@ -1051,10 +1062,12 @@ async function inspect(config) {
|
|
|
1051
1062
|
`Cannot read the client version (${appRoot ? `${appRoot}\\resources\\app\\package.json or resources\\app.asar` : 'AppRoot not found'})`,
|
|
1052
1063
|
))
|
|
1053
1064
|
}
|
|
1065
|
+
// 0.4.10 起:本机/契约版本不同只是提示信息,不再当作「要处理的问题」——拉取不再因版本不一致被阻断。
|
|
1066
|
+
// version 字段仍带 local/contract/match,仅供面板左上角的「本机 / 契约」信息条展示,不构成待办。
|
|
1054
1067
|
if (localVersion && contractVersion && !versionMatch) {
|
|
1055
1068
|
advice.push(t(
|
|
1056
|
-
|
|
1057
|
-
`
|
|
1069
|
+
`本机与仓库客户端版本不同(本机 ${localVersion},契约 ${contractVersion}):0.4.10 起不影响拉取,配置照常同步(实验性 bundle 会剔除)`,
|
|
1070
|
+
`Local and repo client versions differ (local ${localVersion}, contract ${contractVersion}): since 0.4.10 this no longer blocks pull — configs sync as usual (experimental bundles are dropped).`,
|
|
1058
1071
|
))
|
|
1059
1072
|
}
|
|
1060
1073
|
if (unresolved.length) {
|
|
@@ -1110,9 +1123,9 @@ async function inspect(config) {
|
|
|
1110
1123
|
? 'ok'
|
|
1111
1124
|
: (remoteFiles === 0 ? 'await-init' : 'await-pull'),
|
|
1112
1125
|
// 推送:真仓库,或「空目录 + 云端确实没文件」的首次推送(判不了时不放行,宁可按老规矩只拉)
|
|
1113
|
-
pushAllowed:
|
|
1126
|
+
pushAllowed: canPush(phase, remoteFiles),
|
|
1114
1127
|
// 拉取:真仓库,或空目录/没建目录且云端确实有文件(sync.ps1 的 Initialize-RepoIfNeeded 会自动 init + fetch + checkout)
|
|
1115
|
-
pullAllowed:
|
|
1128
|
+
pullAllowed: canPull(phase, remoteFiles),
|
|
1116
1129
|
// 路径是怎么来的:settings=本机设置(面板可改)、config=插件配置、env=环境变量、auto=自动探测、none=没配
|
|
1117
1130
|
source: resolved.source,
|
|
1118
1131
|
configured: Boolean(settings.repoPath || config?.repoPath),
|
|
@@ -1286,10 +1299,6 @@ function pickPs1(repo, name) {
|
|
|
1286
1299
|
))
|
|
1287
1300
|
}
|
|
1288
1301
|
|
|
1289
|
-
function pluginRoot() {
|
|
1290
|
-
try { return dirname(fileURLToPath(import.meta.url)) } catch { return '' }
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
1302
|
function buildCmd(config, action, repo, appRoot, dshHome, state = {}) {
|
|
1294
1303
|
const isRestore = action === 'restore' || action === 'restore-backup'
|
|
1295
1304
|
const restorePs1 = isRestore ? pickPs1(repo, 'restore.ps1') : ''
|
|
@@ -1747,13 +1756,14 @@ function electronApp() {
|
|
|
1747
1756
|
}
|
|
1748
1757
|
|
|
1749
1758
|
/**
|
|
1750
|
-
*
|
|
1751
|
-
*
|
|
1752
|
-
* 旧实现是 `taskkill /PID <主进程>`(不带 /F):对 Electron 主进程无效 ——
|
|
1753
|
-
* 主进程没有自己的顶层窗口,实测直接报 "This process can only be terminated forcefully",
|
|
1754
|
-
* 于是「确认后自动退出 DSH」根本不生效,守护进程只能干等到 30 分钟超时。
|
|
1759
|
+
* 请求客户端退出(手动「立即推送/拉取/还原」排队后走这条)。
|
|
1755
1760
|
*
|
|
1756
|
-
*
|
|
1761
|
+
* 实现顺序(注释与实现保持一致,勿再写成「优先 app.quit」):
|
|
1762
|
+
* 1) 先按映像名发一次礼貌关闭 taskkill /IM(不带 /F),让 Electron 走正常关闭流程;
|
|
1763
|
+
* 2) 3.5 秒后 /F 强杀残留进程族(插件跑在子进程里,只杀 process.pid 杀不干净);
|
|
1764
|
+
* 3) 拿到 electron 句柄时另发一次 app.quit()(走 before-quit 落盘)。
|
|
1765
|
+
* 返回 true 表示「已发起退出请求」,不代表进程已确认退出(spawn 结果无法同步取得)。
|
|
1766
|
+
* 退出后自动同步那条链路用 forceCloseDshDetached(独立进程延迟强杀),不要混用。
|
|
1757
1767
|
*/
|
|
1758
1768
|
function closeDsh() {
|
|
1759
1769
|
const exe = join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'taskkill.exe')
|
|
@@ -1786,8 +1796,17 @@ function closeDsh() {
|
|
|
1786
1796
|
* 用 cmd /c + ping 做秒级延时(timeout.exe 在无控制台的非交互进程里会报错),
|
|
1787
1797
|
* 先给点 × 触发的正常关闭流程一点时间落盘,再 /F 兜底残留进程。
|
|
1788
1798
|
*/
|
|
1799
|
+
let _forceCloseLastAt = 0
|
|
1789
1800
|
function forceCloseDshDetached(config) {
|
|
1790
1801
|
const dshHome = config?.dshHome || process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
1802
|
+
// 幂等:同一次退出事件里「窗口关闭 / 信标 / 定时预排」三处入口可能接连触发,
|
|
1803
|
+
// 1.5s 内只发一次独立强杀,避免重复 spawn。每次都是杀同一进程族,最终状态一致。
|
|
1804
|
+
const _now = Date.now()
|
|
1805
|
+
if (_now - _forceCloseLastAt < 1500) {
|
|
1806
|
+
logLaunch(dshHome, 'auto-exit:1.5s 内已发起过强杀,本次幂等跳过(同一进程族)')
|
|
1807
|
+
return true
|
|
1808
|
+
}
|
|
1809
|
+
_forceCloseLastAt = _now
|
|
1791
1810
|
const sys = process.env.SystemRoot || 'C:\\Windows'
|
|
1792
1811
|
const cmd = join(sys, 'System32', 'cmd.exe')
|
|
1793
1812
|
const taskkill = join(sys, 'System32', 'taskkill.exe')
|
|
@@ -2909,8 +2928,8 @@ function writeScope(dshHome, scope) {
|
|
|
2909
2928
|
}
|
|
2910
2929
|
|
|
2911
2930
|
// 必需组:不许取消勾选 —— 因为不勾就会报错,而不是"少同步一点"。
|
|
2912
|
-
// profile 里的 package.json / cordis.patch.yml 是 apply 的前置条件(仓库里缺它们 apply.ps1 直接 Die
|
|
2913
|
-
// host-contract.json
|
|
2931
|
+
// profile 里的 package.json / cordis.patch.yml 是 apply 的前置条件(仓库里缺它们 apply.ps1 直接 Die)。
|
|
2932
|
+
// host-contract.json 自 0.4.10 起只用于「本机/契约」信息条展示,版本不同不再阻断拉取。
|
|
2914
2933
|
const SCOPE_REQUIRED_GROUPS = ['profile']
|
|
2915
2934
|
function scopeGroupRequired(id) { return SCOPE_REQUIRED_GROUPS.includes(id) }
|
|
2916
2935
|
|
|
@@ -3662,13 +3681,15 @@ async function handleAuto(req, res, config) {
|
|
|
3662
3681
|
/** 核心判断逻辑:给定配置与仓库,判断是否需要自动拉取/推送,需要则排队 watcher(可选关闭 DSH)。
|
|
3663
3682
|
* 供 scheduleAutoStart(定时)、triggerAutoSyncOnClose(关闭钩子)、handleSettings(开关即时触发)复用。 */
|
|
3664
3683
|
async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, options = {}) {
|
|
3665
|
-
const { skipConfirm = false, isManualTrigger = false, shouldCloseDsh = true, isPeriodic = false } = options
|
|
3684
|
+
const { skipConfirm = false, isManualTrigger = false, shouldCloseDsh = true, isPeriodic = false, driftOverride = null } = options
|
|
3666
3685
|
// 已经排队等退出了就别重复拉起 watcher;但 watcher 已死(超时退出)时允许重排
|
|
3667
3686
|
if (autoState.pending && isProcessAlive(autoState.pending.watcherPid)) return { queued: false, reason: 'already_pending' }
|
|
3668
3687
|
if (!repo || !isDir(join(repo, '.git'))) {
|
|
3669
3688
|
return { queued: false, reason: 'no_repo' }
|
|
3670
3689
|
}
|
|
3671
|
-
|
|
3690
|
+
// 定时复查已在同一次 run 里 checkDrift 过(结果写进 autoState.drift),经 driftOverride 复用,
|
|
3691
|
+
// 避免几毫秒内对同一仓库重复 git fetch。未传时行为与原来完全一致(自行 fetch)。
|
|
3692
|
+
const drift = driftOverride || await checkDrift(repo)
|
|
3672
3693
|
if (!drift) {
|
|
3673
3694
|
return { queued: false, reason: 'drift_failed' }
|
|
3674
3695
|
}
|
|
@@ -3718,6 +3739,7 @@ async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, o
|
|
|
3718
3739
|
const restart = settings.autoRestart !== false
|
|
3719
3740
|
const started = await spawnWatcher({ mode: 'push', repo, appRoot, dshHome, restart })
|
|
3720
3741
|
if (started.ok) {
|
|
3742
|
+
// reason=旧版兜底文案,reasonZh/reasonEn=双语文案(前端按语言优先读双语、reason 兜底),三者是不同键,勿合并
|
|
3721
3743
|
autoState.pending = { mode: 'push', at: Date.now(), reason: reasonZh, reasonZh, reasonEn, restart, watcherPid: started.pid, closeRequested: false }
|
|
3722
3744
|
if (shouldCloseDsh) closeDsh()
|
|
3723
3745
|
return { queued: true, mode: 'push', reason: reasonZh }
|
|
@@ -3761,7 +3783,8 @@ function scheduleAutoStart(config) {
|
|
|
3761
3783
|
// (shouldCloseDsh:false)。用户点 × 关闭 DSH 后,预排的 watcher 自动进入 run 执行。
|
|
3762
3784
|
// 前端信标仍保留作双保险:它若送达、发现已排队会直接复用,不会重复。
|
|
3763
3785
|
const appRoot = resolveAppRoot(config?.appRoot) || ''
|
|
3764
|
-
|
|
3786
|
+
// 复用本次复查刚 fetch 的 drift,避免 checkAndQueueAutoSync 内二次 fetch(同一仓库、同一时刻)
|
|
3787
|
+
await checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, { shouldCloseDsh: false, isPeriodic: true, driftOverride: drift })
|
|
3765
3788
|
} catch (error) {
|
|
3766
3789
|
autoState.checking = false
|
|
3767
3790
|
autoState.lastCheckAt = Date.now()
|
|
@@ -3805,6 +3828,8 @@ async function triggerAutoSyncOnClose(config, options = {}) {
|
|
|
3805
3828
|
const phase = repoPhase(repo)
|
|
3806
3829
|
|
|
3807
3830
|
// 本机仓库还没内容:autoPull 可以直接排队(sync.ps1 首次 clone),autoPush 不行(要先确认云端为空)
|
|
3831
|
+
// 注:关闭走的 fast 路径不探测 remoteFiles,这里沿用原 phase === 'empty' 判据;
|
|
3832
|
+
// inspect() 面板门禁已收敛到 canPull()(见文件上方),口径一致但此路径不额外 fetch,行为保持不变。
|
|
3808
3833
|
if (phase !== 'ok') {
|
|
3809
3834
|
if (settings.autoPull && phase === 'empty') {
|
|
3810
3835
|
const restart = settings.autoRestart !== false
|
|
@@ -4327,13 +4352,8 @@ async function handleRoots(req, res, config) {
|
|
|
4327
4352
|
const GH_DEFAULT_REPO = 'QcWyGm/dsh-config-sync-plugin'
|
|
4328
4353
|
const GH_FEEDBACK_LABEL = 'feedback'
|
|
4329
4354
|
|
|
4330
|
-
/**
|
|
4331
|
-
function pluginVersion() {
|
|
4332
|
-
try {
|
|
4333
|
-
const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'package.json'), 'utf8'))
|
|
4334
|
-
return String(pkg.version || '')
|
|
4335
|
-
} catch { return '' }
|
|
4336
|
-
}
|
|
4355
|
+
/** 当前插件版本(同义包装,统一回到 PLUGIN_VERSION 这一份定义)。 */
|
|
4356
|
+
function pluginVersion() { return PLUGIN_VERSION }
|
|
4337
4357
|
|
|
4338
4358
|
function ghPathOf(dshHome) { return join(dshHome, 'config-sync-gh.json') }
|
|
4339
4359
|
function outboxPathOf(dshHome) { return join(dshHome, 'config-sync-feedback-outbox.json') }
|
package/package.json
CHANGED
package/runtime/apply.ps1
CHANGED
|
@@ -48,6 +48,7 @@ param(
|
|
|
48
48
|
[switch]$SkipWorkspace,
|
|
49
49
|
[switch]$PruneWorkspace,
|
|
50
50
|
[switch]$ReplaceWorkspaceRegistry,
|
|
51
|
+
# 已废弃:0.4.10 起默认放行版本差异,此开关不参与判据,仅为兼容旧调用保留
|
|
51
52
|
[switch]$AllowVersionDrift,
|
|
52
53
|
[switch]$ForceBundles,
|
|
53
54
|
[string]$WorkspaceHome = $(Join-Path $env:USERPROFILE 'Documents\deepseek-harness'),
|
|
@@ -404,6 +405,7 @@ function Sync-WorkspaceApply {
|
|
|
404
405
|
# sessions\ 一级目录名 = Get-SessionDirName(工作区绝对路径)。编码不可逆,所以 capture
|
|
405
406
|
# 在 conversations\session-index.json 里记了「目录名 ↔ 工作区 ID」;apply 按本机
|
|
406
407
|
# -AppRoot / -WorkspaceHome 展开后的路径重新编码目录名,B 机才能认出这些会话。
|
|
408
|
+
# 与另一文件同名函数保持一致,修改需同步
|
|
407
409
|
function Get-SessionDirName([string]$path) {
|
|
408
410
|
$sb = New-Object System.Text.StringBuilder
|
|
409
411
|
[void]$sb.Append('--')
|
|
@@ -808,14 +810,12 @@ $settingsMap = @(
|
|
|
808
810
|
@{ Repo = 'settings\workspace-archives.json'; Src = (Join-Path $DshHome 'dsh-session-manager\workspace-archives.v1.json'); Label = 'DSH 工作区隐藏状态' }
|
|
809
811
|
)
|
|
810
812
|
|
|
811
|
-
# ---------- 0.5
|
|
812
|
-
#
|
|
813
|
-
#
|
|
814
|
-
#
|
|
815
|
-
#
|
|
816
|
-
#
|
|
817
|
-
# 现在的规则:版本对不上 → 直接拒绝(可显式 -AllowVersionDrift 放行,但实验性 bundle 一律剔除),
|
|
818
|
-
# 拒绝发生在备份、还原、写文件之前。
|
|
813
|
+
# ---------- 0.5 宿主版本契约(只提示、不阻断拉取;0.4.10 起) ----------
|
|
814
|
+
# 0.4.09 及以前:版本对不上直接 Die,pull 必须加 -AllowVersionDrift 才能继续。
|
|
815
|
+
# 0.4.10 起:配置同步拉取不再校验「本机 app / 仓库契约」是否一致——版本不一致只写一条提示,
|
|
816
|
+
# 拉取照常进行(等价于自动带上 -AllowVersionDrift)。版本差异本身不该阻断配置/技能/资料同步。
|
|
817
|
+
# 实验性 bundle(@deepseek-ai/dsh-experimental-*,宿主自带、按版本强绑定)仍按下面的门控剔除,
|
|
818
|
+
# 避免把为别的客户端构建准备的 bundle 铺到本机、启动期 entry loading 崩溃。
|
|
819
819
|
$contractPath = Join-Path $RepoRoot 'profile\host-contract.json'
|
|
820
820
|
$hostAppVersion = Get-HostAppVersion $AppRoot
|
|
821
821
|
$contractVersion = $null
|
|
@@ -824,17 +824,12 @@ if (Test-Path -LiteralPath $contractPath) {
|
|
|
824
824
|
}
|
|
825
825
|
$versionDrift = $false
|
|
826
826
|
if (-not $hostAppVersion) {
|
|
827
|
-
Warn "读不到客户端 app 版本($AppRoot\resources\app\package.json 与 resources\app.asar
|
|
827
|
+
Warn "读不到客户端 app 版本($AppRoot\resources\app\package.json 与 resources\app.asar 都没读到)——跳过版本提示,拉取照常进行"
|
|
828
828
|
} elseif (-not $contractVersion) {
|
|
829
|
-
Warn "仓库缺少 profile\host-contract.json(或里面没有 appVersion
|
|
829
|
+
Warn "仓库缺少 profile\host-contract.json(或里面没有 appVersion)——跳过版本提示,拉取照常进行"
|
|
830
830
|
} elseif ($hostAppVersion -ne $contractVersion) {
|
|
831
831
|
$versionDrift = $true
|
|
832
|
-
Warn "宿主版本不一致:本机 app = $hostAppVersion,仓库契约 = $contractVersion"
|
|
833
|
-
if (-not $AllowVersionDrift) {
|
|
834
|
-
Die ("两端客户端不是同一版,未改动任何文件。请先把两台升到同一版;" +
|
|
835
|
-
"或加 -AllowVersionDrift 只同步配置/技能/资料(会剔除全部实验性 bundle,避免启动期崩溃)。")
|
|
836
|
-
}
|
|
837
|
-
Warn "已加 -AllowVersionDrift:继续同步,但剔除实验性 bundle"
|
|
832
|
+
Warn "宿主版本不一致:本机 app = $hostAppVersion,仓库契约 = $contractVersion —— 0.4.10 起不再阻断拉取,继续同步(实验性 bundle 会剔除)"
|
|
838
833
|
} else {
|
|
839
834
|
Ok "宿主版本一致(app = $hostAppVersion)"
|
|
840
835
|
}
|
|
@@ -927,7 +922,7 @@ foreach ($b in $bundlesInRepo) {
|
|
|
927
922
|
if ($b -notlike '@deepseek-ai/dsh-experimental-*') { continue }
|
|
928
923
|
$why = $null
|
|
929
924
|
if ($versionDrift) {
|
|
930
|
-
$why = "本机 app 版本不同($hostAppVersion ≠ $contractVersion
|
|
925
|
+
$why = "本机 app 版本不同($hostAppVersion ≠ $contractVersion);仅剔除实验 bundle,不影响主流程"
|
|
931
926
|
} else {
|
|
932
927
|
# 宿主自带 bundle 的落点因构建而异:解包版在 resources\app\dsh\node_modules,
|
|
933
928
|
# 打包版整包塞在 app.asar 里(磁盘上没有目录)——所以交给 Test-HostBundle 统一判断,别只查路径。
|
package/runtime/capture.ps1
CHANGED
|
@@ -310,6 +310,7 @@ function Sync-WorkspaceCapture {
|
|
|
310
310
|
# 绝不做文本替换(zstd 流无法替换;projcache 按 sessionId 索引,cwd 只是历史记录,B 机可读)。
|
|
311
311
|
# sessions\ 一级目录名 = Get-SessionDirName(工作区绝对路径);该编码不可逆,所以 capture 用
|
|
312
312
|
# 「已知工作区路径 → 编码 → 匹配目录名」建 dir ↔ workspaceId 映射,apply 再按本机路径重编码目录名。
|
|
313
|
+
# 与另一文件同名函数保持一致,修改需同步
|
|
313
314
|
function Get-SessionDirName([string]$path) {
|
|
314
315
|
$sb = New-Object System.Text.StringBuilder
|
|
315
316
|
[void]$sb.Append('--')
|
|
@@ -588,7 +589,6 @@ function Sync-ConversationCapture {
|
|
|
588
589
|
# 关键修复(2026-11-10):旧版正则把目录名写死成 DeepSeekHarness,客户端装在 D:\DSH 时归一化整体失效,
|
|
589
590
|
# 本机绝对路径会被原样写进仓库 → 另一台 apply 后 lock 与 package.json 错位 → 安装半装 → 启动崩。
|
|
590
591
|
# 现在先按本机 -AppRoot 的实际路径做字面替换(任意目录名、任意盘符),再用「末级目录名」正则兜底。
|
|
591
|
-
$AppRootPattern = Get-AppRootPattern $AppRoot
|
|
592
592
|
|
|
593
593
|
function Set-AppRootToken([string]$text) {
|
|
594
594
|
return (Convert-AppRootText $text $AppRoot $AppRootToken)
|
|
@@ -712,7 +712,7 @@ function Get-PluginDataFiles([string]$slotDir, $cfg, [string]$baseDir = '') {
|
|
|
712
712
|
|
|
713
713
|
# 必需组:不许取消勾选。理由都是"不勾就报错"这一个事实:
|
|
714
714
|
# profile 里的 package.json / cordis.patch.yml 是 apply 的前置条件 —— 仓库缺它们,apply.ps1 直接 Die;
|
|
715
|
-
# 同一组的 host-contract.json
|
|
715
|
+
# 同一组的 host-contract.json 用于实验 bundle 门控;版本差异不再阻断,只提示,不会因此拒绝铺配置。
|
|
716
716
|
# 所以这里(以及面板)都把 profile 钉死为开启,手改 JSON 关掉也按开启处理。
|
|
717
717
|
$SyncRequiredGroups = @('profile')
|
|
718
718
|
|
package/runtime/restore.ps1
CHANGED
|
@@ -46,35 +46,33 @@ $ProfileDir = Join-Path $DshHome ('profiles\' + $ProfileName)
|
|
|
46
46
|
$ProfileFiles = @('package.json', 'pnpm-lock.yaml', 'pnpm-workspace.yaml', 'cordis.yml', 'cordis.patch.yml')
|
|
47
47
|
$HomeFiles = @('AGENTS.md', 'prompt-inject.md')
|
|
48
48
|
|
|
49
|
-
#
|
|
49
|
+
# 客户端根:优先复用主链路 Resolve-DshAppRoot(显式参数 → $env:DSH_APP_ROOT → 注册表 → 多盘候选);
|
|
50
|
+
# 实在找不到时保留 restore 原有的 D:\DeepSeekHarness 默认路径兜底,避免旧行为报错。
|
|
50
51
|
function Resolve-AppRoot([string]$explicit) {
|
|
51
|
-
$
|
|
52
|
-
if ($
|
|
53
|
-
$cands += @('D:\DeepSeekHarness', 'D:\DSH', 'G:\DSH', 'G:\DeepSeekHarness', 'C:\DeepSeekHarness')
|
|
54
|
-
foreach ($c in $cands) {
|
|
55
|
-
if (Test-Path -LiteralPath (Join-Path $c 'resources\app\package.json')) { return $c }
|
|
56
|
-
}
|
|
52
|
+
$resolved = Resolve-DshAppRoot $explicit
|
|
53
|
+
if ($resolved) { return $resolved }
|
|
57
54
|
if ($explicit) { return $explicit }
|
|
58
55
|
return 'D:\DeepSeekHarness'
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
# git 位置探测统一在 dsh-sync-common.ps1 里(Get-GitExe),restore 允许找不到(只影响 pnpm 安装步骤)
|
|
62
59
|
|
|
63
|
-
# 按 profile\package.json 的 bundles 逐项查能否解析(profile\node_modules
|
|
60
|
+
# 按 profile\package.json 的 bundles 逐项查能否解析(profile\node_modules 优先,再宿主磁盘/asar)
|
|
61
|
+
# 宿主侧统一交给 Test-HostBundle:它同时查 resources\app\dsh\node_modules 与 resources\app.asar,
|
|
62
|
+
# 打包版宿主不再因为 asar 里的 bundle 被误报为缺失。
|
|
64
63
|
function Get-UnresolvedBundles {
|
|
65
64
|
$missing = New-Object System.Collections.ArrayList
|
|
66
65
|
$pkgPath = Join-Path $ProfileDir 'package.json'
|
|
67
66
|
if (-not (Test-Path -LiteralPath $pkgPath)) { return $missing }
|
|
68
67
|
try { $pkg = Get-Content -LiteralPath $pkgPath -Raw -Encoding utf8 | ConvertFrom-Json } catch { return $missing }
|
|
69
68
|
$bundles = @($pkg.dsh.profile.bundles)
|
|
70
|
-
$
|
|
69
|
+
$profileModules = Join-Path $ProfileDir 'node_modules'
|
|
71
70
|
foreach ($b in $bundles) {
|
|
72
71
|
if ([string]::IsNullOrWhiteSpace($b)) { continue }
|
|
73
72
|
$rel = [string]($b -replace '/', '\')
|
|
74
73
|
$found = $false
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
74
|
+
if (Test-Path -LiteralPath (Join-Path $profileModules (Join-Path $rel 'package.json'))) { $found = $true }
|
|
75
|
+
if (-not $found -and (Test-HostBundle $AppRoot $b)) { $found = $true }
|
|
78
76
|
if (-not $found) { [void]$missing.Add($b) }
|
|
79
77
|
}
|
|
80
78
|
return $missing
|
|
@@ -501,7 +499,7 @@ if (Test-Path -LiteralPath $contractPath) {
|
|
|
501
499
|
}
|
|
502
500
|
Say " 本机 app 版本:$localVer;仓库契约:$contractVer"
|
|
503
501
|
if ($localVer -and $contractVer -and $localVer -ne $contractVer) {
|
|
504
|
-
Warn "两端版本不一致:本机 $localVer,仓库契约 $contractVer
|
|
502
|
+
Warn "两端版本不一致:本机 $localVer,仓库契约 $contractVer。0.4.10 起 pull 会放行版本差异,仅实验 bundle 按契约剔除;如需完全一致请升级本机。"
|
|
505
503
|
}
|
|
506
504
|
|
|
507
505
|
$missing = @(Get-UnresolvedBundles)
|
package/runtime/sync.ps1
CHANGED
|
@@ -8,7 +8,7 @@ DSH 配置同步 —— 一条命令入口(把原来的「capture + git add +
|
|
|
8
8
|
|
|
9
9
|
pwsh -File sync.ps1 push -AppRoot "D:\DSH" # 客户端不在默认目录时必须显式传(两个子脚本都会收到)
|
|
10
10
|
pwsh -File sync.ps1 push -Message "加了 xx 插件" # 自定义提交信息(默认自动生成带机器名和时间)
|
|
11
|
-
pwsh -File sync.ps1 pull -AllowVersionDrift #
|
|
11
|
+
pwsh -File sync.ps1 pull -AllowVersionDrift # 兼容旧开关:0.4.10 起版本不一致本就默认放行(仍剔除实验性 bundle)
|
|
12
12
|
pwsh -File sync.ps1 push -WorkspaceOnly # 只推工作区/会话
|
|
13
13
|
pwsh -File sync.ps1 pull -SkipInstall # 只铺配置,不跑 pnpm install
|
|
14
14
|
pwsh -File sync.ps1 push -DeepVerify # 文件比较强制全量算哈希(默认大小+mtime 快筛)
|
|
@@ -16,7 +16,7 @@ DSH 配置同步 —— 一条命令入口(把原来的「capture + git add +
|
|
|
16
16
|
|
|
17
17
|
设计要点
|
|
18
18
|
- push 先跑 capture.ps1(本机 → 仓库),再 git add -A / commit / push,任何一步失败就停,不会带着半截状态继续。
|
|
19
|
-
- pull 先 fetch 再 merge --ff-only(等价于 pull --ff-only,但只付一次网络往返;有本地改动或冲突会直接失败,不去猜怎么合并),再跑 apply.ps1
|
|
19
|
+
- pull 先 fetch 再 merge --ff-only(等价于 pull --ff-only,但只付一次网络往返;有本地改动或冲突会直接失败,不去猜怎么合并),再跑 apply.ps1(0.4.10 起版本契约只提示、不阻断拉取,实验性 bundle 仍按门控剔除)。
|
|
20
20
|
- 不动选项语义:所有开关原样透传给 capture.ps1 / apply.ps1,两个脚本仍可单独调用。
|
|
21
21
|
#>
|
|
22
22
|
param(
|
|
@@ -32,6 +32,7 @@ param(
|
|
|
32
32
|
[switch]$WorkspaceOnly,
|
|
33
33
|
[switch]$SkipWorkspace,
|
|
34
34
|
[switch]$SkipInstall,
|
|
35
|
+
# 已废弃:0.4.10 起默认放行版本差异,此开关不参与判据,仅为兼容旧调用保留
|
|
35
36
|
[switch]$AllowVersionDrift,
|
|
36
37
|
# 推送前强制全量重扫历史里的超大文件(默认只在首次或推送被拒时才扫,省 20s)
|
|
37
38
|
[switch]$ScanHistory,
|
|
@@ -470,7 +471,7 @@ if ($Action -eq 'status') {
|
|
|
470
471
|
}
|
|
471
472
|
if ($app -and $contract) {
|
|
472
473
|
if ($app -eq $contract) { Ok "版本一致:app = $app" }
|
|
473
|
-
else { Warn "
|
|
474
|
+
else { Warn "版本不一致(仅提示,不阻断拉取):本机 app = $app,仓库契约 = $contract —— 0.4.10 起照常同步" }
|
|
474
475
|
} else {
|
|
475
476
|
Warn ("版本信息不全:本机 app = {0},仓库契约 = {1}" -f $app, $contract)
|
|
476
477
|
}
|
|
@@ -567,7 +568,7 @@ function Get-RemoteFileCount([string]$RemoteUrl, [int]$Heads = -2) {
|
|
|
567
568
|
初始化推送:本机空目录 + 云端空仓库,把本机配置当作仓库的初始内容推上去。
|
|
568
569
|
骨架要一起带进仓库 —— 历史仓库本来就有 apply.ps1 / capture.ps1 / dsh-sync-common.ps1 这几份副本,
|
|
569
570
|
少拷了它们,远端就变成「只有 settings 没有执行体」的半截仓库,另一台 pull 下来跑不起来。
|
|
570
|
-
profile\host-contract.json 用本机客户端版本生成(apply
|
|
571
|
+
profile\host-contract.json 用本机客户端版本生成(apply 仅用于实验 bundle 门控;版本差异不再阻断,只提示)。
|
|
571
572
|
#>
|
|
572
573
|
function Initialize-EmptyRepo([string]$RemoteUrl) {
|
|
573
574
|
if (-not $RemoteUrl) {
|
|
@@ -1109,6 +1110,7 @@ $applyArgs = @{ RepoRoot = $RepoRoot; DshHome = $DshHome; ProfileName = $Profile
|
|
|
1109
1110
|
if ($WorkspaceOnly) { $applyArgs['WorkspaceOnly'] = $true }
|
|
1110
1111
|
if ($SkipWorkspace) { $applyArgs['SkipWorkspace'] = $true }
|
|
1111
1112
|
if ($SkipInstall) { $applyArgs['SkipInstall'] = $true }
|
|
1113
|
+
# AllowVersionDrift 已废弃;apply.ps1 从 0.4.10 起忽略版本差异门控,这里仅为兼容旧调用继续透传
|
|
1112
1114
|
if ($AllowVersionDrift) { $applyArgs['AllowVersionDrift'] = $true }
|
|
1113
1115
|
if ($Force) { $applyArgs['Force'] = $true }
|
|
1114
1116
|
& (Join-Path $PSScriptRoot 'apply.ps1') @applyArgs
|
package/tools/clientcheck.mjs
CHANGED
|
@@ -122,9 +122,10 @@ check('设置摘要行展开时 fetch 远端再刷新(远端信息不陈旧)
|
|
|
122
122
|
&& source.includes("callAuto({ action: 'check' })")
|
|
123
123
|
&& source.includes('setInterval(refreshRemoteNow, 30000)')
|
|
124
124
|
&& source.includes('onClick: refreshRemoteNow'))
|
|
125
|
+
// 0.4.11 等价重构:dirty/uncommitted 读取口径统一抽成 uncommittedOf() helper
|
|
125
126
|
check('远端「未提交」纳入本机待同步、刷新按钮触发 fetch(0.3.92)',
|
|
126
|
-
source.includes('repo
|
|
127
|
-
&& source.includes('data.repo
|
|
127
|
+
source.includes('const uncommittedOf = (repo) => (repo?.uncommitted ?? repo?.dirty ?? 0)')
|
|
128
|
+
&& source.includes('uncommittedOf(data.repo)')
|
|
128
129
|
&& source.includes('本机待同步 ${data.repo.pending}'))
|
|
129
130
|
check('设置摘要行两个立即按钮走 pull-now / push-now 队列',
|
|
130
131
|
source.includes("actNow('pull-now')")
|
package/tools/pack-plugin.ps1
CHANGED
|
@@ -40,9 +40,17 @@ try {
|
|
|
40
40
|
$from = Join-Path $RepoRoot $item
|
|
41
41
|
if (Test-Path -LiteralPath $from) { Copy-Item -LiteralPath $from -Destination (Join-Path $pkgDir $item) -Recurse }
|
|
42
42
|
}
|
|
43
|
-
# 排除 .git
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
# 排除 .git 与临时/备份目录、文件(避免把仓库对象、历史或 apply.ps1.bak-0410 之类临时备份打进 tgz)
|
|
44
|
+
$excludedDirNames = @('.git', '_stage-*', '_v4*', '_refactor-*', '_local-backup-*', '_pre-sync-*')
|
|
45
|
+
$excludedFilePatterns = @('*.bak*', '*.tmp')
|
|
46
|
+
Get-ChildItem -LiteralPath $pkgDir -Recurse -Force -ErrorAction SilentlyContinue |
|
|
47
|
+
Where-Object {
|
|
48
|
+
$hitDir = $false
|
|
49
|
+
foreach ($pattern in $excludedDirNames) { if ($_.PSIsContainer -and $_.Name -like $pattern) { $hitDir = $true; break } }
|
|
50
|
+
$hitFile = $false
|
|
51
|
+
foreach ($pattern in $excludedFilePatterns) { if (-not $_.PSIsContainer -and $_.Name -like $pattern) { $hitFile = $true; break } }
|
|
52
|
+
$hitDir -or $hitFile
|
|
53
|
+
} |
|
|
46
54
|
ForEach-Object { Remove-Item -LiteralPath $_.FullName -Recurse -Force -ErrorAction SilentlyContinue }
|
|
47
55
|
# package.json 必须带进包(npm 装包靠它认入口)
|
|
48
56
|
Copy-Item -LiteralPath $pkgFile -Destination (Join-Path $pkgDir 'package.json') -Force
|
package/tools/selftest.mjs
CHANGED
|
@@ -968,9 +968,8 @@ if (pullNote.statusCode === 400) {
|
|
|
968
968
|
}
|
|
969
969
|
|
|
970
970
|
// 配置仓库根目录那 6 个执行体,是「插件还没装 / 正在升级」时的兜底副本。
|
|
971
|
-
//
|
|
972
|
-
//
|
|
973
|
-
// 那条兜底路才会跑到旧逻辑。所以按字节比对,漂了就报,不再指望人记得。
|
|
971
|
+
// 版本不同步时平时不显形,只有 pull 真正走进「仓库副本」那条兜底路才会跑到旧逻辑;
|
|
972
|
+
// 因此按字节比对,漂了就报,不再指望人工记得同步。
|
|
974
973
|
console.log('')
|
|
975
974
|
console.log('== 配置仓库执行体副本一致性 ==')
|
|
976
975
|
const execNames = ['apply.ps1', 'capture.ps1', 'dsh-sync-common.ps1', 'post-exit.ps1', 'restore.ps1', 'sync.ps1']
|
|
@@ -991,7 +990,7 @@ if (!existsSync(repoArg) || !existsSync(pluginRuntime) || !repoReady) {
|
|
|
991
990
|
else if (!existsSync(source)) detail = `插件 runtime 没有 ${name}`
|
|
992
991
|
else {
|
|
993
992
|
same = readFileSync(mirror).equals(readFileSync(source))
|
|
994
|
-
if (!same) detail = `副本 ${readFileSync(mirror).length}B / 正本 ${readFileSync(source).length}B
|
|
993
|
+
if (!same) detail = `副本 ${readFileSync(mirror).length}B / 正本 ${readFileSync(source).length}B,按 runtime/sync.ps1 重新同步执行体副本`
|
|
995
994
|
}
|
|
996
995
|
check(`执行体副本与插件 runtime 逐字节一致:${name}`, same, detail)
|
|
997
996
|
}
|
|
@@ -1000,13 +999,13 @@ if (!existsSync(repoArg) || !existsSync(pluginRuntime) || !repoReady) {
|
|
|
1000
999
|
const sourceTool = join(pluginRuntime, 'tools', 'fix-session-cwd.mjs')
|
|
1001
1000
|
const toolSame = existsSync(mirrorTool) && existsSync(sourceTool) && readFileSync(mirrorTool).equals(readFileSync(sourceTool))
|
|
1002
1001
|
check('执行体副本与插件 runtime 逐字节一致:tools/fix-session-cwd.mjs', toolSame,
|
|
1003
|
-
existsSync(mirrorTool) ? '
|
|
1002
|
+
existsSync(mirrorTool) ? '内容已漂移,按 runtime/sync.ps1 重新同步执行体副本' : '配置仓库没有 tools/fix-session-cwd.mjs')
|
|
1004
1003
|
for (const tname of ['session-log-guard.mjs', 'session-log-lib.mjs', 'bili-state.mjs']) {
|
|
1005
1004
|
const m = join(repoArg, 'tools', tname)
|
|
1006
1005
|
const s = join(pluginRuntime, 'tools', tname)
|
|
1007
1006
|
const ok = existsSync(m) && existsSync(s) && readFileSync(m).equals(readFileSync(s))
|
|
1008
1007
|
check(`执行体副本与插件 runtime 逐字节一致:tools/${tname}`, ok,
|
|
1009
|
-
!existsSync(m) ? `配置仓库没有 tools/${tname}` : (existsSync(s) ? '
|
|
1008
|
+
!existsSync(m) ? `配置仓库没有 tools/${tname}` : (existsSync(s) ? '内容已漂移,按 runtime/sync.ps1 重新同步执行体副本' : `插件 runtime 没有 tools/${tname}`))
|
|
1010
1009
|
}
|
|
1011
1010
|
}
|
|
1012
1011
|
|
|
@@ -1048,11 +1047,16 @@ console.log('== 空白本机仓库:只允许拉取 ==')
|
|
|
1048
1047
|
check('只有插件自己生成的 同步-*.cmd 与隐藏项算「空」',
|
|
1049
1048
|
/同步-\[\\s\\S\]\*\\?\.cmd/i.test(indexNew) || /同步-\[/i.test(indexNew),
|
|
1050
1049
|
'empty 判据没有排除 同步-*.cmd:生成过脚本之后就会被误判成 unusable')
|
|
1050
|
+
// 0.4.11 等价重构:门禁判据抽成 canPush()/canPull() 单一来源,内联判据改调用;断言同时覆盖函数定义与调用点
|
|
1051
1051
|
check('status 暴露 phase / remoteFiles / pushAllowed / pullAllowed',
|
|
1052
1052
|
/phase,\s*\n\s*empty: phase === 'empty'/.test(indexNew)
|
|
1053
1053
|
&& /remoteFiles,/.test(indexNew) && /remoteEmpty: remoteFiles === 0/.test(indexNew)
|
|
1054
|
-
&& /pushAllowed: phase === 'ok' \|\| \(phase === 'empty' && remoteFiles === 0\)/.test(indexNew)
|
|
1055
|
-
|
|
1054
|
+
&& (/pushAllowed: phase === 'ok' \|\| \(phase === 'empty' && remoteFiles === 0\)/.test(indexNew)
|
|
1055
|
+
|| (/pushAllowed: canPush\(phase, remoteFiles\)/.test(indexNew)
|
|
1056
|
+
&& /function canPush\(phase, remoteFiles\)/.test(indexNew)))
|
|
1057
|
+
&& (/pullAllowed: phase === 'ok' \|\| \(\(phase === 'empty' \|\| phase === 'missing'\) && remoteFiles !== 0\)/.test(indexNew)
|
|
1058
|
+
|| (/pullAllowed: canPull\(phase, remoteFiles\)/.test(indexNew)
|
|
1059
|
+
&& /function canPull\(phase, remoteFiles\)/.test(indexNew))),
|
|
1056
1060
|
'status 没有暴露新门禁字段(remoteFiles / pushAllowed / pullAllowed),面板只能靠分支数猜')
|
|
1057
1061
|
check('仓库三态 mode(ok / await-pull / await-init)按文件数算',
|
|
1058
1062
|
/mode: phase === 'ok'[\s\S]{0,120}?remoteFiles === 0 \? 'await-init' : 'await-pull'/.test(indexNew),
|
|
@@ -1972,8 +1976,9 @@ console.log('')
|
|
|
1972
1976
|
console.log('== 0.4.05:定时复查预排 watcher,不依赖前端信标 ==')
|
|
1973
1977
|
{
|
|
1974
1978
|
const idxSrc = readFileSync(join(pluginRootSelf, 'index.js'), 'utf8')
|
|
1979
|
+
// 0.4.11 等价重构:调用点新增 driftOverride 复用本次复查的 drift,核心参数不变
|
|
1975
1980
|
check('scheduleAutoStart 的 run 调用 checkAndQueueAutoSync 预排 watcher',
|
|
1976
|
-
/await checkAndQueueAutoSync\(dshHome, config, settings, repo, appRoot, \{ shouldCloseDsh: false, isPeriodic: true \}\)/.test(idxSrc), 'index.js 定时预排')
|
|
1981
|
+
/await checkAndQueueAutoSync\(dshHome, config, settings, repo, appRoot, \{ shouldCloseDsh: false, isPeriodic: true(?:, driftOverride: drift)? \}\)/.test(idxSrc), 'index.js 定时预排')
|
|
1977
1982
|
check('checkAndQueueAutoSync 支持 isPeriodic 参数',
|
|
1978
1983
|
/isPeriodic = false/.test(idxSrc) && /isManualTrigger/.test(idxSrc), 'index.js isPeriodic 参数')
|
|
1979
1984
|
check('定时复查无人值守不弹确认框',
|
|
@@ -2019,27 +2024,47 @@ console.log('== 0.4.06:点 × 由后端窗口监视触发(不依赖前端信
|
|
|
2019
2024
|
postSrc.includes('$waited -gt 300')
|
|
2020
2025
|
&& postSrc.includes('-and -not $hadVisible'), 'post-exit.ps1 让位收紧')
|
|
2021
2026
|
}
|
|
2022
|
-
|
|
2023
|
-
console.log('')
|
|
2024
|
-
console.log('== 0.4.09:本地提交导致分叉,冲突检测展示处理方式 ==')
|
|
2025
|
-
{
|
|
2026
|
-
const syncSrc = readFileSync(join(pluginRootSelf, 'runtime', 'sync.ps1'), 'utf8')
|
|
2027
|
-
const idxSrc2 = readFileSync(join(pluginRootSelf, 'index.js'), 'utf8')
|
|
2028
|
-
const cliSrc = readFileSync(join(pluginRootSelf, 'client.js'), 'utf8')
|
|
2029
|
-
check('sync.ps1 新增 Get-DivergenceInfo 检测本地提交分叉',
|
|
2030
|
-
syncSrc.includes('function Get-DivergenceInfo') && syncSrc.includes('merge-base --is-ancestor HEAD '), 'sync.ps1 分叉检测')
|
|
2031
|
-
check('sync.ps1 pull 冲突检测阶段调用分叉判断并写入清单',
|
|
2032
|
-
/\$div = Get-DivergenceInfo \$remoteRef/.test(syncSrc) && syncSrc.includes('divergence = $div'), 'sync.ps1 分叉清单')
|
|
2033
|
-
check('sync.ps1 处理方式含保留(rebase)/丢弃(reset)与双机根因',
|
|
2034
|
-
syncSrc.includes('rebase origin/') && syncSrc.includes('reset --hard origin/') && syncSrc.includes('双机同时 push'), 'sync.ps1 处理方式')
|
|
2035
|
-
check('sync.ps1 diff 失败分类把 not possible to fast-forward 单独处理',
|
|
2036
|
-
/not possible to fast-forward\|Not possible to fast-forward\|Diverging branches/.test(syncSrc), 'sync.ps1 分叉分类')
|
|
2037
|
-
check('sync.ps1 备份 README 里展示分叉处理',
|
|
2038
|
-
syncSrc.includes('分支分叉 / Diverged branches') && syncSrc.includes('$Report.divergence'), 'sync.ps1 README 分叉')
|
|
2039
|
-
check('index.js 冲突接口透传 divergence 字段',
|
|
2040
|
-
idxSrc2.includes('divergence: obj.divergence') && idxSrc2.includes('localAhead: Number'), 'index.js divergence 透传')
|
|
2041
|
-
check('client.js 冲突卡展示分叉处理方式',
|
|
2042
|
-
cliSrc.includes('state.divergence ? h(') && cliSrc.includes('本地有提交导致分支分叉'), 'client.js 分叉展示')
|
|
2043
|
-
}
|
|
2027
|
+
|
|
2028
|
+
console.log('')
|
|
2029
|
+
console.log('== 0.4.09:本地提交导致分叉,冲突检测展示处理方式 ==')
|
|
2030
|
+
{
|
|
2031
|
+
const syncSrc = readFileSync(join(pluginRootSelf, 'runtime', 'sync.ps1'), 'utf8')
|
|
2032
|
+
const idxSrc2 = readFileSync(join(pluginRootSelf, 'index.js'), 'utf8')
|
|
2033
|
+
const cliSrc = readFileSync(join(pluginRootSelf, 'client.js'), 'utf8')
|
|
2034
|
+
check('sync.ps1 新增 Get-DivergenceInfo 检测本地提交分叉',
|
|
2035
|
+
syncSrc.includes('function Get-DivergenceInfo') && syncSrc.includes('merge-base --is-ancestor HEAD '), 'sync.ps1 分叉检测')
|
|
2036
|
+
check('sync.ps1 pull 冲突检测阶段调用分叉判断并写入清单',
|
|
2037
|
+
/\$div = Get-DivergenceInfo \$remoteRef/.test(syncSrc) && syncSrc.includes('divergence = $div'), 'sync.ps1 分叉清单')
|
|
2038
|
+
check('sync.ps1 处理方式含保留(rebase)/丢弃(reset)与双机根因',
|
|
2039
|
+
syncSrc.includes('rebase origin/') && syncSrc.includes('reset --hard origin/') && syncSrc.includes('双机同时 push'), 'sync.ps1 处理方式')
|
|
2040
|
+
check('sync.ps1 diff 失败分类把 not possible to fast-forward 单独处理',
|
|
2041
|
+
/not possible to fast-forward\|Not possible to fast-forward\|Diverging branches/.test(syncSrc), 'sync.ps1 分叉分类')
|
|
2042
|
+
check('sync.ps1 备份 README 里展示分叉处理',
|
|
2043
|
+
syncSrc.includes('分支分叉 / Diverged branches') && syncSrc.includes('$Report.divergence'), 'sync.ps1 README 分叉')
|
|
2044
|
+
check('index.js 冲突接口透传 divergence 字段',
|
|
2045
|
+
idxSrc2.includes('divergence: obj.divergence') && idxSrc2.includes('localAhead: Number'), 'index.js divergence 透传')
|
|
2046
|
+
check('client.js 冲突卡展示分叉处理方式',
|
|
2047
|
+
cliSrc.includes('state.divergence ? h(') && cliSrc.includes('本地有提交导致分支分叉'), 'client.js 分叉展示')
|
|
2048
|
+
}
|
|
2049
|
+
console.log('')
|
|
2050
|
+
console.log('== 0.4.10:拉取不再因本机/契约版本不一致而阻断 ==')
|
|
2051
|
+
{
|
|
2052
|
+
const appSrc = readFileSync(join(pluginRuntime, 'apply.ps1'), 'utf8')
|
|
2053
|
+
const syncSrc = readFileSync(join(pluginRootSelf, 'runtime', 'sync.ps1'), 'utf8')
|
|
2054
|
+
const idxSrc = readFileSync(join(pluginRootSelf, 'index.js'), 'utf8')
|
|
2055
|
+
const cliSrc = readFileSync(join(pluginRootSelf, 'client.js'), 'utf8')
|
|
2056
|
+
check('apply.ps1 版本不一致不再 Die 阻断拉取',
|
|
2057
|
+
!/两端客户端不是同一版,未改动任何文件/.test(appSrc)
|
|
2058
|
+
&& appSrc.includes('0.4.10 起不再阻断拉取'), 'apply.ps1 版本不阻断')
|
|
2059
|
+
check('apply.ps1 版本不一致仍保留实验性 bundle 门控',
|
|
2060
|
+
appSrc.includes('实验性 bundle(@deepseek-ai/dsh-experimental-*') && appSrc.includes('$dropped += $b'), 'apply.ps1 bundle 门控保留')
|
|
2061
|
+
check('sync.ps1 status 把版本不一致标为仅提示不阻断',
|
|
2062
|
+
syncSrc.includes('仅提示,不阻断拉取') && syncSrc.includes('0.4.10 起照常同步'), 'sync.ps1 status 提示')
|
|
2063
|
+
check('index.js 版本差异 advice 不再要求 -AllowVersionDrift',
|
|
2064
|
+
idxSrc.includes('0.4.10 起不影响拉取') && !/或 pull 时加 -AllowVersionDrift/.test(idxSrc), 'index.js advice 文案')
|
|
2065
|
+
check('client.js 摘要与指标条不再因版本不一致标告警',
|
|
2066
|
+
!/版本不一致(本机 \$\{version\.local\}/.test(cliSrc)
|
|
2067
|
+
&& cliSrc.includes("metric(M('本机 / 契约', 'App / contract'), versionText, 'ok')"), 'client.js 去告警')
|
|
2068
|
+
}
|
|
2044
2069
|
process.exit(failures === 0 ? 0 : 1)
|
|
2045
2070
|
|