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
@@ -1,18 +1,19 @@
1
1
  /**
2
- * #132 跟随远端删除插件:两个纯函数的行为规格。
2
+ * #132 / #145:跟随远端删除插件的判据 + plugins 分区的按键三方合并。
3
3
  *
4
4
  * 接缝(seam):
5
5
  * 1. planPluginRemovals —— 「哪些已装插件该被删」的唯一判据(开关、祖先、远端、本机三方);
6
- * 2. mergePluginsSection —— plugins 分区的按名三方合并(否则通用 JSON 合并对数组两侧各改即冲突,
6
+ * 2. mergePluginsSection —— plugins 分区的按键三方合并(否则通用 JSON 合并对数组两侧各改即冲突,
7
7
  * 会把「远端删 X + 本机新装 Y」误报成整分区冲突,让删除永远进不了自动应用)。
8
8
  *
9
+ * issue #145 起两者解耦:合并**恒参与**(开关不再决定钩子是否介入),开关只管「远端删了要不要真删」。
9
10
  * 两个函数都是纯函数、零 I/O:引擎与 UI 都只读它们的返回值。
10
11
  */
11
12
  import { test } from 'node:test';
12
13
  import assert from 'node:assert/strict';
13
14
 
14
15
  import { mergePluginsSection, planPluginRemovals } from './plugin-removals.ts';
15
- import type { PluginEntry, PluginsSection } from '../schema/types.ts';
16
+ import type { PatchLine, PluginEntry, PluginsSection } from '../schema/types.ts';
16
17
 
17
18
  function entry(name: string, version: string, extra: Partial<PluginEntry> = {}): PluginEntry {
18
19
  return { name, version, isBundle: false, inBundles: [], enabled: true, ...extra };
@@ -130,15 +131,24 @@ test('planPluginRemovals: 没有祖先(首次同步)→ 一律不删(无
130
131
  assert.deepEqual(plan.kept, []);
131
132
  });
132
133
 
133
- /* ------------------------------------------------------------------ 合并:按名三方 */
134
+ /* ------------------------------------------------------------------ 合并:按键三方 */
134
135
 
135
- /** 钩子只在开关打开时参与;单测里显式开启(关闭路径另有用例)。 */
136
+ /** 开关打开:远端删了、本机未改的条目会被真的删掉(删除判据用同一份开关)。 */
136
137
  const ON = { deletePlugins: true };
137
138
 
138
139
  function section(plugins: PluginEntry[], extra: Partial<PluginsSection> = {}): PluginsSection {
139
140
  return { version: 1, plugins, patch: [], ...extra };
140
141
  }
141
142
 
