dsh-config-sync-plugin 0.3.97 → 0.3.98

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,14 @@ 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
+ ### Default workspace conversations now sync; its files stay local (0.3.98)
261
+
262
+ Previously the whole default workspace was skipped. Reason: its session directory name is encoded from the **local WorkspaceHome absolute path** (`--C-Users-...-default-workspace--`); the two machines have different paths, so copying A's directory onto B only leaves a dead directory DSH cannot recognize (shows up as an empty default-workspace history). This version splits "sync conversations, not files":
263
+
264
+ 1. **Conversations use a cross-machine stable name**: capture writes the default-workspace session directory under the stable name `--default-workspace--` (alongside the existing `--ws-<id>--` and `--im--`), and normalizes the session header cwd to `{{WORKSPACE_HOME}}/default-workspace`; apply resolves the local default workspace path from **this machine's** `workspace.json` global.defaultWorkspaceId, re-encodes the directory name, fixes the header cwd, aligns projcache, and merges the session ids into the local default workspace registry entry — so DSH shows these conversations under the default workspace. No dependence on A's workspace ID.
265
+ 2. **Files stay local, registration kept**: capture skips default-workspace file copying by `defaultWorkspaceId` (files are per-machine), but keeps its `workspace-registry.json` entry — session ownership and sessionIds merging need it. apply's file restore likewise won't lay the default-workspace files slot back down.
266
+ 3. **Regression guards**: 10 selftest assertions (stable-name mapping, cwd normalization, local path resolution, re-encoding, sessionIds merge, files skip). Normal workspaces, im, all other mechanics and scope filters unchanged. On a fresh machine, let DSH start once to create its default-workspace registration before the first pull.
267
+
260
268
  ### Clicking × with pending changes now actively exits DSH and syncs immediately (0.3.97)
261
269
 
262
270
  In 0.3.96 the beacon could "check once on × and queue the watcher", but the watcher then sat in `wait`, **passively waiting for all DSH processes to disappear** before working. In practice clicking × leaves 7 orphaned processes (the plugin itself runs in one of them, the host child), so the normal close path often fails to clean up and the watcher just idles until its 30-minute timeout — appearing as "queued but nothing happens". This version closes the last gap:
@@ -745,6 +753,7 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
745
753
 
746
754
  | Date | Version | Summary |
747
755
  |---|---|---|
756
+ | 2026-11-25 | 0.3.98 | Default workspace conversations now sync (stable name --default-workspace--; apply re-encodes directory/cwd/projcache from local defaultWorkspaceId and merges sessionIds), files stay local |
748
757
  | 2026-11-25 | 0.3.97 | Clicking × with pending pull/push actively force-kills the DSH process family from a detached process (detached taskkill /F); the watcher runs immediately instead of waiting for orphaned processes |
749
758
  | 2026-11-24 | 0.3.96 | Page-unload beacon (pagehide→sendBeacon /auto-exit) replaces the dead Electron close hook; fast check (local tracking ref, no fetch) queues the watcher in milliseconds, finally fixing "× does not trigger" |
750
759
  | 2026-11-24 | 0.3.95 | Fix post-exit.ps1 losing UTF-8 BOM (PS5.1 decoded as GBK, 55 syntax errors, crashed on launch): restored BOM on all three executors, selftest adds full ps1 BOM assertion to prevent regression |
