dsh-config-sync-plugin 0.3.61 → 0.3.62

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.61"` 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.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>` |
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,21 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
589
589
 
590
590
  ## Test log (2026-11-11, isolated environment)
591
591
 
592
+ ### 2026-11-18: pull speed release 0.3.62 (341s → 109s, ~3.1×)
593
+
594
+ 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:
595
+
596
+ | Step | Result |
597
+ |---|---|
598
+ | End-to-end | 340.9s → 108.5s (same environment and input, ~3.1×); all functional assertions pass: 5 workspaces restored, 0 writes/updates, 0 backups, 56 session cwd fixes, 24 bundles resolvable, `EXIT=0` |
599
+ | ① Unconditional full backup | It used to back up the whole workspace before restoring each one (49,110 files × 1.99ms ≈ 98s), yet a second pull finds source and target byte-identical and needs 0 backups. Now a single file is backed up only when it is actually about to be overwritten → backups 49,110 → 0 |
600
+ | ② Hash API | `Get-FileHash` measured 0.957ms/file vs streaming .NET `SHA256.ComputeHash` 0.16ms/file (~6×); workspace/session header comparisons switched to streaming SHA256 |
601
+ | ③ zip version regex | The `package.json` path inside a `Compress-Archive` zip uses backslashes, but the version regex only accepted `/`, so the archive version was unreadable and a `git fetch` mtime refresh made every pull think "local plugin has a new version" and re-extract 3 link plugins. Changed to `[\\/]`; now all three consistently report "plugin already present" |
602
+ | ④ **Root cause: O(n²) array append** | The extra-path scan did `$extra = @()` + `$extra += $lf.FullName`; 101,097 orphan files ≈ 5.1 billion array copies, alone costing 264s (the dsh-config-sync slot has only 16 synced files yet took 264s). Replaced with `[System.Collections.Generic.List[string]]::new()` + `$extra.Add(...)` → O(n) |
603
+ | Remaining 108s | Hashing + copying 49,110 files in DSH破甲 takes 71s of real disk I/O; cutting further needs option ③ "git HEAD short-circuit" (high risk, not implemented) |
604
+ | Also fixed | A historical `market-index.json` structure bug (0.3.61 release wrote `plugins` as a mixed object/array) and that entry's `TODO_COMMIT_0361` placeholder commit; 0.3.61's "skip projcache sync" (context-overflow fix) is preserved |
605
+ | Lessons | Timestamp tracing through a PowerShell `ForEach-Object` pipeline gets swallowed by output buffering — write to stderr (`[Console]::Error.WriteLine`) for live traces; a BOM'd UTF-8 script must be read/written only as UTF8 — ISO-8859-1 round-trips force .NET to UTF8-decode then re-encode, turning all Chinese into `?` and dropping the BOM |
606
+
592
607
  ### 2026-11-15: performance release 0.3.54 (three speedups, behaviour unchanged)
593
608
 
594
609
  | Step | Result |
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # dsh-config-sync-plugin
1
+ # dsh-config-sync-plugin
2
2
  中文 | [English](README.en.md)
3
3
 
4
4
  DSH 插件:左侧栏多一行「配置同步」,点开是整页体检面板;「设置 → 通用」另有一行摘要。插件**只做体检 + 备命令**,同步动作在客户端退出后由 `runtime\sync.ps1` 执行(自动同步那一路会自己拉起客户端)。
@@ -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.61"` 后 `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.62"` 后 `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,21 @@ pwsh -File sync.ps1 push -ScanHistory
565
565
 
566
566
  ## 实测记录
567
567
 
