dsh-config-manager 0.4.3 → 0.5.0
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.md +10 -0
- package/README.zh-CN.md +10 -0
- package/lib/adapters/mcp.d.ts +9 -0
- package/lib/adapters/mcp.js +37 -0
- package/lib/adapters/plugins.js +10 -2
- package/lib/adapters/pnpm-workspace.js +1 -1
- package/lib/adapters/self.d.ts +2 -0
- package/lib/adapters/self.js +18 -2
- package/lib/adapters/workspaces.js +1 -1
- package/lib/cli/restore-resume.js +1 -1
- package/lib/cli/web/page.js +2 -2
- package/lib/client.d.ts +14 -41
- package/lib/client.js +794 -716
- package/lib/core/backup.d.ts +11 -0
- package/lib/core/backup.js +27 -0
- package/lib/core/env-lock-lifecycle.d.ts +17 -3
- package/lib/core/env-lock-lifecycle.js +38 -0
- package/lib/core/external-failure.d.ts +9 -0
- package/lib/core/external-failure.js +50 -0
- package/lib/core/local-plugin-host.d.ts +9 -7
- package/lib/core/local-plugin-host.js +109 -15
- package/lib/core/local-plugin-pack.d.ts +20 -0
- package/lib/core/local-plugin-pack.js +18 -3
- package/lib/core/mcp-connector-store.d.ts +13 -0
- package/lib/core/mcp-connector-store.js +16 -1
- package/lib/core/messages-core.d.ts +45 -0
- package/lib/core/messages-core.js +92 -0
- package/lib/core/messages.d.ts +1 -0
- package/lib/core/messages.js +6 -0
- package/lib/core/model-tool-plans.d.ts +66 -0
- package/lib/core/model-tool-plans.js +128 -0
- package/lib/core/model-tools.d.ts +96 -8
- package/lib/core/model-tools.js +568 -31
- package/lib/core/phase3-host.js +10 -2
- package/lib/core/plugin-data-registry.d.ts +1 -1
- package/lib/core/plugin-data-registry.js +1 -1
- package/lib/core/restore-plan-fingerprint.d.ts +2 -0
- package/lib/core/restore-plan-fingerprint.js +18 -0
- package/lib/core/restore-resume.d.ts +1 -1
- package/lib/core/restore-resume.js +1 -1
- package/lib/core/restore.d.ts +5 -0
- package/lib/core/restore.js +4 -1
- package/lib/core/types.d.ts +12 -0
- package/lib/foreign/claude-sessions.d.ts +1 -1
- package/lib/foreign/claude-sessions.js +1 -1
- package/lib/foreign/registry.js +1 -1
- package/lib/foreign/types.d.ts +1 -1
- package/lib/index.d.ts +15 -15
- package/lib/index.js +60 -67
- package/lib/market/git-file-writer.js +1 -1
- package/lib/market/github-repos.js +1 -1
- package/lib/market/market-config.js +1 -1
- package/lib/market/messages-market.js +1 -1
- package/lib/market/my-repo.js +1 -1
- package/lib/market/prepare.js +1 -1
- package/lib/market/reader.js +2 -2
- package/lib/market/repo-url.d.ts +1 -1
- package/lib/market/security.js +2 -2
- package/lib/market/star-cache.d.ts +1 -1
- package/lib/market/types.d.ts +1 -1
- package/lib/market/types.js +1 -1
- package/lib/market/url.js +1 -1
- package/lib/routes/backup.js +17 -9
- package/lib/routes/index.d.ts +1 -1
- package/lib/routes/kit.d.ts +2 -2
- package/lib/routes/market.d.ts +1 -1
- package/lib/routes/market.js +3 -60
- package/lib/routes/model-tools-deps.d.ts +41 -0
- package/lib/routes/model-tools-deps.js +18 -0
- package/lib/routes/recovery.js +5 -3
- package/lib/routes/route-support.d.ts +18 -26
- package/lib/routes/route-support.js +19 -32
- package/lib/routes/snapshots.d.ts +1 -1
- package/lib/routes/snapshots.js +4 -40
- package/lib/routes/sync.js +40 -28
- package/lib/schema/index.d.ts +2 -2
- package/lib/schema/index.js +2 -2
- package/lib/schema/section-registry.d.ts +5 -3
- package/lib/schema/section-registry.js +7 -3
- package/lib/security/secret-scanner.js +1 -1
- package/lib/sync/apply-bundle.d.ts +50 -0
- package/lib/sync/apply-bundle.js +60 -0
- package/lib/sync/autosync-scheduler.d.ts +9 -0
- package/lib/sync/autosync-scheduler.js +118 -89
- package/lib/sync/backup-scheduler.js +5 -4
- package/lib/sync/blob-store.d.ts +2 -2
- package/lib/sync/git/git-transport.d.ts +12 -0
- package/lib/sync/git/git-transport.js +50 -2
- package/lib/sync/merge.d.ts +2 -0
- package/lib/sync/merge.js +28 -0
- package/lib/sync/messages.d.ts +4 -0
- package/lib/sync/messages.js +9 -2
- package/lib/sync/s3/s3-transport.d.ts +1 -1
- package/lib/sync/s3/s3-transport.js +1 -1
- package/lib/sync/sync-engine.d.ts +4 -4
- package/lib/sync/sync-engine.js +25 -26
- package/lib/sync/sync-scope-boot.d.ts +34 -0
- package/lib/sync/sync-scope-boot.js +71 -0
- package/lib/sync/sync-scope.d.ts +103 -0
- package/lib/sync/sync-scope.js +229 -0
- package/lib/sync/sync-selection.d.ts +17 -4
- package/lib/sync/sync-selection.js +40 -14
- package/lib/sync/transport.d.ts +4 -1
- package/lib/sync/transport.js +6 -0
- package/lib/sync/webdav/webdav-transport.js +1 -1
- package/lib/sync/workspace-merge.d.ts +36 -0
- package/lib/sync/workspace-merge.js +152 -0
- package/lib/ui/backup-schedule.d.ts +13 -2
- package/lib/ui/backup-schedule.js +3 -0
- package/lib/ui/snapshots-view.d.ts +16 -0
- package/lib/ui/snapshots-view.js +21 -0
- package/lib/utils/env-lock.d.ts +96 -0
- package/lib/utils/env-lock.js +332 -111
- package/lib/utils/messages-utils.d.ts +6 -0
- package/lib/utils/messages-utils.js +17 -1
- package/lib/utils/patch-yaml.js +1 -1
- package/lib/utils/zip.js +1 -1
- package/package.json +3 -2
- package/src/adapters/mcp.test.ts +28 -0
- package/src/adapters/mcp.ts +33 -0
- package/src/adapters/plugins.test.ts +49 -0
- package/src/adapters/plugins.ts +9 -1
- package/src/adapters/pnpm-workspace.ts +1 -1
- package/src/adapters/self.test.ts +39 -1
- package/src/adapters/self.ts +20 -2
- package/src/adapters/workspaces.ts +1 -1
- package/src/cli/restore-resume.ts +1 -1
- package/src/cli/web/page.ts +2 -2
- package/src/client/about/AboutPanel.tsx +1 -1
- package/src/client/about/about-view.test.ts +1 -1
- package/src/client/about/about-view.ts +1 -1
- package/src/client/api.ts +1 -6
- package/src/client/chat/chat-entry-view.test.ts +1 -1
- package/src/client/chat/chat-slots.ts +1 -1
- package/src/client/chat/rollback-diff-tab.ts +1 -1
- package/src/client/client-types.ts +1 -1
- package/src/client/common/routes.ts +1 -5
- package/src/client/css-scale-guard.test.ts +1 -1
- package/src/client/home/HomePanel.tsx +3 -0
- package/src/client/library/ArtifactRow.tsx +14 -2
- package/src/client/library/LibraryPanel.tsx +44 -0
- package/src/client/locales/overview.ts +10 -2
- package/src/client/locales/sessions.ts +3 -0
- package/src/client/market/MyConfigsView.tsx +1 -1
- package/src/client/market/market-api.ts +2 -14
- package/src/client/market/market-locales.ts +1 -1
- package/src/client/market/market-view.ts +3 -3
- package/src/client/market/my-configs-api.ts +1 -1
- package/src/client/market/my-configs-view.ts +1 -1
- package/src/client/recovery/recovery-locales.test.ts +1 -1
- package/src/client/run-store.ts +1 -1
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
- package/src/client/sync/history-model.test.ts +28 -7
- package/src/client/sync/history-model.ts +6 -3
- package/src/client/sync/sync-locales.ts +10 -4
- package/src/client/sync/sync-view.ts +1 -1
- package/src/core/analyzer-cache.test.ts +1 -1
- package/src/core/backup.test.ts +45 -1
- package/src/core/backup.ts +25 -0
- package/src/core/disk-usage.test.ts +2 -0
- package/src/core/env-lock-lifecycle.ts +33 -3
- package/src/core/external-failure.test.ts +60 -0
- package/src/core/external-failure.ts +54 -0
- package/src/core/integrity-extra-entries.test.ts +1 -1
- package/src/core/local-plugin-host.test.ts +134 -0
- package/src/core/local-plugin-host.ts +122 -17
- package/src/core/local-plugin-pack.ts +39 -3
- package/src/core/mcp-connector-store.ts +26 -1
- package/src/core/messages-core.ts +94 -0
- package/src/core/messages.ts +6 -0
- package/src/core/model-tool-plans.test.ts +111 -0
- package/src/core/model-tool-plans.ts +170 -0
- package/src/core/model-tools.test.ts +212 -12
- package/src/core/model-tools.ts +710 -38
- package/src/core/phase3-host.ts +10 -2
- package/src/core/phase3-production-integration.test.ts +43 -0
- package/src/core/plugin-data-registry.ts +1 -1
- package/src/core/restore-plan-fingerprint.ts +19 -0
- package/src/core/restore-resume.ts +1 -1
- package/src/core/restore.ts +9 -1
- package/src/core/types.ts +12 -0
- package/src/foreign/claude-sessions.ts +3 -3
- package/src/foreign/registry.ts +1 -1
- package/src/foreign/types.ts +1 -1
- package/src/index.ts +91 -98
- package/src/market/git-file-writer.ts +1 -1
- package/src/market/github-repos.test.ts +1 -1
- package/src/market/github-repos.ts +1 -1
- package/src/market/market-config.ts +1 -1
- package/src/market/messages-market.ts +1 -1
- package/src/market/my-repo.test.ts +1 -1
- package/src/market/my-repo.ts +1 -1
- package/src/market/prepare.test.ts +1 -1
- package/src/market/prepare.ts +1 -1
- package/src/market/reader.ts +2 -2
- package/src/market/repo-url.ts +1 -1
- package/src/market/security.ts +2 -2
- package/src/market/star-cache.ts +1 -1
- package/src/market/types.ts +1 -1
- package/src/market/url.test.ts +1 -1
- package/src/market/url.ts +1 -1
- package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
- package/src/routes/backup.ts +16 -9
- package/src/routes/index.ts +1 -1
- package/src/routes/kit.ts +2 -2
- package/src/routes/market.ts +2 -59
- package/src/routes/model-tools-deps.ts +56 -0
- package/src/routes/recovery.ts +5 -3
- package/src/routes/route-support.ts +49 -36
- package/src/routes/snapshots.ts +4 -40
- package/src/routes/sync.ts +39 -27
- package/src/schema/index.ts +2 -2
- package/src/schema/manifest-schema.test.ts +2 -2
- package/src/schema/registry.test.ts +1 -1
- package/src/schema/section-registry.ts +9 -4
- package/src/security/redaction.test.ts +1 -1
- package/src/security/secret-scanner.test.ts +2 -2
- package/src/security/secret-scanner.ts +1 -1
- package/src/sync/apply-bundle.ts +104 -0
- package/src/sync/autosync-scheduler.test.ts +180 -6
- package/src/sync/autosync-scheduler.ts +132 -92
- package/src/sync/backup-scheduler.test.ts +11 -4
- package/src/sync/backup-scheduler.ts +5 -4
- package/src/sync/blob-store.ts +2 -2
- package/src/sync/git/git-transport.test.ts +62 -0
- package/src/sync/git/git-transport.ts +54 -3
- package/src/sync/merge.ts +29 -0
- package/src/sync/messages.ts +9 -2
- package/src/sync/s3/s3-transport.ts +1 -1
- package/src/sync/sync-engine.test.ts +238 -2
- package/src/sync/sync-engine.ts +25 -26
- package/src/sync/sync-preview-push.test.ts +2 -1
- package/src/sync/sync-scope-boot.ts +87 -0
- package/src/sync/sync-scope.test.ts +154 -0
- package/src/sync/sync-scope.ts +256 -0
- package/src/sync/sync-selection.test.ts +76 -2
- package/src/sync/sync-selection.ts +40 -13
- package/src/sync/transport.test.ts +21 -1
- package/src/sync/transport.ts +12 -0
- package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
- package/src/sync/webdav/webdav-transport.ts +1 -1
- package/src/sync/workspace-merge.test.ts +110 -0
- package/src/sync/workspace-merge.ts +180 -0
- package/src/ui/backup-schedule.test.ts +5 -0
- package/src/ui/backup-schedule.ts +21 -2
- package/src/ui/session-issue-labels.ts +1 -1
- package/src/ui/snapshots-view.test.ts +32 -0
- package/src/ui/snapshots-view.ts +34 -0
- package/src/utils/env-lock.test.ts +242 -9
- package/src/utils/env-lock.ts +247 -13
- package/src/utils/messages-utils.ts +17 -1
- package/src/utils/patch-yaml.ts +1 -1
- package/src/utils/zip.ts +1 -1
- package/src/client/CLIENT_DEPENDENCIES.md +0 -94
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* src/market/** 的领域消息目录(zh 源语言 / en 镜像)——「英文界面零中文」迁移(t5)。
|
|
3
3
|
*
|
|
4
|
-
* 口径(与 src/core/messages.ts 一致,见 docs/
|
|
4
|
+
* 口径(与 src/core/messages.ts 一致,见 docs/archive/2026-10-08-i18n-en-hardcoding.md):
|
|
5
5
|
* - zh 值 = 迁移前的既有中文文案**逐字不变**(既有测试断言依赖它,只允许新增 en);
|
|
6
6
|
* - en 值类型为 Record<keyof typeof zh, string> —— 缺键/多键即编译错误;
|
|
7
7
|
* - 动态明细一律走 {param} 插值传参,不得丢信息;
|
package/lib/market/my-repo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* m-market:MyRepoService —— 「一键上传 / 我的配置」上传编排(docs/
|
|
2
|
+
* m-market:MyRepoService —— 「一键上传 / 我的配置」上传编排(docs/archive/2026-08-20-my-configs-design.md §4.2/§4.3/§4.4/§4.5)。
|
|
3
3
|
*
|
|
4
4
|
* 数据流(upload / update 共用 runPublish 状态机):
|
|
5
5
|
* ① 登录(rest.getUser)→ login(401 → unauthorized,明确可分类)
|
package/lib/market/prepare.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* m-market:市场条目包生成(发布向导核心,docs/
|
|
2
|
+
* m-market:市场条目包生成(发布向导核心,docs/archive/2026-08-19-market-publish-design.md §3.4)。
|
|
3
3
|
*
|
|
4
4
|
* 职责:把「用户配置 zip + 用户填写元数据」转换为市场条目(L2 manifest + config.zip 的
|
|
5
5
|
* SHA-256 + sections),供发布向导展示与引导推送。纯函数、零磁盘写入(zipBytes 内存传入,
|
package/lib/market/reader.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* m-market:市场只读读取通道(MarketReader / GitMarketReader)。
|
|
3
3
|
*
|
|
4
|
-
* 与 docs/
|
|
4
|
+
* 与 docs/archive/2026-08-19-market-publish-design.md §3.2「GitMarketReader:按条目选择仓库」对齐:
|
|
5
5
|
* - 市场用「只读 git fetch」,不复用 GitTransport 的写路径(commit/push/snapshots/<id>/ 布局);
|
|
6
6
|
* - 复用点:git 命令执行层(execFile promise 封装 / 脱敏 mask / SnapshotFs)+ validateRepoUrl;
|
|
7
7
|
* - 每次读取:ensureRepo() 首次 git clone --depth 1,已存在副本则快进到远端(显式 refspec fetch +
|
|
8
8
|
* merge --ff-only,不读 FETCH_HEAD;参数见 src/utils/git-fast-forward.ts);整段在工作副本锁内;
|
|
9
9
|
* - 默认公开市场不注入凭据(repoUrl 拒绝 userinfo);二期私有市场才走 token credential helper;
|
|
10
10
|
* - itemId 必须过 assertSafeItemId(防 items/<id>/ 越界);
|
|
11
|
-
* - 条目级来源仓库(方案 B,docs/
|
|
11
|
+
* - 条目级来源仓库(方案 B,docs/archive/2026-08-19-market-publish-design.md §3.2):
|
|
12
12
|
* readItemManifest/readItemZip 接受可选 repo,读取目录 = repo ?? url;workDir 由调用方按
|
|
13
13
|
* 来源仓库 url-hash 分目录,index.json 永远从市场仓库读。
|
|
14
14
|
*/
|
package/lib/market/repo-url.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* m-market:GitHub 仓库 URL 解析(纯函数,node 可测)。
|
|
3
|
-
* docs/
|
|
3
|
+
* docs/archive/2026-08-21-market-star-filter-sort-design.md §3.1.2。
|
|
4
4
|
*
|
|
5
5
|
* 职责:从条目来源仓库 URL(`https://github.com/<owner>/<repo>[.git]`)解析出
|
|
6
6
|
* `{ owner, repo }`,供 star 查询(getRepoStarsPublic)使用。
|
package/lib/market/security.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* m-market:市场条目安全校验管线(依据 docs/
|
|
2
|
+
* m-market:市场条目安全校验管线(依据 docs/archive/2026-08-19-market-publish-design.md
|
|
3
3
|
* §3.6 安全分析——该节明确引用本模块的校验管线作为威胁缓解)。
|
|
4
4
|
* 下载条目(config.zip)后、生成 ImportPlan 之前依次执行,全部纯函数、node 可测。
|
|
5
5
|
*
|
|
@@ -102,7 +102,7 @@ export function validateMarketItem(itemId, manifestRaw, zipBytes) {
|
|
|
102
102
|
if (!enabled)
|
|
103
103
|
continue;
|
|
104
104
|
// 市场条目禁止分区(BANNED_MARKET_SECTIONS:sessions 历史会话 / pluginFiles 任意文件 / self 本地环境):
|
|
105
|
-
// 与 secrets 同级硬约束(产品决策 2026-08-19,guide docs/
|
|
105
|
+
// 与 secrets 同级硬约束(产品决策 2026-08-19,guide docs/contracts/market-index-v1.md)。
|
|
106
106
|
if (BANNED_MARKET_SECTIONS.includes(sectionId)) {
|
|
107
107
|
return { status: 'invalid', errors: [marketMsg('market.security.bannedSection', { section: sectionId })], warnings, manifest, internalManifest, sections: [], checksumsOk: true };
|
|
108
108
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* m-market:仓库 star 缓存(StarCache)。
|
|
3
|
-
* docs/
|
|
3
|
+
* docs/archive/2026-08-21-market-star-filter-sort-design.md §3.1.3。
|
|
4
4
|
*
|
|
5
5
|
* 职责:市场浏览时按「条目来源仓库」批量查询 star 数的编排层——
|
|
6
6
|
* - **按仓库 URL 去重**:一次浏览中同一 URL 只查一次 GitHub(官方条目共 1 个仓库、
|
package/lib/market/types.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type MarketPublishMode = 'migrate' | 'share';
|
|
|
26
26
|
*/
|
|
27
27
|
export declare const MAX_MARKET_ZIP_BYTES: number;
|
|
28
28
|
/**
|
|
29
|
-
* 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/
|
|
29
|
+
* 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/contracts/market-index-v1.md):
|
|
30
30
|
* - sessions:历史会话,含个人交互记录/上下文;
|
|
31
31
|
* - pluginFiles:任意文件直通(目录放啥带啥),无内容过滤,最易泄漏 token/密钥文件;
|
|
32
32
|
* - self:本地环境专属(sync 通道 URL / WebDAV 地址 / 市场配置 / UI 偏好),无分享价值且泄漏环境信息。
|
package/lib/market/types.js
CHANGED
|
@@ -8,7 +8,7 @@ export const MARKET_ITEM_SCHEMA_VERSION = 1;
|
|
|
8
8
|
*/
|
|
9
9
|
export const MAX_MARKET_ZIP_BYTES = 64 * 1024 * 1024;
|
|
10
10
|
/**
|
|
11
|
-
* 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/
|
|
11
|
+
* 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/contracts/market-index-v1.md):
|
|
12
12
|
* - sessions:历史会话,含个人交互记录/上下文;
|
|
13
13
|
* - pluginFiles:任意文件直通(目录放啥带啥),无内容过滤,最易泄漏 token/密钥文件;
|
|
14
14
|
* - self:本地环境专属(sync 通道 URL / WebDAV 地址 / 市场配置 / UI 偏好),无分享价值且泄漏环境信息。
|
package/lib/market/url.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* m-market:市场仓库地址校验(纯函数,node 可测)。
|
|
3
3
|
*
|
|
4
|
-
* 设计文档 docs/
|
|
4
|
+
* 设计文档 docs/archive/2026-08-19-market-publish-design.md §3.1:
|
|
5
5
|
* 条目来源仓库(repo)与市场仓库 URL 只接受 http(s),**拒绝 git@/ssh/scp 等形态**——
|
|
6
6
|
* 市场通道只走 https clone、永不注入凭据(ssh 依赖用户机器凭据,且 userinfo 已拒)。
|
|
7
7
|
* 复用 sync 的 validateRepoUrl(拒绝 userinfo / 空白),叠加 scheme 强制。
|
package/lib/routes/backup.js
CHANGED
|
@@ -22,13 +22,18 @@ import { join as joinPath } from 'node:path';
|
|
|
22
22
|
* 各写一份目录名而漂移。
|
|
23
23
|
*/
|
|
24
24
|
function diskUsageDirsOf(env) {
|
|
25
|
-
const { dataDir,
|
|
25
|
+
const { dataDir, marketDir, tmpDir, snapshotsDir, exportsDir } = env;
|
|
26
|
+
// `syncRootDir` 缺省回落本档案作用域目录:只有 syncDir 的装配面(未类型化夹具 / 手工装配)
|
|
27
|
+
// 就是历史单作用域布局,此时 syncDir === syncRootDir(见 syncScopeOrDefault)。
|
|
28
|
+
const syncRootDir = env.syncRootDir ?? env.syncDir;
|
|
26
29
|
return {
|
|
27
30
|
dataDir,
|
|
28
31
|
exportsDir,
|
|
29
32
|
snapshotsDir,
|
|
30
|
-
// 同步历史/快照/工作副本都在 <dataDir>/sync 下(Git 通道另有 .git
|
|
31
|
-
|
|
33
|
+
// 同步历史/快照/工作副本都在 <dataDir>/sync 下(Git 通道另有 .git 工作副本,一并计入)。
|
|
34
|
+
// 用 syncRootDir 而不是本档案的 syncDir:体检要看**整棵** sync/(含 sync-profiles/<p>/),
|
|
35
|
+
// 否则切到别的档具体检会把其它档案的同步数据当成不存在。
|
|
36
|
+
syncDir: syncRootDir,
|
|
32
37
|
marketCacheDir: joinPath(marketDir, 'cache'),
|
|
33
38
|
marketWorkDir: joinPath(marketDir, 'work'),
|
|
34
39
|
tmpDir,
|
|
@@ -42,7 +47,8 @@ function diskUsageDirsOf(env) {
|
|
|
42
47
|
}
|
|
43
48
|
/** 体检/清理共用的保留期口径(与 cache-cleaner 缺省逐字一致;定时备份前缀豁免同源) */
|
|
44
49
|
async function diskUsagePolicyOf(env) {
|
|
45
|
-
|
|
50
|
+
// 定时备份配置全机一份(sync/backup-schedule.json):排期与保留策略不属于任何单个档案。
|
|
51
|
+
const schedule = await readBackupSchedule(env.syncRootDir ?? env.syncDir);
|
|
46
52
|
return {
|
|
47
53
|
policy: {
|
|
48
54
|
tmpRetentionMs: TMP_RETENTION_DEFAULT_MS,
|
|
@@ -131,7 +137,9 @@ async function runDiskUsageCleanup(env, categories) {
|
|
|
131
137
|
};
|
|
132
138
|
}
|
|
133
139
|
export function backupRoutes(env) {
|
|
134
|
-
const { backupScheduler, exportsDir,
|
|
140
|
+
const { backupScheduler, exportsDir, withMutationGate, } = env;
|
|
141
|
+
// 定时备份**全机一份**(不是某个档案的同步态):读写都落 syncRootDir,缺省回落 syncDir(同上)。
|
|
142
|
+
const syncRootDir = env.syncRootDir ?? env.syncDir;
|
|
135
143
|
return [
|
|
136
144
|
// ------------------------------------------------------- disk-usage(只读体检)
|
|
137
145
|
// 界面「磁盘占用」卡的数据源:按子区回传字节数/文件数 + 各保留期的「已到期」量。
|
|
@@ -187,7 +195,7 @@ export function backupRoutes(env) {
|
|
|
187
195
|
endpoint({ path: '/api/dsh-config-manager/backup-schedule', methods: ['GET', 'PUT'] }, async (req, res) => {
|
|
188
196
|
if (req.method === 'GET') {
|
|
189
197
|
try {
|
|
190
|
-
writeJson(res, 200, { schedule: await readBackupSchedule(
|
|
198
|
+
writeJson(res, 200, { schedule: await readBackupSchedule(syncRootDir) });
|
|
191
199
|
}
|
|
192
200
|
catch (error) {
|
|
193
201
|
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
@@ -202,11 +210,11 @@ export function backupRoutes(env) {
|
|
|
202
210
|
writeJson(res, 400, { error: parsed.error });
|
|
203
211
|
return;
|
|
204
212
|
}
|
|
205
|
-
const current = await readBackupSchedule(
|
|
213
|
+
const current = await readBackupSchedule(syncRootDir);
|
|
206
214
|
const next = { ...current, ...parsed.value };
|
|
207
215
|
// m-retention:保留策略保存(草稿给了就用草稿值,否则保留既有;缺省由读取层补齐)
|
|
208
216
|
next.retention = parsed.value.retention ?? current.retention ?? { ...DEFAULT_RETENTION_POLICY };
|
|
209
|
-
await writeBackupSchedule(
|
|
217
|
+
await writeBackupSchedule(syncRootDir, next);
|
|
210
218
|
await backupScheduler.reload();
|
|
211
219
|
writeJson(res, 200, { ok: true, schedule: next });
|
|
212
220
|
}
|
|
@@ -226,7 +234,7 @@ export function backupRoutes(env) {
|
|
|
226
234
|
endpoint({ path: '/api/dsh-config-manager/backup-schedule/run', methods: ['POST'] }, async (req, res) => {
|
|
227
235
|
try {
|
|
228
236
|
const run = await backupScheduler.runOnce({ manual: true });
|
|
229
|
-
const schedule = await readBackupSchedule(
|
|
237
|
+
const schedule = await readBackupSchedule(syncRootDir);
|
|
230
238
|
writeJson(res, 200, { ok: true, run, schedule });
|
|
231
239
|
}
|
|
232
240
|
catch (error) {
|
package/lib/routes/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 顺序对匹配无影响:DSH webServer 的契约是「命名路由必须互不相同,注册顺序不影响请求」
|
|
5
5
|
* (见 @deepseek-ai/dsh-host-webserver 的 WebServer 文档)。src/index.ts 保留的 7 条被源码级
|
|
6
|
-
* 守卫按文件窗口钉住,其余
|
|
6
|
+
* 守卫按文件窗口钉住,其余 75 条在这里组装(总数 82:含 path-browse)。
|
|
7
7
|
*/
|
|
8
8
|
import type { WebRoute } from './kit.ts';
|
|
9
9
|
import type { RoutesEnv } from './context.ts';
|
package/lib/routes/kit.d.ts
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* - 「每条路由首行 guard」这条安全不变量此前**只写在注释里**,零测试覆盖;
|
|
9
9
|
* - 3 条 prefix 路由自造围栏(裸 isLoopbackRequest + 自判方法)。
|
|
10
10
|
*
|
|
11
|
-
* 计数口径(三路一致 =
|
|
12
|
-
* 路由快照
|
|
11
|
+
* 计数口径(三路一致 = 82,勿再照抄旧审计初稿的计数 —— 那是计数口径 overcount):
|
|
12
|
+
* 路由快照 82 条 = 现行 `endpoint()` 声明 82 条 = 运行期 `buildRoutes()` 75 条 + `src/index.ts` 保留的 7 条。
|
|
13
13
|
* 增删路由后必须同步这段计数、`src/routes/index.ts` 的头注释与 parity 快照清单;`tests/route/route-parity.test.ts`
|
|
14
14
|
* 的「路由计数散文」守卫会拿真实声明数逐条对账(写错即红灯)。
|
|
15
15
|
*
|
package/lib/routes/market.d.ts
CHANGED
package/lib/routes/market.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 路由组:配置市场(内置公开仓库:状态 / 刷新 / 浏览 /
|
|
2
|
+
* 路由组:配置市场(内置公开仓库:状态 / 刷新 / 浏览 / 下载)。
|
|
3
3
|
*
|
|
4
4
|
* W1(host-entry#F-02/#F-03):路由只在这里声明一次 —— endpoint({ path, methods }, handler) 的
|
|
5
5
|
* path/methods 就是唯一声明处;围栏、方法判定与顶层异常处理由 src/routes/kit.ts 在注册点统一提供。
|
|
6
6
|
*/
|
|
7
|
-
import { endpoint,
|
|
8
|
-
import { isControlledPath } from './route-support.js';
|
|
7
|
+
import { endpoint, readJsonBody, writeJson } from './kit.js';
|
|
9
8
|
import { BUILTIN_MARKET_URL } from '../market/builtin.js';
|
|
10
9
|
import { parseMarketIndex, parseMarketItemManifest } from '../market/index-parser.js';
|
|
11
|
-
import { prepareMarketItem } from '../market/prepare.js';
|
|
12
10
|
import { validateMarketItem } from '../market/security.js';
|
|
13
11
|
import { validateMarketRepoUrl } from '../market/url.js';
|
|
14
12
|
import { marketItemWarnings, toMarketListItem } from '../market/view.js';
|
|
15
|
-
import { zipToBuffer } from '../utils/zip.js';
|
|
16
13
|
import { randomBytes } from 'node:crypto';
|
|
17
14
|
import fs from 'node:fs/promises';
|
|
18
15
|
import { dirname, join } from 'node:path';
|
|
19
16
|
export function marketRoutes(env) {
|
|
20
|
-
const { buildMarketSummary, itemCached, makeImporter, makeMarketReader, marketBootAutoRefreshed, marketCacheIndex, marketCacheItemDir, marketStarCache, marketWorkDir, msg, pruneStagedMarketZips, readCachedIndexObj,
|
|
17
|
+
const { buildMarketSummary, itemCached, makeImporter, makeMarketReader, marketBootAutoRefreshed, marketCacheIndex, marketCacheItemDir, marketStarCache, marketWorkDir, msg, pruneStagedMarketZips, readCachedIndexObj, tmpDir, writeItemCache, } = env;
|
|
21
18
|
return [
|
|
22
19
|
// ---------------------------------------------------- market/status
|
|
23
20
|
// 内置单市场(只读、不可编辑):恒返回内置仓库摘要。无 add/remove —— 市场绑定内置仓库。
|
|
@@ -196,60 +193,6 @@ export function marketRoutes(env) {
|
|
|
196
193
|
writeJson(res, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
197
194
|
}
|
|
198
195
|
}),
|
|
199
|
-
// ---------------------------------------------------- market/prepare
|
|
200
|
-
// 发布向导:由「用户上传的配置 zip + 用户填写元数据」生成市场条目包
|
|
201
|
-
// (L2 manifest + config.zip SHA-256 + sections),供 UI 展示/复制与引导推送。
|
|
202
|
-
// 零写入配置:只在受控临时区生成发布目录;插件不做任何 git 写操作、不持有凭据。
|
|
203
|
-
endpoint({ path: '/api/dsh-config-manager/market/prepare', methods: ['POST'] }, async (req, res) => {
|
|
204
|
-
const body = await requireJsonObject(req);
|
|
205
|
-
const zipPath = typeof body?.['zipPath'] === 'string' ? body['zipPath'] : '';
|
|
206
|
-
if (zipPath === '' || !isControlledPath(zipPath, roots)) {
|
|
207
|
-
writeJson(res, 400, { error: 'zipPath is required and must reference a staged upload' });
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const itemId = typeof body?.['itemId'] === 'string' ? body['itemId'] : '';
|
|
211
|
-
const name = typeof body?.['name'] === 'string' ? body['name'] : '';
|
|
212
|
-
const version = typeof body?.['version'] === 'string' ? body['version'] : undefined;
|
|
213
|
-
const description = typeof body?.['description'] === 'string' ? body['description'] : undefined;
|
|
214
|
-
const author = typeof body?.['author'] === 'string' ? body['author'] : undefined;
|
|
215
|
-
const repoUrl = typeof body?.['repoUrl'] === 'string' && body['repoUrl'] !== '' ? body['repoUrl'] : undefined;
|
|
216
|
-
const categoriesRaw = body?.['categories'];
|
|
217
|
-
const categories = Array.isArray(categoriesRaw)
|
|
218
|
-
? categoriesRaw.filter((c) => typeof c === 'string')
|
|
219
|
-
: undefined;
|
|
220
|
-
// F6 分享模式:share 强制排除 deviceSpecific/platformSpecific 分区 + 保守档内容扫描拦截
|
|
221
|
-
// (prepare.ts 内实现);migrate 缺省。非法值一律回退 migrate。
|
|
222
|
-
const mode = body?.['mode'] === 'share' ? 'share' : 'migrate';
|
|
223
|
-
try {
|
|
224
|
-
const zipBytes = await fs.readFile(zipPath);
|
|
225
|
-
const result = prepareMarketItem({ itemId, name, version, description, author, repoUrl, categories, zipBytes, mode });
|
|
226
|
-
// 发布目录落到受控临时区(供 UI 展示目录结构;不写任何配置)
|
|
227
|
-
const dir = join(tmpDir, `publish-${itemId}-${randomBytes(6).toString('hex')}`);
|
|
228
|
-
const itemDir = join(dir, 'items', itemId);
|
|
229
|
-
await fs.mkdir(itemDir, { recursive: true });
|
|
230
|
-
await fs.writeFile(join(itemDir, 'manifest.json'), result.manifestText, 'utf8');
|
|
231
|
-
await fs.writeFile(join(itemDir, 'config.zip'), zipBytes);
|
|
232
|
-
// 打包发布目录为 zip(供 /download 端点下载;zip 由懒 GC 清理),
|
|
233
|
-
// 打包后删除中间目录,避免 publish-* 目录在 tmpDir 无限累积
|
|
234
|
-
const publishZip = join(tmpDir, `publish-${itemId}-${randomBytes(6).toString('hex')}.zip`);
|
|
235
|
-
await fs.writeFile(publishZip, Buffer.from(zipToBuffer([
|
|
236
|
-
{ name: `items/${itemId}/manifest.json`, data: Buffer.from(result.manifestText, 'utf8') },
|
|
237
|
-
{ name: `items/${itemId}/config.zip`, data: Buffer.from(zipBytes) },
|
|
238
|
-
])));
|
|
239
|
-
await fs.rm(dir, { force: true, recursive: true }).catch(() => undefined);
|
|
240
|
-
writeJson(res, 200, {
|
|
241
|
-
ok: true,
|
|
242
|
-
zipPath: publishZip,
|
|
243
|
-
manifestText: result.manifestText,
|
|
244
|
-
sha256: result.sha256,
|
|
245
|
-
sections: result.sections,
|
|
246
|
-
warnings: result.warnings,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
writeJson(res, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
251
|
-
}
|
|
252
|
-
}),
|
|
253
196
|
];
|
|
254
197
|
}
|
|
255
198
|
//# sourceMappingURL=market.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-config-manager — agent 工具面的依赖装配(从 src/index.ts 下沉)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单列:src/index.ts 有体量棘轮,且「同一批依赖来源」这条口径(D3 凭据槽 /
|
|
5
|
+
* D5 只放行 'auto' 档分区 / D6 受控路径根)最好与路由层代码放在一起看。
|
|
6
|
+
* index.ts 只保留一次 makeRoutes 解构与一次 registerModelTools 调用。
|
|
7
|
+
*
|
|
8
|
+
* 安全不变量(与 model-tools.ts 一致,勿在此处放宽):
|
|
9
|
+
* - syncPassword 只把宿主内存里的密码值交给本次引擎调用,绝不进工具返回 / render / 日志;
|
|
10
|
+
* - optInSections 固定走 selectionOptInSections(channel, true)('auto' 档),
|
|
11
|
+
* sessions 由 model-tools 再永久剔除;
|
|
12
|
+
* - roots 与 /analyze、/plan 同一判据(isControlledPath),缺省空集 = fail-closed。
|
|
13
|
+
*/
|
|
14
|
+
import type { ConfigAdapter, HostContext, SecretScanner } from '../core/types.ts';
|
|
15
|
+
import type { Importer } from '../core/importer.ts';
|
|
16
|
+
import type { ModelToolsDeps } from '../core/model-tools.ts';
|
|
17
|
+
import type { SectionId } from '../schema/types.ts';
|
|
18
|
+
import type { SyncConfig, SyncTransportType } from '../sync/sync-config.ts';
|
|
19
|
+
import type { SyncEngine } from '../sync/sync-engine.ts';
|
|
20
|
+
export interface AgentToolDepsInput {
|
|
21
|
+
host: HostContext;
|
|
22
|
+
adapters: ConfigAdapter[];
|
|
23
|
+
exportsDir: string;
|
|
24
|
+
snapshotsDir: string;
|
|
25
|
+
syncDir: string;
|
|
26
|
+
makeSyncEngine: (cfg: SyncConfig, opts?: {
|
|
27
|
+
optInSections?: readonly SectionId[];
|
|
28
|
+
}) => SyncEngine;
|
|
29
|
+
/** 宿主侧按 DSH credentials 槽位读取(值只在内存里过一手)。 */
|
|
30
|
+
resolveSyncPassword: (ref: string) => Promise<string | undefined>;
|
|
31
|
+
/** 槽位引用构造(ENCRYPT / DECRYPT + 通道),与 /sync/apply-items 同源。 */
|
|
32
|
+
syncPasswordRef: (kind: 'ENCRYPT' | 'DECRYPT', channel: SyncTransportType) => string;
|
|
33
|
+
/** onlyAuto = true 时只放行「自动档」可选分区(agent 侧恒 true)。 */
|
|
34
|
+
selectionOptInSections: (channel: SyncTransportType, onlyAuto?: boolean) => SectionId[];
|
|
35
|
+
makeImporter: () => Importer;
|
|
36
|
+
roots: readonly string[];
|
|
37
|
+
scanner?: SecretScanner;
|
|
38
|
+
exporterVersion?: string;
|
|
39
|
+
}
|
|
40
|
+
/** 组装 9 个模型工具所需的依赖;纯映射,无副作用、不读盘、不触网。 */
|
|
41
|
+
export declare function createAgentToolDeps(input: AgentToolDepsInput): ModelToolsDeps;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** 组装 9 个模型工具所需的依赖;纯映射,无副作用、不读盘、不触网。 */
|
|
2
|
+
export function createAgentToolDeps(input) {
|
|
3
|
+
return {
|
|
4
|
+
host: input.host,
|
|
5
|
+
adapters: input.adapters,
|
|
6
|
+
exportsDir: input.exportsDir,
|
|
7
|
+
snapshotsDir: input.snapshotsDir,
|
|
8
|
+
syncDir: input.syncDir,
|
|
9
|
+
makeSyncEngine: input.makeSyncEngine,
|
|
10
|
+
...(input.exporterVersion === undefined ? {} : { exporterVersion: input.exporterVersion }),
|
|
11
|
+
...(input.scanner === undefined ? {} : { scanner: input.scanner }),
|
|
12
|
+
syncPassword: async (kind, channel) => await input.resolveSyncPassword(input.syncPasswordRef(kind, channel)),
|
|
13
|
+
optInSections: (channel) => input.selectionOptInSections(channel, true),
|
|
14
|
+
makeImporter: input.makeImporter,
|
|
15
|
+
roots: input.roots,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=model-tools-deps.js.map
|
package/lib/routes/recovery.js
CHANGED
|
@@ -762,9 +762,11 @@ export function recoveryRoutes(env) {
|
|
|
762
762
|
log: (line) => host.log.warn(line),
|
|
763
763
|
...(forkSeam !== undefined ? { fork: forkSeam } : {}),
|
|
764
764
|
});
|
|
765
|
-
// 插件偏好文件与 /sync/ui-prefs
|
|
766
|
-
//
|
|
767
|
-
|
|
765
|
+
// 插件偏好文件与 /sync/ui-prefs 同一份,回滚点开关存在那里,绝不另立第二个偏好文件。
|
|
766
|
+
// 目录**按档案**(默认档案 = dataDir/sync,其它 = dataDir/sync-profiles/<profile>):
|
|
767
|
+
// 这里直接取 env.syncDir —— 不能再自己 join(dataDir,'sync'),否则非默认档案的
|
|
768
|
+
// 开关在这里读历史根、在 /sync 里读自己的作用域,两处对不上。
|
|
769
|
+
const syncDir = env.syncDir;
|
|
768
770
|
const sub = segments.slice(1);
|
|
769
771
|
const methodNotAllowed = () => { writeJson(res, 405, { error: 'method not allowed', code: 'method-not-allowed' }); };
|
|
770
772
|
const reply = (value) => {
|
|
@@ -21,31 +21,7 @@ import type { RestoreResumeHint } from '../core/restore-resume.ts';
|
|
|
21
21
|
import type { RestoreJournalPort } from '../core/restore-wal.ts';
|
|
22
22
|
import type { SyncConfig, SyncTransportType } from '../sync/sync-config.ts';
|
|
23
23
|
import type { AutosyncAutoApplyTier, AutosyncConflictPolicy, AutosyncInterval, AutosyncRunStatus } from '../sync/autosync-config.ts';
|
|
24
|
-
|
|
25
|
-
* 同步 token 的 DSH credentials 引用名(POSIX env-var 形态,满足 CredentialRef 品牌要求)。
|
|
26
|
-
* token 只经 credentialRef 读写(写入由请求体触发,读取在每次 git 网络操作时 resolve),
|
|
27
|
-
* 永不进 repoUrl / argv / commit / 同步文件 / 日志。
|
|
28
|
-
*/
|
|
29
|
-
export declare const SYNC_CREDENTIAL_REF = "DSH_CONFIG_MANAGER_SYNC_TOKEN";
|
|
30
|
-
/**
|
|
31
|
-
* WebDAV 通道口令的独立 DSH credentials 引用(与 git token 槽位分离)。
|
|
32
|
-
* 口令只经 credentialRef 读写(写入由请求体触发,读取在每次 WebDAV 网络操作时
|
|
33
|
-
* by WebDavTransport 经注入的 getPassword() resolve),永不进 URL / 请求头 / 日志。
|
|
34
|
-
*/
|
|
35
|
-
export declare const SYNC_WEBDAV_CREDENTIAL_REF = "DSH_CONFIG_MANAGER_SYNC_WEBDAV_PASSWORD";
|
|
36
|
-
/**
|
|
37
|
-
* 同步快照「加密密码 / 解密密码」的 DSH credentials 引用名前缀(按通道各自独立)。
|
|
38
|
-
*
|
|
39
|
-
* 为什么放 DSH credentials:加密/解密密码跨会话必须可用(否则每次推送都要重新输入),
|
|
40
|
-
* 但**绝不允许**写进 sync-selection.json 一类同步文件(那等于把密码推上远端)。
|
|
41
|
-
* 与本插件既有的 token / WebDAV 口令同一套做法:值只存在于 DSH 凭据库,
|
|
42
|
-
* 宿主内部按需 resolve,**永不回传浏览器**(UI 只拿到 configured 布尔)。
|
|
43
|
-
* 引用名形如 DSH_CONFIG_MANAGER_SYNC_ENCRYPT_PASSWORD_GIT。
|
|
44
|
-
*/
|
|
45
|
-
export declare const SYNC_ENCRYPT_PASSWORD_REF_PREFIX = "DSH_CONFIG_MANAGER_SYNC_ENCRYPT_PASSWORD";
|
|
46
|
-
export declare const SYNC_DECRYPT_PASSWORD_REF_PREFIX = "DSH_CONFIG_MANAGER_SYNC_DECRYPT_PASSWORD";
|
|
47
|
-
/** ('ENCRYPT'|'DECRYPT', 'git'|'webdav') → 该通道的凭据引用名。 */
|
|
48
|
-
export declare function syncPasswordRef(kind: 'ENCRYPT' | 'DECRYPT', channel: SyncTransportType): string;
|
|
24
|
+
export { SYNC_CREDENTIAL_REF, SYNC_DECRYPT_PASSWORD_REF_PREFIX, SYNC_ENCRYPT_PASSWORD_REF_PREFIX, SYNC_WEBDAV_CREDENTIAL_REF, scopedSyncRef, syncPasswordRef, syncScopeOrDefault, } from '../sync/sync-scope.ts';
|
|
49
25
|
/**
|
|
50
26
|
* 档案路由的错误响应:engine 的 DshProfileError 带 code(UI 据此映射本地化文案,
|
|
51
27
|
* 不显示裸英文码);其它异常按 500 处理。
|
|
@@ -274,9 +250,25 @@ export declare function executeRestorePlan(plan: RestorePlan, exec: RestoreExecu
|
|
|
274
250
|
}) => void, journal?: RestoreJournalPort, resumeHint?: RestoreResumeHint): Promise<RestoreReport>;
|
|
275
251
|
/** 宿主 restore 执行器装配:ctx.fs(home-relative)+ 快照目录(node fs)+ runDshPlugin。 */
|
|
276
252
|
export declare function makeRestoreExecutor(snapshotDir: string, host: HostContext, profile: string): RestoreExecutor;
|
|
277
|
-
/**
|
|
253
|
+
/**
|
|
254
|
+
* parseSyncBody 的凭据写入依赖(只用到 set;测试可注入内存 mock)。
|
|
255
|
+
*/
|
|
278
256
|
export interface ParseSyncBodyDeps {
|
|
279
257
|
credentials: Pick<CredentialProvider, 'set'>;
|
|
258
|
+
/**
|
|
259
|
+
* per-profile 作用域:只决定**写哪个凭据槽位**,不影响请求体形状与返回值。
|
|
260
|
+
* 缺省 = 历史(不带后缀)槽位名 —— 单档案用户与既有测试的行为逐字不变。
|
|
261
|
+
*/
|
|
262
|
+
scope?: SyncRefScope;
|
|
263
|
+
}
|
|
264
|
+
/** 把历史槽位名映射到当前档案的最小接口(`SyncScope` 结构上即满足)。 */
|
|
265
|
+
export interface SyncRefScope {
|
|
266
|
+
/** 本档案的 git / GitHub token 槽位 */
|
|
267
|
+
tokenRef: string;
|
|
268
|
+
/** 本档案的 WebDAV 口令槽位 */
|
|
269
|
+
webdavPasswordRef: string;
|
|
270
|
+
/** 历史槽位名 → 本档案槽位名(云端点密钥等按需映射) */
|
|
271
|
+
scopeRef(ref: string): string;
|
|
280
272
|
}
|
|
281
273
|
/**
|
|
282
274
|
* 解析同步请求体,按 transport 分支返回归一化的 SyncConfig(可辨识联合,schemaVersion=2)。
|
|
@@ -33,33 +33,12 @@ import { resolveProfileDir, runDshPlugin } from '../core/plugin-cli.js';
|
|
|
33
33
|
import { isSameOrChild } from '../utils/paths.js';
|
|
34
34
|
import { parseZip } from '../utils/zip.js';
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* 同步凭据槽位名与 per-profile 作用域:**唯一声明处已迁到 `src/sync/sync-scope.ts`**
|
|
37
|
+
* (那里也持有 `syncScopeFor` / `adoptLegacySyncScope`)。此文件只 re-export,
|
|
38
|
+
* 保持 `src/index.ts` 与测试既有的 import 面与符号名不变(值不变,只是多了可选档案后缀)。
|
|
39
39
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* WebDAV 通道口令的独立 DSH credentials 引用(与 git token 槽位分离)。
|
|
43
|
-
* 口令只经 credentialRef 读写(写入由请求体触发,读取在每次 WebDAV 网络操作时
|
|
44
|
-
* by WebDavTransport 经注入的 getPassword() resolve),永不进 URL / 请求头 / 日志。
|
|
45
|
-
*/
|
|
46
|
-
export const SYNC_WEBDAV_CREDENTIAL_REF = 'DSH_CONFIG_MANAGER_SYNC_WEBDAV_PASSWORD';
|
|
47
|
-
/**
|
|
48
|
-
* 同步快照「加密密码 / 解密密码」的 DSH credentials 引用名前缀(按通道各自独立)。
|
|
49
|
-
*
|
|
50
|
-
* 为什么放 DSH credentials:加密/解密密码跨会话必须可用(否则每次推送都要重新输入),
|
|
51
|
-
* 但**绝不允许**写进 sync-selection.json 一类同步文件(那等于把密码推上远端)。
|
|
52
|
-
* 与本插件既有的 token / WebDAV 口令同一套做法:值只存在于 DSH 凭据库,
|
|
53
|
-
* 宿主内部按需 resolve,**永不回传浏览器**(UI 只拿到 configured 布尔)。
|
|
54
|
-
* 引用名形如 DSH_CONFIG_MANAGER_SYNC_ENCRYPT_PASSWORD_GIT。
|
|
55
|
-
*/
|
|
56
|
-
export const SYNC_ENCRYPT_PASSWORD_REF_PREFIX = 'DSH_CONFIG_MANAGER_SYNC_ENCRYPT_PASSWORD';
|
|
57
|
-
export const SYNC_DECRYPT_PASSWORD_REF_PREFIX = 'DSH_CONFIG_MANAGER_SYNC_DECRYPT_PASSWORD';
|
|
58
|
-
/** ('ENCRYPT'|'DECRYPT', 'git'|'webdav') → 该通道的凭据引用名。 */
|
|
59
|
-
export function syncPasswordRef(kind, channel) {
|
|
60
|
-
const prefix = kind === 'ENCRYPT' ? SYNC_ENCRYPT_PASSWORD_REF_PREFIX : SYNC_DECRYPT_PASSWORD_REF_PREFIX;
|
|
61
|
-
return prefix + '_' + channel.toUpperCase();
|
|
62
|
-
}
|
|
40
|
+
import { SYNC_CREDENTIAL_REF, SYNC_WEBDAV_CREDENTIAL_REF, } from '../sync/sync-scope.js';
|
|
41
|
+
export { SYNC_CREDENTIAL_REF, SYNC_DECRYPT_PASSWORD_REF_PREFIX, SYNC_ENCRYPT_PASSWORD_REF_PREFIX, SYNC_WEBDAV_CREDENTIAL_REF, scopedSyncRef, syncPasswordRef, syncScopeOrDefault, } from '../sync/sync-scope.js';
|
|
63
42
|
/* 路由基础设施(loopback 围栏 / writeJson / readJsonBody / queryParam / endpoint / 错误映射)
|
|
64
43
|
* 已收敛到 src/routes/kit.ts —— 全仓只有那一份实现。 */
|
|
65
44
|
/**
|
|
@@ -644,6 +623,10 @@ export function makeRestoreExecutor(snapshotDir, host, profile) {
|
|
|
644
623
|
* 返回值不含任何 secret(password/token 只进 credentials,永不回传/落同步文件)。
|
|
645
624
|
*/
|
|
646
625
|
export async function parseSyncBody(body, deps) {
|
|
626
|
+
// per-profile 槽位(缺省 = 历史槽位名;请求体形状与返回值与档案无关)
|
|
627
|
+
const scope = deps.scope;
|
|
628
|
+
const tokenRef = scope === undefined ? SYNC_CREDENTIAL_REF : scope.tokenRef;
|
|
629
|
+
const webdavPasswordRef = scope === undefined ? SYNC_WEBDAV_CREDENTIAL_REF : scope.webdavPasswordRef;
|
|
647
630
|
const rawTransport = body['transport'];
|
|
648
631
|
// 通道值解析:接受通道名(s3/gist);也接受**具体兼容商**(oss/cos/minio/kodo)直接落到 s3 通道
|
|
649
632
|
const transport = parseSyncChannel(rawTransport) ?? (isS3CompatProvider(rawTransport) ? 's3' : 'git');
|
|
@@ -662,11 +645,11 @@ export async function parseSyncBody(body, deps) {
|
|
|
662
645
|
const password = typeof body['password'] === 'string' && body['password'] !== '' ? body['password'] : undefined;
|
|
663
646
|
if (password !== undefined) {
|
|
664
647
|
try {
|
|
665
|
-
await deps.credentials.set(credentialRef(
|
|
648
|
+
await deps.credentials.set(credentialRef(webdavPasswordRef), password);
|
|
666
649
|
}
|
|
667
650
|
catch (error) {
|
|
668
651
|
const reason = error instanceof Error ? error.message : String(error);
|
|
669
|
-
throw new SyncRouteError(engineMsg('host.syncWebdavPasswordWriteFailed', { reason, ref:
|
|
652
|
+
throw new SyncRouteError(engineMsg('host.syncWebdavPasswordWriteFailed', { reason, ref: webdavPasswordRef }));
|
|
670
653
|
}
|
|
671
654
|
}
|
|
672
655
|
return {
|
|
@@ -685,11 +668,11 @@ export async function parseSyncBody(body, deps) {
|
|
|
685
668
|
const token = typeof body['token'] === 'string' && body['token'] !== '' ? body['token'] : undefined;
|
|
686
669
|
if (token !== undefined) {
|
|
687
670
|
try {
|
|
688
|
-
await deps.credentials.set(credentialRef(
|
|
671
|
+
await deps.credentials.set(credentialRef(tokenRef), token);
|
|
689
672
|
}
|
|
690
673
|
catch (error) {
|
|
691
674
|
const reason = error instanceof Error ? error.message : String(error);
|
|
692
|
-
throw new SyncRouteError(engineMsg('host.syncTokenWriteFailed', { reason, ref:
|
|
675
|
+
throw new SyncRouteError(engineMsg('host.syncTokenWriteFailed', { reason, ref: tokenRef }));
|
|
693
676
|
}
|
|
694
677
|
}
|
|
695
678
|
return {
|
|
@@ -702,6 +685,10 @@ export async function parseSyncBody(body, deps) {
|
|
|
702
685
|
function syncStr(value) {
|
|
703
686
|
return typeof value === 'string' ? value.trim() : '';
|
|
704
687
|
}
|
|
688
|
+
/** 云端点密钥槽位按档案映射(无 scope = 历史槽位名,单档案行为逐字不变)。 */
|
|
689
|
+
function scopedCloudSecretRef(ref, deps) {
|
|
690
|
+
return deps.scope === undefined ? ref : deps.scope.scopeRef(ref);
|
|
691
|
+
}
|
|
705
692
|
/** 云端点密钥写入失败 → 可操作错误(**含 ref 名、绝不含密钥值**)。 */
|
|
706
693
|
function cloudCredentialWriteError(ref, kind, error) {
|
|
707
694
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -739,7 +726,7 @@ async function parseCloudS3Body(body, rawTransport, deps) {
|
|
|
739
726
|
throw new SyncRouteError(issue, 400, issue);
|
|
740
727
|
const secret = typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined;
|
|
741
728
|
if (secret !== undefined) {
|
|
742
|
-
const ref = cloudSecretRef(provider);
|
|
729
|
+
const ref = scopedCloudSecretRef(cloudSecretRef(provider), deps);
|
|
743
730
|
try {
|
|
744
731
|
await deps.credentials.set(credentialRef(ref), secret);
|
|
745
732
|
}
|
|
@@ -781,7 +768,7 @@ async function parseCloudGistBody(body, deps) {
|
|
|
781
768
|
? body['token']
|
|
782
769
|
: (typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined);
|
|
783
770
|
if (token !== undefined) {
|
|
784
|
-
const ref = cloudSecretRef(GIST_PROVIDER);
|
|
771
|
+
const ref = scopedCloudSecretRef(cloudSecretRef(GIST_PROVIDER), deps);
|
|
785
772
|
try {
|
|
786
773
|
await deps.credentials.set(credentialRef(ref), token);
|
|
787
774
|
}
|