143
+ function line(file: string, lineId: string, raw: unknown, redactedPaths?: string[]): PatchLine {
144
+ return { file, lineId, raw, ...(redactedPaths === undefined ? {} : { redactedPaths }) };
145
+ }
146
+
147
+ function names(res: { merged: unknown } | undefined): string[] {
148
+ assert.ok(res !== undefined);
149
+ return ((res.merged as PluginsSection).plugins ?? []).map((p) => p.name);
150
+ }
151
+
142
152
  test('mergePluginsSection: 远端删 X、本机新装 Y → 合并结果只留 Y,不报冲突', () => {
143
153
  const res = mergePluginsSection(
144
154
  section([entry('alpha', '1.2.0'), entry('y', '2.0.0')]),
@@ -146,9 +156,8 @@ test('mergePluginsSection: 远端删 X、本机新装 Y → 合并结果只留 Y
146
156
  section([entry('alpha', '1.2.0')]),
147
157
  ON,
148
158
  );
149
- assert.ok(res !== undefined);
150
- assert.deepEqual(res.conflicts, []);
151
- assert.deepEqual((res.merged as PluginsSection).plugins.map((p) => p.name), ['y']);
159
+ assert.deepEqual(res?.conflicts, []);
160
+ assert.deepEqual(names(res), ['y']);
152
161
  });
153
162
 
154
163
  test('mergePluginsSection: 本机升级 X、远端删 X → modify-delete 冲突(不静默删也不静默留)', () => {
@@ -158,28 +167,22 @@ test('mergePluginsSection: 本机升级 X、远端删 X → modify-delete 冲突
158
167
  section([entry('alpha', '1.2.0')]),
159
168
  ON,
160
169
  );
161
- assert.ok(res !== undefined);
162
- assert.equal(res.conflicts.length, 1);
163
- assert.equal(res.conflicts[0]!.path, 'plugins.alpha');
164
- assert.equal(res.conflicts[0]!.reason, 'modify-delete');
170
+ assert.equal(res?.conflicts.length, 1);
171
+ assert.equal(res?.conflicts[0]!.path, 'plugins.alpha');
172
+ assert.equal(res?.conflicts[0]!.reason, 'modify-delete');
165
173
  });
166
174
 
167
175
  test('mergePluginsSection: 两侧同版本 → 保留,两侧同删 → 消失', () => {
168
- const same = mergePluginsSection(
169
- section([entry('alpha', '1.2.0')]),
170
- section([entry('alpha', '1.2.0')]),
171
- undefined,
172
- ON,
173
- );
174
- assert.deepEqual((same!.merged as PluginsSection).plugins.map((p) => p.name), ['alpha']);
176
+ const same = mergePluginsSection(section([entry('alpha', '1.2.0')]), section([entry('alpha', '1.2.0')]), undefined, ON);
177
+ assert.deepEqual(names(same), ['alpha']);
175
178
  const both = mergePluginsSection(section([]), section([]), section([entry('alpha', '1.2.0')]), ON);
176
- assert.deepEqual((both!.merged as PluginsSection).plugins, []);
179
+ assert.deepEqual(names(both), []);
177
180
  });
178
181
 
179
182
  test('mergePluginsSection: 无祖先时本机独有/远端独有都保留(不按删除解释)', () => {
180
183
  const res = mergePluginsSection(section([entry('mine', '1.0.0')]), section([entry('theirs', '1.0.0')]), undefined, ON);
181
- assert.deepEqual(res!.conflicts, []);
182
- assert.deepEqual((res!.merged as PluginsSection).plugins.map((p) => p.name).sort(), ['mine', 'theirs']);
184
+ assert.deepEqual(res?.conflicts, []);
185
+ assert.deepEqual(names(res).sort(), ['mine', 'theirs']);
183
186
  });
184
187
 
185
188
  test('mergePluginsSection: 两侧把同一插件改到不同版本 → both-modified 冲突', () => {
@@ -189,33 +192,190 @@ test('mergePluginsSection: 两侧把同一插件改到不同版本 → both-modi
189
192
  section([entry('alpha', '1.2.0')]),
190
193
  ON,
191
194
  );
192
- assert.equal(res!.conflicts.length, 1);
193
- assert.equal(res!.conflicts[0]!.reason, 'both-modified');
195
+ assert.equal(res?.conflicts.length, 1);
196
+ assert.equal(res?.conflicts[0]!.reason, 'both-modified');
194
197
  });
195
198
 
196
- test('mergePluginsSection: 插件列表以外的字段(patch 行等)两侧不必相同 —— 不同即交回通用合并', () => {
199
+ test('mergePluginsSection: 开关关着 + 远端删了本机未改的插件 → 保留(合并仍参与,绝不交回通用路径)', () => {
197
200
  const res = mergePluginsSection(
198
- section([entry('alpha', '1.2.0')], { pnpmWorkspace: 'onlyBuiltDependencies: [a]\n' }),
199
- section([entry('alpha', '1.2.0')], { pnpmWorkspace: 'onlyBuiltDependencies: [b]\n' }),
200
201
  section([entry('alpha', '1.2.0')]),
202
+ section([]),
203
+ section([entry('alpha', '1.2.0')]),
204
+ { deletePlugins: false },
205
+ );
206
+ assert.ok(res !== undefined, '关着开关也必须参与:否则 patch 行等与卸载无关的改动会整分区冲突');
207
+ assert.deepEqual(res.conflicts, []);
208
+ assert.deepEqual(names(res), ['alpha'], '包还在盘上,删了只会下一轮复活 —— 保留才是诚实结果');
209
+ });
210
+
211
+ test('mergePluginsSection: 不传钩子(缺省开关关)也能按名/按行合并', () => {
212
+ const res = mergePluginsSection(
213
+ section([entry('alpha', '1.2.0')], { patch: [line('cfg.yml', 'l1', { a: 1 })] }),
214
+ section([], { patch: [line('cfg.yml', 'l2', { b: 2 })] }),
215
+ section([entry('alpha', '1.2.0')], { patch: [line('cfg.yml', 'l1', { a: 1 })] }),
216
+ );
217
+ assert.ok(res !== undefined);
218
+ assert.deepEqual(res.conflicts, []);
219
+ assert.deepEqual(names(res), ['alpha']);
220
+ assert.deepEqual((res.merged as PluginsSection).patch.map((p) => p.lineId), ['l1', 'l2']);
221
+ });
222
+
223
+ test('mergePluginsSection: 自身插件远端删了也保留、两侧改不同版本时本机胜,且都不报冲突', () => {
224
+ const deleted = mergePluginsSection(
225
+ section([entry(SELF, '0.9.1')]),
226
+ section([]),
227
+ section([entry(SELF, '0.9.1')]),
228
+ { ...ON, selfPluginName: SELF },
229
+ );
230
+ assert.deepEqual(deleted?.conflicts, []);
231
+ assert.deepEqual(names(deleted), [SELF]);
232
+ const changed = mergePluginsSection(
233
+ section([entry(SELF, '0.9.2')]),
234
+ section([entry(SELF, '0.9.3')]),
235
+ section([entry(SELF, '0.9.1')]),
236
+ { ...ON, selfPluginName: SELF },
237
+ );
238
+ assert.deepEqual(changed?.conflicts, []);
239
+ assert.deepEqual(names(changed), [SELF]);
240
+ assert.equal(((changed!.merged as PluginsSection).plugins[0]!).version, '0.9.2');
241
+ });
242
+
243
+ test('mergePluginsSection: patch 行按 file+lineId 配对 —— 同一行两侧都改 → both-modified(路径带文件名+行号)', () => {
244
+ const res = mergePluginsSection(
245
+ section([], { patch: [line('cfg.yml', 'l1', { timeout: 10 })] }),
246
+ section([], { patch: [line('cfg.yml', 'l1', { timeout: 20 })] }),
247
+ section([], { patch: [line('cfg.yml', 'l1', { timeout: 1 })] }),
201
248
  ON,
202
249
  );
203
- assert.equal(res, undefined, 'patch/pnpmWorkspace 的口径由通用路径负责,这里不自造第二套');
250
+ assert.equal(res?.conflicts.length, 1);
251
+ assert.equal(res?.conflicts[0]!.reason, 'both-modified');
252
+ assert.equal(res?.conflicts[0]!.path, 'patch.cfg.yml#l1', '同文件多行要能分辨');
204
253
  });
205
254
 
206
- test('mergePluginsSection: 形状不认识 → undefined(畸形数据交通用路径的形状闸门)', () => {
207
- assert.equal(mergePluginsSection({ version: 2 } as unknown as PluginsSection, section([]), undefined, ON), undefined);
255
+ test('mergePluginsSection: 同 lineId 不同文件不撞键(两行都保留)', () => {
256
+ const res = mergePluginsSection(
257
+ section([], { patch: [line('a.yml', 'l1', { x: 1 })] }),
258
+ section([], { patch: [line('b.yml', 'l1', { y: 1 })] }),
259
+ undefined,
260
+ ON,
261
+ );
262
+ assert.deepEqual(res?.conflicts, []);
263
+ assert.deepEqual((res!.merged as PluginsSection).patch.map((p) => p.file).sort(), ['a.yml', 'b.yml']);
264
+ });
265
+
266
+ test('mergePluginsSection: 导出侧剥空 + redactedPaths 与远端明文是同一行(门②,不报冲突)', () => {
267
+ // 本机(导出侧):secret 被剥成空串并记进 redactedPaths;远端/祖先:明文、无该字段。
268
+ const redacted = line('cfg.yml', 'l1', { token: '', keep: 1 }, ['raw.token']);
269
+ const plain = line('cfg.yml', 'l1', { token: 'sk-live-123', keep: 1 });
270
+ const res = mergePluginsSection(section([], { patch: [redacted] }), section([], { patch: [plain] }), section([], { patch: [plain] }), ON);
271
+ assert.deepEqual(res?.conflicts, [], '被剥空的叶子按三侧 redactedPaths 并集归一化后是同一身份');
272
+ // 身份相同 → 保留本机那一行(导出侧形态):redactedPaths 原样留下,写回守卫据此换回本机明文。
273
+ const merged = (res!.merged as PluginsSection).patch[0]!;
274
+ assert.deepEqual(merged.raw, { token: '', keep: 1 });
275
+ assert.deepEqual(merged.redactedPaths, ['raw.token']);
276
+ // 归一化只抹「被声明剥空」的叶子,绝不挡真实改动:远端把 keep 改了 → 采用远端那一行。
277
+ const changed = line('cfg.yml', 'l1', { token: 'sk-live-123', keep: 2 });
278
+ const res2 = mergePluginsSection(section([], { patch: [redacted] }), section([], { patch: [changed] }), section([], { patch: [plain] }), ON);
279
+ assert.deepEqual(res2?.conflicts, []);
280
+ assert.deepEqual((res2!.merged as PluginsSection).patch[0]!.raw, { token: 'sk-live-123', keep: 2 });
281
+ });
282
+
283
+ test('mergePluginsSection: 不在 redactedPaths 里的字段真改了 → 仍然 both-modified', () => {
284
+ const redacted = line('cfg.yml', 'l1', { token: '', keep: 2 }, ['raw.token']);
285
+ const remote = line('cfg.yml', 'l1', { token: 'sk-other', keep: 3 });
286
+ const res = mergePluginsSection(
287
+ section([], { patch: [redacted] }),
288
+ section([], { patch: [remote] }),
289
+ section([], { patch: [line('cfg.yml', 'l1', { token: 'sk-base', keep: 1 })] }),
290
+ ON,
291
+ );
292
+ assert.equal(res?.conflicts.length, 1);
293
+ assert.equal(res?.conflicts[0]!.reason, 'both-modified');
208
294
  });
209
295
 
210
- test('mergePluginsSection: 开关关着 → 钩子不参与(undefined = 通用合并,行为与 #132 之前逐字一致)', () => {
211
- assert.equal(
212
- mergePluginsSection(
213
- section([entry('alpha', '1.2.0')]),
214
- section([]),
215
- section([entry('alpha', '1.2.0')]),
216
- { deletePlugins: false },
217
- ),
296
+ test('mergePluginsSection: 合并输出保留本机行的 redactedPaths(写回守卫要靠它)', () => {
297
+ const redacted = line('cfg.yml', 'l1', { token: '', keep: 1 }, ['raw.token']);
298
+ const res = mergePluginsSection(
299
+ section([], { patch: [redacted] }),
300
+ section([], { patch: [line('cfg.yml', 'l1', { token: '', keep: 1 }, ['raw.token']), line('cfg.yml', 'l2', { b: 2 })] }),
218
301
  undefined,
219
- '开关关闭时绝不能丢掉本机条目:包还在盘上,下一轮导出会把它当本机独有推回远端 = 复活',
302
+ ON,
303
+ );
304
+ assert.deepEqual(res?.conflicts, []);
305
+ const kept = (res!.merged as PluginsSection).patch.find((p) => p.lineId === 'l1')!;
306
+ assert.deepEqual(kept.redactedPaths, ['raw.token']);
307
+ assert.equal((res!.merged as PluginsSection).patch.length, 2);
308
+ });
309
+
310
+ test('mergePluginsSection: pnpmWorkspace 单侧改动取该侧,两侧都改 → overlap 冲突(不猜用哪一份)', () => {
311
+ const oneSide = mergePluginsSection(
312
+ section([], { pnpmWorkspace: 'onlyBuiltDependencies: [a]\n' }),
313
+ section([], { pnpmWorkspace: 'onlyBuiltDependencies: [b]\n' }),
314
+ section([], { pnpmWorkspace: 'onlyBuiltDependencies: [a]\n' }),
315
+ ON,
316
+ );
317
+ assert.deepEqual(oneSide?.conflicts, []);
318
+ assert.equal((oneSide!.merged as PluginsSection).pnpmWorkspace, 'onlyBuiltDependencies: [b]\n');
319
+ const both = mergePluginsSection(
320
+ section([], { pnpmWorkspace: 'onlyBuiltDependencies: [b]\n' }),
321
+ section([], { pnpmWorkspace: 'onlyBuiltDependencies: [c]\n' }),
322
+ section([], { pnpmWorkspace: 'onlyBuiltDependencies: [a]\n' }),
323
+ ON,
324
+ );
325
+ assert.equal(both?.conflicts.length, 1);
326
+ assert.equal(both?.conflicts[0]!.path, 'pnpmWorkspace');
327
+ assert.equal(both?.conflicts[0]!.reason, 'overlap');
328
+ });
329
+
330
+ test('mergePluginsSection: 三侧 pnpmWorkspace 都是 null → 原样保留(不抹成缺键,复审 P0-1)', () => {
331
+ const res = mergePluginsSection(section([], { pnpmWorkspace: null }), section([], { pnpmWorkspace: null }), section([], { pnpmWorkspace: null }), ON);
332
+ assert.deepEqual(res?.conflicts, []);
333
+ assert.ok('pnpmWorkspace' in (res!.merged as PluginsSection), 'null 是合法值,删掉会让合并结果与两侧都不等 ⇒ 每轮假合并');
334
+ assert.equal((res!.merged as PluginsSection).pnpmWorkspace, null);
335
+ assert.equal(res?.mergePoints, 0);
336
+ });
337
+
338
+ test('mergePluginsSection: 本机关掉插件、远端升版本 → 版本听远端,启停留本机(复审 P0-2)', () => {
339
+ const res = mergePluginsSection(
340
+ section([entry('alpha', '1.2.0', { enabled: false })]),
341
+ section([entry('alpha', '1.3.0')]),
342
+ section([entry('alpha', '1.2.0')]),
343
+ ON,
220
344
  );
345
+ assert.deepEqual(res?.conflicts, []);
346
+ const merged = (res!.merged as PluginsSection).plugins[0]!;
347
+ assert.equal(merged.version, '1.3.0');
348
+ assert.equal(merged.enabled, false, '本机停用是用户意图,不能被远端版本覆盖');
349
+ });
350
+
351
+ test('mergePluginsSection: 开关打开时远端删 patch 行也不跟删(开关只管插件,复审 P1-1)', () => {
352
+ const kept = line('cfg.yml', 'l1', { a: 1 });
353
+ const res = mergePluginsSection(section([], { patch: [kept] }), section([]), section([], { patch: [kept] }), ON);
354
+ assert.deepEqual(res?.conflicts, []);
355
+ assert.deepEqual((res!.merged as PluginsSection).patch.map((p) => p.lineId), ['l1']);
356
+ });
357
+
358
+ test('mergePluginsSection: patch 行重复 file+lineId → 整轮交回通用路径(不静默吞条目,复审 P1-2)', () => {
359
+ const dup = [line('cfg.yml', 'l1', { a: 1 }), line('cfg.yml', 'l1', { a: 2 })];
360
+ assert.equal(mergePluginsSection(section([], { patch: dup }), section([], { patch: dup }), undefined, ON), undefined);
361
+ });
362
+
363
+ test('mergePluginsSection: patch 冲突路径带 lineId(同文件两行能分辨,复审 P2)', () => {
364
+ const res = mergePluginsSection(
365
+ section([], { patch: [line('cfg.yml', 'l7', { a: 2 })] }),
366
+ section([], { patch: [line('cfg.yml', 'l7', { a: 3 })] }),
367
+ section([], { patch: [line('cfg.yml', 'l7', { a: 1 })] }),
368
+ ON,
369
+ );
370
+ assert.equal(res?.conflicts[0]!.path, 'patch.cfg.yml#l7');
371
+ });
372
+
373
+ test('mergePluginsSection: 远端独有的未知字段被采纳(不被本机形状吞掉,复审 P2)', () => {
374
+ const remote = { ...section([]), pluginsMeta: { scanned: true } } as unknown as PluginsSection;
375
+ const res = mergePluginsSection(section([]), remote, undefined, ON);
376
+ assert.deepEqual((res!.merged as unknown as { pluginsMeta: unknown }).pluginsMeta, { scanned: true });
377
+ });
378
+
379
+ test('mergePluginsSection: 形状不认识 → undefined(畸形数据交通用路径的形状闸门)', () => {
380
+ assert.equal(mergePluginsSection({ version: 2 } as unknown as PluginsSection, section([]), undefined, ON), undefined);
221
381
  });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * #132:同步「跟随远端删除插件」的**唯一判据**与 plugins 分区的按名三方合并。
2
+ * #132 / #145:同步「跟随远端删除插件」的**唯一判据**,以及 plugins 分区的按键三方合并。
3
3
  *
4
4
  * 为什么必须单独一个模块:
5
5
  * 1. 删除判定是纯逻辑(开关 × 祖先 × 远端 × 本机),散进引擎里既测不了也说不清;
@@ -7,6 +7,13 @@
7
7
  * 且不逐字相等 → 冲突」,而本分区的日常形态恰恰是「A 机卸载了 X、B 机新装了 Y」,通用路径
8
8
  * 会把它报成整分区冲突,于是删除永远进不了自动应用(issue #132 的行为表 A→B 走不通)。
9
9
  *
10
+ * issue #145 把两件事彻底解耦(本条是 #132 的语义修正):
11
+ * - **合并恒参与**:开关不再决定钩子是否介入。以前关着开关 = 整个分区交回通用 JSON 合并,
12
+ * 于是与卸载无关的改动(patch 行新增一行)也会因为「数组两侧都改」而整分区冲突;
13
+ * - **开关只管删除**:`deletePlugins` 只决定「远端删了、本机未改的条目要不要真的删」,关着就
14
+ * 保留本机条目(包还在盘上,删了也只会下一轮复活)。
15
+ * - 外壳条目(patch 行 / 本地 tarball / patch 文件)同一口径:跟随三方合并,删除也受同一个开关。
16
+ *
10
17
  * 删除判据(缺一不可,全部满足才删):
11
18
  * - 开关打开(`SyncSelection.deletePlugins`,缺省关);
12
19
  * - **祖先**里有它(A 机那轮同步见过的状态)——没有祖先就没有「谁删了它」的证据;
@@ -19,10 +26,14 @@
19
26
  *
20
27
  * 纯函数、零 I/O:引擎调用它拿计划,UI 调用它拿「将删除」清单。
21
28
  */
22
- import type { PluginEntry, PluginsSection, SectionData } from '../schema/types.ts';
29
+ import type { LocalPluginTarball, PatchLine, PluginEntry, PluginsSection, PnpmPatchFile, SectionData } from '../schema/types.ts';
23
30
  import type { MergeConflict } from './merge.ts';
24
- import type { GranularMergeOutcome } from './workspace-merge.ts';
31
+ import type { GranularMergeHooks, GranularMergeOutcome } from './workspace-merge.ts';
25
32
  import { isBundlesOnlyEntry } from '../core/plugin-cli.ts';
33
+ import { mergeKeyedList } from './merge-keyed.ts';
34
+ import { patchIdentityContext, patchLineIdentity } from './patch-line-identity.ts';
35
+ import type { PatchIdentityContext } from './patch-line-identity.ts';
36
+ import { mergeJsonValues } from './text-merge.ts';
26
37
 
27
38
  /** 一条「该卸载」的结论(version = 祖先/本机一致的版本,用于报告与回滚重装目标)。 */
28
39
  export interface PluginRemoval {
@@ -125,84 +136,159 @@ function entryKey(e: PluginEntry): string {
125
136
  return [e.version ?? '', e.spec ?? '', e.bundlesOnly === true ? '1' : '0'].join('\u0000');
126
137
  }
127
138
 
128
- /** 插件列表以外的字段(patch 行 / pnpm-workspace 原文 / 本地 tarball / patch 文件)必须两侧相等才介入。 */
129
- function sameShell(l: PluginsSection, r: PluginsSection): boolean {
130
- const pick = (s: PluginsSection): string => JSON.stringify({
131
- patch: s.patch ?? [],
132
- pnpmWorkspace: s.pnpmWorkspace ?? null,
133
- localTarballs: s.localTarballs ?? [],
134
- patchFiles: s.patchFiles ?? [],
135
- });
136
- return pick(l) === pick(r);
139
+ /** patch 行的键分隔符:file 与 lineId 各自可能含任意字符,用 NUL 才不会撞键。 */
140
+ const PATCH_KEY_SEP = '\u0000';
141
+
142
+ /** patch 行的身份键 = file + lineId(同一文件里 lineId 才是行身份;issue #145)。 */
143
+ function patchLineKey(line: PatchLine): string {
144
+ return [line.file ?? '', line.lineId ?? ''].join(PATCH_KEY_SEP);
145
+ }
146
+
147
+ /** 本地 tarball 的身份(同包名 = 同一条目;内容变了才算改过)。 */
148
+ function tarballIdentity(t: LocalPluginTarball): string {
149
+ return JSON.stringify({ version: t.version ?? '', relativePath: t.relativePath ?? '', base64: t.base64 ?? '' });
150
+ }
151
+
152
+ /** patch 文件的身份(同相对路径 = 同一条目)。 */
153
+ function patchFileIdentity(f: PnpmPatchFile): string {
154
+ return JSON.stringify({ relativePath: f.relativePath ?? '', base64: f.base64 ?? '' });
137
155
  }
138
156
 
139
157
  /**
140
- * plugins 分区的按名三方合并(`merge.ts` 的 `GRANULAR_MERGES.plugins`)。
158
+ * plugins 分区的按键三方合并(`merge.ts` 的 `GRANULAR_MERGES.plugins`)。
141
159
  *
142
- * 逐名规则与 git 同口径,祖先只用于判断「谁动了它」,绝不猜:
143
- * - 两侧都有:身份相同 → 保留;某一侧与祖先相同 → 取另一侧;两侧都变(或没有祖先)→ both-modified 冲突;
144
- * - 只有本机:有祖先且与祖先相同 → 跟随远端删除(真删除);无祖先 → 本机独有,保留;有祖先且不同 →
145
- * modify-delete 冲突(用户在 A 机卸载、B 机却升级过它,不能替用户选);
146
- * - 只有远端:有祖先且与祖先相同 → 本机删除,跟随(不复活);无祖先 → 远端独有,采纳;有祖先且不同 →
147
- * delete-modify 冲突;
148
- * - 两侧都没有:消失。
160
+ * 逐条规则见 `merge-keyed.ts`;本函数只负责「四条有序集合各用什么键与身份」以及
161
+ * `pnpmWorkspace` 原文的三方(两侧都改且不同 → overlap 交人工,与通用 JSON 合并同口径)。
149
162
  *
150
- * 插件列表以外的字段不一致时返回 `undefined`:patch 行/pnpm-workspace 有各自的既有口径,
151
- * 在这里再造一套合并只会和通用路径打架(通用路径会整分区处理,其中包含 plugins 数组的旧行为)。
163
+ * 形状不认识(`version !== 1` 或缺 plugins 数组)时返回 `undefined`:畸形数据交回通用路径的
164
+ * 形状闸门,这里不另造第二套拒绝逻辑。
152
165
  */
153
166
  export function mergePluginsSection(
154
167
  local: SectionData,
155
168
  remote: SectionData,
156
169
  ancestor: SectionData | undefined,
157
- hooks: { deletePlugins?: boolean } = {},
170
+ hooks: GranularMergeHooks = {},
158
171
  ): GranularMergeOutcome | undefined {
159
- // 开关关着 → 钩子不参与(交回通用合并 = 与 #132 之前逐字一致)。若照常「跟随远端删除」,
160
- // 合并结果会丢掉本机条目:插件包还在盘上,下一轮导出会把它当「本机独有」推回远端 = 复活。
161
- if (hooks.deletePlugins !== true) return undefined;
162
172
  const l = asPlugins(local);
163
173
  const r = asPlugins(remote);
164
174
  if (l === undefined || r === undefined) return undefined;
165
175
  const a = ancestor === undefined ? undefined : asPlugins(ancestor);
166
176
  if (ancestor !== undefined && a === undefined) return undefined;
167
- if (!sameShell(l, r)) return undefined;
168
-
169
- const aMap = byName(a?.plugins);
170
- const rMap = byName(r.plugins);
171
- const merged: PluginEntry[] = [];
172
- const conflicts: MergeConflict[] = [];
173
- let mergePoints = 0;
174
- const conflict = (path: string, reason: 'both-modified' | 'modify-delete' | 'delete-modify', lp: PluginEntry | undefined, rp: PluginEntry | undefined, ap: PluginEntry | undefined): void => {
175
- conflicts.push({ path, kind: 'key', reason, autoMergeAttempted: false, local: lp, remote: rp, ancestor: ap });
176
- };
177
-
178
- for (const lp of l.plugins) {
179
- const name = lp.name;
180
- const rp = rMap.get(name);
181
- const ap = aMap.get(name);
182
- if (rp !== undefined) {
183
- if (entryKey(lp) === entryKey(rp)) { merged.push(lp); continue; }
184
- const lChanged = ap === undefined || entryKey(lp) !== entryKey(ap);
185
- const rChanged = ap === undefined || entryKey(rp) !== entryKey(ap);
186
- if (lChanged && rChanged) { conflict(`plugins.${name}`, 'both-modified', lp, rp, ap); continue; }
187
- if (lChanged) { merged.push(lp); mergePoints += 1; continue; }
188
- merged.push(rp);
189
- mergePoints += 1;
190
- continue;
177
+
178
+ // 开关只决定「远端删了要不要真删」,不再决定钩子是否介入(issue #145 解耦)。
179
+ const followDelete = hooks.deletePlugins === true;
180
+ const selfName = hooks.selfPluginName ?? '';
181
+
182
+ const plugins = mergeKeyedList<PluginEntry>({
183
+ local: l.plugins,
184
+ remote: r.plugins,
185
+ ancestor: a?.plugins,
186
+ spec: {
187
+ keyOf: (p) => (typeof p.name === 'string' ? p.name : ''),
188
+ identityOf: (p) => entryKey(p),
189
+ pathOf: (name) => `plugins.${name}`,
190
+ followDelete,
191
+ // 自身条目永不删、永不报冲突:删了等于把正在跑的宿主插件卸掉。
192
+ keepLocal: (p) => selfName !== '' && p.name === selfName,
193
+ // 版本/来源听远端(本机没改过它才走这条分支),启停是本机 UI 态 —— 恒留本机,
194
+ // 否则远端升一次版本就把用户在本机关掉的插件改回启用(复审 P0-2)。
195
+ compose: (local, remote) => ({ ...remote, enabled: local.enabled }),
196
+ },
197
+ });
198
+ const patch = mergeKeyedList<PatchLine>({
199
+ local: l.patch ?? [],
200
+ remote: r.patch ?? [],
201
+ ancestor: a?.patch,
202
+ spec: {
203
+ keyOf: patchLineKey,
204
+ // 身份按三侧 redactedPaths 并集归一化:本机被剥空、远端明文的同一行算「没改过」(门②)。
205
+ // 并集路径每键只解析一次(上下文),三侧各自比较时复用 —— 行多时不再逐次重解析。
206
+ identityContextOf: (peers) => patchIdentityContext(peers),
207
+ identityOf: (line, peers, context) => patchLineIdentity(line, peers, context as PatchIdentityContext | undefined),
208
+ // 冲突路径带 lineId:同一文件里两行各自冲突时必须能分辨(复审 P2)。
209
+ pathOf: (key) => {
210
+ const [file = '', lineId = ''] = key.split(PATCH_KEY_SEP);
211
+ return `patch.${file}#${lineId}`;
212
+ },
213
+ // 外壳列表**不跟随删除**:deletePlugins 的语义是「远端删了插件」,不是「远端删了 MCP 配置」
214
+ // —— 跟着删会把本机还在用的 patch 行 / tarball 一起丢掉(复审 P1-1)。
215
+ followDelete: false,
216
+ },
217
+ });
218
+ const tarballs = mergeKeyedList<LocalPluginTarball>({
219
+ local: l.localTarballs ?? [],
220
+ remote: r.localTarballs ?? [],
221
+ ancestor: a?.localTarballs,
222
+ spec: {
223
+ keyOf: (t) => (typeof t.packageName === 'string' ? t.packageName : ''),
224
+ identityOf: (t) => tarballIdentity(t),
225
+ pathOf: (key) => `localTarballs.${key}`,
226
+ followDelete: false, // 同上:开关只管插件清单(复审 P1-1)
227
+ },
228
+ });
229
+ const files = mergeKeyedList<PnpmPatchFile>({
230
+ local: l.patchFiles ?? [],
231
+ remote: r.patchFiles ?? [],
232
+ ancestor: a?.patchFiles,
233
+ spec: {
234
+ keyOf: (f) => (typeof f.relativePath === 'string' ? f.relativePath : ''),
235
+ identityOf: (f) => patchFileIdentity(f),
236
+ pathOf: (key) => `patchFiles.${key}`,
237
+ followDelete: false, // 同上:开关只管插件清单(复审 P1-1)
238
+ },
239
+ });
240
+
241
+ // 形状不支持按键合并(同键重复 / 非对象条目 / 无身份键):交回通用路径,
242
+ // 绝不在这里「留一条丢一条」(复审 P1-2)。
243
+ if (plugins.malformed || patch.malformed || tarballs.malformed || files.malformed) return undefined;
244
+
245
+ const conflicts: MergeConflict[] = [
246
+ ...plugins.conflicts,
247
+ ...patch.conflicts,
248
+ ...tarballs.conflicts,
249
+ ...files.conflicts,
250
+ ];
251
+ let mergePoints = plugins.mergePoints + patch.mergePoints + tarballs.mergePoints + files.mergePoints;
252
+
253
+ // pnpm-workspace 原文:标量/对象三方。两侧都改且不同 → overlap(不猜用哪一份)。
254
+ // null 与「没有这个键」在语义上是同一件事(adapter 没有 patch 组时导出 null),
255
+ // 但三方合并之后必须按**原始形态**写回:本机原本带这个键就继续写 null,不能抹成缺键(复审 P0-1)。
256
+ const wsCarried = 'pnpmWorkspace' in l || 'pnpmWorkspace' in r;
257
+ const wsLocal = l.pnpmWorkspace ?? null;
258
+ const wsRemote = r.pnpmWorkspace ?? null;
259
+ const wsAncestor = a?.pnpmWorkspace ?? null;
260
+ const ws = mergeJsonValues(wsAncestor, wsLocal, wsRemote, 'pnpmWorkspace');
261
+ const wsMerged = ws.ok ? (ws.merged as string | null | undefined) : undefined;
262
+ if (!ws.ok) {
263
+ for (const _ of ws.conflicts) {
264
+ conflicts.push({
265
+ path: 'pnpmWorkspace',
266
+ kind: 'key',
267
+ reason: 'overlap',
268
+ autoMergeAttempted: true,
269
+ local: wsLocal ?? null,
270
+ remote: wsRemote ?? null,
271
+ ancestor: wsAncestor ?? null,
272
+ });
191
273
  }
192
- // 只有本机有
193
- if (ap === undefined) { merged.push(lp); mergePoints += 1; continue; } // 本机独有
194
- if (entryKey(lp) === entryKey(ap)) { mergePoints += 1; continue; } // 本机未改、远端删 → 跟随删除
195
- conflict(`plugins.${name}`, 'modify-delete', lp, undefined, ap);
196
- }
197
- // 只有远端有的
198
- for (const rp of r.plugins) {
199
- const name = rp.name;
200
- if (l.plugins.some((p) => p.name === name)) continue;
201
- const ap = aMap.get(name);
202
- if (ap === undefined) { merged.push(rp); mergePoints += 1; continue; } // 远端独有
203
- if (entryKey(rp) === entryKey(ap)) { mergePoints += 1; continue; } // 远端未改、本机删 → 跟随删除
204
- conflict(`plugins.${name}`, 'delete-modify', undefined, rp, ap);
274
+ } else if (wsMerged !== wsLocal) {
275
+ mergePoints += 1;
205
276
  }
277
+
206
278
  if (conflicts.length > 0) return { merged: l as SectionData, conflicts, mergePoints };
207
- return { merged: { ...l, plugins: merged } as SectionData, conflicts: [], mergePoints };
279
+
280
+ // 以远端为底再盖本机:远端独有的未知/将来字段被采纳,而不是被本机形状悄悄吞掉(复审 P2)。
281
+ const next: PluginsSection & Record<string, unknown> = { ...r, ...l };
282
+ next.plugins = plugins.merged;
283
+ next.patch = patch.merged;
284
+ // 可选字段只在「本机或合并结果里确实有」时写回:不擅自在载荷里新增空字段。
285
+ if (l.localTarballs !== undefined || tarballs.merged.length > 0) next.localTarballs = tarballs.merged;
286
+ else delete next.localTarballs;
287
+ if (l.patchFiles !== undefined || files.merged.length > 0) next.patchFiles = files.merged;
288
+ else delete next.patchFiles;
289
+ // 只有「两侧都没带这个键、合并也没产出值」才删键;否则原样写回(含 null)。
290
+ // 把 null 抹成缺键会让合并结果与两侧都不等 ⇒ 每轮都判「已合并」,永不收敛(复审 P0-1)。
291
+ if (wsMerged === undefined || (wsMerged === null && !wsCarried)) delete next.pnpmWorkspace;
292
+ else next.pnpmWorkspace = wsMerged;
293
+ return { merged: next as SectionData, conflicts: [], mergePoints };
208
294
  }