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.
Files changed (286) hide show
  1. package/README.md +10 -0
  2. package/README.zh-CN.md +10 -0
  3. package/lib/adapters/mcp.d.ts +9 -0
  4. package/lib/adapters/mcp.js +37 -0
  5. package/lib/adapters/plugins.js +10 -2
  6. package/lib/adapters/pnpm-workspace.js +1 -1
  7. package/lib/adapters/self.d.ts +2 -0
  8. package/lib/adapters/self.js +18 -2
  9. package/lib/adapters/workspaces.js +1 -1
  10. package/lib/cli/restore-resume.js +1 -1
  11. package/lib/cli/web/page.js +2 -2
  12. package/lib/client.d.ts +17 -41
  13. package/lib/client.js +946 -761
  14. package/lib/core/backup.d.ts +11 -0
  15. package/lib/core/backup.js +27 -0
  16. package/lib/core/env-lock-lifecycle.d.ts +17 -3
  17. package/lib/core/env-lock-lifecycle.js +38 -0
  18. package/lib/core/external-failure.d.ts +9 -0
  19. package/lib/core/external-failure.js +50 -0
  20. package/lib/core/local-plugin-host.d.ts +9 -7
  21. package/lib/core/local-plugin-host.js +109 -15
  22. package/lib/core/local-plugin-pack.d.ts +20 -0
  23. package/lib/core/local-plugin-pack.js +18 -3
  24. package/lib/core/mcp-connector-store.d.ts +13 -0
  25. package/lib/core/mcp-connector-store.js +16 -1
  26. package/lib/core/messages-core.d.ts +45 -0
  27. package/lib/core/messages-core.js +92 -0
  28. package/lib/core/messages.d.ts +5 -0
  29. package/lib/core/messages.js +14 -0
  30. package/lib/core/migration-history.d.ts +40 -0
  31. package/lib/core/migration-history.js +55 -0
  32. package/lib/core/model-tool-plans.d.ts +66 -0
  33. package/lib/core/model-tool-plans.js +128 -0
  34. package/lib/core/model-tools.d.ts +96 -8
  35. package/lib/core/model-tools.js +568 -31
  36. package/lib/core/phase3-host.js +10 -2
  37. package/lib/core/plugin-cli.d.ts +5 -0
  38. package/lib/core/plugin-cli.js +11 -3
  39. package/lib/core/plugin-data-registry.d.ts +1 -1
  40. package/lib/core/plugin-data-registry.js +1 -1
  41. package/lib/core/restore-plan-fingerprint.d.ts +2 -0
  42. package/lib/core/restore-plan-fingerprint.js +18 -0
  43. package/lib/core/restore-resume.d.ts +1 -1
  44. package/lib/core/restore-resume.js +1 -1
  45. package/lib/core/restore.d.ts +5 -0
  46. package/lib/core/restore.js +4 -1
  47. package/lib/core/types.d.ts +12 -0
  48. package/lib/foreign/claude-sessions.d.ts +1 -1
  49. package/lib/foreign/claude-sessions.js +1 -1
  50. package/lib/foreign/registry.js +1 -1
  51. package/lib/foreign/types.d.ts +1 -1
  52. package/lib/index.d.ts +19 -15
  53. package/lib/index.js +72 -80
  54. package/lib/market/git-file-writer.js +1 -1
  55. package/lib/market/github-repos.js +1 -1
  56. package/lib/market/market-config.js +1 -1
  57. package/lib/market/messages-market.js +1 -1
  58. package/lib/market/my-repo.js +1 -1
  59. package/lib/market/prepare.js +1 -1
  60. package/lib/market/reader.js +2 -2
  61. package/lib/market/repo-url.d.ts +1 -1
  62. package/lib/market/security.js +2 -2
  63. package/lib/market/star-cache.d.ts +1 -1
  64. package/lib/market/types.d.ts +1 -1
  65. package/lib/market/types.js +1 -1
  66. package/lib/market/url.js +1 -1
  67. package/lib/profiles/dsh-profile-manager.d.ts +1 -1
  68. package/lib/profiles/dsh-profile-manager.js +26 -7
  69. package/lib/profiles/dsh-profile-shared.d.ts +3 -1
  70. package/lib/routes/backup.js +17 -9
  71. package/lib/routes/index.d.ts +1 -1
  72. package/lib/routes/kit.d.ts +2 -2
  73. package/lib/routes/market.d.ts +1 -1
  74. package/lib/routes/market.js +3 -60
  75. package/lib/routes/model-tools-deps.d.ts +41 -0
  76. package/lib/routes/model-tools-deps.js +18 -0
  77. package/lib/routes/recovery.js +5 -3
  78. package/lib/routes/route-support.d.ts +18 -26
  79. package/lib/routes/route-support.js +19 -32
  80. package/lib/routes/snapshots.d.ts +1 -1
  81. package/lib/routes/snapshots.js +4 -40
  82. package/lib/routes/sync.js +40 -28
  83. package/lib/schema/index.d.ts +2 -2
  84. package/lib/schema/index.js +2 -2
  85. package/lib/schema/section-registry.d.ts +5 -3
  86. package/lib/schema/section-registry.js +7 -3
  87. package/lib/security/secret-scanner.js +1 -1
  88. package/lib/sync/apply-bundle.d.ts +50 -0
  89. package/lib/sync/apply-bundle.js +60 -0
  90. package/lib/sync/autosync-scheduler.d.ts +9 -0
  91. package/lib/sync/autosync-scheduler.js +118 -89
  92. package/lib/sync/backup-scheduler.js +5 -4
  93. package/lib/sync/blob-store.d.ts +2 -2
  94. package/lib/sync/git/git-transport.d.ts +12 -0
  95. package/lib/sync/git/git-transport.js +50 -2
  96. package/lib/sync/merge.d.ts +2 -0
  97. package/lib/sync/merge.js +28 -0
  98. package/lib/sync/messages.d.ts +4 -0
  99. package/lib/sync/messages.js +9 -2
  100. package/lib/sync/s3/s3-transport.d.ts +1 -1
  101. package/lib/sync/s3/s3-transport.js +1 -1
  102. package/lib/sync/sync-engine.d.ts +4 -4
  103. package/lib/sync/sync-engine.js +25 -26
  104. package/lib/sync/sync-scope-boot.d.ts +34 -0
  105. package/lib/sync/sync-scope-boot.js +71 -0
  106. package/lib/sync/sync-scope.d.ts +103 -0
  107. package/lib/sync/sync-scope.js +229 -0
  108. package/lib/sync/sync-selection.d.ts +17 -4
  109. package/lib/sync/sync-selection.js +40 -14
  110. package/lib/sync/transport.d.ts +4 -1
  111. package/lib/sync/transport.js +6 -0
  112. package/lib/sync/webdav/webdav-transport.js +1 -1
  113. package/lib/sync/workspace-merge.d.ts +36 -0
  114. package/lib/sync/workspace-merge.js +152 -0
  115. package/lib/ui/backup-schedule.d.ts +13 -2
  116. package/lib/ui/backup-schedule.js +3 -0
  117. package/lib/ui/snapshots-view.d.ts +16 -0
  118. package/lib/ui/snapshots-view.js +21 -0
  119. package/lib/ui/sync-repository-picker.d.ts +21 -0
  120. package/lib/ui/sync-repository-picker.js +18 -0
  121. package/lib/utils/env-lock.d.ts +96 -0
  122. package/lib/utils/env-lock.js +332 -111
  123. package/lib/utils/messages-utils.d.ts +6 -0
  124. package/lib/utils/messages-utils.js +17 -1
  125. package/lib/utils/patch-yaml.js +1 -1
  126. package/lib/utils/remove-tree.d.ts +7 -0
  127. package/lib/utils/remove-tree.js +265 -0
  128. package/lib/utils/zip.js +1 -1
  129. package/package.json +3 -2
  130. package/src/adapters/mcp.test.ts +28 -0
  131. package/src/adapters/mcp.ts +33 -0
  132. package/src/adapters/plugins.test.ts +49 -0
  133. package/src/adapters/plugins.ts +9 -1
  134. package/src/adapters/pnpm-workspace.ts +1 -1
  135. package/src/adapters/self.test.ts +39 -1
  136. package/src/adapters/self.ts +20 -2
  137. package/src/adapters/workspaces.ts +1 -1
  138. package/src/cli/restore-resume.ts +1 -1
  139. package/src/cli/web/page.ts +2 -2
  140. package/src/client/about/AboutPanel.tsx +1 -1
  141. package/src/client/about/about-view.test.ts +1 -1
  142. package/src/client/about/about-view.ts +1 -1
  143. package/src/client/api.ts +1 -6
  144. package/src/client/chat/chat-entry-view.test.ts +1 -1
  145. package/src/client/chat/chat-slots.ts +1 -1
  146. package/src/client/chat/rollback-diff-tab.ts +1 -1
  147. package/src/client/client-types.ts +1 -1
  148. package/src/client/common/routes.ts +1 -5
  149. package/src/client/config-manager.module.css +21 -1
  150. package/src/client/css-scale-guard.test.ts +1 -1
  151. package/src/client/environment/EnvironmentPanel.tsx +2 -2
  152. package/src/client/home/HomePanel.tsx +3 -0
  153. package/src/client/library/ArtifactRow.tsx +14 -2
  154. package/src/client/library/LibraryPanel.tsx +44 -0
  155. package/src/client/locales/overview.ts +10 -2
  156. package/src/client/locales/profiles.ts +2 -0
  157. package/src/client/locales/sessions.ts +3 -0
  158. package/src/client/market/MyConfigsView.tsx +1 -1
  159. package/src/client/market/market-api.ts +2 -14
  160. package/src/client/market/market-locales.ts +1 -1
  161. package/src/client/market/market-view.ts +3 -3
  162. package/src/client/market/my-configs-api.ts +1 -1
  163. package/src/client/market/my-configs-view.ts +1 -1
  164. package/src/client/recovery/recovery-locales.test.ts +1 -1
  165. package/src/client/run-store.ts +1 -1
  166. package/src/client/sync/ChannelConfigDialog.tsx +32 -1
  167. package/src/client/sync/SyncPanel.tsx +11 -30
  168. package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
  169. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
  170. package/src/client/sync/SyncSettingsView.test.ts +32 -0
  171. package/src/client/sync/config-save-state.test.ts +99 -0
  172. package/src/client/sync/config-save-state.ts +69 -0
  173. package/src/client/sync/history-model.test.ts +28 -7
  174. package/src/client/sync/history-model.ts +6 -3
  175. package/src/client/sync/sync-locales.ts +14 -4
  176. package/src/client/sync/sync-view.ts +1 -1
  177. package/src/core/analyzer-cache.test.ts +1 -1
  178. package/src/core/backup.test.ts +45 -1
  179. package/src/core/backup.ts +25 -0
  180. package/src/core/disk-usage.test.ts +2 -0
  181. package/src/core/engine-locale.test.ts +4 -0
  182. package/src/core/env-lock-lifecycle.ts +33 -3
  183. package/src/core/external-failure.test.ts +60 -0
  184. package/src/core/external-failure.ts +54 -0
  185. package/src/core/integrity-extra-entries.test.ts +1 -1
  186. package/src/core/local-plugin-host.test.ts +134 -0
  187. package/src/core/local-plugin-host.ts +122 -17
  188. package/src/core/local-plugin-pack.ts +39 -3
  189. package/src/core/mcp-connector-store.ts +26 -1
  190. package/src/core/messages-core.ts +94 -0
  191. package/src/core/messages.ts +14 -0
  192. package/src/core/migration-history.test.ts +65 -0
  193. package/src/core/migration-history.ts +70 -0
  194. package/src/core/model-tool-plans.test.ts +111 -0
  195. package/src/core/model-tool-plans.ts +170 -0
  196. package/src/core/model-tools.test.ts +212 -12
  197. package/src/core/model-tools.ts +710 -38
  198. package/src/core/phase3-host.ts +10 -2
  199. package/src/core/phase3-production-integration.test.ts +43 -0
  200. package/src/core/plugin-cli.fs.test.ts +30 -3
  201. package/src/core/plugin-cli.ts +11 -3
  202. package/src/core/plugin-data-registry.ts +1 -1
  203. package/src/core/restore-plan-fingerprint.ts +19 -0
  204. package/src/core/restore-resume.ts +1 -1
  205. package/src/core/restore.ts +9 -1
  206. package/src/core/types.ts +12 -0
  207. package/src/foreign/claude-sessions.ts +3 -3
  208. package/src/foreign/registry.ts +1 -1
  209. package/src/foreign/types.ts +1 -1
  210. package/src/index.ts +102 -111
  211. package/src/market/git-file-writer.ts +1 -1
  212. package/src/market/github-repos.test.ts +1 -1
  213. package/src/market/github-repos.ts +1 -1
  214. package/src/market/market-config.ts +1 -1
  215. package/src/market/messages-market.ts +1 -1
  216. package/src/market/my-repo.test.ts +1 -1
  217. package/src/market/my-repo.ts +1 -1
  218. package/src/market/prepare.test.ts +1 -1
  219. package/src/market/prepare.ts +1 -1
  220. package/src/market/reader.ts +2 -2
  221. package/src/market/repo-url.ts +1 -1
  222. package/src/market/security.ts +2 -2
  223. package/src/market/star-cache.ts +1 -1
  224. package/src/market/types.ts +1 -1
  225. package/src/market/url.test.ts +1 -1
  226. package/src/market/url.ts +1 -1
  227. package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
  228. package/src/profiles/dsh-profile-manager.test.ts +20 -0
  229. package/src/profiles/dsh-profile-manager.ts +25 -7
  230. package/src/profiles/dsh-profile-shared.ts +2 -0
  231. package/src/routes/backup.ts +16 -9
  232. package/src/routes/index.ts +1 -1
  233. package/src/routes/kit.ts +2 -2
  234. package/src/routes/market.ts +2 -59
  235. package/src/routes/model-tools-deps.ts +56 -0
  236. package/src/routes/recovery.ts +5 -3
  237. package/src/routes/route-support.ts +49 -36
  238. package/src/routes/snapshots.ts +4 -40
  239. package/src/routes/sync.ts +39 -27
  240. package/src/schema/index.ts +2 -2
  241. package/src/schema/manifest-schema.test.ts +2 -2
  242. package/src/schema/registry.test.ts +1 -1
  243. package/src/schema/section-registry.ts +9 -4
  244. package/src/security/redaction.test.ts +1 -1
  245. package/src/security/secret-scanner.test.ts +2 -2
  246. package/src/security/secret-scanner.ts +1 -1
  247. package/src/sync/apply-bundle.ts +104 -0
  248. package/src/sync/autosync-scheduler.test.ts +180 -6
  249. package/src/sync/autosync-scheduler.ts +132 -92
  250. package/src/sync/backup-scheduler.test.ts +11 -4
  251. package/src/sync/backup-scheduler.ts +5 -4
  252. package/src/sync/blob-store.ts +2 -2
  253. package/src/sync/git/git-transport.test.ts +62 -0
  254. package/src/sync/git/git-transport.ts +54 -3
  255. package/src/sync/merge.ts +29 -0
  256. package/src/sync/messages.ts +9 -2
  257. package/src/sync/s3/s3-transport.ts +1 -1
  258. package/src/sync/sync-engine.test.ts +238 -2
  259. package/src/sync/sync-engine.ts +25 -26
  260. package/src/sync/sync-preview-push.test.ts +2 -1
  261. package/src/sync/sync-scope-boot.ts +87 -0
  262. package/src/sync/sync-scope.test.ts +154 -0
  263. package/src/sync/sync-scope.ts +256 -0
  264. package/src/sync/sync-selection.test.ts +76 -2
  265. package/src/sync/sync-selection.ts +40 -13
  266. package/src/sync/transport.test.ts +21 -1
  267. package/src/sync/transport.ts +12 -0
  268. package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
  269. package/src/sync/webdav/webdav-transport.ts +1 -1
  270. package/src/sync/workspace-merge.test.ts +110 -0
  271. package/src/sync/workspace-merge.ts +180 -0
  272. package/src/ui/backup-schedule.test.ts +5 -0
  273. package/src/ui/backup-schedule.ts +21 -2
  274. package/src/ui/session-issue-labels.ts +1 -1
  275. package/src/ui/snapshots-view.test.ts +32 -0
  276. package/src/ui/snapshots-view.ts +34 -0
  277. package/src/ui/sync-repository-picker.test.ts +34 -1
  278. package/src/ui/sync-repository-picker.ts +24 -0
  279. package/src/utils/env-lock.test.ts +242 -9
  280. package/src/utils/env-lock.ts +247 -13
  281. package/src/utils/messages-utils.ts +17 -1
  282. package/src/utils/patch-yaml.ts +1 -1
  283. package/src/utils/remove-tree.test.ts +120 -0
  284. package/src/utils/remove-tree.ts +239 -0
  285. package/src/utils/zip.ts +1 -1
  286. package/src/client/CLIENT_DEPENDENCIES.md +0 -94