package/README.md CHANGED
@@ -277,6 +277,14 @@ 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.3.98)
281
+
282
+ 以前默认工作区整个跳过同步。原因:它的会话目录名由**本机 WorkspaceHome 绝对路径**编码(`--C-Users-...-default-workspace--`),两台机器路径不同,直接把 A 机的目录铺到 B 机只会留下 DSH 认不出的死目录(表现为默认工作区历史为空)。这次按「只同步会话、不同步资料」拆开处理:
283
+
284
+ 1. **会话走跨机稳定名**:capture 把默认工作区会话目录写成稳定名 `--default-workspace--`(和已有工作区的 `--ws-<id>--`、`--im--` 并列),会话头 cwd 归一到 `{{WORKSPACE_HOME}}/default-workspace`;apply 按**本机** `workspace.json` 的 `global.defaultWorkspaceId` 反查本机默认工作区路径,重编码目录名、改会话头 cwd、对齐 projcache,并把会话 id 并入本机默认工作区登记条目——DSH 才能把这些会话显示在默认工作区下。不依赖 A 机的工作区 ID。
285
+ 2. **资料不同步、登记保留**:capture 按 `defaultWorkspaceId` 跳过默认工作区的资料文件拷贝(资料各机独立),但 `workspace-registry.json` 里它的登记条目保留——会话归属与 sessionIds 合并不需要它。apply 侧资料还原也不会把默认工作区资料槽铺回来。
286
+ 3. **防回归**:selftest 加 10 条断言(稳定名映射、cwd 归一、本机路径反查、重编码、sessionIds 合并、资料跳过)。普通工作区、im、其余机制与同步内容勾选过滤全部不变。首次拉取前 B 机需先让 DSH 启动一次生成默认工作区登记。
287
+
280
288
  ### 点 × 检测到待同步就主动退出 DSH 并立即执行(0.3.97)
281
289
 
282
290
  0.3.96 的信标已经能「点 × 判一次并排好 watcher」,但 watcher 进入 `wait` 后是**被动等 DSH 进程全部消失**才开工。实测点 × 后 DSH 常残留 7 个进程(插件就跑在其中的 host 子进程里),单靠正常关闭流程经常关不干净,watcher 只能干等到 30 分钟超时——表现为「排了队但迟迟不动」。这次补上最后一环:
@@ -727,6 +735,7 @@ pwsh -File sync.ps1 push -ScanHistory
727
735
 
728
736
  | 日期 | 版本 | 要点 |
729
737
  |---|---|---|
738
+ | 2026-11-25 | 0.3.98 | 默认工作区会话纳入同步(稳定名 --default-workspace--,apply 按本机 defaultWorkspaceId 重编码目录/cwd/projcache 并合并 sessionIds),资料仍各机独立 |
730
739
  | 2026-11-25 | 0.3.97 | 点 × 检测到待拉取/待推送后,从独立进程主动强制退出 DSH 进程族(detached taskkill /F),watcher 立刻执行,不再干等残留进程 |
731
740
  | 2026-11-24 | 0.3.96 | 页面卸载信标(pagehide→sendBeacon /auto-exit)取代失效的 Electron 关窗钩子,fast 判据(本地 tracking ref、不 fetch)毫秒级排队 watcher,真正修好「点 × 不触发」 |
732
741
  | 2026-11-24 | 0.3.95 | 修复 post-exit.ps1 丢 UTF-8 BOM 致 PS5.1 按 GBK 解码、55 处语法错启动即崩:三处执行体补回 BOM,selftest 加全量 ps1 BOM 断言防回归 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-config-sync-plugin",
3
- "version": "0.3.97",
3
+ "version": "0.3.98",
4
4
  "type": "module",
5
5
  "description": "在 DSH 设置里查看 dsh-config 仓库与本机的同步状态,并生成退出后执行的 push/pull 脚本。同步动作本身不在应用内执行。面板与文案跟随客户端语言(中文/English)。",
6
6
  "main": "./index.js",
