dsh-config-manager 0.4.2 → 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.
Files changed (263) hide show
  1. package/README.md +24 -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 +19 -41
  13. package/lib/client.js +863 -722
  14. package/lib/core/access-mode.d.ts +25 -0
  15. package/lib/core/access-mode.js +28 -0
  16. package/lib/core/backup.d.ts +11 -0
  17. package/lib/core/backup.js +27 -0
  18. package/lib/core/env-lock-lifecycle.d.ts +17 -3
  19. package/lib/core/env-lock-lifecycle.js +38 -0
  20. package/lib/core/external-failure.d.ts +9 -0
  21. package/lib/core/external-failure.js +50 -0
  22. package/lib/core/local-plugin-host.d.ts +9 -7
  23. package/lib/core/local-plugin-host.js +109 -15
  24. package/lib/core/local-plugin-pack.d.ts +20 -0
  25. package/lib/core/local-plugin-pack.js +18 -3
  26. package/lib/core/mcp-connector-store.d.ts +13 -0
  27. package/lib/core/mcp-connector-store.js +16 -1
  28. package/lib/core/messages-core.d.ts +45 -0
  29. package/lib/core/messages-core.js +92 -0
  30. package/lib/core/messages.d.ts +1 -0
  31. package/lib/core/messages.js +6 -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-data-registry.d.ts +1 -1
  38. package/lib/core/plugin-data-registry.js +1 -1
  39. package/lib/core/restore-plan-fingerprint.d.ts +2 -0
  40. package/lib/core/restore-plan-fingerprint.js +18 -0
  41. package/lib/core/restore-resume.d.ts +1 -1
  42. package/lib/core/restore-resume.js +1 -1
  43. package/lib/core/restore.d.ts +5 -0
  44. package/lib/core/restore.js +4 -1
  45. package/lib/core/types.d.ts +12 -0
  46. package/lib/foreign/claude-sessions.d.ts +1 -1
  47. package/lib/foreign/claude-sessions.js +1 -1
  48. package/lib/foreign/registry.js +1 -1
  49. package/lib/foreign/types.d.ts +1 -1
  50. package/lib/index.d.ts +15 -15
  51. package/lib/index.js +65 -72
  52. package/lib/market/git-file-writer.js +1 -1
  53. package/lib/market/github-repos.js +1 -1
  54. package/lib/market/market-config.js +1 -1
  55. package/lib/market/messages-market.js +1 -1
  56. package/lib/market/my-repo.js +1 -1
  57. package/lib/market/prepare.js +1 -1
  58. package/lib/market/reader.js +2 -2
  59. package/lib/market/repo-url.d.ts +1 -1
  60. package/lib/market/security.js +2 -2
  61. package/lib/market/star-cache.d.ts +1 -1
  62. package/lib/market/types.d.ts +1 -1
  63. package/lib/market/types.js +1 -1
  64. package/lib/market/url.js +1 -1
  65. package/lib/routes/backup.js +17 -9
  66. package/lib/routes/index.d.ts +1 -1
  67. package/lib/routes/kit.d.ts +42 -3
  68. package/lib/routes/kit.js +43 -3
  69. package/lib/routes/market.d.ts +1 -1
  70. package/lib/routes/market.js +3 -60
  71. package/lib/routes/model-tools-deps.d.ts +41 -0
  72. package/lib/routes/model-tools-deps.js +18 -0
  73. package/lib/routes/recovery.js +5 -3
  74. package/lib/routes/request-trust.d.ts +28 -0
  75. package/lib/routes/request-trust.js +65 -0
  76. package/lib/routes/route-support.d.ts +18 -26
  77. package/lib/routes/route-support.js +19 -32
  78. package/lib/routes/snapshots.d.ts +1 -1
  79. package/lib/routes/snapshots.js +4 -40
  80. package/lib/routes/sync.js +40 -28
  81. package/lib/schema/index.d.ts +2 -2
  82. package/lib/schema/index.js +2 -2
  83. package/lib/schema/section-registry.d.ts +5 -3
  84. package/lib/schema/section-registry.js +7 -3
  85. package/lib/security/secret-scanner.js +1 -1
  86. package/lib/sync/apply-bundle.d.ts +50 -0
  87. package/lib/sync/apply-bundle.js +60 -0
  88. package/lib/sync/autosync-scheduler.d.ts +9 -0
  89. package/lib/sync/autosync-scheduler.js +118 -89
  90. package/lib/sync/backup-scheduler.js +5 -4
  91. package/lib/sync/blob-store.d.ts +2 -2
  92. package/lib/sync/git/git-transport.d.ts +12 -0
  93. package/lib/sync/git/git-transport.js +50 -2
  94. package/lib/sync/merge.d.ts +2 -0
  95. package/lib/sync/merge.js +28 -0
  96. package/lib/sync/messages.d.ts +4 -0
  97. package/lib/sync/messages.js +9 -2
  98. package/lib/sync/s3/s3-transport.d.ts +1 -1
  99. package/lib/sync/s3/s3-transport.js +1 -1
  100. package/lib/sync/sync-engine.d.ts +4 -4
  101. package/lib/sync/sync-engine.js +25 -26
  102. package/lib/sync/sync-scope-boot.d.ts +34 -0
  103. package/lib/sync/sync-scope-boot.js +71 -0
  104. package/lib/sync/sync-scope.d.ts +103 -0
  105. package/lib/sync/sync-scope.js +229 -0
  106. package/lib/sync/sync-selection.d.ts +17 -4
  107. package/lib/sync/sync-selection.js +40 -14
  108. package/lib/sync/transport.d.ts +4 -1
  109. package/lib/sync/transport.js +6 -0
  110. package/lib/sync/webdav/webdav-transport.js +1 -1
  111. package/lib/sync/workspace-merge.d.ts +36 -0
  112. package/lib/sync/workspace-merge.js +152 -0
  113. package/lib/ui/backup-schedule.d.ts +13 -2
  114. package/lib/ui/backup-schedule.js +3 -0
  115. package/lib/ui/snapshots-view.d.ts +16 -0
  116. package/lib/ui/snapshots-view.js +21 -0
  117. package/lib/utils/env-lock.d.ts +96 -0
  118. package/lib/utils/env-lock.js +332 -111
  119. package/lib/utils/messages-utils.d.ts +6 -0
  120. package/lib/utils/messages-utils.js +17 -1
  121. package/lib/utils/patch-yaml.js +1 -1
  122. package/lib/utils/zip.js +1 -1
  123. package/package.json +3 -2
  124. package/src/adapters/mcp.test.ts +28 -0
  125. package/src/adapters/mcp.ts +33 -0
  126. package/src/adapters/plugins.test.ts +49 -0
  127. package/src/adapters/plugins.ts +9 -1
  128. package/src/adapters/pnpm-workspace.ts +1 -1
  129. package/src/adapters/self.test.ts +39 -1
  130. package/src/adapters/self.ts +20 -2
  131. package/src/adapters/workspaces.ts +1 -1
  132. package/src/cli/restore-resume.ts +1 -1
  133. package/src/cli/web/page.ts +2 -2
  134. package/src/client/about/AboutPanel.tsx +8 -1
  135. package/src/client/about/about-view.test.ts +1 -1
  136. package/src/client/about/about-view.ts +1 -1
  137. package/src/client/api.ts +1 -6
  138. package/src/client/chat/chat-entry-view.test.ts +1 -1
  139. package/src/client/chat/chat-slots.ts +1 -1
  140. package/src/client/chat/rollback-diff-tab.ts +1 -1
  141. package/src/client/client-types.ts +1 -1
  142. package/src/client/common/access-mode.ts +21 -0
  143. package/src/client/common/routes.ts +1 -5
  144. package/src/client/css-scale-guard.test.ts +1 -1
  145. package/src/client/home/HomePanel.tsx +34 -6
  146. package/src/client/library/ArtifactRow.tsx +14 -2
  147. package/src/client/library/LibraryPanel.tsx +44 -0
  148. package/src/client/locales/about.ts +6 -0
  149. package/src/client/locales/overview.ts +18 -2
  150. package/src/client/locales/sessions.ts +3 -0
  151. package/src/client/market/MyConfigsView.tsx +1 -1
  152. package/src/client/market/market-api.ts +2 -14
  153. package/src/client/market/market-locales.ts +1 -1
  154. package/src/client/market/market-view.ts +3 -3
  155. package/src/client/market/my-configs-api.ts +1 -1
  156. package/src/client/market/my-configs-view.ts +1 -1
  157. package/src/client/recovery/recovery-locales.test.ts +1 -1
  158. package/src/client/run-store.ts +1 -1
  159. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
  160. package/src/client/sync/history-model.test.ts +28 -7
  161. package/src/client/sync/history-model.ts +6 -3
  162. package/src/client/sync/sync-locales.ts +10 -4
  163. package/src/client/sync/sync-view.ts +1 -1
  164. package/src/core/access-mode.ts +37 -0
  165. package/src/core/analyzer-cache.test.ts +1 -1
  166. package/src/core/backup.test.ts +45 -1
  167. package/src/core/backup.ts +25 -0
  168. package/src/core/disk-usage.test.ts +2 -0
  169. package/src/core/env-lock-lifecycle.ts +33 -3
  170. package/src/core/external-failure.test.ts +60 -0
  171. package/src/core/external-failure.ts +54 -0
  172. package/src/core/integrity-extra-entries.test.ts +1 -1
  173. package/src/core/local-plugin-host.test.ts +134 -0
  174. package/src/core/local-plugin-host.ts +122 -17
  175. package/src/core/local-plugin-pack.ts +39 -3
  176. package/src/core/mcp-connector-store.ts +26 -1
  177. package/src/core/messages-core.ts +94 -0
  178. package/src/core/messages.ts +6 -0
  179. package/src/core/model-tool-plans.test.ts +111 -0
  180. package/src/core/model-tool-plans.ts +170 -0
  181. package/src/core/model-tools.test.ts +212 -12
  182. package/src/core/model-tools.ts +710 -38
  183. package/src/core/phase3-host.ts +10 -2
  184. package/src/core/phase3-production-integration.test.ts +43 -0
  185. package/src/core/plugin-data-registry.ts +1 -1
  186. package/src/core/restore-plan-fingerprint.ts +19 -0
  187. package/src/core/restore-resume.ts +1 -1
  188. package/src/core/restore.ts +9 -1
  189. package/src/core/types.ts +12 -0
  190. package/src/foreign/claude-sessions.ts +3 -3
  191. package/src/foreign/registry.ts +1 -1
  192. package/src/foreign/types.ts +1 -1
  193. package/src/index.ts +96 -103
  194. package/src/market/git-file-writer.ts +1 -1
  195. package/src/market/github-repos.test.ts +1 -1
  196. package/src/market/github-repos.ts +1 -1
  197. package/src/market/market-config.ts +1 -1
  198. package/src/market/messages-market.ts +1 -1
  199. package/src/market/my-repo.test.ts +1 -1
  200. package/src/market/my-repo.ts +1 -1
  201. package/src/market/prepare.test.ts +1 -1
  202. package/src/market/prepare.ts +1 -1
  203. package/src/market/reader.ts +2 -2
  204. package/src/market/repo-url.ts +1 -1
  205. package/src/market/security.ts +2 -2
  206. package/src/market/star-cache.ts +1 -1
  207. package/src/market/types.ts +1 -1
  208. package/src/market/url.test.ts +1 -1
  209. package/src/market/url.ts +1 -1
  210. package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
  211. package/src/routes/backup.ts +16 -9
  212. package/src/routes/index.ts +1 -1
  213. package/src/routes/kit.ts +71 -5
  214. package/src/routes/market.ts +2 -59
  215. package/src/routes/model-tools-deps.ts +56 -0
  216. package/src/routes/recovery.ts +5 -3
  217. package/src/routes/request-trust.ts +97 -0
  218. package/src/routes/route-support.ts +49 -36
  219. package/src/routes/snapshots.ts +4 -40
  220. package/src/routes/sync.ts +39 -27
  221. package/src/schema/index.ts +2 -2
  222. package/src/schema/manifest-schema.test.ts +2 -2
  223. package/src/schema/registry.test.ts +1 -1
  224. package/src/schema/section-registry.ts +9 -4
  225. package/src/security/redaction.test.ts +1 -1
  226. package/src/security/secret-scanner.test.ts +2 -2
  227. package/src/security/secret-scanner.ts +1 -1
  228. package/src/sync/apply-bundle.ts +104 -0
  229. package/src/sync/autosync-scheduler.test.ts +180 -6
  230. package/src/sync/autosync-scheduler.ts +132 -92
  231. package/src/sync/backup-scheduler.test.ts +11 -4
  232. package/src/sync/backup-scheduler.ts +5 -4
  233. package/src/sync/blob-store.ts +2 -2
  234. package/src/sync/git/git-transport.test.ts +62 -0
  235. package/src/sync/git/git-transport.ts +54 -3
  236. package/src/sync/merge.ts +29 -0
  237. package/src/sync/messages.ts +9 -2
  238. package/src/sync/s3/s3-transport.ts +1 -1
  239. package/src/sync/sync-engine.test.ts +238 -2
  240. package/src/sync/sync-engine.ts +25 -26
  241. package/src/sync/sync-preview-push.test.ts +2 -1
  242. package/src/sync/sync-scope-boot.ts +87 -0
  243. package/src/sync/sync-scope.test.ts +154 -0
  244. package/src/sync/sync-scope.ts +256 -0
  245. package/src/sync/sync-selection.test.ts +76 -2
  246. package/src/sync/sync-selection.ts +40 -13
  247. package/src/sync/transport.test.ts +21 -1
  248. package/src/sync/transport.ts +12 -0
  249. package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
  250. package/src/sync/webdav/webdav-transport.ts +1 -1
  251. package/src/sync/workspace-merge.test.ts +110 -0
  252. package/src/sync/workspace-merge.ts +180 -0
  253. package/src/ui/backup-schedule.test.ts +5 -0
  254. package/src/ui/backup-schedule.ts +21 -2
  255. package/src/ui/session-issue-labels.ts +1 -1
  256. package/src/ui/snapshots-view.test.ts +32 -0
  257. package/src/ui/snapshots-view.ts +34 -0
  258. package/src/utils/env-lock.test.ts +242 -9
  259. package/src/utils/env-lock.ts +247 -13
  260. package/src/utils/messages-utils.ts +17 -1
  261. package/src/utils/patch-yaml.ts +1 -1
  262. package/src/utils/zip.ts +1 -1
  263. package/src/client/CLIENT_DEPENDENCIES.md +0 -94
