dsh-config-sync-plugin 0.3.62 → 0.3.64

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
@@ -1,4 +1,4 @@
1
- # dsh-config-sync-plugin
1
+ # dsh-config-sync-plugin
2
2
  [中文](README.md) | English
3
3
 
4
4
  A DSH plugin: it adds a **"Config Sync"** row to the sidebar (opening a full-page health-check panel), plus a summary row under **Settings → General**. It only **inspects and prepares commands** — the sync actions never run inside the app (except the automatic sync that relaunches the client).
@@ -19,7 +19,7 @@ The package name is **`dsh-config-sync-plugin`** (the `dsh-config-sync` name on
19
19
 
20
20
  | Way | Command / entry | Notes |
21
21
  |---|---|---|
22
- | npm | `npm i dsh-config-sync-plugin` | Use it as a dependency, or add `"dsh-config-sync-plugin": "^0.3.62"` to the profile's `package.json` and run `pnpm i`. The name matches the `cordis.patch.yml` insert name and the install folder `dsh-config-sync-plugin-<ver>` |
22
+ | npm | `npm i dsh-config-sync-plugin` | Use it as a dependency, or add `"dsh-config-sync-plugin": "^0.3.64"` to the profile's `package.json` and run `pnpm i`. The name matches the `cordis.patch.yml` insert name and the install folder `dsh-config-sync-plugin-<ver>` |
23
23
  | Marketplace | client → Plugins → Discover → “Config Sync” | Installs from the git commit registered in `market-index.json` |
24
24
  | Offline tgz | `releases\dsh-config-sync-plugin-<ver>.tgz` | GitHub Release asset for air-gapped machines; the panel's Update button downloads the same file |
25
25
 
@@ -589,6 +589,17 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
589
589
 
590
590
  ## Test log (2026-11-11, isolated environment)
591
591
 
592
+ ### 2026-11-18: release 0.3.64 (backup restore fix + failure summary + auto-close)
593
+
594
+ - **Backup restore bug fixed**: `apply.ps1` backed up plugin settings by filename only (e.g. `workspace.json`), and `restore.ps1` dumped them all into `~\.dsh` root, so `storages\workspace.json`, `our-free-model\settings.json`, `redteam\preset-declare.json` never returned to their original directories. Backup now writes `__backup_manifest.json` mapping backup filename -> original path relative to DshHome, and restore writes each file back in place; old snapshots without the manifest fall back to root with a clear warning. Isolated regression: 5 profile files + 3 settings restored in place, zero stray root files, point-in-time rollback moved new files and wrote its manifest — all pass.
595
+ - **Failure summary**: on push/pull failure, `post-exit.ps1` now adds `Show-FailureSummary`, extracting `[X]` error lines with detail and recent `[!]` warnings from the run log and printing them together at the end — no more digging through logs.
596
+ - **Auto-close**: after push/pull/update/restore, the window closes automatically 6 minutes after showing results; no more "press any key" (which hangs under remote desktop / unfocused windows). You can also click the × button to close early.
597
+ - **Boundary**: workspace/conversations/skills/presets/plugin-data backed up before apply are data directories, not part of "config restore" rollback (they have their own sync/session paths; folding them in would add path mapping and heavy directory walking).
598
+
599
+ ### 2026-11-18: push speed release 0.3.63 (Get-RelPath ~10x faster)
600
+
601
+ The shared `Get-RelPath` used by push and pull ran two `-split` + `Where-Object` per file; on a 49k-file workspace push comparison alone cost 11.7s. Now a `StartsWith` + `Substring` fast path, falling back to the original segment-count logic when case or 8.3 short paths disagree. 49,138 files compared with 0 output differences; microbench 5.08s -> 0.51s (~9.9x). All three `dsh-sync-common.ps1` copies (source / config repo / plugin runtime) updated.
602
+
592
603
  ### 2026-11-18: pull speed release 0.3.62 (341s → 109s, ~3.1×)
593
604
 
594
605
  One machine had 49,110 files in a workspace and 101,097 orphan files piled up in another workspace slot; "pull" stalled at "workspace restored" for minutes. Segment tracing found four avoidable costs, all in `runtime\apply.ps1`. Behaviour is unchanged (files committed to the repo, config results and decisions are byte-identical); only "how it computes" changed:
package/README.md CHANGED
@@ -15,7 +15,7 @@ DSH 插件:左侧栏多一行「配置同步」,点开是整页体检面板
15
15
 
16
16
  | 方式 | 命令 / 入口 | 说明 |
17
17
  |---|---|---|
18
- | npm | `npm i dsh-config-sync-plugin` | 适合把它当依赖管理,或在 profile 的 `package.json` 里写 `"dsh-config-sync-plugin": "^0.3.62"` 后 `pnpm i`;包名与 `cordis.patch.yml` 里注册的名字、插件目录 `dsh-config-sync-plugin-<ver>` 一致 |
18
+ | npm | `npm i dsh-config-sync-plugin` | 适合把它当依赖管理,或在 profile 的 `package.json` 里写 `"dsh-config-sync-plugin": "^0.3.64"` 后 `pnpm i`;包名与 `cordis.patch.yml` 里注册的名字、插件目录 `dsh-config-sync-plugin-<ver>` 一致 |
19
19
  | 插件市场 | 客户端「插件市场 → 发现」搜「配置同步」 | 走 `market-index.json` 登记的 git 提交,版本与 README 对齐 |
20
20
  | 离线 tgz | `releases\dsh-config-sync-plugin-<ver>.tgz` | GitHub Release 附件,适合内网机器;面板「更新」按钮下载的也是它 |
21
21
 
@@ -565,6 +565,17 @@ pwsh -File sync.ps1 push -ScanHistory
565
565
 
566
566
  ## 实测记录
567
567
 
568
+ ### 2026-11-18:发版 0.3.64(还原备份修复 + 失败原因集中展示 + 自动关窗)
569
+
570
+ - **还原备份 bug 修复**:`apply.ps1` 备份插件设置时只留文件名(如 `workspace.json`),`restore.ps1` 还原时全堆到 `~\.dsh` 根目录,`storages\workspace.json`、`our-free-model\settings.json`、`redteam\preset-declare.json` 等回不到原位。现在备份时写一份 `__backup_manifest.json` 记录「备份文件名 → 相对 DshHome 的原路径」,还原按清单写回原位;无清单的老快照退化为写回根目录并明确告警。隔离回归:profile 5 文件 + settings 3 文件原位还原、根目录零残留、时点回退移走新增文件并写 rollback 清单,全部通过。
571
+ - **失败原因集中展示**:推送/拉取失败时,`post-exit.ps1` 收尾新增 `Show-FailureSummary`,从执行日志抽取 `[X]` 错误行及后续详情、最近的 `[!]` 警告,红/黄集中打印在末尾,不用再翻日志找原因。
572
+ - **自动关窗**:推送/拉取/更新/还原脚本结束后,展示结果 6 分钟后自动退出关窗,不再要求「按任意键」(远程桌面/无焦点时 `ReadKey` 会一直卡住);也可直接点右上角 × 提前关闭。
573
+ - **边界说明**:`apply` 拉取前备份的 workspace/conversations/skills/presets/plugin-data 属数据目录,不纳入「配置还原」回退范围(有各自的同步/会话路径,强塞会引入路径映射与大目录遍历开销)。
574
+
575
+ ### 2026-11-18:推送提速发版 0.3.63(Get-RelPath 快 10 倍)
576
+
577
+ 推送/拉取共用的 `Get-RelPath` 原来对每个文件做两次 `-split` + `Where-Object`;5 万文件工作区下,推送比对单独占 11.7s。改为 `StartsWith` + `Substring` 快路径,大小写或 8.3 短路径不一致时回退原段数比对逻辑。49138 文件全量比对与老版输出 0 差异,微基准 5.08s → 0.51s(约 9.9 倍)。三处 `dsh-sync-common.ps1`(源码 / 配置仓库 / 插件副本)同步。
578
+
568
579
  ### 2026-11-18:拉取提速发版 0.3.62(341s → 109s,约 3.1×)
569
580
 
570
581
  一台机器上工作区有 49110 个文件、另一个工作区槽位堆积了 101097 个孤儿文件,点「拉取」时卡在「已还原工作区」好几分钟。逐段打点后定位到 4 个浪费点,全部在 `runtime\apply.ps1`,行为不变(落到仓库的文件、提交内容、配置结果逐字节一致),只改「怎么算」:
package/client.js CHANGED
@@ -921,7 +921,7 @@ window.__ModuleLoader__.load({
921
921
  }
922
922
  // 「手动还原」指引里的目标位置:认不出类型时按内容猜不到,索性把三类常见落点都摆出来
923
923
  const manualTargets = () => [
924
- M('插件本体 → 插件安装目录(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.62)', 'Plugin files → the plugin install folder (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.62)'),
924
+ M('插件本体 → 插件安装目录(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.64)', 'Plugin files → the plugin install folder (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.64)'),
925
925
  M('会话目录(--xxx--)→ ~\\.dsh\\sessions', 'Session folders (--xxx--) → ~\\.dsh\\sessions'),
926
926
  M('配置五件套(package.json / pnpm-lock.yaml / cordis.yml…)→ ~\\.dsh\\profiles\\desktop', 'Config files (package.json / pnpm-lock.yaml / cordis.yml…) → ~\\.dsh\\profiles\\desktop'),
927
927
  ]
package/index.js CHANGED
@@ -976,9 +976,9 @@ async function inspect(config) {
976
976
  const remoteFiles = remoteProbe ? remoteProbe.files : null
977
977
  if (!appRoot) {
978
978
  advice.push(t(
979
- '定位不到客户端根目录:插件不在 <客户端根> 下(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.62),'
979
+ '定位不到客户端根目录:插件不在 <客户端根> 下(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.64),'
980
980
  + '或客户端是打包版(resources\\app.asar)而这里没认出来 —— 三份同步脚本会因此生成不了',
981
- 'Cannot locate the client root: the plugin is not under <client root> (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.62), '
981
+ 'Cannot locate the client root: the plugin is not under <client root> (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.64), '
982
982
  + 'or this is a packaged build (resources\\app.asar) that was not recognized — the three sync scripts cannot be generated.',
983
983
  ))
984
984
  }
@@ -3477,9 +3477,9 @@ async function handlePrepare(req, res, config) {
3477
3477
  if (!appRoot) {
3478
3478
  throw new Error(t(
3479
3479
  '定位不到客户端根目录(要能找到 resources\\app\\package.json 或 resources\\app.asar):'
3480
- + '请确认插件装在 <客户端根> 下(例如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.62),或在设置里填客户端根 appRoot',
3480
+ + '请确认插件装在 <客户端根> 下(例如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.64),或在设置里填客户端根 appRoot',
3481
3481
  'Cannot locate the client root (needs resources\\app\\package.json or resources\\app.asar): '
3482
- + 'make sure the plugin is installed under <client root> (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.62), or set appRoot in the settings',
3482
+ + 'make sure the plugin is installed under <client root> (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.64), or set appRoot in the settings',
3483
3483
  ))
3484
3484
  }
3485
3485
  const state = {...await repoState(repo), message}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-config-sync-plugin",
3
- "version": "0.3.62",
3
+ "version": "0.3.64",
4
4
  "type": "module",
5
5
  "description": "在 DSH 设置里查看 dsh-config 仓库与本机的同步状态,并生成退出后执行的 push/pull 脚本。同步动作本身不在应用内执行。面板与文案跟随客户端语言(中文/English)。",
6
6
  "main": "./index.js",
package/runtime/apply.ps1 CHANGED
@@ -744,14 +744,25 @@ foreach ($f in @('AGENTS.md', 'prompt-inject.md')) {
744
744
  $src = Join-Path $DshHome $f
745
745
  if (Test-Path -LiteralPath $src) { Copy-Item -LiteralPath $src -Destination (Join-Path $BackupDir $f) -Force; $backedUp++ }
746
746
  }
747
+ $settingsBackupManifest = [ordered]@{}
747
748
  foreach ($m in $settingsMap) {
748
749
  if (Test-Path -LiteralPath $m.Src) {
749
750
  $bc = Join-Path $BackupDir 'settings'
750
751
  if (-not (Test-Path -LiteralPath $bc)) { New-Item -ItemType Directory -Path $bc -Force | Out-Null }
751
- Copy-Item -LiteralPath $m.Src -Destination (Join-Path $bc (Split-Path -Leaf $m.Src)) -Force
752
+ $leaf = Split-Path -Leaf $m.Src
753
+ Copy-Item -LiteralPath $m.Src -Destination (Join-Path $bc $leaf) -Force
754
+ # 记下「备份文件名 → 相对 DshHome 的原路径」。旧版只留文件名,还原时全堆到 DshHome 根
755
+ # (storages\workspace.json 变根 workspace.json),这里把原位记进清单,还原按它写回。
756
+ $settingsBackupManifest[$leaf] = $m.Src.Substring($DshHome.Length).TrimStart([char]92, [char]47)
752
757
  $backedUp++
753
758
  }
754
759
  }
760
+ if ($settingsBackupManifest.Count -gt 0) {
761
+ try {
762
+ $mfPath = Join-Path (Join-Path $BackupDir 'settings') '__backup_manifest.json'
763
+ [IO.File]::WriteAllText($mfPath, ($settingsBackupManifest | ConvertTo-Json -Depth 3), (New-Object Text.UTF8Encoding($false)))
764
+ } catch { Warn ('写 settings 备份清单失败(还原时只能按旧规则写回根):' + $_.Exception.Message) }
765
+ }
755
766
  if ($backedUp -gt 0) {
756
767
  Ok "已备份 $backedUp 个文件到 $BackupDir"
757
768
  } else {
@@ -845,6 +856,8 @@ if ($dropped.Count -gt 0) { Ok "已剔除 $($dropped.Count) 个实验性 bundle
845
856
  $localPluginMap = [ordered]@{
846
857
  'dsh-our-free-model-2.8.0' = 'dsh-our-free-model'
847
858
  'dsh-purge-1.4.0' = 'dsh-purge'
859
+ 'dsh-config-sync-plugin-0.3.64' = 'dsh-config-sync-plugin'
860
+ 'dsh-config-sync-plugin-0.3.63' = 'dsh-config-sync-plugin'
848
861
  'dsh-config-sync-plugin-0.3.62' = 'dsh-config-sync-plugin'
849
862
  'dsh-config-sync-plugin-0.3.61' = 'dsh-config-sync-plugin'
850
863
  'dsh-config-sync-plugin-0.3.59' = 'dsh-config-sync-plugin'
@@ -158,7 +158,18 @@ function Get-GitExe {
158
158
  }
159
159
 
160
160
  # 求 $full 相对 $base 的路径:按路径段数取尾巴,避免 8.3 短路径(ADMINI~1)或大小写差异导致 Substring 算错
161
- function Get-RelPath([string]$base, [string]$full) { $b = @($base -split '\\' | Where-Object { $_ -ne '' })
161
+ function Get-RelPath([string]$base, [string]$full) {
162
+ # Fast path: $full is under $base from the same enumeration (99.9%). Substring avoids two -split + Where-Object.
163
+ if ($full.StartsWith($base, [StringComparison]::OrdinalIgnoreCase)) {
164
+ $tail = $full.Substring($base.Length)
165
+ if ($tail.Length -gt 0 -and ($tail[0] -eq '\' -or $tail[0] -eq '/')) {
166
+ $rel = $tail.TrimStart('\','/')
167
+ if ($rel) { return $rel }
168
+ }
169
+ return $null
170
+ }
171
+ # Fallback: base/full disagree on case or 8.3 short path (ADMINI~1). Count path segments instead.
172
+ $b = @($base -split '\\' | Where-Object { $_ -ne '' })
162
173
  $f = @($full -split '\\' | Where-Object { $_ -ne '' })
163
174
  if ($f.Count -le $b.Count) { return $null }
164
175
  return ($f[$b.Count..($f.Count - 1)] -join '\')
@@ -193,6 +193,35 @@ function Show-NoticesSummary {
193
193
  Write-Host '--------------------------------------------------------' -ForegroundColor Yellow
194
194
  }
195
195
 
196
+ # 失败原因集中展示:从本次日志里挑出 Die 的红字 [X] 行(含紧随的多行详情)+ 相关警告,
197
+ # 统一打在窗口末尾,用户不必再从几十行进度里翻失败点。只在失败时调用。
198
+ function Show-FailureSummary {
199
+ if (-not (Test-Path -LiteralPath $LogFile)) { return }
200
+ $lines = @()
201
+ try { $lines = @(Get-Content -LiteralPath $LogFile -Encoding utf8) } catch { return }
202
+ if ($lines.Count -eq 0) { return }
203
+ $errIdx = @()
204
+ for ($i = 0; $i -lt $lines.Count; $i++) {
205
+ if ($lines[$i] -match '\[X\]' -or $lines[$i] -match '执行体调用异常|ParserError|终止错误|fatal:|NativeCommandError|未正常结束|没正常跑完|badTimezone') { $errIdx += $i }
206
+ }
207
+ $warns = @($lines | Where-Object { $_ -match '\[!\]' })
208
+ if ($errIdx.Count -eq 0 -and $warns.Count -eq 0) { return }
209
+ Write-Host ''
210
+ Write-Host '================ 失败原因集中展示 ================' -ForegroundColor Red
211
+ $printed = New-Object 'System.Collections.Generic.HashSet[int]'
212
+ foreach ($i in ($errIdx | Select-Object -First 6)) {
213
+ for ($j = $i; $j -lt [Math]::Min($i + 6, $lines.Count); $j++) {
214
+ if ($printed.Add($j)) { Write-Host (' ' + $lines[$j].TrimEnd()) -ForegroundColor Red }
215
+ }
216
+ }
217
+ if ($warns.Count -gt 0) {
218
+ Write-Host (' --- 相关警告(前 8 条)---') -ForegroundColor Yellow
219
+ foreach ($w in ($warns | Select-Object -First 8)) { Write-Host (' ' + $w.TrimEnd()) -ForegroundColor Yellow }
220
+ }
221
+ Write-Host (' 完整日志:{0}' -f $LogFile)
222
+ Write-Host '==================================================' -ForegroundColor Red
223
+ }
224
+
196
225
  function Finish([int]$code, [string]$note) {
197
226
  Log ("结束:{0}(退出码 {1})" -f $note, $code)
198
227
  Log ("日志:{0}" -f $LogFile)
@@ -205,26 +234,21 @@ function Finish([int]$code, [string]$note) {
205
234
  }
206
235
  } catch { }
207
236
 
208
- # 推送 / 拉取 / 插件更新:**不自动关窗**,把结果留在屏幕上让用户自己关。
209
- # 为什么敢一直挂着:客户端是在这之前的 RestartClient 里用 explorer 代启的,跟本窗口没有父子/作业关系,
210
- # 所以窗口留多久、还是被点 × 直接结束,都不会把客户端带走。
211
- # 只有 relaunch(纯重启,窗口里没有可看的结果)仍旧停 3 秒自动关。
237
+ # 结果展示后窗口随进程自动关闭:不再要求「按任意键」(远程桌面/无焦点时 ReadKey 会一直卡住)。
238
+ # 用户可直接点右上角 × 提前关闭;客户端由 explorer 代启,与本窗口无父子关系,关窗不会带走它。
212
239
  if ($Mode -eq 'pull' -or $Mode -eq 'push' -or $Mode -eq 'update' -or $Mode -eq 'restore') {
213
240
  $title = if ($Mode -eq 'update') { '插件更新已完成' } elseif ($Mode -eq 'restore') { '还原已完成' } else { '同步已完成' }
214
241
  try {
215
242
  Show-NoticesSummary
243
+ if ($code -ne 0) { Show-FailureSummary }
216
244
  Write-Host ''
217
245
  Write-Host ("================ {0} ================" -f $title)
218
- Write-Host ' 这个窗口不会自动关闭:看完按任意键,或点右上角 × 关闭。'
219
- Write-Host ' 客户端已在后台由 explorer 拉起,关掉这个窗口不会影响它。'
246
+ Write-Host ' 窗口将在 6 分钟后自动关闭;也可直接点右上角 × 关闭(客户端在后台运行,不受影响)。'
247
+ if ($code -ne 0) { Write-Host ' 失败原因已集中在上面「失败原因集中展示」一段,不必再翻日志。' -ForegroundColor Red }
220
248
  Write-Host '==========================================='
221
- $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
222
- } catch {
223
- # 不是真控制台(被重定向/无窗口)时 ReadKey 会抛,退化成长时间挂起而不是立刻消失
224
- try { Start-Sleep -Seconds 3600 } catch { }
225
- }
249
+ } catch { }
250
+ try { Start-Sleep -Seconds 360 } catch { }
226
251
  } else {
227
- # 窗口跟着进程一起关,停 3 秒让用户看清成功/失败与日志路径
228
252
  try { Start-Sleep -Seconds 3 } catch { }
229
253
  }
230
254
  exit $code
@@ -300,14 +300,29 @@ if ($mode -eq 'git') {
300
300
 
301
301
  $bkSettings = Join-Path $BackupDir 'settings'
302
302
  if (Test-Path -LiteralPath $bkSettings) {
303
- if ($DryRun) { Say " 将写回 settings\ 下的插件设置文件" }
303
+ # 0.3.64 修复:apply 备份时把「备份文件名 → 相对 DshHome 的原路径」写进了清单。
304
+ # 旧版只留文件名、还原全堆到 DshHome 根(storages\workspace.json 变根 workspace.json),
305
+ # 现按清单写回原目录;没有清单的老快照退化为写回根(至少文件还在),并明确告警。
306
+ $bkManifest = $null
307
+ $mfPath = Join-Path $bkSettings '__backup_manifest.json'
308
+ if (Test-Path -LiteralPath $mfPath) {
309
+ try { $bkManifest = Get-Content -LiteralPath $mfPath -Raw -Encoding utf8 | ConvertFrom-Json } catch { $bkManifest = $null }
310
+ } else {
311
+ Warn "这份快照没有 settings 备份清单(老版本备份):设置文件只能写回 $DshHome 根目录,可能要手动挪回原位"
312
+ }
313
+ if ($DryRun) { Say " 将写回 settings\ 下的插件设置文件到各自原位" }
304
314
  else {
305
315
  $cnt = 0
306
- Get-ChildItem -LiteralPath $bkSettings -File -Force | ForEach-Object {
307
- Copy-Item -LiteralPath $_.FullName -Destination (Join-Path $DshHome $_.Name) -Force
316
+ Get-ChildItem -LiteralPath $bkSettings -File -Force | Where-Object { $_.Name -ne '__backup_manifest.json' } | ForEach-Object {
317
+ $prop = if ($bkManifest) { $bkManifest.PSObject.Properties[$_.Name] } else { $null }
318
+ $rel = if ($prop) { [string]$prop.Value } else { $_.Name }
319
+ $dest = Join-Path $DshHome $rel
320
+ $destDir = Split-Path -Parent $dest
321
+ if ($destDir -and -not (Test-Path -LiteralPath $destDir)) { New-Item -ItemType Directory -Path $destDir -Force | Out-Null }
322
+ Copy-Item -LiteralPath $_.FullName -Destination $dest -Force
308
323
  $cnt++
309
324
  }
310
- Ok "已写回 settings 下 $cnt 个插件设置文件"
325
+ Ok "已写回 settings 下 $cnt 个插件设置文件到各自原位"
311
326
  }
312
327
  }
313
328
  }