dsh-config-sync-plugin 0.3.67 → 0.3.69

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/runtime/apply.ps1 CHANGED
@@ -672,6 +672,16 @@ function Sync-ConversationApply {
672
672
  Warn ('没找到可用于修正会话头部的执行器(Node / 客户端 Electron 都没找到,AppRoot={0}),本次未修正' -f $AppRoot)
673
673
  }
674
674
  }
675
+ # 5) billion-context 压缩状态:DSH 原生 compaction 被 bili 接管后,真正的压缩记录在 bili 自己的
676
+ # SQLite(…\billion-context\sessions\index.db)里,不在 .dsh 下。不带这份状态,长会话在本机
677
+ # 继续时会以未压缩的全量 surface 发给 provider,报 CONTEXT_WINDOW_EXCEEDED。
678
+ $biliRepo = Join-Path $convDir 'billion_context'
679
+ if (Test-Path -LiteralPath $biliRepo) {
680
+ $bs = Invoke-BiliStateSync -Mode 'import' -RepoDir $biliRepo -AppRoot $AppRoot -ScriptRoot $PSScriptRoot -RepoRoot $RepoRoot
681
+ Write-BiliStateSyncReport $bs $DshHome
682
+ } else {
683
+ Say ' 仓库里没有 billion-context 压缩状态(首次导出前为空,属正常)'
684
+ }
675
685
  Ok ('会话数据全量还原:{0} 个目录映射,写入/更新 {1} 个文件、备份 {2} 个(四块数据字节保真,会话只增不删)' -f $dirMap.Count, $nAdd, $nBk)
676
686
  }
677
687
 