@@ -46,36 +46,23 @@ import { isSameOrChild } from '../utils/paths.ts'
46
46
  import { parseZip } from '../utils/zip.ts'
47
47
 
48
48
  /**
49
- * 同步 token 的 DSH credentials 引用名(POSIX env-var 形态,满足 CredentialRef 品牌要求)。
50
- * token 只经 credentialRef 读写(写入由请求体触发,读取在每次 git 网络操作时 resolve),
51
- * 永不进 repoUrl / argv / commit / 同步文件 / 日志。
49
+ * 同步凭据槽位名与 per-profile 作用域:**唯一声明处已迁到 `src/sync/sync-scope.ts`**
50
+ * (那里也持有 `syncScopeFor` / `adoptLegacySyncScope`)。此文件只 re-export,
51
+ * 保持 `src/index.ts` 与测试既有的 import 面与符号名不变(值不变,只是多了可选档案后缀)。
52
52
  */
53
- export const SYNC_CREDENTIAL_REF = 'DSH_CONFIG_MANAGER_SYNC_TOKEN'
54
-
55
- /**
56
- * WebDAV 通道口令的独立 DSH credentials 引用(与 git token 槽位分离)。
57
- * 口令只经 credentialRef 读写(写入由请求体触发,读取在每次 WebDAV 网络操作时
58
- * by WebDavTransport 经注入的 getPassword() resolve),永不进 URL / 请求头 / 日志。
59
- */
60
- export const SYNC_WEBDAV_CREDENTIAL_REF = 'DSH_CONFIG_MANAGER_SYNC_WEBDAV_PASSWORD'
61
-
62
- /**
63
- * 同步快照「加密密码 / 解密密码」的 DSH credentials 引用名前缀(按通道各自独立)。
64
- *
65
- * 为什么放 DSH credentials:加密/解密密码跨会话必须可用(否则每次推送都要重新输入),
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
- /** parseSyncBody 的凭据写入依赖(只用到 set;测试可注入内存 mock)。 */
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(SYNC_WEBDAV_CREDENTIAL_REF), password)
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: SYNC_WEBDAV_CREDENTIAL_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(SYNC_CREDENTIAL_REF), token)
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: SYNC_CREDENTIAL_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) {
@@ -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, setSnapshotPinned } from '../core/restore.ts'
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
  // 点开某个文件才请求(列表阶段只做轻量统计),避免会话类快照几百个文件时拖死弹窗。
