dsh-config-sync-plugin 0.4.18 → 0.4.19

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 CHANGED
@@ -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
+ ### One-way contract adoption + landing hardening (0.4.19)
261
+
262
+ This release fixes five classes of issues found in the full-code audit:
263
+
264
+ - **Contract no longer frozen**: the old "any mismatch keeps the old contract" rule froze `host-contract.json` forever once the app auto-upgraded (stuck on rc.2). Now semver one-way adoption: a newer local machine upgrades the contract; an older one keeps it (anti-downgrade preserved).
265
+ - **Init contract read the wrong version**: on packaged (app.asar) machines, the fallback chain wrote the Electron framework version (e.g. 44.7.0) as appVersion. It now reuses `Get-HostAppVersion` (asar-aware), so any build shape writes the real app version.
266
+ - **Four hard-coded versions removed**: lock fallback, `$cssFallback`, landing probe list, and the 23-entry link directory map are now derived at runtime from the repo `package.json`; releases no longer need manual sync in four places, and `--frozen-lockfile` no longer fails on version drift.
267
+ - **Check the cloud before pushing**: capture's mirror-delete assumes "missing locally = delete in repo"; pushing without pulling first silently deleted the other machine's unique files (sessions/attachments are unrecoverable). Push now fetches and stops when behind>0 (-Force overrides).
268
+ - **WorkspaceOnly race closed**: the branch wrote workspace.json/session first frames/bili DB while DSH ran. The process check now runs before that branch.
269
+
270
+ Also: `git add -A` now goes through cmd forwarding (no NativeCommandError under EAP=Stop); push failure classification adds non-fast-forward ("pull first" guidance); capture cwd normalization uses `Get-HostNodeRunner` (no more `& $null` crash) and `$PID` temp names; notices byKind counts `landing`; panel AutoCard uses callAuto; required-group item checkboxes are disabled in the scope card (they were dead switches).
271
+
260
272
  ### Fix over-strict pull preflight (0.4.18)
261
273
 
262
274
  This release fixes the 0.4.17 preflight false-failure that rolled back pulls on the target machine:
package/README.md CHANGED
@@ -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.19)
281
+
282
+ 本版集中修复通读审计发现的五类问题:
283
+
284
+ - **契约防降级不再冻死**:旧逻辑「本机版本 ≠ 仓库契约就保持不变」让 app 每次 nightly 升级后契约永久冻结在旧版(`host-contract.json` 一直停在 rc.2,实验 bundle 门控对着旧版本判断)。现在按 semver 单向采纳:本机比契约新→升级契约;本机更旧→维持不变(保留防降级意图)。
285
+ - **初始化契约读错版本**:打包版(app.asar)机器做初始化推送时,旧回退链读到的是 Electron 框架版本(44.7.0 之类)写进契约。现在复用 `Get-HostAppVersion` 的正确读取链(asar 手工解析),任何构建形态写入的都是真实 app 版本。
286
+ - **硬编码版本四处脱节**:apply 里 lock 兜底版本、`$cssFallback`、landing 探测名单、23 个 link 目录名映射全部改为从仓库 `package.json` 运行时推导,发新版不再需要手工同步四处,`--frozen-lockfile` 不再因版本错位必挂。
287
+ - **推送前先核对云端**:capture 的镜像删除以「本机没有 = 删仓库」为准,另一台机器刚推过而本机没拉时会静默删掉对方独有的文件(会话/附件不可再生)。现在 push 前先 fetch 并检查 behind>0,领先就停(-Force 可越过)。
288
+ - **WorkspaceOnly 竞态收口**:`-WorkspaceOnly` 分支原来绕过 DSH 运行检查,会和运行中的客户端互踩 workspace.json/会话日志/bili 数据库。进程检查现在提到该分支之前。
289
+
290
+ 附带:`git add -A` 改走 cmd 转发(EAP=Stop 下不再被 stderr advice 中断);push 失败分类补 non-fast-forward(双机竞态给出「先拉取」指引);capture 会话头归一执行器统一走 `Get-HostNodeRunner`(无独立 node 时不再 `& $null` 崩溃)并用 `$PID` 命名临时文件;notices byKind 补 `landing` 计数;面板 AutoCard 的 auto 请求统一走 callAuto;同步内容卡必需组单项勾选禁用(原本就是死开关)。
291
+
280
292
  ### 修复拉取前置检查过严(0.4.18)
281
293
 
282
294
  本版修复 0.4.17 新增的拉取前置检查在目标机误报失败、导致拉取被回滚的问题:
