dsh-config-manager 0.8.2 → 0.10.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 (418) hide show
  1. package/lib/adapters/mcp.js +51 -15
  2. package/lib/adapters/messages.d.ts +1 -0
  3. package/lib/adapters/messages.js +2 -0
  4. package/lib/adapters/patch-key-guard.d.ts +23 -0
  5. package/lib/adapters/patch-key-guard.js +13 -0
  6. package/lib/adapters/plugin-data.d.ts +19 -5
  7. package/lib/adapters/plugin-data.js +76 -22
  8. package/lib/adapters/plugins.d.ts +14 -1
  9. package/lib/adapters/plugins.js +204 -6
  10. package/lib/adapters/prompts.js +15 -4
  11. package/lib/adapters/test-helpers.d.ts +15 -1
  12. package/lib/adapters/test-helpers.js +11 -0
  13. package/lib/cli/actions.d.ts +7 -105
  14. package/lib/cli/actions.js +16 -172
  15. package/lib/cli/control-state.d.ts +54 -0
  16. package/lib/cli/control-state.js +107 -0
  17. package/lib/cli/help.d.ts +1 -1
  18. package/lib/cli/help.js +21 -14
  19. package/lib/cli/index.js +132 -104
  20. package/lib/cli/sessions-repair.js +58 -22
  21. package/lib/cli/web/client-script.d.ts +1 -1
  22. package/lib/cli/web/client-script.js +71 -5
  23. package/lib/cli/web/page.d.ts +9 -19
  24. package/lib/cli/web/page.js +277 -173
  25. package/lib/cli/web/routes.js +85 -25
  26. package/lib/cli/write-gates.d.ts +61 -0
  27. package/lib/cli/write-gates.js +110 -0
  28. package/lib/client.d.ts +196 -75
  29. package/lib/client.js +8139 -7487
  30. package/lib/core/backup.d.ts +0 -4
  31. package/lib/core/backup.js +21 -4
  32. package/lib/core/boot-rescue.d.ts +1 -1
  33. package/lib/core/boot-rescue.js +12 -1
  34. package/lib/core/boot-safety.js +37 -2
  35. package/lib/core/conflict-decisions.js +2 -1
  36. package/lib/core/exporter.js +22 -1
  37. package/lib/core/journal.d.ts +54 -4
  38. package/lib/core/journal.js +158 -35
  39. package/lib/core/local-plugin-host.d.ts +29 -0
  40. package/lib/core/local-plugin-host.js +55 -48
  41. package/lib/core/messages.d.ts +17 -0
  42. package/lib/core/messages.js +34 -0
  43. package/lib/core/migration-history.js +16 -9
  44. package/lib/core/model-tools.d.ts +2 -2
  45. package/lib/core/model-tools.js +20 -2
  46. package/lib/core/patch-chain.d.ts +65 -0
  47. package/lib/core/patch-chain.js +100 -0
  48. package/lib/core/patch-document.d.ts +32 -4
  49. package/lib/core/patch-document.js +48 -17
  50. package/lib/core/patch-secret-guard.d.ts +49 -0
  51. package/lib/core/patch-secret-guard.js +164 -0
  52. package/lib/core/reconcile.d.ts +8 -0
  53. package/lib/core/reconcile.js +18 -3
  54. package/lib/core/reinstall.d.ts +2 -0
  55. package/lib/core/reinstall.js +6 -2
  56. package/lib/core/restore.js +31 -6
  57. package/lib/core/section-sanitize.d.ts +32 -0
  58. package/lib/core/section-sanitize.js +13 -0
  59. package/lib/core/snapshot-diff.d.ts +30 -0
  60. package/lib/core/snapshot-diff.js +56 -20
  61. package/lib/core/startup-barrier.js +8 -2
  62. package/lib/core/types.d.ts +38 -1
  63. package/lib/core/update-check.js +51 -2
  64. package/lib/foreign/kernel.js +9 -2
  65. package/lib/foreign/read-claude-plugins.js +29 -11
  66. package/lib/foreign/read-dsh.js +31 -2
  67. package/lib/foreign/session-ir.js +50 -9
  68. package/lib/foreign/session-read.d.ts +8 -0
  69. package/lib/foreign/session-read.js +26 -0
  70. package/lib/index.d.ts +9 -4
  71. package/lib/index.js +42 -47
  72. package/lib/profiles/dsh-profile-io.d.ts +20 -0
  73. package/lib/profiles/dsh-profile-io.js +27 -0
  74. package/lib/profiles/dsh-profile-manager.d.ts +27 -0
  75. package/lib/profiles/dsh-profile-manager.js +45 -4
  76. package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
  77. package/lib/profiles/dsh-profile-runtime.js +16 -3
  78. package/lib/profiles/process-control.d.ts +18 -1
  79. package/lib/profiles/process-control.js +25 -1
  80. package/lib/routes/profiles.js +2 -1
  81. package/lib/routes/sync.js +19 -1
  82. package/lib/schema/types.d.ts +11 -0
  83. package/lib/security/redaction.js +22 -6
  84. package/lib/sync/autosync-repeat.d.ts +27 -0
  85. package/lib/sync/autosync-repeat.js +23 -0
  86. package/lib/sync/autosync-scheduler.d.ts +47 -2
  87. package/lib/sync/autosync-scheduler.js +217 -53
  88. package/lib/sync/baseline-heal.js +7 -0
  89. package/lib/sync/baseline-record.d.ts +67 -0
  90. package/lib/sync/baseline-record.js +74 -0
  91. package/lib/sync/blob-store.js +13 -0
  92. package/lib/sync/content-diff.d.ts +39 -0
  93. package/lib/sync/content-diff.js +46 -0
  94. package/lib/sync/git/git-transport.d.ts +32 -1
  95. package/lib/sync/git/git-transport.js +146 -26
  96. package/lib/sync/github-auth.d.ts +17 -1
  97. package/lib/sync/github-auth.js +37 -1
  98. package/lib/sync/local-changes.d.ts +15 -0
  99. package/lib/sync/local-changes.js +39 -0
  100. package/lib/sync/merge-apply-plan.d.ts +38 -0
  101. package/lib/sync/merge-apply-plan.js +76 -0
  102. package/lib/sync/merge-keyed.d.ts +68 -0
  103. package/lib/sync/merge-keyed.js +124 -0
  104. package/lib/sync/messages.d.ts +1 -0
  105. package/lib/sync/messages.js +2 -0
  106. package/lib/sync/patch-line-identity.d.ts +19 -0
  107. package/lib/sync/patch-line-identity.js +99 -0
  108. package/lib/sync/pending-merge.d.ts +41 -0
  109. package/lib/sync/pending-merge.js +61 -0
  110. package/lib/sync/plugin-removals.d.ts +15 -15
  111. package/lib/sync/plugin-removals.js +134 -83
  112. package/lib/sync/push-skip.d.ts +55 -0
  113. package/lib/sync/push-skip.js +70 -0
  114. package/lib/sync/s3/s3-transport.d.ts +14 -2
  115. package/lib/sync/s3/s3-transport.js +72 -48
  116. package/lib/sync/sync-engine.d.ts +44 -51
  117. package/lib/sync/sync-engine.js +160 -194
  118. package/lib/sync/sync-history.d.ts +7 -0
  119. package/lib/sync/sync-state.d.ts +28 -0
  120. package/lib/sync/sync-state.js +20 -0
  121. package/lib/sync/transport.d.ts +12 -3
  122. package/lib/sync/transport.js +13 -4
  123. package/lib/sync/webdav/webdav-transport.d.ts +19 -2
  124. package/lib/sync/webdav/webdav-transport.js +81 -40
  125. package/lib/sync/workspace-merge.d.ts +8 -2
  126. package/lib/ui/artifact-view.d.ts +1 -1
  127. package/lib/ui/commands.js +5 -11
  128. package/lib/ui/dsh-profiles-view.d.ts +8 -3
  129. package/lib/ui/dsh-profiles-view.js +9 -5
  130. package/lib/ui/foreign-view.d.ts +14 -0
  131. package/lib/ui/foreign-view.js +34 -0
  132. package/lib/ui/i18n.d.ts +7 -1
  133. package/lib/ui/i18n.js +15 -2
  134. package/lib/ui/menu-placement.js +1 -1
  135. package/lib/ui/migration-consult-view.d.ts +11 -0
  136. package/lib/ui/migration-consult-view.js +15 -0
  137. package/lib/ui/overview-view.d.ts +7 -0
  138. package/lib/ui/overview-view.js +3 -0
  139. package/lib/ui/report.d.ts +9 -0
  140. package/lib/ui/report.js +17 -4
  141. package/lib/ui/selection-model.d.ts +10 -2
  142. package/lib/ui/selection-model.js +23 -3
  143. package/lib/utils/async-once.d.ts +11 -0
  144. package/lib/utils/async-once.js +15 -0
  145. package/lib/utils/patch-chain-read.d.ts +51 -0
  146. package/lib/utils/patch-chain-read.js +240 -0
  147. package/lib/utils/patch-yaml.d.ts +39 -1
  148. package/lib/utils/patch-yaml.js +82 -2
  149. package/lib/utils/paths.d.ts +13 -0
  150. package/lib/utils/paths.js +35 -0
  151. package/lib/utils/workdir-lock.js +18 -3
  152. package/package.json +3 -2
  153. package/src/adapters/mcp.test.ts +29 -0
  154. package/src/adapters/mcp.ts +52 -14
  155. package/src/adapters/messages.ts +2 -0
  156. package/src/adapters/patch-key-guard.ts +29 -0
  157. package/src/adapters/plugin-data.test.ts +126 -0
  158. package/src/adapters/plugin-data.ts +97 -26
  159. package/src/adapters/plugins.test.ts +403 -0
  160. package/src/adapters/plugins.ts +198 -8
  161. package/src/adapters/prompts.ts +15 -4
  162. package/src/adapters/test-helpers.ts +15 -1
  163. package/src/cli/actions.test.ts +74 -1
  164. package/src/cli/actions.ts +27 -246
  165. package/src/cli/control-state.ts +143 -0
  166. package/src/cli/help.ts +21 -14
  167. package/src/cli/index.ts +123 -107
  168. package/src/cli/sessions-repair.ts +55 -22
  169. package/src/cli/web/client-script.ts +71 -5
  170. package/src/cli/web/page.ts +327 -208
  171. package/src/cli/web/routes.ts +85 -25
  172. package/src/cli/web/web.test.ts +65 -0
  173. package/src/cli/write-gates.ts +149 -0
  174. package/src/client/ConfigManagerSection.tsx +8 -4
  175. package/src/client/about/AboutPanel.tsx +9 -12
  176. package/src/client/about/release-notes-view.test.ts +17 -0
  177. package/src/client/about/release-notes-view.ts +49 -24
  178. package/src/client/api.ts +2 -1
  179. package/src/client/chat/ChatEntryView.tsx +2 -2
  180. package/src/client/chat/rollback-entry-view.ts +6 -1
  181. package/src/client/common/CommandPalette.tsx +6 -3
  182. package/src/client/common/ConfirmDialog.tsx +29 -12
  183. package/src/client/common/ContentPicker.tsx +24 -24
  184. package/src/client/common/Modal.tsx +12 -5
  185. package/src/client/common/MoreMenu.tsx +4 -1
  186. package/src/client/common/RunsCenter.tsx +103 -32
  187. package/src/client/common/Select.tsx +2 -2
  188. package/src/client/common/floating-bounds.ts +1 -1
  189. package/src/client/common/floating-units.test.ts +1 -2
  190. package/src/client/common/plan-text-redaction.test.ts +190 -5
  191. package/src/client/common/runs-center-guard.test.ts +60 -0
  192. package/src/client/common/runs-center-view.test.ts +128 -0
  193. package/src/client/common/runs-center-view.ts +96 -0
  194. package/src/client/common/section-title-action.test.ts +66 -0
  195. package/src/client/common/ui.tsx +93 -30
  196. package/src/client/config-manager.module.css +1515 -270
  197. package/src/client/consult/ConsultCard.tsx +7 -6
  198. package/src/client/environment/EnvironmentPanel.tsx +22 -25
  199. package/src/client/environment/maintenance/DiskUsageCard.tsx +69 -96
  200. package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
  201. package/src/client/export/ExportView.tsx +7 -16
  202. package/src/client/history/HistoryPanel.tsx +88 -28
  203. package/src/client/history/history-locales.ts +3 -3
  204. package/src/client/home/BackupScheduleCard.tsx +77 -69
  205. package/src/client/home/HomePanel.tsx +47 -12
  206. package/src/client/import/ConflictList.tsx +13 -13
  207. package/src/client/import/ForeignImportView.tsx +67 -9
  208. package/src/client/import/ImportWizardView.tsx +4 -4
  209. package/src/client/import/PathMappingForm.tsx +36 -9
  210. package/src/client/import/PathPickerDialog.tsx +2 -1
  211. package/src/client/import/import-wizard-split.test.ts +1 -1
  212. package/src/client/import/import-wizard-steps.tsx +51 -39
  213. package/src/client/import/use-import-wizard-controller.test.ts +129 -0
  214. package/src/client/import/use-import-wizard-controller.ts +116 -22
  215. package/src/client/library/ArtifactRow.tsx +2 -2
  216. package/src/client/library/BackupInspectView.tsx +21 -15
  217. package/src/client/library/LibraryActions.tsx +116 -28
  218. package/src/client/library/LibraryPanel.tsx +14 -15
  219. package/src/client/library/RestorePlanView.tsx +13 -8
  220. package/src/client/locales/about.ts +0 -2
  221. package/src/client/locales/backup.ts +15 -12
  222. package/src/client/locales/common.ts +2 -0
  223. package/src/client/locales/export.ts +5 -12
  224. package/src/client/locales/foreign.ts +4 -2
  225. package/src/client/locales/import.ts +5 -2
  226. package/src/client/locales/overview.ts +4 -0
  227. package/src/client/locales/profiles.ts +32 -4
  228. package/src/client/locales/restore.ts +2 -2
  229. package/src/client/locales/sessions.ts +0 -2
  230. package/src/client/locales/shell.ts +2 -2
  231. package/src/client/market/MarketImportReview.tsx +4 -4
  232. package/src/client/market/MarketPanel.tsx +58 -56
  233. package/src/client/market/MyConfigsList.tsx +34 -32
  234. package/src/client/market/MyConfigsLoginCard.tsx +12 -15
  235. package/src/client/market/MyConfigsView.tsx +8 -15
  236. package/src/client/market/MyConfigsWizard.tsx +7 -12
  237. package/src/client/market/market-locales.ts +0 -6
  238. package/src/client/market/my-configs-split.test.ts +2 -1
  239. package/src/client/nav-menu-clip-guard.test.ts +52 -0
  240. package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
  241. package/src/client/recovery/RecoveryPanel.tsx +35 -22
  242. package/src/client/recovery/RollbackCard.tsx +132 -75
  243. package/src/client/recovery/RollbackFileChanges.tsx +40 -27
  244. package/src/client/recovery/SessionHealthCard.tsx +2 -2
  245. package/src/client/recovery/SessionHealthDialog.tsx +5 -7
  246. package/src/client/recovery/SessionLayoutSection.tsx +3 -5
  247. package/src/client/recovery/recovery-locales.ts +12 -8
  248. package/src/client/recovery/rollback-enabled.ts +29 -0
  249. package/src/client/recovery/use-recovery-write.ts +5 -0
  250. package/src/client/run-store.test.ts +30 -0
  251. package/src/client/run-store.ts +21 -1
  252. package/src/client/sync/AddChannelCard.tsx +65 -0
  253. package/src/client/sync/AutosyncCard.tsx +184 -108
  254. package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
  255. package/src/client/sync/ChannelConfigDialog.tsx +27 -48
  256. package/src/client/sync/MergePreviewView.tsx +5 -7
  257. package/src/client/sync/PushPreviewCard.tsx +2 -1
  258. package/src/client/sync/PushReportSections.tsx +35 -0
  259. package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
  260. package/src/client/sync/SyncConfirmView.tsx +130 -133
  261. package/src/client/sync/SyncLogList.tsx +29 -14
  262. package/src/client/sync/SyncPanel.tsx +188 -185
  263. package/src/client/sync/SyncProbeRow.tsx +5 -7
  264. package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
  265. package/src/client/sync/SyncSecuritySection.tsx +157 -0
  266. package/src/client/sync/SyncSettingsDialog.tsx +293 -0
  267. package/src/client/sync/SyncSettingsView.test.ts +26 -8
  268. package/src/client/sync/WorkDirCard.tsx +2 -4
  269. package/src/client/sync/config-clear-guard.test.ts +94 -0
  270. package/src/client/sync/config-clear-guard.ts +98 -0
  271. package/src/client/sync/config-dirty.test.ts +91 -0
  272. package/src/client/sync/config-dirty.ts +88 -0
  273. package/src/client/sync/history-model.test.ts +2 -0
  274. package/src/client/sync/history-model.ts +5 -0
  275. package/src/client/sync/merge-request.ts +20 -0
  276. package/src/client/sync/sync-api.ts +13 -1
  277. package/src/client/sync/sync-locales.ts +95 -47
  278. package/src/client/sync/sync-panel-clear.test.ts +44 -0
  279. package/src/client/sync/sync-push-preview.test.ts +9 -0
  280. package/src/client/sync/sync-view.test.ts +20 -0
  281. package/src/client/sync/sync-view.ts +76 -4
  282. package/src/core/backup.test.ts +61 -1
  283. package/src/core/backup.ts +21 -4
  284. package/src/core/boot-rescue.test.ts +35 -0
  285. package/src/core/boot-rescue.ts +13 -2
  286. package/src/core/boot-safety.test.ts +25 -0
  287. package/src/core/boot-safety.ts +37 -2
  288. package/src/core/conflict-decisions.ts +2 -1
  289. package/src/core/exporter.ts +21 -1
  290. package/src/core/journal.test.ts +183 -0
  291. package/src/core/journal.ts +163 -25
  292. package/src/core/local-plugin-host.test.ts +68 -2
  293. package/src/core/local-plugin-host.ts +31 -4
  294. package/src/core/messages.ts +34 -0
  295. package/src/core/migration-history.test.ts +27 -0
  296. package/src/core/migration-history.ts +12 -4
  297. package/src/core/model-tools.test.ts +67 -0
  298. package/src/core/model-tools.ts +22 -4
  299. package/src/core/patch-chain.test.ts +83 -0
  300. package/src/core/patch-chain.ts +150 -0
  301. package/src/core/patch-document.test.ts +48 -1
  302. package/src/core/patch-document.ts +66 -15
  303. package/src/core/patch-layers.test.ts +1 -1
  304. package/src/core/patch-secret-guard.test.ts +110 -0
  305. package/src/core/patch-secret-guard.ts +176 -0
  306. package/src/core/reconcile.ts +32 -4
  307. package/src/core/reinstall.ts +8 -2
  308. package/src/core/restore.ts +32 -7
  309. package/src/core/section-sanitize.ts +37 -0
  310. package/src/core/smoke.test.ts +2 -1
  311. package/src/core/snapshot-diff.test.ts +73 -1
  312. package/src/core/snapshot-diff.ts +66 -21
  313. package/src/core/startup-barrier.test.ts +64 -0
  314. package/src/core/startup-barrier.ts +8 -2
  315. package/src/core/types.ts +43 -2
  316. package/src/core/update-check.test.ts +40 -0
  317. package/src/core/update-check.ts +53 -2
  318. package/src/foreign/claude-code.test.ts +5 -0
  319. package/src/foreign/claude-plugins.test.ts +57 -0
  320. package/src/foreign/claude-sessions-bytes.test.ts +7 -1
  321. package/src/foreign/dsh.test.ts +23 -0
  322. package/src/foreign/kernel.ts +9 -2
  323. package/src/foreign/read-claude-plugins.ts +32 -11
  324. package/src/foreign/read-dsh.ts +33 -2
  325. package/src/foreign/session-ir.test.ts +67 -0
  326. package/src/foreign/session-ir.ts +54 -14
  327. package/src/foreign/session-read.ts +23 -0
  328. package/src/index.facade.test.ts +186 -6
  329. package/src/index.ts +53 -47
  330. package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
  331. package/src/profiles/dsh-profile-io.ts +29 -0
  332. package/src/profiles/dsh-profile-manager.test.ts +30 -0
  333. package/src/profiles/dsh-profile-manager.ts +53 -5
  334. package/src/profiles/dsh-profile-runtime.test.ts +29 -7
  335. package/src/profiles/dsh-profile-runtime.ts +17 -3
  336. package/src/profiles/process-control.test.ts +97 -0
  337. package/src/profiles/process-control.ts +28 -1
  338. package/src/routes/profiles.ts +2 -1
  339. package/src/routes/sync.ts +19 -1
  340. package/src/schema/types.ts +16 -1
  341. package/src/security/redaction.test.ts +31 -0
  342. package/src/security/redaction.ts +23 -6
  343. package/src/security/security.test.ts +1 -1
  344. package/src/sync/autosync-repeat.test.ts +58 -0
  345. package/src/sync/autosync-repeat.ts +55 -0
  346. package/src/sync/autosync-scheduler.test.ts +515 -0
  347. package/src/sync/autosync-scheduler.ts +225 -51
  348. package/src/sync/baseline-heal.ts +6 -0
  349. package/src/sync/baseline-record.ts +135 -0
  350. package/src/sync/blob-store.test.ts +16 -0
  351. package/src/sync/blob-store.ts +13 -0
  352. package/src/sync/content-diff.test.ts +95 -0
  353. package/src/sync/content-diff.ts +79 -0
  354. package/src/sync/git/git-transport.test.ts +151 -4
  355. package/src/sync/git/git-transport.ts +143 -27
  356. package/src/sync/github-auth.test.ts +26 -1
  357. package/src/sync/github-auth.ts +37 -1
  358. package/src/sync/local-changes.ts +40 -0
  359. package/src/sync/merge-apply-plan.ts +117 -0
  360. package/src/sync/merge-keyed.test.ts +167 -0
  361. package/src/sync/merge-keyed.ts +160 -0
  362. package/src/sync/messages.ts +3 -0
  363. package/src/sync/patch-line-identity.test.ts +73 -0
  364. package/src/sync/patch-line-identity.ts +105 -0
  365. package/src/sync/pending-merge.test.ts +41 -0
  366. package/src/sync/pending-merge.ts +85 -0
  367. package/src/sync/plugin-removals.test.ts +199 -39
  368. package/src/sync/plugin-removals.ts +150 -64
  369. package/src/sync/push-skip.test.ts +326 -0
  370. package/src/sync/push-skip.ts +102 -0
  371. package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
  372. package/src/sync/s3/s3-transport.ts +76 -42
  373. package/src/sync/sync-config.test.ts +39 -12
  374. package/src/sync/sync-device-identity.test.ts +3 -0
  375. package/src/sync/sync-engine.test.ts +465 -12
  376. package/src/sync/sync-engine.ts +189 -193
  377. package/src/sync/sync-history.ts +7 -0
  378. package/src/sync/sync-state.ts +48 -0
  379. package/src/sync/transport.test.ts +13 -1
  380. package/src/sync/transport.ts +12 -4
  381. package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
  382. package/src/sync/webdav/webdav-transport.ts +86 -34
  383. package/src/sync/workspace-merge.ts +9 -2
  384. package/src/ui/artifact-view.ts +1 -1
  385. package/src/ui/commands.test.ts +11 -0
  386. package/src/ui/commands.ts +5 -14
  387. package/src/ui/dsh-profiles-view.test.ts +16 -0
  388. package/src/ui/dsh-profiles-view.ts +11 -5
  389. package/src/ui/foreign-view.test.ts +49 -0
  390. package/src/ui/foreign-view.ts +47 -0
  391. package/src/ui/i18n.ts +15 -2
  392. package/src/ui/menu-placement.ts +1 -1
  393. package/src/ui/migration-consult-view.test.ts +20 -1
  394. package/src/ui/migration-consult-view.ts +17 -0
  395. package/src/ui/overview-view.ts +10 -0
  396. package/src/ui/report.test.ts +25 -1
  397. package/src/ui/report.ts +15 -4
  398. package/src/ui/selection-model.test.ts +29 -1
  399. package/src/ui/selection-model.ts +25 -4
  400. package/src/utils/async-once.ts +14 -0
  401. package/src/utils/js-yaml4.d.ts +35 -0
  402. package/src/utils/patch-chain-read.test.ts +171 -0
  403. package/src/utils/patch-chain-read.ts +259 -0
  404. package/src/utils/patch-yaml.test.ts +215 -3
  405. package/src/utils/patch-yaml.ts +98 -2
  406. package/src/utils/paths.test.ts +14 -1
  407. package/src/utils/paths.ts +35 -0
  408. package/src/utils/workdir-lock.test.ts +69 -0
  409. package/src/utils/workdir-lock.ts +17 -3
  410. package/lib/ui/path-mapping.d.ts +0 -38
  411. package/lib/ui/path-mapping.js +0 -75
  412. package/src/client/common/InfoHint.tsx +0 -289
  413. package/src/client/common/info-hint-guard.test.ts +0 -1119
  414. package/src/client/sync/DecryptPasswordCard.tsx +0 -48
  415. package/src/client/sync/SecurityOptionsCard.tsx +0 -97
  416. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
  417. package/src/ui/path-mapping.test.ts +0 -67
  418. package/src/ui/path-mapping.ts +0 -103