@@ -41,7 +41,7 @@ function extractPathMappings(body: Record<string, unknown>): PathMapping[] {
41
41
  }
42
42
  return out
43
43
  }
44
- import { REVIEW_KINDS, ROUTE_TIMEOUT_MS, SYNC_CREDENTIAL_REF, SYNC_WEBDAV_CREDENTIAL_REF, SyncRouteError, buildAutosyncStatus, buildAutosyncStatusByChannel, credentialRef, extractSyncSections, extractSyncSessions, isAutosyncInterval, isGitHubAuthMissing, isToolchainChangeItem, planToConfirmItems, syncPasswordRef, withTimeout, writeSyncRouteError } from './route-support.ts'
44
+ import { REVIEW_KINDS, ROUTE_TIMEOUT_MS, SyncRouteError, buildAutosyncStatus, buildAutosyncStatusByChannel, credentialRef, extractSyncSections, extractSyncSessions, isAutosyncInterval, isGitHubAuthMissing, isToolchainChangeItem, planToConfirmItems, syncScopeOrDefault, withTimeout, writeSyncRouteError } from './route-support.ts'
45
45
  import { GitHubApiError } from '../market/github-repos.ts'
46
46
  import type { SectionId } from '../schema/types.ts'
47
47
  import { redact } from '../security/redaction.ts'