568
+ ### 2026-11-18:拉取提速发版 0.3.62(341s → 109s,约 3.1×)
569
+
570
+ 一台机器上工作区有 49110 个文件、另一个工作区槽位堆积了 101097 个孤儿文件,点「拉取」时卡在「已还原工作区」好几分钟。逐段打点后定位到 4 个浪费点,全部在 `runtime\apply.ps1`,行为不变(落到仓库的文件、提交内容、配置结果逐字节一致),只改「怎么算」:
571
+
572
+ | 环节 | 结果 |
573
+ |---|---|
574
+ | 端到端总耗时 | 340.9s → 108.5s(同环境同输入,约 3.1×);功能断言全过:5 工作区还原、写入/更新 0、备份 0、会话 cwd 修正 56、bundle 24 项可解析、`EXIT=0` |
575
+ | ① 无条件全量备份 | 原来每个工作区还原前把整个工作区备份一遍(49110 文件 × 1.99ms ≈ 98s),而二次拉取时源与目标内容全一致、实际需备份 0 个。改为「确认某个文件即将被覆盖时才备份这一个」→ 备份 49110 → 0 |
576
+ | ② 哈希 API | `Get-FileHash` 实测 0.957ms/文件,.NET `SHA256.ComputeHash` 流式 0.16ms/文件(约 6×);会话首帧与工作区比对的哈希统一换成流式 SHA256 |
577
+ | ③ zip 版本正则 | 归档内 `package.json` 路径在 `Compress-Archive` 打出的 zip 里是反斜杠,而版本正则只认 `/` → 读不到归档版本、`git fetch` 刷新 mtime 后每轮误判「本地插件有新版本」,反复重解压 3 个 link 插件。改成 `[\\/]` 兼容两种分隔符后,三插件稳定显示「本地插件已存在」 |
578
+ | ④ **真凶:O(n²) 数组追加** | extra 扫描里 `$extra = @()` + `$extra += $lf.FullName`,101097 个孤儿文件约 51 亿次数组拷贝,单独占 264s(dsh-config-sync 槽位仅 16 个同步文件却耗时 264s)。换成 `[System.Collections.Generic.List[string]]::new()` + `$extra.Add(...)` → O(n) |
579
+ | 剩余 108s | DSH破甲 49110 文件的哈希 + 复制 71s 是实打实的磁盘 I/O;再压需要方案③「git HEAD 增量短路」,风险高、默认未做 |
580
+ | 顺手修 | 历史遗留的 `market-index.json` 结构损坏(0.3.61 发版时把 `plugins` 数组写成了对象/数组混合)与该条目 commit 的 `TODO_COMMIT_0361` 占位符,本次一并修正;0.3.61 的「跳过 projcache 同步」(上下文超长修复)保持不变 |
581
+ | 教训 | PowerShell 管道 `ForEach-Object` 打时间戳会被输出缓冲吞掉,实时打点要写 stderr(`[Console]::Error.WriteLine`);带 BOM 的 UTF-8 脚本全程只能用 UTF8 读写,用 ISO-8859-1 读写会把中文 `.NET` 强制 UTF8 解码后再写回全变 `?` 并丢 BOM |
582
+
568
583
  ### 2026-11-15:性能发版 0.3.54(三处提速,行为不变)
569
584
 
570
585
  | 环节 | 结果 |
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.61)', 'Plugin files → the plugin install folder (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.61)'),
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)'),
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.61),'
979
+ '定位不到客户端根目录:插件不在 <客户端根> 下(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.62),'
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.61), '
981
+ 'Cannot locate the client root: the plugin is not under <client root> (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.62), '
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.61),或在设置里填客户端根 appRoot',
3480
+ + '请确认插件装在 <客户端根> 下(例如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.62),或在设置里填客户端根 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.61), 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.62), 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.61",
3
+ "version": "0.3.62",
4
4
  "type": "module",
5
5
  "description": "在 DSH 设置里查看 dsh-config 仓库与本机的同步状态,并生成退出后执行的 push/pull 脚本。同步动作本身不在应用内执行。面板与文案跟随客户端语言(中文/English)。",
6
6
  "main": "./index.js",