@@ -16,6 +16,8 @@ import { msgOf, zhMsg } from '../core/messages.js';
16
16
  import { sectionMeta } from '../schema/section-registry.js';
17
17
  import { validateJsonSection } from './json-section.js';
18
18
  import { locatePatchLineLayer, readEffectivePatchLines, resolveWriteLayer } from '../core/patch-layers.js';
19
+ import { findPatchKeyHazards } from '../utils/patch-yaml.js';
20
+ import { patchKeyHazardMessage } from './patch-key-guard.js';
19
21
  import { MCP_CONNECTOR_STORE_REL, buildConnectorRecord, comparableConnector, exportConnectorBlock, findConnectorRecord, mergeConnectorIntoStoreText, pickConnectorKey, readConnectorStore, refillFieldsOf, } from '../core/mcp-connector-store.js';
20
22
  /**
21
23
  * 从 patch 行数组中提取 MCP server 条目(以 config.serverName 存在为判定)。
@@ -122,6 +124,16 @@ const MCP_BUNDLE_NAME = '@deepseek-ai/dsh-mcp-client';
122
124
  * 上才回落 url 猜测(issue #133:此前写回丢了这个字段,stdio/http 只能靠 url 有没有值猜)。
123
125
  */
124
126
  export function buildMcpPatchLine(lineId, server) {
127
+ return { id: lineId, name: MCP_BUNDLE_NAME, config: mcpPatchConfig(server) };
128
+ }
129
+ /**
130
+ * 写进 patch 行的 `config`。
131
+ *
132
+ * 单独抽出来是因为**键名守卫**(issue #137)要检查同一份对象:`env` / `headers` 的键名完全由
133
+ * 用户的 MCP 配置决定,`007` / `~` 这类名字会被 DSH 的 4.x 读端改判、空键会让整份文件解析失败。
134
+ * 守卫必须与真正写盘的形状同源,否则查的和写的不是同一份东西。
135
+ */
136
+ function mcpPatchConfig(server) {
125
137
  const config = { serverName: server.serverName, transport: server.type };
126
138
  if (server.type === 'streamable-http') {
127
139
  config['url'] = server.url;
@@ -137,7 +149,7 @@ export function buildMcpPatchLine(lineId, server) {
137
149
  if (server.cwd !== undefined)
138
150
  config['cwd'] = server.cwd;
139
151
  }
140
- return { id: lineId, name: MCP_BUNDLE_NAME, config };
152
+ return config;
141
153
  }
142
154
  /** 连接器计划项的 id 前缀(导入时按前缀分派到 applyConnectorItem) */
143
155
  const MCP_CONNECTOR_ITEM_PREFIX = 'mcp-connector:';
@@ -302,6 +314,27 @@ export class McpAdapter {
302
314
  const comparable = { ...server };
303
315
  delete comparable.sourceLineId;
304
316
  delete comparable.sourceFile;
317
+ // 与目标一致 ⇒ 不会写盘,键名风险不归我们管(先判 Skip 以免误报)。
318
+ if (existing) {
319
+ const existingComparable = { ...existing };
320
+ delete existingComparable.sourceLineId;
321
+ delete existingComparable.sourceFile;
322
+ if (isDeepStrictEqual(existingComparable, comparable)) {
323
+ items.push({ id, kind: 'Skip', adapter: 'mcp', description: msg('adapter.mcpSame', { serverName: server.serverName }), severity: 'info' });
324
+ continue;
325
+ }
326
+ }
327
+ // issue #137:env / headers 的键名完全由用户配置决定,写出去的键名会被 DSH 的 4.x 读端改判
328
+ // (空键更会让整份文件解析失败)。命中即降级成本项「预判阻断」:本项不写、不整笔回滚。
329
+ const hazard = findPatchKeyHazards(mcpPatchConfig(server))[0];
330
+ if (hazard) {
331
+ const refForMessage = existing?.sourceLineId ?? server.sourceLineId ?? newLineId(server.serverName);
332
+ items.push({
333
+ id, kind: 'Error', adapter: 'mcp',
334
+ description: patchKeyHazardMessage(msg, refForMessage, hazard), severity: 'error',
335
+ });
336
+ continue;
337
+ }
305
338
  if (!existing) {
306
339
  const lineId = server.sourceLineId && targetLines.some((l) => l.lineId === server.sourceLineId)
307
340
  ? `${server.sourceLineId}-imported`
@@ -316,21 +349,17 @@ export class McpAdapter {
316
349
  });
317
350
  }
318
351
  else {
352
+ // 已在上方判过「一致 ⇒ Skip」,到这里只可能是真差异;existingComparable 仍要给 detail 用
319
353
  const existingComparable = { ...existing };
320
354
  delete existingComparable.sourceLineId;
321
355
  delete existingComparable.sourceFile;
322
- if (isDeepStrictEqual(existingComparable, comparable)) {
323
- items.push({ id, kind: 'Skip', adapter: 'mcp', description: msg('adapter.mcpSame', { serverName: server.serverName }), severity: 'info' });
324
- }
325
- else {
326
- items.push({
327
- id, kind: 'Conflict', adapter: 'mcp',
328
- description: msg('adapter.mcpDiff', { serverName: server.serverName }),
329
- detail: `current=${JSON.stringify(existingComparable)} imported=${JSON.stringify(comparable)}`.slice(0, 200),
330
- severity: 'warning',
331
- target: { adapter: 'mcp', ref: existing.sourceLineId, file: existing.sourceFile },
332
- });
333
- }
356
+ items.push({
357
+ id, kind: 'Conflict', adapter: 'mcp',
358
+ description: msg('adapter.mcpDiff', { serverName: server.serverName }),
359
+ detail: `current=${JSON.stringify(existingComparable)} imported=${JSON.stringify(comparable)}`.slice(0, 200),
360
+ severity: 'warning',
361
+ target: { adapter: 'mcp', ref: existing.sourceLineId, file: existing.sourceFile },
362
+ });
334
363
  }
335
364
  }
