dsh-config-sync-plugin 0.3.99 → 0.4.1

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,20 @@ 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
+ ### Project-level skills now sync + auto sync only on active × close (0.4.01)
261
+
262
+ **Project-level skills**: skills placed under a workspace's `.dsh\skills\` were never synced — the workspace ignore list skips the whole `.dsh` directory. `Test-WorkspaceIgnored` now makes a targeted exception for `.dsh\skills\`, so project skills sync with workspace files; other `.dsh` content (session cache/tokens/config) stays skipped.
263
+
264
+ **Auto sync timing**: in 0.3.99, toggling the switches meant instant drift check → queue watcher + close DSH. That caused DSH to auto-close and restart whenever a switch was flipped or the 2-min cycle hit, which was disruptive.
265
+
266
+ Now `checkAndQueueAutoSync` takes a `shouldCloseDsh` parameter, and the three callers are cleanly separated:
267
+
268
+ 1. **scheduleAutoStart** (8s after startup + every 2 min): **only checks drift and updates status**, no auto-close. The panel shows "cloud ahead / local dirty" instantly.
269
+ 2. **handleSettings** (toggle save): **queues watcher only (shouldCloseDsh: false), no auto-close**. Toggle changes take effect immediately but won't interrupt your running DSH.
270
+ 3. **triggerAutoSyncOnClose / handleAutoExit** (× close / pagehide): **shouldCloseDsh: true**, queues watcher then actually closes DSH; the watcher runs the pull/push after DSH exits.
271
+
272
+ Now the behavior is: toggle the switch → drift is checked and watcher is queued (panel status updates instantly), but DSH **stays running**; only when you **actively click × to close the window** does the queued pull/push actually execute. 5 selftest assertions added. Keeps all 0.3.93–0.3.99 fixes.
273
+
260
274
  ### Toggle auto-pull/push now triggers immediate sync check (0.3.99)
261
275
 
262
276
  Previously toggling "Pull on startup" or "Push on exit" meant waiting for the next 2-minute cycle (or DSH exit) before any sync decision. The core logic is now factored into `checkAndQueueAutoSync`, reused in three places:
@@ -763,6 +777,7 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
763
777
 
764
778
  | Date | Version | Summary |
765
779
  |---|---|---|
780
+ | 2026-11-25 | 0.4.01 | Auto sync only on active × close: scheduleAutoStart updates drift status only, handleSettings queues watcher without close, only × close/pagehide (shouldCloseDsh:true) actually closes DSH after queuing |
766
781
  | 2026-11-25 | 0.3.99 | Toggle auto-pull/push now triggers immediate sync check (core logic checkAndQueueAutoSync reused by scheduleAutoStart/triggerAutoSyncOnClose/handleSettings; toggle change queues immediately, manual-trigger mode skips confirm) |
767
782
  | 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 |
768
783
  | 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 |
