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
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() 扫不到(渲染面板里看不见);
|
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) {
|
package/src/routes/snapshots.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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 在注册点统一提供。
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
import { endpoint, readJsonBody, writeJson, writeMutationError } from './kit.ts'
|
|
9
9
|
import type { WebRoute } from './kit.ts'
|
|
10
10
|
import type { RoutesEnv } from './context.ts'
|
|
11
|
-
import { deleteSnapshot, isValidSnapshotId, listSnapshots, planRestore
|
|
11
|
+
import { deleteSnapshot, isValidSnapshotId, listSnapshots, planRestore } from '../core/restore.ts'
|
|
12
|
+
// 预览-执行一致性指纹:与 agent 工具(config_restore)共用同一实现,口径分叉会让防呆失效。
|
|
13
|
+
import { restorePlanFingerprint } from '../core/restore-plan-fingerprint.ts'
|
|
12
14
|
import type { RunState } from '../core/run-registry.ts'
|
|
13
15
|
import { snapshotFileDiff, summarizeRestoreChanges } from '../core/snapshot-diff.ts'
|
|
14
16
|
import { buildFileDiffBody, buildRestoreBody, executeRestorePlan, makeRestoreExecutor } from './route-support.ts'
|
|
@@ -16,19 +18,7 @@ import type { RestoreJournalPort } from '../core/restore-wal.ts'
|
|
|
16
18
|
import { probeRestoreResume, runRestoreWithResume } from '../core/restore-resume.ts'
|
|
17
19
|
import type { RestoreResumeHint } from '../core/restore-resume.ts'
|
|
18
20
|
import { runWithMutationLock } from '../utils/env-lock.ts'
|
|
19
|
-
import { isENOENT } from '../utils/guards.ts'
|
|
20
21
|
import { join } from 'node:path'
|
|
21
|
-
import { createHash } from 'node:crypto'
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 恢复计划指纹(预览-执行一致性):只取「动作类型 + 目标 + blob」三列 —— 描述文案、详情、顺序无关的
|
|
25
|
-
* 易变字段一律不进,保证同一份快照 + 同一磁盘状态下指纹稳定。内容变化不会改变指纹(同 kind/target),
|
|
26
|
-
* 只有**动作集合真的变了**(文件出现/消失、插件增删)才会不同 —— 那正是需要用户重新确认的情况。
|
|
27
|
-
*/
|
|
28
|
-
function restorePlanFingerprint(plan: Awaited<ReturnType<typeof planRestore>>): string {
|
|
29
|
-
const lines = plan.actions.map((action) => [action.kind, action.target ?? '', action.blobPath ?? ''].join('\u0000'))
|
|
30
|
-
return createHash('sha256').update(lines.join('\n')).digest('hex')
|
|
31
|
-
}
|
|
32
22
|
|
|
33
23
|
export function snapshotRoutes(env: RoutesEnv): WebRoute[] {
|
|
34
24
|
const {
|
|
@@ -255,32 +245,6 @@ export function snapshotRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
255
245
|
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) })
|
|
256
246
|
}
|
|
257
247
|
})),
|
|
258
|
-
// --------------------------------------------- snapshots/pin(P1-⑧)
|
|
259
|
-
// 置顶/取消置顶快照:置顶快照豁免「最多保留 N 个」的自动清理(只能手动删除)。
|
|
260
|
-
// 纯元数据写(重写 snapshot.json 的 pinned 字段);loopback fence 必备。
|
|
261
|
-
endpoint({ path: '/api/dsh-config-manager/snapshots/pin', methods: ['POST'] }, withMutationGate('snapshot-pin', async (req, res) => {
|
|
262
|
-
try {
|
|
263
|
-
const body = await readJsonBody(req)
|
|
264
|
-
const id = typeof body === 'object' && body !== null
|
|
265
|
-
? (body as Record<string, unknown>)['snapshotId']
|
|
266
|
-
: undefined
|
|
267
|
-
const pinned = (body as Record<string, unknown> | undefined)?.['pinned'] === true
|
|
268
|
-
if (!isValidSnapshotId(id)) {
|
|
269
|
-
writeJson(res, 400, { error: 'snapshotId is required and must be a valid snapshot id' })
|
|
270
|
-
return
|
|
271
|
-
}
|
|
272
|
-
await setSnapshotPinned(snapshotsDir, id, pinned)
|
|
273
|
-
writeJson(res, 200, { ok: true, pinned })
|
|
274
|
-
} catch (error) {
|
|
275
|
-
// e2e-F4:快照不存在时**不得**把 fs 原始错误(含服务端绝对路径)回给浏览器 ——
|
|
276
|
-
// 结构化 404 + 机器可读码,文案由界面按码映射;其余失败也不再回显原始 message。
|
|
277
|
-
if (isENOENT(error)) {
|
|
278
|
-
writeJson(res, 404, { error: 'snapshot not found', code: 'snapshot-not-found' })
|
|
279
|
-
return
|
|
280
|
-
}
|
|
281
|
-
writeJson(res, 500, { error: 'failed to update snapshot pin' })
|
|
282
|
-
}
|
|
283
|
-
})),
|
|
284
248
|
// --------------------------------------- snapshots/file-diff(git 风格预览)
|
|
285
249
|
// 单个文件的逐行差异(只读):before = 当前磁盘文件 / after = 快照 blob。
|
|
286
250
|
// 点开某个文件才请求(列表阶段只做轻量统计),避免会话类快照几百个文件时拖死弹窗。
|