dsh-profile-config-sync 0.4.1 → 0.6.40
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/LICENSE +2 -1
- package/README.en.md +167 -738
- package/README.md +238 -571
- package/client.js +721 -269
- package/cordis.patch.yml +1 -1
- package/docs/CHANGELOG.en.md +28 -0
- package/docs/CHANGELOG.md +80 -0
- package/docs/HISTORY.en.md +221 -0
- package/docs/HISTORY.md +252 -0
- package/docs/MULTI-PLATFORM.md +165 -0
- package/docs/REFERENCE.md +172 -0
- package/index.js +1247 -190
- package/package.json +11 -5
- package/runtime/apply.ps1 +79 -33
- package/runtime/atomic-write.mjs +57 -0
- package/runtime/capture.ps1 +188 -37
- package/runtime/contract.mjs +59 -7
- package/runtime/dsh-sync-common.ps1 +361 -22
- package/runtime/install-plugin.ps1 +94 -3
- package/runtime/live-log.mjs +75 -0
- package/runtime/platform.mjs +35 -0
- package/runtime/post-exit.ps1 +201 -28
- package/runtime/restore.ps1 +76 -8
- package/runtime/sync-engine.mjs +1324 -857
- package/runtime/sync.ps1 +192 -82
- package/runtime/tools/fix-session-cwd.mjs +12 -3
- package/runtime/tools/workspace-view.mjs +7 -3
- package/runtime/webdav.mjs +269 -23
package/runtime/capture.ps1
CHANGED
|
@@ -54,6 +54,12 @@ $ErrorActionPreference = 'Stop'
|
|
|
54
54
|
if (-not $RepoRoot) { $RepoRoot = $PSScriptRoot }
|
|
55
55
|
. (Join-Path $PSScriptRoot 'dsh-sync-common.ps1')
|
|
56
56
|
|
|
57
|
+
# 并发保护:同一 DSH 目录同时只允许一个同步动作(面板按钮 + 自动 watcher 很容易撞车)
|
|
58
|
+
if (-not (Lock-SyncRun $DshHome '抓取')) {
|
|
59
|
+
Warn "另一个同步动作正在进行(同一个 DSH 目录),本次 抓取 没有执行。等它结束后再试一次。"
|
|
60
|
+
exit 3
|
|
61
|
+
}
|
|
62
|
+
|
|
57
63
|
function Get-NormalizedHash($path) {
|
|
58
64
|
# 文本文件按"去掉 CRLF/LF 差异后的内容"比较,避免换行转换制造假变更;归档文件按原始字节比较
|
|
59
65
|
$ext = [IO.Path]::GetExtension($path).ToLower()
|
|
@@ -369,6 +375,8 @@ function Sync-ConversationCapture {
|
|
|
369
375
|
$dirRemap = @{} # 本机编码目录名 → 仓库稳定目录名
|
|
370
376
|
$cwdToken = @{} # 仓库稳定目录名 → 归一后的 cwd 占位符(让仓库内容与机器无关)
|
|
371
377
|
$skipSessDirs = @{} # 被“同步内容”取消勾选的工作区目录名(其会话不抓、也不入库)
|
|
378
|
+
$skipSessionIds = @{}
|
|
379
|
+
$keepSessionIds = @{}
|
|
372
380
|
if (Test-Path -LiteralPath $sessSrc) {
|
|
373
381
|
foreach ($d in @(Get-ChildItem -LiteralPath $sessSrc -Directory -Force | Sort-Object Name)) {
|
|
374
382
|
if (Test-DefaultWorkspaceDir $d.Name) {
|
|
@@ -378,9 +386,13 @@ function Sync-ConversationCapture {
|
|
|
378
386
|
}
|
|
379
387
|
if ($wsEncToId.ContainsKey($d.Name) -and -not (Test-SyncItemEnabled $Scope 'conversations' ([string]$wsEncToId[$d.Name]))) {
|
|
380
388
|
$skipSessDirs[$d.Name] = $true
|
|
389
|
+
foreach ($sd in @(Get-ChildItem -LiteralPath $d.FullName -Directory -Force -ErrorAction SilentlyContinue)) {
|
|
390
|
+
$skipSessionIds[$sd.Name] = $true
|
|
391
|
+
}
|
|
381
392
|
Warn ('跳过(未勾选同步)该工作区的会话:{0}' -f $d.Name)
|
|
382
393
|
if (Test-SyncDeleteCloud $Scope) {
|
|
383
394
|
$repoDir = Get-RepoSessionDirName 'ws' $wsEncToId[$d.Name] $d.Name
|
|
395
|
+
Add-SyncDeleteCloudPrefix ('conversations/sessions/' + $repoDir)
|
|
384
396
|
$t = Join-Path $convDir ('sessions' + [string][char]92 + $repoDir)
|
|
385
397
|
if (Test-Path -LiteralPath $t) {
|
|
386
398
|
Remove-Item -LiteralPath $t -Recurse -Force
|
|
@@ -389,6 +401,9 @@ function Sync-ConversationCapture {
|
|
|
389
401
|
}
|
|
390
402
|
continue
|
|
391
403
|
}
|
|
404
|
+
foreach ($sd in @(Get-ChildItem -LiteralPath $d.FullName -Directory -Force -ErrorAction SilentlyContinue)) {
|
|
405
|
+
$keepSessionIds[$sd.Name] = $true
|
|
406
|
+
}
|
|
392
407
|
if ($wsEncToId.ContainsKey($d.Name)) {
|
|
393
408
|
$repoDir = Get-RepoSessionDirName 'ws' $wsEncToId[$d.Name] $d.Name
|
|
394
409
|
$dirRemap[$d.Name] = $repoDir
|
|
@@ -428,6 +443,7 @@ function Sync-ConversationCapture {
|
|
|
428
443
|
$changed.Add('conversations/session-index.json') | Out-Null
|
|
429
444
|
}
|
|
430
445
|
|
|
446
|
+
foreach ($kid in @($keepSessionIds.Keys)) { if ($skipSessionIds.ContainsKey($kid)) { $skipSessionIds.Remove($kid) } }
|
|
431
447
|
# 2) 四块数据镜像,全部字节保真(SHA256 判差异,Copy-Item 原样拷)
|
|
432
448
|
# sessions 块的相对路径第一段是本机编码目录名,写进仓库前换成稳定名(见 Get-RepoSessionDirName)
|
|
433
449
|
$blocks = @(
|
|
@@ -452,6 +468,10 @@ function Sync-ConversationCapture {
|
|
|
452
468
|
if (Test-DefaultWorkspaceDir $parts[0]) { continue }
|
|
453
469
|
# 该工作区的会话被取消勾选:整块不抓(目录名保持本机编码,绝不能原样入库)
|
|
454
470
|
if ($b.Remap -and $skipSessDirs.ContainsKey($parts[0])) { continue }
|
|
471
|
+
if (-not $b.Remap -and ($b.Dst -eq 'session_projcache' -or $b.Dst -eq 'vision_router_session_policy')) {
|
|
472
|
+
$sidPart = [IO.Path]::GetFileNameWithoutExtension($parts[0])
|
|
473
|
+
if ($skipSessionIds.ContainsKey($sidPart)) { continue }
|
|
474
|
+
}
|
|
455
475
|
if ($b.Remap -and $dirRemap.ContainsKey($parts[0])) { $parts[0] = $dirRemap[$parts[0]] }
|
|
456
476
|
$rel = ($parts -join '\')
|
|
457
477
|
$srcRels[$rel] = $f
|
|
@@ -538,7 +558,9 @@ function Sync-ConversationCapture {
|
|
|
538
558
|
# 对不上工作区的 passthrough 目录不动(那种目录在 B 机本来也认不出)。
|
|
539
559
|
if ($cwdToken.Count -gt 0) {
|
|
540
560
|
$spec = [ordered]@{ home = $convDir; dirs = $cwdToken } | ConvertTo-Json -Depth 4 -Compress
|
|
541
|
-
|
|
561
|
+
# 文件名必须唯一:面板手动推送与退出后自动推送可能同时跑,固定名会互相覆盖 spec,
|
|
562
|
+
# 且 554 行的清理会把对方正要用的文件删掉(会话头就漏归一了)。
|
|
563
|
+
$specPath = Join-Path ([IO.Path]::GetTempPath()) ('dsh-repo-cwd-{0}-{1}.json' -f (Get-Date -Format 'yyyyMMddHHmmssfff'), $PID)
|
|
542
564
|
[IO.File]::WriteAllText($specPath, $spec, (New-Object Text.UTF8Encoding($false)))
|
|
543
565
|
# 辅助脚本优先用「脚本自己旁边」的那份(仓库可能是个刚 clone 下来、还没铺 tools 的副本)
|
|
544
566
|
$helper = Join-Path $PSScriptRoot 'tools\fix-session-cwd.mjs'
|
|
@@ -546,8 +568,25 @@ function Sync-ConversationCapture {
|
|
|
546
568
|
if (Test-Path -LiteralPath $helper) {
|
|
547
569
|
$nodeExe = Join-Path $AppRoot 'resources\runtime\primary-runtime\dependencies\node\bin\node.exe'
|
|
548
570
|
if (-not (Test-Path -LiteralPath $nodeExe)) { $nodeExe = (Get-Command node -ErrorAction SilentlyContinue).Source }
|
|
549
|
-
|
|
550
|
-
|
|
571
|
+
if (-not $nodeExe) {
|
|
572
|
+
# & $null 会抛「管道元素中的 & 后面的表达式生成无效的对象」并终止抓取(PS 5.1 实测)。
|
|
573
|
+
Warn ('找不到 node.exe,跳过仓库会话头归一(仓库里会存本机路径):' + $helper)
|
|
574
|
+
} else {
|
|
575
|
+
# native 命令往 stderr 写东西时,$ErrorActionPreference='Stop' 会把它包成终止错误(PS 5.1 实测:
|
|
576
|
+
# helper 里的 console.error 只要响一次,整次抓取就断在这里)。临时降级,finally 恢复。
|
|
577
|
+
$eapCwd = $ErrorActionPreference
|
|
578
|
+
$cwdCode = -1
|
|
579
|
+
try {
|
|
580
|
+
$ErrorActionPreference = 'Continue'
|
|
581
|
+
& $nodeExe $helper $specPath *>&1 | ForEach-Object { if ($_ -and ([string]$_).Trim()) { Say (' ' + ([string]$_).Trim()) } }
|
|
582
|
+
$cwdCode = $LASTEXITCODE
|
|
583
|
+
} catch {
|
|
584
|
+
Say (' 会话头归一调用异常:' + $_.Exception.Message)
|
|
585
|
+
} finally {
|
|
586
|
+
$ErrorActionPreference = $eapCwd
|
|
587
|
+
}
|
|
588
|
+
if ($cwdCode -ne 0) { Warn '仓库会话头 cwd 归一时有文件失败(上面有原因),那几个会话可能带着本机路径入库' }
|
|
589
|
+
}
|
|
551
590
|
} else {
|
|
552
591
|
Warn ('找不到 {0},跳过仓库会话头归一(仓库里会继续存本机路径)' -f $helper)
|
|
553
592
|
}
|
|
@@ -581,7 +620,44 @@ foreach ($d in @('profile', 'prompt', 'skills', 'presets', 'local-plugins', 'sto
|
|
|
581
620
|
if (-not (Test-Path -LiteralPath $p)) { New-Item -ItemType Directory -Path $p -Force | Out-Null }
|
|
582
621
|
}
|
|
583
622
|
|
|
623
|
+
# 清掉仓库里历史遗留的浏览器剖面 / 凭据库文件。
|
|
624
|
+
# 旧版本把 <DshHome>\plugin-data\browser-profiles 整棵抓进过仓库(本机 3,696 个文件 / 297MB,
|
|
625
|
+
# 含 Login Data 与 Cookies)。现在抓取规则已经不收,但**仓库里那份还在** —— 下一次
|
|
626
|
+
# git add -A 或 WebDAV 上传就会把它送出去。所以每次 capture 顺手清一遍,并如实报条数。
|
|
627
|
+
function Remove-BlockedRepoFiles([string]$root) {
|
|
628
|
+
if (-not (Test-Path -LiteralPath $root)) { return 0 }
|
|
629
|
+
$removed = 0
|
|
630
|
+
# 只回收「因为删文件才变空」的目录,且**绝不动**仓库顶层的骨架目录(profile/prompt/skills…)
|
|
631
|
+
# —— 早期版本在这里踩过:把所有空目录都删掉,紧接着写 profile\package.json 就报
|
|
632
|
+
# DirectoryNotFoundException,整次抓取中断。
|
|
633
|
+
$touched = New-Object System.Collections.Generic.HashSet[string]
|
|
634
|
+
$all = @(Get-ChildItem -LiteralPath $root -Recurse -File -Force -ErrorAction SilentlyContinue)
|
|
635
|
+
foreach ($f in $all) {
|
|
636
|
+
$rel = Get-RelPath $root $f.FullName
|
|
637
|
+
if (Test-BlockedProfilePath $rel) {
|
|
638
|
+
$parent = $f.DirectoryName
|
|
639
|
+
try { Remove-Item -LiteralPath $f.FullName -Force -ErrorAction Stop; $removed++; if ($parent) { [void]$touched.Add($parent) } } catch { }
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
foreach ($d in @($touched | Sort-Object { $_.Length } -Descending)) {
|
|
643
|
+
$cur = $d
|
|
644
|
+
while ($cur -and $cur.Length -gt $root.Length) {
|
|
645
|
+
if (-not (Test-Path -LiteralPath $cur)) { $cur = [IO.Path]::GetDirectoryName($cur); continue }
|
|
646
|
+
if ([IO.Path]::GetDirectoryName($cur).TrimEnd('\', '/') -eq $root.TrimEnd('\', '/')) { break }
|
|
647
|
+
if (@(Get-ChildItem -LiteralPath $cur -Force -ErrorAction SilentlyContinue).Count -gt 0) { break }
|
|
648
|
+
try { Remove-Item -LiteralPath $cur -Force -ErrorAction Stop } catch { break }
|
|
649
|
+
$cur = [IO.Path]::GetDirectoryName($cur)
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if ($removed -gt 0) {
|
|
653
|
+
Warn ("仓库里有 $removed 个浏览器剖面/凭据库文件(旧版本抓的),已删除;它们不该离开本机。")
|
|
654
|
+
}
|
|
655
|
+
return $removed
|
|
656
|
+
}
|
|
657
|
+
|
|
584
658
|
$changed = New-Object System.Collections.Generic.List[string]
|
|
659
|
+
# 抓取前先清理(在 profile/prompt 组之前做,免得刚写进去又被删)
|
|
660
|
+
[void](Remove-BlockedRepoFiles $RepoRoot)
|
|
585
661
|
|
|
586
662
|
# -WorkspaceOnly:只抓工作区 + 会话(B 机没装 DSH 也能先还原资料),抓完直接给提交指引并结束
|
|
587
663
|
if ($WorkspaceOnly) {
|
|
@@ -671,6 +747,24 @@ function CopyTracked($src, $dst, $label) {
|
|
|
671
747
|
Ok ("更新 " + $label)
|
|
672
748
|
}
|
|
673
749
|
|
|
750
|
+
# 文本文件的「令牌化」复制:把本机根路径换成 {{APP_ROOT}} / {{DSH_HOME}} / {{WORKSPACE_HOME}} / {{ROOT:x}} 再入库。
|
|
751
|
+
# 为什么单独一个函数:CopyTracked 是原样复制(profile 里的 link 路径另有 Convert-AppRootText 处理),
|
|
752
|
+
# 而 prompt/AGENTS.md 里写的往往是「工作区在 D:\...」这类绝对路径 —— 原样入库后,另一台机器拉下来
|
|
753
|
+
# 看到的是上一台机器的路径。JS 引擎(macOS/Linux)一直是令牌化的,这里补齐,两边口径一致。
|
|
754
|
+
function CopyTrackedTokenized($src, $dst, $label, $roots) {
|
|
755
|
+
$mine = Get-TrackedText $src
|
|
756
|
+
$tokenText = ConvertTo-TokenText $mine.Text $roots
|
|
757
|
+
if (Test-Path -LiteralPath $dst) {
|
|
758
|
+
if ((Get-RepoText $dst) -ceq $tokenText) {
|
|
759
|
+
Say (" = " + $label + "(无变化)")
|
|
760
|
+
return
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
[IO.File]::WriteAllText($dst, $tokenText, (New-Object Text.UTF8Encoding($mine.Bom, $false)))
|
|
764
|
+
$changed.Add($label) | Out-Null
|
|
765
|
+
Ok ("更新 " + $label)
|
|
766
|
+
}
|
|
767
|
+
|
|
674
768
|
if (Test-SyncGroupEnabled $Scope 'profile') {
|
|
675
769
|
# 1) profile 配置
|
|
676
770
|
# package.json 里的 link: 指向的是「本机客户端的绝对路径」,入库存成 {{APP_ROOT}}/ 前缀。
|
|
@@ -684,6 +778,10 @@ foreach ($dirName in @('dsh-our-free-model-2.8.0', 'dsh-purge-1.1.92')) {
|
|
|
684
778
|
$pkgRaw = [regex]::Replace($pkgRaw, $pattern, ('link:' + $AppRootToken + '/' + $dirName), 'IgnoreCase')
|
|
685
779
|
}
|
|
686
780
|
if ($pkgRaw) {
|
|
781
|
+
# link: 也可能指向 userHome 下的本地插件(实测:@local/dsh-personal → C:/Users/<user>/AppData/Local/dsh-personal)。
|
|
782
|
+
# 只归一 appRoot 会让这条路径原样入库,另一台机器 pnpm install 直接失败。
|
|
783
|
+
$pkgRoots = Get-SyncRoots $DshHome $AppRoot $WorkspaceHome
|
|
784
|
+
$pkgRaw = ConvertTo-TokenText $pkgRaw $pkgRoots
|
|
687
785
|
$norm = $pkgRaw -replace "`r`n", "`n"
|
|
688
786
|
$dst = Join-Path $RepoRoot 'profile\package.json'
|
|
689
787
|
$existing = $null
|
|
@@ -691,14 +789,21 @@ if ($pkgRaw) {
|
|
|
691
789
|
if ($null -ne $existing -and $existing -eq $norm) {
|
|
692
790
|
Say " = profile\package.json(无变化)"
|
|
693
791
|
} else {
|
|
694
|
-
|
|
792
|
+
Write-FileAtomic $dst $norm (New-Object Text.UTF8Encoding($false, $false))
|
|
695
793
|
$changed.Add('profile\package.json') | Out-Null
|
|
696
794
|
Ok "更新 profile\package.json(link 路径已归一为 $AppRootToken)"
|
|
697
795
|
}
|
|
698
796
|
}
|
|
699
797
|
foreach ($f in @('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'cordis.yml', 'cordis.patch.yml')) {
|
|
700
798
|
$src = Join-Path $ProfileDir $f
|
|
701
|
-
|
|
799
|
+
# 这 4 个文件里会有「本机绝对路径」(实测 cordis.patch.yml 里 path: C:\Users\<user>\bin\pwsh7.cmd)。
|
|
800
|
+
# 原样拷会把那台机器的路径搬到另一台,那边没有这个文件 → 工具起不来。
|
|
801
|
+
# 所以入库前把根路径换成占位符({{APP_ROOT}} / {{DSH_HOME}} / {{WORKSPACE_HOME}} / {{ROOT:*}}),
|
|
802
|
+
# restore / apply 写回本机时再展开。非路径内容逐字节不变。
|
|
803
|
+
if (Test-Path -LiteralPath $src) {
|
|
804
|
+
$rootSet = Get-SyncRoots $DshHome $AppRoot $WorkspaceHome
|
|
805
|
+
CopyTrackedTokenized $src (Join-Path $RepoRoot "profile\$f") "profile\$f" $rootSet
|
|
806
|
+
}
|
|
702
807
|
elseif (Test-Path -LiteralPath (Join-Path $RepoRoot "profile\$f")) {
|
|
703
808
|
Warn "本机缺少 profile\$f,仓库里保留的是上一次的副本(该机器 apply 时会把它铺过来)"
|
|
704
809
|
}
|
|
@@ -713,13 +818,21 @@ if (-not $hostAppVersion) {
|
|
|
713
818
|
Warn "读不到 app 版本($AppRoot\resources\app\package.json),跳过 host-contract.json"
|
|
714
819
|
} else {
|
|
715
820
|
$contractText = ("{`n `"appVersion`": `"$hostAppVersion`",`n `"electronVersion`": `"$(Get-HostElectronVersion $AppRoot)`"`n}`n")
|
|
716
|
-
$
|
|
821
|
+
$existingDoc = $null
|
|
717
822
|
if (Test-Path -LiteralPath $contractPath) {
|
|
718
|
-
try { $
|
|
823
|
+
try { $existingDoc = Get-Content -LiteralPath $contractPath -Raw -Encoding utf8 | ConvertFrom-Json } catch { $existingDoc = $null }
|
|
719
824
|
}
|
|
720
|
-
if ($
|
|
721
|
-
|
|
722
|
-
|
|
825
|
+
$existing = if ($existingDoc) { [string]$existingDoc.appVersion } else { $null }
|
|
826
|
+
# 老规矩是「已存在且不同 → 保持不变」,本意是防止较旧那台把契约拉低;
|
|
827
|
+
# 但它同时让错误值永远卡住:上游手写的契约把 Electron 版本塞进 appVersion(实测 44.7.0),
|
|
828
|
+
# 于是每次 capture 都只告警不改写,另一台 apply 永远判「两端不是同一版」而拒绝同步。
|
|
829
|
+
# 现在交给 Test-ContractStale 判:老格式/更旧的契约重写,更新的契约保留。
|
|
830
|
+
# 版本相同也走「按现状写一遍」的分支(相同内容不会产生 diff,只是把形状补齐成现代格式)。
|
|
831
|
+
$stale = Test-ContractStale $existingDoc $hostAppVersion
|
|
832
|
+
if ($stale -or ($existing -eq $hostAppVersion)) {
|
|
833
|
+
if ($stale -and $existing -and ($existing -ne $hostAppVersion)) {
|
|
834
|
+
Warn "仓库契约 app = $existing,本机 app = $hostAppVersion:按本机版本重写契约(旧值不可信或更旧)"
|
|
835
|
+
}
|
|
723
836
|
$norm = $contractText -replace "`r`n", "`n"
|
|
724
837
|
$now = if (Test-Path -LiteralPath $contractPath) { ([IO.File]::ReadAllText($contractPath) -replace "`r`n", "`n") } else { '' }
|
|
725
838
|
if ($now -ceq $norm) {
|
|
@@ -729,6 +842,8 @@ if (-not $hostAppVersion) {
|
|
|
729
842
|
$changed.Add('profile\host-contract.json') | Out-Null
|
|
730
843
|
Ok "写入 profile\host-contract.json(app = $hostAppVersion)"
|
|
731
844
|
}
|
|
845
|
+
} else {
|
|
846
|
+
Warn "仓库契约 app = $existing,本机 app = $hostAppVersion(契约更新,保持不变;对齐后再 capture)"
|
|
732
847
|
}
|
|
733
848
|
}
|
|
734
849
|
|
|
@@ -739,7 +854,8 @@ if (Test-SyncGroupEnabled $Scope 'prompt') {
|
|
|
739
854
|
foreach ($f in @('AGENTS.md', 'prompt-inject.md')) {
|
|
740
855
|
if (-not (Test-SyncItemEnabled $Scope 'prompt' $f)) { Skip-SyncItem $Scope $RepoRoot 'prompt' $f ("prompt\" + $f); continue }
|
|
741
856
|
$src = Join-Path $DshHome $f
|
|
742
|
-
|
|
857
|
+
# 提示文件里常写绝对路径(工作区在哪个盘):入库前换成占位符,落地时按本机根展开
|
|
858
|
+
if (Test-Path -LiteralPath $src) { CopyTrackedTokenized $src (Join-Path $RepoRoot "prompt\$f") "prompt\$f" (Get-SyncRoots $DshHome $AppRoot $WorkspaceHome) }
|
|
743
859
|
elseif (Test-Path -LiteralPath (Join-Path $RepoRoot "prompt\$f")) {
|
|
744
860
|
Warn "本机缺少 prompt\$f,仓库里保留的是上一次的副本"
|
|
745
861
|
}
|
|
@@ -747,6 +863,27 @@ foreach ($f in @('AGENTS.md', 'prompt-inject.md')) {
|
|
|
747
863
|
|
|
748
864
|
} else { Skip-SyncGroup $Scope $RepoRoot 'prompt' }
|
|
749
865
|
|
|
866
|
+
# 目录型内容(skills / presets)逐文件过凭据闸门。
|
|
867
|
+
# 旧写法是 Copy-Item -Recurse 整树直拷:`.env`、含 ghp_ 令牌的脚本会原样落进仓库工作区,
|
|
868
|
+
# 只剩提交前那道扫描兜底,而那道兜底本身有「>8MB / 含 NUL 直接放行」的旁路。
|
|
869
|
+
# 这里先挡一次,被挡下的写进日志让用户知道少了什么。
|
|
870
|
+
function Copy-SyncTreeFiltered([string]$SrcDir, [string]$DstDir, [string]$Label) {
|
|
871
|
+
if (Test-Path -LiteralPath $DstDir) { Remove-Item -LiteralPath $DstDir -Recurse -Force }
|
|
872
|
+
New-Item -ItemType Directory -Path $DstDir -Force | Out-Null
|
|
873
|
+
Get-ChildItem -LiteralPath $SrcDir -Recurse -File -Force -ErrorAction SilentlyContinue | ForEach-Object {
|
|
874
|
+
$rel = Get-RelPath $SrcDir $_.FullName
|
|
875
|
+
if (-not $rel) { return }
|
|
876
|
+
if (Test-SyncExtraSecret $_.FullName $DshHome) {
|
|
877
|
+
Warn ($Label + ' 跳过含凭据/私密文件:' + $rel)
|
|
878
|
+
return
|
|
879
|
+
}
|
|
880
|
+
$outFile = Join-Path $DstDir $rel
|
|
881
|
+
$outParent = Split-Path -Parent $outFile
|
|
882
|
+
if ($outParent -and -not (Test-Path -LiteralPath $outParent)) { New-Item -ItemType Directory -Path $outParent -Force | Out-Null }
|
|
883
|
+
Copy-Item -LiteralPath $_.FullName -Destination $outFile -Force
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
750
887
|
# 3) Skills(镜像)
|
|
751
888
|
if (Test-SyncGroupEnabled $Scope 'skills') {
|
|
752
889
|
$skillsSrc = Join-Path $DshHome 'skills'
|
|
@@ -756,8 +893,7 @@ if (Test-Path -LiteralPath $skillsSrc) {
|
|
|
756
893
|
if (-not (Test-SyncItemEnabled $Scope 'skills' $_.Name)) { Skip-SyncItem $Scope $RepoRoot 'skills' $_.Name ("skills\" + $_.Name); return }
|
|
757
894
|
$dstDir = Join-Path $skillsDst $_.Name
|
|
758
895
|
if (-not (Test-Path -LiteralPath $dstDir)) { $changed.Add("skills\$($_.Name)") | Out-Null }
|
|
759
|
-
|
|
760
|
-
Copy-Item -LiteralPath $_.FullName -Destination $dstDir -Recurse -Force
|
|
896
|
+
Copy-SyncTreeFiltered $_.FullName $dstDir ('skills\' + $_.Name)
|
|
761
897
|
NormalizeTree $dstDir
|
|
762
898
|
}
|
|
763
899
|
$count = (Get-ChildItem -LiteralPath $skillsSrc -Directory -Force | Measure-Object).Count
|
|
@@ -783,8 +919,7 @@ if (Test-Path -LiteralPath $presetSrc) {
|
|
|
783
919
|
Get-ChildItem -LiteralPath $presetSrc -Directory -Force | ForEach-Object {
|
|
784
920
|
if (-not (Test-SyncItemEnabled $Scope 'presets' $_.Name)) { Skip-SyncItem $Scope $RepoRoot 'presets' $_.Name ("presets\" + $_.Name); return }
|
|
785
921
|
$dstDir = Join-Path $presetDst $_.Name
|
|
786
|
-
|
|
787
|
-
Copy-Item -LiteralPath $_.FullName -Destination $dstDir -Recurse -Force
|
|
922
|
+
Copy-SyncTreeFiltered $_.FullName $dstDir ('presets\' + $_.Name)
|
|
788
923
|
NormalizeTree $dstDir
|
|
789
924
|
}
|
|
790
925
|
Ok "已抓取 Agent 预设:$((Get-ChildItem -LiteralPath $presetSrc -Directory -Force | Select-Object -ExpandProperty Name) -join ', ')"
|
|
@@ -816,22 +951,7 @@ if (Test-SyncGroupEnabled $Scope 'settings') {
|
|
|
816
951
|
Save-SyncRoots $DshHome $roots | Out-Null
|
|
817
952
|
Ok ('路径根:appRoot=' + $roots.appRoot + ';dshHome=' + $roots.dshHome + ';workspaceHome=' + $roots.workspaceHome + '(已写入 config-sync-roots.json)')
|
|
818
953
|
|
|
819
|
-
$settingsMap =
|
|
820
|
-
@{ Repo = 'settings\our-free-model.json'; Src = (Join-Path $DshHome 'our-free-model\settings.json'); Label = 'our-free-model 插件设置' },
|
|
821
|
-
@{ Repo = 'settings\comfyui-workflows.json'; Src = (Join-Path $DshHome 'data\dsh-comfyui\workflows.json'); Label = 'ComfyUI 工作流库' },
|
|
822
|
-
@{ Repo = 'settings\dsh-pet-main-config.jsonc'; Src = (Join-Path $DshHome 'dsh-pet\main-config.jsonc'); Label = '桌宠配置' },
|
|
823
|
-
@{ Repo = 'settings\dsh-market-state.json'; Src = (Join-Path $DshHome ("profiles\" + $ProfileName + '\.dsh-market\state.json')); Label = '插件市场状态' },
|
|
824
|
-
@{ Repo = 'settings\dsh-pet-memory.json'; Src = (Join-Path $DshHome 'dsh-pet\memory.json'); Label = '桌宠记忆' },
|
|
825
|
-
@{ Repo = 'settings\our-free-model-picks.json'; Src = (Join-Path $DshHome 'our-free-model\picks.json'); Label = 'our-free-model 收藏' },
|
|
826
|
-
@{ Repo = 'settings\dsh-im-interface-language.json'; Src = (Join-Path $DshHome 'integrations\dsh-im\interface-language.json'); Label = 'dsh-im 界面语言' },
|
|
827
|
-
@{ Repo = 'settings\dsh-qq-config.json'; Src = (Join-Path $DshHome 'integrations\dsh-qq\config.json'); Label = 'QQ 集成配置' },
|
|
828
|
-
@{ Repo = 'settings\dsh-qq-workspaces.json'; Src = (Join-Path $DshHome 'integrations\dsh-qq\workspaces.json'); Label = 'QQ 集成工作区' },
|
|
829
|
-
@{ Repo = 'settings\redteam-preset-declare.json'; Src = (Join-Path $DshHome 'redteam\preset-declare.json'); Label = '红队预设声明' },
|
|
830
|
-
@{ Repo = 'settings\task-board-ledger.json'; Src = (Join-Path $DshHome 'task-board\ledger-v2.json'); Label = '任务板台账' },
|
|
831
|
-
@{ Repo = 'settings\task-board-scheduler.json'; Src = (Join-Path $DshHome 'task-board\scheduler-v2.json'); Label = '任务板调度' },
|
|
832
|
-
@{ Repo = 'settings\dsh-workspaces.json'; Src = (Join-Path $DshHome 'storages\workspace.json'); Label = 'DSH 工作区登记' },
|
|
833
|
-
@{ Repo = 'settings\workspace-archives.json'; Src = (Join-Path $DshHome 'dsh-session-manager\workspace-archives.v1.json'); Label = 'DSH 工作区隐藏状态' }
|
|
834
|
-
)
|
|
954
|
+
$settingsMap = Get-SyncSettingsMap $DshHome $ProfileName
|
|
835
955
|
foreach ($m in $settingsMap) {
|
|
836
956
|
if (-not (Test-SyncItemEnabled $Scope 'settings' ($m.Repo -replace '^settings\\', ''))) {
|
|
837
957
|
Skip-SyncItem $Scope $RepoRoot 'settings' $m.Repo $m.Repo
|
|
@@ -841,6 +961,10 @@ if (Test-SyncGroupEnabled $Scope 'settings') {
|
|
|
841
961
|
Warn ("本机没有 " + $m.Label + " 的源文件,跳过:" + $m.Src)
|
|
842
962
|
continue
|
|
843
963
|
}
|
|
964
|
+
if (Test-SyncExtraSecret $m.Src $DshHome) {
|
|
965
|
+
Warn ("设置文件含令牌或凭据,已跳过不进仓库:" + $m.Repo)
|
|
966
|
+
continue
|
|
967
|
+
}
|
|
844
968
|
$txt = [IO.File]::ReadAllText($m.Src)
|
|
845
969
|
if ($m.Repo -eq 'settings\our-free-model.json') {
|
|
846
970
|
# 这个文件里有插件自己每秒/每轮刷新的运行时字段,原样入库会导致每次 capture 都"有改动"
|
|
@@ -915,7 +1039,29 @@ if ($PackLocalPlugins) {
|
|
|
915
1039
|
$tgzPath = Join-Path $RepoRoot "local-plugins\$dirName.tgz"
|
|
916
1040
|
if (Test-Path -LiteralPath $tgzPath) { Remove-Item -LiteralPath $tgzPath -Force }
|
|
917
1041
|
if (Test-Path -LiteralPath $zipPath) { Remove-Item -LiteralPath $zipPath -Force }
|
|
918
|
-
|
|
1042
|
+
$stageRoot = Join-Path ([IO.Path]::GetTempPath()) ("dsh-lp-" + [guid]::NewGuid().ToString('N'))
|
|
1043
|
+
$stagePlugin = Join-Path $stageRoot $dirName
|
|
1044
|
+
try {
|
|
1045
|
+
New-Item -ItemType Directory -Path $stagePlugin -Force | Out-Null
|
|
1046
|
+
$skipSegs = @('.git', 'node_modules', 'releases', '.cache')
|
|
1047
|
+
Get-ChildItem -LiteralPath $linkPath -Recurse -File -Force -ErrorAction SilentlyContinue | ForEach-Object {
|
|
1048
|
+
$rel = Get-RelPath $linkPath $_.FullName
|
|
1049
|
+
if (-not $rel) { return }
|
|
1050
|
+
$segs = @($rel -split '[\\/]' | Where-Object { $_ })
|
|
1051
|
+
if ($segs | Where-Object { $skipSegs -contains $_.ToLowerInvariant() }) { return }
|
|
1052
|
+
if (Test-SyncExtraSecret $_.FullName $DshHome) {
|
|
1053
|
+
Warn ("本地插件 $dirName 跳过含凭据/私密文件:$rel")
|
|
1054
|
+
return
|
|
1055
|
+
}
|
|
1056
|
+
$dst = Join-Path $stagePlugin $rel
|
|
1057
|
+
$dDir = Split-Path -Parent $dst
|
|
1058
|
+
if (-not (Test-Path -LiteralPath $dDir)) { New-Item -ItemType Directory -Path $dDir -Force | Out-Null }
|
|
1059
|
+
Copy-Item -LiteralPath $_.FullName -Destination $dst -Force
|
|
1060
|
+
}
|
|
1061
|
+
Compress-Archive -LiteralPath $stagePlugin -DestinationPath $zipPath -CompressionLevel Optimal -Force
|
|
1062
|
+
} finally {
|
|
1063
|
+
if (Test-Path -LiteralPath $stageRoot) { Remove-Item -LiteralPath $stageRoot -Recurse -Force -ErrorAction SilentlyContinue }
|
|
1064
|
+
}
|
|
919
1065
|
$changed.Add("local-plugins\$dirName.zip") | Out-Null
|
|
920
1066
|
$ver = '?'
|
|
921
1067
|
$p = Join-Path $linkPath 'package.json'
|
|
@@ -970,7 +1116,7 @@ function CopyTrackedTokens($src, $dst, $label, $roots) {
|
|
|
970
1116
|
if (Test-Path -LiteralPath $dst) {
|
|
971
1117
|
if ((Get-RepoText $dst) -ceq $text) { Say (" = " + $label + "(无变化)"); return }
|
|
972
1118
|
}
|
|
973
|
-
|
|
1119
|
+
Write-FileAtomic $dst $text (New-Object Text.UTF8Encoding($hasBom, $false))
|
|
974
1120
|
$changed.Add($label) | Out-Null
|
|
975
1121
|
Ok ("更新 " + $label)
|
|
976
1122
|
}
|
|
@@ -1093,11 +1239,15 @@ if (-not (Test-SyncGroupEnabled $Scope 'extra') -or $ExtraCfg.extra.enabled -eq
|
|
|
1093
1239
|
}
|
|
1094
1240
|
Ok ('额外路径 ' + $p.id + ':目录,' + $nFiles + ' 个文件')
|
|
1095
1241
|
} else {
|
|
1096
|
-
$itemDst = Join-Path $exDst ($p.id + (
|
|
1242
|
+
$itemDst = Join-Path $exDst ($p.id + [IO.Path]::GetExtension($srcPath))
|
|
1097
1243
|
if ((Test-Path -LiteralPath $itemDst) -and (Get-Item -LiteralPath $itemDst -Force).PSIsContainer) { Remove-Item -LiteralPath $itemDst -Recurse -Force }
|
|
1098
|
-
if (Test-SyncExtraSecret $srcPath) {
|
|
1099
|
-
|
|
1100
|
-
|
|
1244
|
+
if (Test-SyncExtraSecret $srcPath $DshHome) {
|
|
1245
|
+
Warn ('额外路径 ' + $p.id + ':文件为本机私有或含令牌/凭据,已强制跳过不进仓库(若仓库此前存在副本请手动清理)')
|
|
1246
|
+
if (Test-Path -LiteralPath $itemDst) {
|
|
1247
|
+
Remove-Item -LiteralPath $itemDst -Force -ErrorAction SilentlyContinue
|
|
1248
|
+
$changed.Add('extra\' + (Split-Path -Leaf $itemDst) + '(拦截删除)') | Out-Null
|
|
1249
|
+
}
|
|
1250
|
+
continue
|
|
1101
1251
|
}
|
|
1102
1252
|
CopyTrackedTokens $srcPath $itemDst ('extra\' + (Split-Path -Leaf $itemDst)) $exRoots
|
|
1103
1253
|
$nFiles = 1; $nBytes = (Get-Item -LiteralPath $srcPath).Length
|
|
@@ -1253,5 +1403,6 @@ function Write-OutsideRootReport {
|
|
|
1253
1403
|
}
|
|
1254
1404
|
|
|
1255
1405
|
Write-OutsideRootReport
|
|
1406
|
+
Save-SyncDeleteCloudQueue $DshHome
|
|
1256
1407
|
|
|
1257
1408
|
exit 0
|
package/runtime/contract.mjs
CHANGED
|
@@ -33,6 +33,12 @@ export function readContract(repoRoot) {
|
|
|
33
33
|
if (!existsSync(p)) return null
|
|
34
34
|
const doc = JSON.parse(readFileSync(p, 'utf8'))
|
|
35
35
|
if (!doc || typeof doc !== 'object') return null
|
|
36
|
+
// 老版本(上游 QcWyGm 时期)写的是一份残缺的「手写契约」:只有 appVersion + generatedAt + note,
|
|
37
|
+
// 没有 electronVersion / platforms / platformFamily。那种文件里的 appVersion 常被填成
|
|
38
|
+
// Electron 版本(实测 44.7.0),拿它跟本机 0.2.2-rc.5 比主版本必然「不一致」,
|
|
39
|
+
// 于是 pull 被永久 block。残缺契约一律当「没有契约」:不拦同步,下次推送按现在的结构重写一份。
|
|
40
|
+
const looksComplete = Array.isArray(doc.platforms) || typeof doc.electronVersion === 'string'
|
|
41
|
+
if (!looksComplete) return null
|
|
36
42
|
return {
|
|
37
43
|
appVersion: typeof doc.appVersion === 'string' ? doc.appVersion : '',
|
|
38
44
|
electronVersion: typeof doc.electronVersion === 'string' ? doc.electronVersion : '',
|
|
@@ -49,6 +55,43 @@ export function readContract(repoRoot) {
|
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
|
|
58
|
+
/**
|
|
59
|
+
* 取两个版本字符串里较大的一个(只升不降)。
|
|
60
|
+
*
|
|
61
|
+
* 规则:
|
|
62
|
+
* - 任一侧为空 → 用另一侧;
|
|
63
|
+
* - 数字点分段逐个比(1.10.0 > 1.9.9),缺省段按 0;
|
|
64
|
+
* - 带预发布后缀(-rc.1 / -beta)视为**比同版本正式版小**;两侧都是预发布时按字符串比较;
|
|
65
|
+
* - 完全比不出来(格式异常)→ 保持既有值,不做决定。
|
|
66
|
+
*/
|
|
67
|
+
function parseVersion(v) {
|
|
68
|
+
const text = String(v || '').trim()
|
|
69
|
+
if (!text) return null
|
|
70
|
+
const m = /^v?(\d+(?:\.\d+)*)(?:-([0-9A-Za-z.-]+))?/.exec(text)
|
|
71
|
+
if (!m) return null
|
|
72
|
+
return { nums: m[1].split('.').map((n) => Number(n) || 0), pre: m[2] || '' }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function pickHigherVersion(existing, local) {
|
|
76
|
+
if (!existing) return local
|
|
77
|
+
if (!local) return existing
|
|
78
|
+
if (existing === local) return existing
|
|
79
|
+
const a = parseVersion(existing)
|
|
80
|
+
const b = parseVersion(local)
|
|
81
|
+
if (!a || !b) return existing
|
|
82
|
+
const len = Math.max(a.nums.length, b.nums.length)
|
|
83
|
+
for (let i = 0; i < len; i += 1) {
|
|
84
|
+
const x = a.nums[i] || 0
|
|
85
|
+
const y = b.nums[i] || 0
|
|
86
|
+
if (x !== y) return y > x ? local : existing
|
|
87
|
+
}
|
|
88
|
+
// 数字段相同:正式版 > 预发布版
|
|
89
|
+
if (a.pre === b.pre) return existing
|
|
90
|
+
if (!a.pre) return existing
|
|
91
|
+
if (!b.pre) return local
|
|
92
|
+
return b.pre > a.pre ? local : existing
|
|
93
|
+
}
|
|
94
|
+
|
|
52
95
|
/**
|
|
53
96
|
* 把「本机实测事实」合成一份契约。
|
|
54
97
|
*
|
|
@@ -63,19 +106,28 @@ export function buildContract(local, repoRoot) {
|
|
|
63
106
|
if (existing && existing.platforms.length) {
|
|
64
107
|
for (const p of existing.platforms) platforms.add(p)
|
|
65
108
|
}
|
|
66
|
-
if (local && local.os)
|
|
109
|
+
if (local && local.os) {
|
|
110
|
+
// 大小写去重:contract 里可能已有 'windows'(老版本/手工改过),本机是 'Windows',
|
|
111
|
+
// 直接 add 会让同一个平台在清单里出现两次,跨端判断与面板显示都会看花。
|
|
112
|
+
const os = String(local.os)
|
|
113
|
+
const same = [...platforms].find((p) => String(p).toLowerCase() === os.toLowerCase())
|
|
114
|
+
if (!same) platforms.add(os)
|
|
115
|
+
}
|
|
67
116
|
|
|
68
|
-
// appVersion / electronVersion
|
|
69
|
-
//
|
|
117
|
+
// appVersion / electronVersion:只升不降。
|
|
118
|
+
// 旧规则是「已存在就不动」,本意是防止较旧那台把契约拉低 —— 但升级较新的那台时同样不动,
|
|
119
|
+
// 于是契约永远停在旧版本号:每次 pull 都报「两端版本不同」,直到有人手工改文件。
|
|
120
|
+
// 现在按版本段比较,取较大的那个;比不出来(预发布后缀、格式异常)时保持原值不动。
|
|
70
121
|
const existingVersion = existing ? existing.appVersion : ''
|
|
71
122
|
const localVersion = local ? String(local.dshVersion || '') : ''
|
|
72
|
-
const appVersion = existingVersion
|
|
123
|
+
const appVersion = pickHigherVersion(existingVersion, localVersion)
|
|
124
|
+
|
|
125
|
+
const existingElectron = existing ? existing.electronVersion : ''
|
|
126
|
+
const localElectron = local ? String(local.electronVersion || '') : ''
|
|
73
127
|
|
|
74
128
|
return {
|
|
75
129
|
appVersion,
|
|
76
|
-
electronVersion:
|
|
77
|
-
? existing.electronVersion
|
|
78
|
-
: String((local && local.electronVersion) || ''),
|
|
130
|
+
electronVersion: pickHigherVersion(existingElectron, localElectron),
|
|
79
131
|
platforms: [...platforms].sort(),
|
|
80
132
|
platformFamily: String((local && local.osFamily) || (existing && existing.platformFamily) || ''),
|
|
81
133
|
os: String((local && local.os) || (existing && existing.os) || ''),
|