@@ -81,14 +81,16 @@ interface CredentialDescriber {
81
81
  async function cloudChannelViews(
82
82
  full: FullSyncConfig | null,
83
83
  credentials: CredentialDescriber,
84
+ /** 通道密钥槽位(已按档案作用域;默认档案 = 历史槽位名)。 */
85
+ cloudSecret: (provider: Parameters<typeof cloudSecretRef>[0]) => string,
84
86
  ): Promise<{ s3?: CloudS3ChannelView; gist?: CloudGistChannelView }> {
85
87
  const out: { s3?: CloudS3ChannelView; gist?: CloudGistChannelView } = {}
86
88
  if (full?.s3 !== undefined) {
87
- const info = await credentials.describe(credentialRef(cloudSecretRef(full.s3.provider)))
89
+ const info = await credentials.describe(credentialRef(cloudSecret(full.s3.provider)))
88
90
  out.s3 = s3ChannelView(full.s3.provider, full.s3, info.configured)
89
91
  }
90
92
  if (full?.gist !== undefined) {
91
- const info = await credentials.describe(credentialRef(cloudSecretRef(GIST_PROVIDER)))
93
+ const info = await credentials.describe(credentialRef(cloudSecret(GIST_PROVIDER)))
92
94
  out.gist = gistChannelView(full.gist, info.configured)
93
95
  }
94
96
  return out
@@ -133,6 +135,16 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
133
135
  tryAppendHistory,
134
136
  withMutationGate,
135
137
  } = env
138
+ /**
139
+ * 凭据槽位一律按**档案作用域**取(见 src/sync/sync-scope.ts):
140
+ * 默认档案(web)沿用历史槽位名,零迁移;其它档案追加 `__<PROFILE>` 后缀 ——
141
+ * 于是不同 profile 可以各自绑定不同的 GitHub 账号 / 仓库而不互相覆盖。
142
+ */
143
+ const syncScope = syncScopeOrDefault(syncDir, env.syncScope)
144
+ const tokenRef = syncScope.tokenRef
145
+ const webdavPasswordRef = syncScope.webdavPasswordRef
146
+ const passwordRef = (kind: 'ENCRYPT' | 'DECRYPT', channel: string): string => syncScope.passwordRef(kind, channel)
147
+ const cloudSecret = (provider: Parameters<typeof cloudSecretRef>[0]): string => syncScope.scopeRef(cloudSecretRef(provider))
136
148
  /** 云端点密钥「只写」端口:值只进 DSH credentials,绝不落盘 / 日志 / 回传(cloudSecretRef 槽位)。 */
137
149
  const cloudSecrets: CloudSecretWriter = {
138
150
  set: async (ref, value) => { await credentials.set(credentialRef(ref), value) },
@@ -142,7 +154,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
142
154
  * T-ui-merge:合并预览 / 合并执行共用的引擎选项。
143
155
  *
144
156
  * 解密密码口径与 /sync/sync 完全一致:请求体优先,其次已保存的 DECRYPT 凭据
145
- * (syncPasswordRef('DECRYPT', channel))。密码只存在于内存,绝不写进响应 / 日志 / 同步文件;
157
+ * (passwordRef('DECRYPT', channel),已按档案作用域)。密码只存在于内存,绝不写进响应 / 日志 / 同步文件;
146
158
  * 明文快照根本不会被解密(引擎只在 manifest.encrypted 时才用密码)。
147
159
  */
148
160
  const mergeEngineOptions = async (
@@ -150,7 +162,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
150
162
  syncCfg: SyncConfig,
151
163
  ): Promise<{ snapshotId?: string; password?: string; pathMappings?: PathMapping[] }> => {
152
164
  const snapshotId = typeof body['snapshotId'] === 'string' && body['snapshotId'] !== '' ? body['snapshotId'] : undefined
153
- const savedDecryptPassword = await resolveSyncPassword(syncPasswordRef('DECRYPT', channelOf(syncCfg)))
165
+ const savedDecryptPassword = await resolveSyncPassword(passwordRef('DECRYPT', channelOf(syncCfg)))
154
166
  const decryptPassword = typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
155
167
  ? body['decryptPassword']
156
168
  : savedDecryptPassword
@@ -206,8 +218,8 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
206
218
  const full = await readFullSyncConfig(syncDir, configIssues)
207
219
  const state = await loadSyncState(syncDir)
208
220
  const [cred, webdavCred] = await Promise.all([
209
- credentials.describe(credentialRef(SYNC_CREDENTIAL_REF)),
210
- credentials.describe(credentialRef(SYNC_WEBDAV_CREDENTIAL_REF)),
221
+ credentials.describe(credentialRef(tokenRef)),
222
+ credentials.describe(credentialRef(webdavPasswordRef)),
211
223
  ])
212
224
  const transport: SyncConfig['transport'] = parseSyncChannel(full?.transport) ?? 'git'
213
225
  // m-self:插件 UI 偏好(上次选择的同步通道;ui-prefs.json,随 self 分区进备份)
@@ -223,7 +235,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
223
235
  }
224
236
  : undefined
225
237
  // 云端点配置视图(只回 secretStored 布尔;与当前通道无关,配置过即回填)
226
- const cloud = await cloudChannelViews(full, credentials)
238
+ const cloud = await cloudChannelViews(full, credentials, cloudSecret)
227
239
  // issue #79 / #104 建议 3:git 工作副本是否已跟随 repoUrl,外加「领先远端提交数 /
228
240
  // 远端快照数」(只读自检;后者是「本地一直没真正备份」的预警依据)。
229
241
  // 读不出来时**如实回传错误**(workDirError),不让状态接口静默少一块信息。
@@ -353,15 +365,15 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
353
365
  if (channel === 's3') {
354
366
  // s3 通道断开 → 清掉**全部**兼容商的密钥槽位(该通道不再指向任何一家;幂等)
355
367
  for (const provider of S3_COMPAT_PROVIDERS) {
356
- await credentials.unset(credentialRef(cloudSecretRef(provider)))
368
+ await credentials.unset(credentialRef(cloudSecret(provider)))
357
369
  }
358
370
  } else if (channel === 'gist') {
359
- await credentials.unset(credentialRef(cloudSecretRef(GIST_PROVIDER)))
371
+ await credentials.unset(credentialRef(cloudSecret(GIST_PROVIDER)))
360
372
  } else {
361
- await credentials.unset(credentialRef(channel === 'git' ? SYNC_CREDENTIAL_REF : SYNC_WEBDAV_CREDENTIAL_REF))
373
+ await credentials.unset(credentialRef(channel === 'git' ? tokenRef : webdavPasswordRef))
362
374
  }
363
- await credentials.unset(credentialRef(syncPasswordRef('ENCRYPT', channel)))
364
- await credentials.unset(credentialRef(syncPasswordRef('DECRYPT', channel)))
375
+ await credentials.unset(credentialRef(passwordRef('ENCRYPT', channel)))
376
+ await credentials.unset(credentialRef(passwordRef('DECRYPT', channel)))
365
377
  const auto = await readAutosyncConfig(syncDir, channel)
366
378
  await writeAutosyncConfig(syncDir, channel, { ...auto, enabled: false, consecutiveFailures: 0 })
367
379
  // 立即让调度器丢掉该通道的定时器(否则内存里的旧排期会继续对已删通道发请求)
@@ -384,13 +396,13 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
384
396
  // 云端点通道经 CloudSecretWriter 只写端口落库(值绝不进 sync-cloud-config.json / 日志 / 回传)
385
397
  await writeSyncConfig(syncDir, syncCfg, cloudSecrets)
386
398
  const [cred, webdavCred] = await Promise.all([
387
- credentials.describe(credentialRef(SYNC_CREDENTIAL_REF)),
388
- credentials.describe(credentialRef(SYNC_WEBDAV_CREDENTIAL_REF)),
399
+ credentials.describe(credentialRef(tokenRef)),
400
+ credentials.describe(credentialRef(webdavPasswordRef)),
389
401
  ])
390
402
  // SEC-03:写完就把落盘结果再读一遍(writeSyncConfig 可能因命名空间合并保留旧值),
391
403
  // 成因而非「写成功」才是客户端要显示的真相;字段恒在(默认空数组)。
392
404
  const configIssues: SyncConfigIssue[] = []
393
- const cloud = await cloudChannelViews(await readFullSyncConfig(syncDir, configIssues), credentials)
405
+ const cloud = await cloudChannelViews(await readFullSyncConfig(syncDir, configIssues), credentials, cloudSecret)
394
406
  writeJson(res, 200, {
395
407
  ok: true,
396
408
  configured: true,
@@ -454,7 +466,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
454
466
  // 已保存的加密密码兜底(DSH credentials;用户不必每次重输)。请求体里的密码优先,
455
467
  // 因为那是用户此刻输入的覆盖值;两者都没有 → 交给 engine 报「加密需要密码」。
456
468
  const pushChannel: SyncTransportType = channelOf(syncCfg)
457
- const effectiveEncryptPassword = encryptPassword ?? await resolveSyncPassword(syncPasswordRef('ENCRYPT', pushChannel))
469
+ const effectiveEncryptPassword = encryptPassword ?? await resolveSyncPassword(passwordRef('ENCRYPT', pushChannel))
458
470
  // sessions 的导出参数(「最新 N 个」/ 逐会话点名);**放行**由引擎的 optInSections 决定
459
471
  const sessions = extractSyncSessions(body)
460
472
  const sessionsOpt = sections !== undefined && sections.includes('sessions') && sessions !== undefined
@@ -505,7 +517,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
505
517
  // 解密密码:请求体 > 已保存(DSH credentials)。明文快照根本不会被解密
506
518
  // (engine.prepareSnapshot 只在 manifest.encrypted 时才用密码),因此「未加密备份
507
519
  // 不会误用密码」是引擎层保证,而不是靠这里猜。密码仅内存,绝不落盘/落日志。
508
- const savedDecryptPassword = await resolveSyncPassword(syncPasswordRef('DECRYPT', channelOf(syncCfg)))
520
+ const savedDecryptPassword = await resolveSyncPassword(passwordRef('DECRYPT', channelOf(syncCfg)))
509
521
  const decryptPassword =
510
522
  typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
511
523
  ? body['decryptPassword']
@@ -563,7 +575,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
563
575
  }),
564
576
  // -------------------------------------------------- sync/github/poll
565
577
  // m-github-oauth:轮询授权结果。凭 flowId 取回宿主登记的 device_code → GitHub 换 token
566
- // → 成功则立即写入 DSH credentials(SYNC_CREDENTIAL_REF,与手动 token 同槽),
578
+ // → 成功则立即写入 DSH credentials(本档案的 token 槽位,与手动 token 同槽),
567
579
  // token 绝不回传浏览器;pending 返回下次轮询延迟;终止态(denied/expired/error)清理登记。
568
580
  endpoint({ path: '/api/dsh-config-manager/sync/github/poll', methods: ['POST'] }, async (req, res) => {
569
581
  const body = await readJsonBody(req)
@@ -585,7 +597,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
585
597
  interval: flow.interval,
586
598
  })
587
599
  if (result.status === 'success' && result.accessToken !== undefined) {
588
- await credentials.set(credentialRef(SYNC_CREDENTIAL_REF), result.accessToken)
600
+ await credentials.set(credentialRef(tokenRef), result.accessToken)
589
601
  githubFlows.delete(flowId)
590
602
  host.log.info('GitHub OAuth 登录成功(token 已写入 DSH credentials)')
591
603
  writeJson(res, 200, { status: 'success', credentialConfigured: true })
@@ -619,7 +631,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
619
631
  writeJson(res, 200, { ok: true })
620
632
  }),
621
633
  // -------------------------------------------------- sync/github/validate
622
- // m-sync-github-valid:校验 SYNC_CREDENTIAL_REF 中已存 token 是否有效(GET /user),
634
+ // m-sync-github-valid:校验本档案 token 槽位中已存 token 是否有效(GET /user),
623
635
  // 供 UI 判定「是否已登录」→ 已登录隐藏 GitHub 登录区块、token 失效则重新展示。
624
636
  // 只回布尔 + 登录名(非敏感),token 值绝不回传;仅 401(无效/过期)→ valid:false,
625
637
  // 其余错误(网络/限流)向上抛,由 UI 兜底(不误判登出)。
@@ -654,7 +666,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
654
666
  // 仓库选择器(issue:同步通道支持「选择已有仓库 / 新建仓库」):
655
667
  // GET → 列出当前用户可见仓库(按最近更新排序),供 UI 下拉选择;
656
668
  // POST → 新建**私有**仓库(body: { name, description? }),返回仓库信息供回填 repoUrl。
657
- // token 来源与 /sync/github/validate 完全一致(DSH credentials 的 SYNC_CREDENTIAL_REF),
669
+ // token 来源与 /sync/github/validate 完全一致(DSH credentials 的本档案 token 槽位),
658
670
  // 401(未登录 / token 失效)单独映射,其余错误走通用 500 —— 与 me 路由同一口径。
659
671
  // 不进 mutation gate:两步都不写本地文件(只读列举 + 幂等元操作),
660
672
  // 而 gate 在 SAFE MODE 下会直接拒绝,会把「选仓库」变成不可用功能。
@@ -802,7 +814,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
802
814
  writeJson(res, 400, { error: 'name must be a .zip file name (no path separators)' })
803
815
  return
804
816
  }
