dsh-config-sync-plugin 0.3.68 → 0.3.69
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 +40 -2
- package/README.md +39 -1
- package/client.js +34 -7
- package/index.js +9 -9
- package/package.json +1 -1
- package/runtime/apply.ps1 +34 -4
- package/runtime/capture.ps1 +19 -0
- package/runtime/dsh-sync-common.ps1 +140 -2
- package/runtime/post-exit.ps1 +2 -0
- package/runtime/tools/bili-state.mjs +501 -0
- package/tools/bili-state.mjs +501 -0
- package/tools/selftest.mjs +67 -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.69"` 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,44 @@ 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.69 (carry billion-context compaction state across machines + two new notice kinds)
|
|
610
|
+
|
|
611
|
+
**Problem**: a long session keeps working on machine A, but after pulling to machine B the very next message fails with a context-overflow error.
|
|
612
|
+
|
|
613
|
+
Compaction happens on two layers. On A, DSH's own compaction is already **disabled** by billion-context (`billion-context/dist/agent/dsh-compaction-gate.js` flips `@deepseek-ai/dsh-compaction-basic` and `@deepseek-ai/dsh-command-compact` to `disabled:true` while `__BILI_DSH_COMPACTION_VERDICT__ === "active"`); the real compaction is done by bili **on the outgoing side** — it shrinks a 2.3 M surface down to ~160 K before the request reaches the provider. And bili's records do not live in `.dsh`: they are in a separate SQLite database, `%LOCALAPPDATA%\billion-context\sessions\index.db` (tables `sessions` / `blocks` / `content` / `refs` / `messages` / `checkpoints` …).
|
|
614
|
+
|
|
615
|
+
A pull only restores `sessions` / `attachments` / `vision_router_session_policy`, so **bili's index.db never travels**. Machine B therefore has: (1) no DSH native compaction (bili disabled it), (2) no bili compaction records (bili treats the session as new — `max compressible` is below the threshold, so it does not compact), (3) the whole surface sent straight to the provider → `CONTEXT_WINDOW_EXCEEDED`.
|
|
616
|
+
|
|
617
|
+
**Fix**: new `tools/bili-state.mjs` that moves compaction state per session.
|
|
618
|
+
|
|
619
|
+
| Subcommand | What it does |
|
|
620
|
+
|---|---|
|
|
621
|
+
| `probe` | Print the local bili database overview (tables, row counts, `user_version`) |
|
|
622
|
+
| `export <sessionId> <outFile>` | Dump one session's state (`sessions` row + active `blocks` rows + the summary `content` those blocks reference) |
|
|
623
|
+
| `import <inFile> [--dry-run]` | Write it back; existing primary keys are skipped, so it is repeatable |
|
|
624
|
+
| `sync <specJson> <outJson>` | Batch mode used by `capture.ps1` / `apply.ps1` (results go to a file, never stdout) |
|
|
625
|
+
|
|
626
|
+
Size control is a hard requirement — the default export deliberately leaves out three things:
|
|
627
|
+
|
|
628
|
+
- `sessions.metadata_json` (a 2.4 MB scale cache; the column is also `NOT NULL`, so export must `delete row.metadata_json` and let it fall back to DEFAULT, otherwise `NOT NULL constraint failed`)
|
|
629
|
+
- the snapshot behind `checkpoints.state_hash` (a single row can reach 21.89 MB)
|
|
630
|
+
- `messages` / `message_media` bodies (bili re-ingests them from the DSH session log)
|
|
631
|
+
|
|
632
|
+
Net result: about **5 MB per long session** (34–35 active blocks, ~7000 refs, 34 summaries), stored at `conversations/billion_context/<sessionId>.json`. `--all-blocks` / `--full` are needed only for the full block set and checkpoint snapshots.
|
|
633
|
+
|
|
634
|
+
Wiring: `capture.ps1` calls `-Mode 'export'` for the session ids it just touched; `apply.ps1` calls `-Mode 'import'` against `conversations/billion_context` after restoring sessions. When billion-context is **not installed** on the target machine the whole step is skipped silently and prints “本机没有 billion-context,压缩状态跳过(DSH 自带压缩会接管)” — nothing is written.
|
|
635
|
+
|
|
636
|
+
**Two new notice kinds** (this release also answers “nobody told me a plugin is missing on B”):
|
|
637
|
+
|
|
638
|
+
| kind | When it appears | What the panel says |
|
|
639
|
+
|---|---|---|
|
|
640
|
+
| `plugin-missing` | A `dependencies` plugin is not installed locally, a bundle cannot be resolved, or the repo has no archive for a link plugin | “Missing plugins: pulling only restores config, it does not install dependencies. Run pnpm install in the profile dir first (or re-run apply.ps1 without `-SkipInstall`), then pull again.” |
|
|
641
|
+
| `context-state` | bili compaction state was not synced, import failed, or billion-context is absent | “Missing compaction state: those sessions may hit a context-overflow error here. Push again from the main machine, or set `BILLION_CONTEXT_PLUGIN=0` here to fall back to DSH native compaction.” |
|
|
642
|
+
|
|
643
|
+
Notices land in `~/.dsh/sync-notices.json`, stay on the panel until the next sync clears them, and the exit summary in `post-exit.ps1` prints them grouped by kind. The headline now reflects the actual category — pure file items say “N item(s) unresolved”, plugin / compaction-state items say “N item(s) need attention”, so plugin problems are no longer described as “files not synced”.
|
|
644
|
+
|
|
645
|
+
**Manual fallback**: `node tools/bili-state.mjs probe` to inspect the local database; `node tools/bili-state.mjs export <sessionId> <out.json>` to export one session; `import --dry-run` to preview a write.
|
|
646
|
+
|
|
609
647
|
### 2026-11-19: release 0.3.68 (session projection-cache guard, fixes agent-busy session creation)
|
|
610
648
|
|
|
611
649
|
**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`.
|
|
@@ -628,7 +666,7 @@ Session creation fails outright and refreshing does not help (the same cache kee
|
|
|
628
666
|
|
|
629
667
|
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
668
|
|
|
631
|
-
Implementation: `runtime/tools/session-cache-guard.mjs` (`scanSessionCaches` / `clearSessionCaches` / `runGuard` / `indexSessionLogs`); the client half lives in the `0.3.
|
|
669
|
+
Implementation: `runtime/tools/session-cache-guard.mjs` (`scanSessionCaches` / `clearSessionCaches` / `runGuard` / `indexSessionLogs`); the client half lives in the `0.3.69:会话缓存守卫` block of `client.js`.
|
|
632
670
|
|
|
633
671
|
**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
672
|
|
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.69"` 后 `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,44 @@ 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.69(跨机搬运 billion-context 压缩状态 + 同步清单两类新提示)
|
|
586
|
+
|
|
587
|
+
**问题**:长会话在 A 机能接着聊,拉取到 B 机后一发消息就报上下文超长。
|
|
588
|
+
|
|
589
|
+
原因是压缩分两层:A 机的 DSH 原生 compaction 已被 billion-context **禁用**(`billion-context/dist/agent/dsh-compaction-gate.js` 在 `__BILI_DSH_COMPACTION_VERDICT__ === "active"` 时把 `@deepseek-ai/dsh-compaction-basic`、`@deepseek-ai/dsh-command-compact` 全部改成 `disabled:true`),真正的压缩是 bili 在**出口侧**做的——它把 2.3 M 的 surface 压成 160 K 再发给 provider。而 bili 的压缩记录不在 `.dsh` 里,在独立的 SQLite:`%LOCALAPPDATA%\billion-context\sessions\index.db`(表 `sessions` / `blocks` / `content` / `refs` / `messages` / `checkpoints` …)。
|
|
590
|
+
|
|
591
|
+
同步过去只有 `sessions` / `attachments` / `vision_router_session_policy` 三块,**bili 的 index.db 完全没跟着走**。于是 B 机:①没有 DSH 原生压缩(被 bili 禁了)②没有 bili 的压缩记录(bili 认为这是新会话,`max compressible` 不足,阈值不到不压)③把全量 surface 直接发给 provider → `CONTEXT_WINDOW_EXCEEDED`。
|
|
592
|
+
|
|
593
|
+
**修复**:新增 `tools/bili-state.mjs`,按会话搬运压缩状态,四步都不碰别人的会话。
|
|
594
|
+
|
|
595
|
+
| 子命令 | 作用 |
|
|
596
|
+
|---|---|
|
|
597
|
+
| `probe` | 列本机 bili 库概况(表、行数、`user_version`) |
|
|
598
|
+
| `export <sessionId> <outFile>` | 导出单会话状态(`sessions` 行 + active `blocks` 行 + 这些 block 的 summary `content`) |
|
|
599
|
+
| `import <inFile> [--dry-run]` | 回灌;按主键跳过已存在的行,可重复执行 |
|
|
600
|
+
| `sync <specJson> <outJson>` | 批量,供 `capture.ps1` / `apply.ps1` 调用(结果写文件,不依赖 stdout) |
|
|
601
|
+
|
|
602
|
+
体积控制是硬要求,默认导出**刻意不带**三样东西:
|
|
603
|
+
|
|
604
|
+
- `sessions.metadata_json`(2.4 MB 级缓存;且该列 `NOT NULL`,导出要 `delete row.metadata_json` 让它落 DEFAULT,否则 `NOT NULL constraint failed`)
|
|
605
|
+
- `checkpoints.state_hash` 指向的快照(单条可达 21.89 MB)
|
|
606
|
+
- `messages` / `message_media` 正文(bili 会从 DSH 会话日志自己 ingest)
|
|
607
|
+
|
|
608
|
+
结果:一条长会话约 **5 MB**(34~35 个 active block、约 7000 条 refs、34 条 summary),落在仓库 `conversations/billion_context/<sessionId>.json`。带 `--all-blocks` / `--full` 才导出全部 block 与 checkpoint 快照。
|
|
609
|
+
|
|
610
|
+
接入点:`capture.ps1` 在会话块之后对本次变动的 sessionId 调 `-Mode 'export'`;`apply.ps1` 在会话还原之后对 `conversations/billion_context` 调 `-Mode 'import'`。**B 机没装 billion-context 时静默跳过**,打印「本机没有 billion-context,压缩状态跳过(DSH 自带压缩会接管)」,不做任何写入。
|
|
611
|
+
|
|
612
|
+
**同步清单的两类新提示**(这一版同时解决「B 机没装插件没人告诉你」):
|
|
613
|
+
|
|
614
|
+
| kind | 什么时候出现 | 面板怎么说 |
|
|
615
|
+
|---|---|---|
|
|
616
|
+
| `plugin-missing` | `dependencies` 里的插件没装到本机、bundle 无法解析、仓库里没有该 link 插件的归档 | 「插件没装:拉取只还原配置,不替你装依赖。先在本机 profile 目录执行 pnpm install(或去掉 `-SkipInstall` 重跑 apply.ps1),装好后重新拉取一次。」 |
|
|
617
|
+
| `context-state` | bili 压缩状态没同步过来 / 导入失败 / 本机没有 bili | 「会话缺压缩状态:这些会话在本机可能报上下文超长。在主力机重新推送一次,或在本机设 `BILLION_CONTEXT_PLUGIN=0` 让 DSH 原生压缩兜底。」 |
|
|
618
|
+
|
|
619
|
+
清单落 `~/.dsh/sync-notices.json`,面板常驻显示直到下次同步清掉;`post-exit.ps1` 的结束摘要也按类分组打印。标题按实际类别说人话——纯文件类说「N 项没处理完」,插件/压缩状态类说「N 项需要处理」,不再把插件问题写成「文件没同步」。
|
|
620
|
+
|
|
621
|
+
**手动兜底**:`node tools/bili-state.mjs probe` 看本机 bili 库;`node tools/bili-state.mjs export <sessionId> <out.json>` 单独导一条;`import --dry-run` 先看会写什么。
|
|
622
|
+
|
|
585
623
|
### 2026-11-19:发版 0.3.68(会话投影缓存守卫,治 agent-busy 建会话失败)
|
|
586
624
|
|
|
587
625
|
**问题**: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`。
|
package/client.js
CHANGED
|
@@ -1926,6 +1926,8 @@ window.__ModuleLoader__.load({
|
|
|
1926
1926
|
function noticesBlock(notices) {
|
|
1927
1927
|
if (!notices || !notices.total) return null
|
|
1928
1928
|
const kindLabel = (k) => ({
|
|
1929
|
+
'plugin-missing': M('插件没装', 'Plugin missing'),
|
|
1930
|
+
'context-state': M('缺压缩状态', 'No compaction state'),
|
|
1929
1931
|
'too-large': M('超过单文件上限', 'Over size cap'),
|
|
1930
1932
|
history: M('历史里的超限文件', 'Oversized in history'),
|
|
1931
1933
|
failed: M('失败', 'Failed'),
|
|
@@ -1944,7 +1946,9 @@ window.__ModuleLoader__.load({
|
|
|
1944
1946
|
if (notices.byKind['too-large']) parts.push(M(`${notices.byKind['too-large']} 个超过单文件上限`, `${notices.byKind['too-large']} over the size cap`))
|
|
1945
1947
|
if (notices.byKind.history) parts.push(M(`${notices.byKind.history} 个在历史提交里`, `${notices.byKind.history} already in history`))
|
|
1946
1948
|
if (notices.byKind.failed) parts.push(M(`${notices.byKind.failed} 个失败`, `${notices.byKind.failed} failed`))
|
|
1947
|
-
if (notices.byKind.skipped) parts.push(M(`${notices.byKind.skipped} 个被跳过`, `${notices.byKind.skipped} skipped`))
|
|
1949
|
+
if (notices.byKind.skipped) parts.push(M(`${notices.byKind.skipped} 个被跳过`, `${notices.byKind.skipped} skipped`))
|
|
1950
|
+
if (notices.byKind['plugin-missing']) parts.push(M(`${notices.byKind['plugin-missing']} 个插件没装`, `${notices.byKind['plugin-missing']} plugin(s) missing`))
|
|
1951
|
+
if (notices.byKind['context-state']) parts.push(M(`${notices.byKind['context-state']} 个会话缺压缩状态`, `${notices.byKind['context-state']} session(s) without compaction state`))
|
|
1948
1952
|
}
|
|
1949
1953
|
return h('div', {
|
|
1950
1954
|
style: {
|
|
@@ -1953,11 +1957,34 @@ window.__ModuleLoader__.load({
|
|
|
1953
1957
|
background: 'color-mix(in srgb, var(--dsw-alias-state-warn-primary) 8%, transparent)',
|
|
1954
1958
|
},
|
|
1955
1959
|
},
|
|
1956
|
-
|
|
1957
|
-
|
|
1960
|
+
// 标题按「实际是哪类问题」说人话:插件没装/缺压缩状态不是「文件没同步」,
|
|
1961
|
+
// 混在一起会让人以为磁盘上少了东西。
|
|
1962
|
+
(() => {
|
|
1963
|
+
const fileish = (notices.byKind && (notices.byKind['too-large'] || notices.byKind.history || notices.byKind.failed || notices.byKind.skipped)) || 0
|
|
1964
|
+
const pluginN = (notices.byKind && notices.byKind['plugin-missing']) || 0
|
|
1965
|
+
const stateN = (notices.byKind && notices.byKind['context-state']) || 0
|
|
1966
|
+
const headline = fileish
|
|
1967
|
+
? M(`上次同步有 ${notices.total} 项没处理完${parts.length ? `(${parts.join('、')})` : ''}`,
|
|
1968
|
+
`Last sync left ${notices.total} item(s) unresolved${parts.length ? ` (${parts.join(', ')})` : ''}`)
|
|
1969
|
+
: (pluginN || stateN)
|
|
1970
|
+
? M(`上次同步后有 ${notices.total} 项需要处理${parts.length ? `(${parts.join('、')})` : ''}`,
|
|
1971
|
+
`After the last sync ${notices.total} item(s) need attention${parts.length ? ` (${parts.join(', ')})` : ''}`)
|
|
1972
|
+
: M(`上次同步有 ${notices.total} 项没处理完`, `Last sync left ${notices.total} item(s) unresolved`)
|
|
1973
|
+
return h('div', { style: { fontSize: '12px', fontWeight: 600, color: 'var(--dsw-alias-state-warn-primary)' } }, headline)
|
|
1974
|
+
})(),
|
|
1958
1975
|
h('div', { style: { ...S.footnote, marginTop: '3px' } },
|
|
1959
|
-
M('
|
|
1960
|
-
'
|
|
1976
|
+
M('文件类的仍在本机磁盘上,只是没进仓库;下次同步会自动复查。插件类要先在本机装好,再拉一次。',
|
|
1977
|
+
'File items are still on this machine, just not in the repo; the next sync re-checks them. Plugin items need an install here first, then pull again.')),
|
|
1978
|
+
(notices.byKind && notices.byKind['plugin-missing'])
|
|
1979
|
+
? h('div', { style: { ...S.footnote, marginTop: '3px', color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
1980
|
+
M('插件没装:拉取只还原配置,不替你装依赖。先在本机 profile 目录执行 pnpm install(或去掉 -SkipInstall 重跑 apply.ps1),装好后重新拉取一次。',
|
|
1981
|
+
'Missing plugins: pulling only restores config, it does not install dependencies. Run pnpm install in the profile dir first (or re-run apply.ps1 without -SkipInstall), then pull again.'))
|
|
1982
|
+
: null,
|
|
1983
|
+
(notices.byKind && notices.byKind['context-state'])
|
|
1984
|
+
? h('div', { style: { ...S.footnote, marginTop: '3px', color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
1985
|
+
M('会话缺压缩状态:billion-context 的压缩记录没同步过来,这些会话在本机可能报上下文超长。在主力机重新推送一次(capture 会带上压缩状态),或在本机设置 BILLION_CONTEXT_PLUGIN=0 让 DSH 原生压缩兜底。',
|
|
1986
|
+
'Missing compaction state: billion-context blocks were not synced, so those sessions may hit a context-overflow error here. Push again from the main machine, or set BILLION_CONTEXT_PLUGIN=0 here to fall back to DSH native compaction.'))
|
|
1987
|
+
: null,
|
|
1961
1988
|
h('div', { style: { marginTop: '4px' } }, rows),
|
|
1962
1989
|
notices.truncated
|
|
1963
1990
|
? h('div', { style: { ...S.footnote, marginTop: '3px' } },
|
|
@@ -3185,7 +3212,7 @@ window.__ModuleLoader__.load({
|
|
|
3185
3212
|
} catch { /* 插件路由还没起好就静默跳过,面板里仍会显示同一结果 */ }
|
|
3186
3213
|
}
|
|
3187
3214
|
|
|
3188
|
-
// ==================== 0.3.
|
|
3215
|
+
// ==================== 0.3.69:会话缓存守卫(客户端半身) ====================
|
|
3189
3216
|
// 宿主侧没法拦 agent-busy(它是 sessionController 内部抛的 RemoteError),
|
|
3190
3217
|
// 所以在这里包一层 sessions.create:撞上就上报、清缓存、去掉旧 sessionId 重试一次。
|
|
3191
3218
|
const BUSY_RE = /session\/agent-busy|is owned by subagent routing/i
|
|
@@ -3282,7 +3309,7 @@ window.__ModuleLoader__.load({
|
|
|
3282
3309
|
// 界面还没完全起来时 fetch 可能扑空,所以稍等一会儿再查;只查一次,不轮询。
|
|
3283
3310
|
try { setTimeout(announceLastResult, 1500) } catch { }
|
|
3284
3311
|
|
|
3285
|
-
// 0.3.
|
|
3312
|
+
// 0.3.69:给客户端的 sessions 服务套上 agent-busy 自愈钩子。
|
|
3286
3313
|
// 拿不到 sessions(老版本宿主 / 服务还没起来)就静默跳过,面板功能不受影响。
|
|
3287
3314
|
try {
|
|
3288
3315
|
if (typeof ctx.get === 'function') {
|
package/index.js
CHANGED
|
@@ -24,7 +24,7 @@ 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.
|
|
27
|
+
// 0.3.69:会话投影缓存守卫(agent-busy 自动清缓存,让缓存按日志重建)
|
|
28
28
|
import { runGuard, clearSessionCaches, appendGuardLog } from './runtime/tools/session-cache-guard.mjs'
|
|
29
29
|
|
|
30
30
|
const pluginRequire = createRequire(import.meta.url)
|
|
@@ -39,7 +39,7 @@ const ROUTE_CONFLICT = '/config-sync/conflict'
|
|
|
39
39
|
// 0.3.30:跨机路径确认(每台机器把自己的根目录报给插件一次)与问题反馈(落仓库 feedback\ 再推 GitHub)
|
|
40
40
|
const ROUTE_ROOTS = '/config-sync/roots'
|
|
41
41
|
const ROUTE_FEEDBACK = '/config-sync/feedback'
|
|
42
|
-
// 0.3.
|
|
42
|
+
// 0.3.69:会话投影缓存守卫(GET 只读扫描 / POST scan|sweep|clear|busy)
|
|
43
43
|
const ROUTE_CACHE_GUARD = '/config-sync/cache-guard'
|
|
44
44
|
const SETTINGS_NAME = 'dsh-config-sync.json'
|
|
45
45
|
/** 本插件自己的安装目录(插件根,含 runtime\ 与 index.js)—— 插件备份还原时的目标。 */
|
|
@@ -237,7 +237,7 @@ function readSettings(dshHome) {
|
|
|
237
237
|
// 同步完成重启前把 DSH 的「默认工作区」校正到谁:
|
|
238
238
|
// 留空 = 自动找名字/路径是 default-workspace 的工作区;可填工作区路径或 ID;填 off 关闭。
|
|
239
239
|
defaultWorkspace: typeof raw.defaultWorkspace === 'string' ? raw.defaultWorkspace : '',
|
|
240
|
-
// 0.3.
|
|
240
|
+
// 0.3.69:会话投影缓存守卫,默认开。关掉后既不定时扫描,也不理会客户端的 agent-busy 上报。
|
|
241
241
|
cacheGuard: raw.cacheGuard !== false,
|
|
242
242
|
}
|
|
243
243
|
}
|
|
@@ -1180,7 +1180,7 @@ async function inspect(config) {
|
|
|
1180
1180
|
const pending = c.items.filter((it) => !it.choice).length
|
|
1181
1181
|
return { exists: true, total: c.items.length, pending, at: c.at || '', backupDir: c.backupDir || '' }
|
|
1182
1182
|
})(),
|
|
1183
|
-
// 0.3.
|
|
1183
|
+
// 0.3.69:会话投影缓存守卫状态(面板「会话缓存守卫」卡用)
|
|
1184
1184
|
cacheGuard: cacheGuardSnapshot(config),
|
|
1185
1185
|
}
|
|
1186
1186
|
}
|
|
@@ -1499,7 +1499,7 @@ function readAutoResult(dshHome) {
|
|
|
1499
1499
|
* 就回落到 ~/.dsh/sync-notices.json。两种情况都做裁剪,避免一个几万文件的仓库把 /status 撑爆。
|
|
1500
1500
|
*/
|
|
1501
1501
|
function readNoticeList(dshHome, fromResult) {
|
|
1502
|
-
const KINDS = ['history', 'too-large', 'failed', 'skipped']
|
|
1502
|
+
const KINDS = ['plugin-missing', 'context-state', 'history', 'too-large', 'failed', 'skipped']
|
|
1503
1503
|
let raw = fromResult
|
|
1504
1504
|
if (!raw || !Array.isArray(raw.items)) {
|
|
1505
1505
|
try {
|
|
@@ -1962,7 +1962,7 @@ async function handleSettings(req, res, config) {
|
|
|
1962
1962
|
const autoPull = has('autoPull') ? body.autoPull === true : before.autoPull
|
|
1963
1963
|
const autoPush = has('autoPush') ? body.autoPush === true : before.autoPush
|
|
1964
1964
|
const autoRestart = has('autoRestart') ? body.autoRestart !== false : before.autoRestart
|
|
1965
|
-
// 0.3.
|
|
1965
|
+
// 0.3.69:会话投影缓存守卫开关,字段没给就沿用原值
|
|
1966
1966
|
const cacheGuard = has('cacheGuard') ? body.cacheGuard !== false : before.cacheGuard
|
|
1967
1967
|
|
|
1968
1968
|
if (!has('repoPath') && !has('remoteUrl') && !has('sshKey') &&
|
|
@@ -4022,7 +4022,7 @@ function newIssueUrl(repo, title, text, config) {
|
|
|
4022
4022
|
return `https://github.com/${repo}/issues/new?${q}`
|
|
4023
4023
|
}
|
|
4024
4024
|
|
|
4025
|
-
// ============================ 0.3.
|
|
4025
|
+
// ============================ 0.3.69:会话投影缓存守卫 ============================
|
|
4026
4026
|
// 背景:UI 点「新建会话」时会挑一条 summary.blank===true 的会话复用,挑中了 origin=subagent
|
|
4027
4027
|
// 的子会话就会被宿主拒绝(session/agent-busy:is owned by subagent routing)。
|
|
4028
4028
|
// 起因是投影缓存停在 session/created 那一刻(blank=true、seq=-1),而会话日志早就推进过,
|
|
@@ -4430,7 +4430,7 @@ export function apply(ctx, config) {
|
|
|
4430
4430
|
path: ROUTE_FEEDBACK,
|
|
4431
4431
|
handler: withLang(handleFeedback),
|
|
4432
4432
|
}))
|
|
4433
|
-
// 0.3.
|
|
4433
|
+
// 0.3.69:会话投影缓存守卫(GET 只读扫描 / POST scan|sweep|clear|busy)
|
|
4434
4434
|
scoped.effect(() => scoped.webServer.register({
|
|
4435
4435
|
kind: 'exact',
|
|
4436
4436
|
path: ROUTE_CACHE_GUARD,
|
|
@@ -4443,7 +4443,7 @@ export function apply(ctx, config) {
|
|
|
4443
4443
|
// status 不用再为首屏那 2.5 秒的 ls-remote 埋单。
|
|
4444
4444
|
typeof setTimeout === 'function' ? setTimeout(() => { try { warmRemoteProbe(config) } catch { } }, 300) : null
|
|
4445
4445
|
installQuitWhenAllWindowsClosed(ctx)
|
|
4446
|
-
// 0.3.
|
|
4446
|
+
// 0.3.69:会话投影缓存守卫的定时扫描(默认开,设置里可关)
|
|
4447
4447
|
scheduleCacheGuard(config)
|
|
4448
4448
|
} catch (error) {
|
|
4449
4449
|
// 不抛:缺 webServer 的 profile 里这个插件静默不激活即可
|
package/package.json
CHANGED
package/runtime/apply.ps1
CHANGED
|
@@ -672,6 +672,16 @@ function Sync-ConversationApply {
|
|
|
672
672
|
Warn ('没找到可用于修正会话头部的执行器(Node / 客户端 Electron 都没找到,AppRoot={0}),本次未修正' -f $AppRoot)
|
|
673
673
|
}
|
|
674
674
|
}
|
|
675
|
+
# 5) billion-context 压缩状态:DSH 原生 compaction 被 bili 接管后,真正的压缩记录在 bili 自己的
|
|
676
|
+
# SQLite(…\billion-context\sessions\index.db)里,不在 .dsh 下。不带这份状态,长会话在本机
|
|
677
|
+
# 继续时会以未压缩的全量 surface 发给 provider,报 CONTEXT_WINDOW_EXCEEDED。
|
|
678
|
+
$biliRepo = Join-Path $convDir 'billion_context'
|
|
679
|
+
if (Test-Path -LiteralPath $biliRepo) {
|
|
680
|
+
$bs = Invoke-BiliStateSync -Mode 'import' -RepoDir $biliRepo -AppRoot $AppRoot -ScriptRoot $PSScriptRoot -RepoRoot $RepoRoot
|
|
681
|
+
Write-BiliStateSyncReport $bs $DshHome
|
|
682
|
+
} else {
|
|
683
|
+
Say ' 仓库里没有 billion-context 压缩状态(首次导出前为空,属正常)'
|
|
684
|
+
}
|
|
675
685
|
Ok ('会话数据全量还原:{0} 个目录映射,写入/更新 {1} 个文件、备份 {2} 个(四块数据字节保真,会话只增不删)' -f $dirMap.Count, $nAdd, $nBk)
|
|
676
686
|
}
|
|
677
687
|
|
|
@@ -888,9 +898,12 @@ if ($dropped.Count -gt 0) { Ok "已剔除 $($dropped.Count) 个实验性 bundle
|
|
|
888
898
|
$localPluginMap = [ordered]@{
|
|
889
899
|
'dsh-our-free-model-2.8.0' = 'dsh-our-free-model'
|
|
890
900
|
'dsh-purge-1.4.0' = 'dsh-purge'
|
|
901
|
+
'dsh-config-sync-plugin-0.3.69' = 'dsh-config-sync-plugin'
|
|
902
|
+
'dsh-config-sync-plugin-0.3.68' = 'dsh-config-sync-plugin'
|
|
891
903
|
'dsh-config-sync-plugin-0.3.67' = 'dsh-config-sync-plugin'
|
|
892
|
-
|
|
893
|
-
|
|
904
|
+
'dsh-config-sync-plugin-0.3.66' = 'dsh-config-sync-plugin'
|
|
905
|
+
'dsh-config-sync-plugin-0.3.65' = 'dsh-config-sync-plugin'
|
|
906
|
+
'dsh-config-sync-plugin-0.3.64' = 'dsh-config-sync-plugin'
|
|
894
907
|
'dsh-config-sync-plugin-0.3.63' = 'dsh-config-sync-plugin'
|
|
895
908
|
'dsh-config-sync-plugin-0.3.62' = 'dsh-config-sync-plugin'
|
|
896
909
|
'dsh-config-sync-plugin-0.3.61' = 'dsh-config-sync-plugin'
|
|
@@ -1332,6 +1345,7 @@ if ($needExtract.Count -gt 0) {
|
|
|
1332
1345
|
Ok "已解压并部署:$final"
|
|
1333
1346
|
} else {
|
|
1334
1347
|
Warn "仓库里没有 $dirName 的归档,跳过(该插件会装不上)"
|
|
1348
|
+
Add-SyncNotice -Kind 'plugin-missing' -Path $dirName -Reason ('仓库的 local-plugins\ 里没有这个源码插件包的归档(.tgz/.zip),本机装不上。在主力机跑 capture.ps1 -PackLocalPlugins 打包并推送,然后在本机重新拉取一次。')
|
|
1335
1349
|
}
|
|
1336
1350
|
}
|
|
1337
1351
|
Remove-Item -LiteralPath $staging -Recurse -Force -ErrorAction SilentlyContinue
|
|
@@ -1479,8 +1493,21 @@ foreach ($name in $deps.PSObject.Properties.Name) {
|
|
|
1479
1493
|
$probe = Join-Path $ProfileDir ("node_modules\" + ($name -replace '/', '\'))
|
|
1480
1494
|
if (-not (Test-Path -LiteralPath $probe)) { $missing += $name }
|
|
1481
1495
|
}
|
|
1482
|
-
if ($missing.Count -eq 0) {
|
|
1483
|
-
|
|
1496
|
+
if ($missing.Count -eq 0) {
|
|
1497
|
+
Ok "全部 $(@($deps.PSObject.Properties).Count) 个插件依赖已就位"
|
|
1498
|
+
} else {
|
|
1499
|
+
Warn ("缺少 $($missing.Count) 个插件:" + ($missing -join ', '))
|
|
1500
|
+
# 拉取只还原配置文件,不会替本机安装依赖:仓库里没有这些插件的实体(它们该由 pnpm install 从
|
|
1501
|
+
# registry 装,或从 local-plugins 的归档解压)。把每一个都记进未同步清单,面板会常驻提示
|
|
1502
|
+
# 「装好插件后再拉取一次」,否则用户只看到插件页少几项、不知道下一步做什么。
|
|
1503
|
+
foreach ($nm in $missing) {
|
|
1504
|
+
$why = '插件未安装到本机:拉取不会替你装依赖。'
|
|
1505
|
+
if ($SkipInstall) { $why += '本次带了 -SkipInstall,pnpm install 被跳过;' }
|
|
1506
|
+
$why += '在 profile 目录执行一次 pnpm install(或去掉 -SkipInstall 重跑本脚本),装好后重新拉取一次。'
|
|
1507
|
+
Add-SyncNotice -Kind 'plugin-missing' -Path $nm -Reason $why
|
|
1508
|
+
}
|
|
1509
|
+
Warn '已把这些插件记进未同步清单(sync-notices.json),面板会一直提示到装好并重新拉取为止。'
|
|
1510
|
+
}
|
|
1484
1511
|
|
|
1485
1512
|
# bundle 可解析性检查:清单里写了、本机却没有 → 启动期 entry loading 必挂(整个应用起不来,不是功能不可用)
|
|
1486
1513
|
# 解析顺序与 DSH 一致:先 profile\node_modules(pnpm 装的),再 <AppRoot>\resources\app\dsh\node_modules(宿主自带)
|
|
@@ -1497,6 +1524,9 @@ if ($unresolved.Count -eq 0) {
|
|
|
1497
1524
|
} else {
|
|
1498
1525
|
Warn "以下 $($unresolved.Count) 个 bundle 在本机找不到,启动会在 entry loading 阶段失败:"
|
|
1499
1526
|
$unresolved | ForEach-Object { Warn " - $_" }
|
|
1527
|
+
foreach ($ub in $unresolved) {
|
|
1528
|
+
Add-SyncNotice -Kind 'plugin-missing' -Path $ub -Reason ('bundle 在本机解析不到:插件没装好(pnpm install 没成功,或仓库里没有这个插件的归档)。装好后重新拉取一次;若它是宿主绑定的实验性 bundle,删掉本机 profile\package.json 里那一行。')
|
|
1529
|
+
}
|
|
1500
1530
|
if (-not $ForceBundles) {
|
|
1501
1531
|
Die ("已停止,先别启动。处理:①若上面「缺少插件」不为空,说明 pnpm install 没成功;" +
|
|
1502
1532
|
"②若是宿主绑定的实验性 bundle,直接删掉本机 profile\package.json 里那一行;" +
|
package/runtime/capture.ps1
CHANGED
|
@@ -437,6 +437,8 @@ function Sync-ConversationCapture {
|
|
|
437
437
|
@{ Src = (Join-Path $DshHome 'storages\vision_router_session_policy\policies'); Dst = 'vision_router_session_policy'; Remap = $false }
|
|
438
438
|
)
|
|
439
439
|
$nAdd = 0; $nDel = 0
|
|
440
|
+
# 本次真正写入过的会话 id(用来只导出这些会话的 billion-context 压缩状态)
|
|
441
|
+
$touchedSids = [System.Collections.Generic.List[string]]::new()
|
|
440
442
|
foreach ($b in $blocks) {
|
|
441
443
|
$dstRoot = Join-Path $convDir $b.Dst
|
|
442
444
|
if (-not (Test-Path -LiteralPath $b.Src)) { Warn ('本机没有会话数据块,跳过:{0}' -f $b.Src); continue }
|
|
@@ -472,6 +474,13 @@ function Sync-ConversationCapture {
|
|
|
472
474
|
if (-not (Test-Path -LiteralPath $dd)) { New-Item -ItemType Directory -Path $dd -Force | Out-Null }
|
|
473
475
|
$madeDirs[$dd] = $true
|
|
474
476
|
}
|
|
477
|
+
if ($b.Dst -eq 'sessions') {
|
|
478
|
+
$rp = @($rel -split '\\')
|
|
479
|
+
if ($rp.Count -ge 2) {
|
|
480
|
+
$sid = [string]$rp[1]
|
|
481
|
+
if ($sid -and -not $touchedSids.Contains($sid)) { $touchedSids.Add($sid) | Out-Null }
|
|
482
|
+
}
|
|
483
|
+
}
|
|
475
484
|
if (Test-SessionLogFile $rel) {
|
|
476
485
|
$guardJobs.Add([ordered]@{ Src = $si.FullName; Dst = $d; WriteTo = $d }) | Out-Null
|
|
477
486
|
$dstRels[$rel] = [IO.FileInfo]::new($d)
|
|
@@ -512,6 +521,16 @@ function Sync-ConversationCapture {
|
|
|
512
521
|
}
|
|
513
522
|
}
|
|
514
523
|
}
|
|
524
|
+
# 4) billion-context 压缩状态:DSH 原生 compaction 被 bili 接管后,真正的压缩记录在 bili 自己的
|
|
525
|
+
# SQLite 里(不在 .dsh 下)。只带会话日志、不带这份状态,另一台机器会把未压缩的全量 surface
|
|
526
|
+
# 发给 provider 并报 CONTEXT_WINDOW_EXCEEDED。这里按会话导出 blocks/refs/summary。
|
|
527
|
+
if ($touchedSids.Count -gt 0) {
|
|
528
|
+
$biliRepo = Join-Path $convDir 'billion_context'
|
|
529
|
+
$bs = Invoke-BiliStateSync -Mode 'export' -RepoDir $biliRepo -Sessions $touchedSids.ToArray() -AppRoot $AppRoot -ScriptRoot $PSScriptRoot -RepoRoot $RepoRoot
|
|
530
|
+
Write-BiliStateSyncReport $bs $DshHome
|
|
531
|
+
} else {
|
|
532
|
+
Say ' 本次没有会话变动,跳过 billion-context 压缩状态导出'
|
|
533
|
+
}
|
|
515
534
|
Ok ('会话数据全量同步:{0} 个目录映射,入库/更新 {1} 个文件、删除 {2} 个(四块数据全部字节保真)' -f $idxEntries.Count, $nAdd, $nDel)
|
|
516
535
|
Say (' ' + (Get-TreeCmpSummary))
|
|
517
536
|
|
|
@@ -30,7 +30,9 @@ function Die($m) { Write-Host " [X] $m" -ForegroundColor Red; exit 1 }
|
|
|
30
30
|
# too-large 超过单文件上限(capture 跳过 / push 前从索引剔除 / 历史里已存在)
|
|
31
31
|
# skipped 被规则或占用跳过(不是失败,但用户该知道)
|
|
32
32
|
# failed 写入失败、被远端拒绝等真失败
|
|
33
|
-
# history 历史提交里已存在的超限文件(远端必然拒收,必须改写历史或换仓库)
|
|
33
|
+
# history 历史提交里已存在的超限文件(远端必然拒收,必须改写历史或换仓库)
|
|
34
|
+
# plugin-missing 插件没装在本机(拉取只还原配置,不装依赖;装完要再拉一次)
|
|
35
|
+
# context-state billion-context 的压缩状态没跟着过来(该会话可能报上下文超长)
|
|
34
36
|
$script:SyncNoticeItems = New-Object 'System.Collections.ArrayList'
|
|
35
37
|
$script:SyncNoticeHome = $null
|
|
36
38
|
$script:SyncNoticeMode = ''
|
|
@@ -55,7 +57,7 @@ function Save-SyncNotices {
|
|
|
55
57
|
$dir = Split-Path -Parent $p
|
|
56
58
|
if ($dir -and -not (Test-Path -LiteralPath $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
|
|
57
59
|
$byKind = [ordered]@{}
|
|
58
|
-
foreach ($k in @('too-large', 'history', 'skipped', 'failed')) {
|
|
60
|
+
foreach ($k in @('too-large', 'history', 'skipped', 'failed', 'plugin-missing', 'context-state')) {
|
|
59
61
|
$byKind[$k] = @($script:SyncNoticeItems | Where-Object { $_.kind -eq $k }).Count
|
|
60
62
|
}
|
|
61
63
|
$obj = [ordered]@{
|
|
@@ -108,6 +110,8 @@ function Get-SyncNoticesSummary($notices) {
|
|
|
108
110
|
if ($bk.history -gt 0) { $parts += ("{0} 个历史提交里的超限文件" -f $bk.history) }
|
|
109
111
|
if ($bk.skipped -gt 0) { $parts += ("{0} 个被规则跳过" -f $bk.skipped) }
|
|
110
112
|
if ($bk.failed -gt 0) { $parts += ("{0} 个写入/推送失败" -f $bk.failed) }
|
|
113
|
+
if ($bk.'plugin-missing' -gt 0) { $parts += ("{0} 个插件没装" -f $bk.'plugin-missing') }
|
|
114
|
+
if ($bk.'context-state' -gt 0) { $parts += ("{0} 个会话缺压缩状态" -f $bk.'context-state') }
|
|
111
115
|
return ($parts -join '、')
|
|
112
116
|
}
|
|
113
117
|
|
|
@@ -1141,3 +1145,137 @@ function Write-SessionLogGuardReport($Guard, [string]$DshHome, [string]$Verb) {
|
|
|
1141
1145
|
}
|
|
1142
1146
|
}
|
|
1143
1147
|
|
|
1148
|
+
|
|
1149
|
+
# ── billion-context 压缩状态跨机搬运 ───────────────────────────────────────
|
|
1150
|
+
# 为什么需要:DSH 原生 compaction 被 billion-context 接管(compaction gate 把
|
|
1151
|
+
# dsh-compaction-basic / dsh-command-compact disabled 掉),真正的压缩记录存在
|
|
1152
|
+
# bili 自己的 SQLite(…\billion-context\sessions\index.db)里,不在 .dsh 下。
|
|
1153
|
+
# 只同步会话日志、不同步这份状态,另一台机器就会把未压缩的全量 surface 发给
|
|
1154
|
+
# provider,报 CONTEXT_WINDOW_EXCEEDED。这里按会话导出/导入 blocks+refs+content。
|
|
1155
|
+
|
|
1156
|
+
function Get-BiliStateToolPath([string]$scriptRoot, [string]$repoRoot) {
|
|
1157
|
+
$bases = @()
|
|
1158
|
+
if ($scriptRoot) {
|
|
1159
|
+
$bases += (Join-Path $scriptRoot 'tools')
|
|
1160
|
+
if ((Split-Path -Leaf $scriptRoot) -ne 'runtime') { $bases += (Join-Path $scriptRoot 'runtime\tools') }
|
|
1161
|
+
}
|
|
1162
|
+
if ($repoRoot) {
|
|
1163
|
+
$bases += (Join-Path $repoRoot 'tools')
|
|
1164
|
+
$bases += (Join-Path $repoRoot 'runtime\tools')
|
|
1165
|
+
}
|
|
1166
|
+
if ($MyInvocation.MyCommand.Path) {
|
|
1167
|
+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
1168
|
+
$bases += (Join-Path $here 'tools')
|
|
1169
|
+
}
|
|
1170
|
+
foreach ($b in $bases) {
|
|
1171
|
+
if (-not $b) { continue }
|
|
1172
|
+
$p = Join-Path $b 'bili-state.mjs'
|
|
1173
|
+
if (Test-Path -LiteralPath $p) { return $p }
|
|
1174
|
+
}
|
|
1175
|
+
return $null
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
# 形状仿 Invoke-SessionLogGuard:spec/结果都走临时文件,执行器可能是 Electron GUI 子系统。
|
|
1179
|
+
function Invoke-BiliStateSync {
|
|
1180
|
+
param(
|
|
1181
|
+
[ValidateSet('export', 'import')][string]$Mode,
|
|
1182
|
+
[string]$RepoDir,
|
|
1183
|
+
[object[]]$Sessions,
|
|
1184
|
+
[string]$AppRoot,
|
|
1185
|
+
[string]$ScriptRoot,
|
|
1186
|
+
[string]$RepoRoot,
|
|
1187
|
+
[string]$BiliDir
|
|
1188
|
+
)
|
|
1189
|
+
$res = [ordered]@{ Ok = $true; Mode = $Mode; Exported = @(); Imported = @(); Missing = @(); Failed = @(); Skipped = $true; Reason = ''; NoBili = $false; BiliDir = ''; Bytes = 0 }
|
|
1190
|
+
if (-not $RepoDir) { $res.Reason = '没有指定压缩状态目录'; return $res }
|
|
1191
|
+
$tool = Get-BiliStateToolPath $ScriptRoot $RepoRoot
|
|
1192
|
+
if (-not $tool) { $res.Reason = '找不到 tools\bili-state.mjs'; return $res }
|
|
1193
|
+
$runner = Get-HostNodeRunner $AppRoot
|
|
1194
|
+
if (-not $runner) { $res.Reason = '这台机器既没有 Node 也找不到客户端本体'; return $res }
|
|
1195
|
+
|
|
1196
|
+
$stamp = Get-Date -Format 'yyyyMMddHHmmssfff'
|
|
1197
|
+
$specPath = Join-Path ([IO.Path]::GetTempPath()) ('dsh-bilistate-spec-{0}-{1}.json' -f $stamp, $PID)
|
|
1198
|
+
$outPath = Join-Path ([IO.Path]::GetTempPath()) ('dsh-bilistate-out-{0}-{1}.json' -f $stamp, $PID)
|
|
1199
|
+
$spec = [ordered]@{
|
|
1200
|
+
mode = $Mode
|
|
1201
|
+
repoDir = [string]$RepoDir
|
|
1202
|
+
}
|
|
1203
|
+
if ($BiliDir) { $spec.biliDir = [string]$BiliDir }
|
|
1204
|
+
if ($Sessions -and @($Sessions).Count -gt 0) { $spec.sessions = @($Sessions | ForEach-Object { [string]$_ }) }
|
|
1205
|
+
[IO.File]::WriteAllText($specPath, ($spec | ConvertTo-Json -Depth 5 -Compress), (New-Object Text.UTF8Encoding($false)))
|
|
1206
|
+
|
|
1207
|
+
$oldRunAsNode = $env:ELECTRON_RUN_AS_NODE
|
|
1208
|
+
try {
|
|
1209
|
+
if ($runner.Electron) { $env:ELECTRON_RUN_AS_NODE = '1' }
|
|
1210
|
+
else { Remove-Item Env:\ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue }
|
|
1211
|
+
& $runner.Exe $tool 'sync' $specPath $outPath *> $null
|
|
1212
|
+
$code = $LASTEXITCODE
|
|
1213
|
+
if (-not (Test-Path -LiteralPath $outPath)) {
|
|
1214
|
+
$res.Reason = ('压缩状态工具没有产出结果文件(执行器退出码 {0})' -f $code)
|
|
1215
|
+
return $res
|
|
1216
|
+
}
|
|
1217
|
+
$r = ([IO.File]::ReadAllText($outPath, [Text.Encoding]::UTF8)) | ConvertFrom-Json -ErrorAction Stop
|
|
1218
|
+
$res.Ok = [bool]$r.ok
|
|
1219
|
+
$res.NoBili = [bool]$r.noBili
|
|
1220
|
+
if ($r.biliDir) { $res.BiliDir = [string]$r.biliDir }
|
|
1221
|
+
$res.Exported = @($r.exported)
|
|
1222
|
+
$res.Imported = @($r.imported)
|
|
1223
|
+
$res.Missing = @($r.missing)
|
|
1224
|
+
$res.Failed = @($r.failed)
|
|
1225
|
+
foreach ($e in @($r.exported)) { if ($e -and $e.bytes) { $res.Bytes += [long]$e.bytes } }
|
|
1226
|
+
$res.Skipped = $false
|
|
1227
|
+
return $res
|
|
1228
|
+
} catch {
|
|
1229
|
+
$res.Reason = ('压缩状态工具执行出错:{0}' -f $_.Exception.Message)
|
|
1230
|
+
return $res
|
|
1231
|
+
} finally {
|
|
1232
|
+
if ($null -eq $oldRunAsNode) { Remove-Item Env:\ELECTRON_RUN_AS_NODE -ErrorAction SilentlyContinue }
|
|
1233
|
+
else { $env:ELECTRON_RUN_AS_NODE = $oldRunAsNode }
|
|
1234
|
+
Remove-Item -LiteralPath $specPath -Force -ErrorAction SilentlyContinue
|
|
1235
|
+
Remove-Item -LiteralPath $outPath -Force -ErrorAction SilentlyContinue
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
# 把压缩状态搬运结果变成用户能看懂的提示;导入失败一律进 context-state 通知。
|
|
1240
|
+
function Write-BiliStateSyncReport($State, [string]$DshHome) {
|
|
1241
|
+
if (-not $State) { return }
|
|
1242
|
+
if ($State.Skipped) {
|
|
1243
|
+
Warn ('billion-context 压缩状态本次未搬运({0})' -f $State.Reason)
|
|
1244
|
+
return
|
|
1245
|
+
}
|
|
1246
|
+
if ($State.NoBili) {
|
|
1247
|
+
if ($State.Mode -eq 'import') {
|
|
1248
|
+
Ok ('本机没有 billion-context,跳过压缩状态导入(DSH 自带压缩会接管)')
|
|
1249
|
+
if ($DshHome) {
|
|
1250
|
+
Add-SyncNotice -Kind 'context-state' -Path 'billion-context' -Reason '本机没有 billion-context:会话压缩记录无处导入,DSH 自带压缩会接管;若长会话报上下文超长,在主力机重推一次或在配置里关掉 billion-context。'
|
|
1251
|
+
}
|
|
1252
|
+
} else {
|
|
1253
|
+
Ok ('本机没有 billion-context,跳过压缩状态导出')
|
|
1254
|
+
}
|
|
1255
|
+
return
|
|
1256
|
+
}
|
|
1257
|
+
if ($State.Mode -eq 'export') {
|
|
1258
|
+
$n = @($State.Exported).Count
|
|
1259
|
+
Ok ('billion-context 压缩状态(抓取):导出 {0} 个会话、{1:N1} MB' -f $n, ($State.Bytes / 1MB))
|
|
1260
|
+
foreach ($e in @($State.Exported)) {
|
|
1261
|
+
Ok (' {0}:blocks {1}、refs {2}、summary {3}' -f [string]$e.sessionId, $e.blocks, $e.refs, $e.content)
|
|
1262
|
+
}
|
|
1263
|
+
} else {
|
|
1264
|
+
$n = @($State.Imported).Count
|
|
1265
|
+
Ok ('billion-context 压缩状态(还原):导入 {0} 个会话' -f $n)
|
|
1266
|
+
foreach ($e in @($State.Imported)) {
|
|
1267
|
+
Ok (' {0}:blocks +{1}、refs +{2}、summary +{3}' -f [string]$e.sessionId, $e.blocks, $e.refs, $e.content)
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
foreach ($m in @($State.Missing)) {
|
|
1271
|
+
Warn (' 仓库里没有这个会话的压缩记录:{0}(B 机继续该会话可能报上下文超长)' -f [string]$m)
|
|
1272
|
+
if ($DshHome -and $State.Mode -eq 'import') {
|
|
1273
|
+
Add-SyncNotice -Kind 'context-state' -Path ([string]$m) -Reason '会话压缩状态没同步过来:本机继续该会话可能报上下文超长。在主力机重推一次(抓取会带上压缩状态),或在本机设置 BILLION_CONTEXT_PLUGIN=0 让 DSH 原生压缩兜底。'
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
foreach ($f in @($State.Failed)) {
|
|
1277
|
+
$sid = if ($f.sessionId) { [string]$f.sessionId } elseif ($f.file) { [string]$f.file } else { '(未知)' }
|
|
1278
|
+
Warn (' 压缩状态处理失败:{0}({1})' -f $sid, [string]$f.error)
|
|
1279
|
+
if ($DshHome) { Add-SyncNotice -Kind 'context-state' -Path $sid -Reason ('billion-context 压缩状态搬运失败:' + [string]$f.error) }
|
|
1280
|
+
}
|
|
1281
|
+
}
|
package/runtime/post-exit.ps1
CHANGED
|
@@ -169,6 +169,8 @@ function Show-NoticesSummary {
|
|
|
169
169
|
try { $n = Get-Content -LiteralPath $np -Raw -Encoding utf8 | ConvertFrom-Json } catch { return }
|
|
170
170
|
if (-not $n -or [int]$n.total -le 0) { return }
|
|
171
171
|
$groups = @(
|
|
172
|
+
@{ Kind = 'plugin-missing'; Title = '插件没装在本机(先装插件,再重新拉取一次)' }
|
|
173
|
+
@{ Kind = 'context-state'; Title = '会话缺 billion-context 压缩状态(可能报上下文超长)' }
|
|
172
174
|
@{ Kind = 'history'; Title = '历史提交里的超限文件(远端会拒收,需换仓库或清史)' }
|
|
173
175
|
@{ Kind = 'too-large'; Title = '超过单文件上限,未进仓库' }
|
|
174
176
|
@{ Kind = 'failed'; Title = '写入/推送失败' }
|