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
package/lib/index.js CHANGED
@@ -38,8 +38,7 @@ import { randomBytes } from 'node:crypto';
38
38
  import { execFile } from 'node:child_process';
39
39
  import { existsSync, mkdirSync, readFileSync } from 'node:fs';
40
40
  import fs from 'node:fs/promises';
41
- import path from 'node:path';
42
- import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
41
+ import path, { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
43
42
  import { homedir } from 'node:os';
44
43
  import { promisify } from 'node:util';
45
44
  import * as dshSettings from '@deepseek-ai/dsh-settings';
@@ -47,6 +46,7 @@ import { dshHomePath, resolveDshHome } from '@deepseek-ai/dsh-home-paths';
47
46
  import { endpoint, registerRoutes, requireJsonObject, writeJson, readJsonBody, errorMessage, writeMutationError } from './routes/kit.js';
48
47
  import { installHostRequestTrust } from './routes/request-trust.js';
49
48
  import { buildRoutes } from './routes/index.js';
49
+ import { createAgentToolDeps } from './routes/model-tools-deps.js';
50
50
  import { Exporter, FileSnapshotStore, Importer, verifySnapshot } from './core/index.js';
51
51
  import { DshProfileLauncher, DshProfileManager, DshProfileRuntimeRegistry } from './profiles/index.js';
52
52
  import { cleanupCaches } from './core/cache-cleaner.js';
@@ -67,7 +67,7 @@ import { JournalStore } from './core/journal.js';
67
67
  import { RunRegistry } from './core/run-registry.js';
68
68
  import { registerModelTools } from './core/model-tools.js';
69
69
  import { msgOf, zhMsg } from './core/messages.js';
70
- import { createExitLockReleaser, reclaimStaleLockAtStartup } from './core/env-lock-lifecycle.js';
70
+ import { createExitLockReleaser, createHostMutationLock, reclaimStaleLockAtStartup } from './core/env-lock-lifecycle.js';
71
71
  import { engineMsg, getEngineLocale, setEngineLanguageSource, setEngineLocale } from './core/engine-locale.js';
72
72
  import { RollbackAutoTracker, RollbackPointEngine, ROLLBACK_POINTS_DIR_NAME, rollbackSessionBindingOf, rollbackTrackedEventOf } from './core/rollback-point.js';
73
73
  import { ROLLBACK_ATTRIBUTION_FILE_NAME, RollbackWriteAttribution } from './core/rollback-attribution.js';
@@ -90,6 +90,7 @@ import { PROJECT_KEY_RE, readLogCwdFromBytes, rewriteSessionLogDir } from './uti
90
90
  import { probeSessionFormats, resolveSessionFormatVersion } from './utils/session-format.js';
91
91
  import { describePatchYamlError, dumpPatchDocument, loadPatchDocument } from './utils/patch-yaml.js';
92
92
  import { atomicCopyFile, atomicWriteFile } from './utils/atomic-write.js';
93
+ import { removeTree } from './utils/remove-tree.js';
93
94
  import { isENOENT } from './utils/guards.js';
94
95
  import { EnvironmentLockManager, runWithMutationLock } from './utils/env-lock.js';
95
96
  import { activeProxySummary } from './utils/proxy.js';
@@ -111,12 +112,12 @@ import { AUTO_BACKUP_PREFIX, isValidExportFileName, resolveNonCollidingExportNam
111
112
  import { DEFAULT_RETENTION_POLICY, selectPruneCandidatesByPolicy } from './sync/retention-policy.js';
112
113
  import { selectPruneCandidates } from './core/backup.js';
113
114
  import { appendAutosyncEntry } from './sync/sync-history.js';
114
- import { MigrationStore, historyResultFromAutosyncStatus, MIGRATION_HISTORY_DIR } from './core/migration-history.js';
115
+ import { MigrationStore, autosyncUnifiedHistoryInput, MIGRATION_HISTORY_DIR } from './core/migration-history.js';
115
116
  import { createHistoryPruner } from './core/history-prune.js';
116
117
  import { isWebDavConfig, isS3Config, isGistConfig, channelOf, SYNC_CHANNELS, GIST_PROVIDER, cloudSecretRef } from './sync/sync-config.js';
117
118
  import { resolveSessionFormatDisposition, sessionFormatAbortResponse, } from './routes/session-format.js';
118
119
  import { createPrepareSync } from './sync/config-issue-reporting.js';
119
- import { AUTO_SYNC_OPT_IN_SECTIONS, defaultSyncSelection, effectiveSections, OPT_IN_SYNC_SECTIONS, readAllSyncSelections, readSyncSelection } from './sync/sync-selection.js';
120
+ import { AUTO_SYNC_OPT_IN_SECTIONS, defaultSyncSelection, effectiveSections, OPT_IN_SYNC_SECTIONS, readAllSyncSelections, readAllSyncSelectionsSync, readSyncSelection } from './sync/sync-selection.js';
120
121
  import { GitMarketReader } from './market/reader.js';
121
122
  import { parseMarketIndex } from './market/index-parser.js';
122
123
  import { prepareMarketItem } from './market/prepare.js';
@@ -136,7 +137,10 @@ import { createLogger, parseLogLevel } from './utils/logger.js';
136
137
  // 与 HTTP 路径**同一份**「运行中对话」判据(命令入口绝不能各写一套)
137
138
  import { sessionActiveDenied, sessionActiveGateApplies } from './routes/recovery.js';
138
139
  // P4:路由组共享的纯工具已下沉到 routes/route-support.ts —— 组文件不再反向 import 本文件。
139
- import { ROUTE_TIMEOUT_MS, SYNC_CREDENTIAL_REF, SYNC_WEBDAV_CREDENTIAL_REF, credentialRef, decryptErrorText, executeRestorePlan, isControlledPath, makeRestoreExecutor, safeCredentialRef, syncPasswordRef, tryDecryptCredentials, withTimeout } from './routes/route-support.js';
140
+ import { ROUTE_TIMEOUT_MS, credentialRef, decryptErrorText, executeRestorePlan, isControlledPath, makeRestoreExecutor, safeCredentialRef, syncPasswordRef, tryDecryptCredentials, withTimeout } from './routes/route-support.js';
141
+ // per-profile 同步作用域:单一实现见 src/sync/sync-scope.ts
142
+ import { syncScopeFor } from './sync/sync-scope.js';
143
+ import { bootSyncScope, makeSyncCredentialViews } from './sync/sync-scope-boot.js';
140
144
  export { ROUTE_TIMEOUT_MS, REVIEW_KINDS, SYNC_CREDENTIAL_REF, SYNC_ENCRYPT_PASSWORD_REF_PREFIX, SYNC_DECRYPT_PASSWORD_REF_PREFIX, SYNC_WEBDAV_CREDENTIAL_REF, SyncRouteError, buildAutosyncStatus, buildAutosyncStatusByChannel, buildFileDiffBody, buildRestoreBody, credentialRef, decryptErrorText, executeRestorePlan, extractSyncSections, extractSyncSessions, isAutosyncInterval, isControlledPath, isGitHubAuthMissing, isToolchainChangeItem, makeRestoreExecutor, parseMeForm, planToConfirmItems, safeCredentialRef, sessionHealthNextSteps, syncPasswordRef, tryDecryptCredentials, withTimeout, writeProfileError, writeRequestBodyToFile, writeSyncRouteError } from './routes/route-support.js';
141
145
  /* ---------------------------------------------------------------- identity */
142
146
  /** Stable cordis plugin name — must match the cordis.patch.yml row id. */
@@ -144,7 +148,7 @@ export const name = 'config-manager';
144
148
  /** Services required before the engine can mount (present in every profile). */
145
149
  export const inject = ['settings', 'credentials'];
146
150
  /** Plugin version, kept in sync with package.json ("version"). */
147
- export const PLUGIN_VERSION = '0.4.3';
151
+ export const PLUGIN_VERSION = '0.6.0';
148
152
  /** Plugin own package name — excluded from its own exported plugins list. */
149
153
  const PLUGIN_NAME = 'dsh-config-manager';
150
154
  /**
@@ -166,7 +170,7 @@ export const DEFAULT_GITHUB_CLIENT_ID = 'Ov23liq4i7n8UsylGRfb';
166
170
  /**
167
171
  * 本文件保留的 7 条路由的路径(被源码级守卫按文件窗口钉住,见下方 routesList 注释)。
168
172
  *
169
- * 其余 77 条路由的路径**声明在各自的组文件里**(src/routes/*.ts 的 endpoint({ path, methods }))——
173
+ * 其余 75 条路由的路径**声明在各自的组文件里**(src/routes/*.ts 的 endpoint({ path, methods }))——
170
174
  * 新增一条 API 只需那一条声明,不再有「常量表 + 路由对象」两处要同步。
171
175
  */
172
176
  export const API = {
@@ -1602,8 +1606,12 @@ export class DshFileSystemFacade {
1602
1606
  async copy(from, to) {
1603
1607
  await atomicCopyFile(this.abs(from), this.abs(to));
1604
1608
  }
1609
+ /**
1610
+ * 递归删除(home 内,缺失目标视为成功)。**不用 fs.rm(recursive)**:目录里有悬空链接时它静默
1611
+ * 空转(报告写「已还原」而磁盘原样在)。removeTree 逐条删、只删链接本身、删不净就抛错。
1612
+ */
1605
1613
  async remove(relPath) {
1606
- await fs.rm(this.abs(relPath), { recursive: true, force: true });
1614
+ await removeTree(this.abs(relPath));
1607
1615
  }
1608
1616
  /** 仅路径列表(既有契约):委托 listRecursiveDetailed,丢弃诊断。 */
1609
1617
  async listRecursive(dir) {
@@ -2027,14 +2035,14 @@ async function sessionHealthKnownIds(host) {
2027
2035
  }
2028
2036
  /** Build the /api/dsh-config-manager route family. */
2029
2037
  function makeRoutes(deps) {
2030
- const { host, adapters, exportsDir, tmpDir, snapshotsDir, runs, syncDir, marketDir, dataDir, credentials, githubClientId, githubClientSecret, backupScheduler, history } = deps;
2038
+ const { host, adapters, exportsDir, tmpDir, snapshotsDir, runs, syncDir, syncRootDir, syncScope, marketDir, dataDir, credentials, githubClientId, githubClientSecret, backupScheduler, history } = deps;
2031
2039
  const roots = [exportsDir, tmpDir];
2032
2040
  /**
2033
2041
  * m-retention:快照保留策略提供者(缺省 = 从 sync/backup-schedule.json 实时读取)。
2034
2042
  * 用户改完策略即时生效(每次 prune 都重读);读取失败 → 缺省策略(引擎侧兜底)。
2035
2043
  */
2036
2044
  const retentionPolicyProvider = deps.retentionPolicy
2037
- ?? (async () => (await readBackupSchedule(syncDir)).retention ?? DEFAULT_RETENTION_POLICY);
2045
+ ?? (async () => (await readBackupSchedule(syncRootDir)).retention ?? DEFAULT_RETENTION_POLICY);
2038
2046
  /**
2039
2047
  * m-retention:GFS 分层选择器(sync 层实现)+ 旧路径快速路径绑定。
2040
2048
  * 为什么由宿主注入:架构边界禁止 core → sync 反向依赖;core 只声明 PruneSelector 契约。
@@ -2170,7 +2178,7 @@ function makeRoutes(deps) {
2170
2178
  /** 已知 adapter id 集合(push 请求体 sections 校验用)。 */
2171
2179
  const knownSyncSectionIds = new Set(adapters.map((a) => a.id));
2172
2180
  /** 可同步分区目录(status 回填 UI「同步分区」勾选列表)。
2173
- * 只含 portable + 显式可选项(OPT_IN_SYNC_SECTIONS,当前 mcp / sessions)——
2181
+ * 只含 portable + 显式可选项(OPT_IN_SYNC_SECTIONS,当前 mcp / workspaces / sessions)——
2174
2182
  * 后者是 deviceSpecific,UI 必须显示设备相关徽章,且只有用户主动勾选才进同步通道。 */
2175
2183
  const syncSectionCatalog = adapters
2176
2184
  .filter((a) => a.portability === 'portable' || OPT_IN_SYNC_SECTIONS.includes(a.id))
@@ -2275,17 +2283,18 @@ function makeRoutes(deps) {
2275
2283
  // 这里只做装配:宿主只提供 credentials、日志出口与配置目录。
2276
2284
  const prepareSync = createPrepareSync({
2277
2285
  syncDir,
2278
- parseBody: (body) => parseSyncBody(body, { credentials }),
2286
+ // scope:git/webdav 的 token/口令、s3/gist 的密钥槽位都按档案取(默认档案 = 历史槽位名)。
2287
+ parseBody: (body) => parseSyncBody(body, { credentials, scope: syncScope }),
2279
2288
  mergeWebDavUsername: mergePersistedWebDavUsername,
2280
2289
  log: (line) => host.log.warn(line),
2281
2290
  });
2282
2291
  /** 同步分区选择缓存(按通道;sync-selection.json;makeSyncEngine 同步读取用,保存路由更新)。
2283
- * 缺失通道 = 尚未加载(启动竞态窗口);读取/使用处兜底 defaultSyncSelection。 */
2292
+ * **必须同步种入**(C6):apply() 同步,异步种入会留窗口 —— 窗口内 makeSyncEngine 兜底
2293
+ * defaultSyncSelection(全部 portable),用户 advanced 的收窄在那一轮被吞(判据见 docs/evidence/sync-channel.md)。 */
2284
2294
  const selectionCache = {};
2285
- void readAllSyncSelections(syncDir).then((all) => {
2286
- for (const channel of SYNC_CHANNELS)
2287
- selectionCache[channel] = all[channel];
2288
- }).catch(() => { });
2295
+ const seededSelections = readAllSyncSelectionsSync(syncDir);
2296
+ for (const channel of SYNC_CHANNELS)
2297
+ selectionCache[channel] = seededSelections[channel];
2289
2298
  /** 确保指定通道缓存已加载(status/save 路由调用;启动竞态兜底)。 */
2290
2299
  const ensureSelectionLoaded = async (channel) => {
2291
2300
  const cached = selectionCache[channel];
@@ -2313,26 +2322,8 @@ function makeRoutes(deps) {
2313
2322
  return undefined;
2314
2323
  }
2315
2324
  };
2316
- /** 某个同步密码槽位是否已配置(只回布尔,永不回值)。 */
2317
- const syncPasswordConfigured = async (ref) => {
2318
- try {
2319
- const info = await credentials.describe(credentialRef(ref));
2320
- return info.configured;
2321
- }
2322
- catch {
2323
- return false;
2324
- }
2325
- };
2326
- /** 全部通道的「同步密码是否已保存」视图(只回布尔;密码值永不进任何响应)。 */
2327
- const syncCredentialsByChannelView = async () => {
2328
- const describe = async (channel) => ({
2329
- encryptPasswordConfigured: await syncPasswordConfigured(syncPasswordRef('ENCRYPT', channel)),
2330
- decryptPasswordConfigured: await syncPasswordConfigured(syncPasswordRef('DECRYPT', channel)),
2331
- });
2332
- // t32/B7:通道集合来自唯一枚举(保持 Promise.all 并发语义)
2333
- const pairs = await Promise.all(SYNC_CHANNELS.map(async (channel) => [channel, await describe(channel)]));
2334
- return Object.fromEntries(pairs);
2335
- };
2325
+ // 同步密码槽位的「是否已保存」视图(按本档案取槽位;实现见 src/sync/sync-scope-boot.ts)
2326
+ const { syncPasswordConfigured, syncCredentialsByChannelView } = makeSyncCredentialViews(credentials, syncScope.profile);
2336
2327
  /** 分区选择视图形状(无 schemaVersion;密码值永不进视图)。 */
2337
2328
  /** 全部通道的分区选择视图(status 路由一次返回;UI 按当前 tab 取对应通道)。 */
2338
2329
  /** 指定通道的分区选择视图。 */
@@ -2386,7 +2377,7 @@ function makeRoutes(deps) {
2386
2377
  workDir: gitWorkDir,
2387
2378
  credentials: {
2388
2379
  getToken: async () => {
2389
- const resolved = await credentials.resolve(credentialRef(SYNC_CREDENTIAL_REF));
2380
+ const resolved = await credentials.resolve(credentialRef(syncScope.tokenRef));
2390
2381
  return resolved?.value ?? '';
2391
2382
  },
2392
2383
  },
@@ -2400,7 +2391,7 @@ function makeRoutes(deps) {
2400
2391
  username: cfg.webdav.username ?? '',
2401
2392
  credentials: {
2402
2393
  getPassword: async () => {
2403
- const resolved = await credentials.resolve(credentialRef(SYNC_WEBDAV_CREDENTIAL_REF));
2394
+ const resolved = await credentials.resolve(credentialRef(syncScope.webdavPasswordRef));
2404
2395
  return resolved?.value ?? '';
2405
2396
  },
2406
2397
  },
@@ -2419,7 +2410,7 @@ function makeRoutes(deps) {
2419
2410
  accessKeyId: cfg.s3.accessKeyId,
2420
2411
  credentials: {
2421
2412
  getSecretAccessKey: async () => {
2422
- const resolved = await credentials.resolve(credentialRef(cloudSecretRef(provider)));
2413
+ const resolved = await credentials.resolve(credentialRef(syncScope.scopeRef(cloudSecretRef(provider))));
2423
2414
  return resolved?.value ?? '';
2424
2415
  },
2425
2416
  },
@@ -2437,7 +2428,7 @@ function makeRoutes(deps) {
2437
2428
  gistId: cfg.gist.gistId,
2438
2429
  credentials: {
2439
2430
  getToken: async () => {
2440
- const resolved = await credentials.resolve(credentialRef(cloudSecretRef(GIST_PROVIDER)));
2431
+ const resolved = await credentials.resolve(credentialRef(syncScope.scopeRef(cloudSecretRef(GIST_PROVIDER))));
2441
2432
  return resolved?.value ?? '';
2442
2433
  },
2443
2434
  },
@@ -2490,17 +2481,11 @@ function makeRoutes(deps) {
2490
2481
  // Phase 6:autosync 既写 sync-history.json(既有语义),也写统一迁移历史(COMPLETE 不变量)。
2491
2482
  appendHistoryFn: async (entry) => {
2492
2483
  await appendAutosyncEntry(syncDir, entry).catch(() => undefined);
2493
- await history.append({
2494
- kind: 'autosync',
2495
- result: historyResultFromAutosyncStatus(entry.status),
2496
- sections: entry.appliedSections ?? [],
2497
- source: 'autosync',
2498
- summary: engineMsg('host.autosyncSummary', {
2499
- direction: entry.direction,
2500
- transportSuffix: entry.transport !== undefined ? engineMsg('host.autosyncTransportSuffix', { transport: entry.transport }) : '',
2501
- }),
2502
- error: entry.status === 'failed' ? (entry.error ?? entry.skipReason) : undefined,
2503
- }).catch(() => undefined);
2484
+ // 空检查轮(每 60s 一次的远端探测,什么都没传)不进统一历史;payload 组装与判据见 core。
2485
+ const input = autosyncUnifiedHistoryInput(entry, engineMsg);
2486
+ if (input === null)
2487
+ return;
2488
+ await history.append({ kind: 'autosync', ...input }).catch(() => undefined);
2504
2489
  },
2505
2490
  });
2506
2491
  // P1-B:调度器不再在 makeRoutes 内同步 start —— 由 apply() 在「启动 recovery 分类完成后、仅 NORMAL」时启动。
@@ -2521,7 +2506,7 @@ function makeRoutes(deps) {
2521
2506
  /** 请求级装配只读 GitMarketReader(公开市场无凭据;url = BUILTIN_MARKET_URL,已由 validateRepoUrl 拒绝 userinfo)。 */
2522
2507
  const makeMarketReader = () => new GitMarketReader({ msg, timeoutMs: 60_000 });
2523
2508
  /**
2524
- * 市场条目来源仓库 star 缓存(docs/design/2026-08-21-market-star-filter-sort-design.md §3.1.3)。
2509
+ * 市场条目来源仓库 star 缓存(docs/archive/2026-08-21-market-star-filter-sort-design.md §3.1.3)。
2525
2510
  * - **匿名查询**(getRepoStarsPublic,不注入 token)——守住「市场端点零凭据」安全不变式;
2526
2511
  * - 按仓库 URL 去重 + 1 小时 TTL + 失败降级(单仓失败显示「—」,不影响整体浏览);
2527
2512
  * - tokenProvider 给空函数(requestPublic 不调用它,仅满足构造签名)。
@@ -2573,7 +2558,7 @@ function makeRoutes(deps) {
2573
2558
  // 同一凭据槽),值绝不落盘 / 进日志 / 回传浏览器;gitWriter 写用户仓库与 fork 分支,
2574
2559
  // 安全模式与 GitTransport 一致(credential helper store 临时文件 0600 用后即删)。
2575
2560
  const meTokenProvider = async () => {
2576
- const resolved = await credentials.resolve(credentialRef(SYNC_CREDENTIAL_REF));
2561
+ const resolved = await credentials.resolve(credentialRef(syncScope.tokenRef));
2577
2562
  return resolved?.value ?? '';
2578
2563
  };
2579
2564
  const meGitHubRest = new GitHubAuthRest({ tokenProvider: meTokenProvider });
@@ -2742,6 +2727,8 @@ function makeRoutes(deps) {
2742
2727
  starPromptRepoUrl: STAR_PROMPT_REPO_URL,
2743
2728
  syncCredentialsByChannelView,
2744
2729
  syncDir,
2730
+ syncRootDir,
2731
+ syncScope,
2745
2732
  // issue #79:工作副本自检(只读,挂在 /sync/status)与显式重建(写动作,走 mutation gate)。
2746
2733
  // 路由只传 repoUrl/mode —— 路径、凭据与 git 调用口径都留在宿主这一处。
2747
2734
  syncWorkDir: {
@@ -2793,7 +2780,7 @@ function makeRoutes(deps) {
2793
2780
  /**
2794
2781
  * 路由表:本文件只保留被源码级守卫按**文件窗口**钉住的 7 条(host-entry 审计 F-04 记录的
2795
2782
  * tests/host/**、src/core/model-tools.test.ts、src/core/phase1-wiring.test.ts 的窗口断言)。
2796
- * 其余 77 条已按域拆到 src/routes/*.ts,由 buildRoutes 组装。
2783
+ * 其余 75 条已按域拆到 src/routes/*.ts,由 buildRoutes 组装。
2797
2784
  * 注册顺序不影响匹配:命名路由必须互不相同(webServer 契约)。
2798
2785
  */
2799
2786
  const routeEnv = makeRouteEnv();
@@ -3273,7 +3260,18 @@ function makeRoutes(deps) {
3273
3260
  }),
3274
3261
  ...buildRoutes(routeEnv),
3275
3262
  ];
3276
- return { routes: routesList, scheduler, makeSyncEngine, profileRuntime: routeEnv.profileRuntime };
3263
+ return {
3264
+ routes: routesList,
3265
+ scheduler,
3266
+ makeSyncEngine,
3267
+ profileRuntime: routeEnv.profileRuntime,
3268
+ agentToolDeps: createAgentToolDeps({
3269
+ host, adapters, exportsDir, snapshotsDir, syncDir, makeSyncEngine,
3270
+ resolveSyncPassword, syncPasswordRef, selectionOptInSections, makeImporter, roots,
3271
+ ...(deps.scanner === undefined ? {} : { scanner: deps.scanner }),
3272
+ exporterVersion: PLUGIN_VERSION,
3273
+ }),
3274
+ };
3277
3275
  }
3278
3276
  /* ------------------------------------------------------------------ apply */
3279
3277
  /**
@@ -3292,7 +3290,10 @@ export function apply(ctx, config) {
3292
3290
  const exportsDir = join(dataDir, 'exports');
3293
3291
  const tmpDir = join(dataDir, 'tmp');
3294
3292
  const snapshotsDir = join(dataDir, 'snapshots');
3295
- const syncDir = join(dataDir, 'sync');
3293
+ // 同步作用域按档案分(dataDir 不拆:写锁 / SAFE MODE / 事务日志都长在那棵树上)—— src/sync/sync-scope.ts
3294
+ const syncScope = syncScopeFor(dataDir, resolveProfileName(config, ctx));
3295
+ const syncDir = syncScope.dir;
3296
+ const syncRootDir = syncScope.rootDir;
3296
3297
  /**
3297
3298
  * issue #88 / #89:回合自动留点(回滚点)**缺省关闭**。
3298
3299
  *
@@ -3343,6 +3344,8 @@ export function apply(ctx, config) {
3343
3344
  mkdirSync(marketDir, { recursive: true });
3344
3345
  mkdirSync(historyDir, { recursive: true });
3345
3346
  const host = new ConfigManagerHostContext(ctx, homeDir, resolveProfileName(config, ctx));
3347
+ // 非默认档案首次启动继承历史同步根(配置 + 凭据值,best-effort;见 src/sync/sync-scope-boot.ts)
3348
+ bootSyncScope(syncScope, ctx.credentials, (line) => host.log.warn(line));
3346
3349
  // issue #30:出站代理(插件私有,不改全局)。仅在检测到 HTTP(S)_PROXY 时生效;未配置则完全直连。
3347
3350
  // 打一条脱敏日志,便于用户确认「插件当前到底走没走代理」(凭据不进日志)。
3348
3351
  const proxySummary = activeProxySummary();
@@ -3352,12 +3355,8 @@ export function apply(ctx, config) {
3352
3355
  // Phase 2 跨进程环境锁:全局唯一 GLOBAL EXCLUSIVE MUTATION LOCK(<dataDir>/locks/environment.lock)。
3353
3356
  // 所有 destructive mutation 入口经 runWithMutationLock(host.mutationLock, …) 获取;跨进程/跨 kind 互斥。
3354
3357
  // 随插件生命周期停止:停止 heartbeat 并清除本进程持有(release 由各入口 finally 保证;这里无需额外清理)。
3355
- host.mutationLock = new EnvironmentLockManager({
3356
- dataDir,
3357
- op: 'config-manager',
3358
- target: 'global-mutation',
3359
- lockVersion: PLUGIN_VERSION,
3360
- });
3358
+ // 装配(含「心跳写失败 / 释放失败」留痕)在 core/env-lock-lifecycle.ts:此处只传依赖。
3359
+ host.mutationLock = createHostMutationLock({ dataDir, lockVersion: PLUGIN_VERSION, log: host.log });
3361
3360
  const envLockManager = host.mutationLock;
3362
3361
  // Phase 3:启动 reconcile(只读)+ SAFE MODE。宿主 apply() 为同步 →
3363
3362
  // ① 先同步探测 durable SAFE MODE 标记(scheduler.start() 前即被阻断),
@@ -3538,7 +3537,8 @@ export function apply(ctx, config) {
3538
3537
  const secretScanner = createConfiguredSecretScanner(config?.personalPatterns);
3539
3538
  const runs = new RunRegistry({ msg: host.msg });
3540
3539
  const backupScheduler = new BackupScheduler({
3541
- syncDir,
3540
+ // 定时备份配置是全机一份(不是某个档案的同步态):喂全机根,不喂档案作用域
3541
+ syncDir: syncRootDir,
3542
3542
  exportsDir,
3543
3543
  host,
3544
3544
  adapters,
@@ -3559,7 +3559,7 @@ export function apply(ctx, config) {
3559
3559
  const historyStore = new MigrationStore({ dir: historyDir });
3560
3560
  // 本实例的 web 端口在 webServer 就绪前未知(心跳先报 null,就绪后再报一次)。
3561
3561
  const webPort = { value: null };
3562
- const { routes, scheduler, makeSyncEngine, profileRuntime } = makeRoutes({
3562
+ const { routes, scheduler, profileRuntime, agentToolDeps, } = makeRoutes({
3563
3563
  host,
3564
3564
  adapters,
3565
3565
  exportsDir,
@@ -3567,10 +3567,12 @@ export function apply(ctx, config) {
3567
3567
  snapshotsDir,
3568
3568
  runs,
3569
3569
  syncDir,
3570
+ syncRootDir,
3571
+ syncScope,
3570
3572
  marketDir,
3571
3573
  dataDir,
3572
3574
  runtimePort: () => webPort.value,
3573
- retentionPolicy: async () => (await readBackupSchedule(syncDir)).retention ?? DEFAULT_RETENTION_POLICY,
3575
+ retentionPolicy: async () => (await readBackupSchedule(syncRootDir)).retention ?? DEFAULT_RETENTION_POLICY,
3574
3576
  // F2:部署者 personalPatterns → 强化 secret 扫描器(未配置 = 默认行为)。
3575
3577
  // 该扫描器实现了 scanText(文件类分区文本级扫描,G-09 只告警不改写)——
3576
3578
  // 换成任何没有 scanText 的扫描器都会静默关闭 G-09,改这里务必先看 exporter.ts 的 scanFileSectionText。
@@ -3581,19 +3583,9 @@ export function apply(ctx, config) {
3581
3583
  backupScheduler,
3582
3584
  history: historyStore,
3583
3585
  });
3584
- // Agent 可调用的模型工具(P0-1):复用 src/core 引擎与同一 makeSyncEngine 来源。
3585
- // 不依赖 webServer:host 侧能力在无 Web 部署时仍可用;tools 服务未组合时内部守卫跳过。
3586
- registerModelTools(ctx, {
3587
- host,
3588
- adapters,
3589
- exportsDir,
3590
- snapshotsDir,
3591
- syncDir,
3592
- makeSyncEngine,
3593
- exporterVersion: PLUGIN_VERSION,
3594
- // M1:与 HTTP 导出路由同一个 scanner(G-09 文件类分区凭据告警在两条路径上一致)。
3595
- scanner: secretScanner,
3596
- });
3586
+ // 模型工具(P0-1):与 HTTP 路由同一批依赖(装配见 routes/model-tools-deps.ts);
3587
+ // 不依赖 webServer,tools 服务未组合时内部守卫跳过。
3588
+ registerModelTools(ctx, agentToolDeps);
3597
3589
  // P1-B:backupScheduler 与 autosync scheduler 都不在构造期启动 —— 由启动分类结论驱动(仅 NORMAL)。
3598
3590
  // 启停顺序、卸载清理、退出兜底释放环境锁、实例心跳统一在 lifecycle-hooks 里装配(可单测)。
3599
3591
  const lifecycle = createHostLifecycle({
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * m-market:GitFileWriter —— 通用 git 文件写入器(「一键上传/我的配置」专用)。
3
3
  *
4
- * 背景(docs/design/2026-08-20-my-configs-design.md §4.2 / §4.3):
4
+ * 背景(docs/archive/2026-08-20-my-configs-design.md §4.2 / §4.3):
5
5
  * GitTransport(src/sync/git/git-transport.ts)实现的是 SyncTransport 接口,语义是
6
6
  * **快照同步**(list/upload/download/delete,内容提交到 snapshots/ 与 snapshots-encrypted/),
7
7
  * 不是通用 git 文件写入工具。MyRepoService 需要写入自定义目录结构
@@ -1,5 +1,5 @@
1
1
  /**
2
- * m-market:GitHub REST API 薄客户端 GitHubAuthRest(docs/design/2026-08-20-my-configs-design.md §4.2)。
2
+ * m-market:GitHub REST API 薄客户端 GitHubAuthRest(docs/archive/2026-08-20-my-configs-design.md §4.2)。
3
3
  *
4
4
  * 职责:账户级元操作 ——
5
5
  * getUser() 验证 token(GET /user)并取回登录名;
@@ -4,7 +4,7 @@
4
4
  * $DSH_HOME/dsh-config-manager/market/market-config.json(schemaVersion=1,仿 sync-config.json):
5
5
  * { "schemaVersion": 1, "markets": [ { "url": "...", "addedAt": "..." } ] }
6
6
  *
7
- * 安全纪律(依据 docs/design/2026-08-19-market-publish-design.md §3.6 安全分析:
7
+ * 安全纪律(依据 docs/archive/2026-08-19-market-publish-design.md §3.6 安全分析:
8
8
  * 「不新增任何写路径、不持有凭据」+ validateRepoUrl 拒绝 userinfo):
9
9
  * - 只存 url(拒绝 userinfo,复用 validateRepoUrl)+ addedAt;无任何凭据;
10
10
  * - url 去重(同 url 再 add 视为幂等,不重复登记)。
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * src/market/** 的领域消息目录(zh 源语言 / en 镜像)——「英文界面零中文」迁移(t5)。
3
3
  *
4
- * 口径(与 src/core/messages.ts 一致,见 docs/design/2026-10-08-i18n-en-hardcoding.md):
4
+ * 口径(与 src/core/messages.ts 一致,见 docs/archive/2026-10-08-i18n-en-hardcoding.md):
5
5
  * - zh 值 = 迁移前的既有中文文案**逐字不变**(既有测试断言依赖它,只允许新增 en);
6
6
  * - en 值类型为 Record<keyof typeof zh, string> —— 缺键/多键即编译错误;
7
7
  * - 动态明细一律走 {param} 插值传参,不得丢信息;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * m-market:MyRepoService —— 「一键上传 / 我的配置」上传编排(docs/design/2026-08-20-my-configs-design.md §4.2/§4.3/§4.4/§4.5)。
2
+ * m-market:MyRepoService —— 「一键上传 / 我的配置」上传编排(docs/archive/2026-08-20-my-configs-design.md §4.2/§4.3/§4.4/§4.5)。
3
3
  *
4
4
  * 数据流(upload / update 共用 runPublish 状态机):
5
5
  * ① 登录(rest.getUser)→ login(401 → unauthorized,明确可分类)
@@ -1,5 +1,5 @@
1
1
  /**
2
- * m-market:市场条目包生成(发布向导核心,docs/design/2026-08-19-market-publish-design.md §3.4)。
2
+ * m-market:市场条目包生成(发布向导核心,docs/archive/2026-08-19-market-publish-design.md §3.4)。
3
3
  *
4
4
  * 职责:把「用户配置 zip + 用户填写元数据」转换为市场条目(L2 manifest + config.zip 的
5
5
  * SHA-256 + sections),供发布向导展示与引导推送。纯函数、零磁盘写入(zipBytes 内存传入,
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * m-market:市场只读读取通道(MarketReader / GitMarketReader)。
3
3
  *
4
- * 与 docs/design/2026-08-19-market-publish-design.md §3.2「GitMarketReader:按条目选择仓库」对齐:
4
+ * 与 docs/archive/2026-08-19-market-publish-design.md §3.2「GitMarketReader:按条目选择仓库」对齐:
5
5
  * - 市场用「只读 git fetch」,不复用 GitTransport 的写路径(commit/push/snapshots/<id>/ 布局);
6
6
  * - 复用点:git 命令执行层(execFile promise 封装 / 脱敏 mask / SnapshotFs)+ validateRepoUrl;
7
7
  * - 每次读取:ensureRepo() 首次 git clone --depth 1,已存在副本则快进到远端(显式 refspec fetch +
8
8
  * merge --ff-only,不读 FETCH_HEAD;参数见 src/utils/git-fast-forward.ts);整段在工作副本锁内;
9
9
  * - 默认公开市场不注入凭据(repoUrl 拒绝 userinfo);二期私有市场才走 token credential helper;
10
10
  * - itemId 必须过 assertSafeItemId(防 items/<id>/ 越界);
11
- * - 条目级来源仓库(方案 B,docs/design/2026-08-19-market-publish-design.md §3.2):
11
+ * - 条目级来源仓库(方案 B,docs/archive/2026-08-19-market-publish-design.md §3.2):
12
12
  * readItemManifest/readItemZip 接受可选 repo,读取目录 = repo ?? url;workDir 由调用方按
13
13
  * 来源仓库 url-hash 分目录,index.json 永远从市场仓库读。
14
14
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * m-market:GitHub 仓库 URL 解析(纯函数,node 可测)。
3
- * docs/design/2026-08-21-market-star-filter-sort-design.md §3.1.2。
3
+ * docs/archive/2026-08-21-market-star-filter-sort-design.md §3.1.2。
4
4
  *
5
5
  * 职责:从条目来源仓库 URL(`https://github.com/<owner>/<repo>[.git]`)解析出
6
6
  * `{ owner, repo }`,供 star 查询(getRepoStarsPublic)使用。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * m-market:市场条目安全校验管线(依据 docs/design/2026-08-19-market-publish-design.md
2
+ * m-market:市场条目安全校验管线(依据 docs/archive/2026-08-19-market-publish-design.md
3
3
  * §3.6 安全分析——该节明确引用本模块的校验管线作为威胁缓解)。
4
4
  * 下载条目(config.zip)后、生成 ImportPlan 之前依次执行,全部纯函数、node 可测。
5
5
  *
@@ -102,7 +102,7 @@ export function validateMarketItem(itemId, manifestRaw, zipBytes) {
102
102
  if (!enabled)
103
103
  continue;
104
104
  // 市场条目禁止分区(BANNED_MARKET_SECTIONS:sessions 历史会话 / pluginFiles 任意文件 / self 本地环境):
105
- // 与 secrets 同级硬约束(产品决策 2026-08-19,guide docs/spec/market-index-v1.md)。
105
+ // 与 secrets 同级硬约束(产品决策 2026-08-19,guide docs/contracts/market-index-v1.md)。
106
106
  if (BANNED_MARKET_SECTIONS.includes(sectionId)) {
107
107
  return { status: 'invalid', errors: [marketMsg('market.security.bannedSection', { section: sectionId })], warnings, manifest, internalManifest, sections: [], checksumsOk: true };
108
108
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * m-market:仓库 star 缓存(StarCache)。
3
- * docs/design/2026-08-21-market-star-filter-sort-design.md §3.1.3。
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 个仓库、
@@ -26,7 +26,7 @@ export type MarketPublishMode = 'migrate' | 'share';
26
26
  */
27
27
  export declare const MAX_MARKET_ZIP_BYTES: number;
28
28
  /**
29
- * 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/spec/market-index-v1.md):
29
+ * 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/contracts/market-index-v1.md):
30
30
  * - sessions:历史会话,含个人交互记录/上下文;
31
31
  * - pluginFiles:任意文件直通(目录放啥带啥),无内容过滤,最易泄漏 token/密钥文件;
32
32
  * - self:本地环境专属(sync 通道 URL / WebDAV 地址 / 市场配置 / UI 偏好),无分享价值且泄漏环境信息。
@@ -8,7 +8,7 @@ export const MARKET_ITEM_SCHEMA_VERSION = 1;
8
8
  */
9
9
  export const MAX_MARKET_ZIP_BYTES = 64 * 1024 * 1024;
10
10
  /**
11
- * 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/spec/market-index-v1.md):
11
+ * 市场条目禁止携带的分区(产品决策 2026-08-19,guide docs/contracts/market-index-v1.md):
12
12
  * - sessions:历史会话,含个人交互记录/上下文;
13
13
  * - pluginFiles:任意文件直通(目录放啥带啥),无内容过滤,最易泄漏 token/密钥文件;
14
14
  * - self:本地环境专属(sync 通道 URL / WebDAV 地址 / 市场配置 / UI 偏好),无分享价值且泄漏环境信息。
package/lib/market/url.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * m-market:市场仓库地址校验(纯函数,node 可测)。
3
3
  *
4
- * 设计文档 docs/design/2026-08-19-market-publish-design.md §3.1:
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 强制。
@@ -109,7 +109,7 @@ export declare class DshProfileManager {
109
109
  /** 单个链接的重指向(失败保持原样:源档案还在时仍旧可用,不让整次复制失败)。 */
110
110
  private relinkCopiedEntry;
111
111
  /**
112
- * 物理删除 profile 目录(rmSync recursive;目录内 junction 只删链接本身)。
112
+ * 物理删除 profile 目录(removeTreeSync;目录内 junction 只删链接本身,删不干净报 deleteFailed)。
113
113
  * 当前运行中的 profile 需要 allowCurrent=true 显式确认(删除会让重启后的实例直接失败)。
114
114
  *
115
115
  * Desktop 独占档案(desktop)**一律拒绝**(连 allowCurrent 也不行):它由桌面端应用自己
@@ -18,14 +18,17 @@
18
18
  * 历史上这里还有一个 `<dataDir>/next-profile`「下次启动」标记——DSH 根本没有消费者,
19
19
  * 只会误导用户(2026-09 按产品决策整体移除,连同前端按钮)。
20
20
  *
21
- * 物理删除:remove() 走 rmSync(recursive),profile 目录内的 junction(pnpm 链接)
22
- * 只删链接本身,不会跟随进 pnpm store。
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 } from 'node:fs';
25
27
  // 复制走 async fs(整档案上万个文件,cpSync 会把宿主事件循环卡住二十多秒)
26
- import { copyFile, cp, mkdir, readdir, readlink, rm, stat, symlink, unlink } from 'node:fs/promises';
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.js';
31
+ import { removeTree, removeTreeSync } from '../utils/remove-tree.js';
29
32
  import { isRecord } from '../utils/guards.js';
30
33
  import { resolveProfileDir, validateProfileName } from '../core/plugin-cli.js';
31
34
  import { readTextSafe } from './dsh-profile-io.js';
@@ -74,9 +77,15 @@ function isInsideDir(root, candidate) {
74
77
  }
75
78
  /** t89:profiles 根目录枚举失败的原因码(诊断/日志用)。 */
76
79
  export const PROFILES_ROOT_UNREADABLE = 'profiles-root-unreadable';
77
- /** 回滚复制目标目录的缺省删除实现(递归强制;不存在不算错)。 */
80
+ /**
81
+ * 回滚复制目标目录的缺省删除实现(不存在不算错)。
82
+ *
83
+ * 必须走 removeTree 而不是 fs.rm(recursive):半截副本里可能已经有指向
84
+ * `.dsh-module-fallback` 的悬空 junction,fs.rm 会「成功」却一个字节都不删,
85
+ * 回滚于是无声失败。
86
+ */
78
87
  const defaultProfileRemove = async (target) => {
79
- await rm(target, { recursive: true, force: true });
88
+ await removeTree(target);
80
89
  };
81
90
  /**
82
91
  * 复制失败时回滚目标目录(cross-F3 收尾 / tech-debt #5)。
@@ -398,7 +407,7 @@ export class DshProfileManager {
398
407
  }
399
408
  }
400
409
  /**
401
- * 物理删除 profile 目录(rmSync recursive;目录内 junction 只删链接本身)。
410
+ * 物理删除 profile 目录(removeTreeSync;目录内 junction 只删链接本身,删不干净报 deleteFailed)。
402
411
  * 当前运行中的 profile 需要 allowCurrent=true 显式确认(删除会让重启后的实例直接失败)。
403
412
  *
404
413
  * Desktop 独占档案(desktop)**一律拒绝**(连 allowCurrent 也不行):它由桌面端应用自己
@@ -414,7 +423,17 @@ export class DshProfileManager {
414
423
  if (name === this.currentProfile() && opts.allowCurrent !== true) {
415
424
  throw new DshProfileError('currentProfile');
416
425
  }
417
- rmSync(dir, { recursive: true, force: true });
426
+ // 不用 rmSync(recursive):悬空 junction 会让它静默空转(见 utils/remove-tree.ts 头注)。
427
+ // 删不掉必须变成可见错误码,绝不回 200 —— 那正是「点了删除、档案还在」的成因。
428
+ try {
429
+ removeTreeSync(dir);
430
+ }
431
+ catch (error) {
432
+ throw new DshProfileError('deleteFailed', error instanceof Error ? error.message : String(error));
433
+ }
434
+ if (existsSync(dir)) {
435
+ throw new DshProfileError('deleteFailed', `profile directory still exists after removal: ${dir}`);
436
+ }
418
437
  }
419
438
  /**
420
439
  * cross-F3:目标目录 = **正常 profile(有 package.json)** 或 **中断的复制残留(有进行中标记)**;
@@ -241,7 +241,9 @@ export type DshProfileErrorCode = 'invalidName' | 'reservedName' | 'exists' | 'n
241
241
  /** 复制档案中途失败(目标目录已回滚,磁盘上不留半套副本) */
242
242
  | 'copyFailed'
243
243
  /** 该档案由 Desktop 应用独占管理(启动 / 删除 / 改名一律拒绝,操作它会让桌面端起不来) */
244
- | 'managedProfile';
244
+ | 'managedProfile'
245
+ /** 目录删不干净(被占用 / 权限不足;message 里附底层原因)—— 绝不是「删成功」 */
246
+ | 'deleteFailed';
245
247
  /** 复制档案的非致命告警码(UI 按码映射文案,绝不静默)。 */
246
248
  export type DshProfileCopyWarning =
247
249
  /** 副本没有 node_modules 却声明了依赖:直接启动会解析不到 bundle,必须先装依赖 */