336
365
  items.push(...await this.analyzeConnectors(data, ctx));
@@ -437,10 +466,17 @@ export class McpAdapter {
437
466
  const file = item.kind === 'Create'
438
467
  ? resolveWriteLayer(server.sourceFile, ctx.target.profile)
439
468
  : await locatePatchLineLayer(ctx.target.patchFile, ctx.target.profile, ref);
440
- await ctx.target.patchFile.applyPatchChanges(file, [
469
+ const outcome = await ctx.target.patchFile.applyPatchChanges(file, [
441
470
  { lineId: ref, raw, action: item.kind === 'Create' ? 'insert' : 'update' },
442
471
  ]);
443
- return { ok: true, needsRestart: true, message: msg('adapter.mcpWritten', { serverName }) };
472
+ // issue #144:门面会把「该 id 已由别的层提供」的 insert 降级成覆盖行 —— 写入者必须报出来,
473
+ // 否则落盘形状变了而报告显示一切照旧(out-of-scope 的是「为 mcp 单独设计形状」,不是静默)。
474
+ const downgraded = outcome.downgraded.length > 0;
475
+ return {
476
+ ok: true, warning: downgraded, needsRestart: true,
477
+ message: msg('adapter.mcpWritten', { serverName })
478
+ + (downgraded ? ' ' + msg('adapter.patchLineDowngraded', { ids: outcome.downgraded.join(', ') }) : ''),
479
+ };
444
480
  }
445
481
  /**
446
482
  * 写入一条连接:读全文件 → 只替换 `tables.connections[<key>]` → 整文件原子写。
@@ -14,6 +14,7 @@ export declare const zh: {
14
14
  readonly 'adapter.uiLocalStorageGeneric': '浏览器端 UI 状态无法经 Host API 迁移';
15
15
  readonly 'adapter.pluginDataEnvOverridden': '{path} 的位置被环境变量 {env} 覆盖,本次已跳过(不猜它指向哪里)';
16
16
  readonly 'adapter.pluginDataPathNotAllowed': '路径不在第三方插件数据的允许范围内,已拒绝写入: {path}';
17
+ readonly 'adapter.pluginDataSensitiveSkipped': '已剔除 {count} 个凭据文件(首个:{sample})——第三方插件数据分区永不搬运凭据明文';
17
18
  readonly 'adapter.pluginDataNoOsHome': '第三方插件的数据在系统主目录下,但当前宿主没有提供该目录的文件通道(旧版本宿主):本次不读取也不导入 / third-party plugin data lives under the system home directory, but this host offers no file channel for it (older host): nothing is read or imported this time';
18
19
  readonly 'adapter.pwMachinePathStripped': '已剥离 {count} 条与本机路径绑定的 pnpm 设置(换机后会指向不存在的目录):{keys}';
19
20
  readonly 'adapter.pwMachinePathKept': '保留本机原有的 {count} 条 pnpm 路径设置(不搬运来源机的路径):{keys}';
@@ -32,6 +32,7 @@ export const zh = {
32
32
  // ---------- pluginData / pluginAssets(第三方插件数据迁移) ----------
33
33
  'adapter.pluginDataEnvOverridden': '{path} 的位置被环境变量 {env} 覆盖,本次已跳过(不猜它指向哪里)',
34
34
  'adapter.pluginDataPathNotAllowed': '路径不在第三方插件数据的允许范围内,已拒绝写入: {path}',
35
+ 'adapter.pluginDataSensitiveSkipped': '已剔除 {count} 个凭据文件(首个:{sample})——第三方插件数据分区永不搬运凭据明文',
35
36
  'adapter.pluginDataNoOsHome': '第三方插件的数据在系统主目录下,但当前宿主没有提供该目录的文件通道(旧版本宿主):本次不读取也不导入 / third-party plugin data lives under the system home directory, but this host offers no file channel for it (older host): nothing is read or imported this time',
36
37
  // ---------- pnpm 配置可移植净化(机器相关路径键) ----------
37
38
  'adapter.pwMachinePathStripped': '已剥离 {count} 条与本机路径绑定的 pnpm 设置(换机后会指向不存在的目录):{keys}',
@@ -53,6 +54,7 @@ export const en = {
53
54
  'adapter.uiLocalStorageGeneric': 'Browser-side UI state cannot be migrated through the host API',
54
55
  'adapter.pluginDataEnvOverridden': "the location of {path} is overridden by the {env} environment variable; skipped this time (the new location is never guessed)",
55
56
  'adapter.pluginDataPathNotAllowed': 'the path is outside the range allowed for third-party plugin data and was refused: {path}',
57
+ 'adapter.pluginDataSensitiveSkipped': 'dropped {count} credential file(s) (first: {sample}) — third-party plugin data never carries credential plaintext',
56
58
  'adapter.pluginDataNoOsHome': 'third-party plugin data lives under the system home directory, but this host offers no file channel for it (older host): nothing is read or imported this time',
57
59
  'adapter.pwMachinePathStripped': 'Stripped {count} pnpm setting(s) bound to machine-specific paths (they would point to non-existent directories on another machine): {keys}',
58
60
  'adapter.pwMachinePathKept': "Kept this machine's own {count} pnpm path setting(s) (the source machine's paths are never carried over): {keys}",
@@ -0,0 +1,23 @@
1
+ /**
2
+ * patch 行**键名**的跨大版本守卫(issue #137)。
3
+ *
4
+ * 写侧 `forceQuotes`(issue #135)只保**值**;键名仍由 js-yaml 决定加不加引号,于是
5
+ * `007` / `True` / `.5` / `~` 这类键被 4.x 读成 `7` / `true` / `0.5` / `null`,
6
+ * 空键名更会让整份 `cordis.patch.yml` 解析失败。检测器在 `utils/patch-yaml.ts`
7
+ * (`findPatchKeyHazards`),这里只负责把命中翻成计划项文案 —— 各适配器共用一份措辞,
8
+ * 免得同一个风险在插件 / MCP 两处说法不一致。
9
+ *
10
+ * 为什么是「计划项降级」而不是「写盘时抛错」:抛错走 analyzer 的 hardFailed ⇒
11
+ * `rollbackOnError` 会把**整笔导入**回滚(别的分区也跟着白做);`kind: 'Error'` 的计划项
12
+ * 在 `src/core/analyzer.ts` 里只记账、不回滚、不中断后续条目(与 plugin-files 的
13
+ * SEC-05 同一条通道)。
14
+ */
15
+ import type { MsgFunc } from '../core/messages.ts';
16
+ import type { PatchKeyHazard } from '../utils/patch-yaml.ts';
17
+ /**
18
+ * 把一处键名风险转成用户可见文案。
19
+ *
20
+ * @param ref 计划项对应的 patch 行 id(`lineId`),用于让用户定位到具体是哪一行
21
+ * @param hazard `findPatchKeyHazards` 的命中项
22
+ */
23
+ export declare function patchKeyHazardMessage(msg: MsgFunc, ref: string, hazard: PatchKeyHazard): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 把一处键名风险转成用户可见文案。
3
+ *
4
+ * @param ref 计划项对应的 patch 行 id(`lineId`),用于让用户定位到具体是哪一行
5
+ * @param hazard `findPatchKeyHazards` 的命中项
6
+ */
7
+ export function patchKeyHazardMessage(msg, ref, hazard) {
8
+ const path = hazard.path === '' ? '-' : hazard.path;
9
+ return hazard.effect === 'parse-fail'
10
+ ? msg('adapter.patchKeyParseFail', { ref, path })
11
+ : msg('adapter.patchKeyAmbiguous', { ref, key: hazard.key, path });
12
+ }
13
+ //# sourceMappingURL=patch-key-guard.js.map
@@ -2,7 +2,7 @@ import type { RecursiveListing } from '../utils/recursive-walk.ts';
2
2
  import type { PluginDataArea, PluginDataSource, PluginDataSection } from '../core/plugin-data-registry.ts';
3
3
  import { FileCollectionAdapter } from './file-collection.ts';
4
4
  import type { FilesSection } from '../schema/types.ts';
5
- import type { ApplyResult, ExportOptions, ExportSection, HostContext, ImportContext, PlanItem, SectionPreview } from '../core/types.ts';
5
+ import type { ApplyResult, ExportOptions, ExportSection, ExportUnit, HostContext, ImportContext, PlanItem, SectionPreview } from '../core/types.ts';
6
6
  /** 区域条目(来源 + 区域),编译期与运行期唯一的区域表示 */
7
7
  export type PluginDataEntry = {
8
8
  source: PluginDataSource;
@@ -38,10 +38,16 @@ export declare class PluginDataAdapter extends FileCollectionAdapter {
38
38
  * 白名单就变成了「谁先导入谁说了算」。
39
39
  */
40
40
  private declaredMemo;
41
- /** 本轮清单(listRelPaths 写入;unitIdOf 是同步纯函数,只能从这里拿区域表) */
42
- private active;
43
- /** 本轮告警(环境变量覆盖跳过等;export/preview 收尾合并进返回的 warnings) */
44
- private pendingWarnings;
41
+ /** 每次收集调用一份作用域(listRelPaths 写、unitIdOf 读):绝不放实例字段,否则并发两路互相覆盖 */
42
+ private readonly scope;
43
+ /**
44
+ * 产物 section → 本轮区域表。
45
+ *
46
+ * `listUnits()` 在收集**结束之后**才被调用(作用域已退出),但它必须用「当初归组这批文件的那张区域表」
47
+ * —— 重新解析会与清单不一致(声明来源在这期间装了/卸了插件就会出现「单元 id 不在清单里」)。
48
+ * 键是产物对象本身,因此两路并发各挂各的,不存在覆盖。
49
+ */
50
+ private readonly unitsOf;
45
51
  constructor(section: PluginDataSection, options?: PluginDataAdapterOptions);
46
52
  /** 本分区可收集区域(内置 + 自述声明) */
47
53
  private allowedEntries;
@@ -100,6 +106,14 @@ export declare class PluginDataAdapter extends FileCollectionAdapter {
100
106
  }>;
101
107
  export(ctx: HostContext, options: ExportOptions): Promise<ExportSection<FilesSection>>;
102
108
  preview(ctx: HostContext, options: ExportOptions): Promise<SectionPreview<FilesSection>>;
109
+ /**
110
+ * 收集结束后按**那一次收集**的区域表归组(审计 P2-7)。
111
+ *
112
+ * listUnits 通常在 export/preview 返回之后才被调用(作用域已退出),因此 export/preview 把区域表
113
+ * 挂在产物对象上;这里重新铺作用域再交给基类,unitIdOf 规则只有一处实现。
114
+ * 拿不到登记(例如消费者自己构造的 section、来自快照反序列化)→ 交给基类,走内置来源的兜底口径。
115
+ */
116
+ listUnits(section: ExportSection<FilesSection>): ExportUnit[];
103
117
  /**
104
118
  * 导入分析 + **写入路径白名单**(本分区唯一的越界防线)。
105
119
  *
@@ -26,7 +26,8 @@
26
26
  * - **环境变量覆盖即跳过**:区域声明的 env 存在且解析结果与默认位置不同 → 报码跳过,绝不猜新位置。
27
27
  * - **不产生用户可见散文**:告警与计划项文案一律走消息目录(i18n 铁律)。
28
28
  */
29
- import { normalizePath } from '../utils/paths.js';
29
+ import { AsyncLocalStorage } from 'node:async_hooks';
30
+ import { isSensitiveHomeRel, normalizePath } from '../utils/paths.js';
30
31
  import { engineMsg } from './messages.js';
31
32
  import { listFilesDetailed } from './link-report.js';
32
33
  import { sectionMeta } from '../schema/section-registry.js';
@@ -52,10 +53,16 @@ export class PluginDataAdapter extends FileCollectionAdapter {
52
53
  * 白名单就变成了「谁先导入谁说了算」。
53
54
  */
54
55
  declaredMemo;
55
- /** 本轮清单(listRelPaths 写入;unitIdOf 是同步纯函数,只能从这里拿区域表) */
56
- active;
57
- /** 本轮告警(环境变量覆盖跳过等;export/preview 收尾合并进返回的 warnings) */
58
- pendingWarnings = [];
56
+ /** 每次收集调用一份作用域(listRelPaths 写、unitIdOf 读):绝不放实例字段,否则并发两路互相覆盖 */
57
+ scope = new AsyncLocalStorage();
58
+ /**
59
+ * 产物 section → 本轮区域表。
60
+ *
61
+ * `listUnits()` 在收集**结束之后**才被调用(作用域已退出),但它必须用「当初归组这批文件的那张区域表」
62
+ * —— 重新解析会与清单不一致(声明来源在这期间装了/卸了插件就会出现「单元 id 不在清单里」)。
63
+ * 键是产物对象本身,因此两路并发各挂各的,不存在覆盖。
64
+ */
65
+ unitsOf = new WeakMap();
59
66
  constructor(section, options = {}) {
60
67
  super();
61
68
  this.id = section;
@@ -152,13 +159,16 @@ export class PluginDataAdapter extends FileCollectionAdapter {
152
159
  // 本分区的根是**系统 home**(~/.dsh-wallpaper-engine、~/.mnemon …),不是 $DSH_HOME ——
153
160
  // 内容 I/O 一律走 homeFs;宿主没提供就什么都不收集,并如实报码(绝不退回 $DSH_HOME 去读错位置)。
154
161
  const homeFs = ctx.homeFs;
162
+ // 作用域按调用持有(审计 P2-7):没人包住本次调用时(直接调 listRelPaths 的测试)退化成丢弃用的空壳,
163
+ // 绝不写回实例字段 —— 那正是并发串台的根因。
164
+ const scope = this.scope.getStore() ?? { warnings: [] };
155
165
  if (homeFs === undefined) {
156
- this.active = [];
157
- this.pendingWarnings = [engineMsg('adapter.pluginDataNoOsHome')];
166
+ scope.entries = [];
167
+ scope.warnings = [engineMsg('adapter.pluginDataNoOsHome')];
158
168
  return PluginDataAdapter.emptyListing();
159
169
  }
160
170
  const entries = await this.allowedEntries(ctx);
161
- this.active = entries;
171
+ scope.entries = entries;
162
172
  const warnings = [];
163
173
  const paths = [];
164
174
  const listing = PluginDataAdapter.emptyListing();
@@ -191,8 +201,27 @@ export class PluginDataAdapter extends FileCollectionAdapter {
191
201
  paths.push(p);
192
202
  }
193
203
  }
194
- listing.paths = paths;
195
- this.pendingWarnings = warnings;
204
+ // 凭据文件永不进第三方数据分区(审计 P2-1 P0):分区根是系统主目录,来源含插件自述声明,
205
+ // 声明 `.dsh` 就会把 ~/.dsh/.credentials.yaml 当配置带走 —— 收集侧先剔一次(打包侧还有同判据的兜底)。
206
+ const kept = [];
207
+ let sensitiveSkipped = 0;
208
+ let sensitiveSample = '';
209
+ for (const p of paths) {
210
+ if (!isSensitiveHomeRel(p)) {
211
+ kept.push(p);
212
+ continue;
213
+ }
214
+ sensitiveSkipped += 1;
215
+ if (sensitiveSample === '')
216
+ sensitiveSample = p;
217
+ }
218
+ if (sensitiveSkipped > 0) {
219
+ warnings.push(engineMsg('adapter.pluginDataSensitiveSkipped', {
220
+ count: String(sensitiveSkipped), sample: sensitiveSample,
221
+ }));
222
+ }
223
+ listing.paths = kept;
224
+ scope.warnings = warnings;
196
225
  return listing;
197
226
  }
198
227
  /**
@@ -203,7 +232,9 @@ export class PluginDataAdapter extends FileCollectionAdapter {
203
232
  * \`active\` 可能是 undefined(例如直接调 listUnits),此时退回**内置来源**的最长前缀 —— 与清单口径同源。
204
233
  */
205
234
  unitIdOf(relativePath) {
206
- const entries = this.active ?? areasForSection(this.builtin, this.id);
235
+ // 区域表取自**本次调用**的作用域(AsyncLocalStorage)⇒ 并发两路各读各的(审计 P2-7);
236
+ // 收集结束后才调用的 listUnits 由覆写先铺好作用域,仍走这一处判定。
237
+ const entries = this.scope.getStore()?.entries ?? areasForSection(this.builtin, this.id);
207
238
  const hit = areaOfPath(entries, normalizePath(relativePath));
208
239
  return hit === null ? normalizePath(relativePath) : hit.area.relPath;
209
240
  }
@@ -220,17 +251,37 @@ export class PluginDataAdapter extends FileCollectionAdapter {
220
251
  return super.readMember({ ...ctx, fs: homeFs }, rel, mode, statTimes);
221
252
  }
222
253
  async export(ctx, options) {
223
- this.pendingWarnings = [];
224
- const out = await super.export(ctx, options);
225
- return { ...out, warnings: [...out.warnings, ...this.pendingWarnings] };
254
+ // 每次导出各持一份作用域(审计 P2-7):告警与区域表都属于**这一次**调用,收尾时从它合并/登记
255
+ const scope = { warnings: [] };
256
+ const out = await this.scope.run(scope, () => super.export(ctx, options));
257
+ const merged = { ...out, warnings: [...out.warnings, ...scope.warnings] };
258
+ if (scope.entries !== undefined)
259
+ this.unitsOf.set(merged, scope.entries);
260
+ return merged;
226
261
  }
227
262
  async preview(ctx, options) {
228
- this.pendingWarnings = [];
229
- const out = await super.preview(ctx, options);
230
- return {
231
- ...out,
232
- section: { ...out.section, warnings: [...out.section.warnings, ...this.pendingWarnings] },
263
+ const scope = { warnings: [] };
264
+ const out = await this.scope.run(scope, () => super.preview(ctx, options));
265
+ const section = {
266
+ ...out.section,
267
+ warnings: [...out.section.warnings, ...scope.warnings],
233
268
  };
269
+ if (scope.entries !== undefined)
270
+ this.unitsOf.set(section, scope.entries);
271
+ return { ...out, section };
272
+ }
273
+ /**
274
+ * 收集结束后按**那一次收集**的区域表归组(审计 P2-7)。
275
+ *
276
+ * listUnits 通常在 export/preview 返回之后才被调用(作用域已退出),因此 export/preview 把区域表
277
+ * 挂在产物对象上;这里重新铺作用域再交给基类,unitIdOf 规则只有一处实现。
278
+ * 拿不到登记(例如消费者自己构造的 section、来自快照反序列化)→ 交给基类,走内置来源的兜底口径。
279
+ */
280
+ listUnits(section) {
281
+ const entries = this.unitsOf.get(section);
282
+ if (entries === undefined)
283
+ return super.listUnits(section);
284
+ return this.scope.run({ entries, warnings: [] }, () => super.listUnits(section));
234
285
  }
235
286
  /**
236
287
  * 导入分析 + **写入路径白名单**(本分区唯一的越界防线)。
@@ -243,13 +294,16 @@ export class PluginDataAdapter extends FileCollectionAdapter {
243
294
  // 绝不退回 $DSH_HOME 的 ctx.fs 去比对/写入(那会落到错误位置)。
244
295
  const homeFs = ctx.target.homeFs;
245
296
  const entries = homeFs === undefined ? [] : await this.allowedEntries(ctx.target);
246
- const items = await super.analyzeImport(data, homeFs === undefined ? ctx : { ...ctx, target: { ...ctx.target, fs: homeFs } });
297
+ // 用**本机**白名单表铺作用域:基类逐文件调 unitIdOf 时就有确定口径。
298
+ // 旧代码读的是实例上「上次导出的残留区域表」,并发或首次导入时直接错位(审计 P2-7);
299
+ // 而且被放行的路径必然落在某个本机区域内,区域 id 与导入后 listUnits 的口径一致。
300
+ const items = await this.scope.run({ entries, warnings: [] }, () => super.analyzeImport(data, homeFs === undefined ? ctx : { ...ctx, target: { ...ctx.target, fs: homeFs } }));
247
301
  return items.map((item) => {
248
302
  const ref = item.target?.ref;
249
303
  if (ref === undefined)
250
304
  return item;
251
305
  const rel = normalizeHomeRel(ref);
252
- if (rel !== null && areaOfPath(entries, rel) !== null)
306
+ if (rel !== null && areaOfPath(entries, rel) !== null && !isSensitiveHomeRel(rel))
253
307
  return item;
254
308
  return {
255
309
  id: item.id,
@@ -271,7 +325,7 @@ export class PluginDataAdapter extends FileCollectionAdapter {
271
325
  if (ref !== undefined) {
272
326
  const rel = normalizeHomeRel(ref);
273
327
  const entries = await this.allowedEntries(ctx.target);
274
- if (rel === null || areaOfPath(entries, rel) === null) {
328
+ if (rel === null || areaOfPath(entries, rel) === null || isSensitiveHomeRel(rel)) {
275
329
  return { ok: false, message: engineMsg('adapter.pluginDataPathNotAllowed', { path: ref }) };
276
330
  }
277
331
  }
@@ -2,7 +2,7 @@ import type { PackLocalPluginsResult } from '../core/local-plugin-pack.ts';
2
2
  import type { MsgFunc } from '../core/messages.ts';
3
3
  import { USER_PATCH_FILE } from '../core/patch-layers.ts';
4
4
  import type { PluginEntry, PluginsSection } from '../schema/types.ts';
5
- import type { ApplyResult, ConfigAdapter, ExportOptions, ExportSection, ExportUnit, HostContext, ImportContext, PlanItem, SectionPreview, ValidationResult } from '../core/types.ts';
5
+ import type { ApplyResult, ConfigAdapter, ExportOptions, ExportSection, ExportUnit, HostContext, ImportContext, PlanItem, SectionPreview, SensitiveHit, ValidationResult } from '../core/types.ts';
6
6
  /**
7
7
  * 用户(home)patch 层路径 —— 定义已移到 `core/patch-layers.ts`(issue #71:patch 有 home /
8
8
  * profile 两层,层身份属于引擎知识,不属于某个 adapter)。此处 re-export 保持既有 import 面。
@@ -36,6 +36,19 @@ export declare class PluginsAdapter implements ConfigAdapter<PluginsSection> {
36
36
  private readonly localPack;
37
37
  constructor(selfName?: string, localPack?: LocalPluginPackHook);
38
38
  export(ctx: HostContext, options: ExportOptions): Promise<ExportSection<PluginsSection>>;
39
+ /**
40
+ * issue #136 C:脱敏**归属标注** —— 把 SecretScanner 的命中路径归属回具体 patch 行。
41
+ *
42
+ * 为什么必须做:导出侧把命中字段名/值形状的字符串叶子替换成空串(占位符),语义是「需补录」。
43
+ * 目标机只看到空串,无法区分「被剥空」与「用户主动写空」——于是合并/导入落地时照抄空串,
44
+ * 静默抹掉本机同一行里用户手写的明文(行是整行写回的,行内没有粒度)。
45
+ *
46
+ * 归属规则:命中路径 `patch[i].<内部路径>` → 第 i 行的 `redactedPaths`(行内相对,原样保留
47
+ * 扫描器语法,如 `raw.mcp.args.token`);未命中的行不写该字段(缺省 = 未知,写回侧走保守分支)。
48
+ *
49
+ * 纯函数:不改入参;命中不落在 patch 行上(plugins / pnpmWorkspace / localTarballs 等)→ 原样返回。
50
+ */
51
+ annotateRedactions(sanitized: unknown, hits: SensitiveHit[]): unknown;
39
52
  /**
40
53
  * 只读预览(`/export-preview` 用):与 `export()` **同口径**,但不做任何本地源打包。
41
54
  *