805
- const savedDecryptPassword = await resolveSyncPassword(syncPasswordRef('DECRYPT', channelOf(syncCfg)))
817
+ const savedDecryptPassword = await resolveSyncPassword(passwordRef('DECRYPT', channelOf(syncCfg)))
806
818
  const decryptPassword =
807
819
  typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
808
820
  ? body['decryptPassword']
@@ -901,7 +913,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
901
913
  // 解密密码:请求体 > 已保存(DSH credentials)。明文快照根本不会被解密
902
914
  // (engine.prepareSnapshot 只在 manifest.encrypted 时才用密码),因此「未加密备份
903
915
  // 不会误用密码」是引擎层保证,而不是靠这里猜。密码仅内存,绝不落盘/落日志。
904
- const savedDecryptPassword = await resolveSyncPassword(syncPasswordRef('DECRYPT', channelOf(syncCfg)))
916
+ const savedDecryptPassword = await resolveSyncPassword(passwordRef('DECRYPT', channelOf(syncCfg)))
905
917
  const decryptPassword =
906
918
  typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
907
919
  ? body['decryptPassword']
@@ -1019,7 +1031,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
1019
1031
  // 拿不到密码就 `suppressAncestor` —— 宁可不留祖先(下轮两方合并),也绝不落明文副本。
