dsh-config-sync-plugin 0.3.66 → 0.3.68
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 +50 -1
- package/README.md +50 -1
- package/client.js +81 -1
- package/index.js +215 -8
- package/package.json +1 -1
- package/runtime/apply.ps1 +33 -1
- package/runtime/capture.ps1 +68 -38
- package/runtime/dsh-sync-common.ps1 +131 -1
- package/runtime/tools/session-cache-guard.mjs +407 -0
- package/runtime/tools/session-log-guard.mjs +438 -0
- package/runtime/tools/session-log-lib.mjs +322 -0
- package/tools/check-session-log.mjs +156 -0
- package/tools/pack-plugin.ps1 +1 -1
- package/tools/selftest.mjs +69 -3
- package/tools/session-log-guard.mjs +438 -0
- package/tools/session-log-lib.mjs +322 -0
package/README.en.md
CHANGED
|
@@ -19,7 +19,7 @@ The package name is **`dsh-config-sync-plugin`** (the `dsh-config-sync` name on
|
|
|
19
19
|
|
|
20
20
|
| Way | Command / entry | Notes |
|
|
21
21
|
|---|---|---|
|
|
22
|
-
| npm | `npm i dsh-config-sync-plugin` | Use it as a dependency, or add `"dsh-config-sync-plugin": "^0.3.
|
|
22
|
+
| npm | `npm i dsh-config-sync-plugin` | Use it as a dependency, or add `"dsh-config-sync-plugin": "^0.3.68"` to the profile's `package.json` and run `pnpm i`. The name matches the `cordis.patch.yml` insert name and the install folder `dsh-config-sync-plugin-<ver>` |
|
|
23
23
|
| Marketplace | client → Plugins → Discover → “Config Sync” | Installs from the git commit registered in `market-index.json` |
|
|
24
24
|
| Offline tgz | `releases\dsh-config-sync-plugin-<ver>.tgz` | GitHub Release asset for air-gapped machines; the panel's Update button downloads the same file |
|
|
25
25
|
|
|
@@ -606,6 +606,55 @@ A clean isolated B machine (approot / dshome / wshome + bundled node runner) sim
|
|
|
606
606
|
|
|
607
607
|
Benign warnings (confirmed in the log): `--D-DeepSeekHarness-comfyUI--` / `--dsh-im-forward-confirm--` map to no workspace (special session dirs); `-SkipInstall` skipped 21 registry plugins (isolated offline run — without the flag on a networked machine they install); `dsh-config-sync-0.1.0` / `extra/manifest.json` have no archive/definition and are skipped; the `dsh-config-sync` slot has extra local leftovers (removed only with `-PruneWorkspace`).
|
|
608
608
|
|
|
609
|
+
### 2026-11-19: release 0.3.68 (session projection-cache guard, fixes agent-busy session creation)
|
|
610
|
+
|
|
611
|
+
**Problem**: DSH's "new session" does not always create one. The client first looks for a **blank session** in the workspace to reuse (`client-ui-workspace/createInWorkspace()` → `sessions.ids.find(summary.blank && …)` → `createNamed({ sessionId: blank })`), and `summary.blank` comes from `record.rows.sessionListMetadata.val.blank` in the projection cache `session_projcache\sessions\<id>.json`.
|
|
612
|
+
|
|
613
|
+
That cache can be a half-written artifact: a session creation once wrote `blank:true / seq:-1`, the log afterwards kept appending (`turn/start`, `user/message`), but the cache never advanced. The list therefore still treats the session as blank, the UI picks it for reuse, and the host throws:
|
|
614
|
+
|
|
615
|
+
```
|
|
616
|
+
session/agent-busy: session "<id>" is owned by subagent routing
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
Session creation fails outright and refreshing does not help (the same cache keeps being reused). Cross-machine sync amplifies it: machine A's stale cache is pulled into machine B, which then hits the same wall.
|
|
620
|
+
|
|
621
|
+
**Fix**: three layers, none of which touch the log or the workspace registry — pure cache-file operations.
|
|
622
|
+
|
|
623
|
+
| Layer | Trigger | Action |
|
|
624
|
+
|---|---|---|
|
|
625
|
+
| Client | `sessions.create` hits `agent-busy` | Wraps `sessions.create`: extracts the colliding `sessionId`, reports it to the host, drops the stale `sessionId` and **retries once**. Zero overhead on the normal path |
|
|
626
|
+
| Host | Receives the client report | **Moves** `<DshHome>/storages/session_projcache/sessions/<id>.json` to `<DshHome>/logs/session-cache-guard-backup/` (move only, never delete) so DSH rebuilds the cache from the full log and `blank` becomes `false` |
|
|
627
|
+
| Timer | Every 3 minutes | Proactively sweeps the same class of stale cache. All four conditions must hold (miss rather than mis-delete): (1) cache parses and `blank===true`; (2) a matching `session.v*.jsonl.zstd` exists; (3) the log really has `turn/start` or `user/message`; (4) the log's last event `seq` > the cache's max recorded `seq` |
|
|
628
|
+
|
|
629
|
+
New route `/config-sync/cache-guard`: `GET` is a read-only scan; `POST` accepts `scan` / `sweep` / `clear` / `busy`. A `cacheGuard` switch was added to settings, **on by default**; when off, neither the timer nor the client `agent-busy` report does anything.
|
|
630
|
+
|
|
631
|
+
Implementation: `runtime/tools/session-cache-guard.mjs` (`scanSessionCaches` / `clearSessionCaches` / `runGuard` / `indexSessionLogs`); the client half lives in the `0.3.68:会话缓存守卫` block of `client.js`.
|
|
632
|
+
|
|
633
|
+
**Manual fallback**: the "Session cache guard" card in the panel scans on demand, shows each candidate with its evidence, and lets you pick what to clear. Cache files are only ever backed up, never deleted — a wrong clear is reversible from `<DshHome>/logs/session-cache-guard-backup/`.
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
### 2026-11-19: release 0.3.67 (seq reconciliation guard for session logs)
|
|
637
|
+
|
|
638
|
+
**Problem**: when two machines each append to the same session, sync used a whole-file copy. Whichever side pushed last overwrote the other side's tail, the event stream developed a `seq` jump, and DSH refused to open the session: `stored session ... is corrupt: corrupt session log: invalid committed event at line N: released v2 row N has seq gap (expected X, got Y)`.
|
|
639
|
+
|
|
640
|
+
**Fix**: `capture.ps1` (push side) and `apply.ps1` (pull side) no longer `Copy-Item -Force` a `session*.jsonl.zstd`; they hand it to the new seq guard:
|
|
641
|
+
|
|
642
|
+
| Case | Action |
|
|
643
|
+
|---|---|
|
|
644
|
+
| Target is newer or identical | keep target, write nothing |
|
|
645
|
+
| Source is a strict superset | copy source over target |
|
|
646
|
+
| Each side has exclusive events | merge by `seq`; both sides' events survive |
|
|
647
|
+
| Target itself has a hole the source can fill | repair then write (`merge` — rescues an already-damaged session) |
|
|
648
|
+
| Hole cannot be filled (events really lost) | **leave the file untouched**, record `failed` in `sync-notices.json`, flag for manual handling |
|
|
649
|
+
|
|
650
|
+
Implementation: `tools/session-log-lib.mjs` (multi-frame zstd decoding, byte-prefix compare, seq merge) + `tools/session-log-guard.mjs` (`check` / `decide` / `merge` / `batch`; batch mode is what the ps1 scripts call, and results go through a temp JSON file rather than stdout because Electron is a GUI subsystem). A full 11MB session parses in ~0.6s, fast enough for the sync hot path.
|
|
651
|
+
|
|
652
|
+
**Two extras**:
|
|
653
|
+
- `.gitattributes` now marks `conversations/sessions/**/*.zstd binary` and `workspace/** -text`, so Windows `core.autocrlf` or git line-ending normalisation cannot corrupt the binary logs again;
|
|
654
|
+
- `capture.ps1` hoists the tree-compare helpers above their first use: they were defined after the call site, so `-WorkspaceOnly` hit `Test-TreeFileChanged is not recognized` in the session mirror loop.
|
|
655
|
+
|
|
656
|
+
Diagnostic: `node tools/check-session-log.mjs <log>` or `<logA> <logB>` prints self-consistency (rows / seq range / gaps) and the relation between two files (`identical` / `prefix` / `superset` / `fork`).
|
|
657
|
+
|
|
609
658
|
### 2026-11-19: release 0.3.66 (.gitattributes silences LF/CRLF warnings)
|
|
610
659
|
- **Cross-platform line ending noise**: on Windows `core.autocrlf=true` converts LF in `session_projcache/*.json` to CRLF, causing Git to warn "LF will be replaced by CRLF" on push. Added `.gitattributes` marking that directory as binary (`binary`) and all other text files as `eol=lf`, eliminating the warning class entirely.
|
|
611
660
|
- Pure config change; no sync logic, behavior, or data changes.
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ DSH 插件:左侧栏多一行「配置同步」,点开是整页体检面板
|
|
|
15
15
|
|
|
16
16
|
| 方式 | 命令 / 入口 | 说明 |
|
|
17
17
|
|---|---|---|
|
|
18
|
-
| npm | `npm i dsh-config-sync-plugin` | 适合把它当依赖管理,或在 profile 的 `package.json` 里写 `"dsh-config-sync-plugin": "^0.3.
|
|
18
|
+
| npm | `npm i dsh-config-sync-plugin` | 适合把它当依赖管理,或在 profile 的 `package.json` 里写 `"dsh-config-sync-plugin": "^0.3.68"` 后 `pnpm i`;包名与 `cordis.patch.yml` 里注册的名字、插件目录 `dsh-config-sync-plugin-<ver>` 一致 |
|
|
19
19
|
| 插件市场 | 客户端「插件市场 → 发现」搜「配置同步」 | 走 `market-index.json` 登记的 git 提交,版本与 README 对齐 |
|
|
20
20
|
| 离线 tgz | `releases\dsh-config-sync-plugin-<ver>.tgz` | GitHub Release 附件,适合内网机器;面板「更新」按钮下载的也是它 |
|
|
21
21
|
|
|
@@ -582,6 +582,55 @@ pwsh -File sync.ps1 push -ScanHistory
|
|
|
582
582
|
|
|
583
583
|
非故障警告(日志已确认无害):`--D-DeepSeekHarness-comfyUI--` / `--dsh-im-forward-confirm--` 找不到对应工作区(特殊会话目录);`-SkipInstall` 跳过 21 个 registry 插件(隔离环境离线,真机有网时不加即补齐);`dsh-config-sync-0.1.0` / `extra/manifest.json` 无归档正常跳过;`dsh-config-sync` 槽位有本机多出的残留文件(加 `-PruneWorkspace` 才删)。
|
|
584
584
|
|
|
585
|
+
### 2026-11-19:发版 0.3.68(会话投影缓存守卫,治 agent-busy 建会话失败)
|
|
586
|
+
|
|
587
|
+
**问题**:DSH 的「新建会话」并不每次都真建——客户端会先在工作区里找一条**空白会话**复用(`client-ui-workspace/createInWorkspace()` → `sessions.ids.find(summary.blank && …)` → `createNamed({ sessionId: blank })`)。而 `summary.blank` 来自投影缓存 `session_projcache\sessions\<id>.json` 里的 `record.rows.sessionListMetadata.val.blank`。
|
|
588
|
+
|
|
589
|
+
缓存是「写一半就停」的产物:某次建会话时写出了 `blank:true / seq:-1`,之后日志继续追加(有了 `turn/start`、`user/message`),缓存却没跟着推进。于是列表仍把这条会话当空白,UI 挑它复用,宿主抛:
|
|
590
|
+
|
|
591
|
+
```
|
|
592
|
+
session/agent-busy: session "<id>" is owned by subagent routing
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
新建会话直接失败,且刷不回来(缓存一直被复用)。跨机同步会放大这个问题——A 机的陈旧缓存被 pull 到 B 机,B 机同样中招。
|
|
596
|
+
|
|
597
|
+
**修复**:三层,都不碰日志、不碰工作区登记,只做缓存文件操作。
|
|
598
|
+
|
|
599
|
+
| 层 | 触发 | 动作 |
|
|
600
|
+
|---|---|---|
|
|
601
|
+
| 客户端 | `sessions.create` 撞上 `agent-busy` | 包一层 `sessions.create`:捞出撞车的 `sessionId` 报给宿主,去掉旧 `sessionId` 后**重试一次**。正常路径零开销 |
|
|
602
|
+
| 宿主 | 收到客户端上报 | 把 `<DshHome>/storages/session_projcache/sessions/<id>.json` **挪到** `<DshHome>/logs/session-cache-guard-backup/`(只挪不删),DSH 下次读列表时按完整日志重建缓存,`blank` 自然变 `false` |
|
|
603
|
+
| 定时 | 每 3 分钟 | 主动扫同类陈旧缓存,条件四重全中才算(宁可漏判不可误删):①缓存能解析且 `blank===true` ②能找到对应 `session.v*.jsonl.zstd` ③日志里确有 `turn/start` 或 `user/message` ④日志末事件 `seq` > 缓存记录的最大 `seq` |
|
|
604
|
+
|
|
605
|
+
新增路由 `/config-sync/cache-guard`:`GET` 只读扫描;`POST` 支持 `scan` / `sweep` / `clear` / `busy`。设置里新增 `cacheGuard` 开关,**默认开**;关掉后既不定时扫描,也不理会客户端的 `agent-busy` 上报。
|
|
606
|
+
|
|
607
|
+
实现:`runtime/tools/session-cache-guard.mjs`(`scanSessionCaches` / `clearSessionCaches` / `runGuard` / `indexSessionLogs`),客户端半身在 `client.js` 的 `0.3.68:会话缓存守卫` 段。
|
|
608
|
+
|
|
609
|
+
**手动兜底**:面板「会话缓存守卫」卡可以直接扫一遍、看到候选与判定依据,再决定清哪几条;缓存永远只备份不删除,清错了从 `<DshHome>/logs/session-cache-guard-backup/` 拷回去就行。
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
### 2026-11-19:发版 0.3.67(会话日志 seq 对账护栏)
|
|
613
|
+
|
|
614
|
+
**问题**:两台机器各自往同一个会话写事件时,同步是「整文件覆盖」。谁后 push 谁的内容顶掉对方的后半段,事件流出现 `seq` 跳号,DSH 启动直接报 `stored session ... is corrupt: corrupt session log: invalid committed event at line N: released v2 row N has seq gap (expected X, got Y)`,该会话再也打不开。
|
|
615
|
+
|
|
616
|
+
**修复**:`capture.ps1`(推送侧)与 `apply.ps1`(拉取侧)遇到 `session*.jsonl.zstd` 不再 `Copy-Item -Force`,改为交给新加的 seq 护栏:
|
|
617
|
+
|
|
618
|
+
| 情形 | 处理 |
|
|
619
|
+
|---|---|
|
|
620
|
+
| 目标更全 / 完全相同 | 保留目标,什么都不写 |
|
|
621
|
+
| 源是目标的严格超集 | 用源覆盖目标 |
|
|
622
|
+
| 两边各有独占事件 | 按 `seq` 求并集写入,两边事件全保住 |
|
|
623
|
+
| 目标自身断档、源能补齐 | 先补齐再写(`merge`,可救回已被覆盖坏的会话) |
|
|
624
|
+
| 洞补不回来(事件确实丢了) | **保持原样不覆盖**,记 `sync-notices.json` 的 `failed` 并提示需人工处理 |
|
|
625
|
+
|
|
626
|
+
护栏实现:`tools/session-log-lib.mjs`(多帧 zstd 逐帧解、字节前缀比较、按 seq 合并)+ `tools/session-log-guard.mjs`(`check` / `decide` / `merge` / `batch` CLI,批量模式给 ps1 调用,结果走临时 JSON 文件而不是 stdout——Electron 是 GUI 子系统)。11MB 会话全量解析 ~0.6s,可进同步热路径。
|
|
627
|
+
|
|
628
|
+
**顺带两处**:
|
|
629
|
+
- `.gitattributes` 补 `conversations/sessions/**/*.zstd binary` 与 `workspace/** -text`,避免 Windows `core.autocrlf` 或 git 的行尾归一再次写坏二进制日志;
|
|
630
|
+
- `capture.ps1` 把「大目录文件比较」几个辅助函数上移到脚本前部——它们原先定义在调用点之后,`-WorkspaceOnly` 跑到会话镜像循环会报 `Test-TreeFileChanged is not recognized`。
|
|
631
|
+
|
|
632
|
+
诊断工具:`node tools/check-session-log.mjs <日志>` 或 `<日志A> <日志B>`,输出自洽性(行数/seq 范围/gaps)与两份的关系(`identical` / `prefix` / `superset` / `fork`)。
|
|
633
|
+
|
|
585
634
|
### 2026-11-19:发版 0.3.66(.gitattributes 消除 LF/CRLF 警告)
|
|
586
635
|
- **跨平台行尾噪音**:Windows 上 `core.autocrlf=true` 会把仓库里 LF 写入的 `session_projcache/*.json` 自动转成 CRLF,推送时 Git 报 "LF will be replaced by CRLF" 警告。新增 `.gitattributes` 将该目录标记为二进制(`binary`),其余文本文件统一 `eol=lf`,彻底消除该类警告。
|
|
587
636
|
- 纯配置项改动,不改变任何同步逻辑、行为与数据。
|
package/client.js
CHANGED
|
@@ -929,7 +929,7 @@ window.__ModuleLoader__.load({
|
|
|
929
929
|
}
|
|
930
930
|
// 「手动还原」指引里的目标位置:认不出类型时按内容猜不到,索性把三类常见落点都摆出来
|
|
931
931
|
const manualTargets = () => [
|
|
932
|
-
M('插件本体 → 插件安装目录(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.
|
|
932
|
+
M('插件本体 → 插件安装目录(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.67)', 'Plugin files → the plugin install folder (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.67)'),
|
|
933
933
|
M('会话目录(--xxx--)→ ~\\.dsh\\sessions', 'Session folders (--xxx--) → ~\\.dsh\\sessions'),
|
|
934
934
|
M('配置五件套(package.json / pnpm-lock.yaml / cordis.yml…)→ ~\\.dsh\\profiles\\desktop', 'Config files (package.json / pnpm-lock.yaml / cordis.yml…) → ~\\.dsh\\profiles\\desktop'),
|
|
935
935
|
]
|
|
@@ -3185,6 +3185,67 @@ window.__ModuleLoader__.load({
|
|
|
3185
3185
|
} catch { /* 插件路由还没起好就静默跳过,面板里仍会显示同一结果 */ }
|
|
3186
3186
|
}
|
|
3187
3187
|
|
|
3188
|
+
// ==================== 0.3.68:会话缓存守卫(客户端半身) ====================
|
|
3189
|
+
// 宿主侧没法拦 agent-busy(它是 sessionController 内部抛的 RemoteError),
|
|
3190
|
+
// 所以在这里包一层 sessions.create:撞上就上报、清缓存、去掉旧 sessionId 重试一次。
|
|
3191
|
+
const BUSY_RE = /session\/agent-busy|is owned by subagent routing/i
|
|
3192
|
+
|
|
3193
|
+
/** 从错误里抠出撞车的 sessionId;不是 agent-busy 就返回空串。 */
|
|
3194
|
+
function busySessionId(error) {
|
|
3195
|
+
const text = String((error && (error.message || error)) || '')
|
|
3196
|
+
if (!BUSY_RE.test(text)) return ''
|
|
3197
|
+
const quoted = text.match(/session\s+"([^"]+)"/i) || text.match(/session\s+'([^']+)'/i)
|
|
3198
|
+
return quoted ? String(quoted[1] || '') : ''
|
|
3199
|
+
}
|
|
3200
|
+
|
|
3201
|
+
/** 告诉宿主半身「这条会话撞了 agent-busy」,让它清缓存。失败也不影响新建会话。 */
|
|
3202
|
+
async function reportAgentBusy(sessionId) {
|
|
3203
|
+
try {
|
|
3204
|
+
const res = await fetch('/config-sync/cache-guard', {
|
|
3205
|
+
method: 'POST',
|
|
3206
|
+
cache: 'no-store',
|
|
3207
|
+
credentials: 'same-origin',
|
|
3208
|
+
headers: jsonHeaders,
|
|
3209
|
+
body: JSON.stringify({ action: 'busy', sessionId: sessionId || '' }),
|
|
3210
|
+
})
|
|
3211
|
+
if (!res.ok) return false
|
|
3212
|
+
const body = await res.json()
|
|
3213
|
+
return Boolean(body && body.ok)
|
|
3214
|
+
} catch { return false }
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3217
|
+
/**
|
|
3218
|
+
* 包一层 sessions.create:
|
|
3219
|
+
* 正常路径零开销;只有抛 agent-busy 时才清缓存、把可复用的旧 sessionId 去掉重试一次。
|
|
3220
|
+
* 返回还原函数,插件卸载时把 create 换回去(宿主热重载不残留)。
|
|
3221
|
+
*/
|
|
3222
|
+
function guardSessionCreate(sessions) {
|
|
3223
|
+
if (!sessions || typeof sessions.create !== 'function') return () => { }
|
|
3224
|
+
const original = sessions.create
|
|
3225
|
+
let installed = true
|
|
3226
|
+
sessions.create = async function patchedCreate(opts) {
|
|
3227
|
+
try {
|
|
3228
|
+
return await original.call(this, opts)
|
|
3229
|
+
} catch (error) {
|
|
3230
|
+
const sessionId = busySessionId(error)
|
|
3231
|
+
if (sessionId === '') throw error
|
|
3232
|
+
try { console.warn('[dsh-config-sync] new session hit agent-busy:', sessionId, '→ 清投影缓存后重试') } catch { }
|
|
3233
|
+
const reported = await reportAgentBusy(sessionId)
|
|
3234
|
+
// 只有宿主确实动了缓存才重试,否则原错误照抛,免得反复撞同一堵墙。
|
|
3235
|
+
if (!reported) throw error
|
|
3236
|
+
const retry = { ...(opts || {}) }
|
|
3237
|
+
delete retry.sessionId
|
|
3238
|
+
return await original.call(this, retry)
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
return () => {
|
|
3242
|
+
try {
|
|
3243
|
+
if (installed) sessions.create = original
|
|
3244
|
+
} catch { }
|
|
3245
|
+
installed = false
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3188
3249
|
function apply(ctx) {
|
|
3189
3250
|
// 侧栏行 + 配对面板:两个 slot 必须各自 inject(嵌套),再在作用域里成对 register。
|
|
3190
3251
|
// 只 inject('main') 就向 sidebar.panellist 注册是无效的——区域还没被注入,注册落不下去。
|
|
@@ -3220,6 +3281,25 @@ window.__ModuleLoader__.load({
|
|
|
3220
3281
|
|
|
3221
3282
|
// 界面还没完全起来时 fetch 可能扑空,所以稍等一会儿再查;只查一次,不轮询。
|
|
3222
3283
|
try { setTimeout(announceLastResult, 1500) } catch { }
|
|
3284
|
+
|
|
3285
|
+
// 0.3.68:给客户端的 sessions 服务套上 agent-busy 自愈钩子。
|
|
3286
|
+
// 拿不到 sessions(老版本宿主 / 服务还没起来)就静默跳过,面板功能不受影响。
|
|
3287
|
+
try {
|
|
3288
|
+
if (typeof ctx.get === 'function') {
|
|
3289
|
+
const sessions = ctx.get('sessions')
|
|
3290
|
+
if (sessions) {
|
|
3291
|
+
const off = guardSessionCreate(sessions)
|
|
3292
|
+
if (typeof ctx.effect === 'function') ctx.effect(() => () => { try { off() } catch { } })
|
|
3293
|
+
}
|
|
3294
|
+
} else if (typeof ctx.inject === 'function') {
|
|
3295
|
+
ctx.inject(['sessions'], (scoped) => {
|
|
3296
|
+
const off = guardSessionCreate(scoped.sessions || scoped.get('sessions'))
|
|
3297
|
+
return () => { try { off() } catch { } }
|
|
3298
|
+
})
|
|
3299
|
+
}
|
|
3300
|
+
} catch (error) {
|
|
3301
|
+
try { console.warn('[dsh-config-sync] session cache guard install failed:', error) } catch { }
|
|
3302
|
+
}
|
|
3223
3303
|
}
|
|
3224
3304
|
|
|
3225
3305
|
exports.name = name
|
package/index.js
CHANGED
|
@@ -24,6 +24,8 @@ import { closeSync, existsSync, mkdirSync, mkdtempSync, openSync, readdirSync, r
|
|
|
24
24
|
import { homedir, hostname, tmpdir } from 'node:os'
|
|
25
25
|
import { basename, dirname, isAbsolute, join, relative } from 'node:path'
|
|
26
26
|
import { fileURLToPath } from 'node:url'
|
|
27
|
+
// 0.3.68:会话投影缓存守卫(agent-busy 自动清缓存,让缓存按日志重建)
|
|
28
|
+
import { runGuard, clearSessionCaches, appendGuardLog } from './runtime/tools/session-cache-guard.mjs'
|
|
27
29
|
|
|
28
30
|
const pluginRequire = createRequire(import.meta.url)
|
|
29
31
|
|
|
@@ -37,6 +39,8 @@ const ROUTE_CONFLICT = '/config-sync/conflict'
|
|
|
37
39
|
// 0.3.30:跨机路径确认(每台机器把自己的根目录报给插件一次)与问题反馈(落仓库 feedback\ 再推 GitHub)
|
|
38
40
|
const ROUTE_ROOTS = '/config-sync/roots'
|
|
39
41
|
const ROUTE_FEEDBACK = '/config-sync/feedback'
|
|
42
|
+
// 0.3.68:会话投影缓存守卫(GET 只读扫描 / POST scan|sweep|clear|busy)
|
|
43
|
+
const ROUTE_CACHE_GUARD = '/config-sync/cache-guard'
|
|
40
44
|
const SETTINGS_NAME = 'dsh-config-sync.json'
|
|
41
45
|
/** 本插件自己的安装目录(插件根,含 runtime\ 与 index.js)—— 插件备份还原时的目标。 */
|
|
42
46
|
const PLUGIN_ROOT = fileURLToPath(new URL('.', import.meta.url)).replace(/[\\/]+$/, '')
|
|
@@ -233,6 +237,8 @@ function readSettings(dshHome) {
|
|
|
233
237
|
// 同步完成重启前把 DSH 的「默认工作区」校正到谁:
|
|
234
238
|
// 留空 = 自动找名字/路径是 default-workspace 的工作区;可填工作区路径或 ID;填 off 关闭。
|
|
235
239
|
defaultWorkspace: typeof raw.defaultWorkspace === 'string' ? raw.defaultWorkspace : '',
|
|
240
|
+
// 0.3.68:会话投影缓存守卫,默认开。关掉后既不定时扫描,也不理会客户端的 agent-busy 上报。
|
|
241
|
+
cacheGuard: raw.cacheGuard !== false,
|
|
236
242
|
}
|
|
237
243
|
}
|
|
238
244
|
|
|
@@ -254,6 +260,7 @@ function writeSettings(dshHome, s) {
|
|
|
254
260
|
updateToken: s.updateToken || '',
|
|
255
261
|
backupRoot: s.backupRoot || '',
|
|
256
262
|
defaultWorkspace: s.defaultWorkspace || '',
|
|
263
|
+
cacheGuard: s.cacheGuard !== false,
|
|
257
264
|
}, null, 2) + '\n'
|
|
258
265
|
writeFileSync(settingsPath(dshHome), payload, 'utf8')
|
|
259
266
|
}
|
|
@@ -976,9 +983,9 @@ async function inspect(config) {
|
|
|
976
983
|
const remoteFiles = remoteProbe ? remoteProbe.files : null
|
|
977
984
|
if (!appRoot) {
|
|
978
985
|
advice.push(t(
|
|
979
|
-
'定位不到客户端根目录:插件不在 <客户端根> 下(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.
|
|
986
|
+
'定位不到客户端根目录:插件不在 <客户端根> 下(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.67),'
|
|
980
987
|
+ '或客户端是打包版(resources\\app.asar)而这里没认出来 —— 三份同步脚本会因此生成不了',
|
|
981
|
-
'Cannot locate the client root: the plugin is not under <client root> (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.
|
|
988
|
+
'Cannot locate the client root: the plugin is not under <client root> (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.67), '
|
|
982
989
|
+ 'or this is a packaged build (resources\\app.asar) that was not recognized — the three sync scripts cannot be generated.',
|
|
983
990
|
))
|
|
984
991
|
}
|
|
@@ -1173,6 +1180,8 @@ async function inspect(config) {
|
|
|
1173
1180
|
const pending = c.items.filter((it) => !it.choice).length
|
|
1174
1181
|
return { exists: true, total: c.items.length, pending, at: c.at || '', backupDir: c.backupDir || '' }
|
|
1175
1182
|
})(),
|
|
1183
|
+
// 0.3.68:会话投影缓存守卫状态(面板「会话缓存守卫」卡用)
|
|
1184
|
+
cacheGuard: cacheGuardSnapshot(config),
|
|
1176
1185
|
}
|
|
1177
1186
|
}
|
|
1178
1187
|
|
|
@@ -1953,20 +1962,22 @@ async function handleSettings(req, res, config) {
|
|
|
1953
1962
|
const autoPull = has('autoPull') ? body.autoPull === true : before.autoPull
|
|
1954
1963
|
const autoPush = has('autoPush') ? body.autoPush === true : before.autoPush
|
|
1955
1964
|
const autoRestart = has('autoRestart') ? body.autoRestart !== false : before.autoRestart
|
|
1965
|
+
// 0.3.68:会话投影缓存守卫开关,字段没给就沿用原值
|
|
1966
|
+
const cacheGuard = has('cacheGuard') ? body.cacheGuard !== false : before.cacheGuard
|
|
1956
1967
|
|
|
1957
1968
|
if (!has('repoPath') && !has('remoteUrl') && !has('sshKey') &&
|
|
1958
1969
|
!has('autoPull') && !has('autoPush') && !has('autoRestart') &&
|
|
1959
|
-
!has('backupRoot') && !has('defaultWorkspace') &&
|
|
1970
|
+
!has('backupRoot') && !has('defaultWorkspace') && !has('cacheGuard') &&
|
|
1960
1971
|
!has('updateToken') && !has('updateManifestUrl') && body.clearUpdateToken !== true && body.clearUpdateManifestUrl !== true && body.clearBackupRoot !== true && body.clearDefaultWorkspace !== true) {
|
|
1961
1972
|
throw new Error(t(
|
|
1962
|
-
'没有要保存的字段(repoPath / remoteUrl / sshKey / autoPull / autoPush / autoRestart / backupRoot / defaultWorkspace / updateToken / updateManifestUrl 至少给一个)',
|
|
1963
|
-
'Nothing to save (provide at least one of repoPath / remoteUrl / sshKey / autoPull / autoPush / autoRestart / backupRoot / defaultWorkspace / updateToken / updateManifestUrl)',
|
|
1973
|
+
'没有要保存的字段(repoPath / remoteUrl / sshKey / autoPull / autoPush / autoRestart / backupRoot / defaultWorkspace / cacheGuard / updateToken / updateManifestUrl 至少给一个)',
|
|
1974
|
+
'Nothing to save (provide at least one of repoPath / remoteUrl / sshKey / autoPull / autoPush / autoRestart / backupRoot / defaultWorkspace / cacheGuard / updateToken / updateManifestUrl)',
|
|
1964
1975
|
))
|
|
1965
1976
|
}
|
|
1966
1977
|
|
|
1967
1978
|
// 新仓库路径一落盘,后面的 git remote 要对它做,别用改之前解析出来的旧仓库。
|
|
1968
1979
|
const repo = repoPath || (resolveRepo(config?.repoPath, dshHome).repo || '')
|
|
1969
|
-
writeSettings(dshHome, { repoPath, remoteUrl, sshKey, autoPull, autoPush, autoRestart, updateToken, updateManifestUrl, backupRoot, defaultWorkspace })
|
|
1980
|
+
writeSettings(dshHome, { repoPath, remoteUrl, sshKey, autoPull, autoPush, autoRestart, updateToken, updateManifestUrl, backupRoot, defaultWorkspace, cacheGuard })
|
|
1970
1981
|
|
|
1971
1982
|
const changed = {
|
|
1972
1983
|
repoPath: before.repoPath !== repoPath,
|
|
@@ -1976,6 +1987,7 @@ async function handleSettings(req, res, config) {
|
|
|
1976
1987
|
autoPush: before.autoPush !== autoPush,
|
|
1977
1988
|
backupRoot: before.backupRoot !== backupRoot,
|
|
1978
1989
|
defaultWorkspace: before.defaultWorkspace !== defaultWorkspace,
|
|
1990
|
+
cacheGuard: before.cacheGuard !== cacheGuard,
|
|
1979
1991
|
}
|
|
1980
1992
|
let gitSet = null
|
|
1981
1993
|
if (repo && isDir(join(repo, '.git')) && remoteUrl) {
|
|
@@ -3477,9 +3489,9 @@ async function handlePrepare(req, res, config) {
|
|
|
3477
3489
|
if (!appRoot) {
|
|
3478
3490
|
throw new Error(t(
|
|
3479
3491
|
'定位不到客户端根目录(要能找到 resources\\app\\package.json 或 resources\\app.asar):'
|
|
3480
|
-
+ '请确认插件装在 <客户端根> 下(例如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.
|
|
3492
|
+
+ '请确认插件装在 <客户端根> 下(例如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.67),或在设置里填客户端根 appRoot',
|
|
3481
3493
|
'Cannot locate the client root (needs resources\\app\\package.json or resources\\app.asar): '
|
|
3482
|
-
+ 'make sure the plugin is installed under <client root> (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.
|
|
3494
|
+
+ 'make sure the plugin is installed under <client root> (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.67), or set appRoot in the settings',
|
|
3483
3495
|
))
|
|
3484
3496
|
}
|
|
3485
3497
|
const state = {...await repoState(repo), message}
|
|
@@ -4010,6 +4022,192 @@ function newIssueUrl(repo, title, text, config) {
|
|
|
4010
4022
|
return `https://github.com/${repo}/issues/new?${q}`
|
|
4011
4023
|
}
|
|
4012
4024
|
|
|
4025
|
+
// ============================ 0.3.68:会话投影缓存守卫 ============================
|
|
4026
|
+
// 背景:UI 点「新建会话」时会挑一条 summary.blank===true 的会话复用,挑中了 origin=subagent
|
|
4027
|
+
// 的子会话就会被宿主拒绝(session/agent-busy:is owned by subagent routing)。
|
|
4028
|
+
// 起因是投影缓存停在 session/created 那一刻(blank=true、seq=-1),而会话日志早就推进过,
|
|
4029
|
+
// 两边不一致。这里的处理:发现这种「缓存说空、日志有货」的陈旧缓存就把它挪走,让宿主按日志重建。
|
|
4030
|
+
let loggerRef = null
|
|
4031
|
+
function ctxLoggerInfo(text) {
|
|
4032
|
+
try { loggerRef?.info?.(text) } catch { /* 没有 logger 就算了 */ }
|
|
4033
|
+
}
|
|
4034
|
+
|
|
4035
|
+
const cacheGuardState = {
|
|
4036
|
+
timer: null,
|
|
4037
|
+
interval: null,
|
|
4038
|
+
scans: 0,
|
|
4039
|
+
lastScanAt: 0,
|
|
4040
|
+
lastApplyAt: 0,
|
|
4041
|
+
lastStale: 0,
|
|
4042
|
+
lastRemoved: [],
|
|
4043
|
+
lastError: '',
|
|
4044
|
+
lastTrigger: '',
|
|
4045
|
+
busyHits: [],
|
|
4046
|
+
}
|
|
4047
|
+
|
|
4048
|
+
function dshHomeOf(config) {
|
|
4049
|
+
return config?.dshHome || process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
4050
|
+
}
|
|
4051
|
+
|
|
4052
|
+
/** 跑一次扫描。apply=false 只报告不动手;apply=true 会把陈旧缓存挪到备份目录。 */
|
|
4053
|
+
function cacheGuardRun(config, opts = {}) {
|
|
4054
|
+
const apply = opts.apply === true
|
|
4055
|
+
const dshHome = dshHomeOf(config)
|
|
4056
|
+
try {
|
|
4057
|
+
const report = runGuard(dshHome, {
|
|
4058
|
+
apply,
|
|
4059
|
+
source: opts.source || '',
|
|
4060
|
+
ids: Array.isArray(opts.ids) && opts.ids.length > 0 ? opts.ids : undefined,
|
|
4061
|
+
deep: true,
|
|
4062
|
+
})
|
|
4063
|
+
cacheGuardState.scans += 1
|
|
4064
|
+
cacheGuardState.lastScanAt = Date.now()
|
|
4065
|
+
cacheGuardState.lastTrigger = opts.source || ''
|
|
4066
|
+
cacheGuardState.lastStale = report.staleCount || 0
|
|
4067
|
+
cacheGuardState.lastError = (report.errors || []).join('; ')
|
|
4068
|
+
if (apply) {
|
|
4069
|
+
cacheGuardState.lastApplyAt = Date.now()
|
|
4070
|
+
cacheGuardState.lastRemoved = (report.removed || []).map((x) => ({ id: x.id, to: x.to }))
|
|
4071
|
+
if (cacheGuardState.lastRemoved.length > 0) {
|
|
4072
|
+
ctxLoggerInfo(`[dsh-config-sync-plugin] 已清理 ${cacheGuardState.lastRemoved.length} 条陈旧会话投影缓存:${cacheGuardState.lastRemoved.map((x) => x.id).join(', ')}`)
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
return report
|
|
4076
|
+
} catch (error) {
|
|
4077
|
+
const message = String((error && error.message) || error)
|
|
4078
|
+
cacheGuardState.scans += 1
|
|
4079
|
+
cacheGuardState.lastScanAt = Date.now()
|
|
4080
|
+
cacheGuardState.lastTrigger = opts.source || ''
|
|
4081
|
+
cacheGuardState.lastError = message
|
|
4082
|
+
return { ok: false, scanned: 0, blank: 0, staleCount: 0, stale: [], removed: [], errors: [message] }
|
|
4083
|
+
}
|
|
4084
|
+
}
|
|
4085
|
+
|
|
4086
|
+
/** 客户端报某条会话撞了 agent-busy:先把它的缓存定点点掉,再全盘扫一遍同类陈旧项。 */
|
|
4087
|
+
function cacheGuardOnBusy(config, sessionId) {
|
|
4088
|
+
const dshHome = dshHomeOf(config)
|
|
4089
|
+
const id = String(sessionId || '').trim()
|
|
4090
|
+
const out = { ok: true, sessionId: id, cleared: false, report: null }
|
|
4091
|
+
if (id) {
|
|
4092
|
+
try {
|
|
4093
|
+
const res = clearSessionCaches(dshHome, [id], { reason: 'agent-busy' })
|
|
4094
|
+
out.cleared = Array.isArray(res.removed) && res.removed.length > 0
|
|
4095
|
+
if (out.cleared) {
|
|
4096
|
+
appendGuardLog(dshHome, `[agent-busy] 客户端报 session/agent-busy,已清掉 ${id} 的投影缓存`)
|
|
4097
|
+
ctxLoggerInfo(`[dsh-config-sync-plugin] agent-busy:已清掉 ${id} 的投影缓存,下次新建会话会按日志重建`)
|
|
4098
|
+
}
|
|
4099
|
+
} catch (error) {
|
|
4100
|
+
out.ok = false
|
|
4101
|
+
out.error = String((error && error.message) || error)
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
out.report = cacheGuardRun(config, { apply: true, source: 'agent-busy' })
|
|
4105
|
+
cacheGuardState.busyHits.unshift({ at: Date.now(), sessionId: id, cleared: out.cleared })
|
|
4106
|
+
if (cacheGuardState.busyHits.length > 20) cacheGuardState.busyHits.length = 20
|
|
4107
|
+
return out
|
|
4108
|
+
}
|
|
4109
|
+
|
|
4110
|
+
/** 启动后 12 秒首扫一次,之后每 3 分钟一次;设置里关掉就完全不启动。 */
|
|
4111
|
+
function scheduleCacheGuard(config) {
|
|
4112
|
+
try {
|
|
4113
|
+
if (cacheGuardState.timer) return
|
|
4114
|
+
if (readSettings(dshHomeOf(config)).cacheGuard === false) return
|
|
4115
|
+
const run = () => {
|
|
4116
|
+
try { cacheGuardRun(config, { apply: true, source: 'timer' }) } catch { /* 定时任务不抛 */ }
|
|
4117
|
+
}
|
|
4118
|
+
cacheGuardState.timer = setTimeout(run, 12 * 1000)
|
|
4119
|
+
try { cacheGuardState.timer.unref?.() } catch { }
|
|
4120
|
+
cacheGuardState.interval = setInterval(run, 3 * 60 * 1000)
|
|
4121
|
+
try { cacheGuardState.interval.unref?.() } catch { }
|
|
4122
|
+
} catch { /* 定时器起不来不影响插件其它功能 */ }
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
function cacheGuardSnapshot(config) {
|
|
4126
|
+
const dshHome = dshHomeOf(config)
|
|
4127
|
+
const settings = readSettings(dshHome)
|
|
4128
|
+
return {
|
|
4129
|
+
enabled: settings.cacheGuard !== false,
|
|
4130
|
+
scans: cacheGuardState.scans,
|
|
4131
|
+
lastScanAt: cacheGuardState.lastScanAt,
|
|
4132
|
+
lastApplyAt: cacheGuardState.lastApplyAt,
|
|
4133
|
+
lastStale: cacheGuardState.lastStale,
|
|
4134
|
+
lastRemoved: cacheGuardState.lastRemoved,
|
|
4135
|
+
lastError: cacheGuardState.lastError,
|
|
4136
|
+
lastTrigger: cacheGuardState.lastTrigger,
|
|
4137
|
+
busyHits: cacheGuardState.busyHits.slice(0, 5),
|
|
4138
|
+
backupDir: join(dshHome, 'logs', 'session-cache-guard-backup'),
|
|
4139
|
+
logPath: join(dshHome, 'logs', 'session-cache-guard.log'),
|
|
4140
|
+
}
|
|
4141
|
+
}
|
|
4142
|
+
|
|
4143
|
+
async function handleCacheGuard(req, res, config) {
|
|
4144
|
+
if (req.method === 'GET') {
|
|
4145
|
+
const report = cacheGuardRun(config, { apply: false, source: 'panel' })
|
|
4146
|
+
sendJson(res, 200, {
|
|
4147
|
+
ok: true,
|
|
4148
|
+
applied: false,
|
|
4149
|
+
state: cacheGuardSnapshot(config),
|
|
4150
|
+
scanned: report.scanned,
|
|
4151
|
+
blank: report.blank,
|
|
4152
|
+
staleCount: report.staleCount,
|
|
4153
|
+
stale: report.stale || [],
|
|
4154
|
+
removed: [],
|
|
4155
|
+
errors: report.errors || [],
|
|
4156
|
+
})
|
|
4157
|
+
return
|
|
4158
|
+
}
|
|
4159
|
+
if (req.method !== 'POST') { sendJson(res, 405, { ok: false, error: 'GET/POST only' }); return }
|
|
4160
|
+
if (!originAllowed(req)) { sendJson(res, 403, { ok: false, error: 'cross-origin request rejected' }); return }
|
|
4161
|
+
try {
|
|
4162
|
+
const raw = await readBody(req)
|
|
4163
|
+
const body = raw.trim() ? JSON.parse(raw) : {}
|
|
4164
|
+
const action = String(body.action || 'scan')
|
|
4165
|
+
if (action === 'scan') {
|
|
4166
|
+
const report = cacheGuardRun(config, { apply: false, source: 'panel' })
|
|
4167
|
+
sendJson(res, 200, {
|
|
4168
|
+
ok: true,
|
|
4169
|
+
applied: false,
|
|
4170
|
+
state: cacheGuardSnapshot(config),
|
|
4171
|
+
scanned: report.scanned,
|
|
4172
|
+
blank: report.blank,
|
|
4173
|
+
staleCount: report.staleCount,
|
|
4174
|
+
stale: report.stale || [],
|
|
4175
|
+
errors: report.errors || [],
|
|
4176
|
+
})
|
|
4177
|
+
return
|
|
4178
|
+
}
|
|
4179
|
+
if (action === 'sweep') {
|
|
4180
|
+
const report = cacheGuardRun(config, { apply: true, source: 'panel' })
|
|
4181
|
+
sendJson(res, 200, {
|
|
4182
|
+
ok: true,
|
|
4183
|
+
applied: true,
|
|
4184
|
+
state: cacheGuardSnapshot(config),
|
|
4185
|
+
scanned: report.scanned,
|
|
4186
|
+
blank: report.blank,
|
|
4187
|
+
staleCount: report.staleCount,
|
|
4188
|
+
stale: report.stale || [],
|
|
4189
|
+
removed: report.removed || [],
|
|
4190
|
+
errors: report.errors || [],
|
|
4191
|
+
})
|
|
4192
|
+
return
|
|
4193
|
+
}
|
|
4194
|
+
if (action === 'clear') {
|
|
4195
|
+
const ids = Array.isArray(body.ids) ? body.ids.map((x) => String(x || '').trim()).filter(Boolean) : []
|
|
4196
|
+
if (ids.length === 0) throw new Error(t('ids 不能为空', 'ids must not be empty'))
|
|
4197
|
+
const out = clearSessionCaches(dshHomeOf(config), ids, { reason: 'panel' })
|
|
4198
|
+
sendJson(res, 200, { ok: true, applied: true, removed: out.removed || [], errors: out.errors || [], state: cacheGuardSnapshot(config) })
|
|
4199
|
+
return
|
|
4200
|
+
}
|
|
4201
|
+
if (action === 'busy') {
|
|
4202
|
+
const out = cacheGuardOnBusy(config, body.sessionId)
|
|
4203
|
+
sendJson(res, 200, out)
|
|
4204
|
+
return
|
|
4205
|
+
}
|
|
4206
|
+
throw new Error(t('action 只能是 scan / sweep / clear / busy', 'action must be one of scan / sweep / clear / busy'))
|
|
4207
|
+
} catch (error) {
|
|
4208
|
+
sendJson(res, 400, { ok: false, error: String((error && error.message) || error) })
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4013
4211
|
|
|
4014
4212
|
async function handleFeedback(req, res, config) {
|
|
4015
4213
|
const dshHome = config?.dshHome || process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
@@ -4177,6 +4375,7 @@ async function handleFeedback(req, res, config) {
|
|
|
4177
4375
|
|
|
4178
4376
|
export function apply(ctx, config) {
|
|
4179
4377
|
try {
|
|
4378
|
+
try { loggerRef = ctx?.logger || null } catch { }
|
|
4180
4379
|
ctx.inject(['webServer'], (scoped) => {
|
|
4181
4380
|
// 每个请求按 accept-language 决定返回中文还是英文:AsyncLocalStorage 让 t() 在
|
|
4182
4381
|
// 任何异步后续里都能读到本次请求的语言,不用把语言参数一层层往下传。
|
|
@@ -4231,6 +4430,12 @@ export function apply(ctx, config) {
|
|
|
4231
4430
|
path: ROUTE_FEEDBACK,
|
|
4232
4431
|
handler: withLang(handleFeedback),
|
|
4233
4432
|
}))
|
|
4433
|
+
// 0.3.68:会话投影缓存守卫(GET 只读扫描 / POST scan|sweep|clear|busy)
|
|
4434
|
+
scoped.effect(() => scoped.webServer.register({
|
|
4435
|
+
kind: 'exact',
|
|
4436
|
+
path: ROUTE_CACHE_GUARD,
|
|
4437
|
+
handler: withLang(handleCacheGuard),
|
|
4438
|
+
}))
|
|
4234
4439
|
})
|
|
4235
4440
|
// 开关打开才排一次启动检查(默认关 = 什么都不做)
|
|
4236
4441
|
scheduleAutoStart(config)
|
|
@@ -4238,6 +4443,8 @@ export function apply(ctx, config) {
|
|
|
4238
4443
|
// status 不用再为首屏那 2.5 秒的 ls-remote 埋单。
|
|
4239
4444
|
typeof setTimeout === 'function' ? setTimeout(() => { try { warmRemoteProbe(config) } catch { } }, 300) : null
|
|
4240
4445
|
installQuitWhenAllWindowsClosed(ctx)
|
|
4446
|
+
// 0.3.68:会话投影缓存守卫的定时扫描(默认开,设置里可关)
|
|
4447
|
+
scheduleCacheGuard(config)
|
|
4241
4448
|
} catch (error) {
|
|
4242
4449
|
// 不抛:缺 webServer 的 profile 里这个插件静默不激活即可
|
|
4243
4450
|
try { ctx.logger?.warn?.(`[${PACKAGE_ID}] webServer 不可用,设置页面板不会出现:${error}`) } catch { }
|
package/package.json
CHANGED
package/runtime/apply.ps1
CHANGED
|
@@ -553,6 +553,11 @@ function Sync-ConversationApply {
|
|
|
553
553
|
@{ Repo = 'vision_router_session_policy'; Dst = (Join-Path $DshHome 'storages\vision_router_session_policy\policies'); Remap = $false }
|
|
554
554
|
)
|
|
555
555
|
$nAdd = 0; $nBk = 0
|
|
556
|
+
# 会话日志不能整文件覆盖:本机可能比仓库更新(本机后面又追加了事件),仓库也可能带着
|
|
557
|
+
# 另一条 lineage。直接覆盖会让一方的事件整段消失或首尾拼接,DSH 启动时报 "seq gap"。
|
|
558
|
+
# 这里先攒成批量任务,交给 seq 护栏对账后再写。
|
|
559
|
+
$guardJobs = [System.Collections.Generic.List[object]]::new()
|
|
560
|
+
$guardBackupDir = Join-Path $BackupDir 'session-log-guard'
|
|
556
561
|
foreach ($b in $blocks) {
|
|
557
562
|
$srcRoot = Join-Path $convDir $b.Repo
|
|
558
563
|
if (-not (Test-Path -LiteralPath $srcRoot)) { continue }
|
|
@@ -579,6 +584,10 @@ function Sync-ConversationApply {
|
|
|
579
584
|
if (-not (Test-Path -LiteralPath $d)) { $need = $true }
|
|
580
585
|
elseif ((Get-FileHashFast $f.FullName) -ne (Get-FileHashFast $d)) { $need = $true }
|
|
581
586
|
if ($need) {
|
|
587
|
+
if (Test-SessionLogFile $dstRel) {
|
|
588
|
+
$guardJobs.Add([ordered]@{ Src = $f.FullName; Dst = $d; WriteTo = $d }) | Out-Null
|
|
589
|
+
continue
|
|
590
|
+
}
|
|
582
591
|
# 覆盖前备份本机已有文件
|
|
583
592
|
if (Test-Path -LiteralPath $d) {
|
|
584
593
|
$bd = Join-Path $BackupDir ("conversations\" + $b.Repo + "\" + $dstRel)
|
|
@@ -592,6 +601,29 @@ function Sync-ConversationApply {
|
|
|
592
601
|
}
|
|
593
602
|
}
|
|
594
603
|
}
|
|
604
|
+
if ($guardJobs.Count -gt 0) {
|
|
605
|
+
$g = Invoke-SessionLogGuard -Jobs $guardJobs.ToArray() -AppRoot $AppRoot -ScriptRoot $PSScriptRoot -RepoRoot $RepoRoot -BackupDir $guardBackupDir
|
|
606
|
+
Write-SessionLogGuardReport $g $DshHome '还原'
|
|
607
|
+
if ($g.Skipped) {
|
|
608
|
+
# 护栏用不了(没 Node/脚本缺失):退回整文件覆盖,至少保持原来的行为,但要先备份
|
|
609
|
+
foreach ($j in $guardJobs) {
|
|
610
|
+
if (Test-Path -LiteralPath $j.WriteTo) {
|
|
611
|
+
$bd = Join-Path $guardBackupDir ([IO.Path]::GetFileName($j.WriteTo))
|
|
612
|
+
$bdd = Split-Path -Parent $bd
|
|
613
|
+
if (-not (Test-Path -LiteralPath $bdd)) { New-Item -ItemType Directory -Path $bdd -Force | Out-Null }
|
|
614
|
+
Copy-Item -LiteralPath $j.WriteTo -Destination $bd -Force
|
|
615
|
+
$nBk++
|
|
616
|
+
}
|
|
617
|
+
Copy-Item -LiteralPath $j.Src -Destination $j.WriteTo -Force
|
|
618
|
+
$nAdd++
|
|
619
|
+
}
|
|
620
|
+
} else {
|
|
621
|
+
foreach ($r in @($g.Results)) {
|
|
622
|
+
if ($r -and $r.wrote) { $nAdd++ }
|
|
623
|
+
if ($r -and $r.backup) { $nBk++ }
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
595
627
|
# 会话是增量数据:只覆盖/新增,不删本机多出的会话文件
|
|
596
628
|
# 4) 会话文件头部的 cwd 必须改成本机路径,否则 DSH 判 corrupt、整个会话层起不来
|
|
597
629
|
# projcache 也要一起改:只按 $cwdMap 判断会让「仓库里只有 projcache、没有 sessions」的
|
|
@@ -856,7 +888,7 @@ if ($dropped.Count -gt 0) { Ok "已剔除 $($dropped.Count) 个实验性 bundle
|
|
|
856
888
|
$localPluginMap = [ordered]@{
|
|
857
889
|
'dsh-our-free-model-2.8.0' = 'dsh-our-free-model'
|
|
858
890
|
'dsh-purge-1.4.0' = 'dsh-purge'
|
|
859
|
-
'dsh-config-sync-plugin-0.3.
|
|
891
|
+
'dsh-config-sync-plugin-0.3.67' = 'dsh-config-sync-plugin'
|
|
860
892
|
'dsh-config-sync-plugin-0.3.65' = 'dsh-config-sync-plugin'
|
|
861
893
|
'dsh-config-sync-plugin-0.3.64' = 'dsh-config-sync-plugin'
|
|
862
894
|
'dsh-config-sync-plugin-0.3.63' = 'dsh-config-sync-plugin'
|