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
@@ -21,6 +21,7 @@ import os from 'node:os';
21
21
  import path from 'node:path';
22
22
  import { createAdapters } from '../adapters/index.js';
23
23
  import { defaultSecretScanner } from '../core/exporter.js';
24
+ import { sanitizeSectionData } from '../core/section-sanitize.js';
24
25
  import { Importer } from '../core/importer.js';
25
26
  import { DEFAULT_ROLLBACK_ON_ERROR } from '../core/import-defaults.js';
26
27
  import { isFileSection, SECTION_FILE_PREFIXES, SECTION_JSON_PATHS } from '../schema/config.js';
@@ -37,16 +38,25 @@ import { applyPluginRemovalStep, pluginRemovalPlanOf, pluginRemovalPreviewOf, re
37
38
  import { OPT_IN_SYNC_SECTIONS } from './sync-selection.js';
38
39
  import { listRemoteSnapshotIndex, planSessionBookkeeping, remoteTombstonesOf, stripTombstonedSessionsInPlace, } from './session-tombstones.js';
39
40
  import { DEFAULT_RETENTION_POLICY, selectPruneCandidatesByPolicy } from './retention-policy.js';
40
- import { hashSection, loadSyncState, resolveDeviceIdentity, saveSyncState } from './sync-state.js';
41
+ import { hashSection, loadSyncState, resolveDeviceIdentity } from './sync-state.js';
42
+ import { pendingMergeFor as buildPendingMerge, recordPendingMerge as persistPendingMerge, writeMergeBaseline as persistMergeBaseline, } from './pending-merge.js';
43
+ import { pendingMergeAfterPush, resolveHeldSections, resolvePushTargets } from './push-skip.js';
44
+ import { memoAsync } from '../utils/async-once.js';
45
+ import { hasLocalSectionChanges } from './local-changes.js';
46
+ // 写基线(祖先副本 + sync-state)的实现整体下沉,引擎只做环境透传(体量棘轮 + G-44 口径集中)
47
+ import { recordBaseline as recordBaselineAt } from './baseline-record.js';
48
+ // issue #140:内容判定(拉取/推送共用同一处实现,绝不各自比 id)
49
+ import { diffSnapshotContent, hashSections } from './content-diff.js';
41
50
  import { isEncryptedSections, PROBE_UNSUPPORTED_CODE, SyncTransportError } from './transport.js';
42
51
  import { msgOf, zhMsg } from '../core/messages.js';
43
52
  import { engineMsg } from './messages.js';
44
- import { DEFAULT_ANCESTOR_KEEP, pruneAncestors, tryLoadAncestor, writeAncestor, writeEncryptedAncestor } from './ancestor.js';
53
+ import { tryLoadAncestor } from './ancestor.js';
45
54
  import { merge as mergeSections } from './merge.js';
46
55
  import { prepareApplyBundle } from './apply-bundle.js';
47
56
  import { mergePreviewSectionView, previewCaliberDiffersFromExport } from './merge-preview-view.js';
48
57
  import { gcSkipWarning, readGcSkipCode, reportGcSkipOnce } from './gc-skip.js';
49
58
  import { classifyMergePlan } from './risk.js';
59
+ import { createMergeApplySnapshot, planMergeApply } from './merge-apply-plan.js';
50
60
  import { registerMessageCatalog } from '../core/engine-locale.js';
51
61
  import { createSnapshot, selectPruneCandidates } from '../core/backup.js';
52
62
  import { rollback } from '../core/rollback.js';
@@ -64,6 +74,7 @@ const zh = {
64
74
  'sync.sessionTombstonesInherited': '已从远端快照继承 {count} 条会话删除墓碑:删除继续跨设备传播(本机数据不动)',
65
75
  'sync.applyMergeResolutionsNoImporter': 'applyMergeResolutions: SyncEngine 缺少 importer(需在 options 中注入)',
66
76
  'sync.mergePendingConflicts': '仍有 {count} 个分区未裁决({sections}):已裁决的部分已写入本机,但基线不推进,冲突下一轮会重新出现',
77
+ 'sync.mergeHeldConflicts': '有 {count} 个叶级冲突未裁决(分区:{sections}):这些项保持本机原值、未写入,其余内容已应用;确认后下一轮再合并',
67
78
  'sync.baselineRexportFailed': '写回成功但重新导出本机分区失败({sections}):无法证明基线与本机一致,本次**不记基线**(远端指针保持原值,下一轮重新合并收敛)',
68
79
  'sync.pushBaselineAdopted': '远端最新快照 {remote} 是本机上次推送的(本机基线停在 {base},上次推送在记录基线前被打断):已把它收养为基线并继续本次推送',
69
80
  'sync.pushBaselineAdoptedNoAncestor': '远端最新快照 {remote} 是本机上次推送的,但本机没有它的本地祖先副本:已收养基线(下次合并退化为两方合并,结果仍安全)',
@@ -74,6 +85,7 @@ const en = {
74
85
  'sync.sessionTombstonesInherited': 'Inherited {count} session deletion tombstone(s) from the remote snapshot: deletions keep propagating across devices (local data untouched)',
75
86
  'sync.applyMergeResolutionsNoImporter': 'applyMergeResolutions: SyncEngine is missing the importer (must be injected via options)',
76
87
  'sync.mergePendingConflicts': '{count} section(s) still have no decision ({sections}): the decided parts were written locally, but the baseline is not advanced, so the conflicts will reappear next round',
88
+ 'sync.mergeHeldConflicts': '{count} leaf-level conflict(s) remain undecided (sections: {sections}): those items keep the local value and were not written, while the rest was applied; they merge again next round once decided',
77
89
  'sync.baselineRexportFailed': 'The write succeeded but re-exporting the local section(s) failed ({sections}): the baseline cannot be proven to match this machine, so no baseline was recorded (the remote pointer keeps its old value and the next merge converges again)',
78
90
  'sync.pushBaselineAdopted': 'The newest remote snapshot {remote} was pushed by this device (its baseline stopped at {base}: that push was interrupted before recording the baseline): the baseline has been adopted and this push continues',
79
91
  'sync.pushBaselineAdoptedNoAncestor': 'The newest remote snapshot {remote} was pushed by this device, but no local ancestor copy exists for it: the baseline has been adopted (the next merge degrades to a two-way merge, which is still safe)',
@@ -247,10 +259,15 @@ export class SyncEngine {
247
259
  * 「推上去了、拉下来静默没有」)。
248
260
  */
249
261
  pullSectionIds() {
250
- const ids = this.portableAdapters().map((a) => a.id);
251
- for (const a of this.optInAdapters())
252
- ids.push(a.id);
253
- return new Set(ids);
262
+ return new Set(this.candidateAdapters().map((a) => a.id));
263
+ }
264
+ /**
265
+ * 会进载荷的分区 adapter = portable(受注入范围约束)+ 本次放行的可选分区。
266
+ * 「哪些分区算数」只留这一处:hasLocalChanges / pullSectionIds / pushTargets 三处各写一份候选集合时,
267
+ * 漏掉一处就出现「推上去了、拉下来静默没有」或「有改动却判成无变化」(#146 的候选面纪律)。
268
+ */
269
+ candidateAdapters() {
270
+ return [...this.portableAdapters(), ...this.optInAdapters()];
254
271
  }
255
272
  /** 本次显式放行的「可选分区」adapter(空集 = 一个都不放行;顺序跟随 adapters) */
256
273
  optInAdapters() {
@@ -259,34 +276,15 @@ export class SyncEngine {
259
276
  return this.adapters.filter((a) => this.optInSections.has(a.id));
260
277
  }
261
278
  /**
262
- * push 候选 adapter:
263
- * - sections 缺省/空 → 全部 portable(「默认/快速导出」模式);
264
- * - sections 显式给出 → 只取 portable 且命中的(「高级/自定义导出」模式);
265
- * 非 portable / 未知分区 → 警告跳过(安全约束 + 不静默,用户能看见自己勾了哪个无效项);
266
- * - 例外:本次构造显式放行的可选分区(optInSections,见 SyncEngineOptions)作为候选取出。
267
- * 缺省空集 → 与改造前逐字等价(可选分区一律不进同步通道)。
279
+ * push 候选 adapter:缺省 = portable 全量 + 放行的可选分区;显式 sections 只取命中项,非 portable 警告跳过。
280
+ * issue #146 的「扣下」判定一并解完(`push-skip.ts`)⇒ 过滤只有一处,push 与 previewPush 必然同口径。
268
281
  */
269
- pushTargets(sections, warnings) {
270
- const portable = this.portableAdapters();
271
- const optIn = this.optInAdapters();
272
- // 默认模式(未指定 sections):portable 全量 + 本次显式放行的可选分区。
273
- // 自动同步的 push() 不带 sections,可选分区能否上榜完全由构造期 optInSections 决定
274
- // (scheduler 只传 'auto' 档 → sessions 永不悄悄上行)。
275
- if (sections === undefined || sections.length === 0)
276
- return [...portable, ...optIn];
277
- const byId = new Map(portable.map((a) => [a.id, a]));
278
- for (const a of optIn)
279
- byId.set(a.id, a);
280
- const out = [];
281
- for (const id of sections) {
282
- const adapter = byId.get(id);
283
- if (adapter === undefined) {
284
- warnings.push(this.msg('sync.skipNonPortable', { section: id }));
285
- continue;
286
- }
287
- out.push(adapter);
288
- }
289
- return out;
282
+ async pushTargets(opts, warnings, load) {
283
+ const held = await resolveHeldSections(opts, load);
284
+ // 两列表分开传是为了 sections 的「非 portable 警告跳过」,候选面仍是 candidateAdapters 的同一批。
285
+ return resolvePushTargets(this.portableAdapters(), this.optInAdapters(), opts.sections, held, (id) => {
286
+ warnings.push(this.msg('sync.skipNonPortable', { section: id }));
287
+ });
290
288
  }
291
289
  /** 结构性断言:凭据/秘密分区绝不进入同步载荷(双保险,portable 过滤之上) */
292
290
  assertNoForbiddenSections(sections) {
@@ -484,6 +482,8 @@ export class SyncEngine {
484
482
  if (encrypt && (opts.password === undefined || opts.password === '')) {
485
483
  throw new Error(this.msg('sync.encryptRequiresPassword'));
486
484
  }
485
+ const loadState = memoAsync(() => loadSyncState(this.stateDir, this.fsx, this.msg));
486
+ const { targets, held } = await this.pushTargets(opts, warnings, loadState);
487
487
  // SYN-02:本轮只列一次远端 index(推进检测 + 继承会话删除墓碑共用;墓碑累积在最新快照里)
488
488
  const remoteIndex = await listRemoteSnapshotIndex(this.transport);
489
489
  const remoteTombstones = remoteIndex.reason === undefined ? remoteTombstonesOf(remoteIndex.metas) : [];
@@ -499,8 +499,12 @@ export class SyncEngine {
499
499
  return { ok: false, snapshotId: '', sections: [], warnings, conflict: true, message: pre.message };
500
500
  adopted = pre.adopted;
501
501
  }
502
+ // issue #146:全被冲突扣下 ⇒ 一个分区都不上行。放在前置检测之后:远端已推进时「先同步远端」更该被报出来。
503
+ if (targets.length === 0 && held.length > 0) {
504
+ const message = this.msg('sync.pushSkipConflicted', { sections: held.join(', ') });
505
+ return { ok: true, snapshotId: '', sections: [], warnings: [...warnings, message], message, skipped: 'all-conflicted' };
506
+ }
502
507
  const plainSections = {};
503
- const targets = this.pushTargets(opts.sections, warnings);
504
508
  for (const adapter of targets) {
505
509
  let section;
506
510
  try {
@@ -516,9 +520,11 @@ export class SyncEngine {
516
520
  }
517
521
  warnings.push(...section.warnings);
518
522
  // includeSecrets=true:凭据值保留(随后整体加密);否则过 SecretScanner 剥离(默认安全)
523
+ // issue #136 C:与 exporter 同走 `sanitizeSectionData`(脱敏 + 归属标注一次完成),
524
+ // 否则推送载荷里没有 `redactedPaths`,目标机无从判断哪一行被剥空。
519
525
  const data = isFileSection(adapter.id) || includeSecrets
520
526
  ? section.data
521
- : this.scanner.scanAndRedact(section.data).sanitized;
527
+ : sanitizeSectionData(adapter, this.scanner, section.data).sanitized;
522
528
  plainSections[adapter.id] = data;
523
529
  }
524
530
  if (Object.keys(plainSections).length === 0) {
@@ -539,12 +545,46 @@ export class SyncEngine {
539
545
  // P1-5 + SYN-02:本机墓碑(上次推过、本机已删)叠加上远端继承的墓碑 ——
540
546
  // 不继承的话「A 删 → B 推」会漏掉墓碑,C 带旧快照就能把已删会话复活(删除只在本机传播)。
541
547
  const bookkeeping = await this.computeSessionBookkeeping(targets, plainSections, remoteTombstones);
548
+ const sessionBookkeeping = bookkeeping.tracked ? { sessionUnits: bookkeeping.sessionUnits, deletedSessions: bookkeeping.tombstones } : {};
542
549
  if (bookkeeping.deletedNow.length > 0) {
543
550
  warnings.push(this.msg('sync.sessionDeletionsRecorded', { count: String(bookkeeping.deletedNow.length) }));
544
551
  }
545
552
  if (bookkeeping.inherited > 0) {
546
553
  warnings.push(this.msg('sync.sessionTombstonesInherited', { count: String(bookkeeping.inherited) }));
547
554
  }
555
+ // issue #146:待裁决只剔除**真正推上去**的分区(导出失败/不在候选里的分区一律保留)。
556
+ const pushedSections = Object.keys(plainSections);
557
+ const pendingAfterPush = await pendingMergeAfterPush(loadState, pushedSections);
558
+ // issue #140:内容没变就**不新建快照**(不 upload、不建目录、不裁剪),只收养远端最新指针。
559
+ // 判据只有一处实现(content-diff.ts):远端最新快照实际携带的分区哈希 vs 本次导出。
560
+ // - force:true = 用户明确要求「就算一样也新建」(覆盖语义),跳过本判定;
561
+ // - 加密快照的 sections 恒空(transport.ts)⇒ 判定 unknown ⇒ 维持既有行为,不新增下载/解密;
562
+ // - 本轮新发现会话删除墓碑时不跳过:墓碑只随新快照的 manifest 传播,跳过等于丢掉删除。
563
+ if (!encrypted && opts.force !== true && bookkeeping.deletedNow.length === 0) {
564
+ const latest = remoteIndex.metas[remoteIndex.metas.length - 1];
565
+ const diff = diffSnapshotContent(latest, undefined, hashSections(plainSections));
566
+ if (diff.reason === 'same-content' && latest !== undefined) {
567
+ await this.recordBaseline(latest.id, plainSections, this.now().toISOString(), {
568
+ remoteSnapshotId: latest.id,
569
+ // P2:本轮内容已被远端收下 ⇒ 待裁决已有结论;但 issue #146 被扣下的分区仍待裁决,绝不一起清掉。
570
+ pendingMerge: pendingAfterPush,
571
+ // G-44:远端观测必须是**远端快照自己**的 sections,绝不由 state.sections 反推
572
+ remoteSections: latest.sections,
573
+ ...sessionBookkeeping,
574
+ });
575
+ return {
576
+ ok: true,
577
+ snapshotId: latest.id,
578
+ sections: pushedSections,
579
+ warnings,
580
+ skipped: 'unchanged',
581
+ adoptedSnapshotId: latest.id,
582
+ // 0.4.1 的基线收养是独立事实:本轮可能刚收养了「本机上次被打断的推送」,
583
+ // 紧接着又判定内容一致 —— 两件事都要如实回报(否则面板看不到基线自己动过)。
584
+ ...(adopted !== undefined ? { adoptedBase: adopted } : {}),
585
+ };
586
+ }
587
+ }
548
588
  // ⑥ 设备身份(cloud-sync 借鉴项 ⑥):首次生成后持久化在 sync-state.json(已有则纯读),
549
589
  // 随 manifest 上行 → 别的设备在历史列表里能看到「这份快照是哪台机器推的」。
550
590
  const device = await resolveDeviceIdentity(this.stateDir, os.hostname(), this.fsx, this.msg);
@@ -557,7 +597,7 @@ export class SyncEngine {
557
597
  schemaVersion: CURRENT_SCHEMA_VERSION,
558
598
  dshVersion: this.ctx.dshVersion,
559
599
  platform: this.ctx.platform,
560
- sectionIds: Object.keys(plainSections),
600
+ sectionIds: pushedSections,
561
601
  containsSecrets: includeSecrets,
562
602
  // 记录触发通道(git/webdav),供同步历史展示「由哪个通道触发」
563
603
  transport: this.transport.type,
@@ -581,6 +621,9 @@ export class SyncEngine {
581
621
  }
582
622
  // ② 上传远端(传输通道负责散文件落盘 + 提交推送)
583
623
  await this.transport.upload(snapshot);
624
+ // issue #141:git 的 latest/ 视图只由明文快照生成(密文无明文镜像);显式告警,否则用户看到「push 成功但 latest/ 是旧内容」无从解释。
625
+ if (encrypted && this.transport.type === 'git')
626
+ warnings.push(this.msg('sync.latestSkippedEncrypted'));
584
627
  // ②·1 裁剪远端快照:保留最新 MAX_REMOTE_SNAPSHOTS 个(含刚 push 的)。
585
628
  // 删除失败只告警(进 warnings),不上抛 —— 不阻断 push 主流程。
586
629
  // 放在 upload 之后(保证新快照已推送成功)与 recordBaseline 之前(先管好远端再记基线)。
@@ -592,15 +635,18 @@ export class SyncEngine {
592
635
  // 不落任何副本的旧行为会让每轮合并都缺共同祖先 → 三方退化成两方、整分区冲突,
593
636
  // 用户被迫反复人工裁决。明文通道不受影响(缺省走 writeAncestor 的明文散文件布局)。
594
637
  ...(encrypted ? { ancestorPassword: opts.password } : {}),
595
- // 只有本轮真的跟踪了 sessions 才覆盖这两个字段(见 computeSessionBookkeeping)
596
- ...(bookkeeping.tracked
597
- ? { sessionUnits: bookkeeping.sessionUnits, deletedSessions: bookkeeping.tombstones }
598
- : {}),
638
+ ...sessionBookkeeping,
639
+ // issue #140:远端刚收下的就是这份明文 hash ⇒ 记录远端观测(下一次推送/拉取的内容判定起点)。
640
+ // 加密快照的 sections 恒空 ⇒ 不写(指针一变就清空该字段,判定因此回落 id 比较)。
641
+ ...(encrypted ? {} : { remoteSections: hashSections(plainSections) }),
642
+ // P2:本机配置已经推成远端最新 ⇒ 之前的待裁决已被这次推送消解,不再挂着误导用户。
643
+ // issue #146:被扣下的分区没推上去,它们的待裁决必须留下(只剔除已推分区)。
644
+ pendingMerge: pendingAfterPush,
599
645
  });
600
646
  return {
601
647
  ok: true,
602
648
  snapshotId: id,
603
- sections: Object.keys(plainSections),
649
+ sections: pushedSections,
604
650
  warnings,
605
651
  ...(adopted !== undefined ? { adoptedBase: adopted } : {}),
606
652
  };
@@ -631,7 +677,15 @@ export class SyncEngine {
631
677
  credentialsIncluded = false; // 读不到 = 不会带凭据;预览如实显示 false
632
678
  }
633
679
  }
634
- const targets = this.pushTargets(opts.sections, warnings);
680
+ // 预览最多读一次状态(扣下集合),不需要记忆化 —— 套 memoAsync 只会多一层空壳。
681
+ const { targets, held } = await this.pushTargets(opts, warnings, () => loadSyncState(this.stateDir, this.fsx, this.msg));
682
+ if (targets.length === 0) {
683
+ // issue #146:两种「空目标」必须分开说 —— 全被冲突扣下(不是错误:push 也回 ok:true + skipped)≠ 没有可同步分区。
684
+ if (held.length > 0) {
685
+ return { ok: true, sections: [], remoteSnapshotCount: 0, encrypted, credentialsIncluded, skipped: 'all-conflicted', message: this.msg('sync.pushAllConflicted', { sections: held.join(', ') }) };
686
+ }
687
+ return { ok: false, sections: [], remoteSnapshotCount: 0, encrypted, credentialsIncluded, message: this.msg('sync.noPortableSections') };
688
+ }
635
689
  const plainSections = {};
636
690
  const counts = {};
637
691
  /** issue #91:本趟只读预览省掉了本地源打包 ⇒ 与基线不可比的分区(不可断言「无变化」) */
@@ -664,7 +718,7 @@ export class SyncEngine {
664
718
  }
665
719
  const data = isFileSection(adapter.id) || includeSecrets
666
720
  ? section.data
667
- : this.scanner.scanAndRedact(section.data).sanitized;
721
+ : sanitizeSectionData(adapter, this.scanner, section.data).sanitized;
668
722
  plainSections[adapter.id] = data;
669
723
  counts[adapter.id] = section.counts ? Object.values(section.counts).reduce((a, b) => a + b, 0) : 0;
670
724
  }
@@ -949,7 +1003,10 @@ export class SyncEngine {
949
1003
  * 远端是否出现比本地共同祖先更新的快照(§3.2「检测到远端新快照」)。
950
1004
  * - 远端为空 → false(无物可拉);
951
1005
  * - 远端指针未知(lastSnapshotId='':从未同步 / 远端 id 未知)且远端非空 → true(首次可拉);
952
- * - 否则比较远端最新快照 id 与 lastSnapshotId。
1006
+ * - 否则比较**内容**(issue #140):远端最新快照实际携带的分区哈希 vs 上次记录的远端观测。
1007
+ * 只比 id 时,任何一次新推送(哪怕分区逐字相同)都会判成「有新生」,白跑 download + 合并。
1008
+ * - 两边任一观测缺失(加密快照 sections 恒空 / 旧 state 没记过观测)⇒ 回落 id 比较,
1009
+ * 绝不把「读不到」猜成「没变」(判据与回落规则只在 content-diff.ts)。
953
1010
  * 只读远端列表(transport.list),不做下载/合并。
954
1011
  *
955
1012
  * 前提:lastSnapshotId 必须是**远端**快照 id(P0-7)。旧实现把本地生成的快照 id 也写进去,
@@ -963,11 +1020,15 @@ export class SyncEngine {
963
1020
  const metas = listed ?? await this.transport.list();
964
1021
  if (metas.length === 0)
965
1022
  return false;
966
- const latestId = metas[metas.length - 1].id; // list 按 createdAt 升序 → 最新在末
1023
+ const latest = metas[metas.length - 1]; // list 按 createdAt 升序 → 最新在末
967
1024
  const state = await loadSyncState(this.stateDir, this.fsx, this.msg);
968
1025
  if (state.lastSnapshotId === '')
969
1026
  return true;
970
- return latestId !== state.lastSnapshotId;
1027
+ const diff = diffSnapshotContent(latest, state.lastRemoteSections);
1028
+ // unknown(加密快照 / 旧 state 没有远端观测)⇒ 只能比 id:这是「读不到」的唯一退路。
1029
+ if (diff.reason === 'unknown')
1030
+ return latest.id !== state.lastSnapshotId;
1031
+ return diff.changed;
971
1032
  }
972
1033
  /**
973
1034
  * 连通性探针(cloud-sync 借鉴项 ②):把当前通道的**只读**自检透出给宿主路由。
@@ -984,32 +1045,12 @@ export class SyncEngine {
984
1045
  return await probe.call(this.transport);
985
1046
  }
986
1047
  /**
987
- * 本地**会进载荷**的配置与上次基线(sync-state.sections hash)相比是否有变化(§3.1 上传「看变化」)。
988
- * - 从未同步(sync-state.sections 为空)→ true;
989
- * - 任一 pushTargets 分区(portable + 本次放行的可选分区)导出 hash ≠ 基线 → true;
990
- * - 全部一致 → false(无本地改动,不上传)。只读本地导出 + sync-state,不碰远端。
991
- * 判定集合必须 == 推送载荷集合,且被比较字节必须可复现(细节与实测 → docs/evidence/sync-channel.md)。
1048
+ * 本地**会进载荷**的配置与上次基线相比是否有变化(§3.1,「看变化」)。
1049
+ * 判定集合 == 推送载荷集合(candidateAdapters),字节口径与载荷同源 —— 实现与理由见 local-changes.ts。
992
1050
  */
993
1051
  async hasLocalChanges() {
994
1052
  const state = await loadSyncState(this.stateDir, this.fsx, this.msg);
995
- if (Object.keys(state.sections).length === 0)
996
- return true;
997
- for (const adapter of this.pushTargets(undefined, [])) {
998
- let section;
999
- try {
1000
- section = await adapter.export(this.ctx, { includeSecrets: false });
1001
- }
1002
- catch {
1003
- continue; // 单项导出失败不影响判定(与 push 单项跳过语义一致)
1004
- }
1005
- const data = isFileSection(adapter.id) ? section.data : this.scanner.scanAndRedact(section.data).sanitized;
1006
- const recorded = state.sections[adapter.id];
1007
- if (recorded === undefined)
1008
- return true; // 基线缺该分区 → 视为有变化
1009
- if (recorded.hash !== hashSection(data))
1010
- return true;
1011
- }
1012
- return false;
1053
+ return hasLocalSectionChanges({ state, adapters: this.candidateAdapters(), ctx: this.ctx, scanner: this.scanner });
1013
1054
  }
1014
1055
  /**
1015
1056
  * 一键同步预览:拉取远端(最新或指定历史快照)→ 转临时 ZIP → Importer 分析出计划。
@@ -1122,7 +1163,7 @@ export class SyncEngine {
1122
1163
  catch {
1123
1164
  continue;
1124
1165
  }
1125
- const data = isFileSection(adapter.id) ? section.data : this.scanner.scanAndRedact(section.data).sanitized;
1166
+ const data = isFileSection(adapter.id) ? section.data : sanitizeSectionData(adapter, this.scanner, section.data).sanitized;
1126
1167
  localSections[adapter.id] = data;
1127
1168
  }
1128
1169
  const portableIds = this.pullSectionIds();
@@ -1138,7 +1179,7 @@ export class SyncEngine {
1138
1179
  ancestorPortable[id] = data;
1139
1180
  }
1140
1181
  }
1141
- const plan = mergeSections(localSections, remotePortable, ancestorPortable, { deletePlugins: this.deletePlugins });
1182
+ const plan = mergeSections(localSections, remotePortable, ancestorPortable, { deletePlugins: this.deletePlugins, selfPluginName: this.selfPluginName });
1142
1183
  // 结果**经返回值**交给调用方(previewMerge / applyMergeResolutions 都用这一份,不会二次下载);
1143
1184
  // 这里只留两个进程内备忘:祖先可用性(预览要如实说明「为什么全是冲突」)与三方输入
1144
1185
  // (applyMergeResolutions 要把分区级裁决落回**整分区**数据)。
@@ -1315,33 +1356,18 @@ export class SyncEngine {
1315
1356
  pendingConflicts,
1316
1357
  };
1317
1358
  }
1318
- /** 组装 pendingMerge 记录:同一远端快照上的连续待裁决**保留首次时间**(界面据此讲「挂了多久」)。 */
1359
+ /** P2(2026-11-14 真机事故):自动同步撞冲突时把分区落成待裁决;实现与为什么见 pending-merge.ts。 */
1360
+ async recordPendingMerge(sections) {
1361
+ const deps = { stateDir: this.stateDir, fsx: this.fsx, msg: this.msg };
1362
+ return persistPendingMerge(deps, this.lastMergedRemoteSnapshotId, sections, this.now().toISOString());
1363
+ }
1364
+ /** 组装 pendingMerge 记录(同一远端快照上连续冲突保留首次时间);见 pending-merge.ts。 */
1319
1365
  pendingMergeFor(state, remoteSnapshotId, sections) {
1320
- const since = state.pendingMerge !== undefined && state.pendingMerge.remoteSnapshotId === remoteSnapshotId
1321
- ? state.pendingMerge.since
1322
- : this.now().toISOString();
1323
- return { remoteSnapshotId, sections, since };
1366
+ return buildPendingMerge(state, remoteSnapshotId, sections, this.now().toISOString());
1324
1367
  }
1325
- /**
1326
- * 基线纪律的**纯状态**写入(不写祖先副本、不碰远端):仅在本机没有任何配置写入时使用。
1327
- *
1328
- * - pending 提供 → 写 pendingMerge;undefined → 清除该字段(「全部裁决完」);
1329
- * - advanceRemoteId 提供 → 把远端指针推进到该快照 id(缺省 = 保持不变)。
1330
- *
1331
- * 为什么不走 recordBaseline:那条路径会重建祖先副本并只带本次应用的分区 —— 在「没有应用任何分区」
1332
- * 或「仍有未裁决冲突」时都会把共同基线改坏(下一轮所有分区都退化成「无祖先 → 冲突」)。
1333
- */
1368
+ /** 基线纪律的纯状态写入(不碰祖先副本、不推远端);为什么不用 recordBaseline 见 pending-merge.ts。 */
1334
1369
  async writeMergeBaseline(opts) {
1335
- const state = await loadSyncState(this.stateDir, this.fsx, this.msg);
1336
- if (opts.pending === undefined)
1337
- delete state.pendingMerge;
1338
- else
1339
- state.pendingMerge = opts.pending;
1340
- if (opts.advanceRemoteId !== undefined) {
1341
- state.lastSnapshotId = opts.advanceRemoteId;
1342
- state.lastSyncAt = this.now().toISOString();
1343
- }
1344
- await saveSyncState(this.stateDir, state, this.fsx);
1370
+ await persistMergeBaseline({ stateDir: this.stateDir, fsx: this.fsx, msg: this.msg }, opts, this.now().toISOString());
1345
1371
  }
1346
1372
  /**
1347
1373
  * 重新导出**已应用**的分区(F-2,2026-10):基线的唯一正确来源是「实际落地的本机内容」。
@@ -1363,7 +1389,7 @@ export class SyncEngine {
1363
1389
  const section = await adapter.export(this.ctx, { includeSecrets: false });
1364
1390
  out[adapter.id] = (isFileSection(adapter.id)
1365
1391
  ? section.data
1366
- : this.scanner.scanAndRedact(section.data).sanitized);
1392
+ : sanitizeSectionData(adapter, this.scanner, section.data).sanitized);
1367
1393
  }
1368
1394
  catch {
1369
1395
  return null;
@@ -1375,78 +1401,26 @@ export class SyncEngine {
1375
1401
  * 记录祖先基线:写本地祖先副本 + 更新 sync-state(每分区 hash/updatedAt、lastSyncAt、transport、
1376
1402
  * 远端指针 lastSnapshotId、本地祖先目录名 ancestorId)+ 裁剪到 keep。
1377
1403
  *
1378
- * **两个 id 语义严格分开(P0-7),不要再混用同一个字段**:
1379
- * - `snapshotId`:本次基线的**本地**快照对象 id,同时是本地祖先副本的目录名(写入 `ancestorId`);
1380
- * - `opts.remoteSnapshotId`:该基线在**远端**对应的快照 id(写入 `lastSnapshotId`)。缺省 = snapshotId
1381
- * (push 路径两者天然相同);合并/应用路径**必须显式传**,否则 lastSnapshotId 会退化成「一个远端
1382
- * 并不存在的本地 id」→ hasNewRemoteSnapshot() 恒判「远端有新生」,每轮白跑 list + download + merge。
1383
- * 传入 `''` 表示「远端 id 未知」——宁可留空,也不要把本地 id 冒充成远端 id。
1384
- * - `opts.writeAncestor === false`:不落本地祖先副本,`ancestorId` 一并置 '' ——
1385
- * 绝不把一个本地并不存在的目录名写进状态(旧实现正是这样让下一轮 merge 直接抛错)。
1386
- * - `opts.ancestorPassword`(issue #107):祖先副本落**密文**(manifest.encrypted + 单密文载荷);
1387
- * 加密快照 push 必须传,否则下轮三方合并缺共同祖先、整分区冲突。
1388
- * - `opts.preserveAncestor === true`(合并仍有未裁决冲突):祖先副本与 ancestorId **保持不动** ——
1389
- * 共同基线必须仍是「本机与远端都认可的上一版」;拿只带本次应用分区的副本去覆盖它,会让
1390
- * 下一轮所有分区都退化成「无祖先 → 冲突」。
1391
- * - `opts.pendingMerge`(基线纪律):提供即写入;`null` = 清除该字段;缺省 = 不动(既有行为不变)。
1404
+ * 实现整体在 `baseline-record.ts`:P0-7 的两个 id 语义、G-44 的「远端观测 vs 本机观测」口径
1405
+ * 都写在那份文件头里,改这里之前先读它。引擎只把本机环境(快照目录、通道身份、时钟、文案)交出去。
1392
1406
  */
1393
- async recordBaseline(snapshotId,
1394
- // 基线**恒为明文**(加密快照的基线 hash 也用明文算,供 hasLocalChanges 比较);
1395
- // 需要落盘副本时由 opts.ancestorPassword 决定写明文还是密文目录。
1396
- sections, nowIso, opts = {}) {
1397
- const ts = nowIso ?? this.now().toISOString();
1398
- const preserveAncestor = opts.preserveAncestor === true;
1399
- const writesAncestorCopy = !preserveAncestor && this.localSnapshotsDir !== undefined && opts.writeAncestor !== false;
1400
- // 1) 写本地祖先副本(如有 localSnapshotsDir)。
1401
- // ancestorPassword 提供 → 落**密文**祖先副本(issue #107:加密通道也能做三方合并);
1402
- // 否则落明文散文件布局(既有行为逐字不变)。
1403
- if (writesAncestorCopy) {
1404
- const ancestorPassword = opts.ancestorPassword;
1405
- const encryptedAncestor = ancestorPassword !== undefined && ancestorPassword !== '';
1406
- const manifest = {
1407
- schemaVersion: CURRENT_SCHEMA_VERSION,
1407
+ async recordBaseline(snapshotId, sections, nowIso, opts = {}) {
1408
+ await recordBaselineAt({
1409
+ snapshotId,
1410
+ sections,
1411
+ ...(nowIso === undefined ? {} : { nowIso }),
1412
+ opts,
1413
+ env: {
1414
+ fsx: this.fsx,
1415
+ stateDir: this.stateDir,
1416
+ ...(this.localSnapshotsDir === undefined ? {} : { localSnapshotsDir: this.localSnapshotsDir }),
1408
1417
  dshVersion: this.ctx.dshVersion,
1409
1418
  platform: this.ctx.platform,
1410
- sectionIds: Object.keys(sections),
1411
- containsSecrets: false,
1412
- // 记录触发通道(git/webdav),供同步历史展示「由哪个通道触发」
1413
- transport: this.transport.type,
1414
- ...(encryptedAncestor ? { encrypted: true } : {}),
1415
- };
1416
- if (encryptedAncestor) {
1417
- const encryptedSections = await encryptSectionsPayload(sections, ancestorPassword);
1418
- await writeEncryptedAncestor(this.localSnapshotsDir, { id: snapshotId, createdAt: ts, manifest, sections: encryptedSections }, this.fsx);
1419
- }
1420
- else {
1421
- await writeAncestor(this.localSnapshotsDir, { id: snapshotId, createdAt: ts, manifest, sections }, this.fsx);
1422
- }
1423
- }
1424
- // 2) 更新 sync-state:远端指针 + 本地祖先目录名 + 每分区 hash/updatedAt + lastSyncAt + transport
1425
- const state = await loadSyncState(this.stateDir, this.fsx, this.msg);
1426
- state.lastSnapshotId = opts.remoteSnapshotId ?? snapshotId;
1427
- // preserveAncestor:祖先目录名一并保持不动(既不是 snapshotId,也不是 '')
1428
- if (!preserveAncestor)
1429
- state.ancestorId = writesAncestorCopy ? snapshotId : '';
1430
- state.lastSyncAt = ts;
1431
- state.transport = { type: this.transport.type, ref: this.transportRef };
1432
- // 基线纪律:null = 清除(全部裁决完);undefined = 不动该字段(既有调用方零感知)
1433
- if (opts.pendingMerge === null)
1434
- delete state.pendingMerge;
1435
- else if (opts.pendingMerge !== undefined)
1436
- state.pendingMerge = opts.pendingMerge;
1437
- // P1-5:只在调用方明确提供时覆盖(否则保留既有记录,绝不因某条路径不跟踪而清空)
1438
- if (opts.sessionUnits !== undefined)
1439
- state.sessionUnits = [...opts.sessionUnits];
1440
- if (opts.deletedSessions !== undefined)
1441
- state.deletedSessions = [...opts.deletedSessions];
1442
- for (const [sid, data] of Object.entries(sections)) {
1443
- state.sections[sid] = { hash: hashSection(data), updatedAt: ts };
1444
- }
1445
- await saveSyncState(this.stateDir, state, this.fsx);
1446
- // 3) 裁剪祖先副本(最近 N 个);preserveAncestor 时本轮没有新副本,不参与裁剪
1447
- if (!preserveAncestor && this.localSnapshotsDir !== undefined) {
1448
- await pruneAncestors(this.localSnapshotsDir, DEFAULT_ANCESTOR_KEEP, this.fsx);
1449
- }
1419
+ transport: { type: this.transport.type, ref: this.transportRef },
1420
+ now: () => this.now(),
1421
+ msg: this.msg,
1422
+ },
1423
+ });
1450
1424
  }
1451
1425
  /**
1452
1426
  * 应用自动应用计划:写本地(走 Importer.executeImportPlan 标准路径;应用前调 backup.createSnapshot 兜底);
@@ -1465,6 +1439,7 @@ export class SyncEngine {
1465
1439
  if (!this.importer) {
1466
1440
  throw new Error(this.msg('sync.applyMergePlanNoImporter'));
1467
1441
  }
1442
+ const importer = this.importer;
1468
1443
  const appliedIds = apply.autoApply.map((r) => r.id);
1469
1444
  // 0) 空 autoApply:无物可应用,直接短路(不构造 ZIP、不调 Importer)
1470
1445
  if (appliedIds.length === 0) {
@@ -1491,29 +1466,22 @@ export class SyncEngine {
1491
1466
  const tempSnapshot = bundle.tempSnapshot;
1492
1467
  const zipPath = await this.snapshotToZip(tempSnapshot, this.pullSectionIds());
1493
1468
  try {
1494
- const plan = await this.importer.createImportPlan(zipPath, {
1495
- strategy: 'replace', // auto 路径:冲突已在外部分流;这里 replace = 接受导入值
1496
- resolutions: {},
1497
- // issue #45:合并路径的映射来自 merge() 记下的远端 sourceHome + 用户映射
1469
+ // issue #136 B:两趟计划 + 待裁决面(判定与理由见 `planMergeApply` 的文档注释;不再兜底 replace)。
1470
+ const { plan, heldReview, heldWarnings } = await planMergeApply({
1471
+ zipPath,
1498
1472
  pathMappings: opts.pathMappings ?? this.lastMergedPathMappings,
1473
+ appliedIds,
1474
+ createImportPlan: (zip, decisions) => importer.createImportPlan(zip, decisions),
1475
+ heldConflictMessage: (count, sections) => this.msg('sync.mergeHeldConflicts', { count: String(count), sections: sections.join(', ') }),
1499
1476
  });
1500
1477
  if (!plan.items.length) {
1501
1478
  // 没有可执行项 → 视为 ok 但空 applied
1502
1479
  return { ok: true, applied: [], restoreId: '', rolledBack: false, review: [], warnings: [] };
1503
1480
  }
1504
1481
  // 2) 兜底:先建快照(拿到 restoreId 给 UI 一键回滚用)
1505
- const store = new FileSnapshotStore({ dir: this.rollbackSnapshotsDir });
1506
- let snapshot;
1507
- try {
1508
- snapshot = await createSnapshot({
1509
- ctx: this.ctx,
1510
- plan,
1511
- sourceZip: zipPath,
1512
- store,
1513
- adapters: this.adapters,
1514
- });
1515
- }
1516
- catch (backupErr) {
1482
+ const snap = await createMergeApplySnapshot({ ctx: this.ctx, plan, zipPath, storeDir: this.rollbackSnapshotsDir, adapters: this.adapters });
1483
+ if (!snap.ok) {
1484
+ const backupErr = snap.error;
1517
1485
  return {
1518
1486
  ok: false,
1519
1487
  applied: [],
@@ -1523,9 +1491,9 @@ export class SyncEngine {
1523
1491
  warnings: [this.msg('sync.preApplySnapshotFailed', { err: backupErr instanceof Error ? backupErr.message : String(backupErr) })],
1524
1492
  };
1525
1493
  }
1526
- // 3) 真正执行:Importer.executeImportPlan(rollbackOnError 取单一缺省 → 任一失败整体回滚)
1527
- // 自动同步路径没有密码(凭据载荷无法解密),因此恒不注入 decryptedCredentials;
1528
- // 加密快照本就不会进入自动同步(无密码无法 prepareSnapshot)。
1494
+ const { store, snapshot } = snap;
1495
+ // 3) 真正执行:rollbackOnError 取单一缺省 → 任一失败整体回滚;自动同步没有密码,
1496
+ // 恒不注入 decryptedCredentials(加密快照本就不进自动同步)。
1529
1497
  const result = await this.importer.executeImportPlan(zipPath, plan, {
1530
1498
  confirm: true,
1531
1499
  rollbackOnError: DEFAULT_ROLLBACK_ON_ERROR,
@@ -1549,13 +1517,11 @@ export class SyncEngine {
1549
1517
  rollbackFull: rb.full,
1550
1518
  };
1551
1519
  }
1552
- // 4') issue #132:跟随远端删除插件(手动与自动共享此路径)。必须在 exportAppliedSections
1553
- // 之前 —— 基线要记录「删完之后」的真实清单,否则祖先仍带着刚删的包、每轮重复提删除。
1520
+ // 4') issue #132:跟随远端删除插件(手动与自动共享此路径),必须先于基线重导出 ——
1521
+ // 基线要记录「删完之后」的真实清单,否则祖先仍带着刚删的包、每轮重复提删除。
1554
1522
  // 4'') undo 线索:删掉的插件写进本次回滚快照,恢复计划据此反向重装;记不上只告警。
1555
- const pluginStep = await applyPluginRemovalStep({
1556
- appliedIds, plan: await this.pluginRemovalPlan(), enabled: this.deletePlugins,
1557
- uninstall: (name) => this.ctx.plugins.uninstall(name), msg: this.msg,
1558
- });
1523
+ const pluginStep = await applyPluginRemovalStep({ appliedIds, plan: await this.pluginRemovalPlan(),
1524
+ enabled: this.deletePlugins, uninstall: (name) => this.ctx.plugins.uninstall(name), msg: this.msg });
1559
1525
  const undoWarnings = await recordPluginRemovalUndo({
1560
1526
  removals: pluginStep.removals, snapshotId: snapshot.id,
1561
1527
  record: store.recordPluginRemovals?.bind(store), msg: this.msg,
@@ -1573,8 +1539,8 @@ export class SyncEngine {
1573
1539
  applied: appliedIds,
1574
1540
  restoreId: snapshot.id,
1575
1541
  rolledBack: false,
1576
- review: [],
1577
- warnings: [...(result.warnings ?? []), ...pluginStep.warnings, ...undoWarnings, this.msg('sync.baselineRexportFailed', { sections: appliedIds.join(', ') })],
1542
+ review: heldReview,
1543
+ warnings: [...(result.warnings ?? []), ...pluginStep.warnings, ...undoWarnings, ...heldWarnings, this.msg('sync.baselineRexportFailed', { sections: appliedIds.join(', ') })],
1578
1544
  ...(pluginStep.removals.length === 0 ? {} : { pluginRemovals: pluginStep.removals, needsRestart: true }),
1579
1545
  };
1580
1546
  }
@@ -1589,8 +1555,8 @@ export class SyncEngine {
1589
1555
  applied: appliedIds,
1590
1556
  restoreId: snapshot.id,
1591
1557
  rolledBack: false,
1592
- review: [],
1593
- warnings: [...(result.warnings ?? []), ...pluginStep.warnings, ...undoWarnings],
1558
+ review: heldReview,
1559
+ warnings: [...(result.warnings ?? []), ...pluginStep.warnings, ...undoWarnings, ...heldWarnings],
1594
1560
  // 删过插件必须重启(与安装同语义):报告不能只说「已应用」
1595
1561
  ...(pluginStep.removals.length === 0 ? {} : { pluginRemovals: pluginStep.removals, needsRestart: true }),
1596
1562
  };
@@ -23,6 +23,13 @@ export interface AutosyncHistoryEntry {
23
23
  pulledSnapshotId?: string;
24
24
  /** failed 时的错误摘要(脱敏) */
25
25
  error?: string;
26
+ /**
27
+ * issue #136:本轮下行的用户可见告警(被保住的脱敏叶子 / 被扣下的叶级冲突)。
28
+ * 与 status 同看:有告警就不可能是一条「纯成功、什么都做了」的记录。
29
+ */
30
+ warnings?: string[];
31
+ /** issue #136:被保留待裁决的叶级冲突所在分区。 */
32
+ heldSections?: SectionId[];
26
33
  /** 连续失败 3 次通知时间(ISO-8601 UTC) */
27
34
  notifiedAt?: string;
28
35
  /** 本次触发时的连续失败计数 */