1020
1032
  const applyDecryptPassword = typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
1021
1033
  ? body['decryptPassword']
1022
- : await resolveSyncPassword(syncPasswordRef('DECRYPT', channelOf(session.config)))
1034
+ : await resolveSyncPassword(passwordRef('DECRYPT', channelOf(session.config)))
1023
1035
  const ancestorOpts = session.encrypted !== true
1024
1036
  ? {}
1025
1037
  : applyDecryptPassword !== undefined && applyDecryptPassword !== ''
@@ -1209,8 +1221,8 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
1209
1221
  // 加密/解密密码持久化(用户要求:勾选即记住,取消勾选或主动删除才清)。
1210
1222
  // 值只写进 DSH credentials(绝不进 sync-selection.json / 日志 / 响应);
1211
1223
  // 清空优先于写入,避免「同一次请求既清又写」产生歧义。
1212
- const encryptRef = syncPasswordRef('ENCRYPT', channel)
1213
- const decryptRef = syncPasswordRef('DECRYPT', channel)
1224
+ const encryptRef = passwordRef('ENCRYPT', channel)
1225
+ const decryptRef = passwordRef('DECRYPT', channel)
1214
1226
  if (body['clearEncryptPassword'] === true) await credentials.unset(credentialRef(encryptRef))