package/client.js CHANGED
@@ -1830,6 +1830,13 @@ window.__ModuleLoader__.load({
1830
1830
  }
1831
1831
  const toggleItem = (gid, iid) => {
1832
1832
  if (!state || !editing) return
1833
+ const g0 = state.groups.find((x) => x.id === gid)
1834
+ // 0.4.19:必需组的单项勾选是死开关——ps1 侧 Test-SyncItemEnabled 对必需组恒真,
1835
+ // 勾了也不生效,还让用户误以为排除了。直接不让点,并提示为什么。
1836
+ if (g0 && g0.required === true) {
1837
+ setMsg(M('必需组(工作区/会话/profile)的单项不参与排除,始终同步', 'Items in required groups are always synced and cannot be excluded'))
1838
+ return
1839
+ }
1833
1840
  setState({
1834
1841
  ...state,
1835
1842
  groups: state.groups.map((g) => (g.id === gid
@@ -1943,12 +1950,15 @@ window.__ModuleLoader__.load({
1943
1950
  items.map((i) => h('label', {
1944
1951
  style: {
1945
1952
  display: 'flex', gap: '8px', alignItems: 'center', fontSize: '12px',
1946
- cursor: editing ? 'pointer' : 'default', opacity: groupOn ? 1 : 0.6,
1953
+ cursor: editing && g.required !== true ? 'pointer' : 'default', opacity: groupOn ? 1 : 0.6,
1947
1954
  },
1948
1955
  },
1949
1956
  h('input', {
1950
- type: 'checkbox', checked: i.enabled !== false, disabled: busy || !editing,
1951
- title: editing ? '' : M('只读:先点「修改」', 'Read-only: click Edit first'),
1957
+ type: 'checkbox', checked: i.enabled !== false,
1958
+ disabled: busy || !editing || g.required === true,
1959
+ title: g.required === true
1960
+ ? M('必需组内容始终同步', 'Required groups are always synced')
1961
+ : (editing ? '' : M('只读:先点「修改」', 'Read-only: click Edit first')),
1952
1962
  onChange: () => toggleItem(g.id, i.id), style: { flexShrink: 0 },
1953
1963
  }),
1954
1964
  h('span', { style: { wordBreak: 'break-all' } }, i.label),
@@ -1998,14 +2008,8 @@ window.__ModuleLoader__.load({
1998
2008
  const act = async (action, extra) => {
1999
2009
  setBusy(action); setErr(''); setMsg('')
2000
2010
  try {
2001
- const res = await fetch('/config-sync/auto', {
2002
- method: 'POST', cache: 'no-store', credentials: 'same-origin',
2003
- headers: jsonHeaders(),
2004
- body: JSON.stringify({ action, ...(extra || {}) }),
2005
- })
2006
- const text = await res.text()
2007
- const body = text ? JSON.parse(text) : null
2008
- if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
2011
+ // 0.4.19:统一走 callAuto(带 JSON 解析守卫),旧裸 fetch 遇坏响应把 SyntaxError 原样抛进 UI
2012
+ const body = await callAuto({ action, ...(extra || {}) })
2009
2013
  if (action === 'check') {
2010
2014
  const d = body.drift
2011
2015
  setMsg(d
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-config-sync-plugin",
3
- "version": "0.4.18",
3
+ "version": "0.4.19",
4
4
  "type": "module",
5
5
  "description": "在 DSH 设置里查看 dsh-config 仓库与本机的同步状态,并生成退出后执行的 push/pull 脚本。同步动作本身不在应用内执行。面板与文案跟随客户端语言(中文/English)。",
6
6
  "main": "./index.js",
@@ -58,4 +58,4 @@
58
58
  "check": "node --check index.js && node --check client.js",
59
59
  "verify": "node tools/selftest.mjs && node tools/clientcheck.mjs"
60
60
  }
61
- }
61
+ }
package/runtime/apply.ps1 CHANGED
@@ -763,6 +763,16 @@ $stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
763
763
  $BackupDir = Join-Path $DshHome "backups\config-$stamp"
764
764
  New-Item -ItemType Directory -Path $BackupDir -Force | Out-Null
765
765
 
766
+ # ---------- 0. 前置检查 ----------
767
+ # 0.4.19:DSH 进程检查提到 -WorkspaceOnly 分支之前。WorkspaceOnly 同样要写 workspace.json、
768
+ # 重写会话日志首帧(fix-session-cwd)、导入 billion-context 的 index.db(SQLite 无 BUSY 重试)——
769
+ # 运行中的 DSH 退出时会回写这些文件,落地内容被盖/互踩。之前只拦非 WorkspaceOnly 路径,
770
+ # 是一个数据竞态窗口。-Force 仍是显式越过的出口。
771
+ $proc = Get-Process -Name 'DeepSeek Harness' -ErrorAction SilentlyContinue
772
+ if ($proc -and -not $Force) {
773
+ Die "检测到 DeepSeek Harness 仍在运行(PID: $(($proc.Id) -join ','))。请完全退出(含托盘)后重新执行,或加 -Force 强制继续。"
774
+ }
775
+
766
776
  # -WorkspaceOnly:只还原工作区 + 会话(B 机没装 DSH 也能先落地资料),做完直接结束
767
777
  if ($WorkspaceOnly) {
768
778
  if ($SkipWorkspace) { Die "-WorkspaceOnly 与 -SkipWorkspace 不能同时使用" }
@@ -774,11 +784,6 @@ if ($WorkspaceOnly) {
774
784
  return
775
785
  }
776
786
 
777
- # ---------- 0. 前置检查 ----------
778
- $proc = Get-Process -Name 'DeepSeek Harness' -ErrorAction SilentlyContinue
779
- if ($proc -and -not $Force) {
780
- Die "检测到 DeepSeek Harness 仍在运行(PID: $(($proc.Id) -join ','))。请完全退出(含托盘)后重新执行,或加 -Force 强制继续。"
781
- }
782
787
  foreach ($p in @("$RepoRoot\profile\package.json", "$RepoRoot\profile\cordis.patch.yml")) {
783
788
  if (-not (Test-Path -LiteralPath $p)) {
784
789
  if (Test-SyncGroupEnabled $Scope 'profile') { Die "仓库内容不完整,缺少:$p" }
@@ -907,10 +912,17 @@ foreach ($f in @('cordis.yml', 'cordis.patch.yml', 'pnpm-workspace.yaml', 'pnpm-
907
912
  }
908
913
  # 老仓库的 pnpm-lock.yaml 里 dsh-config-sync-plugin 是 link: 写法,与改成 npm 版本的 package.json
909
914
  # 对不上会让 --frozen-lockfile 必失败。这里一并改写成 npm 版本,frozen 直接通过。
915
+ # 0.4.19:目标版本不再硬编码(硬编码会在插件发新版后与 package.json 脱节 → frozen 必挂 →
916
+ # 就地 no-frozen 重写本机 lock)。从仓库 package.json 读 dsh-config-sync-plugin 的实际依赖值。
910
917
  if ($f -eq 'pnpm-lock.yaml' -and $raw -match 'dsh-config-sync-plugin:[\s\S]{0,200}link:') {
911
- $raw = [regex]::Replace($raw, '(dsh-config-sync-plugin:\s*\r?\n\s*specifier:\s*)link:[^\r\n]*', '${1}0.4.15')
912
- $raw = [regex]::Replace($raw, '(dsh-config-sync-plugin:\s*\r?\n\s*specifier:[^\r\n]*\r?\n\s*version:\s*)link:[^\r\n]*', '${1}0.4.15')
913
- Warn 'pnpm-lock.yaml 里 dsh-config-sync-plugin 的 link: 写法已改写为 npm 版本 0.4.15(与 package.json 对齐)'
918
+ if (-not $cssNpmVersion) {
919
+ $cssNpmVersion = $null
920
+ try { $cssNpmVersion = [string]$repoPkgObj.dependencies.'dsh-config-sync-plugin' } catch { $cssNpmVersion = $null }
921
+ if ($cssNpmVersion -like 'link:*' -or -not $cssNpmVersion) { $cssNpmVersion = '0.4.19' }
922
+ }
923
+ $raw = [regex]::Replace($raw, '(dsh-config-sync-plugin:\s*\r?\n\s*specifier:\s*)link:[^\r\n]*', ('${1}' + $cssNpmVersion))
924
+ $raw = [regex]::Replace($raw, '(dsh-config-sync-plugin:\s*\r?\n\s*specifier:[^\r\n]*\r?\n\s*version:\s*)link:[^\r\n]*', ('${1}' + $cssNpmVersion))
925
+ Warn "pnpm-lock.yaml 里 dsh-config-sync-plugin 的 link: 写法已改写为 npm 版本 $cssNpmVersion(与仓库 package.json 对齐)"
914
926
  }
915
927
  Write-TextPreserveBom (Join-Path $ProfileDir $f) $raw
916
928
  }
@@ -923,6 +935,9 @@ $pkgRaw = Expand-AppRoot (Read-TextPreserveBom (Join-Path $RepoRoot 'profile\pac
923
935
  $bundlesInRepo = @()
924
936
  try { $bundlesInRepo = @(($pkgRaw | ConvertFrom-Json).dsh.profile.bundles) }
925
937
  catch { Die "仓库 profile\package.json 不是合法 JSON:$($_.Exception.Message)" }
938
+ # 0.4.19:仓库 package.json 对象供 link:/npm 版本推导复用(lock 改写、$cssFallback、landing 探测)。
939
+ $repoPkgObj = $null
940
+ try { $repoPkgObj = $pkgRaw | ConvertFrom-Json } catch { }
926
941
 
927
942
  $dropped = @()
928
943
  foreach ($b in $bundlesInRepo) {
@@ -960,32 +975,42 @@ try { $finalBundles = @(($pkgRaw | ConvertFrom-Json).dsh.profile.bundles) }
960
975
  catch { Die "剔除实验性 bundle 后 package.json 不再是合法 JSON(请手动核对 profile\package.json)" }
961
976
  if ($dropped.Count -gt 0) { Ok "已剔除 $($dropped.Count) 个实验性 bundle,清单剩 $($finalBundles.Count) 项" }
962
977
 
963
- $localPluginMap = [ordered]@{
964
- 'dsh-our-free-model-2.8.0' = 'dsh-our-free-model'
965
- 'dsh-purge-1.4.0' = 'dsh-purge'
966
- 'dsh-config-sync-plugin-0.3.69' = 'dsh-config-sync-plugin'
967
- 'dsh-config-sync-plugin-0.3.81' = 'dsh-config-sync-plugin'
968
- 'dsh-config-sync-plugin-0.3.80' = 'dsh-config-sync-plugin'
969
- 'dsh-config-sync-plugin-0.3.79' = 'dsh-config-sync-plugin'
970
- 'dsh-config-sync-plugin-0.3.78' = 'dsh-config-sync-plugin'
971
- 'dsh-config-sync-plugin-0.3.77' = 'dsh-config-sync-plugin'
972
- 'dsh-config-sync-plugin-0.3.76' = 'dsh-config-sync-plugin'
973
- 'dsh-config-sync-plugin-0.3.75' = 'dsh-config-sync-plugin'
974
- 'dsh-config-sync-plugin-0.3.74' = 'dsh-config-sync-plugin'
975
- 'dsh-config-sync-plugin-0.3.73' = 'dsh-config-sync-plugin'
976
- 'dsh-config-sync-plugin-0.3.70' = 'dsh-config-sync-plugin'
977
- 'dsh-config-sync-plugin-0.3.68' = 'dsh-config-sync-plugin'
978
- 'dsh-config-sync-plugin-0.3.67' = 'dsh-config-sync-plugin'
979
- 'dsh-config-sync-plugin-0.3.66' = 'dsh-config-sync-plugin'
980
- 'dsh-config-sync-plugin-0.3.65' = 'dsh-config-sync-plugin'
981
- 'dsh-config-sync-plugin-0.3.64' = 'dsh-config-sync-plugin'
982
- 'dsh-config-sync-plugin-0.3.63' = 'dsh-config-sync-plugin'
983
- 'dsh-config-sync-plugin-0.3.62' = 'dsh-config-sync-plugin'
984
- 'dsh-config-sync-plugin-0.3.61' = 'dsh-config-sync-plugin'
985
- 'dsh-config-sync-plugin-0.3.59' = 'dsh-config-sync-plugin'
986
- 'dsh-config-sync-plugin-0.3.58' = 'dsh-config-sync-plugin'
987
- 'dsh-config-sync-plugin-0.3.57' = 'dsh-config-sync-plugin'
988
- 'dsh-config-sync-plugin-0.3.56' = 'dsh-config-sync-plugin'
978
+ # 0.4.19:link: 目录名映射不再手工维护(23 个硬编码目录名每次发版都要同步,漏一个就装不上)。
979
+ # 改为从仓库 package.json 的 dependencies 动态推导:任何 link:<…>/<leaf> 依赖,
980
+ # leaf 就是 AppRoot 下的源码目录名;唯一例外 dsh-config-sync-plugin 走下面的 npm 兜底。
981
+ # 已知包名 → 原始目录名的对照表只在「leaf 与包名不同」时才需要(如 dsh-our-free-model)。
982
+ $localPluginMap = [ordered]@{ }
983
+ try {
984
+ $depNames = @()
985
+ if ($repoPkgObj -and $repoPkgObj.dependencies) { $depNames = @($repoPkgObj.dependencies.PSObject.Properties.Name) }
986
+ foreach ($dn in $depNames) {
987
+ $dv = [string]$repoPkgObj.dependencies.$dn
988
+ if (-not $dv) { continue }
989
+ if ($dv -like 'link:*') {
990
+ # 本机 package.json 里的 link: 写法(占位符已展开为本机路径):leaf 是目录名
991
+ $leaf = [IO.Path]::GetFileName(($dv -replace '^link:', '').TrimEnd('/', '\'))
992
+ if ($leaf -and $leaf -ne $dn) { $localPluginMap[$leaf] = $dn }
993
+ } elseif ($dv -match '(?i)^[^/"'']*[\\/]?([^/"''\\]+)\.(tgz|zip)$') {
994
+ # 归档写法 file:…/dsh-xxx-1.2.3.tgz:解包后目录名是去掉版本号的包名
995
+ $leaf = $Matches[1]
996
+ if ($leaf -and $leaf -ne $dn) { $localPluginMap[$leaf] = $dn }
997
+ }
998
+ }
999
+ } catch { }
1000
+ # 兼容兜底:老仓库既没有 link: 也没有归档写法时(package.json 里只有裸 link:{{APP_ROOT}}/dsh-xxx-1.2.3
1001
+ # 已被上面的 link: 分支覆盖),保留一组历史遗留目录名,防止老仓库漏映射。
1002
+ if ($localPluginMap.Count -eq 0) {
1003
+ foreach ($legacy in @('dsh-our-free-model-2.8.0', 'dsh-purge-1.4.0',
1004
+ 'dsh-config-sync-plugin-0.3.56', 'dsh-config-sync-plugin-0.3.57', 'dsh-config-sync-plugin-0.3.58',
1005
+ 'dsh-config-sync-plugin-0.3.59', 'dsh-config-sync-plugin-0.3.61', 'dsh-config-sync-plugin-0.3.62',
1006
+ 'dsh-config-sync-plugin-0.3.63', 'dsh-config-sync-plugin-0.3.64', 'dsh-config-sync-plugin-0.3.65',
1007
+ 'dsh-config-sync-plugin-0.3.66', 'dsh-config-sync-plugin-0.3.67', 'dsh-config-sync-plugin-0.3.68',
1008
+ 'dsh-config-sync-plugin-0.3.69', 'dsh-config-sync-plugin-0.3.70', 'dsh-config-sync-plugin-0.3.73',
1009
+ 'dsh-config-sync-plugin-0.3.74', 'dsh-config-sync-plugin-0.3.75', 'dsh-config-sync-plugin-0.3.76',
1010
+ 'dsh-config-sync-plugin-0.3.77', 'dsh-config-sync-plugin-0.3.78', 'dsh-config-sync-plugin-0.3.79',
1011
+ 'dsh-config-sync-plugin-0.3.80', 'dsh-config-sync-plugin-0.3.81')) {
1012
+ $localPluginMap[$legacy] = ($legacy -replace '-\d+\.\d+\.\d+$', '')
1013
+ }
989
1014
  }
990
1015
  foreach ($dirName in $localPluginMap.Keys) {
991
1016
  $pattern = 'link:[^"]*' + [regex]::Escape($dirName)
@@ -993,10 +1018,15 @@ foreach ($dirName in $localPluginMap.Keys) {
993
1018
  }
994
1019
  # 兜底:老仓库里 dsh-config-sync-plugin 还是 link:{{APP_ROOT}}/dsh-config-sync-plugin-xxx,
995
1020
  # 目标机 AppRoot 下没有那个源码目录 → pnpm 装不上 → bundle "dsh-config-sync-plugin" 解析失败。
996
- # 该插件已发布到 npm,统一改写成 npm 版本依赖(用仓库契约/已装版本,缺省 0.4.15),
1021
+ # 该插件已发布到 npm,统一改写成 npm 版本依赖(用仓库 package.json 的实际值,缺省 0.4.19),
997
1022
  # 让 pnpm install 从 registry 安装。新仓库 capture 已直接写 npm 版本,这里只兜底老仓库。
998
1023
  if ($pkgRaw -match '"dsh-config-sync-plugin"\s*:\s*"link:') {
999
- $cssFallback = '0.4.15'
1024
+ if (-not $cssNpmVersion) {
1025
+ $cssNpmVersion = $null
1026
+ try { $cssNpmVersion = [string]$repoPkgObj.dependencies.'dsh-config-sync-plugin' } catch { $cssNpmVersion = $null }
1027
+ if ($cssNpmVersion -like 'link:*' -or -not $cssNpmVersion) { $cssNpmVersion = '0.4.19' }
1028
+ }
1029
+ $cssFallback = $cssNpmVersion
1000
1030
  $pkgRaw = [regex]::Replace($pkgRaw, '"dsh-config-sync-plugin"\s*:\s*"link:[^"]*"', ('"dsh-config-sync-plugin": "' + $cssFallback + '"'))
1001
1031
  Warn "package.json 里 dsh-config-sync-plugin 是 link: 开发依赖,已改写为 npm 版本 $cssFallback(本地源码目录在目标机不存在,必须走 npm 安装)"
1002
1032
  }
@@ -1675,17 +1705,23 @@ function Test-PullLanding {
1675
1705
  foreach ($ub in @($unresolved)) {
1676
1706
  Add-SyncNotice -Kind 'landing' -Path $ub -Reason 'bundle 本机不可解析,工作区/会话已落地但相关功能不可用。'
1677
1707
  }
1678
- # 7) 本机 profile 若仍用 link: 指向 AppRoot 下的本地源码目录,那目录必须存在
1708
+ # 7) 本机 profile 若仍用 link: 指向 AppRoot 下的本地源码目录,那目录必须存在。
1709
+ # 0.4.19:不再写死两个插件名——遍历 profile\package.json 全部 link: 依赖,leaf 缺目录就报。
1679
1710
  $localProfilePkg = Join-Path $ProfileDir 'package.json'
1680
1711
  if (Test-Path -LiteralPath $localProfilePkg) {
1681
1712
  try {
1682
1713
  $lp = Get-Content -LiteralPath $localProfilePkg -Raw -Encoding UTF8 | ConvertFrom-Json
1683
- foreach ($d in @('dsh-purge-1.4.0', 'dsh-our-free-model-2.8.0')) {
1684
- $dn = $d -replace '-\d+\.\d+\.\d+$', ''
1685
- $dep = $lp.dependencies.$dn
1686
- if ($dep -and ([string]$dep -like 'link:*') -and -not (Test-Path -LiteralPath (Join-Path $AppRoot $d))) {
1687
- $issues += "link:$d"
1688
- Add-SyncNotice -Kind 'landing' -Path $d -Reason ("本机 profile 用 link: 依赖 " + $dn + ",但 AppRoot 下缺少 " + $d + " 目录。")
1714
+ if ($lp.dependencies) {
1715
+ foreach ($depProp in $lp.dependencies.PSObject.Properties) {
1716
+ $depName = [string]$depProp.Name
1717
+ $depVal = [string]$depProp.Value
1718
+ if ($depVal -notlike 'link:*') { continue }
1719
+ $leaf = [IO.Path]::GetFileName(($depVal -replace '^link:', '').TrimEnd('/', '\'))
1720
+ if (-not $leaf) { continue }
1721
+ if (-not (Test-Path -LiteralPath (Join-Path $AppRoot $leaf))) {
1722
+ $issues += "link:$leaf"
1723
+ Add-SyncNotice -Kind 'landing' -Path $leaf -Reason ("本机 profile 用 link: 依赖 " + $depName + ",但 AppRoot 下缺少 " + $leaf + " 目录。")
1724
+ }
1689
1725
  }
1690
1726
  }
1691
1727
  } catch { }
@@ -564,16 +564,31 @@ function Sync-ConversationCapture {
564
564
  # 对不上工作区的 passthrough 目录不动(那种目录在 B 机本来也认不出)。
565
565
  if ($cwdToken.Count -gt 0) {
566
566
  $spec = [ordered]@{ home = $convDir; dirs = $cwdToken } | ConvertTo-Json -Depth 4 -Compress
567
- $specPath = Join-Path ([IO.Path]::GetTempPath()) ('dsh-repo-cwd-{0}.json' -f $stamp)
567
+ # 0.4.19:临时文件名带 $PID——旧版引用了一个未赋值的 $stamp,所有进程都撞同一个
568
+ # dsh-repo-cwd-.json,两次并发 capture 会互相覆盖 spec/结果文件。
569
+ $specPath = Join-Path ([IO.Path]::GetTempPath()) ('dsh-repo-cwd-' + $PID + '.json')
568
570
  [IO.File]::WriteAllText($specPath, $spec, (New-Object Text.UTF8Encoding($false)))
569
571
  # 辅助脚本优先用「脚本自己旁边」的那份(仓库可能是个刚 clone 下来、还没铺 tools 的副本)
570
572
  $helper = Join-Path $PSScriptRoot 'tools\fix-session-cwd.mjs'
571
573
  if (-not (Test-Path -LiteralPath $helper)) { $helper = Join-Path $RepoRoot 'tools\fix-session-cwd.mjs' }
572
574
  if (Test-Path -LiteralPath $helper) {
573
- $nodeExe = Join-Path $AppRoot 'resources\runtime\primary-runtime\dependencies\node\bin\node.exe'
574
- if (-not (Test-Path -LiteralPath $nodeExe)) { $nodeExe = (Get-Command node -ErrorAction SilentlyContinue).Source }
575
- & $nodeExe $helper $specPath *>&1 | ForEach-Object { if ($_ -and ([string]$_).Trim()) { Say (' ' + ([string]$_).Trim()) } }
576
- if ($LASTEXITCODE -ne 0) { Warn '仓库会话头 cwd 归一时有文件失败(上面有原因),那几个会话可能带着本机路径入库' }
575
+ # 0.4.19:执行器统一走 Get-HostNodeRunner(真 node → Electron ELECTRON_RUN_AS_NODE 兜底)。
576
+ # 旧链路在无独立 node 时拿到 $null 再 & $null,ErrorActionPreference=Stop 下直接把 capture 打死。
577
+ $cwdRunner = Get-HostNodeRunner $AppRoot
578
+ if ($cwdRunner) {
579
+ $cwdPrevEan = $env:ELECTRON_RUN_AS_NODE
580
+ try {
581
+ if ($cwdRunner.Electron) { $env:ELECTRON_RUN_AS_NODE = '1' }
582
+ & $cwdRunner.Exe $helper $specPath *>&1 | ForEach-Object { if ($_ -and ([string]$_).Trim()) { Say (' ' + ([string]$_).Trim()) } }
583
+ } finally {
584
+ if ($cwdRunner.Electron) {
585
+ if ($null -eq $cwdPrevEan) { Remove-Item Env:ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue } else { $env:ELECTRON_RUN_AS_NODE = $cwdPrevEan }
586
+ }
587
+ }
588
+ if ($LASTEXITCODE -ne 0) { Warn '仓库会话头 cwd 归一时有文件失败(上面有原因),那几个会话可能带着本机路径入库' }
589
+ } else {
590
+ Warn '找不到可用的 node/Electron 执行器,跳过仓库会话头归一(仓库里会继续存本机路径)'
591
+ }
577
592
  } else {
578
593
  Warn ('找不到 {0},跳过仓库会话头归一(仓库里会继续存本机路径)' -f $helper)
579
594
  }
@@ -748,7 +763,9 @@ foreach ($f in @('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'cordis.yml', 'cordis.
748
763
 
749
764
  # 1.5) 宿主版本契约:记下本机实测的 app 版本,另一台 apply 时据此比对,版本不一致就不铺实验性 bundle
750
765
  # 只写 appVersion + electronVersion,不写机器名/日期(那两样会让每次 capture 都产生假 diff)。
751
- # 已存在且版本不同 → 只告警不改写,避免「较旧的那台 capture 一次就把契约拉低」。
766
+ # 防降级 + 不冻死(0.4.19):按 semver 单向采纳——本机版本比仓库契约新才改写;本机更旧只告警,
767
+ # 防止「较旧的那台 capture 一次就把契约拉低」。旧策略「只要不等就保持不变」会让 app 每次
768
+ # nightly 升级后契约永久冻结在旧版(apply 的实验 bundle 门控因此一直对着旧版本判断)。
752
769
  $hostAppVersion = Get-HostAppVersion $AppRoot
753
770
  $contractPath = Join-Path $RepoRoot 'profile\host-contract.json'
754
771
  if (-not $hostAppVersion) {
@@ -760,8 +777,18 @@ if (-not $hostAppVersion) {
760
777
  try { $existing = [string](Get-Content -LiteralPath $contractPath -Raw -Encoding utf8 | ConvertFrom-Json).appVersion } catch { $existing = $null }
761
778
  }
762
779
  if ($existing -and ($existing -ne $hostAppVersion)) {
763
- Warn "仓库契约 app = $existing,本机 app = $hostAppVersion(不一致,契约保持不变;对齐后再 capture)"
780
+ $cmp = Compare-Semver $hostAppVersion $existing
781
+ if ($cmp -gt 0) {
782
+ Warn ("仓库契约 app = $existing 落后于本机 $hostAppVersion,按 0.4.19 单向采纳规则升级契约")
783
+ $adoptNewer = $true
784
+ } else {
785
+ Warn "仓库契约 app = $existing,本机 app = $hostAppVersion(本机较旧或无法比较,契约保持不变;防止旧机器拉低契约)"
786
+ $adoptNewer = $false
787
+ }
764
788
  } else {
789
+ $adoptNewer = $true
790
+ }
791
+ if ($adoptNewer) {
765
792
  $norm = $contractText -replace "`r`n", "`n"
766
793
  $now = if (Test-Path -LiteralPath $contractPath) { ([IO.File]::ReadAllText($contractPath) -replace "`r`n", "`n") } else { '' }
767
794
  if ($now -ceq $norm) {
@@ -60,7 +60,7 @@ function Save-SyncNotices {
60
60
  $dir = Split-Path -Parent $p
61
61
  if ($dir -and -not (Test-Path -LiteralPath $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
62
62
  $byKind = [ordered]@{}
63
- foreach ($k in @('too-large', 'history', 'skipped', 'failed', 'plugin-missing', 'context-state')) {
63
+ foreach ($k in @('too-large', 'history', 'skipped', 'failed', 'plugin-missing', 'context-state', 'landing')) {
64
64
  $byKind[$k] = @($script:SyncNoticeItems | Where-Object { $_.kind -eq $k }).Count
65
65
  }
66
66
  $obj = [ordered]@{
@@ -470,6 +470,58 @@ function Get-HostElectronVersion([string]$appRoot) {
470
470
  return (Read-TextPreserveBom $p).Trim()
471
471
  }
472
472
 
473
+ <#
474
+ semver 比较(0.4.19 新增,供 capture 契约单向采纳 / sync 契约生成共用):
475
+ 返回 1 = a 更新,-1 = b 更新,0 = 相等。b 更新但解析失败时返回 0(当作「无法比较」),
476
+ 调用方对 0 一律按「保持现状」处理,保证旧机器永远拉不低契约。
477
+ 支持数字段 + 预发布段(0.2.2-rc.5 > 0.2.2-rc.2 > 0.2.2);不含构建段(+build 忽略)。
478
+ #>
479
+ function Compare-Semver([string]$a, [string]$b) {
480
+ $a = ('' + $a).Trim(); $b = ('' + $b).Trim()
481
+ if ($a -ceq $b) { return 0 }
482
+ $parse = {
483
+ param([string]$v)
484
+ if ($v -notmatch '^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.\-]+))?$') { return $null }
485
+ $pre = $null
486
+ if ($Matches[4]) { $pre = $Matches[4] -split '\.' }
487
+ return [pscustomobject]@{
488
+ Major = [long]$Matches[1]; Minor = [long]$Matches[2]; Patch = [long]$Matches[3]; Pre = $pre
489
+ }
490
+ }
491
+ $pa = & $parse $a
492
+ $pb = & $parse $b
493
+ if (-not $pa -or -not $pb) { return 0 }
494
+ foreach ($f in @('Major', 'Minor', 'Patch')) {
495
+ if ($pa.$f -gt $pb.$f) { return 1 }
496
+ if ($pa.$f -lt $pb.$f) { return -1 }
497
+ }
498
+ # 主版本段相等:无预发布 > 有预发布(semver 规则 11)
499
+ if (-not $pa.Pre -and -not $pb.Pre) { return 0 }
500
+ if (-not $pa.Pre) { return 1 }
501
+ if (-not $pb.Pre) { return -1 }
502
+ $n = [Math]::Min($pa.Pre.Count, $pb.Pre.Count)
503
+ for ($i = 0; $i -lt $n; $i++) {
504
+ $x = $pa.Pre[$i]; $y = $pb.Pre[$i]
505
+ if ($x -ceq $y) { continue }
506
+ $xn = 0L; $yn = 0L
507
+ $xIsNum = [long]::TryParse($x, [ref]$xn)
508
+ $yIsNum = [long]::TryParse($y, [ref]$yn)
509
+ if ($xIsNum -and $yIsNum) {
510
+ if ($xn -gt $yn) { return 1 }
511
+ if ($xn -lt $yn) { return -1 }
512
+ continue
513
+ }
514
+ # 数字段 < 文本段(semver 规则 12)
515
+ if ($xIsNum) { return -1 }
516
+ if ($yIsNum) { return 1 }
517
+ $c = [string]::CompareOrdinal($x, $y)
518
+ if ($c -ne 0) { return [Math]::Sign($c) }
519
+ }
520
+ if ($pa.Pre.Count -gt $pb.Pre.Count) { return 1 }
521
+ if ($pa.Pre.Count -lt $pb.Pre.Count) { return -1 }
522
+ return 0
523
+ }
524
+
473
525
  # ---------- 客户端根(AppRoot)自动定位 ----------
474
526
  # 客户端可能装在任意盘/任意目录,也会被卸载重装到别处;脚本里写死一个盘符换机或换盘就废。
475
527
  # 定位顺序:显式参数(且要对得上)→ 环境变量 → 注册表卸载项的 InstallLocation(最权威)→ 常见位置。
package/runtime/sync.ps1 CHANGED
@@ -694,22 +694,20 @@ function Initialize-EmptyRepo([string]$RemoteUrl) {
694
694
 
695
695
  $contractPath = Join-Path $RepoRoot 'profile\host-contract.json'
696
696
  if (-not (Test-Path -LiteralPath $contractPath)) {
697
- $ver = ''
698
- $pkg = Join-Path $AppRoot 'resources\app\package.json'
699
- if (Test-Path -LiteralPath $pkg) {
700
- try { $ver = [string](Get-Content -LiteralPath $pkg -Raw -Encoding utf8 | ConvertFrom-Json).version } catch { }
701
- }
702
- if (-not $ver) {
703
- $vf = Join-Path $AppRoot 'version'
704
- if (Test-Path -LiteralPath $vf) { $ver = (Get-Content -LiteralPath $vf -Raw -Encoding utf8).Trim() }
705
- }
697
+ # 0.4.19:复用 Get-HostAppVersion(dsh-sync-common.ps1),它的读取链是
698
+ # resources\app\package.json → app.asar 内 dsh/package.json(asar 手工解析)。
699
+ # 旧回退链在打包版下读不到 resources\app\,兜底去读 <AppRoot>\version——那是 electron-builder
700
+ # 写的 Electron 框架版本(如 44.7.0),被当 appVersion 写进契约后,capture 的防降级
701
+ # 策略会把它永久冻住,另一台 apply 的实验 bundle 门控就对着一个假版本判断。
702
+ $ver = Get-HostAppVersion $AppRoot
706
703
  if ($ver) {
707
704
  $dir = Join-Path $RepoRoot 'profile'
708
705
  if (-not (Test-Path -LiteralPath $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
709
706
  $obj = [ordered]@{
710
- appVersion = $ver
711
- generatedAt = (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
712
- note = '由 dsh-config-sync 首次推送生成(客户端版本契约)'
707
+ appVersion = $ver
708
+ electronVersion = Get-HostElectronVersion $AppRoot
709
+ generatedAt = (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
710
+ note = '由 dsh-config-sync 首次推送生成(客户端版本契约)'
713
711
  }
714
712
  [IO.File]::WriteAllText($contractPath, ($obj | ConvertTo-Json -Depth 4), (New-Object Text.UTF8Encoding $false))
715
713
  Ok "已写入版本契约:$ver"
@@ -834,6 +832,28 @@ if ($Action -eq 'push') {
834
832
  Warn "建议完全退出(含托盘)后重跑;确认要继续可加 -Force"
835
833
  Die "已停止(未抓取、未提交)。"
836
834
  }
835
+ # 0.4.19:推送前先把云端最新历史取下来核对——capture 的镜像删除以「本机没有 = 删仓库」为准,
836
+ # 若另一台机器刚推过而本机没拉,未取下的快进合并会把对方独有的文件(尤其会话/附件这类
837
+ # 不可再生数据)从仓库里删掉。这里取完发现云端领先就停,让用户先拉取;-Force 可显式越过。
838
+ $behindCheck = $null
839
+ if ($hasGit -and $hasCommit) {
840
+ $fetchOut = (& "$env:ComSpec" /c ('"' + $git + '" -C "' + $RepoRoot + '" fetch origin --prune 2>&1') | Out-String)
841
+ if ($LASTEXITCODE -eq 0) {
842
+ $upstreamProbe = (Get-GitText 'rev-parse --abbrev-ref --symbolic-full-name "@{upstream}"')
843
+ if ($upstreamProbe.Code -eq 0 -and $upstreamProbe.Text) {
844
+ $cnt = (Get-GitText ('rev-list --count HEAD..' + $upstreamProbe.Text))
845
+ if ($cnt.Code -eq 0 -and $cnt.Text) { $behindCheck = 0; [void][int]::TryParse($cnt.Text, [ref]$behindCheck) }
846
+ }
847
+ } else {
848
+ Warn "推送前 fetch 失败(网络/地址问题):继续按无更新处理,但若另一台机器刚推过,本次镜像删除可能覆盖它的改动"
849
+ }
850
+ }
851
+ if ($behindCheck -gt 0 -and -not $Force) {
852
+ Warn ("云端比本机领先 {0} 个提交:先拉取(pwsh -File sync.ps1 pull),否则 capture 的镜像删除会把云端独有的文件从仓库删掉。" -f $behindCheck)
853
+ Die "已停止(未抓取、未提交、未推送)。确认要覆盖云端请加 -Force。"
854
+ } elseif ($behindCheck -gt 0) {
855
+ Warn ("云端比本机领先 {0} 个提交(-Force 已越过检查):镜像删除可能清掉云端独有文件,会话/附件不可再生,请确认。" -f $behindCheck)
856
+ }
837
857
  $captureArgs = @{ RepoRoot = $RepoRoot; DshHome = $DshHome; ProfileName = $ProfileName; AppRoot = $AppRoot; WorkspaceHome = $WorkspaceHome; NoResetNotices = $true }
838
858
  if ($WorkspaceOnly) { $captureArgs['WorkspaceOnly'] = $true }
839
859
  if ($SkipWorkspace) { $captureArgs['SkipWorkspace'] = $true }
@@ -844,7 +864,10 @@ if ($Action -eq 'push') {
844
864
  Say ""
845
865
  Say "== 提交 =="
846
866
  Initialize-CommitIdentity
847
- & $git -C $RepoRoot add -A
867
+ # 0.4.19:与 push 同款 cmd 转发。本脚本 ErrorActionPreference=Stop,git add 偶尔往 stderr 写
868
+ # advice/告警时会被包成 NativeCommandError 直接中断——且发生在 add 之后 commit 之前,索引留半截。
869
+ & "$env:ComSpec" /c ('"' + $git + '" -C "' + $RepoRoot + '" add -A 2>&1') | Out-Null
870
+ if ($LASTEXITCODE -ne 0) { Die ("git add -A 失败(退出码 {0}):索引/文件系统可能异常(如 .git/index.lock)。" -f $LASTEXITCODE) }
848
871
  # 走 Read-GitLines:中文目录名若被 quotepath 转义成 "…\347\240\264…",连引号一起拿进
849
872
  # Test-Path -LiteralPath 就是「路径中具有非法字符」,整次同步会在这里挂掉
850
873
  $pending = @((Read-GitLines 'diff --cached --name-only').Lines)
@@ -1015,6 +1038,9 @@ if ($Action -eq 'push') {
1015
1038
  $quotaHit = [bool]($pushOut -match 'exceeds .*quota|repository size|total repository size|仓库容量|容量上限')
1016
1039
  $networkHit = [bool]($pushOut -match 'Could not read from remote|Permission denied|publickey|Host key verification|Could not resolve host|timed out|Connection refused|Operation timed out')
1017
1040
  $rejectedHit = [bool]($pushOut -match '\[remote rejected\]|pre-receive hook declined')
1041
+ # 0.4.19:普通推送被拒(远端领先/分支保护)单独分类——双机竞态下最常见的失败,
1042
+ # 旧版落进兜底「既不是文件超限也不是已知网络特征」,排查体验差。
1043
+ $nonFastForwardHit = [bool]($pushOut -match 'non-fast-forward|fetch first|\[rejected\]')
1018
1044
 
1019
1045
  if ($remoteOversized.Count -gt 0 -or $histTooLarge.Count -gt 0) {
1020
1046
  # 有具体文件名(远端报的)或历史预检命中:这是「文件超限」,不是网络
@@ -1038,6 +1064,10 @@ if ($Action -eq 'push') {
1038
1064
  Die ("git push 被远端拒绝(remote rejected / pre-receive hook declined),原因见上面 remote: 那几行。" +
1039
1065
  "`n 改动已提交在本地,处理完远端限制后重跑 git -C `"$RepoRoot`" push 即可。")
1040
1066
  }
1067
+ if ($nonFastForwardHit) {
1068
+ Die ("git push 被拒:远端比本机领先(non-fast-forward),多半是另一台机器刚推送过。" +
1069
+ "`n 处理:先执行拉取 pwsh -File `"$RepoRoot\sync.ps1`" pull(有分叉时按面板「同步冲突」处理),再重新推送。")
1070
+ }
1041
1071
  if ($networkHit) {
1042
1072
  Die "git push 失败(网络/认证)。改动已提交在本地,修好网络后重跑:git -C `"$RepoRoot`" push;若是 GIT_SSH_COMMAND 问题,先确认它第一个词是 ssh.exe 本体"
1043
1073
  }
@@ -2110,7 +2110,7 @@ console.log('== 0.4.17:拉取落地加固(前置检查 + 自愈 + 落地验
2110
2110
  && appS.includes('duplicate-path') && appS.includes('session-dirs-0'), 'apply.ps1')
2111
2111
  check('落地验证覆盖 projcache/bundle/link 且写 pull-landing-check.json',
2112
2112
  appS.includes('projcache-token') && appS.includes('pull-landing-check.json')
2113
- && appS.includes('link:$d'), 'apply.ps1')
2113
+ && appS.includes("link:$leaf"), 'apply.ps1')
2114
2114
 
2115
2115
  // notice 白名单与面板文案同步
2116
2116
  check('index.js notice KINDS 含 landing',