package/README.md CHANGED
@@ -277,6 +277,20 @@ 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
+ ### 项目级技能纳入同步 + 自动同步仅在主动关闭 DSH 窗口(×)时触发(0.4.01)
281
+
282
+ **项目级技能同步**:技能放在工作区的 `.dsh\skills\` 下时,之前从来不会被同步——工作区同步的忽略清单把整个 `.dsh` 目录跳过了。现在 `Test-WorkspaceIgnored` 给 `.dsh\skills\` 开定向例外,项目级技能能随工作区资料一起推送/拉取;其余 `.dsh` 内容(会话缓存/token/配置)仍照旧跳过。
283
+
284
+ **自动同步时机**:以前勾选「启动时自动拉取」或「退出时自动推送」后,立即判 drift → 满足条件即排队 watcher 并关闭 DSH(0.3.99)。这会导致用户只是在面板改开关、或 2 分钟周期到达时,DSH 就自动关闭重启,体验很差。
285
+
286
+ 现在把核心判断 `checkAndQueueAutoSync` 拆出 `shouldCloseDsh` 参数,三路明确分工:
287
+
288
+ 1. **scheduleAutoStart**(启动 8 秒后 + 每 2 分钟复查):**只做 drift 检查与状态更新,不自动关闭 DSH**,供面板显示「云端领先/本地未提交」等状态
289
+ 2. **handleSettings**(开关保存后):**只排队 watcher(shouldCloseDsh: false),不自动退出**,开关变更即时生效但不干扰正在用的 DSH
290
+ 3. **triggerAutoSyncOnClose / handleAutoExit**(点 × 关闭 / 页面卸载):**shouldCloseDsh: true**,排队后真正关闭 DSH,watcher 在 DSH 退出后立即执行
291
+
292
+ 现在的行为:勾选开关 → 即时判 drift 并排队(面板状态立即刷新),但 DSH **不会** 自动关闭;只有用户**主动点 × 关闭窗口**时,才会按已排队的模式真正执行拉取/推送。selftest 加断言防回归。保留 0.3.93-0.3.99 全部修复。
293
+
280
294
  ### 勾选自动同步开关即时触发判断(0.3.99)
281
295
 
282
296
  以前勾选「启动时自动拉取」或「退出时自动推送」后,必须等到下一个 2 分钟周期(或退出 DSH)才会判断是否需要同步。这次把核心判断逻辑抽离为 `checkAndQueueAutoSync`,在三处复用:
@@ -745,6 +759,7 @@ pwsh -File sync.ps1 push -ScanHistory
745
759
 
746
760
  | 日期 | 版本 | 要点 |
747
761
  |---|---|---|
762
+ | 2026-11-25 | 0.4.01 | 自动同步仅在主动关闭 DSH 窗口(×)时触发:scheduleAutoStart 只做 drift 状态更新,handleSettings 只排队不退出,只有 × 关闭/页面卸载走 shouldCloseDsh: true 真正关闭 DSH |
748
763
  | 2026-11-25 | 0.3.99 | 勾选自动同步开关即时触发判断(核心逻辑抽离为 checkAndQueueAutoSync,scheduleAutoStart/triggerAutoSyncOnClose/handleSettings 三路复用,开关变更即时排队,手动模式跳过确认框) |
749
764
  | 2026-11-25 | 0.3.98 | 默认工作区会话纳入同步(稳定名 --default-workspace--,apply 按本机 defaultWorkspaceId 重编码目录/cwd/projcache 并合并 sessionIds),资料仍各机独立 |
750
765
  | 2026-11-25 | 0.3.97 | 点 × 检测到待拉取/待推送后,从独立进程主动强制退出 DSH 进程族(detached taskkill /F),watcher 立刻执行,不再干等残留进程 |
package/index.js CHANGED
@@ -2189,12 +2189,13 @@ async function handleSettings(req, res, config) {
2189
2189
  },
2190
2190
  }
2191
2191
  // autoPull/autoPush 开关变更时,若已开启则立即判断并排队(不等 2 分钟周期)
2192
+ // shouldCloseDsh: false —— 用户只是在面板改开关,不想自动退出 DSH
2192
2193
  if (changed.autoPull || changed.autoPush) {
2193
2194
  const repoPathResolved = repo || resolveRepo(config?.repoPath, dshHome).repo || ''
2194
2195
  const appRoot = resolveAppRoot(config?.appRoot) || ''
2195
2196
  const newSettings = readSettings(dshHome)
2196
2197
  if (repoPathResolved && isDir(join(repoPathResolved, '.git'))) {
2197
- await checkAndQueueAutoSync(dshHome, config, newSettings, repoPathResolved, appRoot, { isManualTrigger: true })
2198
+ await checkAndQueueAutoSync(dshHome, config, newSettings, repoPathResolved, appRoot, { isManualTrigger: true, shouldCloseDsh: false })
2198
2199
  }
2199
2200
  }
2200
2201
  sendJson(res, 200, response)
@@ -3498,10 +3499,10 @@ async function handleAuto(req, res, config) {
3498
3499
  }
3499
3500
  }
3500
3501
 
3501
- /** 核心判断逻辑:给定配置与仓库,判断是否需要自动拉取/推送,需要则排队 watcher 并关闭 DSH。
3502
+ /** 核心判断逻辑:给定配置与仓库,判断是否需要自动拉取/推送,需要则排队 watcher(可选关闭 DSH)。
3502
3503
  * 供 scheduleAutoStart(定时)、triggerAutoSyncOnClose(关闭钩子)、handleSettings(开关即时触发)复用。 */
3503
3504
  async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, options = {}) {
3504
- const { skipConfirm = false, isManualTrigger = false } = options
3505
+ const { skipConfirm = false, isManualTrigger = false, shouldCloseDsh = true } = options
3505
3506
  // 已经排队等退出了就别重复拉起 watcher
3506
3507
  if (autoState.pending) return { queued: false, reason: 'already_pending' }
3507
3508
  if (!repo || !isDir(join(repo, '.git'))) {
@@ -3532,7 +3533,7 @@ async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, o
3532
3533
  const started = await spawnWatcher({ mode: 'pull', repo, appRoot, dshHome, restart: settings.autoRestart })
3533
3534
  if (started.ok) {
3534
3535
  autoState.pending = { mode: 'pull', at: Date.now(), restart: settings.autoRestart, watcherPid: started.pid, closeRequested: true }
3535
- closeDsh()
3536
+ if (shouldCloseDsh) closeDsh()
3536
3537
  return { queued: true, mode: 'pull', reason: `behind ${drift.behind}` }
3537
3538
  } else {
3538
3539
  return { queued: false, reason: 'spawn_failed', error: started.error }
@@ -3557,7 +3558,7 @@ async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, o
3557
3558
  const started = await spawnWatcher({ mode: 'push', repo, appRoot, dshHome, restart })
3558
3559
  if (started.ok) {
3559
3560
  autoState.pending = { mode: 'push', at: Date.now(), reason: reasonZh, reasonZh, reasonEn, restart, watcherPid: started.pid, closeRequested: false }
3560
- closeDsh()
3561
+ if (shouldCloseDsh) closeDsh()
3561
3562
  return { queued: true, mode: 'push', reason: reasonZh }
3562
3563
  } else {
3563
3564
  return { queued: false, reason: 'spawn_failed', error: started.error }
@@ -3567,7 +3568,8 @@ async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, o
3567
3568
  return { queued: false, reason: 'no_action_needed' }
3568
3569
  }
3569
3570
 
3570
- /** 启动后的自动检查:延迟跑,避免和客户端自身的启动流程抢 IO;失败只记进状态,不打扰用户。 */
3571
+ /** 启动后的自动检查:延迟跑,避免和客户端自身的启动流程抢 IO;失败只记进状态,不打扰用户。
3572
+ * 只做 drift 检查与状态更新,不自动关闭 DSH;关闭只在用户显式动作(× 关闭、手动按钮)触发。 */
3571
3573
  function scheduleAutoStart(config) {
3572
3574
  const dshHome = config?.dshHome || process.env.DSH_HOME || join(homedir(), '.dsh')
3573
3575
  const settings = readSettings(dshHome)
@@ -3577,19 +3579,29 @@ function scheduleAutoStart(config) {
3577
3579
  try {
3578
3580
  if (autoState.pending) return
3579
3581
  const repo = resolveRepo(config?.repoPath, dshHome).repo || ''
3580
- const appRoot = resolveAppRoot(config?.appRoot) || ''
3581
- await checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot)
3582
+ if (!repo || !isDir(join(repo, '.git'))) {
3583
+ autoState.lastCheckError = (repo && repoPhase(repo) === 'empty') ? '' : '仓库未就位'
3584
+ autoState.lastCheckAt = Date.now()
3585
+ return
3586
+ }
3587
+ autoState.checking = true
3588
+ const drift = await checkDrift(repo)
3589
+ autoState.checking = false
3590
+ autoState.lastCheckAt = Date.now()
3591
+ if (!drift) {
3592
+ autoState.lastCheckError = '读不到远端'
3593
+ return
3594
+ }
3595
+ autoState.drift = drift
3596
+ // 仅更新状态供面板显示;不自动关闭 DSH,关闭由用户显式动作触发
3582
3597
  } catch (error) {
3583
3598
  autoState.checking = false
3584
3599
  autoState.lastCheckAt = Date.now()
3585
3600
  autoState.lastCheckError = String((error && error.message) || error)
3586
3601
  }
3587
3602
  }
3588
- // 首检别拖太久:用户可能开起来看一眼就关窗口,20 秒会让他这次关闭什么都没推。
3589
3603
  autoState.timer = setTimeout(run, 8 * 1000)
3590
3604
  try { autoState.timer.unref?.() } catch { }
3591
- // 之后每 2 分钟复查一次:会话/资料是运行中才产生的,只在启动判一次会把它们全漏掉。
3592
- // 命中就排一次队,watcher 已在等进程退出,退出即执行;已排队时 run 会直接返回。
3593
3605
  try {
3594
3606
  autoState.interval = setInterval(run, 2 * 60 * 1000)
3595
3607
  autoState.interval.unref?.()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-config-sync-plugin",
3
- "version": "0.3.99",
3
+ "version": "0.4.01",
4
4
  "type": "module",
5
5
  "description": "在 DSH 设置里查看 dsh-config 仓库与本机的同步状态,并生成退出后执行的 push/pull 脚本。同步动作本身不在应用内执行。面板与文案跟随客户端语言(中文/English)。",
6
6
  "main": "./index.js",
@@ -216,8 +216,15 @@ $wsMaxFileBytes = 100MB
216
216
  function Test-WorkspaceIgnored([string]$rel) {
217
217
  # 只按「目录段」判忽略,最后一段是文件名不算目录(否则一个恰好叫 logs 的文件会被误跳过)
218
218
  $parts = @($rel.Replace($BS,'/') -split '/' | Where-Object { $_ -ne '' })
219
+ # 0.4.01:项目级技能在工作区的 .dsh\skills\ 下,而 .dsh 整个被 wsSkipDirs 排除,
220
+ # 导致项目技能永远不同步。这里给「.dsh/skills/」开定向例外:只有恰好位于
221
+ # .dsh\skills\ 之下的内容放行,其余 .dsh 内容(会话缓存/token/配置)仍照旧跳过。
222
+ $isProjectSkill = ($parts.Count -ge 3 -and $parts[0] -eq '.dsh' -and $parts[1] -eq 'skills')
219
223
  $dirParts = if ($parts.Count -gt 1) { @($parts[0..($parts.Count-2)]) } else { @() }
220
- foreach ($seg in $dirParts) { if ($wsSkipDirs -contains $seg) { return $true } }
224
+ foreach ($seg in $dirParts) {
225
+ if ($isProjectSkill -and ($seg -eq '.dsh' -or $seg -eq 'skills')) { continue }
226
+ if ($wsSkipDirs -contains $seg) { return $true }
227
+ }
221
228
  $leaf = if ($parts.Count -gt 0) { $parts[$parts.Count-1] } else { '' }
222
229
  if ($wsSkipFiles -contains $leaf) { return $true }
223
230
  if ($wsSkipExt -contains ([IO.Path]::GetExtension($leaf).ToLower())) { return $true }
@@ -759,6 +759,9 @@ if (prevScope === null) { try { unlinkSync(scopeFile) } catch { } } else writeFi
759
759
  && captureSrc.includes('Get-SyncExtraSecretSkips'), 'common/index/capture')
760
760
  check('符号链接/junction 不跟进(插件目录常把外部数据链进来)',
761
761
  commonSrc.includes('[IO.FileAttributes]::ReparsePoint'), 'dsh-sync-common.ps1')
762
+ check('0.4.01:项目级技能 .dsh/skills/ 在工作区同步里放行(其余 .dsh 仍跳过)',
763
+ commonSrc.includes("$isProjectSkill = ($parts.Count -ge 3") && commonSrc.includes("$parts[1] -eq 'skills'")
764
+ && commonSrc.includes('if ($isProjectSkill -and ($seg -eq \'.dsh\' -or $seg -eq \'skills\')) { continue }'), 'dsh-sync-common.ps1 项目技能例外')
762
765
  check('「插件数据与额外路径」卡先只读,点「修改」才能改、点「保存」才落盘',
763
766
  clientSrc.includes('readOnly: !editing')
764
767
  && clientSrc.includes('disabled: !editing')