1215
1227
  else if (typeof body['encryptPassword'] === 'string' && body['encryptPassword'] !== '') {
1216
1228
  await credentials.set(credentialRef(encryptRef), body['encryptPassword'])
@@ -9,7 +9,7 @@
9
9
  * 据此实现自己的 importer / exporter(ZIP 内路径与文件类分区前缀的唯一权威);
10
10
  * - 取到**分区注册表**(`SECTION_REGISTRY` / `SectionMeta` / `sectionMeta` / `jsonPathOf` /
11
11
  * `PORTABLE_SECTION_IDS` / `OPT_IN_SYNC_SECTION_IDS` / `DEFAULT_INCLUDED_SECTION_IDS` …)——
12
- * 「有哪些分区、各自什么形态/可移植性」的机器可读唯一来源,与 `docs/spec/` 的分区清单对应;
12
+ * 「有哪些分区、各自什么形态/可移植性」的机器可读唯一来源,与 `docs/contracts/` 的分区清单对应;
13
13
  * - 引用 Bundle Format v1 的全部载荷类型。
14
14
  *
15
15
  * 为什么需要它:此前的 `exports["./schema"]` 指向 `./lib/schema/types.js`,而 `types.ts`
@@ -22,7 +22,7 @@
22
22
  * `./versions.ts`)。`section-registry.ts` 自身仍然只 import 一个**类型**(`type { SectionId }`;
23
23
  * 未注册分区的错误文案 t7 起在 `config.ts`,见那里)。
24
24
  * 目标性质是**零 `node:` / 零 npm / 零 @deepseek-ai 依赖**(headless 消费:
25
- * `docs/spec/headless-consumption.md`;client bundle 自包含)。唯一的跨层依赖是本域消息目录
25
+ * `docs/contracts/headless-consumption.md`;client bundle 自包含)。唯一的跨层依赖是本域消息目录
26
26
  * (`./messages.ts` → `../core/engine-locale.ts`,纯函数、零 node / 零 npm),不破坏该性质;
27
27
  * 除此之外不得 import `../core/*`、`node:*` 或任何 UI / DSH 包。
28
28
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Bundle manifest JSON Schema ↔ 实现绑定测试。
3
3
  *
4
- * 目的:把 `docs/spec/bundle-manifest.schema.json`(Bundle Format v1 的机器可校验形态)
4
+ * 目的:把 `docs/contracts/bundle-manifest.schema.json`(Bundle Format v1 的机器可校验形态)
5
5
  * 焊死在 `src/schema/manifest.ts` 的实现上。规格最大的死法是漂移——文档说一套、代码做一套。
6
6
  *
7
7
  * 方案选择:(a) 手写仅覆盖本 schema 所用关键字的最小校验器,而不是 (b) 退化为
@@ -153,7 +153,7 @@ function validateAgainstSchema(schema: SchemaNode, data: unknown): SchemaIssue[]
153
153
  * 载入 schema 原文(被验证的就是发布出去的那份文件)
154
154
  * ==========================================================================*/
155
155
 
156
- const SCHEMA_PATH = resolve(import.meta.dirname, '..', '..', 'docs', 'spec', 'bundle-manifest.schema.json');
156
+ const SCHEMA_PATH = resolve(import.meta.dirname, '..', '..', 'docs', 'contracts', 'bundle-manifest.schema.json');
157
157
  const SCHEMA = JSON.parse(readFileSync(SCHEMA_PATH, 'utf8')) as SchemaNode;
158
158
 
159
159
  /* ============================================================================
@@ -101,7 +101,7 @@ test('registry: 派生的可移植性 / 可选分区 / 默认勾选与既有声
101
101
  'settings', 'ui', 'providers', 'plugins', 'prompts', 'skills',
102
102
  'agentPresets', 'agentInstructions', 'self',
103
103
  ]);
104
- assert.deepEqual([...OPT_IN_SYNC_SECTION_IDS], ['mcp', 'sessions'], '可选分区 = syncOptIn !== off(issue #78)');
104
+ assert.deepEqual([...OPT_IN_SYNC_SECTION_IDS], ['mcp', 'workspaces', 'sessions'], '可选分区 = syncOptIn !== off(issue #78;#127 起 workspaces 手动可选)');
105
105
  assert.deepEqual([...DEFAULT_INCLUDED_SECTION_IDS], [
106
106
  'settings', 'ui', 'providers', 'plugins', 'mcp', 'prompts', 'skills',
107
107
  'agentPresets', 'agentInstructions', 'workspaces', 'credentialsStatus', 'self',
@@ -144,7 +144,8 @@ export interface SectionMeta {
144
144
  * 同步准入档位(非 portable 分区的显式准入;portable 分区恒为 'off',走默认通道)。
145
145
  * - 'off' = 永不进入同步通道;
146
146
  * - 'manual' = 必须用户在同步分区弹窗里显式勾选,且**只跟随用户驱动的手动 push/pull**;
147
- * 自动同步永不带(内容隐私 / 设备相关,例如 sessions);
147
+ * 自动同步永不带(内容隐私 / 设备相关,例如 sessions;路径与本机绑定的
148
+ * workspaces 同属 manual —— 它要随会话一起走,但绝不悄悄上下行);
148
149
  * - 'auto' = 用户显式勾选后,手动与自动同步都带(内容可跨机,只是命令 / 路径可能与
149
150
  * 目标机不同,例如 mcp)。
150
151
  * **必填**(Record<SectionId, SectionMeta> 强制):新增分区漏填即 tsc 报错。
@@ -180,7 +181,7 @@ export const SECTION_DATA_VERSION = 1 as const;
180
181
  * - `portability` / `defaultIncluded` ← 各 adapter 的 `portability` / `defaultIncluded`,
181
182
  * 以及 `ui/export-flow.ts` 的内置目录、`market/prepare.ts` 的 SECTION_PORTABILITY
182
183
  * (三者此前必须人工保持一致,现以本表为源);
183
- * - `syncOptIn` ← **本表声明**(mcp='auto' / sessions='manual' / 其余 'off'),
184
+ * - `syncOptIn` ← **本表声明**(mcp='auto' / workspaces='manual' / sessions='manual' / 其余 'off'),
184
185
  * `sync/sync-selection.ts` 的 OPT_IN_SYNC_SECTIONS 与 `AUTO_SYNC_OPT_IN_SECTION_IDS` 都是它的派生视图
185
186
  * (此前是两份手写字面量、零护栏 —— issue #78 收敛为单一事实源);
186
187
  * - `applyOrder` ← 历史 SECTION_IDS 数组顺序(1 起,连续)。
@@ -318,7 +319,10 @@ export const SECTION_REGISTRY: Record<SectionId, SectionMeta> = {
318
319
  applyOrder: 10,
319
320
  riskTier: 'medium',
320
321
  portability: 'platformSpecific',
321
- syncOptIn: 'off',
322
+ // issue #127:工作区改为**手动可选**同步分区 —— 会话要能在目标机的工作区里显示出来,
323
+ // 包内就必须有指向它 cwd 的工作区记录(DSH 按 realpath(cwd) == workspace.path 归组)。
324
+ // 仍是 platformSpecific(路径与机器绑定,靠 PathMapping 重定基),故只能手动放行、绝不进自动同步。
325
+ syncOptIn: 'manual',
322
326
  defaultIncluded: true,
323
327
  configSnapshot: true,
324
328
  },
@@ -478,7 +482,8 @@ export const PORTABLE_SECTION_IDS: readonly SectionId[] = SECTION_IDS.filter(
478
482
 
479
483
  /**
480
484
  * 同步「可选分区」:非 portable、必须推/拉两侧显式放行的分区(syncOptIn !== 'off')。
481
- * 当前 = ['mcp', 'sessions']。**顺序按 applyOrder**(mcp=5 在 sessions=14 之前)。
485
+ * 当前 = ['mcp', 'workspaces', 'sessions']。**顺序按 applyOrder**
486
+ * (mcp=5 → workspaces=10 → sessions=14)。
482
487
  */