@@ -888,9 +898,12 @@ if ($dropped.Count -gt 0) { Ok "已剔除 $($dropped.Count) 个实验性 bundle
888
898
  $localPluginMap = [ordered]@{
889
899
  'dsh-our-free-model-2.8.0' = 'dsh-our-free-model'
890
900
  'dsh-purge-1.4.0' = 'dsh-purge'
901
+ 'dsh-config-sync-plugin-0.3.69' = 'dsh-config-sync-plugin'
902
+ 'dsh-config-sync-plugin-0.3.68' = 'dsh-config-sync-plugin'
891
903
  'dsh-config-sync-plugin-0.3.67' = 'dsh-config-sync-plugin'
892
- 'dsh-config-sync-plugin-0.3.65' = 'dsh-config-sync-plugin'
893
- 'dsh-config-sync-plugin-0.3.64' = 'dsh-config-sync-plugin'
904
+ 'dsh-config-sync-plugin-0.3.66' = 'dsh-config-sync-plugin'
905
+ 'dsh-config-sync-plugin-0.3.65' = 'dsh-config-sync-plugin'
906
+ 'dsh-config-sync-plugin-0.3.64' = 'dsh-config-sync-plugin'
894
907
  'dsh-config-sync-plugin-0.3.63' = 'dsh-config-sync-plugin'
895
908
  'dsh-config-sync-plugin-0.3.62' = 'dsh-config-sync-plugin'
896
909
  'dsh-config-sync-plugin-0.3.61' = 'dsh-config-sync-plugin'
@@ -1332,6 +1345,7 @@ if ($needExtract.Count -gt 0) {
1332
1345
  Ok "已解压并部署:$final"
1333
1346
  } else {
1334
1347
  Warn "仓库里没有 $dirName 的归档,跳过(该插件会装不上)"
1348
+ Add-SyncNotice -Kind 'plugin-missing' -Path $dirName -Reason ('仓库的 local-plugins\ 里没有这个源码插件包的归档(.tgz/.zip),本机装不上。在主力机跑 capture.ps1 -PackLocalPlugins 打包并推送,然后在本机重新拉取一次。')
1335
1349
  }
1336
1350
  }
1337
1351
  Remove-Item -LiteralPath $staging -Recurse -Force -ErrorAction SilentlyContinue
@@ -1479,8 +1493,21 @@ foreach ($name in $deps.PSObject.Properties.Name) {
1479
1493
  $probe = Join-Path $ProfileDir ("node_modules\" + ($name -replace '/', '\'))
1480
1494
  if (-not (Test-Path -LiteralPath $probe)) { $missing += $name }
1481
1495
  }
1482
- if ($missing.Count -eq 0) { Ok "全部 $(@($deps.PSObject.Properties).Count) 个插件依赖已就位" }
1483
- else { Warn ("缺少 $($missing.Count) 个插件:" + ($missing -join ', ')) }
1496
+ if ($missing.Count -eq 0) {
1497
+ Ok "全部 $(@($deps.PSObject.Properties).Count) 个插件依赖已就位"
1498
+ } else {
1499
+ Warn ("缺少 $($missing.Count) 个插件:" + ($missing -join ', '))
1500
+ # 拉取只还原配置文件,不会替本机安装依赖:仓库里没有这些插件的实体(它们该由 pnpm install 从
1501
+ # registry 装,或从 local-plugins 的归档解压)。把每一个都记进未同步清单,面板会常驻提示
1502
+ # 「装好插件后再拉取一次」,否则用户只看到插件页少几项、不知道下一步做什么。
1503
+ foreach ($nm in $missing) {
1504
+ $why = '插件未安装到本机:拉取不会替你装依赖。'
1505
+ if ($SkipInstall) { $why += '本次带了 -SkipInstall,pnpm install 被跳过;' }
1506
+ $why += '在 profile 目录执行一次 pnpm install(或去掉 -SkipInstall 重跑本脚本),装好后重新拉取一次。'
1507
+ Add-SyncNotice -Kind 'plugin-missing' -Path $nm -Reason $why
1508
+ }
1509
+ Warn '已把这些插件记进未同步清单(sync-notices.json),面板会一直提示到装好并重新拉取为止。'
1510
+ }
1484
1511
 
1485
1512
  # bundle 可解析性检查:清单里写了、本机却没有 → 启动期 entry loading 必挂(整个应用起不来,不是功能不可用)
1486
1513
  # 解析顺序与 DSH 一致:先 profile\node_modules(pnpm 装的),再 <AppRoot>\resources\app\dsh\node_modules(宿主自带)
@@ -1497,6 +1524,9 @@ if ($unresolved.Count -eq 0) {
1497
1524
  } else {
1498
1525
  Warn "以下 $($unresolved.Count) 个 bundle 在本机找不到,启动会在 entry loading 阶段失败:"
1499
1526
  $unresolved | ForEach-Object { Warn " - $_" }
1527
+ foreach ($ub in $unresolved) {
1528
+ Add-SyncNotice -Kind 'plugin-missing' -Path $ub -Reason ('bundle 在本机解析不到:插件没装好(pnpm install 没成功,或仓库里没有这个插件的归档)。装好后重新拉取一次;若它是宿主绑定的实验性 bundle,删掉本机 profile\package.json 里那一行。')
1529
+ }
1500
1530
  if (-not $ForceBundles) {
1501
1531
  Die ("已停止,先别启动。处理:①若上面「缺少插件」不为空,说明 pnpm install 没成功;" +
1502
1532
  "②若是宿主绑定的实验性 bundle,直接删掉本机 profile\package.json 里那一行;" +
@@ -437,6 +437,8 @@ function Sync-ConversationCapture {
437
437
  @{ Src = (Join-Path $DshHome 'storages\vision_router_session_policy\policies'); Dst = 'vision_router_session_policy'; Remap = $false }
438
438
  )
439
439
  $nAdd = 0; $nDel = 0
440
+ # 本次真正写入过的会话 id(用来只导出这些会话的 billion-context 压缩状态)
441
+ $touchedSids = [System.Collections.Generic.List[string]]::new()
440
442
  foreach ($b in $blocks) {
441
443
  $dstRoot = Join-Path $convDir $b.Dst
442
444
  if (-not (Test-Path -LiteralPath $b.Src)) { Warn ('本机没有会话数据块,跳过:{0}' -f $b.Src); continue }
@@ -472,6 +474,13 @@ function Sync-ConversationCapture {
472
474
  if (-not (Test-Path -LiteralPath $dd)) { New-Item -ItemType Directory -Path $dd -Force | Out-Null }
473
475
  $madeDirs[$dd] = $true
474
476
  }
477
+ if ($b.Dst -eq 'sessions') {
478
+ $rp = @($rel -split '\\')
479
+ if ($rp.Count -ge 2) {
480
+ $sid = [string]$rp[1]
481
+ if ($sid -and -not $touchedSids.Contains($sid)) { $touchedSids.Add($sid) | Out-Null }
482
+ }
483
+ }
475
484
  if (Test-SessionLogFile $rel) {
476
485
  $guardJobs.Add([ordered]@{ Src = $si.FullName; Dst = $d; WriteTo = $d }) | Out-Null
477
486
  $dstRels[$rel] = [IO.FileInfo]::new($d)
@@ -512,6 +521,16 @@ function Sync-ConversationCapture {
512
521
  }
513
522
  }
514
523
  }
524
+ # 4) billion-context 压缩状态:DSH 原生 compaction 被 bili 接管后,真正的压缩记录在 bili 自己的
525
+ # SQLite 里(不在 .dsh 下)。只带会话日志、不带这份状态,另一台机器会把未压缩的全量 surface
526
+ # 发给 provider 并报 CONTEXT_WINDOW_EXCEEDED。这里按会话导出 blocks/refs/summary。
527
+ if ($touchedSids.Count -gt 0) {
528
+ $biliRepo = Join-Path $convDir 'billion_context'
529
+ $bs = Invoke-BiliStateSync -Mode 'export' -RepoDir $biliRepo -Sessions $touchedSids.ToArray() -AppRoot $AppRoot -ScriptRoot $PSScriptRoot -RepoRoot $RepoRoot
530
+ Write-BiliStateSyncReport $bs $DshHome
531
+ } else {
532
+ Say ' 本次没有会话变动,跳过 billion-context 压缩状态导出'
533
+ }
515
534
  Ok ('会话数据全量同步:{0} 个目录映射,入库/更新 {1} 个文件、删除 {2} 个(四块数据全部字节保真)' -f $idxEntries.Count, $nAdd, $nDel)
516
535
  Say (' ' + (Get-TreeCmpSummary))
517
536
 
@@ -30,7 +30,9 @@ function Die($m) { Write-Host " [X] $m" -ForegroundColor Red; exit 1 }
30
30
  # too-large 超过单文件上限(capture 跳过 / push 前从索引剔除 / 历史里已存在)
31
31
  # skipped 被规则或占用跳过(不是失败,但用户该知道)
32
32
  # failed 写入失败、被远端拒绝等真失败
33
- # history 历史提交里已存在的超限文件(远端必然拒收,必须改写历史或换仓库)
33
+ # history 历史提交里已存在的超限文件(远端必然拒收,必须改写历史或换仓库)
34
+ # plugin-missing 插件没装在本机(拉取只还原配置,不装依赖;装完要再拉一次)
35
+ # context-state billion-context 的压缩状态没跟着过来(该会话可能报上下文超长)
34
36
  $script:SyncNoticeItems = New-Object 'System.Collections.ArrayList'
35
37
  $script:SyncNoticeHome = $null
36
38
  $script:SyncNoticeMode = ''
@@ -55,7 +57,7 @@ function Save-SyncNotices {
55
57
  $dir = Split-Path -Parent $p
56
58
  if ($dir -and -not (Test-Path -LiteralPath $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
57
59
  $byKind = [ordered]@{}
58
- foreach ($k in @('too-large', 'history', 'skipped', 'failed')) {
60
+ foreach ($k in @('too-large', 'history', 'skipped', 'failed', 'plugin-missing', 'context-state')) {
59
61
  $byKind[$k] = @($script:SyncNoticeItems | Where-Object { $_.kind -eq $k }).Count
60
62
  }
61
63
  $obj = [ordered]@{
@@ -108,6 +110,8 @@ function Get-SyncNoticesSummary($notices) {
108
110
  if ($bk.history -gt 0) { $parts += ("{0} 个历史提交里的超限文件" -f $bk.history) }
109
111
  if ($bk.skipped -gt 0) { $parts += ("{0} 个被规则跳过" -f $bk.skipped) }
110
112
  if ($bk.failed -gt 0) { $parts += ("{0} 个写入/推送失败" -f $bk.failed) }
113
+ if ($bk.'plugin-missing' -gt 0) { $parts += ("{0} 个插件没装" -f $bk.'plugin-missing') }
114
+ if ($bk.'context-state' -gt 0) { $parts += ("{0} 个会话缺压缩状态" -f $bk.'context-state') }
111
115
  return ($parts -join '、')
112
116
  }
113
117
 
@@ -1141,3 +1145,137 @@ function Write-SessionLogGuardReport($Guard, [string]$DshHome, [string]$Verb) {
1141
1145
  }
1142
1146
  }
1143
1147
 
1148
+
1149
+ # ── billion-context 压缩状态跨机搬运 ───────────────────────────────────────
1150
+ # 为什么需要:DSH 原生 compaction 被 billion-context 接管(compaction gate 把
1151
+ # dsh-compaction-basic / dsh-command-compact disabled 掉),真正的压缩记录存在
1152
+ # bili 自己的 SQLite(…\billion-context\sessions\index.db)里,不在 .dsh 下。
1153
+ # 只同步会话日志、不同步这份状态,另一台机器就会把未压缩的全量 surface 发给
1154
+ # provider,报 CONTEXT_WINDOW_EXCEEDED。这里按会话导出/导入 blocks+refs+content。
1155
+
1156
+ function Get-BiliStateToolPath([string]$scriptRoot, [string]$repoRoot) {
1157
+ $bases = @()
1158
+ if ($scriptRoot) {
1159
+ $bases += (Join-Path $scriptRoot 'tools')
1160
+ if ((Split-Path -Leaf $scriptRoot) -ne 'runtime') { $bases += (Join-Path $scriptRoot 'runtime\tools') }
1161
+ }
1162
+ if ($repoRoot) {
1163
+ $bases += (Join-Path $repoRoot 'tools')
1164
+ $bases += (Join-Path $repoRoot 'runtime\tools')
1165
+ }
1166
+ if ($MyInvocation.MyCommand.Path) {
1167
+ $here = Split-Path -Parent $MyInvocation.MyCommand.Path
1168
+ $bases += (Join-Path $here 'tools')
1169
+ }
1170
+ foreach ($b in $bases) {
1171
+ if (-not $b) { continue }
1172
+ $p = Join-Path $b 'bili-state.mjs'
1173
+ if (Test-Path -LiteralPath $p) { return $p }
1174
+ }
1175
+ return $null
1176
+ }
1177
+
1178
+ # 形状仿 Invoke-SessionLogGuard:spec/结果都走临时文件,执行器可能是 Electron GUI 子系统。
1179
+ function Invoke-BiliStateSync {
1180
+ param(
1181
+ [ValidateSet('export', 'import')][string]$Mode,
1182
+ [string]$RepoDir,
1183
+ [object[]]$Sessions,
1184
+ [string]$AppRoot,
1185
+ [string]$ScriptRoot,
1186
+ [string]$RepoRoot,
1187
+ [string]$BiliDir
1188
+ )
1189
+ $res = [ordered]@{ Ok = $true; Mode = $Mode; Exported = @(); Imported = @(); Missing = @(); Failed = @(); Skipped = $true; Reason = ''; NoBili = $false; BiliDir = ''; Bytes = 0 }
1190
+ if (-not $RepoDir) { $res.Reason = '没有指定压缩状态目录'; return $res }
1191
+ $tool = Get-BiliStateToolPath $ScriptRoot $RepoRoot
1192
+ if (-not $tool) { $res.Reason = '找不到 tools\bili-state.mjs'; return $res }
1193
+ $runner = Get-HostNodeRunner $AppRoot
1194
+ if (-not $runner) { $res.Reason = '这台机器既没有 Node 也找不到客户端本体'; return $res }
1195
+
1196
+ $stamp = Get-Date -Format 'yyyyMMddHHmmssfff'
1197
+ $specPath = Join-Path ([IO.Path]::GetTempPath()) ('dsh-bilistate-spec-{0}-{1}.json' -f $stamp, $PID)
1198
+ $outPath = Join-Path ([IO.Path]::GetTempPath()) ('dsh-bilistate-out-{0}-{1}.json' -f $stamp, $PID)
1199
+ $spec = [ordered]@{
1200
+ mode = $Mode
1201
+ repoDir = [string]$RepoDir
1202
+ }
1203
+ if ($BiliDir) { $spec.biliDir = [string]$BiliDir }
1204
+ if ($Sessions -and @($Sessions).Count -gt 0) { $spec.sessions = @($Sessions | ForEach-Object { [string]$_ }) }
1205
+ [IO.File]::WriteAllText($specPath, ($spec | ConvertTo-Json -Depth 5 -Compress), (New-Object Text.UTF8Encoding($false)))
1206
+
1207
+ $oldRunAsNode = $env:ELECTRON_RUN_AS_NODE
1208
+ try {
1209
+ if ($runner.Electron) { $env:ELECTRON_RUN_AS_NODE = '1' }
1210
+ else { Remove-Item Env:\ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue }
1211
+ & $runner.Exe $tool 'sync' $specPath $outPath *> $null
1212
+ $code = $LASTEXITCODE
1213
+ if (-not (Test-Path -LiteralPath $outPath)) {
1214
+ $res.Reason = ('压缩状态工具没有产出结果文件(执行器退出码 {0})' -f $code)
1215
+ return $res
1216
+ }
1217
+ $r = ([IO.File]::ReadAllText($outPath, [Text.Encoding]::UTF8)) | ConvertFrom-Json -ErrorAction Stop
1218
+ $res.Ok = [bool]$r.ok
1219
+ $res.NoBili = [bool]$r.noBili
1220
+ if ($r.biliDir) { $res.BiliDir = [string]$r.biliDir }
1221
+ $res.Exported = @($r.exported)
1222
+ $res.Imported = @($r.imported)
1223
+ $res.Missing = @($r.missing)
1224
+ $res.Failed = @($r.failed)
1225
+ foreach ($e in @($r.exported)) { if ($e -and $e.bytes) { $res.Bytes += [long]$e.bytes } }
1226
+ $res.Skipped = $false
1227
+ return $res
1228
+ } catch {
1229
+ $res.Reason = ('压缩状态工具执行出错:{0}' -f $_.Exception.Message)
1230
+ return $res
1231
+ } finally {
1232
+ if ($null -eq $oldRunAsNode) { Remove-Item Env:\ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue }
1233
+ else { $env:ELECTRON_RUN_AS_NODE = $oldRunAsNode }
1234
+ Remove-Item -LiteralPath $specPath -Force -ErrorAction SilentlyContinue
1235
+ Remove-Item -LiteralPath $outPath -Force -ErrorAction SilentlyContinue
1236
+ }
1237
+ }
1238
+
1239
+ # 把压缩状态搬运结果变成用户能看懂的提示;导入失败一律进 context-state 通知。
1240
+ function Write-BiliStateSyncReport($State, [string]$DshHome) {
1241
+ if (-not $State) { return }
1242
+ if ($State.Skipped) {
1243
+ Warn ('billion-context 压缩状态本次未搬运({0})' -f $State.Reason)
1244
+ return
1245
+ }
1246
+ if ($State.NoBili) {
1247
+ if ($State.Mode -eq 'import') {
1248
+ Ok ('本机没有 billion-context,跳过压缩状态导入(DSH 自带压缩会接管)')
1249
+ if ($DshHome) {
1250
+ Add-SyncNotice -Kind 'context-state' -Path 'billion-context' -Reason '本机没有 billion-context:会话压缩记录无处导入,DSH 自带压缩会接管;若长会话报上下文超长,在主力机重推一次或在配置里关掉 billion-context。'
1251
+ }
1252
+ } else {
1253
+ Ok ('本机没有 billion-context,跳过压缩状态导出')
1254
+ }
1255
+ return
1256
+ }
1257
+ if ($State.Mode -eq 'export') {
1258
+ $n = @($State.Exported).Count
1259
+ Ok ('billion-context 压缩状态(抓取):导出 {0} 个会话、{1:N1} MB' -f $n, ($State.Bytes / 1MB))
1260
+ foreach ($e in @($State.Exported)) {
1261
+ Ok (' {0}:blocks {1}、refs {2}、summary {3}' -f [string]$e.sessionId, $e.blocks, $e.refs, $e.content)
1262
+ }
1263
+ } else {
1264
+ $n = @($State.Imported).Count
1265
+ Ok ('billion-context 压缩状态(还原):导入 {0} 个会话' -f $n)
1266
+ foreach ($e in @($State.Imported)) {
1267
+ Ok (' {0}:blocks +{1}、refs +{2}、summary +{3}' -f [string]$e.sessionId, $e.blocks, $e.refs, $e.content)
1268
+ }
1269
+ }
1270
+ foreach ($m in @($State.Missing)) {
1271
+ Warn (' 仓库里没有这个会话的压缩记录:{0}(B 机继续该会话可能报上下文超长)' -f [string]$m)
1272
+ if ($DshHome -and $State.Mode -eq 'import') {
1273
+ Add-SyncNotice -Kind 'context-state' -Path ([string]$m) -Reason '会话压缩状态没同步过来:本机继续该会话可能报上下文超长。在主力机重推一次(抓取会带上压缩状态),或在本机设置 BILLION_CONTEXT_PLUGIN=0 让 DSH 原生压缩兜底。'
1274
+ }
1275
+ }
1276
+ foreach ($f in @($State.Failed)) {
1277
+ $sid = if ($f.sessionId) { [string]$f.sessionId } elseif ($f.file) { [string]$f.file } else { '(未知)' }
1278
+ Warn (' 压缩状态处理失败:{0}({1})' -f $sid, [string]$f.error)
1279
+ if ($DshHome) { Add-SyncNotice -Kind 'context-state' -Path $sid -Reason ('billion-context 压缩状态搬运失败:' + [string]$f.error) }
1280
+ }
1281
+ }
@@ -169,6 +169,8 @@ function Show-NoticesSummary {
169
169
  try { $n = Get-Content -LiteralPath $np -Raw -Encoding utf8 | ConvertFrom-Json } catch { return }
170
170
  if (-not $n -or [int]$n.total -le 0) { return }
171
171
  $groups = @(
172
+ @{ Kind = 'plugin-missing'; Title = '插件没装在本机(先装插件,再重新拉取一次)' }
173
+ @{ Kind = 'context-state'; Title = '会话缺 billion-context 压缩状态(可能报上下文超长)' }
172
174
  @{ Kind = 'history'; Title = '历史提交里的超限文件(远端会拒收,需换仓库或清史)' }
173
175
  @{ Kind = 'too-large'; Title = '超过单文件上限,未进仓库' }
174
176
  @{ Kind = 'failed'; Title = '写入/推送失败' }