dsh-config-manager 0.4.3 → 0.6.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 +17 -41
- package/lib/client.js +946 -761
- 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 +5 -0
- package/lib/core/messages.js +14 -0
- package/lib/core/migration-history.d.ts +40 -0
- package/lib/core/migration-history.js +55 -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-cli.d.ts +5 -0
- package/lib/core/plugin-cli.js +11 -3
- 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 +19 -15
- package/lib/index.js +72 -80
- 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/profiles/dsh-profile-manager.d.ts +1 -1
- package/lib/profiles/dsh-profile-manager.js +26 -7
- package/lib/profiles/dsh-profile-shared.d.ts +3 -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/ui/sync-repository-picker.d.ts +21 -0
- package/lib/ui/sync-repository-picker.js +18 -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/remove-tree.d.ts +7 -0
- package/lib/utils/remove-tree.js +265 -0
- 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/config-manager.module.css +21 -1
- package/src/client/css-scale-guard.test.ts +1 -1
- package/src/client/environment/EnvironmentPanel.tsx +2 -2
- 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/profiles.ts +2 -0
- 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/ChannelConfigDialog.tsx +32 -1
- package/src/client/sync/SyncPanel.tsx +11 -30
- package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
- package/src/client/sync/SyncSettingsView.test.ts +32 -0
- package/src/client/sync/config-save-state.test.ts +99 -0
- package/src/client/sync/config-save-state.ts +69 -0
- 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 +14 -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/engine-locale.test.ts +4 -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 +14 -0
- package/src/core/migration-history.test.ts +65 -0
- package/src/core/migration-history.ts +70 -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-cli.fs.test.ts +30 -3
- package/src/core/plugin-cli.ts +11 -3
- 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 +102 -111
- 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/profiles/dsh-profile-manager.test.ts +20 -0
- package/src/profiles/dsh-profile-manager.ts +25 -7
- package/src/profiles/dsh-profile-shared.ts +2 -0
- 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/ui/sync-repository-picker.test.ts +34 -1
- package/src/ui/sync-repository-picker.ts +24 -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/remove-tree.test.ts +120 -0
- package/src/utils/remove-tree.ts +239 -0
- package/src/utils/zip.ts +1 -1
- package/src/client/CLIENT_DEPENDENCIES.md +0 -94
package/src/market/security.ts
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
|
*
|
|
@@ -128,7 +128,7 @@ export function validateMarketItem(
|
|
|
128
128
|
for (const [sectionId, enabled] of Object.entries(internalManifest.sections) as [SectionId, boolean][]) {
|
|
129
129
|
if (!enabled) continue;
|
|
130
130
|
// 市场条目禁止分区(BANNED_MARKET_SECTIONS:sessions 历史会话 / pluginFiles 任意文件 / self 本地环境):
|
|
131
|
-
// 与 secrets 同级硬约束(产品决策 2026-08-19,guide docs/
|
|
131
|
+
// 与 secrets 同级硬约束(产品决策 2026-08-19,guide docs/contracts/market-index-v1.md)。
|
|
132
132
|
if (BANNED_MARKET_SECTIONS.includes(sectionId)) {
|
|
133
133
|
return { status: 'invalid', errors: [marketMsg('market.security.bannedSection', { section: sectionId })], warnings, manifest, internalManifest, sections: [], checksumsOk: true };
|
|
134
134
|
}
|
package/src/market/star-cache.ts
CHANGED
|
@@ -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/src/market/types.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type MarketPublishMode = 'migrate' | 'share';
|
|
|
31
31
|
export const MAX_MARKET_ZIP_BYTES = 64 * 1024 * 1024;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/
|
|
34
|
+
* 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/contracts/market-index-v1.md):
|
|
35
35
|
* - sessions:历史会话,含个人交互记录/上下文;
|
|
36
36
|
* - pluginFiles:任意文件直通(目录放啥带啥),无内容过滤,最易泄漏 token/密钥文件;
|
|
37
37
|
* - self:本地环境专属(sync 通道 URL / WebDAV 地址 / 市场配置 / UI 偏好),无分享价值且泄漏环境信息。
|
package/src/market/url.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* m-market:validateMarketRepoUrl 单测(docs/
|
|
2
|
+
* m-market:validateMarketRepoUrl 单测(docs/archive/2026-08-19-market-publish-design.md §3.1)。
|
|
3
3
|
* 覆盖:合法 https 通过;git@/ssh/scp 形态拒绝;userinfo / 空白 / 空串拒绝。
|
|
4
4
|
*/
|
|
5
5
|
import { test } from 'node:test'
|
package/src/market/url.ts
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 强制。
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* tech-debt #5 回归:**复制失败后的回滚也失败时,残留目录必须仍然可被发现、可被删除**。
|
|
3
3
|
*
|
|
4
|
-
* 现场(docs/
|
|
4
|
+
* 现场(docs/known-issues/tech-debt.md:20 的窄缝):copy() 的 catch 里是一把 `rm(recursive)` 加一句注释。
|
|
5
5
|
* 若那次 rm 先删掉了标记(`.dcm-copy-in-progress.json`)再失败 —— 例如某个只读子目录让它中途放弃,
|
|
6
6
|
* 或 rm 自身部分生效 —— 残留目录就退回「没有 package.json、也没有标记」的形态:
|
|
7
7
|
* - listIncompleteCopies() / listIncompleteCopiesScan() 扫不到(渲染面板里看不见);
|
|
@@ -349,6 +349,26 @@ test('remove:物理删除目录;当前 profile 需显式确认', () => {
|
|
|
349
349
|
}
|
|
350
350
|
})
|
|
351
351
|
|
|
352
|
+
test('remove:含悬空 junction 的档案也能删净(fs.rm 静默失效的回归)', () => {
|
|
353
|
+
const { mgr, home, cleanup } = makeManager()
|
|
354
|
+
try {
|
|
355
|
+
mgr.create('work', 'base')
|
|
356
|
+
const dir = join(home, 'profiles', 'work')
|
|
357
|
+
mkdirSync(join(dir, 'node_modules'), { recursive: true })
|
|
358
|
+
// DSH 的真实形态:node_modules/<pkg> → 已消失的 .dsh-module-fallback/node_modules/<pkg>
|
|
359
|
+
symlinkSync(
|
|
360
|
+
join(dir, '.dsh-module-fallback', 'node_modules', 'immer'),
|
|
361
|
+
join(dir, 'node_modules', 'immer'),
|
|
362
|
+
process.platform === 'win32' ? 'junction' : 'dir',
|
|
363
|
+
)
|
|
364
|
+
mgr.remove('work')
|
|
365
|
+
// 曾经:fs.rmSync 遇到悬空链接「不抛错也不删」,路由回 200 + 台账 success,档案留在磁盘上
|
|
366
|
+
assert.equal(existsSync(dir), false, '悬空 junction 不得让删除静默失败')
|
|
367
|
+
} finally {
|
|
368
|
+
cleanup()
|
|
369
|
+
}
|
|
370
|
+
})
|
|
371
|
+
|
|
352
372
|
test('desktop 保留档案:删除与改名一律拒绝(managedProfile),只读操作照常', async () => {
|
|
353
373
|
const { mgr, home, cleanup } = makeManager()
|
|
354
374
|
try {
|
|
@@ -18,14 +18,17 @@
|
|
|
18
18
|
* 历史上这里还有一个 `<dataDir>/next-profile`「下次启动」标记——DSH 根本没有消费者,
|
|
19
19
|
* 只会误导用户(2026-09 按产品决策整体移除,连同前端按钮)。
|
|
20
20
|
*
|
|
21
|
-
* 物理删除:remove() 走 rmSync(recursive)
|
|
22
|
-
*
|
|
21
|
+
* 物理删除:remove() 走 utils/remove-tree 的 removeTreeSync —— 不能用 fs.rmSync(recursive):
|
|
22
|
+
* 目录里只要有一个**悬空链接**(DSH 的 node_modules/<pkg> → 已消失的 .dsh-module-fallback),
|
|
23
|
+
* rmSync 会不报错也不删任何东西(实测),于是「删除成功」而档案原样留在磁盘上。
|
|
24
|
+
* profile 目录内的 junction(pnpm 链接)只删链接本身,不会跟随进 pnpm store。
|
|
23
25
|
*/
|
|
24
26
|
import { existsSync, mkdirSync, readdirSync, renameSync, rmSync, statSync, type Dirent } from 'node:fs'
|
|
25
27
|
// 复制走 async fs(整档案上万个文件,cpSync 会把宿主事件循环卡住二十多秒)
|
|
26
|
-
import { copyFile, cp, mkdir, readdir, readlink,
|
|
28
|
+
import { copyFile, cp, mkdir, readdir, readlink, stat, symlink, unlink } from 'node:fs/promises'
|
|
27
29
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
28
30
|
import { atomicWriteFileSync } from '../utils/atomic-write.ts'
|
|
31
|
+
import { removeTree, removeTreeSync } from '../utils/remove-tree.ts'
|
|
29
32
|
import { isRecord } from '../utils/guards.ts'
|
|
30
33
|
import { resolveProfileDir, validateProfileName } from '../core/plugin-cli.ts'
|
|
31
34
|
import { readTextSafe } from './dsh-profile-io.ts'
|
|
@@ -103,9 +106,15 @@ export interface DshProfileIncompleteCopiesScan {
|
|
|
103
106
|
/** t89:profiles 根目录枚举失败的原因码(诊断/日志用)。 */
|
|
104
107
|
export const PROFILES_ROOT_UNREADABLE = 'profiles-root-unreadable'
|
|
105
108
|
|
|
106
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* 回滚复制目标目录的缺省删除实现(不存在不算错)。
|
|
111
|
+
*
|
|
112
|
+
* 必须走 removeTree 而不是 fs.rm(recursive):半截副本里可能已经有指向
|
|
113
|
+
* `.dsh-module-fallback` 的悬空 junction,fs.rm 会「成功」却一个字节都不删,
|
|
114
|
+
* 回滚于是无声失败。
|
|
115
|
+
*/
|
|
107
116
|
const defaultProfileRemove = async (target: string): Promise<void> => {
|
|
108
|
-
await
|
|
117
|
+
await removeTree(target)
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
/**
|
|
@@ -413,7 +422,7 @@ export class DshProfileManager {
|
|
|
413
422
|
}
|
|
414
423
|
|
|
415
424
|
/**
|
|
416
|
-
* 物理删除 profile 目录(
|
|
425
|
+
* 物理删除 profile 目录(removeTreeSync;目录内 junction 只删链接本身,删不干净报 deleteFailed)。
|
|
417
426
|
* 当前运行中的 profile 需要 allowCurrent=true 显式确认(删除会让重启后的实例直接失败)。
|
|
418
427
|
*
|
|
419
428
|
* Desktop 独占档案(desktop)**一律拒绝**(连 allowCurrent 也不行):它由桌面端应用自己
|
|
@@ -428,7 +437,16 @@ export class DshProfileManager {
|
|
|
428
437
|
if (name === this.currentProfile() && opts.allowCurrent !== true) {
|
|
429
438
|
throw new DshProfileError('currentProfile')
|
|
430
439
|
}
|
|
431
|
-
rmSync(
|
|
440
|
+
// 不用 rmSync(recursive):悬空 junction 会让它静默空转(见 utils/remove-tree.ts 头注)。
|
|
441
|
+
// 删不掉必须变成可见错误码,绝不回 200 —— 那正是「点了删除、档案还在」的成因。
|
|
442
|
+
try {
|
|
443
|
+
removeTreeSync(dir)
|
|
444
|
+
} catch (error) {
|
|
445
|
+
throw new DshProfileError('deleteFailed', error instanceof Error ? error.message : String(error))
|
|
446
|
+
}
|
|
447
|
+
if (existsSync(dir)) {
|
|
448
|
+
throw new DshProfileError('deleteFailed', `profile directory still exists after removal: ${dir}`)
|
|
449
|
+
}
|
|
432
450
|
}
|
|
433
451
|
|
|
434
452
|
/**
|
|
@@ -275,6 +275,8 @@ export type DshProfileErrorCode =
|
|
|
275
275
|
| 'copyFailed'
|
|
276
276
|
/** 该档案由 Desktop 应用独占管理(启动 / 删除 / 改名一律拒绝,操作它会让桌面端起不来) */
|
|
277
277
|
| 'managedProfile'
|
|
278
|
+
/** 目录删不干净(被占用 / 权限不足;message 里附底层原因)—— 绝不是「删成功」 */
|
|
279
|
+
| 'deleteFailed'
|
|
278
280
|
|
|
279
281
|
/** 复制档案的非致命告警码(UI 按码映射文案,绝不静默)。 */
|
|
280
282
|
export type DshProfileCopyWarning =
|
package/src/routes/backup.ts
CHANGED
|
@@ -37,13 +37,18 @@ import { join as joinPath } from 'node:path'
|
|
|
37
37
|
* 各写一份目录名而漂移。
|
|
38
38
|
*/
|
|
39
39
|
function diskUsageDirsOf(env: RoutesEnv): DiskUsageDirs {
|
|
40
|
-
const { dataDir,
|
|
40
|
+
const { dataDir, marketDir, tmpDir, snapshotsDir, exportsDir } = env
|
|
41
|
+
// `syncRootDir` 缺省回落本档案作用域目录:只有 syncDir 的装配面(未类型化夹具 / 手工装配)
|
|
42
|
+
// 就是历史单作用域布局,此时 syncDir === syncRootDir(见 syncScopeOrDefault)。
|
|
43
|
+
const syncRootDir = env.syncRootDir ?? env.syncDir
|
|
41
44
|
return {
|
|
42
45
|
dataDir,
|
|
43
46
|
exportsDir,
|
|
44
47
|
snapshotsDir,
|
|
45
|
-
// 同步历史/快照/工作副本都在 <dataDir>/sync 下(Git 通道另有 .git
|
|
46
|
-
|
|
48
|
+
// 同步历史/快照/工作副本都在 <dataDir>/sync 下(Git 通道另有 .git 工作副本,一并计入)。
|
|
49
|
+
// 用 syncRootDir 而不是本档案的 syncDir:体检要看**整棵** sync/(含 sync-profiles/<p>/),
|
|
50
|
+
// 否则切到别的档具体检会把其它档案的同步数据当成不存在。
|
|
51
|
+
syncDir: syncRootDir,
|
|
47
52
|
marketCacheDir: joinPath(marketDir, 'cache'),
|
|
48
53
|
marketWorkDir: joinPath(marketDir, 'work'),
|
|
49
54
|
tmpDir,
|
|
@@ -58,7 +63,8 @@ function diskUsageDirsOf(env: RoutesEnv): DiskUsageDirs {
|
|
|
58
63
|
|
|
59
64
|
/** 体检/清理共用的保留期口径(与 cache-cleaner 缺省逐字一致;定时备份前缀豁免同源) */
|
|
60
65
|
async function diskUsagePolicyOf(env: RoutesEnv): Promise<{ policy: DiskUsagePolicyInput; retention: RetentionPolicy }> {
|
|
61
|
-
|
|
66
|
+
// 定时备份配置全机一份(sync/backup-schedule.json):排期与保留策略不属于任何单个档案。
|
|
67
|
+
const schedule = await readBackupSchedule(env.syncRootDir ?? env.syncDir)
|
|
62
68
|
return {
|
|
63
69
|
policy: {
|
|
64
70
|
tmpRetentionMs: TMP_RETENTION_DEFAULT_MS,
|
|
@@ -154,9 +160,10 @@ export function backupRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
154
160
|
const {
|
|
155
161
|
backupScheduler,
|
|
156
162
|
exportsDir,
|
|
157
|
-
syncDir,
|
|
158
163
|
withMutationGate,
|
|
159
164
|
} = env
|
|
165
|
+
// 定时备份**全机一份**(不是某个档案的同步态):读写都落 syncRootDir,缺省回落 syncDir(同上)。
|
|
166
|
+
const syncRootDir = env.syncRootDir ?? env.syncDir
|
|
160
167
|
return [
|
|
161
168
|
// ------------------------------------------------------- disk-usage(只读体检)
|
|
162
169
|
// 界面「磁盘占用」卡的数据源:按子区回传字节数/文件数 + 各保留期的「已到期」量。
|
|
@@ -209,7 +216,7 @@ export function backupRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
209
216
|
endpoint({ path: '/api/dsh-config-manager/backup-schedule', methods: ['GET', 'PUT'] }, async (req, res) => {
|
|
210
217
|
if (req.method === 'GET') {
|
|
211
218
|
try {
|
|
212
|
-
writeJson(res, 200, { schedule: await readBackupSchedule(
|
|
219
|
+
writeJson(res, 200, { schedule: await readBackupSchedule(syncRootDir) })
|
|
213
220
|
} catch (error) {
|
|
214
221
|
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) })
|
|
215
222
|
}
|
|
@@ -223,11 +230,11 @@ export function backupRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
223
230
|
writeJson(res, 400, { error: parsed.error })
|
|
224
231
|
return
|
|
225
232
|
}
|
|
226
|
-
const current = await readBackupSchedule(
|
|
233
|
+
const current = await readBackupSchedule(syncRootDir)
|
|
227
234
|
const next: BackupScheduleConfig = { ...current, ...parsed.value }
|
|
228
235
|
// m-retention:保留策略保存(草稿给了就用草稿值,否则保留既有;缺省由读取层补齐)
|
|
229
236
|
next.retention = parsed.value.retention ?? current.retention ?? { ...DEFAULT_RETENTION_POLICY }
|
|
230
|
-
await writeBackupSchedule(
|
|
237
|
+
await writeBackupSchedule(syncRootDir, next)
|
|
231
238
|
await backupScheduler.reload()
|
|
232
239
|
writeJson(res, 200, { ok: true, schedule: next })
|
|
233
240
|
} catch (error) {
|
|
@@ -246,7 +253,7 @@ export function backupRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
246
253
|
endpoint({ path: '/api/dsh-config-manager/backup-schedule/run', methods: ['POST'] }, async (req, res) => {
|
|
247
254
|
try {
|
|
248
255
|
const run = await backupScheduler.runOnce({ manual: true })
|
|
249
|
-
const schedule = await readBackupSchedule(
|
|
256
|
+
const schedule = await readBackupSchedule(syncRootDir)
|
|
250
257
|
writeJson(res, 200, { ok: true, run, schedule })
|
|
251
258
|
} catch (error) {
|
|
252
259
|
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) })
|
package/src/routes/index.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/src/routes/kit.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/src/routes/market.ts
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
7
|
|
|
8
|
-
import { endpoint,
|
|
8
|
+
import { endpoint, readJsonBody, writeJson } from './kit.ts'
|
|
9
9
|
import type { WebRoute } from './kit.ts'
|
|
10
10
|
import type { RoutesEnv } from './context.ts'
|
|
11
|
-
import { isControlledPath } from './route-support.ts'
|
|
12
11
|
import { BUILTIN_MARKET_URL } from '../market/builtin.ts'
|
|
13
12
|
import { parseMarketIndex, parseMarketItemManifest } from '../market/index-parser.ts'
|
|
14
|
-
import { prepareMarketItem } from '../market/prepare.ts'
|
|
15
13
|
import { validateMarketItem } from '../market/security.ts'
|
|
16
14
|
import type { MarketDownloadResult, MarketIndex, MarketItemDetail, MarketListItem } from '../market/types.ts'
|
|
17
15
|
import { validateMarketRepoUrl } from '../market/url.ts'
|
|
18
16
|
import { marketItemWarnings, toMarketListItem } from '../market/view.ts'
|
|
19
17
|
import type { SectionId } from '../schema/types.ts'
|
|
20
|
-
import { zipToBuffer } from '../utils/zip.ts'
|
|
21
18
|
import { randomBytes } from 'node:crypto'
|
|
22
19
|
import fs from 'node:fs/promises'
|
|
23
20
|
import { dirname, join } from 'node:path'
|
|
@@ -36,7 +33,6 @@ export function marketRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
36
33
|
msg,
|
|
37
34
|
pruneStagedMarketZips,
|
|
38
35
|
readCachedIndexObj,
|
|
39
|
-
roots,
|
|
40
36
|
tmpDir,
|
|
41
37
|
writeItemCache,
|
|
42
38
|
} = env
|
|
@@ -217,58 +213,5 @@ export function marketRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
217
213
|
writeJson(res, 400, { error: error instanceof Error ? error.message : String(error) })
|
|
218
214
|
}
|
|
219
215
|
}),
|
|
220
|
-
// ---------------------------------------------------- market/prepare
|
|
221
|
-
// 发布向导:由「用户上传的配置 zip + 用户填写元数据」生成市场条目包
|
|
222
|
-
// (L2 manifest + config.zip SHA-256 + sections),供 UI 展示/复制与引导推送。
|
|
223
|
-
// 零写入配置:只在受控临时区生成发布目录;插件不做任何 git 写操作、不持有凭据。
|
|
224
|
-
endpoint({ path: '/api/dsh-config-manager/market/prepare', methods: ['POST'] }, async (req, res) => {
|
|
225
|
-
const body = await requireJsonObject(req)
|
|
226
|
-
const zipPath = typeof body?.['zipPath'] === 'string' ? body['zipPath'] : ''
|
|
227
|
-
if (zipPath === '' || !isControlledPath(zipPath, roots)) {
|
|
228
|
-
writeJson(res, 400, { error: 'zipPath is required and must reference a staged upload' })
|
|
229
|
-
return
|
|
230
|
-
}
|
|
231
|
-
const itemId = typeof body?.['itemId'] === 'string' ? body['itemId'] : ''
|
|
232
|
-
const name = typeof body?.['name'] === 'string' ? body['name'] : ''
|
|
233
|
-
const version = typeof body?.['version'] === 'string' ? body['version'] : undefined
|
|
234
|
-
const description = typeof body?.['description'] === 'string' ? body['description'] : undefined
|
|
235
|
-
const author = typeof body?.['author'] === 'string' ? body['author'] : undefined
|
|
236
|
-
const repoUrl = typeof body?.['repoUrl'] === 'string' && body['repoUrl'] !== '' ? body['repoUrl'] : undefined
|
|
237
|
-
const categoriesRaw = body?.['categories']
|
|
238
|
-
const categories = Array.isArray(categoriesRaw)
|
|
239
|
-
? categoriesRaw.filter((c): c is string => typeof c === 'string')
|
|
240
|
-
: undefined
|
|
241
|
-
// F6 分享模式:share 强制排除 deviceSpecific/platformSpecific 分区 + 保守档内容扫描拦截
|
|
242
|
-
// (prepare.ts 内实现);migrate 缺省。非法值一律回退 migrate。
|
|
243
|
-
const mode = body?.['mode'] === 'share' ? 'share' : 'migrate'
|
|
244
|
-
try {
|
|
245
|
-
const zipBytes = await fs.readFile(zipPath)
|
|
246
|
-
const result = prepareMarketItem({ itemId, name, version, description, author, repoUrl, categories, zipBytes, mode })
|
|
247
|
-
// 发布目录落到受控临时区(供 UI 展示目录结构;不写任何配置)
|
|
248
|
-
const dir = join(tmpDir, `publish-${itemId}-${randomBytes(6).toString('hex')}`)
|
|
249
|
-
const itemDir = join(dir, 'items', itemId)
|
|
250
|
-
await fs.mkdir(itemDir, { recursive: true })
|
|
251
|
-
await fs.writeFile(join(itemDir, 'manifest.json'), result.manifestText, 'utf8')
|
|
252
|
-
await fs.writeFile(join(itemDir, 'config.zip'), zipBytes)
|
|
253
|
-
// 打包发布目录为 zip(供 /download 端点下载;zip 由懒 GC 清理),
|
|
254
|
-
// 打包后删除中间目录,避免 publish-* 目录在 tmpDir 无限累积
|
|
255
|
-
const publishZip = join(tmpDir, `publish-${itemId}-${randomBytes(6).toString('hex')}.zip`)
|
|
256
|
-
await fs.writeFile(publishZip, Buffer.from(zipToBuffer([
|
|
257
|
-
{ name: `items/${itemId}/manifest.json`, data: Buffer.from(result.manifestText, 'utf8') },
|
|
258
|
-
{ name: `items/${itemId}/config.zip`, data: Buffer.from(zipBytes) },
|
|
259
|
-
])))
|
|
260
|
-
await fs.rm(dir, { force: true, recursive: true }).catch(() => undefined)
|
|
261
|
-
writeJson(res, 200, {
|
|
262
|
-
ok: true,
|
|
263
|
-
zipPath: publishZip,
|
|
264
|
-
manifestText: result.manifestText,
|
|
265
|
-
sha256: result.sha256,
|
|
266
|
-
sections: result.sections,
|
|
267
|
-
warnings: result.warnings,
|
|
268
|
-
})
|
|
269
|
-
} catch (error) {
|
|
270
|
-
writeJson(res, 400, { error: error instanceof Error ? error.message : String(error) })
|
|
271
|
-
}
|
|
272
|
-
}),
|
|
273
216
|
]
|
|
274
217
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
|
|
21
|
+
export interface AgentToolDepsInput {
|
|
22
|
+
host: HostContext
|
|
23
|
+
adapters: ConfigAdapter[]
|
|
24
|
+
exportsDir: string
|
|
25
|
+
snapshotsDir: string
|
|
26
|
+
syncDir: string
|
|
27
|
+
makeSyncEngine: (cfg: SyncConfig, opts?: { optInSections?: readonly SectionId[] }) => SyncEngine
|
|
28
|
+
/** 宿主侧按 DSH credentials 槽位读取(值只在内存里过一手)。 */
|
|
29
|
+
resolveSyncPassword: (ref: string) => Promise<string | undefined>
|
|
30
|
+
/** 槽位引用构造(ENCRYPT / DECRYPT + 通道),与 /sync/apply-items 同源。 */
|
|
31
|
+
syncPasswordRef: (kind: 'ENCRYPT' | 'DECRYPT', channel: SyncTransportType) => string
|
|
32
|
+
/** onlyAuto = true 时只放行「自动档」可选分区(agent 侧恒 true)。 */
|
|
33
|
+
selectionOptInSections: (channel: SyncTransportType, onlyAuto?: boolean) => SectionId[]
|
|
34
|
+
makeImporter: () => Importer
|
|
35
|
+
roots: readonly string[]
|
|
36
|
+
scanner?: SecretScanner
|
|
37
|
+
exporterVersion?: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 组装 9 个模型工具所需的依赖;纯映射,无副作用、不读盘、不触网。 */
|
|
41
|
+
export function createAgentToolDeps(input: AgentToolDepsInput): ModelToolsDeps {
|
|
42
|
+
return {
|
|
43
|
+
host: input.host,
|
|
44
|
+
adapters: input.adapters,
|
|
45
|
+
exportsDir: input.exportsDir,
|
|
46
|
+
snapshotsDir: input.snapshotsDir,
|
|
47
|
+
syncDir: input.syncDir,
|
|
48
|
+
makeSyncEngine: input.makeSyncEngine,
|
|
49
|
+
...(input.exporterVersion === undefined ? {} : { exporterVersion: input.exporterVersion }),
|
|
50
|
+
...(input.scanner === undefined ? {} : { scanner: input.scanner }),
|
|
51
|
+
syncPassword: async (kind, channel) => await input.resolveSyncPassword(input.syncPasswordRef(kind, channel)),
|
|
52
|
+
optInSections: (channel) => input.selectionOptInSections(channel, true),
|
|
53
|
+
makeImporter: input.makeImporter,
|
|
54
|
+
roots: input.roots,
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/routes/recovery.ts
CHANGED
|
@@ -726,9 +726,11 @@ export function recoveryRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
726
726
|
log: (line) => host.log.warn(line),
|
|
727
727
|
...(forkSeam !== undefined ? { fork: forkSeam } : {}),
|
|
728
728
|
})
|
|
729
|
-
// 插件偏好文件与 /sync/ui-prefs
|
|
730
|
-
//
|
|
731
|
-
|
|
729
|
+
// 插件偏好文件与 /sync/ui-prefs 同一份,回滚点开关存在那里,绝不另立第二个偏好文件。
|
|
730
|
+
// 目录**按档案**(默认档案 = dataDir/sync,其它 = dataDir/sync-profiles/<profile>):
|
|
731
|
+
// 这里直接取 env.syncDir —— 不能再自己 join(dataDir,'sync'),否则非默认档案的
|
|
732
|
+
// 开关在这里读历史根、在 /sync 里读自己的作用域,两处对不上。
|
|
733
|
+
const syncDir = env.syncDir
|
|
732
734
|
const sub = segments.slice(1)
|
|
733
735
|
const methodNotAllowed = (): void => { writeJson(res, 405, { error: 'method not allowed', code: 'method-not-allowed' }) }
|
|
734
736
|
const reply = (value: { ok?: boolean; code?: string; outcome?: string }): void => {
|
|
@@ -46,36 +46,23 @@ import { isSameOrChild } from '../utils/paths.ts'
|
|
|
46
46
|
import { parseZip } from '../utils/zip.ts'
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
49
|
+
* 同步凭据槽位名与 per-profile 作用域:**唯一声明处已迁到 `src/sync/sync-scope.ts`**
|
|
50
|
+
* (那里也持有 `syncScopeFor` / `adoptLegacySyncScope`)。此文件只 re-export,
|
|
51
|
+
* 保持 `src/index.ts` 与测试既有的 import 面与符号名不变(值不变,只是多了可选档案后缀)。
|
|
52
52
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* 但**绝不允许**写进 sync-selection.json 一类同步文件(那等于把密码推上远端)。
|
|
67
|
-
* 与本插件既有的 token / WebDAV 口令同一套做法:值只存在于 DSH 凭据库,
|
|
68
|
-
* 宿主内部按需 resolve,**永不回传浏览器**(UI 只拿到 configured 布尔)。
|
|
69
|
-
* 引用名形如 DSH_CONFIG_MANAGER_SYNC_ENCRYPT_PASSWORD_GIT。
|
|
70
|
-
*/
|
|
71
|
-
export const SYNC_ENCRYPT_PASSWORD_REF_PREFIX = 'DSH_CONFIG_MANAGER_SYNC_ENCRYPT_PASSWORD'
|
|
72
|
-
export const SYNC_DECRYPT_PASSWORD_REF_PREFIX = 'DSH_CONFIG_MANAGER_SYNC_DECRYPT_PASSWORD'
|
|
73
|
-
|
|
74
|
-
/** ('ENCRYPT'|'DECRYPT', 'git'|'webdav') → 该通道的凭据引用名。 */
|
|
75
|
-
export function syncPasswordRef(kind: 'ENCRYPT' | 'DECRYPT', channel: SyncTransportType): string {
|
|
76
|
-
const prefix = kind === 'ENCRYPT' ? SYNC_ENCRYPT_PASSWORD_REF_PREFIX : SYNC_DECRYPT_PASSWORD_REF_PREFIX
|
|
77
|
-
return prefix + '_' + channel.toUpperCase()
|
|
78
|
-
}
|
|
53
|
+
import {
|
|
54
|
+
SYNC_CREDENTIAL_REF,
|
|
55
|
+
SYNC_WEBDAV_CREDENTIAL_REF,
|
|
56
|
+
} from '../sync/sync-scope.ts'
|
|
57
|
+
export {
|
|
58
|
+
SYNC_CREDENTIAL_REF,
|
|
59
|
+
SYNC_DECRYPT_PASSWORD_REF_PREFIX,
|
|
60
|
+
SYNC_ENCRYPT_PASSWORD_REF_PREFIX,
|
|
61
|
+
SYNC_WEBDAV_CREDENTIAL_REF,
|
|
62
|
+
scopedSyncRef,
|
|
63
|
+
syncPasswordRef,
|
|
64
|
+
syncScopeOrDefault,
|
|
65
|
+
} from '../sync/sync-scope.ts'
|
|
79
66
|
|
|
80
67
|
/* 路由基础设施(loopback 围栏 / writeJson / readJsonBody / queryParam / endpoint / 错误映射)
|
|
81
68
|
* 已收敛到 src/routes/kit.ts —— 全仓只有那一份实现。 */
|
|
@@ -744,9 +731,26 @@ export function makeRestoreExecutor(snapshotDir: string, host: HostContext, prof
|
|
|
744
731
|
* 下沉后 `src/index.sync.test.ts` 仍经组合根的再导出取用(符号名不变)。
|
|
745
732
|
*/
|
|
746
733
|
|
|
747
|
-
/**
|
|
734
|
+
/**
|
|
735
|
+
* parseSyncBody 的凭据写入依赖(只用到 set;测试可注入内存 mock)。
|
|
736
|
+
*/
|
|
748
737
|
export interface ParseSyncBodyDeps {
|
|
749
738
|
credentials: Pick<CredentialProvider, 'set'>
|
|
739
|
+
/**
|
|
740
|
+
* per-profile 作用域:只决定**写哪个凭据槽位**,不影响请求体形状与返回值。
|
|
741
|
+
* 缺省 = 历史(不带后缀)槽位名 —— 单档案用户与既有测试的行为逐字不变。
|
|
742
|
+
*/
|
|
743
|
+
scope?: SyncRefScope
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/** 把历史槽位名映射到当前档案的最小接口(`SyncScope` 结构上即满足)。 */
|
|
747
|
+
export interface SyncRefScope {
|
|
748
|
+
/** 本档案的 git / GitHub token 槽位 */
|
|
749
|
+
tokenRef: string
|
|
750
|
+
/** 本档案的 WebDAV 口令槽位 */
|
|
751
|
+
webdavPasswordRef: string
|
|
752
|
+
/** 历史槽位名 → 本档案槽位名(云端点密钥等按需映射) */
|
|
753
|
+
scopeRef(ref: string): string
|
|
750
754
|
}
|
|
751
755
|
|
|
752
756
|
/**
|
|
@@ -761,6 +765,10 @@ export async function parseSyncBody(
|
|
|
761
765
|
body: Record<string, unknown>,
|
|
762
766
|
deps: ParseSyncBodyDeps,
|
|
763
767
|
): Promise<SyncConfig> {
|
|
768
|
+
// per-profile 槽位(缺省 = 历史槽位名;请求体形状与返回值与档案无关)
|
|
769
|
+
const scope = deps.scope
|
|
770
|
+
const tokenRef = scope === undefined ? SYNC_CREDENTIAL_REF : scope.tokenRef
|
|
771
|
+
const webdavPasswordRef = scope === undefined ? SYNC_WEBDAV_CREDENTIAL_REF : scope.webdavPasswordRef
|
|
764
772
|
const rawTransport = body['transport']
|
|
765
773
|
// 通道值解析:接受通道名(s3/gist);也接受**具体兼容商**(oss/cos/minio/kodo)直接落到 s3 通道
|
|
766
774
|
const transport = parseSyncChannel(rawTransport) ?? (isS3CompatProvider(rawTransport) ? 's3' : 'git')
|
|
@@ -775,11 +783,11 @@ export async function parseSyncBody(
|
|
|
775
783
|
const password = typeof body['password'] === 'string' && body['password'] !== '' ? body['password'] : undefined
|
|
776
784
|
if (password !== undefined) {
|
|
777
785
|
try {
|
|
778
|
-
await deps.credentials.set(credentialRef(
|
|
786
|
+
await deps.credentials.set(credentialRef(webdavPasswordRef), password)
|
|
779
787
|
} catch (error) {
|
|
780
788
|
const reason = error instanceof Error ? error.message : String(error)
|
|
781
789
|
throw new SyncRouteError(
|
|
782
|
-
engineMsg('host.syncWebdavPasswordWriteFailed', { reason, ref:
|
|
790
|
+
engineMsg('host.syncWebdavPasswordWriteFailed', { reason, ref: webdavPasswordRef }),
|
|
783
791
|
)
|
|
784
792
|
}
|
|
785
793
|
}
|
|
@@ -797,11 +805,11 @@ export async function parseSyncBody(
|
|
|
797
805
|
const token = typeof body['token'] === 'string' && body['token'] !== '' ? body['token'] : undefined
|
|
798
806
|
if (token !== undefined) {
|
|
799
807
|
try {
|
|
800
|
-
await deps.credentials.set(credentialRef(
|
|
808
|
+
await deps.credentials.set(credentialRef(tokenRef), token)
|
|
801
809
|
} catch (error) {
|
|
802
810
|
const reason = error instanceof Error ? error.message : String(error)
|
|
803
811
|
throw new SyncRouteError(
|
|
804
|
-
engineMsg('host.syncTokenWriteFailed', { reason, ref:
|
|
812
|
+
engineMsg('host.syncTokenWriteFailed', { reason, ref: tokenRef }),
|
|
805
813
|
)
|
|
806
814
|
}
|
|
807
815
|
}
|
|
@@ -817,6 +825,11 @@ function syncStr(value: unknown): string {
|
|
|
817
825
|
return typeof value === 'string' ? value.trim() : ''
|
|
818
826
|
}
|
|
819
827
|
|
|
828
|
+
/** 云端点密钥槽位按档案映射(无 scope = 历史槽位名,单档案行为逐字不变)。 */
|
|
829
|
+
function scopedCloudSecretRef(ref: string, deps: ParseSyncBodyDeps): string {
|
|
830
|
+
return deps.scope === undefined ? ref : deps.scope.scopeRef(ref)
|
|
831
|
+
}
|
|
832
|
+
|
|
820
833
|
/** 云端点密钥写入失败 → 可操作错误(**含 ref 名、绝不含密钥值**)。 */
|
|
821
834
|
function cloudCredentialWriteError(ref: string, kind: string, error: unknown): SyncRouteError {
|
|
822
835
|
const reason = error instanceof Error ? error.message : String(error)
|
|
@@ -862,7 +875,7 @@ async function parseCloudS3Body(
|
|
|
862
875
|
if (issue !== null) throw new SyncRouteError(issue, 400, issue)
|
|
863
876
|
const secret = typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined
|
|
864
877
|
if (secret !== undefined) {
|
|
865
|
-
const ref = cloudSecretRef(provider)
|
|
878
|
+
const ref = scopedCloudSecretRef(cloudSecretRef(provider), deps)
|
|
866
879
|
try {
|
|
867
880
|
await deps.credentials.set(credentialRef(ref), secret)
|
|
868
881
|
} catch (error) {
|
|
@@ -903,7 +916,7 @@ async function parseCloudGistBody(body: Record<string, unknown>, deps: ParseSync
|
|
|
903
916
|
? body['token']
|
|
904
917
|
: (typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined)
|
|
905
918
|
if (token !== undefined) {
|
|
906
|
-
const ref = cloudSecretRef(GIST_PROVIDER)
|
|
919
|
+
const ref = scopedCloudSecretRef(cloudSecretRef(GIST_PROVIDER), deps)
|
|
907
920
|
try {
|
|
908
921
|
await deps.credentials.set(credentialRef(ref), token)
|
|
909
922
|
} catch (error) {
|