package/runtime/apply.ps1 CHANGED
@@ -110,6 +110,13 @@ function Expand-AppRootTree([string]$dir, [string]$rootFwd) {
110
110
  # 一律 Copy-Item -LiteralPath 原样拷;登记表里的路径占位符在这里展开成本机绝对路径。
111
111
  # ($BS / $WorkspaceHomeToken / $wsSkip* / Test-WorkspaceIgnored 都在 dsh-sync-common.ps1 里,两个脚本共用)
112
112
 
113
+ # 快速 SHA256:复用单个静态实例,比 Get-FileHash cmdlet 快约 6 倍(大批量逐文件比对是拉取主要瓶颈)
114
+ $_dshSha256 = [System.Security.Cryptography.SHA256]::Create()
115
+ function Get-FileHashFast([string]$path) {
116
+ $fs = [System.IO.File]::Open($path, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
117
+ try { return [Convert]::ToBase64String($_dshSha256.ComputeHash($fs)) }
118
+ finally { $fs.Dispose() }
119
+ }
113
120
  function Sync-WorkspaceApply {
114
121
  $wsDir = Join-Path $RepoRoot 'workspace'
115
122
  # 登记表 sessionIds 常常滞后于实际会话目录(会话是后来新建的、capture 只抄了当时的快照)。
@@ -182,23 +189,8 @@ function Sync-WorkspaceApply {
182
189
  }
183
190
  $repoRels[$rel] = $f.FullName
184
191
  }
185
- # 备份本机现有资料(覆盖前的完整快照)
186
- # 但排除「不参与同步」的东西(models/、*.whl、>100MB 之类):备份它们会把磁盘写满,
187
- # 而且它们本来就不会被覆盖,没有备份价值(真实事故:13.8GB 模型被备份进 ~\.dsh\backups,C 盘直接满)。
188
- if (Test-Path -LiteralPath $e.LocalPath) {
189
- $bk = Join-Path $BackupDir ("workspace\" + $e.Slot)
190
- foreach ($lf in @(Get-ChildItem -LiteralPath $e.LocalPath -Recurse -File -Force -ErrorAction SilentlyContinue)) {
191
- $rel = Get-RelPath $e.LocalPath $lf.FullName
192
- if (-not $rel) { continue }
193
- if (Test-WorkspaceIgnored $rel) { continue }
194
- if ($lf.Length -gt $wsMaxFileBytes) { continue }
195
- $bd = Join-Path $bk $rel
196
- $bdd = Split-Path -Parent $bd
197
- if (-not (Test-Path -LiteralPath $bdd)) { New-Item -ItemType Directory -Path $bdd -Force | Out-Null }
198
- Copy-Item -LiteralPath $lf.FullName -Destination $bd -Force
199
- $nBk++
200
- }
201
- }
192
+ # 备份策略:不再无条件全量备份整个工作区(二次拉取 4.9 万文件全量备份白耗 ~100 秒)。
193
+ # 真正的回滚点只在文件「即将被覆盖」时逐个备份,见下方 if ($need) 分支。
202
194
  if (-not (Test-Path -LiteralPath $e.LocalPath)) { New-Item -ItemType Directory -Path $e.LocalPath -Force | Out-Null }
203
195
  foreach ($rel in @($repoRels.Keys)) {
204
196
  $s = $repoRels[$rel]
@@ -207,14 +199,24 @@ function Sync-WorkspaceApply {
207
199
  if (-not (Test-Path -LiteralPath $dd)) { New-Item -ItemType Directory -Path $dd -Force | Out-Null }
208
200
  $need = $false
209
201
  if (-not (Test-Path -LiteralPath $d)) { $need = $true }
210
- elseif ((Get-FileHash -LiteralPath $s -Algorithm SHA256).Hash -ne (Get-FileHash -LiteralPath $d -Algorithm SHA256).Hash) { $need = $true }
211
- if ($need) { Copy-Item -LiteralPath $s -Destination $d -Force; $nAdd++ }
202
+ elseif ((Get-FileHashFast $s) -ne (Get-FileHashFast $d)) { $need = $true }
203
+ if ($need) {
204
+ # 仅覆盖前备份这一个文件(目标存在说明是改动而非新增)
205
+ if (Test-Path -LiteralPath $d) {
206
+ $bd = Join-Path (Join-Path $BackupDir ("workspace\" + $e.Slot)) $rel
207
+ $bdd = Split-Path -Parent $bd
208
+ if (-not (Test-Path -LiteralPath $bdd)) { New-Item -ItemType Directory -Path $bdd -Force | Out-Null }
209
+ Copy-Item -LiteralPath $d -Destination $bd -Force
210
+ $nBk++
211
+ }
212
+ Copy-Item -LiteralPath $s -Destination $d -Force; $nAdd++
213
+ }
212
214
  }
213
215
  # 本机多出的文件:默认不动只提示,加 -PruneWorkspace 才删
214
- $extra = @()
216
+ $extra = [System.Collections.Generic.List[string]]::new()
215
217
  foreach ($lf in @(Get-ChildItem -LiteralPath $e.LocalPath -Recurse -File -Force -ErrorAction SilentlyContinue)) {
216
218
  $rel = Get-RelPath $e.LocalPath $lf.FullName
217
- if ($rel -and -not $repoRels.ContainsKey($rel) -and -not (Test-WorkspaceIgnored $rel)) { $extra += $lf.FullName }
219
+ if ($rel -and -not $repoRels.ContainsKey($rel) -and -not (Test-WorkspaceIgnored $rel)) { $extra.Add([string]$lf.FullName) }
218
220
  }
219
221
  if ($extra.Count -gt 0) {
220
222
  if ($PruneWorkspace) {
@@ -575,7 +577,7 @@ function Sync-ConversationApply {
575
577
  if (-not (Test-Path -LiteralPath $dd)) { New-Item -ItemType Directory -Path $dd -Force | Out-Null }
576
578
  $need = $false
577
579
  if (-not (Test-Path -LiteralPath $d)) { $need = $true }
578
- elseif ((Get-FileHash -LiteralPath $f.FullName -Algorithm SHA256).Hash -ne (Get-FileHash -LiteralPath $d -Algorithm SHA256).Hash) { $need = $true }
580
+ elseif ((Get-FileHashFast $f.FullName) -ne (Get-FileHashFast $d)) { $need = $true }
579
581
  if ($need) {
580
582
  # 覆盖前备份本机已有文件
581
583
  if (Test-Path -LiteralPath $d) {
@@ -843,6 +845,7 @@ if ($dropped.Count -gt 0) { Ok "已剔除 $($dropped.Count) 个实验性 bundle
843
845
  $localPluginMap = [ordered]@{
844
846
  'dsh-our-free-model-2.8.0' = 'dsh-our-free-model'
845
847
  'dsh-purge-1.4.0' = 'dsh-purge'
848
+ 'dsh-config-sync-plugin-0.3.62' = 'dsh-config-sync-plugin'
846
849
  'dsh-config-sync-plugin-0.3.61' = 'dsh-config-sync-plugin'
847
850
  'dsh-config-sync-plugin-0.3.59' = 'dsh-config-sync-plugin'
848
851
  'dsh-config-sync-plugin-0.3.58' = 'dsh-config-sync-plugin'
@@ -1187,8 +1190,8 @@ function Get-ArchivePluginVersion([string]$archPath, [string]$dirName) {
1187
1190
  try { Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop } catch { }
1188
1191
  $zip = [IO.Compression.ZipFile]::OpenRead($archPath)
1189
1192
  try {
1190
- $entry = $zip.Entries | Where-Object { $_.FullName -match ("(^|/)" + [regex]::Escape($dirName) + "/package\.json$") } | Select-Object -First 1
1191
- if (-not $entry) { $entry = $zip.Entries | Where-Object { $_.FullName -match '^(package/)?package\.json$' } | Select-Object -First 1 }
1193
+ $entry = $zip.Entries | Where-Object { $_.FullName -match ("(^|[\\/])" + [regex]::Escape($dirName) + "[\\/]package\.json$") } | Select-Object -First 1
1194
+ if (-not $entry) { $entry = $zip.Entries | Where-Object { $_.FullName -match '^(package[\\/])?package\.json$' } | Select-Object -First 1 }
1192
1195
  if (-not $entry) { return $null }
1193
1196
  $sr = New-Object IO.StreamReader($entry.Open())
1194
1197
  try { return [string](($sr.ReadToEnd()) | ConvertFrom-Json).version } finally { $sr.Dispose() }
@@ -1461,4 +1464,4 @@ if ($hostAppVersion) { Say "版本:本机 app = $hostAppVersion(仓库契约
1461
1464
  Say "验证:插件页看 20 项是否齐全、按要求检查 cordis.patch.yml 里的开关是否生效、Skill 列表能列出。"
1462
1465
  Say "如需回滚:把 $BackupDir 里的文件拷回原位置(工作区资料在 workspace\ 子目录、登记表备份为 workspace-registry-before.json)。"
1463
1466
 
1464
- exit 0
1467
+ exit 0