@@ -22,13 +22,18 @@ import { join as joinPath } from 'node:path';
22
22
  * 各写一份目录名而漂移。
23
23
  */
24
24
  function diskUsageDirsOf(env) {
25
- const { dataDir, syncDir, marketDir, tmpDir, snapshotsDir, exportsDir } = env;
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
- syncDir: syncDir ?? joinPath(dataDir, 'sync'),
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
- const schedule = await readBackupSchedule(env.syncDir);
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, syncDir, withMutationGate, } = env;
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(syncDir) });
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(syncDir);
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(syncDir, next);
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(syncDir);
237
+ const schedule = await readBackupSchedule(syncRootDir);
230
238
  writeJson(res, 200, { ok: true, run, schedule });
231
239
  }
232
240
  catch (error) {
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 顺序对匹配无影响:DSH webServer 的契约是「命名路由必须互不相同,注册顺序不影响请求」
5
5
  * (见 @deepseek-ai/dsh-host-webserver 的 WebServer 文档)。src/index.ts 保留的 7 条被源码级
6
- * 守卫按文件窗口钉住,其余 77 条在这里组装(总数 84:含 path-browse)。
6
+ * 守卫按文件窗口钉住,其余 75 条在这里组装(总数 82:含 path-browse)。
7
7
  */
8
8
  import type { WebRoute } from './kit.ts';
9
9
  import type { RoutesEnv } from './context.ts';
@@ -8,8 +8,8 @@
8
8
  * - 「每条路由首行 guard」这条安全不变量此前**只写在注释里**,零测试覆盖;
9
9
  * - 3 条 prefix 路由自造围栏(裸 isLoopbackRequest + 自判方法)。
10
10
  *
11
- * 计数口径(三路一致 = 84,勿再照抄旧审计初稿的计数 —— 那是计数口径 overcount):
12
- * 路由快照 84 条 = 现行 `endpoint()` 声明 84 条 = 运行期 `buildRoutes()` 77 条 + `src/index.ts` 保留的 7 条。
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
  *
@@ -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 在注册点统一提供。
@@ -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, requireJsonObject, readJsonBody, writeJson } from './kit.js';
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, roots, tmpDir, writeItemCache, } = env;
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
@@ -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 同一份(dataDir/sync/ui-prefs.json);回滚点开关存在那里,
766
- // 所以这里派生同一个目录,绝不另立第二个偏好文件。
767
- const syncDir = join(dataDir, 'sync');
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
- /** parseSyncBody 的凭据写入依赖(只用到 set;测试可注入内存 mock)。 */
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
- * 同步 token 的 DSH credentials 引用名(POSIX env-var 形态,满足 CredentialRef 品牌要求)。
37
- * token 只经 credentialRef 读写(写入由请求体触发,读取在每次 git 网络操作时 resolve),
38
- * 永不进 repoUrl / argv / commit / 同步文件 / 日志。
36
+ * 同步凭据槽位名与 per-profile 作用域:**唯一声明处已迁到 `src/sync/sync-scope.ts`**
37
+ * (那里也持有 `syncScopeFor` / `adoptLegacySyncScope`)。此文件只 re-export,
38
+ * 保持 `src/index.ts` 与测试既有的 import 面与符号名不变(值不变,只是多了可选档案后缀)。
39
39
  */
