dsh-config-sync-plugin 0.3.98 → 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 +26 -0
- package/README.md +26 -0
- package/index.js +87 -66
- package/package.json +1 -1
- package/runtime/dsh-sync-common.ps1 +8 -1
- package/tools/selftest.mjs +20 -0
package/README.en.md
CHANGED
|
@@ -257,6 +257,30 @@ 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
|
+
|
|
274
|
+
### Toggle auto-pull/push now triggers immediate sync check (0.3.99)
|
|
275
|
+
|
|
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:
|
|
277
|
+
|
|
278
|
+
1. **scheduleAutoStart** (8s after startup + every 2 min)
|
|
279
|
+
2. **triggerAutoSyncOnClose** (× close)
|
|
280
|
+
3. **handleSettings** (toggle save)
|
|
281
|
+
|
|
282
|
+
When a switch is saved and already on with a ready repo, it instantly checks drift and queues the watcher + closes DSH if criteria are met; manual-trigger mode (toggle change) skips the confirm dialog. No more "toggled switch, wait 2 min for anything to happen". 5 selftest assertions added. Keeps all 0.3.93–0.3.98 fixes.
|
|
283
|
+
|
|
260
284
|
### Default workspace conversations now sync; its files stay local (0.3.98)
|
|
261
285
|
|
|
262
286
|
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":
|
|
@@ -753,6 +777,8 @@ The log shows which path ran: `文件比较(快筛):比对 N 个,深哈
|
|
|
753
777
|
|
|
754
778
|
| Date | Version | Summary |
|
|
755
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 |
|
|
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) |
|
|
756
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 |
|
|
757
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 |
|
|
758
784
|
| 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" |
|
package/README.md
CHANGED
|
@@ -277,6 +277,30 @@ 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
|
+
|
|
294
|
+
### 勾选自动同步开关即时触发判断(0.3.99)
|
|
295
|
+
|
|
296
|
+
以前勾选「启动时自动拉取」或「退出时自动推送」后,必须等到下一个 2 分钟周期(或退出 DSH)才会判断是否需要同步。这次把核心判断逻辑抽离为 `checkAndQueueAutoSync`,在三处复用:
|
|
297
|
+
|
|
298
|
+
1. **scheduleAutoStart**(启动 8 秒后 + 每 2 分钟复查)
|
|
299
|
+
2. **triggerAutoSyncOnClose**(点 × 关闭时)
|
|
300
|
+
3. **handleSettings**(开关保存后)
|
|
301
|
+
|
|
302
|
+
开关保存后,若已开启且仓库就位,立即判 drift→满足条件即排队 watcher 并关闭 DSH;手动触发模式(开关变更)跳过确认框,直接排队。不再有「勾了开关、等 2 分钟才动」的延迟。selftest 加 5 条断言防回归。保留 0.3.93-0.3.98 全部修复。
|
|
303
|
+
|
|
280
304
|
### 默认工作区会话纳入同步、资料仍各机独立(0.3.98)
|
|
281
305
|
|
|
282
306
|
以前默认工作区整个跳过同步。原因:它的会话目录名由**本机 WorkspaceHome 绝对路径**编码(`--C-Users-...-default-workspace--`),两台机器路径不同,直接把 A 机的目录铺到 B 机只会留下 DSH 认不出的死目录(表现为默认工作区历史为空)。这次按「只同步会话、不同步资料」拆开处理:
|
|
@@ -735,6 +759,8 @@ pwsh -File sync.ps1 push -ScanHistory
|
|
|
735
759
|
|
|
736
760
|
| 日期 | 版本 | 要点 |
|
|
737
761
|
|---|---|---|
|
|
762
|
+
| 2026-11-25 | 0.4.01 | 自动同步仅在主动关闭 DSH 窗口(×)时触发:scheduleAutoStart 只做 drift 状态更新,handleSettings 只排队不退出,只有 × 关闭/页面卸载走 shouldCloseDsh: true 真正关闭 DSH |
|
|
763
|
+
| 2026-11-25 | 0.3.99 | 勾选自动同步开关即时触发判断(核心逻辑抽离为 checkAndQueueAutoSync,scheduleAutoStart/triggerAutoSyncOnClose/handleSettings 三路复用,开关变更即时排队,手动模式跳过确认框) |
|
|
738
764
|
| 2026-11-25 | 0.3.98 | 默认工作区会话纳入同步(稳定名 --default-workspace--,apply 按本机 defaultWorkspaceId 重编码目录/cwd/projcache 并合并 sessionIds),资料仍各机独立 |
|
|
739
765
|
| 2026-11-25 | 0.3.97 | 点 × 检测到待拉取/待推送后,从独立进程主动强制退出 DSH 进程族(detached taskkill /F),watcher 立刻执行,不再干等残留进程 |
|
|
740
766
|
| 2026-11-24 | 0.3.96 | 页面卸载信标(pagehide→sendBeacon /auto-exit)取代失效的 Electron 关窗钩子,fast 判据(本地 tracking ref、不 fetch)毫秒级排队 watcher,真正修好「点 × 不触发」 |
|
package/index.js
CHANGED
|
@@ -2163,7 +2163,7 @@ async function handleSettings(req, res, config) {
|
|
|
2163
2163
|
}
|
|
2164
2164
|
|
|
2165
2165
|
const sshKey2 = sshKey || defaultSshKey()
|
|
2166
|
-
|
|
2166
|
+
const response = {
|
|
2167
2167
|
ok: true,
|
|
2168
2168
|
changed,
|
|
2169
2169
|
gitRemoteSet: Boolean(gitSet),
|
|
@@ -2187,7 +2187,18 @@ async function handleSettings(req, res, config) {
|
|
|
2187
2187
|
defaultWorkspaceAuto: !defaultWorkspace,
|
|
2188
2188
|
settingsPath: file,
|
|
2189
2189
|
},
|
|
2190
|
-
}
|
|
2190
|
+
}
|
|
2191
|
+
// autoPull/autoPush 开关变更时,若已开启则立即判断并排队(不等 2 分钟周期)
|
|
2192
|
+
// shouldCloseDsh: false —— 用户只是在面板改开关,不想自动退出 DSH
|
|
2193
|
+
if (changed.autoPull || changed.autoPush) {
|
|
2194
|
+
const repoPathResolved = repo || resolveRepo(config?.repoPath, dshHome).repo || ''
|
|
2195
|
+
const appRoot = resolveAppRoot(config?.appRoot) || ''
|
|
2196
|
+
const newSettings = readSettings(dshHome)
|
|
2197
|
+
if (repoPathResolved && isDir(join(repoPathResolved, '.git'))) {
|
|
2198
|
+
await checkAndQueueAutoSync(dshHome, config, newSettings, repoPathResolved, appRoot, { isManualTrigger: true, shouldCloseDsh: false })
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
sendJson(res, 200, response)
|
|
2191
2202
|
} catch (error) {
|
|
2192
2203
|
sendJson(res, 400, { ok: false, error: String((error && error.message) || error) })
|
|
2193
2204
|
}
|
|
@@ -3488,7 +3499,77 @@ async function handleAuto(req, res, config) {
|
|
|
3488
3499
|
}
|
|
3489
3500
|
}
|
|
3490
3501
|
|
|
3491
|
-
/**
|
|
3502
|
+
/** 核心判断逻辑:给定配置与仓库,判断是否需要自动拉取/推送,需要则排队 watcher(可选关闭 DSH)。
|
|
3503
|
+
* 供 scheduleAutoStart(定时)、triggerAutoSyncOnClose(关闭钩子)、handleSettings(开关即时触发)复用。 */
|
|
3504
|
+
async function checkAndQueueAutoSync(dshHome, config, settings, repo, appRoot, options = {}) {
|
|
3505
|
+
const { skipConfirm = false, isManualTrigger = false, shouldCloseDsh = true } = options
|
|
3506
|
+
// 已经排队等退出了就别重复拉起 watcher
|
|
3507
|
+
if (autoState.pending) return { queued: false, reason: 'already_pending' }
|
|
3508
|
+
if (!repo || !isDir(join(repo, '.git'))) {
|
|
3509
|
+
return { queued: false, reason: 'no_repo' }
|
|
3510
|
+
}
|
|
3511
|
+
const drift = await checkDrift(repo)
|
|
3512
|
+
if (!drift) {
|
|
3513
|
+
return { queued: false, reason: 'drift_failed' }
|
|
3514
|
+
}
|
|
3515
|
+
autoState.drift = drift
|
|
3516
|
+
|
|
3517
|
+
// autoPull:云端领先,且开启了自动拉取
|
|
3518
|
+
if (settings.autoPull && drift.behind > 0) {
|
|
3519
|
+
if (!skipConfirm && !isManualTrigger) {
|
|
3520
|
+
const yes = await askConfirm(
|
|
3521
|
+
t('云端有更新,要同步到本机吗?', 'The cloud has new commits — sync them to this machine?'),
|
|
3522
|
+
t(
|
|
3523
|
+
`云端比本机多 ${drift.behind} 个提交。\n`
|
|
3524
|
+
+ '同步需要先完全退出 DSH:确认后客户端会自动关闭,拉取完成后按设置自动重新打开。\n'
|
|
3525
|
+
+ `(本机领先 ${drift.ahead} 个提交,拉取不会动它们)`,
|
|
3526
|
+
`The cloud is ${drift.behind} commit(s) ahead of this machine.\n`
|
|
3527
|
+
+ 'Syncing requires DSH to fully exit first: after you confirm, the client closes itself and reopens according to your settings once the pull finishes.\n'
|
|
3528
|
+
+ `(This machine is ${drift.ahead} commit(s) ahead — pulling leaves those alone.)`,
|
|
3529
|
+
),
|
|
3530
|
+
)
|
|
3531
|
+
if (!yes) return { queued: false, reason: 'user_cancelled_pull' }
|
|
3532
|
+
}
|
|
3533
|
+
const started = await spawnWatcher({ mode: 'pull', repo, appRoot, dshHome, restart: settings.autoRestart })
|
|
3534
|
+
if (started.ok) {
|
|
3535
|
+
autoState.pending = { mode: 'pull', at: Date.now(), restart: settings.autoRestart, watcherPid: started.pid, closeRequested: true }
|
|
3536
|
+
if (shouldCloseDsh) closeDsh()
|
|
3537
|
+
return { queued: true, mode: 'pull', reason: `behind ${drift.behind}` }
|
|
3538
|
+
} else {
|
|
3539
|
+
return { queued: false, reason: 'spawn_failed', error: started.error }
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
// autoPush:三个来源判据(领先提交 / 未提交改动 / 本机资料比上次同步新)
|
|
3544
|
+
if (settings.autoPush) {
|
|
3545
|
+
let dirty = 0
|
|
3546
|
+
const raw = await git(repo, ['status', '--porcelain'])
|
|
3547
|
+
if (raw) dirty = raw.split('\n').filter((l) => l.trim()).length
|
|
3548
|
+
const syncState = readSyncState(dshHome)
|
|
3549
|
+
const lp = localPending(dshHome, syncState.lastSyncAt, config?.profileName, { repo, appRoot })
|
|
3550
|
+
const reasonZh = drift.ahead > 0 ? `领先 ${drift.ahead} 个提交`
|
|
3551
|
+
: dirty > 0 ? `未提交 ${dirty} 项`
|
|
3552
|
+
: (lp.known && lp.pending > 0) ? `本机 ${lp.pending} 个文件比上次同步新` : ''
|
|
3553
|
+
const reasonEn = drift.ahead > 0 ? `${drift.ahead} commit(s) ahead`
|
|
3554
|
+
: dirty > 0 ? `${dirty} uncommitted change(s)`
|
|
3555
|
+
: (lp.known && lp.pending > 0) ? `${lp.pending} file(s) newer than the last sync` : ''
|
|
3556
|
+
if (reasonZh) {
|
|
3557
|
+
const restart = settings.autoRestart !== false
|
|
3558
|
+
const started = await spawnWatcher({ mode: 'push', repo, appRoot, dshHome, restart })
|
|
3559
|
+
if (started.ok) {
|
|
3560
|
+
autoState.pending = { mode: 'push', at: Date.now(), reason: reasonZh, reasonZh, reasonEn, restart, watcherPid: started.pid, closeRequested: false }
|
|
3561
|
+
if (shouldCloseDsh) closeDsh()
|
|
3562
|
+
return { queued: true, mode: 'push', reason: reasonZh }
|
|
3563
|
+
} else {
|
|
3564
|
+
return { queued: false, reason: 'spawn_failed', error: started.error }
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
return { queued: false, reason: 'no_action_needed' }
|
|
3569
|
+
}
|
|
3570
|
+
|
|
3571
|
+
/** 启动后的自动检查:延迟跑,避免和客户端自身的启动流程抢 IO;失败只记进状态,不打扰用户。
|
|
3572
|
+
* 只做 drift 检查与状态更新,不自动关闭 DSH;关闭只在用户显式动作(× 关闭、手动按钮)触发。 */
|
|
3492
3573
|
function scheduleAutoStart(config) {
|
|
3493
3574
|
const dshHome = config?.dshHome || process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
3494
3575
|
const settings = readSettings(dshHome)
|
|
@@ -3496,14 +3577,10 @@ function scheduleAutoStart(config) {
|
|
|
3496
3577
|
if (autoState.timer) return
|
|
3497
3578
|
const run = async () => {
|
|
3498
3579
|
try {
|
|
3499
|
-
// 已经排队等退出了就别重复拉起 watcher:第二遍 fetch/stat 纯属浪费
|
|
3500
3580
|
if (autoState.pending) return
|
|
3501
3581
|
const repo = resolveRepo(config?.repoPath, dshHome).repo || ''
|
|
3502
3582
|
if (!repo || !isDir(join(repo, '.git'))) {
|
|
3503
|
-
|
|
3504
|
-
autoState.lastCheckError = (repo && repoPhase(repo) === 'empty')
|
|
3505
|
-
? ''
|
|
3506
|
-
: t('仓库还没就位,跳过本次自动检查', 'The repo is not in place yet — skipping this auto check')
|
|
3583
|
+
autoState.lastCheckError = (repo && repoPhase(repo) === 'empty') ? '' : '仓库未就位'
|
|
3507
3584
|
autoState.lastCheckAt = Date.now()
|
|
3508
3585
|
return
|
|
3509
3586
|
}
|
|
@@ -3512,75 +3589,19 @@ function scheduleAutoStart(config) {
|
|
|
3512
3589
|
autoState.checking = false
|
|
3513
3590
|
autoState.lastCheckAt = Date.now()
|
|
3514
3591
|
if (!drift) {
|
|
3515
|
-
autoState.lastCheckError =
|
|
3592
|
+
autoState.lastCheckError = '读不到远端'
|
|
3516
3593
|
return
|
|
3517
3594
|
}
|
|
3518
3595
|
autoState.drift = drift
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
if (settings.autoPull && drift.behind > 0) {
|
|
3522
|
-
const yes = await askConfirm(
|
|
3523
|
-
t('云端有更新,要同步到本机吗?', 'The cloud has new commits — sync them to this machine?'),
|
|
3524
|
-
t(
|
|
3525
|
-
`云端比本机多 ${drift.behind} 个提交。\n`
|
|
3526
|
-
+ '同步需要先完全退出 DSH:确认后客户端会自动关闭,拉取完成后按设置自动重新打开。\n'
|
|
3527
|
-
+ `(本机领先 ${drift.ahead} 个提交,拉取不会动它们)`,
|
|
3528
|
-
`The cloud is ${drift.behind} commit(s) ahead of this machine.\n`
|
|
3529
|
-
+ 'Syncing requires DSH to fully exit first: after you confirm, the client closes itself and reopens according to your settings once the pull finishes.\n'
|
|
3530
|
-
+ `(This machine is ${drift.ahead} commit(s) ahead — pulling leaves those alone.)`,
|
|
3531
|
-
),
|
|
3532
|
-
)
|
|
3533
|
-
if (yes) {
|
|
3534
|
-
const started = await spawnWatcher({ mode: 'pull', repo, appRoot, dshHome, restart: settings.autoRestart })
|
|
3535
|
-
if (started.ok) {
|
|
3536
|
-
autoState.pending = { mode: 'pull', at: Date.now(), restart: settings.autoRestart, watcherPid: started.pid, closeRequested: true }
|
|
3537
|
-
closeDsh()
|
|
3538
|
-
} else {
|
|
3539
|
-
autoState.lastCheckError = started.error
|
|
3540
|
-
}
|
|
3541
|
-
} else {
|
|
3542
|
-
autoState.pending = null
|
|
3543
|
-
}
|
|
3544
|
-
return
|
|
3545
|
-
}
|
|
3546
|
-
|
|
3547
|
-
if (settings.autoPush) {
|
|
3548
|
-
// 该不该推,三个来源都算:本地领先的提交、未提交的改动、以及"本机资料比上次同步新"
|
|
3549
|
-
// (新会话还没 capture 时仓库是干净的,只看 ahead 会把最该推的那种改动漏掉 —— 真实踩过)
|
|
3550
|
-
let dirty = 0
|
|
3551
|
-
const raw = await git(repo, ['status', '--porcelain'])
|
|
3552
|
-
if (raw) dirty = raw.split('\n').filter((l) => l.trim()).length
|
|
3553
|
-
const syncState = readSyncState(dshHome)
|
|
3554
|
-
const lp = localPending(dshHome, syncState.lastSyncAt, config?.profileName, { repo, appRoot })
|
|
3555
|
-
// 后台调度里拿不到请求语言,所以中英各存一份,由客户端按自己的语言挑
|
|
3556
|
-
const reasonZh = drift.ahead > 0 ? `领先 ${drift.ahead} 个提交`
|
|
3557
|
-
: dirty > 0 ? `未提交 ${dirty} 项`
|
|
3558
|
-
: (lp.known && lp.pending > 0) ? `本机 ${lp.pending} 个文件比上次同步新` : ''
|
|
3559
|
-
const reasonEn = drift.ahead > 0 ? `${drift.ahead} commit(s) ahead`
|
|
3560
|
-
: dirty > 0 ? `${dirty} uncommitted change(s)`
|
|
3561
|
-
: (lp.known && lp.pending > 0) ? `${lp.pending} file(s) newer than the last sync` : ''
|
|
3562
|
-
if (reasonZh) {
|
|
3563
|
-
// 自动推送不需要确认(用户已开开关),排队等退出即可;推完把客户端拉回来
|
|
3564
|
-
const restart = settings.autoRestart !== false
|
|
3565
|
-
const started = await spawnWatcher({ mode: 'push', repo, appRoot, dshHome, restart })
|
|
3566
|
-
if (started.ok) {
|
|
3567
|
-
autoState.pending = { mode: 'push', at: Date.now(), reason: reasonZh, reasonZh, reasonEn, restart, watcherPid: started.pid, closeRequested: false }
|
|
3568
|
-
} else {
|
|
3569
|
-
autoState.lastCheckError = started.error
|
|
3570
|
-
}
|
|
3571
|
-
}
|
|
3572
|
-
}
|
|
3596
|
+
// 仅更新状态供面板显示;不自动关闭 DSH,关闭由用户显式动作触发
|
|
3573
3597
|
} catch (error) {
|
|
3574
3598
|
autoState.checking = false
|
|
3575
3599
|
autoState.lastCheckAt = Date.now()
|
|
3576
3600
|
autoState.lastCheckError = String((error && error.message) || error)
|
|
3577
3601
|
}
|
|
3578
3602
|
}
|
|
3579
|
-
// 首检别拖太久:用户可能开起来看一眼就关窗口,20 秒会让他这次关闭什么都没推。
|
|
3580
3603
|
autoState.timer = setTimeout(run, 8 * 1000)
|
|
3581
3604
|
try { autoState.timer.unref?.() } catch { }
|
|
3582
|
-
// 之后每 2 分钟复查一次:会话/资料是运行中才产生的,只在启动判一次会把它们全漏掉。
|
|
3583
|
-
// 命中就排一次队,watcher 已在等进程退出,退出即执行;已排队时 run 会直接返回。
|
|
3584
3605
|
try {
|
|
3585
3606
|
autoState.interval = setInterval(run, 2 * 60 * 1000)
|
|
3586
3607
|
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')
|
|
@@ -1905,6 +1908,23 @@ console.log('== 0.3.97:检测到待拉取/待推送就主动强制退出 DSH
|
|
|
1905
1908
|
/result && result\.queued[\s\S]{0,60}?forceCloseDshDetached/.test(idxSrc), 'index.js queued 守卫')
|
|
1906
1909
|
}
|
|
1907
1910
|
console.log('')
|
|
1911
|
+
console.log('== 0.3.99:开关变更即时触发自动同步判断(不等 2 分钟周期)==')
|
|
1912
|
+
{
|
|
1913
|
+
const idxSrc = readFileSync(join(pluginRootSelf, 'index.js'), 'utf8')
|
|
1914
|
+
check('新增 checkAndQueueAutoSync 核心判断函数',
|
|
1915
|
+
/async function checkAndQueueAutoSync\(/.test(idxSrc), 'index.js checkAndQueueAutoSync')
|
|
1916
|
+
check('scheduleAutoStart 复用 checkAndQueueAutoSync',
|
|
1917
|
+
/await checkAndQueueAutoSync\(/.test(idxSrc), 'index.js scheduleAutoStart 复用')
|
|
1918
|
+
check('handleSettings 保存 autoPull/autoPush 后立即调用 checkAndQueueAutoSync',
|
|
1919
|
+
/changed\.autoPull \|\| changed\.autoPush/.test(idxSrc)
|
|
1920
|
+
&& /await checkAndQueueAutoSync\(/.test(idxSrc), 'index.js 即时触发')
|
|
1921
|
+
check('checkAndQueueAutoSync 支持 isManualTrigger 跳过确认框',
|
|
1922
|
+
/isManualTrigger/.test(idxSrc) && /skipConfirm/.test(idxSrc), 'index.js 手动触发模式')
|
|
1923
|
+
check('checkAndQueueAutoSync 返回 queued/mode/reason 供上层判断',
|
|
1924
|
+
/return \{ queued: true, mode:/.test(idxSrc)
|
|
1925
|
+
&& /return \{ queued: false, reason:/.test(idxSrc), 'index.js 返回结构')
|
|
1926
|
+
}
|
|
1927
|
+
console.log('')
|
|
1908
1928
|
console.log('== 0.3.98:默认工作区会话同步(稳定名 --default-workspace--,资料仍不同步)==')
|
|
1909
1929
|
{
|
|
1910
1930
|
const capPath = join(pluginRuntime, 'capture.ps1')
|