package/runtime/apply.ps1 CHANGED
@@ -123,9 +123,16 @@ function Sync-WorkspaceApply {
123
123
  # DSH 归属权威就是这里的 sessionIds 成员:没登记的会话即便 cwd 改对也不会挂到工作区。
124
124
  # 按 conversations\sessions\--ws-<workspaceId>--\<sessionId>\ 反推补齐,与会话还原段同源。
125
125
  $sidByWsDir = @{}
126
+ $defaultSids = @() # 默认工作区会话(仓库稳定名 --default-workspace--)的会话 id
126
127
  $convSessionsDir = Join-Path $RepoRoot 'conversations\sessions'
127
128
  if (Test-Path -LiteralPath $convSessionsDir) {
128
129
  foreach ($wd in @(Get-ChildItem -LiteralPath $convSessionsDir -Directory -Force)) {
130
+ if ($wd.Name -eq '--default-workspace--') {
131
+ foreach ($sd in @(Get-ChildItem -LiteralPath $wd.FullName -Directory -Force)) {
132
+ $defaultSids += [string]$sd.Name
133
+ }
134
+ continue
135
+ }
129
136
  if ($wd.Name -notmatch '^--ws-(?<id>.+)--$') { continue }
130
137
  $wid = $Matches['id']
131
138
  if (-not $sidByWsDir.ContainsKey($wid)) { $sidByWsDir[$wid] = @() }
@@ -355,6 +362,13 @@ function Sync-WorkspaceApply {
355
362
  else { $localGlobal['defaultWorkspaceId'] = '' }
356
363
  }
357
364
  elseif (-not $localGlobal.Contains('defaultWorkspaceId')) { $localGlobal['defaultWorkspaceId'] = $localDefault }
365
+ # 默认工作区的会话 id 并入「本机」默认工作区条目:普通工作区靠上面 sidByWsDir 反推补进 sessionIds,
366
+ # 默认工作区是稳定名 --default-workspace-- 不那条路,这里用仓库会话目录反推出来的 $defaultSids 补。
367
+ # DSH 归属权威就是 sessionIds,不补的话 cwd 和目录名对了、会话也不会挂到默认工作区下。
368
+ $dwId = [string]$localGlobal['defaultWorkspaceId']
369
+ if ($defaultSids.Count -gt 0 -and $dwId -and $localTable.Contains($dwId)) {
370
+ $localTable[$dwId]['sessionIds'] = @(@($localTable[$dwId]['sessionIds']) + $defaultSids | Where-Object { $_ -ne '' } | Sort-Object -Unique)
371
+ }
358
372
  $localGlobal['initialized'] = $true
359
373
  $localGlobal['workspaceIds'] = $ids
360
374
  $localGlobal['archivedSessionIds'] = @($gArchAll | Sort-Object -Unique)
@@ -426,6 +440,27 @@ function Sync-ConversationApply {
426
440
  }
427
441
  }
428
442
 
443
+ # 1b) 本机默认工作区路径:从「本机」workspace.json 的 global.defaultWorkspaceId 反查。
444
+ # 绝不用仓库 registry 里那台机器的 default ID——各机默认工作区 ID 不同;但「本机这一个」
445
+ # 由本机登记表唯一确定。默认工作区会话在仓库里是稳定名 --default-workspace--,
446
+ # 还原时按这里的本机路径重编码目录名 + 改写会话头 cwd,B 机才能认出。
447
+ $localDefaultWsPath = ''
448
+ $localWsReg = Join-Path $DshHome 'storages\workspace.json'
449
+ if (Test-Path -LiteralPath $localWsReg) {
450
+ try {
451
+ $lreg = Get-Content -LiteralPath $localWsReg -Raw -Encoding UTF8 | ConvertFrom-Json
452
+ $ldefId = if ($lreg.global) { [string]$lreg.global.defaultWorkspaceId } else { '' }
453
+ if ($ldefId -and $lreg.tables -and $lreg.tables.workspaces) {
454
+ $lp = $lreg.tables.workspaces.PSObject.Properties[$ldefId]
455
+ if ($lp) { $localDefaultWsPath = [string]$lp.Value.path }
456
+ }
457
+ } catch { }
458
+ }
459
+ if (-not $localDefaultWsPath -and $WorkspaceHome) {
460
+ # 兜底:默认工作区路径固定就是 <WorkspaceHome>\default-workspace
461
+ $localDefaultWsPath = Join-Path $WorkspaceHome 'default-workspace'
462
+ }
463
+
429
464
  # 2) 目录名重映射:A 机目录名 → B 机目录名;同时记下 B 机这条目录应对应的 cwd
430
465
  # (会话文件 header 里的 cwd 必须与目录名编码一致,否则 DSH 判 corrupt)
431
466
  $dirMap = @{}
@@ -450,6 +485,16 @@ function Sync-ConversationApply {
450
485
  $newDir = Get-SessionDirName $imLocal
451
486
  $dirMap[$oldDir] = $newDir
452
487
  $cwdMap[$newDir] = $imLocal
488
+ } elseif ($e.special -eq 'default') {
489
+ # 默认工作区:按本机路径重编码目录名,会话头 cwd 也指本机默认工作区
490
+ if ($localDefaultWsPath) {
491
+ $newDir = Get-SessionDirName $localDefaultWsPath
492
+ $dirMap[$oldDir] = $newDir
493
+ $cwdMap[$newDir] = $localDefaultWsPath
494
+ } else {
495
+ $dirMap[$oldDir] = $oldDir
496
+ Warn ('默认工作区会话 {0} 找不到本机落点,请先在 DSH 里打开一次默认工作区再拉取' -f $oldDir)
497
+ }
453
498
  } else {
454
499
  $dirMap[$oldDir] = $oldDir # passthrough / 对应不到的工作区,原名保留
455
500
  Warn ('会话目录 {0} 对应不到本机工作区,目录名与文件头 cwd 都无法重算,DSH 可能把它判为损坏:请在本机重新打开该工作区后再同步' -f $oldDir)
@@ -461,6 +506,15 @@ function Sync-ConversationApply {
461
506
  if (Test-Path -LiteralPath $repoSessions) {
462
507
  foreach ($d in @(Get-ChildItem -LiteralPath $repoSessions -Directory -Force)) {
463
508
  if ($dirMap.ContainsKey($d.Name)) { continue }
509
+ # 默认工作区稳定名(session-index 缺失时兜底)
510
+ if ($d.Name -eq '--default-workspace--') {
511
+ if ($localDefaultWsPath) {
512
+ $newDir = Get-SessionDirName $localDefaultWsPath
513
+ $dirMap[$d.Name] = $newDir
514
+ $cwdMap[$newDir] = $localDefaultWsPath
515
+ }
516
+ continue
517
+ }
464
518
  if ($d.Name -match '^--ws-(?<id>.+)--$') {
465
519
  $id = $Matches['id']
466
520
  $hit = $null
@@ -530,6 +584,12 @@ function Sync-ConversationApply {
530
584
  $projMap[[string]$sd.Name] = $imLocal
531
585
  }
532
586
  }
587
+ # 默认工作区会话(--default-workspace-- 顶层)的 projcache 指到本机默认工作区
588
+ if ($wd.Name -eq '--default-workspace--' -and $localDefaultWsPath) {
589
+ foreach ($sd in @(Get-ChildItem -LiteralPath $wd.FullName -Directory -Force)) {
590
+ $projMap[[string]$sd.Name] = $localDefaultWsPath
591
+ }
592
+ }
533
593
  }
534
594
  }
535
595
  if ($cwdMap.Count -gt 0 -or $projMap.Count -gt 0) {
@@ -568,8 +628,10 @@ function Sync-ConversationApply {
568
628
  if ($b.Remap) {
569
629
  # 相对路径第一段是 A 机的编码目录名,换成 B 机重编码后的名字
570
630
  $parts = @($rel -split '\\')
571
- # 默认工作区不同步(见 dsh-sync-common.ps1):老仓库里可能还留着这条,直接跳过不铺。
572
- if (Test-DefaultWorkspaceDir $parts[0]) { continue }
631
+ # 默认工作区会话现在要同步:稳定的 --default-workspace-- 已在 dirMap 里映射到本机编码名,
632
+ # 下面会随 Remap 改写。老仓库里可能还留着「路径式」的默认工作区目录名(本机编码、对不上
633
+ # 任何映射),那种仍跳过不铺——它跨机无法重定位,铺了反而是死目录。
634
+ if ((Test-DefaultWorkspaceDir $parts[0]) -and -not $dirMap.ContainsKey($parts[0])) { continue }
573
635
  # 该工作区的会话被取消勾选:不铺回本机(否则等于把未勾选的内容写回来了)
574
636
  if (-not $dirMap.ContainsKey($parts[0]) -and $skipConvDirs.ContainsKey($parts[0])) { continue }
575
637
  if ($dirMap.ContainsKey($parts[0])) { $parts[0] = $dirMap[$parts[0]] }
@@ -233,6 +233,10 @@ function Sync-WorkspaceCapture {
233
233
  foreach ($s in $skipWs) { $slotSet[$s.Slot] = $true }
234
234
  $nAdd = 0; $nDel = 0
235
235
  foreach ($e in $entries) {
236
+ # 默认工作区只同步「会话」、不同步「资料」(资料各机独立):登记条目已在上面的
237
+ # workspace-registry.json 里保留(会话归属/sessionIds 合并需要它),这里跳过资料文件
238
+ # 拷贝,也不给它建槽;镜像删除会把仓库里历史遗留的默认工作区资料槽清掉。
239
+ if ($e.Id -eq $gDefault) { continue }
236
240
  $slotSet[$e.Slot] = $true
237
241
  $srcRoot = $e.LocalPath
238
242
  $dstRoot = Join-Path $wsDir $e.Slot
@@ -333,6 +337,10 @@ function Get-RepoSessionDirName([string]$kind, [string]$id, [string]$localDir) {
333
337
  if ($safe) { return ('--ws-{0}--' -f $safe) }
334
338
  }
335
339
  if ($kind -eq 'im') { return '--im--' }
340
+ # 默认工作区用跨机稳定名:它的 ID 与路径编码各机都不同,无法像普通工作区那样按 ID/路径对齐。
341
+ # 每台机器有且只有一个默认工作区(title=default-workspace、路径=<WorkspaceHome>\default-workspace),
342
+ # apply 侧按「本机」workspace.json 的 defaultWorkspaceId 找到本机路径再重编码即可。
343
+ if ($kind -eq 'default') { return '--default-workspace--' }
336
344
  return $localDir
337
345
  }
338
346
 
@@ -344,6 +352,8 @@ function Sync-ConversationCapture {
344
352
  $wsEncToId = @{}
345
353
  $wsPathById = @{}
346
354
  $regSrc = Join-Path $DshHome 'storages/workspace.json'
355
+ $defaultWsEnc = '' # 本机默认工作区的会话目录编码名(路径由 defaultWorkspaceId 反查)
356
+ $defaultWsPath = ''
347
357
  if (Test-Path -LiteralPath $regSrc) {
348
358
  $reg = Get-Content -LiteralPath $regSrc -Raw -Encoding UTF8 | ConvertFrom-Json
349
359
  if ($reg.tables.workspaces) {
@@ -352,6 +362,12 @@ function Sync-ConversationCapture {
352
362
  $wsPathById[[string]$prop.Name] = [string]$prop.Value.path
353
363
  }
354
364
  }
365
+ # 默认工作区:ID 从 global 读,路径从登记表反查(各机的 ID 不同,但「本机这一个」是确定的)
366
+ $defId = if ($reg.global) { [string]$reg.global.defaultWorkspaceId } else { '' }
367
+ if ($defId -and $wsPathById.ContainsKey($defId)) {
368
+ $defaultWsPath = $wsPathById[$defId]
369
+ $defaultWsEnc = Get-SessionDirName $defaultWsPath
370
+ }
355
371
  }
356
372
  $imEnc = Get-SessionDirName (Join-Path $DshHome 'im')
357
373
  $sessSrc = Join-Path $DshHome 'sessions'
@@ -372,8 +388,12 @@ function Sync-ConversationCapture {
372
388
  if (Test-Path -LiteralPath $sessSrc) {
373
389
  foreach ($d in @(Get-ChildItem -LiteralPath $sessSrc -Directory -Force | Sort-Object Name)) {
374
390
  if (Test-DefaultWorkspaceDir $d.Name) {
375
- # 默认工作区不同步(见 dsh-sync-common.ps1 的说明):不记映射,也不入仓库。
376
- Ok ('默认工作区不参与同步,跳过:{0}' -f $d.Name)
391
+ # 默认工作区的会话要同步(资料不同步)。ID/路径编码各机不同,用跨机稳定名 --default-workspace--
392
+ # 入库;apply 侧按本机 workspace.json 的 defaultWorkspaceId 找到本机路径再重编码。
393
+ $repoDir = Get-RepoSessionDirName 'default' '' $d.Name
394
+ $dirRemap[$d.Name] = $repoDir
395
+ $idxEntries += [ordered]@{ dir = $repoDir; special = 'default' }
396
+ Ok ('默认工作区会话纳入同步(稳定名 {0}):{1}' -f $repoDir, $d.Name)
377
397
  continue
378
398
  }
379
399
  if ($wsEncToId.ContainsKey($d.Name) -and -not (Test-SyncItemEnabled $Scope 'conversations' ([string]$wsEncToId[$d.Name]))) {
@@ -407,6 +427,9 @@ function Sync-ConversationCapture {
407
427
  # 不归一的话,仓库里这条 cwd 永远是「最后推上来的那台机器」的路径,两台机器互推时每次都改这批文件。
408
428
  $imRepoDirName = Get-RepoSessionDirName 'im' '' ''
409
429
  $cwdToken[$imRepoDirName] = ($DshHomeToken + '/im')
430
+ # 默认工作区的 cwd 归一到 {{WORKSPACE_HOME}}/default-workspace(路径各机不同,必须占位符)
431
+ $defaultRepoDirName = Get-RepoSessionDirName 'default' '' ''
432
+ if ($defaultWsPath) { $cwdToken[$defaultRepoDirName] = (ConvertTo-WorkspaceToken $defaultWsPath) }
410
433
  foreach ($e in @($idxEntries)) {
411
434
  if (-not $e.workspaceId) { continue }
412
435
  $localCwd = $null
@@ -448,8 +471,10 @@ function Sync-ConversationCapture {
448
471
  $rel = Get-RelPath $b.Src $f.FullName
449
472
  if (-not $rel) { continue }
450
473
  $parts = @($rel -split '\\')
451
- # 默认工作区的文件不入库(第一段就是那个 -default-workspace-- 目录名)。
452
- if (Test-DefaultWorkspaceDir $parts[0]) { continue }
474
+ # 默认工作区的「会话」现在也要入库(资料仍不同步):它在 dirRemap 里已映射成稳定名
475
+ # --default-workspace--,下面会随 Remap 一起改写。只有非 Remap 块仍按原名跳过默认工作区
476
+ # (那些块按 sessionId/hash 平铺,通常也不会出现这种目录名,纯属兜底)。
477
+ if ((-not $b.Remap) -and (Test-DefaultWorkspaceDir $parts[0])) { continue }
453
478
  # 该工作区的会话被取消勾选:整块不抓(目录名保持本机编码,绝不能原样入库)
454
479
  if ($b.Remap -and $skipSessDirs.ContainsKey($parts[0])) { continue }
455
480
  if ($b.Remap -and $dirRemap.ContainsKey($parts[0])) { $parts[0] = $dirRemap[$parts[0]] }
@@ -1904,5 +1904,35 @@ console.log('== 0.3.97:检测到待拉取/待推送就主动强制退出 DSH
1904
1904
  check('只在 queued 时才强制退出(无待同步不误杀 DSH)',
1905
1905
  /result && result\.queued[\s\S]{0,60}?forceCloseDshDetached/.test(idxSrc), 'index.js queued 守卫')
1906
1906
  }
1907
+ console.log('')
1908
+ console.log('== 0.3.98:默认工作区会话同步(稳定名 --default-workspace--,资料仍不同步)==')
1909
+ {
1910
+ const capPath = join(pluginRuntime, 'capture.ps1')
1911
+ const appPath = join(pluginRuntime, 'apply.ps1')
1912
+ const cap = existsSync(capPath) ? readFileSync(capPath, 'utf8') : ''
1913
+ const app = existsSync(appPath) ? readFileSync(appPath, 'utf8') : ''
1914
+ // capture:默认工作区会话用稳定名入库(不再跳过)
1915
+ check('capture Get-RepoSessionDirName 支持 default → --default-workspace--',
1916
+ /if \(\$kind -eq 'default'\) \{ return '--default-workspace--' \}/.test(cap), 'capture.ps1 default 稳定名')
1917
+ check('capture 默认工作区会话纳入映射(special=default,不再跳过)',
1918
+ /special = 'default'/.test(cap) && /默认工作区会话纳入同步/.test(cap), 'capture.ps1 顶层映射')
1919
+ check('capture 从本机 defaultWorkspaceId 反查默认工作区路径',
1920
+ /defaultWorkspaceId/.test(cap) && /\$defaultWsPath = \$wsPathById\[\$defId\]/.test(cap), 'capture.ps1 默认路径反查')
1921
+ check('capture 默认工作区 cwd 归一到 {{WORKSPACE_HOME}}/default-workspace',
1922
+ /\$cwdToken\[\$defaultRepoDirName\] = \(ConvertTo-WorkspaceToken \$defaultWsPath\)/.test(cap), 'capture.ps1 cwd 归一')
1923
+ check('capture 资料按 defaultWorkspaceId 跳过默认工作区(资料不同步、登记保留)',
1924
+ /if \(\$e\.Id -eq \$gDefault\) \{ continue \}/.test(cap), 'capture.ps1 资料跳过')
1925
+ check('capture 会话镜像不再无条件跳过默认工作区目录',
1926
+ /\(Test-DefaultWorkspaceDir \$parts\[0\]\)/.test(cap) && /-not \$b\.Remap/.test(cap), 'capture.ps1 镜像')
1927
+ // apply:按本机默认工作区路径重编码 + 注册会话到默认工作区
1928
+ check('apply 从本机 workspace.json 读 defaultWorkspaceId 反查默认工作区路径',
1929
+ /\$localDefaultWsPath/.test(app) && /\$lreg\.global\.defaultWorkspaceId/.test(app), 'apply.ps1 本机默认路径')
1930
+ check('apply special=default 分支按本机路径重编码目录与 cwd',
1931
+ /\$e\.special -eq 'default'/.test(app) && /\$newDir = Get-SessionDirName \$localDefaultWsPath/.test(app), 'apply.ps1 重编码')
1932
+ check('apply 2b 兜底与 projcache 都处理 --default-workspace--',
1933
+ /\$d\.Name -eq '--default-workspace--'/.test(app) && /\$wd\.Name -eq '--default-workspace--'/.test(app), 'apply.ps1 兜底+projcache')
1934
+ check('apply 默认工作区会话 id 并入本机默认工作区登记(sessionIds)',
1935
+ /\$localTable\[\$dwId\]\['sessionIds'\]/.test(app) && /\$defaultSids/.test(app), 'apply.ps1 sessionIds 合并')
1936
+ }
1907
1937
  process.exit(failures === 0 ? 0 : 1)
1908
1938