40
- export const SYNC_CREDENTIAL_REF = 'DSH_CONFIG_MANAGER_SYNC_TOKEN';
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(SYNC_WEBDAV_CREDENTIAL_REF), password);
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: SYNC_WEBDAV_CREDENTIAL_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(SYNC_CREDENTIAL_REF), token);
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: SYNC_CREDENTIAL_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
  }
@@ -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 在注册点统一提供。
@@ -1,27 +1,18 @@
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
  import { endpoint, readJsonBody, writeJson, writeMutationError } from './kit.js';
8
- import { deleteSnapshot, isValidSnapshotId, listSnapshots, planRestore, setSnapshotPinned } from '../core/restore.js';
8
+ import { deleteSnapshot, isValidSnapshotId, listSnapshots, planRestore } from '../core/restore.js';
9
+ // 预览-执行一致性指纹:与 agent 工具(config_restore)共用同一实现,口径分叉会让防呆失效。
10
+ import { restorePlanFingerprint } from '../core/restore-plan-fingerprint.js';
9
11
  import { snapshotFileDiff, summarizeRestoreChanges } from '../core/snapshot-diff.js';
10
12
  import { buildFileDiffBody, buildRestoreBody, executeRestorePlan, makeRestoreExecutor } from './route-support.js';
11
13
  import { probeRestoreResume, runRestoreWithResume } from '../core/restore-resume.js';
