dsh-config-sync-plugin 0.3.99 → 0.4.2
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 +20 -0
- package/README.md +20 -0
- package/index.js +29 -12
- package/package.json +1 -1
- package/runtime/dsh-sync-common.ps1 +8 -1
- package/tools/selftest.mjs +13 -0
package/README.en.md
CHANGED
|
@@ -257,6 +257,24 @@ 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
|
+
### npm fallback version normalization fix (0.4.02)
|
|
261
|
+
|
|
262
|
+
npm normalizes `0.4.01` to `0.4.1` per semver, so the tarball is `dsh-config-sync-plugin-0.4.1.tgz`. Before 0.4.02 the fallback URL was built as `-0.4.01.tgz`, which 404s on npm. `npmTgzUrls` now strips leading zeros from numeric segments (`0.4.01`→`0.4.1`) before building the URL; GitHub release and version.json keep the user-specified version (same artifact, identical sha256). Selftest assertion added.
|
|
263
|
+
|
|
264
|
+
### Project-level skills now sync + auto sync only on active × close (0.4.01)
|
|
265
|
+
|
|
266
|
+
**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.
|
|
267
|
+
|
|
268
|
+
**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.
|
|
269
|
+
|
|
270
|
+
Now `checkAndQueueAutoSync` takes a `shouldCloseDsh` parameter, and the three callers are cleanly separated:
|
|
271
|
+
|
|
272
|
+
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.
|
|
273
|
+
2. **handleSettings** (toggle save): **queues watcher only (shouldCloseDsh: false), no auto-close**. Toggle changes take effect immediately but won't interrupt your running DSH.
|
|
274
|
+
3. **triggerAutoSyncOnClose / handleAutoExit** (× close / pagehide): **shouldCloseDsh: true**, queues watcher then actually closes DSH; the watcher runs the pull/push after DSH exits.
|
|
275
|
+
|
|
276
|
+
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.
|
|
277
|
+
|
|
260
278
|
### Toggle auto-pull/push now triggers immediate sync check (0.3.99)
|
|
261
279
|
|
|
262
280
|
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 +781,8 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
|
|
|
763
781
|
|
|
764
782
|
| Date | Version | Summary |
|
|
765
783
|
|---|---|---|
|
|
784
|
+
| 2026-11-25 | 0.4.02 | Fix npm fallback version normalization: npm semver turns 0.4.01 into 0.4.1; strip leading zeros when building tarball URL, otherwise 404 |
|
|
785
|
+
| 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
786
|
| 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
787
|
| 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
788
|
| 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,24 @@ 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
|
+
### npm 兜底下载的版本规范化修复(0.4.02)
|
|
281
|
+
|
|
282
|
+
npm 按 semver 把版本号 `0.4.01` 规范化成 `0.4.1`,tarball 文件名是 `dsh-config-sync-plugin-0.4.1.tgz`。0.4.01 之前拼的是 `-0.4.01.tgz`,npm 兜底下载会 404。`npmTgzUrls` 现在对数字段去前导零(`0.4.01`→`0.4.1`)再拼 URL;GitHub release 与 version.json 仍保留用户指定的版本号(同一份产物、sha256 一致)。selftest 加断言防回归。
|
|
283
|
+
|
|
284
|
+
### 项目级技能纳入同步 + 自动同步仅在主动关闭 DSH 窗口(×)时触发(0.4.01)
|
|
285
|
+
|
|
286
|
+
**项目级技能同步**:技能放在工作区的 `.dsh\skills\` 下时,之前从来不会被同步——工作区同步的忽略清单把整个 `.dsh` 目录跳过了。现在 `Test-WorkspaceIgnored` 给 `.dsh\skills\` 开定向例外,项目级技能能随工作区资料一起推送/拉取;其余 `.dsh` 内容(会话缓存/token/配置)仍照旧跳过。
|
|
287
|
+
|
|
288
|
+
**自动同步时机**:以前勾选「启动时自动拉取」或「退出时自动推送」后,立即判 drift → 满足条件即排队 watcher 并关闭 DSH(0.3.99)。这会导致用户只是在面板改开关、或 2 分钟周期到达时,DSH 就自动关闭重启,体验很差。
|
|
289
|
+
|
|
290
|
+
现在把核心判断 `checkAndQueueAutoSync` 拆出 `shouldCloseDsh` 参数,三路明确分工:
|
|
291
|
+
|
|
292
|
+
1. **scheduleAutoStart**(启动 8 秒后 + 每 2 分钟复查):**只做 drift 检查与状态更新,不自动关闭 DSH**,供面板显示「云端领先/本地未提交」等状态
|
|
293
|
+
2. **handleSettings**(开关保存后):**只排队 watcher(shouldCloseDsh: false),不自动退出**,开关变更即时生效但不干扰正在用的 DSH
|
|
294
|
+
3. **triggerAutoSyncOnClose / handleAutoExit**(点 × 关闭 / 页面卸载):**shouldCloseDsh: true**,排队后真正关闭 DSH,watcher 在 DSH 退出后立即执行
|
|
295
|
+
|
|
296
|
+
现在的行为:勾选开关 → 即时判 drift 并排队(面板状态立即刷新),但 DSH **不会** 自动关闭;只有用户**主动点 × 关闭窗口**时,才会按已排队的模式真正执行拉取/推送。selftest 加断言防回归。保留 0.3.93-0.3.99 全部修复。
|
|
297
|
+
|
|
280
298
|
### 勾选自动同步开关即时触发判断(0.3.99)
|
|
281
299
|
|
|
282
300
|
以前勾选「启动时自动拉取」或「退出时自动推送」后,必须等到下一个 2 分钟周期(或退出 DSH)才会判断是否需要同步。这次把核心判断逻辑抽离为 `checkAndQueueAutoSync`,在三处复用:
|
|
@@ -745,6 +763,8 @@ pwsh -File sync.ps1 push -ScanHistory
|
|
|
745
763
|
|
|
746
764
|
| 日期 | 版本 | 要点 |
|
|
747
765
|
|---|---|---|
|
|
766
|
+
| 2026-11-25 | 0.4.02 | 修复 npm 兜底下载的版本规范化:0.4.01 被 npm semver 规范化成 0.4.1,拼 tarball 时去前导零,否则 404 |
|
|
767
|
+
| 2026-11-25 | 0.4.01 | 自动同步仅在主动关闭 DSH 窗口(×)时触发:scheduleAutoStart 只做 drift 状态更新,handleSettings 只排队不退出,只有 × 关闭/页面卸载走 shouldCloseDsh: true 真正关闭 DSH |
|
|
748
768
|
| 2026-11-25 | 0.3.99 | 勾选自动同步开关即时触发判断(核心逻辑抽离为 checkAndQueueAutoSync,scheduleAutoStart/triggerAutoSyncOnClose/handleSettings 三路复用,开关变更即时排队,手动模式跳过确认框) |
|
|
749
769
|
| 2026-11-25 | 0.3.98 | 默认工作区会话纳入同步(稳定名 --default-workspace--,apply 按本机 defaultWorkspaceId 重编码目录/cwd/projcache 并合并 sessionIds),资料仍各机独立 |
|
|
750
770
|
| 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)
|
|
@@ -2250,7 +2251,12 @@ function compareVersion(a, b) {
|
|
|
2250
2251
|
* 清单里的权威 sha256 照常校验,换源不放宽校验。
|
|
2251
2252
|
*/
|
|
2252
2253
|
function npmTgzUrls(version) {
|
|
2253
|
-
|
|
2254
|
+
// npm 按 semver 规范化版本号:0.4.01 → 0.4.1(数字段去前导零)。
|
|
2255
|
+
// 版本号本身在 version.json / GitHub release / market 里保留用户指定的 0.4.01,
|
|
2256
|
+
// 但拼 npm tarball 文件名必须用规范化后的版本,否则兜底下载 404。
|
|
2257
|
+
const raw = String(version || '').trim()
|
|
2258
|
+
const semver = raw.replace(/^(\d+)\.(\d+)\.(\d+)/, (_m, a, b, c) => `${Number(a)}.${Number(b)}.${Number(c)}`)
|
|
2259
|
+
const v = semver.replace(/[^0-9A-Za-z.+\-]/g, '')
|
|
2254
2260
|
if (!v) return []
|
|
2255
2261
|
const f = `dsh-config-sync-plugin-${v}.tgz`
|
|
2256
2262
|
return [
|
|
@@ -3498,10 +3504,10 @@ async function handleAuto(req, res, config) {
|
|
|
3498
3504
|
}
|
|
3499
3505
|
}
|
|
3500
3506
|
|
|
3501
|
-
/** 核心判断逻辑:给定配置与仓库,判断是否需要自动拉取/推送,需要则排队 watcher
|
|
3507
|
+
/** 核心判断逻辑:给定配置与仓库,判断是否需要自动拉取/推送,需要则排队 watcher(可选关闭 DSH)。
|
|
3502
3508
|
* 供 scheduleAutoStart(定时)、triggerAutoSyncOnClose(关闭钩子)、handleSettings(开关即时触发)复用。 */
|
|
3503
3509
|
async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, options = {}) {
|
|
3504
|
-
const { skipConfirm = false, isManualTrigger = false } = options
|
|
3510
|
+
const { skipConfirm = false, isManualTrigger = false, shouldCloseDsh = true } = options
|
|
3505
3511
|
// 已经排队等退出了就别重复拉起 watcher
|
|
3506
3512
|
if (autoState.pending) return { queued: false, reason: 'already_pending' }
|
|
3507
3513
|
if (!repo || !isDir(join(repo, '.git'))) {
|
|
@@ -3532,7 +3538,7 @@ async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, o
|
|
|
3532
3538
|
const started = await spawnWatcher({ mode: 'pull', repo, appRoot, dshHome, restart: settings.autoRestart })
|
|
3533
3539
|
if (started.ok) {
|
|
3534
3540
|
autoState.pending = { mode: 'pull', at: Date.now(), restart: settings.autoRestart, watcherPid: started.pid, closeRequested: true }
|
|
3535
|
-
closeDsh()
|
|
3541
|
+
if (shouldCloseDsh) closeDsh()
|
|
3536
3542
|
return { queued: true, mode: 'pull', reason: `behind ${drift.behind}` }
|
|
3537
3543
|
} else {
|
|
3538
3544
|
return { queued: false, reason: 'spawn_failed', error: started.error }
|
|
@@ -3557,7 +3563,7 @@ async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, o
|
|
|
3557
3563
|
const started = await spawnWatcher({ mode: 'push', repo, appRoot, dshHome, restart })
|
|
3558
3564
|
if (started.ok) {
|
|
3559
3565
|
autoState.pending = { mode: 'push', at: Date.now(), reason: reasonZh, reasonZh, reasonEn, restart, watcherPid: started.pid, closeRequested: false }
|
|
3560
|
-
closeDsh()
|
|
3566
|
+
if (shouldCloseDsh) closeDsh()
|
|
3561
3567
|
return { queued: true, mode: 'push', reason: reasonZh }
|
|
3562
3568
|
} else {
|
|
3563
3569
|
return { queued: false, reason: 'spawn_failed', error: started.error }
|
|
@@ -3567,7 +3573,8 @@ async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, o
|
|
|
3567
3573
|
return { queued: false, reason: 'no_action_needed' }
|
|
3568
3574
|
}
|
|
3569
3575
|
|
|
3570
|
-
/** 启动后的自动检查:延迟跑,避免和客户端自身的启动流程抢 IO;失败只记进状态,不打扰用户。
|
|
3576
|
+
/** 启动后的自动检查:延迟跑,避免和客户端自身的启动流程抢 IO;失败只记进状态,不打扰用户。
|
|
3577
|
+
* 只做 drift 检查与状态更新,不自动关闭 DSH;关闭只在用户显式动作(× 关闭、手动按钮)触发。 */
|
|
3571
3578
|
function scheduleAutoStart(config) {
|
|
3572
3579
|
const dshHome = config?.dshHome || process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
3573
3580
|
const settings = readSettings(dshHome)
|
|
@@ -3577,19 +3584,29 @@ function scheduleAutoStart(config) {
|
|
|
3577
3584
|
try {
|
|
3578
3585
|
if (autoState.pending) return
|
|
3579
3586
|
const repo = resolveRepo(config?.repoPath, dshHome).repo || ''
|
|
3580
|
-
|
|
3581
|
-
|
|
3587
|
+
if (!repo || !isDir(join(repo, '.git'))) {
|
|
3588
|
+
autoState.lastCheckError = (repo && repoPhase(repo) === 'empty') ? '' : '仓库未就位'
|
|
3589
|
+
autoState.lastCheckAt = Date.now()
|
|
3590
|
+
return
|
|
3591
|
+
}
|
|
3592
|
+
autoState.checking = true
|
|
3593
|
+
const drift = await checkDrift(repo)
|
|
3594
|
+
autoState.checking = false
|
|
3595
|
+
autoState.lastCheckAt = Date.now()
|
|
3596
|
+
if (!drift) {
|
|
3597
|
+
autoState.lastCheckError = '读不到远端'
|
|
3598
|
+
return
|
|
3599
|
+
}
|
|
3600
|
+
autoState.drift = drift
|
|
3601
|
+
// 仅更新状态供面板显示;不自动关闭 DSH,关闭由用户显式动作触发
|
|
3582
3602
|
} catch (error) {
|
|
3583
3603
|
autoState.checking = false
|
|
3584
3604
|
autoState.lastCheckAt = Date.now()
|
|
3585
3605
|
autoState.lastCheckError = String((error && error.message) || error)
|
|
3586
3606
|
}
|
|
3587
3607
|
}
|
|
3588
|
-
// 首检别拖太久:用户可能开起来看一眼就关窗口,20 秒会让他这次关闭什么都没推。
|
|
3589
3608
|
autoState.timer = setTimeout(run, 8 * 1000)
|
|
3590
3609
|
try { autoState.timer.unref?.() } catch { }
|
|
3591
|
-
// 之后每 2 分钟复查一次:会话/资料是运行中才产生的,只在启动判一次会把它们全漏掉。
|
|
3592
|
-
// 命中就排一次队,watcher 已在等进程退出,退出即执行;已排队时 run 会直接返回。
|
|
3593
3610
|
try {
|
|
3594
3611
|
autoState.interval = setInterval(run, 2 * 60 * 1000)
|
|
3595
3612
|
autoState.interval.unref?.()
|
package/package.json
CHANGED
|
@@ -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) {
|
|
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 }
|
package/tools/selftest.mjs
CHANGED
|
@@ -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')
|
|
@@ -1951,5 +1954,15 @@ console.log('== 0.3.98:默认工作区会话同步(稳定名 --default-works
|
|
|
1951
1954
|
check('apply 默认工作区会话 id 并入本机默认工作区登记(sessionIds)',
|
|
1952
1955
|
/\$localTable\[\$dwId\]\['sessionIds'\]/.test(app) && /\$defaultSids/.test(app), 'apply.ps1 sessionIds 合并')
|
|
1953
1956
|
}
|
|
1957
|
+
console.log('')
|
|
1958
|
+
console.log('== 0.4.02:npm tarball 版本按 semver 规范化(0.4.01 → 0.4.1)==')
|
|
1959
|
+
{
|
|
1960
|
+
const idxSrc = readFileSync(join(pluginRootSelf, 'index.js'), 'utf8')
|
|
1961
|
+
check('npmTgzUrls 对版本号做 semver 规范化(数字段去前导零)',
|
|
1962
|
+
/const semver = raw\.replace\(\/\^\\\(\\d\+\\\)/.test(idxSrc)
|
|
1963
|
+
|| /\$\{Number\(a\)\}\.\$\{Number\(b\)\}\.\$\{Number\(c\)\}/.test(idxSrc), 'index.js semver 规范化')
|
|
1964
|
+
check('npmTgzUrls 保留预发布/构建后缀清洗',
|
|
1965
|
+
idxSrc.includes("semver.replace(/[^0-9A-Za-z.+\\-]/g, '')"), 'index.js 版本清洗')
|
|
1966
|
+
}
|
|
1954
1967
|
process.exit(failures === 0 ? 0 : 1)
|
|
1955
1968
|
|