483
488
  export const OPT_IN_SYNC_SECTION_IDS: readonly SectionId[] = SECTION_IDS.filter(
484
489
  (id) => SECTION_REGISTRY[id].syncOptIn !== 'off',
@@ -114,7 +114,7 @@ test('t78-e(正例清单 ≥8 组):散文/字段名/开关/路径必须原
114
114
  'the bearer scheme is defined by RFC 7235',
115
115
  'run with --api-key-required to continue',
116
116
  "kind: 'openai-style-key' is an internal enum",
117
- 'path: docs/spec/known-gaps.md',
117
+ 'path: docs/contracts/known-gaps.md',
118
118
  'GET /api/health?ready=1',
119
119
  'bearer token missing from the header',
120
120
  'secrets are never exported by default',
@@ -5,7 +5,7 @@
5
5
  * 这类**合法**(RFC 7235 / 6750:auth-scheme 名大小写不敏感)的授权头在 env / headers / url 通道上
6
6
  * 明文进包且**完全不可见**(refs / skipped 皆空)。
7
7
  *
8
- * 两条口径(改这条判定的任何人先读 `docs/maintenance/known-gaps.md` **G-36**):
8
+ * 两条口径(改这条判定的任何人先读 `docs/known-issues/known-gaps.md` **G-36**):
9
9
  * ① 规范形态 `Bearer …` 的**行为与历史逐字一致**(命中名仍是 `bearer-token`):本模块只**补**非规范大小写;
10
10
  * ② 厂商前缀(`sk-` / `AKIA` / `ghp_` / `github_pat_`)**刻意保持大小写敏感** —— `SK-…` 不是真实厂商形态,
11
11
  * 全改 `i` 会连带放宽整个脱敏面(日志 / 导出 / 界面渲染前 redact),代价大于收益 ⇒ 登记为**已知边界**
@@ -74,7 +74,7 @@ test('t72-d:厂商前缀的大小写边界钉成事实(SK- / GHP_ / akia 是
74
74
  assert.equal(matchSecretValuePattern('AKIAIOSFODNN7A1B2C3D4'), 'aws-access-key');
75
75
  assert.equal(matchSecretValuePattern('ghp_' + 'AbCdEf0123456789aBcDeF0123456789aB'), 'github-token');
76
76
  // 不命中侧:**刻意保留**的大小写边界。改这里 = 改整个脱敏面(日志/导出/界面),需单独决策 ——
77
- // 若确要收,请连同 known-gaps G-36 与 docs/lessons/security-and-credentials.md 一起改,不要只改死这条断言。
77
+ // 若确要收,请连同 known-gaps G-36 与 docs/evidence/security-and-credentials.md 一起改,不要只改死这条断言。
78
78
  const boundary = [
79
79
  'SK-ABCDEFGHIJKLMNOP0123456789XYZ',
80
80
  'Sk-abcdefghijklmnop0123456789XYZ',
@@ -81,7 +81,7 @@ const BEARER_TOKEN_CHARS = '[A-Za-z0-9._~+/=-]';
81
81
  * 于是 `bearer credentials are required` / `bearer authentication failed` / `BEARER HEADER NOT SET`
82
82
  * 这类纯小写或纯大写的英文词**不命中**;而 `bearer abc12345`、`BEARER AbCdEfGh`、`bearer <24+ 字符>` 命中。
83
83
  *
84
- * 已知残余(登记在 `docs/maintenance/known-gaps.md` G-36):scheme 用非规范大小写**且** token 是 8–23 个**纯字母、
84
+ * 已知残余(登记在 `docs/known-issues/known-gaps.md` G-36):scheme 用非规范大小写**且** token 是 8–23 个**纯字母、
85
85
  * 单一大小写**时本条不命中;规范 `Bearer …` 形态不受此限(上面那条 `bearer-token` 只要求 8+ 字符,行为不变)。
86
86
  */
87
87
  const BEARER_TOKEN_ANY_CASE = new RegExp(