12
14
  import { runWithMutationLock } from '../utils/env-lock.js';
13
- import { isENOENT } from '../utils/guards.js';
14
15
  import { join } from 'node:path';
15
- import { createHash } from 'node:crypto';
16
- /**
17
- * 恢复计划指纹(预览-执行一致性):只取「动作类型 + 目标 + blob」三列 —— 描述文案、详情、顺序无关的
18
- * 易变字段一律不进,保证同一份快照 + 同一磁盘状态下指纹稳定。内容变化不会改变指纹(同 kind/target),
19
- * 只有**动作集合真的变了**(文件出现/消失、插件增删)才会不同 —— 那正是需要用户重新确认的情况。
20
- */
21
- function restorePlanFingerprint(plan) {
22
- const lines = plan.actions.map((action) => [action.kind, action.target ?? '', action.blobPath ?? ''].join('\u0000'));
23
- return createHash('sha256').update(lines.join('\n')).digest('hex');
24
- }
25
16
  export function snapshotRoutes(env) {
26
17
  const { host, msg, runs, snapshotEntrySections, snapshotsDir, tryAppendHistory, withMutationGate, } = env;
27
18
  return [
@@ -237,33 +228,6 @@ export function snapshotRoutes(env) {
237
228
  writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
238
229
  }
239
230
  })),
240
- // --------------------------------------------- snapshots/pin(P1-⑧)
241
- // 置顶/取消置顶快照:置顶快照豁免「最多保留 N 个」的自动清理(只能手动删除)。
242
- // 纯元数据写(重写 snapshot.json 的 pinned 字段);loopback fence 必备。
243
- endpoint({ path: '/api/dsh-config-manager/snapshots/pin', methods: ['POST'] }, withMutationGate('snapshot-pin', async (req, res) => {
244
- try {
245
- const body = await readJsonBody(req);
246
- const id = typeof body === 'object' && body !== null
247
- ? body['snapshotId']
248
- : undefined;
249
- const pinned = body?.['pinned'] === true;
250
- if (!isValidSnapshotId(id)) {
251
- writeJson(res, 400, { error: 'snapshotId is required and must be a valid snapshot id' });
252
- return;
253
- }
254
- await setSnapshotPinned(snapshotsDir, id, pinned);
255
- writeJson(res, 200, { ok: true, pinned });
256
- }
257
- catch (error) {
258
- // e2e-F4:快照不存在时**不得**把 fs 原始错误(含服务端绝对路径)回给浏览器 ——
259
- // 结构化 404 + 机器可读码,文案由界面按码映射;其余失败也不再回显原始 message。
260
- if (isENOENT(error)) {
261
- writeJson(res, 404, { error: 'snapshot not found', code: 'snapshot-not-found' });
262
- return;
263
- }
264
- writeJson(res, 500, { error: 'failed to update snapshot pin' });
265
- }
266
- })),
267
231
  // --------------------------------------- snapshots/file-diff(git 风格预览)
268
232
  // 单个文件的逐行差异(只读):before = 当前磁盘文件 / after = 快照 blob。
269
233
  // 点开某个文件才请求(列表阶段只做轻量统计),避免会话类快照几百个文件时拖死弹窗。